示例#1
0
    public static bool Intersects(BoundingBox box, BoundingSphere sphere){
      // get closet point in cube
      Vector3 clamped = Vector3.Clamp (sphere.Center, box.Minimum, box.Maximum);
      float dist = (sphere.Center - clamped).Length;
      return dist <= sphere.Radius;

    }
示例#2
0
 public static bool Contains(BoundingBox box, Vector3 vector){
   if (box.Minimum.X <= vector.X && vector.X <= box.Maximum.X &&
       box.Minimum.Y <= vector.Y && vector.Y <= box.Maximum.Y &&
       box.Minimum.Z <= vector.Z && vector.Z <= box.Maximum.Z) {
     return true;
   } else {
     return false;
   }
 }
示例#3
0
    public static bool Intersects(BoundingBox box1, BoundingBox box2){
      if (box1.Minimum.X > box2.Maximum.X || box1.Maximum.X < box2.Minimum.X) {
        return false;
      }
      if (box1.Minimum.Y > box2.Maximum.Y || box1.Maximum.Y < box2.Minimum.Y) {
        return false;
      }

      return (box1.Minimum.Z <= box2.Maximum.Z && box1.Maximum.Z >= box2.Minimum.Z);
    }
示例#4
0
    public static bool Intersect(Plane plane, BoundingBox box){
      // source: SlimDX math/Plane.cpp

      Vector3 min, max;
      max.X = (plane.Normal.X >= 0.0f) ? box.Minimum.X : box.Maximum.X;
      max.Y = (plane.Normal.Y >= 0.0f) ? box.Minimum.Y : box.Maximum.Y;
      max.Z = (plane.Normal.Z >= 0.0f) ? box.Minimum.Z : box.Maximum.Z;
      min.X = (plane.Normal.X >= 0.0f) ? box.Maximum.X : box.Minimum.X;
      min.Y = (plane.Normal.Y >= 0.0f) ? box.Maximum.Y : box.Minimum.Y;
      min.Z = (plane.Normal.Z >= 0.0f) ? box.Maximum.Z : box.Minimum.Z;

      return Distance (plane, max) <= 0.0f && Distance (plane, min) >= 0.0f;
    }
示例#5
0
    public static bool Intersect(Ray ray, BoundingBox box, out float distance){
      // current minimum t to get inside
      float t = 0.0f; 
      // max t before going outside in one dim
      float tmax = float.MaxValue;

      for (int dim = 0; dim < 3; dim++) {
        if (Math.Abs (ray.Direction [dim]) < Precission) {
          // parallel to X face
          if (ray.Position [dim] < box.Minimum [dim] || ray.Position [dim] > box.Maximum [dim]) {
            distance = 0.0f;
            return false;
          }
        } else {
          // ray eq:
          // p = p0 + t * d
          // t = (p.x - p0.x)/d.x

          float tin = (box.Minimum [dim] - ray.Position [dim]) / ray.Direction [dim];
          float tout = (box.Maximum [dim] - ray.Position [dim]) / ray.Direction [dim];

          if (tin > tout) {
            float aux = tin;
            tin = tout;
            tout = aux;
          }
          t = Math.Max (tin, t);
          tmax = Math.Min (tout, tmax);
          if (t > tmax) {
            // is out of another dim when entering this one.
            distance = 0.0f;
            return false;
          }
        }
      }
      distance = t;
      return true;
    }
示例#6
0
 public static bool Intersects(BoundingBox box, Ray ray, out float distance){
   return Ray.Intersect (ray, box, out distance);
   
 }
示例#7
0
 public static bool Intersects(BoundingBox box, Plane plane){
   return Plane.Intersect (plane, box);
 }
示例#8
0
 public static bool Intersects(BoundingSphere sphere, BoundingBox box){
   return BoundingBox.Intersects(box, sphere);
 }
 public static bool Intersects(BoundingSphere sphere, BoundingBox box)
 {
     return(BoundingBox.Intersects(box, sphere));
 }