Chipmunk2D Pro API Reference  7.0.1
 All Classes Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Macros | Functions | Variables
Misc

Macros

#define CP_BUFFER_BYTES   (32*1024)
 Allocated size for various Chipmunk buffers.
 
#define cpcalloc   calloc
 Chipmunk calloc() alias.
 
#define cprealloc   realloc
 Chipmunk realloc() alias.
 
#define cpfree   free
 Chipmunk free() alias.
 
#define CP_CONVEX_HULL(__count__, __verts__, __count_var__, __verts_var__)
 Convenience macro to work with cpConvexHull. More...
 

Functions

cpFloat cpMomentForCircle (cpFloat m, cpFloat r1, cpFloat r2, cpVect offset)
 Calculate the moment of inertia for a circle. More...
 
cpFloat cpAreaForCircle (cpFloat r1, cpFloat r2)
 Calculate area of a hollow circle. More...
 
cpFloat cpMomentForSegment (cpFloat m, cpVect a, cpVect b, cpFloat radius)
 Calculate the moment of inertia for a line segment. More...
 
cpFloat cpAreaForSegment (cpVect a, cpVect b, cpFloat radius)
 Calculate the area of a fattened (capsule shaped) line segment.
 
cpFloat cpMomentForPoly (cpFloat m, int count, const cpVect *verts, cpVect offset, cpFloat radius)
 Calculate the moment of inertia for a solid polygon shape assuming it's center of gravity is at it's centroid. The offset is added to each vertex.
 
cpFloat cpAreaForPoly (const int count, const cpVect *verts, cpFloat radius)
 Calculate the signed area of a polygon. More...
 
cpVect cpCentroidForPoly (const int count, const cpVect *verts)
 Calculate the natural centroid of a polygon.
 
cpFloat cpMomentForBox (cpFloat m, cpFloat width, cpFloat height)
 Calculate the moment of inertia for a solid box.
 
cpFloat cpMomentForBox2 (cpFloat m, cpBB box)
 Calculate the moment of inertia for a solid box.
 
int cpConvexHull (int count, const cpVect *verts, cpVect *result, int *first, cpFloat tol)
 Calculate the convex hull of a given set of points. More...
 
static cpVect cpClosetPointOnSegment (const cpVect p, const cpVect a, const cpVect b)
 Returns the closest point on the line segment ab, to the point p.
 

Variables

const char * cpVersionString
 Version string.
 

Detailed Description

Macro Definition Documentation

#define CP_CONVEX_HULL (   __count__,
  __verts__,
  __count_var__,
  __verts_var__ 
)
Value:
cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \
int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \

Convenience macro to work with cpConvexHull.

count and verts is the input array passed to cpConvexHull(). count_var and verts_var are the names of the variables the macro creates to store the result. The output vertex array is allocated on the stack using alloca() so it will be freed automatically, but cannot be returned from the current scope.

Function Documentation

cpFloat cpAreaForCircle ( cpFloat  r1,
cpFloat  r2 
)

Calculate area of a hollow circle.

r1 and r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.

cpFloat cpAreaForPoly ( const int  count,
const cpVect verts,
cpFloat  radius 
)

Calculate the signed area of a polygon.

A Clockwise winding gives positive area. This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.

int cpConvexHull ( int  count,
const cpVect verts,
cpVect result,
int *  first,
cpFloat  tol 
)

Calculate the convex hull of a given set of points.

Returns the count of points in the hull. result must be a pointer to a cpVect array with at least count elements. If verts == result, then verts will be reduced inplace. first is an optional pointer to an integer to store where the first vertex in the hull came from (i.e. verts[first] == result[0]) tol is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.

cpFloat cpMomentForCircle ( cpFloat  m,
cpFloat  r1,
cpFloat  r2,
cpVect  offset 
)

Calculate the moment of inertia for a circle.

r1 and r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.

cpFloat cpMomentForSegment ( cpFloat  m,
cpVect  a,
cpVect  b,
cpFloat  radius 
)

Calculate the moment of inertia for a line segment.

Beveling radius is not supported.