Matrix and dirction ,position

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

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 on other sites
Hi,

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

kp

Share on other sites
Quote:
 Original post by kovacspHi,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 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.

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 18
• 12
• 12
• 11
• 9
• Forum Statistics

• Total Topics
634754
• Total Posts
3019147
×