Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 11 ■ 3D SCene Configuration: uSing the perSpeCtiveCamera anD pointLight

The colorProperty() method specifies the ObjectProperty for the light source, while the
getColor() method gets the Color value property for the light source. The getScope() method will get an
ObservableList containing a List of Nodes that specifies the hierarchical scope for the LightBase
subclass (object).
The isLightOn() method call returns the boolean value of on (true) or off (false) for the light
source, and the lightOnProperty() method call will set the boolean data value for the light source
BooleanProperty lightOn.
Finally, the void setColor(Color value) method will set the data value of the light color property, and
the void setLightOn(boolean value) method will set the data value of the LightBase subobject lightOn
boolean value property.
Next, let’s take a closer look at the AmbientLight and PointLight concrete classes individually.


JavaFX AmbientLight Class: Lighting Your 3D Scene Uniformly


The public JavaFX AmbientLight class is a concrete class, used to create a general or “ambient” level of
illumination for a 3D scene. There is generally only one instance of AmbientLight defined for a given 3D
Scene instance. The AmbientLight class is kept in the javafx.graphics module in the core javafx.scene
package and is a subclass of LightBase, which is a Node subclass, as it is ultimately a Node at the top of
the SceneGraph. The AmbientLight class also implements a Styleable interface so it can be styled and an
EventTarget interface so that it can process events. The Java class hierarchy for the JavaFX AmbientLight
class therefore would look like the following:


java.lang.Object



javafx.scene.Node
javafx.scene.LightBase
javafx.scene.AmbientLight



The AmbientLight class defines the ambient light source object for your 3D Scene, if needed. Ambient
light can be defined as a global or general amount of illumination of an area from an unseen light source that
appears to be coming into the scene from every direction. All AmbientLight object properties are inherited
from the LightBase superclass and should include an initial color for the light source and whether the light
source is initially turned on (enabled) or off (disabled). It’s again important to note that since this is a 3D
feature, it is a conditional feature.
AmbientLight has two overloaded constructor methods; the first one creates an unconfigured
AmbientLight object class using the (default) Color.WHITE light source, using the following Java
instantiation programming format:


AmbientLight ambient = new AmbientLight();


The second overloaded constructor method creates a new instance of PointLight using a specified color
that is not Color.WHITE, using the following Java instantiation programming format:


AmbientLight ambientaqua = new AmbientLight(Color.AQUA);


Next, let’s take a look at the PointLight concrete class in detail, and then we can add a PointLight object
into your 3D Scene before we finish up with this chapter on setting up a 3D rendering scene environment
that we can drop 3D objects into over the duration of the rest of this book.

Free download pdf