NGL
6.5
The NCCA Graphics Library
|
#include <Quaternion.h>
Public Member Functions | |
Quaternion (const Real _s=0.0f, const Real _x=0.0f, const Real _y=0.0f, const Real _z=0.0f) noexcept | |
constructor I use the format used in John Vinces bood where we have a scalar and a vector, some libs do this the otherway round and use the w component, make sure you check if using different libs More... | |
Quaternion (const Mat4 &_m) noexcept | |
constructor passing in a matrix More... | |
Quaternion (const Vec3 &_rot) noexcept | |
constructor passing in a Vec3 which represents the rolls around the x y and z axis More... | |
Quaternion (const Quaternion &_q) noexcept | |
copy constructor More... | |
void | set (Real _s, Real _x, Real _y, Real _z) noexcept |
method to set the quaternion values More... | |
Real | getS () const noexcept |
accesor for the scalar part More... | |
Real | getX () const noexcept |
accesor for the x vector components More... | |
Real | getY () const noexcept |
accesor for the y vector components More... | |
Real | getZ () const noexcept |
accesor for the z vector components More... | |
Vec4 | getVector () const noexcept |
accesor for the vector components as an Vec4 More... | |
void | setVector (const Vec4 &_v) noexcept |
mutator for the vector components as an Vec4 More... | |
void | setS (Real &_s) noexcept |
mutator for the scalar part More... | |
void | setX (Real &_x) noexcept |
mutator for the x vector part More... | |
void | setY (Real &_y) noexcept |
mutator for the y vector part More... | |
void | setZ (Real &_z) noexcept |
mutator for the z vector part More... | |
Quaternion | operator* (const Quaternion &_q) const noexcept |
Perform a multiplication between 2 quaternions. More... | |
void | operator*= (const Quaternion &_q) noexcept |
Perform a multiplication this and another quaternions sets the current quat q1 = q1*q2. More... | |
Quaternion | operator* (Real _s) const noexcept |
Perform a multiplication between a quaternion and a scalar. More... | |
void | operator*= (Real _s) noexcept |
Perform a multiplication this and a real scalar sets the current quat to q=q*_s. More... | |
Quaternion | operator+ (const Quaternion &_q) const noexcept |
add two quaternions More... | |
Quaternion | operator- (const Quaternion &_q) const noexcept |
subtract two quaternions More... | |
void | operator+= (const Quaternion &_q) noexcept |
add _q to the current quaternion More... | |
void | operator-= (const Quaternion &_q) noexcept |
subtract _q from the current quaternion More... | |
void | normalise () noexcept |
normalise this quaternion this sets each of the component parts by calculating the magnitude and dividing each component by this More... | |
Real | magnitude () const noexcept |
returns the magnitude of the quaternion More... | |
Quaternion | conjugate () const noexcept |
conjugate negate the vector part can also be done by the -() operator More... | |
Quaternion | inverse () const noexcept |
conjugate negate the vector part can also be done by the -() operator More... | |
void | operator- () noexcept |
conjugate negate the vector part but for the current vector - More... | |
Quaternion | operator- () const noexcept |
returns the inverse of the quaternion (aka conjugate) the scalar part remains the same and we reverse the vector part More... | |
bool | operator== (const Quaternion &_q) const noexcept |
test for equality More... | |
Vec4 | operator* (const Vec4 &_vec) const noexcept |
operator to allow a quat to be multiplied by a vector V2=Q*V1 this is formed by sandwiching the vector between the current quat and the inverse of the current quat (conjugate) so we get q*_vec*q.conjugate() this is the main way to do quaternion rotation on points (or can use the rotatePoint method which does the same thing) we must ensure that the quat has been set to the correct values for rotation (i.e. set the axis and the rotation values this can be done using the rotateX/Y/Z or fromAxisAngle or fromEulerAngle methods More... | |
void | rotateX (Real _angle) noexcept |
set the current quaternion as a rotation around the X cartesian axis [1,0,0] More... | |
void | rotateY (Real _angle) noexcept |
set the current quaternion as a rotation around the Y cartesian axis [0,1,0] More... | |
void | rotateZ (Real _angle) noexcept |
set the current quaternion as a rotation around the Z cartesian axis [0,0,1] More... | |
void | fromAxisAngle (const Vec3 &_axis, Real _angle) noexcept |
set the current quaternion as a rotation around the vector _axis More... | |
void | fromEulerAngles (const Real _x, const Real _y, const Real _z) noexcept |
set the current quaternion as a rotation based on 3 Euler angles this will create the quat as a product of 3 seprate quats More... | |
void | rotatePoint (const Quaternion &_r, Vec3 &io_p) noexcept |
rotate our point by a quat (but can also be done using the * operator) More... | |
void | toAxisAngle (Vec3 &o_axis, Real &o_angle) noexcept |
return the axis and angle of the current quat (angle in degrees) More... | |
Mat4 | toMat4 () const noexcept |
return the current quat as a 4x4 transform matrix More... | |
Mat4 | toMat4Transpose () const noexcept |
return the current quat as a 4x4 transform matrix transposed More... | |
Static Public Member Functions | |
static Quaternion | slerp (const Quaternion &_q1, const Quaternion &_q2, const Real &_t) noexcept |
this function spherically interpolates between two quaternions with respect to t More... | |
Protected Attributes | |
Real | m_s |
the quaternion data for the scalar real part More... | |
Real | m_x |
the quaternion data for x More... | |
Real | m_y |
the quaternion data for y More... | |
Real | m_z |
the quaternion data for z More... | |
Definition at line 38 of file Quaternion.h.
|
inlinenoexcept |
constructor I use the format used in John Vinces bood where we have a scalar and a vector, some libs do this the otherway round and use the w component, make sure you check if using different libs
[in] | _s | - the s component of the quaternion |
[in] | _x | - the x component of the quaternion |
[in] | _y | - the y component of the quaternion |
[in] | _z | - the z component of the quaternion |
Definition at line 51 of file Quaternion.h.
|
noexcept |
constructor passing in a matrix
_m | the matrix to build the quat from this is useful when using the slerp so we can interpolate between two rotation matrices |
Definition at line 30 of file Quaternion.cpp.
|
noexcept |
constructor passing in a Vec3 which represents the rolls around the x y and z axis
_rot | the roatation to build the quat from this is useful when using the slerp so we can interpolate between two rotation matrices |
Definition at line 70 of file Quaternion.cpp.
References ngl::radians().
|
inlinenoexcept |
copy constructor
[in] | _q | - the quaternion to copy |
Definition at line 75 of file Quaternion.h.
|
inlinenoexcept |
conjugate negate the vector part can also be done by the -() operator
Definition at line 210 of file Quaternion.h.
set the current quaternion as a rotation around the vector _axis
[in] _axis the axis to rotate around (will be normalized)
[in] | _angle | the angle of rotation around the Z axis in degrees |
Definition at line 245 of file Quaternion.cpp.
References m_s, m_x, ngl::Vec3::m_x, m_y, ngl::Vec3::m_y, ngl::Vec3::m_z, m_z, ngl::Vec3::normalize(), and ngl::radians().
set the current quaternion as a rotation based on 3 Euler angles this will create the quat as a product of 3 seprate quats
[in] _x the rotation in degrees around the x axis [in] _y the rotation in degrees around the y axis [in] _z the rotation in degrees around the z axis
Definition at line 259 of file Quaternion.cpp.
References m_s, m_x, m_y, m_z, and ngl::radians().
|
inlinenoexcept |
accesor for the scalar part
Definition at line 98 of file Quaternion.h.
|
inlinenoexcept |
accesor for the vector components as an Vec4
Definition at line 118 of file Quaternion.h.
|
inlinenoexcept |
accesor for the x vector components
Definition at line 103 of file Quaternion.h.
|
inlinenoexcept |
accesor for the y vector components
Definition at line 108 of file Quaternion.h.
|
inlinenoexcept |
accesor for the z vector components
Definition at line 113 of file Quaternion.h.
|
inlinenoexcept |
conjugate negate the vector part can also be done by the -() operator
Definition at line 215 of file Quaternion.h.
|
noexcept |
|
noexcept |
normalise this quaternion this sets each of the component parts by calculating the magnitude and dividing each component by this
Definition at line 171 of file Quaternion.cpp.
References m_s, m_x, m_y, m_z, and magnitude().
|
noexcept |
Perform a multiplication between 2 quaternions.
[in] | _q | the rhs quaternion argument |
Definition at line 88 of file Quaternion.cpp.
References ngl::Vec4::cross(), m_s, m_x, ngl::Vec4::m_x, m_y, ngl::Vec4::m_y, m_z, and ngl::Vec4::m_z.
|
noexcept |
Perform a multiplication between a quaternion and a scalar.
[in] | _s | the rhs scalar argument |
Definition at line 153 of file Quaternion.cpp.
operator to allow a quat to be multiplied by a vector V2=Q*V1 this is formed by sandwiching the vector between the current quat and the inverse of the current quat (conjugate) so we get q*_vec*q.conjugate() this is the main way to do quaternion rotation on points (or can use the rotatePoint method which does the same thing) we must ensure that the quat has been set to the correct values for rotation (i.e. set the axis and the rotation values this can be done using the rotateX/Y/Z or fromAxisAngle or fromEulerAngle methods
[in] | _vec | the vector to be multiplied |
Definition at line 200 of file Quaternion.cpp.
|
noexcept |
Perform a multiplication this and another quaternions sets the current quat q1 = q1*q2.
[in] | _q | the rhs quaternion argument |
Definition at line 110 of file Quaternion.cpp.
Perform a multiplication this and a real scalar sets the current quat to q=q*_s.
[in] | _s | the rhs quaternion argument |
Definition at line 160 of file Quaternion.cpp.
|
noexcept |
|
noexcept |
add _q to the current quaternion
[in] | _q | the rhs quaternion argument |
Definition at line 140 of file Quaternion.cpp.
|
noexcept |
|
inlinenoexcept |
conjugate negate the vector part but for the current vector -
Definition at line 220 of file Quaternion.h.
|
inlinenoexcept |
returns the inverse of the quaternion (aka conjugate) the scalar part remains the same and we reverse the vector part
Definition at line 226 of file Quaternion.h.
References ngl::operator*(), and ngl::operator==().
|
noexcept |
subtract _q from the current quaternion
[in] | _q | the rhs quaternion argument |
Definition at line 146 of file Quaternion.cpp.
|
noexcept |
|
noexcept |
set the current quaternion as a rotation around the X cartesian axis [1,0,0]
[in] | _angle | the angle of rotation around the x axis in degrees |
Definition at line 211 of file Quaternion.cpp.
References m_s, m_x, m_y, m_z, and ngl::radians().
set the current quaternion as a rotation around the Y cartesian axis [0,1,0]
[in] | _angle | the angle of rotation around the y axis in degrees |
Definition at line 221 of file Quaternion.cpp.
References m_s, m_x, m_y, m_z, and ngl::radians().
set the current quaternion as a rotation around the Z cartesian axis [0,0,1]
[in] | _angle | the angle of rotation around the Z axis in degrees |
Definition at line 232 of file Quaternion.cpp.
References m_s, m_x, m_y, m_z, and ngl::radians().
method to set the quaternion values
[in] | _x | the x value |
[in] | _y | the y value |
[in] | _z | the z value |
[in] | _w | the w value |
Definition at line 87 of file Quaternion.h.
mutator for the scalar part
[in] | _s | the scalar part of the quaternion to set |
Definition at line 133 of file Quaternion.h.
mutator for the vector components as an Vec4
[in] | _v | the vector to set the quat vector components from |
Definition at line 123 of file Quaternion.h.
mutator for the x vector part
[in] | _x | the x vector part of the quaternion to set |
Definition at line 138 of file Quaternion.h.
mutator for the y vector part
[in] | _x | the x vector part of the quaternion to set |
Definition at line 143 of file Quaternion.h.
mutator for the z vector part
[in] | _z | the z vector part of the quaternion to set |
Definition at line 148 of file Quaternion.h.
References ngl::operator*().
|
staticnoexcept |
return the axis and angle of the current quat (angle in degrees)
[out] o_axis the axis of rotation ( [out] o_angle the angle of rotation about the quat angle in degrees
Definition at line 282 of file Quaternion.cpp.
References ngl::degrees(), m_s, m_x, m_y, and m_z.
|
noexcept |
return the current quat as a 4x4 transform matrix
Definition at line 340 of file Quaternion.cpp.
References ngl::Mat4::m_openGL, m_s, m_x, m_y, and m_z.
|
noexcept |
return the current quat as a 4x4 transform matrix transposed
Definition at line 379 of file Quaternion.cpp.
References ngl::Mat4::m_openGL, m_s, m_x, m_y, and m_z.
|
protected |
the quaternion data for the scalar real part
Definition at line 306 of file Quaternion.h.
|
protected |
the quaternion data for x
Definition at line 308 of file Quaternion.h.
|
protected |
the quaternion data for y
Definition at line 310 of file Quaternion.h.
|
protected |
the quaternion data for z
Definition at line 312 of file Quaternion.h.