chipmunk 5.2.2 → 5.3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/LICENSE +21 -19
  2. data/README +67 -60
  3. data/Rakefile +85 -50
  4. data/ext/chipmunk/extconf.rb +42 -35
  5. data/ext/chipmunk/rb_chipmunk.c +250 -125
  6. data/ext/chipmunk/rb_chipmunk.h +105 -96
  7. data/ext/chipmunk/rb_cpArbiter.c +253 -225
  8. data/ext/chipmunk/rb_cpBB.c +210 -174
  9. data/ext/chipmunk/rb_cpBody.c +504 -347
  10. data/ext/chipmunk/rb_cpConstraint.c +336 -346
  11. data/ext/chipmunk/rb_cpShape.c +433 -455
  12. data/ext/chipmunk/rb_cpSpace.c +711 -544
  13. data/ext/chipmunk/rb_cpVect.c +346 -321
  14. data/lib/chipmunk.rb +183 -30
  15. metadata +12 -66
  16. data/ext/chipmunk/chipmunk.c +0 -105
  17. data/ext/chipmunk/cpArbiter.c +0 -274
  18. data/ext/chipmunk/cpArray.c +0 -128
  19. data/ext/chipmunk/cpBB.c +0 -47
  20. data/ext/chipmunk/cpBody.c +0 -188
  21. data/ext/chipmunk/cpCollision.c +0 -391
  22. data/ext/chipmunk/cpConstraint.c +0 -54
  23. data/ext/chipmunk/cpDampedRotarySpring.c +0 -106
  24. data/ext/chipmunk/cpDampedSpring.c +0 -117
  25. data/ext/chipmunk/cpGearJoint.c +0 -114
  26. data/ext/chipmunk/cpGrooveJoint.c +0 -138
  27. data/ext/chipmunk/cpHashSet.c +0 -253
  28. data/ext/chipmunk/cpPinJoint.c +0 -117
  29. data/ext/chipmunk/cpPivotJoint.c +0 -114
  30. data/ext/chipmunk/cpPolyShape.c +0 -241
  31. data/ext/chipmunk/cpRatchetJoint.c +0 -128
  32. data/ext/chipmunk/cpRotaryLimitJoint.c +0 -122
  33. data/ext/chipmunk/cpShape.c +0 -400
  34. data/ext/chipmunk/cpSimpleMotor.c +0 -99
  35. data/ext/chipmunk/cpSlideJoint.c +0 -131
  36. data/ext/chipmunk/cpSpace.c +0 -899
  37. data/ext/chipmunk/cpSpaceHash.c +0 -541
  38. data/ext/chipmunk/cpVect.c +0 -71
  39. data/ext/chipmunk/include/chipmunk/chipmunk.h +0 -148
  40. data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +0 -42
  41. data/ext/chipmunk/include/chipmunk/chipmunk_types.h +0 -80
  42. data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +0 -54
  43. data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +0 -92
  44. data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +0 -46
  45. data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +0 -53
  46. data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +0 -41
  47. data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +0 -44
  48. data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +0 -43
  49. data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +0 -42
  50. data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +0 -40
  51. data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +0 -39
  52. data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +0 -37
  53. data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +0 -44
  54. data/ext/chipmunk/include/chipmunk/constraints/util.h +0 -116
  55. data/ext/chipmunk/include/chipmunk/cpArbiter.h +0 -136
  56. data/ext/chipmunk/include/chipmunk/cpArray.h +0 -46
  57. data/ext/chipmunk/include/chipmunk/cpBB.h +0 -74
  58. data/ext/chipmunk/include/chipmunk/cpBody.h +0 -160
  59. data/ext/chipmunk/include/chipmunk/cpCollision.h +0 -23
  60. data/ext/chipmunk/include/chipmunk/cpHashSet.h +0 -82
  61. data/ext/chipmunk/include/chipmunk/cpPolyShape.h +0 -103
  62. data/ext/chipmunk/include/chipmunk/cpShape.h +0 -174
  63. data/ext/chipmunk/include/chipmunk/cpSpace.h +0 -180
  64. data/ext/chipmunk/include/chipmunk/cpSpaceHash.h +0 -109
  65. data/ext/chipmunk/include/chipmunk/cpVect.h +0 -157
  66. data/ext/chipmunk/prime.h +0 -68
  67. data/lib/chipmunk/version.rb +0 -3
