Game Development Reference
In-Depth Information
gl.glPushMatrix();
gl.glTranslatef(ship.position.x, ship.position.y, ship.position.z);
gl.glRotatef(ship.velocity.x / Ship. SHIP_VELOCITY * 90, 0, 0, -1);
Assets. shipModel .draw(GL10. GL_TRIANGLES , 0,
Assets. shipModel .getNumVertices());
gl.glPopMatrix();
Assets. shipModel .unbind();
}
}
The renderShip() method starts off by checking the state of the ship. If it is exploding, we
disable lighting, call renderExplosion() to render an explosion at the position of the ship, and
enable lighting again.
If the ship is alive, we bind its texture and model, push the model-view matrix, move it to its
position and rotate it around the z axis based on its velocity, and draw its model. Finally, we
pop the model-view matrix again (leaving only the camera's view) and unbind the ship model's
vertices.
private void renderInvaders(GL10 gl, List<Invader> invaders, float deltaTime) {
invaderAngle += 45 * deltaTime;
Assets. invaderTexture .bind();
Assets. invaderModel .bind();
int len = invaders.size();
for ( int i = 0; i < len; i++) {
Invader invader = invaders.get(i);
if (invader.state == Invader. INVADER_DEAD ) {
gl.glDisable(GL10. GL_LIGHTING );
Assets. invaderModel .unbind();
renderExplosion(gl, invader.position, invader.stateTime);
Assets. invaderTexture .bind();
Assets. invaderModel .bind();
gl.glEnable(GL10. GL_LIGHTING );
} else {
gl.glPushMatrix();
gl.glTranslatef(invader.position.x, invader.position.y,
invader.position.z);
gl.glRotatef(invaderAngle, 0, 1, 0);
Assets. invaderModel .draw(GL10. GL_TRIANGLES , 0,
Assets. invaderModel .getNumVertices());
gl.glPopMatrix();
}
}
Assets. invaderModel .unbind();
}
The renderInvaders() method is pretty much the same as the renderShip() method. The only
difference is that bind the texture and mesh before we render each invader. This considerably
reduces the number of binds and speeds up the rendering. For each invader, we check its state
again and render either an explosion or the normal invader model. Since we bind the model
 
Search WWH ::




Custom Search