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;
}
Py_ssize_t i
Definition: abstract.h:645
Bool SendModelingCommand(Int32 command, ModelingCommandData &data)
Executes a builtin modelling operation as for example extruding a polygon selection or selecting all ...
C4DAtom * GetIndex(Int32 idx) const
Definition: c4d_baselist.h:1841
Definition: ge_autoptr.h:37
Definition: c4d_baseobject.h:248
Definition: lib_collider.h:85
Definition: c4d_baseobject.h:1784
PyObject * obj
Definition: complexobject.h:60
Py_UNICODE c
Definition: unicodeobject.h:1200
maxon::Bool Bool
Definition: ge_sys_math.h:51
#define COL_OK
OK.
Definition: lib_collider.h:25
#define MCOMMAND_CURRENTSTATETOOBJECT
Current state to object (returns object): MDATA_CURRENTSTATETOOBJECT.
Definition: ge_prepass.h:1641
#define MCOMMAND_TRIANGULATE
Triangulate.
Definition: ge_prepass.h:1630
Represents a polygon that can be either a triangle or a quadrangle.
Definition: c4d_baseobject.h:44
A helper object for SendModelingCommand().
Definition: operatingsystem.h:842
AtomArray * result
Definition: operatingsystem.h:864
BaseObject * op
The input object. Use arr for multiple objects.
Definition: operatingsystem.h:855
BaseDocument * doc
Definition: operatingsystem.h:853

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