raylib: [raymath] bug in QuaternionToMatrix/QuaternionFromMatrix?
Please, before submitting a new issue verify and check:
- I tested it on latest raylib version from master branch
- I checked there is no similar issue already reported
- My code has no errors or misuse of raylib (I do not think so, at least)
Issue description
Source:
Vector3 euler_src= {(float)0, PI / 4, (float)0};
auto quat1 = QuaternionFromEuler(euler_src.x, euler_src.y, euler_src.z);
auto euler1 = QuaternionToEuler(quat1);
auto mat1 = QuaternionToMatrix(quat1);
cout << "orig angles: (" << euler_src.x << "," << euler_src.y << "," << euler_src.z << ")" << endl;
cout << "euler1: (" << euler1.x << "," << euler1.y << "," << euler1.z << ")" << endl;
cout << "quat1: (" << quat1.x << "," << quat1.y << "," << quat1.z << "," << quat1.w << ")" << endl;
auto quat2 = QuaternionFromMatrix(mat1);
auto euler2 = QuaternionToEuler(quat2);
auto mat2 = MatrixRotateXYZ(euler_src);
cout << "euler2: (" << euler2.x << "," << euler2.y << "," << euler2.z << ")" << endl;
cout << "quat2: (" << quat2.x << "," << quat2.y << "," << quat2.z << "," << quat2.w << ")" << endl;
This prints:
orig angles: (0,0.785398,0)
euler1: (0,45,0)
quat1: (0,0.382683,0,0.92388)
euler2: (0,-45,0)
quat2: (0,-0.336557,0,1.0505)
These are indeed different angles, which is not what I think would be expected, because the first quaternion is made by converting from euler, and the second quaternion is made by converting back from the matrix.
Environment
Linux x64, but I don’t think this is relevant because this is in the standalone math library.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (15 by maintainers)
this works:
but there is still the issue with quat to mat…
okay I can see (i think) equivalent but different values happening with euler to quat with different code, the problem seems to be with matrix to quat, which seems to be way out… I’ve tried a few other similar methods but seem to not be getting correct results… I’ll have a think about it and try again another time, in the mean time if anyone else wants to chip in by all means!
I’ll have a play over the weekend, its probably a variable transposed somewhere I’m betting…
On Thursday, 30 July 2020, Adrie notifications@github.com wrote:
sorry haven’t had time to look at this till now…
my QtoM function seems to line up with taking a quat from a matrix and again if you take a quat to euler and then create a matrix rotated in the order XYZ …
I see issues with multiple quaternion conversions (not just matrix) I’ve not managed to get a quat to matrix working as I suspect that different functions are using different rotation orders (in effect) this code should highlight the issues I see