Sign in to follow this  
vetroXL

Help With Local Object Orientation Code

Recommended Posts

Hi, Can someone tell me what I'm doing wrong. It doesn't seem to work the way I want. I just want to be able to rotate on the y axis ( YAW ) and the x axis( PITCH ). I'm trying to keep track of my orientation but i still "lose" it after a while, i'm noticing the pitch is the first to go. Thanks void Render() // ... D3DXVECTOR3 right( 1.0f, 0.0f, 0.0f ); D3DXVECTOR3 up ( 0.0f, 1.0f, 0.0f ); D3DXVECTOR3 look ( 0.0f, 0.0f, 1.0f ); D3DXMATRIX yRot, xRot; D3DXMatrixRotationAxis( &yRot, &up, y ); // yaw about the up vector D3DXVec3TransformCoord(&look, &look, &yRot); D3DXVec3TransformCoord(&right, &right, &yRot); D3DXMatrixRotationAxis( &xRot, &right, x ); //Pitch about right vector. D3DXVec3TransformCoord(&look, &look, &xRot); D3DXVec3TransformCoord(&up, &up, &xRot); D3DXVec3Normalize(&right, &right); D3DXVec3Normalize(&look, &look); D3DXVec3Normalize(&up, &up); D3DXMATRIX World; D3DXMatrixIdentity( &World ); World._11 = right.x; World._12 = up.x; World._13 = look.x; World._21 = right.y; World._22 = up.y; World._23 = look.y; World._31 = right.z; World._32 = up.z; World._33 = look.z; Device->SetTransform(D3DTS_WORLD, &World);

Share this post


Link to post
Share on other sites
Why not just stick to the simple route:

here's some pseudo code I think should work:
Matrix mat, mat2;
D3DXMatrixRotationX(mat, pitch);
D3DXMatrixRotationY(mat2, yaw);

Matrix matWorld;
D3DXMatrixMultiply(matWorld, pitch, yaw);


Hope this helps. :)

Share this post


Link to post
Share on other sites
Quote:
Original post by sirob
Why not just stick to the simple route:

here's some pseudo code I think should work:
Matrix mat, mat2;
D3DXMatrixRotationX(mat, pitch);
D3DXMatrixRotationY(mat2, yaw);

Matrix matWorld;
D3DXMatrixMultiply(matWorld, pitch, yaw);


Hope this helps. :)



Hi, Thanks for the reply. However this code loses the orientation of the object. I.E. if you pitch 90deg down then do a yaw, it will look like a roll. I'm trying to avoid this.

Share this post


Link to post
Share on other sites
right, sorry, I misunderstood :).

If you want the roll and pitch to be in Object space, you'll need to do something of this sort (again, pseudo code):

Matrix matOldWorld;
mat = device->GetTransform(WORLD); // Or, when drawing more than one object, this would need to be
// the World Matrix used with this object in the last frame.

Matrix matRot;
D3DXMatrixRotationY(matRot, yaw); // <-- this is only the difference in yaw for this frame, not the total amount.
Matrix matWorld;
D3DXMatrixMultiply(matWorld, matRot, matOldWorld); // <-- this will yaw;
// Reversing the parameter order for the multiply will switch between object and world space.

You can replace the RotationY with RotationX to perform a pitch, instead.

Hope this helps :).

Share this post


Link to post
Share on other sites
Hi, thanks again sirob.

I have not tried your second solution. However, after starring(sp) at my code I found my goof. I was transposing my matrix when I shouldn't be. Also I was reseting my vectors.

Thanks again for you help sirob.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this