Пример #1
0
    bool rayIntersects(RayN<N, T> const & ray, T max_time = -1) const
    {
      if (max_time >= 0)
        return rayIntersectionTime(ray, max_time) >= 0;

      VectorT co = ray.getOrigin() - center;

      T c = co.squaredNorm() - radius * radius;
      if (c <= 0)  // origin is inside ball
        return true;

      T a = ray.getDirection().squaredNorm();
      T b = 2 * co.dot(ray.getDirection());

      // Solve quadratic a * t^2 + b * t + c = 0
      T b2 = b * b;
      T det = b2 - 4 * a * c;
      if (det < 0) return false;

      if (a > 0)
        return b <= 0 || det >= b2;
      else if (a < 0)
        return b >= 0 || det >= b2;
      else
        return false;
    }
Пример #2
0
 RayIntersectionN<N, T> rayIntersection(RayN<N, T> const & ray, T max_time = -1) const
 {
   T t = rayIntersectionTime(ray, max_time);
   if (t >= 0)
     return RayIntersectionN<N, T>(t, &normal);
   else
     return RayIntersectionN<N, T>(-1);
 }
Пример #3
0
 RayIntersectionN<N, T> rayIntersection(RayN<N, T> const & ray, T max_time = -1) const
 {
   T t = rayIntersectionTime(ray, max_time);
   if (t >= 0)
   {
     VectorT p = ray.getPoint(t);
     VectorT n = p - center;
     return RayIntersectionN<N, T>(t, &n);
   }
   else
     return RayIntersectionN<N, T>(-1);
 }
Пример #4
0
 /**
  * Get the intersection of a ray with the object, including the hit time and the normal at the intersection point. A
  * negative time is returned if there was no intersection in the forward direction. If the normal cannot be computed, the
  * zero vector is returned.
  *
  * @param ray The ray to test for intersection.
  * @param max_time Maximum allowable hit time, ignored if negative.
  *
  * @note The returned normal need not have unit length.
  */
 virtual RayIntersectionN<N, T> rayIntersection(RayN<N, T> const & ray, T max_time = -1) const
 { return RayIntersectionN<N, T>(rayIntersectionTime(ray, max_time)); }
Пример #5
0
 /**
  * Check if a ray intersects the object in the forward direction.
  *
  * @param ray The ray to test for intersection.
  * @param max_time Maximum allowable hit time, ignored if negative.
  */
 virtual bool rayIntersects(RayN<N, T> const & ray, T max_time = -1) const
 { return rayIntersectionTime(ray, max_time) >= 0; }