< Zurück | Inhalt | Weiter >

13.3 ExplodeBehavior

The constructor for the ExplodeBehavior is as follows:

public ExplodeBehavior( Shape3D shape3D,

int nElapsedTime, int nNumFrames, ExplosionListener listener )

The behavior attaches to the Shape3D specified and explodes the object after nElapsedTime milliseconds (figure 13.2). The explosion animation takes nNumFrames to complete, and, once complete, a notification is passed to the caller via an ExplosionListener interface method.


Figure 13.2 The ExplodeBehavior: Frame 1, the original Shape3D; frames 2–4, some frames of the explosion animation

To model the simple explosion, the behavior switches the Shape3D’s appearance to rendering in points (by modifying the PolygonAttributes) and sets the point size (using PointAttributes). The transparency of the Shape3D is then set using TransparencyAttributes. The vertices of the Shape3D’s geometry are then moved away from the origin with a slight random bias in the x+, y+, and z+ direction.

The ExplodeBehavior moves through the following life cycle:

1. The behavior is created.

2. Initialize is called by Java 3D.

3. WakeUp condition is set to be WakeupOnElapsedTime( n milliseconds ).

4. processStimulus is called after n milliseconds.

5. The Appearance attributes are modified for the Shape3D.

6. The WakeUp condition is set to WakeupOnElapsedFrames( 1 ).

7. processStimulus is called after every frame.

8. The GeometryArray’s vertex coordinates is modified.

9. Coordinates are reassigned.

10. If frame number < number of frames for animation

Set the WakeUp condition to WakeupOnElapsedFrames( 1 )

11. Else

Restore the original Shape3D Appearance and coordinates.

Notify the ExplosionListener that the behavior is done.

Call setEnable( false ) to disabled the behavior.

The processStimulus method for the ExplodeBehavior is as follows.


From ExplodeBehavior.java