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

Method ComputePolygonSeparation

CollisionB2CollideEdge.go:561–604  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

559}
560
561func (collider *B2EPCollider) ComputePolygonSeparation() B2EPAxis {
562
563 axis := MakeB2EPAxis()
564 axis.Type = B2EPAxis_Type.E_unknown
565 axis.Index = -1
566 axis.Separation = -B2_maxFloat
567
568 perp := MakeB2Vec2(-collider.M_normal.Y, collider.M_normal.X)
569
570 for i := 0; i < collider.M_polygonB.Count; i++ {
571 n := collider.M_polygonB.Normals[i].OperatorNegate()
572
573 s1 := B2Vec2Dot(n, B2Vec2Sub(collider.M_polygonB.Vertices[i], collider.M_v1))
574 s2 := B2Vec2Dot(n, B2Vec2Sub(collider.M_polygonB.Vertices[i], collider.M_v2))
575 s := math.Min(s1, s2)
576
577 if s > collider.M_radius {
578 // No collision
579 axis.Type = B2EPAxis_Type.E_edgeB
580 axis.Index = i
581 axis.Separation = s
582 return axis
583 }
584
585 // Adjacency
586 if B2Vec2Dot(n, perp) >= 0.0 {
587 if B2Vec2Dot(B2Vec2Sub(n, collider.M_upperLimit), collider.M_normal) < -B2_angularSlop {
588 continue
589 }
590 } else {
591 if B2Vec2Dot(B2Vec2Sub(n, collider.M_lowerLimit), collider.M_normal) < -B2_angularSlop {
592 continue
593 }
594 }
595
596 if s > axis.Separation {
597 axis.Type = B2EPAxis_Type.E_edgeB
598 axis.Index = i
599 axis.Separation = s
600 }
601 }
602
603 return axis
604}
605
606func B2CollideEdgeAndPolygon(manifold *B2Manifold, edgeA *B2EdgeShape, xfA B2Transform, polygonB *B2PolygonShape, xfB B2Transform) {
607 collider := MakeB2EPCollider()

Callers 1

CollideMethod · 0.95

Calls 5

MakeB2EPAxisFunction · 0.85
MakeB2Vec2Function · 0.85
B2Vec2DotFunction · 0.85
B2Vec2SubFunction · 0.85
OperatorNegateMethod · 0.45

Tested by

no test coverage detected