Creating the Scene

Figure 18-3 shows the methods defined in WrapTour3D.

WrapTour3D methods

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: makeScenery(), addTourist(), and 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.

Scene graph for the Tour3D scene

Figure 18-4. Scene graph for the Tour3D scene

Adding a Background Image

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 ...

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.