Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Ray< T > Class Template Reference

Math class that represents a ray or a straight line in 3D space. More...

Public Member Functions

 Ray (T X, T Y, T Z, T directionX, T directionY, T directionZ)
 Constructs a Ray object from its position and direction. More...
 
 Ray (const Vector3< T > &origin, const Vector3< T > &direction)
 Constructs a Ray object from two Vector3. More...
 
 Ray (const T origin[3], const T direction[3])
 Constructs a Ray object from two arrays of three elements. More...
 
 Ray (const Plane< T > &planeOne, const Plane< T > &planeTwo)
 Constructs a Ray object from the intersection of two planes. More...
 
template<typename U >
 Ray (const Ray< U > &ray)
 Constructs a Ray object from another type of Ray. More...
 
template<typename U >
 Ray (const Vector3< U > &origin, const Vector3< U > &direction)
 Constructs a Ray object from two Vector3 from another type of Ray. More...
 
 Ray (const Ray< T > &ray)=default
 
ClosestPoint (const Vector3< T > &point) const
 Finds the closest point of the ray from point. More...
 
Vector3< T > GetPoint (T lambda) const
 Gets the point along the ray for this parameter. More...
 
bool Intersect (const BoundingVolume< T > &volume, T *closestHit=nullptr, T *furthestHit=nullptr) const
 Checks whether or not this ray intersects with the BoundingVolume. More...
 
bool Intersect (const Box< T > &box, T *closestHit=nullptr, T *furthestHit=nullptr) const
 Checks whether or not this ray intersects with the Box. More...
 
bool Intersect (const Box< T > &box, const Matrix4< T > &transform, T *closestHit=nullptr, T *furthestHit=nullptr) const
 Checks whether or not this ray intersects with the transform Matrix4 applied to the Box. More...
 
bool Intersect (const OrientedBox< T > &orientedBox, T *closestHit=nullptr, T *furthestHit=nullptr) const
 Checks whether or not this ray intersects with the OrientedBox. More...
 
bool Intersect (const Plane< T > &plane, T *hit=nullptr) const
 Checks whether or not this ray intersects with the plane. More...
 
bool Intersect (const Sphere< T > &sphere, T *closestHit=nullptr, T *furthestHit=nullptr) const
 Checks whether or not this ray intersects with the sphere. More...
 
bool Intersect (const Vector3< T > &firstPoint, const Vector3< T > &secondPoint, const Vector3< T > &thirdPoint, T *hit=nullptr) const
 Checks whether or not this ray intersects with the triangle. More...
 
RayMakeAxisX ()
 Makes the ray with position (0, 0, 0) and direction (1, 0, 0) More...
 
RayMakeAxisY ()
 Makes the ray with position (0, 0, 0) and direction (0, 1, 0) More...
 
RayMakeAxisZ ()
 Makes the ray with position (0, 0, 0) and direction (0, 0, 1) More...
 
RaySet (T X, T Y, T Z, T directionX, T directionY, T directionZ)
 Sets the components of the ray with position and direction. More...
 
RaySet (const Vector3< T > &origin, const Vector3< T > &direction)
 Sets the components of the ray with position and direction. More...
 
RaySet (const T origin[3], const T direction[3])
 Sets the components of this ray from two arrays of three elements. More...
 
RaySet (const Plane< T > &planeOne, const Plane< T > &planeTwo)
 Sets the components of this ray from the intersection of two planes. More...
 
RaySet (const Ray &ray)
 Sets the components of the ray with components from another. More...
 
template<typename U >
RaySet (const Ray< U > &ray)
 
template<typename U >
RaySet (const Vector3< U > &origin, const Vector3< U > &direction)
 
String ToString () const
 Gives a string representation. More...
 
Vector3< T > operator* (T lambda) const
 Multiplies the direction ray with the lambda to get the point along the ray for this parameter. More...
 
Rayoperator= (const Ray &other)=default
 
bool operator== (const Ray &ray) const
 Compares the ray to other one. More...
 
bool operator!= (const Ray &ray) const
 Compares the ray to other one. More...
 
template<typename U >
Ray< T > & Set (const Ray< U > &ray)
 Sets the components of the ray from another type of Ray. More...
 
template<typename U >
Ray< T > & Set (const Vector3< U > &Origin, const Vector3< U > &Direction)
 Sets the components of the ray from another type of Ray. More...
 

