Jump to content
  • Advertisement
Sign in to follow this  
Samurai Jack

Matrix and Quaternion mismatch

This topic is 4508 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Give an example of a set of YPR angles which reproduce the problem, and the quaternions produced by each approach.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!