Java Reference
In-Depth Information
Figure 17. A background based on a 2D image
1. import com.sun.j3d.utils.image.*;
2. public void flatImageBackground (BranchGroup branchRoot)
3. {
4. Background myBackground = new Background();
5. myBackground.setImage(new TextureLoader("cloud.jpg", this).getImage());
6. myBackground.setImageScaleMode(Background.SCALE_FIT_ALL);
9. myBackground.setApplicationBounds(bounds);
10. branchRoot.addChild(myBackground);
11. }
Step back
Initial position
3D world. Also, the option SCALE_FIT_ALL has been selected so that the image will
fill the entire window regardless of the display resolution of the monitor and the pixel size
of the image. Other options as indicated in lines 7 and 8 are also possible. Specifically,
SCALE_REPEAT will not scale the image to match the window size even though there is a
mismatch in their resolutions. Instead, the image will be used in its original pixel resolution,
but will be repeated in both horizontal and vertical directions to fill the entire window.
To have a more realistic background that befits a 3D environment, a relevant geometry
model must be used for its construction (Creating a geometric background in Java3D,
2006). This way, as the user navigates around in the virtual 3D world, the background
will change in an appropriate manner. A common geometry for creating a realistic 3D
background would be that of a sphere with effectively infinite size, or size that enclose all
the visual objects of interest.
Figure 18 shows an example code segment and the result obtained based on this ap-
proach. Specifically, to create a background based on spherical geometry, we need to create
a background node myBackground and a branchgroup branchRoot, add the appropriate
geometry to the branchgroup, use setGeometry to set the branchgroup into backgroup,
set the application bound, and then add the background node to the branchroot. With this
background, a better and more realistic visual effects can be obtained as the user navigates
in the 3D world. In particular, while the background, at infinite distance effectively, will
Search WWH ::

Custom Search