public override void OnEntityAdded(IEntity entity) { base.OnEntityAdded(entity); var polygon = entity.GetComponent<HexagonComponent>(); var mesh = polygon.Renderer.Mesh; var vertices = mesh.vertices; polygon.Points = new List<PolygonPoint>(vertices.Length); polygon.Segments = new List<PolygonSegment>(vertices.Length); polygon.Contour = new PolygonContour(); for (int i = 0; i < vertices.Length - 1; i++) polygon.Points.Add(new PolygonPoint { Shape = polygon, Index = i }); for (int i = 0; i < polygon.Points.Count; i++) { var pointA = polygon.Points[i]; var pointB = polygon.Points[(i + 1) % polygon.Points.Count]; var segment = new PolygonSegment { Shape = polygon, Index = i, PointA = pointA, PointB = pointB }; pointA.SegmentB = segment; pointB.SegmentA = segment; polygon.Segments.Add(segment); polygon.Contour.Segments.Add(segment); } }
void FindFirstSegment(List<IEntity> particles, AtomBlueprint blueprint, out int firstHexagonIndex, out PolygonSegment firstSegment) { firstHexagonIndex = -1; float leftmostPosition = float.MaxValue; for (int i = 0; i < blueprint.Quarks.Length; i++) { var quark = blueprint.Quarks[i]; if (quark.Position.x < leftmostPosition) { leftmostPosition = quark.Position.x; firstHexagonIndex = i; } } firstSegment = particles[firstHexagonIndex].GetComponent<HexagonComponent>().Contour.Segments[1]; }
bool IsConnected(PolygonSegment segment, AtomBlueprint.Quark quark) { AtomBlueprint.Connection connection; return FindConnection(segment, quark, out connection); }
bool FindConnection(PolygonSegment segment, AtomBlueprint.Quark quark, out AtomBlueprint.Connection connection) { for (int i = 0; i < quark.Connections.Length; i++) { connection = quark.Connections[i]; if (connection.SegmentA == segment.Index) return true; } connection = new AtomBlueprint.Connection(); return false; }