Hi there,
I'm having a problem with the execution of a behaviour
based on collision detection. Two objects collide in
my scene and a switch takes place on one object and
writes to a switch for the other object. I have
attached a BoundingLeaf to each object. These bounding
leaves take parameters from two separate bounding
boxes which are quite small so that the objects have
to collide in an exact position before the switches
can take place. The behaviour is executed on collision
entry. However, when I run the scene, the switches
take place straight away which suggests to me that the
application is using the universal application
bounding sphere (which encompasses the entire world).
It would appear that the application is ignoring the
bouning leaves set up for the collision detection.
Could someone please help with this as I've run out of
solutions for this!!! I have attached both the
behaviour file and the main application file if
someone wants to take a look. The application will not
run with these two files but there are too many to
send over email.
Thanks in advance,
Regards,
Jennifer.

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.picking.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import ncsa.j3d.loaders.ModelLoader;
import ncsa.j3d.loaders.Loader_WRL;
import ncsa.j3d.loaders.Loader_IOB;
import ncsa.j3d.loaders.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.image.TextureLoader;
import javax.media.j3d.*;
import java.io.*;


public class MyLoaderTest1 extends Applet implements ActionListener {

        protected Button exitButton = new Button("Exit");

    private SimpleUniverse u = null;
    private String filename = "MyModels/myTable.wrl";

    private String filename1 = "MyModels/bottle_yellow_starch.wrl";
    private String filename1a = "MyModels/bottle_empty.wrl";

    private String filename2 = "MyModels/dropper_empty.wrl";
        private String filename2a = "MyModels/dropper_yellow_starch.wrl";
        private String filename2b = "MyModels/dropper_brown_iodine.wrl";

        private String filename3 = "MyModels/flask.iob";

        private String filename4 = "MyModels/test_tube_rack.wrl";

        private String filename5 = "MyModels/test_tube_empty.wrl";
        private String filename5a = "MyModels/test_tube_yellow_starch.wrl";

        Switch bottleSwitch;
        Switch dropperSwitch;
        Switch tubeSwitch;


