- Main Page
- Classes
- Files
- Directories

- Class List
- Class Hierarchy
- Class Members

# cCollisionSpheres Class Reference

cCollisionSpheres provides methods to create a sphere tree for collision detection, and to use this tree to check for the intersection of a line with a mesh. More...

`#include <CCollisionSpheres.h>`

Inheritance diagram for cCollisionSpheres:

List of all members.

## Public Member Functions
| cCollisionSpheres (vector< cTriangle > *a_triangles, bool a_useNeighbors)
| Constructor of cCollisionSpheres.
virtual | ~cCollisionSpheres ()
| Destructor of cCollisionSpheres.
void | initialize ()
| Build the sphere tree based on the given triangles.
void | render ()
| Draw the collision spheres in OpenGL.
bool | computeCollision (cVector3d &a_segmentPointA, cVector3d &a_segmentPointB, cGenericObject *&a_colObject, cTriangle *&a_colTriangle, cVector3d &a_colPoint, double &a_colSquareDistance, int a_proxyCall=-1)
| Return the nearest triangle intersected by the given segment, if any.
## Public Attributes
cCollisionSpheresSphere * | m_root
| Pointer to the sphere at the root of the sphere tree.
vector< cTriangle > * | m_trigs
| Pointer to the list of triangles in the mesh.
cTriangle * | m_lastCollision
| Triangle returned by last successful collision test.
bool | m_useNeighbors
| Use neighbor list to speed up collision detection?
cCollisionSpheresLeaf * | m_firstLeaf
| Pointer to the beginning of list of leaf nodes.

## Detailed Description

cCollisionSpheres provides methods to create a sphere tree for collision detection, and to use this tree to check for the intersection of a line with a mesh.

## Constructor & Destructor Documentation

cCollisionSpheres::cCollisionSpheres | ( | vector< cTriangle > * | a_triangles,
|  | bool | a_useNeighbors |
| ) |  |  |

Constructor of cCollisionSpheres.

Constructor of cCollisionSpheres.

Parameters:

  | a_triangles | Pointer to array of triangles.
  | a_useNeighbors | Use neighbor lists to speed up collision detection?

cCollisionSpheres::~cCollisionSpheres | ( |  | ) | `[virtual]`

Destructor of cCollisionSpheres.

Destructor of cCollisionSpheres.

## Member Function Documentation

void cCollisionSpheres::initialize | ( |  | ) | `[virtual]`

Build the sphere tree based on the given triangles.

Build the Sphere Tree collision-detection tree. Each leaf is associated with one triangle and with a bounding sphere of minimal radius such that it fully encloses the triangle. Each internal node is associated with a bounding sphere of minimal radius such that it fully encloses the bounding spheres of its two children.

Reimplemented from cGenericCollision.

void cCollisionSpheres::render | ( |  | ) | `[virtual]`

Draw the collision spheres in OpenGL.

Draw the collision spheres at the given level.

Reimplemented from cGenericCollision.

bool cCollisionSpheres::computeCollision | ( | cVector3d & | a_segmentPointA,
|  | cVector3d & | a_segmentPointB,
|  | cGenericObject *& | a_colObject,
|  | cTriangle *& | a_colTriangle,
|  | cVector3d & | a_colPoint,
|  | double & | a_colSquareDistance,
|  | int | a_proxyCall = `-1` |
| ) |  |  | `[virtual]`

Return the nearest triangle intersected by the given segment, if any.

Check if the given line segment intersects any triangle of the mesh. If so, return true, as well as (through the output parameters) pointers to the intersected triangle, the mesh of which this triangle is a part, the point of intersection, and the distance from the origin of the segment to the collision point. If more than one triangle is intersected, return the one closest to the origin of the segment. The method uses the pre-computed sphere tree, starting at the root and recursing through the tree, breaking the recursion along any path in which the sphere bounding the line segment does not intersect the sphere of the node. At the leafs, triangle-segment intersection testing is called.

Parameters:

  | a_segmentPointA | Initial point of segment.
  | a_segmentPointB | End point of segment.
  | a_colObject | Returns pointer to nearest collided object.
  | a_colTriangle | Returns pointer to nearest collided triangle.
  | a_colPoint | Returns position of nearest collision.
  | a_colSquareDistance | Returns distance between ray origin and collision point.
  | a_proxyCall | If this is > 0, this is a call from a proxy, and the value of a_proxyCall specifies which call this is. When checking for the second and third constraint planes, only the neighbors of the triangle intersected in the first call need be checked, not the whole tree. Call with a_proxyCall = -1 for non-proxy calls.

Returns:
  Return true if the line segment intersects a triangle.

Reimplemented from cGenericCollision.

The documentation for this class was generated from the following files:

- chai3d/src/collisions/CCollisionSpheres.h
- chai3d/src/collisions/CCollisionSpheres.cpp