# Pulling camera position vector out of device.Transform.View matrix

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

## Recommended Posts

Hi, I need to get the position vector of the camera, and since I'm already passing the device around from class to class, I'd like to pull the camera's position vector out of device.Transform.View as opposed to keeping a seperate camera class around. I'm setting my View matrix as follows: device.Transform.View = Matrix.LookAtLH(new Vector3(0.0f, 3.0f, -90.0f), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); and I need something like: Vector3 cameraPos = getCameraPosFromViewMatrix(device.Transform.View); (which in this case would result in cameraPos having a value of {0.0, 3.0, -90.0} ) Any thoughts on the best way to do this? Thanks, Dave

##### Share on other sites
It's right in the matrix, you should write a quick function to output the matrix elements and you'll be able to see how it's stored.

##### Share on other sites
At the risk of being dense, it's not.

A simple tostring operation on the matrix leads to the following output:
Determinant: 0.9999999
M11: -0.8137335
M12: -0.3325133
M13: -0.4767313
M14: 0
M21: 0
M22: 0.8201995
M23: -0.5720775
M24: 0
M31: 0.5812382
M32: -0.4655186
M33: -0.6674238
M34: 0
M41: 0
M42: 0
M43: 10.48809
M44: 1

There seems to be several calculations involved with LookAtLH, calculations which I do not know how to invert...

##### Share on other sites
D3DXMATRIXA16 m;
D3DXMatrixInverse( &m, NULL, &matView ); (matView = your view matrix)

D3DXVECTOR3 camPos;
camPos.x = m._41;
camPos.y = m._42;
camPos.z = m._43;

Try something like that.

##### Share on other sites
Perfect! Thanks :)

1. 1
Rutin
35
2. 2
3. 3
4. 4
5. 5

• 12
• 14
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633343
• Total Posts
3011431
• ### Who's Online (See full list)

There are no registered users currently online

×