Euphoria
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
eu::Q Struct Reference

A quaternion representing a rotation in 3d. More...

Public Member Functions

constexpr Q (float aw, const v3 &v)
 
void normalize ()
 Normalize the quaternion.
 
Q then_get_rotated (const Q &q) const
 Return the passed rotation composed after the current rotation.
 
n3 get_rotated (const n3 &v) const
 Rotate a unit vector according to the quaternion.
 
Q get_negated () const
 Gets the negated quaternion.
 
v3 get_vec_part () const
 Get the [x,y,z] part as a regular 3d vector.
 
Q get_conjugate () const
 Returns the conjugate of the quaternion.
 
Q get_inverse () const
 Gets the inverse rotation.
 
float get_length () const
 Gets the length of the quaternion.
 
Q get_normalized () const
 Return a normalized quaternion If it can't be normalized, the identity is returned.
 
n3 get_local_in () const
 Get the local in vector.
 
n3 get_local_out () const
 Get the local out vector.
 
n3 get_local_right () const
 Get the local right vector.
 
n3 get_local_left () const
 Get the local left vector.
 
n3 get_local_up () const
 Get the local up vector.
 
n3 get_local_down () const
 Get the local down vector.
 
void operator*= (float rhs)
 
void operator*= (const Q &rhs)
 

Static Public Member Functions

static Q from (const AA &aa)
 Create a quaternion from an axis angle.
 
static Q from (const Ypr &ypr)
 Create a quaternion from a yaw-pitch-roll.
 
static Q from_to (const Q &from, const Q &to)
 Create a quaternion going from from to to.
 
static std::optional< Qlook_at (const v3 &from, const v3 &to, const n3 &up)
 Creates a look-at quaternion from 2 positions.
 
static Q look_in_direction (const n3 &dir, const n3 &up)
 Creates a look-at quaternion looking in a direction.
 
static Q nlerp (const Q &f, float scale, const Q &t)
 Normalized lerp between 2 quaternions This will result in a non-linear rotation.
 
static Q slerp_fast (const Q &qa, float t, const Q &qb)
 Spherical lerp between 2 quaternions.
 
static Q slerp (const Q &from, float scale, const Q &to)
 Shortest spherical lerp between 2 quaternions.
 

Public Attributes

float w
 
float x
 
float y
 
float z
 

Detailed Description

A quaternion representing a rotation in 3d.

Definition at line 18 of file quat.h.

Constructor & Destructor Documentation

◆ Q()

constexpr eu::Q::Q ( float  aw,
const v3 v 
)
inlineconstexpr

Definition at line 25 of file quat.h.

Member Function Documentation

◆ from() [1/2]

static Q eu::Q::from ( const AA aa)
static

Create a quaternion from an axis angle.

◆ from() [2/2]

static Q eu::Q::from ( const Ypr ypr)
static

Create a quaternion from a yaw-pitch-roll.

◆ from_to()

static Q eu::Q::from_to ( const Q from,
const Q to 
)
static

Create a quaternion going from from to to.

◆ get_conjugate()

Q eu::Q::get_conjugate ( ) const

Returns the conjugate of the quaternion.

◆ get_inverse()

Q eu::Q::get_inverse ( ) const

Gets the inverse rotation.

Implemented as a conjugate with assert that the quaternion is normalized.

See also
get_conjugate()

◆ get_length()

float eu::Q::get_length ( ) const

Gets the length of the quaternion.

Since the quaternion should be a unit, this should always be 1

◆ get_local_down()

n3 eu::Q::get_local_down ( ) const

Get the local down vector.

◆ get_local_in()

n3 eu::Q::get_local_in ( ) const

Get the local in vector.

◆ get_local_left()

n3 eu::Q::get_local_left ( ) const

Get the local left vector.

◆ get_local_out()

n3 eu::Q::get_local_out ( ) const

Get the local out vector.

◆ get_local_right()

n3 eu::Q::get_local_right ( ) const

Get the local right vector.

◆ get_local_up()

n3 eu::Q::get_local_up ( ) const

Get the local up vector.

◆ get_negated()

Q eu::Q::get_negated ( ) const

Gets the negated quaternion.

The negated represents the same rotation

◆ get_normalized()

Q eu::Q::get_normalized ( ) const

Return a normalized quaternion If it can't be normalized, the identity is returned.

◆ get_rotated()

n3 eu::Q::get_rotated ( const n3 v) const

Rotate a unit vector according to the quaternion.

◆ get_vec_part()

v3 eu::Q::get_vec_part ( ) const

Get the [x,y,z] part as a regular 3d vector.

◆ look_at()

static std::optional< Q > eu::Q::look_at ( const v3 from,
const v3 to,
const n3 up 
)
static

Creates a look-at quaternion from 2 positions.

Standing at from and up is up, the result will be a quaternion looking at to

◆ look_in_direction()

static Q eu::Q::look_in_direction ( const n3 dir,
const n3 up 
)
static

Creates a look-at quaternion looking in a direction.

◆ nlerp()

static Q eu::Q::nlerp ( const Q f,
float  scale,
const Q t 
)
static

Normalized lerp between 2 quaternions This will result in a non-linear rotation.

See also
slerp()

◆ normalize()

void eu::Q::normalize ( )

Normalize the quaternion.

If it can't be normalized, it is set to the identity.

◆ operator*=() [1/2]

void eu::Q::operator*= ( const Q rhs)

◆ operator*=() [2/2]

void eu::Q::operator*= ( float  rhs)

◆ slerp()

static Q eu::Q::slerp ( const Q from,
float  scale,
const Q to 
)
static

Shortest spherical lerp between 2 quaternions.

Has extra logic to take the shortest route.

See also
slerp_fast()
nlerp()

◆ slerp_fast()

static Q eu::Q::slerp_fast ( const Q qa,
float  t,
const Q qb 
)
static

Spherical lerp between 2 quaternions.

Will take the longer route sometimes but is technically faster.

See also
nlerp()

◆ then_get_rotated()

Q eu::Q::then_get_rotated ( const Q q) const

Return the passed rotation composed after the current rotation.

Member Data Documentation

◆ w

float eu::Q::w

Definition at line 20 of file quat.h.

◆ x

float eu::Q::x

Definition at line 21 of file quat.h.

◆ y

float eu::Q::y

Definition at line 22 of file quat.h.

◆ z

float eu::Q::z

Definition at line 23 of file quat.h.


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