Pyrogenesis trunk
Quaternion.h
Go to the documentation of this file.
1/* Copyright (C) 2009 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18#ifndef INCLUDED_QUATERNION
19#define INCLUDED_QUATERNION
20
21#include "Vector3D.h"
22
23class CMatrix3D;
24
26{
27public:
29 float m_W;
30
31public:
33 CQuaternion(float x, float y, float z, float w);
34
35 CQuaternion operator + (const CQuaternion &quat) const;
37
38 CQuaternion operator - (const CQuaternion &quat) const;
40
41 CQuaternion operator * (const CQuaternion &quat) const;
43
44 CQuaternion operator * (float factor) const;
45
46 float Dot(const CQuaternion& quat) const;
47
48 void FromEulerAngles (float x, float y, float z);
50
51 // Convert the quaternion to matrix
52 CMatrix3D ToMatrix() const;
53 void ToMatrix(CMatrix3D& result) const;
54
55 // Sphere interpolation
56 void Slerp(const CQuaternion& from, const CQuaternion& to, float ratio);
57
58 // Normalised linear interpolation
59 void Nlerp(const CQuaternion& from, const CQuaternion& to, float ratio);
60
61 // Create a quaternion from axis/angle representation of a rotation
62 void FromAxisAngle(const CVector3D& axis, float angle);
63
64 // Convert the quaternion to axis/angle representation of a rotation
65 void ToAxisAngle(CVector3D& axis, float& angle);
66
67 // Normalize this quaternion
68 void Normalize();
69
70 // Rotate a vector by this quaternion. Assumes the quaternion is normalised.
71 CVector3D Rotate(const CVector3D& vec) const;
72
73 // Calculate q^-1. Assumes the quaternion is normalised.
74 CQuaternion GetInverse() const;
75};
76
77#endif
Definition: Matrix3D.h:34
Definition: Quaternion.h:26
void FromEulerAngles(float x, float y, float z)
Definition: Quaternion.cpp:98
void Normalize()
Definition: Quaternion.cpp:290
float Dot(const CQuaternion &quat) const
Definition: Quaternion.cpp:89
void ToAxisAngle(CVector3D &axis, float &angle)
Definition: Quaternion.cpp:275
CQuaternion & operator+=(const CQuaternion &quat)
Definition: Quaternion.cpp:46
CQuaternion GetInverse() const
Definition: Quaternion.cpp:310
CVector3D m_V
Definition: Quaternion.h:28
CVector3D Rotate(const CVector3D &vec) const
Definition: Quaternion.cpp:302
float m_W
Definition: Quaternion.h:29
void Nlerp(const CQuaternion &from, const CQuaternion &to, float ratio)
Definition: Quaternion.cpp:250
CVector3D ToEulerAngles()
Definition: Quaternion.cpp:124
void Slerp(const CQuaternion &from, const CQuaternion &to, float ratio)
Definition: Quaternion.cpp:200
CQuaternion operator+(const CQuaternion &quat) const
Definition: Quaternion.cpp:38
CMatrix3D ToMatrix() const
Definition: Quaternion.cpp:154
CQuaternion & operator*=(const CQuaternion &quat)
Definition: Quaternion.cpp:74
CQuaternion operator*(const CQuaternion &quat) const
Definition: Quaternion.cpp:66
CQuaternion & operator-=(const CQuaternion &quat)
Definition: Quaternion.cpp:60
void FromAxisAngle(const CVector3D &axis, float angle)
Definition: Quaternion.cpp:262
CQuaternion operator-(const CQuaternion &quat) const
Definition: Quaternion.cpp:52
CQuaternion()
Definition: Quaternion.cpp:28
Definition: Vector3D.h:31
Definition: mongoose.cpp:428