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

Q4S1 needs to position itself 300 units along Z (from the 0,0 origin) and 750 units along X at
the right. This is done by changing the location method call to .setTranslateZ( 300 ). Be sure to set
.setMaterial(Shader16) to reference the correct shader that then references and applies the diffuse16
Image object as a diffuseMap property.
Q4S2 needs to position itself 150 units along Z (from the 0,0 origin) and the full 750 units
along X. This is done by changing the location method call to .setTranslateZ( 150 ). Be sure to set
.setMaterial(Shader17) to reference the correct shader that then references and applies the diffuse17
Image object as a diffuseMap property.
Q4S3 only needs to position itself 750 units along X from the 0,0 origin because it is at the right
corner. This means the only location method call needed is .setTranslateX( 750 ). Be sure to set
.setMaterial(Shader18) to reference the correct shader that then references and applies the diffuse18
Image object as a diffuseMap property.
Q4S4 only needs to position itself 600 units along X from the 0,0 origin to pull this square back 150 units
in the direction, of the origin, in order to move it to the left, along the bottom of your game board layout.
This is done by using only the .setTranslateX( 600 ) method call. Be sure to set .setMaterial(Shader19)
to reference the correct Shader9 object, which references (and applies) the diffuse19 Image object as a
PhongMaterial diffuseMap property.
Q4S5 needs to position itself 450 units in the X direction from 0,0 so your last game square is
located near the bottom middle of this game board. This is again done using one location method call to
.setTranslateX( 450 ). Be sure to set .setMaterial(Shader20) to reference the correct Shader20 object,
which then references (and applies) the diffuse20 Image object as a diffuseMap property. The Java code for
the construction of this final quadrant of the game board should look like the following Java code:


private void createGameBoardNodes() {
...
q4 = new Box(300, 5, 300); // Java code creating a second quadrant for the gameboard
q4.setTranslateX( 525 );
q4.setTranslateZ( 225 );
Q4S1 = new Box(150, 5, 150);
Q4S1.setTranslateX( 750 );
Q4S1.setTranslateZ( 300 );
Q4S1.setMaterial(Shader 16 );
Q4S2 = new Box(150, 5, 150);
Q4S2.setTranslateX( 750 );
Q4S2.setTranslateZ( 150 );
Q4S2.setMaterial(Shader 17 );
Q4S3 = new Box(150, 5, 150);
Q4S3.setTranslateX( 750 );
Q4S3.setMaterial(Shader 18 );
Q4S4 = new Box(150, 5, 150);
Q4S4.setTranslateX( 600 );
Q4S4.setMaterial(Shader 19 );
Q4S5 = new Box(150, 5, 150);
Q4S5.setTranslateX( 450 );
Q4S5.setMaterial(Shader 20 );
}


Figure 14-24 shows the Run ➤ Project Java code testing work process, showing a completed 3D game
board.

Free download pdf