This topic is now archived and is closed to further replies.


a question about 3d rotation (yes, another)

Recommended Posts

First off, thanks for reading this, and if you help me, thanks even more (I''m new here). Ok, on to my question. I''m making a 3D engine (isn''t everyone?) and am storing an object''s orientation in a rotation matrix. I was using Euler angels but suffered from gimbal lock, so I switched. Now, when I rotate an object, I first make a rotation matrix out of the desired rotation angles, and then use that, and multiply it by the objects former rotation matrix, resulting in the new matrix. (I multiply in that order to acheive rotation relative to the object). This works. Now, when I wanted to move the object I created a vector for it. Then, I load it with the velocities for the object, again, relative to the object at first. Then, to get the rotated vector, I multiply it by the rotation matrix of the object. This then gives me the world translation values, which I use to move the object. This *should* work, and in a way, it does. As long as I don''t rotate on one axis, the other two work great. When I start using the 3rd, it goops up, but only in movement, rotation still works perfect. This feels to me like gimbal lock, but from what I read using matrix rotation gets rid of that, and it does work for the rotation, just not the movement. Also, since I couldn''t find a function to multiply a vector by a matrix, I had to write my own, which seems right. This might also be an issue. Lastly, I''m concerned at maybe having problems with accuracy somewhere, though I use floats everywhere, and in my tests made sure not to go into high values, so that''s most likely not the issue. I''d appreciate any help, or even just a wild guess. P.S. I know you''re gonna say "use Quaternions", but I''d REALLY rather not. Thanks for reading.

Share this post

Link to post
Share on other sites
You can use Direct3DX''s math functions, like this:

D3DXVECTOR3 Vector( X, Y, Z );

D3DXMatrixRotationYawPitchRoll( &Matrix, -float(PI_OVER_180) * (float)Rotation.Yaw, -float(PI_OVER_180) * (float)Rotation.Pitch, -float(PI_OVER_180) * (float)Rotation.Roll );
D3DXVec3TransformCoord( &Vector, &Vector, &Matrix );

Vector is now rotated. You may prefer using your own functions but at least for debugging purposes it''s good to use what you know works.

~CGameProgrammer( );

Share this post

Link to post
Share on other sites
Thanks for the speedy response.

I have a follow up question though.

Until now I was using the _D3DVECTOR type, but your solution uses the D3DXVECTOR3 type.

That''s fine, but I have no clue how to apply this vector to the object after it has been calculated. With _D3DVECTOR I''d just use the .x, .y and .z to get the components and then use those to create a transformation matrix, and multiply the old matrix by the new one. However, I don''t know how to get the x, y, and z components out of the D3DXVECTOR3 type.

I tried using D3DXMatrixTransformation( ) to create a transformation matrix directly, but for some reason this isn''t working, as the object doesn''t move at all (I''m using NULL as all parameters except the out matrix, and the translation vector).

It''s possible I have a mistake somewhere else in the code, but I''ve double and triple checked it all.

Is the D3DXMatrixTransformation( ) method viable? or should I seek a different method?

Thanks in advance.

And P.S.,
nice signature.

Share this post

Link to post
Share on other sites