This is the first method we see from MyGLSurfaceView. It tells the renderer how to move the second triangle in response to user gestures.
62 public boolean onTouchEvent (MotionEvent event) 63 { 64 65 switch (event.getAction()) 66 { 67 case MotionEvent.ACTION_MOVE: 68 renderer.motion(event.getX() - touch.x, touch.y - event.getY()); 69 touch.set(event.getX(), event.getY()); 70 requestRender(); 71 return true; 72 73 case MotionEvent.ACTION_DOWN: 74 touch.set(event.getX(), event.getY()); 75 return true; 76 77 default: 78 return super.onTouchEvent(event); 79 } 80 }
Remember that MyGLSurfaceView is a subclass of View so all we need to do to handle touch events is implement onTouchEvent.
As soon as the user touches the screen, we record the location. Then as their finger moves over the screen, the change in position of the finger is provided to the renderer, and the new position updated.
Returning true indicates that the event has been handled. For any touch event we don't handle, we invoke the superclass event handler.