    public BranchGroup createSceneGraph(Canvas3D canvas) {


                //Create the root of the scenegraph
                BranchGroup objRoot = new BranchGroup();

                //Create the bounding leaf node
                BoundingSphere bounds = new BoundingSphere( new Point3d( 0.0,0.0,0.0 ), 100.0 );
                BoundingBox bottlebounds = new BoundingBox( new Point3d(-0.9, 6.0, -0.9),new Point3d(0.9, 6.5, 0.9));
                BoundingBox tubebounds = new BoundingBox( new Point3d(-0.6, 3.1, -0.6),new Point3d(-0.6, 3.6, 0.6));
                BoundingBox flaskbounds = new BoundingBox( new Point3d(-0.5, 5.8, -0.5),new Point3d(0.5, 6.0, 0.5));


                // Attach picking behavior utlities to the scene root.
                // They will wake up when user manipulates a scene node.
                PickRotateBehavior behavior = new PickRotateBehavior(objRoot, canvas, bounds);
                objRoot.addChild(behavior);

                PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
                objRoot.addChild(behavior2);

                PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
                objRoot.addChild(behavior3);


                //NEW TRANSFORMGROUP FOR MYTABLE.WRL
                TransformGroup objTrans1 = new TransformGroup( );
                //enable modification of transform at runtime
                objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objTrans1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

                Transform3D tr = new Transform3D();
        objTrans1.getTransform( tr );
        tr.setTranslation(new Vector3d(0.0, -10.0, -48.0));
        tr.setScale( 0.5);
        objTrans1.setTransform( tr );

                // load the object file
                Scene s = null;
                Shape3D shape = null;

                // read in the geometry information from the data file
                ModelLoader  objFileloader = new ModelLoader();

                        try
                        {
                                s = objFileloader.load(filename);
                        }
                        catch ( Exception e )
                        {
                                s = null;
                                System.err.println( e );
                        }

                        if( s == null )
                                System.exit( 1 );


                objTrans1.addChild( s.getSceneGroup( ) );
                objRoot.addChild( objTrans1 );



                //NEW TRANSFORMGROUP FOR BOTTLE.WRL
                TransformGroup objTrans1a = new TransformGroup( );
                objTrans1a.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objTrans1a.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
                objTrans1a.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

                objTrans1a.setCapability(TransformGroup.ALLOW_COLLISION_BOUNDS_READ);
                objTrans1a.setCapability(TransformGroup.ALLOW_COLLISION_BOUNDS_WRITE);

                bottleSwitch = new Switch(0);
            bottleSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

                BoundingLeaf bl = new BoundingLeaf (bottlebounds);

                Transform3D tra = new Transform3D();
        objTrans1a.getTransform( tra );
        tra.rotX(Math.PI*3/2.0d);
        tra.setTranslation(new Vector3d(-10.0, 1.0, -48.0));
        tra.setScale( 0.4);
        objTrans1a.setTransform( tra );

                // load the object file
                Scene s1 = null;
                Scene s1a = null;
                Shape3D shape1 = null;

                // read in the geometry information from the data file
                ModelLoader  objFileloader1 = new ModelLoader();

                        try
                        {
                                s1 = objFileloader1.load(filename1);
                        }
                        catch ( Exception e )
                        {
                                s1 = null;
                                System.err.println( e );
                        }

                        if( s1 == null )
                                System.exit( 1 );


                // read in the geometry information from the data file
                ModelLoader  objFileloader1a = new ModelLoader();

                        try
                        {
                                s1a = objFileloader1a.load(filename1a);
                        }
                        catch ( Exception e )
                        {
                                s1a = null;
                                System.err.println( e );
                        }

                        if( s1a == null )
                                System.exit( 1 );



                //objTrans1a.addChild( s1.getSceneGroup( ) );
                //objRoot.addChild( objTrans1a );
                bottleSwitch.addChild(s1.getSceneGroup());
                bottleSwitch.addChild(s1a.getSceneGroup());

                objTrans1a.addChild(bl);
                objTrans1a.addChild(bottleSwitch);
                objRoot.addChild(objTrans1a);




                // NEW TRANSFORM GROUP FOR MYDROPPER1.WRL
                TransformGroup objTrans1b = new TransformGroup( );
                objTrans1b.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objTrans1b.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
                objTrans1b.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
                dropperSwitch = new Switch(0);
            dropperSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

                Transform3D trb = new Transform3D();
        objTrans1b.getTransform( trb );
        trb.rotZ(Math.PI*3/4.0d);
        trb.setScale( 0.7);
        trb.setTranslation(new Vector3d(0.5, 7, -48));
        objTrans1b.setTransform( trb );

                // load the object file
                Scene s2 = null;
                Scene s2a = null;
                Scene s2b = null;

                //Shape3D shape2 = null;

                // read in the geometry information from the data file
                ModelLoader  objFileloader2 = new ModelLoader();

                        try
                        {
                                s2 = objFileloader2.load(filename2);
                        }
                        catch ( Exception e )
                        {
                                s2 = null;
                                System.err.println( e );
                        }

                        if( s2 == null )
                                System.exit( 1 );


                // read in the geometry information from the data file
                ModelLoader  objFileloader2a = new ModelLoader();

                        try
                        {
                                s2a = objFileloader2a.load(filename2a);
                        }
                        catch ( Exception e )
                        {
                                s2a = null;
                                System.err.println( e );
                        }

                        if( s2a == null )
                                System.exit( 1 );


                // read in the geometry information from the data file
                ModelLoader  objFileloader2b = new ModelLoader();

                        try
                        {
                                s2b = objFileloader2b.load(filename2b);
                        }
                        catch ( Exception e )
                        {
                                s2b = null;
                                System.err.println( e );
                        }

                        if( s2b == null )
                                System.exit( 1 );

                dropperSwitch.addChild(s2.getSceneGroup());
                dropperSwitch.addChild(s2a.getSceneGroup());
                dropperSwitch.addChild(s2b.getSceneGroup());

                objTrans1b.addChild(dropperSwitch);
                objRoot.addChild(objTrans1b);

                //objTrans1b.addChild( s2.getSceneGroup( ) );
                //objRoot.addChild( objTrans1b );






                // NEW TRANSFORM GROUP FOR FLASK.IOB
                TransformGroup objTrans1c = new TransformGroup( );
                objTrans1c.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objTrans1c.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
                objTrans1c.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

                objTrans1c.setCapability(TransformGroup.ALLOW_COLLISION_BOUNDS_READ);
                objTrans1c.setCapability(TransformGroup.ALLOW_COLLISION_BOUNDS_WRITE);

                BoundingLeaf bl1 = new BoundingLeaf (tubebounds);

                Transform3D trc = new Transform3D();
        objTrans1c.getTransform( trc );
        trc.rotX(Math.PI*3/2.0d);
        trc.setScale( 0.4);
        trc.setTranslation(new Vector3d(10.0, -3.0, -48.0));
        objTrans1c.setTransform( trc );

                // load the object file
                Scene s3 = null;
                Shape3D shape3 = null;

                // read in the geometry information from the data file

                ModelLoader  objFileloader3 = new ModelLoader();

                        try
                        {
                                s3 = objFileloader3.load(filename3);
                        }
                        catch ( Exception e )
                        {
                                s3 = null;
                                System.err.println( e );
                        }

                        if( s3 == null )
                                System.exit( 1 );



                objTrans1c.addChild( s3.getSceneGroup( ) );
                objTrans1c.addChild(bl1);
                objRoot.addChild( objTrans1c );





                // NEW TRANSFORM GROUP FOR TEST_TUBE_RACK.WRL
                TransformGroup objTrans1d = new TransformGroup( );
                objTrans1d.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objTrans1d.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

                Transform3D trd = new Transform3D();
        objTrans1d.getTransform( trd );
        trd.setScale( 0.1);
        trd.setTranslation(new Vector3d(0.0, -5.0, -48.0));
        objTrans1d.setTransform( trd );

                // load the object file
                Scene s4 = null;
                Shape3D shape4 = null;

                // read in the geometry information from the data file

                ModelLoader  objFileloader4 = new ModelLoader();

                        try
                        {
                                s4 = objFileloader4.load(filename4);
                        }
                        catch ( Exception e )
                        {
                                s4 = null;
                                System.err.println( e );
                        }

                        if( s4 == null )
                                System.exit( 1 );

                objTrans1d.addChild( s4.getSceneGroup( ) );
                objRoot.addChild( objTrans1d );










                // NEW TRANSFORM GROUP FOR TEST_TUBE.WRL
                TransformGroup objTrans1e = new TransformGroup( );
                objTrans1e.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
                objTrans1e.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
                objTrans1e.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

                objTrans1e.setCapability(TransformGroup.ALLOW_COLLISION_BOUNDS_READ);
                objTrans1e.setCapability(TransformGroup.ALLOW_COLLISION_BOUNDS_WRITE);

                tubeSwitch = new Switch(0);
            tubeSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

                BoundingLeaf bl2 = new BoundingLeaf (tubebounds);

                Transform3D tre = new Transform3D();
        objTrans1e.getTransform( tre );
        tre.setScale( 0.04);
        tre.setTranslation(new Vector3d(0.0, -2.0, -48.0));
        objTrans1e.setTransform( tre );

                // load the object file
                Scene s5 = null;
                Scene s5a = null;
                //Shape3D shape5 = null;

                // read in the geometry information from the data file

                ModelLoader  objFileloader5 = new ModelLoader();

                        try
                        {
                                s5 = objFileloader5.load(filename5);
                        }
                        catch ( Exception e )
                        {
                                s5 = null;
                                System.err.println( e );
                        }

                        if( s5 == null )
                                System.exit( 1 );


                ModelLoader  objFileloader5a = new ModelLoader();

                        try
                        {
                                s5a = objFileloader5a.load(filename5a);
                        }
                        catch ( Exception e )
                        {
                                s5a = null;
                                System.err.println( e );
                        }

                        if( s5a == null )
                                System.exit( 1 );

                tubeSwitch.addChild(s5.getSceneGroup());
                tubeSwitch.addChild(s5a.getSceneGroup());

                objTrans1e.addChild(bl2);
                objTrans1e.addChild(tubeSwitch);
                objRoot.addChild(objTrans1e);

                //objTrans1e.addChild( s5.getSceneGroup( ) );
                //objRoot.addChild( objTrans1e );






                // Add global lights to the content branch of the scenegraph.
                //First define the colours of the light
                Color3f alCol = new Color3f( 50.2f, 50.2f, 50.2f );
        Color3f dlCol = new Color3f( 0.7f, 0.7f, 0.7f );
                Vector3f lDir  = new Vector3f( -1.0f, -1.0f, -1.0f );

                //Define the ambient light
                AmbientLight aLgt1 = new AmbientLight( alCol );
                aLgt1.setInfluencingBounds( bounds );

                //Define the directional light
                DirectionalLight dLgt1 = new DirectionalLight( dlCol, lDir );
                dLgt1.setInfluencingBounds( bounds );

                DirectionalLight dLgt1a = new DirectionalLight();
                dLgt1a.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1a.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1a.setInfluencingBounds(new BoundingBox(new Point3d(-70.0, -70.0, -70.0),new Point3d(70.0, 70.0, 70.0)));
                dLgt1a.setEnable(true);

                /*DirectionalLight dLgt1b = new DirectionalLight();
                dLgt1b.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1b.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1b.setInfluencingBounds(new BoundingBox(new Point3d(-20.0, -20.0, -20.0),new Point3d(20.0, 20.0, 20.0)));
                dLgt1b.setEnable(true);

                DirectionalLight dLgt1c = new DirectionalLight();
                dLgt1c.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1c.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1c.setInfluencingBounds(new BoundingBox(new Point3d(-20.0, -20.0, -20.0),new Point3d(20.0, 20.0, 20.0)));
                dLgt1c.setEnable(true);*/

                objRoot.addChild(aLgt1);
                objRoot.addChild(dLgt1);
                objRoot.addChild(dLgt1a);
                /*objRoot.addChild(dLgt1b);
                objRoot.addChild(dLgt1c);*/







                /* Add global lights to the content branch of the scenegraph.
                //First define the colours of the light
                //Color3f alCol = new Color3f( 0.8f, 0.8f, 0.8f );
        //Color3f dlCol = new Color3f( 0.3f, 0.3f, 0.3f );
                //Vector3f lDir  = new Vector3f( 5.0f, 5.0f, 100.0f );

                Bounds lightbounds = new BoundingSphere (new Point3d(-10.0, 1.0, -0.48), 20);
                BoundingLeaf bll = new BoundingLeaf(lightbounds);


                //Define the ambient light
                AmbientLight aLgt1 = new AmbientLight();
                aLgt1.setColor(new Color3f(0.8f, 0.8f, 0.8f ));
                aLgt1.setInfluencingBounds( bounds );

                //Define the directional light
                DirectionalLight dLgt1 = new DirectionalLight();
                dLgt1.setColor(new Color3f(0.3f,0.3f,0.3f));
                dLgt1.setDirection(5.0f, 5.0f, 50.0f);
                dLgt1.setInfluencingBounds( new BoundingSphere(new Point3d(0.0, -10.0, -20.0),1.0) );
                dLgt1.setEnable(true);

                DirectionalLight dLgt1a = new DirectionalLight();
                dLgt1a.setColor(new Color3f(0.3f,0.3f,0.3f));
                dLgt1a.setDirection(-1.0f, 2.0f, 0.0f);
                dLgt1a.setInfluencingBounds(new BoundingSphere (new Point3d(20.0, 20.0, 20.0),20.0));
                dLgt1a.setEnable(true);


                DirectionalLight dLgt1 = new DirectionalLight();
                dLgt1.setColor(new Color3f(0.3f,0.3f,0.3f));
                dLgt1.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1.setInfluencingBounds(new BoundingBox(new Point3d(-12.0, -7.0, -50.0),new Point3d(0.7, 3.0, 0.0)));
                dLgt1.setEnable(true);



                DirectionalLight dLgt1a = new DirectionalLight();
                dLgt1a.setColor(new Color3f(0.3f,0.3f,0.3f));
                dLgt1a.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1a.setInfluencingBounds(new BoundingBox(new Point3d(-12.0, -7.0, -50.0),new Point3d(0.7, 3.0, 0.0)));
                dLgt1a.setEnable(true);


                DirectionalLight dLgt1b = new DirectionalLight();
                dLgt1b.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1b.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1b.setInfluencingBounds(bounds);
                dLgt1b.setEnable(true);




                objRoot.addChild(aLgt1);
                objRoot.addChild(dLgt1);
                objRoot.addChild(dLgt1a);
                //objRoot.addChild(dLgt1b);


                // Add global lights to the content branch of the scenegraph.
                //First define the colours of the light
                Color3f alCol = new Color3f( 50.2f, 50.2f, 50.2f );
        //Color3f dlCol = new Color3f( 0.7f, 0.7f, 0.7f );
                //Vector3f lDir  = new Vector3f( -1.0f, -1.0f, -1.0f );

                //Define the ambient light
                AmbientLight aLgt1 = new AmbientLight( alCol );
                aLgt1.setInfluencingBounds( bounds );

                //Define the directional light
                DirectionalLight dLgt1 = new DirectionalLight();
                dLgt1.setColor(new Color3f(0.7f,0.7f,0.7f));
                dLgt1.setDirection(0.3f, 0.3f, 0.3f);
                dLgt1.setInfluencingBounds( new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 50.0));
                dLgt1.setEnable(true);

                DirectionalLight dLgt1a = new DirectionalLight();
                dLgt1a.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1a.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1a.setInfluencingBounds(new BoundingBox(new Point3d(-70.0, -70.0, -70.0),new Point3d(70.0, 70.0, 70.0)));
                dLgt1a.setEnable(true);

                DirectionalLight dLgt1b = new DirectionalLight();
                dLgt1b.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1b.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1b.setInfluencingBounds(new BoundingBox(new Point3d(-20.0, -20.0, -20.0),new Point3d(20.0, 20.0, 20.0)));
                dLgt1b.setEnable(true);

                DirectionalLight dLgt1c = new DirectionalLight();
                dLgt1c.setColor(new Color3f(1.0f,1.0f,1.0f));
                dLgt1c.setDirection(0.30000001192092896f,0.30000001192092896f,-0.699999988079071f);
                dLgt1c.setInfluencingBounds(new BoundingBox(new Point3d(-20.0, -20.0, -20.0),new Point3d(20.0, 20.0, 20.0)));
                dLgt1c.setEnable(true);

                objRoot.addChild(aLgt1);
                objRoot.addChild(dLgt1);
                //objRoot.addChild(dLgt1a);
                objRoot.addChild(dLgt1b);
                objRoot.addChild(dLgt1c);*/

                //Set up the background
        Color3f bgColor = new Color3f(0.00f, 0.00f, 1.0f);
        Background bgNode = new Background(bgColor);
        bgNode.setApplicationBounds(bounds);
        objRoot.addChild(bgNode);


        BottleBehaviourTest1 bb = new BottleBehaviourTest1(s1.getSceneGroup(), bottleSwitch, dropperSwitch, bottlebounds);
        objRoot.addChild(bb);


        /*TubeBehaviourTest1 tb = new TubeBehaviourTest1(s5.getSceneGroup(), tubeSwitch, dropperSwitch, tubebounds);
        objRoot.addChild(tb);


        FlaskBehaviourTest1 fb = new FlaskBehaviourTest1(s3.getSceneGroup(), dropperSwitch, flaskbounds);
        objRoot.addChild(fb);*/


                return objRoot;
    }


