OpenBarnyard
 
Loading...
Searching...
No Matches
TQuaternion Class Reference

#include <TQuaternion.h>

Public Member Functions

 TQuaternion ()
 
 TQuaternion (const TQuaternion &a_pQuaternion)
 
 TQuaternion (TFLOAT a_fX, TFLOAT a_fY, TFLOAT a_fZ, TFLOAT a_fW)
 
void Set (TFLOAT a_fX, TFLOAT a_fY, TFLOAT a_fZ, TFLOAT a_fW)
 
void SetIdentity ()
 
void SetFromEulerYX (const TFLOAT *fVal)
 
void SetFromEulerRollPitchYaw (TFLOAT a_fRoll, TFLOAT a_fPitch, TFLOAT a_fYaw)
 
void SetConjugate ()
 
void SetInverse ()
 
void SetRotation (const TVector3 &a_rVec3, TFLOAT a_fVal)
 
void SetVectorDirection (const TVector3 &a_rVec3, const TVector3 &a_rVec3_2)
 
void RotateAroundAxis (const TVector3 &param_1, TFLOAT param_2)
 
void Negate ()
 
void GetEulerXYZ (TVector3 &outVec) const
 
TFLOAT Magnitude () const
 
TFLOAT MagnitudeSq () const
 
const TVector4AsVector4 () const
 
TVector4AsVector4 ()
 
void operator= (const TQuaternion &other)
 
TQuaternionoperator*= (const TQuaternion &a_rQuat)
 

Static Public Member Functions

static void RotateVector (TVector3 &param_1, const TQuaternion &param_2, const TVector3 param_3)
 
static void Nlerp (TQuaternion &a_rOut, const TQuaternion &a_rStart, const TQuaternion &a_rEnd, float a_fProgress)
 
static void Slerp (TQuaternion &a_rOut, const TQuaternion &a_rStart, const TQuaternion &a_rEnd, float a_fProgress)
 

Public Attributes

TFLOAT x
 
TFLOAT y
 
TFLOAT z
 
TFLOAT w
 

Static Public Attributes

static const TQuaternion IDENTITY = { 0.0f, 0.0f, 0.0f, 1.0f }
 
static constexpr TFLOAT DELTA = 0.001f
 

Detailed Description

Definition at line 18 of file TQuaternion.h.

Constructor & Destructor Documentation

◆ TQuaternion() [1/3]

TQuaternion::TQuaternion ( )
inline

Definition at line 21 of file TQuaternion.h.

22 : x( 0.0f ), y( 0.0f ), z( 0.0f ), w( 1.0f )
23 {}

◆ TQuaternion() [2/3]

TQuaternion::TQuaternion ( const TQuaternion & a_pQuaternion)
inline

Definition at line 25 of file TQuaternion.h.

26 : x( a_pQuaternion.x ), y( a_pQuaternion.y ), z( a_pQuaternion.z ), w( a_pQuaternion.w ) {}

◆ TQuaternion() [3/3]

TQuaternion::TQuaternion ( TFLOAT a_fX,
TFLOAT a_fY,
TFLOAT a_fZ,
TFLOAT a_fW )
inline

Definition at line 28 of file TQuaternion.h.

29 : x( a_fX ), y( a_fY ), z( a_fZ ), w( a_fW ) {}

Member Function Documentation

◆ AsVector4() [1/2]

TVector4 & TQuaternion::AsVector4 ( )
inline

Definition at line 67 of file TQuaternion.h.

67{ return reinterpret_cast<TVector4&>( *this ); }

◆ AsVector4() [2/2]

const TVector4 & TQuaternion::AsVector4 ( ) const
inline

Definition at line 66 of file TQuaternion.h.

66{ return reinterpret_cast<const TVector4&>( *this ); }

◆ GetEulerXYZ()

void TQuaternion::GetEulerXYZ ( TVector3 & outVec) const

Definition at line 109 of file TQuaternion.cpp.

