41#ifndef GLS_QUATERNION_H 
   42#define GLS_QUATERNION_H 
  113        Type angle2, 
const Vector& axis2,
 
  114        Type angle3, 
const Vector& axis3 )
 
  172    inline const Type* 
Data()
 const 
  186        return _v[ 0 ] == q.
_v[ 0 ] && 
_v[ 1 ] == q.
_v[ 1 ] && 
_v[ 2 ] == q.
_v[ 2 ] && 
_v[ 3 ] == q.
_v[ 3 ];
 
  198        return _v[ 0 ] != q.
_v[ 0 ] || 
_v[ 1 ] != q.
_v[ 1 ] || 
_v[ 2 ] != q.
_v[ 2 ] || 
_v[ 3 ] != q.
_v[ 3 ];
 
  210        if( 
_v[ 0 ] < q.
_v[ 0 ] )
 
  212        else if( 
_v[ 0 ] > q.
_v[ 0 ] )
 
  214        else if( 
_v[ 1 ] < q.
_v[ 1 ] )
 
  216        else if( 
_v[ 1 ] > q.
_v[ 1 ] )
 
  218        else if( 
_v[ 2 ] < q.
_v[ 2 ] )
 
  220        else if( 
_v[ 2 ] > q.
_v[ 2 ] )
 
  223            return ( 
_v[ 3 ] < q.
_v[ 3 ] );
 
  260            q.
_v[ 3 ] * 
_v[ 1 ] + q.
_v[ 0 ] * 
_v[ 2 ] + q.
_v[ 1 ] * 
_v[ 3 ] - q.
_v[ 2 ] * 
_v[ 0 ],
 
  261            q.
_v[ 3 ] * 
_v[ 2 ] - q.
_v[ 0 ] * 
_v[ 1 ] + q.
_v[ 1 ] * 
_v[ 0 ] + q.
_v[ 2 ] * 
_v[ 3 ],
 
  262            q.
_v[ 3 ] * 
_v[ 3 ] - q.
_v[ 0 ] * 
_v[ 0 ] - q.
_v[ 1 ] * 
_v[ 1 ] - q.
_v[ 2 ] * 
_v[ 2 ] );
 
  270        Type x  = q.
_v[ 3 ] * 
_v[ 0 ] + q.
_v[ 0 ] * 
_v[ 3 ] - q.
_v[ 1 ] * 
_v[ 2 ] + q.
_v[ 2 ] * 
_v[ 1 ];
 
  271        Type y  = q.
_v[ 3 ] * 
_v[ 1 ] + q.
_v[ 0 ] * 
_v[ 2 ] + q.
_v[ 1 ] * 
_v[ 3 ] - q.
_v[ 2 ] * 
_v[ 0 ];
 
  272        Type z  = q.
_v[ 3 ] * 
_v[ 2 ] - q.
_v[ 0 ] * 
_v[ 1 ] + q.
_v[ 1 ] * 
_v[ 0 ] + q.
_v[ 2 ] * 
_v[ 3 ];
 
  273        _v[ 3 ] = q.
_v[ 3 ] * 
_v[ 3 ] - q.
_v[ 0 ] * 
_v[ 0 ] - q.
_v[ 1 ] * 
_v[ 1 ] - q.
_v[ 2 ] * 
_v[ 2 ];
 
  321        return ( ( *
this ) * q.
Inverse() );
 
  333        ( *this ) = ( *this ) * q.
Inverse();
 
  347            _v[ 2 ] + q.
_v[ 2 ], 
_v[ 3 ] + q.
_v[ 3 ] );
 
  359        _v[ 0 ] += q.
_v[ 0 ];
 
  360        _v[ 1 ] += q.
_v[ 1 ];
 
  361        _v[ 2 ] += q.
_v[ 2 ];
 
  362        _v[ 3 ] += q.
_v[ 3 ];
 
  376            _v[ 2 ] - q.
