adjust tap position for aspect ratio

This commit is contained in:
Josh Holtrop 2012-11-15 22:43:01 -05:00
parent 76fd3ad35d
commit d34c51acf9

View File

@ -28,6 +28,7 @@ public class MyRenderer implements GLSurfaceView.Renderer
private float m_modelview[] = new float[16];
private int m_width;
private int m_height;
private float m_aspect = 1.0f;
private float m_x = 0.0f;
private float m_y = 0.0f;
@ -154,20 +155,13 @@ public class MyRenderer implements GLSurfaceView.Renderer
{
m_width = width;
m_height = height;
m_aspect = width / (float) height;
GLES20.glViewport(0, 0, width, height);
if (width < height)
{
Matrix.orthoM(m_proj_matrix, 0, -1, 1,
-height / (float) width, height / (float) width, 1, -1);
}
else
{
Matrix.orthoM(m_proj_matrix, 0,
-width / (float) height, width / (float) height,
-1, 1, 1, -1);
}
Matrix.orthoM(m_proj_matrix, 0,
-m_aspect, m_aspect,
-1, 1, 1, -1);
GLES20.glUseProgram(m_program);
@ -180,7 +174,7 @@ public class MyRenderer implements GLSurfaceView.Renderer
{
if (e.getAction() == MotionEvent.ACTION_DOWN)
{
float x = (e.getX() / (float) m_width) * 2.0f - 1.0f;
float x = m_aspect * ((e.getX() / (float) m_width) * 2.0f - 1.0f);
float y = -((e.getY() / (float) m_height) * 2.0f - 1.0f);
m_x = x;