OpenGL ES在Android上的问题:投影矩阵中的物体位置有问题。

huangapple go评论75阅读模式
英文:

Opengl es on android problem with object opsition on projection matrix

问题

我正在尝试使用OpenGL ES 3来显示对象。一切都正常,直到我尝试设置相机视图。当我将我的vP矩阵与相机矩阵和投影矩阵相乘时,对象就会消失。

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,
    // 我的位置
    0f,
    0f,
    1f,
    // 我要看的位置
    0f,
    0f,
    -1f,
    // 头朝向的方向
    0f,
    1f,
    0f
);

Matrix.multiplyMM(
    vPMatrix,
    0,
    projectionMatrix,
    0,
    camera,
    0
);
英文:

I trying to display object with opengl es 3. Everything works till i trying to set camera view. When I multiply my vPMatrix with camera matrix and projection matrix object just disapears.

            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
            );

答案1

得分: 0

我通过以下方式将相机设置来修复了那个错误:

Matrix.setLookAtM(
                    camera
                    , 0
                    //我的位置
                    , 0f
                    , 0f
                    , 5f
                    //我在寻找什么
                    , 0f
                    , 0f
                    , 0f
                    //顶部在哪里
                    , 0f
                    , 1f
                    , 0f
            );

但我不明白为什么旧版本会有问题(我寻找的是 z 轴)。如果有人能解释给我听,麻烦请发布你的回答。

英文:

I fixed that bug by setting camera as below:

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

but i dont understand why old version was bad (what i looking for z). If enyone can explain me this then please post youre answer.

答案2

得分: 0

大多数情况下,几何图形会被视景体的近平面剪裁掉。注意,如果几何图形不在近平面和远平面之间,则会被剪裁掉。

OpenGL ES在Android上的问题:投影矩阵中的物体位置有问题。

在设置透视投影时,您指定了到近平面的距离为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);
英文:

Moste likely the geometry is clipped by the near plane of the Viewing frustum. Note, if the geometry is not between the near and far plane, the geoemtry is clipped.

OpenGL ES在Android上的问题:投影矩阵中的物体位置有问题。

You specified a distance to the near plane of 3 and a distance to the far plane of 7 when setting the perspective projection:

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

But the distance of the point of view to the the center fot the worlds is just 1:

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


You have 2 options. Either change the point of view:

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

Or change the near and far plane. For instance:

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

huangapple
  • 本文由 发表于 2020年9月24日 02:57:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/64034609.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定