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

Function B2Distance

CollisionB2Distance.go:566–708  ·  view source on GitHub ↗
(output *B2DistanceOutput, cache *B2SimplexCache, input *B2DistanceInput)

Source from the content-addressed store, hash-verified

564}
565
566func B2Distance(output *B2DistanceOutput, cache *B2SimplexCache, input *B2DistanceInput) {
567 b2_gjkCalls++
568
569 proxyA := &input.ProxyA
570 proxyB := &input.ProxyB
571
572 transformA := input.TransformA
573 transformB := input.TransformB
574
575 // Initialize the simplex.
576 simplex := MakeB2Simplex()
577 simplex.ReadCache(cache, proxyA, transformA, proxyB, transformB)
578
579 // Get simplex vertices as an array.
580 vertices := &simplex.M_vs
581 k_maxIters := 20
582
583 // These store the vertices of the last simplex so that we
584 // can check for duplicates and prevent cycling.
585 saveA := make([]int, 3)
586 saveB := make([]int, 3)
587 saveCount := 0
588
589 // Main iteration loop.
590 iter := 0
591 for iter < k_maxIters {
592 // Copy simplex so we can identify duplicates.
593 saveCount = simplex.M_count
594 for i := 0; i < saveCount; i++ {
595 saveA[i] = vertices[i].IndexA
596 saveB[i] = vertices[i].IndexB
597 }
598
599 switch simplex.M_count {
600 case 1:
601 break
602
603 case 2:
604 simplex.Solve2()
605 break
606
607 case 3:
608 simplex.Solve3()
609 break
610
611 default:
612 B2Assert(false)
613 }
614
615 // If we have 3 points, then the origin is in the corresponding triangle.
616 if simplex.M_count == 3 {
617 break
618 }
619
620 // Get search direction.
621 d := simplex.GetSearchDirection()
622
623 // Ensure the search direction is numerically fit.

Callers 2

B2TimeOfImpactFunction · 0.85
B2TestOverlapShapesFunction · 0.85

Calls 15

MakeB2SimplexFunction · 0.85
B2AssertFunction · 0.85
B2RotVec2MulTFunction · 0.85
B2TransformVec2MulFunction · 0.85
B2Vec2SubFunction · 0.85
B2Vec2DistanceFunction · 0.85
B2Vec2MulScalarFunction · 0.85
B2Vec2AddFunction · 0.85
ReadCacheMethod · 0.80
Solve2Method · 0.80
Solve3Method · 0.80
GetSearchDirectionMethod · 0.80

Tested by

no test coverage detected