Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 11 ■ 3D SCene Configuration: uSing the perSpeCtiveCamera anD pointLight


Note that the PerspectiveCamera is a conditional 3D feature. You can poll the ConditionalFeature.
SCENE3D boolean variable to ascertain if a given user’s device supports this feature (in this case, supports
i3D). This would be done using the following Java code structure, which sets a boolean variable to reflect
system support for 3D rendering:


boolean supportFor3D = Platform.isSupported(ConditionalFeature.SCENE3D);


Finally, there is a Boolean property for this class called verticalFieldOfView, which is used to define
whether the fieldOfView property will apply to the vertical dimension of the projection. This logically
means that increasing or decreasing the FOV will change the width of the projection but not the (vertical)
height if this is false, and if this is true, it will change (scale) both the horizontal (width) and vertical (height)
dimensions of the camera projection, which would ostensibly maintain aspect ratio better than changing
only one dimension of the camera’s projection plane.
Next, let’s take a look at the ParallelCamera class, which we’ll cover to be consistent in our Camera
subclass coverage, even though this camera is more useful for use with 2D games and possibly Orthographic
3D applications.


JavaFX ParallelCamera Class: Your 2D Space Parallel Camera


The JavaFX ParallelCamera class also extends the Camera class and is used to create a ParallelCamera
(object), which is used to render your i2D scene. This ParallelCamera class is also kept in the javafx.graphics
module in the core javafx.scene package; it is a subclass of Node and is a Node at the top of your JavaFX
SceneGraph. The ParallelCamera class also implements the Styleable interface so it can be styled and the
EventTarget interface so it can process events. The Java class hierarchy for the JavaFX ParallelCamera class
will therefore look like the following:


java.lang.Object



javafx.scene.Node
javafx.scene.Camera
javafx.scene.ParallelCamera



The default camera created by JavaFX 9 will always be a ParallelCamera, which is why we are coding
specific Camera and LightBase object creation during this chapter. For instance, if you simply created a
Sphere object without creating any Camera subclass object or any LightBase subclass object, the JavaFX
runtime would automatically create a ParallelCamera object and an AmbientLight object so that the
Shape3D subclass (Sphere) would be visible to the renderer.
If a scene contains only 2D transforms, then it does not require a PerspectiveCamera and would thus
utilize a ParallelCamera, which doesn’t render all of a 3D object’s characteristics. The ParallelCamera would
be better suited for what is covered in Beginning Java 8 Games Development (Apress, 2014). This camera
defines a viewing volume for a parallel, also called an orthographic projection in the 3D industry. Essentially
an orthographic projection would equate to being a rectangular plane.
The ParallelCamera is always located at center of the window and will look along the positive z-axis.
What is different about the ParallelCamera (relative to the PerspectiveCamera) is that the scene coordinate
system defined by this camera has its origin in the upper-left corner of the screen, with a y-axis running
down the left side of the screen, the x-axis running to the right along the top of the screen, and the z-axis
pointing away from the viewer (into the distance in the screen representation).

Free download pdf