Reputation: 31
I am using the new QtQuick3D from Qt6. I need to draw a line between 2 points, but didn't find a function dedicated for this. Therefore I decided to use a basic cylinder that I can scale and rotate. The scaling works as intended, but the rotation has some issues.
Node {
property vector3d center
property vector3d scaleCylinder
property vector3d eulerAngles
Model {
id: line
position: center
source: "#Cylinder"
scale: scaleCylinder
eulerRotation: eulerAngles
materials:
DefaultMaterial {
diffuseColor: "blue"
}
}
}
I compute the rotation using the Eigen library, via an angle axis to retrieve the Euler angles. The cylinder axis is in the Y-axis when displaying it.
AngleAxis angleAxis(const PointType vec) {
double angle;
VectorType axis;
PointType a = PointType({0, 1, 0});
PointType v = normalize(vec);
axis = point2vector(normalize(cross(a, v)));
angle = acos(dot(a, v));
return AngleAxis(angle, axis);
}
void setEulerAngles() {
AngleAxis rotation = angleAxis(target - entry);
VectorType angles= rotation.toRotationMatrix().eulerAngles(0, 1, 2);
eulerAngles = QVector3D(float(angles[0] * 180.0 / M_PI), float(angles[1] * 180.0 / M_PI), float(angles[2] * 180.0 / M_PI));
}
Did I make a mistake when computing my Euler angles? Should I use another technique, like quaternions? Maybe there is even a simpler solution I don't know about.
Upvotes: 1
Views: 503