GeColliderEngine Class Reference

#include <lib_collider.h>

Detailed Description

Collision engine : contains algorithms for collision detection.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.
// Get the first object
if (!o1)
return;
BaseObject* obj1 = doc->GetFirstObject();
if (!obj1)
return;
FillColliderCache(*o1, *obj1);
// Use the next object as second object
if (!o2)
return;
BaseObject* obj2 = obj1->GetNext();
if (!obj2)
return;
FillColliderCache(*o2, *obj2);
// Create the engine
if (!e)
return;
// Check for collisions
GePrint("DoCollide():");
e->DoCollide(obj1->GetMg(), o1, obj2->GetMg(), o2, COL_ALL_CONTACTS);
GePrint(" " + String::IntToString(e->GetNumPairs()) + " pairs;");
for (int k = 0; k < e->GetNumPairs(); ++k)
{
GePrint(" " + String::IntToString(e->GetId1(k)) + " - " + String::IntToString(e->GetId2(k)));
}
PyObject * o2
Definition: abstract.h:399
BaseDocument * GetActiveDocument()
void GePrint(const maxon::String &str)
Definition: ge_autoptr.h:37
Definition: c4d_basedocument.h:497
Definition: c4d_baseobject.h:248
Matrix GetMg() const
Definition: c4d_baseobject.h:510
BaseObject * GetNext()
Definition: c4d_baseobject.h:279
static String IntToString(Int32 v)
Definition: c4d_string.h:495
#define COL_ALL_CONTACTS
All contacts.
Definition: lib_collider.h:35
Py_ssize_t * e
Definition: longobject.h:89
const char * doc
Definition: pyerrors.h:226

Public Member Functions

Int32 DoCollide (const Matrix &M1, GeColliderCache *o1, const Matrix &M2, GeColliderCache *o2, Int32 flag)
 
Int32 DoPolyPairs (const Matrix &M1, GeColliderCache *o1, const Matrix &M2, GeColliderCache *o2, Float tolerance)
 
Int32 DoTolerance (const Matrix &M1, GeColliderCache *o1, const Matrix &M2, GeColliderCache *o2, Float tolerance)
 
Int32 DoDistance (const Matrix &M1, GeColliderCache *o1, const Matrix &M2, GeColliderCache *o2, Float rel_err, Float abs_err)
 
void FreePairsList ()
 
Int32 GetNumPairs ()
 
Int32 GetId1 (Int32 k)
 
Int32 GetId2 (Int32 k)
 
Bool IsCloser ()
 
Float GetDistance ()
 
const VectorGetP1 ()
 
const VectorGetP2 ()
 
Int32 DoRayCollide (GeColliderCache *o1, const Vector &ray_p, const Vector &ray_dir, Float ray_length)
 

Static Public Member Functions

static GeColliderEngineAlloc ()
 
static void Free (GeColliderEngine *&data)
 

Private Member Functions

 GeColliderEngine ()
 
 ~GeColliderEngine ()
 

Constructor & Destructor Documentation

◆ GeColliderEngine()

GeColliderEngine ( )
private

◆ ~GeColliderEngine()

~GeColliderEngine ( )
private

Member Function Documentation

◆ Alloc()

static GeColliderEngine* Alloc ( )
static

Allocates a collider engine. Destroy the allocated collider engine with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

Returns
The allocated collider engine, or nullptr if the allocation failed.

◆ Free()

static void Free ( GeColliderEngine *&  data)
static

Destructs collider engines allocated with Alloc(). Use AutoAlloc to automate the allocation and destruction based on scope.

Parameters
[in,out]dataThe collider engine to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

◆ DoCollide()

Int32 DoCollide ( const Matrix M1,
GeColliderCache o1,
const Matrix M2,
GeColliderCache o2,
Int32  flag 
)

Checks for intersecting triangles in o1 and o2.
If the function succeeds retrieve a list of colliding triangle pairs with GetNumPairs(), GetId1() and GetId2().

Note
The matrices must be orthonormal!
Parameters
[in]M1The world matrix of first object.
[in]o1The cache for first object.
[in]M2The world matrix of second object.
[in]o2The cache for second object.
[in]flagThe method: COL_CONTACT
Returns
The result: COL

