camera movement

Started by
2 comments, last by MJP 15 years, 10 months ago
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);
Advertisement
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);
thank you so much, i have been fiddling with this for bou 6 hours.
thank you again!
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.

This topic is closed to new replies.

Advertisement