Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


Figure 11-19. Use your Run ➤ Project work process and test the 3D Scene infrastructure that you have put
into place


We are now in a position to be able to work on 3D modeling and 3D texture mapping using the JavaFX APIs.

Summary


In this eleventh chapter, we added 3D Scene capabilities to JavaFXGame.java by adding a PerspectiveCamera
object, which allows the rendering of 3D assets using X, Y, and Z dimensions, and a 3D perspective to the
Scene object. We also added a PointLight object to simulate a lightbulb light source to illuminate these 3D
assets, as well as a Sphere object (a “primitive”) to test our basic 3D Scene setup.
You learned about the abstract Camera superclass and its ParallelCamera (for 2D or Orthographic
3D Scene usage) and PerspectiveCamera, which we are going to use for the most effective 3D or i3D
Scene rendering. We then learned how to declare, instantiate, and configure a PerspectiveCamera in the
JavaFXGame, changing how it operates.
We then tested our 2D UI elements and hierarchy and observed that these are now on a 2D “plane” in
3D space. We corrected the Java code to compensate for this change in coordinate space, restoring your UI to
full-screen.
We then tested all the UI Button objects and found our new 3D Scene black background color was
affecting our information screens and very cleverly used a complex nested Java statement to create and
insert a Color.WHITE BackgroundFill object into your StackPane object’s Background object. This solved
the problem by replacing one of the compositing layer’s transparency with a white color fill and adding
another opaque layer to our now hybrid 3D and 2D compositing pipeline. Once that problem was solved, we
changed the logic in the gameButton event handler and allowed the end user to start the game by hiding the
UI overlay and reveal the test Sphere primitive, correctly lit.
In the next chapter, we are going to take a look at the JavaFX Shape3D superclass and its subclasses as
we continue to begin working on the foundation knowledge needed to create the i3D portions of your pro
Java 9 game.

Free download pdf