Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 12 ■ 3D MoDel Design anD priMitives: Using JavaFX 9 shape3D Classes

There are more complex ways to rotate 3D objects in JavaFX that we will get into as the book progresses
because rotation is quite a complex subject in 3D that doesn’t seem to be “on the surface” (no pun
intended). Rotation uses a more complex set of mathematics in its algorithms than translation, and some of
this complexity will percolate to the surface and therefore will have to be dealt with, and comprehended by,
all you pro Java 9 3D game developers.
Now that we have the three basic primitives offered in JavaFX separated and facing in a way that will
show you more of their faces and edges in the rendered view, we’ll take a closer look at what Face Culling
and Draw Modes do to your geometry. We will save Material object creation and application for its own in
Chapter 13 ; Material object creation is a core 3D topic (texture mapping) and should be treated as its own
topic, as a 3D object’s shading determines its visual quality.
Next, let’s take a look at Draw Modes (called rendering modes in most 3D software packages) so that you
can look at the 3D wireframe representations of your objects as you develop your pro Java 9 games.


Shape3D Draw Mode Property: Solid Geometry and Wireframe


Now that we have the three primary JavaFX primitives arrayed across our screen, let’s take a look at the
drawMode property of the Shape3D superclass, which is inherited by each of these primitives. This property
uses a constant from the DrawMode class, as you may have guessed already, and the two constants available
currently are DrawMode.FILL and DrawMode.LINE. The FILL constant gives you a Solid Model Geometry
representation, and the LINE constant gives you a Wireframe Model Geometry representation. We are
going to use the .setDrawMode(drawMode) method call in this section to change our three primitives from
being solid models to being wireframe models so that we can change the resolution or divisions of the
wireframe and see what that does and so that we can rotate the Sphere around the X dimension to see how
its wireframe construction looks and how the divisions attribute changes how it looks (renders) in your 3D
Scene. First, however, I am getting a bit tired of looking at these primitives in the upper-left corner of the 3D
scene, so we are going to use .setTranslateZ(-500) to move the Camera object 100 percent closer (or scale
the primitives up in size 100 percent) and use the .setTranslateY(300) method to center the primitives in the
horizontal center of the view. Later we will use the .setTranslateX(-300) method call to center the primitives
in the vertical center of the view.
Open your .start() method and your gameButton event handling code block and change the
.setTranslateZ() method call value from -1000 to -500. Then add a .setTranslateY() method call off the
camera object and pass it a -300 scene units data value, as shown in Figure 12-11 as well as in the following
Java code statements:


camera.setTranslateZ(-500);
camera.setTranslateY(-300);

Free download pdf