OpenGL ES 2.0相机问题

Mat*_*att 5 android opengl-es matrix opengl-es-2.0

我正在使用Android和OpenGL ES 2.0,我遇到了一个问题,我无法真正解决这个问题.在图像http://i.imgur.com/XuCHF.png中,我基本上有一个形状来代表中间的船只,当它移动到侧面时,它会向消失点伸展.我想要完成的是让船在移动时保持其大部分形状.我相信这可能是由于我的矩阵,但我看过的每一种资源似乎都使用相同的方法.

//Setting up the projection matrix
final float ratio = (float) width / height;
final float left = -ratio;
final float right = ratio;
final float bottom = -1.0f;
final float top = 1.0f;
final float near = 1.0f;
final float far = 1000.0f;
Matrix.frustumM(projection_matrix, 0, left, right, bottom, top, near, far);

//Setting the view matrix
Matrix.setLookAtM(view_matrix, 0, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f);

//Setting the model matrix
Matrix.setIdentityM(model_matrix, 0);
Matrix.translateM(model_matrix, 0, 2f, 0f, 0f);

//Setting the model-view-projection matrix
Matrix.multiplyMM(mvp_matrix, 0, view_matrix, 0, model_matrix, 0);
Matrix.multiplyMM(mvp_matrix, 0, GL.projection_matrix, 0, mvp_matrix, 0);
GLES20.glUniformMatrix4fv(mvp_matrix_location, 1, false, mvp_matrix, 0);
Run Code Online (Sandbox Code Playgroud)

着色器也是非常基本的:

private final static String vertex_shader = 
      "uniform mat4 u_mvp_matrix;"
    + "attribute vec4 a_position;"
    + "void main()"
    + "{"
    + "  gl_Position = u_mvp_matrix * a_position;"
    + "}";

private final static String fragment_shader = 
       "precision mediump float;"
     + "void main()"
     + "{"
     + "  gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);"
     + "}";
Run Code Online (Sandbox Code Playgroud)

非常感谢任何想法/见解.

谢谢.

Mār*_*iko 7

这是正常的 - 这就是透视投影的样子.虽然在你的情况下它看起来非常紧张 - 具有宽视野.

尝试使用而不是frustumM方法perspectiveM(projection_matrix,0,45.0f,ratio,near,far).或者,如果你必须使用frustumM,计算左/右/底部/顶部像这样:

float fov = 60; // degrees, try also 45, or different number if you like
top = tan(fov * PI / 360.0f) * near;
bottom = -top;
left = ratio * bottom;
right = ratio * top;
Run Code Online (Sandbox Code Playgroud)