2 gph-math - math library for graphics programs
3 Copyright (C) 2016 John Tsiombikas <nuclear@member.fsf.org>
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.
20 float x, y, z, w; // w + xi + yj + zk
22 static Quaternion identity;
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) {}
28 inline void normalize();
29 inline void conjugate();
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);
37 inline Matrix4x4 calc_matrix() const;
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);
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);
49 inline float length(const Quaternion &q);
50 inline float length_sq(const Quaternion &q);
52 inline Quaternion normalize(const Quaternion &q);
53 inline Quaternion conjugate(const Quaternion &q);
54 inline Quaternion inverse(const Quaternion &q);
56 Quaternion slerp(const Quaternion &a, const Quaternion &b, float t);
57 inline Quaternion lerp(const Quaternion &a, const Quaternion &b, float t);
63 #endif // QUATERNION_H_