Game Development Reference
In-Depth Information
Figure 10-15. The crate system
The HierarchicalObject Class
Let's define a simple class that can encode a generic solar system object with the following
properties:
ï?®
A position relative to its parent's center
ï?®
A rotation angle around the parent
ï?®
A rotation angle around its own y axis
ï?®
A scale
ï?®
A list of children
Vertices3 instance to be rendered
Our HierarchicalObject instance should update its rotation angles and its children, and render
itself and all its children. This is a recursive process since each child will render its own children.
We will use glPushMatrix() and glPopMatrix() to save a parent's transformations so that
children will move along with the parent. Listing 10-7 shows the code.
ï?®
A reference to a
Listing 10-7. HierarchicalObject.java, Representing an Object in the Crate System
package com.badlogic.androidgames.gl3d;
import java.util.ArrayList;
import java.util.List;
import javax.microedition.khronos.opengles.GL10;
import com.badlogic.androidgames.framework.gl.Vertices3;
public class HierarchicalObject {
public float x, y, z;
public float scale = 1;
public float rotationY, rotationParent;
 
Search WWH ::




Custom Search