视图和投影矩阵不起作用

问题描述 投票:0回答:1

我正在尝试将MVP矩阵实施到我的引擎中。我的模型矩阵工作正常,但我的视图和投影矩阵不起作用。这是两者的创建:

    public void calculateProjectionMatrix() {
        final float aspect = Display.getDisplayWidth() / Display.getDisplayHeight();
        final float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspect);
        final float x_scale = y_scale / aspect;
        final float frustum_length = FAR_PLANE - NEAR_PLANE;

        proj.identity();
        proj._m00(x_scale);
        proj._m11(y_scale);
        proj._m22(-((FAR_PLANE + NEAR_PLANE) / frustum_length));
        proj._m23(-1);
        proj._m32(-((2 * NEAR_PLANE * FAR_PLANE) / frustum_length));
        proj._m33(0);
    }

    public void calculateViewMatrix() {
        view.identity();
        view.rotate((float) Math.toRadians(rot.x), Mathf.xRot);
        view.rotate((float) Math.toRadians(rot.y), Mathf.yRot);
        view.rotate((float) Math.toRadians(rot.z), Mathf.zRot);
        view.translate(new Vector3f(pos).mul(-1));
        System.out.println(view);
    }

我要渲染的顶点是:-0.5f,0.5f,-1.0f,-0.5f,-0.5f,-1.0f,0.5f,-0.5f,-1.0f,0.5f,0.5f,-1.0f

我在上传到着色器之前测试了视图矩阵,它是正确的。

这是我的渲染方式:

    ss.bind();
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glEnableVertexAttribArray(2);
    ss.loadViewProjection(cam);
    ss.loadModelMatrix(Mathf.transformation(new Vector3f(0, 0, 0), new Vector3f(), new Vector3f(1)));
    ss.connectTextureUnits();
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);
    glDisableVertexAttribArray(2);
    ss.unbind();
java opengl
1个回答
0
投票

几何必须放置在Viewing frustum中。视锥台之外的所有几何均被裁剪为不可见。几何形状必须位于NEAR_PLANEFAR_PLANE之间。注意,在透视投影时,NEAR_PLANEFAR_PLANE必须大于0:

0 < NEAR_PLANE < FAR_PLANE 

注意,在视图空间中,z轴指向视口之外。可以通过以下方式定义查看对象的初始视图矩阵:

pos = new Vector3f(0, 0, (NEAR_PLANE + FAR_PLANE)/2f );
rot = new Vector3f(0, 0, 0);
© www.soinside.com 2019 - 2024. All rights reserved.