Game Development Reference
In-Depth Information
For a pinch gesture, you must check whether you are pinching inward or outward. When the
deltas are DX1 > 0 && DX2 < 0 , you have an inward pinch or zoom in; otherwise, it's a zoom
out. In either case, you modify the width and height of the display by an arbitrary factor and
invoke the view's setVideoSize(width, height) method. This method invokes the
C++ Init(w,h) subroutine.
// Pinch inwards: zoom in
if (DX1 > 0 && DX2 < 0) {
width *= 0.6;
height *= 0.8;
view.setVideoSize(width, height);
} else {
// Pinch outwards: zoom out
width *= 1.4;
height *= 1.2;
view.setVideoSize(width, height);
}
Now let's compile and run the project in the device.
Compiling and Running
To compile the native library, start the Cygwin console in Windows, change to the project
folder ch04.OpenGL2Shaders , and use the Android compilation script.
$ ndk-build
The compilation script Android.mk is very simple, as shown in the following fragment.
It defines a module called libicosahedron that is bound to the libraries—log (for text
logging) and GLESv2 for OpenGL ES 3.1. When compilation completes, the shared library
libicosahedron.so will be created in the libs/armeabi folder of your project.
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libicosahedron
LOCAL_CFLAGS := -Werror
LOCAL_SRC_FILES := ico.cpp
LOCAL_LDLIBS := -llog -lGLESv2
include $(BUILD_SHARED_LIBRARY)
The library can now be loaded within Java with the system call of System.
loadLibrary( " icosahedron " ) .
You're done! Connect the device to your computer, create a run configuration for the project,
and launch it in your device. The result is shown in Figure 4-6 . Try swiping a finger to the left
or right to change the rotation speed or pinching to zoom in/out—and have some fun with
OpenGL 3.0/3.1.
 
Search WWH ::




Custom Search