chipmunk 4.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/LICENSE +20 -0
  2. data/README +60 -0
  3. data/Rakefile +47 -40
  4. data/ext/chipmunk/chipmunk.c +39 -3
  5. data/ext/chipmunk/cpArbiter.c +91 -80
  6. data/ext/chipmunk/cpArray.c +24 -10
  7. data/ext/chipmunk/cpBB.c +5 -4
  8. data/ext/chipmunk/cpBody.c +30 -22
  9. data/ext/chipmunk/cpCollision.c +54 -53
  10. data/ext/chipmunk/cpConstraint.c +54 -0
  11. data/ext/chipmunk/cpDampedRotarySpring.c +106 -0
  12. data/ext/chipmunk/cpDampedSpring.c +117 -0
  13. data/ext/chipmunk/cpGearJoint.c +114 -0
  14. data/ext/chipmunk/cpGrooveJoint.c +138 -0
  15. data/ext/chipmunk/cpHashSet.c +74 -40
  16. data/ext/chipmunk/cpPinJoint.c +117 -0
  17. data/ext/chipmunk/cpPivotJoint.c +114 -0
  18. data/ext/chipmunk/cpPolyShape.c +117 -15
  19. data/ext/chipmunk/cpRatchetJoint.c +128 -0
  20. data/ext/chipmunk/cpRotaryLimitJoint.c +122 -0
  21. data/ext/chipmunk/cpShape.c +174 -18
  22. data/ext/chipmunk/cpSimpleMotor.c +99 -0
  23. data/ext/chipmunk/cpSlideJoint.c +131 -0
  24. data/ext/chipmunk/cpSpace.c +584 -215
  25. data/ext/chipmunk/cpSpaceHash.c +191 -105
  26. data/ext/chipmunk/cpVect.c +18 -10
  27. data/ext/chipmunk/extconf.rb +34 -4
  28. data/ext/chipmunk/{chipmunk.h → include/chipmunk/chipmunk.h} +63 -6
  29. data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +42 -0
  30. data/ext/chipmunk/include/chipmunk/chipmunk_types.h +80 -0
  31. data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +54 -0
  32. data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +92 -0
  33. data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +46 -0
  34. data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +53 -0
  35. data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +41 -0
  36. data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +44 -0
  37. data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +43 -0
  38. data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +42 -0
  39. data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +40 -0
  40. data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +39 -0
  41. data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +37 -0
  42. data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +44 -0
  43. data/ext/chipmunk/include/chipmunk/constraints/util.h +116 -0
  44. data/ext/chipmunk/{cpArbiter.h → include/chipmunk/cpArbiter.h} +66 -15
  45. data/ext/chipmunk/{cpArray.h → include/chipmunk/cpArray.h} +2 -1
  46. data/ext/chipmunk/{cpBB.h → include/chipmunk/cpBB.h} +21 -0
  47. data/ext/chipmunk/{cpBody.h → include/chipmunk/cpBody.h} +37 -9
  48. data/ext/chipmunk/{cpCollision.h → include/chipmunk/cpCollision.h} +1 -1
  49. data/ext/chipmunk/{cpHashSet.h → include/chipmunk/cpHashSet.h} +12 -9
  50. data/ext/chipmunk/{cpPolyShape.h → include/chipmunk/cpPolyShape.h} +13 -2
  51. data/ext/chipmunk/{cpShape.h → include/chipmunk/cpShape.h} +51 -18
  52. data/ext/chipmunk/include/chipmunk/cpSpace.h +180 -0
  53. data/ext/chipmunk/{cpSpaceHash.h → include/chipmunk/cpSpaceHash.h} +18 -9
  54. data/ext/chipmunk/{cpVect.h → include/chipmunk/cpVect.h} +61 -10
  55. data/ext/chipmunk/prime.h +32 -32
  56. data/ext/chipmunk/rb_chipmunk.c +125 -109
  57. data/ext/chipmunk/rb_chipmunk.h +96 -77
  58. data/ext/chipmunk/rb_cpArbiter.c +225 -0
  59. data/ext/chipmunk/rb_cpBB.c +174 -154
  60. data/ext/chipmunk/rb_cpBody.c +347 -239
  61. data/ext/chipmunk/rb_cpConstraint.c +346 -0
  62. data/ext/chipmunk/rb_cpShape.c +455 -292
  63. data/ext/chipmunk/rb_cpSpace.c +544 -330
  64. data/ext/chipmunk/rb_cpVect.c +321 -250
  65. data/lib/chipmunk.rb +28 -15
  66. data/lib/chipmunk/version.rb +3 -0
  67. metadata +74 -34
  68. data/ext/chipmunk/cpJoint.c +0 -553
  69. data/ext/chipmunk/cpJoint.h +0 -122
  70. data/ext/chipmunk/cpSpace.h +0 -120
  71. data/ext/chipmunk/rb_cpJoint.c +0 -136
