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

Now let’s create the second quadrant of our game board by going back into the
createGameBoardNodes() method body and creating the second section of code for Box primitives
Q2S1 through Q2S5 by copying the Q1S1 to Q1S5 statements, pasting them again underneath themselves,
and then changing the object names and method call parameters (so that you do not have to type the
majority of these Java statements into the NetBeans 9 IDE again).
The q2 Box object (second quadrant) will need to be moved by 300 units (quadrants are 300x300 in size)
out along the z-axis, so the q2.setTranslateZ() method parameter needs to be incremented from 225 to 525
to accomplish this second quadrant game board component positioning, as shown in Figure 14-22, if you
wanted to look ahead.
Q2S1 needs to position itself 450 units along the z-axis (from the 0,0 origin) because Q1S5 is at 300 plus
150, which is 450. This is done by changing the location method call to .setTranslateZ( 450 ). Be sure to set
.setMaterial(Shader6) to reference the correct shader, which references (and applies) the diffuse6 Image
object as a diffuseMap property.
Q2S2 needs to position itself 600 units along the z-axis (from an 0,0 origin) because 450 plus 150
equals 600. This is done by changing the location method call to .setTranslateZ( 600 ). Be sure to also set
.setMaterial(Shader7) to reference the correct shader that then references (and applies) the diffuse7
Image object as a diffuseMap property.


Figure 14-20. Copy and paste 5 Shader PhongMaterial instantiations 3 times and create all 20 Shader objects

Free download pdf