diff --git a/src/com/homelinux/holtrop/opengltest/MyRenderer.java b/src/com/homelinux/holtrop/opengltest/MyRenderer.java index b5e89e0..09aa6c8 100644 --- a/src/com/homelinux/holtrop/opengltest/MyRenderer.java +++ b/src/com/homelinux/holtrop/opengltest/MyRenderer.java @@ -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;