chipmunk 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ require 'mkmf'
2
+
3
+ $CFLAGS += ' -std=gnu99 -ffast-math'
4
+ create_makefile('chipmunk')
@@ -0,0 +1,68 @@
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
+ // Used for resizing hash tables.
23
+ // Values approximately double.
24
+
25
+ static int primes[] = {
26
+ 5, //2^2 + 1
27
+ 11, //2^3 + 3
28
+ 17, //2^4 + 1
29
+ 37, //2^5 + 5
30
+ 67, //2^6 + 3
31
+ 131, //2^7 + 3
32
+ 257, //2^8 + 1
33
+ 521, //2^9 + 9
34
+ 1031, //2^10 + 7
35
+ 2053, //2^11 + 5
36
+ 4099, //2^12 + 3
37
+ 8209, //2^13 + 17
38
+ 16411, //2^14 + 27
39
+ 32771, //2^15 + 3
40
+ 65537, //2^16 + 1
41
+ 131101, //2^17 + 29
42
+ 262147, //2^18 + 3
43
+ 524309, //2^19 + 21
44
+ 1048583, //2^20 + 7
45
+ 2097169, //2^21 + 17
46
+ 4194319, //2^22 + 15
47
+ 8388617, //2^23 + 9
48
+ 16777259, //2^24 + 43
49
+ 33554467, //2^25 + 35
50
+ 67108879, //2^26 + 15
51
+ 134217757, //2^27 + 29
52
+ 268435459, //2^28 + 3
53
+ 536870923, //2^29 + 11
54
+ 1073741827, //2^30 + 3
55
+ 0,
56
+ };
57
+
58
+ static int
59
+ next_prime(int n)
60
+ {
61
+ int i = 0;
62
+ while(n > primes[i]){
63
+ i++;
64
+ assert(primes[i]); // realistically this should never happen
65
+ }
66
+
67
+ return primes[i];
68
+ }
@@ -0,0 +1,109 @@
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 m_Chipmunk;
28
+
29
+ ID id_parent;
30
+
31
+ static VALUE
32
+ rb_get_cp_bias_coef(VALUE self)
33
+ {
34
+ return rb_float_new(cp_bias_coef);
35
+ }
36
+
37
+ static VALUE
38
+ rb_set_cp_bias_coef(VALUE self, VALUE num)
39
+ {
40
+ cp_bias_coef = NUM2DBL(num);
41
+ return num;
42
+ }
43
+
44
+ static VALUE
45
+ rb_get_cp_collision_slop(VALUE self)
46
+ {
47
+ return rb_float_new(cp_collision_slop);
48
+ }
49
+
50
+ static VALUE
51
+ rb_set_cp_collision_slop(VALUE self, VALUE num)
52
+ {
53
+ cp_collision_slop = NUM2DBL(num);
54
+ return num;
55
+ }
56
+
57
+ static VALUE
58
+ rb_momentForCircle(VALUE self, VALUE m, VALUE r1, VALUE r2, VALUE offset)
59
+ {
60
+ cpFloat i = cpMomentForCircle(NUM2DBL(m), NUM2DBL(r1), NUM2DBL(r2), *VGET(offset));
61
+ return rb_float_new(i);
62
+ }
63
+
64
+ static VALUE
65
+ rb_momentForPoly(VALUE self, VALUE m, VALUE arr, VALUE offset)
66
+ {
67
+ Check_Type(arr, T_ARRAY);
68
+ int numVerts = RARRAY_LEN(arr);
69
+ cpVect verts[numVerts];
70
+
71
+ for(int i=0; i<numVerts; i++)
72
+ verts[i] = *VGET(RARRAY_PTR(arr)[i]);
73
+
74
+ cpFloat inertia = cpMomentForPoly(NUM2DBL(m), numVerts, verts, *VGET(offset));
75
+ return rb_float_new(inertia);
76
+ }
77
+
78
+ static VALUE
79
+ rb_dampedSpring(VALUE self, VALUE a, VALUE b, VALUE r1, VALUE r2, VALUE len, VALUE k, VALUE dmp, VALUE dt)
80
+ {
81
+ cpDampedSpring(BODY(a), BODY(b), *VGET(r1), *VGET(r2), NUM2DBL(len), NUM2DBL(k), NUM2DBL(dmp), NUM2DBL(dt));
82
+ return Qnil;
83
+ }
84
+
85
+ void
86
+ Init_chipmunk(void)
87
+ {
88
+ id_parent = rb_intern("parent");
89
+
90
+ cpInitChipmunk();
91
+
92
+ m_Chipmunk = rb_define_module("CP");
93
+ rb_define_module_function(m_Chipmunk, "bias_coef", rb_get_cp_bias_coef, 0);
94
+ rb_define_module_function(m_Chipmunk, "bias_coef=", rb_set_cp_bias_coef, 1);
95
+ rb_define_module_function(m_Chipmunk, "collision_slop", rb_get_cp_collision_slop, 0);
96
+ rb_define_module_function(m_Chipmunk, "collision_slop=", rb_set_cp_collision_slop, 1);
97
+
98
+ rb_define_module_function(m_Chipmunk, "moment_for_circle", rb_momentForCircle, 4);
99
+ rb_define_module_function(m_Chipmunk, "moment_for_poly", rb_momentForPoly, 3);
100
+
101
+ rb_define_module_function(m_Chipmunk, "damped_spring", rb_dampedSpring, 8);
102
+
103
+ Init_cpVect();
104
+ Init_cpBB();
105
+ Init_cpBody();
106
+ Init_cpShape();
107
+ Init_cpJoint();
108
+ Init_cpSpace();
109
+ }
@@ -0,0 +1,77 @@
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
+ extern VALUE m_Chipmunk;
23
+
24
+ extern VALUE c_cpVect;
25
+ extern VALUE c_cpBB;
26
+ extern VALUE c_cpBody;
27
+ extern VALUE m_cpShape;
28
+ extern VALUE c_cpCircleShape;
29
+ extern VALUE c_cpSegmentShape;
30
+ extern VALUE c_cpPolyShape;
31
+ extern VALUE m_cpJoint;
32
+ extern VALUE c_cpSpace;
33
+
34
+ extern ID id_parent;
35
+
36
+ static inline VALUE
37
+ VNEW(cpVect v)
38
+ {
39
+ cpVect *ptr = malloc(sizeof(cpVect));
40
+ *ptr = v;
41
+ return Data_Wrap_Struct(c_cpVect, NULL, free, ptr);
42
+ }
43
+
44
+ static inline VALUE
45
+ VWRAP(VALUE parent, cpVect *v)
46
+ {
47
+ VALUE vec_obj = Data_Wrap_Struct(c_cpVect, NULL, NULL, v);
48
+ rb_ivar_set(vec_obj, id_parent, parent);
49
+
50
+ return vec_obj;
51
+ }
52
+
53
+ #define GETTER_TEMPLATE(func_name, klass, klass_name, type)\
54
+ static inline type *\
55
+ func_name(VALUE self)\
56
+ {\
57
+ if(!rb_obj_is_kind_of(self, klass))\
58
+ rb_raise(rb_eTypeError, "wrong argument type %s (expected CP::klass_name)", rb_obj_classname(self));\
59
+ type *ptr;\
60
+ Data_Get_Struct(self, type, ptr);\
61
+ return ptr;\
62
+ }\
63
+
64
+ GETTER_TEMPLATE(VGET , c_cpVect , Vec2 , cpVect )
65
+ GETTER_TEMPLATE(BBGET, c_cpBB , BB , cpBB )
66
+ GETTER_TEMPLATE(BODY , c_cpBody , Body , cpBody )
67
+ GETTER_TEMPLATE(SHAPE, m_cpShape, Shape, cpShape)
68
+ GETTER_TEMPLATE(JOINT, m_cpJoint, Joint, cpJoint)
69
+ GETTER_TEMPLATE(SPACE, c_cpSpace, Space, cpSpace)
70
+
71
+ void Init_chipmunk(void);
72
+ void Init_cpVect();
73
+ void Init_cpBB();
74
+ void Init_cpBody();
75
+ void Init_cpShape();
76
+ void Init_cpJoint();
77
+ void Init_cpSpace();
@@ -0,0 +1,154 @@
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_cpBB;
28
+
29
+ static VALUE
30
+ rb_cpBBAlloc(VALUE klass)
31
+ {
32
+ cpBB *bb = malloc(sizeof(cpBB));
33
+ return Data_Wrap_Struct(klass, NULL, free, bb);
34
+ }
35
+
36
+ static VALUE
37
+ rb_cpBBInitialize(VALUE self, VALUE l, VALUE b, VALUE r, VALUE t)
38
+ {
39
+ cpBB *bb = BBGET(self);
40
+ bb->l = NUM2DBL(l);
41
+ bb->b = NUM2DBL(b);
42
+ bb->r = NUM2DBL(r);
43
+ bb->t = NUM2DBL(t);
44
+
45
+ return self;
46
+ }
47
+
48
+ static VALUE
49
+ rb_cpBBintersects(VALUE self, VALUE other)
50
+ {
51
+ int bool = cpBBintersects(*BBGET(self), *BBGET(other));
52
+ return bool ? Qtrue : Qfalse;
53
+ }
54
+
55
+ static VALUE
56
+ rb_cpBBClampVect(VALUE self, VALUE v)
57
+ {
58
+ return VNEW(cpBBClampVect(*BBGET(self), *VGET(v)));
59
+ }
60
+
61
+ static VALUE
62
+ rb_cpBBWrapVect(VALUE self, VALUE v)
63
+ {
64
+ return VNEW(cpBBWrapVect(*BBGET(self), *VGET(v)));
65
+ }
66
+
67
+ static VALUE
68
+ rb_cpBBGetL(VALUE self)
69
+ {
70
+ return rb_float_new(BBGET(self)->l);
71
+ }
72
+
73
+ static VALUE
74
+ rb_cpBBGetB(VALUE self)
75
+ {
76
+ return rb_float_new(BBGET(self)->b);
77
+ }
78
+
79
+ static VALUE
80
+ rb_cpBBGetR(VALUE self)
81
+ {
82
+ return rb_float_new(BBGET(self)->r);
83
+ }
84
+
85
+ static VALUE
86
+ rb_cpBBGetT(VALUE self)
87
+ {
88
+ return rb_float_new(BBGET(self)->t);
89
+ }
90
+
91
+ static VALUE
92
+ rb_cpBBSetL(VALUE self, VALUE val)
93
+ {
94
+ BBGET(self)->l = NUM2DBL(val);
95
+ return val;
96
+ }
97
+
98
+ static VALUE
99
+ rb_cpBBSetB(VALUE self, VALUE val)
100
+ {
101
+ BBGET(self)->b = NUM2DBL(val);
102
+ return val;
103
+ }
104
+
105
+ static VALUE
106
+ rb_cpBBSetR(VALUE self, VALUE val)
107
+ {
108
+ BBGET(self)->r = NUM2DBL(val);
109
+ return val;
110
+ }
111
+
112
+ static VALUE
113
+ rb_cpBBSetT(VALUE self, VALUE val)
114
+ {
115
+ BBGET(self)->t = NUM2DBL(val);
116
+ return val;
117
+ }
118
+
119
+ static VALUE
120
+ rb_cpBBToString(VALUE self)
121
+ {
122
+ char str[256];
123
+ cpBB *bb = BBGET(self);
124
+
125
+ sprintf(str, "#<CP::BB:(% .3f, % .3f) -> (% .3f, % .3f)>", bb->l, bb->b, bb->r, bb->t);
126
+
127
+ return rb_str_new2(str);
128
+ }
129
+
130
+ void
131
+ Init_cpBB(void)
132
+ {
133
+ c_cpBB = rb_define_class_under(m_Chipmunk, "BB", rb_cObject);
134
+ rb_define_alloc_func(c_cpBB, rb_cpBBAlloc);
135
+ rb_define_method(c_cpBB, "initialize", rb_cpBBInitialize, 4);
136
+
137
+ rb_define_method(c_cpBB, "l", rb_cpBBGetL, 0);
138
+ rb_define_method(c_cpBB, "b", rb_cpBBGetB, 0);
139
+ rb_define_method(c_cpBB, "r", rb_cpBBGetR, 0);
140
+ rb_define_method(c_cpBB, "t", rb_cpBBGetT, 0);
141
+
142
+ rb_define_method(c_cpBB, "l=", rb_cpBBSetL, 1);
143
+ rb_define_method(c_cpBB, "b=", rb_cpBBSetB, 1);
144
+ rb_define_method(c_cpBB, "r=", rb_cpBBSetR, 1);
145
+ rb_define_method(c_cpBB, "t=", rb_cpBBSetT, 1);
146
+
147
+ rb_define_method(c_cpBB, "intersect?", rb_cpBBintersects, 1);
148
+ //containsBB
149
+ //containsVect
150
+ rb_define_method(c_cpBB, "clamp_vect", rb_cpBBClampVect, 1);
151
+ rb_define_method(c_cpBB, "wrap_vect", rb_cpBBWrapVect, 1);
152
+
153
+ rb_define_method(c_cpBB, "to_s", rb_cpBBToString, 0);
154
+ }
@@ -0,0 +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 "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
+ }