Game Development Reference
In-Depth Information
Listing 12-12. WorldRenderer.java, the World Renderer
package com.badlogic.androidgames.androidinvaders;
import java.util.List;
import javax.microedition.khronos.opengles.GL10;
import com.badlogic.androidgames.framework.gl.AmbientLight;
import com.badlogic.androidgames.framework.gl.Animation;
import com.badlogic.androidgames.framework.gl.DirectionalLight;
import com.badlogic.androidgames.framework.gl.LookAtCamera;
import com.badlogic.androidgames.framework.gl.SpriteBatcher;
import com.badlogic.androidgames.framework.gl.TextureRegion;
import com.badlogic.androidgames.framework.impl.GLGraphics;
import com.badlogic.androidgames.framework.math.Vector3;
public class WorldRenderer {
GLGraphics glGraphics;
LookAtCamera camera;
AmbientLight ambientLight;
DirectionalLight directionalLight;
SpriteBatcher batcher;
float invaderAngle = 0;
The WorldRenderer keeps track of the GLGraphics instance from which we'll fetch the
GL10 instance. We also have a LookAtCamera , an AmbientLight , a DirectionLight , and a
SpriteBatcher . Finally, we use a member to keep track of the current rotation angle for all
invaders.
public WorldRenderer(GLGraphics glGraphics) {
this .glGraphics = glGraphics;
camera = new LookAtCamera(67, glGraphics.getWidth()
/ ( float ) glGraphics.getHeight(), 0.1f, 100);
camera.getPosition().set(0, 6, 2);
camera.getLookAt().set(0, 0, -4);
ambientLight = new AmbientLight();
ambientLight.setColor(0.2f, 0.2f, 0.2f, 1.0f);
directionalLight = new DirectionalLight();
directionalLight.setDirection(−1, -0.5f, 0);
batcher = new SpriteBatcher(glGraphics, 10);
}
In the constructor, we set up all members, as usual. The camera has a field of view of
67 degrees, a near clipping plane distance of 0.1 units, and a far clipping plane distance
of 100 units. The view frustum will thus easily contain the entire game world. We position
it above and behind the ship and let it look at (0,0,-4). The ambient light is just a faint gray,
and the directional light is white and comes from the top-right side. Finally, we instantiate the
SpriteBatcher so that we can render the explosion rectangles.
Search WWH ::




Custom Search