Unsolved QMatrix, QQuaternion Confusion
-
Hello,
for the communication with another program I need to convert a Transformmatrix into a QQuaternion and back. This worked so far. (Maybe because both convertion ways where wrong so it compensated the mistake. )
But since I added another conversion for special cases which only reads the EulerAngles of the quat, the sened X-Rotation can turn out as Z-Rotation on the other side so there must be something wrong with the order of the values in the ctors.
The docu is not telling much so hopefully someone can see the mistake:
Convert MyMatrix to QMatrix:
float values[] = { uVec.x, uVec.y, uVec.z, vVec.x, vVec.y, vVec.z, wVec.x, wVec.y, wVec.z }; QMatrix3x3 rotatioMa (values);
Convert QMatrix to MyMatrix:
// Column-major order
uVec (qMatrix.data()[0], qMatrix.data()[3], qMatrix.data()[6]); // x y z vVec (qMatrix.data()[1], qMatrix.data()[4], qMatrix.data()[7]); // x y z wVec (qMatrix.data()[2], qMatrix.data()[5], qMatrix.data()[8]); // x y z
Converting euler angles to a Quaternion:
QQuaternion::fromEulerAngles( yRot_Pitch, zRot_Yaw, xRot_Roll); // I looked in wikipedia which axis are used for pitch, yaw and roll
regards,
Patrick -
Hi,
You should use the copyDataTo method store the matrix values and use the constructor which takes a pointer to reload them.
-
Thanks for your answer.
I guess you think I copy one QMatrix to another but the original Matrix has a different type.Meanwhile I totally replaced the QMatrix by the QQuaternion but still the XAngle turns out as Z at the other side. Pretty sure the problem is the order of the euler angles in the QuatCtor.
This is the declaration:
QQuaternion.fromEulerAngles(float pitch, float yaw, float roll);
As mentioned I used the angles in the following order:
fromEulerAngles(yRot, zRot, xRot);
-
So you go from QMatrix3x3 to your own matrix and then QQuaternion through fromEulerAngles ?
What if you use fromRotationMatrix ?