[otwarty teren] wydzielenie generowania ze skryptow unity part 5
This commit is contained in:
parent
b06f9f1887
commit
cfc5bf47cf
@ -19,8 +19,8 @@ namespace Assets.Common
|
||||
public Point Center { get; set; }
|
||||
public bool IsOuter { get; set; } = false;
|
||||
public IEnumerable<int> Boundary { get; set; }
|
||||
// public IEnumerable<(int, int)> Edges => Boundary.Append(Boundary.First()).Zip(Boundary.RotateRight(), (a, b) => (a, b));
|
||||
public IEnumerable<(int, int)> Edges { get; set; }
|
||||
public IEnumerable<(int, int)> Edges => Boundary.RotateRight().Zip(Boundary, (a, b) => (a, b));
|
||||
// public IEnumerable<(int, int)> Edges { get; set; }
|
||||
|
||||
[field: NonSerialized]
|
||||
public Map Map { get; internal set; }
|
||||
|
@ -26,7 +26,12 @@ namespace Assets.Common
|
||||
a = a - center;
|
||||
b = b - center;
|
||||
|
||||
return Math.Acos((a.x*b.x+a.y*b.y)/(a.Length * b.Length));
|
||||
var dot = a.x * b.x + a.y * b.y;
|
||||
var det = a.x * b.y - a.y * b.x;
|
||||
|
||||
var angle = Math.Atan2(det, dot);
|
||||
|
||||
return angle > 0 ? angle : 2*Math.PI + angle;
|
||||
}
|
||||
|
||||
public static bool IsClockwise(Point center, Point a, Point b)
|
||||
|
@ -31,7 +31,7 @@ namespace Assets.GridGenerator
|
||||
result.Boundaries = (Graph<Point>)generator.Voronoi.Clone();
|
||||
result.Sites = generator.Delaunay.Morph(s =>
|
||||
{
|
||||
var site = new MapSite(s.Point, ClockwiseVertices(generator.Voronoi, s.Vertices)) { Edges = s.Edges };
|
||||
var site = new MapSite(s.Point, ClockwiseVertices(generator.Voronoi, s.Vertices));
|
||||
|
||||
site.Metadata.SetProperty(VoronoiSiteProperty, s);
|
||||
|
||||
@ -64,7 +64,7 @@ namespace Assets.GridGenerator
|
||||
var enumerated = vertices as int[] ?? vertices.ToArray();
|
||||
|
||||
var center = PointUtils.Mean(enumerated.Select(n => graph[n]));
|
||||
var reference = center + new Point(0, 1);
|
||||
var reference = center + new Point(0, -100);
|
||||
|
||||
return enumerated
|
||||
.Select(n => (Vertex: n, Point: graph[n]))
|
||||
|
@ -12,12 +12,12 @@ namespace Assets.Utils
|
||||
public static void DisplayGraphVertices<T>(Graph<T> graph, PointExtractor<T> extractor, bool displayLabels = true)
|
||||
{
|
||||
var vertices = graph.Vertices.Select(p => extractor(p).ToVector3());
|
||||
var offset = Vector3.right;
|
||||
var offset = Vector3.right + Vector3.up;
|
||||
|
||||
foreach (var (v, i) in vertices.Select((x, i) => (x, i)))
|
||||
{
|
||||
Gizmos.DrawSphere(v, 1);
|
||||
if (displayLabels) Handles.Label(v + offset, $"{i} at {v.x:F2}, {v.y:f2}");
|
||||
if (displayLabels) Handles.Label(v + offset, $"{i} at {v.x:F2}, {v.z:f2}");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user