@@ -1,346 +1,336 @@
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 "chipmunk.h"
24
-
25
- #include "ruby.h"
26
- #include "rb_chipmunk.h"
27
-
28
- VALUE m_cpConstraint;
29
-
30
- #define CONSTRAINT_GETSET_FUNCS(member) \
31
- static VALUE rb_cpConstraint_get_##member(VALUE self) \
32
- {return rb_float_new(CONSTRAINT(self)->member);} \
33
- static VALUE rb_cpConstraint_set_##member(VALUE self, VALUE value) \
34
- {CONSTRAINT(self)->member = NUM2DBL(value); return value;}
35
-
36
- CONSTRAINT_GETSET_FUNCS(maxForce)
37
- CONSTRAINT_GETSET_FUNCS(biasCoef)
38
- CONSTRAINT_GETSET_FUNCS(maxBias)
39
-
40
-
41
- #define MAKE_FLT_GETTER(func) \
42
- static VALUE rb_##func(VALUE self) \
43
- {return rb_float_new(func(CONSTRAINT(self)));}
44
-
45
- #define MAKE_FLT_SETTER(func) \
46
- static VALUE rb_##func(VALUE self, VALUE value) \
47
- {func(CONSTRAINT(self), NUM2DBL(value)); return value;} \
48
-
49
- #define MAKE_FLT_ACCESSORS(s, m) \
50
- MAKE_FLT_GETTER(s##Get##m) \
51
- MAKE_FLT_SETTER(s##Set##m)
52
-
53
- #define MAKE_VEC_GETTER(func) \
54
- static VALUE rb_##func(VALUE self) \
55
- {return VNEW(func(CONSTRAINT(self)));}
56
-
57
- #define MAKE_VEC_SETTER(func) \
58
- static VALUE rb_##func(VALUE self, VALUE value) \
59
- {func(CONSTRAINT(self), *VGET(value)); return value;} \
60
-
61
- #define MAKE_VEC_ACCESSORS(s, m) \
62
- MAKE_VEC_GETTER(s##Get##m) \
63
- MAKE_VEC_SETTER(s##Set##m)
64
-
65
-
66
- #define ALLOC_TEMPLATE(s, alloc) \
67
- static VALUE rb_##s##_alloc(VALUE klass) \
68
- {return Data_Wrap_Struct(klass, NULL, cpConstraintFree, alloc);}
69
-
70
- ALLOC_TEMPLATE(cpPinJoint, cpPinJointAlloc())
71
-
72
- static VALUE
73
- rb_cpPinJoint_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2)
74
- {
75
- cpPinJoint *joint = (cpPinJoint *)CONSTRAINT(self);
76
- cpPinJointInit(joint, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2));
77
- rb_iv_set(self, "@body_a", a);
78
- rb_iv_set(self, "@body_b", b);
79
-
80
- return self;
81
- }
82
-
83
- MAKE_FLT_ACCESSORS(cpPinJoint, Dist)
84
- MAKE_VEC_ACCESSORS(cpPinJoint, Anchr1)
85
- MAKE_VEC_ACCESSORS(cpPinJoint, Anchr2)
86
-
87
-
88
- ALLOC_TEMPLATE(cpDampedRotarySpring, cpDampedRotarySpringAlloc())
89
-
90
- static VALUE
91
- rb_cpDampedRotarySpring_init(VALUE self, VALUE a, VALUE b, VALUE restAngle, VALUE stiffness, VALUE damping)
92
- {
93
- cpDampedRotarySpring *spring = (cpDampedRotarySpring *)CONSTRAINT(self);
94
- cpDampedRotarySpringInit(spring, BODY(a), BODY(b), NUM2DBL(restAngle), NUM2DBL(stiffness), NUM2DBL(damping));
95
- rb_iv_set(self, "@body_a", a);
96
- rb_iv_set(self, "@body_b", b);
97
-
98
- return self;
99
- }
100
-
101
- MAKE_FLT_ACCESSORS(cpDampedRotarySpring, RestAngle);
102
- MAKE_FLT_ACCESSORS(cpDampedRotarySpring, Stiffness);
103
- MAKE_FLT_ACCESSORS(cpDampedRotarySpring, Damping);
104
-
105
-
106
- ALLOC_TEMPLATE(cpDampedSpring, cpDampedSpringAlloc())
107
-
108
- static VALUE
109
- rb_cpDampedSpring_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2, VALUE restLength, VALUE stiffness, VALUE damping)
110
- {
111
- cpDampedSpring *spring = (cpDampedSpring *)CONSTRAINT(self);
112
- cpDampedSpringInit(spring, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2), NUM2DBL(restLength), NUM2DBL(stiffness), NUM2DBL(damping));
113
- rb_iv_set(self, "@body_a", a);
114
- rb_iv_set(self, "@body_b", b);
115
-
116
- return self;
117
- }
118
-
119
- MAKE_VEC_ACCESSORS(cpDampedSpring, Anchr1)
120
- MAKE_VEC_ACCESSORS(cpDampedSpring, Anchr2)
121
- MAKE_FLT_ACCESSORS(cpDampedSpring, RestLength);
122
- MAKE_FLT_ACCESSORS(cpDampedSpring, Stiffness);
123
- MAKE_FLT_ACCESSORS(cpDampedSpring, Damping);
124
-
125
-
126
- ALLOC_TEMPLATE(cpGearJoint, cpGearJointAlloc())
127
-
128
- static VALUE
129
- rb_cpGearJoint_init(VALUE self, VALUE a, VALUE b, VALUE phase, VALUE ratio)
130
- {
131
- cpGearJoint *joint = (cpGearJoint *)CONSTRAINT(self);
132
- cpGearJointInit(joint, BODY(a), BODY(b), NUM2DBL(phase), NUM2DBL(ratio));
133
- rb_iv_set(self, "@body_a", a);
134
- rb_iv_set(self, "@body_b", b);
135
-
136
- return self;
137
- }
138
-
139
- MAKE_FLT_ACCESSORS(cpGearJoint, Phase);
140
- MAKE_FLT_ACCESSORS(cpGearJoint, Ratio);
141
-
142
-
143
- ALLOC_TEMPLATE(cpPivotJoint, cpPivotJointAlloc())
144
-
145
- static VALUE
146
- rb_cpPivotJoint_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2)
147
- {
148
- cpPivotJoint *joint = (cpPivotJoint *)CONSTRAINT(self);
149
- cpPivotJointInit(joint, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2));
150
- rb_iv_set(self, "@body_a", a);
151
- rb_iv_set(self, "@body_b", b);
152
-
153
- return self;
154
- }
155
-
156
- MAKE_VEC_ACCESSORS(cpPivotJoint, Anchr1);
157
- MAKE_VEC_ACCESSORS(cpPivotJoint, Anchr2);
158
-
159
-
160
- ALLOC_TEMPLATE(cpRotaryLimitJoint, cpRotaryLimitJointAlloc())
161
-
162
- static VALUE
163
- rb_cpRotaryLimitJoint_init(VALUE self, VALUE a, VALUE b, VALUE min, VALUE max)
164
- {
165
- cpRotaryLimitJoint *joint = (cpRotaryLimitJoint *)CONSTRAINT(self);
166
- cpRotaryLimitJointInit(joint, BODY(a), BODY(b), NUM2DBL(min), NUM2DBL(max));
167
- rb_iv_set(self, "@body_a", a);
168
- rb_iv_set(self, "@body_b", b);
169
-
170
- return self;
171
- }
172
-
173
- MAKE_FLT_ACCESSORS(cpRotaryLimitJoint, Min);
174
- MAKE_FLT_ACCESSORS(cpRotaryLimitJoint, Max);
175
-
176
-
177
- ALLOC_TEMPLATE(cpSimpleMotor, cpSimpleMotorAlloc())
178
-
179
- static VALUE
180
- rb_cpSimpleMotor_init(VALUE self, VALUE a, VALUE b, VALUE rate)
181
- {
182
- cpSimpleMotor *motor = (cpSimpleMotor *)CONSTRAINT(self);
183
- cpSimpleMotorInit(motor, BODY(a), BODY(b), NUM2DBL(rate));
184
- rb_iv_set(self, "@body_a", a);
185
- rb_iv_set(self, "@body_b", b);
186
-
187
- return self;
188
- }
189
-
190
- MAKE_FLT_ACCESSORS(cpSimpleMotor, Rate);
191
-
192
-
193
- ALLOC_TEMPLATE(cpSlideJoint, cpSlideJointAlloc())
194
-
195
- static VALUE
196
- rb_cpSlideJoint_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2, VALUE min, VALUE max)
197
- {
198
- cpSlideJoint *joint = (cpSlideJoint *)CONSTRAINT(self);
199
- cpSlideJointInit(joint, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2), NUM2DBL(min), NUM2DBL(max));
200
- rb_iv_set(self, "@body_a", a);
201
- rb_iv_set(self, "@body_b", b);
202
-
203
- return self;
204
- }
205
-
206
- MAKE_VEC_ACCESSORS(cpSlideJoint, Anchr1)
207
- MAKE_VEC_ACCESSORS(cpSlideJoint, Anchr2)
208
- MAKE_FLT_ACCESSORS(cpSlideJoint, Min);
209
- MAKE_FLT_ACCESSORS(cpSlideJoint, Max);
210
-
211
-
212
- ALLOC_TEMPLATE(cpGrooveJoint, cpGrooveJointAlloc())
213
-
214
- static VALUE
215
- rb_cpGrooveJoint_init(VALUE self, VALUE a, VALUE b, VALUE grv_a, VALUE grv_b, VALUE anchr2)
216
- {
217
- cpGrooveJoint *joint = (cpGrooveJoint *)CONSTRAINT(self);
218
- cpGrooveJointInit(joint, BODY(a), BODY(b), *VGET(grv_a), *VGET(grv_b), *VGET(anchr2));
219
- rb_iv_set(self, "@body_a", a);
220
- rb_iv_set(self, "@body_b", b);
221
-
222
- return self;
223
- }
224
-
225
- MAKE_VEC_ACCESSORS(cpGrooveJoint, Anchr2)
226
-
227
- /*
228
- These are for later, when Chipmunk C supports them.
229
- MAKE_VEC_ACCESSORS(cpGrooveJoint, Grv_a)
230
- MAKE_VEC_ACCESSORS(cpGrooveJoint, Grv_b)
231
- MAKE_VEC_ACCESSORS(cpGrooveJoint, Grv_n)
232
- MAKE_VEC_ACCESSORS(cpGrooveJoint, R1)
233
- MAKE_VEC_ACCESSORS(cpGrooveJoint, R2)
234
- MAKE_VEC_ACCESSORS(cpGrooveJoint, K1)
235
- MAKE_VEC_ACCESSORS(cpGrooveJoint, K2)
236
- MAKE_VEC_ACCESSORS(cpGrooveJoint, Bias)
237
- MAKE_VEC_ACCESSORS(cpGrooveJoint, JAcc)
238
- MAKE_FLT_ACCESSORS(cpGrooveJoint, Clamp)
239
- MAKE_FLT_ACCESSORS(cpGrooveJoint, JMaxLen)
240
- */
241
-
242
- ALLOC_TEMPLATE(cpRatchetJoint, cpRatchetJointAlloc())
243
-
244
- static VALUE
245
- rb_cpRatchetJoint_init(VALUE self, VALUE a, VALUE b, VALUE phase, VALUE ratchet)
246
- {
247
- cpRatchetJoint *joint = (cpRatchetJoint *)CONSTRAINT(self);
248
- cpRatchetJointInit(joint, BODY(a), BODY(b), NUM2DBL(phase), NUM2DBL(ratchet));
249
- rb_iv_set(self, "@body_a", a);
250
- rb_iv_set(self, "@body_b", b);
251
-
252
- return self;
253
- }
254
-
255
- MAKE_FLT_ACCESSORS(cpRatchetJoint, Angle)
256
- MAKE_FLT_ACCESSORS(cpRatchetJoint, Phase)
257
- MAKE_FLT_ACCESSORS(cpRatchetJoint, Ratchet)
258
-
259
-
260
- #define STRINGIFY(v) #v
261
- #define ACCESSOR_METHODS(s, m, name) \
262
- rb_define_method(c_##s, STRINGIFY(name), rb_##s##Get##m, 0); \
263
- rb_define_method(c_##s, STRINGIFY(name=), rb_##s##Set##m, 1);
264
-
265
- static VALUE
266
- make_class(char *name, void *alloc_func, void *init_func, int init_params)
267
- {
268
- VALUE klass = rb_define_class_under(m_cpConstraint, name, rb_cObject);
269
- rb_include_module(klass, m_cpConstraint);
270
- rb_define_alloc_func(klass, alloc_func);
271
- rb_define_method(klass, "initialize", init_func, init_params);
272
-
273
- return klass;
274
- }
275
-
276
- void
277
- Init_cpConstraint(void)
278
- {
279
- m_cpConstraint = rb_define_module_under(m_Chipmunk, "Constraint");
280
- rb_define_attr(m_cpConstraint, "body_a", 1, 0);
281
- rb_define_attr(m_cpConstraint, "body_b", 1, 0);
282
- rb_define_method(m_cpConstraint, "max_force", rb_cpConstraint_get_maxForce, 0);
283
- rb_define_method(m_cpConstraint, "max_force=", rb_cpConstraint_set_maxForce, 1);
284
- rb_define_method(m_cpConstraint, "bias_coef", rb_cpConstraint_get_biasCoef, 0);
285
- rb_define_method(m_cpConstraint, "bias_coef=", rb_cpConstraint_set_biasCoef, 1);
286
- rb_define_method(m_cpConstraint, "max_bias", rb_cpConstraint_get_maxBias, 0);
287
- rb_define_method(m_cpConstraint, "max_bias=", rb_cpConstraint_set_maxBias, 1);
288
-
289
- VALUE c_cpPinJoint = make_class("PinJoint", rb_cpPinJoint_alloc, rb_cpPinJoint_init, 4);
290
- ACCESSOR_METHODS(cpPinJoint, Anchr1, anchr1)
291
- ACCESSOR_METHODS(cpPinJoint, Anchr2, anchr2)
292
- ACCESSOR_METHODS(cpPinJoint, Dist, dist)
293
-
294
- VALUE c_cpDampedRotarySpring = make_class("DampedRotarySpring", rb_cpDampedRotarySpring_alloc, rb_cpDampedRotarySpring_init, 5);
295
- ACCESSOR_METHODS(cpDampedRotarySpring, RestAngle, rest_angle)
296
- ACCESSOR_METHODS(cpDampedRotarySpring, Stiffness, stiffness)
297
- ACCESSOR_METHODS(cpDampedRotarySpring, Damping, damping)
298
-
299
- VALUE c_cpDampedSpring = make_class("DampedSpring", rb_cpDampedSpring_alloc, rb_cpDampedSpring_init, 7);
300
- ACCESSOR_METHODS(cpDampedSpring, Anchr1, anchr1)
301
- ACCESSOR_METHODS(cpDampedSpring, Anchr2, anchr2)
302
- ACCESSOR_METHODS(cpDampedSpring, RestLength, rest_length)
303
- ACCESSOR_METHODS(cpDampedSpring, Stiffness, stiffness)
304
- ACCESSOR_METHODS(cpDampedSpring, Damping, damping)
305
-
306
- VALUE c_cpGearJoint = make_class("GearJoint", rb_cpGearJoint_alloc, rb_cpGearJoint_init, 4);
307
- ACCESSOR_METHODS(cpGearJoint, Phase, phase)
308
- ACCESSOR_METHODS(cpGearJoint, Ratio, ratio)
309
-
310
- VALUE c_cpPivotJoint = make_class("PivotJoint", rb_cpPivotJoint_alloc, rb_cpPivotJoint_init, 4);
311
- ACCESSOR_METHODS(cpPivotJoint, Anchr1, anchr1)
312
- ACCESSOR_METHODS(cpPivotJoint, Anchr2, anchr2)
313
-
314
- VALUE c_cpRotaryLimitJoint = make_class("RotaryLimitJoint", rb_cpRotaryLimitJoint_alloc, rb_cpRotaryLimitJoint_init, 4);
315
- ACCESSOR_METHODS(cpRotaryLimitJoint, Min, min)
316
- ACCESSOR_METHODS(cpRotaryLimitJoint, Max, max)
317
-
318
- VALUE c_cpSimpleMotor = make_class("SimpleMotor", rb_cpSimpleMotor_alloc, rb_cpSimpleMotor_init, 3);
319
- ACCESSOR_METHODS(cpSimpleMotor, Rate, rate);
320
-
321
- VALUE c_cpSlideJoint = make_class("SlideJoint", rb_cpSlideJoint_alloc, rb_cpSlideJoint_init, 6);
322
- ACCESSOR_METHODS(cpSlideJoint, Anchr1, anchr1)
323
- ACCESSOR_METHODS(cpSlideJoint, Anchr2, anchr2)
324
- ACCESSOR_METHODS(cpSlideJoint, Min, min)
325
- ACCESSOR_METHODS(cpSlideJoint, Max, max)
326
-
327
- VALUE c_cpGrooveJoint = make_class("GrooveJoint", rb_cpGrooveJoint_alloc, rb_cpGrooveJoint_init, 5);
328
- ACCESSOR_METHODS(cpGrooveJoint, Anchr2, anchr2)
329
-
330
- /*
331
- ACCESSOR_METHODS(cpGrooveJoint, Clamp, clamp)
332
- ACCESSOR_METHODS(cpGrooveJoint, JMaxLen, max)
333
- */
334
-
335
- VALUE c_cpRatchetJoint =
336
- make_class("RatchetJoint", rb_cpRatchetJoint_alloc, rb_cpRatchetJoint_init, 4);
337
- ACCESSOR_METHODS(cpRatchetJoint, Angle, angle)
338
- ACCESSOR_METHODS(cpRatchetJoint, Phase, phase)
339
- ACCESSOR_METHODS(cpRatchetJoint, Ratchet, ratchet)
340
-
341
-
342
-
343
- // TODO groove joint accessors
344
-
345
- // TODO breakable joint
346
- }
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 "chipmunk.h"
24
+
25
+ #include "ruby.h"
26
+ #include "rb_chipmunk.h"
27
+
28
+ VALUE m_cpConstraint;
29
+
30
+ #define CONSTRAINT_GETSET_FUNCS(member) \
31
+ static VALUE rb_cpConstraint_get_##member(VALUE self) \
32
+ {return rb_float_new(CONSTRAINT(self)->member);} \
33
+ static VALUE rb_cpConstraint_set_##member(VALUE self, VALUE value) \
34
+ {CONSTRAINT(self)->member = NUM2DBL(value); return value;}
35
+
36
+ CONSTRAINT_GETSET_FUNCS(maxForce)
37
+ CONSTRAINT_GETSET_FUNCS(biasCoef)
38
+ CONSTRAINT_GETSET_FUNCS(maxBias)
39
+
40
+
41
+ #define MAKE_FLT_GETTER(func) \
42
+ static VALUE rb_##func(VALUE self) \
43
+ {return rb_float_new(func(CONSTRAINT(self)));}
44
+
45
+ #define MAKE_FLT_SETTER(func) \
46
+ static VALUE rb_##func(VALUE self, VALUE value) \
47
+ {func(CONSTRAINT(self), NUM2DBL(value)); return value;} \
48
+
49
+ #define MAKE_FLT_ACCESSORS(s, m) \
50
+ MAKE_FLT_GETTER(s##Get##m) \
51
+ MAKE_FLT_SETTER(s##Set##m)
52
+
53
+ #define MAKE_VEC_GETTER(func) \
54
+ static VALUE rb_##func(VALUE self) \
55
+ {return VNEW(func(CONSTRAINT(self)));}
56
+
57
+ #define MAKE_VEC_SETTER(func) \
58
+ static VALUE rb_##func(VALUE self, VALUE value) \
59
+ {func(CONSTRAINT(self), *VGET(value)); return value;} \
60
+
61
+ #define MAKE_VEC_ACCESSORS(s, m) \
62
+ MAKE_VEC_GETTER(s##Get##m) \
63
+ MAKE_VEC_SETTER(s##Set##m)
64
+
65
+
66
+ #define ALLOC_TEMPLATE(s, alloc) \
67
+ static VALUE rb_##s##_alloc(VALUE klass) \
68
+ {return Data_Wrap_Struct(klass, NULL, cpConstraintFree, alloc);}
69
+
70
+ ALLOC_TEMPLATE(cpPinJoint, cpPinJointAlloc())
71
+
72
+ static VALUE
73
+ rb_cpPinJoint_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2)
74
+ {
75
+ cpPinJoint *joint = (cpPinJoint *)CONSTRAINT(self);
76
+ cpPinJointInit(joint, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2));
77
+ rb_iv_set(self, "@body_a", a);
78
+ rb_iv_set(self, "@body_b", b);
79
+
80
+ return self;
81
+ }
82
+
83
+ MAKE_FLT_ACCESSORS(cpPinJoint, Dist)
84
+ MAKE_VEC_ACCESSORS(cpPinJoint, Anchr1)
85
+ MAKE_VEC_ACCESSORS(cpPinJoint, Anchr2)
86
+
87
+
88
+ ALLOC_TEMPLATE(cpDampedRotarySpring, cpDampedRotarySpringAlloc())
89
+
90
+ static VALUE
91
+ rb_cpDampedRotarySpring_init(VALUE self, VALUE a, VALUE b, VALUE restAngle, VALUE stiffness, VALUE damping)
92
+ {
93
+ cpDampedRotarySpring *spring = (cpDampedRotarySpring *)CONSTRAINT(self);
94
+ cpDampedRotarySpringInit(spring, BODY(a), BODY(b), NUM2DBL(restAngle), NUM2DBL(stiffness), NUM2DBL(damping));
95
+ rb_iv_set(self, "@body_a", a);
96
+ rb_iv_set(self, "@body_b", b);
97
+
98
+ return self;
99
+ }
100
+
101
+ MAKE_FLT_ACCESSORS(cpDampedRotarySpring, RestAngle);
102
+ MAKE_FLT_ACCESSORS(cpDampedRotarySpring, Stiffness);
103
+ MAKE_FLT_ACCESSORS(cpDampedRotarySpring, Damping);
104
+
105
+
106
+ ALLOC_TEMPLATE(cpDampedSpring, cpDampedSpringAlloc())
107
+
108
+ static VALUE
109
+ rb_cpDampedSpring_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2, VALUE restLength, VALUE stiffness, VALUE damping)
110
+ {
111
+ cpDampedSpring *spring = (cpDampedSpring *)CONSTRAINT(self);
112
+ cpDampedSpringInit(spring, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2), NUM2DBL(restLength), NUM2DBL(stiffness), NUM2DBL(damping));
113
+ rb_iv_set(self, "@body_a", a);
114
+ rb_iv_set(self, "@body_b", b);
115
+
116
+ return self;
117
+ }
118
+
119
+ MAKE_VEC_ACCESSORS(cpDampedSpring, Anchr1)
120
+ MAKE_VEC_ACCESSORS(cpDampedSpring, Anchr2)
121
+ MAKE_FLT_ACCESSORS(cpDampedSpring, RestLength);
122
+ MAKE_FLT_ACCESSORS(cpDampedSpring, Stiffness);
123
+ MAKE_FLT_ACCESSORS(cpDampedSpring, Damping);
124
+
125
+
126
+ ALLOC_TEMPLATE(cpGearJoint, cpGearJointAlloc())
127
+
128
+ static VALUE
129
+ rb_cpGearJoint_init(VALUE self, VALUE a, VALUE b, VALUE phase, VALUE ratio)
130
+ {
131
+ cpGearJoint *joint = (cpGearJoint *)CONSTRAINT(self);
132
+ cpGearJointInit(joint, BODY(a), BODY(b), NUM2DBL(phase), NUM2DBL(ratio));
133
+ rb_iv_set(self, "@body_a", a);
134
+ rb_iv_set(self, "@body_b", b);
135
+
136
+ return self;
137
+ }
138
+
139
+ MAKE_FLT_ACCESSORS(cpGearJoint, Phase);
140
+ MAKE_FLT_ACCESSORS(cpGearJoint, Ratio);
141
+
142
+
143
+ ALLOC_TEMPLATE(cpPivotJoint, cpPivotJointAlloc())
144
+
145
+ static VALUE
146
+ rb_cpPivotJoint_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2)
147
+ {
148
+ cpPivotJoint *joint = (cpPivotJoint *)CONSTRAINT(self);
149
+ cpPivotJointInit(joint, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2));
150
+ rb_iv_set(self, "@body_a", a);
151
+ rb_iv_set(self, "@body_b", b);
152
+
153
+ return self;
154
+ }
155
+
156
+ MAKE_VEC_ACCESSORS(cpPivotJoint, Anchr1);
157
+ MAKE_VEC_ACCESSORS(cpPivotJoint, Anchr2);
158
+
159
+
160
+ ALLOC_TEMPLATE(cpRotaryLimitJoint, cpRotaryLimitJointAlloc())
161
+
162
+ static VALUE
163
+ rb_cpRotaryLimitJoint_init(VALUE self, VALUE a, VALUE b, VALUE min, VALUE max)
164
+ {
165
+ cpRotaryLimitJoint *joint = (cpRotaryLimitJoint *)CONSTRAINT(self);
166
+ cpRotaryLimitJointInit(joint, BODY(a), BODY(b), NUM2DBL(min), NUM2DBL(max));
167
+ rb_iv_set(self, "@body_a", a);
168
+ rb_iv_set(self, "@body_b", b);
169
+
170
+ return self;
171
+ }
172
+
173
+ MAKE_FLT_ACCESSORS(cpRotaryLimitJoint, Min);
174
+ MAKE_FLT_ACCESSORS(cpRotaryLimitJoint, Max);
175
+
176
+
177
+ ALLOC_TEMPLATE(cpSimpleMotor, cpSimpleMotorAlloc())
178
+
179
+ static VALUE
180
+ rb_cpSimpleMotor_init(VALUE self, VALUE a, VALUE b, VALUE rate)
181
+ {
182
+ cpSimpleMotor *motor = (cpSimpleMotor *)CONSTRAINT(self);
183
+ cpSimpleMotorInit(motor, BODY(a), BODY(b), NUM2DBL(rate));
184
+ rb_iv_set(self, "@body_a", a);
185
+ rb_iv_set(self, "@body_b", b);
186
+
187
+ return self;
188
+ }
189
+
190
+ MAKE_FLT_ACCESSORS(cpSimpleMotor, Rate);
191
+
192
+
193
+ ALLOC_TEMPLATE(cpSlideJoint, cpSlideJointAlloc())
194
+
195
+ static VALUE
196
+ rb_cpSlideJoint_init(VALUE self, VALUE a, VALUE b, VALUE anchr1, VALUE anchr2, VALUE min, VALUE max)
197
+ {
198
+ cpSlideJoint *joint = (cpSlideJoint *)CONSTRAINT(self);
199
+ cpSlideJointInit(joint, BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2), NUM2DBL(min), NUM2DBL(max));
200
+ rb_iv_set(self, "@body_a", a);
201
+ rb_iv_set(self, "@body_b", b);
202
+
203
+ return self;
204
+ }
205
+
206
+ MAKE_VEC_ACCESSORS(cpSlideJoint, Anchr1)
207
+ MAKE_VEC_ACCESSORS(cpSlideJoint, Anchr2)
208
+ MAKE_FLT_ACCESSORS(cpSlideJoint, Min);
209
+ MAKE_FLT_ACCESSORS(cpSlideJoint, Max);
210
+
211
+
212
+ ALLOC_TEMPLATE(cpGrooveJoint, cpGrooveJointAlloc())
213
+
214
+ static VALUE
215
+ rb_cpGrooveJoint_init(VALUE self, VALUE a, VALUE b, VALUE grv_a, VALUE grv_b, VALUE anchr2)
216
+ {
217
+ cpGrooveJoint *joint = (cpGrooveJoint *)CONSTRAINT(self);
218
+ cpGrooveJointInit(joint, BODY(a), BODY(b), *VGET(grv_a), *VGET(grv_b), *VGET(anchr2));
219
+ rb_iv_set(self, "@body_a", a);
220
+ rb_iv_set(self, "@body_b", b);
221
+
222
+ return self;
223
+ }
224
+
225
+ MAKE_VEC_ACCESSORS(cpGrooveJoint, GrooveA)
226
+ MAKE_VEC_ACCESSORS(cpGrooveJoint, GrooveB)
227
+ MAKE_VEC_ACCESSORS(cpGrooveJoint, Anchr2)
228
+
229
+
230
+ ALLOC_TEMPLATE(cpRatchetJoint, cpRatchetJointAlloc())
231
+
232
+ static VALUE
233
+ rb_cpRatchetJoint_init(VALUE self, VALUE a, VALUE b, VALUE phase, VALUE ratchet)
234
+ {
235
+ cpRatchetJoint * joint = (cpRatchetJoint *)CONSTRAINT(self);
236
+ cpRatchetJointInit(joint, BODY(a), BODY(b), NUM2DBL(phase), NUM2DBL(ratchet));
237
+ rb_iv_set(self, "@body_a", a);
238
+ rb_iv_set(self, "@body_b", b);
239
+
240
+ return self;
241
+ }
242
+
243
+ MAKE_FLT_ACCESSORS(cpRatchetJoint, Angle);
244
+ MAKE_FLT_ACCESSORS(cpRatchetJoint, Phase);
245
+ MAKE_FLT_ACCESSORS(cpRatchetJoint, Ratchet);
246
+
247
+ static VALUE
248
+ rb_cpConstraintGetImpulse(VALUE self) {
249
+ return rb_float_new(cpConstraintGetImpulse(CONSTRAINT(self)));
250
+ }
251
+
252
+
253
+ #define STRINGIFY(v) #v
254
+ #define ACCESSOR_METHODS(s, m, name) \
255
+ rb_define_method(c_##s, STRINGIFY(name), rb_##s##Get##m, 0); \
256
+ rb_define_method(c_##s, STRINGIFY(name=), rb_##s##Set##m, 1);
257
+
258
+ static VALUE
259
+ make_class(const char *name, void *alloc_func, void *init_func, int init_params)
260
+ {
261
+ VALUE klass = rb_define_class_under(m_cpConstraint, name, rb_cObject);
262
+ rb_include_module(klass, m_cpConstraint);
263
+ rb_define_alloc_func(klass, alloc_func);
264
+ rb_define_method(klass, "initialize", init_func, init_params);
265
+
266
+ return klass;
267
+ }
268
+
269
+ void
270
+ Init_cpConstraint(void)
271
+ {
272
+ m_cpConstraint = rb_define_module_under(m_Chipmunk, "Constraint");
273
+ rb_define_attr(m_cpConstraint, "body_a", 1, 0);
274
+ rb_define_attr(m_cpConstraint, "body_b", 1, 0);
275
+ rb_define_method(m_cpConstraint, "max_force", rb_cpConstraint_get_maxForce, 0);
276
+ rb_define_method(m_cpConstraint, "max_force=", rb_cpConstraint_set_maxForce, 1);
277
+ rb_define_method(m_cpConstraint, "bias_coef", rb_cpConstraint_get_biasCoef, 0);
278
+ rb_define_method(m_cpConstraint, "bias_coef=", rb_cpConstraint_set_biasCoef, 1);
279
+ rb_define_method(m_cpConstraint, "max_bias", rb_cpConstraint_get_maxBias, 0);
280
+ rb_define_method(m_cpConstraint, "max_bias=" , rb_cpConstraint_set_maxBias, 1);
281
+ rb_define_method(m_cpConstraint, "impulse" , rb_cpConstraintGetImpulse, 0);
282
+
283
+
284
+ VALUE c_cpDampedRotarySpring = make_class("DampedRotarySpring", rb_cpDampedRotarySpring_alloc, rb_cpDampedRotarySpring_init, 5);
285
+ ACCESSOR_METHODS(cpDampedRotarySpring, RestAngle, rest_angle)
286
+ ACCESSOR_METHODS(cpDampedRotarySpring, Stiffness, stiffness)
287
+ ACCESSOR_METHODS(cpDampedRotarySpring, Damping, damping)
288
+
289
+ VALUE c_cpDampedSpring = make_class("DampedSpring", rb_cpDampedSpring_alloc, rb_cpDampedSpring_init, 7);
290
+ ACCESSOR_METHODS(cpDampedSpring, Anchr1, anchr1)
291
+ ACCESSOR_METHODS(cpDampedSpring, Anchr2, anchr2)
292
+ ACCESSOR_METHODS(cpDampedSpring, RestLength, rest_length)
293
+ ACCESSOR_METHODS(cpDampedSpring, Stiffness, stiffness)
294
+ ACCESSOR_METHODS(cpDampedSpring, Damping, damping)
295
+
296
+ VALUE c_cpGearJoint = make_class("GearJoint", rb_cpGearJoint_alloc, rb_cpGearJoint_init, 4);
297
+ ACCESSOR_METHODS(cpGearJoint, Phase, phase)
298
+ ACCESSOR_METHODS(cpGearJoint, Ratio, ratio)
299
+
300
+ VALUE c_cpGrooveJoint = make_class("GrooveJoint", rb_cpGrooveJoint_alloc, rb_cpGrooveJoint_init, 5);
301
+ ACCESSOR_METHODS(cpGrooveJoint, Anchr2, anchr2)
302
+
303
+
304
+ VALUE c_cpPinJoint = make_class("PinJoint", rb_cpPinJoint_alloc, rb_cpPinJoint_init, 4);
305
+ ACCESSOR_METHODS(cpPinJoint, Anchr1, anchr1)
306
+ ACCESSOR_METHODS(cpPinJoint, Anchr2, anchr2)
307
+ ACCESSOR_METHODS(cpPinJoint, Dist, dist)
308
+
309
+
310
+ VALUE c_cpPivotJoint = make_class("PivotJoint", rb_cpPivotJoint_alloc, rb_cpPivotJoint_init, 4);
311
+ ACCESSOR_METHODS(cpPivotJoint, Anchr1, anchr1)
312
+ ACCESSOR_METHODS(cpPivotJoint, Anchr2, anchr2)
313
+
314
+ VALUE c_cpRotaryLimitJoint = make_class("RotaryLimitJoint", rb_cpRotaryLimitJoint_alloc, rb_cpRotaryLimitJoint_init, 4);
315
+ ACCESSOR_METHODS(cpRotaryLimitJoint, Min, min)
316
+ ACCESSOR_METHODS(cpRotaryLimitJoint, Max, max)
317
+
318
+ VALUE c_cpSimpleMotor = make_class("SimpleMotor", rb_cpSimpleMotor_alloc, rb_cpSimpleMotor_init, 3);
319
+ ACCESSOR_METHODS(cpSimpleMotor, Rate, rate);
320
+
321
+ VALUE c_cpSlideJoint = make_class("SlideJoint", rb_cpSlideJoint_alloc, rb_cpSlideJoint_init, 6);
322
+ ACCESSOR_METHODS(cpSlideJoint, Anchr1, anchr1)
323
+ ACCESSOR_METHODS(cpSlideJoint, Anchr2, anchr2)
324
+ ACCESSOR_METHODS(cpSlideJoint, Min, min)
325
+ ACCESSOR_METHODS(cpSlideJoint, Max, max)
326
+
327
+
328
+ VALUE c_cpRatchetJoint = make_class("RatchetJoint", rb_cpRatchetJoint_alloc, rb_cpRatchetJoint_init, 4);
329
+ ACCESSOR_METHODS(cpRatchetJoint, Angle, angle)
330
+ ACCESSOR_METHODS(cpRatchetJoint, Phase, phase)
331
+ ACCESSOR_METHODS(cpRatchetJoint, Ratchet, ratchet)
332
+
333
+
334
+ // TODO: breakable joints. Seems to be missing in chipmunk 5.4.3.
335
+
336
+ }