fixed copying of library links in install target
[gph-math] / src / quat.h
1 /*
2 gph-math - math library for graphics programs
3 Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software. Feel free to use, modify, and/or redistribute
6 it under the terms of the MIT/X11 license. See LICENSE for details.
7 If you intend to redistribute parts of the code without the LICENSE file
8 replace this paragraph with the full contents of the LICENSE file.
9 */
10 #ifndef QUATERNION_H_
11 #define QUATERNION_H_
12
13 #include "vector.h"
14 #include "matrix.h"
15
16 namespace gph {
17
18 class Quaternion {
19 public:
20         float x, y, z, w;       // w + xi + yj + zk
21
22         static Quaternion identity;
23
24         Quaternion() : x(0), y(0), z(0), w(1) {}
25         Quaternion(float x_, float y_, float z_, float w_) : x(x_), y(y_), z(z_), w(w_) {}
26         Quaternion(const Vector3 &v, float s) : x(v.x), y(v.y), z(v.z), w(s) {}
27
28         inline void normalize();
29         inline void conjugate();
30         inline void invert();
31
32         inline void set_rotation(const Vector3 &axis, float angle);
33         inline void rotate(const Vector3 &axis, float angle);
34         // rotate by a quaternion rq by doing: rq * *this * conjugate(rq)
35         inline void rotate(const Quaternion &rq);
36
37         inline Matrix4x4 calc_matrix() const;
38 };
39
40 inline Quaternion operator -(const Quaternion &q);
41 inline Quaternion operator +(const Quaternion &a, const Quaternion &b);
42 inline Quaternion operator -(const Quaternion &a, const Quaternion &b);
43 inline Quaternion operator *(const Quaternion &a, const Quaternion &b);
44
45 inline Quaternion &operator +=(Quaternion &a, const Quaternion &b);
46 inline Quaternion &operator -=(Quaternion &a, const Quaternion &b);
47 inline Quaternion &operator *=(Quaternion &a, const Quaternion &b);
48
49 inline float length(const Quaternion &q);
50 inline float length_sq(const Quaternion &q);
51
52 inline Quaternion normalize(const Quaternion &q);
53 inline Quaternion conjugate(const Quaternion &q);
54 inline Quaternion inverse(const Quaternion &q);
55
56 Quaternion slerp(const Quaternion &a, const Quaternion &b, float t);
57 inline Quaternion lerp(const Quaternion &a, const Quaternion &b, float t);
58
59 #include "quat.inl"
60
61 }       // namespace gph
62
63 #endif  // QUATERNION_H_