[Gameplay] Reduce loom cost
[0ad.git] / source / maths / Quaternion.h
blobc25aa0a502d6c95588eb88bb6d96bad3887c2a17
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 "Vector3D.h"
23 class CMatrix3D;
25 class CQuaternion
27 public:
28 CVector3D m_V;
29 float m_W;
31 public:
32 CQuaternion();
33 CQuaternion(float x, float y, float z, float w);
35 CQuaternion operator + (const CQuaternion &quat) const;
36 CQuaternion &operator += (const CQuaternion &quat);
38 CQuaternion operator - (const CQuaternion &quat) const;
39 CQuaternion &operator -= (const CQuaternion &quat);
41 CQuaternion operator * (const CQuaternion &quat) const;
42 CQuaternion &operator *= (const CQuaternion &quat);
44 CQuaternion operator * (float factor) const;
46 float Dot(const CQuaternion& quat) const;
48 void FromEulerAngles (float x, float y, float z);
49 CVector3D ToEulerAngles();
51 // Convert the quaternion to matrix
52 CMatrix3D ToMatrix() const;
53 void ToMatrix(CMatrix3D& result) const;
55 // Sphere interpolation
56 void Slerp(const CQuaternion& from, const CQuaternion& to, float ratio);
58 // Normalised linear interpolation
59 void Nlerp(const CQuaternion& from, const CQuaternion& to, float ratio);
61 // Create a quaternion from axis/angle representation of a rotation
62 void FromAxisAngle(const CVector3D& axis, float angle);
64 // Convert the quaternion to axis/angle representation of a rotation
65 void ToAxisAngle(CVector3D& axis, float& angle);
67 // Normalize this quaternion
68 void Normalize();
70 // Rotate a vector by this quaternion. Assumes the quaternion is normalised.
71 CVector3D Rotate(const CVector3D& vec) const;
73 // Calculate q^-1. Assumes the quaternion is normalised.
74 CQuaternion GetInverse() const;
77 #endif