Game Development Reference
In-Depth Information
Figure 7-20. That's a lot of Bobs!
That's not the end of all of our fun with transformations yet. If you remember what we said a
couple of pages ago, you'll know what's coming: rotations and scaling.
More Transformations
Besides the glTranslatef() method, OpenGL ES also offers us two methods for transformations:
glRotatef() and glScalef() .
Rotation
Here's the signature of glRotatef() :
GL10.glRotatef( float angle, float axisX, float axisY, float axisZ);
The first parameter is the angle in degrees by which we want to rotate our vertices. What do the
rest of the parameters mean?
When we rotate something, we rotate it around an axis. What is an axis? Well, we already know
three axes: the x axis, the y axis, and the z axis. We can express these three axes as vectors .
The positive x axis would be described as (1,0,0), the positive y axis would be (0,1,0), and the
positive z axis would be (0,0,1). As you can see, a vector actually encodes a direction—in our
case, in 3D space. Bob's direction is also a vector, but in 2D space. Vectors can also encode
positions, like Bob's position in 2D space.
To define the axis around which we want to rotate the model of Bob, we need to go back to 3D
space. Figure 7-21 shows the model of Bob (with a texture applied for orientation), as defined in
the previous code in 3D space.
 
Search WWH ::




Custom Search