Pro Java 9 Games Development Leveraging the JavaFX APIs

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

Notice when you move the Camera object, it stays looking straight ahead, whereas in 3D software
packages, there is a Camera “target” that stays locked in the center of the scene or on a 3D object in the
Scene. In JavaFX, the Camera object is “fixed” with a straight line (called a ray or vector) that emanates
from the back of the camera out through the front, going out to infinity in the direction the camera object is
pointed in. So, in 3D software, if you move the camera up, its field of view rotates down, and there is a link (or
line) between the camera and its subject.
If you wanted this behavior in JavaFX, you would have to rotate the camera manually, as the JavaFX
Camera superclass currently has no specifyTarget attribute (target functionality). We will be looking at the
PerspectiveCamera object and how to leverage it in a more advanced way in your 3D Scene as the book
progresses because cameras are an important aspect of an i3D scene and an important tool for use in the pro
Java 9 i3D games development process.
Before we render the 3D Scene again, since we know from our code that it is now going to be centered
well enough for us to look at attributes such as divisions and face culling and see how these affect the
polygons that make up the 3D primitives, let’s use the overloaded (second) Sphere(size, divisions)
constructor method format and reduce the mesh resolution of the Sphere object to optimize the amount of
memory that it takes to hold this 3D object. You will also rotate it forward so that you can see the top of the
Sphere’s construction and also reduce the resolution of the Cylinder by 100 percent, from 24 to 12 divisions.
I always use a division value that is divisible by four (90 degrees times 4 is 360), and half of the divisions
are not even rendering if face culling is turned on. This can all be accomplished by using the following Java
statements, which are highlighted in (and at the bottom of ) Figure 12-15:


sphere = new Sphere(100, 12 );
sphere.setRotationAxis(Rotate.X_AXIS);
sphere.setRotate( 90 );
sphere.setDrawMode(DrawMode.LINE);


Figure 12-15. Construct your Sphere with 12 divisions, X rotate it 90 degrees, and reduce your Cylinder to 12
divisions

Free download pdf