@@ -1,239 +1,347 @@
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 "chipmunk.h"
23
-
24
- #include "ruby.h"
25
- #include "rb_chipmunk.h"
26
-
27
- VALUE c_cpBody;
28
-
29
- static VALUE
30
- rb_cpBodyAlloc(VALUE klass)
31
- {
32
- cpBody *body = cpBodyNew(1.0f, 1.0f);
33
- return Data_Wrap_Struct(klass, NULL, cpBodyFree, body);
34
- }
35
-
36
- static VALUE
37
- rb_cpBodyInitialize(VALUE self, VALUE m, VALUE i)
38
- {
39
- cpBody *body = BODY(self);
40
- cpBodyInit(body, NUM2DBL(m), NUM2DBL(i));
41
-
42
- return self;
43
- }
44
-
45
- static VALUE
46
- rb_cpBodyGetMass(VALUE self)
47
- {
48
- return rb_float_new(BODY(self)->m);
49
- }
50
-
51
- static VALUE
52
- rb_cpBodyGetMoment(VALUE self)
53
- {
54
- return rb_float_new(BODY(self)->i);
55
- }
56
-
57
- static VALUE
58
- rb_cpBodyGetPos(VALUE self)
59
- {
60
- return VWRAP(self, &BODY(self)->p);
61
- }
62
-
63
- static VALUE
64
- rb_cpBodyGetVel(VALUE self)
65
- {
66
- return VWRAP(self, &BODY(self)->v);
67
- }
68
-
69
- static VALUE
70
- rb_cpBodyGetForce(VALUE self)
71
- {
72
- return VWRAP(self, &BODY(self)->f);
73
- }
74
-
75
- static VALUE
76
- rb_cpBodyGetAngle(VALUE self)
77
- {
78
- return rb_float_new(BODY(self)->a);
79
- }
80
-
81
- static VALUE
82
- rb_cpBodyGetAVel(VALUE self)
83
- {
84
- return rb_float_new(BODY(self)->w);
85
- }
86
-
87
- static VALUE
88
- rb_cpBodyGetTorque(VALUE self)
89
- {
90
- return rb_float_new(BODY(self)->t);
91
- }
92
-
93
- static VALUE
94
- rb_cpBodyGetRot(VALUE self)
95
- {
96
- return VWRAP(self, &BODY(self)->rot);
97
- }
98
-
99
-
100
- static VALUE
101
- rb_cpBodySetMass(VALUE self, VALUE val)
102
- {
103
- cpBodySetMass(BODY(self), NUM2DBL(val));
104
- return val;
105
- }
106
-
107
- static VALUE
108
- rb_cpBodySetMoment(VALUE self, VALUE val)
109
- {
110
- cpBodySetMoment(BODY(self), NUM2DBL(val));
111
- return val;
112
- }
113
-
114
- static VALUE
115
- rb_cpBodySetPos(VALUE self, VALUE val)
116
- {
117
- BODY(self)->p = *VGET(val);
118
- return val;
119
- }
120
-
121
- static VALUE
122
- rb_cpBodySetVel(VALUE self, VALUE val)
123
- {
124
- BODY(self)->v = *VGET(val);
125
- return val;
126
- }
127
-
128
- static VALUE
129
- rb_cpBodySetForce(VALUE self, VALUE val)
130
- {
131
- BODY(self)->f = *VGET(val);
132
- return val;
133
- }
134
-
135
- static VALUE
136
- rb_cpBodySetAngle(VALUE self, VALUE val)
137
- {
138
- cpBodySetAngle(BODY(self), NUM2DBL(val));
139
- return val;
140
- }
141
-
142
- static VALUE
143
- rb_cpBodySetAVel(VALUE self, VALUE val)
144
- {
145
- BODY(self)->w = NUM2DBL(val);
146
- return val;
147
- }
148
-
149
- static VALUE
150
- rb_cpBodySetTorque(VALUE self, VALUE val)
151
- {
152
- BODY(self)->t = NUM2DBL(val);
153
- return val;
154
- }
155
-
156
- static VALUE
157
- rb_cpBodyLocal2World(VALUE self, VALUE v)
158
- {
159
- return VNEW(cpBodyLocal2World(BODY(self), *VGET(v)));
160
- }
161
-
162
- static VALUE
163
- rb_cpBodyWorld2Local(VALUE self, VALUE v)
164
- {
165
- return VNEW(cpBodyWorld2Local(BODY(self), *VGET(v)));
166
- }
167
-
168
- static VALUE
169
- rb_cpBodyResetForces(VALUE self)
170
- {
171
- cpBodyResetForces(BODY(self));
172
- return Qnil;
173
- }
174
-
175
- static VALUE
176
- rb_cpBodyApplyForce(VALUE self, VALUE f, VALUE r)
177
- {
178
- cpBodyApplyForce(BODY(self), *VGET(f), *VGET(r));
179
- return Qnil;
180
- }
181
-
182
- static VALUE
183
- rb_cpBodyApplyImpulse(VALUE self, VALUE j, VALUE r)
184
- {
185
- cpBodyApplyImpulse(BODY(self), *VGET(j), *VGET(r));
186
- return Qnil;
187
- }
188
-
189
- static VALUE
190
- rb_cpBodyUpdateVelocity(VALUE self, VALUE g, VALUE dmp, VALUE dt)
191
- {
192
- cpBodyUpdateVelocity(BODY(self), *VGET(g), NUM2DBL(dmp), NUM2DBL(dt));
193
- return Qnil;
194
- }
195
-
196
- static VALUE
197
- rb_cpBodyUpdatePosition(VALUE self, VALUE dt)
198
- {
199
- cpBodyUpdatePosition(BODY(self), NUM2DBL(dt));
200
- return Qnil;
201
- }
202
-
203
-
204
- void
205
- Init_cpBody(void)
206
- {
207
- c_cpBody = rb_define_class_under(m_Chipmunk, "Body", rb_cObject);
208
- rb_define_alloc_func(c_cpBody, rb_cpBodyAlloc);
209
- rb_define_method(c_cpBody, "initialize", rb_cpBodyInitialize, 2);
210
-
211
- rb_define_method(c_cpBody, "m" , rb_cpBodyGetMass, 0);
212
- rb_define_method(c_cpBody, "i" , rb_cpBodyGetMoment, 0);
213
- rb_define_method(c_cpBody, "p" , rb_cpBodyGetPos, 0);
214
- rb_define_method(c_cpBody, "v" , rb_cpBodyGetVel, 0);
215
- rb_define_method(c_cpBody, "f" , rb_cpBodyGetForce, 0);
216
- rb_define_method(c_cpBody, "a" , rb_cpBodyGetAngle, 0);
217
- rb_define_method(c_cpBody, "w" , rb_cpBodyGetAVel, 0);
218
- rb_define_method(c_cpBody, "t" , rb_cpBodyGetTorque, 0);
219
- rb_define_method(c_cpBody, "rot", rb_cpBodyGetRot, 0);
220
-
221
- rb_define_method(c_cpBody, "m=", rb_cpBodySetMass, 1);
222
- rb_define_method(c_cpBody, "i=", rb_cpBodySetMoment, 1);
223
- rb_define_method(c_cpBody, "p=", rb_cpBodySetPos, 1);
224
- rb_define_method(c_cpBody, "v=", rb_cpBodySetVel, 1);
225
- rb_define_method(c_cpBody, "f=", rb_cpBodySetForce, 1);
226
- rb_define_method(c_cpBody, "a=", rb_cpBodySetAngle, 1);
227
- rb_define_method(c_cpBody, "w=", rb_cpBodySetAVel, 1);
228
- rb_define_method(c_cpBody, "t=", rb_cpBodySetTorque, 1);
229
-
230
- rb_define_method(c_cpBody, "local2world", rb_cpBodyLocal2World, 1);
231
- rb_define_method(c_cpBody, "world2local", rb_cpBodyWorld2Local, 1);
232
-
233
- rb_define_method(c_cpBody, "reset_forces", rb_cpBodyResetForces, 0);
234
- rb_define_method(c_cpBody, "apply_force", rb_cpBodyApplyForce, 2);
235
- rb_define_method(c_cpBody, "apply_impulse", rb_cpBodyApplyImpulse, 2);
236
-
237
- rb_define_method(c_cpBody, "update_velocity", rb_cpBodyUpdateVelocity, 3);
238
- rb_define_method(c_cpBody, "update_position", rb_cpBodyUpdatePosition, 1);
239
- }
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 c_cpBody;
29
+
30
+ static VALUE
31
+ rb_cpBodyAlloc(VALUE klass)
32
+ {
33
+ cpBody *body = cpBodyNew(1.0f, 1.0f);
34
+ return Data_Wrap_Struct(klass, NULL, cpBodyFree, body);
35
+ }
36
+
37
+ static VALUE
38
+ rb_cpBodyInitialize(VALUE self, VALUE m, VALUE i)
39
+ {
40
+ cpBody *body = BODY(self);
41
+ cpBodyInit(body, NUM2DBL(m), NUM2DBL(i));
42
+
43
+ return self;
44
+ }
45
+
46
+ static VALUE
47
+ rb_cpBodyGetMass(VALUE self)
48
+ {
49
+ return rb_float_new(BODY(self)->m);
50
+ }
51
+
52
+ static VALUE
53
+ rb_cpBodyGetMassInv(VALUE self)
54
+ {
55
+ return rb_float_new(BODY(self)->m_inv);
56
+ }
57
+
58
+ static VALUE
59
+ rb_cpBodyGetMoment(VALUE self)
60
+ {
61
+ return rb_float_new(BODY(self)->i);
62
+ }
63
+
64
+ static VALUE
65
+ rb_cpBodyGetMomentInv(VALUE self)
66
+ {
67
+ return rb_float_new(BODY(self)->i_inv);
68
+ }
69
+
70
+ static VALUE
71
+ rb_cpBodyGetPos(VALUE self)
72
+ {
73
+ return VWRAP(self, &BODY(self)->p);
74
+ }
75
+
76
+ static VALUE
77
+ rb_cpBodyGetVel(VALUE self)
78
+ {
79
+ return VWRAP(self, &BODY(self)->v);
80
+ }
81
+
82
+ static VALUE
83
+ rb_cpBodyGetForce(VALUE self)
84
+ {
85
+ return VWRAP(self, &BODY(self)->f);
86
+ }
87
+
88
+ static VALUE
89
+ rb_cpBodyGetAngle(VALUE self)
90
+ {
91
+ return rb_float_new(BODY(self)->a);
92
+ }
93
+
94
+ static VALUE
95
+ rb_cpBodyGetAVel(VALUE self)
96
+ {
97
+ return rb_float_new(BODY(self)->w);
98
+ }
99
+
100
+ static VALUE
101
+ rb_cpBodyGetTorque(VALUE self)
102
+ {
103
+ return rb_float_new(BODY(self)->t);
104
+ }
105
+
106
+ static VALUE
107
+ rb_cpBodyGetRot(VALUE self)
108
+ {
109
+ return VWRAP(self, &BODY(self)->rot);
110
+ }
111
+
112
+ static VALUE
113
+ rb_cpBodyGetVelLimit(VALUE self)
114
+ {
115
+ return rb_float_new(BODY(self)->v_limit);
116
+ }
117
+
118
+ static VALUE
119
+ rb_cpBodyGetAVelLimit(VALUE self)
120
+ {
121
+ return rb_float_new(BODY(self)->w_limit);
122
+ }
123
+
124
+
125
+ static VALUE
126
+ rb_cpBodySetMass(VALUE self, VALUE val)
127
+ {
128
+ cpBodySetMass(BODY(self), NUM2DBL(val));
129
+ return val;
130
+ }
131
+
132
+ static VALUE
133
+ rb_cpBodySetMoment(VALUE self, VALUE val)
134
+ {
135
+ cpBodySetMoment(BODY(self), NUM2DBL(val));
136
+ return val;
137
+ }
138
+
139
+ static VALUE
140
+ rb_cpBodySetMomentInv(VALUE self, VALUE val)
141
+ {
142
+ cpBodySetMoment(BODY(self), 1.0 / NUM2DBL(val));
143
+ return val;
144
+ }
145
+
146
+ static VALUE
147
+ rb_cpBodySetPos(VALUE self, VALUE val)
148
+ {
149
+ BODY(self)->p = *VGET(val);
150
+ return val;
151
+ }
152
+
153
+ static VALUE
154
+ rb_cpBodySetVel(VALUE self, VALUE val)
155
+ {
156
+ BODY(self)->v = *VGET(val);
157
+ return val;
158
+ }
159
+
160
+ static VALUE
161
+ rb_cpBodySetForce(VALUE self, VALUE val)
162
+ {
163
+ BODY(self)->f = *VGET(val);
164
+ return val;
165
+ }
166
+
167
+ static VALUE
168
+ rb_cpBodySetAngle(VALUE self, VALUE val)
169
+ {
170
+ cpBodySetAngle(BODY(self), NUM2DBL(val));
171
+ return val;
172
+ }
173
+
174
+ static VALUE
175
+ rb_cpBodySetAVel(VALUE self, VALUE val)
176
+ {
177
+ BODY(self)->w = NUM2DBL(val);
178
+ return val;
179
+ }
180
+
181
+ static VALUE
182
+ rb_cpBodySetTorque(VALUE self, VALUE val)
183
+ {
184
+ BODY(self)->t = NUM2DBL(val);
185
+ return val;
186
+ }
187
+
188
+ static VALUE
189
+ rb_cpBodySetVelLimit(VALUE self, VALUE val)
190
+ {
191
+ BODY(self)->v_limit = NUM2DBL(val);
192
+ return val;
193
+ }
194
+
195
+ static VALUE
196
+ rb_cpBodySetAVelLimit(VALUE self, VALUE val)
197
+ {
198
+ BODY(self)->w_limit = NUM2DBL(val);
199
+ return val;
200
+ }
201
+
202
+
203
+ static VALUE
204
+ rb_cpBodyLocal2World(VALUE self, VALUE v)
205
+ {
206
+ return VNEW(cpBodyLocal2World(BODY(self), *VGET(v)));
207
+ }
208
+
209
+ static VALUE
210
+ rb_cpBodyWorld2Local(VALUE self, VALUE v)
211
+ {
212
+ return VNEW(cpBodyWorld2Local(BODY(self), *VGET(v)));
213
+ }
214
+
215
+ static VALUE
216
+ rb_cpBodyResetForces(VALUE self)
217
+ {
218
+ cpBodyResetForces(BODY(self));
219
+ return self;
220
+ }
221
+
222
+ static VALUE
223
+ rb_cpBodyApplyForce(VALUE self, VALUE f, VALUE r)
224
+ {
225
+ cpBodyApplyForce(BODY(self), *VGET(f), *VGET(r));
226
+ return self;
227
+ }
228
+
229
+ static VALUE
230
+ rb_cpBodyApplyImpulse(VALUE self, VALUE j, VALUE r)
231
+ {
232
+ cpBodyApplyImpulse(BODY(self), *VGET(j), *VGET(r));
233
+ return self;
234
+ }
235
+
236
+ static VALUE
237
+ rb_cpBodyUpdateVelocity(VALUE self, VALUE g, VALUE dmp, VALUE dt)
238
+ {
239
+ cpBodyUpdateVelocity(BODY(self), *VGET(g), NUM2DBL(dmp), NUM2DBL(dt));
240
+ return self;
241
+ }
242
+
243
+ static VALUE
244
+ rb_cpBodyUpdatePosition(VALUE self, VALUE dt)
245
+ {
246
+ cpBodyUpdatePosition(BODY(self), NUM2DBL(dt));
247
+ return self;
248
+ }
249
+
250
+ // Intended for objects that are moved manually with a custom velocity integration function.
251
+ static VALUE
252
+ rb_cpBodySlew(VALUE self, VALUE pos, VALUE dt)
253
+ {
254
+ cpBodySlew(BODY(self), *VGET(pos), NUM2DBL(dt));
255
+ return self;
256
+ }
257
+
258
+ static VALUE
259
+ rb_cpApplyDampedSpring(VALUE klass, VALUE a, VALUE b,
260
+ VALUE anchr1, VALUE anchr2, VALUE rlen, VALUE k, VALUE dmp, VALUE dt)
261
+ {
262
+ cpApplyDampedSpring(BODY(a), BODY(b), *VGET(anchr1), *VGET(anchr2),
263
+ NUM2DBL(rlen), NUM2DBL(k), NUM2DBL(dmp), NUM2DBL(dt));
264
+ return klass;
265
+ }
266
+
267
+
268
+ void cpApplyDampedSpring(cpBody *a, cpBody *b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt);
269
+
270
+ void
271
+ Init_cpBody(void)
272
+ {
273
+ c_cpBody = rb_define_class_under(m_Chipmunk, "Body", rb_cObject);
274
+ rb_define_alloc_func(c_cpBody, rb_cpBodyAlloc);
275
+ rb_define_method(c_cpBody, "initialize", rb_cpBodyInitialize, 2);
276
+
277
+ rb_define_method(c_cpBody, "m" , rb_cpBodyGetMass, 0);
278
+ rb_define_method(c_cpBody, "m_inv" , rb_cpBodyGetMassInv, 0);
279
+ rb_define_method(c_cpBody, "i" , rb_cpBodyGetMoment, 0);
280
+ rb_define_method(c_cpBody, "i_inv" , rb_cpBodyGetMomentInv, 0);
281
+ rb_define_method(c_cpBody, "p" , rb_cpBodyGetPos, 0);
282
+ rb_define_method(c_cpBody, "v" , rb_cpBodyGetVel, 0);
283
+ rb_define_method(c_cpBody, "f" , rb_cpBodyGetForce, 0);
284
+ rb_define_method(c_cpBody, "a" , rb_cpBodyGetAngle, 0);
285
+ rb_define_method(c_cpBody, "w" , rb_cpBodyGetAVel, 0);
286
+ rb_define_method(c_cpBody, "t" , rb_cpBodyGetTorque, 0);
287
+ rb_define_method(c_cpBody, "rot" , rb_cpBodyGetRot, 0);
288
+
289
+ rb_define_method(c_cpBody, "m=" , rb_cpBodySetMass, 1);
290
+ rb_define_method(c_cpBody, "i=" , rb_cpBodySetMoment, 1);
291
+ rb_define_method(c_cpBody, "p=" , rb_cpBodySetPos, 1);
292
+ rb_define_method(c_cpBody, "v=" , rb_cpBodySetVel, 1);
293
+ rb_define_method(c_cpBody, "f=" , rb_cpBodySetForce, 1);
294
+ rb_define_method(c_cpBody, "a=" , rb_cpBodySetAngle, 1);
295
+ rb_define_method(c_cpBody, "w=" , rb_cpBodySetAVel, 1);
296
+ rb_define_method(c_cpBody, "t=" , rb_cpBodySetTorque, 1);
297
+
298
+ rb_define_method(c_cpBody, "mass" , rb_cpBodyGetMass, 0);
299
+ rb_define_method(c_cpBody, "moment" , rb_cpBodyGetMoment, 0);
300
+ rb_define_method(c_cpBody, "pos" , rb_cpBodyGetPos, 0);
301
+ rb_define_method(c_cpBody, "vel" , rb_cpBodyGetVel, 0);
302
+ rb_define_method(c_cpBody, "force" , rb_cpBodyGetForce, 0);
303
+ rb_define_method(c_cpBody, "angle" , rb_cpBodyGetAngle, 0);
304
+ rb_define_method(c_cpBody, "ang_vel" , rb_cpBodyGetAVel, 0);
305
+ rb_define_method(c_cpBody, "torque" , rb_cpBodyGetTorque, 0);
306
+ rb_define_method(c_cpBody, "rot" , rb_cpBodyGetRot, 0);
307
+ rb_define_method(c_cpBody, "v_limit" , rb_cpBodyGetVelLimit, 0);
308
+ rb_define_method(c_cpBody, "w_limit" , rb_cpBodyGetAVelLimit, 0);
309
+
310
+ rb_define_method(c_cpBody, "mass=" , rb_cpBodySetMass, 1);
311
+ rb_define_method(c_cpBody, "moment=" , rb_cpBodySetMoment, 1);
312
+ rb_define_method(c_cpBody, "pos=" , rb_cpBodySetPos, 1);
313
+ rb_define_method(c_cpBody, "vel=" , rb_cpBodySetVel, 1);
314
+ rb_define_method(c_cpBody, "force=" , rb_cpBodySetForce, 1);
315
+ rb_define_method(c_cpBody, "angle=" , rb_cpBodySetAngle, 1);
316
+ rb_define_method(c_cpBody, "ang_vel=", rb_cpBodySetAVel, 1);
317
+ rb_define_method(c_cpBody, "torque=" , rb_cpBodySetTorque, 1);
318
+ rb_define_method(c_cpBody, "v_limit=", rb_cpBodySetVelLimit, 1);
319
+ rb_define_method(c_cpBody, "w_limit=", rb_cpBodySetAVelLimit, 1);
320
+
321
+ /* Some more aliases */
322
+ rb_define_method(c_cpBody, "moment_inv" , rb_cpBodyGetMomentInv, 1);
323
+ rb_define_method(c_cpBody, "moment_inv=" , rb_cpBodySetMomentInv, 1);
324
+ rb_define_method(c_cpBody, "ang_vel_limit" , rb_cpBodyGetAVelLimit, 0);
325
+ rb_define_method(c_cpBody, "vel_limit" , rb_cpBodyGetVelLimit, 0);
326
+ rb_define_method(c_cpBody, "ang_vel_limit=" , rb_cpBodySetAVelLimit, 1);
327
+ rb_define_method(c_cpBody, "vel_limit=" , rb_cpBodySetVelLimit, 1);
328
+
329
+
330
+ rb_define_method(c_cpBody, "local2world", rb_cpBodyLocal2World, 1);
331
+ rb_define_method(c_cpBody, "world2local", rb_cpBodyWorld2Local, 1);
332
+
333
+ rb_define_method(c_cpBody, "reset_forces", rb_cpBodyResetForces, 0);
334
+ rb_define_method(c_cpBody, "apply_force", rb_cpBodyApplyForce, 2);
335
+ rb_define_method(c_cpBody, "apply_impulse", rb_cpBodyApplyImpulse, 2);
336
+
337
+ rb_define_method(c_cpBody, "update_velocity", rb_cpBodyUpdateVelocity, 3);
338
+ rb_define_method(c_cpBody, "update_position", rb_cpBodyUpdatePosition, 1);
339
+
340
+ /* Manual integration function */
341
+ rb_define_method(c_cpBody, "slew", rb_cpBodySlew, 2);
342
+
343
+ /* Damped spring function */
344
+ rb_define_singleton_method(c_cpBody,
345
+ "apply_damped_spring", rb_cpApplyDampedSpring, 8);
346
+
347
+ }