◆ DoPolyPairs()

Int32 DoPolyPairs ( const Matrix M1,
GeColliderCache o1,
const Matrix M2,
GeColliderCache o2,
Float  tolerance 
)

Checks for triangles in o1 and o2 that are closer than tolerance to each other.
If the function succeeds retrieve a list of colliding triangle pairs with GetNumPairs(), GetId1() and GetId2().

Note
The matrices must be orthonormal!
Parameters
[in]M1The world matrix of first object.
[in]o1The cache for first object.
[in]M2The world matrix of second object.
[in]o2The cache for second object.
[in]toleranceThe tolerance.
Returns
The result: COL

◆ DoTolerance()

Int32 DoTolerance ( const Matrix M1,
GeColliderCache o1,
const Matrix M2,
GeColliderCache o2,
Float  tolerance 
)

Checks if o1 and o2 are closer to each other than tolerance.
If the function succeeds check the result with IsCloser(): if it returns true, the proof is in GetDistance(), GetP1() and GetP2().

Note
The matrices must be orthonormal!
Parameters
[in]M1The world matrix of first object.
[in]o1The cache for first object.
[in]M2The world matrix of second object.
[in]o2The cache for second object.
[in]toleranceThe tolerance.
Returns
The result: COL

◆ DoDistance()

Int32 DoDistance ( const Matrix M1,
GeColliderCache o1,
const Matrix M2,
GeColliderCache o2,
Float  rel_err,
Float  abs_err 
)

Calculates the minimum distance between o1 and o2 with the accuracy specified by rel_err and abs_err.
If the function succeeds check the result with GetDistance(). The two closest points can be retrieved with GetP1() and GetP2().

Note
The matrices must be orthonormal!
Parameters
[in]M1The world matrix of first object.
[in]o1The cache for first object.
[in]M2The world matrix of second object.
[in]o2The cache for second object.
[in]rel_errThe maximum relative error.
[in]abs_errThe maximum absolute error.
Returns
The result: COL

◆ FreePairsList()

void FreePairsList ( )

Frees the pairs list.

◆ GetNumPairs()

Int32 GetNumPairs ( )

Retrieves the number of pairs found by DoCollide() or DoPolyPairs().

Returns
The number of pairs.

◆ GetId1()

Int32 GetId1 ( Int32  k)

Retrieves the ID of the first triangle in the pair at k found by DoCollide() or DoPolyPairs().

Parameters
[in]kThe pair index: 0 <= k < GetNumPairs()
Returns
The first triangle ID in pair.

◆ GetId2()

Int32 GetId2 ( Int32  k)

Retrieves the ID of the second triangle in the pair at k found by DoCollide() or DoPolyPairs().

Parameters
[in]kThe pair index: 0 <= k < GetNumPairs()
Returns
The second triangle ID in pair.

◆ IsCloser()

Bool IsCloser ( )

Checks the result of the tolerance check done with DoTolerance().

Returns
true if the objects are closer than the tolerance, otherwise false.

◆ GetDistance()

Float GetDistance ( )

Retrieves the result of the distance calculation done with DoDistance() or DoTolerance().

Returns
The calculated distance.

◆ GetP1()

const Vector& GetP1 ( )

Retrieves the closest point found on the first object during the distance calculation done with DoDistance() or DoTolerance().

Returns
The closest point on the first object, in object coordinates.

◆ GetP2()

const Vector& GetP2 ( )

Retrieves the closest point found on the second object during the distance calculation done with DoDistance() or DoTolerance().

Returns
The closest point on the second object, in object coordinates.

◆ DoRayCollide()

Int32 DoRayCollide ( GeColliderCache o1,
const Vector ray_p,
const Vector ray_dir,
Float  ray_length 
)

Checks if the line segment specified by ray_p to ray_p + ray_dir*ray_length intersects the object.
If the function succeeds retrieve the list of intersections with GetNumPairs(), GetId1() and GetId2().

Parameters
[in]o1The cache for the object.
[in]ray_pThe start point of the ray in object coordinates
[in]ray_dirThe ray direction in object coordinates.
[in]ray_lengthThe ray length.
Returns
The result: COL