    public MyLoaderTest1() {

    }

    /** Exit the application */
        public void actionPerformed(ActionEvent e) {
        System.exit(0);
        }



    public void init() {

                // These are the string arguments given to the VirtualInputDevice
        // constructor.  These are settable parameters.  Look in the
        // VirtualInputDevice constructor for a complete list.
        String[] args = new String[10];
        args[0] = "printvalues";
        args[1] = "true";
        args[2] = "yscreeninitloc";
        args[3] = "50";
        args[4] = null;

        InputDevice device = new VirtualInputDevice( args );

        // now create the HelloUniverse Canvas
                setLayout(new BorderLayout());
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

        Canvas3D c = new Canvas3D(config);
                add("Center", c);
                exitButton.addActionListener(this);
            add("South", exitButton);
            setVisible(true);


                // Create a simple scene and attach it to the virtual universe
                BranchGroup scene = createSceneGraph(c);
                u = new SimpleUniverse(c);

        // The InputDevice must be initialized before registering it
        // with the PhysicalEnvironment object.
        device.initialize();

                // Register the VirtualInputDevice with Java 3D
                u.getViewer().getPhysicalEnvironment().addInputDevice( device );

                TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform();
                SensorBehavior s = new SensorBehavior( viewTrans, device.getSensor(0) );
                s.setSchedulingBounds( new BoundingSphere ( new Point3d(0.0,0.0,0.0), Float.MAX_VALUE ));
                scene.addChild( s );
                u.addBranchGraph(scene);




    }

