Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 3 ■ advanCed 3d Content rendering: 3d asset ConCepts and prinCiples


by 3D software packages back in the Amiga days. The 3D software package that originated this design and
development approach was Real 3D, by Realsoft OY, which today is called Realsoft 3D. Fortunately, JavaFX 9
also has an extensive Scene Graph API, which makes it perfect for creating both Interactive 3D and
Interactive 2D games and IoT applications.


Interactive 2D Assets: 2D Vector Content Concepts


There is one other type of 2D asset that we didn’t cover in detail in Chapter 2 as its concepts relate directly to
3D, so I decided to logically put this information at the beginning of this chapter so the information flowed
together better. 2D and 3D are very similar in their use of vertices and splines, which we will be learning
about next. 2D uses the X ,Y dimension, which is a flat plane (or planar area, if you will), and 3D uses the
X,Y,Z dimension (which is a cubic area, if you will).
Therefore, in this section, we will look at how to create 2D vector illustration by placing points, or
vertices, in 2D space and then connecting them together by using straight lines, or curved splines, and filling
closed shapes with solid colors, color gradients, or tiling image patterns. JavaFX 9 offers a plethora of
2D classes supporting each of these 2D elements, as well as a SVGPath class, used for importing all of these
2D data elements, if you choose to use Inkscape.
The 2D assets or objects that you will use in Java using the JavaFX APIs are generally called shapes,
although they are technically also geometry since shapes are inherently geometric! Typically in the industry,
3D is referred to as 3D Geometry, and 2D is referred to as 2D Shapes. The foundation of both 2D and 3D
assets start with points in space called vertices. These are connected with (straight) lines or (nonstraight)
curves. Let’s look at these next.


Points on a Plane: 2D Vertices, Model Reference Origin, Pivot Point,


Dummy Point


Now don’t get excited—this is not the sequel to Snakes on a Plane; it’s just a discussion regarding the
foundation of 2D shapes, which, like 3D models, are based on points in space. Since 2D space consists of an
X,Y plane, we place points on a 2D plane. Each point in space is called a vertex in professional terminology,
since this is Pro Java 9 Games Development after all. You can use these vertices both in planar X,Y space for
your 2D shape creation and in cubic X,Y,Z space for 3D geometry creation, which we will be covering later
during this chapter.
The reason I subtitled this section “Points on a Plane” is because vertices are placed in 2D space using
an X,Y grid on a 2D plane and in an X,Y,Z cubic area in 3D space. The origin of this 2D grid is located at 0,0.
Usually this is the upper-left corner of the screen, and for the 3D cubic area, this referencing origin would be
located 0,0,0.
For both 2D shapes and 3D objects, this origin can be relocated, so different packages will reference
this grid from a different corner of the plane or cube. You will see this later in JavaFX, which has different
ways to reference coordinates. Another reference point inside of that plane or cubic area is used for the
rotation of your 2D or 3D object and is called the pivot point.
For instance, if you wanted your hammer 2D shape (or 3D model) to rotate near the end of the handle,
as it would be rotated in real life, you would accomplish this by moving the pivot from the default (center)
position in your 2D (or 3D) modeling space down toward the end of the handle of the hammer. For this
application, your pivot point will then become the center for the axis for that object. The pivot point is
a referencing origin for how the asset needs to be rotated, whereas the grid (space) origin will provide a
reference for how the points will be positioned relative to each other. Thus, a rotation algorithm will use both
the modeling grid origin as well as the pivot point position. These are usually different point coordinates;
however, it is possible that they can be the same point, in some scenarios.

Free download pdf