Game Development Reference
In-Depth Information
16, 17, 18, 18, 19, 16,
20, 21, 22, 22, 23, 20,
24, 25, 26, 26, 27, 24 };
Vertices3 cube =
new
Vertices3(glGraphics, vertices.length / 8, indices.length,
false
,
true
,
true
);
cube.setVertices(vertices, 0, vertices.length);
cube.setIndices(indices, 0, indices.length);
return
cube;
}
The
createCube()
method is mostly the same as the one we used in previous examples. This
time, however, we add normals to each vertex, as shown in Figure
11-4
. Apart from that, nothing
has really changed.
@Override
public void
update(
float
deltaTime) {
angle += deltaTime * 20;
}
In the
update()
method, we simply increase the rotation angle of the cube.
@Override
public void
present(
float
deltaTime) {
GL10 gl = glGraphics.getGL();
gl.glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
gl.glClear(GL10.
GL_COLOR_BUFFER_BIT
| GL10.
GL_DEPTH_BUFFER_BIT
);
gl.glEnable(GL10.
GL_DEPTH_TEST
);
gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());
gl.glMatrixMode(GL10.
GL_PROJECTION
);
gl.glLoadIdentity();
GLU.
gluPerspective
(gl, 67, glGraphics.getWidth()
/ (
float
) glGraphics.getHeight(), 0.1f, 10f);
gl.glMatrixMode(GL10.
GL_MODELVIEW
);
gl.glLoadIdentity();
GLU.
gluLookAt
(gl, 0, 1, 3, 0, 0, 0, 0, 1, 0);
gl.glEnable(GL10.
GL_LIGHTING
);
ambientLight.enable(gl);
pointLight.enable(gl, GL10.
GL_LIGHT0
);
directionalLight.enable(gl, GL10.
GL_LIGHT1
);
material.enable(gl);
gl.glEnable(GL10.
GL_TEXTURE_2D
);
texture.bind();
gl.glRotatef(angle, 0, 1, 0);
cube.bind();
cube.draw(GL10.
GL_TRIANGLES
, 0, 6 * 2 * 3);
cube.unbind();