chipmunk 5.2.2 → 5.3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -19
- data/README +67 -60
- data/Rakefile +85 -50
- data/ext/chipmunk/extconf.rb +42 -35
- data/ext/chipmunk/rb_chipmunk.c +250 -125
- data/ext/chipmunk/rb_chipmunk.h +105 -96
- data/ext/chipmunk/rb_cpArbiter.c +253 -225
- data/ext/chipmunk/rb_cpBB.c +210 -174
- data/ext/chipmunk/rb_cpBody.c +504 -347
- data/ext/chipmunk/rb_cpConstraint.c +336 -346
- data/ext/chipmunk/rb_cpShape.c +433 -455
- data/ext/chipmunk/rb_cpSpace.c +711 -544
- data/ext/chipmunk/rb_cpVect.c +346 -321
- data/lib/chipmunk.rb +183 -30
- metadata +12 -66
- data/ext/chipmunk/chipmunk.c +0 -105
- data/ext/chipmunk/cpArbiter.c +0 -274
- data/ext/chipmunk/cpArray.c +0 -128
- data/ext/chipmunk/cpBB.c +0 -47
- data/ext/chipmunk/cpBody.c +0 -188
- data/ext/chipmunk/cpCollision.c +0 -391
- data/ext/chipmunk/cpConstraint.c +0 -54
- data/ext/chipmunk/cpDampedRotarySpring.c +0 -106
- data/ext/chipmunk/cpDampedSpring.c +0 -117
- data/ext/chipmunk/cpGearJoint.c +0 -114
- data/ext/chipmunk/cpGrooveJoint.c +0 -138
- data/ext/chipmunk/cpHashSet.c +0 -253
- data/ext/chipmunk/cpPinJoint.c +0 -117
- data/ext/chipmunk/cpPivotJoint.c +0 -114
- data/ext/chipmunk/cpPolyShape.c +0 -241
- data/ext/chipmunk/cpRatchetJoint.c +0 -128
- data/ext/chipmunk/cpRotaryLimitJoint.c +0 -122
- data/ext/chipmunk/cpShape.c +0 -400
- data/ext/chipmunk/cpSimpleMotor.c +0 -99
- data/ext/chipmunk/cpSlideJoint.c +0 -131
- data/ext/chipmunk/cpSpace.c +0 -899
- data/ext/chipmunk/cpSpaceHash.c +0 -541
- data/ext/chipmunk/cpVect.c +0 -71
- data/ext/chipmunk/include/chipmunk/chipmunk.h +0 -148
- data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +0 -42
- data/ext/chipmunk/include/chipmunk/chipmunk_types.h +0 -80
- data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +0 -54
- data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +0 -92
- data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +0 -46
- data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +0 -53
- data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +0 -41
- data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +0 -44
- data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +0 -43
- data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +0 -42
- data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +0 -40
- data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +0 -39
- data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +0 -37
- data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +0 -44
- data/ext/chipmunk/include/chipmunk/constraints/util.h +0 -116
- data/ext/chipmunk/include/chipmunk/cpArbiter.h +0 -136
- data/ext/chipmunk/include/chipmunk/cpArray.h +0 -46
- data/ext/chipmunk/include/chipmunk/cpBB.h +0 -74
- data/ext/chipmunk/include/chipmunk/cpBody.h +0 -160
- data/ext/chipmunk/include/chipmunk/cpCollision.h +0 -23
- data/ext/chipmunk/include/chipmunk/cpHashSet.h +0 -82
- data/ext/chipmunk/include/chipmunk/cpPolyShape.h +0 -103
- data/ext/chipmunk/include/chipmunk/cpShape.h +0 -174
- data/ext/chipmunk/include/chipmunk/cpSpace.h +0 -180
- data/ext/chipmunk/include/chipmunk/cpSpaceHash.h +0 -109
- data/ext/chipmunk/include/chipmunk/cpVect.h +0 -157
- data/ext/chipmunk/prime.h +0 -68
- data/lib/chipmunk/version.rb +0 -3
@@ -1,136 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
* of this software and associated documentation files (the "Software"), to deal
|
5
|
-
* in the Software without restriction, including without limitation the rights
|
6
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
* copies of the Software, and to permit persons to whom the Software is
|
8
|
-
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
10
|
-
* The above copyright notice and this permission notice shall be included in
|
11
|
-
* all copies or substantial portions of the Software.
|
12
|
-
*
|
13
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
* SOFTWARE.
|
20
|
-
*/
|
21
|
-
|
22
|
-
struct cpArbiter;
|
23
|
-
struct cpSpace;
|
24
|
-
struct cpCollisionHandler;
|
25
|
-
|
26
|
-
// Determines how fast penetrations resolve themselves.
|
27
|
-
extern cpFloat cp_bias_coef;
|
28
|
-
// Amount of allowed penetration. Used to reduce vibrating contacts.
|
29
|
-
extern cpFloat cp_collision_slop;
|
30
|
-
|
31
|
-
// Data structure for contact points.
|
32
|
-
typedef struct cpContact {
|
33
|
-
// Contact point and normal.
|
34
|
-
cpVect p, n;
|
35
|
-
// Penetration distance.
|
36
|
-
cpFloat dist;
|
37
|
-
|
38
|
-
// Calculated by cpArbiterPreStep().
|
39
|
-
cpVect r1, r2;
|
40
|
-
cpFloat nMass, tMass, bounce;
|
41
|
-
|
42
|
-
// Persistant contact information.
|
43
|
-
cpFloat jnAcc, jtAcc, jBias;
|
44
|
-
cpFloat bias;
|
45
|
-
|
46
|
-
// Hash value used to (mostly) uniquely identify a contact.
|
47
|
-
cpHashValue hash;
|
48
|
-
} cpContact;
|
49
|
-
|
50
|
-
// Contacts are always allocated in groups.
|
51
|
-
cpContact* cpContactInit(cpContact *con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash);
|
52
|
-
|
53
|
-
// Sum the contact impulses. (Can be used after cpSpaceStep() returns)
|
54
|
-
cpVect cpContactsSumImpulses(cpContact *contacts, int numContacts);
|
55
|
-
cpVect cpContactsSumImpulsesWithFriction(cpContact *contacts, int numContacts);
|
56
|
-
|
57
|
-
typedef enum cpArbiterState {
|
58
|
-
cpArbiterStateNormal,
|
59
|
-
cpArbiterStateFirstColl,
|
60
|
-
cpArbiterStateIgnore,
|
61
|
-
} cpArbiterState;
|
62
|
-
|
63
|
-
// Data structure for tracking collisions between shapes.
|
64
|
-
typedef struct cpArbiter {
|
65
|
-
// Information on the contact points between the objects.
|
66
|
-
int numContacts;
|
67
|
-
cpContact *contacts;
|
68
|
-
|
69
|
-
// The two shapes involved in the collision.
|
70
|
-
// These variables are NOT in the order defined by the collision handler.
|
71
|
-
cpShape *private_a, *private_b;
|
72
|
-
|
73
|
-
// Calculated before calling the pre-solve collision handler
|
74
|
-
// Override them with custom values if you want specialized behavior
|
75
|
-
cpFloat e;
|
76
|
-
cpFloat u;
|
77
|
-
// Used for surface_v calculations, implementation may change
|
78
|
-
cpVect surface_vr;
|
79
|
-
|
80
|
-
// Time stamp of the arbiter. (from cpSpace)
|
81
|
-
int stamp;
|
82
|
-
|
83
|
-
struct cpCollisionHandler *handler;
|
84
|
-
|
85
|
-
// Are the shapes swapped in relation to the collision handler?
|
86
|
-
char swappedColl;
|
87
|
-
char state;
|
88
|
-
} cpArbiter;
|
89
|
-
|
90
|
-
// Arbiters are allocated in large buffers by the space and don't require a destroy function
|
91
|
-
cpArbiter* cpArbiterInit(cpArbiter *arb, cpShape *a, cpShape *b);
|
92
|
-
|
93
|
-
// These functions are all intended to be used internally.
|
94
|
-
// Inject new contact points into the arbiter while preserving contact history.
|
95
|
-
void cpArbiterUpdate(cpArbiter *arb, cpContact *contacts, int numContacts, struct cpCollisionHandler *handler, cpShape *a, cpShape *b);
|
96
|
-
// Precalculate values used by the solver.
|
97
|
-
void cpArbiterPreStep(cpArbiter *arb, cpFloat dt_inv);
|
98
|
-
void cpArbiterApplyCachedImpulse(cpArbiter *arb);
|
99
|
-
// Run an iteration of the solver on the arbiter.
|
100
|
-
void cpArbiterApplyImpulse(cpArbiter *arb, cpFloat eCoef);
|
101
|
-
|
102
|
-
// Arbiter Helper Functions
|
103
|
-
cpVect cpArbiterTotalImpulse(cpArbiter *arb);
|
104
|
-
cpVect cpArbiterTotalImpulseWithFriction(cpArbiter *arb);
|
105
|
-
void cpArbiterIgnore(cpArbiter *arb);
|
106
|
-
|
107
|
-
|
108
|
-
static inline void
|
109
|
-
cpArbiterGetShapes(cpArbiter *arb, cpShape **a, cpShape **b)
|
110
|
-
{
|
111
|
-
if(arb->swappedColl){
|
112
|
-
(*a) = arb->private_b, (*b) = arb->private_a;
|
113
|
-
} else {
|
114
|
-
(*a) = arb->private_a, (*b) = arb->private_b;
|
115
|
-
}
|
116
|
-
}
|
117
|
-
#define CP_ARBITER_GET_SHAPES(arb, a, b) cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
|
118
|
-
|
119
|
-
static inline int
|
120
|
-
cpArbiterIsFirstContact(cpArbiter *arb)
|
121
|
-
{
|
122
|
-
return arb->state == cpArbiterStateFirstColl;
|
123
|
-
}
|
124
|
-
|
125
|
-
static inline cpVect
|
126
|
-
cpArbiterGetNormal(cpArbiter *arb, int i)
|
127
|
-
{
|
128
|
-
cpVect n = arb->contacts[i].n;
|
129
|
-
return arb->swappedColl ? cpvneg(n) : n;
|
130
|
-
}
|
131
|
-
|
132
|
-
static inline cpVect
|
133
|
-
cpArbiterGetPoint(cpArbiter *arb, int i)
|
134
|
-
{
|
135
|
-
return arb->contacts[i].p;
|
136
|
-
}
|
@@ -1,46 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
* of this software and associated documentation files (the "Software"), to deal
|
5
|
-
* in the Software without restriction, including without limitation the rights
|
6
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
* copies of the Software, and to permit persons to whom the Software is
|
8
|
-
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
10
|
-
* The above copyright notice and this permission notice shall be included in
|
11
|
-
* all copies or substantial portions of the Software.
|
12
|
-
*
|
13
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
* SOFTWARE.
|
20
|
-
*/
|
21
|
-
|
22
|
-
// NOTE: cpArray is rarely used and will probably go away.
|
23
|
-
|
24
|
-
typedef struct cpArray{
|
25
|
-
int num, max;
|
26
|
-
void **arr;
|
27
|
-
} cpArray;
|
28
|
-
|
29
|
-
typedef void (*cpArrayIter)(void *ptr, void *data);
|
30
|
-
|
31
|
-
cpArray *cpArrayAlloc(void);
|
32
|
-
cpArray *cpArrayInit(cpArray *arr, int size);
|
33
|
-
cpArray *cpArrayNew(int size);
|
34
|
-
|
35
|
-
void cpArrayDestroy(cpArray *arr);
|
36
|
-
void cpArrayFree(cpArray *arr);
|
37
|
-
|
38
|
-
void cpArrayClear(cpArray *arr);
|
39
|
-
|
40
|
-
void cpArrayPush(cpArray *arr, void *object);
|
41
|
-
void *cpArrayPop(cpArray *arr);
|
42
|
-
void cpArrayDeleteIndex(cpArray *arr, int idx);
|
43
|
-
void cpArrayDeleteObj(cpArray *arr, void *obj);
|
44
|
-
|
45
|
-
void cpArrayEach(cpArray *arr, cpArrayIter iterFunc, void *data);
|
46
|
-
int cpArrayContains(cpArray *arr, void *ptr);
|
@@ -1,74 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
* of this software and associated documentation files (the "Software"), to deal
|
5
|
-
* in the Software without restriction, including without limitation the rights
|
6
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
* copies of the Software, and to permit persons to whom the Software is
|
8
|
-
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
10
|
-
* The above copyright notice and this permission notice shall be included in
|
11
|
-
* all copies or substantial portions of the Software.
|
12
|
-
*
|
13
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
* SOFTWARE.
|
20
|
-
*/
|
21
|
-
|
22
|
-
typedef struct cpBB{
|
23
|
-
cpFloat l, b, r ,t;
|
24
|
-
} cpBB;
|
25
|
-
|
26
|
-
static inline cpBB
|
27
|
-
cpBBNew(const cpFloat l, const cpFloat b,
|
28
|
-
const cpFloat r, const cpFloat t)
|
29
|
-
{
|
30
|
-
cpBB bb = {l, b, r, t};
|
31
|
-
return bb;
|
32
|
-
}
|
33
|
-
|
34
|
-
static inline int
|
35
|
-
cpBBintersects(const cpBB a, const cpBB b)
|
36
|
-
{
|
37
|
-
return (a.l<=b.r && b.l<=a.r && a.b<=b.t && b.b<=a.t);
|
38
|
-
}
|
39
|
-
|
40
|
-
static inline int
|
41
|
-
cpBBcontainsBB(const cpBB bb, const cpBB other)
|
42
|
-
{
|
43
|
-
return (bb.l < other.l && bb.r > other.r && bb.b < other.b && bb.t > other.t);
|
44
|
-
}
|
45
|
-
|
46
|
-
static inline int
|
47
|
-
cpBBcontainsVect(const cpBB bb, const cpVect v)
|
48
|
-
{
|
49
|
-
return (bb.l < v.x && bb.r > v.x && bb.b < v.y && bb.t > v.y);
|
50
|
-
}
|
51
|
-
|
52
|
-
static inline cpBB
|
53
|
-
cpBBmerge(const cpBB a, const cpBB b){
|
54
|
-
return cpBBNew(
|
55
|
-
cpfmin(a.l, b.l),
|
56
|
-
cpfmin(a.b, b.b),
|
57
|
-
cpfmax(a.r, b.r),
|
58
|
-
cpfmax(a.t, b.t)
|
59
|
-
);
|
60
|
-
}
|
61
|
-
|
62
|
-
static inline cpBB
|
63
|
-
cpBBexpand(const cpBB bb, const cpVect v){
|
64
|
-
return cpBBNew(
|
65
|
-
cpfmin(bb.l, v.x),
|
66
|
-
cpfmin(bb.b, v.y),
|
67
|
-
cpfmax(bb.r, v.x),
|
68
|
-
cpfmax(bb.t, v.y)
|
69
|
-
);
|
70
|
-
}
|
71
|
-
|
72
|
-
cpVect cpBBClampVect(const cpBB bb, const cpVect v); // clamps the vector to lie within the bbox
|
73
|
-
// TODO edge case issue
|
74
|
-
cpVect cpBBWrapVect(const cpBB bb, const cpVect v); // wrap a vector to a bbox
|
@@ -1,160 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
* of this software and associated documentation files (the "Software"), to deal
|
5
|
-
* in the Software without restriction, including without limitation the rights
|
6
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
* copies of the Software, and to permit persons to whom the Software is
|
8
|
-
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
10
|
-
* The above copyright notice and this permission notice shall be included in
|
11
|
-
* all copies or substantial portions of the Software.
|
12
|
-
*
|
13
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
* SOFTWARE.
|
20
|
-
*/
|
21
|
-
|
22
|
-
struct cpBody;
|
23
|
-
typedef void (*cpBodyVelocityFunc)(struct cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
|
24
|
-
typedef void (*cpBodyPositionFunc)(struct cpBody *body, cpFloat dt);
|
25
|
-
|
26
|
-
extern cpBodyVelocityFunc cpBodyUpdateVelocityDefault;
|
27
|
-
extern cpBodyPositionFunc cpBodyUpdatePositionDefault;
|
28
|
-
|
29
|
-
typedef struct cpBody{
|
30
|
-
// *** Integration Functions.ntoehu
|
31
|
-
|
32
|
-
// Function that is called to integrate the body's velocity. (Defaults to cpBodyUpdateVelocity)
|
33
|
-
cpBodyVelocityFunc velocity_func;
|
34
|
-
|
35
|
-
// Function that is called to integrate the body's position. (Defaults to cpBodyUpdatePosition)
|
36
|
-
cpBodyPositionFunc position_func;
|
37
|
-
|
38
|
-
// *** Mass Properties
|
39
|
-
|
40
|
-
// Mass and it's inverse.
|
41
|
-
// Always use cpBodySetMass() whenever changing the mass as these values must agree.
|
42
|
-
cpFloat m, m_inv;
|
43
|
-
|
44
|
-
// Moment of inertia and it's inverse.
|
45
|
-
// Always use cpBodySetMoment() whenever changing the moment as these values must agree.
|
46
|
-
cpFloat i, i_inv;
|
47
|
-
|
48
|
-
// *** Positional Properties
|
49
|
-
|
50
|
-
// Linear components of motion (position, velocity, and force)
|
51
|
-
cpVect p, v, f;
|
52
|
-
|
53
|
-
// Angular components of motion (angle, angular velocity, and torque)
|
54
|
-
// Always use cpBodySetAngle() to set the angle of the body as a and rot must agree.
|
55
|
-
cpFloat a, w, t;
|
56
|
-
|
57
|
-
// Cached unit length vector representing the angle of the body.
|
58
|
-
// Used for fast vector rotation using cpvrotate().
|
59
|
-
cpVect rot;
|
60
|
-
|
61
|
-
// *** User Definable Fields
|
62
|
-
|
63
|
-
// User defined data pointer.
|
64
|
-
cpDataPointer data;
|
65
|
-
|
66
|
-
// Maximum velocities this body can move at after integrating velocity
|
67
|
-
cpFloat v_limit, w_limit;
|
68
|
-
|
69
|
-
// *** Internally Used Fields
|
70
|
-
|
71
|
-
// Velocity bias values used when solving penetrations and correcting constraints.
|
72
|
-
cpVect v_bias;
|
73
|
-
cpFloat w_bias;
|
74
|
-
|
75
|
-
// int active;
|
76
|
-
} cpBody;
|
77
|
-
|
78
|
-
// Basic allocation/destruction functions
|
79
|
-
cpBody *cpBodyAlloc(void);
|
80
|
-
cpBody *cpBodyInit(cpBody *body, cpFloat m, cpFloat i);
|
81
|
-
cpBody *cpBodyNew(cpFloat m, cpFloat i);
|
82
|
-
|
83
|
-
void cpBodyDestroy(cpBody *body);
|
84
|
-
void cpBodyFree(cpBody *body);
|
85
|
-
|
86
|
-
#define CP_DefineBodyGetter(type, member, name) static inline type cpBodyGet##name(cpBody *body){return body->member;}
|
87
|
-
#define CP_DefineBodySetter(type, member, name) static inline void cpBodySet##name(cpBody *body, type value){body->member = value;}
|
88
|
-
|
89
|
-
#define CP_DefineBodyProperty(type, member, name) \
|
90
|
-
CP_DefineBodyGetter(type, member, name) \
|
91
|
-
CP_DefineBodySetter(type, member, name)
|
92
|
-
|
93
|
-
|
94
|
-
// Accessors for cpBody struct members
|
95
|
-
CP_DefineBodyGetter(cpFloat, m, Mass);
|
96
|
-
void cpBodySetMass(cpBody *body, cpFloat m);
|
97
|
-
|
98
|
-
CP_DefineBodyGetter(cpFloat, i, Moment);
|
99
|
-
void cpBodySetMoment(cpBody *body, cpFloat i);
|
100
|
-
|
101
|
-
|
102
|
-
CP_DefineBodyProperty(cpVect, p, Pos);
|
103
|
-
CP_DefineBodyProperty(cpVect, v, Vel);
|
104
|
-
CP_DefineBodyProperty(cpVect, f, Force);
|
105
|
-
CP_DefineBodyGetter(cpFloat, a, Angle);
|
106
|
-
void cpBodySetAngle(cpBody *body, cpFloat a);
|
107
|
-
CP_DefineBodyProperty(cpFloat, w, AngVel);
|
108
|
-
CP_DefineBodyProperty(cpFloat, t, Torque);
|
109
|
-
CP_DefineBodyGetter(cpVect, rot, Rot);
|
110
|
-
CP_DefineBodyProperty(cpFloat, v_limit, VelLimit);
|
111
|
-
CP_DefineBodyProperty(cpFloat, w_limit, AngVelLimit);
|
112
|
-
|
113
|
-
// Modify the velocity of the body so that it will move to the specified absolute coordinates in the next timestep.
|
114
|
-
// Intended for objects that are moved manually with a custom velocity integration function.
|
115
|
-
void cpBodySlew(cpBody *body, cpVect pos, cpFloat dt);
|
116
|
-
|
117
|
-
// Default Integration functions.
|
118
|
-
void cpBodyUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt);
|
119
|
-
void cpBodyUpdatePosition(cpBody *body, cpFloat dt);
|
120
|
-
|
121
|
-
// Convert body local to world coordinates
|
122
|
-
static inline cpVect
|
123
|
-
cpBodyLocal2World(cpBody *body, cpVect v)
|
124
|
-
{
|
125
|
-
return cpvadd(body->p, cpvrotate(v, body->rot));
|
126
|
-
}
|
127
|
-
|
128
|
-
// Convert world to body local coordinates
|
129
|
-
static inline cpVect
|
130
|
-
cpBodyWorld2Local(cpBody *body, cpVect v)
|
131
|
-
{
|
132
|
-
return cpvunrotate(cpvsub(v, body->p), body->rot);
|
133
|
-
}
|
134
|
-
|
135
|
-
// Apply an impulse (in world coordinates) to the body at a point relative to the center of gravity (also in world coordinates).
|
136
|
-
static inline void
|
137
|
-
cpBodyApplyImpulse(cpBody *body, cpVect j, cpVect r)
|
138
|
-
{
|
139
|
-
body->v = cpvadd(body->v, cpvmult(j, body->m_inv));
|
140
|
-
body->w += body->i_inv*cpvcross(r, j);
|
141
|
-
}
|
142
|
-
|
143
|
-
// Not intended for external use. Used by cpArbiter.c and cpConstraint.c.
|
144
|
-
static inline void
|
145
|
-
cpBodyApplyBiasImpulse(cpBody *body, cpVect j, cpVect r)
|
146
|
-
{
|
147
|
-
body->v_bias = cpvadd(body->v_bias, cpvmult(j, body->m_inv));
|
148
|
-
body->w_bias += body->i_inv*cpvcross(r, j);
|
149
|
-
}
|
150
|
-
|
151
|
-
// Zero the forces on a body.
|
152
|
-
void cpBodyResetForces(cpBody *body);
|
153
|
-
// Apply a force (in world coordinates) to a body at a point relative to the center of gravity (also in world coordinates).
|
154
|
-
void cpBodyApplyForce(cpBody *body, cpVect f, cpVect r);
|
155
|
-
|
156
|
-
// Apply a damped spring force between two bodies.
|
157
|
-
// Warning: Large damping values can be unstable. Use a cpDampedSpring constraint for this instead.
|
158
|
-
void cpApplyDampedSpring(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt);
|
159
|
-
|
160
|
-
//int cpBodyMarkLowEnergy(cpBody *body, cpFloat dvsq, int max);
|
@@ -1,23 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
* of this software and associated documentation files (the "Software"), to deal
|
5
|
-
* in the Software without restriction, including without limitation the rights
|
6
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
* copies of the Software, and to permit persons to whom the Software is
|
8
|
-
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
10
|
-
* The above copyright notice and this permission notice shall be included in
|
11
|
-
* all copies or substantial portions of the Software.
|
12
|
-
*
|
13
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
* SOFTWARE.
|
20
|
-
*/
|
21
|
-
|
22
|
-
// Collides two cpShape structures. (this function is lonely :( )
|
23
|
-
int cpCollideShapes(cpShape *a, cpShape *b, cpContact *arr);
|
@@ -1,82 +0,0 @@
|
|
1
|
-
/* Copyright (c) 2007 Scott Lembcke
|
2
|
-
*
|
3
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
* of this software and associated documentation files (the "Software"), to deal
|
5
|
-
* in the Software without restriction, including without limitation the rights
|
6
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
* copies of the Software, and to permit persons to whom the Software is
|
8
|
-
* furnished to do so, subject to the following conditions:
|
9
|
-
*
|
10
|
-
* The above copyright notice and this permission notice shall be included in
|
11
|
-
* all copies or substantial portions of the Software.
|
12
|
-
*
|
13
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
-
* SOFTWARE.
|
20
|
-
*/
|
21
|
-
|
22
|
-
// cpHashSet uses a chained hashtable implementation.
|
23
|
-
// Other than the transformation functions, there is nothing fancy going on.
|
24
|
-
|
25
|
-
// cpHashSetBin's form the linked lists in the chained hash table.
|
26
|
-
typedef struct cpHashSetBin {
|
27
|
-
// Pointer to the element.
|
28
|
-
void *elt;
|
29
|
-
// Hash value of the element.
|
30
|
-
cpHashValue hash;
|
31
|
-
// Next element in the chain.
|
32
|
-
struct cpHashSetBin *next;
|
33
|
-
} cpHashSetBin;
|
34
|
-
|
35
|
-
// Equality function. Returns true if ptr is equal to elt.
|
36
|
-
typedef int (*cpHashSetEqlFunc)(void *ptr, void *elt);
|
37
|
-
// Used by cpHashSetInsert(). Called to transform the ptr into an element.
|
38
|
-
typedef void *(*cpHashSetTransFunc)(void *ptr, void *data);
|
39
|
-
// Iterator function for a hashset.
|
40
|
-
typedef void (*cpHashSetIterFunc)(void *elt, void *data);
|
41
|
-
// Filter function. Returns false if elt should be dropped.
|
42
|
-
typedef int (*cpHashSetFilterFunc)(void *elt, void *data);
|
43
|
-
|
44
|
-
typedef struct cpHashSet {
|
45
|
-
// Number of elements stored in the table.
|
46
|
-
int entries;
|
47
|
-
// Number of cells in the table.
|
48
|
-
int size;
|
49
|
-
|
50
|
-
cpHashSetEqlFunc eql;
|
51
|
-
cpHashSetTransFunc trans;
|
52
|
-
|
53
|
-
// Default value returned by cpHashSetFind() when no element is found.
|
54
|
-
// Defaults to NULL.
|
55
|
-
void *default_value;
|
56
|
-
|
57
|
-
// The table and recycled bins
|
58
|
-
cpHashSetBin **table, *pooledBins;
|
59
|
-
|
60
|
-
cpArray *allocatedBuffers;
|
61
|
-
} cpHashSet;
|
62
|
-
|
63
|
-
// Basic allocation/destruction functions.
|
64
|
-
void cpHashSetDestroy(cpHashSet *set);
|
65
|
-
void cpHashSetFree(cpHashSet *set);
|
66
|
-
|
67
|
-
cpHashSet *cpHashSetAlloc(void);
|
68
|
-
cpHashSet *cpHashSetInit(cpHashSet *set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans);
|
69
|
-
cpHashSet *cpHashSetNew(int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans);
|
70
|
-
|
71
|
-
// Insert an element into the set, returns the element.
|
72
|
-
// If it doesn't already exist, the transformation function is applied.
|
73
|
-
void *cpHashSetInsert(cpHashSet *set, cpHashValue hash, void *ptr, void *data);
|
74
|
-
// Remove and return an element from the set.
|
75
|
-
void *cpHashSetRemove(cpHashSet *set, cpHashValue hash, void *ptr);
|
76
|
-
// Find an element in the set. Returns the default value if the element isn't found.
|
77
|
-
void *cpHashSetFind(cpHashSet *set, cpHashValue hash, void *ptr);
|
78
|
-
|
79
|
-
// Iterate over a hashset.
|
80
|
-
void cpHashSetEach(cpHashSet *set, cpHashSetIterFunc func, void *data);
|
81
|
-
// Iterate over a hashset, retain .
|
82
|
-
void cpHashSetFilter(cpHashSet *set, cpHashSetFilterFunc func, void *data);
|