added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / n3dmath2 / n3dmath2_qua.hpp
1 /*
2 This file is part of the n3dmath2 library.
3
4 Copyright (c) 2003 - 2005 John Tsiombikas <nuclear@siggraph.org>
5
6 The n3dmath2 library is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 The n3dmath2 library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with the n3dmath2 library; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20
21 /* quaterinion math
22  *
23  * Author: John Tsiombikas 2003
24  * Modified: John Tsiombikas 2004, 2005
25  */
26
27 #ifndef _N3DMATH2_QUA_HPP_
28 #define _N3DMATH2_QUA_HPP_
29
30 #include <iostream>
31 #include "n3dmath2_types.hpp"
32
33 class Quaternion {
34 public:
35         scalar_t s;
36         Vector3 v;
37
38         Quaternion();
39         Quaternion(scalar_t s, const Vector3 &v);
40         Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z);
41         Quaternion(const Vector3 &axis, scalar_t angle);
42
43         Quaternion operator +(const Quaternion &quat) const;
44         Quaternion operator -(const Quaternion &quat) const;
45         Quaternion operator -() const;
46         Quaternion operator *(const Quaternion &quat) const;
47         
48         void operator +=(const Quaternion &quat);
49         void operator -=(const Quaternion &quat);
50         void operator *=(const Quaternion &quat);
51
52         void reset_identity();
53
54         Quaternion conjugate() const;
55
56         scalar_t length() const;
57         scalar_t length_sq() const;
58         
59         void normalize();
60         Quaternion normalized() const;
61
62         Quaternion inverse() const;
63
64         void set_rotation(const Vector3 &axis, scalar_t angle);
65         void rotate(const Vector3 &axis, scalar_t angle);
66         /* note: this is a totally different operation from the above
67          * this treats the quaternion as signifying direction and rotates
68          * it by a rotation quaternion by rot * q * rot'
69          */
70         void rotate(const Quaternion &q);
71
72         Matrix3x3 get_rotation_matrix() const;
73         
74         friend Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
75         
76         friend std::ostream &operator <<(std::ostream &out, const Quaternion &q);
77 };
78
79
80 #endif  // _N3DMATH2_QUA_HPP_