Tuesday
Classes | Typedefs | Functions
<tue/quat.hpp>

Detailed Description

The quat class template and its associated functions.

Classes

class  tue::quat< T >
 A quaternion. More...
 

Typedefs

using tue::fquat = quat< float >
 A quaternion with float components. More...
 
using tue::dquat = quat< double >
 A quaternion with double components. More...
 

Functions

template<typename T , typename U >
constexpr quat< decltype(std::declval< T >)*std::declval< U >))> tue::operator* (const quat< T > &lhs, const quat< U > &rhs) noexcept
 Computes a copy of lhs rotated by rhs. More...
 
template<typename T , typename U >
constexpr vec3< decltype(std::declval< T >)*std::declval< U >))> tue::operator* (const vec3< T > &lhs, const quat< U > &rhs) noexcept
 Computes a copy of lhs rotated by rhs. More...
 
template<typename T , typename U >
constexpr bool tue::operator== (const quat< T > &lhs, const quat< U > &rhs) noexcept
 Determines whether or not two quat's compare equal. More...
 
template<typename T , typename U >
constexpr bool tue::operator!= (const quat< T > &lhs, const quat< U > &rhs) noexcept
 Determines whether or not two quat's compare not equal. More...
 
template<typename T >
quat< T > tue::math::normalize (const quat< T > &q) noexcept
 Computes a normalized copy of q. More...
 
template<typename T >
constexpr quat< T > tue::math::conjugate (const quat< T > &q) noexcept
 Computes the conjugate of q. More...
 

Class Documentation

class tue::quat

template<typename T>
class tue::quat< T >

A quaternion.

quat has the same size and alignment requirements as T[4]. The first three components represent the vector part of the quaternion. The fourth component represents the scalar part.

Template Parameters
TThe component type. is_vec_component<T>value must be true.

Public Types

using component_type = T
 This quat type's component type. More...
 

Static Public Attributes

static constexpr int component_count = 4
 This quat type's component count. More...
 

Constructors, Conversions, and Factory Functions

 quat () noexcept=default
 Default constructs each component. More...
 
constexpr quat (const T &x, const T &y, const T &z, const T &w) noexcept
 Constructs each component with the value of the corresponding argument. More...
 
constexpr quat (const vec3< T > &xyz, const T &w) noexcept
 Constructs each component with the value of the corresponding argument. More...
 
constexpr quat (const vec4< T > &xyzw) noexcept
 Explicitly casts a vec4 to a quat. More...
 
template<typename U >
constexpr quat (const quat< U > &q) noexcept
 Explicitly casts another quat to a new component type. More...
 
template<typename U >
constexpr operator quat< U > () const noexcept
 Implicitly casts this quat to a new component type. More...
 
static constexpr quat< T > identity () noexcept
 Returns a quat with the fourth component set to 1 and all other components set to 0. More...
 

Public Member Functions

template<typename I >
constexpr const T & operator[] (const I &i) const noexcept
 Returns a reference to the component at the given index. More...
 
template<typename I >
T & operator[] (const I &i) noexcept
 Returns a reference to the component at the given index. More...
 
const T * data () const noexcept
 Returns a pointer to this quat's underlying component array. More...
 
T * data () noexcept
 Returns a pointer to this quat's underlying component array. More...
 
constexpr T x () const noexcept
 Returns a copy of this quat's first component. More...
 
constexpr T y () const noexcept
 Returns a copy of this quat's second component. More...
 
constexpr T z () const noexcept
 Returns a copy of this quat's third component. More...
 
constexpr T w () const noexcept
 Returns a copy of this quat's fourth component. More...
 
constexpr vec3< T > xyz () const noexcept
 Returns a copy of this quat's first three components. More...
 
constexpr vec4< T > xyzw () const noexcept
 Returns a copy of this quat's four components. More...
 
void set_x (const T &x) noexcept
 Sets this quat's first component. More...
 
void set_y (const T &y) noexcept
 Sets this quat's second component. More...
 
void set_z (const T &z) noexcept
 Sets this quat's third component. More...
 
void set_w (const T &w) noexcept
 Sets this quat's fourth component. More...
 
void set_xyz (const T &x, const T &y, const T &z) noexcept
 Sets this quat's first three components. More...
 
void set_xyz (const vec3< T > &xyz) noexcept
 Sets this quat's first three components. More...
 
void set_xyzw (const T &x, const T &y, const T &z, const T &w) noexcept
 Sets this quat's four components. More...
 
void set_xyzw (const vec3< T > &xyz, const T &w) noexcept
 Sets this quat's four components. More...
 
void set_xyzw (const vec4< T > &xyzw) noexcept
 Sets this quat's four components. More...
 
constexpr vec3< T > v () const noexcept
 Returns a copy of this quat's first three components. More...
 
constexpr T s () const noexcept
 Returns a copy of this quat's fourth component. More...
 
void set_v (const T &x, const T &y, const T &z) noexcept
 Sets this quat's first three components. More...
 
