CUGL 2.1
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
cugl::Ray Class Reference

#include <CURay.h>

Public Member Functions

 Ray ()
 
 Ray (const Vec3 direction)
 
 Ray (const Vec3 origin, const Vec3 direction)
 
 Ray (const Ray &ray)
 
 ~Ray ()
 
Rayoperator= (const Ray &ray)
 
Rayoperator= (const Vec3 direction)
 
Rayset (const Ray &ray)
 
Rayset (const Vec3 origin, const Vec3 direction)
 
Rayset (const Vec3 direction)
 
Vec3 getEndpoint (float distance) const
 
Raymultiply (const Mat4 &mat)
 
Rayoperator*= (const Mat4 &mat)
 
Vec3 operator* (float distance) const
 
const Ray operator* (const Mat4 &mat) const
 
bool operator== (const Ray &r) const
 
bool operator!= (const Ray &r) const
 
bool equals (const Ray &r, float variance=CU_MATH_EPSILON) const
 
std::string toString (bool verbose=false) const
 
 operator std::string () const
 

Static Public Member Functions

static Vec3endpoint (const Ray &ray, float distance, Vec3 *dst)
 
static Raymultiply (const Ray &ray, const Mat4 &mat, Ray *dst)
 

Public Attributes

Vec3 origin
 
Vec3 direction
 

Static Public Attributes

static const Ray X_AXIS
 
static const Ray Y_AXIS
 
static const Ray Z_AXIS
 

Detailed Description

This class is a ray with a starting position and a unit length direction.

While this class has a few convience methods, most of the access is intended to be through the individual attributes.

Constructor & Destructor Documentation

◆ Ray() [1/4]

cugl::Ray::Ray ( )
inline

Creates a new ray along the x-axis

◆ Ray() [2/4]

cugl::Ray::Ray ( const Vec3  direction)
inline

Creates a new ray with the given direction.

The origin of the ray is (0,0,0)

Parameters
directionThe ray direction

◆ Ray() [3/4]

cugl::Ray::Ray ( const Vec3  origin,
const Vec3  direction 
)
inline

Creates a new ray with the given origin and the direction.

Parameters
originThe starting position
directionThe ray direction

◆ Ray() [4/4]

cugl::Ray::Ray ( const Ray ray)
inline

Creates a copy of the given ray.

Parameters
rayThe ray to copy

◆ ~Ray()

cugl::Ray::~Ray ( )
inline

Destroys this ray, releasing all resources

Member Function Documentation

◆ endpoint()

static Vec3* cugl::Ray::endpoint ( const Ray ray,
float  distance,
Vec3 dst 
)
static

Computes the endpoint for the given distance and assigns it to dst.

This is calculated as startpoint + distance * direction.

Parameters
rayThe ray to calculate
distanceThe distance value
dstA vector to store the result in
Returns
A reference to dst for chaining

◆ equals()

bool cugl::Ray::equals ( const Ray r,
float  variance = CU_MATH_EPSILON 
) const
inline

Returns true if the rays are within tolerance of each other.

The tolerance bounds the origin and direction separately.

Parameters
rThe ray to compare against.
varianceThe comparison tolerance.
Returns
true if the rays are within tolerance of each other.

◆ getEndpoint()

Vec3 cugl::Ray::getEndpoint ( float  distance) const
inline

Returns the endpoint for the given distance.

This is calculated as startpoint + distance * direction.

Parameters
distanceThe distance value
Returns
the endpoint for the given distance.

◆ multiply() [1/2]

Ray& cugl::Ray::multiply ( const Mat4 mat)
inline

Multiplies this ray by the given matrix.

Use this to transform the ray into another coordinate system.

Parameters
matThe transform matrix
Returns
A reference to this (modified) Ray for chaining.

◆ multiply() [2/2]

static Ray* cugl::Ray::multiply ( const Ray ray,
const Mat4 mat,
Ray dst 
)
static

Multiplies the ray by the given matrix and assigns it to dst.

Use this to transform a ray into another coordinate system.

Parameters
rayThe ray to transform
matThe transform matrix
dstA ray to store the result in
Returns
A reference to dst for chaining

◆ operator std::string()

cugl::Ray::operator std::string ( ) const
inline

Cast from Ray to a string.

◆ operator!=()

bool cugl::Ray::operator!= ( const Ray r) const
inline

Returns true if this ray is not equal to the given ray.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
rThe ray to compare against.
Returns
True if this ray is not equal to the given ray.

◆ operator*() [1/2]

const Ray cugl::Ray::operator* ( const Mat4 mat) const
inline

Returns a copy of this ray multiplied by the given matrix.

Use this to transform the ray into another coordinate system.

Parameters
matThe transform matrix
Returns
a copy of this ray multiplied by the given matrix.

◆ operator*() [2/2]

Vec3 cugl::Ray::operator* ( float  distance) const
inline

Returns the endpoint for the given distance.

This is calculated as startpoint + distance * direction.

Parameters
distanceThe distance value
Returns
the endpoint for the given distance.

◆ operator*=()

Ray& cugl::Ray::operator*= ( const Mat4 mat)
inline

Multiplies this ray by the given matrix.

Use this to transform the ray into another coordinate system.

Parameters
matThe transform matrix
Returns
A reference to this (modified) Ray for chaining.

◆ operator=() [1/2]

Ray& cugl::Ray::operator= ( const Ray ray)
inline

Sets this ray to be a copy of the given ray.

Parameters
rayThe ray to copy
Returns
A reference to this (modified) Ray for chaining.

◆ operator=() [2/2]

Ray& cugl::Ray::operator= ( const Vec3  direction)
inline

Sets this ray to go along the given direction from the origin.

This will reset the origin to (0,0,0).

Parameters
directionThe ray direction
Returns
A reference to this (modified) Ray for chaining.

◆ operator==()

bool cugl::Ray::operator== ( const Ray r) const
inline

Returns true if this ray is equal to the given ray.

Comparison is exact, which may be unreliable given that the attributes are floats.

Parameters
rThe ray to compare against.
Returns
True if this ray is equal to the given ray.

◆ set() [1/3]

Ray& cugl::Ray::set ( const Ray ray)
inline

Sets this ray to be a copy of the given ray.

Parameters
rayThe ray to copy
Returns
A reference to this (modified) Ray for chaining.

◆ set() [2/3]

Ray& cugl::Ray::set ( const Vec3  direction)
inline

Sets this ray to go along the given direction from the origin.

This will reset the origin to (0,0,0).

Parameters
directionThe ray direction
Returns
A reference to this (modified) Ray for chaining.

◆ set() [3/3]

Ray& cugl::Ray::set ( const Vec3  origin,
const Vec3  direction 
)
inline

Sets this ray to have the given origin and the direction.

Parameters
originThe starting position
directionThe ray direction
Returns
A reference to this (modified) Ray for chaining.

◆ toString()

std::string cugl::Ray::toString ( bool  verbose = false) const

Returns a string representation of this ray for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this ray for debugging purposes.

Member Data Documentation

◆ direction

Vec3 cugl::Ray::direction

The direction of this ray (a unit vector)

◆ origin

Vec3 cugl::Ray::origin

The anchoring origin of this ray.

◆ X_AXIS

const Ray cugl::Ray::X_AXIS
static

The ray anchored at the origin along the x-axis

◆ Y_AXIS

const Ray cugl::Ray::Y_AXIS
static

The ray anchored at the origin along the y-axis

◆ Z_AXIS

const Ray cugl::Ray::Z_AXIS
static

The ray anchored at the origin along the z-axis


The documentation for this class was generated from the following file: