Creating Ground Cover
Ground cover is the 2D scenery that decorates a landscape. An item of ground cover is represented by a transparent GIF pasted onto a quad that stands on the terrain's surface and is always oriented towards the viewer. The quad is implemented as a four-sided QuadArray
inside a GroundShape
object (a subclass of OrientedShape3D
). The pasting uses blended transparency so the quad is invisible and only the opaque parts of the GIF are rendered.
Typical ground cover includes trees, bushes, and road signs. Such elements will appear many times inside a scene, and it would be inefficient to create a separate shape for each one. Instead, the GroundShape
object (e.g., a tree) is embedded in a SharedGroup
node, which allows the geometry to be shared by multiple TransformGroups
. Each TransfromGroup
specifies a location for a particular ground cover element, but the object is a shared node.
The approach is illustrated by Figure 27-19.
Figure 27-19. A subgraph using a shared GroundShape object
Since a GroundShape
object is attached to landBG
, terrain coordinates can be used to set its position inside the landscape.
The constructor for Landscape()
adds ground cover by calling:
GroundCover gc = new GroundCover(fname); landBG.addChild( gc.getCoverBG() );
The GroundCover
object, gc
, manages the creation of the subgraph holding the ground cover items. The call to getCoverBG()
returns the ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.