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

Method Initialize

DynamicsB2ContactSolver.go:692–733  ·  view source on GitHub ↗
(pc *B2ContactPositionConstraint, xfA B2Transform, xfB B2Transform, index int)

Source from the content-addressed store, hash-verified

690}
691
692func (solvermanifold *B2PositionSolverManifold) Initialize(pc *B2ContactPositionConstraint, xfA B2Transform, xfB B2Transform, index int) {
693
694 B2Assert(pc.PointCount > 0)
695
696 switch pc.Type {
697 case B2Manifold_Type.E_circles:
698 {
699 pointA := B2TransformVec2Mul(xfA, pc.LocalPoint)
700 pointB := B2TransformVec2Mul(xfB, pc.LocalPoints[0])
701 solvermanifold.Normal = B2Vec2Sub(pointB, pointA)
702 solvermanifold.Normal.Normalize()
703 solvermanifold.Point = B2Vec2MulScalar(0.5, B2Vec2Add(pointA, pointB))
704 solvermanifold.Separation = B2Vec2Dot(B2Vec2Sub(pointB, pointA), solvermanifold.Normal) - pc.RadiusA - pc.RadiusB
705 }
706 break
707
708 case B2Manifold_Type.E_faceA:
709 {
710 solvermanifold.Normal = B2RotVec2Mul(xfA.Q, pc.LocalNormal)
711 planePoint := B2TransformVec2Mul(xfA, pc.LocalPoint)
712
713 clipPoint := B2TransformVec2Mul(xfB, pc.LocalPoints[index])
714 solvermanifold.Separation = B2Vec2Dot(B2Vec2Sub(clipPoint, planePoint), solvermanifold.Normal) - pc.RadiusA - pc.RadiusB
715 solvermanifold.Point = clipPoint
716 }
717 break
718
719 case B2Manifold_Type.E_faceB:
720 {
721 solvermanifold.Normal = B2RotVec2Mul(xfB.Q, pc.LocalNormal)
722 planePoint := B2TransformVec2Mul(xfB, pc.LocalPoint)
723
724 clipPoint := B2TransformVec2Mul(xfA, pc.LocalPoints[index])
725 solvermanifold.Separation = B2Vec2Dot(B2Vec2Sub(clipPoint, planePoint), solvermanifold.Normal) - pc.RadiusA - pc.RadiusB
726 solvermanifold.Point = clipPoint
727
728 // Ensure normal points from A to B
729 solvermanifold.Normal = solvermanifold.Normal.OperatorNegate()
730 }
731 break
732 }
733}
734
735// Sequential solver.
736func (solver *B2ContactSolver) SolvePositionConstraints() bool {

Calls 9

B2AssertFunction · 0.85
B2TransformVec2MulFunction · 0.85
B2Vec2SubFunction · 0.85
B2Vec2MulScalarFunction · 0.85
B2Vec2AddFunction · 0.85
B2Vec2DotFunction · 0.85
B2RotVec2MulFunction · 0.85
NormalizeMethod · 0.45
OperatorNegateMethod · 0.45

Tested by

no test coverage detected