chipmunk-ffi 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/chipmunk-ffi.gemspec +1 -1
- data/lib/chipmunk-ffi/body.rb +0 -2
- data/lib/chipmunk-ffi/space.rb +29 -21
- data/spec/body_spec.rb +12 -3
- data/spec/shape_spec.rb +7 -0
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/chipmunk-ffi.gemspec
CHANGED
data/lib/chipmunk-ffi/body.rb
CHANGED
@@ -87,7 +87,6 @@ module CP
|
|
87
87
|
Vec2.new @struct.v
|
88
88
|
end
|
89
89
|
def v=(pv)
|
90
|
-
@struct.v = pv.struct
|
91
90
|
@struct.v.pointer.put_bytes 0, pv.struct.to_bytes, 0,Vect.size
|
92
91
|
self
|
93
92
|
end
|
@@ -99,7 +98,6 @@ module CP
|
|
99
98
|
end
|
100
99
|
def f=(pf)
|
101
100
|
@struct.f.pointer.put_bytes 0, pf.struct.to_bytes, 0,Vect.size
|
102
|
-
@struct.f = pf.struct
|
103
101
|
self
|
104
102
|
end
|
105
103
|
alias :force :f
|
data/lib/chipmunk-ffi/space.rb
CHANGED
@@ -122,27 +122,35 @@ module CP
|
|
122
122
|
|
123
123
|
def add_collision_func(a,b,&block)
|
124
124
|
beg = nil
|
125
|
-
pre =
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
125
|
+
pre = nil
|
126
|
+
unless block.nil?
|
127
|
+
pre = Proc.new do |arb_ptr,space_ptr,data_ptr|
|
128
|
+
begin
|
129
|
+
arb = ArbiterStruct.new(arb_ptr)
|
130
|
+
|
131
|
+
swapped = arb.swapped_col == 0 ? false : true
|
132
|
+
arba = swapped ? arb.b : arb.a
|
133
|
+
arbb = swapped ? arb.a : arb.b
|
134
|
+
|
135
|
+
as = ShapeStruct.new(arba)
|
136
|
+
a_obj_id = as.data.get_ulong 0
|
137
|
+
rb_a = ObjectSpace._id2ref a_obj_id
|
138
|
+
|
139
|
+
bs = ShapeStruct.new(arbb)
|
140
|
+
b_obj_id = bs.data.get_ulong 0
|
141
|
+
rb_b = ObjectSpace._id2ref b_obj_id
|
142
|
+
|
143
|
+
block.call rb_a, rb_b
|
144
|
+
1
|
145
|
+
rescue Exception => ex
|
146
|
+
puts ex.message
|
147
|
+
puts ex.backtrace
|
148
|
+
0
|
149
|
+
end
|
150
|
+
end
|
151
|
+
else
|
152
|
+
# needed for old chipmunk style
|
153
|
+
pre = Proc.new do |arb_ptr,space_ptr,data_ptr|
|
146
154
|
0
|
147
155
|
end
|
148
156
|
end
|
data/spec/body_spec.rb
CHANGED
@@ -17,12 +17,21 @@ describe 'A new Body' do
|
|
17
17
|
b.p.y.should == 0
|
18
18
|
|
19
19
|
b.pos = vec2(4,6)
|
20
|
-
|
21
|
-
|
20
|
+
b.pos.x.should == 4
|
21
|
+
b.pos.y.should == 6
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'can set its vel' do
|
25
|
+
b = CP::Body.new(5, 7)
|
26
|
+
b.p.x.should == 0
|
27
|
+
b.p.y.should == 0
|
28
|
+
|
29
|
+
b.v = vec2(4,6)
|
30
|
+
b.v.x.should == 4
|
31
|
+
b.v.y.should == 6
|
22
32
|
end
|
23
33
|
|
24
34
|
it 'can set its moment'
|
25
|
-
it 'can set its vel'
|
26
35
|
it 'can set its force'
|
27
36
|
it 'can set its angle'
|
28
37
|
it 'can set its angle_vel'
|
data/spec/shape_spec.rb
CHANGED
@@ -72,7 +72,14 @@ describe 'ShapeStruct in chipmunk' do
|
|
72
72
|
s = CP::Shape::Circle.new bod, 40, CP::ZERO_VEC_2
|
73
73
|
ShapeClassStruct.new(s.struct.klass).type.should == :circle_shape
|
74
74
|
end
|
75
|
+
|
76
|
+
it 'can set its bodys v' do
|
77
|
+
bod = CP::Body.new 90, 76
|
78
|
+
s = CP::Shape::Circle.new bod, 20, CP::ZERO_VEC_2
|
79
|
+
s.body.v = vec2(4,5)
|
80
|
+
end
|
75
81
|
end
|
82
|
+
|
76
83
|
describe 'Segment class' do
|
77
84
|
it 'can be created' do
|
78
85
|
bod = CP::Body.new 90, 76
|