Matrix and Quaternion mismatch
Greetings!
For long time now, I was parsing several 3D file formats, but there are still some questions open. In Half-Life .smd format by Valve there is something i can not understand:
vertices are passed in following order:
bone x y z nx ny nz u v yaw pitch roll
What bothers me is that yaw pitch roll - that are rotation parameters in radians. When I say:
(method 1)
D3DXMatrixRotationX(&matrix_x, yaw);
D3DXMatrixRotationY(&matrix_y, pitch);
D3DXMatrixRotationZ(&matrix_z, roll);
rotation_matrix = matrix_x * matrix_y * matrix_z;
(method 2)
everything works fine, but if I say:
D3DXQuaternionRotationYawPitchRoll(&qrot, yaw, pitch, roll);
D3DXMatrixRotationQuaternion(&rotation_matrix, &qrot);
the two rotation matrices SOMETIMES (cca. 10% of all cases) differ. I MEAN REALLY DIFFER not just a smal floating precision fallof. I know one may say It could be in the order is it ypr, pyr, rpy etc... but it isn't! I tried all possible permutations/combinations but there are cases where the quaternion produced matrix differs a lot and in 90% of the cases it is the same as the first method.
So the problem is, whenever i try to compute the rotation matrices with the quaternion method some of them get corrupted.
I have used those quaternion functions also for Unreal and it works just superb.
As for reverse engeneering I have also tried to export the ONE AND SAME MESH via smd exporter and a customized exporter that dumps corresponding quaternions that acctualy do work in unreal, but are different as I would compute them in method 2. All quaternions are practialy the same just some get corrupted and ONLY the corrupted ones differ in both exporters.
Can anyone provide some help?
I also tried like that:
1. compute by method 1 and get a quaternion out of it,
2. compute quaternion by method 2 and compare by step 1
3. if they differ there is something wrong
Right at the moment I do not have any values to play with, but I will try to provide some that work and some that are corrupted.
Thank you in advance!
It looks like your code is basically doing the same thing (assuming the order is correct) but, just to be sure, have you tried using D3DMatrixRotationYawPitchRoll()? Like this:
D3DXMatrixRotationYawPitchRoll(&rotation_matrix1, yaw, pitch, roll);D3DXQuaternionRotationYawPitchRoll(&qrot, yaw, pitch, roll);D3DXMatrixRotationQuaternion(&rotation_matrix2, &qrot);
And then compare rotation_matrix1 and rotation_matrix2...
I dare to believe mx*my*mz is not allways the same als D3DXMatrixRotationYawPitchRoll. I will trully try to find some time to find some values that mismatch and post them. But I am sure I have tried exactly the method you mentioned. I'm at work right now and it is hard to find time to seek for those values. I saw the math forum at gamedev and had to try it.
Give an example of a set of YPR angles which reproduce the problem, and the quaternions produced by each approach.
Perhaps yaw should be a rotation around the Y axis and pitch a rotation about the X axis? Also, I believe the order of multiplication should be M = roll * pitch * yaw. I'm pretty sure that's how D3DXxxxxxRotationYawPitchRoll interprets it. But in any case, I would use D3DXMatrixRotationYawPitchRoll instead of either method.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement