#### Archived

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

# translating camera in world space ??

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

## 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 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 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;
}

1. 1
2. 2
Rutin
20
3. 3
khawk
17
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 11
• ### Forum Statistics

• Total Topics
633757
• Total Posts
3013711
×