Flutter Engine
The Flutter Engine
Public Member Functions | Public Attributes | List of all members
impeller::Quaternion Struct Reference

#include <quaternion.h>

Public Member Functions

 Quaternion ()
 
 Quaternion (Scalar px, Scalar py, Scalar pz, Scalar pw)
 
 Quaternion (const Vector3 &axis, Scalar angle)
 
Scalar Dot (const Quaternion &q) const
 
Scalar Length () const
 
Quaternion Normalize () const
 
Quaternion Invert () const
 
Quaternion Slerp (const Quaternion &to, double time) const
 
Quaternion operator* (const Quaternion &o) const
 
Quaternion operator* (Scalar scale) const
 
Vector3 operator* (Vector3 vector) const
 
Quaternion operator+ (const Quaternion &o) const
 
Quaternion operator- (const Quaternion &o) const
 
bool operator== (const Quaternion &o) const
 
bool operator!= (const Quaternion &o) const
 

Public Attributes

union {
   struct {
      Scalar   x = 0.0
 
      Scalar   y = 0.0
 
      Scalar   z = 0.0
 
      Scalar   w = 1.0
 
   } 
 
   Scalar   e [4]
 
}; 
 

Detailed Description

Definition at line 14 of file quaternion.h.

Constructor & Destructor Documentation

◆ Quaternion() [1/3]

impeller::Quaternion::Quaternion ( )
inline

Definition at line 25 of file quaternion.h.

25{}

◆ Quaternion() [2/3]

impeller::Quaternion::Quaternion ( Scalar  px,
Scalar  py,
Scalar  pz,
Scalar  pw 
)
inline

Definition at line 27 of file quaternion.h.

28 : x(px), y(py), z(pz), w(pw) {}

◆ Quaternion() [3/3]

impeller::Quaternion::Quaternion ( const Vector3 axis,
Scalar  angle 
)
inline

Definition at line 30 of file quaternion.h.

30 {
31 const auto sine = sin(angle * 0.5f);
32 x = sine * axis.x;
33 y = sine * axis.y;
34 z = sine * axis.z;
35 w = cos(angle * 0.5f);
36 }

Member Function Documentation

◆ Dot()

Scalar impeller::Quaternion::Dot ( const Quaternion q) const
inline

Definition at line 38 of file quaternion.h.

38 {
39 return x * q.x + y * q.y + z * q.z + w * q.w;
40 }

◆ Invert()

Quaternion impeller::Quaternion::Invert ( ) const
inline

Definition at line 49 of file quaternion.h.

49{ return {-x, -y, -z, w}; }

◆ Length()

Scalar impeller::Quaternion::Length ( ) const
inline

Definition at line 42 of file quaternion.h.

42{ return sqrt(x * x + y * y + z * z + w * w); }
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition: SkVx.h:706

◆ Normalize()

Quaternion impeller::Quaternion::Normalize ( ) const
inline

Definition at line 44 of file quaternion.h.

44 {
45 auto m = 1.0f / Length();
46 return {x * m, y * m, z * m, w * m};
47 }
Scalar Length() const
Definition: quaternion.h:42

◆ operator!=()

bool impeller::Quaternion::operator!= ( const Quaternion o) const
inline

Definition at line 85 of file quaternion.h.

85 {
86 return x != o.x || y != o.y || z != o.z || w != o.w;
87 }

◆ operator*() [1/3]

Quaternion impeller::Quaternion::operator* ( const Quaternion o) const
inline

Definition at line 53 of file quaternion.h.

53 {
54 return {
55 w * o.x + x * o.w + y * o.z - z * o.y,
56 w * o.y + y * o.w + z * o.x - x * o.z,
57 w * o.z + z * o.w + x * o.y - y * o.x,
58 w * o.w - x * o.x - y * o.y - z * o.z,
59 };
60 }

◆ operator*() [2/3]

Quaternion impeller::Quaternion::operator* ( Scalar  scale) const
inline

Definition at line 62 of file quaternion.h.

62 {
63 return {scale * x, scale * y, scale * z, scale * w};
64 }
const Scalar scale

◆ operator*() [3/3]

Vector3 impeller::Quaternion::operator* ( Vector3  vector) const
inline

Definition at line 66 of file quaternion.h.

66 {
67 Vector3 v(x, y, z);
68 return v * v.Dot(vector) * 2 + //
69 vector * (w * w - v.Dot(v)) + //
70 v.Cross(vector) * 2 * w;
71 }

◆ operator+()

Quaternion impeller::Quaternion::operator+ ( const Quaternion o) const
inline

Definition at line 73 of file quaternion.h.

73 {
74 return {x + o.x, y + o.y, z + o.z, w + o.w};
75 }

◆ operator-()

Quaternion impeller::Quaternion::operator- ( const Quaternion o) const
inline

Definition at line 77 of file quaternion.h.

77 {
78 return {x - o.x, y - o.y, z - o.z, w - o.w};
79 }

◆ operator==()

bool impeller::Quaternion::operator== ( const Quaternion o) const
inline

Definition at line 81 of file quaternion.h.

81 {
82 return x == o.x && y == o.y && z == o.z && w == o.w;
83 }

◆ Slerp()

Quaternion impeller::Quaternion::Slerp ( const Quaternion to,
double  time 
) const

Definition at line 10 of file quaternion.cc.

10 {
11 double cosine = Dot(to);
12 if (fabs(cosine) < 1.0 - 1e-3 /* epsilon */) {
13 /*
14 * Spherical Interpolation.
15 */
16 auto sine = sqrt(1.0 - cosine * cosine);
17 auto angle = atan2(sine, cosine);
18 auto sineInverse = 1.0 / sine;
19 auto c0 = sin((1.0 - time) * angle) * sineInverse;
20 auto c1 = sin(time * angle) * sineInverse;
21 return *this * c0 + to * c1;
22 } else {
23 /*
24 * Linear Interpolation.
25 */
26 return (*this * (1.0 - time) + to * time).Normalize();
27 }
28}
static double time(int loops, Benchmark *bench, Target *target)
Definition: nanobench.cpp:394
Scalar Dot(const Quaternion &q) const
Definition: quaternion.h:38

Member Data Documentation

◆ 

union { ... } impeller::Quaternion::@31

◆ e

Scalar impeller::Quaternion::e[4]

Definition at line 22 of file quaternion.h.

◆ w

Scalar impeller::Quaternion::w = 1.0

Definition at line 20 of file quaternion.h.

◆ x

Scalar impeller::Quaternion::x = 0.0

Definition at line 17 of file quaternion.h.

◆ y

Scalar impeller::Quaternion::y = 0.0

Definition at line 18 of file quaternion.h.

◆ z

Scalar impeller::Quaternion::z = 0.0

Definition at line 19 of file quaternion.h.


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