Static Public Member Functions

static Ray AxisX ()
 Shorthand for the ray (0, 0, 0), (1, 0, 0) More...
 
static Ray AxisY ()
 Shorthand for the ray (0, 0, 0), (0, 1, 0) More...
 
static Ray AxisZ ()
 Shorthand for the ray (0, 0, 0), (0, 0, 1) More...
 
static Ray Lerp (const Ray &from, const Ray &to, T interpolation)
 Interpolates the ray to other one with a factor of interpolation. More...
 

Public Attributes

Vector3< T > direction
 
Vector3< T > origin
 

Detailed Description

template<typename T>
class Nz::Ray< T >

Math class that represents a ray or a straight line in 3D space.

This ray is meant to be understood like origin + lambda * direction, where lambda is a real positive parameter

Constructor & Destructor Documentation

◆ Ray() [1/6]

template<typename T >
Nz::Ray< T >::Ray ( X,
Y,
Z,
DirectionX,
DirectionY,
DirectionZ 
)

Constructs a Ray object from its position and direction.

Parameters
XX position
YY position
ZZ position
DirectionXX component of the vector direction
DirectionYY component of the vector direction
DirectionYY component of the vector direction

◆ Ray() [2/6]

template<typename T >
Nz::Ray< T >::Ray ( const Vector3< T > &  Origin,
const Vector3< T > &  Direction 
)

Constructs a Ray object from two Vector3.

Parameters
OriginVector which represents the origin of the ray
DirectionVector which represents the direction of the ray

◆ Ray() [3/6]

template<typename T >
Nz::Ray< T >::Ray ( const T  Origin[3],
const T  Direction[3] 
)

Constructs a Ray object from two arrays of three elements.

Parameters
Origin[3]Origin[0] is X position, Origin[1] is Y position and Origin[2] is Z position
Direction[3]Direction[0] is X direction, Direction[1] is Y direction and Direction[2] is Z direction

◆ Ray() [4/6]

template<typename T >
Nz::Ray< T >::Ray ( const Plane< T > &  planeOne,
const Plane< T > &  planeTwo 
)

Constructs a Ray object from the intersection of two planes.

Parameters
planeOneFirst plane
planeTwoSecond secant plane
Remarks
Produce a NazaraError if planes are parallel with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and planes are parallel

◆ Ray() [5/6]

template<typename T >
template<typename U >
Nz::Ray< T >::Ray ( const Ray< U > &  ray)
explicit

Constructs a Ray object from another type of Ray.

Parameters
rayRay of type U to convert to type T

◆ Ray() [6/6]

template<typename T >
template<typename U >
Nz::Ray< T >::Ray ( const Vector3< U > &  Origin,
const Vector3< U > &  Direction 
)
explicit

Constructs a Ray object from two Vector3 from another type of Ray.

Parameters
OriginOrigin of type U to convert to type T
DirectionDirection of type U to convert to type T

Member Function Documentation

◆ AxisX()

template<typename T >
Ray< T > Nz::Ray< T >::AxisX ( )
static

Shorthand for the ray (0, 0, 0), (1, 0, 0)

Returns
A ray with position (0, 0, 0) and direction (1, 0, 0)
See also
MakeAxisX

◆ AxisY()

template<typename T >
Ray< T > Nz::Ray< T >::AxisY ( )
static

Shorthand for the ray (0, 0, 0), (0, 1, 0)

Returns
A ray with position (0, 0, 0) and direction (0, 1, 0)
See also
MakeAxisY

◆ AxisZ()

template<typename T >
Ray< T > Nz::Ray< T >::AxisZ ( )
static

Shorthand for the ray (0, 0, 0), (0, 0, 1)

Returns
A ray with position (0, 0, 0) and direction (0, 0, 1)
See also
MakeAxisZ

◆ ClosestPoint()

template<typename T >
T Nz::Ray< T >::ClosestPoint ( const Vector3< T > &  point) const

Finds the closest point of the ray from point.

Returns
The parameter where the point along this ray that is closest to the point provided
Parameters
pointThe point to get the closest approach to

◆ GetPoint()

template<typename T >
Vector3< T > Nz::Ray< T >::GetPoint ( lambda) const

Gets the point along the ray for this parameter.

