Class Ray3

All Implemented Interfaces:
Poolable, ReadOnlyLine3Base, ReadOnlyRay3, Savable, Externalizable, Serializable

public class Ray3 extends Line3Base implements ReadOnlyRay3, Poolable
See Also:
  • Constructor Details

    • Ray3

      public Ray3()
      Constructs a new ray with an origin at (0,0,0) and a direction of (0,0,1).
    • Ray3

      public Ray3(ReadOnlyRay3 source)
      Copy constructor.
      Parameters:
      source - the ray to copy from.
    • Ray3

      public Ray3(ReadOnlyVector3 origin, ReadOnlyVector3 direction)
      Constructs a new ray using the supplied origin point and unit length direction vector
      Parameters:
      origin - the origin
      direction - the direction - unit length
  • Method Details

    • set

      public Ray3 set(ReadOnlyRay3 source)
      Copies the values of the given source ray into this ray.
      Parameters:
      source - the source ray
      Returns:
      this ray for chaining
      Throws:
      NullPointerException - if source is null.
    • getDistanceToPrimitive

      public double getDistanceToPrimitive(Vector3[] worldVertices)
      Specified by:
      getDistanceToPrimitive in interface ReadOnlyRay3
      Parameters:
      worldVertices - an array of vectors describing a polygon
      Returns:
      the distance from our origin to the primitive or POSITIVE_INFINITY if we do not intersect.
    • intersects

      public boolean intersects(Vector3[] polygonVertices, Vector3 locationStore)
      Specified by:
      intersects in interface ReadOnlyRay3
      Parameters:
      polygonVertices - the vertices of the polygon
      locationStore - the store of the location
      Returns:
      true if this ray intersects a polygon described by the given vertices.
    • intersectsTriangle

      public boolean intersectsTriangle(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, Vector3 locationStore)
      Specified by:
      intersectsTriangle in interface ReadOnlyRay3
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
      locationStore - if not null, and this ray intersects, the point of intersection is calculated and stored in this Vector3
      Returns:
      true if this ray intersects a triangle formed by the given three points.
      Throws:
      NullPointerException - if any of the points are null.
    • intersectsTrianglePlanar

      public boolean intersectsTrianglePlanar(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, Vector3 locationStore)
      Specified by:
      intersectsTrianglePlanar in interface ReadOnlyRay3
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
      locationStore - if not null, and this ray intersects, the point of intersection is calculated and stored in this Vector3 as (t, u, v) where t is the distance from the _origin to the point of intersection and (u, v) is the intersection point on the triangle plane.
      Returns:
      true if this ray intersects a triangle formed by the given three points.
      Throws:
      NullPointerException - if any of the points are null.
    • intersectsQuad

      public boolean intersectsQuad(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, ReadOnlyVector3 pointD, Vector3 locationStore)
      Specified by:
      intersectsQuad in interface ReadOnlyRay3
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
      pointD - the point D
      locationStore - if not null, and this ray intersects, the point of intersection is calculated and stored in this Vector3
      Returns:
      true if this ray intersects a triangle formed by the given three points. The points are assumed to be coplanar.
      Throws:
      NullPointerException - if any of the points are null.
    • intersectsQuadPlanar

      public boolean intersectsQuadPlanar(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, ReadOnlyVector3 pointD, Vector3 locationStore)
      Specified by:
      intersectsQuadPlanar in interface ReadOnlyRay3
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
      pointD - the point D
      locationStore - if not null, and this ray intersects, the point of intersection is calculated and stored in this Vector3 as (t, u, v) where t is the distance from the _origin to the point of intersection and (u, v) is the intersection point on the triangle plane.
      Returns:
      true if this ray intersects a quad formed by the given four points. The points are assumed to be coplanar.
      Throws:
      NullPointerException - if any of the points are null.
    • intersects

      protected boolean intersects(ReadOnlyVector3 pointA, ReadOnlyVector3 pointB, ReadOnlyVector3 pointC, Vector3 locationStore, boolean doPlanar)
      Ray vs triangle implementation.
      Parameters:
      pointA - the point A
      pointB - the point B
      pointC - the point C
      locationStore - the store of the location
      doPlanar - true if the intersection is planar (has no effect if locationStore is null)
      Returns:
      true if this ray intersects a triangle formed by the given three points.
      Throws:
      NullPointerException - if any of the points are null.
    • intersectsPlane

      public boolean intersectsPlane(ReadOnlyPlane plane, Vector3 locationStore)
      Specified by:
      intersectsPlane in interface ReadOnlyRay3
      Parameters:
      plane - the plane
      locationStore - if not null, and this ray intersects the plane, the world location of the point of intersection is stored in this vector.
      Returns:
      true if the ray collides with the given Plane
      Throws:
      NullPointerException - if the plane is null.
    • distanceSquared

      public double distanceSquared(ReadOnlyVector3 point, Vector3 store)
      Specified by:
      distanceSquared in interface ReadOnlyLine3Base
      Parameters:
      point - the point
      store - if not null, the closest point is stored in this param
      Returns:
      the squared distance from this ray to the given point.
      Throws:
      NullPointerException - if the point is null.
    • isValid

      public static boolean isValid(ReadOnlyRay3 ray)
      Check a ray... if it is null or the values of its origin or direction are NaN or infinite, return false. Else return true.
      Parameters:
      ray - the ray to check
      Returns:
      true or false as stated above.
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      the string representation of this ray.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Parameters:
      o - the object to compare for equality
      Returns:
      true if this ray and the provided ray have the same constant and normal values.
    • clone

      public Ray3 clone()
      Specified by:
      clone in interface ReadOnlyRay3
      Overrides:
      clone in class Object
    • fetchTempInstance

      public static final Ray3 fetchTempInstance()
      Returns:
      An instance of Ray that is intended for temporary use in calculations and so forth. Multiple calls to the method should return instances of this class that are not currently in use.
    • releaseTempInstance

      public static final void releaseTempInstance(Ray3 ray)
      Releases a Ray back to be used by a future call to fetchTempInstance. TAKE CARE: this Ray object should no longer have other classes referencing it or "Bad Things" will happen.
      Parameters:
      ray - the Ray to release.