我从一些软件中得到一个变换矩阵,我必须提取轴旋转。我不确定确切的名称,但我想要有与Matrix4d.rotX(a)相反的功能。从矩阵4d提取旋转
比方说,我有这样的代码:
Matrix4d matrix = new Matrix4d();
matrix.setIdentity();
Matrix4d m = new Matrix4d();
m.rotX(a);
matrix.mul(m);
m.rotY(b);
matrix.mul(m);
m.rotZ(c);
matrix.mul(m);
我希望能够得到的值,b和c的矩阵。会有人有想法吗?我在3D中几乎没有任何经验,我查看了java vecmath包,但找不到任何东西。
我试着用下面的:
public static float[] getRotation(Matrix4f matrix) {
float Yaw;
float Pitch;
float Roll;
if (Math.abs(matrix.m00 + 1.0f) < 0.01f)
{
Yaw = (float) Math.atan2(matrix.m02, matrix.m23);
Pitch = 0;
Roll = 0;
}else if (Math.abs(matrix.m00 -1.0f) < 0.01f)
{
Yaw = (float) Math.atan2(matrix.m02, matrix.m23);
Pitch = 0;
Roll = 0;
}else
{
Yaw = (float) Math.atan2(-matrix.m20,matrix.m00);
Pitch = (float) Math.asin(matrix.m10);
Roll = (float) Math.atan2(-matrix.m12,matrix.m11);
}
return new float[] { Yaw, Pitch, Roll};
}
和
public static float[] GetRotation(Matrix4f matrix) {
float Yaw;
float Pitch;
float Roll;
if (matrix.m00 == 1.0f)
{
Yaw = (float) Math.atan2(matrix.m20, matrix.m32);
Pitch = 0;
Roll = 0;
}else if (matrix.m00 == -1.0f)
{
Yaw = (float) Math.atan2(matrix.m20, matrix.m32);
Pitch = 0;
Roll = 0;
}else
{
Yaw = (float) Math.atan2(-matrix.m02,matrix.m00);
Pitch = (float) Math.asin(matrix.m01);
Roll = (float) Math.atan2(-matrix.m21,matrix.m11);
}
return new float[] { Yaw, Pitch, Roll};
}
但价值是错误的
相关:http://gamedev.st ackexchange.com/questions/50963/how-to-extract-euler-angles-from-transformation-matrix –
我已经尝试过,但无法让它工作。 – kelto
你还没有分享你的代码,所以我不能提供任何提示错误的地方。 –