• Advertisement
Sign in to follow this  

Matrix and dirction ,position

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

If a object in 3d space rotate it and move it somewhere now given a matrix that do the same thing,can I work out the rotating angle and translation? If impossible, can I woke out the 3 direction of object?

Share this post


Link to post
Share on other sites
Advertisement
Hi,

use D3DXMatrixDecompose() to get the rotation, scaling and translation from a matrix.

kp

Share this post


Link to post
Share on other sites
Quote:
Original post by kovacsp
Hi,

use D3DXMatrixDecompose() to get the rotation, scaling and translation from a matrix.

kp


I WANT to get 3 direction of a object . that just get a rotation quaternion.

Share this post


Link to post
Share on other sites
I think you want .. Euler Angles. I.e. the "3 direction" of the object.

Getting the Euler angles out of a matrix is a little tricky, and it depends on the rotation order that was used to create the matrix. If you used YXZ order (for example, a matrix created with D3DXMatrixRotationYawPitchRoll), you can use the following code to extract the three angles:

void matToEulerAngles(D3DXMATRIX& mat, float& x, float& y, float& z)
{
if(mat.m[2][1] > 1)
mat.m[2][1] = 1;
if(mat.m[2][1] < -1)
mat.m[2][1] = -1;
x = asin(mat.m[2][1]);
const double epsilon = 0.01;
if(x + epsilon < (3.1415926535 / 2))
{
if(x - epsilon > (-3.1415926535 / 2))
{
z = atan2(-mat.m[0][1], mat.m[1][1]);
y = atan2(-mat.m[2][0], mat.m[2][2]);
}
else
{
z = -atan2(mat.m[0][2], mat.m[0][0]);
y = 0;
}
}
else
{
z = atan2(mat.m[0][2], mat.m[0][0]);
y = 0;
}
}


If you call the function like so:

float xang, yang, zang;
matToEulerAngles(someMatrix, xang, yang, zang);



xang, yang, and zang will contain the Euler angles in radians.

If you're not using YXZ rotation order, this will give you bogus answers. The formula needs to be changed if you use a different order.

Share this post


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

  • Advertisement