GeColliderCache Class Reference

#include <lib_collider.h>

Detailed Description

Collision cache : stores a set of triangles, each with an ID, for use with the other collision classes.

Note
Has to be created with Alloc() and destroyed with Free(). Use AutoAlloc to automate the allocation and destruction based on scope.

The following function fills a GeColliderCache from a BaseObject:

Bool FillColliderCache(GeColliderCache& c, BaseObject& obj)
{
// Get polygon object
ModelingCommandData md1; md1.op = &obj; md1.doc = obj.GetDocument();
return false;
// Triangulate it
ModelingCommandData md2; md2.op = static_cast<BaseObject*>(md1.result->GetIndex(0));
return false;
AutoAlloc<PolygonObject> poly(static_cast<PolygonObject*>(md2.op));
if (!poly)
return false;
// Get the polygon data
CPolygon* tris = poly->GetPolygon();
Vector* points = poly->GetPoint();
// Fill the cache
if (c.BeginInput(poly->GetPolygonCount()) != COL_OK)
return false;
for (int i = 0; i < poly->GetPolygonCount(); ++i)
{
if (c.AddTriangle(points[tris[i].a], points[tris[i].b], points[tris[i].c], i) != COL_OK)
return false;
}
if (c.EndInput() != COL_OK)
return false;
return true;
}

Public Member Functions

Bool CopyTo (GeColliderCache *dest)
 
Int32 BeginInput (Int32 cnt_tris)
 
Int32 AddTriangle (const Vector &p1, const Vector &p2, const Vector &p3, Int32 id)
 
Int32 EndInput ()
 

Static Public Member Functions

static GeColliderCacheAlloc ()
 
static void Free (GeColliderCache *&data)
 

Private Member Functions

 GeColliderCache ()
 
 ~GeColliderCache ()
 

Constructor & Destructor Documentation

◆ GeColliderCache()

GeColliderCache ( )
private

◆ ~GeColliderCache()

~GeColliderCache ( )
private

Member Function Documentation

◆ Alloc()

static GeColliderCache* Alloc ( )
static

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

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

◆ Free()

static void Free ( GeColliderCache *&  data)
static

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

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

◆ CopyTo()

Bool CopyTo ( GeColliderCache dest)

Copies all triangles to another cache.

Parameters
[in,out]destThe destination cache. The caller owns the pointed collider cache.
Returns
true if successful, otherwise false.

◆ BeginInput()

Int32 BeginInput ( Int32  cnt_tris)

Call this function before storing triangles into the cache. Removes any previous data and allocates space for cnt_tris number of triangles.

Parameters
[in]cnt_trisThe number of triangles to store.
Returns
The result: COL

◆ AddTriangle()

Int32 AddTriangle ( const Vector p1,
const Vector p2,
const Vector p3,
Int32  id 
)

Adds a triangle to the cache with the specified corners and id.

Parameters
[in]p1The first point.
[in]p2The second point.
[in]p3The third point.
[in]idThe triangle ID.
Returns
The result: COL

◆ EndInput()

Int32 EndInput ( )

Call this function after storing triangles into the cache.

Returns
The result: COL