public override Geometry.Polygon ToPolygon() { List <Vector2> coneSegemnts = new List <Vector2>(); for (float i = -OwnSpellData.ConeAngle / 2f; i <= OwnSpellData.ConeAngle / 2f; i++) { coneSegemnts.Add(RotateAroundPoint(FixedStartPos.To2D(), FixedEndPos.To2D(), i * (float)Math.PI / 180)); } if (Missile != null) { var beginPoints = GetBeginEdgePoints(new[] { coneSegemnts.First(), coneSegemnts.Last() }); coneSegemnts.Insert(0, beginPoints[0]); coneSegemnts.Insert(0, beginPoints[1]); } else { coneSegemnts.Insert(0, FixedStartPos.To2D()); } Geometry.Polygon polygon = new Geometry.Polygon(); polygon.Points.AddRange(coneSegemnts); return(polygon); }
public Geometry.Polygon ToSimplePolygon() { var poly = new Geometry.Polygon(); poly.Add(RotateAroundPoint(FixedStartPos.To2D(), FixedEndPos.To2D(), -OwnSpellData.ConeAngle / 2f * (float)Math.PI / 180)); poly.Add(RotateAroundPoint(FixedStartPos.To2D(), FixedEndPos.To2D(), +OwnSpellData.ConeAngle / 2f * (float)Math.PI / 180)); poly.Add(FixedStartPos); return(poly); }
Vector2[] GetBeginEdgePoints(Vector2[] edges) { var endEdges = edges; Vector2 direction = (FixedEndPos - FixedStartPos).To2D(); var perpVecStart = CurrentPos.To2D() + direction.Normalized().Perpendicular(); var perpVecEnd = CurrentPos.To2D() + direction.Normalized().Perpendicular() * 1500; //right side is not the same? var perpVecStart2 = CurrentPos.To2D() + direction.Normalized().Perpendicular2(); var perpVecEnd2 = CurrentPos.To2D() + direction.Normalized().Perpendicular2() * 1500; Geometry.Polygon.Line leftEdgeLine = new Geometry.Polygon.Line(FixedStartPos.To2D(), endEdges[1]); Geometry.Polygon.Line rightEdgeLine = new Geometry.Polygon.Line(FixedStartPos.To2D(), endEdges[0]); var inters = leftEdgeLine.GetIntersectionPointsWithLineSegment(perpVecStart, perpVecEnd); var inters2 = rightEdgeLine.GetIntersectionPointsWithLineSegment(perpVecStart2, perpVecEnd2); Vector2 p1 = Vector2.Zero, p2 = Vector2.Zero; if (inters.Any()) { var closestInter = inters.OrderBy(x => x.Distance(CurrentPos)).First(); p2 = closestInter; } if (inters2.Any()) { var closestInter = inters2.OrderBy(x => x.Distance(CurrentPos)).First(); p1 = closestInter; } if (!p1.IsZero && !p2.IsZero) { return new[] { p1, p2 } } ; return(new[] { CurrentPos.To2D(), CurrentPos.To2D() }); }