Game Development Reference
In-Depth Information
Figure 7-25. Bob, first rotated and then scaled
Wow, this is not the Bob we used to know. What happened here? If you look at the code
snippets, you'd actually expect Figure 7-24 to look like Figure 7-25 , and Figure 7-25 to look like
Figure 7-24 . In the first snippet, we apply the rotation first and then scale Bob, right?
Wrong. The way OpenGL ES multiplies matrices with each other dictates the order in which
the transformations the matrices encode are applied to a model. The last matrix with which
we multiply the currently active matrix will be the first that gets applied to the vertices. So if
we want to scale, rotate, and translate Bob in that exact order, we have to call the methods
like this:
glTranslatef(bobs[i].x, bobs[i].y, 0);
glRotatef(45, 0, 0, 1);
glScalef(2, 0.5f, 1);
If we changed the loop in our BobScreen.present() method to the following code, the output
would look like Figure 7-26 :
gl.glMatrixMode(GL10. GL_MODELVIEW );
for ( int i = 0; i < NUM_BOBS ; i++) {
gl.glLoadIdentity();
gl.glTranslatef(bobs[i].x, bobs[i].y, 0);
gl.glRotatef(45, 0, 0, 1);
gl.glScalef(2, 0.5f, 0);
bobModel.draw(GL10. GL_TRIANGLES , 0, 6);
}
Search WWH ::




Custom Search