Package eas.miscellaneous.java3D

Source Code of eas.miscellaneous.java3D.CollisionBehaviour1

package eas.miscellaneous.java3D;

import java.util.Enumeration;

import javax.media.j3d.Behavior;
import javax.media.j3d.Bounds;
import javax.media.j3d.Switch;
import javax.media.j3d.WakeupCriterion;
import javax.media.j3d.WakeupOnCollisionEntry;
import javax.media.j3d.WakeupOnCollisionExit;
import javax.media.j3d.WakeupOr;



/**
* This class implements the change between two states (Switches)
* when a collision occurs.
*
* @author Frank Klawonn
* Last change 07.07.2005
* @see CollisionExample
*/
@SuppressWarnings("all")
public class CollisionBehaviour1 extends Behavior
{

   //Collision entry and exit must be taken into account.
   public WakeupCriterion[] theCriteria;
   public WakeupOr oredCriteria;
   public Switch collidingShape;


   public CollisionBehaviour1(Switch theShape, Bounds theBounds)
   {
     collidingShape = theShape;
     setSchedulingBounds(theBounds);
   }


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



  public void processStimulus(Enumeration criteria)
  {
    //Here we define what happens when a collision occurs.
    while (criteria.hasMoreElements())
    {
      WakeupCriterion theCriterion = (WakeupCriterion) criteria.nextElement();
      if (theCriterion instanceof WakeupOnCollisionEntry) //-> switch to the red sphere
      {
        collidingShape.setWhichChild(1);
      }
      else
      {
        if (theCriterion instanceof WakeupOnCollisionExit) //-> switch to the green sphere
        {
          collidingShape.setWhichChild(0);
        }
      }
      wakeupOn(oredCriteria);
    }
  }

}
TOP

Related Classes of eas.miscellaneous.java3D.CollisionBehaviour1

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.