Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


CHAPTER 14


3D Model Hierarchy Creation:


Using Primitives to Create a


Game Board


Now that you have learned how to “skin” your 3D primitives using the JavaFX Phong shader algorithms and
their various color and effects mapping channels and you have created colorful, highly optimized game board
square texture maps, it’s time to add some more custom methods for building the game board and setting up
the Phong shader objects with the texture maps. We’ll need to create a createGameBoardNodes() method to
organize the 3D primitive assets that comprise our 3D gameboard, as the createBoardGameNodes() method
should (and does) contain higher-level Node subobject instantiation and configuration, such as the Scene,
Root, UI StackPane, 3D gameBoard Group, Camera, and Lighting, as well as four game board Quadrant Group
objects named Q1 through Q4 (quadrants 1 through 4). We will also create the other 19 game board square
objects, named Q1S1 through Q1S5, Q2S1 through Q2S5, Q3S1 through Q3S5, and Q4S1 through Q4S5 to keep
object names short. Naming the objects the abbreviated version of Quadrant1Square1 (Q1S1) will make the
Java code that uses these abbreviated terms much more readable.
During this chapter, you will be building your gameBoard Group branch of your SceneGraph, which
is under your SceneGraph root, next to the uiLayout branch, which you’ve already built. Under your
gameBoard Group branch, we’ll segment the game board into four quadrants, so the middle of the game
board can have four larger 300x300 unit areas we can use for gameplay, with each of the quadrants having 5
of your 20 perimeter game board squares as child objects. With a three-tiered 3D primitive object hierarchy,
we can access your entire game board as a whole (to rotate it, for instance), access each quadrant as a unit
(to levitate it or apply shader effects, for instance), and access individual game board squares at the bottom
(leaf Node subobjects) of the hierarchy. Let’s get to work! We have hundreds of lines of new Java code to
write during this chapter implementing primitives, shaders, images, and SceneGraph hierarchy nodes.


Primitive Creation Method: createGameBoardNodes()


Since creating the 24 primitives (4 center board quadrants and 20 perimeter squares) is going to take over
100 Java statements (instantiate using new, setTranslateX(), setTranslateZ(), setMaterial(), etc.), let’s create
a method specifically to hold our game board objects and their instantiation and configuration statements.
In this way, a createBoardGameNodes() method will create the global and top-level Node subclass objects
(scene, root, camera, light, uiLayout branch, gameBoard branch, Q1 through Q4 branches, etc.). Later in the
chapter, we will also extract the PhongMaterial shader creation logic to another custom createMaterials()
method, where we will create a couple dozen custom shader objects to use to skin various components

Free download pdf