• 11
• 9
• 10
• 9
• 10

# Help With Local Object Orientation Code

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

## 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 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 on other sites
Quote:
 Original post by sirobWhy 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 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 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.