Sign in to follow this  

camera movement

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i have just started learning directx and i am programming a simple first person shooter. I am currently implmenting a camera which translates to the users position and rotates around the player when the mouse is moved. I currently have the movement all sorted although i am having problems with the camera rotation. Wheneva i rotate the camera rotates around 0,0,0 instead of the position of the camera. am i fully aware that you should translate the camera to the center point rotate and then translate back but as of yet i have not been able to impliment this. I was just wondering if any one could have a look at my code and tell me where i am going wrong. Thanks in advance Dan //vector3D is a custom made vector class used throughout the rest of //the program. vector3D posip = player->pos(); vector3D face = player->facing(); D3DXQUATERNION rot; D3DXQuaternionIdentity(&rot); D3DXQuaternionRotationYawPitchRoll(&rot, face.x, face.y, 0); D3DXMATRIX matView; D3DXMatrixIdentity(&matView); D3DXVECTOR3 pos(posip.x, posip.y, posip.z); D3DXVECTOR3 headoffset(0,10,0); pos = pos + headoffset; D3DXMatrixAffineTransformation(&matView, 1.00f, &pos, &rot, &pos); d3ddev->SetTransform(D3DTS_VIEW, &matView);

Share this post


Link to post
Share on other sites
Try this:


D3DXMATRIX rot;
D3DXMatrixRotationYawPitchRoll(&rot, face.x, face.y, 0);

D3DXVECTOR3 pos(posip.x, posip.y, posip.z);
D3DXVECTOR3 headoffset(0,10,0);
pos = pos + headoffset;
D3DXMATRIX translation;
D3DXMatrixTranslation(&translation, pos.x, pos.y, pos.z);

D3DXMATRIX matView = rot * translation;
D3DXMatrixInverse(&matView, NULL, &matView);

Share this post


Link to post
Share on other sites
Just so you know what I did there...the view matrix is simply the inverse of matrix representing the transforms needed to get the camera to a specific position and orientation. In your case, this transformation is the combination of two other transformations: a rotation and a translation. By applying the rotation first the camera is rotated about it's own origin (since it hasn't been translated yet) and then the translation moves it to its position afterwards.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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