GameSpawn Site Map
GameSpawn Update mailing list
Lee's Lessons



Today's topic deals with the powerful, yet sometimes complex, world of Java3D behaviors. Behaviors are what make the objects in Java3D 'do things'. These can be as simple as having an object just spin around constantly to complex behaviors such as strange animations and paths, morphing, and much more. Today I'm going to start off with a simple example just to show you how to add behavior to an object.

The screen is the same one as yesterdays. It is just a green cube. The user can then click on it and rotate it and move it around and such. This, along with the previous examples, form the basis of almost all Java3D scenes.

The important code in this example is:

objTrans.setCapability ( TransformGroup.ALLOW_TRANSFORM_WRITE );

objTrans.setCapability ( TransformGroup.ALLOW_TRANSFORM_READ );

objTrans.setCapability ( TransformGroup.ENABLE_PICK_REPORTING );

This gives the objects in that transform group the ability to change at runtime. It also enables pick reporting which allows it to be referenced through an event type system such as a mouse click, etc.

PickRotateBehavior behavior = new PickRotateBehavior(objRoot, canvas, bounds, PickObject.USE_BOUNDS);


This code is added to the branch group. It tells the Java3D internal compiler (which compiles the scene) that this branch group can have pick behavior. This pick behavior is the mouse events I mentioned before. So any branch group that has any object that can move in it needs to have some type of behavior node added to it. Within that branch group, you need to add the appropriate behavior to any transform group you want to perform a certain way.

I updated my Java3D to 1.2. This does have some deprecated methods so I am going to have to go back and see how Behaviors have changed in Java3D.

Michael C. Lee, Jr.