32 Real T = 1 + _m.m_openGL[0] + _m.m_openGL[5] + _m.m_openGL[10];
33 if ( T > 0.00000001
f )
35 Real S =
static_cast<Real>(sqrt(T) * 2.0f);
36 m_x = ( _m.m_openGL[6] - _m.m_openGL[9] ) / S;
37 m_y = ( _m.m_openGL[8] - _m.m_openGL[2] ) / S;
38 m_z = ( _m.m_openGL[1] - _m.m_openGL[4] ) / S;
42 if ( _m.m_openGL[0] > _m.m_openGL[5] &&
43 _m.m_openGL[0] > _m.m_openGL[10] )
45 Real S =
static_cast<Real>(sqrt( 1.0
f + _m.m_openGL[0] - _m.m_openGL[5] - _m.m_openGL[10] ) * 2.0f);
47 m_y = (_m.m_openGL[1] + _m.m_openGL[4] ) / S;
48 m_z = (_m.m_openGL[8] + _m.m_openGL[2] ) / S;
49 m_s = (_m.m_openGL[6] - _m.m_openGL[9] ) / S;
52 if ( _m.m_openGL[5] > _m.m_openGL[10] )
54 Real S =
static_cast<Real>(sqrt( 1.0 + _m.m_openGL[5] - _m.m_openGL[0] - _m.m_openGL[10] ) * 2.0f);
55 m_x = (_m.m_openGL[1] + _m.m_openGL[4] ) / S;
57 m_z = (_m.m_openGL[6] + _m.m_openGL[9] ) / S;
58 m_s = (_m.m_openGL[8] - _m.m_openGL[2] ) / S;
62 Real S =
static_cast<Real>(sqrt( 1.0 + _m.m_openGL[10] - _m.m_openGL[0] - _m.m_openGL[5] ) * 2.0f);
63 m_x = (_m.m_openGL[8] + _m.m_openGL[2] ) / S;
64 m_y = (_m.m_openGL[6] + _m.m_openGL[9] ) / S;
66 m_s = (_m.m_openGL[1] - _m.m_openGL[4] ) / S;
80 m_s=cx*cy*cz + sx*sy*sz,
81 m_x=sx*cy*cz - cx*sy*sz,
82 m_y=cx*sy*cz + sx*cy*sz,
83 m_z=cx*cy*sz - sx*sy*cz;
94 ret.
m_s=(m_s*_q.m_s)-(m_x*_q.m_x+m_y*_q.m_y+m_z*_q.m_z);
99 Vec4 v2( _q.m_x, _q.m_y, _q.m_z );
101 Vec4 vectorPart = (m_s *
v2) + (_q.m_s * v1) + (v1.
cross(v2));
155 return Quaternion(m_s*_s,m_x*_s,m_y*_s,m_z*_s);
203 Quaternion point(0.0,_vec.m_x,_vec.m_y,_vec.m_z);
204 point = temp*point* *
this;
205 return Vec4(point.m_x,point.m_y,point.m_z,1.0);
250 Real sinAngle =
static_cast<Real>(sin( _angle / 2.0
f ));
251 Real cosAngle =
static_cast<Real>(cos( _angle / 2.0
f ));
253 m_x = axis.
m_x * sinAngle;
254 m_y = axis.
m_y * sinAngle;
255 m_z = axis.
m_z * sinAngle;
268 m_s=cx*cy*cz + sx*sy*sz,
269 m_x=sx*cy*cz - cx*sy*sz,
270 m_y=cx*sy*cz + sx*cy*sz,
271 m_z=cx*cy*sz - sx*sy*cz;
277 Quaternion point(0.0,io_p.m_x, io_p.m_y, io_p.m_z);
278 point = temp * point * _r;
284 o_angle =
degrees(static_cast<Real>(acos(
m_s ) * 2.0
f));
286 if( fabs( sinA ) < 0.0005f )
290 o_axis.m_x =
m_x / sinA;
291 o_axis.m_y =
m_y / sinA;
292 o_axis.m_z =
m_z / sinA;
300 Real cosom = _q1.
m_x * _q2.m_x + _q1.m_y * _q2.m_y + _q1.m_z * _q2.m_z + _q1.m_s * _q2.m_s;
315 if( (1.0
f - cosom) > 0.0001
f)
319 omega = acosf( cosom);
320 sinom = sinf( omega);
321 sclp = sinf( (1.0
f - _t) * omega) / sinom;
322 sclq = sinf( _t * omega) / sinom;
331 out.
m_x = sclp * _q1.m_x + sclq * end.
m_x;
332 out.
m_y = sclp * _q1.m_y + sclq * end.
m_y;
333 out.
m_z = sclp * _q1.m_z + sclq * end.
m_z;
334 out.
m_s = sclp * _q1.m_s + sclq * end.
m_s;
354 o.
m_openGL[0] = 1.0f - 2.0f * (yy+zz);
361 o.
m_openGL[5] = 1.0f - 2.0f * (xx+zz);
368 o.
m_openGL[10]= 1.0f - 2.0f * (xx+yy);
393 o.
m_openGL[0] = 1.0f - 2.0f * (yy+zz);
400 o.
m_openGL[5] = 1.0f - 2.0f * (xx+zz);
407 o.
m_openGL[10]= 1.0f - 2.0f * (xx+yy);
some useful definitions and functions
void rotateZ(Real _angle) noexcept
set the current quaternion as a rotation around the Z cartesian axis [0,0,1]
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 produ...
simple Vector class for OpenGL graphics, contains overloaded operators for most math functions...
Quaternion operator+(const Quaternion &_q) const noexcept
add two quaternions
Real m_s
the quaternion data for the scalar real part
void operator-() noexcept
conjugate negate the vector part but for the current vector -
void normalise() noexcept
normalise this quaternion this sets each of the component parts by calculating the magnitude and divi...
GLfloat GLfloat GLfloat v2
void rotateX(Real _angle) noexcept
set the current quaternion as a rotation around the X cartesian axis [1,0,0]
Real m_y
the quaternion data for y
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
implementation files for RibExport class
Real m_x
the quaternion data for x
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
Quaternion operator*(const Quaternion &_q) const noexcept
Perform a multiplication between 2 quaternions.
#define FCompare(a, b)
FCompare macro used for floating point comparision functions.
void fromAxisAngle(const Vec3 &_axis, Real _angle) noexcept
set the current quaternion as a rotation around the vector _axis
void operator+=(const Quaternion &_q) noexcept
add _q to the current quaternion
void set(Real _s, Real _x, Real _y, Real _z) noexcept
method to set the quaternion values
void operator-=(const Quaternion &_q) noexcept
subtract _q from the current quaternion
void toAxisAngle(Vec3 &o_axis, Real &o_angle) noexcept
return the axis and angle of the current quat (angle in degrees)
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...
Real m_z
the quaternion data for z
Defines the class Quaternion based on John Vinces lecture notes basically we have a scalar part and t...
NGL_DLLEXPORT Real degrees(const Real _rad) noexcept
converts Radians to Degrees
Mat4 toMat4() const noexcept
return the current quat as a 4x4 transform matrix
void rotatePoint(const Quaternion &_r, Vec3 &io_p) noexcept
rotate our point by a quat (but can also be done using the * operator)
void rotateY(Real _angle) noexcept
set the current quaternion as a rotation around the Y cartesian axis [0,1,0]
void operator*=(const Quaternion &_q) noexcept
Perform a multiplication this and another quaternions sets the current quat q1 = q1*q2.
NGL_DLLEXPORT Real radians(const Real _deg)
converts Degrees to Radians
Matrix Class to do simple matrix operations included operator overloaded functions for maths and matr...
std::array< Real, 16 > m_openGL
The matrix in m_openGL 16 Real array format usefull for OpenGL fv formats mapped to m_m[][] elements ...
Mat4 toMat4Transpose() const noexcept
return the current quat as a 4x4 transform matrix transposed
bool operator==(const Quaternion &_q) const noexcept
test for equality
void normalize() noexcept
Normalize the vector using .
void cross(const Vec4 &_v1, const Vec4 &_v2) noexcept
set the vector as the cross product from 2 other vectors
static Quaternion slerp(const Quaternion &_q1, const Quaternion &_q2, const Real &_t) noexcept
this function spherically interpolates between two quaternions with respect to t
Real magnitude() const noexcept
returns the magnitude of the quaternion