Пример #1
0
    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);
        }
    }
Пример #2
0
    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];
    }
Пример #3
0
 bool IsConnected(PolygonSegment segment, AtomBlueprint.Quark quark)
 {
     AtomBlueprint.Connection connection;
     return FindConnection(segment, quark, out connection);
 }
Пример #4
0
    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;
    }