Game Development Reference
In-Depth Information
of the tests to the manifest in the form of
<activity>
elements again. All our tests will be run in
fixed landscape orientation, which we will specify per
<activity>
element.
Each of the tests is an instance of the
GLGame
abstract class, and the actual test logic is
implemented in the form of a
GLScreen
instance contained in the
GLGame
implementation of the
test, as seen in Chapter 9. We will present only the relevant portions of the
GLScreen
instance, to
conserve some pages. The naming conventions are again
XXXTest
and
XXXScreen
for the
GLGame
and
GLScreen
implementation of each test.
Vertices in 3D
In Chapter 7, you learned that a vertex has a few attributes:
ï?®
Position
ï?®
Color (optional)
ï?®
We created a helper class called
Vertices
, which handles all the dirty details for us. We limited
the vertex positions to have only x and y coordinates. All we need to do to go 3D is modify the
Vertices
class so that it supports 3D vertex positions.
Texture coordinates (optional)
Vertices3: Storing 3D Positions
Let's write a new class called
Vertices3
to handle 3D vertices based on our original
Vertices
class. Listing 10-1 shows the code.
Listing 10-1. Vertices3.java, Now with More Coordinates
package
com.badlogic.androidgames.framework.gl;
import
java.nio.ByteBuffer;
import
java.nio.ByteOrder;
import
java.nio.IntBuffer;
import
java.nio.ShortBuffer;
import
javax.microedition.khronos.opengles.GL10;
import
com.badlogic.androidgames.framework.impl.GLGraphics;
public class
Vertices3 {
final
GLGraphics glGraphics;
final boolean
hasColor;
final boolean
hasTexCoords;
final int
vertexSize;
final
IntBuffer vertices;
final int
[] tmpBuffer;
final
ShortBuffer indices;