MCPcopy Create free account
hub / github.com/ByteArena/box2d / SolveVelocityConstraints

Method SolveVelocityConstraints

DynamicsB2JointMouse.go:214–236  ·  view source on GitHub ↗
(data B2SolverData)

Source from the content-addressed store, hash-verified

212}
213
214func (joint *B2MouseJoint) SolveVelocityConstraints(data B2SolverData) {
215
216 vB := data.Velocities[joint.M_indexB].V
217 wB := data.Velocities[joint.M_indexB].W
218
219 // Cdot = v + cross(w, r)
220 Cdot := B2Vec2Add(vB, B2Vec2CrossScalarVector(wB, joint.M_rB))
221 impulse := B2Vec2Mat22Mul(joint.M_mass, (B2Vec2Add(B2Vec2Add(Cdot, joint.M_C), B2Vec2MulScalar(joint.M_gamma, joint.M_impulse))).OperatorNegate())
222
223 oldImpulse := joint.M_impulse
224 joint.M_impulse.OperatorPlusInplace(impulse)
225 maxImpulse := data.Step.Dt * joint.M_maxForce
226 if joint.M_impulse.LengthSquared() > maxImpulse*maxImpulse {
227 joint.M_impulse.OperatorScalarMulInplace(maxImpulse / joint.M_impulse.Length())
228 }
229 impulse = B2Vec2Sub(joint.M_impulse, oldImpulse)
230
231 vB.OperatorPlusInplace(B2Vec2MulScalar(joint.M_invMassB, impulse))
232 wB += joint.M_invIB * B2Vec2Cross(joint.M_rB, impulse)
233
234 data.Velocities[joint.M_indexB].V = vB
235 data.Velocities[joint.M_indexB].W = wB
236}
237
238func (joint *B2MouseJoint) SolvePositionConstraints(data B2SolverData) bool {
239 return true

Callers

nothing calls this directly

Calls 11

B2Vec2AddFunction · 0.85
B2Vec2CrossScalarVectorFunction · 0.85
B2Vec2Mat22MulFunction · 0.85
B2Vec2MulScalarFunction · 0.85
B2Vec2SubFunction · 0.85
B2Vec2CrossFunction · 0.85
LengthSquaredMethod · 0.80
LengthMethod · 0.80
OperatorNegateMethod · 0.45
OperatorPlusInplaceMethod · 0.45

Tested by

no test coverage detected