Creating a Projection Matrix in Our Code

We’re now ready to add a perspective projection to our code. Android’s Matrix class contains two methods for this, frustumM and perspectiveM. Unfortunately, frustumM has a bug that affects some types of projections,[32] and perspectiveM was only introduced in Android Ice Cream Sandwich and is not available on earlier versions of Android. We could simply target Ice Cream Sandwich and above, but then we’d be leaving out a large part of the market that still runs earlier versions of Android.

Instead, we can create our own method to implement the matrix as defined in the previous section. Open up the project we created back at the beginning of this chapter and add a new class called MatrixHelper to the package ...

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.