Game Development Reference
In-Depth Information
Getting ready
This is an advanced recipe that requires an understanding the generation of a basic terrain,
which can be found earlier in the chapter, and the building blocks of meshes and how to
create custom meshes.
Before we begin, we will create a class called
CubeUtil
and populate it with some
shaped data that we will need later. Since each of the cells is of a box shape, we can borrow
some fields from the
Box
and
AbstractBox
classes and save some time in setting it up.
Just copy the
GEOMETRY_INDICES_DATA
,
GEOMETRY_NORMALS_DATA
, and
GEOMETRY_TEXTURE_DATA
fields to the
CubeUtil
class.
At the bottom of the class, there is a method called
doUpdateGeometryVertices
that
contains a float array. Copy this float array too and call its vertices. This array contains data
for the 24 vertices needed to create a cube with normal. It in turn relies on references to
eight original vertex positions. We can get these from the
AbstractBox
class and the
computeVertices
method. The
Vector3f
center referenced here can be replaced
with
Vector3f.ZERO
. The
xExtent
,
yExtent
, and
zExtent
parameters can be re-
placed with
0.5f
to get a square box with
1f
sides.