Beispiel #1
0
 /// <summary>
 /// Returns the bounding box containing this box and the given box.
 /// </summary>
 public void Enlarge(Box2f box)
 {
     Min.x = Math.Min(Min.x, box.Min.x);
     Min.y = Math.Min(Min.y, box.Min.y);
     Max.x = Math.Max(Max.x, box.Max.x);
     Max.y = Math.Max(Max.y, box.Max.y);
 }
Beispiel #2
0
        public static Box2f CalculateBoundsXZ(Box2f box, Matrix4x4f localToWorld)
        {
            Box2f bounds = new Box2f(float.PositiveInfinity, float.NegativeInfinity);

            Vector3f corners0 = localToWorld * new Vector3f(box.Min.x, 0, box.Min.y);
            Vector3f corners1 = localToWorld * new Vector3f(box.Min.x, 0, box.Max.y);
            Vector3f corners2 = localToWorld * new Vector3f(box.Max.x, 0, box.Max.y);
            Vector3f corners3 = localToWorld * new Vector3f(box.Max.x, 0, box.Min.y);

            float x = corners0.x;
            float y = corners0.z;

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            x = corners1.x;
            y = corners1.z;

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            x = corners2.x;
            y = corners2.z;

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            x = corners3.x;
            y = corners3.z;

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            return(bounds);
        }
Beispiel #3
0
        public static Box2i CalculateBoundsXZ(Box2f box, Matrix4x4f localToWorld)
        {
            Box2i bounds = new Box2i(int.MaxValue, int.MinValue);

            Vector3f corners0 = localToWorld * new Vector3f(box.Min.x, 0, box.Min.y);
            Vector3f corners1 = localToWorld * new Vector3f(box.Min.x, 0, box.Max.y);
            Vector3f corners2 = localToWorld * new Vector3f(box.Max.x, 0, box.Max.y);
            Vector3f corners3 = localToWorld * new Vector3f(box.Max.x, 0, box.Min.y);

            int x = (int)Math.Round(corners0.x);
            int y = (int)Math.Round(corners0.z);

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            x = (int)Math.Round(corners1.x);
            y = (int)Math.Round(corners1.z);

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            x = (int)Math.Round(corners2.x);
            y = (int)Math.Round(corners2.z);

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            x = (int)Math.Round(corners3.x);
            y = (int)Math.Round(corners3.z);

            if (x < bounds.Min.x)
            {
                bounds.Min.x = x;
            }
            if (y < bounds.Min.y)
            {
                bounds.Min.y = y;
            }
            if (x > bounds.Max.x)
            {
                bounds.Max.x = x;
            }
            if (y > bounds.Max.y)
            {
                bounds.Max.y = y;
            }

            return(bounds);
        }