00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef CHIPMUNK_HEADER
00023 #define CHIPMUNK_HEADER
00024
00025 #include <stdlib.h>
00026 #include <math.h>
00027
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031
00032 #ifndef CP_ALLOW_PRIVATE_ACCESS
00033 #define CP_ALLOW_PRIVATE_ACCESS 0
00034 #endif
00035
00036 #if CP_ALLOW_PRIVATE_ACCESS == 1
00037 #define CP_PRIVATE(symbol) symbol
00038 #else
00039 #define CP_PRIVATE(symbol) symbol##_private
00040 #endif
00041
00042 void cpMessage(const char *condition, const char *file, int line, int isError, int isHardError, const char *message, ...);
00043 #ifdef NDEBUG
00044 #define cpAssertWarn(condition, ...)
00045 #else
00046 #define cpAssertWarn(condition, ...) if(!(condition)) cpMessage(#condition, __FILE__, __LINE__, 0, 0, __VA_ARGS__)
00047 #endif
00048
00049 #ifdef NDEBUG
00050 #define cpAssertSoft(condition, ...)
00051 #else
00052 #define cpAssertSoft(condition, ...) if(!(condition)) cpMessage(#condition, __FILE__, __LINE__, 1, 0, __VA_ARGS__)
00053 #endif
00054
00055
00056 #define cpAssertHard(condition, ...) if(!(condition)) cpMessage(#condition, __FILE__, __LINE__, 1, 1, __VA_ARGS__)
00057
00058
00059 #include "chipmunk_types.h"
00060
00063
00065 #ifndef CP_BUFFER_BYTES
00066 #define CP_BUFFER_BYTES (32*1024)
00067 #endif
00068
00069 #ifndef cpcalloc
00070
00071 #define cpcalloc calloc
00072 #endif
00073
00074 #ifndef cprealloc
00075
00076 #define cprealloc realloc
00077 #endif
00078
00079 #ifndef cpfree
00080
00081 #define cpfree free
00082 #endif
00083
00084 typedef struct cpArray cpArray;
00085 typedef struct cpHashSet cpHashSet;
00086
00087 typedef struct cpBody cpBody;
00088 typedef struct cpShape cpShape;
00089 typedef struct cpConstraint cpConstraint;
00090
00091 typedef struct cpCollisionHandler cpCollisionHandler;
00092 typedef struct cpArbiter cpArbiter;
00093
00094 typedef struct cpSpace cpSpace;
00095
00096 #include "cpVect.h"
00097 #include "cpBB.h"
00098 #include "cpSpatialIndex.h"
00099
00100 #include "cpBody.h"
00101 #include "cpShape.h"
00102 #include "cpPolyShape.h"
00103
00104 #include "cpArbiter.h"
00105 #include "constraints/cpConstraint.h"
00106
00107 #include "cpSpace.h"
00108
00109
00110 #define CP_VERSION_MAJOR 6
00111 #define CP_VERSION_MINOR 1
00112 #define CP_VERSION_RELEASE 2
00113
00115 extern const char *cpVersionString;
00116
00118 void cpInitChipmunk(void);
00119
00121 void cpEnableSegmentToSegmentCollisions(void);
00122
00123
00126 cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
00127
00130 cpFloat cpAreaForCircle(cpFloat r1, cpFloat r2);
00131
00134 cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b);
00135
00137 cpFloat cpAreaForSegment(cpVect a, cpVect b, cpFloat r);
00138
00140 cpFloat cpMomentForPoly(cpFloat m, int numVerts, const cpVect *verts, cpVect offset);
00141
00144 cpFloat cpAreaForPoly(const int numVerts, const cpVect *verts);
00145
00147 cpVect cpCentroidForPoly(const int numVerts, const cpVect *verts);
00148
00150 void cpRecenterPoly(const int numVerts, cpVect *verts);
00151
00153 cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height);
00154
00156 cpFloat cpMomentForBox2(cpFloat m, cpBB box);
00157
00162 int cpConvexHull(int count, cpVect *verts, cpVect *result, int *first, cpFloat tol);
00163
00164 #ifdef _MSC_VER
00165 #include "malloc.h"
00166 #endif
00167
00172 #define CP_CONVEX_HULL(__count__, __verts__, __count_var__, __verts_var__) \
00173 cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \
00174 int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \
00175
00176 #if defined(__has_extension)
00177 #if __has_extension(blocks)
00178
00179
00180
00181
00182 void cpSpaceEachBody_b(cpSpace *space, void (^block)(cpBody *body));
00183 void cpSpaceEachShape_b(cpSpace *space, void (^block)(cpShape *shape));
00184 void cpSpaceEachConstraint_b(cpSpace *space, void (^block)(cpConstraint *constraint));
00185
00186 void cpBodyEachShape_b(cpBody *body, void (^block)(cpShape *shape));
00187 void cpBodyEachConstraint_b(cpBody *body, void (^block)(cpConstraint *constraint));
00188 void cpBodyEachArbiter_b(cpBody *body, void (^block)(cpArbiter *arbiter));
00189
00190 typedef void (^cpSpaceNearestPointQueryBlock)(cpShape *shape, cpFloat distance, cpVect point);
00191 void cpSpaceNearestPointQuery_b(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpSpaceNearestPointQueryBlock block);
00192
00193 typedef void (^cpSpaceSegmentQueryBlock)(cpShape *shape, cpFloat t, cpVect n);
00194 void cpSpaceSegmentQuery_b(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryBlock block);
00195
00196 typedef void (^cpSpaceBBQueryBlock)(cpShape *shape);
00197 void cpSpaceBBQuery_b(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryBlock block);
00198
00199 typedef void (^cpSpaceShapeQueryBlock)(cpShape *shape, cpContactPointSet *points);
00200 cpBool cpSpaceShapeQuery_b(cpSpace *space, cpShape *shape, cpSpaceShapeQueryBlock block);
00201
00202 #endif
00203 #endif
00204
00205
00207
00208 #ifdef __cplusplus
00209 }
00210
00211 static inline cpVect operator *(const cpVect v, const cpFloat s){return cpvmult(v, s);}
00212 static inline cpVect operator +(const cpVect v1, const cpVect v2){return cpvadd(v1, v2);}
00213 static inline cpVect operator -(const cpVect v1, const cpVect v2){return cpvsub(v1, v2);}
00214 static inline cpBool operator ==(const cpVect v1, const cpVect v2){return cpveql(v1, v2);}
00215 static inline cpVect operator -(const cpVect v){return cpvneg(v);}
00216
00217 #endif
00218 #endif