MCPcopy Create free account
hub / github.com/cinder/Cinder / Solve

Method Solve

blocks/Box2D/src/Box2D/Dynamics/b2Island.cpp:183–382  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183void b2Island::Solve(b2Profile* profile, const b2TimeStep& step, const b2Vec2& gravity, bool allowSleep)
184{
185 b2Timer timer;
186
187 float32 h = step.dt;
188
189 // Integrate velocities and apply damping. Initialize the body state.
190 for (int32 i = 0; i < m_bodyCount; ++i)
191 {
192 b2Body* b = m_bodies[i];
193
194 b2Vec2 c = b->m_sweep.c;
195 float32 a = b->m_sweep.a;
196 b2Vec2 v = b->m_linearVelocity;
197 float32 w = b->m_angularVelocity;
198
199 // Store positions for continuous collision.
200 b->m_sweep.c0 = b->m_sweep.c;
201 b->m_sweep.a0 = b->m_sweep.a;
202
203 if (b->m_type == b2_dynamicBody)
204 {
205 // Integrate velocities.
206 v += h * (b->m_gravityScale * gravity + b->m_invMass * b->m_force);
207 w += h * b->m_invI * b->m_torque;
208
209 // Apply damping.
210 // ODE: dv/dt + c * v = 0
211 // Solution: v(t) = v0 * exp(-c * t)
212 // Time step: v(t + dt) = v0 * exp(-c * (t + dt)) = v0 * exp(-c * t) * exp(-c * dt) = v * exp(-c * dt)
213 // v2 = exp(-c * dt) * v1
214 // Taylor expansion:
215 // v2 = (1.0f - c * dt) * v1
216 v *= b2Clamp(1.0f - h * b->m_linearDamping, 0.0f, 1.0f);
217 w *= b2Clamp(1.0f - h * b->m_angularDamping, 0.0f, 1.0f);
218 }
219
220 m_positions[i].c = c;
221 m_positions[i].a = a;
222 m_velocities[i].v = v;
223 m_velocities[i].w = w;
224 }
225
226 timer.Reset();
227
228 // Solver data
229 b2SolverData solverData;
230 solverData.step = step;
231 solverData.positions = m_positions;
232 solverData.velocities = m_velocities;
233
234 // Initialize velocity constraints.
235 b2ContactSolverDef contactSolverDef;
236 contactSolverDef.step = step;
237 contactSolverDef.contacts = m_contacts;
238 contactSolverDef.count = m_contactCount;
239 contactSolverDef.positions = m_positions;
240 contactSolverDef.velocities = m_velocities;

Callers

nothing calls this directly

Calls 15

b2ClampFunction · 0.85
b2DotFunction · 0.85
b2AbsFunction · 0.85
b2MinFunction · 0.85
WarmStartMethod · 0.80
GetMillisecondsMethod · 0.80
StoreImpulsesMethod · 0.80
LengthMethod · 0.80
SynchronizeTransformMethod · 0.80
SetAwakeMethod · 0.80
ResetMethod · 0.45

Tested by

no test coverage detected