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