Ejemplo n.º 1
0
    public static bool Intersect(Ray ray, BoundingSphere sphere, out float distance){
      Vector3 diff = sphere.Center - ray.Position;
      float dd = (diff).LengthSquared;
      float rr = sphere.Radius * sphere.Radius;

      // check if ray point is inside sphere
      if ( dd < rr){
        distance = 0.0f;
        return true;
      }

      float dot = Vector3.Dot (diff, ray.Direction);
      if (dot < 0.0) {
        distance = 0.0f;
        return false;
      }

      // temp = ||diff||^2 - ||diff||^2 cos^2(theta)
      // temp = ||diff||^2 sin^2(theta)
      float temp = dd - dot * dot;
      if (temp > rr) {
        distance = 0.0f;
        return false;
      }

      distance = dot - (float)Math.Sqrt(rr - temp);
      return true;
    }
Ejemplo n.º 2
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;

    }
Ejemplo n.º 3
0
 public static bool Intersect(Plane plane, BoundingSphere sphere){
   float d = Distance(plane, sphere.Center);
   return Math.Abs(d) <= sphere.Radius;
 }
Ejemplo n.º 4
0
    public static bool Intersects(BoundingSphere sphere, Ray ray, out float distance){
      return Ray.Intersect (ray, sphere, out distance);

    }
Ejemplo n.º 5
0
 public static bool Intersects(BoundingSphere sphere, BoundingBox box){
   return BoundingBox.Intersects(box, sphere);
 }
Ejemplo n.º 6
0
 public static bool Intersects(BoundingSphere sphere, Plane plane){
   return Plane.Intersect (plane, sphere);
 }
Ejemplo n.º 7
0
    public static bool Contains(BoundingSphere sphere, Vector3 vector){
      float d = (sphere.Center - vector).Length;

      return (d <= sphere.Radius);
    }
Ejemplo n.º 8
0
 public static bool Intersects(BoundingSphere sphere1, BoundingSphere sphere2){
   float d = (sphere1.Center - sphere2.Center).Length;
   return (d <= sphere1.Radius + sphere2.Radius);
 }
 public static bool Intersects(BoundingSphere sphere, Ray ray, out float distance)
 {
     return(Ray.Intersect(ray, sphere, out distance));
 }
 public static bool Intersects(BoundingSphere sphere, Plane plane)
 {
     return(Plane.Intersect(plane, sphere));
 }
 public static bool Intersects(BoundingSphere sphere, BoundingBox box)
 {
     return(BoundingBox.Intersects(box, sphere));
 }
        public static bool Intersects(BoundingSphere sphere1, BoundingSphere sphere2)
        {
            float d = (sphere1.Center - sphere2.Center).Length;

            return(d <= sphere1.Radius + sphere2.Radius);
        }
        public static bool Contains(BoundingSphere sphere, Vector3 vector)
        {
            float d = (sphere.Center - vector).Length;

            return(d <= sphere.Radius);
        }