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

Next, let’s create the third quadrant for your game board by going back into the
createGameBoardNodes() method body and creating the third section of code for the Box primitives Q3S1
through Q3S5 (as well as for your q3 center quadrant). Just copy the Q2S1 to Q2S5 statements and paste
them again underneath themselves (and after the q3 instantiation and configuration statements to keep
grouped nodes together logically in the Java code body). Next, you will again change your object names and
method call parameters (so that you do not have to type the majority of these Java 9 statements into your
NetBeans 9 IDE again) to position your squares diagonally, from your first quadrant.
The q3 Box object (third quadrant) will need to be moved by 300 units (quadrants are 300x300 in
size) out along both the x- and z-axes, so the q3.setTranslateX() method parameter also needs to be
incremented from 225 to 525 to accomplish this third quadrant game board component positioning, as
shown in Figure 14-24.


Q3S1 needs to position itself 450 units along the x-axis from the 0,0 origin and 750 units out along
the z-axis. This is done by changing your locational method call to .setTranslateX(450) and leaving
(or adding w, which depends on which Java code you copied) .setTranslateZ( 750 ). Be sure to also set
.setMaterial(Shader11) to reference the correct shader number, which then references (and applies) the
diffuse11 Image object as the diffuseMap property.
Q3S2 needs to position itself 600 units along x-axis from the 0,0 origin and 750 units out, along
the z-axis. This is done by changing the location method call to .setTranslateX( 600 ) and leaving (or
adding, depending on the block of Java code you have copied) .setTranslateZ( 750 ). Be sure to also set
.setMaterial(Shader12) to reference the correct shader number, which then references (and applies) the
diffuse12 Image object as a diffuseMap property.
Q3S3 needs to position itself 750 units along the z-axis from the 0,0 origin, as well as 750 units
along x-axis, which puts it diagonal to an 0,0 origin. This is done by changing the location method call to
.setTranslateZ( 750 ) and then adding a second .setTranslateX( 750 ) method call. Be sure to also set
.setMaterial(Shader13) to reference your correct Phong shader object number, which references (and
applies) the diffuse13 Image object as your diffuseMap property.


Figure 14-24. Use your Run ➤ Project work process to see that quadrants 1 to 4 are now coded and aligning
properly

Free download pdf