jotto

Untitled

Jun 14th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.50 KB | None | 0 0
  1.         // Create a new Behavior object that will perform the collision
  2.         // detection on the specified object, and add it into
  3.         // the scene graph.
  4.         CollisionDetector cd = new CollisionDetector(przedmiot);
  5.         BoundingSphere boundy = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
  6.             1.0);
  7.         cd.setSchedulingBounds(boundy);
  8.  
  9.   class CollisionDetector extends Behavior {
  10.   private final Color3f highlightColor = new Color3f(0.0f, 1.0f, 0.0f);
  11.  
  12.   private final ColoringAttributes highlight = new ColoringAttributes(
  13.       highlightColor, ColoringAttributes.SHADE_GOURAUD);
  14.  
  15.   final private Sphere sferka;
  16.   final private ColoringAttributes shapeColoring;
  17.   final private Appearance shapeAppearance;
  18.   private WakeupOnCollisionEntry wEnter;
  19.   private WakeupOnCollisionExit wExit;
  20.  
  21.   public CollisionDetector(Sphere s) {
  22.     sferka = s;
  23.     shapeAppearance = sferka.getAppearance();
  24.     shapeColoring = shapeAppearance.getColoringAttributes();
  25.     inCollision = false;
  26.   }
  27.  
  28.   @Override
  29.   public void initialize() {
  30.     wEnter = new WakeupOnCollisionEntry(sferka);
  31.     wExit = new WakeupOnCollisionExit(sferka);
  32.     wakeupOn(wEnter);
  33.   }
  34.  
  35.   @Override
  36.   public void processStimulus(Enumeration criteria) {
  37.     inCollision = !inCollision;
  38.  
  39.     if (inCollision) {
  40.       shapeAppearance.setColoringAttributes(highlight);
  41.       wakeupOn(wExit);
  42.     } else {
  43.       shapeAppearance.setColoringAttributes(shapeColoring);
  44.       wakeupOn(wEnter);
  45.     }
  46.   }
  47.   }
Advertisement
Add Comment
Please, Sign In to add comment