chipmunk 5.3.4.0-x86-mingw32 → 5.3.4.2-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/README +33 -13
  2. data/Rakefile +20 -7
  3. data/ext/chipmunk/extconf.rb +55 -12
  4. data/ext/chipmunk/rb_chipmunk.c +92 -98
  5. data/ext/chipmunk/rb_chipmunk.h +44 -34
  6. data/ext/chipmunk/rb_cpArbiter.c +135 -98
  7. data/ext/chipmunk/rb_cpBB.c +84 -101
  8. data/ext/chipmunk/rb_cpBody.c +219 -241
  9. data/ext/chipmunk/rb_cpConstraint.c +173 -185
  10. data/ext/chipmunk/rb_cpShape.c +347 -251
  11. data/ext/chipmunk/rb_cpSpace.c +376 -408
  12. data/ext/chipmunk/rb_cpVect.c +132 -170
  13. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk.h +163 -0
  14. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_ffi.h +59 -0
  15. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_private.h +49 -0
  16. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_types.h +151 -0
  17. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/chipmunk_unsafe.h +54 -0
  18. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpConstraint.h +105 -0
  19. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
  20. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpDampedSpring.h +53 -0
  21. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGearJoint.h +41 -0
  22. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpGrooveJoint.h +48 -0
  23. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPinJoint.h +43 -0
  24. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpPivotJoint.h +42 -0
  25. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
  26. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
  27. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
  28. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/cpSlideJoint.h +44 -0
  29. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/constraints/util.h +134 -0
  30. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArbiter.h +188 -0
  31. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpArray.h +49 -0
  32. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBB.h +74 -0
  33. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpBody.h +219 -0
  34. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpCollision.h +28 -0
  35. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpHashSet.h +82 -0
  36. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpPolyShape.h +103 -0
  37. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpShape.h +177 -0
  38. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpace.h +206 -0
  39. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpSpaceHash.h +110 -0
  40. data/ext/chipmunk/vendor/chipmunk-5.3.4/include/chipmunk/cpVect.h +207 -0
  41. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/chipmunk.c +151 -0
  42. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpConstraint.c +54 -0
  43. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedRotarySpring.c +105 -0
  44. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpDampedSpring.c +115 -0
  45. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGearJoint.c +113 -0
  46. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpGrooveJoint.c +161 -0
  47. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPinJoint.c +116 -0
  48. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpPivotJoint.c +114 -0
  49. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRatchetJoint.c +126 -0
  50. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpRotaryLimitJoint.c +120 -0
  51. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSimpleMotor.c +97 -0
  52. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/constraints/cpSlideJoint.c +129 -0
  53. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArbiter.c +280 -0
  54. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpArray.c +143 -0
  55. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBB.c +47 -0
  56. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpBody.c +192 -0
  57. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpCollision.c +411 -0
  58. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpHashSet.c +253 -0
  59. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpPolyShape.c +240 -0
  60. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpShape.c +405 -0
  61. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpace.c +499 -0
  62. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceComponent.c +279 -0
  63. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceHash.c +534 -0
  64. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceQuery.c +246 -0
  65. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpSpaceStep.c +398 -0
  66. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/cpVect.c +71 -0
  67. data/ext/chipmunk/vendor/chipmunk-5.3.4/src/prime.h +68 -0
  68. data/lib/1.9/chipmunk.so +0 -0
  69. data/lib/chipmunk.rb +19 -8
  70. metadata +84 -42
  71. data/lib/1.8/chipmunk.so +0 -0
