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

Method SolvePositionConstraints

DynamicsB2ContactSolver.go:736–815  ·  view source on GitHub ↗

Sequential solver.

()

Source from the content-addressed store, hash-verified

734
735// Sequential solver.
736func (solver *B2ContactSolver) SolvePositionConstraints() bool {
737
738 minSeparation := 0.0
739
740 for i := 0; i < solver.M_count; i++ {
741 pc := &solver.M_positionConstraints[i]
742
743 indexA := pc.IndexA
744 indexB := pc.IndexB
745 localCenterA := pc.LocalCenterA
746 mA := pc.InvMassA
747 iA := pc.InvIA
748 localCenterB := pc.LocalCenterB
749 mB := pc.InvMassB
750 iB := pc.InvIB
751 pointCount := pc.PointCount
752
753 cA := solver.M_positions[indexA].C
754 aA := solver.M_positions[indexA].A
755
756 cB := solver.M_positions[indexB].C
757 aB := solver.M_positions[indexB].A
758
759 // Solve normal constraints
760 for j := 0; j < pointCount; j++ {
761 xfA := MakeB2Transform()
762 xfB := MakeB2Transform()
763
764 xfA.Q.Set(aA)
765 xfB.Q.Set(aB)
766 xfA.P = B2Vec2Sub(cA, B2RotVec2Mul(xfA.Q, localCenterA))
767 xfB.P = B2Vec2Sub(cB, B2RotVec2Mul(xfB.Q, localCenterB))
768
769 psm := MakeB2PositionSolverManifold()
770 psm.Initialize(pc, xfA, xfB, j)
771 normal := psm.Normal
772
773 point := psm.Point
774 separation := psm.Separation
775
776 rA := B2Vec2Sub(point, cA)
777 rB := B2Vec2Sub(point, cB)
778
779 // Track max constraint error.
780 minSeparation = math.Min(minSeparation, separation)
781
782 // Prevent large corrections and allow slop.
783 C := B2FloatClamp(B2_baumgarte*(separation+B2_linearSlop), -B2_maxLinearCorrection, 0.0)
784
785 // Compute the effective mass.
786 rnA := B2Vec2Cross(rA, normal)
787 rnB := B2Vec2Cross(rB, normal)
788 K := mA + mB + iA*rnA*rnA + iB*rnB*rnB
789
790 // Compute normal impulse
791 impulse := 0.0
792 if K > 0.0 {
793 impulse = -C / K

Callers

nothing calls this directly

Calls 11

MakeB2TransformFunction · 0.85
B2Vec2SubFunction · 0.85
B2RotVec2MulFunction · 0.85
B2FloatClampFunction · 0.85
B2Vec2CrossFunction · 0.85
B2Vec2MulScalarFunction · 0.85
SetMethod · 0.45
InitializeMethod · 0.45
OperatorMinusInplaceMethod · 0.45
OperatorPlusInplaceMethod · 0.45

Tested by

no test coverage detected