Game Development Reference
In-Depth Information
gl.glLoadIdentity();
gl.glOrthof(0, FRUSTUM_WIDTH, 0, FRUSTUM_HEIGHT, 1, -1);
gl.glMatrixMode(GL10. GL_MODELVIEW );
gl.glLoadIdentity();
gl.glTranslatef(cannonPos.x, cannonPos.y, 0);
gl.glRotatef(cannonAngle, 0, 0, 1);
gl.glColor4f(1,1,1,1);
cannonVertices.bind();
cannonVertices.draw(GL10. GL_TRIANGLES , 0, 3);
cannonVertices.unbind();
gl.glLoadIdentity();
gl.glTranslatef(ballPos.x, ballPos.y, 0);
gl.glColor4f(1,0,0,1);
ballVertices.bind();
ballVertices.draw(GL10. GL_TRIANGLES , 0, 6);
ballVertices.unbind();
}
In the present() method, we simply add the rendering of the cannonball rectangle. We do this
after rendering the cannon's triangle, which means that we have to “clean� the model-view
matrix before we can render the rectangle. We do this with glLoadIdentity() , and then use
glTranslatef() to convert the cannonball's rectangle from model space to world space at the
ball's current position.
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
If you run the example and touch the screen a couple of times, you'll get a pretty good feel for
how the cannonball will fly. Figure 8-7 shows the output (which is not all that impressive, since it
is a still image).
Search WWH ::




Custom Search