Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 14 ■ 3D MoDel hierarChy Creation: Using priMitives to Create a gaMe BoarD


Let’s render the 3D Scene using the Run ➤ Project work process and see if the two Box primitives are
still overlapping or if they are positioned correctly. As you can see in Figure 14-12, the corners of the game
board square and the first quadrant are now aligned corner to corner, and you can begin to see how the
game board will be laid out.


Although this is the result I wanted to see, in thinking ahead about how I am going to access each
quadrant and its child squares, I want to keep the squares in QxSy 1 through 5 order going around the game
board, and this would not work if I started with square 1 on the corner of each quadrant! Think about it!
Therefore, I actually need to move this square location from 0, 0 (X, Z) to 300, 0 (X, Z). I will do this after I
create the custom method body to hold my shaders next.
Since I’m going to have a couple dozen shaders, I’m going to quickly create another custom method to
keep the shader creation separate and organized so that I can collapse and expand the shader-related code
as needed.


Coding a Phong Shader Creation Method: createMaterials()


Since shaders are an important part of a pro Java 9 game design pipeline, let’s give them their own method
body and move the PhongMaterial object code from createBoardGameNodes() to this new createMaterials()
method. Add a line of code at the top of your start() method after loadImageAssets() as these are used
in the shaders and before createGameBoardNodes(); these objects will use the shaders created in this
createMaterials() method body. Type in createMaterials() and a semicolon to call the nonexistent method;
then use your Alt+Enter keystroke combination and select the “add the createMaterials() method in
javafxgame.JavaFXGame” option. Let’s also change our PhongMaterial name to Shader1. We can name
these first 20 shaders in this method body, as well as at the top of your class where I have added declarations


Figure 14-12. Use the Run ➤ Project work process to see if the two 3D primitives are precisely aligned corner
to corner

Free download pdf