X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fquat.h;h=aabf2c2bfbd55853c7dc316a1dc049be6f47390e;hb=19e9cbd5ac2394b302a9e79b15cad8faf071b6e1;hp=d77f70f7cb96b0403b90bdd538d727aa9e90e1ee;hpb=049b9453cf079d9aa0710b3a885e96d0920e5547;p=gph-math diff --git a/src/quat.h b/src/quat.h index d77f70f..aabf2c2 100644 --- a/src/quat.h +++ b/src/quat.h @@ -1,7 +1,17 @@ +/* +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 { @@ -15,10 +25,16 @@ public: 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) {} - void normalize(); - void invert(); + inline void normalize(); + inline void conjugate(); + inline void invert(); - Matrix4x4 calc_matrix() const; + 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); @@ -30,12 +46,11 @@ 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 Quaternion conjugate(const Quaternion &q); - 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);