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
GeColliderCache::EndInput
Int32 EndInput()
ModelingCommandData::result
AtomArray * result
Definition: operatingsystem.h:833
SendModelingCommand
Bool SendModelingCommand(Int32 command, ModelingCommandData &data)
BaseObject
Definition: c4d_baseobject.h:224
CPolygon
Represents a polygon that can be either a triangle or a quadrangle.
Definition: c4d_baseobject.h:43
GeColliderCache::BeginInput
Int32 BeginInput(Int32 cnt_tris)
CPolygon::GetPoint
Int32 & GetPoint(Int32 index) const
Definition: c4d_baseobject.h:131
GeColliderCache::AddTriangle
Int32 AddTriangle(const Vector &p1, const Vector &p2, const Vector &p3, Int32 id)
ModelingCommandData
A helper object for SendModelingCommand().
Definition: operatingsystem.h:810
maxon::Vec3< maxon::Float64, 1 >
GeColliderCache
Definition: lib_collider.h:84
GeListNode::GetDocument
BaseDocument * GetDocument()
Definition: c4d_baselist.h:1944
ModelingCommandData::op
BaseObject * op
The input object. Use arr for multiple objects.
Definition: operatingsystem.h:824
PolygonObject
Definition: c4d_baseobject.h:1618
COL_OK
#define COL_OK
OK.
Definition: lib_collider.h:25
MCOMMAND_TRIANGULATE
#define MCOMMAND_TRIANGULATE
Triangulate.
Definition: ge_prepass.h:1411
AutoAlloc
Definition: ge_autoptr.h:36
MCOMMAND_CURRENTSTATETOOBJECT
#define MCOMMAND_CURRENTSTATETOOBJECT
Current state to object (returns object): MDATA_CURRENTSTATETOOBJECT.
Definition: ge_prepass.h:1422
Bool
maxon::Bool Bool
Definition: ge_sys_math.h:55
ModelingCommandData::doc
BaseDocument * doc
Definition: operatingsystem.h:822
AtomArray::GetIndex
C4DAtom * GetIndex(Int32 idx) const
Definition: c4d_baselist.h:1663