Index : Reference : Collider library :

GeColliderCache

Header

lib_collider.h

Stores a set of triangles, each with an ID, for use with the other collision classes. Has to be created with Alloc() and destroyed with Free(). You can use AutoAlloc to automate the allocation and destruction based on scope.

This 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();
    if (!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, md1)) return false;
  
    // Triangulate it
    ModelingCommandData md2; md2.op = static_cast<BaseObject*>(md1.result->GetIndex(0));
    if (!SendModelingCommand(MCOMMAND_TRIANGULATE, md2)) 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;
  }
  

Definition

class GeColliderCache
{
public:
  static GeColliderCache* Alloc();
  static void Free(GeColliderCache*& data);

  Bool CopyTo(GeColliderCache* dest);

  Int32 BeginInput(Int32 cnt_tris);
  Int32 AddTriangle(const Vector& p1, const Vector& p2, const Vector& p3, Int32 id);
  Int32 EndInput();
};

Members

static GeColliderCache* Alloc()

Allocates a collider cache. Destroy the allocated collider cache with Free().

Return
GeColliderCache*

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

static void Free(GeColliderCache*& data)

Destructs collider caches allocated with Alloc().

Parameters
GeColliderCache*& data

The collider cache to destruct. If the pointer is nullptr nothing happens. The pointer is assigned nullptr afterwards.

Bool CopyTo(GeColliderCache* dest)

Copy all triangles from this cache to dest.

Return
Bool

true if successful, otherwise false.

Parameters
GeColliderCache* dest

Destination. The caller owns the pointed object.

Int32 BeginInput(Int32 cnt_tris)

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

Return
Int32

Result:

Constant Description

COL_OK

OK.

COL_ERR_OUT_OF_MEMORY

Out of memory.

COL_ERR_UNPROCESSED_MODEL

Unprocessed model.

COL_ERR_WRONG_BUILD_ORDER

Wrong build order.

COL_ERR_EMPTY_OBJECT

Empty object.


Parameters
Int32 cnt_tris

Number of triangles to store.

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.

Return
Int32

Result:

Constant Description

COL_OK

OK.

COL_ERR_OUT_OF_MEMORY

Out of memory.

COL_ERR_UNPROCESSED_MODEL

Unprocessed model.

COL_ERR_WRONG_BUILD_ORDER

Wrong build order.

COL_ERR_EMPTY_OBJECT

Empty object.


Parameters
const Vector& p1

First point.

const Vector& p2

Second point.

const Vector& p3

Third point.

Int32 id

Triangle ID.

Int32 EndInput()

Call this function after you have stored all triangles.

Return
Int32

Result:

Constant Description

COL_OK

OK.

COL_ERR_OUT_OF_MEMORY

Out of memory.

COL_ERR_UNPROCESSED_MODEL

Unprocessed model.

COL_ERR_WRONG_BUILD_ORDER

Wrong build order.

COL_ERR_EMPTY_OBJECT

Empty object.



Copyright 2013 MAXON. See Plugin Cafe for the latest version. Last modified: 2013-09-19