Build Better Software. Faster.
Visit our company site at: www.techsoft3d.com
 

White Papers Index

Collision Detection Using HOOPS
Reuben

Overview

It is sometimes necessary to find out if objects intersect with each other. This is typically referred to as collision detection or interference checking. Detecting intersections between shells is implemented in HOOPS/3dGS as another form of selection.

HC_Compute_Selection_By_Shell or HC_Compute_Selection_By_Key are used to provide either the definition of a shell or the key of an existing shell to HOOPS/3dGS, which returns any facetted items below "start_segment" that intersect with it. (Facetted items include shells, meshes, NURBS Surfaces, circles, ellipses, polygons and polycylinders) The selection process is subject, as usual, to selectability attributes. The return value indicates whether or not there was at least one thing selected. The inputs are somewhat similar to the other HC_Compute_Selection variants, in that it contains an "action", a "start_segment" and a description of the rules by which to select. The "action", and "start_segment" parameters behave exactly as in the other variants. However, the selection is always performed in world space, so there is no need for driver or locater parameters. If any transform needs to be applied to the points, it must be applied before calling HC_Compute_Selection_By_Shell.

Optimizing Collision Detection

Behind the scenes, this calculation involves a reorganized octtree representation of the scene to maximize performance. Building that reorganization can, depending on the data, take a non-trivial amount of time. Therefore, during a sequence of interactive calls, we want to keep that data around between computations. The functions HC_Begin_Shell_Selection and HC_End_Shell_Selection can be used for this purpose. For example, let's say we wanted to repeatedly detect collisions as an object was moving through the scene. We would call HC_Begin_Shell_Selection when the mouse went down, repeatedly call HC_Compute_Selection_By_Shell while the object was moving, and then call HC_End_Shell_Selection when the mouse went up.

If it is only interesting to know if there is a collision (as opposed to what collides) a substantial performance improvement can be achieved by setting the "related selection limit" (see HC_Set_Heuristics) to zero. This will cause the computation to halt as soon as the first intersection is encountered.

If the shell used for intersection also happens to reside below "start_seg", be sure to move it away or turn off selectability in its parent segment. While on the subject of selectability settings, it’s useful to note that the default selectability is off for any segment that is not under a driver. Thus, if calculations are done from non-driver segments, selectability would need to be turned on for this function to have any possibility of selecting anything.

Example:

A reference example of usage of this functionality is contained in the HOOPS/MVO class called HOpObjectClash (defined in HOpObjectClash.h and implemented in HOpObjectClash.cpp) is dervied from the HOpObjectTranslate class which provides functionality for translating selected objects. HOpConstructRectangle performs interactive collision detection by implementing the following methods:

1. HOpObjectClash::OnLButtonDown
Calls HC_Begin_Shell_Selection

2. HOpObjectClash::OnLButtonDownAndMove
Calls HC_Compute_Selection_By_Shell for each of the shells in the selection list. If a segment key was in the selection list, then all the shells in that segment will be used to perform the selection. Selected objects are then highlighted by calling the HSelectionSet::Select method.

3. HOpObjectClash::OnLButtonUp
Calls HC_End_Shell_Selection and deselects all the items.

Closest Distance Calculations

Closest distance information is necessary when performing tolerance checking. The routine HC_Compute_Selection_Distance_By_Shell provides this functionality. If a vector is supplied to the function, then the return value is the exact distance that the shell would need to be moved along this vector before it hits a piece of geometry in the specified segment tree.

A "maximum distance" can also be passed to this function which will further improve performance. By default, there is no maximum distance so every object in the scene, no matter how far, is checked. Therefore, if the goal is to perform a closest distance calculation for purposes of tolerance checking, it's highly recommended that a maximum distance be specified.

 
 

 

 

 

 

©2004-06 Tech Soft 3D All Rights Reserved. Privacy | Legal