void set_v (const vec3< T > &v) noexcept
 Sets this quat's first three components. More...
 
void set_s (const T &s) noexcept
 Sets this quat's fourth component. More...
 
template<typename U >
quat< T > & operator*= (const quat< U > &q) noexcept
 Rotates this quat by q. More...
 

Member Typedef Documentation

template<typename T>
using tue::quat< T >::component_type = T

This quat type's component type.

Member Data Documentation

template<typename T>
constexpr int tue::quat< T >::component_count = 4
static

This quat type's component count.

Constructor & Destructor Documentation

template<typename T>
tue::quat< T >::quat ( )
defaultnoexcept

Default constructs each component.

template<typename T>
constexpr tue::quat< T >::quat ( const T &  x,
const T &  y,
const T &  z,
const T &  w 
)
inlinenoexcept

Constructs each component with the value of the corresponding argument.

Parameters
xThe value to construct the first component with.
yThe value to construct the second component with.
zThe value to construct the third component with.
wThe value to construct the fourth component with.
template<typename T>
constexpr tue::quat< T >::quat ( const vec3< T > &  xyz,
const T &  w 
)
inlinenoexcept

Constructs each component with the value of the corresponding argument.

Parameters
xyzThe values to construct the first three components with.
wThe value to construct the fourth component with.
template<typename T>
constexpr tue::quat< T >::quat ( const vec4< T > &  xyzw)
inlineexplicitnoexcept

Explicitly casts a vec4 to a quat.

Parameters
xyzwThe vec to cast from.
template<typename T>
template<typename U >
constexpr tue::quat< T >::quat ( const quat< U > &  q)
inlineexplicitnoexcept

Explicitly casts another quat to a new component type.

Template Parameters
UThe component type of q.
Parameters
qThe quat to cast from.

Member Function Documentation

template<typename T>
template<typename U >
constexpr tue::quat< T >::operator quat< U > ( ) const
inlinenoexcept

Implicitly casts this quat to a new component type.

Template Parameters
UThe new component type.
Returns
A new quat with the new component type.
template<typename T>
static constexpr quat<T> tue::quat< T >::identity ( )
inlinestaticnoexcept

Returns a quat with the fourth component set to 1 and all other components set to 0.

Returns
A quat with the fourth component set to 1 and all other components set to 0.
template<typename T>
template<typename I >
constexpr const T& tue::quat< T >::operator[] ( const I &  i) const
inlinenoexcept

Returns a reference to the component at the given index.

No bounds checking is performed.

Template Parameters
IThe index type.
Parameters
iThe index.
Returns
A reference to the component at the given index.
template<typename T>
template<typename I >
T& tue::quat< T >::operator[] ( const I &  i)
inlinenoexcept

Returns a reference to the component at the given index.

No bounds checking is performed.

Template Parameters
IThe index type.
Parameters
iThe index.
Returns
A reference to the component at the given index.
template<typename T>
const T* tue::quat< T >::data ( ) const
inlinenoexcept

Returns a pointer to this quat's underlying component array.

Returns
A pointer to this quat's underlying component array.
template<typename T>
T* tue::quat< T >::data ( )
inlinenoexcept

Returns a pointer to this quat's underlying component array.

Returns
A pointer to this quat's underlying component array.
template<typename T>
constexpr T tue::quat< T >::x ( ) const
inlinenoexcept

Returns a copy of this quat's first component.

Returns
A copy of this quat's first component.
template<typename T>
constexpr T tue::quat< T >::y ( ) const
inlinenoexcept

Returns a copy of this quat's second component.

Returns
A copy of this quat's second component.
template<typename T>
constexpr T tue::quat< T >::z ( ) const
inlinenoexcept

Returns a copy of this quat's third component.

Returns
A copy of this quat's third component.
template<typename T>
constexpr T tue::quat< T >::w ( ) const
inlinenoexcept

Returns a copy of this quat's fourth component.

Returns
A copy of this quat's fourth component.
template<typename T>
constexpr vec3<T> tue::quat< T >::xyz ( ) const
inlinenoexcept

Returns a copy of this quat's first three components.

Returns
A copy of this quat's first three components.
template<typename T>
constexpr vec4<T> tue::quat< T >::xyzw ( ) const
inlinenoexcept

Returns a copy of this quat's four components.

Returns
A copy of this quat's four components.
template<typename T>
void tue::quat< T >::set_x ( const T &  x)
inlinenoexcept

Sets this quat's first component.

Parameters
xThe new value for the first component.
template<typename T>
void tue::quat< T >::set_y ( const T &  y)
inlinenoexcept

Sets this quat's second component.

Parameters
yThe new value for the second component.
template<typename T>
void tue::quat< T >::set_z ( const T &  z)
inlinenoexcept

Sets this quat's third component.

Parameters
zThe new value for the third component.
template<typename T>
void tue::quat< T >::set_w ( const T &  w)
inlinenoexcept

Sets this quat's fourth component.

Parameters
wThe new value for the fourth component.
template<typename T>
void tue::quat< T >::set_xyz ( const T &  x,
const T &  y,
const T &  z 
)
inlinenoexcept

