lwjgl 的实体坐标问题

trouble with entity coordinates with lwjgl

我在 OpenGL 上下文中移动实体时遇到问题: 当我尝试放置一个实体时,位置似乎是正确的,但是当实体开始移动时,一切都出错了,碰撞也不起作用。我是 OpenGL 的新手,我怀疑我的世界矩阵或模型矩阵有误。

这是顶点着色器的代码:

#version 330 core

layout (location=0) in vec3 position;

out vec3 extColor;

uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform vec3 inColor;
void main()
{
    gl_Position = projectionMatrix * modelMatrix  * vec4(position, 1.0);
    extColor = inColor;
}

这是计算大部分矩阵的class:

public class Transformations {
    private Matrix4f projectionMatrix;
    private  Matrix4f modelMatrix;

    public Transformations() {
        projectionMatrix = new Matrix4f();
        modelMatrix = new Matrix4f();
    }

    public final Matrix4f getOrthoMatrix(float width, float height, float zNear, float zFar) {
        projectionMatrix.identity();
        projectionMatrix.ortho(0.0f, width, 0.0f, height, zNear, zFar);
        return projectionMatrix;
    }

    public Matrix4f getModelMatrix(Vector3f offset, float angleZ, float scale) {
        modelMatrix.identity().translation(offset).rotate(angleZ, 0, 0, 0).scale(scale);
        return modelMatrix;
    }
}

这是碰撞测试:

 public boolean isIn(Pos p) {
        return (p.getX() >= this.pos.getX() &&
                p.getX() <= this.pos.getX() + DIMENSION)
                && (p.getY() >= this.pos.getY() &&
                p.getY() <= this.pos.getY() + DIMENSION);
}

另外,github 项目有一个 link:https://github.com/ShiroUsagi-san/opengl-engine

我是 OpenGL 3 的新手,所以我可能会犯一些非常大的错误。

我也是运行作为WM的i3,我真的不知道这是否会导致这种问题。

我在思考 openGL 和 VBO 的工作原理后解决了这些问题:事实上,我正在为每个实体设置一个新的引用,所以我不得不更改行

Mesh fourmiMesh = MeshBuilder.buildRect(this.position.getX(), this.position.getY(), 10, 10);

Mesh fourmiMesh = MeshBuilder.buildRect(0, 0, 10, 10);

我混淆了 VBO 中的顶点位置和我的世界中的位置。 希望被误解的能帮助大家理解。