#### Archived

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

# rotation in Immediate Mode

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

## Recommended Posts

currently I can rotate an object one of its own axis, but how do I go about rotating an object around any point in space? to rotate around its own axis I go: D3DUtil_SetTranslateMatrix(matTrans,x,y,z); D3DUtil_SetRotateYMatrix( matRotate, m_fRotationCurrent ); D3DMath_MatrixMultiply( matWorld, matRotate, matTrans ); m_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld); m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, D3DFVF_VERTEX,lpVertices,TOTAL_VERTICES,0);

##### Share on other sites
Rotations are always performed around the origin (0,0,0) so if you wish to rotate about an arbitrary point in space:

1. translate so the point lies in the origin
2. rotate
3. translate it back to its original position.

In D3D you would do it like this:

D3DMATRIX T,R,TInv,World;
D3DUtil_SetTranslateMatrix(T,-Point.x,-Point.y,-Point.z);
D3DUtil_SetRotateYMatrix(R, m_fRotationCurrent);
D3DUtil_SetTranslateMatrix(TInv,Point.x,Point.y,Point.z);
D3DMath_MatrixMultiply(World,T,R);
D3DMath_MatrixMultiply(World,World,TInv);
m_pd3dDevice->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);

- WitchLord

• 10
• 13
• 57
• 11
• 84