Archived

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

Matrix question

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

how do you extract the angles of rotation from a D3DXMATRIX? i have a view matrix which is rotated and translated correctly, but another part of my program needs the rotation, and only the rotation, so how can i extract just that info? thanks for any help.

Share this post


Link to post
Share on other sites
1) extract the 3 vectors in the top left 3x3 part of the matrix.

2) call those right, up and forward (you'll probably see those same ones being set in your camera creation code).

3) use atan2() to get the angle between each of those and the axis you're interested in.


Though of course it's pretty unlikely you'll actually _need_ the angle for anything - most things you can do with the vectors and matrices. The main things I find explicitly using angles useful for these days are user input and visualisation.


BTW: if all you're needing to do is make the matrix into a rotation only matrix, then just set the translation part to 0 and that'll do the trick.

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - S1CA on March 4, 2003 12:15:19 PM]

Share this post


Link to post
Share on other sites
thanks so much for your help, actually i''m trying to implement billboarding by rotating the image by the opposite of the view matrix, i tried using transpose, but it would distort the image a whole lot so i think i''m just gonna keep things simple,

by the way, after a matrix has been translated, can you remove that translation without knowing what the translation was???

thank you

Share this post


Link to post
Share on other sites
quote:
Original post by TheLameDuck
thanks so much for your help, actually i''m trying to implement billboarding by rotating the image by the opposite of the view matrix, i tried using transpose, but it would distort the image a whole lot so i think i''m just gonna keep things simple,




Something you should definately do:

1) extract the vectors I talked about above from the camera matrix.


2) Every frame, draw each of those vectors as lines in world space (identity for the world transform), put the start point of the line at the centre of the screen and the end point along the vector, e.g.:

const float length = 5.0f; // or whatever makes sense to your world scale
start.x = 0.0f;
start.y = 0.0f;
start.z = 0.0f;
end.x = right.x * length;
end.y = right.y * length;
end.z = right.z * length;
draw_line( start, end, RED );

start.x = 0.0f;
start.y = 0.0f;
start.z = 0.0f;
end.x = up.x * length;
end.y = up.y * length;
end.z = up.z * length;
draw_line( start, end, GREEN );

start.x = 0.0f;
start.y = 0.0f;
start.z = 0.0f;
end.x = forward.x * length;
end.y = forward.y * length;
end.z = forward.z * length;
draw_line( start, end, BLUE );


3) Move your camera about, rotate it, roll it etc


4) Hopefully you should have a "Eureka!" moment with what you see (the up and right vectors won''t move, they''ll always remain aligned to the screen). You can use that knowledge to do billboards which don''t require any angles or expensive trig operations!


quote:
by the way, after a matrix has been translated, can you remove that translation without knowing what the translation was???


Yes, usually. But it depends if the translation was applied before or after other operations where the translation may have affected them.

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites