Find the separation between poly1 and poly2 for a give edge normal on poly1.
| 21 | |
| 22 | // Find the separation between poly1 and poly2 for a give edge normal on poly1. |
| 23 | static float32 b2EdgeSeparation(const b2PolygonShape* poly1, const b2Transform& xf1, int32 edge1, |
| 24 | const b2PolygonShape* poly2, const b2Transform& xf2) |
| 25 | { |
| 26 | const b2Vec2* vertices1 = poly1->m_vertices; |
| 27 | const b2Vec2* normals1 = poly1->m_normals; |
| 28 | |
| 29 | int32 count2 = poly2->m_count; |
| 30 | const b2Vec2* vertices2 = poly2->m_vertices; |
| 31 | |
| 32 | b2Assert(0 <= edge1 && edge1 < poly1->m_count); |
| 33 | |
| 34 | // Convert normal from poly1's frame into poly2's frame. |
| 35 | b2Vec2 normal1World = b2Mul(xf1.q, normals1[edge1]); |
| 36 | b2Vec2 normal1 = b2MulT(xf2.q, normal1World); |
| 37 | |
| 38 | // Find support vertex on poly2 for -normal. |
| 39 | int32 index = 0; |
| 40 | float32 minDot = b2_maxFloat; |
| 41 | |
| 42 | for (int32 i = 0; i < count2; ++i) |
| 43 | { |
| 44 | float32 dot = b2Dot(vertices2[i], normal1); |
| 45 | if (dot < minDot) |
| 46 | { |
| 47 | minDot = dot; |
| 48 | index = i; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | b2Vec2 v1 = b2Mul(xf1, vertices1[edge1]); |
| 53 | b2Vec2 v2 = b2Mul(xf2, vertices2[index]); |
| 54 | float32 separation = b2Dot(v2 - v1, normal1World); |
| 55 | return separation; |
| 56 | } |
| 57 | |
| 58 | // Find the max separation between poly1 and poly2 using edge normals from poly1. |
| 59 | static float32 b2FindMaxSeparation(int32* edgeIndex, |
no test coverage detected