_v[ 2 ], 
_v[ 3 ] - q.
_v[ 3 ] );
 
  388        _v[ 0 ] -= q.
_v[ 0 ];
 
  389        _v[ 1 ] -= q.
_v[ 1 ];
 
  390        _v[ 2 ] -= q.
_v[ 2 ];
 
  391        _v[ 3 ] -= q.
_v[ 3 ];
 
  411        return sqrt( 
_v[ 0 ] * 
_v[ 0 ] + 
_v[ 1 ] * 
_v[ 1 ] + 
_v[ 2 ] * 
_v[ 2 ] + 
_v[ 3 ] * 
_v[ 3 ] );
 
  422        return _v[ 0 ] * 
_v[ 0 ] + 
_v[ 1 ] * 
_v[ 1 ] + 
_v[ 2 ] * 
_v[ 2 ] + 
_v[ 3 ] * 
_v[ 3 ];
 
  456        return ( ( 
_v[ 0 ] * q.
_v[ 0 ] ) + ( 
_v[ 1 ] * q.
_v[ 1 ] ) + ( 
_v[ 2 ] * q.
_v[ 2 ] ) + ( 
_v[ 3 ] * q.
_v[ 3 ] ) );
 
  478    inline void Set( Type x, Type y, Type z, Type w )
 
  495        Type half_angle     = angle * (Type)0.5;
 
  496        Type sin_half_angle = sin( half_angle );
 
  498        _v[ 0 ] = sin_half_angle * axis.
x;
 
  499        _v[ 1 ] = sin_half_angle * axis.
y;
 
  500        _v[ 2 ] = sin_half_angle * axis.
z;
 
  501        _v[ 3 ] = cos( half_angle );
 
  516        Type angle2, 
const Vector& axis2,
 
  517        Type angle3, 
const Vector& axis3 )
 
  523        *
this = q1 * q2 * *
this;
 
  539        Type xOver2 = angleX * (Type)0.5;
 
  540        Type yOver2 = angleY * (Type)0.5;
 
  541        Type zOver2 = angleZ * (Type)0.5;
 
  544        qx.
_v[ 0 ] = sin( xOver2 );
 
  545        qx.
_v[ 1 ] = (Type)0.0;
 
  546        qx.
_v[ 2 ] = (Type)0.0;
 
  547        qx.
_v[ 3 ] = cos( xOver2 );
 
  550        qy.
_v[ 0 ] = (Type)0.0;
 
  551        qy.
_v[ 1 ] = sin( yOver2 );
 
  552        qy.
_v[ 2 ] = (Type)0.0;
 
  553        qy.
_v[ 3 ] = cos( yOver2 );
 
  556        qz.
_v[ 0 ] = (Type)0.0;
 
  557        qz.
_v[ 1 ] = (Type)0.0;
 
  558        qz.
_v[ 2 ] = sin( zOver2 );
 
  559        qz.
_v[ 3 ] = cos( zOver2 );
 
  562        *
this = qx * qy * qz;
 
  591            if( fabs( from.
x ) < fabs( from.
y ) )
 
  592                if( fabs( from.
x ) < fabs( from.
z ) )
 
  593                    tmp = 
Vector( 1.0, 0.0, 0.0 ); 
 
  595                    tmp = 
Vector( 0.0, 0.0, 1.0 );
 
  596            else if( fabs( from.
y ) < fabs( from.
z ) )
 
  597                tmp = 
Vector( 0.0, 1.0, 0.0 );
 
  599                tmp = 
