The class SoDualSceneCollider performs very fast collision detection for the case of two scene graphs, one static and one moving. This class has been designed to detect collisions between very large scenes (i.e., containing millions of triangles) while still allowing interactive display of the two scenes. You can retrieve information about colliding triangles, coordinates of common points, and so forth. This is useful, for example, for walk-through of a complex factory environment.
SoDualSceneCollider has not been designed to check collisions
of an animated scene in which several shapes are moving.
The first scene, called the “moving scene”, is specified by the method setMovingScene(). The second scene, called the “static scene”, is specified by the method setStaticScene(). These two methods each have two arguments, an SoPath and an integer. The tail node of this path specifies the root of the moving or static scene graph. SoDualSceneCollider references each of the scenes by storing its triangle list and by building a database as a tree. The tree is organized spatially and hierarchically to optimize the process of searching for intersecting pairs of triangles. The leaves of this tree contain the triangles while the internal nodes do not. The performance of intersection checking between the two scenes depends on the number of triangles in each leaf. For this reason, the methods setMovingScene()/**setStaticScene()** have also an integer argument (max_triangles_per_leaf) for specifying the maximum number of triangles per leaf.
The spatial tree does not depend on the organization of the two supplied Open Inventor scene graphs. This means that the application does not need to spatially organize the scene graphs to get better performance when using SoDualSceneCollider.
The following figure shows the tree of the same Open Inventor scene graph with three different values of max_triangles_per_leaf.
null transform, this transform is monitored by SoDualSceneCollider. Each time the transform node changes, the method checkCollision() is automatically called and checks if the moving scene collides with the static scene.
SoDualSceneCollider does not monitor the scene graph:checkCollision() is not called when a modification to the Open
Inventor nodes in the static scene or the moving scene occurs. To maintain consistency between
the scene graph and the spatial tree (see above), setMovingScene() / setStaticScene() must be
called whenever the moving/static scene graph is changed.
When the two scenes collide, the “response” method searchNextIntersection() is called for each common point of the two scenes. Each time checkCollision() finds a new pair of intersecting triangles, searchNextIntersection() is called. By default, this method returns FALSE, telling checkCollision() that no other pairs of intersecting triangles need to be searched. This default implementation means that checkCollision() is just answering the question: are the two scenes colliding or not?
However, the main interest of collision detection is to provide different responses like, for instance:
The simplest response type is item 1, and can be implemented as shown below. See source code at:
$OIVHOME/src/Inventor/examples/Features/Collision/SimpleSceneCollider/CountingIntersection.cxx
C++ :
C# :
Java :
This previous example is not the most efficient way to know if two scenes
collide or not. The default implementation of SoDualSceneCollider is much more efficient because it stops the search for
intersecting triangles after the first pair is found.
In order to implement other types of responses, for example items 2 through 5 in the list above, the API of SoDualSceneCollider provides additional methods (protected) that can be called by an overridden version of searchNextIntersection():
Returns the path in the scene of the current colliding shape:
The following example shows a way of getting the coordinates of each pair of common points. See source code at:
$OIVHOME/Inventor/examples/Features/Collision/SimpleSceneCollider/GettingIntersectionPoints.cxx
C++ :
C# :
The SoDualSceneCollider also provides methods that allow an application to know when the hierarchical structure of the scenes is rebuilding.
The demonstration example DemoCollider shows a more sophisticated implementation of searchNextIntersection() and checkCollision() that
See source code at:
$OIVHOME/Inventor/examples/Features/Collision/SceneCollider/DemoCollider.cxx