• Advertisement


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

translating camera in world space ??

This topic is 5674 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 a problem with a mouse look camera. It seem like if I set the matrix position like this mat._43 = -50; and then call SetTransform(D3DTS_VIEW, &mat); Then the camera will be translated -50 in the direction the camera is facing. But I want to move it -50 in worldspace otherwise the camera will be rotating around the center of the world. Anyone know how to convert the camera translation into worldspace or the correct way to call the funtion ? Thanks

Share this post

Link to post
Share on other sites
Before translating your camera, rotate it so that the camera''s axis matches that of world space. Next, translate your camera and finally rotate your camera back to where it started.

In matrix terms, multiply your translation matrix by the inverse of your rotation matrix. Then multiply your rotation matrix by the product of the previous operation. The resulting matrix can now be set as your view matrix.

Remember that order matters when doing matrix multiplication. It works in a right-to-left order (counter-intuative). So when you want to create transformation matrices remember:
MOut = M1 * M2 (where the transformation M2 is performed before M1)

Chris Z.

Share this post

Link to post
Share on other sites
I tried that and it seems to work except for one thing. When I translate the camera back and forth in Z it will move towards the center 0,0,0. This is of course because I do something wrong. Here is the code can someone see what I am doing wrong ?

void JC_Camera::SetCameraRotationRad(float aXAngle,float aYAngle,float aZAngle, D3DXVECTOR3 aTranslation)
D3DXMATRIX tempRotMat, tempTranslate, tempInvRotMat, tempMat;

//Setup rotation matrix
D3DXMatrixRotationYawPitchRoll(&tempRotMat, aYAngle, aXAngle, aZAngle);
//Get the inverse of the view to transform back to world space
D3DXMatrixInverse(&tempInvRotMat, NULL, &tempRotMat);
//Translate the camera
D3DXMatrixTranslation(&tempTranslate, aTranslation.x, aTranslation.y, aTranslation.z);
//Apply the inverse of the rotation
D3DXMatrixMultiply(&tempMat, &tempTranslate, &tempInvRotMat);

//Apply the correct rotation
D3DXMatrixMultiply(&tempRotMat, &tempRotMat, &tempMat);

//Assign to the camera matrix
myMatrix = tempRotMat;

Share this post

Link to post
Share on other sites

  • Advertisement