Class Ray


  • public final class Ray
    extends java.lang.Object
    This class represents a ray as a oriented half line segment. The ray direction is always normalized. The valid region is delimted by two distances along the ray, tMin and tMax.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      float dx  
      float dy  
      float dz  
      float ox  
      float oy  
      float oz  
    • Constructor Summary

      Constructors 
      Constructor Description
      Ray​(float ox, float oy, float oz, float dx, float dy, float dz)
      Creates a new ray that points from the given origin to the given direction.
      Ray​(Point3 a, Point3 b)
      Creates a new ray that points from point a to point b.
      Ray​(Point3 o, Vector3 d)
      Creates a new ray that points from the given origin to the given direction.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      float dot​(float vx, float vy, float vz)
      Computes the dot product of an arbitrary vector with the direction of the ray.
      float dot​(Vector3 v)
      Computes the dot product of an arbitrary vector with the direction of the ray.
      Vector3 getDirection()
      Creates a vector to represent the direction of the ray.
      float getMax()
      Gets the maximum distance along the ray.
      float getMin()
      Gets the minimum distance along the ray - usually 0.
      Point3 getPoint​(Point3 dest)
      Gets the end point of the ray.
      boolean isInside​(float t)
      Checks to see if the specified distance falls within the valid range on this ray.
      void normalize()
      Normalize the direction component of the ray.
      void setMax​(float t)
      Updates the maximum to the specified distance if and only if the new distance is smaller than the current one.
      void setMinMax​(float min, float max)  
      Ray transform​(Matrix4 m)
      Create a new ray by transforming the supplied one by the given matrix.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ox

        public float ox
      • oy

        public float oy
      • oz

        public float oz
      • dx

        public float dx
      • dy

        public float dy
      • dz

        public float dz
    • Constructor Detail

      • Ray

        public Ray​(float ox,
                   float oy,
                   float oz,
                   float dx,
                   float dy,
                   float dz)
        Creates a new ray that points from the given origin to the given direction. The ray has infinite length. The direction vector is normalized.
        Parameters:
        ox - ray origin x
        oy - ray origin y
        oz - ray origin z
        dx - ray direction x
        dy - ray direction y
        dz - ray direction z
      • Ray

        public Ray​(Point3 o,
                   Vector3 d)
        Creates a new ray that points from the given origin to the given direction. The ray has infinite length. The direction vector is normalized.
        Parameters:
        o - ray origin
        d - ray direction (need not be normalized)
      • Ray

        public Ray​(Point3 a,
                   Point3 b)
        Creates a new ray that points from point a to point b. The created ray will set tMin and tMax to limit the ray to the segment (a,b) (non-inclusive of a and b). This is often used to create shadow rays.
        Parameters:
        a - start point
        b - end point
    • Method Detail

      • transform

        public Ray transform​(Matrix4 m)
        Create a new ray by transforming the supplied one by the given matrix. If the matrix is null, the original ray is returned.
        Parameters:
        m - matrix to transform the ray by
      • normalize

        public void normalize()
        Normalize the direction component of the ray.
      • getMin

        public final float getMin()
        Gets the minimum distance along the ray - usually 0.
        Returns:
        value of the smallest distance along the ray
      • getMax

        public final float getMax()
        Gets the maximum distance along the ray. May be infinite.
        Returns:
        value of the largest distance along the ray
      • getDirection

        public final Vector3 getDirection()
        Creates a vector to represent the direction of the ray.
        Returns:
        a vector equal to the direction of this ray
      • isInside

        public final boolean isInside​(float t)
        Checks to see if the specified distance falls within the valid range on this ray. This should always be used before an intersection with the ray is detected.
        Parameters:
        t - distance to be tested
        Returns:
        true if t falls between the minimum and maximum distance of this ray, false otherwise
      • getPoint

        public final Point3 getPoint​(Point3 dest)
        Gets the end point of the ray. A reference to dest is returned to support chaining.
        Parameters:
        dest - reference to the point to store
        Returns:
        reference to dest
      • dot

        public final float dot​(Vector3 v)
        Computes the dot product of an arbitrary vector with the direction of the ray. This method avoids having to call getDirection() which would instantiate a new Vector object.
        Parameters:
        v - vector
        Returns:
        dot product of the ray direction and the specified vector
      • dot

        public final float dot​(float vx,
                               float vy,
                               float vz)
        Computes the dot product of an arbitrary vector with the direction of the ray. This method avoids having to call getDirection() which would instantiate a new Vector object.
        Parameters:
        vx - vector x coordinate
        vy - vector y coordinate
        vz - vector z coordinate
        Returns:
        dot product of the ray direction and the specified vector
      • setMax

        public final void setMax​(float t)
        Updates the maximum to the specified distance if and only if the new distance is smaller than the current one.
        Parameters:
        t - new maximum distance
      • setMinMax

        public void setMinMax​(float min,
                              float max)