110{
111 TMatrix44 matrix;
112 matrix.SetFromQuaternion( *this );
113
114 matrix.GetEulerXYZ( outVec );
115}
void GetEulerXYZ(TVector3 &a_rOutVec) const
TMatrix44 & SetFromQuaternion(const TQuaternion &a_rQuaternion)

◆ Magnitude()

TFLOAT TQuaternion::Magnitude ( ) const
inline

Definition at line 63 of file TQuaternion.h.

63{ return TMath::Sqrt( w * w + z * z + y * y + x * x ); }
TFORCEINLINE TFLOAT Sqrt(TFLOAT a_fX)
Definition TMathInline.h:84

◆ MagnitudeSq()

TFLOAT TQuaternion::MagnitudeSq ( ) const
inline

Definition at line 64 of file TQuaternion.h.

64{ return w * w + z * z + y * y + x * x; }

◆ Negate()

void TQuaternion::Negate ( )
inline

Definition at line 60 of file TQuaternion.h.

60{ Set( -x, -y, -z, -w ); }
void Set(TFLOAT a_fX, TFLOAT a_fY, TFLOAT a_fZ, TFLOAT a_fW)
Definition TQuaternion.h:31

◆ Nlerp()

void TQuaternion::Nlerp ( TQuaternion & a_rOut,
const TQuaternion & a_rStart,
const TQuaternion & a_rEnd,
float a_fProgress )
static

Definition at line 129 of file TQuaternion.cpp.

130{
131 TFLOAT fDot = TVector4::DotProduct4( a_rStart.AsVector4(), a_rEnd.AsVector4() );
132
133 if ( 0.0f <= fDot )
134 {
135 TVector4 vec = a_rEnd.AsVector4();
136
137 vec.Substract4( a_rStart.AsVector4() );
138 vec.Multiply4( vec, a_fProgress );
139
140 a_rOut.x = vec.x + a_rStart.x;
141 a_rOut.y = vec.y + a_rStart.y;
142 a_rOut.z = vec.z + a_rStart.z;
143 a_rOut.w = vec.w + a_rStart.w;
144
145 a_rOut.AsVector4().Normalise4();
146 }
147 else
148 {
149 TVector4 vec = a_rEnd.AsVector4();
150 vec.Add4( a_rStart.AsVector4() );
151 vec.Multiply4( vec, a_fProgress );
152
153 a_rOut.x = vec.x - a_rStart.x;
154 a_rOut.y = vec.y - a_rStart.y;
155 a_rOut.z = vec.z - a_rStart.z;
156 a_rOut.w = vec.w - a_rStart.w;
157
158 a_rOut.AsVector4().Normalise4();
159 }
160}
float TFLOAT
Definition Typedefs.h:4
const TVector4 & AsVector4() const
Definition TQuaternion.h:66
constexpr void Add4(const TVector4 &vec)
Definition TVector4.h:81
TFLOAT constexpr DotProduct4(const TVector4 &vec) const
Definition TVector4.h:344
void Normalise4()
Definition TVector4.cpp:64
constexpr void Substract4(const TVector4 &vec)
Definition TVector4.h:102
TFLOAT w
Definition TVector4.h:367
TFLOAT x
Definition TVector4.h:367
TFLOAT y
Definition TVector4.h:367
constexpr void Multiply4(const TVector4 &vec)
Definition TVector4.h:192
TFLOAT z
Definition TVector4.h:367

◆ operator*=()

TQuaternion & TQuaternion::operator*= ( const TQuaternion & a_rQuat)

Definition at line 118 of file TQuaternion.cpp.

