reflexion 0.1.7 → 0.1.8
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 -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
@@ -0,0 +1,119 @@
|
|
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/b2BroadPhase.h>
|
20
|
+
|
21
|
+
b2BroadPhase::b2BroadPhase()
|
22
|
+
{
|
23
|
+
m_proxyCount = 0;
|
24
|
+
|
25
|
+
m_pairCapacity = 16;
|
26
|
+
m_pairCount = 0;
|
27
|
+
m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
|
28
|
+
|
29
|
+
m_moveCapacity = 16;
|
30
|
+
m_moveCount = 0;
|
31
|
+
m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
|
32
|
+
}
|
33
|
+
|
34
|
+
b2BroadPhase::~b2BroadPhase()
|
35
|
+
{
|
36
|
+
b2Free(m_moveBuffer);
|
37
|
+
b2Free(m_pairBuffer);
|
38
|
+
}
|
39
|
+
|
40
|
+
int32 b2BroadPhase::CreateProxy(const b2AABB& aabb, void* userData)
|
41
|
+
{
|
42
|
+
int32 proxyId = m_tree.CreateProxy(aabb, userData);
|
43
|
+
++m_proxyCount;
|
44
|
+
BufferMove(proxyId);
|
45
|
+
return proxyId;
|
46
|
+
}
|
47
|
+
|
48
|
+
void b2BroadPhase::DestroyProxy(int32 proxyId)
|
49
|
+
{
|
50
|
+
UnBufferMove(proxyId);
|
51
|
+
--m_proxyCount;
|
52
|
+
m_tree.DestroyProxy(proxyId);
|
53
|
+
}
|
54
|
+
|
55
|
+
void b2BroadPhase::MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement)
|
56
|
+
{
|
57
|
+
bool buffer = m_tree.MoveProxy(proxyId, aabb, displacement);
|
58
|
+
if (buffer)
|
59
|
+
{
|
60
|
+
BufferMove(proxyId);
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
void b2BroadPhase::TouchProxy(int32 proxyId)
|
65
|
+
{
|
66
|
+
BufferMove(proxyId);
|
67
|
+
}
|
68
|
+
|
69
|
+
void b2BroadPhase::BufferMove(int32 proxyId)
|
70
|
+
{
|
71
|
+
if (m_moveCount == m_moveCapacity)
|
72
|
+
{
|
73
|
+
int32* oldBuffer = m_moveBuffer;
|
74
|
+
m_moveCapacity *= 2;
|
75
|
+
m_moveBuffer = (int32*)b2Alloc(m_moveCapacity * sizeof(int32));
|
76
|
+
memcpy(m_moveBuffer, oldBuffer, m_moveCount * sizeof(int32));
|
77
|
+
b2Free(oldBuffer);
|
78
|
+
}
|
79
|
+
|
80
|
+
m_moveBuffer[m_moveCount] = proxyId;
|
81
|
+
++m_moveCount;
|
82
|
+
}
|
83
|
+
|
84
|
+
void b2BroadPhase::UnBufferMove(int32 proxyId)
|
85
|
+
{
|
86
|
+
for (int32 i = 0; i < m_moveCount; ++i)
|
87
|
+
{
|
88
|
+
if (m_moveBuffer[i] == proxyId)
|
89
|
+
{
|
90
|
+
m_moveBuffer[i] = e_nullProxy;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
|
95
|
+
// This is called from b2DynamicTree::Query when we are gathering pairs.
|
96
|
+
bool b2BroadPhase::QueryCallback(int32 proxyId)
|
97
|
+
{
|
98
|
+
// A proxy cannot form a pair with itself.
|
99
|
+
if (proxyId == m_queryProxyId)
|
100
|
+
{
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
|
104
|
+
// Grow the pair buffer as needed.
|
105
|
+
if (m_pairCount == m_pairCapacity)
|
106
|
+
{
|
107
|
+
b2Pair* oldBuffer = m_pairBuffer;
|
108
|
+
m_pairCapacity *= 2;
|
109
|
+
m_pairBuffer = (b2Pair*)b2Alloc(m_pairCapacity * sizeof(b2Pair));
|
110
|
+
memcpy(m_pairBuffer, oldBuffer, m_pairCount * sizeof(b2Pair));
|
111
|
+
b2Free(oldBuffer);
|
112
|
+
}
|
113
|
+
|
114
|
+
m_pairBuffer[m_pairCount].proxyIdA = b2Min(proxyId, m_queryProxyId);
|
115
|
+
m_pairBuffer[m_pairCount].proxyIdB = b2Max(proxyId, m_queryProxyId);
|
116
|
+
++m_pairCount;
|
117
|
+
|
118
|
+
return true;
|
119
|
+
}
|
@@ -0,0 +1,257 @@
|
|
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 B2_BROAD_PHASE_H
|
20
|
+
#define B2_BROAD_PHASE_H
|
21
|
+
|
22
|
+
#include <Box2D/Common/b2Settings.h>
|
23
|
+
#include <Box2D/Collision/b2Collision.h>
|
24
|
+
#include <Box2D/Collision/b2DynamicTree.h>
|
25
|
+
#include <algorithm>
|
26
|
+
|
27
|
+
struct b2Pair
|
28
|
+
{
|
29
|
+
int32 proxyIdA;
|
30
|
+
int32 proxyIdB;
|
31
|
+
};
|
32
|
+
|
33
|
+
/// The broad-phase is used for computing pairs and performing volume queries and ray casts.
|
34
|
+
/// This broad-phase does not persist pairs. Instead, this reports potentially new pairs.
|
35
|
+
/// It is up to the client to consume the new pairs and to track subsequent overlap.
|
36
|
+
class b2BroadPhase
|
37
|
+
{
|
38
|
+
public:
|
39
|
+
|
40
|
+
enum
|
41
|
+
{
|
42
|
+
e_nullProxy = -1
|
43
|
+
};
|
44
|
+
|
45
|
+
b2BroadPhase();
|
46
|
+
~b2BroadPhase();
|
47
|
+
|
48
|
+
/// Create a proxy with an initial AABB. Pairs are not reported until
|
49
|
+
/// UpdatePairs is called.
|
50
|
+
int32 CreateProxy(const b2AABB& aabb, void* userData);
|
51
|
+
|
52
|
+
/// Destroy a proxy. It is up to the client to remove any pairs.
|
53
|
+
void DestroyProxy(int32 proxyId);
|
54
|
+
|
55
|
+
/// Call MoveProxy as many times as you like, then when you are done
|
56
|
+
/// call UpdatePairs to finalized the proxy pairs (for your time step).
|
57
|
+
void MoveProxy(int32 proxyId, const b2AABB& aabb, const b2Vec2& displacement);
|
58
|
+
|
59
|
+
/// Call to trigger a re-processing of it's pairs on the next call to UpdatePairs.
|
60
|
+
void TouchProxy(int32 proxyId);
|
61
|
+
|
62
|
+
/// Get the fat AABB for a proxy.
|
63
|
+
const b2AABB& GetFatAABB(int32 proxyId) const;
|
64
|
+
|
65
|
+
/// Get user data from a proxy. Returns NULL if the id is invalid.
|
66
|
+
void* GetUserData(int32 proxyId) const;
|
67
|
+
|
68
|
+
/// Test overlap of fat AABBs.
|
69
|
+
bool TestOverlap(int32 proxyIdA, int32 proxyIdB) const;
|
70
|
+
|
71
|
+
/// Get the number of proxies.
|
72
|
+
int32 GetProxyCount() const;
|
73
|
+
|
74
|
+
/// Update the pairs. This results in pair callbacks. This can only add pairs.
|
75
|
+
template <typename T>
|
76
|
+
void UpdatePairs(T* callback);
|
77
|
+
|
78
|
+
/// Query an AABB for overlapping proxies. The callback class
|
79
|
+
/// is called for each proxy that overlaps the supplied AABB.
|
80
|
+
template <typename T>
|
81
|
+
void Query(T* callback, const b2AABB& aabb) const;
|
82
|
+
|
83
|
+
/// Ray-cast against the proxies in the tree. This relies on the callback
|
84
|
+
/// to perform a exact ray-cast in the case were the proxy contains a shape.
|
85
|
+
/// The callback also performs the any collision filtering. This has performance
|
86
|
+
/// roughly equal to k * log(n), where k is the number of collisions and n is the
|
87
|
+
/// number of proxies in the tree.
|
88
|
+
/// @param input the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1).
|
89
|
+
/// @param callback a callback class that is called for each proxy that is hit by the ray.
|
90
|
+
template <typename T>
|
91
|
+
void RayCast(T* callback, const b2RayCastInput& input) const;
|
92
|
+
|
93
|
+
/// Get the height of the embedded tree.
|
94
|
+
int32 GetTreeHeight() const;
|
95
|
+
|
96
|
+
/// Get the balance of the embedded tree.
|
97
|
+
int32 GetTreeBalance() const;
|
98
|
+
|
99
|
+
/// Get the quality metric of the embedded tree.
|
100
|
+
float32 GetTreeQuality() const;
|
101
|
+
|
102
|
+
/// Shift the world origin. Useful for large worlds.
|
103
|
+
/// The shift formula is: position -= newOrigin
|
104
|
+
/// @param newOrigin the new origin with respect to the old origin
|
105
|
+
void ShiftOrigin(const b2Vec2& newOrigin);
|
106
|
+
|
107
|
+
private:
|
108
|
+
|
109
|
+
friend class b2DynamicTree;
|
110
|
+
|
111
|
+
void BufferMove(int32 proxyId);
|
112
|
+
void UnBufferMove(int32 proxyId);
|
113
|
+
|
114
|
+
bool QueryCallback(int32 proxyId);
|
115
|
+
|
116
|
+
b2DynamicTree m_tree;
|
117
|
+
|
118
|
+
int32 m_proxyCount;
|
119
|
+
|
120
|
+
int32* m_moveBuffer;
|
121
|
+
int32 m_moveCapacity;
|
122
|
+
int32 m_moveCount;
|
123
|
+
|
124
|
+
b2Pair* m_pairBuffer;
|
125
|
+
int32 m_pairCapacity;
|
126
|
+
int32 m_pairCount;
|
127
|
+
|
128
|
+
int32 m_queryProxyId;
|
129
|
+
};
|
130
|
+
|
131
|
+
/// This is used to sort pairs.
|
132
|
+
inline bool b2PairLessThan(const b2Pair& pair1, const b2Pair& pair2)
|
133
|
+
{
|
134
|
+
if (pair1.proxyIdA < pair2.proxyIdA)
|
135
|
+
{
|
136
|
+
return true;
|
137
|
+
}
|
138
|
+
|
139
|
+
if (pair1.proxyIdA == pair2.proxyIdA)
|
140
|
+
{
|
141
|
+
return pair1.proxyIdB < pair2.proxyIdB;
|
142
|
+
}
|
143
|
+
|
144
|
+
return false;
|
145
|
+
}
|
146
|
+
|
147
|
+
inline void* b2BroadPhase::GetUserData(int32 proxyId) const
|
148
|
+
{
|
149
|
+
return m_tree.GetUserData(proxyId);
|
150
|
+
}
|
151
|
+
|
152
|
+
inline bool b2BroadPhase::TestOverlap(int32 proxyIdA, int32 proxyIdB) const
|
153
|
+
{
|
154
|
+
const b2AABB& aabbA = m_tree.GetFatAABB(proxyIdA);
|
155
|
+
const b2AABB& aabbB = m_tree.GetFatAABB(proxyIdB);
|
156
|
+
return b2TestOverlap(aabbA, aabbB);
|
157
|
+
}
|
158
|
+
|
159
|
+
inline const b2AABB& b2BroadPhase::GetFatAABB(int32 proxyId) const
|
160
|
+
{
|
161
|
+
return m_tree.GetFatAABB(proxyId);
|
162
|
+
}
|
163
|
+
|
164
|
+
inline int32 b2BroadPhase::GetProxyCount() const
|
165
|
+
{
|
166
|
+
return m_proxyCount;
|
167
|
+
}
|
168
|
+
|
169
|
+
inline int32 b2BroadPhase::GetTreeHeight() const
|
170
|
+
{
|
171
|
+
return m_tree.GetHeight();
|
172
|
+
}
|
173
|
+
|
174
|
+
inline int32 b2BroadPhase::GetTreeBalance() const
|
175
|
+
{
|
176
|
+
return m_tree.GetMaxBalance();
|
177
|
+
}
|
178
|
+
|
179
|
+
inline float32 b2BroadPhase::GetTreeQuality() const
|
180
|
+
{
|
181
|
+
return m_tree.GetAreaRatio();
|
182
|
+
}
|
183
|
+
|
184
|
+
template <typename T>
|
185
|
+
void b2BroadPhase::UpdatePairs(T* callback)
|
186
|
+
{
|
187
|
+
// Reset pair buffer
|
188
|
+
m_pairCount = 0;
|
189
|
+
|
190
|
+
// Perform tree queries for all moving proxies.
|
191
|
+
for (int32 i = 0; i < m_moveCount; ++i)
|
192
|
+
{
|
193
|
+
m_queryProxyId = m_moveBuffer[i];
|
194
|
+
if (m_queryProxyId == e_nullProxy)
|
195
|
+
{
|
196
|
+
continue;
|
197
|
+
}
|
198
|
+
|
199
|
+
// We have to query the tree with the fat AABB so that
|
200
|
+
// we don't fail to create a pair that may touch later.
|
201
|
+
const b2AABB& fatAABB = m_tree.GetFatAABB(m_queryProxyId);
|
202
|
+
|
203
|
+
// Query tree, create pairs and add them pair buffer.
|
204
|
+
m_tree.Query(this, fatAABB);
|
205
|
+
}
|
206
|
+
|
207
|
+
// Reset move buffer
|
208
|
+
m_moveCount = 0;
|
209
|
+
|
210
|
+
// Sort the pair buffer to expose duplicates.
|
211
|
+
std::sort(m_pairBuffer, m_pairBuffer + m_pairCount, b2PairLessThan);
|
212
|
+
|
213
|
+
// Send the pairs back to the client.
|
214
|
+
int32 i = 0;
|
215
|
+
while (i < m_pairCount)
|
216
|
+
{
|
217
|
+
b2Pair* primaryPair = m_pairBuffer + i;
|
218
|
+
void* userDataA = m_tree.GetUserData(primaryPair->proxyIdA);
|
219
|
+
void* userDataB = m_tree.GetUserData(primaryPair->proxyIdB);
|
220
|
+
|
221
|
+
callback->AddPair(userDataA, userDataB);
|
222
|
+
++i;
|
223
|
+
|
224
|
+
// Skip any duplicate pairs.
|
225
|
+
while (i < m_pairCount)
|
226
|
+
{
|
227
|
+
b2Pair* pair = m_pairBuffer + i;
|
228
|
+
if (pair->proxyIdA != primaryPair->proxyIdA || pair->proxyIdB != primaryPair->proxyIdB)
|
229
|
+
{
|
230
|
+
break;
|
231
|
+
}
|
232
|
+
++i;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
// Try to keep the tree balanced.
|
237
|
+
//m_tree.Rebalance(4);
|
238
|
+
}
|
239
|
+
|
240
|
+
template <typename T>
|
241
|
+
inline void b2BroadPhase::Query(T* callback, const b2AABB& aabb) const
|
242
|
+
{
|
243
|
+
m_tree.Query(callback, aabb);
|
244
|
+
}
|
245
|
+
|
246
|
+
template <typename T>
|
247
|
+
inline void b2BroadPhase::RayCast(T* callback, const b2RayCastInput& input) const
|
248
|
+
{
|
249
|
+
m_tree.RayCast(callback, input);
|
250
|
+
}
|
251
|
+
|
252
|
+
inline void b2BroadPhase::ShiftOrigin(const b2Vec2& newOrigin)
|
253
|
+
{
|
254
|
+
m_tree.ShiftOrigin(newOrigin);
|
255
|
+
}
|
256
|
+
|
257
|
+
#endif
|
@@ -0,0 +1,154 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007-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/b2Collision.h>
|
20
|
+
#include <Box2D/Collision/Shapes/b2CircleShape.h>
|
21
|
+
#include <Box2D/Collision/Shapes/b2PolygonShape.h>
|
22
|
+
|
23
|
+
void b2CollideCircles(
|
24
|
+
b2Manifold* manifold,
|
25
|
+
const b2CircleShape* circleA, const b2Transform& xfA,
|
26
|
+
const b2CircleShape* circleB, const b2Transform& xfB)
|
27
|
+
{
|
28
|
+
manifold->pointCount = 0;
|
29
|
+
|
30
|
+
b2Vec2 pA = b2Mul(xfA, circleA->m_p);
|
31
|
+
b2Vec2 pB = b2Mul(xfB, circleB->m_p);
|
32
|
+
|
33
|
+
b2Vec2 d = pB - pA;
|
34
|
+
float32 distSqr = b2Dot(d, d);
|
35
|
+
float32 rA = circleA->m_radius, rB = circleB->m_radius;
|
36
|
+
float32 radius = rA + rB;
|
37
|
+
if (distSqr > radius * radius)
|
38
|
+
{
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
|
42
|
+
manifold->type = b2Manifold::e_circles;
|
43
|
+
manifold->localPoint = circleA->m_p;
|
44
|
+
manifold->localNormal.SetZero();
|
45
|
+
manifold->pointCount = 1;
|
46
|
+
|
47
|
+
manifold->points[0].localPoint = circleB->m_p;
|
48
|
+
manifold->points[0].id.key = 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
void b2CollidePolygonAndCircle(
|
52
|
+
b2Manifold* manifold,
|
53
|
+
const b2PolygonShape* polygonA, const b2Transform& xfA,
|
54
|
+
const b2CircleShape* circleB, const b2Transform& xfB)
|
55
|
+
{
|
56
|
+
manifold->pointCount = 0;
|
57
|
+
|
58
|
+
// Compute circle position in the frame of the polygon.
|
59
|
+
b2Vec2 c = b2Mul(xfB, circleB->m_p);
|
60
|
+
b2Vec2 cLocal = b2MulT(xfA, c);
|
61
|
+
|
62
|
+
// Find the min separating edge.
|
63
|
+
int32 normalIndex = 0;
|
64
|
+
float32 separation = -b2_maxFloat;
|
65
|
+
float32 radius = polygonA->m_radius + circleB->m_radius;
|
66
|
+
int32 vertexCount = polygonA->m_count;
|
67
|
+
const b2Vec2* vertices = polygonA->m_vertices;
|
68
|
+
const b2Vec2* normals = polygonA->m_normals;
|
69
|
+
|
70
|
+
for (int32 i = 0; i < vertexCount; ++i)
|
71
|
+
{
|
72
|
+
float32 s = b2Dot(normals[i], cLocal - vertices[i]);
|
73
|
+
|
74
|
+
if (s > radius)
|
75
|
+
{
|
76
|
+
// Early out.
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (s > separation)
|
81
|
+
{
|
82
|
+
separation = s;
|
83
|
+
normalIndex = i;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
// Vertices that subtend the incident face.
|
88
|
+
int32 vertIndex1 = normalIndex;
|
89
|
+
int32 vertIndex2 = vertIndex1 + 1 < vertexCount ? vertIndex1 + 1 : 0;
|
90
|
+
b2Vec2 v1 = vertices[vertIndex1];
|
91
|
+
b2Vec2 v2 = vertices[vertIndex2];
|
92
|
+
|
93
|
+
// If the center is inside the polygon ...
|
94
|
+
if (separation < b2_epsilon)
|
95
|
+
{
|
96
|
+
manifold->pointCount = 1;
|
97
|
+
manifold->type = b2Manifold::e_faceA;
|
98
|
+
manifold->localNormal = normals[normalIndex];
|
99
|
+
manifold->localPoint = 0.5f * (v1 + v2);
|
100
|
+
manifold->points[0].localPoint = circleB->m_p;
|
101
|
+
manifold->points[0].id.key = 0;
|
102
|
+
return;
|
103
|
+
}
|
104
|
+
|
105
|
+
// Compute barycentric coordinates
|
106
|
+
float32 u1 = b2Dot(cLocal - v1, v2 - v1);
|
107
|
+
float32 u2 = b2Dot(cLocal - v2, v1 - v2);
|
108
|
+
if (u1 <= 0.0f)
|
109
|
+
{
|
110
|
+
if (b2DistanceSquared(cLocal, v1) > radius * radius)
|
111
|
+
{
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
|
115
|
+
manifold->pointCount = 1;
|
116
|
+
manifold->type = b2Manifold::e_faceA;
|
117
|
+
manifold->localNormal = cLocal - v1;
|
118
|
+
manifold->localNormal.Normalize();
|
119
|
+
manifold->localPoint = v1;
|
120
|
+
manifold->points[0].localPoint = circleB->m_p;
|
121
|
+
manifold->points[0].id.key = 0;
|
122
|
+
}
|
123
|
+
else if (u2 <= 0.0f)
|
124
|
+
{
|
125
|
+
if (b2DistanceSquared(cLocal, v2) > radius * radius)
|
126
|
+
{
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
|
130
|
+
manifold->pointCount = 1;
|
131
|
+
manifold->type = b2Manifold::e_faceA;
|
132
|
+
manifold->localNormal = cLocal - v2;
|
133
|
+
manifold->localNormal.Normalize();
|
134
|
+
manifold->localPoint = v2;
|
135
|
+
manifold->points[0].localPoint = circleB->m_p;
|
136
|
+
manifold->points[0].id.key = 0;
|
137
|
+
}
|
138
|
+
else
|
139
|
+
{
|
140
|
+
b2Vec2 faceCenter = 0.5f * (v1 + v2);
|
141
|
+
float32 separation = b2Dot(cLocal - faceCenter, normals[vertIndex1]);
|
142
|
+
if (separation > radius)
|
143
|
+
{
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
|
147
|
+
manifold->pointCount = 1;
|
148
|
+
manifold->type = b2Manifold::e_faceA;
|
149
|
+
manifold->localNormal = normals[vertIndex1];
|
150
|
+
manifold->localPoint = faceCenter;
|
151
|
+
manifold->points[0].localPoint = circleB->m_p;
|
152
|
+
manifold->points[0].id.key = 0;
|
153
|
+
}
|
154
|
+
}
|