matrix rotation ?

Started by
2 comments, last by Buckeye 13 years, 9 months ago
the code below will rotate an object in its local space , ie. it will rotate relitive to it present rotations, like a plane..

but how do i rotate relitive to world space , please




D3DXVECTOR3 rotLocal;

D3DXMatrixRotationX(&x, (rotLocal.x * 0.0174532925));
D3DXMatrixRotationY(&y, (rotLocal.y * 0.0174532925));
D3DXMatrixRotationZ(&z, (rotLocal.z * 0.0174532925));

D3DXMATRIX matrix = x * y * z;
Advertisement
The code below isn't using any particular space. All you have done is construct a rotation matrix. If you set this as your world transform (with device->SetTransform()) and then draw your model, your models vertices will be transformed from local space to world space.
with the code above i can control an mesh like a plane

if i use D3DXMatrixRotationX(&x, (rotLocal.x * 0.0174532925));

then the plane will tilt back or forward like a real plane .



but how do i do it so it rotates forwards relitive to the screen not the objetc/mesh
Could you describe a little more clearly how you want the plane to rotate? "rel[a]tive to the screen" isn't quite descriptive enough.

Expending on what Dave mentioned, how the rotation is applied will depend on how you construct your world matrix - the order of the matrices involved.

E.g. (this applies to DirectX. OpenGL order is the reverse):

world = translate_plane * rotate_plane;

will rotate the plane locally, then translate it to some location.

world = rotate_plane * translate_plane;

will translate the plane to some location, then rotate it with respect to the translated position.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement