use perspective matrix

This commit is contained in:
Josh Holtrop 2012-12-01 08:28:14 -05:00
parent 2ddae706eb
commit 1fc70c5266

View File

@ -21,6 +21,7 @@ import android.view.MotionEvent;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import android.opengl.GLUtils;
import java.lang.Math;
public class MyRenderer implements GLSurfaceView.Renderer
{
@ -36,6 +37,9 @@ public class MyRenderer implements GLSurfaceView.Renderer
private final int GRID_WIDTH = 16;
private final int GRID_HEIGHT = 9;
private float[][] m_tiles = new float[GRID_WIDTH][GRID_HEIGHT];
private float m_aspect = 1.0f;
private final float DISTANCE =
(float) (GRID_HEIGHT / 2.0 / Math.tan(Math.toRadians(30)));
public MyRenderer(AssetManager am, Resources resources)
{
@ -171,7 +175,8 @@ public class MyRenderer implements GLSurfaceView.Renderer
{
Matrix.setIdentityM(m_modelview, 0);
Matrix.translateM(m_modelview, 0,
x - GRID_WIDTH / 2.0f, y - GRID_HEIGHT / 2.0f, 0);
x - GRID_WIDTH / 2.0f, y - GRID_HEIGHT / 2.0f,
-DISTANCE);
GLES20.glUniformMatrix4fv(
GLES20.glGetUniformLocation(m_program, "modelview"),
1, false, m_modelview, 0);
@ -190,13 +195,11 @@ public class MyRenderer implements GLSurfaceView.Renderer
{
m_width = width;
m_height = height;
m_aspect = width / (float) height;
GLES20.glViewport(0, 0, width, height);
Matrix.orthoM(m_proj_matrix, 0,
-GRID_WIDTH / 2.0f, GRID_WIDTH / 2.0f,
-GRID_HEIGHT / 2.0f, GRID_HEIGHT / 2.0f,
1, -1);
Matrix.perspectiveM(m_proj_matrix, 0, 60.0f, 16.0f/9.0f, 0.1f, 10.0f);
GLES20.glUseProgram(m_program);