Lighting the Scene

The next important element of the 3D scene is a light source. 

There are two types of light:

  • PointLight, which works like a lamp
  • AmbientLight, which softly lights from all directions

You can use AmbientLight to subtly adjust the coloring of the scene. PointLight plays the more important role of an actual light source. Let's add PointLight to our example, and make it follow the mouse cursor instead of the camera:

// chapter12/LightDemo.javaPointLight light = new PointLight();light.setTranslateX(350);light.setTranslateY(100);light.setTranslateZ(300); scene.setOnMouseMoved((event) -> {    light.setTranslateX(event.getSceneX()-50);    light.setTranslateY(event.getSceneY()-200); light.setTranslateZ( 300 - event.getSceneX()/2 ); ...

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.