Core 1.0
Public Member Functions | Protected Attributes | Friends | List of all members
Ray Class Reference

A ray characterized by its origin an unit direction vector. More...

#include <ray.h>

Public Member Functions

 Ray ()
 Empty.
 
 Ray (const Vector &, const Vector &)
 Creates a ray. More...
 
 ~Ray ()
 Empty.
 
Ray Reflect (const Vector &, const Vector &)
 Compute the reflected ray from a ray hitting a surface. More...
 
Vector operator() (const double &) const
 Computes the location of a vertex along the ray. More...
 
double Length () const
 Gets the length of the direction vector.
 
double LengthSquared () const
 Gets the squared length of the direction vector.
 
Ray Scaled (const Vector &) const
 Scale the ray. More...
 
Ray Translated (const Vector &) const
 Translate the ray. More...
 
Ray Rotated (const Matrix &) const
 Rotate the ray. More...
 
Vector Origin () const
 Return the origin of the ray.
 
Vector Direction () const
 Return the direction of the ray.
 

Protected Attributes

Vector c
 Origin of the ray.
 
Vector n
 Direction.
 

Friends

std::ostream & operator<< (std::ostream &, const Ray &)
 Overloaded. More...
 

Detailed Description

A ray characterized by its origin an unit direction vector.

This class should be used in ray-object intersection methods and for ray-tracing.

Constructor & Destructor Documentation

◆ Ray()

Ray::Ray ( const Vector p,
const Vector d 
)
inlineexplicit

Creates a ray.

The direction should be unit:

Ray ray(Vector(0.0,0.0,0.0),Normalized(Vector(2.0,-1.0,3.0)));
A ray characterized by its origin an unit direction vector.
Definition: ray.h:13
Vectors in three dimensions.
Definition: evector.h:21
Parameters
pOrigin.
dDirection (should be unit vector).

Member Function Documentation

◆ operator()()

Vector Ray::operator() ( const double &  t) const
inline

Computes the location of a vertex along the ray.

Parameters
tParameter.

◆ Reflect()

Ray Ray::Reflect ( const Vector p,
const Vector normal 
)

Compute the reflected ray from a ray hitting a surface.

The origin of the ray is defined as the argument intersection point, and direction is set according to the normal of the surface at intersection point.

Parameters
pIntersection point.
normalSurface outgoing normal.

◆ Rotated()

Ray Ray::Rotated ( const Matrix r) const

Rotate the ray.

Parameters
rRotation matrix.

◆ Scaled()

Ray Ray::Scaled ( const Vector s) const

Scale the ray.

This function changes both the direction vector and origin. Note that the direction is kept unit.

Parameters
sScaling vector.

◆ Translated()

Ray Ray::Translated ( const Vector t) const

Translate the ray.

Parameters
tTranslation vector.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  s,
const Ray ray 
)
friend

Overloaded.

Parameters
sStream.
rayThe ray.