Vector( 0.0, 0.0, 1.0 );
 
  616            Type angle = acos( cosangle );
 
  634        int nxt[ 3 ] = { 1, 2, 0 };
 
  636        tr = mat[ 0 * 4 + 0 ] + mat[ 1 * 4 + 1 ] + mat[ 2 * 4 + 2 ];
 
  641            s       = (Type)sqrt( tr + 1.0 );
 
  644            _v[ 0 ] = ( mat[ 1 * 4 + 2 ] - mat[ 2 * 4 + 1 ] ) * s;
 
  645            _v[ 1 ] = ( mat[ 2 * 4 + 0 ] - mat[ 0 * 4 + 2 ] ) * s;
 
  646            _v[ 2 ] = ( mat[ 0 * 4 + 1 ] - mat[ 1 * 4 + 0 ] ) * s;
 
  652            if( mat[ 1 * 4 + 1 ] > mat[ 0 * 4 + 0 ] )
 
  654            if( mat[ 2 * 4 + 2 ] > mat[ i * 4 + i ] )
 
  659            s = (Type)sqrt( ( mat[ i * 4 + i ] - ( mat[ j * 4 + j ] + mat[ k * 4 + k ] ) ) + 1.0 );
 
  666            tq[ 3 ] = ( mat[ j * 4 + k ] - mat[ k * 4 + j ] ) * s;
 
  667            tq[ j ] = ( mat[ i * 4 + j ] + mat[ j * 4 + i ] ) * s;
 
  668            tq[ k ] = ( mat[ i * 4 + k ] + mat[ k * 4 + i ] ) * s;
 
  682        return atan2( 2 * ( 
_v[ 1 ] * 
_v[ 2 ] + 
_v[ 3 ] * 
_v[ 0 ] ), 
_v[ 3 ] * 
_v[ 3 ] - 
_v[ 0 ] * 
_v[ 0 ] - 
_v[ 1 ] * 
_v[ 1 ] + 
_v[ 2 ] * 
_v[ 2 ] );
 
  690        Type tmp = -2 * ( 
_v[ 0 ] * 
_v[ 2 ] - 
_v[ 3 ] * 
_v[ 1 ] );
 
  696        else if( tmp < -1.0 )
 
  708        return atan2( 2 * ( 
_v[ 0 ] * 
_v[ 1 ] + 
_v[ 3 ] * 
_v[ 2 ] ), 
_v[ 3 ] * 
_v[ 3 ] + 
_v[ 0 ] * 
_v[ 0 ] - 
_v[ 1 ] * 
_v[ 1 ] - 
_v[ 2 ] * 
_v[ 2 ] );
 
  728        if( abs( 
_v[ 3 ] ) > (Type)1.0 )
 
  730        if( fabs( (
double)
_v[ 3 ] ) > 1.0 )
 
  737        Type rad = acos( 
_v[ 3 ] ) * (Type)2.0;
 
  747            Type sin_half_angle = sin( rad * (Type)0.5 );
 
  748            if( sin_half_angle >= (Type)0.0001 ) 
 
  750                Type sin_half_angle_inv = Type( 1.0 ) / sin_half_angle;
 
  751                axis->
x                 = float( 
_v[ 0 ] * sin_half_angle_inv );
 
  752                axis->
y                 = float( 
_v[ 1 ] * sin_half_angle_inv );
 
  753                axis->
z                 = float( 
_v[ 2 ] * sin_half_angle_inv );
 
  763                axis->
x = (float)1.0;
 
  764                axis->
y = (float)0.0;
 
  765                axis->
z = (float)0.0;
 
  775        Type wx, wy, wz, xx, yy, yz, xy, xz, zz, x2, y2, z2;
 
  778        x2 = 
_v[ 0 ] + 
_v[ 0 ];
 
  779        y2 = 
_v[ 1 ] + 
_v[ 1 ];
 
  780        z2 = 
_v[ 2 ] + 
_v[ 2 ];
 
  794        mat[ 0 ][ 0 ] = 1.0f - ( yy + zz );
 
  795        mat[ 0 ][ 1 ] = xy - wz;
 
  796        mat[ 0 ][ 2 ] = xz + wy;
 
  797        mat[ 0 ][ 3 ] = 0.0f;
 
  799        mat[ 1 ][ 0 ] = xy + wz;
 
  800        mat[ 1 ][ 1 ] = 1.0f - ( xx + zz );
 
  801        mat[ 1 ][ 2 ] = yz - wx;
 
  802        mat[ 1 ][ 3 ] = 0.0f;
 
  804        mat[ 2 ][ 0 ] = xz - wy;
 
  805        mat[ 2 ][ 1 ] = yz + wx;
 
  806        mat[ 2 ][ 2 ] = 1.0f - ( xx + yy );
 
  807        mat[ 2 ][ 3 ] = 0.0f;
 
  833        if( adjustSign && ( cosom < (Type)0.0 ) )
 
  836            q.
