Adding an Object Builder

Now we can start writing our object builder class. Let’s create a class in the package com.airhockey.android.objects called ObjectBuilder. Start out with the following code inside the class:

AirHockeyWithImprovedMallets/src/com/airhockey/android/objects/ObjectBuilder.java
 
private​ ​static​ ​final​ ​int​ FLOATS_PER_VERTEX = 3;
 
private​ ​final​ ​float​​[]​ vertexData;
 
private​ ​int​ offset = 0;
 
 
private​ ObjectBuilder(​int​ sizeInVertices) {
 
vertexData = ​new​ ​float​[sizeInVertices * FLOATS_PER_VERTEX];
 
}

There’s nothing too fancy here so far. We’ve defined a constant to represent how many floats we need for a vertex, an array to hold these vertices, and a variable to keep track of the position in the array ...

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.