OpenGL ES在Android上,投影矩阵下物体位置问题。

3

我试着使用OpenGL ES 3来显示一个物体,所有的东西都可以正常工作直到我设置相机视角。当我将我的vPMatrix与相机矩阵和投影矩阵相乘后,物体就会消失。

            float[] projectionMatrix = new float[16];
            float[] vPMatrix = new float[16];
            float[] camera = new float[16];
            Matrix.frustumM(
                    projectionMatrix,
                    0,
                    -1,
                    1,
                    -1,
                    1,
                    3,
                    7
            );

            Matrix.setLookAtM(
                    camera
                    , 0
                    //where i am
                    , 0f
                    , 0f
                    , 1f
                    //what i looking for
                    , 0f
                    , 0f
                    , -1f
                    //where is top
                    , 0f
                    , 1f
                    , 0f
            );


            Matrix.multiplyMM(
                    vPMatrix,
                    0,
                    projectionMatrix,
                    0,
                    camera,
                    0
            );
2个回答

0

我通过以下设置相机来修复了那个 bug:

Matrix.setLookAtM(
                    camera
                    , 0
                    //where i am
                    , 0f
                    , 0f
                    , 5f
                    //what i looking for
                    , 0f
                    , 0f
                    , 0f
                    //where is top
                    , 0f
                    , 1f
                    , 0f
            );

但我不明白为什么旧版本不好(我在寻找的是z)。如果有人能解释给我听,那么请发表你的答案。


0

很可能几何图形被视锥体的近平面剪裁了。请注意,如果几何图形不在近平面和远平面之间,则几何图形将被剪裁。

在设置透视投影时,您指定了近平面距离为3,远平面距离为7:

Matrix.frustumM(projectionMatrix, 0, -1, 1, -1, 1, 3, 7);

但是观察点到世界中心的距离只有1:

Matrix.setLookAtM(camera, 0, 0f, 0f, 1f, ...);

你有两个选择。要么改变观点:

Matrix.setLookAtM(camera, 0, 0f, 0f, 5f, ...);

或者改变近平面和远平面。例如:

Matrix.frustumM(projectionMatrix, 0, -1, 1, -1, 1, 0.1, 100);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接