    public void destroy() {
        u.removeAllLocales();
    }


    public static void main(String[] args) {
        new MainFrame(new MyLoaderTest1(), 500, 500);
    }
}
import java.util.*;
import javax.media.j3d.*;
import java.awt.event.*;
import java.awt.*;
import javax.vecmath.*;

/**
 * This is used in the SimpleGame application.
 * It defines the behaviour for the duck, which is the
 * target in the shooting game.  If something collides
 * with the duck, it swaps a switch value to 'kill' the duck
 * The duck is revived when it's alpha value passes through zero.
 * @author I.J.Palmer
 * @version 1.0
 */
public class BottleBehaviourTest1 extends Behavior {
    /** The shape that is being watched for collisions. */
    protected Node collidingObject;
    /** The separate criteria that trigger this behaviour */
    protected WakeupCriterion[] theCriteria;
    /** The result of the 'OR' of the separate criteria */
    //protected WakeupAnd andedCriteria;
    protected WakeupOr oredCriteria;
    /** The switch that is used to swap the bottle shapes */
    protected Switch theSwitch;
    /** The switch that is used to swap the dropper shapes */
    protected Switch theSwitch2;
    /** Defines whether the dropper is empty or full */
    public boolean dropperempty = true;


    /**
     * This sets up the data for the behaviour.
     * @param theShape Node that is to be watched for collisions.
     * @param sw Switch that is used to swap shapes.
     * @param a1 Alpha that drives the dropper's animation.
     * @param theBounds Bounds that define the active region for this behaviour.
     */
    public BottleBehaviourTest1(Node theObject, Switch bs, Switch ds, Bounds theBounds ) {
        collidingObject = theObject;
        theSwitch = bs;
        theSwitch2 = ds;
        setSchedulingBounds(theBounds);
    }

