public static void Fracture(Destroyable destructible, int count, float irregularity) { if (destructible != null && count > 0) { DestroyableSplitGroup.ClearAll(); { var width = destructible.AlphaWidth; var height = destructible.AlphaHeight; var mainQuad = new DestroyableQuad(); quadCount = 1; pointCount = 0; xMin = 0; xMax = width - 1; yMin = 0; yMax = height - 1; mainQuad.BL = new DestroyableVector2Operator(xMin, yMin); mainQuad.BR = new DestroyableVector2Operator(xMax, yMin); mainQuad.TL = new DestroyableVector2Operator(xMin, yMax); mainQuad.TR = new DestroyableVector2Operator(xMax, yMax); mainQuad.Calculate(); if (quads.Count > 0) { quads[0] = mainQuad; } else { quads.Add(mainQuad); } for (var i = 0; i < count; i++) { SplitLargest(); } if (irregularity > 0.0f) { FindPoints(); ShiftPoints(irregularity); } for (var i = 0; i < quadCount; i++) { var quad = quads[i]; var group = DestroyableSplitGroup.GetSplitGroup(); group.AddTriangle(quad.BL, quad.BR, quad.TL); group.AddTriangle(quad.TR, quad.TL, quad.BR); } destructible.SplitWhole(DestroyableSplitGroup.SplitGroups); } DestroyableSplitGroup.ClearAll(); } }
public void Submit(DestroyableDistanceField baseField, DestroyableSplitGroup splitGroup, DestroyableRect baseRect, DestroyableRect rect) { distanceField.Transform(rect, this); for (var y = rect.MinY; y < rect.MaxY; y++) { for (var x = rect.MinX; x < rect.MaxX; x++) { var cell = distanceField.Cells[x - rect.MinX + (y - rect.MinY) * rect.SizeX]; var baseCell = baseField.Cells[x - baseRect.MinX + (y - baseRect.MinY) * baseRect.SizeX]; if (cell.D == baseCell.D) { splitGroup.AddPixel(x, y); } } } }