Merge 'remotes/trunk'
[0ad.git] / source / maths / Quaternion.h
blobd63852ffa4990fa7ab67c19e95ff1504a7d601de
1 /* Copyright (C) 2009 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef INCLUDED_QUATERNION
19 #define INCLUDED_QUATERNION
21 #include "Matrix3D.h"
22 #include "Vector3D.h"
24 class CQuaternion
26 public:
27 CVector3D m_V;
28 float m_W;
30 public:
31 CQuaternion();
32 CQuaternion(float x, float y, float z, float w);
34 CQuaternion operator + (const CQuaternion &quat) const;
35 CQuaternion &operator += (const CQuaternion &quat);
37 CQuaternion operator - (const CQuaternion &quat) const;
38 CQuaternion &operator -= (const CQuaternion &quat);
40 CQuaternion operator * (const CQuaternion &quat) const;
41 CQuaternion &operator *= (const CQuaternion &quat);
43 CQuaternion operator * (float factor) const;
45 float Dot(const CQuaternion& quat) const;
47 void FromEulerAngles (float x, float y, float z);
48 CVector3D ToEulerAngles();
50 // Convert the quaternion to matrix
51 CMatrix3D ToMatrix() const;
52 void ToMatrix(CMatrix3D& result) const;
54 // Sphere interpolation
55 void Slerp(const CQuaternion& from, const CQuaternion& to, float ratio);
57 // Normalised linear interpolation
58 void Nlerp(const CQuaternion& from, const CQuaternion& to, float ratio);
60 // Create a quaternion from axis/angle representation of a rotation
61 void FromAxisAngle(const CVector3D& axis, float angle);
63 // Convert the quaternion to axis/angle representation of a rotation
64 void ToAxisAngle(CVector3D& axis, float& angle);
66 // Normalize this quaternion
67 void Normalize();
69 // Rotate a vector by this quaternion. Assumes the quaternion is normalised.
70 CVector3D Rotate(const CVector3D& vec) const;
72 // Calculate q^-1. Assumes the quaternion is normalised.
73 CQuaternion GetInverse() const;
76 #endif