Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Create a new Behavior object that will perform the collision
- // detection on the specified object, and add it into
- // the scene graph.
- CollisionDetector cd = new CollisionDetector(przedmiot);
- BoundingSphere boundy = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
- 1.0);
- cd.setSchedulingBounds(boundy);
- class CollisionDetector extends Behavior {
- private final Color3f highlightColor = new Color3f(0.0f, 1.0f, 0.0f);
- private final ColoringAttributes highlight = new ColoringAttributes(
- highlightColor, ColoringAttributes.SHADE_GOURAUD);
- final private Sphere sferka;
- final private ColoringAttributes shapeColoring;
- final private Appearance shapeAppearance;
- private WakeupOnCollisionEntry wEnter;
- private WakeupOnCollisionExit wExit;
- public CollisionDetector(Sphere s) {
- sferka = s;
- shapeAppearance = sferka.getAppearance();
- shapeColoring = shapeAppearance.getColoringAttributes();
- inCollision = false;
- }
- @Override
- public void initialize() {
- wEnter = new WakeupOnCollisionEntry(sferka);
- wExit = new WakeupOnCollisionExit(sferka);
- wakeupOn(wEnter);
- }
- @Override
- public void processStimulus(Enumeration criteria) {
- inCollision = !inCollision;
- if (inCollision) {
- shapeAppearance.setColoringAttributes(highlight);
- wakeupOn(wExit);
- } else {
- shapeAppearance.setColoringAttributes(shapeColoring);
- wakeupOn(wEnter);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment