Class Ray

  • All Implemented Interfaces:
    java.io.Serializable

    public class Ray
    extends java.lang.Object
    implements java.io.Serializable
    Encapsulates a ray having a starting position and a unit length direction.
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      Ray()  
      Ray​(Vector3 origin, Vector3 direction)
      Constructor, sets the starting position of the ray and the direction.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Ray cpy()  
      boolean equals​(java.lang.Object o)  
      Vector3 getEndPoint​(Vector3 out, float distance)
      Returns the endpoint given the distance.
      int hashCode()  
      Ray mul​(Matrix4 matrix)
      Multiplies the ray by the given matrix.
      Ray set​(float x, float y, float z, float dx, float dy, float dz)
      Sets this ray from the given starting position and direction.
      Ray set​(Ray ray)
      Sets the starting position and direction from the given ray
      Ray set​(Vector3 origin, Vector3 direction)
      Sets the starting position and the direction of this ray.
      java.lang.String toString()
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • origin

        public final Vector3 origin
      • direction

        public final Vector3 direction
    • Constructor Detail

      • Ray

        public Ray()
      • Ray

        public Ray​(Vector3 origin,
                   Vector3 direction)
        Constructor, sets the starting position of the ray and the direction.
        Parameters:
        origin - The starting position
        direction - The direction
    • Method Detail

      • cpy

        public Ray cpy()
        Returns:
        a copy of this ray.
      • getEndPoint

        public Vector3 getEndPoint​(Vector3 out,
                                   float distance)
        Returns the endpoint given the distance. This is calculated as startpoint + distance * direction.
        Parameters:
        out - The vector to set to the result
        distance - The distance from the end point to the start point.
        Returns:
        The out param
      • mul

        public Ray mul​(Matrix4 matrix)
        Multiplies the ray by the given matrix. Use this to transform a ray into another coordinate system.
        Parameters:
        matrix - The matrix
        Returns:
        This ray for chaining.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • set

        public Ray set​(Vector3 origin,
                       Vector3 direction)
        Sets the starting position and the direction of this ray.
        Parameters:
        origin - The starting position
        direction - The direction
        Returns:
        this ray for chaining
      • set

        public Ray set​(float x,
                       float y,
                       float z,
                       float dx,
                       float dy,
                       float dz)
        Sets this ray from the given starting position and direction.
        Parameters:
        x - The x-component of the starting position
        y - The y-component of the starting position
        z - The z-component of the starting position
        dx - The x-component of the direction
        dy - The y-component of the direction
        dz - The z-component of the direction
        Returns:
        this ray for chaining
      • set

        public Ray set​(Ray ray)
        Sets the starting position and direction from the given ray
        Parameters:
        ray - The ray
        Returns:
        This ray for chaining
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object