Archived

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

dxAvatar

Rotations ...

Recommended Posts

dxAvatar    122
Hi everyone I''ve got a problem with rotation matrices : (you''ll perhaps think that is very easy but i''m beginning with D3D so plz help me) I''ve made a sample which displays a cube : you can rotate it with keyboard keys but i''ve got a very big problem : If i rotate around an axis it''s okay but if i change of axis then the scene comes back to beginning ... Should i explain : i make a 45° rotation to my cube around Z axis that''s cool ... and then i want to make it rotate around Y axis and ... the cube undo the 45° Z rotation !!! Can you help me ? I can put on the forum the code but i''ll be in TurboPascal !!! Thanx for the one who ''ll help me And Bye everyone dxAvatar

Share this post


Link to post
Share on other sites
Wierdo    122
I don''t really understand your question, but you need to multiply the matrices together to have them both work.







It''s like my grandfather used to say, "Never quote your elders."

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
D3DXMATRIX TranslationMatrix;
D3DXMATRIX RotationMatrix;
D3DXMATRIX FinalMatrix;

D3DXMatrixRotationYawPitchRoll(&RotationMatrix, yaw, pitch, roll);
D3DXMatrixTranslation(&TranslationMatrix, x, y, z);

D3DXMatrixMultiply(&FinalMatrix, &RotationMatrix, &TranslationMatrix);

pd3dDevice->SetTransform(D3DTS_WORLD, &FinalMatrix);

Share this post


Link to post
Share on other sites
dxAvatar    122
The only problem is that in my version of DirectX(called DelphiX) we don''t have neither RotationYawPitchRoll nor Translation so it''s a bit harder to do this ...

in fact my code looks like that

with dxInput do // this is the dxInput object
Begin // in c begin = { and end = }
if isUp in states then// if the key up is pressed
Begin
Pitch := Pitch+0.01 ; // Pitch = Real
D3DUTILS.D3DUTIL_SETXROTATION(World, Pitch);
dxDraw1.D3DDEVICE7.SETTRANSFORM(D3DTRANSFORMSTATE_World, World);
end;

if isdown in states then// if the key down is pressed
Begin
Pitch := Pitch-0.01 ;
D3DUTILS.D3DUTIL_SETXROTATION(World, Pitch);
dxDraw1.D3DDEVICE7.SETTRANSFORM(D3DTRANSFORMSTATE_World, World);
end;

if isLeft in States then
Begin
Roll := Roll +0.01;
D3DUTILS.D3DUTIL_SETZRotation(World, Roll);
DxDraw1.D3DDEvice7.SEtTransform(D3DTRANSFORMSTATE_World,World);
End;

if isRight in States then
Begin
Roll := Roll-0.01;
D3DUTILS.D3DUTIL_SETZROTATION(World, Roll);
DxDraw1.D3DDEVICE7.SetTransform(D3DTRANSFORMSTATE_World,World);
end

same thing for YAW

etc ...

Can you help me somewhere ?
if you can''t understand the code i can put it in C

thanx a lots and bye

dxAvatar

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
If I understand your problem, you are having difficulty causing your object to pitch, yaw, and or roll relative to IT''S local coordinate system. I always think of this stuff in airplane terms.. no matter what orientation the plane has, when you pull back on the stick, you pitch up in the planes object space, but that might be sideways if you are already in a steep bank.

Here''s how I solved the problem:

1. Maintain a Matrix that is your current rotation.
2. Maintain a vector which represents all 3 of your axis''.
(D3dXvector3(1,0,0) might be your pitch vector.
3. Now, here is the tricky part: Let''s say you already have a pitch yaw and roll dialed in, and you want to pitch up some more.. do this:

1.You would rotate the Pitch Identity vector (1,0,0) by the current rotation matrix:

D3DXVec3TransformCoord &vect,&vector_pitch,¤t_rotation);

2. Then create a rotation vector that is an arbitrary rotation about an axis.. in this case the axis would be our transformed identity vector from step 1.(This is easy with the dx8 sdk, possibly difficult if your are using Delphi) My code looks somehthing like this:

D3DXMatrixRotationAxis(&rot_pitch,&vect,fPitch_angle);

Then you just multiply the current rotation matrix by the new pitch rotation matrix, and voila, you can now pitch yaw and roll when your object already has been transformed into some arbitrary space.

If this makes no sense, I can try and clarify.

-andy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Andy, it makes a lot of sense, but Iam still missing something.
Can you post your actual code?

Bye & thanx,
ivan bolèina

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Just to explain my question.
I have an airplane in world space.

How to represent its orientation?
How to move it around its axes?


bye and thanx
ivan bolèina

Share this post


Link to post
Share on other sites