Game Development Reference
In-Depth Information
How to do it...
1. We begin by creating a new application class extending SimpleApplication .
2. In the simpleInitApp method, we first need to create Geometry for the sun:
Geometry sun = new Geometry("Sun", new Quad(1.5f,
1.5f));
3. We need to set some rendering hints on it, as shown in the following code:
sun.setQueueBucket(RenderQueue.Bucket.Sky);
sun.setCullHint(Spatial.CullHint.Never);
sun.setShadowMode(RenderQueue.ShadowMode.Off);
4. Now, we can load a Material instance based on the unshaded material defini-
tion.
5. For ColorMap , we load the texture with the white circle in it and apply the tex-
ture. Then, for Color we can set an almost white color with a tint of yellow in it.
We also have to enable alpha in the material:
sunMat.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
sunMat.setTexture("ColorMap",
assetManager.loadTexture("Textures/sun.png"));
sunMat.setColor("Color", new ColorRGBA(1f, 1f, 0.9f,
1f));
So, the basic Geometry is set up and we can create a Control class to move the sun
across the sky by performing the following steps:
1. Create a class called SunControl , which extends AbstractControl .
2. It should have a float field called time , a reference to the application camera
called cam , a Vector3f field called position , and a DirectionalLight
field called directionalLight .
3. In the controlUpdate method, we start by finding the x and z positions based
on the time and multiply the result to move it some distance away. We can also
make the sun move up and down by doing the same for the y value:
float x = FastMath.cos(time) * 10f;
float z = FastMath.sin(time) * 10f;
Search WWH ::




Custom Search