SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Quaternion.hpp
Go to the documentation of this file.
1#ifndef _QUATERNION_H_
2#define _QUATERNION_H_
3
4#include <Math/Vector.hpp>
6
7namespace Sleak {
8 namespace Math {
9
10 /**
11 * @class Quaternion
12 * @brief Represents a quaternion for 3D rotations.
13 *
14 * Quaternions provide a more robust and efficient way to represent rotations
15 * compared to Euler angles, avoiding issues like gimbal lock.
16 *
17 * This class provides functionalities for creating, manipulating, and
18 * using quaternions for various 3D rotation operations.
19 * @ingroup math
20 */
21
22 //Forward Declare
23 template <typename T, size_t Rows, size_t Cols>
24 class Matrix;
25
26 class Quaternion {
27 public:
28 float w; // Scalar component
29 float x; // Vector component (i)
30 float y; // Vector component (j)
31 float z; // Vector component (k)
32
33 // Constructors
34 Quaternion();
35 Quaternion(float w, float x, float y, float z);
36 Quaternion(const Vector3D& axis, float angle);
37 Quaternion(const Matrix<float, 4, 4>& matrix);
38
39 // Accessors and Mutators
40 float& operator[](int index);
41 const float& operator[](int index) const;
42
43 // Quaternion Operations
44 Quaternion operator*(const Quaternion& other) const;
45 Quaternion& operator*=(const Quaternion& other);
46 Quaternion operator-() const;
47
48 float GetX() const;
49 float GetY() const;
50 float GetZ() const;
51 float GetW() const;
52
53 // Normalize the quaternion
54 void normalize();
55
56 // Calculate the magnitude of the quaternion
57 float magnitude() const;
58
59 // Calculate the conjugate of the quaternion
60 Quaternion conjugate() const;
61
62 // Calculate the inverse of the quaternion
63 Quaternion inverse() const;
64
65 // Rotate a vector by this quaternion
66 Vector3D rotateVector(const Vector3D& vec) const;
67
68 // Conversion to Rotation Matrix
70
71 // Static method for look rotation
72 static Quaternion LookRotation(Vector3D& forward, Vector3D& up);
73 private:
74 };
75
76 // Free function for quaternion-vector multiplication
77 Vector3D operator*(const Quaternion& quat, const Vector3D& vec);
78
79 } // namespace Math
80} // namespace Sleak
81
82#endif // _QUATERNION_H_
Represents a quaternion for 3D rotations.
Quaternion operator*(const Quaternion &other) const
Quaternion conjugate() const
Quaternion & operator*=(const Quaternion &other)
Vector3D rotateVector(const Vector3D &vec) const
static Quaternion LookRotation(Vector3D &forward, Vector3D &up)
float & operator[](int index)
Matrix< float, 4, 4 > toRotationMatrix() const
Quaternion operator-() const
Quaternion inverse() const
Vectors, matrices, quaternions, colors, AABBs, and random helpers.
Vector3D operator*(const Quaternion &quat, const Vector3D &vec)
Root namespace for everything the engine exposes.
Definition Camera.hpp:10