# Getting the Camera Position from the View Matrix

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

## Recommended Posts

I'm using C#/XNA and am wondering if it is possible to get the position of the Camera (in world coordinates) from the View Matrix or not, and if so, how do you do it. Thanks.

##### Share on other sites
The last column of the view matrix describes the position of the camera in world space.

##### Share on other sites
That's what I thought originally, but the position in the last column of the View Matrix has the untransformed coordinates (before any rotations are applied). Here is how I calculate my view matrix (taken from the XNA Particle3D Sample):

// Set up the View matrix according to the Camera's arc, rotation, and distance from the Offset positioncViewMatrix = Matrix.CreateTranslation(msCamera.cFixedCameraLookAtOffset) *Matrix.CreateRotationY(MathHelper.ToRadians(msCamera.fCameraRotation)) *Matrix.CreateRotationX(MathHelper.ToRadians(msCamera.fCameraArc)) *Matrix.CreateLookAt(new Vector3(0, 0, -msCamera.fCameraDistance),                    new Vector3(0, 0, 0), Vector3.Up);

Basically my Camera is fixed to always look at the msCamera.cFixedCameraLookAtOffset Position (which is (0, 50, 0), right above the origin). I then Yaw the Camera according to the CameraRotation value and Pitch it according to the CameraArc value. This allows me to rotate around the FixedCameraLookAtOffset Position while always looking at it. After performing the above operations and looking at the last column of the ViewMatrix, instead of holding the (x,y,z) values of the Camera Position it seems to be holding (0 , CameraArc, CameraDistance). So for example, rotating the Camera around the origin does not change the values in the last column at all. What am I missing here? Thanks.

##### Share on other sites
Quote:
 The last column of the view matrix describes the position of the camera in world space.
That's incorrect. However, if you invert the view matrix, the last column of the resulting matrix (or row, depending on convention) should then contain the camera position.

##### Share on other sites
Quote:
Original post by jyk
Quote:
 The last column of the view matrix describes the position of the camera in world space.
That's incorrect. However, if you invert the view matrix, the last column of the resulting matrix (or row, depending on convention) should then contain the camera position.

Thank you so much, that solved my problem!!

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002324
×