Game Development Reference
In-Depth Information
25. After this, return the
geometry
field, which might be null.
26. Coming back to the
WaterFieldControl
class, if the returned
geometry
variable is not null, set its location and attach it to the
water
node as follows:
g.setLocalTranslation(x, -1f +
cell.getTerrainHeight() + cell.getAmount() * 0.5f, y);
water.attachChild(g);
27. Apply the material to the
water
node and then batch it to increase the perform-
ance before attaching it to the control's
spatial
, as follows:
water = GeometryBatchFactory.optimize(water, false);
water.setMaterial(material);
((Node)spatial).attachChild(water);
28. To finish things off, update the
controlUpdate
method to call
up-
dateCells
and
createGeometry
.
29. Now this can be used with a few lines in the application class. First of all, create a
new
WaterFieldControl
class that we'll add to a
Node
class that contains a
Terrain
instance.
30. Next, we need to create the material for the water. This can be as simple as creat-
ing a
Material
instance with
Unshaded MaterialDefinition
and ap-
plying a blueish color to it or an advanced custom shader. It is then applied to the
WaterFieldControl
class via the
setMaterial
method.