Skip to Main Content
Killer Game Programming in Java
book

Killer Game Programming in Java

by Andrew Davison
May 2005
Intermediate to advanced content levelIntermediate to advanced
998 pages
26h
English
O'Reilly Media, Inc.
Content preview from Killer Game Programming in Java

Examining a Model's Scene Graph

After loading the model, WrapLoaderInfo3D's next main task is to traverse the model's scene graph and report on its structure. Walking over the graph is easy due to the parent-child relationship between the nodes and that all the nodes are subclasses of a single superclass, SceneGraphObject . A simplified inheritance hierarchy is shown in Figure 16-8.

As mentioned in Chapter 14, Leaf nodes are subclassed in various ways to obtain Shape3D and environment nodes for lighting, backgrounds, sound, and so on. The subclasses of Group include BranchGroup and TransformGroup, which may have their own children (Group and/or Leaf nodes). NodeComponent objects are used to store information in nodes, such as Geometry and Appearance attributes, and may be shared between nodes.

Some subclasses of SceneGraphObject

Figure 16-8. Some subclasses of SceneGraphObject

A simple algorithm for traversing a scene graph is shown here:

    examineNode(node) {
      if the node is a Group {
        print Group info;
        for each child of the node
          examineNode(child);  // recursive call
      }
      else if the node is a Leaf
        if the node is a Shape3D {
          examine its appearance;
          examine its geometry;
        }
        else print Leaf info
      }
      else print general node info;
    }

This pseudocode is the heart of the examineNode() and examineShape3D() methods in WrapLoaderInfo3D. The algorithm is simplified by concentrating on a few node types, principally Shape3D, and by considering ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Game Development with LibGDX: From Beginner to Professional

Java Game Development with LibGDX: From Beginner to Professional

Lee Stemkoski

Publisher Resources

ISBN: 0596007302Supplemental ContentErrata Page