Figure 18-3 shows the methods defined in
Figure 18-3. WrapTour3D methods
WrapTour3D sets up the checkered floor and lights (similar to previous Wrap classes). However,
addBackground() uses a scaled image, and there are three new methods:
addAlien(). These methods are called by
createSceneGraph() to add scenery, obstacles, and sprites to the scene.
The application's scene graph is shown in Figure 18-4. Its details will be explained in subsequent sections.
Figure 18-4. Scene graph for the Tour3D scene
A Java 3D
Background node can use a solid color, an image, or a geometric shape (e.g., a sphere or a box) with an image rendered onto it. Here, the application utilizes a picture of a hazy sky, 400 × 400 pixels in size, stored in bigSky.jpg:
TextureLoader bgTexture = new TextureLoader("models/bigSky.jpg", null); Background back = new Background(bgTexture.getImage()); back.setImageScaleMode(Background.SCALE_FIT_MAX); // fit the display back.setApplicationBounds( bounds ); sceneBG.addChild( back );
The image is loaded as a texture and then converted to
ImageComponent2D form for the
Background object. Java 3D 1.3 added several scaling modes to
Background; the one employed here scales the image to fit the display ...