rotation in Immediate Mode
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);
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement