Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

© Wallace Jackson 2017 267
W. Jackson, Pro Java 9 Games Development, https://doi.org/10.1007/978-1-4842-0973-8_11


CHAPTER 11


3D Scene Configuration: Using the


PerspectiveCamera and PointLight


Now that you have finished the 2D SceneGraph hierarchy for the splash screen and user interface design,
let’s get back into our JavaFXGame primary application class coding here in Chapter 11 and start to design
the 3D GameBoard Scene Infrastructure that will be the foundation for the rendering and lighting of the
board game and its gameplay. We will learn about the basic 3D scene components that you will find pre-
installed (for all default or empty scenes) in 3D software packages like Blender or Autodesk 3D Studio Max.
After that, we can get into JavaFX Primitives (Box, Plane, Cylinder, Disk, Sphere, and Pill) during Chapter 12
and shading with materials and texture maps in Chapter 13.
During the chapter you’ll be learning about the different types of JavaFX 9 Camera and LightBase
subclasses that are contained in the core javafx.scene package, which, in turn, is contained (as of Java 9)
in the javafx.graphics module. We will cover PerspectiveCamera since you will be using this in the basic
3D scene infrastructure that we’ll be creating during this chapter, as well as ParallelCamera, another
Camera subclass that is better suited for your 2D or 2.5D game development pipeline. Camera is an abstract
superclass and cannot be utilized directly. We’ll also learn about the public LightBase abstract superclass
and its two core lighting subclasses, AmbientLight and PointLight.
We will also continue to work on your JavaFXGame Java code by adding 3D rendering, camera, and
lighting to the JavaFX SceneGraph so that you can start to add 3D elements to your 3D game, which we will
do after we cover the JavaFX Shape3D class and its primitive subclasses (in Chapter 12 ) and using shaders
and applying materials and texture maps to that 3D geometry (in Chapter 13 ).
We have a lot to learn about what is needed for JavaFX to even be able to visualize (render) your game’s
3D geometry assets and their texture maps in your 3D scene, so let’s get started learning about the scene
camera object.


Use a 3D Camera: Adding Perspective to 3D Games


The top level of any 3D rendering pipeline is the scene camera, as this is what processes everything in the
3D scene and then hands that data over to the rendering engine. In this case, that’s the PRISM software
renderer (in the absence of a GPU), or it could be the OpenGL hardware rendering engine on the consumer
electronic device (PC, phone, tablet, iTV set, laptop, game console, set-top box) that your 3D game is playing
on. If you are still using Windows, it might also include DirectX 3D rendering. The Camera object (in our
case, this will be a PerpectiveCamera object) is used specifically for 3D scene rendering; we will be looking
at it during this section of the chapter. It is so integral to the JavaFX 9 SceneGraph that it has its own Scene.
setCamera(Camera) method call. This method call is used to add the Camera object to the SceneGraph
root to make sure it is at the very top (the root) of the SceneGraph rendering hierarchy. It does not use the

Free download pdf