Leviathan  0.8.0.0
Leviathan game engine
Leviathan::Quaternion Struct Reference

A Quaternion type to make quaternion specific operations easier to access. More...

#include <Quaternion.h>

+ Inheritance diagram for Leviathan::Quaternion:

Public Member Functions

constexpr Quaternion () noexcept
 
constexpr Quaternion (const Quaternion &other) noexcept
 
constexpr Quaternion (const Float4 &copy) noexcept
 
constexpr Quaternion (float f1, float f2, float f3, float f4) noexcept
 
 Quaternion (const bs::Quaternion &quat)
 
 Quaternion (const Matrix3 &matrix)
 
constexpr Quaternion (const Float3 &axis, Radian angle) noexcept
 Makes a quaternion from axis angle. More...
 
 Quaternion (const Float3 &angles)
 Makes a quaternion from euler angles. More...
 
Float4 operator* (const Float4 &other) const noexcept=delete
 
Float4operator*= (const Float4 &other) noexcept=delete
 
Quaternionoperator= (const Quaternion &other) noexcept
 
constexpr bool operator== (const Quaternion &other) const noexcept
 
DLLEXPORT Quaternion operator+ (const Quaternion &other) const noexcept
 
DLLEXPORT Quaternionoperator+= (const Quaternion &other) noexcept
 
DLLEXPORT Quaternion operator- (const Quaternion &other) const noexcept
 
DLLEXPORT Quaternionoperator-= (const Quaternion &other) noexcept
 
DLLEXPORT Quaternion operator- () const noexcept
 
DLLEXPORT Quaternion operator+ () const noexcept
 
DLLEXPORT Quaternion operator* (float val) const noexcept
 
DLLEXPORT Quaternionoperator*= (float val) noexcept
 
constexpr Quaternion operator* (const Quaternion &other) const noexcept
 
constexpr Float3 operator* (const Float3 &vector) const noexcept
 Rotates a vector by this quaternion. More...
 
Float3 ToAxis () const
 
DLLEXPORT float ToAngle () const noexcept
 
Quaternion Inverse () const noexcept
 Inverts a quaternion. More...
 
Quaternion Reverse () const noexcept
 Reverse quaternion. You probably actually want to use Inverse. More...
 
DLLEXPORT Float3 XAxis () const
 
DLLEXPORT Float3 YAxis () const
 Computes the y-axis of the quaternion. More...
 
DLLEXPORT Float3 ZAxis () const
 
DLLEXPORT void FromRotationMatrix (const Matrix3 &matrix)
 
DLLEXPORT void ToRotationMatrix (Matrix3 &matrix) const
 
Quaternion Slerp (const Quaternion &other, float f) const
 does SPHERICAL interpolation between quaternions More...
 
DLLEXPORT Float3 ToEuler () const noexcept
 
 VALUE_TYPE (Quaternion)
 
- Public Member Functions inherited from Leviathan::Float4
DLLEXPORT constexpr Float4 () noexcept=default
 
DLLEXPORT constexpr Float4 (float f1, float f2, float f3, float f4)
 
DLLEXPORT constexpr Float4 (Float2 floats, float f3, float f4)
 
DLLEXPORT constexpr Float4 (Float3 floats, float f4)
 
DLLEXPORT constexpr Float4 (float data)
 
DLLEXPORT bool HasInvalidValues () const noexcept
 
DLLEXPORT void CheckForNans () const
 
DLLEXPORT float & operator[] (unsigned nindex)
 
DLLEXPORT float operator[] (unsigned nindex) const
 
DLLEXPORT operator float * () noexcept
 return first value of {X, Y, Z, W} as a pointer More...
 
DLLEXPORT Float4 operator+ (const Float4 &other) const noexcept
 
DLLEXPORT Float4operator+= (const Float4 &other) noexcept
 
DLLEXPORT Float4 operator- (const Float4 &other) const noexcept
 
DLLEXPORT Float4operator-= (const Float4 &other) noexcept
 
DLLEXPORT Float4 operator- () const noexcept
 
