Game Development Reference
In-Depth Information
gl.glTranslatef(cannonPos.x, cannonPos.y, 0);
gl.glRotatef(cannonAngle, 0, 0, 1);
vertices.bind();
vertices.draw(GL10. GL_TRIANGLES , 0, 3);
vertices.unbind();
}
The present() method does the same boring things as it did before. We set the viewport, clear
the screen, set up the orthographic projection matrix using our frustum's width and height, and
tell OpenGL ES that all subsequent matrix operations will work on the model-view matrix. We
load an identity matrix to the model-view matrix to “clear� it. Next, we multiply the (identity)
model-view matrix with a translation matrix, which will move the vertices of your triangle from
model space to world space. We call glRotatef() with the angle we calculated in the update()
method, so that our triangle gets rotated in model space before it is translated. Remember,
transformations are applied in reverse order—the last specified transform is applied first. Finally,
we bind the vertices of the triangle, render it, and unbind it.
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
Now we have a triangle that will follow your every touch. Figure 8-6 shows the output after
touching the upper-left corner of the screen.
Figure 8-6. Our triangle cannon reacting to a touch event in the upper-left corner
 
Search WWH ::




Custom Search