Sign in to follow this  

proper rotation about a vector

Recommended Posts

hopefully this will be quick and painless... I have 2 vectors one is a "target" and the other is a "position" what i want to do is to have the "position" rotate about the "target"... I have my rotating working but i can only get is to rotate around (0,0,0) i know i some how need to incorporate the "target" im just not sure where / how here is what i got / have...

D3DXMATRIX matRot, matTrans;
D3DXMatrixRotationYawPitchRoll(&matRot, y, x, z);
D3DXVec3TransformCoord(&m_pos, &m_pos, &matRot);

// locks the camera to a distance
m_pos =  m_pos - m_target;
D3DXVec3Normalize(&m_pos, &m_pos);
m_pos = m_pos * m_targetDistance;

Share this post

Link to post
Share on other sites
If I follow what you're asking then rotations are always about an axis passing through the origin. If you want a rotation about an axis that doesn't pass through the origin then you need a translation so that a point on the axis is the origin, do the rotation then translate it back.

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