DLLEXPORT Float4 operator+ () const noexcept
 
DLLEXPORT Float4 operator* (const Float4 &other) const noexcept
 
DLLEXPORT Float4operator*= (const Float4 &other) noexcept
 
DLLEXPORT Float4 operator/ (float val) const
 
DLLEXPORT Float4operator/= (float val)
 
DLLEXPORT Float4 operator* (float val) const noexcept
 
DLLEXPORT Float4operator*= (float val) noexcept
 
DLLEXPORT Float4 operator/ (const Float4 &other) const
 
DLLEXPORT Float4operator/= (const Float4 &other)
 
DLLEXPORT bool operator< (const Float4 &other) const noexcept
 
DLLEXPORT bool operator<= (const Float4 &other) const noexcept
 
DLLEXPORT bool operator> (const Float4 &other) const noexcept
 
DLLEXPORT bool operator>= (const Float4 &other) const noexcept
 
DLLEXPORT bool operator== (const Float4 &other) const noexcept
 
DLLEXPORT bool operator!= (const Float4 &other) const noexcept
 
DLLEXPORT float GetX () const noexcept
 
DLLEXPORT float GetY () const noexcept
 
DLLEXPORT float GetZ () const noexcept
 
DLLEXPORT float GetW () const noexcept
 
DLLEXPORT void SetX (float val)
 
DLLEXPORT void SetY (float val)
 
DLLEXPORT void SetZ (float val)
 
DLLEXPORT void SetW (float val)
 
DLLEXPORT float HAdd () const noexcept
 
DLLEXPORT float HAddAbs () const noexcept
 
DLLEXPORT Float4 MinElements (const Float4 &other) const noexcept
 
DLLEXPORT Float4 MaxElements (const Float4 &other) const noexcept
 
DLLEXPORT Float4 Clamp (const Float4 &min, const Float4 &max) const noexcept
 
DLLEXPORT float Dot (const Float4 &val) const noexcept
 
DLLEXPORT float Length () const noexcept
 
DLLEXPORT float LengthSquared () const noexcept
 
DLLEXPORT Float4 Normalize () const
 
DLLEXPORT Float4 NormalizeSafe (const Float4 &safer=Float4(1, 0, 0, 0)) const noexcept
 
DLLEXPORT bool IsNormalized () const noexcept
 
DLLEXPORT Float4 Lerp (const Float4 &other, float f) const noexcept
 
DLLEXPORT bool Compare (const Float4 &other, float tolerance) const noexcept
 
DLLEXPORT void ConvertToHSB (float &hue, float &saturation, float &brightness) const
 
DLLEXPORT Float4 (const bs::Quaternion &quat)
 
DLLEXPORT Float4 (const bs::Color &colour)
 
DLLEXPORT operator bs::Quaternion () const
 
DLLEXPORT operator bs::Color () const
 
DLLEXPORT operator bs::Vector4 () const
 
DLLEXPORT Float4 (const btQuaternion &quat)
 
DLLEXPORT operator btQuaternion () const
 
 VALUE_TYPE (Float4)
 

Static Public Member Functions

static Quaternion LookAt (const Float3 &sourcepoint, const Float3 &target)
 
static constexpr Quaternion Identity ()
 
- Static Public Member Functions inherited from Leviathan::Float4
static DLLEXPORT Float4 FromHSB (float hue, float saturation, float brightness)
 
static DLLEXPORT const Float4GetColourBlack ()
 
static DLLEXPORT const Float4GetColourWhite ()
 
static DLLEXPORT const Float4GetColourTransparent ()
 

Static Public Attributes

static const Quaternion IDENTITY {0.f, 0.f, 0.f, 1.f}
 
- Static Public Attributes inherited from Leviathan::Float4
static DLLEXPORT const Float4 ColourBlack = Float4(0, 0, 0, 1)
 
static DLLEXPORT const Float4 ColourWhite = Float4(1, 1, 1, 1)
 
static DLLEXPORT const Float4 ColourTransparent = Float4(0, 0, 0, 0)
 

Additional Inherited Members

- Public Attributes inherited from Leviathan::Float4
float X = 0
 
float Y = 0
 
float Z = 0
 
float W = 0
 

Detailed Description

A Quaternion type to make quaternion specific operations easier to access.

Todo:
There are a ton of places that still use Float4 instead of Quaternion

Definition at line 14 of file Quaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/8]

constexpr Leviathan::Quaternion::Quaternion ( )
inlinenoexcept

Definition at line 16 of file Quaternion.h.

16 : Float4() {}
DLLEXPORT constexpr Float4() noexcept=default

◆ Quaternion() [2/8]

constexpr Leviathan::Quaternion::Quaternion ( const Quaternion other)
inlinenoexcept

Definition at line 17 of file Quaternion.h.

17 : Float4(other) {}
DLLEXPORT constexpr Float4() noexcept=default

◆ Quaternion() [3/8]

constexpr Leviathan::Quaternion::Quaternion ( const Float4 copy)
inlinenoexcept

Definition at line 18 of file Quaternion.h.

18 : Float4(copy) {}
DLLEXPORT constexpr Float4() noexcept=default

◆ Quaternion() [4/8]

constexpr Leviathan::Quaternion::Quaternion ( float  f1,
float  f2,
float  f3,
float  f4 
)
inlinenoexcept

Definition at line 20 of file Quaternion.h.

20  :
21  Float4(f1, f2, f3, f4)
22  {}
DLLEXPORT constexpr Float4() noexcept=default

◆ Quaternion() [5/8]

Leviathan::Quaternion::Quaternion ( const bs::Quaternion &  quat)
inline

Definition at line 24 of file Quaternion.h.

25  {
26  X = quat.x;
27  Y = quat.y;
28  Z = quat.z;
29  W = quat.w;
30  }

◆ Quaternion() [6/8]

Leviathan::Quaternion::Quaternion ( const Matrix3 matrix)
inlineexplicit

Definition at line 32 of file Quaternion.h.

33  {
34  FromRotationMatrix(matrix);
35  }
DLLEXPORT void FromRotationMatrix(const Matrix3 &matrix)
Definition: Quaternion.cpp:59

◆ Quaternion() [7/8]

constexpr Leviathan::Quaternion::Quaternion ( const Float3 axis,
Radian  angle 
)
inlinenoexcept

Makes a quaternion from axis angle.

Note
axis must be normalized

This resource is a life saver: http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm

Definition at line 42 of file Quaternion.h.

42  :
43  Float4(axis * static_cast<float>(
44  std::sin(angle.ValueInRadians() / 2.0f) /* this is 's' */),
45  static_cast<float>(std::cos(angle.ValueInRadians() / 2.0f) /* this is 'w' */))
46  {}
DLLEXPORT constexpr Float4() noexcept=default

◆ Quaternion() [8/8]

Leviathan::Quaternion::Quaternion ( const Float3 angles)
inline

Makes a quaternion from euler angles.

Definition at line 50 of file Quaternion.h.

51  {
52  // multiplied by 0.5 to get double the value //
53  const float cosx = std::cos(0.5f * angles.X);
54  const float cosy = std::cos(0.5f * angles.Y);
55  const float cosz = std::cos(0.5f * angles.Z);
56 
57  const float sinx = std::sin(0.5f * angles.X);
58  const float siny = std::sin(0.5f * angles.Y);
59  const float sinz = std::sin(0.5f * angles.Z);
60 
61  // compute quaternion //
62  // X
63  X = cosz * cosy * sinx - sinz * siny * cosx;
64  // Y
65  Y = cosz * siny * cosx + sinz * cosy * sinx;
66  // Z
67  Z = sinz * cosy * cosx - cosz * siny * sinx;
68  // W
69  W = cosz * cosy * cosx * sinz * siny * sinx;
70  }

Member Function Documentation

◆ FromRotationMatrix()

DLLEXPORT void Quaternion::FromRotationMatrix ( const Matrix3 matrix)

Definition at line 59 of file Quaternion.cpp.

60 {
61  // Code taken from bs::framework with modifications, see License.txt for details
62 
63  // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
64  // article "Quaternion Calculus and Fast Animation".
65 
66  float trace = matrix[0][0] + matrix[1][1] + matrix[2][2];
67  float root;
68 
69  if(trace > 0.0f) {
70  // |w| > 1/2, may as well choose w > 1/2
71  root = std::sqrt(trace + 1.0f); // 2w
72  W = 0.5f * root;
73  root = 0.5f / root; // 1/(4w)
74  X = (matrix[2][1] - matrix[1][2]) * root;
75  Y = (matrix[0][2] - matrix[2][0]) * root;
76  Z = (matrix[1][0] - matrix[0][1]) * root;
77  } else {
78  // |w| <= 1/2
79  static uint32_t nextLookup[3] = {1, 2, 0};
80  uint32_t i = 0;
81 
82  if(matrix[1][1] > matrix[0][0])
83  i = 1;
84 
85  if(matrix[2][2] > matrix[i][i])
86  i = 2;
87 
88  uint32_t j = nextLookup[i];
89  uint32_t k = nextLookup[j];
90 
91  root = std::sqrt(matrix[i][i] - matrix[j][j] - matrix[k][k] + 1.0f);
92 
93  float* cmpntLookup[3] = {&X, &Y, &Z};
94  *cmpntLookup[i] = 0.5f * root;
95  root = 0.5f / root;
96 
97  W = (matrix[k][j] - matrix[j][k]) * root;
98  *cmpntLookup[j] = (matrix[j][i] + matrix[i][j]) * root;
99  *cmpntLookup[k] = (matrix[k][i] + matrix[i][k]) * root;
100  }
101 
102  Normalize();
103 }
DLLEXPORT Float4 Normalize() const
Definition: Types.h:1655
unsigned int uint32_t
Definition: core.h:40

◆ Identity()

static constexpr Quaternion Leviathan::Quaternion::Identity ( )
inlinestatic

Definition at line 311 of file Quaternion.h.

312  {
313  return Quaternion{0.f, 0.f, 0.f, 1.f};
314  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ Inverse()

Quaternion Leviathan::Quaternion::Inverse ( ) const
inlinenoexcept

Inverts a quaternion.

Definition at line 207 of file Quaternion.h.

208  {
209  const auto length = Length();
210  if(length > 0.0f) {
211  const auto inverted = 1.0f / length;
212  return Quaternion(-X * inverted, -Y * inverted, -Z * inverted, W * inverted);
213  } else {
214  // Invalid inversing
215  return Quaternion(0.f, 0.f, 0.f, 0.f);
216  }
217  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16
DLLEXPORT float Length() const noexcept
Definition: Types.h:1644

◆ LookAt()

static Quaternion Leviathan::Quaternion::LookAt ( const Float3 sourcepoint,
const Float3 target 
)
inlinestatic

Definition at line 292 of file Quaternion.h.

293  {
294  const auto forward = (target - sourcepoint).NormalizeSafe();
295  const float dot = Float3::UnitVForward.Dot(forward);
296 
297  if(std::abs(dot - (-1.0f)) < 0.000001f) {
298  // Assumes up is Float3(0, 1, 0)
299  return Float4(Float3::UnitVUp, 3.1415926535897932f);
300  }
301 
302  if(std::abs(dot - 1.0f) < 0.000001f) {
303  return Quaternion::IDENTITY;
304  }
305 
306  const auto rotAngle = Radian(std::acos(dot));
307  const Float3 rotAxis = Float3::UnitVForward.Cross(forward).Normalize();
308  return Quaternion(rotAxis, rotAngle);
309  }
DLLEXPORT constexpr Float4() noexcept=default
static DLLEXPORT const Float3 UnitVUp
Definition: Types.h:1334
DLLEXPORT Float4 NormalizeSafe(const Float4 &safer=Float4(1, 0, 0, 0)) const noexcept
Definition: Types.h:1668
constexpr Quaternion() noexcept
Definition: Quaternion.h:16
DLLEXPORT Float3 Normalize() const
Definition: Types.h:1250
DLLEXPORT constexpr float Dot(const Float3 &val) const noexcept
Definition: Types.h:1227
static DLLEXPORT const Float3 UnitVForward
Definition: Types.h:1333
static const Quaternion IDENTITY
Definition: Quaternion.h:322
DLLEXPORT constexpr Float3 Cross(const Float3 &val) const
Definition: Types.h:1233

◆ operator*() [1/4]

Float4 Leviathan::Quaternion::operator* ( const Float4 other) const
inlinedeletenoexcept

◆ operator*() [2/4]

DLLEXPORT Quaternion Leviathan::Quaternion::operator* ( float  val) const
inlinenoexcept

Definition at line 138 of file Quaternion.h.

139  {
140  return Quaternion(X * val, Y * val, Z * val, W * val);
141  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ operator*() [3/4]

constexpr Quaternion Leviathan::Quaternion::operator* ( const Quaternion other) const
inlinenoexcept
Returns
A rotated quaternion

Definition at line 156 of file Quaternion.h.

157  {
158  return Quaternion(X * other.X + X * other.W + Y * other.Z - Z * other.Y,
159  W * other.Y - X * other.Z + Y * other.W + Z * other.X,
160  W * other.Z + X * other.Y - Y * other.X + Z * other.W,
161  W * other.W - X * other.X - Y * other.Y - Z * other.Z);
162  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ operator*() [4/4]

constexpr Float3 Leviathan::Quaternion::operator* ( const Float3 vector) const
inlinenoexcept

Rotates a vector by this quaternion.

Definition at line 165 of file Quaternion.h.

166  {
167  // // Alternative from
168  // //
169  // https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion
170  // const auto u = Float3(X, Y, Z);
171 
172  // // Complex math going on
173  // return u * 2.0f * u.Dot(vector)
174  // + vector * (W*W - u.Dot(u))
175  // + u.Cross(vector) * 2.0f * W;
176 
177  // Math taken from Ogre::Quaternion
178  Float3 qvec(X, Y, Z);
179  const Float3 uv1 = qvec.Cross(vector);
180  const Float3 uuv = qvec.Cross(uv1) * 2.0f;
181  const Float3 uv2 = uv1 * 2.0f * W;
182 
183  return vector + uv2 + uuv;
184  }

◆ operator*=() [1/2]

Float4& Leviathan::Quaternion::operator*= ( const Float4 other)
inlinedeletenoexcept

◆ operator*=() [2/2]

DLLEXPORT Quaternion& Leviathan::Quaternion::operator*= ( float  val)
inlinenoexcept

Definition at line 143 of file Quaternion.h.

144  {
145  X *= val;
146  Y *= val;
147  Z *= val;
148  W *= val;
149  return *this;
150  }

◆ operator+() [1/2]

DLLEXPORT Quaternion Leviathan::Quaternion::operator+ ( const Quaternion other) const
inlinenoexcept

Definition at line 95 of file Quaternion.h.

96  {
97  return Quaternion(X + other.X, Y + other.Y, Z + other.Z, W + other.W);
98  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ operator+() [2/2]

DLLEXPORT Quaternion Leviathan::Quaternion::operator+ ( ) const
inlinenoexcept

Definition at line 131 of file Quaternion.h.

132  {
133  return Quaternion(*this);
134  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ operator+=()

DLLEXPORT Quaternion& Leviathan::Quaternion::operator+= ( const Quaternion other)
inlinenoexcept

Definition at line 100 of file Quaternion.h.

101  {
102  X += other.X;
103  Y += other.Y;
104  Z += other.Z;
105  W += other.W;
106  return *this;
107  }

◆ operator-() [1/2]

DLLEXPORT Quaternion Leviathan::Quaternion::operator- ( const Quaternion other) const
inlinenoexcept

Definition at line 110 of file Quaternion.h.

111  {
112  return Quaternion(X - other.X, Y - other.Y, Z - other.Z, W - other.W);
113  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ operator-() [2/2]

DLLEXPORT Quaternion Leviathan::Quaternion::operator- ( ) const
inlinenoexcept

Definition at line 125 of file Quaternion.h.

126  {
127  return Quaternion(-X, -Y, -Z, -W);
128  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ operator-=()

DLLEXPORT Quaternion& Leviathan::Quaternion::operator-= ( const Quaternion other)
inlinenoexcept

Definition at line 115 of file Quaternion.h.

116  {
117  X -= other.X;
118  Y -= other.Y;
119  Z -= other.Z;
120  W -= other.W;
121  return *this;
122  }

◆ operator=()

Quaternion& Leviathan::Quaternion::operator= ( const Quaternion other)
inlinenoexcept

Definition at line 80 of file Quaternion.h.

81  {
82  X = other.X;
83  Y = other.Y;
84  Z = other.Z;
85  W = other.W;
86  return *this;
87  }

◆ operator==()

constexpr bool Leviathan::Quaternion::operator== ( const Quaternion other) const
inlinenoexcept

Definition at line 89 of file Quaternion.h.

90  {
91  return X == other.X && Y == other.Y && Z == other.Z && W == other.W;
92  }

◆ Reverse()

Quaternion Leviathan::Quaternion::Reverse ( ) const
inlinenoexcept

Reverse quaternion. You probably actually want to use Inverse.

Definition at line 220 of file Quaternion.h.

221  {
222  return Quaternion(-X, -Y, -Z, W);
223  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16

◆ Slerp()

Quaternion Leviathan::Quaternion::Slerp ( const Quaternion other,
float  f 
) const
inline

does SPHERICAL interpolation between quaternions

Definition at line 240 of file Quaternion.h.

241  {
242  // extra quaternion for calculations //
243  Quaternion quaternion3;
244 
245  // dot product of both //
246  float dot = this->Dot(other);
247 
248  if(dot < 0) {
249  dot = -dot;
250  quaternion3 = -other;
251  } else {
252  quaternion3 = other;
253  }
254 
255  if(dot < 0.95f) {
256  const float angle = std::acos(dot);
257  return ((*this) * std::sin(angle * (1 - f)) + quaternion3 * std::sin(angle * f)) /
258  sinf(angle);
259 
260  } else {
261  // small angle, linear interpolation will be fine //
262  return this->Lerp(quaternion3, f);
263  }
264  }
constexpr Quaternion() noexcept
Definition: Quaternion.h:16
DLLEXPORT Float4 Lerp(const Float4 &other, float f) const noexcept
Definition: Types.h:1688
DLLEXPORT float Dot(const Float4 &val) const noexcept
Definition: Types.h:1638

◆ ToAngle()

DLLEXPORT float Leviathan::Quaternion::ToAngle ( ) const
inlinenoexcept

Converts a quaternion to angle (and skips outputting the Axis)

Note
Must be normalized

Definition at line 201 of file Quaternion.h.

202  {
203  return 2 * std::acos(W);
204  }

◆ ToAxis()

Float3 Leviathan::Quaternion::ToAxis ( ) const
inline

Converts a quaternion to Axis (and skips outputting the angle)

Note
Must be normalized

Definition at line 188 of file Quaternion.h.

189  {
190  const auto s = std::sqrt(1 - std::pow(W, 2));
191  // Avoid division by zero (this small axis it can be basically converted directly)
192  if(s > 0) {
193  return Float3(X / s, Y / s, Z / s);
194  } else {
195  return Float3(X, Y, Z);
196  }
197  }

◆ ToEuler()

DLLEXPORT Float3 Leviathan::Quaternion::ToEuler ( ) const
inlinenoexcept
Note
This quaternion has to be normalized
See also
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/

Definition at line 269 of file Quaternion.h.

270  {
271  const float test = X * Y + Z * W;
272 
273  if(test > 0.499) {
274  // Singularity at north pole
275  return Float3(2 * std::atan2(X, W), PI / 2, 0);
276  }
277 
278  if(test < -0.499) {
279  // Singularity at south pole
280  return Float3(-2 * std::atan2(X, W), -PI / 2, 0);
281  }
282 
283  const float sqx = X * X;
284  const float sqy = Y * Y;
285  const float sqz = Z * Z;
286 
287  return Float3(std::atan2(2 * Y * W - 2 * X * Z, 1 - 2 * sqy - 2 * sqz),
288  std::asin(2 * test), std::atan2(2 * X * W - 2 * Y * Z, 1 - 2 * sqx - 2 * sqz));
289  }
constexpr float PI
Definition: Define.h:65

◆ ToRotationMatrix()

DLLEXPORT void Quaternion::ToRotationMatrix ( Matrix3 matrix) const

Definition at line 105 of file Quaternion.cpp.

106 {
107  // Math from bs::framework
108  const float tx = X + X;
109  const float ty = Y + Y;
110  const float tz = Z + Z;
111  const float twx = tx * W;
112  const float twy = ty * W;
113  const float twz = tz * W;
114  const float txx = tx * X;
115  const float txy = ty * X;
116  const float txz = tz * X;
117  const float tyy = ty * Y;
118  const float tyz = tz * Y;
119  const float tzz = tz * Z;
120 
121  matrix[0][0] = 1.0f - (tyy + tzz);
122  matrix[0][1] = txy - twz;
123  matrix[0][2] = txz + twy;
124  matrix[1][0] = txy + twz;
125  matrix[1][1] = 1.0f - (txx + tzz);
126  matrix[1][2] = tyz - twx;
127  matrix[2][0] = txz - twy;
128  matrix[2][1] = tyz + twx;
129  matrix[2][2] = 1.0f - (txx + tyy);
130 }

◆ VALUE_TYPE()

Leviathan::Quaternion::VALUE_TYPE ( Quaternion  )

◆ XAxis()

DLLEXPORT Float3 Quaternion::XAxis ( ) const

Definition at line 15 of file Quaternion.cpp.

16 {
17  const float fTy = 2.0f * Y;
18  const float fTz = 2.0f * Z;
19  const float fTwy = fTy * W;
20  const float fTwz = fTz * W;
21  const float fTxy = fTy * X;
22  const float fTxz = fTz * X;
23  const float fTyy = fTy * Y;
24  const float fTzz = fTz * Z;
25 
26  return Float3(1.0f - (fTyy + fTzz), fTxy + fTwz, fTxz - fTwy);
27 }

◆ YAxis()

DLLEXPORT Float3 Quaternion::YAxis ( ) const

Computes the y-axis of the quaternion.

Definition at line 29 of file Quaternion.cpp.

30 {
31  const float fTx = 2.0f * X;
32  const float fTy = 2.0f * Y;
33  const float fTz = 2.0f * Z;
34  const float fTwx = fTx * W;
35  const float fTwz = fTz * W;
36  const float fTxx = fTx * X;
37  const float fTxy = fTy * X;
38  const float fTyz = fTz * Y;
39  const float fTzz = fTz * Z;
40 
41  return Float3(fTxy - fTwz, 1.0f - (fTxx + fTzz), fTyz + fTwx);
42 }

◆ ZAxis()

DLLEXPORT Float3 Quaternion::ZAxis ( ) const

Definition at line 44 of file Quaternion.cpp.

45 {
46  const float fTx = 2.0f * X;
47  const float fTy = 2.0f * Y;
48  const float fTz = 2.0f * Z;
49  const float fTwx = fTx * W;
50  const float fTwy = fTy * W;
51  const float fTxx = fTx * X;
52  const float fTxz = fTz * X;
53  const float fTyy = fTy * Y;
54  const float fTyz = fTz * Y;
55 
56  return Float3(fTxz + fTwy, fTyz - fTwx, 1.0f - (fTxx + fTyy));
57 }

Member Data Documentation

◆ IDENTITY

constexpr const Quaternion Leviathan::Quaternion::IDENTITY {0.f, 0.f, 0.f, 1.f}
inlinestatic

Definition at line 322 of file Quaternion.h.


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