使用 JOML 时对象旋转不稳

Object is rotating weidly when using JOML

我正在尝试使用 LWJGL3 创建 3D 引擎,但我一直遇到这个问题:

旋转对象时,它会执行以下操作:

四边形应该在中间,因为我没有更改 x 坐标,但事实并非如此。 我实际上尝试使用 LWJGL2 中的旧实用程序 jar 重做变换矩阵,四边形绕其轴旋转,而不是围绕中间的某种轨道。(顺便说一句,我使用的是最新版本的 JOML)

当我在 google 上搜索有关问题时,我:

  1. 什么都听不懂。
  2. 我理解的东西不起作用(比如更新 JOML)

下面是生成变换矩阵的代码:

public static Matrix4f createTransformationMatrix(Entity entity) {
        Matrix4f matrix = new Matrix4f()
        .identity()
        .translate(new Vector3f(entity.getX(), entity.getY(), entity.getZ()))
        .rotateX((float)Math.toRadians(entity.getRotationX()))
        .rotateY((float)Math.toRadians(entity.getRotationY()))
        .rotateZ((float)Math.toRadians(entity.getRotationZ()))
        .scale(entity.getScale());
        
        return matrix;
}

这是来自顶点着色器的代码:

#version 450

in vec3 position;
out vec4 out_color;

uniform mat4 projection;
uniform mat4 transformation;

void main()
{
    gl_Position =  projection * transformation * vec4(position, 1.0);
    out_color = vec4(position.y, position.x, -position.x, 0);
}

提前致谢!

我刚刚发现问题所在。

这是我的四边形坐标:

float[] vertices = {
        -0.5f, 0.5f, -1f,
        -0.5f, -0.5f, -1f,
        0.5f, -0.5f, -1f,
        0.5f, 0.5f, -1f
};

所以我将它们更改为:

float[] vertices = {
        -0.5f, 0.5f, 0f,
        -0.5f, -0.5f, 0f,
        0.5f, -0.5f, 0f,
        0.5f, 0.5f, 0f
};

它终于奏效了,但不知道为什么。