chipmunk 5.3.4.0-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README +70 -0
- data/Rakefile +86 -0
- data/ext/chipmunk/extconf.rb +42 -0
- data/ext/chipmunk/rb_chipmunk.c +250 -0
- data/ext/chipmunk/rb_chipmunk.h +105 -0
- data/ext/chipmunk/rb_cpArbiter.c +253 -0
- data/ext/chipmunk/rb_cpBB.c +210 -0
- data/ext/chipmunk/rb_cpBody.c +504 -0
- data/ext/chipmunk/rb_cpConstraint.c +336 -0
- data/ext/chipmunk/rb_cpShape.c +450 -0
- data/ext/chipmunk/rb_cpSpace.c +711 -0
- data/ext/chipmunk/rb_cpVect.c +346 -0
- data/lib/1.8/chipmunk.so +0 -0
- data/lib/1.9/chipmunk.so +0 -0
- data/lib/chipmunk.rb +183 -0
- metadata +83 -0
@@ -0,0 +1,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 c_cpVect;
|
29
|
+
|
30
|
+
static VALUE
|
31
|
+
rb_cpVectForAngle(VALUE self, VALUE angle)
|
32
|
+
{
|
33
|
+
return VNEW(cpvforangle(NUM2DBL(angle)));
|
34
|
+
}
|
35
|
+
|
36
|
+
static VALUE
|
37
|
+
rb_cpVectAlloc(VALUE klass)
|
38
|
+
{
|
39
|
+
cpVect *v = malloc(sizeof(cpVect));
|
40
|
+
return Data_Wrap_Struct(klass, NULL, free, v);
|
41
|
+
}
|
42
|
+
|
43
|
+
static VALUE
|
44
|
+
rb_cpVectInitialize(VALUE self, VALUE x, VALUE y)
|
45
|
+
{
|
46
|
+
cpVect *v = VGET(self);
|
47
|
+
v->x = NUM2DBL(x);
|
48
|
+
v->y = NUM2DBL(y);
|
49
|
+
|
50
|
+
return self;
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE
|
54
|
+
rb_cpVectGetX(VALUE self)
|
55
|
+
{
|
56
|
+
return rb_float_new(VGET(self)->x);
|
57
|
+
}
|
58
|
+
|
59
|
+
static VALUE
|
60
|
+
rb_cpVectGetY(VALUE self)
|
61
|
+
{
|
62
|
+
return rb_float_new(VGET(self)->y);
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE
|
66
|
+
rb_cpVectSetX(VALUE self, VALUE x)
|
67
|
+
{
|
68
|
+
VGET(self)->x = NUM2DBL(x);
|
69
|
+
return self;
|
70
|
+
}
|
71
|
+
|
72
|
+
static VALUE
|
73
|
+
rb_cpVectSetY(VALUE self, VALUE y)
|
74
|
+
{
|
75
|
+
VGET(self)->y = NUM2DBL(y);
|
76
|
+
return self;
|
77
|
+
}
|
78
|
+
|
79
|
+
static VALUE
|
80
|
+
rb_cpVectToString(VALUE self)
|
81
|
+
{
|
82
|
+
char str[256];
|
83
|
+
cpVect *v = VGET(self);
|
84
|
+
|
85
|
+
sprintf(str, "(% .3f, % .3f)", v->x, v->y);
|
86
|
+
|
87
|
+
return rb_str_new2(str);
|
88
|
+
}
|
89
|
+
|
90
|
+
static VALUE
|
91
|
+
rb_cpVectToArray(VALUE self)
|
92
|
+
{
|
93
|
+
cpVect *v = VGET(self);
|
94
|
+
return rb_ary_new3(2, rb_float_new(v->x), rb_float_new(v->y));
|
95
|
+
}
|
96
|
+
|
97
|
+
static VALUE
|
98
|
+
rb_cpVectToAngle(VALUE self)
|
99
|
+
{
|
100
|
+
return rb_float_new(cpvtoangle(*VGET(self)));
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
static VALUE
|
105
|
+
rb_cpVectNegate(VALUE self)
|
106
|
+
{
|
107
|
+
return VNEW(cpvneg(*VGET(self)));
|
108
|
+
}
|
109
|
+
|
110
|
+
static VALUE
|
111
|
+
rb_cpVectAdd(VALUE self, VALUE v)
|
112
|
+
{
|
113
|
+
return VNEW(cpvadd(*VGET(self), *VGET(v)));
|
114
|
+
}
|
115
|
+
|
116
|
+
static VALUE
|
117
|
+
rb_cpVectSub(VALUE self, VALUE v)
|
118
|
+
{
|
119
|
+
return VNEW(cpvsub(*VGET(self), *VGET(v)));
|
120
|
+
}
|
121
|
+
|
122
|
+
static VALUE
|
123
|
+
rb_cpVectSMult(VALUE self, VALUE s)
|
124
|
+
{
|
125
|
+
return VNEW(cpvmult(*VGET(self), NUM2DBL(s)));
|
126
|
+
}
|
127
|
+
|
128
|
+
static VALUE
|
129
|
+
rb_cpVectSDiv(VALUE self, VALUE s)
|
130
|
+
{
|
131
|
+
cpFloat factor = 1.0f/(float)NUM2DBL(s);
|
132
|
+
return VNEW(cpvmult(*VGET(self), factor));
|
133
|
+
}
|
134
|
+
|
135
|
+
static VALUE
|
136
|
+
rb_cpVectDot(VALUE self, VALUE v)
|
137
|
+
{
|
138
|
+
return rb_float_new(cpvdot(*VGET(self), *VGET(v)));
|
139
|
+
}
|
140
|
+
|
141
|
+
static VALUE
|
142
|
+
rb_cpVectCross(VALUE self, VALUE v)
|
143
|
+
{
|
144
|
+
return rb_float_new(cpvcross(*VGET(self), *VGET(v)));
|
145
|
+
}
|
146
|
+
|
147
|
+
static VALUE
|
148
|
+
rb_cpVectLength(VALUE self)
|
149
|
+
{
|
150
|
+
cpVect *v;
|
151
|
+
Data_Get_Struct(self, cpVect, v);
|
152
|
+
return rb_float_new(cpvlength(*v));
|
153
|
+
}
|
154
|
+
|
155
|
+
static VALUE
|
156
|
+
rb_cpVectLengthsq(VALUE self)
|
157
|
+
{
|
158
|
+
cpVect *v;
|
159
|
+
Data_Get_Struct(self, cpVect, v);
|
160
|
+
return rb_float_new(cpvlengthsq(*v));
|
161
|
+
}
|
162
|
+
|
163
|
+
static VALUE
|
164
|
+
rb_cpVectNorm(VALUE self)
|
165
|
+
{
|
166
|
+
return VNEW(cpvnormalize(*VGET(self)));
|
167
|
+
}
|
168
|
+
|
169
|
+
static VALUE
|
170
|
+
rb_cpVectNormBang(VALUE self)
|
171
|
+
{
|
172
|
+
cpVect *v = VGET(self);
|
173
|
+
*v = cpvnormalize(*v);
|
174
|
+
return self;
|
175
|
+
}
|
176
|
+
|
177
|
+
static VALUE
|
178
|
+
rb_cpVectNormSafe(VALUE self)
|
179
|
+
{
|
180
|
+
return VNEW(cpvnormalize_safe(*VGET(self)));
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
rb_cpVectNormSafeBang(VALUE self)
|
185
|
+
{
|
186
|
+
cpVect *v = VGET(self);
|
187
|
+
*v = cpvnormalize_safe(*v);
|
188
|
+
return self;
|
189
|
+
}
|
190
|
+
|
191
|
+
static VALUE
|
192
|
+
rb_cpVectPerp(VALUE self)
|
193
|
+
{
|
194
|
+
return VNEW(cpvperp(*VGET(self)));
|
195
|
+
}
|
196
|
+
|
197
|
+
static VALUE
|
198
|
+
rb_cpVectRperp(VALUE self)
|
199
|
+
{
|
200
|
+
return VNEW(cpvrperp(*VGET(self)));
|
201
|
+
}
|
202
|
+
|
203
|
+
static VALUE
|
204
|
+
rb_cpVectLerp(VALUE self, VALUE v, VALUE d)
|
205
|
+
{
|
206
|
+
cpFloat df = NUM2DBL(d);
|
207
|
+
return VNEW(cpvlerp(*VGET(self), *VGET(v), df));
|
208
|
+
}
|
209
|
+
|
210
|
+
static VALUE
|
211
|
+
rb_cpVectLerpconst(VALUE self, VALUE v, VALUE d)
|
212
|
+
{
|
213
|
+
cpFloat df = (cpFloat) NUM2DBL(d);
|
214
|
+
return VNEW(cpvlerpconst(*VGET(self), *VGET(v), df));
|
215
|
+
}
|
216
|
+
|
217
|
+
static VALUE
|
218
|
+
rb_cpVectSlerp(VALUE self, VALUE v, VALUE d)
|
219
|
+
{
|
220
|
+
cpFloat df = (cpFloat) NUM2DBL(d);
|
221
|
+
return VNEW(cpvslerp(*VGET(self), *VGET(v), df));
|
222
|
+
}
|
223
|
+
|
224
|
+
static VALUE
|
225
|
+
rb_cpVectSlerpconst(VALUE self, VALUE v, VALUE d)
|
226
|
+
{
|
227
|
+
cpFloat df = (cpFloat) NUM2DBL(d);
|
228
|
+
return VNEW(cpvslerpconst(*VGET(self), *VGET(v), df));
|
229
|
+
}
|
230
|
+
|
231
|
+
static VALUE
|
232
|
+
rb_cpVectProject(VALUE self, VALUE v)
|
233
|
+
{
|
234
|
+
return VNEW(cpvproject(*VGET(self), *VGET(v)));
|
235
|
+
}
|
236
|
+
|
237
|
+
static VALUE
|
238
|
+
rb_cpVectRotate(VALUE self, VALUE v)
|
239
|
+
{
|
240
|
+
return VNEW(cpvrotate(*VGET(self), *VGET(v)));
|
241
|
+
}
|
242
|
+
|
243
|
+
static VALUE
|
244
|
+
rb_cpVectUnRotate(VALUE self, VALUE v)
|
245
|
+
{
|
246
|
+
return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
|
247
|
+
}
|
248
|
+
|
249
|
+
static VALUE
|
250
|
+
rb_cpVectDist(VALUE self, VALUE v)
|
251
|
+
{
|
252
|
+
return rb_float_new(cpvdist(*VGET(self), *VGET(v)));
|
253
|
+
}
|
254
|
+
|
255
|
+
static VALUE
|
256
|
+
rb_cpVectDistsq(VALUE self, VALUE v)
|
257
|
+
{
|
258
|
+
return rb_float_new(cpvdistsq(*VGET(self), *VGET(v)));
|
259
|
+
}
|
260
|
+
|
261
|
+
static VALUE
|
262
|
+
rb_cpVectClamp(VALUE self, VALUE len)
|
263
|
+
{
|
264
|
+
return VNEW(cpvclamp(*VGET(self), NUM2DBL(len)));
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
static VALUE
|
269
|
+
rb_cpVectNear(VALUE self, VALUE v, VALUE d)
|
270
|
+
{
|
271
|
+
cpFloat dist = NUM2DBL(d);
|
272
|
+
cpVect delta = cpvsub(*VGET(self), *VGET(v));
|
273
|
+
return (cpvdot(delta, delta) <= dist*dist) ? Qtrue : Qfalse;
|
274
|
+
}
|
275
|
+
|
276
|
+
static VALUE
|
277
|
+
rb_cpVectEql(VALUE self, VALUE other)
|
278
|
+
{
|
279
|
+
return cpveql(*VGET(self), *VGET(other)) ? Qtrue : Qfalse;
|
280
|
+
}
|
281
|
+
|
282
|
+
// the usefulness of unary plus is debatable, but I'll include it for consistency.
|
283
|
+
static VALUE rb_cpVectUnaryplus(VALUE self) {
|
284
|
+
return self;
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
static VALUE
|
289
|
+
rb_vec2(VALUE self, VALUE x, VALUE y)
|
290
|
+
{
|
291
|
+
return VNEW(cpv(NUM2DBL(x), NUM2DBL(y)));
|
292
|
+
}
|
293
|
+
|
294
|
+
void
|
295
|
+
Init_cpVect(void)
|
296
|
+
{
|
297
|
+
c_cpVect = rb_define_class_under(m_Chipmunk, "Vec2", rb_cObject);
|
298
|
+
rb_define_singleton_method(c_cpVect, "for_angle", rb_cpVectForAngle, 1);
|
299
|
+
|
300
|
+
rb_define_alloc_func(c_cpVect, rb_cpVectAlloc);
|
301
|
+
rb_define_method(c_cpVect, "initialize", rb_cpVectInitialize, 2);
|
302
|
+
|
303
|
+
rb_define_method(c_cpVect, "x", rb_cpVectGetX, 0);
|
304
|
+
rb_define_method(c_cpVect, "y", rb_cpVectGetY, 0);
|
305
|
+
rb_define_method(c_cpVect, "x=", rb_cpVectSetX, 1);
|
306
|
+
rb_define_method(c_cpVect, "y=", rb_cpVectSetY, 1);
|
307
|
+
|
308
|
+
rb_define_method(c_cpVect, "to_s", rb_cpVectToString, 0);
|
309
|
+
rb_define_method(c_cpVect, "to_a", rb_cpVectToArray, 0);
|
310
|
+
rb_define_method(c_cpVect, "to_angle", rb_cpVectToAngle, 0);
|
311
|
+
|
312
|
+
rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
|
313
|
+
rb_define_method(c_cpVect, "+@", rb_cpVectUnaryplus, 0);
|
314
|
+
rb_define_method(c_cpVect, "+", rb_cpVectAdd, 1);
|
315
|
+
rb_define_method(c_cpVect, "-", rb_cpVectSub, 1);
|
316
|
+
rb_define_method(c_cpVect, "*", rb_cpVectSMult, 1);
|
317
|
+
rb_define_method(c_cpVect, "/", rb_cpVectSDiv, 1);
|
318
|
+
rb_define_method(c_cpVect, "dot", rb_cpVectDot, 1);
|
319
|
+
rb_define_method(c_cpVect, "cross", rb_cpVectCross, 1);
|
320
|
+
rb_define_method(c_cpVect, "length", rb_cpVectLength, 0);
|
321
|
+
rb_define_method(c_cpVect, "lengthsq", rb_cpVectLengthsq, 0);
|
322
|
+
rb_define_method(c_cpVect, "normalize", rb_cpVectNorm, 0);
|
323
|
+
rb_define_method(c_cpVect, "normalize!", rb_cpVectNormBang, 0);
|
324
|
+
rb_define_method(c_cpVect, "normalize_safe", rb_cpVectNormSafe, 0);
|
325
|
+
rb_define_method(c_cpVect, "normalize_safe!", rb_cpVectNormSafeBang, 0);
|
326
|
+
rb_define_method(c_cpVect, "perp", rb_cpVectPerp, 0);
|
327
|
+
rb_define_method(c_cpVect, "rperp", rb_cpVectRperp, 0);
|
328
|
+
rb_define_method(c_cpVect, "lerp", rb_cpVectLerp, 2);
|
329
|
+
rb_define_method(c_cpVect, "lerpconst", rb_cpVectLerpconst, 2);
|
330
|
+
rb_define_method(c_cpVect, "slerp", rb_cpVectSlerp, 2);
|
331
|
+
rb_define_method(c_cpVect, "slerpconst", rb_cpVectSlerpconst, 2);
|
332
|
+
|
333
|
+
rb_define_method(c_cpVect, "project", rb_cpVectProject, 1);
|
334
|
+
rb_define_method(c_cpVect, "rotate", rb_cpVectRotate, 1);
|
335
|
+
rb_define_method(c_cpVect, "unrotate", rb_cpVectUnRotate, 1);
|
336
|
+
rb_define_method(c_cpVect, "near?", rb_cpVectNear, 2);
|
337
|
+
|
338
|
+
rb_define_method(c_cpVect, "dist", rb_cpVectDist, 1);
|
339
|
+
rb_define_method(c_cpVect, "distsq", rb_cpVectDistsq, 1);
|
340
|
+
|
341
|
+
rb_define_method(c_cpVect, "==", rb_cpVectEql, 1);
|
342
|
+
rb_define_method(c_cpVect, "clamp", rb_cpVectClamp, 1);
|
343
|
+
|
344
|
+
|
345
|
+
rb_define_global_function("vec2", rb_vec2, 2);
|
346
|
+
}
|
data/lib/1.8/chipmunk.so
ADDED
Binary file
|
data/lib/1.9/chipmunk.so
ADDED
Binary file
|
data/lib/chipmunk.rb
ADDED
@@ -0,0 +1,183 @@
|
|
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
|
16
|
+
|
17
|
+
# Add some constants to CP here, so we don't need
|
18
|
+
# to do it in the C code.
|
19
|
+
# Let's cheat a bit here.. :p
|
20
|
+
|
21
|
+
module CP
|
22
|
+
VERSION = '5.4.3'
|
23
|
+
ZERO_VEC_2 = Vec2.new(0,0).freeze
|
24
|
+
ALL_ONES = Vec2.new(1,1).freeze
|
25
|
+
end
|
26
|
+
|
27
|
+
# Extra functionality added by Slembkce and Beoran.
|
28
|
+
|
29
|
+
module CP
|
30
|
+
# Chipmunk Object
|
31
|
+
# Makes it easier to manage complex objects that reference many primitive Chipmunk objects such as bodies shapes and constraints.
|
32
|
+
# New composite objects simply need to include CP::Object and call #init_chipmunk_object(*objects) with the
|
33
|
+
# composite and primitive Chipmunk objects that make up itself.
|
34
|
+
module Object
|
35
|
+
# Returns the list of primitive Chipmunk objects (bodies, shapes and constraints)
|
36
|
+
# that this composite object references directly and indirectly.
|
37
|
+
def chipmunk_objects
|
38
|
+
if @chipmunk_objects
|
39
|
+
return @chipmunk_objects
|
40
|
+
else
|
41
|
+
raise "This CP::Object (#{self.class}) did not call #init_chipmunk_object."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
# Should be called during initialization of a CP::Object to set what primitive
|
47
|
+
# and composite Chipmunk objects this object references.
|
48
|
+
def init_chipmunk_object(*objs)
|
49
|
+
bad_objs = objs.reject{|obj| obj.is_a?(CP::Object)}
|
50
|
+
raise(ArgumentError, "The following objects: #{bad_objs.inspect} are not CP::Objects") unless bad_objs.empty?
|
51
|
+
|
52
|
+
@chipmunk_objects = objs.inject([]){|sum, obj| sum + obj.chipmunk_objects}.uniq
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class Body
|
57
|
+
include CP::Object
|
58
|
+
|
59
|
+
def chipmunk_objects
|
60
|
+
[self]
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_to_space(space)
|
64
|
+
space.add_body(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
def remove_from_space(space)
|
68
|
+
space.remove_body(self)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
module Shape
|
74
|
+
include CP::Object
|
75
|
+
|
76
|
+
def chipmunk_objects
|
77
|
+
[self]
|
78
|
+
end
|
79
|
+
|
80
|
+
def add_to_space(space)
|
81
|
+
space.add_shape(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
def remove_from_space(space)
|
85
|
+
space.remove_shape(self)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
module Constraint
|
90
|
+
include CP::Object
|
91
|
+
|
92
|
+
def chipmunk_objects
|
93
|
+
[self]
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_to_space(space)
|
97
|
+
space.add_constraint(self)
|
98
|
+
end
|
99
|
+
|
100
|
+
def remove_from_space(space)
|
101
|
+
space.remove_constraint(self)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class Space
|
106
|
+
def add_object(obj)
|
107
|
+
obj.chipmunk_objects.each{|elt| elt.add_to_space(self)}
|
108
|
+
end
|
109
|
+
|
110
|
+
def add_objects(*objs)
|
111
|
+
objs.each{|obj| add_object(obj)}
|
112
|
+
end
|
113
|
+
|
114
|
+
def remove_object(obj)
|
115
|
+
obj.chipmunk_objects.each{|elt| elt.remove_from_space(self)}
|
116
|
+
end
|
117
|
+
|
118
|
+
def remove_objects(*objs)
|
119
|
+
objs.each{|obj| remove_object(obj)}
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
class Vec2
|
125
|
+
ZERO = Vec2.new(0,0).freeze
|
126
|
+
end
|
127
|
+
|
128
|
+
# define the helpers here( easier than in the extension.
|
129
|
+
class SegmentQueryInfo
|
130
|
+
def hit_point(start, stop)
|
131
|
+
return start.lerp(stop, self.t)
|
132
|
+
end
|
133
|
+
|
134
|
+
def hit_dist(start, stop)
|
135
|
+
return start.dist(stop) * self.t
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
# Create derived static objects that know to add themselves as static.
|
144
|
+
module CP
|
145
|
+
class StaticBody < Body
|
146
|
+
def initialize
|
147
|
+
super(Float::INFINITY, Float::INFINITY)
|
148
|
+
end
|
149
|
+
|
150
|
+
def chipmunk_objects
|
151
|
+
# return [] instead of [self] so the static body will not be added.
|
152
|
+
[]
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
module StaticShape
|
157
|
+
include Shape
|
158
|
+
|
159
|
+
class Circle < Shape::Circle
|
160
|
+
include StaticShape
|
161
|
+
end
|
162
|
+
|
163
|
+
class Segment < Shape::Segment
|
164
|
+
include StaticShape
|
165
|
+
end
|
166
|
+
|
167
|
+
class Poly < Shape::Poly
|
168
|
+
include StaticShape
|
169
|
+
end
|
170
|
+
|
171
|
+
def add_to_space(space)
|
172
|
+
space.add_static_shape(self)
|
173
|
+
end
|
174
|
+
|
175
|
+
def remove_from_space(space)
|
176
|
+
space.remove_static_shape(self)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
|