Jump to content
  • Advertisement
Sign in to follow this  
fervent

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

This topic is 4440 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 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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!