Jump to content
  • Advertisement

Archived

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

Teric

I need the XYZ position of the camera

This topic is 5402 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

Ok this seems really weird to me. I''m working in DirectX 9, and I''m trying to determine the XYZ coordinates of the camera. I thought that if I used device->GetTransform(D3DTS_VIEW, &matView) I could get it. But when I extract the _41, _42, and _43 members of the view matrix, it''s not coming out right. I initially set up the View Matrix with the camera at 2.0, 3.0, -15.0, and I have it looking at 1,1,1. I''m using a left-handed view matrix. Later in the program (haven''t moved the camera at all), when I grab the view matrix, the _41 comes out to be 0.79, the _42 is -1.13, and the _43 is 15.36. It seems that with the view matrix I can''t simply extract the _41, _42, and _43 to get the camera''s exact XYZ position. Is there a better way to do this? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Look at the docs for D3DXMatrixLookAtLH(). It tells you how the view matrix is built from that function. It looks like a bear to extract though.



I like pie.

Share this post


Link to post
Share on other sites
Just do it:

device->GetTransform(D3DTS_VIEW, &matView);
D3DXMatrixInverse(&matView, NULL, &matView);

D3DXVECTOR3 v3CamPos(matView._41, matView._42, matView._43);

As you see, the matrix must be inverted to transform view space to world space.

Share this post


Link to post
Share on other sites
quote:
Original post by Teric
I initially set up the View Matrix with the camera at 2.0, 3.0, -15.0, and I have it looking at 1,1,1. I''m using a left-handed view matrix. Later in the program (haven''t moved the camera at all), when I grab the view matrix, the _41 comes out to be 0.79, the _42 is -1.13, and the _43 is 15.36.


If you''ve already set up the view matrix with the camera position at some specific value, why do you need to get this value again from the view matrix? Your app should have some kind of variable somewhere that keeps track of the cameras'' position.

neneboricua

Share this post


Link to post
Share on other sites
Ah--didn''t know that I need to invert the matrix to transpose it back to world space. I''ll try that, thanks!

Share this post


Link to post
Share on other sites
That was it! All I had to do was invert the View Matrix and the XYZ coords popped right out. Thanks!

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!