119{
120 TFLOAT fX = ( ( x * a_Quat.w + a_Quat.z * y ) - a_Quat.y * z ) + a_Quat.x * w;
121 TFLOAT fY = a_Quat.x * z + ( y * a_Quat.w - a_Quat.z * x ) + a_Quat.y * w;
122 TFLOAT fZ = w * a_Quat.z + ( a_Quat.y * x - a_Quat.x * y ) + z * a_Quat.w;
123 TFLOAT fW = ( -( a_Quat.y * y + a_Quat.x * x ) - a_Quat.z * z ) + a_Quat.w * w;
124 Set( fX, fY, fZ, fW );
125 return *this;
126}

◆ operator=()

void TQuaternion::operator= ( const TQuaternion & other)
inline

Definition at line 69 of file TQuaternion.h.

69{ Set( other.x, other.y, other.z, other.w ); }

◆ RotateAroundAxis()

void TQuaternion::RotateAroundAxis ( const TVector3 & param_1,
TFLOAT param_2 )

Definition at line 100 of file TQuaternion.cpp.

101{
102 TFLOAT fVal;
103 TFLOAT fVal2;
104
105 TMath::SinCos( param_2 * 0.5f, fVal, fVal2 );
106 *this *= TQuaternion( param_1.x * fVal, param_1.y * fVal, param_1.z * fVal, fVal2 );
107}
TFORCEINLINE void SinCos(TFLOAT fVal, TFLOAT &a_rSin, TFLOAT &a_rCos)
TFLOAT y
Definition TVector3.h:163
TFLOAT z
Definition TVector3.h:163
TFLOAT x
Definition TVector3.h:163

◆ RotateVector()

void TQuaternion::RotateVector ( TVector3 & param_1,
const TQuaternion & param_2,
const TVector3 param_3 )
static

Definition at line 87 of file TQuaternion.cpp.

88{
89 TQuaternion quat = param_2;
90 quat.Negate();
91 TQuaternion quat2 = TQuaternion( param_3.x, param_3.y, param_3.z, 0.0f );
92 TQuaternion quat3 = param_2;
93 quat3 *= quat2;
94 quat3 *= quat;
95
96 param_1.Set( quat3.x, quat3.y, quat3.z );
97}
void Negate()
Definition TQuaternion.h:60
constexpr void Set(const TVector3 &vec)
Definition TVector3.h:33

◆ Set()

void TQuaternion::Set ( TFLOAT a_fX,
TFLOAT a_fY,
TFLOAT a_fZ,
TFLOAT a_fW )
inline

Definition at line 31 of file TQuaternion.h.

32 {
33 x = a_fX;
34 y = a_fY;
35 z = a_fZ;
36 w = a_fW;
37 }

◆ SetConjugate()

void TQuaternion::SetConjugate ( )
inline

Definition at line 52 of file TQuaternion.h.

52{ AsVector4().Negate3(); }
constexpr void Negate3(const TVector4 &vec)
Definition TVector4.h:265

◆ SetFromEulerRollPitchYaw()

void TQuaternion::SetFromEulerRollPitchYaw ( TFLOAT a_fRoll,
TFLOAT a_fPitch,
TFLOAT a_fYaw )

Definition at line 21 of file TQuaternion.cpp.

22{
23 TFLOAT fCosRoll = cos( a_fRoll * 0.5f );
24 TFLOAT fSinRoll = sin( a_fRoll * 0.5f );
25 TFLOAT fCosPitch = cos( a_fPitch * 0.5f );
26 TFLOAT fSinPitch = sin( a_fPitch * 0.5f );
27 TFLOAT fCosYaw = cos( a_fYaw * 0.5f );
28 TFLOAT fSinYaw = sin( a_fYaw * 0.5f );
29
30 TFLOAT fX = fCosYaw * fCosPitch * fSinRoll - fSinYaw * fSinPitch * fCosRoll;
31 TFLOAT fY = fCosPitch * fSinRoll * fSinYaw + fSinPitch * fCosRoll * fCosYaw;
32 TFLOAT fZ = fCosRoll * fCosPitch * fSinYaw - fCosYaw * fSinPitch * fSinRoll;
33 TFLOAT fW = fSinYaw * fSinPitch * fSinRoll + fCosYaw * fCosPitch * fCosRoll;
34
35 Set( fX, fY, fZ, fW );
36}