Returns
The point on the ray
Parameters
lambdaParameter to obtain a particular point on the ray

◆ Intersect() [1/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const BoundingVolume< T > &  volume,
T *  closestHit = nullptr,
T *  furthestHit = nullptr 
) const

Checks whether or not this ray intersects with the BoundingVolume.

Returns
true if it intersects
Parameters
volumeBoundingVolume to check
closestHitOptional argument to get the closest parameter where the intersection is only if it happened
furthestHitOptional argument to get the furthest parameter where the intersection is only if it happened
Remarks
If BoundingVolume is Extend_Infinite, then closestHit and furthestHit are equal to 0 et infinity
If BoundingVolume is Extend_Null, then closestHit and furthestHit are unchanged
If enumeration of BoundingVolume is not defined in Extend, a NazaraError is thrown and closestHit and furthestHit are unchanged
See also
Intersect

◆ Intersect() [2/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const Box< T > &  box,
T *  closestHit = nullptr,
T *  furthestHit = nullptr 
) const

Checks whether or not this ray intersects with the Box.

Returns
true if it intersects
Parameters
boxBox to check
closestHitOptional argument to get the closest parameter where the intersection is only if it happened
furthestHitOptional argument to get the furthest parameter where the intersection is only if it happened
See also
Intersect

◆ Intersect() [3/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const Box< T > &  box,
const Matrix4< T > &  transform,
T *  closestHit = nullptr,
T *  furthestHit = nullptr 
) const

Checks whether or not this ray intersects with the transform Matrix4 applied to the Box.

Returns
true if it intersects
Parameters
boxBox to check
transformMatrix4 which represents the transformation of the box
closestHitOptional argument to get the closest parameter where the intersection is only if it happened
furthestHitOptional argument to get the furthest parameter where the intersection is only if it happened
See also
Intersect

◆ Intersect() [4/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const OrientedBox< T > &  orientedBox,
T *  closestHit = nullptr,
T *  furthestHit = nullptr 
) const

Checks whether or not this ray intersects with the OrientedBox.

Returns
true if it intersects
Parameters
orientedBoxOrientedBox to check
closestHitOptional argument to get the closest parameter where the intersection is only if it happened
furthestHitOptional argument to get the furthest parameter where the intersection is only if it happened
See also
Intersect

◆ Intersect() [5/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const Plane< T > &  plane,
T *  hit = nullptr 
) const

Checks whether or not this ray intersects with the plane.

Returns
true if it intersects
Parameters
planePlane to check
hitOptional argument to get the parameter where the intersection is only if it happened
See also
Intersect

◆ Intersect() [6/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const Sphere< T > &  sphere,
T *  closestHit = nullptr,
T *  furthestHit = nullptr 
) const

Checks whether or not this ray intersects with the sphere.

Returns
true if it intersects
Parameters
sphereSphere to check
closestHitOptional argument to get the closest parameter where the intersection is only if it happened
furthestHitOptional argument to get the furthest parameter where the intersection is only if it happened
See also
Intersect

◆ Intersect() [7/7]

template<typename T >
bool Nz::Ray< T >::Intersect ( const Vector3< T > &  firstPoint,
const Vector3< T > &  secondPoint,
const Vector3< T > &  thirdPoint,
T *  hit = nullptr 
) const

Checks whether or not this ray intersects with the triangle.

Returns
true if it intersects
Parameters
firstPointFirst vertex of the triangle
secondPointSecond vertex of the triangle
thirdPointThird vertex of the triangle
hitOptional argument to get the parameter where the intersection is only if it happened
See also
Intersect

◆ Lerp()

template<typename T >
Ray< T > Nz::Ray< T >::Lerp ( const Ray< T > &  from,
const Ray< T > &  to,
interpolation 
)
static

Interpolates the ray to other one with a factor of interpolation.

Returns
A new ray which is the interpolation of two rectangles
Parameters
fromInitial ray
toTarget ray
interpolationFactor of interpolation
Remarks
interpolation is meant to be between 0 and 1, other values are potentially undefined behavior
See also
Lerp

◆ MakeAxisX()

template<typename T >
Ray< T > & Nz::Ray< T >::MakeAxisX ( )

Makes the ray with position (0, 0, 0) and direction (1, 0, 0)

Returns
A reference to this ray with position (0, 0, 0) and direction (1, 0, 0)
See also
AxisX

