Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 13 ■ 3D MoDel ShaDer Creation: USing the JavaFX 9 phongMaterial ClaSS

Next, let’s remove the sphere Sphere and pole Cylinder instantiations and configuration statements; you
can leave the declarations at the top of the class if you want to as we will use these later.
To make a game board square, which will be used around the perimeter of the game board and
will be 150 units square and 5 units thin (tall), we will leave the Box box object and construct it with the
Box(150,5,150) method call. I will also rotate it 45 degrees for now so the point (corner) is facing the camera
object. We can keep the PhongMaterial code because all we have to do to change the diffuseMap once we
create it in GIMP is to change the file name in the loadImageAssets() method, which we will do after we
create the game board square texture map. Don’t forget, if you forget to remove the objects we’ve removed
from the SceneGraph node, you will get a fatal error during compile.
As stated initially, a Box constructor method is very basic and looks like the Java code in Figure 13-20:


box = new Box( 150 , 5 , 150 );
box.setRotationAxis(Rotate.Y_AXIS);
box.setRotate(45);
box.setMaterial(phongMaterial);


Figure 13-19. Reconfigure your camera object to dolly to Z = 0, rotate 45 degrees, and zoom in with FOV = 1

Free download pdf