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

Building the Model's Scene Graph

Figure 16-22 shows the scene graph after dolphins.3ds has been loaded (the three dolphins model). The PropManager object creates the long branch shown on the right of the figure, consisting of a chain of four TransformGroup nodes and a BranchGroup with three Shape3D children. The loaded model was translated into the BranchGroup and its children (each dolphin in dolphins.3ds is represented by a Shape3D node).

PropManager utilizes four TransformGroups to deal with different aspects of the model's configuration:

moveTG

Handles the translations

rotTG

For rotations

scaleTG

For scaling

objBoundsTG

Carries out the scaling and possible rotation of the model when it's first loaded

Scene graph for loaded dolphins

Figure 16-22. Scene graph for loaded dolphins

The reason for this separation is to process distinct operations in different nodes in the graph. This reduces the overall complexity of the coding because I can take advantage of the hierarchy of local coordinate systems used by the TransformGroup nodes.

A TransformGroup's local coordinate system means it always starts at (0, 0, 0) with no rotation or scaling. However, when Java 3D renders the node into the virtual world, it must obtain its global coordinates (i.e., its virtual world position). It does this by calculating the combined effects of all the ancestor TransformGroup nodes operations upon the node.

For example, if the moveTG node ...

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