23.3. Intersection Detection Action

Figure 23.2. Intersection detection action class

This class is an Open Inventor action. It allows programmers to analyze a complete scene graph to detect intersections between pairs of shapes. The action first detects intersections between bounding boxes. If an intersection exists between two shapes, the action calls a user filter function. This function can stop the detection process for these two shapes.

The second step of the intersection detection mechanism consists of comparing each triangle of both shapes. If a triangle collision is found, the action calls the user callbacks. Each callback is able to inform the action if it is interested in the next collision report. It can be informed of the intersection for the next graphics primitive or only for the next shape or it can just say that it is not interested in the next intersection. Intersections are detected even if objects are not visible or not pickable. See SoIntersectionDetectionAction SoIntersectionDetectionAction SoIntersectionDetectionAction for more information.

The code in the following example can be used to do this.

SoIntersectionDetectionAction (scene 1)
SoIntersectionDetectionAction (scene 1)

Intersections are detected between all the parts of the scene.

Figure 23.3. SoIntersectionDetectionAction (scene 1)

SoIntersectionDetectionAction (scene 2)
SoIntersectionDetectionAction (scene 2)

After the legs of the jumping man are moved, there is no intersection between the legs and the left and right cylinders (feet).

Figure 23.4. SoIntersectionDetectionAction (scene 2)

Example 23.2. How to use SoIntersectionDetectionAction

This code can be used to analyze a scene graph to determine which pairs of objects within the scene intersect. See Figure 23.3, “SoIntersectionDetectionAction (scene 1)” and Figure 23.4, “SoIntersectionDetectionAction (scene 2)”.

Source code from: $OIVHOME/src/Inventor/examples/Features/Collision/Intersections/Intersections.cxx

  // This callback is called when the action is started.
    onIntersection(void *userData,
    const SoIntersectingPrimitive *primitive1,
    const SoIntersectingPrimitive *primitive2)
    // These two primitive have an intersection.
    printf("%d %s (%s) *** %s (%s)\n",
      (char *)primitive1->path->getTail()->getName().getString(),
      (char *)primitive1->path->getTail()->getTypeId().getName().getString(),
      (char *)primitive2->path->getTail()->getName().getString(),
      (char *)primitive2->path->getTail()->getTypeId().getName().getString());


    // This callback will be called for the two next colliding shapes
    return SoIntersectionDetectionAction::NEXT_SHAPE;

    SoIntersectionDetectionAction action;
    action.addIntersectionCallback(onIntersection, NULL);