Package org.sunflow.core
Class Ray
java.lang.Object
org.sunflow.core.Ray
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 -
Constructor Summary
ConstructorsConstructorDescriptionRay
(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.Creates a new ray that points from point a to point b.Creates a new ray that points from the given origin to the given direction. -
Method Summary
Modifier and TypeMethodDescriptionfinal float
dot
(float vx, float vy, float vz) Computes the dot product of an arbitrary vector with the direction of the ray.final float
Computes the dot product of an arbitrary vector with the direction of the ray.final Vector3
Creates a vector to represent the direction of the ray.final float
getMax()
Gets the maximum distance along the ray.final float
getMin()
Gets the minimum distance along the ray - usually 0.final Point3
Gets the end point of the ray.final boolean
isInside
(float t) Checks to see if the specified distance falls within the valid range on this ray.void
Normalize the direction component of the ray.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.void
setMinMax
(float min, float max) Create a new ray by transforming the supplied one by the given matrix.
-
Field Details
-
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 Details
-
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
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)
-
Ray
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 pointb
- end point
-
-
Method Details
-
transform
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
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
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
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)
-