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
@@ -0,0 +1,241 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007-2011 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/Dynamics/Joints/b2RopeJoint.h>
|
20
|
+
#include <Box2D/Dynamics/b2Body.h>
|
21
|
+
#include <Box2D/Dynamics/b2TimeStep.h>
|
22
|
+
|
23
|
+
|
24
|
+
// Limit:
|
25
|
+
// C = norm(pB - pA) - L
|
26
|
+
// u = (pB - pA) / norm(pB - pA)
|
27
|
+
// Cdot = dot(u, vB + cross(wB, rB) - vA - cross(wA, rA))
|
28
|
+
// J = [-u -cross(rA, u) u cross(rB, u)]
|
29
|
+
// K = J * invM * JT
|
30
|
+
// = invMassA + invIA * cross(rA, u)^2 + invMassB + invIB * cross(rB, u)^2
|
31
|
+
|
32
|
+
b2RopeJoint::b2RopeJoint(const b2RopeJointDef* def)
|
33
|
+
: b2Joint(def)
|
34
|
+
{
|
35
|
+
m_localAnchorA = def->localAnchorA;
|
36
|
+
m_localAnchorB = def->localAnchorB;
|
37
|
+
|
38
|
+
m_maxLength = def->maxLength;
|
39
|
+
|
40
|
+
m_mass = 0.0f;
|
41
|
+
m_impulse = 0.0f;
|
42
|
+
m_state = e_inactiveLimit;
|
43
|
+
m_length = 0.0f;
|
44
|
+
}
|
45
|
+
|
46
|
+
void b2RopeJoint::InitVelocityConstraints(const b2SolverData& data)
|
47
|
+
{
|
48
|
+
m_indexA = m_bodyA->m_islandIndex;
|
49
|
+
m_indexB = m_bodyB->m_islandIndex;
|
50
|
+
m_localCenterA = m_bodyA->m_sweep.localCenter;
|
51
|
+
m_localCenterB = m_bodyB->m_sweep.localCenter;
|
52
|
+
m_invMassA = m_bodyA->m_invMass;
|
53
|
+
m_invMassB = m_bodyB->m_invMass;
|
54
|
+
m_invIA = m_bodyA->m_invI;
|
55
|
+
m_invIB = m_bodyB->m_invI;
|
56
|
+
|
57
|
+
b2Vec2 cA = data.positions[m_indexA].c;
|
58
|
+
float32 aA = data.positions[m_indexA].a;
|
59
|
+
b2Vec2 vA = data.velocities[m_indexA].v;
|
60
|
+
float32 wA = data.velocities[m_indexA].w;
|
61
|
+
|
62
|
+
b2Vec2 cB = data.positions[m_indexB].c;
|
63
|
+
float32 aB = data.positions[m_indexB].a;
|
64
|
+
b2Vec2 vB = data.velocities[m_indexB].v;
|
65
|
+
float32 wB = data.velocities[m_indexB].w;
|
66
|
+
|
67
|
+
b2Rot qA(aA), qB(aB);
|
68
|
+
|
69
|
+
m_rA = b2Mul(qA, m_localAnchorA - m_localCenterA);
|
70
|
+
m_rB = b2Mul(qB, m_localAnchorB - m_localCenterB);
|
71
|
+
m_u = cB + m_rB - cA - m_rA;
|
72
|
+
|
73
|
+
m_length = m_u.Length();
|
74
|
+
|
75
|
+
float32 C = m_length - m_maxLength;
|
76
|
+
if (C > 0.0f)
|
77
|
+
{
|
78
|
+
m_state = e_atUpperLimit;
|
79
|
+
}
|
80
|
+
else
|
81
|
+
{
|
82
|
+
m_state = e_inactiveLimit;
|
83
|
+
}
|
84
|
+
|
85
|
+
if (m_length > b2_linearSlop)
|
86
|
+
{
|
87
|
+
m_u *= 1.0f / m_length;
|
88
|
+
}
|
89
|
+
else
|
90
|
+
{
|
91
|
+
m_u.SetZero();
|
92
|
+
m_mass = 0.0f;
|
93
|
+
m_impulse = 0.0f;
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
|
97
|
+
// Compute effective mass.
|
98
|
+
float32 crA = b2Cross(m_rA, m_u);
|
99
|
+
float32 crB = b2Cross(m_rB, m_u);
|
100
|
+
float32 invMass = m_invMassA + m_invIA * crA * crA + m_invMassB + m_invIB * crB * crB;
|
101
|
+
|
102
|
+
m_mass = invMass != 0.0f ? 1.0f / invMass : 0.0f;
|
103
|
+
|
104
|
+
if (data.step.warmStarting)
|
105
|
+
{
|
106
|
+
// Scale the impulse to support a variable time step.
|
107
|
+
m_impulse *= data.step.dtRatio;
|
108
|
+
|
109
|
+
b2Vec2 P = m_impulse * m_u;
|
110
|
+
vA -= m_invMassA * P;
|
111
|
+
wA -= m_invIA * b2Cross(m_rA, P);
|
112
|
+
vB += m_invMassB * P;
|
113
|
+
wB += m_invIB * b2Cross(m_rB, P);
|
114
|
+
}
|
115
|
+
else
|
116
|
+
{
|
117
|
+
m_impulse = 0.0f;
|
118
|
+
}
|
119
|
+
|
120
|
+
data.velocities[m_indexA].v = vA;
|
121
|
+
data.velocities[m_indexA].w = wA;
|
122
|
+
data.velocities[m_indexB].v = vB;
|
123
|
+
data.velocities[m_indexB].w = wB;
|
124
|
+
}
|
125
|
+
|
126
|
+
void b2RopeJoint::SolveVelocityConstraints(const b2SolverData& data)
|
127
|
+
{
|
128
|
+
b2Vec2 vA = data.velocities[m_indexA].v;
|
129
|
+
float32 wA = data.velocities[m_indexA].w;
|
130
|
+
b2Vec2 vB = data.velocities[m_indexB].v;
|
131
|
+
float32 wB = data.velocities[m_indexB].w;
|
132
|
+
|
133
|
+
// Cdot = dot(u, v + cross(w, r))
|
134
|
+
b2Vec2 vpA = vA + b2Cross(wA, m_rA);
|
135
|
+
b2Vec2 vpB = vB + b2Cross(wB, m_rB);
|
136
|
+
float32 C = m_length - m_maxLength;
|
137
|
+
float32 Cdot = b2Dot(m_u, vpB - vpA);
|
138
|
+
|
139
|
+
// Predictive constraint.
|
140
|
+
if (C < 0.0f)
|
141
|
+
{
|
142
|
+
Cdot += data.step.inv_dt * C;
|
143
|
+
}
|
144
|
+
|
145
|
+
float32 impulse = -m_mass * Cdot;
|
146
|
+
float32 oldImpulse = m_impulse;
|
147
|
+
m_impulse = b2Min(0.0f, m_impulse + impulse);
|
148
|
+
impulse = m_impulse - oldImpulse;
|
149
|
+
|
150
|
+
b2Vec2 P = impulse * m_u;
|
151
|
+
vA -= m_invMassA * P;
|
152
|
+
wA -= m_invIA * b2Cross(m_rA, P);
|
153
|
+
vB += m_invMassB * P;
|
154
|
+
wB += m_invIB * b2Cross(m_rB, P);
|
155
|
+
|
156
|
+
data.velocities[m_indexA].v = vA;
|
157
|
+
data.velocities[m_indexA].w = wA;
|
158
|
+
data.velocities[m_indexB].v = vB;
|
159
|
+
data.velocities[m_indexB].w = wB;
|
160
|
+
}
|
161
|
+
|
162
|
+
bool b2RopeJoint::SolvePositionConstraints(const b2SolverData& data)
|
163
|
+
{
|
164
|
+
b2Vec2 cA = data.positions[m_indexA].c;
|
165
|
+
float32 aA = data.positions[m_indexA].a;
|
166
|
+
b2Vec2 cB = data.positions[m_indexB].c;
|
167
|
+
float32 aB = data.positions[m_indexB].a;
|
168
|
+
|
169
|
+
b2Rot qA(aA), qB(aB);
|
170
|
+
|
171
|
+
b2Vec2 rA = b2Mul(qA, m_localAnchorA - m_localCenterA);
|
172
|
+
b2Vec2 rB = b2Mul(qB, m_localAnchorB - m_localCenterB);
|
173
|
+
b2Vec2 u = cB + rB - cA - rA;
|
174
|
+
|
175
|
+
float32 length = u.Normalize();
|
176
|
+
float32 C = length - m_maxLength;
|
177
|
+
|
178
|
+
C = b2Clamp(C, 0.0f, b2_maxLinearCorrection);
|
179
|
+
|
180
|
+
float32 impulse = -m_mass * C;
|
181
|
+
b2Vec2 P = impulse * u;
|
182
|
+
|
183
|
+
cA -= m_invMassA * P;
|
184
|
+
aA -= m_invIA * b2Cross(rA, P);
|
185
|
+
cB += m_invMassB * P;
|
186
|
+
aB += m_invIB * b2Cross(rB, P);
|
187
|
+
|
188
|
+
data.positions[m_indexA].c = cA;
|
189
|
+
data.positions[m_indexA].a = aA;
|
190
|
+
data.positions[m_indexB].c = cB;
|
191
|
+
data.positions[m_indexB].a = aB;
|
192
|
+
|
193
|
+
return length - m_maxLength < b2_linearSlop;
|
194
|
+
}
|
195
|
+
|
196
|
+
b2Vec2 b2RopeJoint::GetAnchorA() const
|
197
|
+
{
|
198
|
+
return m_bodyA->GetWorldPoint(m_localAnchorA);
|
199
|
+
}
|
200
|
+
|
201
|
+
b2Vec2 b2RopeJoint::GetAnchorB() const
|
202
|
+
{
|
203
|
+
return m_bodyB->GetWorldPoint(m_localAnchorB);
|
204
|
+
}
|
205
|
+
|
206
|
+
b2Vec2 b2RopeJoint::GetReactionForce(float32 inv_dt) const
|
207
|
+
{
|
208
|
+
b2Vec2 F = (inv_dt * m_impulse) * m_u;
|
209
|
+
return F;
|
210
|
+
}
|
211
|
+
|
212
|
+
float32 b2RopeJoint::GetReactionTorque(float32 inv_dt) const
|
213
|
+
{
|
214
|
+
B2_NOT_USED(inv_dt);
|
215
|
+
return 0.0f;
|
216
|
+
}
|
217
|
+
|
218
|
+
float32 b2RopeJoint::GetMaxLength() const
|
219
|
+
{
|
220
|
+
return m_maxLength;
|
221
|
+
}
|
222
|
+
|
223
|
+
b2LimitState b2RopeJoint::GetLimitState() const
|
224
|
+
{
|
225
|
+
return m_state;
|
226
|
+
}
|
227
|
+
|
228
|
+
void b2RopeJoint::Dump()
|
229
|
+
{
|
230
|
+
int32 indexA = m_bodyA->m_islandIndex;
|
231
|
+
int32 indexB = m_bodyB->m_islandIndex;
|
232
|
+
|
233
|
+
b2Log(" b2RopeJointDef jd;\n");
|
234
|
+
b2Log(" jd.bodyA = bodies[%d];\n", indexA);
|
235
|
+
b2Log(" jd.bodyB = bodies[%d];\n", indexB);
|
236
|
+
b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected);
|
237
|
+
b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y);
|
238
|
+
b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y);
|
239
|
+
b2Log(" jd.maxLength = %.15lef;\n", m_maxLength);
|
240
|
+
b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index);
|
241
|
+
}
|
@@ -0,0 +1,114 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2011 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_ROPE_JOINT_H
|
20
|
+
#define B2_ROPE_JOINT_H
|
21
|
+
|
22
|
+
#include <Box2D/Dynamics/Joints/b2Joint.h>
|
23
|
+
|
24
|
+
/// Rope joint definition. This requires two body anchor points and
|
25
|
+
/// a maximum lengths.
|
26
|
+
/// Note: by default the connected objects will not collide.
|
27
|
+
/// see collideConnected in b2JointDef.
|
28
|
+
struct b2RopeJointDef : public b2JointDef
|
29
|
+
{
|
30
|
+
b2RopeJointDef()
|
31
|
+
{
|
32
|
+
type = e_ropeJoint;
|
33
|
+
localAnchorA.Set(-1.0f, 0.0f);
|
34
|
+
localAnchorB.Set(1.0f, 0.0f);
|
35
|
+
maxLength = 0.0f;
|
36
|
+
}
|
37
|
+
|
38
|
+
/// The local anchor point relative to bodyA's origin.
|
39
|
+
b2Vec2 localAnchorA;
|
40
|
+
|
41
|
+
/// The local anchor point relative to bodyB's origin.
|
42
|
+
b2Vec2 localAnchorB;
|
43
|
+
|
44
|
+
/// The maximum length of the rope.
|
45
|
+
/// Warning: this must be larger than b2_linearSlop or
|
46
|
+
/// the joint will have no effect.
|
47
|
+
float32 maxLength;
|
48
|
+
};
|
49
|
+
|
50
|
+
/// A rope joint enforces a maximum distance between two points
|
51
|
+
/// on two bodies. It has no other effect.
|
52
|
+
/// Warning: if you attempt to change the maximum length during
|
53
|
+
/// the simulation you will get some non-physical behavior.
|
54
|
+
/// A model that would allow you to dynamically modify the length
|
55
|
+
/// would have some sponginess, so I chose not to implement it
|
56
|
+
/// that way. See b2DistanceJoint if you want to dynamically
|
57
|
+
/// control length.
|
58
|
+
class b2RopeJoint : public b2Joint
|
59
|
+
{
|
60
|
+
public:
|
61
|
+
b2Vec2 GetAnchorA() const;
|
62
|
+
b2Vec2 GetAnchorB() const;
|
63
|
+
|
64
|
+
b2Vec2 GetReactionForce(float32 inv_dt) const;
|
65
|
+
float32 GetReactionTorque(float32 inv_dt) const;
|
66
|
+
|
67
|
+
/// The local anchor point relative to bodyA's origin.
|
68
|
+
const b2Vec2& GetLocalAnchorA() const { return m_localAnchorA; }
|
69
|
+
|
70
|
+
/// The local anchor point relative to bodyB's origin.
|
71
|
+
const b2Vec2& GetLocalAnchorB() const { return m_localAnchorB; }
|
72
|
+
|
73
|
+
/// Set/Get the maximum length of the rope.
|
74
|
+
void SetMaxLength(float32 length) { m_maxLength = length; }
|
75
|
+
float32 GetMaxLength() const;
|
76
|
+
|
77
|
+
b2LimitState GetLimitState() const;
|
78
|
+
|
79
|
+
/// Dump joint to dmLog
|
80
|
+
void Dump();
|
81
|
+
|
82
|
+
protected:
|
83
|
+
|
84
|
+
friend class b2Joint;
|
85
|
+
b2RopeJoint(const b2RopeJointDef* data);
|
86
|
+
|
87
|
+
void InitVelocityConstraints(const b2SolverData& data);
|
88
|
+
void SolveVelocityConstraints(const b2SolverData& data);
|
89
|
+
bool SolvePositionConstraints(const b2SolverData& data);
|
90
|
+
|
91
|
+
// Solver shared
|
92
|
+
b2Vec2 m_localAnchorA;
|
93
|
+
b2Vec2 m_localAnchorB;
|
94
|
+
float32 m_maxLength;
|
95
|
+
float32 m_length;
|
96
|
+
float32 m_impulse;
|
97
|
+
|
98
|
+
// Solver temp
|
99
|
+
int32 m_indexA;
|
100
|
+
int32 m_indexB;
|
101
|
+
b2Vec2 m_u;
|
102
|
+
b2Vec2 m_rA;
|
103
|
+
b2Vec2 m_rB;
|
104
|
+
b2Vec2 m_localCenterA;
|
105
|
+
b2Vec2 m_localCenterB;
|
106
|
+
float32 m_invMassA;
|
107
|
+
float32 m_invMassB;
|
108
|
+
float32 m_invIA;
|
109
|
+
float32 m_invIB;
|
110
|
+
float32 m_mass;
|
111
|
+
b2LimitState m_state;
|
112
|
+
};
|
113
|
+
|
114
|
+
#endif
|
@@ -0,0 +1,344 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2006-2011 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/Dynamics/Joints/b2WeldJoint.h>
|
20
|
+
#include <Box2D/Dynamics/b2Body.h>
|
21
|
+
#include <Box2D/Dynamics/b2TimeStep.h>
|
22
|
+
|
23
|
+
// Point-to-point constraint
|
24
|
+
// C = p2 - p1
|
25
|
+
// Cdot = v2 - v1
|
26
|
+
// = v2 + cross(w2, r2) - v1 - cross(w1, r1)
|
27
|
+
// J = [-I -r1_skew I r2_skew ]
|
28
|
+
// Identity used:
|
29
|
+
// w k % (rx i + ry j) = w * (-ry i + rx j)
|
30
|
+
|
31
|
+
// Angle constraint
|
32
|
+
// C = angle2 - angle1 - referenceAngle
|
33
|
+
// Cdot = w2 - w1
|
34
|
+
// J = [0 0 -1 0 0 1]
|
35
|
+
// K = invI1 + invI2
|
36
|
+
|
37
|
+
void b2WeldJointDef::Initialize(b2Body* bA, b2Body* bB, const b2Vec2& anchor)
|
38
|
+
{
|
39
|
+
bodyA = bA;
|
40
|
+
bodyB = bB;
|
41
|
+
localAnchorA = bodyA->GetLocalPoint(anchor);
|
42
|
+
localAnchorB = bodyB->GetLocalPoint(anchor);
|
43
|
+
referenceAngle = bodyB->GetAngle() - bodyA->GetAngle();
|
44
|
+
}
|
45
|
+
|
46
|
+
b2WeldJoint::b2WeldJoint(const b2WeldJointDef* def)
|
47
|
+
: b2Joint(def)
|
48
|
+
{
|
49
|
+
m_localAnchorA = def->localAnchorA;
|
50
|
+
m_localAnchorB = def->localAnchorB;
|
51
|
+
m_referenceAngle = def->referenceAngle;
|
52
|
+
m_frequencyHz = def->frequencyHz;
|
53
|
+
m_dampingRatio = def->dampingRatio;
|
54
|
+
|
55
|
+
m_impulse.SetZero();
|
56
|
+
}
|
57
|
+
|
58
|
+
void b2WeldJoint::InitVelocityConstraints(const b2SolverData& data)
|
59
|
+
{
|
60
|
+
m_indexA = m_bodyA->m_islandIndex;
|
61
|
+
m_indexB = m_bodyB->m_islandIndex;
|
62
|
+
m_localCenterA = m_bodyA->m_sweep.localCenter;
|
63
|
+
m_localCenterB = m_bodyB->m_sweep.localCenter;
|
64
|
+
m_invMassA = m_bodyA->m_invMass;
|
65
|
+
m_invMassB = m_bodyB->m_invMass;
|
66
|
+
m_invIA = m_bodyA->m_invI;
|
67
|
+
m_invIB = m_bodyB->m_invI;
|
68
|
+
|
69
|
+
float32 aA = data.positions[m_indexA].a;
|
70
|
+
b2Vec2 vA = data.velocities[m_indexA].v;
|
71
|
+
float32 wA = data.velocities[m_indexA].w;
|
72
|
+
|
73
|
+
float32 aB = data.positions[m_indexB].a;
|
74
|
+
b2Vec2 vB = data.velocities[m_indexB].v;
|
75
|
+
float32 wB = data.velocities[m_indexB].w;
|
76
|
+
|
77
|
+
b2Rot qA(aA), qB(aB);
|
78
|
+
|
79
|
+
m_rA = b2Mul(qA, m_localAnchorA - m_localCenterA);
|
80
|
+
m_rB = b2Mul(qB, m_localAnchorB - m_localCenterB);
|
81
|
+
|
82
|
+
// J = [-I -r1_skew I r2_skew]
|
83
|
+
// [ 0 -1 0 1]
|
84
|
+
// r_skew = [-ry; rx]
|
85
|
+
|
86
|
+
// Matlab
|
87
|
+
// K = [ mA+r1y^2*iA+mB+r2y^2*iB, -r1y*iA*r1x-r2y*iB*r2x, -r1y*iA-r2y*iB]
|
88
|
+
// [ -r1y*iA*r1x-r2y*iB*r2x, mA+r1x^2*iA+mB+r2x^2*iB, r1x*iA+r2x*iB]
|
89
|
+
// [ -r1y*iA-r2y*iB, r1x*iA+r2x*iB, iA+iB]
|
90
|
+
|
91
|
+
float32 mA = m_invMassA, mB = m_invMassB;
|
92
|
+
float32 iA = m_invIA, iB = m_invIB;
|
93
|
+
|
94
|
+
b2Mat33 K;
|
95
|
+
K.ex.x = mA + mB + m_rA.y * m_rA.y * iA + m_rB.y * m_rB.y * iB;
|
96
|
+
K.ey.x = -m_rA.y * m_rA.x * iA - m_rB.y * m_rB.x * iB;
|
97
|
+
K.ez.x = -m_rA.y * iA - m_rB.y * iB;
|
98
|
+
K.ex.y = K.ey.x;
|
99
|
+
K.ey.y = mA + mB + m_rA.x * m_rA.x * iA + m_rB.x * m_rB.x * iB;
|
100
|
+
K.ez.y = m_rA.x * iA + m_rB.x * iB;
|
101
|
+
K.ex.z = K.ez.x;
|
102
|
+
K.ey.z = K.ez.y;
|
103
|
+
K.ez.z = iA + iB;
|
104
|
+
|
105
|
+
if (m_frequencyHz > 0.0f)
|
106
|
+
{
|
107
|
+
K.GetInverse22(&m_mass);
|
108
|
+
|
109
|
+
float32 invM = iA + iB;
|
110
|
+
float32 m = invM > 0.0f ? 1.0f / invM : 0.0f;
|
111
|
+
|
112
|
+
float32 C = aB - aA - m_referenceAngle;
|
113
|
+
|
114
|
+
// Frequency
|
115
|
+
float32 omega = 2.0f * b2_pi * m_frequencyHz;
|
116
|
+
|
117
|
+
// Damping coefficient
|
118
|
+
float32 d = 2.0f * m * m_dampingRatio * omega;
|
119
|
+
|
120
|
+
// Spring stiffness
|
121
|
+
float32 k = m * omega * omega;
|
122
|
+
|
123
|
+
// magic formulas
|
124
|
+
float32 h = data.step.dt;
|
125
|
+
m_gamma = h * (d + h * k);
|
126
|
+
m_gamma = m_gamma != 0.0f ? 1.0f / m_gamma : 0.0f;
|
127
|
+
m_bias = C * h * k * m_gamma;
|
128
|
+
|
129
|
+
invM += m_gamma;
|
130
|
+
m_mass.ez.z = invM != 0.0f ? 1.0f / invM : 0.0f;
|
131
|
+
}
|
132
|
+
else if (K.ez.z == 0.0f)
|
133
|
+
{
|
134
|
+
K.GetInverse22(&m_mass);
|
135
|
+
m_gamma = 0.0f;
|
136
|
+
m_bias = 0.0f;
|
137
|
+
}
|
138
|
+
else
|
139
|
+
{
|
140
|
+
K.GetSymInverse33(&m_mass);
|
141
|
+
m_gamma = 0.0f;
|
142
|
+
m_bias = 0.0f;
|
143
|
+
}
|
144
|
+
|
145
|
+
if (data.step.warmStarting)
|
146
|
+
{
|
147
|
+
// Scale impulses to support a variable time step.
|
148
|
+
m_impulse *= data.step.dtRatio;
|
149
|
+
|
150
|
+
b2Vec2 P(m_impulse.x, m_impulse.y);
|
151
|
+
|
152
|
+
vA -= mA * P;
|
153
|
+
wA -= iA * (b2Cross(m_rA, P) + m_impulse.z);
|
154
|
+
|
155
|
+
vB += mB * P;
|
156
|
+
wB += iB * (b2Cross(m_rB, P) + m_impulse.z);
|
157
|
+
}
|
158
|
+
else
|
159
|
+
{
|
160
|
+
m_impulse.SetZero();
|
161
|
+
}
|
162
|
+
|
163
|
+
data.velocities[m_indexA].v = vA;
|
164
|
+
data.velocities[m_indexA].w = wA;
|
165
|
+
data.velocities[m_indexB].v = vB;
|
166
|
+
data.velocities[m_indexB].w = wB;
|
167
|
+
}
|
168
|
+
|
169
|
+
void b2WeldJoint::SolveVelocityConstraints(const b2SolverData& data)
|
170
|
+
{
|
171
|
+
b2Vec2 vA = data.velocities[m_indexA].v;
|
172
|
+
float32 wA = data.velocities[m_indexA].w;
|
173
|
+
b2Vec2 vB = data.velocities[m_indexB].v;
|
174
|
+
float32 wB = data.velocities[m_indexB].w;
|
175
|
+
|
176
|
+
float32 mA = m_invMassA, mB = m_invMassB;
|
177
|
+
float32 iA = m_invIA, iB = m_invIB;
|
178
|
+
|
179
|
+
if (m_frequencyHz > 0.0f)
|
180
|
+
{
|
181
|
+
float32 Cdot2 = wB - wA;
|
182
|
+
|
183
|
+
float32 impulse2 = -m_mass.ez.z * (Cdot2 + m_bias + m_gamma * m_impulse.z);
|
184
|
+
m_impulse.z += impulse2;
|
185
|
+
|
186
|
+
wA -= iA * impulse2;
|
187
|
+
wB += iB * impulse2;
|
188
|
+
|
189
|
+
b2Vec2 Cdot1 = vB + b2Cross(wB, m_rB) - vA - b2Cross(wA, m_rA);
|
190
|
+
|
191
|
+
b2Vec2 impulse1 = -b2Mul22(m_mass, Cdot1);
|
192
|
+
m_impulse.x += impulse1.x;
|
193
|
+
m_impulse.y += impulse1.y;
|
194
|
+
|
195
|
+
b2Vec2 P = impulse1;
|
196
|
+
|
197
|
+
vA -= mA * P;
|
198
|
+
wA -= iA * b2Cross(m_rA, P);
|
199
|
+
|
200
|
+
vB += mB * P;
|
201
|
+
wB += iB * b2Cross(m_rB, P);
|
202
|
+
}
|
203
|
+
else
|
204
|
+
{
|
205
|
+
b2Vec2 Cdot1 = vB + b2Cross(wB, m_rB) - vA - b2Cross(wA, m_rA);
|
206
|
+
float32 Cdot2 = wB - wA;
|
207
|
+
b2Vec3 Cdot(Cdot1.x, Cdot1.y, Cdot2);
|
208
|
+
|
209
|
+
b2Vec3 impulse = -b2Mul(m_mass, Cdot);
|
210
|
+
m_impulse += impulse;
|
211
|
+
|
212
|
+
b2Vec2 P(impulse.x, impulse.y);
|
213
|
+
|
214
|
+
vA -= mA * P;
|
215
|
+
wA -= iA * (b2Cross(m_rA, P) + impulse.z);
|
216
|
+
|
217
|
+
vB += mB * P;
|
218
|
+
wB += iB * (b2Cross(m_rB, P) + impulse.z);
|
219
|
+
}
|
220
|
+
|
221
|
+
data.velocities[m_indexA].v = vA;
|
222
|
+
data.velocities[m_indexA].w = wA;
|
223
|
+
data.velocities[m_indexB].v = vB;
|
224
|
+
data.velocities[m_indexB].w = wB;
|
225
|
+
}
|
226
|
+
|
227
|
+
bool b2WeldJoint::SolvePositionConstraints(const b2SolverData& data)
|
228
|
+
{
|
229
|
+
b2Vec2 cA = data.positions[m_indexA].c;
|
230
|
+
float32 aA = data.positions[m_indexA].a;
|
231
|
+
b2Vec2 cB = data.positions[m_indexB].c;
|
232
|
+
float32 aB = data.positions[m_indexB].a;
|
233
|
+
|
234
|
+
b2Rot qA(aA), qB(aB);
|
235
|
+
|
236
|
+
float32 mA = m_invMassA, mB = m_invMassB;
|
237
|
+
float32 iA = m_invIA, iB = m_invIB;
|
238
|
+
|
239
|
+
b2Vec2 rA = b2Mul(qA, m_localAnchorA - m_localCenterA);
|
240
|
+
b2Vec2 rB = b2Mul(qB, m_localAnchorB - m_localCenterB);
|
241
|
+
|
242
|
+
float32 positionError, angularError;
|
243
|
+
|
244
|
+
b2Mat33 K;
|
245
|
+
K.ex.x = mA + mB + rA.y * rA.y * iA + rB.y * rB.y * iB;
|
246
|
+
K.ey.x = -rA.y * rA.x * iA - rB.y * rB.x * iB;
|
247
|
+
K.ez.x = -rA.y * iA - rB.y * iB;
|
248
|
+
K.ex.y = K.ey.x;
|
249
|
+
K.ey.y = mA + mB + rA.x * rA.x * iA + rB.x * rB.x * iB;
|
250
|
+
K.ez.y = rA.x * iA + rB.x * iB;
|
251
|
+
K.ex.z = K.ez.x;
|
252
|
+
K.ey.z = K.ez.y;
|
253
|
+
K.ez.z = iA + iB;
|
254
|
+
|
255
|
+
if (m_frequencyHz > 0.0f)
|
256
|
+
{
|
257
|
+
b2Vec2 C1 = cB + rB - cA - rA;
|
258
|
+
|
259
|
+
positionError = C1.Length();
|
260
|
+
angularError = 0.0f;
|
261
|
+
|
262
|
+
b2Vec2 P = -K.Solve22(C1);
|
263
|
+
|
264
|
+
cA -= mA * P;
|
265
|
+
aA -= iA * b2Cross(rA, P);
|
266
|
+
|
267
|
+
cB += mB * P;
|
268
|
+
aB += iB * b2Cross(rB, P);
|
269
|
+
}
|
270
|
+
else
|
271
|
+
{
|
272
|
+
b2Vec2 C1 = cB + rB - cA - rA;
|
273
|
+
float32 C2 = aB - aA - m_referenceAngle;
|
274
|
+
|
275
|
+
positionError = C1.Length();
|
276
|
+
angularError = b2Abs(C2);
|
277
|
+
|
278
|
+
b2Vec3 C(C1.x, C1.y, C2);
|
279
|
+
|
280
|
+
b2Vec3 impulse;
|
281
|
+
if (K.ez.z > 0.0f)
|
282
|
+
{
|
283
|
+
impulse = -K.Solve33(C);
|
284
|
+
}
|
285
|
+
else
|
286
|
+
{
|
287
|
+
b2Vec2 impulse2 = -K.Solve22(C1);
|
288
|
+
impulse.Set(impulse2.x, impulse2.y, 0.0f);
|
289
|
+
}
|
290
|
+
|
291
|
+
b2Vec2 P(impulse.x, impulse.y);
|
292
|
+
|
293
|
+
cA -= mA * P;
|
294
|
+
aA -= iA * (b2Cross(rA, P) + impulse.z);
|
295
|
+
|
296
|
+
cB += mB * P;
|
297
|
+
aB += iB * (b2Cross(rB, P) + impulse.z);
|
298
|
+
}
|
299
|
+
|
300
|
+
data.positions[m_indexA].c = cA;
|
301
|
+
data.positions[m_indexA].a = aA;
|
302
|
+
data.positions[m_indexB].c = cB;
|
303
|
+
data.positions[m_indexB].a = aB;
|
304
|
+
|
305
|
+
return positionError <= b2_linearSlop && angularError <= b2_angularSlop;
|
306
|
+
}
|
307
|
+
|
308
|
+
b2Vec2 b2WeldJoint::GetAnchorA() const
|
309
|
+
{
|
310
|
+
return m_bodyA->GetWorldPoint(m_localAnchorA);
|
311
|
+
}
|
312
|
+
|
313
|
+
b2Vec2 b2WeldJoint::GetAnchorB() const
|
314
|
+
{
|
315
|
+
return m_bodyB->GetWorldPoint(m_localAnchorB);
|
316
|
+
}
|
317
|
+
|
318
|
+
b2Vec2 b2WeldJoint::GetReactionForce(float32 inv_dt) const
|
319
|
+
{
|
320
|
+
b2Vec2 P(m_impulse.x, m_impulse.y);
|
321
|
+
return inv_dt * P;
|
322
|
+
}
|
323
|
+
|
324
|
+
float32 b2WeldJoint::GetReactionTorque(float32 inv_dt) const
|
325
|
+
{
|
326
|
+
return inv_dt * m_impulse.z;
|
327
|
+
}
|
328
|
+
|
329
|
+
void b2WeldJoint::Dump()
|
330
|
+
{
|
331
|
+
int32 indexA = m_bodyA->m_islandIndex;
|
332
|
+
int32 indexB = m_bodyB->m_islandIndex;
|
333
|
+
|
334
|
+
b2Log(" b2WeldJointDef jd;\n");
|
335
|
+
b2Log(" jd.bodyA = bodies[%d];\n", indexA);
|
336
|
+
b2Log(" jd.bodyB = bodies[%d];\n", indexB);
|
337
|
+
b2Log(" jd.collideConnected = bool(%d);\n", m_collideConnected);
|
338
|
+
b2Log(" jd.localAnchorA.Set(%.15lef, %.15lef);\n", m_localAnchorA.x, m_localAnchorA.y);
|
339
|
+
b2Log(" jd.localAnchorB.Set(%.15lef, %.15lef);\n", m_localAnchorB.x, m_localAnchorB.y);
|
340
|
+
b2Log(" jd.referenceAngle = %.15lef;\n", m_referenceAngle);
|
341
|
+
b2Log(" jd.frequencyHz = %.15lef;\n", m_frequencyHz);
|
342
|
+
b2Log(" jd.dampingRatio = %.15lef;\n", m_dampingRatio);
|
343
|
+
b2Log(" joints[%d] = m_world->CreateJoint(&jd);\n", m_index);
|
344
|
+
}
|