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


Q2S3 needs to position itself 750 units along the z-axis (from an 0,0 origin) because 600 plus 150
equals 750. This is done by changing the location method call to .setTranslateZ( 750 ). Be sure to also set
.setMaterial(Shader8) to reference the correct shader that then references (and applies) the diffuse8
Image object as a diffuseMap property.
Q2S4 also needs to position itself 750 units along the z-axis from the 0,0 origin, but this time,
we’ll need to push this square over 150 units in the X direction in order to move it to the right, along
the top of your game board layout. This is done by changing over to using two location method calls.
One would be .setTranslateX( 150 ), and the other would be .setTranslationZ( 750 ). Be sure to set
.setMaterial(Shader9) to reference the correct Shader9 object, which then references (and applies) the
diffuse9 Image object as a diffuseMap property.
Q2S5 needs to position itself 300 units in the X direction from 0,0, as well as 750 units in the Z
direction, so that this square is located near the top middle of this game board, on the other side of the game
board from square 1. This is again done using two location method calls, to .setTranslateZ( 750 ) and to
.setTranslateX( 300 ). Be sure to set .setMaterial(Shader10) to reference the correct Shader10 object,
which then references (and applies) the diffuse10 Image object as a diffuseMap property.
The Java code for the construction of the second quadrant of the game board, which is shown in
Figure 14-21 after the code for the construction of the first quadrant, should look like the following (spaced
out for readability):


private void createGameBoardNodes() {
...
q2 = new Box(300, 5, 300); // Java code creating a second quadrant for the gameboard
q2.setTranslateX(225);
q2.setTranslateZ(525);


Q2S1 = new Box(150, 5, 150);
Q2S1.setTranslateZ( 450 );
Q2S1.setMaterial(Shader 6 );


Q2S2 = new Box(150, 5, 150);
Q2S2.setTranslateZ( 600 );
Q2S2.setMaterial(Shader 7 );


Q2S3 = new Box(150, 5, 150);
Q2S3.setTranslateZ( 750 );
Q2S3.setMaterial(Shader 8 );


Q2S4 = new Box(150, 5, 150);
Q2S4.setTranslateZ( 750 );
Q2S4.setTranslateX( 150 );
Q2S4.setMaterial(Shader 9 );


Q2S5 = new Box(150, 5, 150);
Q2S5.setTranslateZ( 750 );
Q2S5.setTranslateX( 300 );
Q2S5.setMaterial(Shader 10 );

Free download pdf