reflexion 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.doc/ext/reflex/application.cpp +5 -5
- data/.doc/ext/reflex/body.cpp +167 -0
- data/.doc/ext/reflex/capture_event.cpp +4 -4
- data/.doc/ext/reflex/draw_event.cpp +4 -4
- data/.doc/ext/reflex/event.cpp +4 -4
- data/.doc/ext/reflex/fixture.cpp +101 -0
- data/.doc/ext/reflex/focus_event.cpp +4 -4
- data/.doc/ext/reflex/frame_event.cpp +4 -4
- data/.doc/ext/reflex/image_view.cpp +22 -5
- data/.doc/ext/reflex/key_event.cpp +4 -4
- data/.doc/ext/reflex/native.cpp +6 -0
- data/.doc/ext/reflex/pointer_event.cpp +4 -4
- data/.doc/ext/reflex/reflex.cpp +2 -3
- data/.doc/ext/reflex/scroll_event.cpp +4 -4
- data/.doc/ext/reflex/selector.cpp +4 -4
- data/.doc/ext/reflex/style.cpp +4 -4
- data/.doc/ext/reflex/style_length.cpp +4 -4
- data/.doc/ext/reflex/style_length2.cpp +4 -4
- data/.doc/ext/reflex/style_length4.cpp +4 -4
- data/.doc/ext/reflex/update_event.cpp +4 -4
- data/.doc/ext/reflex/view.cpp +110 -8
- data/.doc/ext/reflex/wheel_event.cpp +4 -4
- data/.doc/ext/reflex/window.cpp +36 -12
- data/README.md +2 -2
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/ext/reflex/application.cpp +8 -8
- data/ext/reflex/body.cpp +181 -0
- data/ext/reflex/capture_event.cpp +4 -4
- data/ext/reflex/draw_event.cpp +4 -4
- data/ext/reflex/event.cpp +4 -4
- data/ext/reflex/fixture.cpp +108 -0
- data/ext/reflex/focus_event.cpp +4 -4
- data/ext/reflex/frame_event.cpp +4 -4
- data/ext/reflex/image_view.cpp +24 -5
- data/ext/reflex/key_event.cpp +4 -4
- data/ext/reflex/native.cpp +6 -0
- data/ext/reflex/pointer_event.cpp +4 -4
- data/ext/reflex/reflex.cpp +2 -3
- data/ext/reflex/scroll_event.cpp +4 -4
- data/ext/reflex/selector.cpp +4 -4
- data/ext/reflex/style.cpp +4 -4
- data/ext/reflex/style_length.cpp +4 -4
- data/ext/reflex/style_length2.cpp +4 -4
- data/ext/reflex/style_length4.cpp +4 -4
- data/ext/reflex/update_event.cpp +4 -4
- data/ext/reflex/view.cpp +126 -12
- data/ext/reflex/wheel_event.cpp +4 -4
- data/ext/reflex/window.cpp +39 -12
- data/include/reflex/bitmap.h +20 -0
- data/include/reflex/body.h +82 -0
- data/include/reflex/bounds.h +20 -0
- data/include/reflex/color.h +20 -0
- data/include/reflex/color_space.h +20 -0
- data/include/reflex/defs.h +5 -1
- data/include/reflex/event.h +16 -25
- data/include/reflex/fixture.h +116 -0
- data/include/reflex/font.h +20 -0
- data/include/reflex/image.h +20 -0
- data/include/reflex/image_view.h +1 -1
- data/include/reflex/matrix.h +20 -0
- data/include/reflex/painter.h +20 -0
- data/include/reflex/point.h +24 -0
- data/include/reflex/ruby/application.h +6 -0
- data/include/reflex/ruby/body.h +41 -0
- data/include/reflex/ruby/event.h +68 -0
- data/include/reflex/ruby/fixture.h +41 -0
- data/include/reflex/ruby/image_view.h +14 -0
- data/include/reflex/ruby/selector.h +14 -0
- data/include/reflex/ruby/style.h +14 -0
- data/include/reflex/ruby/style_length.h +26 -0
- data/include/reflex/ruby/view.h +43 -39
- data/include/reflex/ruby/window.h +27 -21
- data/include/reflex/ruby.h +2 -0
- data/include/reflex/shader.h +20 -0
- data/include/reflex/style.h +2 -3
- data/include/reflex/texture.h +20 -0
- data/include/reflex/view.h +45 -24
- data/include/reflex/window.h +11 -14
- data/include/reflex.h +3 -0
- data/lib/reflex/application.rb +6 -2
- data/lib/reflex/body.rb +17 -0
- data/lib/reflex/fixture.rb +17 -0
- data/lib/reflex/view.rb +16 -1
- data/lib/reflex/window.rb +13 -1
- data/lib/reflex.rb +2 -0
- data/reflex.gemspec +1 -1
- data/samples/bats.rb +4 -3
- data/samples/checker.rb +4 -3
- data/samples/fans.rb +4 -3
- data/samples/fps.rb +5 -3
- data/samples/grid.rb +5 -4
- data/samples/hello.rb +1 -1
- data/samples/image.rb +3 -2
- data/samples/ios/hello/hello/main.cpp +12 -3
- data/samples/ios/hello/hello.xcodeproj/project.pbxproj +376 -123
- data/samples/key.rb +5 -4
- data/samples/layout.rb +3 -2
- data/samples/model.rb +3 -2
- data/samples/osx/hello/hello/main.cpp +12 -3
- data/samples/osx/hello/hello.xcodeproj/project.pbxproj +375 -120
- data/samples/physics.rb +37 -0
- data/samples/repl.rb +3 -2
- data/samples/shader.rb +4 -4
- data/samples/shapes.rb +4 -4
- data/samples/text.rb +6 -4
- data/samples/tree.rb +5 -4
- data/samples/views.rb +3 -2
- data/samples/visuals.rb +1 -2
- data/src/body.cpp +244 -0
- data/src/event.cpp +18 -18
- data/src/fixture.cpp +108 -0
- data/src/image_view.cpp +1 -1
- data/src/ios/native_window.h +2 -0
- data/src/ios/native_window.mm +18 -1
- data/src/ios/opengl_view.mm +8 -0
- data/src/ios/window.mm +24 -3
- data/src/ios/window_data.h +3 -3
- data/src/osx/native_window.mm +17 -1
- data/src/osx/window.mm +24 -3
- data/src/osx/window_data.h +3 -3
- data/src/physics/Box2D/Box2D.h +68 -0
- data/src/physics/Box2D/Collision/Shapes/b2ChainShape.cpp +193 -0
- data/src/physics/Box2D/Collision/Shapes/b2ChainShape.h +105 -0
- data/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp +99 -0
- data/src/physics/Box2D/Collision/Shapes/b2CircleShape.h +91 -0
- data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.cpp +138 -0
- data/src/physics/Box2D/Collision/Shapes/b2EdgeShape.h +74 -0
- data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.cpp +467 -0
- data/src/physics/Box2D/Collision/Shapes/b2PolygonShape.h +101 -0
- data/src/physics/Box2D/Collision/Shapes/b2Shape.h +101 -0
- data/src/physics/Box2D/Collision/b2BroadPhase.cpp +119 -0
- data/src/physics/Box2D/Collision/b2BroadPhase.h +257 -0
- data/src/physics/Box2D/Collision/b2CollideCircle.cpp +154 -0
- data/src/physics/Box2D/Collision/b2CollideEdge.cpp +698 -0
- data/src/physics/Box2D/Collision/b2CollidePolygon.cpp +239 -0
- data/src/physics/Box2D/Collision/b2Collision.cpp +252 -0
- data/src/physics/Box2D/Collision/b2Collision.h +277 -0
- data/src/physics/Box2D/Collision/b2Distance.cpp +603 -0
- data/src/physics/Box2D/Collision/b2Distance.h +141 -0
- data/src/physics/Box2D/Collision/b2DynamicTree.cpp +778 -0
- data/src/physics/Box2D/Collision/b2DynamicTree.h +289 -0
- data/src/physics/Box2D/Collision/b2TimeOfImpact.cpp +486 -0
- data/src/physics/Box2D/Collision/b2TimeOfImpact.h +58 -0
- data/src/physics/Box2D/Common/b2BlockAllocator.cpp +215 -0
- data/src/physics/Box2D/Common/b2BlockAllocator.h +62 -0
- data/src/physics/Box2D/Common/b2Draw.cpp +44 -0
- data/src/physics/Box2D/Common/b2Draw.h +86 -0
- data/src/physics/Box2D/Common/b2GrowableStack.h +85 -0
- data/src/physics/Box2D/Common/b2Math.cpp +94 -0
- data/src/physics/Box2D/Common/b2Math.h +720 -0
- data/src/physics/Box2D/Common/b2Settings.cpp +44 -0
- data/src/physics/Box2D/Common/b2Settings.h +151 -0
- data/src/physics/Box2D/Common/b2StackAllocator.cpp +83 -0
- data/src/physics/Box2D/Common/b2StackAllocator.h +60 -0
- data/src/physics/Box2D/Common/b2Timer.cpp +101 -0
- data/src/physics/Box2D/Common/b2Timer.h +50 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.cpp +53 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h +39 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.cpp +53 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h +39 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.cpp +52 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2CircleContact.h +39 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2Contact.cpp +247 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2Contact.h +349 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.cpp +838 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2ContactSolver.h +95 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp +49 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h +39 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp +49 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h +39 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp +49 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h +38 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.cpp +52 -0
- data/src/physics/Box2D/Dynamics/Contacts/b2PolygonContact.h +39 -0
- data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.cpp +260 -0
- data/src/physics/Box2D/Dynamics/Joints/b2DistanceJoint.h +169 -0
- data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.cpp +251 -0
- data/src/physics/Box2D/Dynamics/Joints/b2FrictionJoint.h +119 -0
- data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.cpp +419 -0
- data/src/physics/Box2D/Dynamics/Joints/b2GearJoint.h +125 -0
- data/src/physics/Box2D/Dynamics/Joints/b2Joint.cpp +211 -0
- data/src/physics/Box2D/Dynamics/Joints/b2Joint.h +226 -0
- data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.cpp +304 -0
- data/src/physics/Box2D/Dynamics/Joints/b2MotorJoint.h +133 -0
- data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.cpp +222 -0
- data/src/physics/Box2D/Dynamics/Joints/b2MouseJoint.h +129 -0
- data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.cpp +629 -0
- data/src/physics/Box2D/Dynamics/Joints/b2PrismaticJoint.h +196 -0
- data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.cpp +348 -0
- data/src/physics/Box2D/Dynamics/Joints/b2PulleyJoint.h +152 -0
- data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.cpp +502 -0
- data/src/physics/Box2D/Dynamics/Joints/b2RevoluteJoint.h +204 -0
- data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.cpp +241 -0
- data/src/physics/Box2D/Dynamics/Joints/b2RopeJoint.h +114 -0
- data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.cpp +344 -0
- data/src/physics/Box2D/Dynamics/Joints/b2WeldJoint.h +126 -0
- data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.cpp +419 -0
- data/src/physics/Box2D/Dynamics/Joints/b2WheelJoint.h +210 -0
- data/src/physics/Box2D/Dynamics/b2Body.cpp +549 -0
- data/src/physics/Box2D/Dynamics/b2Body.h +860 -0
- data/src/physics/Box2D/Dynamics/b2ContactManager.cpp +296 -0
- data/src/physics/Box2D/Dynamics/b2ContactManager.h +52 -0
- data/src/physics/Box2D/Dynamics/b2Fixture.cpp +303 -0
- data/src/physics/Box2D/Dynamics/b2Fixture.h +345 -0
- data/src/physics/Box2D/Dynamics/b2Island.cpp +539 -0
- data/src/physics/Box2D/Dynamics/b2Island.h +93 -0
- data/src/physics/Box2D/Dynamics/b2TimeStep.h +70 -0
- data/src/physics/Box2D/Dynamics/b2World.cpp +1339 -0
- data/src/physics/Box2D/Dynamics/b2World.h +354 -0
- data/src/physics/Box2D/Dynamics/b2WorldCallbacks.cpp +36 -0
- data/src/physics/Box2D/Dynamics/b2WorldCallbacks.h +155 -0
- data/src/physics/Box2D/Rope/b2Rope.cpp +259 -0
- data/src/physics/Box2D/Rope/b2Rope.h +115 -0
- data/src/style.cpp +2 -2
- data/src/view.cpp +217 -17
- data/src/window.cpp +25 -15
- data/src/world.cpp +206 -0
- data/src/world.h +96 -0
- data/task/box2d.rake +25 -0
- data/test/test_view.rb +5 -5
- metadata +125 -3
data/src/ios/window.mm
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
#include "reflex/window.h"
|
3
3
|
|
4
4
|
|
5
|
-
#include <rays/bounds.h>
|
6
5
|
#include "reflex/event.h"
|
7
6
|
#include "reflex/exception.h"
|
8
7
|
#include "window_data.h"
|
@@ -111,8 +110,17 @@ namespace Reflex
|
|
111
110
|
if (!*this)
|
112
111
|
invalid_state_error(__FILE__, __LINE__);
|
113
112
|
|
114
|
-
|
113
|
+
int new_count = self->hide_count - 1;
|
114
|
+
if (new_count == 0)
|
115
|
+
{
|
116
|
+
Event e;
|
117
|
+
on_show(&e);
|
118
|
+
if (e.is_blocked()) return;
|
119
|
+
|
115
120
|
[self->native makeKeyAndVisible];
|
121
|
+
}
|
122
|
+
|
123
|
+
self->hide_count = new_count;
|
116
124
|
}
|
117
125
|
|
118
126
|
void
|
@@ -121,8 +129,17 @@ namespace Reflex
|
|
121
129
|
if (!*this)
|
122
130
|
invalid_state_error(__FILE__, __LINE__);
|
123
131
|
|
124
|
-
|
132
|
+
int new_count = self->hide_count + 1;
|
133
|
+
if (new_count == 1)
|
134
|
+
{
|
135
|
+
Event e;
|
136
|
+
on_hide(&e);
|
137
|
+
if (e.is_blocked()) return;
|
138
|
+
|
125
139
|
not_implemented_error(__FILE__, __LINE__);
|
140
|
+
}
|
141
|
+
|
142
|
+
self->hide_count = new_count;
|
126
143
|
}
|
127
144
|
|
128
145
|
void
|
@@ -131,6 +148,10 @@ namespace Reflex
|
|
131
148
|
if (!*this)
|
132
149
|
invalid_state_error(__FILE__, __LINE__);
|
133
150
|
|
151
|
+
Event e;
|
152
|
+
on_close(&e);
|
153
|
+
if (e.is_blocked()) return;
|
154
|
+
|
134
155
|
not_implemented_error(__FILE__, __LINE__);
|
135
156
|
}
|
136
157
|
|
data/src/ios/window_data.h
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
|
7
7
|
#include <map>
|
8
8
|
#include <xot/time.h>
|
9
|
-
#include <
|
10
|
-
#include <
|
9
|
+
#include <reflex/point.h>
|
10
|
+
#include <reflex/painter.h>
|
11
11
|
#include <reflex/window.h>
|
12
12
|
#include <reflex/view.h>
|
13
13
|
|
@@ -37,7 +37,7 @@ namespace Reflex
|
|
37
37
|
|
38
38
|
View::Ref root, focus;
|
39
39
|
|
40
|
-
|
40
|
+
Point prev_position, prev_size;
|
41
41
|
|
42
42
|
double prev_time_update, prev_time_draw, prev_fps;
|
43
43
|
|
data/src/osx/native_window.mm
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
#include <assert.h>
|
6
6
|
#import <Cocoa/Cocoa.h>
|
7
|
-
#include
|
7
|
+
#include "reflex/bounds.h"
|
8
8
|
#include "reflex/window.h"
|
9
9
|
#include "reflex/exception.h"
|
10
10
|
#include "event.h"
|
@@ -15,6 +15,16 @@
|
|
15
15
|
#define REF (*pref)
|
16
16
|
|
17
17
|
|
18
|
+
namespace Reflex
|
19
|
+
{
|
20
|
+
|
21
|
+
void update_view_tree (View* v, const UpdateEvent& e);
|
22
|
+
|
23
|
+
void draw_view_tree (View* v, const DrawEvent& e, const Point& offset, const Bounds& clip);
|
24
|
+
|
25
|
+
}// Reflex
|
26
|
+
|
27
|
+
|
18
28
|
static const NSUInteger WINDOW_STYLE_MASK =
|
19
29
|
NSTitledWindowMask |
|
20
30
|
NSClosableWindowMask |
|
@@ -131,6 +141,8 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
131
141
|
REF->self->prev_time_update = now;
|
132
142
|
|
133
143
|
REF->on_update(&e);
|
144
|
+
if (!e.is_blocked())
|
145
|
+
Reflex::update_view_tree(REF->root(), e);
|
134
146
|
|
135
147
|
if (REF->self->redraw)
|
136
148
|
{
|
@@ -164,7 +176,11 @@ static const NSUInteger WINDOW_STYLE_MASK =
|
|
164
176
|
|
165
177
|
e.painter->begin();
|
166
178
|
e.painter->clear();
|
179
|
+
|
167
180
|
REF->on_draw(&e);
|
181
|
+
if (!e.is_blocked())
|
182
|
+
draw_view_tree(REF->root(), e, 0, REF->frame().dup().move_to(0));
|
183
|
+
|
168
184
|
e.painter->end();
|
169
185
|
}
|
170
186
|
|
data/src/osx/window.mm
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
|
5
5
|
#import <Cocoa/Cocoa.h>
|
6
|
-
#include <rays/bounds.h>
|
7
6
|
#include "reflex/event.h"
|
8
7
|
#include "reflex/exception.h"
|
9
8
|
#include "window_data.h"
|
@@ -112,8 +111,17 @@ namespace Reflex
|
|
112
111
|
if (!*this)
|
113
112
|
invalid_state_error(__FILE__, __LINE__);
|
114
113
|
|
115
|
-
|
114
|
+
int new_count = self->hide_count - 1;
|
115
|
+
if (new_count == 0)
|
116
|
+
{
|
117
|
+
Event e;
|
118
|
+
on_show(&e);
|
119
|
+
if (e.is_blocked()) return;
|
120
|
+
|
116
121
|
[self->native makeKeyAndOrderFront: nil];
|
122
|
+
}
|
123
|
+
|
124
|
+
self->hide_count = new_count;
|
117
125
|
}
|
118
126
|
|
119
127
|
void
|
@@ -122,8 +130,17 @@ namespace Reflex
|
|
122
130
|
if (!*this)
|
123
131
|
invalid_state_error(__FILE__, __LINE__);
|
124
132
|
|
125
|
-
|
133
|
+
int new_count = self->hide_count + 1;
|
134
|
+
if (new_count == 1)
|
135
|
+
{
|
136
|
+
Event e;
|
137
|
+
on_hide(&e);
|
138
|
+
if (e.is_blocked()) return;
|
139
|
+
|
126
140
|
[self->native orderOut: self->native];
|
141
|
+
}
|
142
|
+
|
143
|
+
self->hide_count = new_count;
|
127
144
|
}
|
128
145
|
|
129
146
|
void
|
@@ -132,6 +149,10 @@ namespace Reflex
|
|
132
149
|
if (!*this)
|
133
150
|
invalid_state_error(__FILE__, __LINE__);
|
134
151
|
|
152
|
+
Event e;
|
153
|
+
on_close(&e);
|
154
|
+
if (e.is_blocked()) return;
|
155
|
+
|
135
156
|
[self->native close];
|
136
157
|
}
|
137
158
|
|
data/src/osx/window_data.h
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
|
7
7
|
#include <map>
|
8
8
|
#include <xot/time.h>
|
9
|
-
#include <
|
10
|
-
#include <
|
9
|
+
#include <reflex/point.h>
|
10
|
+
#include <reflex/painter.h>
|
11
11
|
#include <reflex/window.h>
|
12
12
|
#include <reflex/view.h>
|
13
13
|
|
@@ -35,7 +35,7 @@ namespace Reflex
|
|
35
35
|
|
36
36
|
View::Ref root, focus;
|
37
37
|
|
38
|
-
|
38
|
+
Point prev_position, prev_size;
|
39
39
|
|
40
40
|
double prev_time_update, prev_time_draw, prev_fps;
|
41
41
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
3
|
+
*
|
4
|
+
* This software is provided 'as-is', without any express or implied
|
5
|
+
* warranty. In no event will the authors be held liable for any damages
|
6
|
+
* arising from the use of this software.
|
7
|
+
* Permission is granted to anyone to use this software for any purpose,
|
8
|
+
* including commercial applications, and to alter it and redistribute it
|
9
|
+
* freely, subject to the following restrictions:
|
10
|
+
* 1. The origin of this software must not be misrepresented; you must not
|
11
|
+
* claim that you wrote the original software. If you use this software
|
12
|
+
* in a product, an acknowledgment in the product documentation would be
|
13
|
+
* appreciated but is not required.
|
14
|
+
* 2. Altered source versions must be plainly marked as such, and must not be
|
15
|
+
* misrepresented as being the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef BOX2D_H
|
20
|
+
#define BOX2D_H
|
21
|
+
|
22
|
+
/**
|
23
|
+
\mainpage Box2D API Documentation
|
24
|
+
|
25
|
+
\section intro_sec Getting Started
|
26
|
+
|
27
|
+
For documentation please see http://box2d.org/documentation.html
|
28
|
+
|
29
|
+
For discussion please visit http://box2d.org/forum
|
30
|
+
*/
|
31
|
+
|
32
|
+
// These include files constitute the main Box2D API
|
33
|
+
|
34
|
+
#include <Box2D/Common/b2Settings.h>
|
35
|
+
#include <Box2D/Common/b2Draw.h>
|
36
|
+
#include <Box2D/Common/b2Timer.h>
|
37
|
+
|
38
|
+
#include <Box2D/Collision/Shapes/b2CircleShape.h>
|
39
|
+
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
40
|
+
#include <Box2D/Collision/Shapes/b2ChainShape.h>
|
41
|
+
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
|
42
|
+
|
43
|
+
#include <Box2D/Collision/b2BroadPhase.h>
|
44
|
+
#include <Box2D/Collision/b2Distance.h>
|
45
|
+
#include <Box2D/Collision/b2DynamicTree.h>
|
46
|
+
#include <Box2D/Collision/b2TimeOfImpact.h>
|
47
|
+
|
48
|
+
#include <Box2D/Dynamics/b2Body.h>
|
49
|
+
#include <Box2D/Dynamics/b2Fixture.h>
|
50
|
+
#include <Box2D/Dynamics/b2WorldCallbacks.h>
|
51
|
+
#include <Box2D/Dynamics/b2TimeStep.h>
|
52
|
+
#include <Box2D/Dynamics/b2World.h>
|
53
|
+
|
54
|
+
#include <Box2D/Dynamics/Contacts/b2Contact.h>
|
55
|
+
|
56
|
+
#include <Box2D/Dynamics/Joints/b2DistanceJoint.h>
|
57
|
+
#include <Box2D/Dynamics/Joints/b2FrictionJoint.h>
|
58
|
+
#include <Box2D/Dynamics/Joints/b2GearJoint.h>
|
59
|
+
#include <Box2D/Dynamics/Joints/b2MotorJoint.h>
|
60
|
+
#include <Box2D/Dynamics/Joints/b2MouseJoint.h>
|
61
|
+
#include <Box2D/Dynamics/Joints/b2PrismaticJoint.h>
|
62
|
+
#include <Box2D/Dynamics/Joints/b2PulleyJoint.h>
|
63
|
+
#include <Box2D/Dynamics/Joints/b2RevoluteJoint.h>
|
64
|
+
#include <Box2D/Dynamics/Joints/b2RopeJoint.h>
|
65
|
+
#include <Box2D/Dynamics/Joints/b2WeldJoint.h>
|
66
|
+
#include <Box2D/Dynamics/Joints/b2WheelJoint.h>
|
67
|
+
|
68
|
+
#endif
|
@@ -0,0 +1,193 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
|
3
|
+
*
|
4
|
+
* This software is provided 'as-is', without any express or implied
|
5
|
+
* warranty. In no event will the authors be held liable for any damages
|
6
|
+
* arising from the use of this software.
|
7
|
+
* Permission is granted to anyone to use this software for any purpose,
|
8
|
+
* including commercial applications, and to alter it and redistribute it
|
9
|
+
* freely, subject to the following restrictions:
|
10
|
+
* 1. The origin of this software must not be misrepresented; you must not
|
11
|
+
* claim that you wrote the original software. If you use this software
|
12
|
+
* in a product, an acknowledgment in the product documentation would be
|
13
|
+
* appreciated but is not required.
|
14
|
+
* 2. Altered source versions must be plainly marked as such, and must not be
|
15
|
+
* misrepresented as being the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <Box2D/Collision/Shapes/b2ChainShape.h>
|
20
|
+
#include <Box2D/Collision/Shapes/b2EdgeShape.h>
|
21
|
+
#include <new>
|
22
|
+
#include <string.h>
|
23
|
+
|
24
|
+
b2ChainShape::~b2ChainShape()
|
25
|
+
{
|
26
|
+
Clear();
|
27
|
+
}
|
28
|
+
|
29
|
+
void b2ChainShape::Clear()
|
30
|
+
{
|
31
|
+
b2Free(m_vertices);
|
32
|
+
m_vertices = NULL;
|
33
|
+
m_count = 0;
|
34
|
+
}
|
35
|
+
|
36
|
+
void b2ChainShape::CreateLoop(const b2Vec2* vertices, int32 count)
|
37
|
+
{
|
38
|
+
b2Assert(m_vertices == NULL && m_count == 0);
|
39
|
+
b2Assert(count >= 3);
|
40
|
+
for (int32 i = 1; i < count; ++i)
|
41
|
+
{
|
42
|
+
b2Vec2 v1 = vertices[i-1];
|
43
|
+
b2Vec2 v2 = vertices[i];
|
44
|
+
// If the code crashes here, it means your vertices are too close together.
|
45
|
+
b2Assert(b2DistanceSquared(v1, v2) > b2_linearSlop * b2_linearSlop);
|
46
|
+
}
|
47
|
+
|
48
|
+
m_count = count + 1;
|
49
|
+
m_vertices = (b2Vec2*)b2Alloc(m_count * sizeof(b2Vec2));
|
50
|
+
memcpy(m_vertices, vertices, count * sizeof(b2Vec2));
|
51
|
+
m_vertices[count] = m_vertices[0];
|
52
|
+
m_prevVertex = m_vertices[m_count - 2];
|
53
|
+
m_nextVertex = m_vertices[1];
|
54
|
+
m_hasPrevVertex = true;
|
55
|
+
m_hasNextVertex = true;
|
56
|
+
}
|
57
|
+
|
58
|
+
void b2ChainShape::CreateChain(const b2Vec2* vertices, int32 count)
|
59
|
+
{
|
60
|
+
b2Assert(m_vertices == NULL && m_count == 0);
|
61
|
+
b2Assert(count >= 2);
|
62
|
+
for (int32 i = 1; i < count; ++i)
|
63
|
+
{
|
64
|
+
// If the code crashes here, it means your vertices are too close together.
|
65
|
+
b2Assert(b2DistanceSquared(vertices[i-1], vertices[i]) > b2_linearSlop * b2_linearSlop);
|
66
|
+
}
|
67
|
+
|
68
|
+
m_count = count;
|
69
|
+
m_vertices = (b2Vec2*)b2Alloc(count * sizeof(b2Vec2));
|
70
|
+
memcpy(m_vertices, vertices, m_count * sizeof(b2Vec2));
|
71
|
+
|
72
|
+
m_hasPrevVertex = false;
|
73
|
+
m_hasNextVertex = false;
|
74
|
+
|
75
|
+
m_prevVertex.SetZero();
|
76
|
+
m_nextVertex.SetZero();
|
77
|
+
}
|
78
|
+
|
79
|
+
void b2ChainShape::SetPrevVertex(const b2Vec2& prevVertex)
|
80
|
+
{
|
81
|
+
m_prevVertex = prevVertex;
|
82
|
+
m_hasPrevVertex = true;
|
83
|
+
}
|
84
|
+
|
85
|
+
void b2ChainShape::SetNextVertex(const b2Vec2& nextVertex)
|
86
|
+
{
|
87
|
+
m_nextVertex = nextVertex;
|
88
|
+
m_hasNextVertex = true;
|
89
|
+
}
|
90
|
+
|
91
|
+
b2Shape* b2ChainShape::Clone(b2BlockAllocator* allocator) const
|
92
|
+
{
|
93
|
+
void* mem = allocator->Allocate(sizeof(b2ChainShape));
|
94
|
+
b2ChainShape* clone = new (mem) b2ChainShape;
|
95
|
+
clone->CreateChain(m_vertices, m_count);
|
96
|
+
clone->m_prevVertex = m_prevVertex;
|
97
|
+
clone->m_nextVertex = m_nextVertex;
|
98
|
+
clone->m_hasPrevVertex = m_hasPrevVertex;
|
99
|
+
clone->m_hasNextVertex = m_hasNextVertex;
|
100
|
+
return clone;
|
101
|
+
}
|
102
|
+
|
103
|
+
int32 b2ChainShape::GetChildCount() const
|
104
|
+
{
|
105
|
+
// edge count = vertex count - 1
|
106
|
+
return m_count - 1;
|
107
|
+
}
|
108
|
+
|
109
|
+
void b2ChainShape::GetChildEdge(b2EdgeShape* edge, int32 index) const
|
110
|
+
{
|
111
|
+
b2Assert(0 <= index && index < m_count - 1);
|
112
|
+
edge->m_type = b2Shape::e_edge;
|
113
|
+
edge->m_radius = m_radius;
|
114
|
+
|
115
|
+
edge->m_vertex1 = m_vertices[index + 0];
|
116
|
+
edge->m_vertex2 = m_vertices[index + 1];
|
117
|
+
|
118
|
+
if (index > 0)
|
119
|
+
{
|
120
|
+
edge->m_vertex0 = m_vertices[index - 1];
|
121
|
+
edge->m_hasVertex0 = true;
|
122
|
+
}
|
123
|
+
else
|
124
|
+
{
|
125
|
+
edge->m_vertex0 = m_prevVertex;
|
126
|
+
edge->m_hasVertex0 = m_hasPrevVertex;
|
127
|
+
}
|
128
|
+
|
129
|
+
if (index < m_count - 2)
|
130
|
+
{
|
131
|
+
edge->m_vertex3 = m_vertices[index + 2];
|
132
|
+
edge->m_hasVertex3 = true;
|
133
|
+
}
|
134
|
+
else
|
135
|
+
{
|
136
|
+
edge->m_vertex3 = m_nextVertex;
|
137
|
+
edge->m_hasVertex3 = m_hasNextVertex;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
|
141
|
+
bool b2ChainShape::TestPoint(const b2Transform& xf, const b2Vec2& p) const
|
142
|
+
{
|
143
|
+
B2_NOT_USED(xf);
|
144
|
+
B2_NOT_USED(p);
|
145
|
+
return false;
|
146
|
+
}
|
147
|
+
|
148
|
+
bool b2ChainShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
149
|
+
const b2Transform& xf, int32 childIndex) const
|
150
|
+
{
|
151
|
+
b2Assert(childIndex < m_count);
|
152
|
+
|
153
|
+
b2EdgeShape edgeShape;
|
154
|
+
|
155
|
+
int32 i1 = childIndex;
|
156
|
+
int32 i2 = childIndex + 1;
|
157
|
+
if (i2 == m_count)
|
158
|
+
{
|
159
|
+
i2 = 0;
|
160
|
+
}
|
161
|
+
|
162
|
+
edgeShape.m_vertex1 = m_vertices[i1];
|
163
|
+
edgeShape.m_vertex2 = m_vertices[i2];
|
164
|
+
|
165
|
+
return edgeShape.RayCast(output, input, xf, 0);
|
166
|
+
}
|
167
|
+
|
168
|
+
void b2ChainShape::ComputeAABB(b2AABB* aabb, const b2Transform& xf, int32 childIndex) const
|
169
|
+
{
|
170
|
+
b2Assert(childIndex < m_count);
|
171
|
+
|
172
|
+
int32 i1 = childIndex;
|
173
|
+
int32 i2 = childIndex + 1;
|
174
|
+
if (i2 == m_count)
|
175
|
+
{
|
176
|
+
i2 = 0;
|
177
|
+
}
|
178
|
+
|
179
|
+
b2Vec2 v1 = b2Mul(xf, m_vertices[i1]);
|
180
|
+
b2Vec2 v2 = b2Mul(xf, m_vertices[i2]);
|
181
|
+
|
182
|
+
aabb->lowerBound = b2Min(v1, v2);
|
183
|
+
aabb->upperBound = b2Max(v1, v2);
|
184
|
+
}
|
185
|
+
|
186
|
+
void b2ChainShape::ComputeMass(b2MassData* massData, float32 density) const
|
187
|
+
{
|
188
|
+
B2_NOT_USED(density);
|
189
|
+
|
190
|
+
massData->mass = 0.0f;
|
191
|
+
massData->center.SetZero();
|
192
|
+
massData->I = 0.0f;
|
193
|
+
}
|
@@ -0,0 +1,105 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2010 Erin Catto http://www.box2d.org
|
3
|
+
*
|
4
|
+
* This software is provided 'as-is', without any express or implied
|
5
|
+
* warranty. In no event will the authors be held liable for any damages
|
6
|
+
* arising from the use of this software.
|
7
|
+
* Permission is granted to anyone to use this software for any purpose,
|
8
|
+
* including commercial applications, and to alter it and redistribute it
|
9
|
+
* freely, subject to the following restrictions:
|
10
|
+
* 1. The origin of this software must not be misrepresented; you must not
|
11
|
+
* claim that you wrote the original software. If you use this software
|
12
|
+
* in a product, an acknowledgment in the product documentation would be
|
13
|
+
* appreciated but is not required.
|
14
|
+
* 2. Altered source versions must be plainly marked as such, and must not be
|
15
|
+
* misrepresented as being the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef B2_CHAIN_SHAPE_H
|
20
|
+
#define B2_CHAIN_SHAPE_H
|
21
|
+
|
22
|
+
#include <Box2D/Collision/Shapes/b2Shape.h>
|
23
|
+
|
24
|
+
class b2EdgeShape;
|
25
|
+
|
26
|
+
/// A chain shape is a free form sequence of line segments.
|
27
|
+
/// The chain has two-sided collision, so you can use inside and outside collision.
|
28
|
+
/// Therefore, you may use any winding order.
|
29
|
+
/// Since there may be many vertices, they are allocated using b2Alloc.
|
30
|
+
/// Connectivity information is used to create smooth collisions.
|
31
|
+
/// WARNING: The chain will not collide properly if there are self-intersections.
|
32
|
+
class b2ChainShape : public b2Shape
|
33
|
+
{
|
34
|
+
public:
|
35
|
+
b2ChainShape();
|
36
|
+
|
37
|
+
/// The destructor frees the vertices using b2Free.
|
38
|
+
~b2ChainShape();
|
39
|
+
|
40
|
+
/// Clear all data.
|
41
|
+
void Clear();
|
42
|
+
|
43
|
+
/// Create a loop. This automatically adjusts connectivity.
|
44
|
+
/// @param vertices an array of vertices, these are copied
|
45
|
+
/// @param count the vertex count
|
46
|
+
void CreateLoop(const b2Vec2* vertices, int32 count);
|
47
|
+
|
48
|
+
/// Create a chain with isolated end vertices.
|
49
|
+
/// @param vertices an array of vertices, these are copied
|
50
|
+
/// @param count the vertex count
|
51
|
+
void CreateChain(const b2Vec2* vertices, int32 count);
|
52
|
+
|
53
|
+
/// Establish connectivity to a vertex that precedes the first vertex.
|
54
|
+
/// Don't call this for loops.
|
55
|
+
void SetPrevVertex(const b2Vec2& prevVertex);
|
56
|
+
|
57
|
+
/// Establish connectivity to a vertex that follows the last vertex.
|
58
|
+
/// Don't call this for loops.
|
59
|
+
void SetNextVertex(const b2Vec2& nextVertex);
|
60
|
+
|
61
|
+
/// Implement b2Shape. Vertices are cloned using b2Alloc.
|
62
|
+
b2Shape* Clone(b2BlockAllocator* allocator) const;
|
63
|
+
|
64
|
+
/// @see b2Shape::GetChildCount
|
65
|
+
int32 GetChildCount() const;
|
66
|
+
|
67
|
+
/// Get a child edge.
|
68
|
+
void GetChildEdge(b2EdgeShape* edge, int32 index) const;
|
69
|
+
|
70
|
+
/// This always return false.
|
71
|
+
/// @see b2Shape::TestPoint
|
72
|
+
bool TestPoint(const b2Transform& transform, const b2Vec2& p) const;
|
73
|
+
|
74
|
+
/// Implement b2Shape.
|
75
|
+
bool RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
76
|
+
const b2Transform& transform, int32 childIndex) const;
|
77
|
+
|
78
|
+
/// @see b2Shape::ComputeAABB
|
79
|
+
void ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const;
|
80
|
+
|
81
|
+
/// Chains have zero mass.
|
82
|
+
/// @see b2Shape::ComputeMass
|
83
|
+
void ComputeMass(b2MassData* massData, float32 density) const;
|
84
|
+
|
85
|
+
/// The vertices. Owned by this class.
|
86
|
+
b2Vec2* m_vertices;
|
87
|
+
|
88
|
+
/// The vertex count.
|
89
|
+
int32 m_count;
|
90
|
+
|
91
|
+
b2Vec2 m_prevVertex, m_nextVertex;
|
92
|
+
bool m_hasPrevVertex, m_hasNextVertex;
|
93
|
+
};
|
94
|
+
|
95
|
+
inline b2ChainShape::b2ChainShape()
|
96
|
+
{
|
97
|
+
m_type = e_chain;
|
98
|
+
m_radius = b2_polygonRadius;
|
99
|
+
m_vertices = NULL;
|
100
|
+
m_count = 0;
|
101
|
+
m_hasPrevVertex = false;
|
102
|
+
m_hasNextVertex = false;
|
103
|
+
}
|
104
|
+
|
105
|
+
#endif
|
@@ -0,0 +1,99 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
|
3
|
+
*
|
4
|
+
* This software is provided 'as-is', without any express or implied
|
5
|
+
* warranty. In no event will the authors be held liable for any damages
|
6
|
+
* arising from the use of this software.
|
7
|
+
* Permission is granted to anyone to use this software for any purpose,
|
8
|
+
* including commercial applications, and to alter it and redistribute it
|
9
|
+
* freely, subject to the following restrictions:
|
10
|
+
* 1. The origin of this software must not be misrepresented; you must not
|
11
|
+
* claim that you wrote the original software. If you use this software
|
12
|
+
* in a product, an acknowledgment in the product documentation would be
|
13
|
+
* appreciated but is not required.
|
14
|
+
* 2. Altered source versions must be plainly marked as such, and must not be
|
15
|
+
* misrepresented as being the original software.
|
16
|
+
* 3. This notice may not be removed or altered from any source distribution.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include <Box2D/Collision/Shapes/b2CircleShape.h>
|
20
|
+
#include <new>
|
21
|
+
|
22
|
+
b2Shape* b2CircleShape::Clone(b2BlockAllocator* allocator) const
|
23
|
+
{
|
24
|
+
void* mem = allocator->Allocate(sizeof(b2CircleShape));
|
25
|
+
b2CircleShape* clone = new (mem) b2CircleShape;
|
26
|
+
*clone = *this;
|
27
|
+
return clone;
|
28
|
+
}
|
29
|
+
|
30
|
+
int32 b2CircleShape::GetChildCount() const
|
31
|
+
{
|
32
|
+
return 1;
|
33
|
+
}
|
34
|
+
|
35
|
+
bool b2CircleShape::TestPoint(const b2Transform& transform, const b2Vec2& p) const
|
36
|
+
{
|
37
|
+
b2Vec2 center = transform.p + b2Mul(transform.q, m_p);
|
38
|
+
b2Vec2 d = p - center;
|
39
|
+
return b2Dot(d, d) <= m_radius * m_radius;
|
40
|
+
}
|
41
|
+
|
42
|
+
// Collision Detection in Interactive 3D Environments by Gino van den Bergen
|
43
|
+
// From Section 3.1.2
|
44
|
+
// x = s + a * r
|
45
|
+
// norm(x) = radius
|
46
|
+
bool b2CircleShape::RayCast(b2RayCastOutput* output, const b2RayCastInput& input,
|
47
|
+
const b2Transform& transform, int32 childIndex) const
|
48
|
+
{
|
49
|
+
B2_NOT_USED(childIndex);
|
50
|
+
|
51
|
+
b2Vec2 position = transform.p + b2Mul(transform.q, m_p);
|
52
|
+
b2Vec2 s = input.p1 - position;
|
53
|
+
float32 b = b2Dot(s, s) - m_radius * m_radius;
|
54
|
+
|
55
|
+
// Solve quadratic equation.
|
56
|
+
b2Vec2 r = input.p2 - input.p1;
|
57
|
+
float32 c = b2Dot(s, r);
|
58
|
+
float32 rr = b2Dot(r, r);
|
59
|
+
float32 sigma = c * c - rr * b;
|
60
|
+
|
61
|
+
// Check for negative discriminant and short segment.
|
62
|
+
if (sigma < 0.0f || rr < b2_epsilon)
|
63
|
+
{
|
64
|
+
return false;
|
65
|
+
}
|
66
|
+
|
67
|
+
// Find the point of intersection of the line with the circle.
|
68
|
+
float32 a = -(c + b2Sqrt(sigma));
|
69
|
+
|
70
|
+
// Is the intersection point on the segment?
|
71
|
+
if (0.0f <= a && a <= input.maxFraction * rr)
|
72
|
+
{
|
73
|
+
a /= rr;
|
74
|
+
output->fraction = a;
|
75
|
+
output->normal = s + a * r;
|
76
|
+
output->normal.Normalize();
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
|
83
|
+
void b2CircleShape::ComputeAABB(b2AABB* aabb, const b2Transform& transform, int32 childIndex) const
|
84
|
+
{
|
85
|
+
B2_NOT_USED(childIndex);
|
86
|
+
|
87
|
+
b2Vec2 p = transform.p + b2Mul(transform.q, m_p);
|
88
|
+
aabb->lowerBound.Set(p.x - m_radius, p.y - m_radius);
|
89
|
+
aabb->upperBound.Set(p.x + m_radius, p.y + m_radius);
|
90
|
+
}
|
91
|
+
|
92
|
+
void b2CircleShape::ComputeMass(b2MassData* massData, float32 density) const
|
93
|
+
{
|
94
|
+
massData->mass = density * b2_pi * m_radius * m_radius;
|
95
|
+
massData->center = m_p;
|
96
|
+
|
97
|
+
// inertia about the local origin
|
98
|
+
massData->I = massData->mass * (0.5f * m_radius * m_radius + b2Dot(m_p, m_p));
|
99
|
+
}
|