reflexion 0.1.8 → 0.1.9
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.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/application.cpp +5 -1
- data/.doc/ext/reflex/arc_shape.cpp +89 -0
- data/.doc/ext/reflex/body.cpp +91 -12
- data/.doc/ext/reflex/contact_event.cpp +90 -0
- data/.doc/ext/reflex/ellipse_shape.cpp +89 -0
- data/.doc/ext/reflex/image_view.cpp +0 -16
- data/.doc/ext/reflex/native.cpp +18 -6
- data/.doc/ext/reflex/rect_shape.cpp +83 -0
- data/.doc/ext/reflex/shape_view.cpp +153 -0
- data/.doc/ext/reflex/view.cpp +63 -26
- data/.doc/ext/reflex/window.cpp +5 -1
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +6 -2
- data/ext/reflex/arc_shape.cpp +94 -0
- data/ext/reflex/body.cpp +101 -13
- data/ext/reflex/contact_event.cpp +95 -0
- data/ext/reflex/ellipse_shape.cpp +94 -0
- data/ext/reflex/image_view.cpp +0 -18
- data/ext/reflex/native.cpp +18 -6
- data/ext/reflex/rect_shape.cpp +86 -0
- data/ext/reflex/shape_view.cpp +161 -0
- data/ext/reflex/view.cpp +71 -30
- data/ext/reflex/window.cpp +5 -1
- data/include/reflex/body.h +42 -12
- data/include/reflex/event.h +27 -1
- data/include/reflex/fixture.h +6 -5
- data/include/reflex/image_view.h +5 -5
- data/include/reflex/ruby/application.h +27 -6
- data/include/reflex/ruby/event.h +11 -0
- data/include/reflex/ruby/shape_view.h +96 -0
- data/include/reflex/ruby/view.h +60 -5
- data/include/reflex/ruby/window.h +12 -3
- data/include/reflex/shape_view.h +146 -0
- data/include/reflex/view.h +17 -5
- data/lib/reflex/application.rb +9 -9
- data/lib/reflex/body.rb +2 -0
- data/lib/reflex/contact_event.rb +38 -0
- data/lib/reflex/image_view.rb +1 -1
- data/lib/reflex/shape_view.rb +25 -0
- data/lib/reflex/view.rb +19 -9
- data/lib/reflex/window.rb +11 -10
- data/lib/reflex.rb +15 -13
- data/lib/reflexion.rb +25 -18
- data/samples/osx/hello/hello/main.cpp +6 -0
- data/samples/physics.rb +22 -12
- data/samples/reflexion/breakout.rb +52 -0
- data/samples/reflexion/hello.rb +5 -7
- data/samples/reflexion/paint.rb +10 -11
- data/samples/reflexion/physics.rb +28 -0
- data/samples/reflexion/pulse.rb +10 -8
- data/samples/shapes.rb +2 -2
- data/src/body.cpp +241 -40
- data/src/event.cpp +32 -2
- data/src/shape_view.cpp +306 -0
- data/src/view.cpp +232 -66
- data/src/world.cpp +110 -30
- data/src/world.h +61 -14
- metadata +24 -7
- data/lib/reflex/arc_shape.rb +0 -20
- data/lib/reflex/ellipse_shape.rb +0 -20
- data/lib/reflex/line_shape.rb +0 -20
- data/lib/reflex/rect_shape.rb +0 -20
- data/lib/reflex/shape.rb +0 -34
data/samples/reflexion/hello.rb
CHANGED
@@ -14,11 +14,9 @@ array = []
|
|
14
14
|
draw do
|
15
15
|
gray += 0.01
|
16
16
|
gray %= 1
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
p.text "#{fps} FPS", 10, 10
|
23
|
-
end
|
17
|
+
background gray, gray, gray
|
18
|
+
array.unshift event.fps
|
19
|
+
array.slice! 32..-1
|
20
|
+
text "#{array.reduce(0) {|sum, n| sum + n}.tap {|n| break n / array.size}.to_i} FPS", 10, 30
|
21
|
+
text "#{event.fps} FPS", 10, 10
|
24
22
|
end
|
data/samples/reflexion/paint.rb
CHANGED
@@ -10,30 +10,29 @@ require 'reflexion/include'
|
|
10
10
|
|
11
11
|
FILENAME = 'paint.png'
|
12
12
|
|
13
|
-
canvas =
|
14
|
-
|
15
|
-
|
16
|
-
}
|
13
|
+
canvas =
|
14
|
+
Image.load(FILENAME) rescue nil ||
|
15
|
+
Image.new(512, 512).paint {background :white}
|
17
16
|
|
18
17
|
setup do
|
19
18
|
size canvas.size
|
20
19
|
end
|
21
20
|
|
22
21
|
draw do
|
23
|
-
|
22
|
+
image canvas
|
24
23
|
end
|
25
24
|
|
26
|
-
pointer do
|
27
|
-
if
|
25
|
+
pointer do
|
26
|
+
if down? || drag?
|
28
27
|
canvas.paint do
|
29
|
-
fill
|
30
|
-
ellipse
|
28
|
+
fill event.left? ? :red : event.right? ? :blue : :white
|
29
|
+
ellipse *(event.pos - 10).to_a, 20, 20
|
31
30
|
end
|
32
31
|
end
|
33
32
|
end
|
34
33
|
|
35
|
-
key do
|
36
|
-
case
|
34
|
+
key do
|
35
|
+
case chars
|
37
36
|
when /s/i then canvas.save FILENAME
|
38
37
|
when /q/i, "\e" then quit
|
39
38
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[xot rays reflex]
|
5
|
+
.map {|s| File.expand_path "../../../../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
|
+
|
8
|
+
require 'reflexion/include'
|
9
|
+
|
10
|
+
|
11
|
+
setup do
|
12
|
+
set size: [600, 400], gravity: Point.new(0, 9.8) * meter #, debug: true
|
13
|
+
end
|
14
|
+
|
15
|
+
draw do
|
16
|
+
text "#{event.fps.to_i} FPS", 10, 10
|
17
|
+
end
|
18
|
+
|
19
|
+
pointer do
|
20
|
+
if down? || drag?
|
21
|
+
window.add [RectShape, EllipseShape].sample.new {
|
22
|
+
size = rand 20..40
|
23
|
+
color = event.right? ? :gray : [:red, :green, :blue].sample
|
24
|
+
set frame: [*event.pos.to_a, size, size], fill: color
|
25
|
+
set dynamic: event.left?, density: 1
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
data/samples/reflexion/pulse.rb
CHANGED
@@ -17,18 +17,20 @@ setup do
|
|
17
17
|
painter.font = Font.new nil, 24
|
18
18
|
end
|
19
19
|
|
20
|
-
draw do
|
20
|
+
draw do
|
21
21
|
frame += 1
|
22
|
-
fps =
|
23
|
-
|
22
|
+
fps = event.fps.to_i if (frame % 5) == 0
|
23
|
+
text "#{fps} FPS | FRAME: #{frame}", 10, 10
|
24
24
|
end
|
25
25
|
|
26
|
-
key do
|
27
|
-
quit if
|
26
|
+
key do
|
27
|
+
quit if chars == 'q' || code == 53
|
28
28
|
end
|
29
29
|
|
30
|
-
pointer do
|
31
|
-
if
|
32
|
-
window.add EllipseShape.new {
|
30
|
+
pointer do
|
31
|
+
if down? || drag?
|
32
|
+
window.add EllipseShape.new {
|
33
|
+
set frame: [*(event.pos - 10).to_a, 20, 20], fill: :red
|
34
|
+
}
|
33
35
|
end
|
34
36
|
end
|
data/samples/shapes.rb
CHANGED
@@ -17,9 +17,9 @@ win = Window.new do
|
|
17
17
|
p.background 0
|
18
18
|
p.fill 1
|
19
19
|
|
20
|
-
%w[
|
20
|
+
%w[rect ellipse arc].each.with_index do |shape, i|
|
21
21
|
add Reflex.const_get("#{shape.capitalize}Shape").new {
|
22
|
-
set frame: [32 + 64 * i, 32, 50, 50],
|
22
|
+
set frame: [32 + 64 * i, 32, 50, 50], fill: :gray, stroke: :white
|
23
23
|
}
|
24
24
|
end
|
25
25
|
end
|
data/src/body.cpp
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include "reflex/body.h"
|
2
2
|
|
3
3
|
|
4
|
+
#include <math.h>
|
4
5
|
#include <assert.h>
|
5
6
|
#include <vector>
|
6
7
|
#include <Box2D/Common/b2Math.h>
|
@@ -10,7 +11,9 @@
|
|
10
11
|
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
11
12
|
#include <Box2D/Collision/Shapes/b2ChainShape.h>
|
12
13
|
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
|
14
|
+
#include "xot/util.h"
|
13
15
|
#include "reflex/exception.h"
|
16
|
+
#include "reflex/painter.h"
|
14
17
|
#include "world.h"
|
15
18
|
|
16
19
|
|
@@ -21,18 +24,26 @@ namespace Reflex
|
|
21
24
|
{
|
22
25
|
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
static const float PI = M_PI;
|
28
|
+
|
29
|
+
static const float PI_2 = PI * 2;
|
30
|
+
|
31
|
+
|
32
|
+
Body::Body (Handle h, float pixels_per_meter)
|
33
|
+
: handle(h), ppm(pixels_per_meter)
|
26
34
|
{
|
27
35
|
assert(h);
|
28
36
|
}
|
29
37
|
|
30
38
|
Fixture
|
31
|
-
Body::add_box (
|
39
|
+
Body::add_box (coord width, coord height)
|
32
40
|
{
|
33
|
-
assert(PTR);
|
41
|
+
assert(PTR && PTR->GetWorld());
|
34
42
|
|
35
|
-
|
43
|
+
if (PTR->GetWorld()->IsLocked())
|
44
|
+
invalid_state_error(__FILE__, __LINE__);
|
45
|
+
|
46
|
+
b2Vec2 size(width / ppm / 2, height / ppm / 2);
|
36
47
|
|
37
48
|
b2PolygonShape shape;
|
38
49
|
shape.SetAsBox(size.x, size.y);
|
@@ -46,11 +57,9 @@ namespace Reflex
|
|
46
57
|
}
|
47
58
|
|
48
59
|
Fixture
|
49
|
-
|
60
|
+
add_circle (b2Body* handle, coord size, float ppm)
|
50
61
|
{
|
51
|
-
|
52
|
-
|
53
|
-
float radius = size / scale / 2.f;
|
62
|
+
coord radius = size / ppm / 2.f;
|
54
63
|
|
55
64
|
b2CircleShape shape;
|
56
65
|
shape.m_radius = radius;
|
@@ -62,13 +71,81 @@ namespace Reflex
|
|
62
71
|
return PTR->CreateFixture(&fixture);
|
63
72
|
}
|
64
73
|
|
74
|
+
Fixture
|
75
|
+
add_ellipse (
|
76
|
+
b2Body* handle, coord width, coord height, float from, float to,
|
77
|
+
coord radius_min, uint nsegment, float ppm)
|
78
|
+
{
|
79
|
+
coord w = width / 2, h = height / 2;
|
80
|
+
|
81
|
+
if (nsegment == 0) nsegment = Painter::ELLIPSE_NSEGMENT;
|
82
|
+
|
83
|
+
std::vector<b2Vec2> vecs;
|
84
|
+
vecs.reserve(nsegment);
|
85
|
+
for (uint seg = 0; seg < nsegment; ++seg)
|
86
|
+
{
|
87
|
+
float pos = (float) seg / (float) nsegment;
|
88
|
+
float radian = (from + (to - from) * pos) * PI_2;
|
89
|
+
float x = cos(radian);
|
90
|
+
float y = -sin(radian);
|
91
|
+
vecs.push_back(b2Vec2(to_b2coord(w + w * x, ppm), to_b2coord(h + h * y, ppm)));
|
92
|
+
}
|
93
|
+
|
94
|
+
b2PolygonShape shape;
|
95
|
+
shape.Set(&vecs[0], (int32) nsegment);
|
96
|
+
|
97
|
+
b2FixtureDef fixture;
|
98
|
+
fixture.shape = &shape;
|
99
|
+
|
100
|
+
return PTR->CreateFixture(&fixture);
|
101
|
+
}
|
102
|
+
|
103
|
+
Fixture
|
104
|
+
Body::add_ellipse (coord width, coord height, coord radius_min, uint nsegment)
|
105
|
+
{
|
106
|
+
assert(PTR && PTR->GetWorld());
|
107
|
+
|
108
|
+
if (PTR->GetWorld()->IsLocked())
|
109
|
+
invalid_state_error(__FILE__, __LINE__);
|
110
|
+
|
111
|
+
if (width == height && radius_min == 0)
|
112
|
+
return add_circle(PTR, width, ppm);
|
113
|
+
else
|
114
|
+
{
|
115
|
+
return Reflex::add_ellipse(
|
116
|
+
PTR, width, height, 0, 360, radius_min, nsegment, ppm);
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
Fixture
|
121
|
+
Body::add_arc (
|
122
|
+
coord width, coord height, float angle_from, float angle_to,
|
123
|
+
coord radius_min, uint nsegment)
|
124
|
+
{
|
125
|
+
assert(PTR && PTR->GetWorld());
|
126
|
+
|
127
|
+
if (PTR->GetWorld()->IsLocked())
|
128
|
+
invalid_state_error(__FILE__, __LINE__);
|
129
|
+
|
130
|
+
if (width == height && angle_from == 0 && angle_to == 360 && radius_min == 0)
|
131
|
+
return add_circle(PTR, width, ppm);
|
132
|
+
else
|
133
|
+
{
|
134
|
+
return Reflex::add_ellipse(
|
135
|
+
PTR, width, height, angle_from, angle_to, radius_min, nsegment, ppm);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
65
139
|
Fixture
|
66
140
|
Body::add_edge (const Point& begin, const Point& end)
|
67
141
|
{
|
68
|
-
assert(PTR);
|
142
|
+
assert(PTR && PTR->GetWorld());
|
143
|
+
|
144
|
+
if (PTR->GetWorld()->IsLocked())
|
145
|
+
invalid_state_error(__FILE__, __LINE__);
|
69
146
|
|
70
147
|
b2EdgeShape shape;
|
71
|
-
shape.Set(
|
148
|
+
shape.Set(to_b2vec2(begin, ppm), to_b2vec2(end, ppm));
|
72
149
|
|
73
150
|
b2FixtureDef fixture;
|
74
151
|
fixture.shape = &shape;
|
@@ -79,7 +156,10 @@ namespace Reflex
|
|
79
156
|
Fixture
|
80
157
|
Body::add_edge (const Point* points, size_t size, bool loop)
|
81
158
|
{
|
82
|
-
assert(PTR);
|
159
|
+
assert(PTR && PTR->GetWorld());
|
160
|
+
|
161
|
+
if (PTR->GetWorld()->IsLocked())
|
162
|
+
invalid_state_error(__FILE__, __LINE__);
|
83
163
|
|
84
164
|
if (size == 2)
|
85
165
|
return add_edge(points[0], points[1]);
|
@@ -87,7 +167,7 @@ namespace Reflex
|
|
87
167
|
std::vector<b2Vec2> vecs;
|
88
168
|
vecs.reserve(size);
|
89
169
|
for (size_t i = 0; i < size; ++i)
|
90
|
-
vecs.push_back(
|
170
|
+
vecs.push_back(to_b2vec2(points[i], ppm));
|
91
171
|
|
92
172
|
b2ChainShape shape;
|
93
173
|
if (loop)
|
@@ -104,12 +184,15 @@ namespace Reflex
|
|
104
184
|
Fixture
|
105
185
|
Body::add_polygon (const Point* points, size_t size)
|
106
186
|
{
|
107
|
-
assert(PTR);
|
187
|
+
assert(PTR && PTR->GetWorld());
|
188
|
+
|
189
|
+
if (PTR->GetWorld()->IsLocked())
|
190
|
+
invalid_state_error(__FILE__, __LINE__);
|
108
191
|
|
109
192
|
std::vector<b2Vec2> vecs;
|
110
193
|
vecs.reserve(size);
|
111
194
|
for (size_t i = 0; i < size; ++i)
|
112
|
-
vecs.push_back(
|
195
|
+
vecs.push_back(to_b2vec2(points[i], ppm));
|
113
196
|
|
114
197
|
b2PolygonShape shape;
|
115
198
|
shape.Set(&vecs[0], (int32) size);
|
@@ -123,19 +206,66 @@ namespace Reflex
|
|
123
206
|
void
|
124
207
|
Body::clear_fixtures ()
|
125
208
|
{
|
126
|
-
assert(PTR);
|
209
|
+
assert(PTR && PTR->GetWorld());
|
210
|
+
|
211
|
+
if (PTR->GetWorld()->IsLocked())
|
212
|
+
invalid_state_error(__FILE__, __LINE__);
|
127
213
|
|
128
214
|
b2Fixture* f;
|
129
215
|
while (f = PTR->GetFixtureList())
|
130
216
|
PTR->DestroyFixture(f);
|
131
217
|
}
|
132
218
|
|
219
|
+
float
|
220
|
+
Body::meter2pixel (float meter) const
|
221
|
+
{
|
222
|
+
return meter * ppm;
|
223
|
+
}
|
224
|
+
|
225
|
+
void
|
226
|
+
Body::set_static (bool state)
|
227
|
+
{
|
228
|
+
assert(PTR && PTR->GetWorld());
|
229
|
+
|
230
|
+
if (PTR->GetWorld()->IsLocked())
|
231
|
+
invalid_state_error(__FILE__, __LINE__);
|
232
|
+
|
233
|
+
PTR->SetType(state ? b2_staticBody : b2_dynamicBody);
|
234
|
+
}
|
235
|
+
|
236
|
+
bool
|
237
|
+
Body::is_static () const
|
238
|
+
{
|
239
|
+
assert(PTR);
|
240
|
+
|
241
|
+
return PTR->GetType() == b2_staticBody;
|
242
|
+
}
|
243
|
+
|
244
|
+
void
|
245
|
+
Body::set_dynamic (bool state)
|
246
|
+
{
|
247
|
+
assert(PTR && PTR->GetWorld());
|
248
|
+
|
249
|
+
if (PTR->GetWorld()->IsLocked())
|
250
|
+
invalid_state_error(__FILE__, __LINE__);
|
251
|
+
|
252
|
+
PTR->SetType(state ? b2_dynamicBody : b2_staticBody);
|
253
|
+
}
|
254
|
+
|
255
|
+
bool
|
256
|
+
Body::is_dynamic () const
|
257
|
+
{
|
258
|
+
assert(PTR);
|
259
|
+
|
260
|
+
return PTR->GetType() == b2_dynamicBody;
|
261
|
+
}
|
262
|
+
|
133
263
|
Point
|
134
264
|
Body::position () const
|
135
265
|
{
|
136
266
|
assert(PTR);
|
137
267
|
|
138
|
-
return to_point(PTR->GetPosition(),
|
268
|
+
return to_point(PTR->GetPosition(), ppm);
|
139
269
|
}
|
140
270
|
|
141
271
|
float
|
@@ -143,69 +273,129 @@ namespace Reflex
|
|
143
273
|
{
|
144
274
|
assert(PTR);
|
145
275
|
|
146
|
-
return PTR->GetAngle();
|
276
|
+
return Xot::rad2deg(PTR->GetAngle());
|
147
277
|
}
|
148
278
|
|
149
279
|
void
|
150
|
-
Body::
|
280
|
+
Body::set_linear_velocity (coord x, coord y)
|
281
|
+
{
|
282
|
+
set_linear_velocity(Point(x, y));
|
283
|
+
}
|
284
|
+
|
285
|
+
void
|
286
|
+
Body::set_linear_velocity (const Point& velocity)
|
151
287
|
{
|
152
288
|
assert(PTR);
|
153
289
|
|
154
|
-
PTR->
|
290
|
+
PTR->SetLinearVelocity(to_b2vec2(velocity, ppm));
|
155
291
|
}
|
156
292
|
|
157
|
-
|
158
|
-
Body::
|
293
|
+
Point
|
294
|
+
Body::linear_velocity () const
|
159
295
|
{
|
160
296
|
assert(PTR);
|
161
297
|
|
162
|
-
return PTR->
|
298
|
+
return to_point(PTR->GetLinearVelocity(), ppm);
|
163
299
|
}
|
164
300
|
|
165
301
|
void
|
166
|
-
Body::
|
302
|
+
Body::set_angular_velocity (float velocity)
|
167
303
|
{
|
168
304
|
assert(PTR);
|
169
305
|
|
170
|
-
PTR->
|
306
|
+
PTR->SetAngularVelocity(Xot::deg2rad(velocity));
|
171
307
|
}
|
172
308
|
|
173
|
-
|
174
|
-
Body::
|
309
|
+
float
|
310
|
+
Body::angular_velocity () const
|
175
311
|
{
|
176
312
|
assert(PTR);
|
177
313
|
|
178
|
-
return PTR->
|
314
|
+
return Xot::rad2deg(PTR->GetAngularVelocity());
|
179
315
|
}
|
180
316
|
|
181
317
|
void
|
182
318
|
Body::set_density (float density)
|
183
319
|
{
|
184
|
-
iterator
|
185
|
-
|
186
|
-
|
320
|
+
iterator end_ = end();
|
321
|
+
for (iterator it = begin(); it != end_; ++it)
|
322
|
+
it->set_density(density);
|
323
|
+
}
|
187
324
|
|
188
|
-
|
325
|
+
float
|
326
|
+
Body::density () const
|
327
|
+
{
|
328
|
+
const_iterator it = begin(), end_ = end();
|
329
|
+
if (it == end_)
|
330
|
+
invalid_state_error(__FILE__, __LINE__, "no fixture.");
|
331
|
+
|
332
|
+
float val = it->density();
|
333
|
+
for (; it != end_; ++it)
|
334
|
+
{
|
335
|
+
if (val != it->density())
|
336
|
+
{
|
337
|
+
invalid_state_error(
|
338
|
+
__FILE__, __LINE__,
|
339
|
+
"each fixture have different values.");
|
340
|
+
}
|
341
|
+
}
|
342
|
+
return val;
|
189
343
|
}
|
190
344
|
|
191
345
|
void
|
192
346
|
Body::set_friction (float friction)
|
193
347
|
{
|
194
|
-
iterator
|
195
|
-
|
196
|
-
|
348
|
+
iterator end_ = end();
|
349
|
+
for (iterator it = begin(); it != end_; ++it)
|
350
|
+
it->set_friction(friction);
|
351
|
+
}
|
197
352
|
|
198
|
-
|
353
|
+
float
|
354
|
+
Body::friction () const
|
355
|
+
{
|
356
|
+
const_iterator it = begin(), end_ = end();
|
357
|
+
if (it == end_)
|
358
|
+
invalid_state_error(__FILE__, __LINE__, "no fixture.");
|
359
|
+
|
360
|
+
float val = it->friction();
|
361
|
+
for (; it != end_; ++it)
|
362
|
+
{
|
363
|
+
if (val != it->friction())
|
364
|
+
{
|
365
|
+
invalid_state_error(
|
366
|
+
__FILE__, __LINE__,
|
367
|
+
"each fixture have different values.");
|
368
|
+
}
|
369
|
+
}
|
370
|
+
return val;
|
199
371
|
}
|
200
372
|
|
201
373
|
void
|
202
374
|
Body::set_restitution (float restitution)
|
203
375
|
{
|
204
|
-
iterator
|
205
|
-
|
206
|
-
|
376
|
+
iterator end_ = end();
|
377
|
+
for (iterator it = begin(); it != end_; ++it)
|
378
|
+
it->set_restitution(restitution);
|
379
|
+
}
|
207
380
|
|
208
|
-
|
381
|
+
float
|
382
|
+
Body::restitution () const
|
383
|
+
{
|
384
|
+
const_iterator it = begin(), end_ = end();
|
385
|
+
if (it == end_)
|
386
|
+
invalid_state_error(__FILE__, __LINE__, "no fixture.");
|
387
|
+
|
388
|
+
float val = it->restitution();
|
389
|
+
for (; it != end_; ++it)
|
390
|
+
{
|
391
|
+
if (val != it->restitution())
|
392
|
+
{
|
393
|
+
invalid_state_error(
|
394
|
+
__FILE__, __LINE__,
|
395
|
+
"each fixture have different values.");
|
396
|
+
}
|
397
|
+
}
|
398
|
+
return val;
|
209
399
|
}
|
210
400
|
|
211
401
|
Body::iterator
|
@@ -240,5 +430,16 @@ namespace Reflex
|
|
240
430
|
return Fixture(NULL);
|
241
431
|
}
|
242
432
|
|
433
|
+
void
|
434
|
+
Body::set_transform (coord x, coord y, float degree)
|
435
|
+
{
|
436
|
+
assert(PTR && PTR->GetWorld());
|
437
|
+
|
438
|
+
if (PTR->GetWorld()->IsLocked())
|
439
|
+
invalid_state_error(__FILE__, __LINE__);
|
440
|
+
|
441
|
+
PTR->SetTransform(to_b2vec2(x, y, ppm), Xot::deg2rad(degree));
|
442
|
+
}
|
443
|
+
|
243
444
|
|
244
445
|
}// Reflex
|
data/src/event.cpp
CHANGED
@@ -38,8 +38,21 @@ namespace Reflex
|
|
38
38
|
}
|
39
39
|
|
40
40
|
|
41
|
-
FrameEvent::FrameEvent (
|
42
|
-
|
41
|
+
FrameEvent::FrameEvent (
|
42
|
+
const Bounds& frame, coord dx, coord dy, coord dwidth, coord dheight,
|
43
|
+
float angle, float dangle)
|
44
|
+
: frame(frame), dx(dx), dy(dy), dwidth(dwidth), dheight(dheight),
|
45
|
+
angle(angle), dangle(dangle)
|
46
|
+
{
|
47
|
+
}
|
48
|
+
|
49
|
+
FrameEvent::FrameEvent (
|
50
|
+
const Bounds& frame, const Bounds& prev_frame,
|
51
|
+
float angle, float prev_angle)
|
52
|
+
: frame(frame),
|
53
|
+
dx( frame.x - prev_frame.x), dy( frame.y - prev_frame.y),
|
54
|
+
dwidth(frame.w - prev_frame.w), dheight(frame.h - prev_frame.h),
|
55
|
+
angle(angle), dangle(angle - prev_angle)
|
43
56
|
{
|
44
57
|
}
|
45
58
|
|
@@ -55,6 +68,12 @@ namespace Reflex
|
|
55
68
|
return dwidth != 0 || dheight != 0;
|
56
69
|
}
|
57
70
|
|
71
|
+
bool
|
72
|
+
FrameEvent::is_rotate () const
|
73
|
+
{
|
74
|
+
return dangle != 0;
|
75
|
+
}
|
76
|
+
|
58
77
|
|
59
78
|
ScrollEvent::ScrollEvent ()
|
60
79
|
: x(0), y(0), z(0), dx(0), dy(0), dz(0)
|
@@ -222,4 +241,15 @@ namespace Reflex
|
|
222
241
|
}
|
223
242
|
|
224
243
|
|
244
|
+
ContactEvent::ContactEvent ()
|
245
|
+
: type(NONE), view(NULL)
|
246
|
+
{
|
247
|
+
}
|
248
|
+
|
249
|
+
ContactEvent::ContactEvent (Type type, View* view)
|
250
|
+
: type(type), view(view)
|
251
|
+
{
|
252
|
+
}
|
253
|
+
|
254
|
+
|
225
255
|
}// Reflex
|