Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 3 ■ advanCed 3d Content rendering: 3d asset ConCepts and prinCiples

Both origins and pivots represent that point in space using an axis. This axis can be moved and looks
like a star in 3D software and like a plus symbol in 2D software. In fact, an axis is really a separate object
within a 2D shape or 3D geometry, and it can even be animated just like every other 2D or 3D object element
can, using JavaFX and Java code, to create special effects relating to how the shape or geometry rotates over
time. There’s also a “dummy point” used for special effects and advanced applications that is very similar
to a pivot but used for other purposes that is also represented using an axis. You’ll see later during the book
how important this axis element is for Java games.


Connect the 2D Dots: Vector Lines and Spline Curves Connect Your


2D Vertices


Since vertices are mathematically infinitely small, making these tiny dots essentially invisible, you will need
to connect them to make something that you can visualise. The simplest incarnation of this is a straight line,
known as a vector (also sometimes termed a ray in 3D rendering). A vector starts at one vertex and projects
out until it hits a second vertex, which defines the direction of the vector. A vector is inherently straight, so it
would be considered a line, not a curve. A curve is mathematically far more complex than a straight line is,
as you are about to see.
Since we often want an infinitely smooth curve as part of our 2D shape or 3D geometry, we will need to
use a different type of mathematical construct, called a spline. The reason why a spline is infinitely smooth
is because it is a curvature that is defined using a mathematical equation, the resolution of which can be
increased by using smaller numbers such as by using floating-point numbers rather than integers, for all of
you computer programmers out there (which I am hoping is everyone, given the professional nature of this
Pro Java 9 Games Development book).
The mathematical foundation for most types of splines is called the Bezier curve, which was named
after the mathematician Pierre Étienne Bézier, who was a French engineer who lived from 1910 to 1999.
Pierre was one of the founders of the fields of 3D solids, geometric modeling, and physical modeling, as well
as the leader in the specialty area of representing curves, especially in CAD CAM and 3D systems. There
are several mathematical formats for Bézier curves, including cubic or quadratic Bézier curves, which are
defined using different types of mathematical equations that define how each curve is to be constructed.
The simplest of these curves is the Linear Bézier curve, which can be used to create straight-line
(vector) rays and which uses only two control points to define your curve. If you can get your shapes defined
using only Linear Bezier curves, less processing and memory will be used by your game or IoT application.
This is because fewer control points will need to be processed. As you can see in the top part of Figure 3-1,
Inkscape draws control points and their handles using blue. If you want to try this in Inkscape, click the
Spline/Line tool, shown on the left of Figure 3-1, and click to create a point, click a second point somewhere
else to add a straight line, and then click a third point and drag to create a curve! It’s fairly easy once you get
the hang of it; that being said, the truth is, everything you learn in this book takes tons of practice to master
at a professional level.
To adjust the curvature of the Linear Bezier curve, you can move each of the two handles that come
out of the vertex you just added. If you want a straight line, just click to add vertices, and straight lines will
connect them. On the other hand, if you want to make a curve, click down to add the vertex, and with the
mouse still clicked (keep your mouse depressed), drag out the Bezier curve control point handles.
The next most complex type of Bezier curve is a Quadratic Bézier curve, named after the type of
quadratic mathematical algorithm that is used to prescribe it. A Quadratic Bezier has three control points
instead of two, so it is more processing intensive but provides more control over “tweaking” the curvature of
the curve by using the handles.
The most complex is the Cubic Bézier curve, named after the type of cubic mathematical algorithm
that is used to prescribe it, and it has four control points, instead of three, so it is even more processing
intensive, but again, it provides even more control over tweaking the curvature of the curve.

Free download pdf