The ESProjection Class

We have seen each of these methods before, but here they are integrated into the full class.

 1 package com.vizit;
 2 
 3 import android.app.Activity;
 4 import android.os.Bundle;
 5 import android.content.Context;
 6 import android.opengl.GLSurfaceView;
 7 import android.view.MotionEvent;
 8 import android.graphics.PointF;
 9 import android.view.ViewGroup;
10 
11 public class ESProjection
12        extends Activity
13 {
14     private GLSurfaceView GLView;
15 
16     @Override
17     public void onCreate(Bundle savedInstanceState)
18     {
19         super.onCreate(savedInstanceState);
20 
21         // Create a GLSurfaceView instance and set it
22         // as the ContentView for this Activity.
23         GLView = new MyGLSurfaceView(this);
24         setContentView(GLView,
25                        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
26     }
27 
28     @Override
29     protected void onResume()
30     {
31         // Forward onResume to the GL surface view to restart rendering.
32         super.onResume();
33         GLView.onResume();
34     }
35 
36     @Override
37     protected void onPause()
38     {
39         // Forward onPause to the GL surface view to stop rendering.
40         super.onPause();
41         GLView.onPause();
42     }
43 
44     class MyGLSurfaceView extends GLSurfaceView
45     {
46         private final  TriangleRenderer renderer;
47         /** Location of the most recent touch */
48         private        PointF           touch    = new PointF();
49 
50         public MyGLSurfaceView(Context context)
51         {
52             super(context);
53             // We are using the OpenGL ES 2 API..
54             setEGLContextClientVersion(2);
55             renderer = new TriangleRenderer();
56             // Set the Renderer for drawing on the GLSurfaceView
57             setRenderer(renderer);
58             // Render the view only when there is a change in the drawing data
59             setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
60         }
61 
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         }
81     }
82 }

Notes