/usr/include/cegui-0.8.4/CEGUI/Quaternion.h is in libcegui-mk2-dev 0.8.4+dfsg-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | /***********************************************************************
created: 2/1/2011
author: Martin Preisler
purpose: Defines interface for the Quaternion class
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#ifndef _CEGUIQuaternion_h_
#define _CEGUIQuaternion_h_
#include "CEGUI/Base.h"
#include "CEGUI/Interpolator.h"
#include "CEGUI/Vector.h"
#include <cmath>
// Start of CEGUI namespace section
namespace CEGUI
{
/*!
\brief
Class to represent rotation, avoids Gimbal lock
Most people are afraid of Quaternions, you don't have to fully understand them.
In CEGUI, you can just think of quaternions as magic opaque boxes that hold rotation
data. No need to understand how they work and why. You obviously have to
understand what degrees and radians are, I won't go into that here.
How to convert "human readable" rotation data to Quaternions:
1) Euler angles, 3 floating point values
x - rotation around X axis (anticlockwise)
y - rotation around Y axis (anticlockwise)
z - rotation around Z axis (anticlockwise)
The actual rotation is performed in z, y, x order. Keep that in mind!
For these, just use eulerAnglesDegrees or eulerAnglesRadians static methods.
2) Rotation around axis, 1 Vector3 and one degree/radian angle
the vector represents the axis (it's length doesn't matter at all),
rotation is then performed by rotating given angle anticlockwise
around that axis.
For these, use axisAngleDegrees or axisAngleRadians static methods.
*/
class CEGUIEXPORT Quaternion :
public AllocatedObject<Quaternion>
{
public:
//! verbatim constructor
inline Quaternion(float w = 1.0f, float x = 0.0f, float y = 0.0f, float z = 0.0f):
d_w(w),
d_x(x),
d_y(y),
d_z(z)
{}
//! copy constructor
inline Quaternion(const Quaternion& v):
d_w(v.d_w),
d_x(v.d_x),
d_y(v.d_y),
d_z(v.d_z)
{}
//! assignment operator
inline Quaternion& operator = (const Quaternion& v)
{
d_w = v.d_w;
d_x = v.d_x;
d_y = v.d_y;
d_z = v.d_z;
return *this;
}
/*!
\brief constructs a quaternion from euler angles in radians
\param x
Anticlockwise rotation around X axis
\param y
Anticlockwise rotation around Y axis
\param z
Anticlockwise rotation around Z axis
The rotation is performed around Z first, then Y and then X!
*/
static Quaternion eulerAnglesRadians(float x, float y, float z);
/*!
\brief constructs a quaternion from euler angles in degrees
\param x
Anticlockwise rotation around X axis
\param y
Anticlockwise rotation around Y axis
\param z
Anticlockwise rotation around Z axis
The rotation is performed around Z first, then Y and then X!
*/
static Quaternion eulerAnglesDegrees(float x, float y, float z);
/*!
\brief constructs a quaternion from axis and angle around it in radians
\param axis
vector describing the axis of rotation
\param rotation
Anticlockwise rotation around given axis
*/
static Quaternion axisAngleRadians(const Vector3f& axis, float rotation);
/*!
\brief constructs a quaternion from axis and angle around it in degrees
\param axis
vector describing the axis of rotation
\param rotation
Anticlockwise rotation around given axis
*/
static Quaternion axisAngleDegrees(const Vector3f& axis, float rotation);
//! equality operator
inline bool operator == (const Quaternion& v) const
{
return (d_w == v.d_w) && (d_x == v.d_x) && (d_y == v.d_y) && (d_z == v.d_z);
}
//! inequality operator
inline bool operator != (const Quaternion& v) const
{
return (d_w != v.d_w) || (d_x != v.d_x) || (d_y != v.d_y) || (d_z != v.d_z);
}
//! negation operator
inline Quaternion operator - () const
{
return Quaternion(-d_w, -d_x, -d_y, -d_z);
}
//! scalar multiplication operator
inline Quaternion operator * (float v) const
{
return Quaternion(d_w * v, d_x * v, d_y * v, d_z * v);
}
//! scalar multiplication operator
inline friend Quaternion operator * (float v, const Quaternion& q)
{
return Quaternion(v * q.d_w, v * q.d_x, v * q.d_y, v * q.d_z);
}
//! quaternion dot product
inline float dot(const Quaternion& v) const
{
return d_w * v.d_w + d_x * v.d_x + d_y * v.d_y + d_z * v.d_z;
}
//! addition operator
inline Quaternion operator + (const Quaternion& v) const
{
return Quaternion(d_w + v.d_w, d_x + v.d_x, d_y + v.d_y, d_z + v.d_z);
}
/*!
\brief quaternion multiplication (not commutative!)
Lets say we have quaternion A describing a rotation and another quaternion B.
If we write C = A * B, C is actually describing a rotation we would get if we
rotated Identity by A and then rotated the result by B
*/
inline Quaternion operator * (const Quaternion& v) const
{
return Quaternion(
d_w * v.d_w - d_x * v.d_x - d_y * v.d_y - d_z * v.d_z,
d_w * v.d_x + d_x * v.d_w + d_y * v.d_z - d_z * v.d_y,
d_w * v.d_y + d_y * v.d_w + d_z * v.d_x - d_x * v.d_z,
d_w * v.d_z + d_z * v.d_w + d_x * v.d_y - d_y * v.d_x
);
}
/*!
\brief computers and returns the length of this quaternion
*/
inline float length() const
{
return sqrtf((d_w * d_w) + (d_x * d_x) + (d_y * d_y) + (d_z * d_z));
}
/*!
\brief normalises this quaternion and returns it's length (since it has to be computed anyways)
*/
inline float normalise()
{
const float len = length();
const float factor = 1.0f / len;
*this = *this * factor;
return len;
}
/*!
\brief spherical linear interpolation
\param left
Left keyframe Quaternion
\param right
Right keyframe Quaternion
\param position
Number from range <0.0, 1.0), the closer this is to 1.0, the closer the interpolation is to the "right" quaternion
\param shortestPath
If true, the interpolation is guaranteed to go through the shortest path
*/
static Quaternion slerp(const Quaternion& left, const Quaternion& right, float position, bool shortestPath = false);
//! Quaternion(0, 0, 0, 0)
static const Quaternion ZERO;
//! Quaternion(1, 0, 0, 0)
static const Quaternion IDENTITY;
/*!
\brief allows writing the quaternion to std ostream
*/
inline friend std::ostream& operator << (std::ostream& s, const Quaternion& v)
{
s << "CEGUI::Quaternion(" << v.d_w << ", " << v.d_x << ", " << v.d_y << ", " << v.d_z << ")";
return s;
}
//! imaginary part
float d_w;
//! x component of the vector part
float d_x;
//! y component of the vector part
float d_y;
//! z component of the vector part
float d_z;
};
/*!
\brief Special interpolator class for Quaternion
Quaternions can't be interpolated as floats and/or vectors, we have to use
"Spherical linear interpolator" instead.
*/
class QuaternionSlerpInterpolator : public Interpolator
{
public:
typedef PropertyHelper<Quaternion> Helper;
//! destructor
virtual ~QuaternionSlerpInterpolator() {}
//! \copydoc Interpolator::getType
virtual const String& getType() const;
//! \copydoc Interpolator::interpolateAbsolute
virtual String interpolateAbsolute(const String& value1,
const String& value2,
float position);
//! \copydoc Interpolator::interpolateRelative
virtual String interpolateRelative(const String& base,
const String& value1,
const String& value2,
float position);
//! \copydoc Interpolator::interpolateRelativeMultiply
virtual String interpolateRelativeMultiply(const String& base,
const String& value1,
const String& value2,
float position);
};
} // End of CEGUI namespace section
#endif // end of guard _CEGUIQuaternion_h_
|