Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Friends | List of all members
G3D::Ray Class Reference

A 3D Ray, optionally limited to a positive subsegment of the ray. More...

Public Member Functions

 Ray ()
 
 Ray (const Point3 &origin, const Vector3 &direction, float minDistance=0.0f, float maxDistance=finf())
 
 Ray (class BinaryInput &b)
 
Ray bumpedRay (float distance) const
 Returns a new ray which has the same direction but an origin advanced along direction by distance. More...
 
Ray bumpedRay (float distance, const Vector3 &bumpDirection) const
 Returns a new ray which has the same direction but an origin advanced by distance * bumpDirection. More...
 
Point3 closestPoint (const Point3 &point) const
 Returns the closest point on the Ray to point. More...
 
void deserialize (class BinaryInput &b)
 
const Vector3direction () const
 Unit direction vector. More...
 
float distance (const Point3 &point) const
 
Returns the closest distance between point and the Ray More...
 
Point3 intersection (const class Plane &plane) const
 
Returns the point where the Ray and plane intersect. More...
 
float intersectionTime (const class Sphere &sphere, bool solid=false) const
 
Returns the distance until intersection with the sphere or the (solid) ball bounded by the sphere. More...
 
float intersectionTime (const class Plane &plane) const
 
float intersectionTime (const class Box &box) const
 
float intersectionTime (const class AABox &box) const
 
float intersectionTime (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &edge01, const Vector3 &edge02, float &w0, float &w1, float &w2) const
 
The three extra arguments are the weights of vertices 0, 1, and 2 at the intersection point; they are useful for texture mapping and interpolated normals. More...
 
float intersectionTime (const Point3 &vert0, const Point3 &vert1, const Point3 &vert2, const Vector3 &edge01, const Vector3 &edge02) const
 
Ray-triangle intersection for a 1-sided triangle. More...
 
float intersectionTime (const Point3 &vert0, const Point3 &vert1, const Point3 &vert2) const
 
float intersectionTime (const Point3 &vert0, const Point3 &vert1, const Point3 &vert2, float &w0, float &w1, float &w2) const
 
float intersectionTime (const Triangle &triangle) const
 
float intersectionTime (const Triangle &triangle, float &w0, float &w1, float &w2) const
 
Vector3 invDirection () const
 Component-wise inverse of direction vector. More...
 
float maxDistance () const
 
float minDistance () const
 
const Point3origin () const
 
Ray reflect (const Vector3 &newOrigin, const Vector3 &normal) const
 Reflects about the normal using G3D::Vector3::reflectionDirection and bumps the ray slightly from the newOrigin. More...
 
Ray refract (const Vector3 &newOrigin, const Vector3 &normal, float iInside, float iOutside) const
 Refracts about the normal using G3D::Vector3::refractionDirection and bumps the ray slightly from the newOrigin. More...
 
void serialize (class BinaryOutput &b) const
 
void set (const Point3 &origin, const Vector3 &direction, float minDistance=0.0f, float maxDistance=finf())
 

Static Public Member Functions

static Ray fromOriginAndDirection (const Point3 &point, const Vector3 &direction, float minDistance=0.0f, float maxDistance=finf())
 Creates a Ray from a origin and a (nonzero) unit direction. More...
 

Friends

class Intersect
 

Detailed Description

A 3D Ray, optionally limited to a positive subsegment of the ray.

See also
G3D::NativeTriTree::PrecomputedRay, G3D::LineSegment, G3D::Line

Constructor & Destructor Documentation

◆ Ray() [1/3]

G3D::Ray::Ray ( )
inline

◆ Ray() [2/3]

G3D::Ray::Ray ( const Point3 origin,
const Vector3 direction,
float  minDistance = 0.0f,
float  maxDistance = finf() 
)
inline
Parameters
directionAssumed to have unit length

◆ Ray() [3/3]

G3D::Ray::Ray ( class BinaryInput b)

Member Function Documentation

◆ bumpedRay() [1/2]

Ray G3D::Ray::bumpedRay ( float  distance) const
inline

Returns a new ray which has the same direction but an origin advanced along direction by distance.

The min and max distance of the ray are unmodified.

◆ bumpedRay() [2/2]

Ray G3D::Ray::bumpedRay ( float  distance,
const Vector3 bumpDirection 
) const
inline

Returns a new ray which has the same direction but an origin advanced by distance * bumpDirection.

The min and max distance of the ray are unmodified.

◆ closestPoint()

Point3 G3D::Ray::closestPoint ( const Point3 point) const
inline

Returns the closest point on the Ray to point.

Referenced by distance().

◆ deserialize()

void G3D::Ray::deserialize ( class BinaryInput b)

◆ direction()

const Vector3& G3D::Ray::direction ( ) const
inline

◆ distance()

float G3D::Ray::distance ( const Point3 point) const
inline


Returns the closest distance between point and the Ray

