DragInfo IGlobalFluidAffectable.GetFluidInfo(Vector2D tangent) { Scalar min, max; ShapeHelper.GetProjectedBounds(this.Vertexes, tangent, out min, out max); Scalar avg = (max + min) / 2; return(new DragInfo(tangent * avg, max - min)); }
public static void GetFluidInfo(Vector2D[][] polygons, Vector2D tangent, out Vector2D dragCenter, out Scalar dragArea) { Scalar min, max; Scalar avg; if (polygons.Length == 1) { ShapeHelper.GetProjectedBounds( polygons[0], tangent, out min, out max); avg = (max + min) / 2; dragCenter = tangent * avg; dragArea = max - min; return; } SAPNode[] sapNodes = new SAPNode[polygons.Length * 2]; for (int index = 0; index < polygons.Length; ++index) { ShapeHelper.GetProjectedBounds(polygons[index], tangent, out min, out max); sapNodes[index * 2] = new SAPNode(min, true); sapNodes[(index * 2) + 1] = new SAPNode(max, false); } Array.Sort <SAPNode>(sapNodes, comparer); int depth = 0; Scalar result = 0; Scalar start = 0; for (int index = 0; index < sapNodes.Length; ++index) { SAPNode node = sapNodes[index]; if (node.begin) { if (depth == 0) { start = node.value; } depth++; } else { depth--; if (depth == 0) { result += node.value - start; } } } avg = (sapNodes[0].value + sapNodes[sapNodes.Length - 1].value) / 2; dragCenter = tangent * avg; dragArea = result; }
DragInfo IExplosionAffectable.GetExplosionInfo(Matrix2x3 matrix, Scalar radius, GetTangentCallback callback) { Vector2D[] vertexes2 = new Vector2D[Vertexes.Length]; for (int index = 0; index < vertexes2.Length; ++index) { vertexes2[index] = matrix * Vertexes[index]; } Vector2D[] inter = ShapeHelper.GetIntersection(vertexes2, radius); if (inter.Length < 3) { return(null); } Vector2D centroid = PolygonShape.GetCentroid(inter); Vector2D tangent = callback(centroid); Scalar min, max; ShapeHelper.GetProjectedBounds(inter, tangent, out min, out max); Scalar avg = (max + min) / 2; return(new DragInfo(tangent * avg, max - min)); }
public static FluidInfo GetFluidInfo(Vector2D[] vertexes2, GetTangentCallback callback, Line line) { Vector2D centroid; Scalar area; Vector2D dragCenter; Scalar dragArea; Vector2D[] vertexes = ShapeHelper.GetIntersection(vertexes2, line); if (vertexes.Length < 3) { return(null); } centroid = PolygonShape.GetCentroid(vertexes); area = PolygonShape.GetArea(vertexes); Vector2D tangent = callback(centroid); Scalar min, max; ShapeHelper.GetProjectedBounds(vertexes, tangent, out min, out max); Scalar avg = (max + min) / 2; dragCenter = tangent * avg; dragArea = max - min; return(new FluidInfo(dragCenter, dragArea, centroid, area)); }