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,129 @@
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
+ #include <stdlib.h>
23
+
24
+ #include "chipmunk_private.h"
25
+ #include "constraints/util.h"
26
+
27
+ static void
28
+ preStep(cpSlideJoint *joint, cpFloat dt, cpFloat dt_inv)
29
+ {
30
+ CONSTRAINT_BEGIN(joint, a, b);
31
+
32
+ joint->r1 = cpvrotate(joint->anchr1, a->rot);
33
+ joint->r2 = cpvrotate(joint->anchr2, b->rot);
34
+
35
+ cpVect delta = cpvsub(cpvadd(b->p, joint->r2), cpvadd(a->p, joint->r1));
36
+ cpFloat dist = cpvlength(delta);
37
+ cpFloat pdist = 0.0f;
38
+ if(dist > joint->max) {
39
+ pdist = dist - joint->max;
40
+ } else if(dist < joint->min) {
41
+ pdist = joint->min - dist;
42
+ dist = -dist;
43
+ }
44
+ joint->n = cpvmult(delta, 1.0f/(dist ? dist : (cpFloat)INFINITY));
45
+
46
+ // calculate mass normal
47
+ joint->nMass = 1.0f/k_scalar(a, b, joint->r1, joint->r2, joint->n);
48
+
49
+ // calculate bias velocity
50
+ cpFloat maxBias = joint->constraint.maxBias;
51
+ joint->bias = cpfclamp(-joint->constraint.biasCoef*dt_inv*(pdist), -maxBias, maxBias);
52
+
53
+ // compute max impulse
54
+ joint->jnMax = J_MAX(joint, dt);
55
+
56
+ // apply accumulated impulse
57
+ if(!joint->bias) //{
58
+ // if bias is 0, then the joint is not at a limit.
59
+ joint->jnAcc = 0.0f;
60
+ // } else {
61
+ cpVect j = cpvmult(joint->n, joint->jnAcc);
62
+ apply_impulses(a, b, joint->r1, joint->r2, j);
63
+ // }
64
+ }
65
+
66
+ static void
67
+ applyImpulse(cpSlideJoint *joint)
68
+ {
69
+ if(!joint->bias) return; // early exit
70
+
71
+ CONSTRAINT_BEGIN(joint, a, b);
72
+
73
+ cpVect n = joint->n;
74
+ cpVect r1 = joint->r1;
75
+ cpVect r2 = joint->r2;
76
+
77
+ // compute relative velocity
78
+ cpVect vr = relative_velocity(a, b, r1, r2);
79
+ cpFloat vrn = cpvdot(vr, n);
80
+
81
+ // compute normal impulse
82
+ cpFloat jn = (joint->bias - vrn)*joint->nMass;
83
+ cpFloat jnOld = joint->jnAcc;
84
+ joint->jnAcc = cpfclamp(jnOld + jn, -joint->jnMax, 0.0f);
85
+ jn = joint->jnAcc - jnOld;
86
+
87
+ // apply impulse
88
+ apply_impulses(a, b, joint->r1, joint->r2, cpvmult(n, jn));
89
+ }
90
+
91
+ static cpFloat
92
+ getImpulse(cpConstraint *joint)
93
+ {
94
+ return cpfabs(((cpSlideJoint *)joint)->jnAcc);
95
+ }
96
+
97
+ static const cpConstraintClass klass = {
98
+ (cpConstraintPreStepFunction)preStep,
99
+ (cpConstraintApplyImpulseFunction)applyImpulse,
100
+ (cpConstraintGetImpulseFunction)getImpulse,
101
+ };
102
+ CP_DefineClassGetter(cpSlideJoint)
103
+
104
+ cpSlideJoint *
105
+ cpSlideJointAlloc(void)
106
+ {
107
+ return (cpSlideJoint *)cpmalloc(sizeof(cpSlideJoint));
108
+ }
109
+
110
+ cpSlideJoint *
111
+ cpSlideJointInit(cpSlideJoint *joint, cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max)
112
+ {
113
+ cpConstraintInit((cpConstraint *)joint, &klass, a, b);
114
+
115
+ joint->anchr1 = anchr1;
116
+ joint->anchr2 = anchr2;
117
+ joint->min = min;
118
+ joint->max = max;
119
+
120
+ joint->jnAcc = 0.0f;
121
+
122
+ return joint;
123
+ }
124
+
125
+ cpConstraint *
126
+ cpSlideJointNew(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max)
127
+ {
128
+ return (cpConstraint *)cpSlideJointInit(cpSlideJointAlloc(), a, b, anchr1, anchr2, min, max);
129
+ }
@@ -0,0 +1,280 @@
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
+ #include <stdlib.h>
23
+
24
+ #include "chipmunk_private.h"
25
+ #include "constraints/util.h"
26
+
27
+ cpFloat cp_bias_coef = 0.1f;
28
+ cpFloat cp_collision_slop = 0.1f;
29
+
30
+ cpContact*
31
+ cpContactInit(cpContact *con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash)
32
+ {
33
+ con->p = p;
34
+ con->n = n;
35
+ con->dist = dist;
36
+
37
+ con->jnAcc = 0.0f;
38
+ con->jtAcc = 0.0f;
39
+ con->jBias = 0.0f;
40
+
41
+ con->hash = hash;
42
+
43
+ return con;
44
+ }
45
+
46
+ cpVect
47
+ cpArbiterTotalImpulse(cpArbiter *arb)
48
+ {
49
+ cpContact *contacts = arb->contacts;
50
+ cpVect sum = cpvzero;
51
+
52
+ for(int i=0, count=arb->numContacts; i<count; i++){
53
+ cpContact *con = &contacts[i];
54
+ sum = cpvadd(sum, cpvmult(con->n, con->jnAcc));
55
+ }
56
+
57
+ return sum;
58
+ }
59
+
60
+ cpVect
61
+ cpArbiterTotalImpulseWithFriction(cpArbiter *arb)
62
+ {
63
+ cpContact *contacts = arb->contacts;
64
+ cpVect sum = cpvzero;
65
+
66
+ for(int i=0, count=arb->numContacts; i<count; i++){
67
+ cpContact *con = &contacts[i];
68
+ sum = cpvadd(sum, cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc)));
69
+ }
70
+
71
+ return sum;
72
+ }
73
+
74
+ cpFloat
75
+ cpContactsEstimateCrushingImpulse(cpContact *contacts, int numContacts)
76
+ {
77
+ cpFloat fsum = 0.0f;
78
+ cpVect vsum = cpvzero;
79
+
80
+ for(int i=0; i<numContacts; i++){
81
+ cpContact *con = &contacts[i];
82
+ cpVect j = cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc));
83
+
84
+ fsum += cpvlength(j);
85
+ vsum = cpvadd(vsum, j);
86
+ }
87
+
88
+ cpFloat vmag = cpvlength(vsum);
89
+ return (1.0f - vmag/fsum);
90
+ }
91
+
92
+ void
93
+ cpArbiterIgnore(cpArbiter *arb)
94
+ {
95
+ arb->state = cpArbiterStateIgnore ;
96
+ }
97
+
98
+ cpArbiter*
99
+ cpArbiterAlloc(void)
100
+ {
101
+ return (cpArbiter *)cpcalloc(1, sizeof(cpArbiter));
102
+ }
103
+
104
+ cpArbiter*
105
+ cpArbiterInit(cpArbiter *arb, cpShape *a, cpShape *b)
106
+ {
107
+ arb->handler = NULL;
108
+ arb->swappedColl = cpFalse;
109
+
110
+ arb->e = 0.0f;
111
+ arb->u = 0.0f;
112
+ arb->surface_vr = cpvzero;
113
+
114
+ arb->numContacts = 0;
115
+ arb->contacts = NULL;
116
+
117
+ arb->a = a;
118
+ arb->b = b;
119
+
120
+ arb->stamp = 0;
121
+ arb->state = cpArbiterStateFirstColl;
122
+
123
+ return arb;
124
+ }
125
+
126
+ cpArbiter*
127
+ cpArbiterNew(cpShape *a, cpShape *b)
128
+ {
129
+ return cpArbiterInit(cpArbiterAlloc(), a, b);
130
+ }
131
+
132
+ void
133
+ cpArbiterDestroy(cpArbiter *arb)
134
+ {
135
+ // if(arb->contacts) cpfree(arb->contacts);
136
+ }
137
+
138
+ void
139
+ cpArbiterFree(cpArbiter *arb)
140
+ {
141
+ if(arb){
142
+ cpArbiterDestroy(arb);
143
+ cpfree(arb);
144
+ }
145
+ }
146
+
147
+ void
148
+ cpArbiterUpdate(cpArbiter *arb, cpContact *contacts, int numContacts, cpCollisionHandler *handler, cpShape *a, cpShape *b)
149
+ {
150
+ // Arbiters without contact data may exist if a collision function rejected the collision.
151
+ if(arb->contacts){
152
+ // Iterate over the possible pairs to look for hash value matches.
153
+ for(int i=0; i<arb->numContacts; i++){
154
+ cpContact *old = &arb->contacts[i];
155
+
156
+ for(int j=0; j<numContacts; j++){
157
+ cpContact *new_contact = &contacts[j];
158
+
159
+ // This could trigger false positives, but is fairly unlikely nor serious if it does.
160
+ if(new_contact->hash == old->hash){
161
+ // Copy the persistant contact information.
162
+ new_contact->jnAcc = old->jnAcc;
163
+ new_contact->jtAcc = old->jtAcc;
164
+ }
165
+ }
166
+ }
167
+ }
168
+
169
+ arb->contacts = contacts;
170
+ arb->numContacts = numContacts;
171
+
172
+ arb->handler = handler;
173
+ arb->swappedColl = (a->collision_type != handler->a);
174
+
175
+ arb->e = a->e * b->e;
176
+ arb->u = a->u * b->u;
177
+ arb->surface_vr = cpvsub(a->surface_v, b->surface_v);
178
+
179
+ // For collisions between two similar primitive types, the order could have been swapped.
180
+ arb->a = a;
181
+ arb->b = b;
182
+
183
+ // mark it as new if it's been cached
184
+ if(arb->state == cpArbiterStateCached) arb->state = cpArbiterStateFirstColl;
185
+ }
186
+
187
+ void
188
+ cpArbiterPreStep(cpArbiter *arb, cpFloat dt_inv)
189
+ {
190
+ cpBody *a = arb->a->body;
191
+ cpBody *b = arb->b->body;
192
+
193
+ for(int i=0; i<arb->numContacts; i++){
194
+ cpContact *con = &arb->contacts[i];
195
+
196
+ // Calculate the offsets.
197
+ con->r1 = cpvsub(con->p, a->p);
198
+ con->r2 = cpvsub(con->p, b->p);
199
+
200
+ // Calculate the mass normal and mass tangent.
201
+ con->nMass = 1.0f/k_scalar(a, b, con->r1, con->r2, con->n);
202
+ con->tMass = 1.0f/k_scalar(a, b, con->r1, con->r2, cpvperp(con->n));
203
+
204
+ // Calculate the target bias velocity.
205
+ con->bias = -cp_bias_coef*dt_inv*cpfmin(0.0f, con->dist + cp_collision_slop);
206
+ con->jBias = 0.0f;
207
+
208
+ // Calculate the target bounce velocity.
209
+ con->bounce = normal_relative_velocity(a, b, con->r1, con->r2, con->n)*arb->e;//cpvdot(con->n, cpvsub(v2, v1))*e;
210
+ }
211
+ }
212
+
213
+ void
214
+ cpArbiterApplyCachedImpulse(cpArbiter *arb)
215
+ {
216
+ cpShape *shapea = arb->a;
217
+ cpShape *shapeb = arb->b;
218
+
219
+ arb->u = shapea->u * shapeb->u;
220
+ arb->surface_vr = cpvsub(shapeb->surface_v, shapea->surface_v);
221
+
222
+ cpBody *a = shapea->body;
223
+ cpBody *b = shapeb->body;
224
+
225
+ for(int i=0; i<arb->numContacts; i++){
226
+ cpContact *con = &arb->contacts[i];
227
+ apply_impulses(a, b, con->r1, con->r2, cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc)));
228
+ }
229
+ }
230
+
231
+ void
232
+ cpArbiterApplyImpulse(cpArbiter *arb, cpFloat eCoef)
233
+ {
234
+ cpBody *a = arb->a->body;
235
+ cpBody *b = arb->b->body;
236
+
237
+ for(int i=0; i<arb->numContacts; i++){
238
+ cpContact *con = &arb->contacts[i];
239
+ cpVect n = con->n;
240
+ cpVect r1 = con->r1;
241
+ cpVect r2 = con->r2;
242
+
243
+ // Calculate the relative bias velocities.
244
+ cpVect vb1 = cpvadd(a->v_bias, cpvmult(cpvperp(r1), a->w_bias));
245
+ cpVect vb2 = cpvadd(b->v_bias, cpvmult(cpvperp(r2), b->w_bias));
246
+ cpFloat vbn = cpvdot(cpvsub(vb2, vb1), n);
247
+
248
+ // Calculate and clamp the bias impulse.
249
+ cpFloat jbn = (con->bias - vbn)*con->nMass;
250
+ cpFloat jbnOld = con->jBias;
251
+ con->jBias = cpfmax(jbnOld + jbn, 0.0f);
252
+ jbn = con->jBias - jbnOld;
253
+
254
+ // Apply the bias impulse.
255
+ apply_bias_impulses(a, b, r1, r2, cpvmult(n, jbn));
256
+
257
+ // Calculate the relative velocity.
258
+ cpVect vr = relative_velocity(a, b, r1, r2);
259
+ cpFloat vrn = cpvdot(vr, n);
260
+
261
+ // Calculate and clamp the normal impulse.
262
+ cpFloat jn = -(con->bounce*eCoef + vrn)*con->nMass;
263
+ cpFloat jnOld = con->jnAcc;
264
+ con->jnAcc = cpfmax(jnOld + jn, 0.0f);
265
+ jn = con->jnAcc - jnOld;
266
+
267
+ // Calculate the relative tangent velocity.
268
+ cpFloat vrt = cpvdot(cpvadd(vr, arb->surface_vr), cpvperp(n));
269
+
270
+ // Calculate and clamp the friction impulse.
271
+ cpFloat jtMax = arb->u*con->jnAcc;
272
+ cpFloat jt = -vrt*con->tMass;
273
+ cpFloat jtOld = con->jtAcc;
274
+ con->jtAcc = cpfclamp(jtOld + jt, -jtMax, jtMax);
275
+ jt = con->jtAcc - jtOld;
276
+
277
+ // Apply the final impulse.
278
+ apply_impulses(a, b, r1, r2, cpvrotate(n, cpv(jn, jt)));
279
+ }
280
+ }
@@ -0,0 +1,143 @@
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
+ #include <stdlib.h>
23
+ #include <string.h>
24
+
25
+ #include "chipmunk_private.h"
26
+
27
+
28
+ //#define CP_ARRAY_INCREMENT 10
29
+
30
+ // NOTE: cpArray is rarely used and will probably go away.
31
+
32
+ cpArray*
33
+ cpArrayAlloc(void)
34
+ {
35
+ return (cpArray *)cpcalloc(1, sizeof(cpArray));
36
+ }
37
+
38
+ cpArray*
39
+ cpArrayInit(cpArray *arr, int size)
40
+ {
41
+ arr->num = 0;
42
+
43
+ size = (size ? size : 4);
44
+ arr->max = size;
45
+ arr->arr = (void **)cpmalloc(size*sizeof(void**));
46
+
47
+ return arr;
48
+ }
49
+
50
+ cpArray*
51
+ cpArrayNew(int size)
52
+ {
53
+ return cpArrayInit(cpArrayAlloc(), size);
54
+ }
55
+
56
+ void
57
+ cpArrayDestroy(cpArray *arr)
58
+ {
59
+ cpfree(arr->arr);
60
+ arr->arr = NULL;
61
+ }
62
+
63
+ void
64
+ cpArrayFree(cpArray *arr)
65
+ {
66
+ if(arr){
67
+ cpArrayDestroy(arr);
68
+ cpfree(arr);
69
+ }
70
+ }
71
+
72
+ void
73
+ cpArrayPush(cpArray *arr, void *object)
74
+ {
75
+ if(arr->num == arr->max){
76
+ arr->max *= 2;
77
+ arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
78
+ }
79
+
80
+ arr->arr[arr->num] = object;
81
+ arr->num++;
82
+ }
83
+
84
+ void *
85
+ cpArrayPop(cpArray *arr)
86
+ {
87
+ arr->num--;
88
+
89
+ void *value = arr->arr[arr->num];
90
+ arr->arr[arr->num] = NULL;
91
+
92
+ return value;
93
+ }
94
+
95
+ void
96
+ cpArrayDeleteIndex(cpArray *arr, int idx)
97
+ {
98
+ arr->num--;
99
+
100
+ arr->arr[idx] = arr->arr[arr->num];
101
+ arr->arr[arr->num] = NULL;
102
+ }
103
+
104
+ void
105
+ cpArrayDeleteObj(cpArray *arr, void *obj)
106
+ {
107
+ for(int i=0; i<arr->num; i++){
108
+ if(arr->arr[i] == obj){
109
+ cpArrayDeleteIndex(arr, i);
110
+ return;
111
+ }
112
+ }
113
+ }
114
+
115
+ void
116
+ cpArrayAppend(cpArray *arr, cpArray *other)
117
+ {
118
+ void *tail = &arr->arr[arr->num];
119
+
120
+ arr->num += other->num;
121
+ if(arr->num >= arr->max){
122
+ arr->max = arr->num;
123
+ arr->arr = (void **)cprealloc(arr->arr, arr->max*sizeof(void**));
124
+ }
125
+
126
+ memcpy(tail, other->arr, other->num*sizeof(void**));
127
+ }
128
+
129
+ void
130
+ cpArrayEach(cpArray *arr, cpArrayIter iterFunc, void *data)
131
+ {
132
+ for(int i=0; i<arr->num; i++)
133
+ iterFunc(arr->arr[i], data);
134
+ }
135
+
136
+ cpBool
137
+ cpArrayContains(cpArray *arr, void *ptr)
138
+ {
139
+ for(int i=0; i<arr->num; i++)
140
+ if(arr->arr[i] == ptr) return cpTrue;
141
+
142
+ return cpFalse;
143
+ }