_v[ 0 ] = -to.
_v[ 0 ]; 
 
  837            q.
_v[ 1 ] = -to.
_v[ 1 ];
 
  838            q.
_v[ 2 ] = -to.
_v[ 2 ];
 
  839            q.
_v[ 3 ] = -to.
_v[ 3 ];
 
  848        if( ( (Type)1.0 - cosom ) > (Type)0.0001 ) 
 
  852            omega = acos( cosom ); 
 
  853            sinom = sin( omega );
 
  854            sclp  = sin( ( (Type)1.0 - t ) * omega ) / sinom;
 
  855            sclq  = sin( t * omega ) / sinom;
 
  860            sclp = (Type)1.0 - t;
 
  864        _v[ 0 ] = sclp * p.
_v[ 0 ] + sclq * q.
_v[ 0 ];
 
  865        _v[ 1 ] = sclp * p.
_v[ 1 ] + sclq * q.
_v[ 1 ];
 
  866        _v[ 2 ] = sclp * p.
_v[ 2 ] + sclq * q.
_v[ 2 ];
 
  867        _v[ 3 ] = sclp * p.
_v[ 3 ] + sclq * q.
_v[ 3 ];
 
  892    outstr << quat.
Data()[ 0 ] << 
" ";
 
  894    outstr << quat.
Data()[ 1 ] << 
" ";
 
  896    outstr << quat.
Data()[ 2 ] << 
" ";
 
  898    outstr << quat.
Data()[ 3 ];
 
  910    instr >> quat.
Data()[ 0 ] >> quat.
Data()[ 1 ] >> quat.
Data()[ 2 ] >> quat.
Data()[ 3 ];
 
