Java Reference
In-Depth Information
In addition to using lighting and fog to enhance a virtual 3D world, the choice of a suitable
background is also very important to enable interesting foreground 3D objects to stand out
and be seen in the right context.
In Java 3D, a black background or window will be used if no background node is active,
while generally, three types of non-trivial backgrounds may be used. Specifically, a simple
constant color background, a more complicated background using a flat 2D image, or a more
interesting background based on appropriate geometrical construction can be specified.
In the creation process, all these three types of background require a relevant color, im-
age or geometry specification as well as a bounding volume that controls when and which
background will be activated. Note that more than one background node may be added to
the scene graph and the node, which is closest to the current one will be rendered.
Figure 16 shows the code segment and result for adding a simple constant color back-
ground node to the branch root. Note that regardless of how we navigate in the created 3D
world, the background is static, dull, and has the same color.
Rather than using a simple constant color background, a slightly more complicated but
more interesting background will be to use one based on an imported 2D image. Figure 17
shows how this can be done as well as the results obtained. Note that while the background
is more interesting and impressive, it will not change even as we navigate around in the
Figure 16. Adding a constant color background and result
public void constantColorBackground (BranchGroup branchRoot)
Color3f backgroundColor = new Color3f(0.05f, 0.05f, 0.5f);
Background myBackground = new Background();
Initial position
Step back
Search WWH ::

Custom Search