Package org.sunflow.core
Class Ray
- java.lang.Object
-
- org.sunflow.core.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.
-
-
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.
-
-
-
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 xoy
- ray origin yoz
- ray origin zdx
- ray direction xdy
- ray direction ydz
- 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 origind
- ray direction (need not be normalized)
-
-
Method Detail
-
transform
public Ray transform(Matrix4 m)
Create a new ray by transforming the supplied one by the given matrix. If the matrix isnull
, 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 todest
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 coordinatevy
- vector y coordinatevz
- 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)
-
-