chipmunk 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,330 @@
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
+ ID id_call;
28
+
29
+
30
+ VALUE c_cpSpace;
31
+
32
+ static VALUE
33
+ rb_cpSpaceAlloc(VALUE klass)
34
+ {
35
+ cpSpace *space = cpSpaceAlloc();
36
+ return Data_Wrap_Struct(klass, NULL, cpSpaceFree, space);
37
+ }
38
+
39
+ static VALUE
40
+ rb_cpSpaceInitialize(VALUE self)
41
+ {
42
+ cpSpace *space = SPACE(self);
43
+ cpSpaceInit(space);
44
+
45
+ // These might as well be in one shared hash.
46
+ rb_iv_set(self, "static_shapes", rb_ary_new());
47
+ rb_iv_set(self, "active_shapes", rb_ary_new());
48
+ rb_iv_set(self, "bodies", rb_ary_new());
49
+ rb_iv_set(self, "joints", rb_ary_new());
50
+ rb_iv_set(self, "blocks", rb_hash_new());
51
+
52
+ return self;
53
+ }
54
+
55
+ static VALUE
56
+ rb_cpSpaceGetIterations(VALUE self)
57
+ {
58
+ return INT2NUM(SPACE(self)->iterations);
59
+ }
60
+
61
+ static VALUE
62
+ rb_cpSpaceSetIterations(VALUE self, VALUE val)
63
+ {
64
+ SPACE(self)->iterations = NUM2INT(val);
65
+ return val;
66
+ }
67
+
68
+ static VALUE
69
+ rb_cpSpaceGetElasticIterations(VALUE self)
70
+ {
71
+ return INT2NUM(SPACE(self)->elasticIterations);
72
+ }
73
+
74
+ static VALUE
75
+ rb_cpSpaceSetElasticIterations(VALUE self, VALUE val)
76
+ {
77
+ SPACE(self)->elasticIterations = NUM2INT(val);
78
+ return val;
79
+ }
80
+
81
+ static VALUE
82
+ rb_cpSpaceGetDamping(VALUE self)
83
+ {
84
+ return rb_float_new(SPACE(self)->damping);
85
+ }
86
+
87
+ static VALUE
88
+ rb_cpSpaceSetDamping(VALUE self, VALUE val)
89
+ {
90
+ SPACE(self)->damping = NUM2DBL(val);
91
+ return val;
92
+ }
93
+
94
+ static VALUE
95
+ rb_cpSpaceGetGravity(VALUE self)
96
+ {
97
+ return VWRAP(self, &SPACE(self)->gravity);
98
+ }
99
+
100
+ static VALUE
101
+ rb_cpSpaceSetGravity(VALUE self, VALUE val)
102
+ {
103
+ SPACE(self)->gravity = *VGET(val);
104
+ return val;
105
+ }
106
+
107
+ static int
108
+ collisionCallback(cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data)
109
+ {
110
+ VALUE block = (VALUE)data;
111
+ VALUE shapea = (VALUE)a->data;
112
+ VALUE shapeb = (VALUE)b->data;
113
+
114
+ return rb_funcall(block, id_call, 2, shapea, shapeb);
115
+ }
116
+
117
+ static VALUE
118
+ rb_cpSpaceAddCollisionFunc(int argc, VALUE *argv, VALUE self)
119
+ {
120
+ VALUE a, b, block;
121
+ rb_scan_args(argc, argv, "20&", &a, &b, &block);
122
+
123
+ VALUE id_a = rb_obj_id(a);
124
+ VALUE id_b = rb_obj_id(b);
125
+ if(NIL_P(block)) {
126
+ cpSpaceAddCollisionPairFunc(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
127
+ NULL, NULL);
128
+ } else {
129
+ cpSpaceAddCollisionPairFunc(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b),
130
+ collisionCallback, (void *)block);
131
+ }
132
+
133
+ VALUE blocks = rb_iv_get(self, "blocks");
134
+ rb_hash_aset(blocks, rb_ary_new3(2, id_a, id_b), block);
135
+
136
+ return Qnil;
137
+ }
138
+
139
+ static VALUE
140
+ rb_cpSpaceRemoveCollisionFunc(VALUE self, VALUE a, VALUE b)
141
+ {
142
+ VALUE id_a = rb_obj_id(a);
143
+ VALUE id_b = rb_obj_id(b);
144
+ cpSpaceRemoveCollisionPairFunc(SPACE(self), NUM2UINT(id_a), NUM2UINT(id_b));
145
+
146
+ VALUE blocks = rb_iv_get(self, "blocks");
147
+ rb_hash_delete(blocks, rb_ary_new3(2, id_a, id_b));
148
+
149
+ return Qnil;
150
+ }
151
+
152
+ static VALUE
153
+ rb_cpSpaceSetDefaultCollisionFunc(int argc, VALUE *argv, VALUE self)
154
+ {
155
+ VALUE block;
156
+ rb_scan_args(argc, argv, "00&", &block);
157
+
158
+ if(NIL_P(block)) {
159
+ cpSpaceSetDefaultCollisionPairFunc(SPACE(self), NULL, NULL);
160
+ } else {
161
+ cpSpaceSetDefaultCollisionPairFunc(SPACE(self), collisionCallback, (void *)block);
162
+ }
163
+
164
+ rb_hash_aset(rb_iv_get(self, "blocks"), ID2SYM(rb_intern("default")), block);
165
+
166
+ return Qnil;
167
+ }
168
+
169
+ static VALUE
170
+ rb_cpSpaceAddShape(VALUE self, VALUE shape)
171
+ {
172
+ cpSpaceAddShape(SPACE(self), SHAPE(shape));
173
+ rb_ary_push(rb_iv_get(self, "active_shapes"), shape);
174
+ return shape;
175
+ }
176
+
177
+ static VALUE
178
+ rb_cpSpaceAddStaticShape(VALUE self, VALUE shape)
179
+ {
180
+ cpSpaceAddStaticShape(SPACE(self), SHAPE(shape));
181
+ rb_ary_push(rb_iv_get(self, "static_shapes"), shape);
182
+ return shape;
183
+ }
184
+
185
+ static VALUE
186
+ rb_cpSpaceAddBody(VALUE self, VALUE body)
187
+ {
188
+ cpSpaceAddBody(SPACE(self), BODY(body));
189
+ rb_ary_push(rb_iv_get(self, "bodies"), body);
190
+ return body;
191
+ }
192
+
193
+ static VALUE
194
+ rb_cpSpaceAddJoint(VALUE self, VALUE joint)
195
+ {
196
+ cpSpaceAddJoint(SPACE(self), JOINT(joint));
197
+ rb_ary_push(rb_iv_get(self, "joints"), joint);
198
+ return joint;
199
+ }
200
+
201
+ static VALUE
202
+ rb_cpSpaceRemoveShape(VALUE self, VALUE shape)
203
+ {
204
+ cpSpaceRemoveShape(SPACE(self), SHAPE(shape));
205
+ return rb_ary_delete(rb_iv_get(self, "active_shapes"), shape);
206
+ }
207
+
208
+ static VALUE
209
+ rb_cpSpaceRemoveStaticShape(VALUE self, VALUE shape)
210
+ {
211
+ cpSpaceRemoveStaticShape(SPACE(self), SHAPE(shape));
212
+ return rb_ary_delete(rb_iv_get(self, "static_shapes"), shape);
213
+ }
214
+
215
+ static VALUE
216
+ rb_cpSpaceRemoveBody(VALUE self, VALUE body)
217
+ {
218
+ cpSpaceRemoveBody(SPACE(self), BODY(body));
219
+ return rb_ary_delete(rb_iv_get(self, "bodies"), body);
220
+ }
221
+
222
+ static VALUE
223
+ rb_cpSpaceRemoveJoint(VALUE self, VALUE joint)
224
+ {
225
+ cpSpaceRemoveJoint(SPACE(self), JOINT(joint));
226
+ return rb_ary_delete(rb_iv_get(self, "joints"), joint);
227
+ }
228
+
229
+ static VALUE
230
+ rb_cpSpaceResizeStaticHash(VALUE self, VALUE dim, VALUE count)
231
+ {
232
+ cpSpaceResizeStaticHash(SPACE(self), NUM2DBL(dim), NUM2INT(count));
233
+ return Qnil;
234
+ }
235
+
236
+ static VALUE
237
+ rb_cpSpaceResizeActiveHash(VALUE self, VALUE dim, VALUE count)
238
+ {
239
+ cpSpaceResizeActiveHash(SPACE(self), NUM2DBL(dim), NUM2INT(count));
240
+ return Qnil;
241
+ }
242
+
243
+ static VALUE
244
+ rb_cpSpaceRehashStatic(VALUE self)
245
+ {
246
+ cpSpaceRehashStatic(SPACE(self));
247
+ return Qnil;
248
+ }
249
+
250
+ static void
251
+ pointQueryHelper(cpShape *shape, void *block)
252
+ {
253
+ rb_funcall((VALUE)block, id_call, 1, (VALUE)shape->data);
254
+ }
255
+
256
+ static VALUE
257
+ rb_cpSpaceShapePointQuery(int argc, VALUE *argv, VALUE self)
258
+ {
259
+ VALUE point, block;
260
+ rb_scan_args(argc, argv, "10&", &point, &block);
261
+
262
+ cpSpaceShapePointQuery(SPACE(self), *VGET(point), pointQueryHelper, (void *)block);
263
+
264
+ return Qnil;
265
+ }
266
+
267
+ static VALUE
268
+ rb_cpSpaceStaticShapePointQuery(int argc, VALUE *argv, VALUE self)
269
+ {
270
+ VALUE point, block;
271
+ rb_scan_args(argc, argv, "10&", &point, &block);
272
+
273
+ cpSpaceStaticShapePointQuery(SPACE(self), *VGET(point), pointQueryHelper, (void *)block);
274
+
275
+ return Qnil;
276
+ }
277
+
278
+ static VALUE
279
+ rb_cpSpaceStep(VALUE self, VALUE dt)
280
+ {
281
+ cpSpaceStep(SPACE(self), NUM2DBL(dt));
282
+ return Qnil;
283
+ }
284
+
285
+
286
+
287
+ void
288
+ Init_cpSpace(void)
289
+ {
290
+ id_call = rb_intern("call");
291
+
292
+ c_cpSpace = rb_define_class_under(m_Chipmunk, "Space", rb_cObject);
293
+ rb_define_alloc_func(c_cpSpace, rb_cpSpaceAlloc);
294
+ rb_define_method(c_cpSpace, "initialize", rb_cpSpaceInitialize, 0);
295
+
296
+ rb_define_method(c_cpSpace, "iterations", rb_cpSpaceGetIterations, 0);
297
+ rb_define_method(c_cpSpace, "iterations=", rb_cpSpaceSetIterations, 1);
298
+
299
+ rb_define_method(c_cpSpace, "elastic_iterations", rb_cpSpaceGetElasticIterations, 0);
300
+ rb_define_method(c_cpSpace, "elastic_iterations=", rb_cpSpaceSetElasticIterations, 1);
301
+
302
+ rb_define_method(c_cpSpace, "damping", rb_cpSpaceGetDamping, 0);
303
+ rb_define_method(c_cpSpace, "damping=", rb_cpSpaceSetDamping, 1);
304
+
305
+ rb_define_method(c_cpSpace, "gravity", rb_cpSpaceGetGravity, 0);
306
+ rb_define_method(c_cpSpace, "gravity=", rb_cpSpaceSetGravity, 1);
307
+
308
+ rb_define_method(c_cpSpace, "add_collision_func", rb_cpSpaceAddCollisionFunc, -1);
309
+ rb_define_method(c_cpSpace, "remove_collision_func", rb_cpSpaceRemoveCollisionFunc, 2);
310
+ rb_define_method(c_cpSpace, "set_default_collision_func", rb_cpSpaceSetDefaultCollisionFunc, -1);
311
+
312
+ rb_define_method(c_cpSpace, "add_shape", rb_cpSpaceAddShape, 1);
313
+ rb_define_method(c_cpSpace, "add_static_shape", rb_cpSpaceAddStaticShape, 1);
314
+ rb_define_method(c_cpSpace, "add_body", rb_cpSpaceAddBody, 1);
315
+ rb_define_method(c_cpSpace, "add_joint", rb_cpSpaceAddJoint, 1);
316
+
317
+ rb_define_method(c_cpSpace, "remove_shape", rb_cpSpaceRemoveShape, 1);
318
+ rb_define_method(c_cpSpace, "remove_static_shape", rb_cpSpaceRemoveStaticShape, 1);
319
+ rb_define_method(c_cpSpace, "remove_body", rb_cpSpaceRemoveBody, 1);
320
+ rb_define_method(c_cpSpace, "remove_joint", rb_cpSpaceRemoveJoint, 1);
321
+
322
+ rb_define_method(c_cpSpace, "resize_static_hash", rb_cpSpaceResizeStaticHash, 2);
323
+ rb_define_method(c_cpSpace, "resize_active_hash", rb_cpSpaceResizeActiveHash, 2);
324
+ rb_define_method(c_cpSpace, "rehash_static", rb_cpSpaceRehashStatic, 0);
325
+
326
+ rb_define_method(c_cpSpace, "shape_point_query", rb_cpSpaceShapePointQuery, -1);
327
+ rb_define_method(c_cpSpace, "static_shape_point_query", rb_cpSpaceStaticShapePointQuery, -1);
328
+
329
+ rb_define_method(c_cpSpace, "step", rb_cpSpaceStep, 1);
330
+ }
@@ -0,0 +1,250 @@
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_cpVect;
28
+
29
+ static VALUE
30
+ rb_cpVectForAngle(VALUE self, VALUE angle)
31
+ {
32
+ return VNEW(cpvforangle(NUM2DBL(angle)));
33
+ }
34
+
35
+ static VALUE
36
+ rb_cpVectAlloc(VALUE klass)
37
+ {
38
+ cpVect *v = malloc(sizeof(cpVect));
39
+ return Data_Wrap_Struct(klass, NULL, free, v);
40
+ }
41
+
42
+ static VALUE
43
+ rb_cpVectInitialize(VALUE self, VALUE x, VALUE y)
44
+ {
45
+ cpVect *v = VGET(self);
46
+ v->x = NUM2DBL(x);
47
+ v->y = NUM2DBL(y);
48
+
49
+ return self;
50
+ }
51
+
52
+ static VALUE
53
+ rb_cpVectGetX(VALUE self)
54
+ {
55
+ return rb_float_new(VGET(self)->x);
56
+ }
57
+
58
+ static VALUE
59
+ rb_cpVectGetY(VALUE self)
60
+ {
61
+ return rb_float_new(VGET(self)->y);
62
+ }
63
+
64
+ static VALUE
65
+ rb_cpVectSetX(VALUE self, VALUE x)
66
+ {
67
+ VGET(self)->x = NUM2DBL(x);
68
+ return self;
69
+ }
70
+
71
+ static VALUE
72
+ rb_cpVectSetY(VALUE self, VALUE y)
73
+ {
74
+ VGET(self)->y = NUM2DBL(y);
75
+ return self;
76
+ }
77
+
78
+ static VALUE
79
+ rb_cpVectToString(VALUE self)
80
+ {
81
+ char str[256];
82
+ cpVect *v = VGET(self);
83
+
84
+ sprintf(str, "(% .3f, % .3f)", v->x, v->y);
85
+
86
+ return rb_str_new2(str);
87
+ }
88
+
89
+ static VALUE
90
+ rb_cpVectToArray(VALUE self)
91
+ {
92
+ cpVect *v = VGET(self);
93
+ return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y));
94
+ }
95
+
96
+ static VALUE
97
+ rb_cpVectToAngle(VALUE self)
98
+ {
99
+ return rb_float_new(cpvtoangle(*VGET(self)));
100
+ }
101
+
102
+
103
+ static VALUE
104
+ rb_cpVectNegate(VALUE self)
105
+ {
106
+ return VNEW(cpvneg(*VGET(self)));
107
+ }
108
+
109
+ static VALUE
110
+ rb_cpVectAdd(VALUE self, VALUE v)
111
+ {
112
+ return VNEW(cpvadd(*VGET(self), *VGET(v)));
113
+ }
114
+
115
+ static VALUE
116
+ rb_cpVectSub(VALUE self, VALUE v)
117
+ {
118
+ return VNEW(cpvsub(*VGET(self), *VGET(v)));
119
+ }
120
+
121
+ static VALUE
122
+ rb_cpVectSMult(VALUE self, VALUE s)
123
+ {
124
+ return VNEW(cpvmult(*VGET(self), NUM2DBL(s)));
125
+ }
126
+
127
+ static VALUE
128
+ rb_cpVectSDiv(VALUE self, VALUE s)
129
+ {
130
+ cpFloat factor = 1.0f/(float)NUM2DBL(s);
131
+ return VNEW(cpvmult(*VGET(self), factor));
132
+ }
133
+
134
+ static VALUE
135
+ rb_cpVectDot(VALUE self, VALUE v)
136
+ {
137
+ return rb_float_new(cpvdot(*VGET(self), *VGET(v)));
138
+ }
139
+
140
+ static VALUE
141
+ rb_cpVectCross(VALUE self, VALUE v)
142
+ {
143
+ return rb_float_new(cpvcross(*VGET(self), *VGET(v)));
144
+ }
145
+
146
+ static VALUE
147
+ rb_cpVectLength(VALUE self)
148
+ {
149
+ cpVect *v;
150
+ Data_Get_Struct(self, cpVect, v);
151
+ return rb_float_new(cpvlength(*v));
152
+ }
153
+
154
+ static VALUE
155
+ rb_cpVectLengthsq(VALUE self)
156
+ {
157
+ cpVect *v;
158
+ Data_Get_Struct(self, cpVect, v);
159
+ return rb_float_new(cpvlengthsq(*v));
160
+ }
161
+
162
+ static VALUE
163
+ rb_cpVectNorm(VALUE self)
164
+ {
165
+ return VNEW(cpvnormalize(*VGET(self)));
166
+ }
167
+
168
+ static VALUE
169
+ rb_cpVectNormBang(VALUE self)
170
+ {
171
+ cpVect *v = VGET(self);
172
+ *v = cpvnormalize(*v);
173
+ return self;
174
+ }
175
+
176
+ static VALUE
177
+ rb_cpVectPerp(VALUE self)
178
+ {
179
+ return VNEW(cpvperp(*VGET(self)));
180
+ }
181
+
182
+ static VALUE
183
+ rb_cpVectProject(VALUE self, VALUE v)
184
+ {
185
+ return VNEW(cpvproject(*VGET(self), *VGET(v)));
186
+ }
187
+
188
+ static VALUE
189
+ rb_cpVectRotate(VALUE self, VALUE v)
190
+ {
191
+ return VNEW(cpvrotate(*VGET(self), *VGET(v)));
192
+ }
193
+
194
+ static VALUE
195
+ rb_cpVectUnRotate(VALUE self, VALUE v)
196
+ {
197
+ return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
198
+ }
199
+
200
+ static VALUE
201
+ rb_cpVectNear(VALUE self, VALUE v, VALUE d)
202
+ {
203
+ cpFloat dist = NUM2DBL(d);
204
+ cpVect delta = cpvsub(*VGET(self), *VGET(v));
205
+ return (cpvdot(delta, delta) <= dist*dist) ? Qtrue : Qfalse;
206
+ }
207
+
208
+ static VALUE
209
+ rb_vec2(VALUE self, VALUE x, VALUE y)
210
+ {
211
+ return VNEW(cpv(NUM2DBL(x), NUM2DBL(y)));
212
+ }
213
+
214
+ void
215
+ Init_cpVect(void)
216
+ {
217
+ c_cpVect = rb_define_class_under(m_Chipmunk, "Vec2", rb_cObject);
218
+ rb_define_singleton_method(c_cpBB, "for_angle", rb_cpVectForAngle, 1);
219
+
220
+ rb_define_alloc_func(c_cpVect, rb_cpVectAlloc);
221
+ rb_define_method(c_cpVect, "initialize", rb_cpVectInitialize, 2);
222
+
223
+ rb_define_method(c_cpVect, "x", rb_cpVectGetX, 0);
224
+ rb_define_method(c_cpVect, "y", rb_cpVectGetY, 0);
225
+ rb_define_method(c_cpVect, "x=", rb_cpVectSetX, 1);
226
+ rb_define_method(c_cpVect, "y=", rb_cpVectSetY, 1);
227
+
228
+ rb_define_method(c_cpVect, "to_s", rb_cpVectToString, 0);
229
+ rb_define_method(c_cpVect, "to_a", rb_cpVectToArray, 0);
230
+ rb_define_method(c_cpVect, "to_angle", rb_cpVectToAngle, 0);
231
+
232
+ rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
233
+ rb_define_method(c_cpVect, "+", rb_cpVectAdd, 1);
234
+ rb_define_method(c_cpVect, "-", rb_cpVectSub, 1);
235
+ rb_define_method(c_cpVect, "*", rb_cpVectSMult, 1);
236
+ rb_define_method(c_cpVect, "/", rb_cpVectSDiv, 1);
237
+ rb_define_method(c_cpVect, "dot", rb_cpVectDot, 1);
238
+ rb_define_method(c_cpVect, "cross", rb_cpVectCross, 1);
239
+ rb_define_method(c_cpVect, "length", rb_cpVectLength, 0);
240
+ rb_define_method(c_cpVect, "lengthsq", rb_cpVectLengthsq, 0);
241
+ rb_define_method(c_cpVect, "normalize", rb_cpVectNorm, 0);
242
+ rb_define_method(c_cpVect, "normalize!", rb_cpVectNormBang, 0);
243
+ rb_define_method(c_cpVect, "perp", rb_cpVectPerp, 0);
244
+ rb_define_method(c_cpVect, "project", rb_cpVectProject, 1);
245
+ rb_define_method(c_cpVect, "rotate", rb_cpVectRotate, 1);
246
+ rb_define_method(c_cpVect, "unrotate", rb_cpVectUnRotate, 1);
247
+ rb_define_method(c_cpVect, "near?", rb_cpVectNear, 2);
248
+
249
+ rb_define_global_function("vec2", rb_vec2, 2);
250
+ }
data/lib/chipmunk.rb ADDED
@@ -0,0 +1,15 @@
1
+ # this redirection script by John Mair (banisterfiend)
2
+
3
+ require 'rbconfig'
4
+
5
+ direc = File.dirname(__FILE__)
6
+ dlext = Config::CONFIG['DLEXT']
7
+ begin
8
+ if RUBY_VERSION && RUBY_VERSION =~ /1.9/
9
+ require "#{direc}/1.9/chipmunk.#{dlext}"
10
+ else
11
+ require "#{direc}/1.8/chipmunk.#{dlext}"
12
+ end
13
+ rescue LoadError => e
14
+ require "#{direc}/chipmunk.#{dlext}"
15
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chipmunk
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scott Lembcke, Beoran, John Mair (banisterfiend)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-01 00:00:00 +13:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ruby bindings for the chipmunk physics engine
17
+ email: jrmair@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/chipmunk/extconf.rb
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - lib/chipmunk.rb
27
+ - ext/chipmunk/extconf.rb
28
+ - ext/chipmunk/prime.h
29
+ - ext/chipmunk/cpVect.h
30
+ - ext/chipmunk/cpJoint.h
31
+ - ext/chipmunk/cpBB.h
32
+ - ext/chipmunk/rb_chipmunk.h
33
+ - ext/chipmunk/cpBody.h
34
+ - ext/chipmunk/chipmunk.h
35
+ - ext/chipmunk/cpHashSet.h
36
+ - ext/chipmunk/cpShape.h
37
+ - ext/chipmunk/cpSpace.h
38
+ - ext/chipmunk/cpPolyShape.h
39
+ - ext/chipmunk/cpCollision.h
40
+ - ext/chipmunk/cpArray.h
41
+ - ext/chipmunk/cpSpaceHash.h
42
+ - ext/chipmunk/cpArbiter.h
43
+ - ext/chipmunk/cpBB.c
44
+ - ext/chipmunk/cpCollision.c
45
+ - ext/chipmunk/rb_cpBody.c
46
+ - ext/chipmunk/cpArbiter.c
47
+ - ext/chipmunk/cpJoint.c
48
+ - ext/chipmunk/chipmunk.c
49
+ - ext/chipmunk/cpHashSet.c
50
+ - ext/chipmunk/cpSpace.c
51
+ - ext/chipmunk/cpShape.c
52
+ - ext/chipmunk/cpBody.c
53
+ - ext/chipmunk/rb_cpBB.c
54
+ - ext/chipmunk/cpArray.c
55
+ - ext/chipmunk/rb_cpJoint.c
56
+ - ext/chipmunk/rb_cpVect.c
57
+ - ext/chipmunk/rb_cpSpace.c
58
+ - ext/chipmunk/cpSpaceHash.c
59
+ - ext/chipmunk/cpVect.c
60
+ - ext/chipmunk/rb_cpShape.c
61
+ - ext/chipmunk/rb_chipmunk.c
62
+ - ext/chipmunk/cpPolyShape.c
63
+ has_rdoc: true
64
+ homepage: http://code.google.com/p/chipmunk-physics/
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.5
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: ruby bindings for the chipmunk physics engine
91
+ test_files: []
92
+