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

Function B2CollidePolygons

CollisionB2CollidePolygon.go:90–213  ·  view source on GitHub ↗

Find edge normal of max separation on A - return if separating axis is found Find edge normal of max separation on B - return if separation axis is found Choose reference edge as min(minA, minB) Find incident edge Clip The normal points from 1 to 2

(manifold *B2Manifold, polyA *B2PolygonShape, xfA B2Transform, polyB *B2PolygonShape, xfB B2Transform)

Source from the content-addressed store, hash-verified

88
89// The normal points from 1 to 2
90func B2CollidePolygons(manifold *B2Manifold, polyA *B2PolygonShape, xfA B2Transform, polyB *B2PolygonShape, xfB B2Transform) {
91
92 manifold.PointCount = 0
93 totalRadius := polyA.M_radius + polyB.M_radius
94
95 edgeA := 0
96 separationA := B2FindMaxSeparation(&edgeA, polyA, xfA, polyB, xfB)
97 if separationA > totalRadius {
98 return
99 }
100
101 edgeB := 0
102 separationB := B2FindMaxSeparation(&edgeB, polyB, xfB, polyA, xfA)
103 if separationB > totalRadius {
104 return
105 }
106
107 var poly1 *B2PolygonShape // reference polygon
108 var poly2 *B2PolygonShape // incident polygon
109
110 xf1 := MakeB2Transform()
111 xf2 := MakeB2Transform()
112
113 edge1 := 0 // reference edge
114 var flip uint8
115 k_tol := 0.1 * B2_linearSlop
116
117 if separationB > separationA+k_tol {
118 poly1 = polyB
119 poly2 = polyA
120 xf1 = xfB
121 xf2 = xfA
122 edge1 = edgeB
123 manifold.Type = B2Manifold_Type.E_faceB
124 flip = 1
125 } else {
126 poly1 = polyA
127 poly2 = polyB
128 xf1 = xfA
129 xf2 = xfB
130 edge1 = edgeA
131 manifold.Type = B2Manifold_Type.E_faceA
132 flip = 0
133 }
134
135 incidentEdge := make([]B2ClipVertex, 2)
136 B2FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2)
137
138 count1 := poly1.M_count
139 vertices1 := poly1.M_vertices
140
141 iv1 := edge1
142 iv2 := 0
143 if edge1+1 < count1 {
144 iv2 = edge1 + 1
145 }
146
147 v11 := vertices1[iv1]

Callers 1

EvaluateMethod · 0.85

Calls 14

B2FindMaxSeparationFunction · 0.85
MakeB2TransformFunction · 0.85
B2FindIncidentEdgeFunction · 0.85
B2Vec2SubFunction · 0.85
B2Vec2CrossVectorScalarFunction · 0.85
B2Vec2MulScalarFunction · 0.85
B2Vec2AddFunction · 0.85
B2RotVec2MulFunction · 0.85
B2TransformVec2MulFunction · 0.85
B2Vec2DotFunction · 0.85
B2ClipSegmentToLineFunction · 0.85
B2TransformVec2MulTFunction · 0.85

Tested by

no test coverage detected