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

Method SolvePositionConstraints

DynamicsB2JointRevolute.go:375–455  ·  view source on GitHub ↗
(data B2SolverData)

Source from the content-addressed store, hash-verified

373}
374
375func (joint *B2RevoluteJoint) SolvePositionConstraints(data B2SolverData) bool {
376 cA := data.Positions[joint.M_indexA].C
377 aA := data.Positions[joint.M_indexA].A
378 cB := data.Positions[joint.M_indexB].C
379 aB := data.Positions[joint.M_indexB].A
380
381 qA := MakeB2RotFromAngle(aA)
382 qB := MakeB2RotFromAngle(aB)
383
384 angularError := 0.0
385 positionError := 0.0
386
387 fixedRotation := (joint.M_invIA+joint.M_invIB == 0.0)
388
389 // Solve angular limit constraint.
390 if joint.M_enableLimit && joint.M_limitState != B2LimitState.E_inactiveLimit && fixedRotation == false {
391 angle := aB - aA - joint.M_referenceAngle
392 limitImpulse := 0.0
393
394 if joint.M_limitState == B2LimitState.E_equalLimits {
395 // Prevent large angular corrections
396 C := B2FloatClamp(angle-joint.M_lowerAngle, -B2_maxAngularCorrection, B2_maxAngularCorrection)
397 limitImpulse = -joint.M_motorMass * C
398 angularError = math.Abs(C)
399 } else if joint.M_limitState == B2LimitState.E_atLowerLimit {
400 C := angle - joint.M_lowerAngle
401 angularError = -C
402
403 // Prevent large angular corrections and allow some slop.
404 C = B2FloatClamp(C+B2_angularSlop, -B2_maxAngularCorrection, 0.0)
405 limitImpulse = -joint.M_motorMass * C
406 } else if joint.M_limitState == B2LimitState.E_atUpperLimit {
407 C := angle - joint.M_upperAngle
408 angularError = C
409
410 // Prevent large angular corrections and allow some slop.
411 C = B2FloatClamp(C-B2_angularSlop, 0.0, B2_maxAngularCorrection)
412 limitImpulse = -joint.M_motorMass * C
413 }
414
415 aA -= joint.M_invIA * limitImpulse
416 aB += joint.M_invIB * limitImpulse
417 }
418
419 // Solve point-to-point constraint.
420 {
421 qA.Set(aA)
422 qB.Set(aB)
423 rA := B2RotVec2Mul(qA, B2Vec2Sub(joint.M_localAnchorA, joint.M_localCenterA))
424 rB := B2RotVec2Mul(qB, B2Vec2Sub(joint.M_localAnchorB, joint.M_localCenterB))
425
426 C := B2Vec2Sub(B2Vec2Sub(B2Vec2Add(cB, rB), cA), rA)
427 positionError = C.Length()
428
429 mA := joint.M_invMassA
430 mB := joint.M_invMassB
431 iA := joint.M_invIA
432 iB := joint.M_invIB

Callers

nothing calls this directly

Calls 13

SolveMethod · 0.95
MakeB2RotFromAngleFunction · 0.85
B2FloatClampFunction · 0.85
B2RotVec2MulFunction · 0.85
B2Vec2SubFunction · 0.85
B2Vec2AddFunction · 0.85
B2Vec2MulScalarFunction · 0.85
B2Vec2CrossFunction · 0.85
LengthMethod · 0.80
SetMethod · 0.45
OperatorNegateMethod · 0.45
OperatorMinusInplaceMethod · 0.45

Tested by

no test coverage detected