Definition: gls_matrix_affine.h:61
Definition: gls_quaternion.h:57
void Set(Type x, Type y, Type z, Type w)
Definition: gls_quaternion.h:478
Type GetRoll() const
Definition: gls_quaternion.h:680
bool operator==(const GlsQuaternion &q) const
Definition: gls_quaternion.h:184
void SetFromSlerp(float t, const GlsQuaternion &from, const GlsQuaternion &to, bool adjustSign=true)
Definition: gls_quaternion.h:824
void SetFromVectors(const Vector &to, const Vector &from)
Definition: gls_quaternion.h:574
GlsQuaternion & operator+=(const GlsQuaternion &q)
Definition: gls_quaternion.h:357
GlsQuaternion(Type angle, const Vector &axis)
Definition: gls_quaternion.h:96
GlsQuaternion & operator/=(const GlsQuaternion &q)
Definition: gls_quaternion.h:331
static bool IsVeryCloseToZero(double value)
Definition: gls_quaternion.h:876
const GlsQuaternion operator/(const GlsQuaternion &q) const
Definition: gls_quaternion.h:319
GlsQuaternion & operator-=(const GlsQuaternion &q)
Definition: gls_quaternion.h:386
GlsQuaternion & operator/=(Type s)
Definition: gls_quaternion.h:302
Type * Data()
Definition: gls_quaternion.h:161
GlsQuaternion operator/(Type s) const
Definition: gls_quaternion.h:289
void SetFromAngleAxis(Type angle1, const Vector &axis1, Type angle2, const Vector &axis2, Type angle3, const Vector &axis3)
Definition: gls_quaternion.h:515
Type _v[4]
The four components of the quaternion.
Definition: gls_quaternion.h:871
const GlsQuaternion operator+(const GlsQuaternion &q) const
Definition: gls_quaternion.h:344
const Type * Data() const
Definition: gls_quaternion.h:172
void GetAngleAxis(Type *angle, Vector *axis)
Definition: gls_quaternion.h:724
const GlsQuaternion Inverse() const
Definition: gls_quaternion.h:442
Type GetYaw() const
Definition: gls_quaternion.h:706
Type MagnitudeSquared() const
Definition: gls_quaternion.h:420
GlsQuaternion(Type x, Type y, Type z, Type w)
Definition: gls_quaternion.h:81
void SetFromEulerAngles(Type angleX, Type angleY, Type angleZ)
Definition: gls_quaternion.h:534
GlsQuaternion(const GlsMatrixAffine< Type > &matrix)
Definition: gls_quaternion.h:150
GlsQuaternion & operator*=(const GlsQuaternion &q)
Definition: gls_quaternion.h:268
const GlsQuaternion operator*(const GlsQuaternion &q) const
Definition: gls_quaternion.h:257
const GlsQuaternion operator*(Type s) const
Definition: gls_quaternion.h:233
GlsQuaternion(const Vector &anglesVec)
Definition: gls_quaternion.h:139
Vector GetEulerAngles()
Definition: gls_quaternion.h:714
void SetFromRotationMatrix(const GlsMatrixAffine< Type > &matrix)
Definition: gls_quaternion.h:627
GlsQuaternion(Type angleX, Type angleY, Type angleZ)
Definition: gls_quaternion.h:127
GlsQuaternion(Type angle1, const Vector &axis1, Type angle2, const Vector &axis2, Type angle3, const Vector &axis3)
Definition: gls_quaternion.h:112
bool operator!=(const GlsQuaternion &q) const
Definition: gls_quaternion.h:196
const GlsQuaternion operator-() const
Definition: gls_quaternion.h:398
void SetFromAngleAxis(Type angle, const Vector &axis)
Definition: gls_quaternion.h:493
GlsQuaternion()
Definition: gls_quaternion.h:64
Type GetPitch() const
Definition: gls_quaternion.h:688
GlsQuaternion Conjugate() const
Definition: gls_quaternion.h:431
GlsQuaternion & operator*=(Type s)
Definition: gls_quaternion.h:245
Type DotProduct(const GlsQuaternion &q) const
Definition: gls_quaternion.h:454
Type Magnitude() const
Definition: gls_quaternion.h:409
GlsMatrixAffine< Type > GetRotationMatrix()
Definition: gls_quaternion.h:773
void Normalize()
Definition: gls_quaternion.h:464
bool operator<(const GlsQuaternion &q) const
Definition: gls_quaternion.h:208
const GlsQuaternion operator-(const GlsQuaternion &q) const
Definition: gls_quaternion.h:373
VertexNoColor CrossProduct(const VertexNoColor &w) const
Definition: vertex.h:349
float DotProduct(const VertexNoColor &w) const
Definition: vertex.h:360
float y
The Y component.
Definition: vertex.h:88
float x
The X component.
Definition: vertex.h:87
float Magnitude() const
Definition: vertex.h:330
void Normalize()
Definition: vertex.h:311
float z
The Z component.
Definition: vertex.h:89
Macros and helper code to determine what subset of C++11/14/17 is available.
Force inclusion of the DirectShow library.
Definition: bmpimage.h:47
GlsQuaternion< float > GlsQuaternionF
Typedef for a quaternion of floats.
Definition: gls_quaternion.h:879
std::ostream & operator<<(std::ostream &outstr, const AttributeName &name)
GlsQuaternion< double > GlsQuaternionD
Typedef for a quaternion of doubles.
Definition: gls_quaternion.h:880
VertexNoColor Vector
Definition: gls_font_base.h:69
std::istream & operator>>(std::istream &instr, GlsColor &color)
Definition: gls_cpp_lang_support.h:468
The disti::Vertex class. A class for manipulating 3D vertices.