Ejemplo n.º 1
0
    /// <summary>
    /// Clamps the entire bounds of this shape to the bounds of the given shape.
    /// </summary>
    /// <param name="other">The shape to clamp to.</param>
    public void ClampShapeToShape(Poly other)
    {
        Vector2[] extents     = other.borders;
        bool      sizeChanged = false;

        for (int i = 0; i < points.Length; i++)
        {
            // If any end point is not contained in the target shape, clamp it to that shape.
            if (!other.ContainsPoint(pointsWorldSpace[i]))
            {
                Vector3 clamp  = other.ClampPointToShape(new Vector3(pointsWorldSpace[i].x, 0, pointsWorldSpace[i].y));
                Vector2 newPos = new Vector2(clamp.x, clamp.z);

                // We need to update the local space points as well!
                points[i]          -= (pointsWorldSpace[i] - newPos);
                pointsWorldSpace[i] = newPos;

                sizeChanged = true;
            }
        }

        // Center and borders may have changed.
        if (sizeChanged)
        {
            FindCenter();
            SetBorders();
        }
    }