title: Android opengl moving an object Ontouch
body: <p>firstly I'm really new to opengl on androidand I'm still looking though courses online</p>
  
  <p>I'm trying to make a simply appthat has a sequre in the middle of the screen
  and on touch it's moves to the touch event coordinate
  this is my sureface view</p>
  
  <pre><code>public class MyGLSurfaceView extends GLSurfaceView {
  
  private final MyGLRenderer mRenderer;
  
  public MyGLSurfaceView(Context context) {
      super(context);
  
      // Set the Renderer for drawing on the GLSurfaceView
      mRenderer = new MyGLRenderer();
      setRenderer(mRenderer);
  
      // Render the view only when there is a change in the drawing data
      setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
  }
  
  
  @Override
  public boolean onTouchEvent(MotionEvent e)
  {
      float x =e.getX();
      float y =e.getY();
  
      if(e.getAction()==MotionEvent.ACTION_MOVE)
      {
          mRenderer.setLoc(x,y);
          requestRender();
      }
      return true;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and this is me renderer class</p>
  
  <pre><code>public class MyGLRenderer implements GLSurfaceView.Renderer {
  
  private float mAngle;
  
  public PVector pos;
  public Rectangle r;
  public Square sq;
  
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
      // Set the background frame color
      gl.glClearColor(1f, 1f, 1f, 1.0f);
  
      pos=new PVector();
      r=new Rectangle(0.5f,0.4f);
      sq=new Square(0.3f);
  }
  
  @Override
  public void onDrawFrame(GL10 gl) {
  
      // Draw background color
      gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  
      // Set GL_MODELVIEW transformation mode
      gl.glMatrixMode(GL10.GL_MODELVIEW);
      gl.glLoadIdentity();   // reset the matrix to its default state
  
      // When using GL_MODELVIEW, you must set the view point
      GLU.gluLookAt(gl, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
  
      gl.glTranslatef(pos.x,pos.y,0f);
  
      //r.draw(gl);
      sq.draw(gl);
  
  }//rend
  
  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
      // Adjust the viewport based on geometry changes
      // such as screen rotations
      gl.glViewport(0, 0, width, height);
  
      // make adjustments for screen ratio
      float ratio = (float) width / height;
      gl.glMatrixMode(GL10.GL_PROJECTION);        // set matrix to projection mode
      gl.glLoadIdentity();                        // reset the matrix to its default state
      gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);  // apply the projection matrix
  }
  
  /**
   * Returns the rotation angle of the triangle shape (mTriangle).
   *
   * @return - A float representing the rotation angle.
   */
  public float getAngle() {
      return mAngle;
  }
  
  /**
   * Sets the rotation angle of the triangle shape (mTriangle).
   */
  public void setAngle(float angle) {
      mAngle = angle;
  }
  
  public void setLoc(float x,float y)
  {
      pos.x=x; pos.y=y;
  }
  </code></pre>
  
  <p>}</p>