Referenced by bumpedRay().

◆ fromOriginAndDirection()

static Ray G3D::Ray::fromOriginAndDirection ( const Point3 point,
const Vector3 direction,
float  minDistance = 0.0f,
float  maxDistance = finf() 
)
inlinestatic

Creates a Ray from a origin and a (nonzero) unit direction.

Referenced by G3D::CollisionDetection::collisionTimeForMovingPointFixedTriangle().

◆ intersection()

Point3 G3D::Ray::intersection ( const class Plane plane) const


Returns the point where the Ray and plane intersect.

If there is no intersection, returns a point at infinity.

Planes are considered one-sided, so the ray will not intersect a plane where the normal faces in the traveling direction.

◆ intersectionTime() [1/10]

float G3D::Ray::intersectionTime ( const class Sphere sphere,
bool  solid = false 
) const


Returns the distance until intersection with the sphere or the (solid) ball bounded by the sphere.

Will be 0 if inside the sphere, inf if there is no intersection.

The ray direction is not normalized. If the ray direction has unit length, the distance from the origin to intersection is equal to the time. If the direction does not have unit length, the distance = time * direction.length().

See also the G3D::CollisionDetection "movingPoint" methods, which give more information about the intersection.

Parameters
solidIf true, rays inside the sphere immediately intersect (good for collision detection). If false, they hit the opposite side of the sphere (good for ray tracing).

Referenced by G3D::CollisionDetection::collisionTimeForMovingPointFixedTriangle(), and intersectionTime().

◆ intersectionTime() [2/10]

float G3D::Ray::intersectionTime ( const class Plane plane) const

◆ intersectionTime() [3/10]

float G3D::Ray::intersectionTime ( const class Box box) const

◆ intersectionTime() [4/10]

float G3D::Ray::intersectionTime ( const class AABox box) const

◆ intersectionTime() [5/10]

float G3D::Ray::intersectionTime ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 edge01,
const Vector3 edge02,
float &  w0,
float &  w1,
float &  w2 
) const
inline


The three extra arguments are the weights of vertices 0, 1, and 2 at the intersection point; they are useful for texture mapping and interpolated normals.

◆ intersectionTime() [6/10]

float G3D::Ray::intersectionTime ( const Point3 vert0,
const Point3 vert1,
const Point3 vert2,
const Vector3 edge01,
const Vector3 edge02 
) const
inline


Ray-triangle intersection for a 1-sided triangle.

Fastest version.

Referenced Code: http://www.acm.org/jgt/papers/MollerTrumbore97/
http://www.graphics.cornell.edu/pubs/1997/MT97.html

◆ intersectionTime() [7/10]

float G3D::Ray::intersectionTime ( const Point3 vert0,
const Point3 vert1,
const Point3 vert2 
) const
inline

◆ intersectionTime() [8/10]

float G3D::Ray::intersectionTime ( const Point3 vert0,
const Point3 vert1,
const Point3 vert2,
float &  w0,
float &  w1,
float &  w2 
) const
inline

◆ intersectionTime() [9/10]

float G3D::Ray::intersectionTime ( const Triangle triangle) const
inline

◆ intersectionTime() [10/10]

float G3D::Ray::intersectionTime ( const Triangle triangle,
float &  w0,
float &  w1,
float &  w2 
) const
inline

◆ invDirection()

Vector3 G3D::Ray::invDirection ( ) const
inline

Component-wise inverse of direction vector.

May have inf() components

◆ maxDistance()

float G3D::Ray::maxDistance ( ) const
inline

Referenced by fromOriginAndDirection(), and Ray().

◆ minDistance()

float G3D::Ray::minDistance ( ) const
inline

Referenced by fromOriginAndDirection(), and Ray().

◆ origin()

const Point3& G3D::Ray::origin ( ) const
inline

◆ reflect()

Ray G3D::Ray::reflect ( const Vector3 newOrigin,
const Vector3 normal 
) const

Reflects about the normal using G3D::Vector3::reflectionDirection and bumps the ray slightly from the newOrigin.

Sets the min distance to zero and the max distance to infinity.

◆ refract()

Ray G3D::Ray::refract ( const Vector3 newOrigin,
const Vector3 normal,
float  iInside,
float  iOutside 
) const

Refracts about the normal using G3D::Vector3::refractionDirection and bumps the ray slightly from the newOrigin.

Sets the min distance to zero and the max distance to infinity.

◆ serialize()

void G3D::Ray::serialize ( class BinaryOutput b) const

◆ set()

void G3D::Ray::set ( const Point3 origin,
const Vector3 direction,
float  minDistance = 0.0f,
float  maxDistance = finf() 
)
Parameters
directionAssumed to have unit length

Friends And Related Function Documentation

◆ Intersect

friend class Intersect
friend

documentation generated on Wed Nov 24 2021 08:01:59 using doxygen 1.8.15