Lwjgl 旋转不起作用

Lwjgl rotation not work

我有一个可以在所有轴上旋转的对象,我的问题是如果你在 y 轴上旋转对象(例如 90°),z 轴上的旋转是不正确的,因为它在 x 轴上旋转,相反,x 轴上的旋转继续完美运行,如果 y 轴设置为 0°,则 z 轴的旋转 returns 可以正常运行。

我使用此代码旋转和平移对象:

public static Matrix4f createTransformationMatrix(Vector3f translation , float rx, float ry, float rz , float scale){
    Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation,matrix,matrix);
    Matrix4f.rotate((float) Math.toRadians(rx),new Vector3f(1, 0, 0) , matrix,matrix);
    Matrix4f.rotate((float) Math.toRadians(ry),new Vector3f(0, 1, 0) , matrix,matrix);
    Matrix4f.rotate((float) Math.toRadians(rz),new Vector3f(0, 0, 1) , matrix,matrix);
    Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix);
    return matrix;}

这是欧拉角旋转的内在奇点,称为万向节锁。使用 四元数 代替旋转(可以指定任意轴)。