Game Development Reference
In-Depth Information
3. ColorRGBA has a method to interpolate two colors that we can use to get a
smooth transition during the day:
sunColor.interpolate(eveningColor, dayColor,
FastMath.sqr(height));
4. After this, we set the color of directionalLight to the same as sunColor
and also set the material's Color parameter to the same:
directionalLight.setColor(sunColor);
((Geometry)spatial).getMaterial().setColor("Color",
sunColor);
Handling the sky color will take a bit more work. To do this, perform the following steps:
1. We begin by creating a new class called SkyControl extending Ab-
stractControl .
2. Like SunControl , the SkyControl class needs a Camera field called cam .
It also needs a ColorRGBA field called color and three static ColorRGBA
fields for different times in the day:
private static final ColorRGBA dayColor = new
ColorRGBA(0.5f, 0.5f, 1f, 1f);
private static final ColorRGBA eveningColor = new
ColorRGBA(1f, 0.7f, 0.5f, 1f);
private static final ColorRGBA nightColor = new
ColorRGBA(0.1f, 0.1f, 0.2f, 1f);
3. The SkyControl class needs to know about the sun's location so we add a
SunControl field called sun .
4. In the controlUpdate method, we set the localTranslation of the spa-
tial to the location of the cam .
5. Next, we get the sun's height and if it is higher than 0, we interpolate the color
between eveningColor and dayColor . Otherwise, we interpolate between
the eveningColor and nightColor instead. Then, we set the resulting color
in the sky's material's Color parameter, as shown in the following code:
if(sunHeight> 0){
color.interpolate(eveningColor, dayColor,
Search WWH ::




Custom Search