chipmunk 4.1.0-x86-mswin32 → 5.3.4.0-x86-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/{ext/chipmunk/cpCollision.h → LICENSE} +4 -5
  2. data/README +67 -0
  3. data/Rakefile +76 -29
  4. data/ext/chipmunk/extconf.rb +38 -0
  5. data/ext/chipmunk/rb_chipmunk.c +162 -21
  6. data/ext/chipmunk/rb_chipmunk.h +39 -11
  7. data/ext/chipmunk/rb_cpArbiter.c +253 -0
  8. data/ext/chipmunk/rb_cpBB.c +60 -4
  9. data/ext/chipmunk/rb_cpBody.c +282 -17
  10. data/ext/chipmunk/rb_cpConstraint.c +336 -0
  11. data/ext/chipmunk/rb_cpShape.c +145 -4
  12. data/ext/chipmunk/rb_cpSpace.c +438 -57
  13. data/ext/chipmunk/rb_cpVect.c +98 -2
  14. data/lib/1.8/chipmunk.so +0 -0
  15. data/lib/1.9/chipmunk.so +0 -0
  16. data/lib/chipmunk.rb +168 -0
  17. metadata +29 -41
  18. data/ext/chipmunk/chipmunk.c +0 -69
  19. data/ext/chipmunk/chipmunk.h +0 -91
  20. data/ext/chipmunk/cpArbiter.c +0 -263
  21. data/ext/chipmunk/cpArbiter.h +0 -85
  22. data/ext/chipmunk/cpArray.c +0 -114
  23. data/ext/chipmunk/cpArray.h +0 -45
  24. data/ext/chipmunk/cpBB.c +0 -46
  25. data/ext/chipmunk/cpBB.h +0 -53
  26. data/ext/chipmunk/cpBody.c +0 -180
  27. data/ext/chipmunk/cpBody.h +0 -132
  28. data/ext/chipmunk/cpCollision.c +0 -390
  29. data/ext/chipmunk/cpHashSet.c +0 -219
  30. data/ext/chipmunk/cpHashSet.h +0 -79
  31. data/ext/chipmunk/cpJoint.c +0 -553
  32. data/ext/chipmunk/cpJoint.h +0 -122
  33. data/ext/chipmunk/cpPolyShape.c +0 -139
  34. data/ext/chipmunk/cpPolyShape.h +0 -92
  35. data/ext/chipmunk/cpShape.c +0 -244
  36. data/ext/chipmunk/cpShape.h +0 -141
  37. data/ext/chipmunk/cpSpace.c +0 -530
  38. data/ext/chipmunk/cpSpace.h +0 -120
  39. data/ext/chipmunk/cpSpaceHash.c +0 -455
  40. data/ext/chipmunk/cpSpaceHash.h +0 -100
  41. data/ext/chipmunk/cpVect.c +0 -63
  42. data/ext/chipmunk/cpVect.h +0 -106
  43. data/ext/chipmunk/prime.h +0 -68
  44. data/ext/chipmunk/rb_cpJoint.c +0 -136
@@ -19,6 +19,7 @@
19
19
  * SOFTWARE.
20
20
  */
21
21
 
22
+ #include <stdlib.h>
22
23
  #include "chipmunk.h"
23
24
 
24
25
  #include "ruby.h"
@@ -173,12 +174,60 @@ rb_cpVectNormBang(VALUE self)
173
174
  return self;
174
175
  }
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
+
176
191
  static VALUE
177
192
  rb_cpVectPerp(VALUE self)
178
193
  {
179
194
  return VNEW(cpvperp(*VGET(self)));
180
195
  }
181
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 = 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 = 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 = NUM2DBL(d);
228
+ return VNEW(cpvslerpconst(*VGET(self), *VGET(v), df));
229
+ }
230
+
182
231
  static VALUE
183
232
  rb_cpVectProject(VALUE self, VALUE v)
184
233
  {
@@ -197,6 +246,25 @@ rb_cpVectUnRotate(VALUE self, VALUE v)
197
246
  return VNEW(cpvunrotate(*VGET(self), *VGET(v)));
198
247
  }
199
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
+
200
268
  static VALUE
201
269
  rb_cpVectNear(VALUE self, VALUE v, VALUE d)
202
270
  {
@@ -205,6 +273,18 @@ rb_cpVectNear(VALUE self, VALUE v, VALUE d)
205
273
  return (cpvdot(delta, delta) <= dist*dist) ? Qtrue : Qfalse;
206
274
  }
207
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
+
208
288
  static VALUE
209
289
  rb_vec2(VALUE self, VALUE x, VALUE y)
