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

Method SolvePositionConstraints

DynamicsB2JointDistance.go:282–319  ·  view source on GitHub ↗
(data B2SolverData)

Source from the content-addressed store, hash-verified

280}
281
282func (joint *B2DistanceJoint) SolvePositionConstraints(data B2SolverData) bool {
283 if joint.M_frequencyHz > 0.0 {
284 // There is no position correction for soft distance constraints.
285 return true
286 }
287
288 cA := data.Positions[joint.M_indexA].C
289 aA := data.Positions[joint.M_indexA].A
290 cB := data.Positions[joint.M_indexB].C
291 aB := data.Positions[joint.M_indexB].A
292
293 qA := MakeB2RotFromAngle(aA)
294 qB := MakeB2RotFromAngle(aB)
295
296 rA := B2RotVec2Mul(qA, B2Vec2Sub(joint.M_localAnchorA, joint.M_localCenterA))
297 rB := B2RotVec2Mul(qB, B2Vec2Sub(joint.M_localAnchorB, joint.M_localCenterB))
298 u := B2Vec2Sub(B2Vec2Sub(B2Vec2Add(cB, rB), cA), rA)
299
300 length := u.Normalize()
301 C := length - joint.M_length
302 C = B2FloatClamp(C, -B2_maxLinearCorrection, B2_maxLinearCorrection)
303
304 impulse := -joint.M_mass * C
305 P := B2Vec2MulScalar(impulse, u)
306
307 cA.OperatorMinusInplace(B2Vec2MulScalar(joint.M_invMassA, P))
308 aA -= joint.M_invIA * B2Vec2Cross(rA, P)
309 cB.OperatorPlusInplace(B2Vec2MulScalar(joint.M_invMassB, P))
310 aB += joint.M_invIB * B2Vec2Cross(rB, P)
311
312 // Note: mutation on value, not ref; but OK because Positions is an array
313 data.Positions[joint.M_indexA].C = cA
314 data.Positions[joint.M_indexA].A = aA
315 data.Positions[joint.M_indexB].C = cB
316 data.Positions[joint.M_indexB].A = aB
317
318 return math.Abs(C) < B2_linearSlop
319}
320
321func (joint B2DistanceJoint) GetAnchorA() B2Vec2 {
322 return joint.M_bodyA.GetWorldPoint(joint.M_localAnchorA)

Callers

nothing calls this directly

Calls 10

MakeB2RotFromAngleFunction · 0.85
B2RotVec2MulFunction · 0.85
B2Vec2SubFunction · 0.85
B2Vec2AddFunction · 0.85
B2FloatClampFunction · 0.85
B2Vec2MulScalarFunction · 0.85
B2Vec2CrossFunction · 0.85
NormalizeMethod · 0.45
OperatorMinusInplaceMethod · 0.45
OperatorPlusInplaceMethod · 0.45

Tested by

no test coverage detected