X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fquat.h;h=aabf2c2bfbd55853c7dc316a1dc049be6f47390e;hb=19e9cbd5ac2394b302a9e79b15cad8faf071b6e1;hp=4b71c7c894532ddecd8c8ad4b842e56a0e4c3dad;hpb=bdeb1048917667c00f540c17f397443e8f6f76bf;p=gph-math diff --git a/src/quat.h b/src/quat.h index 4b71c7c..aabf2c2 100644 --- a/src/quat.h +++ b/src/quat.h @@ -1,19 +1,63 @@ +/* +gph-math - math library for graphics programs +Copyright (C) 2016 John Tsiombikas + +This program is free software. Feel free to use, modify, and/or redistribute +it under the terms of the MIT/X11 license. See LICENSE for details. +If you intend to redistribute parts of the code without the LICENSE file +replace this paragraph with the full contents of the LICENSE file. +*/ #ifndef QUATERNION_H_ #define QUATERNION_H_ +#include "vector.h" +#include "matrix.h" + namespace gph { class Quaternion { public: float x, y, z, w; // w + xi + yj + zk + static Quaternion identity; + Quaternion() : x(0), y(0), z(0), w(1) {} Quaternion(float x_, float y_, float z_, float w_) : x(x_), y(y_), z(z_), w(w_) {} Quaternion(const Vector3 &v, float s) : x(v.x), y(v.y), z(v.z), w(s) {} - // TODO more + inline void normalize(); + inline void conjugate(); + inline void invert(); + + inline void set_rotation(const Vector3 &axis, float angle); + inline void rotate(const Vector3 &axis, float angle); + // rotate by a quaternion rq by doing: rq * *this * conjugate(rq) + inline void rotate(const Quaternion &rq); + + inline Matrix4x4 calc_matrix() const; }; +inline Quaternion operator -(const Quaternion &q); +inline Quaternion operator +(const Quaternion &a, const Quaternion &b); +inline Quaternion operator -(const Quaternion &a, const Quaternion &b); +inline Quaternion operator *(const Quaternion &a, const Quaternion &b); + +inline Quaternion &operator +=(Quaternion &a, const Quaternion &b); +inline Quaternion &operator -=(Quaternion &a, const Quaternion &b); +inline Quaternion &operator *=(Quaternion &a, const Quaternion &b); + +inline float length(const Quaternion &q); +inline float length_sq(const Quaternion &q); + +inline Quaternion normalize(const Quaternion &q); +inline Quaternion conjugate(const Quaternion &q); +inline Quaternion inverse(const Quaternion &q); + +Quaternion slerp(const Quaternion &a, const Quaternion &b, float t); +inline Quaternion lerp(const Quaternion &a, const Quaternion &b, float t); + +#include "quat.inl" + } // namespace gph #endif // QUATERNION_H_