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


There are one or two rendering anomalies visible, such as the Q1S2 square, which looks like it is lying
over the Q1S1 square. This is strange, as the code is precise and based on multiples of 150, so it should
be aligned precisely like the others. Since this problem is not with the code, we will take a look at how we
can deal with this rendering anomaly in the next chapter. Use the .setRotationAxis(Rotate.Y_AXIS) and
.setRotate(30) methods to rotate the game board 30 degrees, as you have done before, to see what pivot
point is being used to rotate this gameBoard hierarchy. This Java 9 test code should be placed in your
createBoardGameNodes() method, as shown highlighted in Figure 14-25.


The reason that we’re doing this is that we need to check, before we leave this chapter, whether or not
this game board is working as a hierarchy. That is, if we rotate it around the y-axis, will it use the center of the
gameBoard Group as the pivot point, or will it pivot (rotate) around the center of the 0,0 origin corner square
of the game board?
As you can see in Figure 14-26, the gameBoard Group object is indeed defining its own 0,0 center, using
the average center of all of its Group Node’s children. As we know from the 6 × 150 (900) construction of the
game board, this 0,0 center is offset 450 (half of 900) in X and Z (450, 450) or 625 (450 + 1/2 of 450) in linear
units (on the diagonal) between origins. By constructing things in evenly divisible whole numbers, we will
be able to use integers (int) for our gameplay code in later chapters, which saves on memory and processing
for the JavaFX game engine.


Figure 14-25. Add .setRotationAxis(Rotate.Y_AXIS) and a .setRotate(30) method call to the gameBoard
Group object

Free download pdf