Sequential solver.
()
| 734 | |
| 735 | // Sequential solver. |
| 736 | func (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 |
nothing calls this directly
no test coverage detected