210
290
  {
@@ -215,7 +295,7 @@ void
215
295
  Init_cpVect(void)
216
296
  {
217
297
  c_cpVect = rb_define_class_under(m_Chipmunk, "Vec2", rb_cObject);
218
- rb_define_singleton_method(c_cpBB, "for_angle", rb_cpVectForAngle, 1);
298
+ rb_define_singleton_method(c_cpVect, "for_angle", rb_cpVectForAngle, 1);
219
299
 
220
300
  rb_define_alloc_func(c_cpVect, rb_cpVectAlloc);
221
301
  rb_define_method(c_cpVect, "initialize", rb_cpVectInitialize, 2);
@@ -230,6 +310,7 @@ Init_cpVect(void)
230
310
  rb_define_method(c_cpVect, "to_angle", rb_cpVectToAngle, 0);
231
311
 
232
312
  rb_define_method(c_cpVect, "-@", rb_cpVectNegate, 0);
313
+ rb_define_method(c_cpVect, "+@", rb_cpVectUnaryplus, 0);
233
314
  rb_define_method(c_cpVect, "+", rb_cpVectAdd, 1);
234
315
  rb_define_method(c_cpVect, "-", rb_cpVectSub, 1);
235
316
  rb_define_method(c_cpVect, "*", rb_cpVectSMult, 1);
@@ -240,11 +321,26 @@ Init_cpVect(void)
240
321
  rb_define_method(c_cpVect, "lengthsq", rb_cpVectLengthsq, 0);
241
322
  rb_define_method(c_cpVect, "normalize", rb_cpVectNorm, 0);
242
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);
243
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
+
244
333
  rb_define_method(c_cpVect, "project", rb_cpVectProject, 1);
245
334
  rb_define_method(c_cpVect, "rotate", rb_cpVectRotate, 1);
246
335
  rb_define_method(c_cpVect, "unrotate", rb_cpVectUnRotate, 1);
247
- rb_define_method(c_cpVect, "near?", rb_cpVectNear, 2);
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
+
248
344
 
249
345
  rb_define_global_function("vec2", rb_vec2, 2);
250
346
  }
data/lib/1.8/chipmunk.so CHANGED
Binary file
data/lib/1.9/chipmunk.so CHANGED
Binary file
data/lib/chipmunk.rb CHANGED
@@ -13,3 +13,171 @@ begin
13
13
  rescue LoadError => e
14
14
  require "#{direc}/chipmunk.#{dlext}"
15
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
+
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chipmunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ prerelease: false
5
+ segments:
6
+ - 5
7
+ - 3
8
+ - 4
9
+ - 0
10
+ version: 5.3.4.0
5
11
  platform: x86-mswin32
6
12
  authors:
7
13
  - Scott Lembcke, Beoran, John Mair (banisterfiend)
@@ -9,12 +15,12 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-01 00:00:00 +13:00
18
+ date: 2011-05-01 00:00:00 +02:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
16
- description: ruby bindings for the chipmunk physics engine
17
- email: jrmair@gmail.com
22
+ description: "Enhanced ruby bindings for the chipmunk 5.3.4 game physics engine. "
23
+ email: beoran@rubyforge.com
18
24
  executables: []
19
25
 
20
26
  extensions: []
@@ -23,70 +29,52 @@ extra_rdoc_files: []
23
29
 
24
30
  files:
25
31
  - Rakefile
32
+ - README
33
+ - LICENSE
26
34
  - lib/chipmunk.rb
27
35
  - 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
36
  - 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
37
+ - ext/chipmunk/rb_chipmunk.c
45
38
  - 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
39
  - ext/chipmunk/rb_cpBB.c
54
- - ext/chipmunk/cpArray.c
55
- - ext/chipmunk/rb_cpJoint.c
40
+ - ext/chipmunk/rb_cpShape.c
41
+ - ext/chipmunk/rb_cpConstraint.c
56
42
  - ext/chipmunk/rb_cpVect.c
43
+ - ext/chipmunk/rb_cpArbiter.c
57
44
  - 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
45
  - lib/1.8/chipmunk.so
64
46
  - lib/1.9/chipmunk.so
65
- has_rdoc: false
66
- homepage: http://code.google.com/p/chipmunk-physics/
47
+ has_rdoc: true
48
+ homepage: https://github.com/beoran/chipmunk
49
+ licenses: []
50
+
67
51
  post_install_message:
68
52
  rdoc_options: []
69
53
 
70
54
  require_paths:
71
55
  - lib
72
56
  required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
73
58
  requirements:
74
59
  - - ">="
75
60
  - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
76
63
  version: "0"
77
- version:
78
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
79
66
  requirements:
80
67
  - - ">="
81
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
82
71
  version: "0"
83
- version:
84
72
  requirements: []
85
73
 
86
74
  rubyforge_project:
87
- rubygems_version: 1.2.0
75
+ rubygems_version: 1.3.7
88
76
  signing_key:
89
- specification_version: 2
90
- summary: ruby bindings for the chipmunk physics engine
77
+ specification_version: 3
78
+ summary: Enhanced ruby bindings for the chipmunk 5.3.4 game physics engine.
91
79
  test_files: []
92
80