我正在与Android和OpenGL ES 2.0的,我有我真的不能配制成固体问题的问题。在图像中, https://m.xsw88.com/allimgs/daicuo/20230906/2474.png ,我基本上形状重新present船舶在中间,当它移到一边它被伸向消失点。我所希望做到的是让船保持其大部分的形状时,很是感动。我相信这可能是由于我的基质,但每一种资源,我看着好像用同样的方法。
I'm working with Android and OpenGL ES 2.0 and I am having an issue that I can't really formulate into a solid question. In the image, https://m.xsw88.com/allimgs/daicuo/20230906/2474.png, I basically have a shape to represent a ship in the middle and when it's moved to the side it gets stretched toward the vanishing point. What I am wanting to accomplish is to have the ship maintain most of its shape when it is moved. I believe it may be due to my matrices but every resource I've looked seems to use the same method.
//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);
的着色器是非常基本的,以及:
The shaders are very basic as well:
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);"
+ "}";
有什么想法/观点是大大AP preciated。
Any thoughts/insight is greatly appreciated.
感谢。
这是正常的 - 这是透视投影应该是什么样子。 Altough在你的情况下,它看起来非常伸一 - 与宽视场
That is normal - that is how perspective projection should look like. Altough in your case it looks really stretched one - with wide field of view.
尝试使用,而不是frustmM方法perpectiveM(projection_matrix,0,45.0f,比例,近,远)。 或者,如果你必须使用frustmM,计算这样的左/右击/底/顶部:
Try using instead of frustmM method perpectiveM(projection_matrix, 0, 45.0f, ratio, near, far). Or if you must use frustmM, calculate left/righ/bottom/top like this:
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;