public override float ComputeSubmergedArea(Vector2 normal, float offset, Transform xf, out Vector2 c)
{
//Note that v0 is independent of any details of the specific edge
//We are relying on v0 being consistent between multiple edges of the same body
Vector2 v0 = offset * normal;
//b2Vec2 v0 = xf.position + (offset - b2Dot(normal, xf.position)) * normal;
Vector2 v1 = xf.TransformPoint(_v1);
Vector2 v2 = xf.TransformPoint(_v2);
float d1 = Vector2.Dot(normal, v1) - offset;
float d2 = Vector2.Dot(normal, v2) - offset;
if (d1 > 0.0f)
{
if (d2 > 0.0f)
{
c = new Vector2();
return 0.0f;
}
else
{
v1 = -d2 / (d1 - d2) * v1 + d1 / (d1 - d2) * v2;
}
}
else
{
if (d2 > 0.0f)
{
v2 = -d2 / (d1 - d2) * v1 + d1 / (d1 - d2) * v2;
}
else
{
//Nothing
}
}
// v0,v1,v2 represents a fully submerged triangle
float k_inv3 = 1.0f / 3.0f;
// Area weighted centroid
c = k_inv3 * (v0 + v1 + v2);
Vector2 e1 = v1 - v0;
Vector2 e2 = v2 - v0;
return 0.5f * e1.Cross(e2);
}