import javax.media.j3d.*;
import java.util.*;

/**
 * Simple behaviour for updating a bunch of objects "simultaneously";
 * in this example, there are three objects: cat, dog, mouse
 *
 * @author Josh Richmond
 */
public class CatDogMouseBehaviour extends Behavior {

    /** Wakeup every frame (actively) **/
    private WakeupOnElapsedFrames conditions = 
	new WakeupOnElapsedFrames(0, false);
    /** We will be affecting these transform group **/
    private TransformGroup[] dogTG, catTG, mouseTG;
    /** These will be the values of the TG's **/
    private Transform3D dogT, catT, mouseT;
  
    /**
     * Pass references to the TG's in the scene graph
     */
    public SensorArrayBehaviour(TransformGroup cat, TransformGroup dog,
				TransformGroup mouse)
    {
	dogTG = dog;
	catTG = cat;
	mouseTG = mouse;
	
	// initialise the transforms
	dogT = new Transform3D();
	catT = new Transform3D();
	mouseT = new Transform3D();
	
	// get initial positions from your methods
	updateData();
    }

    /**
     * Set our wakeup condition.
     */
    public void initialize() 
    {
	wakeupOn( conditions );
    }

    /**
     * Set all the transforms at once. Is this guaranteed to be atomic (i.e,
     * within one frame)?
     */
    public synchronized void processStimulus( Enumeration criteria ) 
    {
	updateData();
	dogTG.setTransform(dogT);
	catTG.setTransform(catT);
	mouseTG.setTransform(mouseT);
	wakeupOn( conditions );
    }

    /**
     * Update your next positions here by whatever means you'd like.
     */
    protected void updateData()
    {
	// These will change the transforms dogT, catT and mouseT
	updateDog();
	updateCat();
	updateMouse();
    }
}