Sets this quat's first three components.

Parameters
xThe new value for the first component.
yThe new value for the second component.
zThe new value for the third component.
template<typename T>
void tue::quat< T >::set_xyz ( const vec3< T > &  xyz)
inlinenoexcept

Sets this quat's first three components.

Parameters
xyzThe new values for the first three components.
template<typename T>
void tue::quat< T >::set_xyzw ( const T &  x,
const T &  y,
const T &  z,
const T &  w 
)
inlinenoexcept

Sets this quat's four components.

Parameters
xThe new value for the first component.
yThe new value for the second component.
zThe new value for the third component.
wThe new value for the fourth component.
template<typename T>
void tue::quat< T >::set_xyzw ( const vec3< T > &  xyz,
const T &  w 
)
inlinenoexcept

Sets this quat's four components.

Parameters
xyzThe new values for the first three components.
wThe new value for the fourth component.
template<typename T>
void tue::quat< T >::set_xyzw ( const vec4< T > &  xyzw)
inlinenoexcept

Sets this quat's four components.

Parameters
xyzwThe new values for the four components.
template<typename T>
constexpr vec3<T> tue::quat< T >::v ( ) const
inlinenoexcept

Returns a copy of this quat's first three components.

Returns
A copy of this quat's first three components.
template<typename T>
constexpr T tue::quat< T >::s ( ) const
inlinenoexcept

Returns a copy of this quat's fourth component.

Returns
A copy of this quat's fourth component.
template<typename T>
void tue::quat< T >::set_v ( const T &  x,
const T &  y,
const T &  z 
)
inlinenoexcept

Sets this quat's first three components.

Parameters
xThe new value for the first component.
yThe new value for the second component.
zThe new value for the third component.
template<typename T>
void tue::quat< T >::set_v ( const vec3< T > &  v)
inlinenoexcept

Sets this quat's first three components.

Parameters
vThe new values for the first three components.
template<typename T>
void tue::quat< T >::set_s ( const T &  s)
inlinenoexcept

Sets this quat's fourth component.

Parameters
sThe new value for the fourth component.
template<typename T>
template<typename U >
quat<T>& tue::quat< T >::operator*= ( const quat< U > &  q)
inlinenoexcept

Rotates this quat by q.

The operand order might be the opposite of what you expect from other libraries. This library generally prefers compound transformations be written from left-to-right instead of right-to-left.

Template Parameters
UThe component type of q.
Parameters
qA rotation quat.
Returns
A reference to this quat.

Typedef Documentation

using tue::fquat = typedef quat<float>

A quaternion with float components.

using tue::dquat = typedef quat<double>

A quaternion with double components.

Function Documentation

template<typename T , typename U >
constexpr quat<decltype(std::declval<T>) * std::declval<U>))> tue::operator* ( const quat< T > &  lhs,
const quat< U > &  rhs 
)
inlinenoexcept

Computes a copy of lhs rotated by rhs.

The operand order might be the opposite of what you expect from other libraries. This library generally prefers compound transformations be written from left-to-right instead of right-to-left.

Template Parameters
TThe component type of lhs.
UThe component type of rhs.
Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
A copy of lhs rotated by rhs.
template<typename T , typename U >
constexpr vec3<decltype(std::declval<T>) * std::declval<U>))> tue::operator* ( const vec3< T > &  lhs,
const quat< U > &  rhs 
)
inlinenoexcept

Computes a copy of lhs rotated by rhs.

The operand order might be the opposite of what you expect from other libraries. This library generally prefers compound transformations be written from left-to-right instead of right-to-left.

Template Parameters
TThe component type of lhs.
UThe component type of rhs.
Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
A copy of lhs rotated by rhs.
template<typename T , typename U >
constexpr bool tue::operator== ( const quat< T > &  lhs,
const quat< U > &  rhs 
)
inlinenoexcept

Determines whether or not two quat's compare equal.

Template Parameters
TThe component type of lhs.
UThe component type of rhs.
Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
true if all the corresponding pairs of components compare equal and false otherwise.
template<typename T , typename U >
constexpr bool tue::operator!= ( const quat< T > &  lhs,
const quat< U > &  rhs 
)
inlinenoexcept

Determines whether or not two quat's compare not equal.

Template Parameters
TThe component type of lhs.
UThe component type of rhs.
Parameters
lhsThe left-hand side operand.
rhsThe right-hand side operand.
Returns
true if at least one of the corresponding pairs of components compares not equal and false otherwise.
template<typename T >
quat<T> tue::math::normalize ( const quat< T > &  q)
inlinenoexcept

Computes a normalized copy of q.

Template Parameters
TThe component type of q.
Parameters
qA quat.
Returns
A normalized copy of q.
template<typename T >
constexpr quat<T> tue::math::conjugate ( const quat< T > &  q)
inlinenoexcept

Computes the conjugate of q.

Template Parameters
TThe component type of q.
Parameters
qA quat.
Returns
The conjugate of q.