@@ -0,0 +1,37 @@
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
+ const cpConstraintClass *cpSimpleMotorGetClass();
23
+
24
+ typedef struct cpSimpleMotor {
25
+ cpConstraint constraint;
26
+ cpFloat rate;
27
+
28
+ cpFloat iSum;
29
+
30
+ cpFloat jAcc, jMax;
31
+ } cpSimpleMotor;
32
+
33
+ cpSimpleMotor *cpSimpleMotorAlloc(void);
34
+ cpSimpleMotor *cpSimpleMotorInit(cpSimpleMotor *joint, cpBody *a, cpBody *b, cpFloat rate);
35
+ cpConstraint *cpSimpleMotorNew(cpBody *a, cpBody *b, cpFloat rate);
36
+
37
+ CP_DefineConstraintProperty(cpSimpleMotor, cpFloat, rate, Rate);
@@ -0,0 +1,44 @@
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
+ const cpConstraintClass *cpSlideJointGetClass();
23
+
24
+ typedef struct cpSlideJoint {
25
+ cpConstraint constraint;
26
+ cpVect anchr1, anchr2;
27
+ cpFloat min, max;
28
+
29
+ cpVect r1, r2;
30
+ cpVect n;
31
+ cpFloat nMass;
32
+
33
+ cpFloat jnAcc, jnMax;
34
+ cpFloat bias;
35
+ } cpSlideJoint;
36
+
37
+ cpSlideJoint *cpSlideJointAlloc(void);
38
+ cpSlideJoint *cpSlideJointInit(cpSlideJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max);
39
+ cpConstraint *cpSlideJointNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max);
40
+
41
+ CP_DefineConstraintProperty(cpSlideJoint, cpVect, anchr1, Anchr1);
42
+ CP_DefineConstraintProperty(cpSlideJoint, cpVect, anchr2, Anchr2);
43
+ CP_DefineConstraintProperty(cpSlideJoint, cpFloat, min, Min);
44
+ CP_DefineConstraintProperty(cpSlideJoint, cpFloat, max, Max);
@@ -0,0 +1,134 @@
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
+ #define CP_DefineClassGetter(t) const cpConstraintClass * t##GetClass(){return (cpConstraintClass *)&klass;}
23
+
24
+ void cpConstraintInit(cpConstraint *constraint, const cpConstraintClass *klass, cpBody *a, cpBody *b);
25
+
26
+ #define J_MAX(constraint, dt) (((cpConstraint *)constraint)->maxForce*(dt))
27
+
28
+ // Get valid body pointers and exit early if the bodies are idle
29
+ #define CONSTRAINT_BEGIN(constraint, a_var, b_var) \
30
+ cpBody *a_var, *b_var; { \
31
+ a_var = ((cpConstraint *)constraint)->a; \
32
+ b_var = ((cpConstraint *)constraint)->b; \
33
+ if( \
34
+ (cpBodyIsSleeping(a_var) || cpBodyIsStatic(a_var)) && \
35
+ (cpBodyIsSleeping(b_var) || cpBodyIsStatic(b_var)) \
36
+ ) return; \
37
+ }
38
+
39
+ static inline cpVect
40
+ relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2){
41
+ cpVect v1_sum = cpvadd(a->v, cpvmult(cpvperp(r1), a->w));
42
+ cpVect v2_sum = cpvadd(b->v, cpvmult(cpvperp(r2), b->w));
43
+
44
+ return cpvsub(v2_sum, v1_sum);
45
+ }
46
+
47
+ static inline cpFloat
48
+ normal_relative_velocity(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n){
49
+ return cpvdot(relative_velocity(a, b, r1, r2), n);
50
+ }
51
+
52
+ static inline void
53
+ apply_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
54
+ {
55
+ cpBodyApplyImpulse(a, cpvneg(j), r1);
56
+ cpBodyApplyImpulse(b, j, r2);
57
+ }
58
+
59
+ static inline void
60
+ apply_bias_impulse(cpBody *body, cpVect j, cpVect r)
61
+ {
62
+ body->v_bias = cpvadd(body->v_bias, cpvmult(j, body->m_inv));
63
+ body->w_bias += body->i_inv*cpvcross(r, j);
64
+ }
65
+
66
+ static inline void
67
+ apply_bias_impulses(cpBody *a , cpBody *b, cpVect r1, cpVect r2, cpVect j)
68
+ {
69
+ apply_bias_impulse(a, cpvneg(j), r1);
70
+ apply_bias_impulse(b, j, r2);
71
+ }
72
+
73
+ static inline cpVect
74
+ clamp_vect(cpVect v, cpFloat len)
75
+ {
76
+ return cpvclamp(v, len);
77
+ // return (cpvdot(v,v) > len*len) ? cpvmult(cpvnormalize(v), len) : v;
78
+ }
79
+
80
+ static inline cpFloat
81
+ k_scalar(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect n)
82
+ {
83
+ cpFloat mass_sum = a->m_inv + b->m_inv;
84
+ cpFloat r1cn = cpvcross(r1, n);
85
+ cpFloat r2cn = cpvcross(r2, n);
86
+
87
+ cpFloat value = mass_sum + a->i_inv*r1cn*r1cn + b->i_inv*r2cn*r2cn;
88
+ cpAssert(value != 0.0, "Unsolvable collision or constraint.");
89
+
90
+ return value;
91
+ }
92
+
93
+ static inline void
94
+ k_tensor(cpBody *a, cpBody *b, cpVect r1, cpVect r2, cpVect *k1, cpVect *k2)
95
+ {
96
+ // calculate mass matrix
97
+ // If I wasn't lazy and wrote a proper matrix class, this wouldn't be so gross...
98
+ cpFloat k11, k12, k21, k22;
99
+ cpFloat m_sum = a->m_inv + b->m_inv;
100
+
101
+ // start with I*m_sum
102
+ k11 = m_sum; k12 = 0.0f;
103
+ k21 = 0.0f; k22 = m_sum;
104
+
105
+ // add the influence from r1
106
+ cpFloat a_i_inv = a->i_inv;
107
+ cpFloat r1xsq = r1.x * r1.x * a_i_inv;
108
+ cpFloat r1ysq = r1.y * r1.y * a_i_inv;
109
+ cpFloat r1nxy = -r1.x * r1.y * a_i_inv;
110
+ k11 += r1ysq; k12 += r1nxy;
111
+ k21 += r1nxy; k22 += r1xsq;
112
+
113
+ // add the influnce from r2
114
+ cpFloat b_i_inv = b->i_inv;
115
+ cpFloat r2xsq = r2.x * r2.x * b_i_inv;
116
+ cpFloat r2ysq = r2.y * r2.y * b_i_inv;
117
+ cpFloat r2nxy = -r2.x * r2.y * b_i_inv;
118
+ k11 += r2ysq; k12 += r2nxy;
119
+ k21 += r2nxy; k22 += r2xsq;
120
+
121
+ // invert
122
+ cpFloat determinant = k11*k22 - k12*k21;
123
+ cpAssert(determinant != 0.0, "Unsolvable constraint.");
124
+
125
+ cpFloat det_inv = 1.0f/determinant;
126
+ *k1 = cpv( k22*det_inv, -k12*det_inv);
127
+ *k2 = cpv(-k21*det_inv, k11*det_inv);
128
+ }
129
+
130
+ static inline cpVect
131
+ mult_k(cpVect vr, cpVect k1, cpVect k2)
132
+ {
133
+ return cpv(cpvdot(vr, k1), cpvdot(vr, k2));
134
+ }
@@ -0,0 +1,188 @@
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 CP_PRIVATE(p), CP_PRIVATE(n);
35
+ // Penetration distance.
36
+ CP_PRIVATE(cpFloat dist);
37
+
38
+ // Calculated by cpArbiterPreStep().
39
+ cpVect CP_PRIVATE(r1), CP_PRIVATE(r2);
40
+ cpFloat CP_PRIVATE(nMass), CP_PRIVATE(tMass), CP_PRIVATE(bounce);
41
+
42
+ // Persistant contact information.
43
+ cpFloat CP_PRIVATE(jnAcc), CP_PRIVATE(jtAcc), CP_PRIVATE(jBias);
44
+ CP_PRIVATE(cpFloat bias);
45
+
46
+ // Hash value used to (mostly) uniquely identify a contact.
47
+ CP_PRIVATE(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 CP_PRIVATE(cpContactsSumImpulses)(cpContact *contacts, int numContacts);
55
+ cpVect CP_PRIVATE(cpContactsSumImpulsesWithFriction)(cpContact *contacts, int numContacts);
56
+
57
+ #define CP_MAX_CONTACTS_PER_ARBITER 6
58
+
59
+ typedef enum cpArbiterState {
60
+ cpArbiterStateNormal,
61
+ cpArbiterStateFirstColl,
62
+ cpArbiterStateIgnore,
63
+ cpArbiterStateSleep,
64
+ cpArbiterStateCached,
65
+ } cpArbiterState;
66
+
67
+ // Data structure for tracking collisions between shapes.
68
+ typedef struct cpArbiter {
69
+ // Information on the contact points between the objects.
70
+ CP_PRIVATE(int numContacts);
71
+ CP_PRIVATE(cpContact *contacts);
72
+
73
+ // The two shapes and bodies involved in the collision.
74
+ // These variables are NOT in the order defined by the collision handler.
75
+ // Using CP_ARBITER_GET_SHAPES and CP_ARBITER_GET_BODIES will save you from
76
+ // many headaches
77
+ cpShape CP_PRIVATE(*a), CP_PRIVATE(*b);
78
+
79
+ // Calculated before calling the pre-solve collision handler
80
+ // Override them with custom values if you want specialized behavior
81
+ CP_PRIVATE(cpFloat e);
82
+ CP_PRIVATE(cpFloat u);
83
+ // Used for surface_v calculations, implementation may change
84
+ CP_PRIVATE(cpVect surface_vr);
85
+
86
+ // Time stamp of the arbiter. (from cpSpace)
87
+ CP_PRIVATE(cpTimestamp stamp);
88
+
89
+ CP_PRIVATE(struct cpCollisionHandler *handler);
90
+
91
+ // Are the shapes swapped in relation to the collision handler?
92
+ CP_PRIVATE(cpBool swappedColl);
93
+ CP_PRIVATE(cpArbiterState state);
94
+ } cpArbiter;
95
+
96
+ // Arbiters are allocated in large buffers by the space and don't require a destroy function
97
+ cpArbiter* CP_PRIVATE(cpArbiterInit)(cpArbiter *arb, cpShape *a, cpShape *b);
98
+
99
+ // These functions are all intended to be used internally.
100
+ // Inject new contact points into the arbiter while preserving contact history.
101
+ void CP_PRIVATE(cpArbiterUpdate)(cpArbiter *arb, cpContact *contacts, int numContacts, struct cpCollisionHandler *handler, cpShape *a, cpShape *b);
102
+ // Precalculate values used by the solver.
103
+ void CP_PRIVATE(cpArbiterPreStep)(cpArbiter *arb, cpFloat dt_inv);
104
+ void CP_PRIVATE(cpArbiterApplyCachedImpulse)(cpArbiter *arb);
105
+ // Run an iteration of the solver on the arbiter.
106
+ void CP_PRIVATE(cpArbiterApplyImpulse)(cpArbiter *arb, cpFloat eCoef);
107
+
108
+ // Arbiter Helper Functions
109
+ cpVect cpArbiterTotalImpulse(cpArbiter *arb);
110
+ cpVect cpArbiterTotalImpulseWithFriction(cpArbiter *arb);
111
+ void cpArbiterIgnore(cpArbiter *arb);
112
+
113
+
114
+ static inline void
115
+ cpArbiterGetShapes(const cpArbiter *arb, cpShape **a, cpShape **b)
116
+ {
117
+ if(arb->CP_PRIVATE(swappedColl)){
118
+ (*a) = arb->CP_PRIVATE(b), (*b) = arb->CP_PRIVATE(a);
119
+ } else {
120
+ (*a) = arb->CP_PRIVATE(a), (*b) = arb->CP_PRIVATE(b);
121
+ }
122
+ }
123
+ #define CP_ARBITER_GET_SHAPES(arb, a, b) cpShape *a, *b; cpArbiterGetShapes(arb, &a, &b);
124
+
125
+ static inline void
126
+ cpArbiterGetBodies(const cpArbiter *arb, cpBody **a, cpBody **b)
127
+ {
128
+ CP_ARBITER_GET_SHAPES(arb, shape_a, shape_b);
129
+ (*a) = shape_a->body;
130
+ (*b) = shape_b->body;
131
+ }
132
+ #define CP_ARBITER_GET_BODIES(arb, a, b) cpBody *a, *b; cpArbiterGetBodies(arb, &a, &b);
133
+
134
+ static inline cpBool
135
+ cpArbiterIsFirstContact(const cpArbiter *arb)
136
+ {
137
+ return arb->CP_PRIVATE(state) == cpArbiterStateFirstColl;
138
+ }
139
+
140
+ static inline int
141
+ cpArbiterGetCount(const cpArbiter *arb)
142
+ {
143
+ return arb->CP_PRIVATE(numContacts);
144
+ }
145
+
146
+ static inline cpVect
147
+ cpArbiterGetNormal(const cpArbiter *arb, int i)
148
+ {
149
+ cpVect n = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(n);
150
+ return arb->CP_PRIVATE(swappedColl) ? cpvneg(n) : n;
151
+ }
152
+
153
+ static inline cpVect
154
+ cpArbiterGetPoint(const cpArbiter *arb, int i)
155
+ {
156
+ return arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(p);
157
+ }
158
+
159
+ static inline cpFloat
160
+ cpArbiteGetDepth(const cpArbiter *arb, int i)
161
+ {
162
+ return arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(dist);
163
+ }
164
+
165
+ typedef struct cpContactPointSet {
166
+ int count;
167
+
168
+ struct {
169
+ cpVect point, normal;
170
+ cpFloat dist;
171
+ } points[CP_MAX_CONTACTS_PER_ARBITER];
172
+ } cpContactPointSet;
173
+
174
+ static inline cpContactPointSet
175
+ cpArbiterGetContactPointSet(const cpArbiter *arb)
176
+ {
177
+ cpContactPointSet set;
178
+ set.count = cpArbiterGetCount(arb);
179
+
180
+ int i;
181
+ for(i=0; i<set.count; i++){
182
+ set.points[i].point = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(p);
183
+ set.points[i].normal = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(n);
184
+ set.points[i].dist = arb->CP_PRIVATE(contacts)[i].CP_PRIVATE(dist);
185
+ }
186
+
187
+ return set;
188
+ }
@@ -0,0 +1,49 @@
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
+ CP_PRIVATE(int num);
26
+ CP_PRIVATE(int max);
27
+ CP_PRIVATE(void **arr);
28
+ } cpArray;
29
+
30
+ typedef void (*cpArrayIter)(void *ptr, void *data);
31
+
32
+ cpArray *cpArrayAlloc(void);
33
+ cpArray *cpArrayInit(cpArray *arr, int size);
34
+ cpArray *cpArrayNew(int size);
35
+
36
+ void cpArrayDestroy(cpArray *arr);
37
+ void cpArrayFree(cpArray *arr);
38
+
39
+ void cpArrayClear(cpArray *arr);
40
+
41
+ void cpArrayPush(cpArray *arr, void *object);
42
+ void *cpArrayPop(cpArray *arr);
43
+ void cpArrayDeleteIndex(cpArray *arr, int idx);
44
+ void cpArrayDeleteObj(cpArray *arr, void *obj);
45
+
46
+ void cpArrayAppend(cpArray *arr, cpArray *other);
47
+
48
+ void cpArrayEach(cpArray *arr, cpArrayIter iterFunc, void *data);
49
+ cpBool cpArrayContains(cpArray *arr, void *ptr);