public bool IsIntersectingLine(Vector3 begin, Vector3 end) { Vector3 tl, tr, bl, br; GenerationUtility.BoxBounds(this.Start.Position, this.End.Position, this.Width, out tl, out tr, out bl, out br); if (GenerationUtility.PointInBox(begin, tl, tr, bl, br) || GenerationUtility.PointInBox(end, tl, tr, bl, br)) { return(true); } return(GenerationUtility.CheckBoxLineIntersection(begin, end, tl, tr, bl, br)); }
public IEnumerator RasterizeLayer(MiddleLayer l, Floor upper, Floor lower) { Square[,,,] squares = l.Squares; Vector3 tl, tr, bl, br; foreach (LayerPath p in l.Paths) { //if (p.Start is CircleRoom) //{ // CircleRoom circle = (CircleRoom)p.Start; // RasterizeCircle(squares, l.rasterizationGrid, circle.Position, circle.Radius); //} //else //{ // RectangleRoom rect = (RectangleRoom)p.Start; // rect.BoxBounds(out tl, out tr, out bl, out br); // RasterizeBox(squares, l.rasterizationGrid, tl, tr, bl, br); //} //if (p.End is CircleRoom) //{ // CircleRoom circle = (CircleRoom)p.End; // RasterizeCircle(squares, l.rasterizationGrid, circle.Position, circle.Radius); //} //else //{ // RectangleRoom rect = (RectangleRoom)p.End; // rect.BoxBounds(out tl, out tr, out bl, out br); // RasterizeBox(squares, l.rasterizationGrid, tl, tr, bl, br); //} GenerationUtility.BoxBounds(p.Start.Position, p.End.Position, p.Width, out tl, out tr, out bl, out br); RasterizeBox(squares, l.rasterizationGrid, tl, tr, bl, br); yield return(null); } foreach (LayerPath p in l.Paths) { Vector3 start = GetRoomEdgePoint(p.Start, p); Vector3 end = GetRoomEdgePoint(p.End, p); MarkForKeeping(squares, l.rasterizationGrid, start, end, p.Width); ReserveGridSquares(upper, start, Vector3.Lerp(start, end, .02f), p.Width); ReserveGridSquares(lower, Vector3.Lerp(start, end, .98f), end, p.Width); Vector3 startHeight = l.transform.InverseTransformPoint(p.Start.WorldPosition); Vector3 endHeight = l.transform.InverseTransformPoint(p.End.WorldPosition); RaiseMesh(squares, l.rasterizationGrid, start, end, p.Width, startHeight, endHeight); yield return(null); } l.Squares = squares; }
public bool IsIntersectingCircle(Vector3 center, float radius) { Vector3 tl, tr, bl, br; GenerationUtility.BoxBounds(this.Start.Position, this.End.Position, this.Width, out tl, out tr, out bl, out br); if (GenerationUtility.PointInCircle(tl, center, radius)) { return(true); } if (GenerationUtility.PointInCircle(tr, center, radius)) { return(true); } if (GenerationUtility.PointInCircle(bl, center, radius)) { return(true); } if (GenerationUtility.PointInCircle(br, center, radius)) { return(true); } if (GenerationUtility.CheckCircleLineIntersection(tl, tr, center, radius)) { return(true); } if (GenerationUtility.CheckCircleLineIntersection(bl, br, center, radius)) { return(true); } if (GenerationUtility.CheckCircleLineIntersection(tl, bl, center, radius)) { return(true); } if (GenerationUtility.CheckCircleLineIntersection(tr, br, center, radius)) { return(true); } return(GenerationUtility.PointInBox(center, tl, tr, bl, br)); }
private void ReserveGridSquares(Floor floor, Vector3 start, Vector3 end, float width) { RasterizationGrid rast = floor.rasterizationGrid; Square[,,,] squares = floor.Squares; Vector3 tl, tr, bl, br; GenerationUtility.BoxBounds(start, end, width, out tl, out tr, out bl, out br); float left = Mathf.Min(tl.x, tr.x, bl.x, br.x); float right = Mathf.Max(tl.x, tr.x, bl.x, br.x); float up = Mathf.Max(tl.y, tr.y, bl.y, br.y); float down = Mathf.Min(tl.y, tr.y, bl.y, br.y); Vector2 topLeft = new Vector2(left, up); Vector2 bottomRight = new Vector2(right, down); int sectorTop = rast.SectorColumn(topLeft); int sectorBottom = rast.SectorColumn(bottomRight); int sectorLeft = rast.SectorRow(topLeft); int sectorRight = rast.SectorRow(bottomRight); for (int sr = sectorLeft; sr <= sectorRight; sr++) { for (int sc = sectorTop; sc <= sectorBottom; sc++) { Vector2Int sector = new Vector2Int(sr, sc); int gridTop = rast.GridColumn(sector, topLeft); int gridBottom = rast.GridColumn(sector, bottomRight); int gridLeft = rast.GridRow(sector, topLeft); int gridRight = rast.GridRow(sector, bottomRight); for (int gr = gridLeft; gr <= gridRight; gr++) { for (int gc = gridTop; gc <= gridBottom; gc++) { bool a = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].TopLeft.Position, tl, tr, bl, br); bool b = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].TopRight.Position, tl, tr, bl, br); bool c = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].BottomLeft.Position, tl, tr, bl, br); bool d = GenerationUtility.PointInBox(squares[sr, sc, gr, gc].BottomRight.Position, tl, tr, bl, br); if (a || b || c || d) { squares[sr, sc, gr, gc].Reserved = true; } } } } } }
public IEnumerator RasterizeFloor(Floor f) { Square[,,,] squares = f.Squares; foreach (Room room in f.Rooms) { if (room is CircleRoom) { CircleRoom circle = (CircleRoom)room; RasterizeCircle(squares, f.rasterizationGrid, circle.Position, circle.Radius); } else { RectangleRoom rect = (RectangleRoom)room; Vector3 tl, tr, bl, br; rect.BoxBounds(out tl, out tr, out bl, out br); RasterizeBox(squares, f.rasterizationGrid, tl, tr, bl, br); } } yield return(null); if (f.Paths != null) { foreach (FloorPath p in f.Paths) { foreach (Edge e in p.Edges) { Vector3 tl, tr, bl, br; GenerationUtility.BoxBounds(e.Start, e.End, e.Width, out tl, out tr, out bl, out br); RasterizeBox(squares, f.rasterizationGrid, tl, tr, bl, br); if (!e.TailEdge) { RasterizeCircle(squares, f.rasterizationGrid, e.End, e.Width / 2f); } } } } f.Squares = squares; }
private void RaiseMesh(Square[,,,] squares, RasterizationGrid rast, Vector3 start, Vector3 end, float width, Vector3 startHeight, Vector3 endHeight) { Vector3 tl, tr, bl, br; GenerationUtility.BoxBounds(start, end, width, out tl, out tr, out bl, out br); float left = Mathf.Min(tl.x, tr.x, bl.x, br.x); float right = Mathf.Max(tl.x, tr.x, bl.x, br.x); float up = Mathf.Max(tl.y, tr.y, bl.y, br.y); float down = Mathf.Min(tl.y, tr.y, bl.y, br.y); Vector2 topLeft = new Vector2(left, up); Vector2 bottomRight = new Vector2(right, down); int sectorTop = rast.SectorColumn(topLeft); int sectorBottom = rast.SectorColumn(bottomRight); int sectorLeft = rast.SectorRow(topLeft); int sectorRight = rast.SectorRow(bottomRight); for (int sr = sectorLeft; sr <= sectorRight; sr++) { for (int sc = sectorTop; sc <= sectorBottom; sc++) { Vector2Int sector = new Vector2Int(sr, sc); int gridTop = rast.GridColumn(sector, topLeft); int gridBottom = rast.GridColumn(sector, bottomRight); int gridLeft = rast.GridRow(sector, topLeft); int gridRight = rast.GridRow(sector, bottomRight); for (int gr = gridLeft; gr <= gridRight; gr++) { for (int gc = gridTop; gc <= gridBottom; gc++) { if (squares[sr, sc, gr, gc].Marked) { squares[sr, sc, gr, gc].SetZHeight(startHeight, endHeight); } } } } } }
/// <summary> Checks if the given edge is blocked. </summary> /// <param name="begin"> The start of the edge. </param> /// <param name="end"> The end of the edge. </param> /// <param name="r1"> The starting room of the path. </param> /// <param name="r2"> The ending room of the path. </param> /// <param name="floor"> The floor this path is on. </param> /// <param name="upperLayer"> The Layer above this path's floor. </param> /// <param name="lowerLayer"> The layer below this path's floor. </param> /// <returns> True if there is something blocking this edge. </returns> private bool CheckEdgeBlocked(Vector3 begin, Vector3 end, Room r1, Room r2, Floor floor, MiddleLayer upperLayer, MiddleLayer lowerLayer) { Vector3 tl, tr, bl, br; GenerationUtility.BoxBounds(begin, end, this.pathWidth, out tl, out tr, out bl, out br); foreach (Room r in floor.Rooms) { if (r != r1 && r != r2) { if (r.IsIntersectingLine(tl, bl)) { return(true); } if (r.IsIntersectingLine(tr, br)) { return(true); } } } if (upperLayer != null) { foreach (LayerPath l in upperLayer.Paths) { if (l.IsIntersectingLine(tl, bl)) { Vector3 pos = GenerationUtility.LineLineIntersection(tl, bl, l.Start.Position, l.End.Position); bool inRoom = IsInRoom(pos, l.Start, l.End); if (!inRoom) { return(true); } } if (l.IsIntersectingLine(tr, br)) { Vector3 pos = GenerationUtility.LineLineIntersection(tr, br, l.Start.Position, l.End.Position); bool inRoom = IsInRoom(pos, l.Start, l.End); if (!inRoom) { return(true); } } } } if (lowerLayer != null) { foreach (LayerPath l in lowerLayer.Paths) { if (l.IsIntersectingLine(tl, bl)) { Vector3 pos = GenerationUtility.LineLineIntersection(tl, bl, l.Start.Position, l.End.Position); bool inRoom = IsInRoom(pos, l.Start, l.End); if (!inRoom) { return(true); } } if (l.IsIntersectingLine(tr, br)) { Vector3 pos = GenerationUtility.LineLineIntersection(tr, br, l.Start.Position, l.End.Position); bool inRoom = IsInRoom(pos, l.Start, l.End); if (!inRoom) { return(true); } } } } return(false); }