Game Development Reference
In-Depth Information
How it works...
Always causing the geometries of this recipe follow the camera around is one of the parts
that make this recipe work. The other trick is using the Sky QueueBucket . The Sky
QueueBucket can be thought of as lists of items to be rendered. Everything in the Sky
bucket is rendered first. Because it's rendered first, other things will be rendered on top of
it. This is why it appears to be far away even though it's really close to the camera.
We also use the direction of the sun from the camera for DirectionalLight in the
scene, making it follow the sun as it moves across the sky.
When updating the control, we handle the movement of the sun using the time value,
which increases with each update. Using FastMath.sin and FastMath.cos for the x
and z values, we get it to move in a circle around the camera. Using FastMath.sin
again for the y value will move it in an arc above (and below) the horizon. By multiplying
the y value, we can get it to rise higher in the sky.
The resulting position was added to the camera's location to always make the sun centered
around the camera. Since the sun is a simple quad, we also had to rotate it to face the cam-
era with every update.
We went on to change the color of the sun based on the height above the horizon. We used
the interpolate method of ColorRGBA to do this. Interpolation requires a value between
0.0 and 1.0 . That's why we needed to divide the y value by the max y value (or amp-
litude) in the case where we've multiplied it earlier to get a higher arc in the sky.
The movement of the box simulating the sky is similar. We just keep it centered around the
camera so that even if it's a small box, it appears to cover the whole sky. Normally, we
wouldn't see the sides of the box when we're inside it so we set FaceCullMode to Off to
always make it render the sides.
SkyControl was fitted with three instances of ColorRGBA: dayColor with a bluish
tint, eveningColor with orange, and nightColor almost black. The SunControl
was supplied to the control and used to interpolate between the colors based on the height
of the sun. Anything above 0.0f is considered day.
In this implementation, the whole sky changes color with the sun. Any further development
of SkyControl could include a more complex shape, such as a cylinder or sphere where
Search WWH ::




Custom Search