#### Archived

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

# D3DXMatrixLookAtRH() how to extract the angle?

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

## Recommended Posts

Hi, look at this code:
D3DXMATRIX   matView;
D3DXMatrixLookAtRH( &matView, ....., ....., &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );

How can I extract the X,Y and Z angles from the ''matView'' matrix? thanx in advance
KaMiKaZe

##### Share on other sites
Try this:

D3DXVECTOR right = D3DXVECTOR(matView._11, matView._21, matView._31 ) ;
D3DXVECTOR up = D3DXVECTOR(matView._12, matView._21, matView._32 ) ;
D3DXVECTOR dir = D3DXVECTOR(matView._13, matView._23, matView._33 ) ;

D3DXVec3Normalize(right) ;
D3DXVec3Normalize(up) ;
D3DXVec3Normalize(dir) ;

float angle_x = acosf( D3DXVec3Dot( right, D3DXVECTOR(1,0,0) ) ) ;
float angle_y = acosf( D3DXVec3Dot( up, D3DXVECTOR(0,1,0) ) ) ;
float angle_z = acosf( D3DXVec3Dot( dir, D3DXVECTOR(0,0,1) ) ) ;

Hope this helps you.

-G.Z.-

##### Share on other sites
He may run into domain problems, maybe.

Gamedev for learning.
libGDN for putting it all together.
An opensource, cross platform, cross API game development library.

##### Share on other sites
shouldnt work. if its rotated to the left the result for x and z axis are correct, as soon as its rotated up or down too it wont. also normalizing them shouldnt be necessary (not at that point).

try to discard what you dont need and project the vector to the right plane. for example:

right = (matView._11, 0, matView._31)

THEN normalize it and do the dot product. though i cant tell you what happens when right is straight up and results in (0,0,0) (well, i can.. normalizing will divide by zero *g*).

also your view matrix is already inverted, so you might have to transpose the rotation part first (i think gzito already did that).

but because of those problems i would avoid trying to get angles out of it unless theres really no other way (and if so, dont forget that it wont work if an axis is coming close to the wrong axis in world space (like x and z to y).

##### Share on other sites
Ok guys, sorry, just a fast (and probably not much accurate) answer.

Anyway, in my 3D engine implementation I save camera orientation vectors and keep them updated whenever I apply a transformation, so I''m able to know euler angles without any recomputation.

So, Kamikaze15, keep it in mind.

-G.Z.-

##### Share on other sites
Thanx guys I''m going to try that as soon as I can

quote:
Original post by gzito
Ok guys, sorry, just a fast (and probably not much accurate) answer.

Anyway, in my 3D engine implementation I save camera orientation vectors and keep them updated whenever I apply a transformation, so I''m able to know euler angles without any recomputation.

So, Kamikaze15, keep it in mind.

-G.Z.-

I keep my angles saved too but now I''m implementing a ''LookAt()'' function to my
camera class. I tried trigonometry but that gave me strange results in certain
situations, but thanx for trying to help

KaMiKaZe

1. 1
Rutin
36
2. 2
3. 3
4. 4
5. 5

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

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

There are no registered users currently online

×