Areas
  • J3D FAQ
  • Tutorials
  • Utilities
  • Books
  • News
  • Other Sites
  •  Chapters
  • TOC
  • Getting Started
  • Lighting
  • Textures
  • Behaviours
  • User Feedback
  • Navigation
  • Audio
  • Input Devices
  • No Monitors
  •  Sections
  • Chapter TOC
  • Mouse Handling
  • Picking
  • Summary
  •   

    Collisions

    © Justin Couch 2000

    In the previous section it was mentioned that one of potential the uses of picking is to build a collision detection system. It was also noted that Java3D has its own in-built system for this. Collision detection is built in so that it acts like any other behaviour. It has wakeup criteria available for notification and also methods of specifying exactly what should be collided with.

    Per Object

    The most simple collision system is based on object to object collision. The default implementation of the Node object sets the collision system on by default (just like picking). Based on this, whenever one piece of geometry collides with another, a behaviour could be executed to deal with the results. Simple or complex interactions can then take place. Note that this could be any arbitrary object, not just the user’s avatar with an object.

    Because collisions notifications are delivered by the behaviour mechanism, unless you register a behaviour you will never know if two objects collide. That is, the default implementation is just to issue a message to say that two objects have collided, but do nothing about it. It is possible for two objects to pass straight through each other and the rendering engine will not do anything about it.

    There are three types of notification that the system will deliver for collisions:

    1. WakeupOnCollisionEntry: When two objects first collide this condition is executed. You might use this to stop the movement of one object through another. One point of this is that you can construct a bounds that is just outside the object so that as collision occurs you can prevent situations where it appears that the object moves just in and out of collision with the other.
    2. WakeupOnCollisionExit: when two objects stop colliding this condition is executed. This uses similar conditions to the entry condition allowing a bounding area to work. The best way to set these two up is with slightly different bounds to prevent jitter occurring.
    3. WakeupOnCollisionMovement: Once two objects have started colliding, as they move relative to each other, this criteria is executed until the exit condition.

    Overriding Default Bounds

    One potential problem with per object collisions is that complex, non-primitive objects can be extremely compute intensive to deal with collision detection. If you are finding that this is slowing you application down, you might want to try optimising the calculation routines by providing alternative bounds to work against. One typical example of this is to provide a box collision volume around a complex object (eg a car).

    If you wish to override the default object shape, then you can use the setCollisionBounds() method of the Group node. Note that this is does not belong to an individual leaf node like Shape3D, but is much higher in the chain. This way you can combine many smaller shapes into a single bounding area.

    Once this is set, your collision behaviours are now based on this region rather than the raw geometry objects themselves and should (providing you actually do make the bounding area simpler) provide a great speed improvement.

      

    [ TOC ] [ Home ] [ FAQ ] [ Books ] [ Tutorials ] [ Utilities ] [ Contact Us ]