◆ SetFromEulerYX()

void TQuaternion::SetFromEulerYX ( const TFLOAT * fVal)

Definition at line 9 of file TQuaternion.cpp.

10{
11 TFLOAT f1;
12 TFLOAT f2;
13
14 TMath::SinCos( fVal[ 0 ] * 0.5f, f1, f2 );
15 TQuaternion quat = TQuaternion( f1, 0, 0, f2 );
16 TMath::SinCos( fVal[ 1 ] * 0.5f, f1, f2 );
17 Set( 0, f1, 0, f2 );
18 *this *= quat;
19}

◆ SetIdentity()

void TQuaternion::SetIdentity ( )
inline

Definition at line 39 of file TQuaternion.h.

40 {
41 Set(
46 );
47 }
static const TQuaternion IDENTITY
Definition TQuaternion.h:7

◆ SetInverse()

void TQuaternion::SetInverse ( )
inline

Definition at line 53 of file TQuaternion.h.

53{ SetConjugate(); }
void SetConjugate()
Definition TQuaternion.h:52

◆ SetRotation()

void TQuaternion::SetRotation ( const TVector3 & a_rVec3,
TFLOAT a_fVal )

Definition at line 39 of file TQuaternion.cpp.

40{
41 TFLOAT fVal;
42 TFLOAT fVal2;
43
44 TMath::SinCos( a_fVal * 0.5f, fVal, fVal2 );
45 Set( a_rVec3.x * fVal, a_rVec3.y * fVal, a_rVec3.z * fVal, fVal2 );
46}

◆ SetVectorDirection()

void TQuaternion::SetVectorDirection ( const TVector3 & a_rVec3,
const TVector3 & a_rVec3_2 )

Definition at line 49 of file TQuaternion.cpp.

50{
51 TVector3 vec3;
52 vec3.CrossProduct( a_rVec3_2, a_rVec3 );
53
54 TFLOAT mag = vec3.Magnitude();
55
56 if ( mag > TMath::TFLOAT_EPSILON )
57 {
58 vec3.Divide( mag );
59 TFLOAT dotProduct = TVector3::DotProduct( a_rVec3_2, a_rVec3 );
60 TFLOAT rot = 0.0f;
61 if ( ( dotProduct <= 1.0f - TMath::TFLOAT_EPSILON ) && ( rot = TMath::PI, -1.0f + TMath::TFLOAT_EPSILON <= dotProduct ) )
62 {
63 rot = TMath::ACos( dotProduct );
64 }
65 SetRotation( vec3, rot );
66 return;
67 }
68
69 TFLOAT dotProduct = TVector3::DotProduct( a_rVec3_2, a_rVec3 );
70
71 if ( dotProduct < 0.0f )
72 {
73 TVector3 vec = a_rVec3_2;
74 if ( TMath::Abs( a_rVec3_2.y ) < 0.95f )
75 {
76 vec.RotateY( TMath::PI * 0.0055555557f * 90.0f );
77 }
78 else
79 {
80 vec.RotateX( TMath::PI * 0.0055555557f * 90.0f );
81 }
83 RotateAroundAxis( vec, TMath::PI * 0.0055555557f * 180.0f );
84 }
85}
TFORCEINLINE TFLOAT Abs(TFLOAT fVal)
Definition TMathInline.h:63
constexpr TFLOAT TFLOAT_EPSILON
Definition TMathInline.h:32
constexpr TFLOAT PI
Definition TMathInline.h:35
TFORCEINLINE TFLOAT ACos(TFLOAT fVal)
Definition TMathInline.h:50
void SetRotation(const TVector3 &a_rVec3, TFLOAT a_fVal)
void RotateAroundAxis(const TVector3 &param_1, TFLOAT param_2)
void SetIdentity()
Definition TQuaternion.h:39
constexpr void Divide(const TVector3 &vec)
Definition TVector3.h:77
void CrossProduct(const TVector3 &, const TVector3 &)
Definition TVector3.cpp:25
void RotateX(TFLOAT a_fRotation)
Definition TVector3.cpp:34
void RotateY(TFLOAT a_fRotation)
Definition TVector3.cpp:47
static constexpr TFLOAT DotProduct(const TVector3 &vec1, const TVector3 &vec2)
Definition TVector3.h:147
TFLOAT Magnitude() const
Definition TVector3.h:132

