Game Development Reference
In-Depth Information
How to do it...
Now that we have the basics covered, let's explore a pattern that allows us to move lights
using objects in the scene graph:
1. First, create a new
PointLight
class called
pointLight
and set
radius
to
40
.
2. Then, call
rootNode.addLight(pointLight)
to add it to the scene graph.
3. Now, create a new
CameraNode
called
camNode
and then call
camNode.setControlDir(CameraControl.ControlDirection.CameraToSpatial);
before attaching it to the
rootNode
.
4. Next, create a new
LightControl
called
lightControl
, supplying
pointLight
to it to indicate that this is the light to control, as shown in the fol-
lowing code:
LightControl lightControl = new
LightControl(pointLight);
5. We set
controlDir
to be
LightCon-
trol.ControlDirection.SpatialToLight
. This means that the Spatial
camNode
will control the light's position:
lightControl.setControlDir(LightControl.ControlDirection.SpatialToLight);
6. Finally, we add
lightControl
to
camNode
.
7. To test this out, we can load
Sponza
(Models/Sponza/Sponza.j3o) from the jMon-
keyEngine's
test-data
library and apply the
Lighting
material to it.