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 1
00113
00115 extern const char *cpVersionString;
00116
00118 void cpInitChipmunk(void);
00119
00122 cpFloat cpMomentForCircle(cpFloat m, cpFloat r1, cpFloat r2, cpVect offset);
00123
00126 cpFloat cpAreaForCircle(cpFloat r1, cpFloat r2);
00127
00130 cpFloat cpMomentForSegment(cpFloat m, cpVect a, cpVect b);
00131
00133 cpFloat cpAreaForSegment(cpVect a, cpVect b, cpFloat r);
00134
00136 cpFloat cpMomentForPoly(cpFloat m, int numVerts, const cpVect *verts, cpVect offset);
00137
00140 cpFloat cpAreaForPoly(const int numVerts, const cpVect *verts);
00141
00143 cpVect cpCentroidForPoly(const int numVerts, const cpVect *verts);
00144
00146 void cpRecenterPoly(const int numVerts, cpVect *verts);
00147
00149 cpFloat cpMomentForBox(cpFloat m, cpFloat width, cpFloat height);
00150
00152 cpFloat cpMomentForBox2(cpFloat m, cpBB box);
00153
00158 int cpConvexHull(int count, cpVect *verts, cpVect *result, int *first, cpFloat tol);
00159
00160 #ifdef _MSC_VER
00161 #include "malloc.h"
00162 #endif
00163
00168 #define CP_CONVEX_HULL(__count__, __verts__, __count_var__, __verts_var__) \
00169 cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \
00170 int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \
00171
00172 #if defined(__has_extension)
00173 #if __has_extension(blocks)
00174
00175
00176
00177
00178 void cpSpaceEachBody_b(cpSpace *space, void (^block)(cpBody *body));
00179 void cpSpaceEachShape_b(cpSpace *space, void (^block)(cpShape *shape));
00180 void cpSpaceEachConstraint_b(cpSpace *space, void (^block)(cpConstraint *constraint));
00181
00182 void cpBodyEachShape_b(cpBody *body, void (^block)(cpShape *shape));
00183 void cpBodyEachConstraint_b(cpBody *body, void (^block)(cpConstraint *constraint));
00184 void cpBodyEachArbiter_b(cpBody *body, void (^block)(cpArbiter *arbiter));
00185
00186 typedef void (^cpSpaceNearestPointQueryBlock)(cpShape *shape, cpFloat distance, cpVect point);
00187 void cpSpaceNearestPointQuery_b(cpSpace *space, cpVect point, cpFloat maxDistance, cpLayers layers, cpGroup group, cpSpaceNearestPointQueryBlock block);
00188
00189 typedef void (^cpSpaceSegmentQueryBlock)(cpShape *shape, cpFloat t, cpVect n);
00190 void cpSpaceSegmentQuery_b(cpSpace *space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryBlock block);
00191
00192 typedef void (^cpSpaceBBQueryBlock)(cpShape *shape);
00193 void cpSpaceBBQuery_b(cpSpace *space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryBlock block);
00194
00195 typedef void (^cpSpaceShapeQueryBlock)(cpShape *shape, cpContactPointSet *points);
00196 cpBool cpSpaceShapeQuery_b(cpSpace *space, cpShape *shape, cpSpaceShapeQueryBlock block);
00197
00198 #endif
00199 #endif
00200
00201
00203
00204 #ifdef __cplusplus
00205 }
00206
00207 static inline cpVect operator *(const cpVect v, const cpFloat s){return cpvmult(v, s);}
00208 static inline cpVect operator +(const cpVect v1, const cpVect v2){return cpvadd(v1, v2);}
00209 static inline cpVect operator -(const cpVect v1, const cpVect v2){return cpvsub(v1, v2);}
00210 static inline cpBool operator ==(const cpVect v1, const cpVect v2){return cpveql(v1, v2);}
00211 static inline cpVect operator -(const cpVect v){return cpvneg(v);}
00212
00213 #endif
00214 #endif