2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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.
|
|
|
|
*
|
|
|
|
* 0 A.D. 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 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_QUATERNION
|
|
|
|
#define INCLUDED_QUATERNION
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
#include "Matrix3D.h"
|
2005-09-15 07:31:49 +02:00
|
|
|
#include "Vector3D.h"
|
2004-05-29 22:53:40 +02:00
|
|
|
|
|
|
|
class CQuaternion
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CVector3D m_V;
|
|
|
|
float m_W;
|
|
|
|
|
|
|
|
public:
|
|
|
|
CQuaternion();
|
2005-09-15 07:31:49 +02:00
|
|
|
CQuaternion(float x, float y, float z, float w);
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2005-09-15 07:31:49 +02:00
|
|
|
CQuaternion operator + (const CQuaternion &quat) const;
|
|
|
|
CQuaternion &operator += (const CQuaternion &quat);
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2007-03-01 01:14:35 +01:00
|
|
|
CQuaternion operator - (const CQuaternion &quat) const;
|
|
|
|
CQuaternion &operator -= (const CQuaternion &quat);
|
|
|
|
|
2005-09-15 07:31:49 +02:00
|
|
|
CQuaternion operator * (const CQuaternion &quat) const;
|
|
|
|
CQuaternion &operator *= (const CQuaternion &quat);
|
2007-03-01 01:14:35 +01:00
|
|
|
|
|
|
|
CQuaternion operator * (float factor) const;
|
|
|
|
|
|
|
|
float Dot(const CQuaternion& quat) const;
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2005-09-15 07:31:49 +02:00
|
|
|
void FromEulerAngles (float x, float y, float z);
|
2006-08-22 04:24:44 +02:00
|
|
|
CVector3D ToEulerAngles();
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Convert the quaternion to matrix
|
2004-05-29 22:53:40 +02:00
|
|
|
CMatrix3D ToMatrix() const;
|
|
|
|
void ToMatrix(CMatrix3D& result) const;
|
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Sphere interpolation
|
2005-12-06 21:16:50 +01:00
|
|
|
void Slerp(const CQuaternion& from, const CQuaternion& to, float ratio);
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2007-03-01 01:14:35 +01:00
|
|
|
// Normalised linear interpolation
|
|
|
|
void Nlerp(const CQuaternion& from, const CQuaternion& to, float ratio);
|
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Create a quaternion from axis/angle representation of a rotation
|
2005-12-06 21:16:50 +01:00
|
|
|
void FromAxisAngle(const CVector3D& axis, float angle);
|
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Convert the quaternion to axis/angle representation of a rotation
|
2005-12-06 21:16:50 +01:00
|
|
|
void ToAxisAngle(CVector3D& axis, float& angle);
|
2004-05-29 22:53:40 +02:00
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Normalize this quaternion
|
2004-10-06 20:45:59 +02:00
|
|
|
void Normalize();
|
2005-09-15 07:31:49 +02:00
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Rotate a vector by this quaternion. Assumes the quaternion is normalised.
|
2005-09-15 07:31:49 +02:00
|
|
|
CVector3D Rotate(const CVector3D& vec) const;
|
|
|
|
|
2006-12-15 17:09:30 +01:00
|
|
|
// Calculate q^-1. Assumes the quaternion is normalised.
|
2005-09-15 07:31:49 +02:00
|
|
|
CQuaternion GetInverse() const;
|
2004-05-29 22:53:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|