Estoy trabajando con Android y OpenGL ES 2.0 y estoy teniendo un problema que realmente no puedo formular en una pregunta sólida. En la imagen, http://i.imgur.com/XuCHF.png, básicamente tengo una forma para representar un barco en el medio y cuando se mueve hacia un lado se estira hacia el punto de fuga. Lo que quiero lograr es que la nave mantenga la mayor parte de su forma cuando se mueva. Creo que puede deberse a mis matrices, pero todos los recursos que he buscado parecen usar el mismo método.Cuestiones de la cámara OpenGL ES 2.0
//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);
Los shaders son muy básicas, así:
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);"
+ "}";
Cualquier pensamiento/penetración es muy apreciada.
Gracias.
¡Gracias por esto! Me he estado golpeando la cabeza tratando de descubrir cómo cambiar la perspectiva de una manera significativa, hasta que encontré esta respuesta. Me faltaba la lógica del campo de visión. Tuve un momento Eureka cuando vi tu respuesta. –