chipmunk 5.2.2 → 5.3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +21 -19
- data/README +67 -60
- data/Rakefile +85 -50
- data/ext/chipmunk/extconf.rb +42 -35
- data/ext/chipmunk/rb_chipmunk.c +250 -125
- data/ext/chipmunk/rb_chipmunk.h +105 -96
- data/ext/chipmunk/rb_cpArbiter.c +253 -225
- data/ext/chipmunk/rb_cpBB.c +210 -174
- data/ext/chipmunk/rb_cpBody.c +504 -347
- data/ext/chipmunk/rb_cpConstraint.c +336 -346
- data/ext/chipmunk/rb_cpShape.c +433 -455
- data/ext/chipmunk/rb_cpSpace.c +711 -544
- data/ext/chipmunk/rb_cpVect.c +346 -321
- data/lib/chipmunk.rb +183 -30
- metadata +12 -66
- data/ext/chipmunk/chipmunk.c +0 -105
- data/ext/chipmunk/cpArbiter.c +0 -274
- data/ext/chipmunk/cpArray.c +0 -128
- data/ext/chipmunk/cpBB.c +0 -47
- data/ext/chipmunk/cpBody.c +0 -188
- data/ext/chipmunk/cpCollision.c +0 -391
- data/ext/chipmunk/cpConstraint.c +0 -54
- data/ext/chipmunk/cpDampedRotarySpring.c +0 -106
- data/ext/chipmunk/cpDampedSpring.c +0 -117
- data/ext/chipmunk/cpGearJoint.c +0 -114
- data/ext/chipmunk/cpGrooveJoint.c +0 -138
- data/ext/chipmunk/cpHashSet.c +0 -253
- data/ext/chipmunk/cpPinJoint.c +0 -117
- data/ext/chipmunk/cpPivotJoint.c +0 -114
- data/ext/chipmunk/cpPolyShape.c +0 -241
- data/ext/chipmunk/cpRatchetJoint.c +0 -128
- data/ext/chipmunk/cpRotaryLimitJoint.c +0 -122
- data/ext/chipmunk/cpShape.c +0 -400
- data/ext/chipmunk/cpSimpleMotor.c +0 -99
- data/ext/chipmunk/cpSlideJoint.c +0 -131
- data/ext/chipmunk/cpSpace.c +0 -899
- data/ext/chipmunk/cpSpaceHash.c +0 -541
- data/ext/chipmunk/cpVect.c +0 -71
- data/ext/chipmunk/include/chipmunk/chipmunk.h +0 -148
- data/ext/chipmunk/include/chipmunk/chipmunk_ffi.h +0 -42
- data/ext/chipmunk/include/chipmunk/chipmunk_types.h +0 -80
- data/ext/chipmunk/include/chipmunk/chipmunk_unsafe.h +0 -54
- data/ext/chipmunk/include/chipmunk/constraints/cpConstraint.h +0 -92
- data/ext/chipmunk/include/chipmunk/constraints/cpDampedRotarySpring.h +0 -46
- data/ext/chipmunk/include/chipmunk/constraints/cpDampedSpring.h +0 -53
- data/ext/chipmunk/include/chipmunk/constraints/cpGearJoint.h +0 -41
- data/ext/chipmunk/include/chipmunk/constraints/cpGrooveJoint.h +0 -44
- data/ext/chipmunk/include/chipmunk/constraints/cpPinJoint.h +0 -43
- data/ext/chipmunk/include/chipmunk/constraints/cpPivotJoint.h +0 -42
- data/ext/chipmunk/include/chipmunk/constraints/cpRatchetJoint.h +0 -40
- data/ext/chipmunk/include/chipmunk/constraints/cpRotaryLimitJoint.h +0 -39
- data/ext/chipmunk/include/chipmunk/constraints/cpSimpleMotor.h +0 -37
- data/ext/chipmunk/include/chipmunk/constraints/cpSlideJoint.h +0 -44
- data/ext/chipmunk/include/chipmunk/constraints/util.h +0 -116
- data/ext/chipmunk/include/chipmunk/cpArbiter.h +0 -136
- data/ext/chipmunk/include/chipmunk/cpArray.h +0 -46
- data/ext/chipmunk/include/chipmunk/cpBB.h +0 -74
- data/ext/chipmunk/include/chipmunk/cpBody.h +0 -160
- data/ext/chipmunk/include/chipmunk/cpCollision.h +0 -23
- data/ext/chipmunk/include/chipmunk/cpHashSet.h +0 -82
- data/ext/chipmunk/include/chipmunk/cpPolyShape.h +0 -103
- data/ext/chipmunk/include/chipmunk/cpShape.h +0 -174
- data/ext/chipmunk/include/chipmunk/cpSpace.h +0 -180
- data/ext/chipmunk/include/chipmunk/cpSpaceHash.h +0 -109
- data/ext/chipmunk/include/chipmunk/cpVect.h +0 -157
- data/ext/chipmunk/prime.h +0 -68
- data/lib/chipmunk/version.rb +0 -3
data/ext/chipmunk/rb_cpShape.c
CHANGED
@@ -1,455 +1,433 @@
|
|
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
|
-
ID id_body;
|
29
|
-
|
30
|
-
VALUE m_cpShape;
|
31
|
-
VALUE c_cpCircleShape;
|
32
|
-
VALUE c_cpSegmentShape;
|
33
|
-
VALUE c_cpPolyShape;
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
return
|
194
|
-
}
|
195
|
-
|
196
|
-
static VALUE
|
197
|
-
|
198
|
-
{
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
{
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
return
|
227
|
-
}
|
228
|
-
|
229
|
-
static VALUE
|
230
|
-
|
231
|
-
{
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
return
|
241
|
-
}
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
//
|
272
|
-
static VALUE
|
273
|
-
|
274
|
-
{
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
static VALUE
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
rb_define_method(m_cpShape, "
|
377
|
-
|
378
|
-
|
379
|
-
rb_define_method(m_cpShape, "
|
380
|
-
|
381
|
-
|
382
|
-
rb_define_method(m_cpShape, "
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
rb_define_method(
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
rb_define_method(
|
410
|
-
rb_define_method(
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
c_cpSegmentQueryInfo = rb_define_class_under(m_cpShape,
|
436
|
-
"SegmentQueryInfo", rb_cObject);
|
437
|
-
rb_define_alloc_func(c_cpSegmentQueryInfo, rb_cpSegmentQueryInfoAlloc);
|
438
|
-
rb_define_method(c_cpSegmentQueryInfo, "initialize",
|
439
|
-
rb_cpSeqmentQueryInfoInitialize, 3);
|
440
|
-
|
441
|
-
rb_define_method(c_cpSegmentQueryInfo, "shape",
|
442
|
-
rb_cpSeqmentQueryInfoGetShape, 0);
|
443
|
-
rb_define_method(c_cpSegmentQueryInfo, "hit",
|
444
|
-
rb_cpSeqmentQueryInfoGetShape, 0);
|
445
|
-
rb_define_method(c_cpSegmentQueryInfo, "t",
|
446
|
-
rb_cpSeqmentQueryInfoGetT, 0);
|
447
|
-
rb_define_method(c_cpSegmentQueryInfo, "n",
|
448
|
-
rb_cpSeqmentQueryInfoGetN, 0);
|
449
|
-
rb_define_method(c_cpSegmentQueryInfo, "hit_point",
|
450
|
-
rb_cpSeqmentQueryInfoHitPoint, 2);
|
451
|
-
rb_define_method(c_cpSegmentQueryInfo, "hit_distance",
|
452
|
-
rb_cpSeqmentQueryInfoHitDist, 2);
|
453
|
-
|
454
|
-
}
|
455
|
-
|
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
|
+
ID id_body;
|
29
|
+
|
30
|
+
VALUE m_cpShape;
|
31
|
+
VALUE c_cpCircleShape;
|
32
|
+
VALUE c_cpSegmentShape;
|
33
|
+
VALUE c_cpPolyShape;
|
34
|
+
|
35
|
+
VALUE c_cpSegmentQueryInfo;
|
36
|
+
|
37
|
+
//Helper that allocates and initializes a SegmenQueryInfo struct
|
38
|
+
VALUE
|
39
|
+
rb_cpSegmentQueryInfoNew(VALUE shape, VALUE t, VALUE n) {
|
40
|
+
return rb_struct_new(c_cpSegmentQueryInfo, shape, t, n);
|
41
|
+
}
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
static VALUE
|
46
|
+
rb_cpShapeGetBody(VALUE self)
|
47
|
+
{
|
48
|
+
return rb_ivar_get(self, id_body);
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE
|
52
|
+
rb_cpShapeSensorP(VALUE self)
|
53
|
+
{
|
54
|
+
return SHAPE(self)->sensor ? Qtrue : Qfalse;
|
55
|
+
}
|
56
|
+
|
57
|
+
static VALUE
|
58
|
+
rb_cpShapeSetSensor(VALUE self, VALUE sensor)
|
59
|
+
{
|
60
|
+
int sens = (NIL_P(sensor) || (!sensor)) ? 0 : 1;
|
61
|
+
SHAPE(self)->sensor = sens;
|
62
|
+
return sensor;
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE
|
66
|
+
rb_cpShapeSetBody(VALUE self, VALUE body)
|
67
|
+
{
|
68
|
+
SHAPE(self)->body = BODY(body);
|
69
|
+
rb_ivar_set(self, id_body, body);
|
70
|
+
|
71
|
+
return body;
|
72
|
+
}
|
73
|
+
|
74
|
+
static VALUE
|
75
|
+
rb_cpShapeGetCollType(VALUE self)
|
76
|
+
{
|
77
|
+
return rb_iv_get(self, "collType");
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE
|
81
|
+
rb_cpShapeSetCollType(VALUE self, VALUE val)
|
82
|
+
{
|
83
|
+
VALUE col_type = rb_obj_id(val);
|
84
|
+
rb_iv_set(self, "collType", val);
|
85
|
+
SHAPE(self)->collision_type = NUM2UINT(col_type);
|
86
|
+
|
87
|
+
return val;
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE
|
91
|
+
rb_cpShapeGetData(VALUE self)
|
92
|
+
{
|
93
|
+
return rb_iv_get(self, "data");
|
94
|
+
}
|
95
|
+
|
96
|
+
static VALUE
|
97
|
+
rb_cpShapeSetData(VALUE self, VALUE val)
|
98
|
+
{
|
99
|
+
rb_iv_set(self, "data", val);
|
100
|
+
return val;
|
101
|
+
}
|
102
|
+
|
103
|
+
static VALUE
|
104
|
+
rb_cpShapeGetSelf(VALUE self)
|
105
|
+
{
|
106
|
+
return self;
|
107
|
+
}
|
108
|
+
|
109
|
+
|
110
|
+
static VALUE
|
111
|
+
rb_cpShapeGetGroup(VALUE self)
|
112
|
+
{
|
113
|
+
return rb_iv_get(self, "group");
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
rb_cpShapeSetGroup(VALUE self, VALUE val)
|
118
|
+
{
|
119
|
+
VALUE col_type = rb_obj_id(val);
|
120
|
+
rb_iv_set(self, "group", val);
|
121
|
+
SHAPE(self)->group = NUM2UINT(col_type);
|
122
|
+
|
123
|
+
return val;
|
124
|
+
}
|
125
|
+
|
126
|
+
static VALUE
|
127
|
+
rb_cpShapeGetLayers(VALUE self)
|
128
|
+
{
|
129
|
+
return UINT2NUM(SHAPE(self)->layers);
|
130
|
+
}
|
131
|
+
|
132
|
+
static VALUE
|
133
|
+
rb_cpShapeSetLayers(VALUE self, VALUE layers)
|
134
|
+
{
|
135
|
+
SHAPE(self)->layers = NUM2UINT(layers);
|
136
|
+
|
137
|
+
return layers;
|
138
|
+
}
|
139
|
+
|
140
|
+
static VALUE
|
141
|
+
rb_cpShapeGetBB(VALUE self)
|
142
|
+
{
|
143
|
+
cpBB *bb = malloc(sizeof(cpBB));
|
144
|
+
*bb = SHAPE(self)->bb;
|
145
|
+
return Data_Wrap_Struct(c_cpBB, NULL, free, bb);
|
146
|
+
}
|
147
|
+
|
148
|
+
static VALUE
|
149
|
+
rb_cpShapeCacheBB(VALUE self)
|
150
|
+
{
|
151
|
+
cpShape *shape = SHAPE(self);
|
152
|
+
cpShapeCacheBB(shape);
|
153
|
+
|
154
|
+
return rb_cpShapeGetBB(self);
|
155
|
+
}
|
156
|
+
|
157
|
+
static VALUE
|
158
|
+
rb_cpShapeGetElasticity(VALUE self)
|
159
|
+
{
|
160
|
+
return rb_float_new(SHAPE(self)->e);
|
161
|
+
}
|
162
|
+
|
163
|
+
static VALUE
|
164
|
+
rb_cpShapeGetFriction(VALUE self)
|
165
|
+
{
|
166
|
+
return rb_float_new(SHAPE(self)->u);
|
167
|
+
}
|
168
|
+
|
169
|
+
static VALUE
|
170
|
+
rb_cpShapeSetElasticity(VALUE self, VALUE val)
|
171
|
+
{
|
172
|
+
SHAPE(self)->e = NUM2DBL(val);
|
173
|
+
return val;
|
174
|
+
}
|
175
|
+
|
176
|
+
static VALUE
|
177
|
+
rb_cpShapeSetFriction(VALUE self, VALUE val)
|
178
|
+
{
|
179
|
+
SHAPE(self)->u = NUM2DBL(val);
|
180
|
+
return val;
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
rb_cpShapeGetSurfaceV(VALUE self)
|
185
|
+
{
|
186
|
+
return VWRAP(self, &SHAPE(self)->surface_v);
|
187
|
+
}
|
188
|
+
|
189
|
+
static VALUE
|
190
|
+
rb_cpShapeSetSurfaceV(VALUE self, VALUE val)
|
191
|
+
{
|
192
|
+
SHAPE(self)->surface_v = *VGET(val);
|
193
|
+
return val;
|
194
|
+
}
|
195
|
+
|
196
|
+
static VALUE
|
197
|
+
rb_cpShapeResetIdCounter(VALUE self)
|
198
|
+
{
|
199
|
+
cpResetShapeIdCounter();
|
200
|
+
return Qnil;
|
201
|
+
}
|
202
|
+
|
203
|
+
// Test if a point lies within a shape.
|
204
|
+
static VALUE rb_cpShapePointQuery(VALUE self, VALUE point) {
|
205
|
+
cpBool res = cpShapePointQuery(SHAPE(self), *VGET(point));
|
206
|
+
return res ? Qtrue : Qfalse;
|
207
|
+
}
|
208
|
+
|
209
|
+
|
210
|
+
static VALUE rb_cpShapeSegmentQuery(VALUE self, VALUE a, VALUE b) {
|
211
|
+
cpSegmentQueryInfo info;
|
212
|
+
cpShapeSegmentQuery(SHAPE(self), *VGET(a), *VGET(b), &info);
|
213
|
+
if(info.shape) {
|
214
|
+
return rb_cpSegmentQueryInfoNew((VALUE)info.shape->data, rb_float_new(info.t), VNEW(info.n));
|
215
|
+
}
|
216
|
+
return Qnil;
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
//cpCircle
|
222
|
+
static VALUE
|
223
|
+
rb_cpCircleAlloc(VALUE klass)
|
224
|
+
{
|
225
|
+
cpCircleShape *circle = cpCircleShapeAlloc();
|
226
|
+
return Data_Wrap_Struct(klass, NULL, cpShapeFree, circle);
|
227
|
+
}
|
228
|
+
|
229
|
+
static VALUE
|
230
|
+
rb_cpCircleInitialize(VALUE self, VALUE body, VALUE radius, VALUE offset)
|
231
|
+
{
|
232
|
+
cpCircleShape *circle = (cpCircleShape *)SHAPE(self);
|
233
|
+
|
234
|
+
cpCircleShapeInit(circle, BODY(body), NUM2DBL(radius), *VGET(offset));
|
235
|
+
circle->shape.data = (void *)self;
|
236
|
+
circle->shape.collision_type = Qnil;
|
237
|
+
|
238
|
+
rb_ivar_set(self, id_body, body);
|
239
|
+
|
240
|
+
return self;
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
//cpSegment
|
248
|
+
static VALUE
|
249
|
+
rb_cpSegmentAlloc(VALUE klass)
|
250
|
+
{
|
251
|
+
cpSegmentShape *seg = cpSegmentShapeAlloc();
|
252
|
+
return Data_Wrap_Struct(klass, NULL, cpShapeFree, seg);
|
253
|
+
}
|
254
|
+
|
255
|
+
static VALUE
|
256
|
+
rb_cpSegmentInitialize(VALUE self, VALUE body, VALUE a, VALUE b, VALUE r)
|
257
|
+
{
|
258
|
+
cpSegmentShape *seg = (cpSegmentShape *)SHAPE(self);
|
259
|
+
|
260
|
+
cpSegmentShapeInit(seg, BODY(body), *VGET(a), *VGET(b), NUM2DBL(r));
|
261
|
+
seg->shape.data = (void *)self;
|
262
|
+
seg->shape.collision_type = Qnil;
|
263
|
+
|
264
|
+
rb_ivar_set(self, id_body, body);
|
265
|
+
|
266
|
+
return self;
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
//cpPoly
|
272
|
+
static VALUE
|
273
|
+
rb_cpPolyAlloc(VALUE klass)
|
274
|
+
{
|
275
|
+
cpPolyShape *poly = cpPolyShapeAlloc();
|
276
|
+
return Data_Wrap_Struct(klass, NULL, cpShapeFree, poly);
|
277
|
+
}
|
278
|
+
|
279
|
+
static VALUE
|
280
|
+
rb_cpPolyInitialize(VALUE self, VALUE body, VALUE arr, VALUE offset)
|
281
|
+
{
|
282
|
+
cpPolyShape *poly = (cpPolyShape *)SHAPE(self);
|
283
|
+
|
284
|
+
Check_Type(arr, T_ARRAY);
|
285
|
+
int numVerts = RARRAY_LEN(arr);
|
286
|
+
VALUE *ary_ptr = RARRAY_PTR(arr);
|
287
|
+
cpVect verts[numVerts];
|
288
|
+
|
289
|
+
for(int i=0; i<numVerts; i++)
|
290
|
+
verts[i] = *VGET(ary_ptr[i]);
|
291
|
+
|
292
|
+
cpPolyShapeInit(poly, BODY(body), numVerts, verts, *VGET(offset));
|
293
|
+
poly->shape.data = (void *)self;
|
294
|
+
poly->shape.collision_type = Qnil;
|
295
|
+
|
296
|
+
rb_ivar_set(self, id_body, body);
|
297
|
+
|
298
|
+
return self;
|
299
|
+
}
|
300
|
+
|
301
|
+
// some getters
|
302
|
+
static VALUE rb_cpCircleShapeGetOffset(VALUE self) {
|
303
|
+
return VNEW(cpCircleShapeGetOffset(SHAPE(self)));
|
304
|
+
}
|
305
|
+
|
306
|
+
static VALUE rb_cpCircleShapeGetRadius(VALUE self) {
|
307
|
+
return rb_float_new(cpCircleShapeGetRadius(SHAPE(self)));
|
308
|
+
}
|
309
|
+
|
310
|
+
static VALUE rb_cpSegmentShapeGetA(VALUE self) {
|
311
|
+
return VNEW(cpSegmentShapeGetA(SHAPE(self)));
|
312
|
+
}
|
313
|
+
|
314
|
+
static VALUE rb_cpSegmentShapeGetB(VALUE self) {
|
315
|
+
return VNEW(cpSegmentShapeGetB(SHAPE(self)));
|
316
|
+
}
|
317
|
+
|
318
|
+
static VALUE rb_cpSegmentShapeGetRadius(VALUE self) {
|
319
|
+
return rb_float_new(cpSegmentShapeGetRadius(SHAPE(self)));
|
320
|
+
}
|
321
|
+
|
322
|
+
static VALUE rb_cpSegmentShapeGetNormal(VALUE self) {
|
323
|
+
return VNEW(cpSegmentShapeGetNormal(SHAPE(self)));
|
324
|
+
}
|
325
|
+
|
326
|
+
static VALUE rb_cpPolyShapeGetNumVerts(VALUE self) {
|
327
|
+
return INT2NUM(cpPolyShapeGetNumVerts(SHAPE(self)));
|
328
|
+
}
|
329
|
+
|
330
|
+
static VALUE rb_cpPolyShapeGetVert(VALUE self, VALUE vindex) {
|
331
|
+
cpShape *shape = SHAPE(self);
|
332
|
+
int index = NUM2INT(vindex);
|
333
|
+
if ((index < 0) || (index >= cpPolyShapeGetNumVerts(shape))) {
|
334
|
+
return Qnil;
|
335
|
+
}
|
336
|
+
return VNEW(cpPolyShapeGetVert(shape, index));
|
337
|
+
}
|
338
|
+
|
339
|
+
|
340
|
+
void
|
341
|
+
Init_cpShape(void)
|
342
|
+
{
|
343
|
+
id_body = rb_intern("body");
|
344
|
+
|
345
|
+
m_cpShape = rb_define_module_under(m_Chipmunk, "Shape");
|
346
|
+
rb_define_attr(m_cpShape, "obj", 1, 1);
|
347
|
+
|
348
|
+
rb_define_method(m_cpShape, "body", rb_cpShapeGetBody, 0);
|
349
|
+
rb_define_method(m_cpShape, "body=", rb_cpShapeSetBody, 1);
|
350
|
+
|
351
|
+
rb_define_method(m_cpShape, "sensor?", rb_cpShapeSensorP, 0);
|
352
|
+
rb_define_method(m_cpShape, "sensor=", rb_cpShapeSetSensor, 1);
|
353
|
+
|
354
|
+
|
355
|
+
rb_define_method(m_cpShape, "collision_type", rb_cpShapeGetCollType, 0);
|
356
|
+
rb_define_method(m_cpShape, "collision_type=", rb_cpShapeSetCollType, 1);
|
357
|
+
|
358
|
+
// this method only exists for Chipmunk-FFI compatibility as it seems useless
|
359
|
+
// to me.
|
360
|
+
rb_define_method(m_cpShape, "data", rb_cpShapeGetSelf, 0);
|
361
|
+
// So we use this as the object setter
|
362
|
+
rb_define_method(m_cpShape, "object" , rb_cpShapeGetData, 0);
|
363
|
+
rb_define_method(m_cpShape, "object=", rb_cpShapeSetData, 1);
|
364
|
+
|
365
|
+
rb_define_method(m_cpShape, "group", rb_cpShapeGetGroup, 0);
|
366
|
+
rb_define_method(m_cpShape, "group=", rb_cpShapeSetGroup, 1);
|
367
|
+
|
368
|
+
rb_define_method(m_cpShape, "layers", rb_cpShapeGetLayers, 0);
|
369
|
+
rb_define_method(m_cpShape, "layers=", rb_cpShapeSetLayers, 1);
|
370
|
+
|
371
|
+
rb_define_method(m_cpShape, "bb" , rb_cpShapeCacheBB, 0);
|
372
|
+
rb_define_method(m_cpShape, "cache_bb" , rb_cpShapeCacheBB, 0);
|
373
|
+
rb_define_method(m_cpShape, "raw_bb" , rb_cpShapeGetBB, 0);
|
374
|
+
|
375
|
+
rb_define_method(m_cpShape, "e", rb_cpShapeGetElasticity, 0);
|
376
|
+
rb_define_method(m_cpShape, "u", rb_cpShapeGetFriction, 0);
|
377
|
+
|
378
|
+
rb_define_method(m_cpShape, "e=", rb_cpShapeSetElasticity, 1);
|
379
|
+
rb_define_method(m_cpShape, "u=", rb_cpShapeSetFriction, 1);
|
380
|
+
|
381
|
+
rb_define_method(m_cpShape, "surface_v", rb_cpShapeGetSurfaceV, 0);
|
382
|
+
rb_define_method(m_cpShape, "surface_v=", rb_cpShapeSetSurfaceV, 1);
|
383
|
+
|
384
|
+
rb_define_method(m_cpShape, "point_query", rb_cpShapePointQuery, 1);
|
385
|
+
rb_define_method(m_cpShape, "segment_query", rb_cpShapeSegmentQuery, 2);
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
rb_define_singleton_method(m_cpShape, "reset_id_counter", rb_cpShapeResetIdCounter, 0);
|
390
|
+
|
391
|
+
|
392
|
+
c_cpCircleShape = rb_define_class_under(m_cpShape, "Circle", rb_cObject);
|
393
|
+
rb_include_module(c_cpCircleShape, m_cpShape);
|
394
|
+
rb_define_alloc_func(c_cpCircleShape, rb_cpCircleAlloc);
|
395
|
+
rb_define_method(c_cpCircleShape, "initialize", rb_cpCircleInitialize, 3);
|
396
|
+
|
397
|
+
|
398
|
+
c_cpSegmentShape = rb_define_class_under(m_cpShape, "Segment", rb_cObject);
|
399
|
+
rb_include_module(c_cpSegmentShape, m_cpShape);
|
400
|
+
rb_define_alloc_func(c_cpSegmentShape, rb_cpSegmentAlloc);
|
401
|
+
rb_define_method(c_cpSegmentShape, "initialize", rb_cpSegmentInitialize, 4);
|
402
|
+
|
403
|
+
|
404
|
+
c_cpPolyShape = rb_define_class_under(m_cpShape, "Poly", rb_cObject);
|
405
|
+
rb_include_module(c_cpPolyShape, m_cpShape);
|
406
|
+
rb_define_alloc_func(c_cpPolyShape, rb_cpPolyAlloc);
|
407
|
+
rb_define_method(c_cpPolyShape, "initialize", rb_cpPolyInitialize, 3);
|
408
|
+
|
409
|
+
rb_define_method(c_cpCircleShape, "offset", rb_cpCircleShapeGetOffset, 0);
|
410
|
+
rb_define_method(c_cpCircleShape, "radius", rb_cpCircleShapeGetRadius, 0);
|
411
|
+
rb_define_method(c_cpCircleShape, "r" , rb_cpCircleShapeGetRadius, 0);
|
412
|
+
|
413
|
+
rb_define_method(c_cpSegmentShape, "a" , rb_cpSegmentShapeGetA, 0);
|
414
|
+
rb_define_method(c_cpSegmentShape, "b" , rb_cpSegmentShapeGetB, 0);
|
415
|
+
rb_define_method(c_cpSegmentShape, "radius" , rb_cpSegmentShapeGetRadius, 0);
|
416
|
+
rb_define_method(c_cpSegmentShape, "r" , rb_cpSegmentShapeGetRadius, 0);
|
417
|
+
rb_define_method(c_cpSegmentShape, "normal" , rb_cpSegmentShapeGetNormal, 0);
|
418
|
+
rb_define_method(c_cpSegmentShape, "n" , rb_cpSegmentShapeGetNormal, 0);
|
419
|
+
|
420
|
+
rb_define_method(c_cpPolyShape , "num_verts" , rb_cpPolyShapeGetNumVerts, 0);
|
421
|
+
rb_define_method(c_cpPolyShape , "vert" , rb_cpPolyShapeGetVert, 1);
|
422
|
+
// also include an array-ish interface
|
423
|
+
rb_define_method(c_cpPolyShape , "length" , rb_cpPolyShapeGetNumVerts, 0);
|
424
|
+
rb_define_method(c_cpPolyShape , "size" , rb_cpPolyShapeGetNumVerts, 0);
|
425
|
+
rb_define_method(c_cpPolyShape , "[]" , rb_cpPolyShapeGetVert, 1);
|
426
|
+
|
427
|
+
/* Use a struct for this small class. More efficient. */
|
428
|
+
c_cpSegmentQueryInfo = rb_struct_define("SegmentQueryInfo",
|
429
|
+
"shape", "t", "n", NULL);
|
430
|
+
rb_define_const(m_Chipmunk, "SegmentQueryInfo", c_cpSegmentQueryInfo);
|
431
|
+
|
432
|
+
}
|
433
|
+
//
|