    /**
     * This sets up the criteria for triggering the behaviour.
     * It creates an collision crtiterion and a mouse event criterion, AND's these
     * together and then sets the AND'ed criterion as the wake up
     * condition.
     */
    /*public void initialize() {
        theCriteria = new WakeupCriterion[1];
        theCriteria[0] = new WakeupOnCollisionEntry(collidingObject);
        //theCriteria[1] = new WakeupOnAWTEvent( MouseEvent.MOUSE_RELEASED );
        //andedCriteria = new WakeupAnd(theCriteria);
        //wakeupOn(andedCriteria);
    //wakeupOn(theCriteria);
    }*/


    public void initialize() {
        theCriteria = new WakeupCriterion[2];
        theCriteria[0] = new WakeupOnCollisionEntry(collidingObject);
        theCriteria[1] = new WakeupOnCollisionEntry( collidingObject );
        oredCriteria = new WakeupOr(theCriteria);
        wakeupOn(oredCriteria);

        }



    /**
     * This is where the work is done.
     * If there is a collision, then if the dropper is
     * empty we switch to the full dropper.  If the dropper
     * was already full then we take no action.

     * The other case we need to check for is when the
     * alpha value is zero, when we need to set the duck back
     * to the live one for its next traversal of the screen.

     * Finally, the wake up condition is set
     * to be the OR'ed criterion again.
     */
    public void processStimulus(Enumeration criteria) {
        while (criteria.hasMoreElements()) {
                WakeupCriterion theCriterion = (WakeupCriterion) criteria.nextElement();
                if (theCriterion instanceof WakeupOnCollisionEntry) {
                        //If there's a collsion with the flask and the dropper is empty then swap
                        //it to the full (brown) dropper.
                        if (dropperempty == true) {
                                theSwitch.setWhichChild(1);
                                theSwitch2.setWhichChild(1);
                                dropperempty = false;
                        }
                }

        }
        //wakeupOn(andedCriteria);
    //wakeupOn(theCriteria);
    //WakeUpOnCollisionEntry(collidingObject);
    wakeupOn(oredCriteria);
    }
}


Reply via email to