◆ Slerp()

void TQuaternion::Slerp ( TQuaternion & a_rOut,
const TQuaternion & a_rStart,
const TQuaternion & a_rEnd,
float a_fProgress )
static

Definition at line 163 of file TQuaternion.cpp.

164{
165 if ( a_fProgress == 0.0f )
166 {
167 a_rOut = a_rStart;
168 return;
169 }
170
171 if ( a_fProgress == 1.0f )
172 {
173 a_rOut = a_rEnd;
174 return;
175 }
176
177 TFLOAT fDot = TVector4::DotProduct4( a_rStart.AsVector4(), a_rEnd.AsVector4() );
178 TBOOL bNegativeDot = fDot < 0.0f;
179
180 if ( bNegativeDot )
181 fDot *= -1;
182
183 TFLOAT fProg1 = a_fProgress;
184 TFLOAT fProg2;
185
186 if ( 1.0f - fDot <= 0.001f )
187 {
188 fProg2 = 1.0f - a_fProgress;
189 }
190 else
191 {
192 TFLOAT fAcos = TMath::ACos( fDot );
193 TFLOAT fSin = TMath::Sin( fAcos );
194
195 fProg1 = TMath::Sin( fAcos * a_fProgress ) * ( 1.0f / fSin );
196 fProg2 = TMath::Sin( ( 1.0f - a_fProgress ) * fAcos ) * ( 1.0f / fSin );
197 }
198
199 if ( bNegativeDot )
200 {
201 a_rOut.x = a_rStart.x * fProg2 - a_rEnd.x * fProg1;
202 a_rOut.y = a_rStart.y * fProg2 - a_rEnd.y * fProg1;
203 a_rOut.z = a_rStart.z * fProg2 - a_rEnd.z * fProg1;
204 a_rOut.w = a_rStart.w * fProg2 - a_rEnd.w * fProg1;
205 }
206 else
207 {
208 a_rOut.x = a_rStart.x * fProg2 + a_rEnd.x * fProg1;
209 a_rOut.y = a_rStart.y * fProg2 + a_rEnd.y * fProg1;
210 a_rOut.z = a_rStart.z * fProg2 + a_rEnd.z * fProg1;
211 a_rOut.w = a_rStart.w * fProg2 + a_rEnd.w * fProg1;
212 }
213}
bool TBOOL
Definition Typedefs.h:6
TFORCEINLINE TFLOAT Sin(TFLOAT fVal)
Definition TMathInline.h:42

Member Data Documentation

◆ DELTA

TFLOAT TQuaternion::DELTA = 0.001f
inlinestaticconstexpr

Definition at line 77 of file TQuaternion.h.

◆ IDENTITY

const TQuaternion TQuaternion::IDENTITY = { 0.0f, 0.0f, 0.0f, 1.0f }
static

Definition at line 7 of file TQuaternion.h.

◆ w

TFLOAT TQuaternion::w

Definition at line 80 of file TQuaternion.h.

◆ x

TFLOAT TQuaternion::x

Definition at line 80 of file TQuaternion.h.

◆ y

TFLOAT TQuaternion::y

Definition at line 80 of file TQuaternion.h.

◆ z

TFLOAT TQuaternion::z

Definition at line 80 of file TQuaternion.h.


The documentation for this class was generated from the following files: