Backgrounds

Backgrounds are very useful in providing a sense of immersion in virtual environments and have other special uses in some areas of visualization. Java 3D provides three different types of backgrounds, and they are listed in Table 11.6.

Table 11.6. Different Types of Backgrounds and Their Usage
Background Type Usage
Color Specifies a basic color background.
Geometry Tesselates geometry onto a sphere surrounding the entire scene.
Image Uses an image as the background.

The Background Node contains a Bounds object that specifies the region in which the Background is active. Thus, whenever the ViewPlatform intersects the Bounds object, the Background is rendered. Note that it is possible to specify multiple Backgrounds that become active when the ViewPlatform is in different locations in the environment. In this case, the Background closest to the ViewPlatform is active even if the ViewPlatform intersects more than one. An example is provided next.

Using a Colored Background

A colored background is by far the easiest to implement. The following code can be added directly into the createScene() method of BasicRecipeJ3D.java:

//create a large sphere to contain applications bounds
BoundingSphere bounds =
     new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

//make a custom color
Color3f bgColor = new Color3f(0.2f, 0.05f, 0.28);
Background bg = new Background(bgColor);
bg.setApplicationBounds(bounds);

//add the background node to the scene graph
objRoot.addChild(bg);

Image Backgrounds

Image backgrounds add an additional degree of realism except for the fact that the background is the same for all views of the environment. For backgrounds like stars or clouds, the static nature of an image background isn't a large problem; however, in many virtual environment applications, the programmer might want to use background geometry (see the next section) in order to provide a different view for each orientation. The following code snippet demonstrates how to add a Background to the scene graph:

TransformGroup group = new TransformGroup();
. . .
TextureLoader l = new TextureLoader("clouds.jpg", this);
ImageComponent2D image = l.getImage();
. . .
Background back = new Background();
Back.setImage(image);
. . .
back.setApplicationBounds(bounds);
group.addChild(back);

Using Background Geometry

Using background geometry is slightly more complicated than using color or image backgrounds; however, the improvement in realism might be well worth it. The primary advantage is that the viewer sees different parts of the background from different view perspectives.

To create background geometry, it is necessary to add the elements to a BranchGroup and add BranchGroup to the scene graph.

For example, if the programmer wants a city scene in the background, we could use the following code segment:

TransformGroup tg = new TransformGroup();
BranchGroup branch = createBackground();
Background back = new Background();
back.setGeometry(branch);
back.setApplicationBounds(bounds);
group.addChild(back);
. . .
public BranchGroup createBackground() {
   BranchGroup objRoot = new BranchGroup();
return objRoot;
}

Note that the snippet doesn't show the creation of the BranchGroup containing the city scene, but only show the structure necessary to set up background geometry.

Multiple Backgrounds

It is possible to specify multiple backgrounds that are differentially activated when the ViewPlatform is within a certain range. Remember that when multiple backgrounds exist, ava 3D automatically chooses the one nearest the ViewPlatform.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset