Skip to main content
GameDev.net gamedev.net
🔒 Locked

Camera position from D3DTS_VIEW matrix

Started by cronodragon Nov 10, 2006 at 11:18 AM 3 replies 5.8k views
Original Post
cronodragon
cronodragon
How can I get the position X,Y,Z of the camera if I have only the View matrix created with D3DXMatrixLookAtLH()?
S1CA
S1CA
Invert the matrix (so it changes from being a worldToView matrix and becomes a viewToWorld matrix) and read the translation part (_41, _42, _43).

Since view matrices are only made from rotations and translations, the matrix is orthogonal so you can avoid doing the full inverse:

D3DXVECTOR3 vPos;vPos.x = -matView._41;vPos.y = -matView._42;vPos.z = -matView._43;D3DXMatrixTranspose(&matView, &matView);D3DXVec3TransformNormal(&vPos, &vPos, &matView);


1. the transpose of the top-left-3x3 part of an orthogonal matrix is the same as the inverse of the top-left-3x3 part of the matrix.

2. D3DXVec3TransformNormal() transforms a vector by the top-left-3x3 part of a matrix (i.e. rotates but doesn't translate), so although our input vector isn't a normal, we can use this function to do what we want.

3. basically it's just what you do to invert the translation part of the matrix when you know the rotation part only does rotations.


BTW: is there any particular reason why you don't already have the position - surely your code set that matrix up somewhere.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
TheAdmiral
TheAdmiral
Quote:
Original post by S1CA
Since view matrices are only made from rotations and translations, the matrix is orthogonal so you can avoid doing the full inverse...

While the rest of your post shows that you clearly understand the subject matter, this statement isn't true. Translations aren't orthogonal. Not a single one of them [rolleyes] (the identity translation doesn't qualify). I'm sure you meant that the homogeneous part of them is orthogonal.

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
S1CA
S1CA
Quote:
Original post by TheAdmiral
I'm sure you meant that the homogeneous part of them is orthogonal.


Yep. That's what I get for posting with a hangover - forgetting part of a sentence and not proof-reading what I'd posted.

That should indeed read: "Since view matrices are only made from rotations and translations, the top-left-3x3 part of the matrix is orthogonal so you can avoid doing the full inverse on that part"
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
cronodragon
cronodragon
I decided to remember the position of the camera as adviced. Anyway, thanks for explaining how to get those values with the matrix. :D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.