NcEngine
Quaternion.h
Go to the documentation of this file.
1
5#pragma once
6
7#include "Vector.h"
8
9namespace nc
10{
13{
14 float x, y, z, w;
15
16 constexpr explicit Quaternion()
17 : x{0.0f}, y{0.0f}, z{0.0f}, w{1.0f}
18 {
19 }
20
21 explicit Quaternion(float X, float Y, float Z, float W);
22
23 auto ToEulerAngles() const noexcept -> Vector3;
24 void ToAxisAngle(Vector3* axisOut, float* angleOut) const noexcept;
25
26 static constexpr auto Identity() -> Quaternion { return Quaternion{}; }
27 static auto FromEulerAngles(const Vector3& angles) -> Quaternion;
28 static auto FromEulerAngles(float x, float y, float z) -> Quaternion;
29 static auto FromAxisAngle(const Vector3& axis, float radians) -> Quaternion; // axis cannot be zero
30};
31
33auto Normalize(const Quaternion& quat) -> Quaternion;
34
40auto Multiply(const Quaternion& lhs, const Quaternion& rhs) -> Quaternion;
41
43auto Difference(const Quaternion& lhs, const Quaternion& rhs) -> Quaternion;
44
46auto Slerp(const Quaternion& lhs, const Quaternion& rhs, float factor) -> Quaternion;
47
49auto Scale(const Quaternion& quat, float factor) -> Quaternion;
50
51inline auto operator==(const Quaternion& lhs, const Quaternion& rhs) -> bool
52{
53 return FloatEqual(lhs.x, rhs.x) &&
54 FloatEqual(lhs.y, rhs.y) &&
55 FloatEqual(lhs.z, rhs.z) &&
56 FloatEqual(lhs.w, rhs.w);
57}
58
59inline auto operator!=(const Quaternion& lhs, const Quaternion& rhs) -> bool
60{
61 return !(lhs == rhs);
62}
63} // namespace nc
auto Normalize(const Quaternion &quat) -> Quaternion
Return a normalized quaternion.
auto Multiply(const Quaternion &lhs, const Quaternion &rhs) -> Quaternion
Multiplies two quaternions.
auto Scale(const Quaternion &quat, float factor) -> Quaternion
Slerp from Identity to quat.
auto Slerp(const Quaternion &lhs, const Quaternion &rhs, float factor) -> Quaternion
Interpolates from lhs to rhs.
auto Difference(const Quaternion &lhs, const Quaternion &rhs) -> Quaternion
Finds rotation between lhs and rhs such that result * lhs == rhs.
Quaternion type for representing 3D rotations.
Definition: Quaternion.h:13
A three component vector.
Definition: Vector.h:29