summaryrefslogtreecommitdiff
path: root/src/mbgl/util/quaternion.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util/quaternion.hpp')
-rw-r--r--src/mbgl/util/quaternion.hpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mbgl/util/quaternion.hpp b/src/mbgl/util/quaternion.hpp
new file mode 100644
index 0000000000..b2ae40eaf7
--- /dev/null
+++ b/src/mbgl/util/quaternion.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "mat3.hpp"
+#include "mat4.hpp"
+
+namespace mbgl {
+
+struct Quaternion {
+ union {
+ vec4 m;
+ struct {
+ double x, y, z, w;
+ };
+ };
+
+ Quaternion() : Quaternion(0.0, 0.0, 0.0, 0.0) {}
+ Quaternion(double x_, double y_, double z_, double w_) : x(x_), y(y_), z(z_), w(w_) {}
+ Quaternion(const vec4& vec) : m(vec) {}
+
+ Quaternion conjugate() const;
+ Quaternion normalized() const;
+ Quaternion multiply(const Quaternion& o) const;
+ double length() const;
+ vec3 transform(const vec3& v) const;
+ mat4 toRotationMatrix() const;
+
+ static Quaternion fromAxisAngle(const vec3& axis, double angleRad);
+ static Quaternion fromEulerAngles(double x, double y, double z);
+
+ static Quaternion identity;
+};
+
+bool operator==(const Quaternion&, const Quaternion&);
+bool operator!=(const Quaternion&, const Quaternion&);
+
+} // namespace mbgl \ No newline at end of file