Besides the initialization
work done in the starter project [1.1.6], this method creates the scene
and initializes the rotator.
In the create scene method, we create an effect that will paint black
the lines of the meshes [1.1.6] with the following call:
BCColorSet colorSet = new
BCColorSet(Color.Black);
BCDynamicEffectVisitor colorSetter =
new BCDynamicEffectVisitor(colorSet.getFunction("Shader.ColorSet"),
colorSet, 0);
Then
the plane is created using the ProceduralModelers
[1.1.6], The call to create the plane is:
plane =
ProceduralModelers.PLANE_MODELER.createPlane
(4,
4, 25, 25, new Vector3(0, 0, 0),
new BCVertexPosContainer(),
1);
Where the first parameter is the number of vertices in the X axis, the
second parameter is the number of vertices in the Y axis, the third
parameter is the length of each column, the fourth parameter is the
height of each row, the fifth parameter is the center of the plane, the
sixth parameter is the vertex container, which will be discussed later
in the tutorials and the last parameter is the texture scale, which
will also be discussed later.
Then the sphere is created [1.1.6], after that the cylinder is created
with the following call:
cylinder =
ProceduralModelers.CYLINDER_MODELER.createCylinder(
5,
6,
1,
1, new BCVertexPosContainer());
The first parameter is the number of divisions in a log2(n) fashion,
the second parameter is the length of the cylinder, the third parameter
is the radix of one of the caps of the cylinder, the fourth parameter
is the radix of the other cap, finally, the fifth parameter is the
vertex container , which will be discussed on another tutorial.
Now we are going to elaborate further on the visit method of the mesh.
A mesh doesn't have directly the vertices and faces that make the
shape, instead, a mesh is a collection of parts, in the example image,
the mesh can have 3 parts, the body part, the accessories part and the
weapons part. Each part does have the vertices and faces.
If
we want all the parts to have the same effect, we would need to iterate
over the parts and assign them the effect, but what if we want all
parts to have the same material?, ok we iterate over the parts and
assign them the material, ok, now I want all the parts to have the same
textures, etc.
A year later I have a lot of cycles in my applications and I
discover that a hash map is a better way to represent the collection of
parts in a mesh; what can I do? Basically you can kiss your hash map
idea good bye. Designing software prevents this kind of issues, and the
use of design patterns is a powerful tool in software design. In
BetaCell, when we want to apply the same operation over all the the
parts of a mesh, we use a visitor pattern. A visitor, as it's name
implies, visits all the parts of a mesh taking the same action in each;
for example, the dynamic effect visitor adds the specified effect part
to the mesh's effect.
After the creation of each mesh, the mesh is initialized and the "paint
it black" effect is set to all it's parts.
plane.visit(colorSetter);
Now, the rotator is just a class that holds and maintains rotation
information over time, heres the line that creates it:
rotator = new BCProceduralRotator(0, 0,
0.1f, 0, 1000);
The
first parameter is the radix of the rotator, the second, third and
fourth are how much the rotator rotates over the x, y and z axises
respectively, the last one is a modulator that makes the rotation
slower.