O'Reilly logo

OpenGL ES 2 for Android by Kevin Brothaler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required