Пример #1
0
 public void Encapsulate(RectBounds target)
 {
     xMin = Mathf.Min(target.xMin, xMin);
     yMin = Mathf.Min(target.yMin, yMin);
     xMax = Mathf.Max(target.xMax, xMax);
     yMax = Mathf.Max(target.yMax, yMax);
 }
Пример #2
0
        public RectBounds GetBounds()
        {
            RectBounds bounds = RectBounds.Empty();

            foreach (var shape in WalkAble)
            {
                bounds.Encapsulate(shape.GetBounds());
            }
            return(bounds);
        }
Пример #3
0
        public static RectBounds PointsBounds(Vector2[] points)
        {
            RectBounds bounds = RectBounds.Empty();

            for (int i = 0; i < points.Length; ++i)
            {
                bounds.Encapsulate(points[i]);
            }
            return(bounds);
        }
Пример #4
0
        public static RectBounds BoxBounds(Vector2 center, Vector2 rotation, Vector2 size)
        {
            RectBounds bounds = RectBounds.Empty();

            for (int i = 0; i < 4; ++i)
            {
                Vector2 point = Vector2.Scale(BoxPoints[i], size) + center;
                point = point.Rotate(rotation);
                //point = matrix.Multiply(point);
                bounds.Encapsulate(point);
            }
            return(bounds);
        }
Пример #5
0
        public static SDFRawData GeneratorByRoot(GameObject root)
        {
            SDFScene scene = new SDFScene();

            scene.AddRoot(root);
            if (!scene.IsValid())
            {
                return(null);
            }
            RectBounds bounds = scene.GetBounds();

            bounds.Expand(1, 1);
            bounds.Floor();
            Vector2 size = bounds.Size;

            if (size.x < 1 || size.y < 1)
            {
                return(null);
            }
            Vector2 min         = bounds.Min;
            int     width       = Mathf.FloorToInt(size.x);
            int     height      = Mathf.FloorToInt(size.y);
            float   maxDistance = Mathf.Max(size.x, size.y);
            float   scale       = maxDistance / short.MaxValue;

            short[] data = new short[width * height];
            for (int i = 0; i < width; ++i)
            {
                for (int j = 0; j < height; ++j)
                {
                    Vector2 pos = min + new Vector2(i, j);
                    float   val = scene.SDF(pos);
                    val = (val / maxDistance) * short.MaxValue;
                    data[i + width * j] = (short)val;
                }
            }
            SDFRawData rawData = new SDFRawData();

            rawData.Init(width, height, scale, min, data);
            return(rawData);
        }