Switching to a Projection Matrix

We’ll now switch to using the perspective projection matrix. Open up AirHockeyRenderer and remove all of the code from onSurfaceChanged, except for the call to glViewport. Add the following code:

AirHockey3D/src/com/airhockey/android/AirHockeyRenderer.java
 
MatrixHelper.perspectiveM(projectionMatrix, 45, (​float​) width
 
/ (​float​) height, 1f, 10f);

This will create a perspective projection with a field of vision of 45 degrees. The frustum will begin at a z of -1 and will end at a z of -10.

After adding the import for MatrixHelper, go ahead and run the program. You’ll probably notice that our air hockey table has disappeared! Since we didn’t specify a z position for our table, it’s located at a z of 0 by default. ...

Get OpenGL ES 2 for Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.