旋转部分比您所拥有的要复杂一些。
R = yawMat.pitchMat.rollMat
where:
yawMat={ { cosZ, -sinZ, 0 }, { sinZ, cosZ , 0 }, {0,0,1 } };
pitchMat = { { cosY , 0 , sinY }, { 0, 1 , 0 }, { -sinY, 0, cosY } };
rollMat = { {1,0,0 }, {0,cosX,-sinX }, {0,sinX,cosX } };
三者的点积构成了齐次变换内的 3x3 旋转矩阵 R。点积的顺序很重要,因此请保持一致。
Here http://planning.cs.uiuc.edu/ch3.pdf是我的参考。
最终的 4x4 矩阵应该是这样的
T = {{R00,R01,R02,X},{R10,R11,R12,Y},{R20,R21,R22,Z},{0,0,0,1}}
Edit如果您想一次进行一次旋转,那么其他两个 3x3 矩阵将进入恒等式,因此您将只需要偏航旋转:
R = yawMat.I.I = yawMat
So:
R = { { cosZ, -sinZ, 0 }, { sinZ, cosZ , 0 }, {0,0,1 } }
对于其他人来说也是如此。
正如您为了构建转换矩阵而编写的那样,它应该是:
Vector3f xAxis = new Vector3f(
cosYaw*cosPitch,
cosYaw* sinPitch*sinRoll - sinYaw*cosRoll,
cosYaw*sinPitch*cosRoll + sinYaw*sinRoll
);
Vector3f yAxis = new Vector3f(
sinYaw*cosPitch,
sinYaw*sinPitch*sinRoll + cosYaw*cosRoll,
sinYaw*sinPitch*cosRoll - cosYaw*sinRoll
);
Vector3f zAxis = new Vector3f(
-sinPitch,
cosPitch*sinRoll,
cosPitch * cosYaw
);
假设固定旋转顺序 x -> y -> z 后跟平移 X,Y,Z