◆ MakeAxisY()

template<typename T >
Ray< T > & Nz::Ray< T >::MakeAxisY ( )

Makes the ray with position (0, 0, 0) and direction (0, 1, 0)

Returns
A reference to this ray with position (0, 0, 0) and direction (0, 1, 0)
See also
AxisY

◆ MakeAxisZ()

template<typename T >
Ray< T > & Nz::Ray< T >::MakeAxisZ ( )

Makes the ray with position (0, 0, 0) and direction (0, 0, 1)

Returns
A reference to this ray with position (0, 0, 0) and direction (0, 0, 1)
See also
AxisZ

◆ operator!=()

template<typename T >
bool Nz::Ray< T >::operator!= ( const Ray< T > &  ray) const

Compares the ray to other one.

Returns
false if the ray are the same
Parameters
recOther ray to compare with

◆ operator*()

template<typename T >
Vector3< T > Nz::Ray< T >::operator* ( lambda) const

Multiplies the direction ray with the lambda to get the point along the ray for this parameter.

Returns
The point on the ray
Parameters
lambdaParameter to obtain a particular point on the ray
See also
GetPoint

◆ operator==()

template<typename T >
bool Nz::Ray< T >::operator== ( const Ray< T > &  ray) const

Compares the ray to other one.

Returns
true if the ray are the same
Parameters
recOther ray to compare with

◆ Set() [1/7]

template<typename T >
Ray< T > & Nz::Ray< T >::Set ( X,
Y,
Z,
directionX,
directionY,
directionZ 
)

Sets the components of the ray with position and direction.

Returns
A reference to this ray
Parameters
XX position
YY position
ZZ position
DirectionXX component of the vector direction
DirectionYY component of the vector direction
DirectionYY component of the vector direction

◆ Set() [2/7]

template<typename T >
Ray< T > & Nz::Ray< T >::Set ( const Vector3< T > &  Origin,
const Vector3< T > &  Direction 
)

Sets the components of the ray with position and direction.

Returns
A reference to this ray
Parameters
OriginVector which represents the origin of the ray
DirectionVector which represents the direction of the ray

◆ Set() [3/7]

template<typename T >
Ray< T > & Nz::Ray< T >::Set ( const T  Origin[3],
const T  Direction[3] 
)

Sets the components of this ray from two arrays of three elements.

Returns
A reference to this ray
Parameters
Origin[3]Origin[0] is X position, Origin[1] is Y position and Origin[2] is Z position
Direction[3]Direction[0] is X direction, Direction[1] is Y direction and Direction[2] is Z direction

◆ Set() [4/7]

template<typename T >
Ray< T > & Nz::Ray< T >::Set ( const Plane< T > &  planeOne,
const Plane< T > &  planeTwo 
)

Sets the components of this ray from the intersection of two planes.

Returns
A reference to this ray
Parameters
planeOneFirst plane
planeTwoSecond secant plane
Remarks
Produce a NazaraError if planes are parallel with NAZARA_MATH_SAFE defined
Exceptions
std::domain_errorif NAZARA_MATH_SAFE is defined and planes are parallel

◆ Set() [5/7]

template<typename T >
Ray< T > & Nz::Ray< T >::Set ( const Ray< T > &  ray)

Sets the components of the ray with components from another.

Returns
A reference to this ray
Parameters
rayThe other ray

◆ Set() [6/7]

template<typename T>
template<typename U >
Ray<T>& Nz::Ray< T >::Set ( const Ray< U > &  ray)

Sets the components of the ray from another type of Ray.

Returns
A reference to this ray
Parameters
rayRay of type U to convert its components

◆ Set() [7/7]

template<typename T>
template<typename U >
Ray<T>& Nz::Ray< T >::Set ( const Vector3< U > &  Origin,
const Vector3< U > &  Direction 
)

Sets the components of the ray from another type of Ray.

Returns
A reference to this ray
Parameters
OriginOrigin of type U to convert to type T
DirectionDirection of type U to convert to type T

◆ ToString()

template<typename T >
String Nz::Ray< T >::ToString ( ) const

Gives a string representation.

Returns
A string representation of the object: "Ray(origin: Vector3(origin.x, origin.y, origin.z), direction: Vector3(direction.x, direction.y, direction.z))"

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