X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2F3dengfx%2Fsrc%2Fn3dmath2%2Fn3dmath2_qua.hpp;fp=src%2F3dengfx%2Fsrc%2Fn3dmath2%2Fn3dmath2_qua.hpp;h=8d503c776553a1259352ecee78a6a50fcf8ff4b6;hb=6e23259dbabaeb1711a2a5ca25b9cb421f693759;hp=0000000000000000000000000000000000000000;hpb=fe068fa879814784c45e0cb2e65dac489e8f5594;p=summerhack diff --git a/src/3dengfx/src/n3dmath2/n3dmath2_qua.hpp b/src/3dengfx/src/n3dmath2/n3dmath2_qua.hpp new file mode 100644 index 0000000..8d503c7 --- /dev/null +++ b/src/3dengfx/src/n3dmath2/n3dmath2_qua.hpp @@ -0,0 +1,80 @@ +/* +This file is part of the n3dmath2 library. + +Copyright (c) 2003 - 2005 John Tsiombikas + +The n3dmath2 library is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +The n3dmath2 library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the n3dmath2 library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* quaterinion math + * + * Author: John Tsiombikas 2003 + * Modified: John Tsiombikas 2004, 2005 + */ + +#ifndef _N3DMATH2_QUA_HPP_ +#define _N3DMATH2_QUA_HPP_ + +#include +#include "n3dmath2_types.hpp" + +class Quaternion { +public: + scalar_t s; + Vector3 v; + + Quaternion(); + Quaternion(scalar_t s, const Vector3 &v); + Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z); + Quaternion(const Vector3 &axis, scalar_t angle); + + Quaternion operator +(const Quaternion &quat) const; + Quaternion operator -(const Quaternion &quat) const; + Quaternion operator -() const; + Quaternion operator *(const Quaternion &quat) const; + + void operator +=(const Quaternion &quat); + void operator -=(const Quaternion &quat); + void operator *=(const Quaternion &quat); + + void reset_identity(); + + Quaternion conjugate() const; + + scalar_t length() const; + scalar_t length_sq() const; + + void normalize(); + Quaternion normalized() const; + + Quaternion inverse() const; + + void set_rotation(const Vector3 &axis, scalar_t angle); + void rotate(const Vector3 &axis, scalar_t angle); + /* note: this is a totally different operation from the above + * this treats the quaternion as signifying direction and rotates + * it by a rotation quaternion by rot * q * rot' + */ + void rotate(const Quaternion &q); + + Matrix3x3 get_rotation_matrix() const; + + friend Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t); + + friend std::ostream &operator <<(std::ostream &out, const Quaternion &q); +}; + + +#endif // _N3DMATH2_QUA_HPP_