Below the commented-out code outline, add the following function definition
of addLights().
functionaddLights() {
scene.add(newTHREE.AmbientLight(0x999999));
varback_light =newTHREE.PointLight(0xffffff);
back_light.position.set(50, 50, -100);
scene.add(back_light);
varspot_light =newTHREE.SpotLight(0xffffff);
spot_light.position.set(-250, 250, 250);
spot_light.castShadow = true;
scene.add(spot_light);
}
We’ve seen lights from our work in Chapter 12, Working with Lights and
Materials, on page 109, and in Chapter 13, Project: Build Your Own Solar Sys-
tem, on page 117. We’re using three kinds of lights here. An ambient light is
a light that is everywhere—it won’t cast shadows or make things shine, but
will bring out colors in things. A point light is like a light bulb—we place it
above and behind the center of the scene so that it can shine down on the
game platform. A spot light is just what it sounds like—we use it to shine a
light from the side and to cast a shadow.
Now that we’ve added the function definition, uncomment the call to addLights()
in the code outline.
Add the Game Ball
Let’s get started with the addBall() function by adding the following code below
the function definition for addLights().
functionaddBall() {
varball =newPhysijs.SphereMesh(
newTHREE.SphereGeometry(10, 25, 21),
newTHREE.MeshPhongMaterial({
color: 0x333333,
shininess: 100.0,
ambient: 0xff0000,
emissive: 0x111111,
specular: 0xbbbbbb
})
);
ball.castShadow = true;
scene.add(ball);
resetBall(ball);
returnball;
}
Chapter 16. Project: Tilt-a-Board • 148
Prepared exclusively for Michael Powell report erratum • discuss