Class SoCollisionManager


  • public class SoCollisionManager
    extends Inventor
    Class to manage collisions. The SoCollisionManager class manages collisions, i.e., it controls the position of an object in a scene, preventing it from colliding with other objects in the scene.

    The collision manager references a scene, an object and a transformation. It can prevent collisions between the specified object and other objects within the scene.

    It can use the actual primitives of the objects during the computation, or for faster performance, it may use their bounding boxes.

    When the referenced transformation changes, the collision manager looks for a collision between the bounding box of the object and the bounding boxes of objects within the scene. If a collision between the bounding boxes is detected, the algorithm can (depending on what the programmer specifies) compute a more precise intersection using the actual primitives of the object and/or the objects of the scene.

    The algorithm can call programmer-supplied callbacks when there is a collision between the bounding boxes, and when there is a collision between the primitives of the shapes.

    When there is a collision, the collision manager can "glue" the object on the scene. This refers to placing the object at the position just before the first collision that would occur along the transformation path. For example, if an object would collide with (intersect) a wall, the object would be placed directly against the wall.

    See Also:
    SoIntersectionDetectionAction, SoWinCollisionViewer
    • Constructor Detail

      • SoCollisionManager

        public SoCollisionManager​(SoPath object,
                                  SoGroup scene,
                                  SoTransform transform)
        Constructor. The specified scene must be the head of the path to the specified object.
    • Method Detail

      • setFilter

        public void setFilter​(SoCollisionManager.Filter f)
        Sets the Filter callback function called when an object shape collides with a scene shape. If the callback function returns TRUE, the Collision Manager looks forward for collisions; else, it aborts searching. If it is NULL, no filter is applied.

        Warning: This callback is not fully compliant with OSGi applications. It may crash in an OSGi environment, in that case we suggest to use SoDualSceneCollider instead.

      • addBBoxCollisionListener

        public void addBBoxCollisionListener​(SoCollisionManager.BBoxCollisionListener listener)
        Adds bounding box collision callback.

        Warning: This callback is not fully compliant with OSGi applications. It may crash in an OSGi environment, in that case we suggest to use SoDualSceneCollider instead.

      • addCollisionListener

        public void addCollisionListener​(SoCollisionManager.CollisionListener listener)
        Adds collision callback.

        Warning: This callback is not fully compliant with OSGi applications. It may crash in an OSGi environment, in that case we suggest to use SoDualSceneCollider instead.

      • setSceneBBoxOnly

        public void setSceneBBoxOnly()
        Calls setSceneBBoxOnly(true).
      • setObjectBBoxOnly

        public void setObjectBBoxOnly()
        Calls setObjectBBoxOnly(true).
      • activate

        public void activate()
        Calls activate(true).
      • setGluing

        public void setGluing()
        Calls setGluing(true).
      • setScene

        public void setScene​(SoGroup scene)
        Sets the scene the object is interacting with.
      • getScene

        public SoGroup getScene()
        Returns the scene the object is interacting with.
      • setTransform

        public void setTransform​(SoTransform transform)
        Sets the transformation that will be watched.
      • setObject

        public void setObject​(SoPath object)
        Sets the object that will be transformed.
      • getObject

        public SoPath getObject()
        Returns the object that will be transformed.
      • setGluing

        public void setGluing​(boolean flag)
        Sets a flag indicating that the collision manager should place the object at the position just before the first collision that would occur along the transformation path. For example, if an object would collide with (intersect) a wall, the object would be placed directly against the wall. Default value is false.
      • isSceneBBoxOnly

        public boolean isSceneBBoxOnly()
        Returns a flag indicating whether to use the bounding boxes of objects in the scene instead of the actual primitives when computing collisions.
      • isGluing

        public boolean isGluing()
        Returns a flag indicating whether the collision manager should place the object at the position just before the first collision that would occur along the transformation path.
      • isActivated

        public boolean isActivated()
        Returns a flag indicating whether the collision manager is activated.
      • activate

        public void activate​(boolean flag)
        Sets a flag to activate the collision manager, for instance, to tell it to watch the transformation and start collision detection computations when the transformation changes. Default value is true.
      • setSceneBBoxOnly

        public void setSceneBBoxOnly​(boolean flag)
        Sets a flag indicating whether to use the bounding boxes of objects in the scene instead of the actual primitives when computing collisions. Default value is false.
      • setGluingLevel

        public void setGluingLevel​(int level)
        Sets the gluing level. The larger the number, the more precise the check for intermediate collisions, and the longer the computation will take. If this level is set to 0, the collision manager will act as if the gluing flag was set to false, except the collision callbacks are called with a gluing flag of true. Default value is 1.
      • getTransform

        public SoTransform getTransform()
        Returns the transformation that will be watched.
      • getGluingLevel

        public int getGluingLevel()
        Returns the gluing level.
      • isObjectBBoxOnly

        public boolean isObjectBBoxOnly()
        Returns a flag indicating whether to use the object's bounding box instead of the actual primitives when computing collisions.
      • setObjectBBoxOnly

        public void setObjectBBoxOnly​(boolean flag)
        Sets a flag indicating whether to use the object's bounding box instead of the actual primitives when computing collisions. Default value is false.