| Flutter Impeller |

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 13 of file quaternion.h.

## Constructor & Destructor Documentation

## ◆ Quaternion() [1/3]

impeller::Quaternion::Quaternion | ( |  | ) |
| inline

Definition at line 24 of file quaternion.h.

24 {}

## ◆ Quaternion() [2/3]

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

Definition at line 26 of file quaternion.h.

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

## ◆ Quaternion() [3/3]

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

Definition at line 29 of file quaternion.h.

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

References w, x, impeller::Vector3::x, y, impeller::Vector3::y, z, and impeller::Vector3::z.

## Member Function Documentation

## ◆ Dot()

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

Definition at line 37 of file quaternion.h.

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

References w, x, y, and z.

Referenced by Slerp().

## ◆ Invert()

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

Definition at line 48 of file quaternion.h.

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

References w, x, y, and z.

Referenced by impeller::scene::RotationTimelineResolver::Apply().

## ◆ Length()

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

Definition at line 41 of file quaternion.h.

41 { return sqrt(x * x + y * y + z * z + w * w); }

References w, x, y, and z.

Referenced by Normalize().

## ◆ Normalize()

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

Definition at line 43 of file quaternion.h.

43 {
44 auto m = 1.0f / Length();
45 return {x * m, y * m, z * m, w * m};
46 }

References Length(), w, x, y, and z.

Referenced by Slerp().

## ◆ operator!=()

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

Definition at line 84 of file quaternion.h.

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

References w, x, y, and z.

## ◆ operator*() [1/3]

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

Definition at line 52 of file quaternion.h.

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

References w, x, y, and z.

## ◆ operator*() [2/3]

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

Definition at line 61 of file quaternion.h.

61 {
62 return {scale * x, scale * y, scale * z, scale * w};
63 }

References w, x, y, and z.

## ◆ operator*() [3/3]

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

Definition at line 65 of file quaternion.h.

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

References impeller::Vector3::Cross(), impeller::Vector3::Dot(), w, x, y, and z.

## ◆ operator+()

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

Definition at line 72 of file quaternion.h.

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

References w, x, y, and z.

## ◆ operator-()

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

Definition at line 76 of file quaternion.h.

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

References w, x, y, and z.

## ◆ operator==()

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

Definition at line 80 of file quaternion.h.

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

References w, x, y, and z.

## ◆ 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 }

References Dot(), e, and Normalize().

Referenced by impeller::scene::RotationTimelineResolver::Apply().

## Member Data Documentation

## ◆ @15

union { ... }

## ◆ e

Scalar impeller::Quaternion::e[4]

Definition at line 21 of file quaternion.h.

Referenced by Slerp().

## ◆ w

Scalar impeller::Quaternion::w = 1.0

Definition at line 19 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

## ◆ x

Scalar impeller::Quaternion::x = 0.0

Definition at line 16 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

## ◆ y

Scalar impeller::Quaternion::y = 0.0

Definition at line 17 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

## ◆ z

Scalar impeller::Quaternion::z = 0.0

Definition at line 18 of file quaternion.h.

Referenced by impeller::Matrix::Decompose(), Dot(), Invert(), Length(), impeller::Matrix::MakeRotation(), impeller::Matrix::Matrix(), Normalize(), operator!=(), operator*(), operator+(), operator-(), std::operator<<(), operator==(), Quaternion(), and QuaternionNear().

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

- impeller/geometry/quaternion.h
- impeller/geometry/quaternion.cc

impeller::Quaternion::z
Scalar z
Definition: quaternion.h:18
impeller::Quaternion::e
Scalar e[4]
Definition: quaternion.h:21
impeller::Quaternion::w
Scalar w
Definition: quaternion.h:19
impeller::Quaternion::x
Scalar x
Definition: quaternion.h:16
impeller::Quaternion::Dot
Scalar Dot(const Quaternion &q) const
Definition: quaternion.h:37
impeller::Quaternion::y
Scalar y
Definition: quaternion.h:17
impeller::Quaternion::Length
Scalar Length() const
Definition: quaternion.h:41