Finding or writing the appropriate behavior class for your application is the beginning of writing an interactive Java 3D program. This tip covers the programming issues in adding behavior objects to programs.

The next list summarizes the steps for using a behavior object in a recipe.

  • prepare the scene graph (by adding a TransformGroup or other necessary objects)
  • insert behavior object in the scene graph, referencing the object of change
  • specify a scheduling bounds (or SchedulingBoundingLeaf)
  • set write (and read) capabilities for the target object (as appropriate)

The sample illustrates this recipe,it renders a single ColorCube that rotates when any key is pressed.

 public BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objRotate = new TransformGroup();

    objRotate.addChild(new ColorCube(0.4));
    // Create the SimpleBehavior object
    SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate);
    myRotationBehavior.setSchedulingBounds(new BoundingSphere());
    // Add it into the scene


    return objRoot;