O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adjusting a Model's Shape Attributes

After reporting on the model's scene graph, WrapLoaderInfo3D's last task is to modify the model's appearance according to the user's supplied adaptation number. Many aspects of a model can be easily changed once its individual Shape3D nodes are accessible. This

The dolphins modeldD

Figure 16-9. The dolphins modeldD

can be done with a variant of the examineNode() pseudocode, concentrating only on Leaf nodes that are Shape3Ds:

    visitNode(node) {
      if the node is a Group {
        for each child of the node
          visitNode(child);  // recursive call
      }
      else if the node is a Shape3D
         adjust the node's attributes;
    }

This pseudocode is the basis of visitNode() in WrapLoaderInfo3D.

The manipulation of the shape's attributes is initiated in adjustShape3D(), which uses the adaptation number entered by the user to choose between six possibilities:

0 Makes the shape blue with makeBlue()

1 Draws the shape in outline with drawOutline()

2 Renders the shape almost transparent with makeAlmostTransparent()

3 Lays a texture over the shape with addTexture()

4 Makes the shape blue and adds a texture by calling makeBlue() and addTexture()

Anything else

Makes no changes at all

Turning the Shape Blue

Figure 16-10 shows the rendering of the dolphins model after being turned blue.

Blue dolphins

Figure 16-10. Blue dolphins

The Material ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required