1
- /* Copyright (c) 2007 Scott Lembcke
1
+ /* Copyright (c) 2013 Scott Lembcke and Howling Moon Software
2
2
*
3
3
* Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
* of this software and associated documentation files (the "Software"), to deal
19
19
* SOFTWARE.
20
20
*/
21
21
22
- #ifndef CHIPMUNK_HEADER
23
- #define CHIPMUNK_HEADER
24
-
25
- #ifdef _MSC_VER
26
- #define _USE_MATH_DEFINES
27
- #endif
22
+ #ifndef CHIPMUNK_H
23
+ #define CHIPMUNK_H
28
24
29
25
#include <stdlib.h>
30
26
#include <math.h>
31
27
28
+ #ifdef WIN32
29
+ // For alloca().
30
+ #include <malloc.h>
31
+ #define CP_EXPORT __declspec(dllexport)
32
+ #else
33
+ #include <alloca.h>
34
+ #define CP_EXPORT
35
+ #endif
36
+
32
37
#ifdef __cplusplus
33
38
extern "C" {
34
39
#endif
35
40
41
+ // NUKE
36
42
#ifndef CP_ALLOW_PRIVATE_ACCESS
37
43
#define CP_ALLOW_PRIVATE_ACCESS 0
38
44
#endif
@@ -43,22 +49,17 @@ extern "C" {
43
49
#define CP_PRIVATE (__symbol__ ) __symbol__##_private
44
50
#endif
45
51
46
- void cpMessage (const char * condition , const char * file , int line , int isError , int isHardError , const char * message , ...);
52
+ CP_EXPORT void cpMessage (const char * condition , const char * file , int line , int isError , int isHardError , const char * message , ...);
47
53
#ifdef NDEBUG
48
54
#define cpAssertWarn (__condition__ , ...)
49
- #else
50
- #define cpAssertWarn (__condition__ , ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 0, 0, __VA_ARGS__)
51
- #endif
52
-
53
- #ifdef NDEBUG
54
55
#define cpAssertSoft (__condition__ , ...)
55
56
#else
56
- #define cpAssertSoft (__condition__ , ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 1, 0, __VA_ARGS__)
57
+ #define cpAssertSoft (__condition__ , ...) if(!(__condition__)){cpMessage(#__condition__, __FILE__, __LINE__, 1, 0, __VA_ARGS__); abort();}
58
+ #define cpAssertWarn (__condition__ , ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 0, 0, __VA_ARGS__)
57
59
#endif
58
60
59
- // Hard assertions are important and cheap to execute. They are not disabled by compiling as debug.
60
- #define cpAssertHard (__condition__ , ...) if(!(__condition__)) cpMessage(#__condition__, __FILE__, __LINE__, 1, 1, __VA_ARGS__)
61
-
61
+ // Hard assertions are used in situations where the program definitely will crash anyway, and the reason is inexpensive to detect.
62
+ #define cpAssertHard (__condition__ , ...) if(!(__condition__)){cpMessage(#__condition__, __FILE__, __LINE__, 1, 1, __VA_ARGS__); abort();}
62
63
63
64
#include "chipmunk_types.h"
64
65
@@ -89,81 +90,90 @@ typedef struct cpArray cpArray;
89
90
typedef struct cpHashSet cpHashSet ;
90
91
91
92
typedef struct cpBody cpBody ;
93
+
92
94
typedef struct cpShape cpShape ;
95
+ typedef struct cpCircleShape cpCircleShape ;
96
+ typedef struct cpSegmentShape cpSegmentShape ;
97
+ typedef struct cpPolyShape cpPolyShape ;
98
+
93
99
typedef struct cpConstraint cpConstraint ;
100
+ typedef struct cpPinJoint cpPinJoint ;
101
+ typedef struct cpSlideJoint cpSlideJoint ;
102
+ typedef struct cpPivotJoint cpPivotJoint ;
103
+ typedef struct cpGrooveJoint cpGrooveJoint ;
104
+ typedef struct cpDampedSpring cpDampedSpring ;
105
+ typedef struct cpDampedRotarySpring cpDampedRotarySpring ;
106
+ typedef struct cpRotaryLimitJoint cpRotaryLimitJoint ;
107
+ typedef struct cpRatchetJoint cpRatchetJoint ;
108
+ typedef struct cpGearJoint cpGearJoint ;
109
+ typedef struct cpSimpleMotorJoint cpSimpleMotorJoint ;
94
110
95
111
typedef struct cpCollisionHandler cpCollisionHandler ;
112
+ typedef struct cpContactPointSet cpContactPointSet ;
96
113
typedef struct cpArbiter cpArbiter ;
97
114
98
115
typedef struct cpSpace cpSpace ;
99
116
100
117
#include "cpVect.h"
101
118
#include "cpBB.h"
119
+ #include "cpTransform.h"
102
120
#include "cpSpatialIndex.h"
103
121
122
+ #include "cpArbiter.h"
123
+
104
124
#include "cpBody.h"
105
125
#include "cpShape.h"
106
126
#include "cpPolyShape.h"
107
127
108
- #include "cpArbiter.h"
109
- #include "constraints/cpConstraint.h"
128
+ #include "cpConstraint.h"
110
129
111
130
#include "cpSpace.h"
131
+ #include "cpHastySpace.h"
112
132
113
- // Chipmunk 6.2 .1
114
- #define CP_VERSION_MAJOR 6
115
- #define CP_VERSION_MINOR 2
133
+ // Chipmunk 7.0 .1
134
+ #define CP_VERSION_MAJOR 7
135
+ #define CP_VERSION_MINOR 0
116
136
#define CP_VERSION_RELEASE 1
117
137
118
138
/// Version string.
119
- extern const char * cpVersionString ;
120
-
121
- /// @deprecated
122
- void cpInitChipmunk (void );
123
-
124
- /// Enables segment to segment shape collisions.
125
- void cpEnableSegmentToSegmentCollisions (void );
126
-
139
+ CP_EXPORT extern const char * cpVersionString ;
127
140
128
141
/// Calculate the moment of inertia for a circle.
129
142
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
130
- cpFloat cpMomentForCircle (cpFloat m , cpFloat r1 , cpFloat r2 , cpVect offset );
143
+ CP_EXPORT cpFloat cpMomentForCircle (cpFloat m , cpFloat r1 , cpFloat r2 , cpVect offset );
131
144
132
145
/// Calculate area of a hollow circle.
133
146
/// @c r1 and @c r2 are the inner and outer diameters. A solid circle has an inner diameter of 0.
134
- cpFloat cpAreaForCircle (cpFloat r1 , cpFloat r2 );
147
+ CP_EXPORT cpFloat cpAreaForCircle (cpFloat r1 , cpFloat r2 );
135
148
136
149
/// Calculate the moment of inertia for a line segment.
137
150
/// Beveling radius is not supported.
138
- cpFloat cpMomentForSegment (cpFloat m , cpVect a , cpVect b );
151
+ CP_EXPORT cpFloat cpMomentForSegment (cpFloat m , cpVect a , cpVect b , cpFloat radius );
139
152
140
153
/// Calculate the area of a fattened (capsule shaped) line segment.
141
- cpFloat cpAreaForSegment (cpVect a , cpVect b , cpFloat r );
154
+ CP_EXPORT cpFloat cpAreaForSegment (cpVect a , cpVect b , cpFloat radius );
142
155
143
156
/// 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.
144
- cpFloat cpMomentForPoly (cpFloat m , int numVerts , const cpVect * verts , cpVect offset );
157
+ CP_EXPORT cpFloat cpMomentForPoly (cpFloat m , int count , const cpVect * verts , cpVect offset , cpFloat radius );
145
158
146
159
/// Calculate the signed area of a polygon. A Clockwise winding gives positive area.
147
160
/// This is probably backwards from what you expect, but matches Chipmunk's the winding for poly shapes.
148
- cpFloat cpAreaForPoly (const int numVerts , const cpVect * verts );
161
+ CP_EXPORT cpFloat cpAreaForPoly (const int count , const cpVect * verts , cpFloat radius );
149
162
150
163
/// Calculate the natural centroid of a polygon.
151
- cpVect cpCentroidForPoly (const int numVerts , const cpVect * verts );
152
-
153
- /// Center the polygon on the origin. (Subtracts the centroid of the polygon from each vertex)
154
- void cpRecenterPoly (const int numVerts , cpVect * verts );
164
+ CP_EXPORT cpVect cpCentroidForPoly (const int count , const cpVect * verts );
155
165
156
166
/// Calculate the moment of inertia for a solid box.
157
- cpFloat cpMomentForBox (cpFloat m , cpFloat width , cpFloat height );
167
+ CP_EXPORT cpFloat cpMomentForBox (cpFloat m , cpFloat width , cpFloat height );
158
168
159
169
/// Calculate the moment of inertia for a solid box.
160
- cpFloat cpMomentForBox2 (cpFloat m , cpBB box );
170
+ CP_EXPORT cpFloat cpMomentForBox2 (cpFloat m , cpBB box );
161
171
162
172
/// Calculate the convex hull of a given set of points. Returns the count of points in the hull.
163
- /// @c result must be a pointer to a @c cpVect array with at least @c count elements. If @c result is @c NULL , then @c verts will be reduced instead .
173
+ /// @c result must be a pointer to a @c cpVect array with at least @c count elements. If @c verts == @c result , then @c verts will be reduced inplace .
164
174
/// @c 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])
165
175
/// @c tol is the allowed amount to shrink the hull when simplifying it. A tolerance of 0.0 creates an exact hull.
166
- int cpConvexHull (int count , cpVect * verts , cpVect * result , int * first , cpFloat tol );
176
+ CP_EXPORT int cpConvexHull (int count , const cpVect * verts , cpVect * result , int * first , cpFloat tol );
167
177
168
178
#ifdef _MSC_VER
169
179
#include "malloc.h"
@@ -177,6 +187,15 @@ int cpConvexHull(int count, cpVect *verts, cpVect *result, int *first, cpFloat t
177
187
cpVect *__verts_var__ = (cpVect *)alloca(__count__*sizeof(cpVect)); \
178
188
int __count_var__ = cpConvexHull(__count__, __verts__, __verts_var__, NULL, 0.0); \
179
189
190
+ /// Returns the closest point on the line segment ab, to the point p.
191
+ static inline cpVect
192
+ cpClosetPointOnSegment (const cpVect p , const cpVect a , const cpVect b )
193
+ {
194
+ cpVect delta = cpvsub (a , b );
195
+ cpFloat t = cpfclamp01 (cpvdot (delta , cpvsub (p , b ))/cpvlengthsq (delta ));
196
+ return cpvadd (b , cpvmult (delta , t ));
197
+ }
198
+
180
199
#if defined(__has_extension )
181
200
#if __has_extension (blocks )
182
201
// Define alternate block based alternatives for a few of the callback heavy functions.
@@ -191,14 +210,14 @@ void cpBodyEachShape_b(cpBody *body, void (^block)(cpShape *shape));
191
210
void cpBodyEachConstraint_b (cpBody * body , void (^block )(cpConstraint * constraint ));
192
211
void cpBodyEachArbiter_b (cpBody * body , void (^block )(cpArbiter * arbiter ));
193
212
194
- typedef void (^cpSpaceNearestPointQueryBlock )(cpShape * shape , cpFloat distance , cpVect point );
195
- void cpSpaceNearestPointQuery_b (cpSpace * space , cpVect point , cpFloat maxDistance , cpLayers layers , cpGroup group , cpSpaceNearestPointQueryBlock block );
213
+ typedef void (^cpSpacePointQueryBlock )(cpShape * shape , cpVect point , cpFloat distance , cpVect gradient );
214
+ void cpSpacePointQuery_b (cpSpace * space , cpVect point , cpFloat maxDistance , cpShapeFilter filter , cpSpacePointQueryBlock block );
196
215
197
- typedef void (^cpSpaceSegmentQueryBlock )(cpShape * shape , cpFloat t , cpVect n );
198
- void cpSpaceSegmentQuery_b (cpSpace * space , cpVect start , cpVect end , cpLayers layers , cpGroup group , cpSpaceSegmentQueryBlock block );
216
+ typedef void (^cpSpaceSegmentQueryBlock )(cpShape * shape , cpVect point , cpVect normal , cpFloat alpha );
217
+ void cpSpaceSegmentQuery_b (cpSpace * space , cpVect start , cpVect end , cpFloat radius , cpShapeFilter filter , cpSpaceSegmentQueryBlock block );
199
218
200
219
typedef void (^cpSpaceBBQueryBlock )(cpShape * shape );
201
- void cpSpaceBBQuery_b (cpSpace * space , cpBB bb , cpLayers layers , cpGroup group , cpSpaceBBQueryBlock block );
220
+ void cpSpaceBBQuery_b (cpSpace * space , cpBB bb , cpShapeFilter filter , cpSpaceBBQueryBlock block );
202
221
203
222
typedef void (^cpSpaceShapeQueryBlock )(cpShape * shape , cpContactPointSet * points );
204
223
cpBool cpSpaceShapeQuery_b (cpSpace * space , cpShape * shape , cpSpaceShapeQueryBlock block );
0 commit comments