2 Applied Research Associates Inc. (c)2011
\r
4 Redistribution and use in source and binary forms,
\r
5 with or without modification, are permitted provided that the
\r
6 following conditions are met:
\r
7 * Redistributions of source code must retain the above copyright
\r
8 notice, this list of conditions and the following disclaimer.
\r
9 * Redistributions in binary form must reproduce the above copyright
\r
10 notice, this list of conditions and the following disclaimer in the
\r
11 documentation and/or other materials provided with the distribution.
\r
12 * Neither the name of the Applied Research Associates Inc nor the names
\r
13 of its contributors may be used to endorse or promote products derived
\r
14 from this software without specific prior written permission.
\r
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
\r
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
\r
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
\r
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
\r
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
\r
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
\r
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
26 POSSIBILITY OF SUCH DAMAGE.
\r
29 package pfx.renderingsupport;
\r
31 import android.opengl.GLSurfaceView;
\r
32 import android.content.Context;
\r
33 import android.view.MotionEvent;
\r
36 * Implementation of the OpenGL ES view window and creates/assigns a renderer.
\r
37 * Handles touch events to allow the user to change scene on tap, move the camera
\r
38 * around by touch based movement, and allows the user to zoom in and out by pinching.
\r
42 public class PhysicsEffectsGLSurfaceView extends GLSurfaceView {
\r
43 public PhysicsEffectsGLSurfaceView(Context context) {
\r
45 peRenderer = new PhysicsEffectsRenderer();
\r
46 setRenderer(peRenderer);
\r
49 float x1 = 0, x2, y1 = 0, y2;
\r
53 * Function to process touch events for camera and scene control
\r
56 public boolean onTouchEvent(final MotionEvent event) {
\r
57 switch(event.getAction()) {
\r
58 case(MotionEvent.ACTION_DOWN):
\r
61 downTime = event.getDownTime();
\r
63 case(MotionEvent.ACTION_UP):
\r
64 if(event.getEventTime() - downTime < 100) nativeSceneChange();
\r
66 case(MotionEvent.ACTION_MOVE): {
\r
67 if(event.getPointerCount() == 1){
\r
73 // Use dx and dy to determine the direction
\r
77 nativeCameraRight();
\r
86 } else if(event.getPointerCount() == 2){
\r
91 // Use dy to determine zoom
\r
93 nativeCameraZoomIn();
\r
95 nativeCameraZoomOut();
\r
104 PhysicsEffectsRenderer peRenderer;
\r
106 private static native void nativeCameraUp();
\r
107 private static native void nativeCameraDown();
\r
108 private static native void nativeCameraLeft();
\r
109 private static native void nativeCameraRight();
\r
110 private static native void nativeCameraZoomOut();
\r
111 private static native void nativeCameraZoomIn();
\r
112 private static native void nativeSceneChange();
\r