22 using namespace Marble;
24 Quaternion::Quaternion()
30 Quaternion::Quaternion(qreal w, qreal x, qreal y, qreal z)
38 Quaternion Quaternion::fromSpherical(qreal lon, qreal lat)
41 const qreal x = cos(lat) * sin(lon);
42 const qreal y = sin(lat);
43 const qreal z = cos(lat) * cos(lon);
48 void Quaternion::getSpherical(qreal &lon, qreal &lat)
const
59 lon = atan2(v[
Q_X], v[
Q_Z]);
66 (*this) *= 1.0 / length();
69 qreal Quaternion::length()
const
76 (*this) = (*this) * mult;
89 Quaternion Quaternion::fromEuler(qreal pitch, qreal yaw, qreal roll)
91 const qreal cPhi = cos(0.5 * pitch);
92 const qreal cThe = cos(0.5 * yaw);
93 const qreal cPsi = cos(0.5 * roll);
95 const qreal sPhi = sin(0.5 * pitch);
96 const qreal sThe = sin(0.5 * yaw);
97 const qreal sPsi = sin(0.5 * roll);
99 const qreal w = cPhi * cThe * cPsi + sPhi * sThe * sPsi;
100 const qreal x = sPhi * cThe * cPsi - cPhi * sThe * sPsi;
101 const qreal y = cPhi * sThe * cPsi + sPhi * cThe * sPsi;
102 const qreal z = cPhi * cThe * sPsi - sPhi * sThe * cPsi;
107 qreal Quaternion::pitch() const
110 ( 1.0 - 2.0*(v[
Q_X]*v[
Q_X]+v[Q_Z]*v[Q_Z]) ) );
113 qreal Quaternion::yaw() const
116 ( 1.0 - 2.0*(v[
Q_Y]*v[
Q_Y]+v[Q_Z]*v[Q_Z]) ) );
119 qreal Quaternion::roll() const
124 #ifndef QT_NO_DEBUG_STREAM
127 QString quatdisplay = QString(
"Quaternion: w= %1, x= %2, y= %3, z= %4, |q|= %5" )
130 debug << quatdisplay;
138 (*this) = (*this) * q;
183 qreal cosAlpha = ( q1.
v[
Q_X] * q2.
v[
Q_X]
187 qreal alpha = acos( cosAlpha );
188 qreal sinAlpha = sin( alpha );
190 if ( sinAlpha > 0.0 ) {
191 p1 = sin( ( 1.0 - t ) * alpha ) / sinAlpha;
192 p2 = sin( t * alpha ) / sinAlpha;
199 const qreal w = p1 * q1.
v[
Q_W] + p2 * q2.
v[
Q_W];
200 const qreal x = p1 * q1.
v[
Q_X] + p2 * q2.
v[
Q_X];
201 const qreal y = p1 * q1.
v[
Q_Y] + p2 * q2.
v[
Q_Y];
202 const qreal z = p1 * q1.
v[
Q_Z] + p2 * q2.
v[
Q_Z];
209 const qreal p1 = 1.0 - t;
211 const qreal w = p1 * q1.
v[
Q_W] + t * q2.
v[
Q_W];
212 const qreal x = p1 * q1.
v[
Q_X] + t * q2.
v[
Q_X];
213 const qreal y = p1 * q1.
v[
Q_Y] + t * q2.
v[
Q_Y];
214 const qreal z = p1 * q1.
v[
Q_Z] + t * q2.
v[
Q_Z];
222 void Quaternion::toMatrix(
matrix &m)
const
229 m[0][0] = 1.0 - 2.0 * (yy + zz);
230 m[0][1] = 2.0 * (xy + zw);
231 m[0][2] = 2.0 * (xz - yw);
234 const qreal xx = v[
Q_X] * v[
Q_X];
235 const qreal xw = v[
Q_X] * v[
Q_W];
236 const qreal yz = v[
Q_Y] * v[
Q_Z];
238 m[1][0] = 2.0 * (xy - zw);
239 m[1][1] = 1.0 - 2.0 * (xx + zz);
240 m[1][2] = 2.0 * (yz + xw);
243 m[2][0] = 2.0 * (xz + yw);
244 m[2][1] = 2.0 * (yz - xw);
245 m[2][2] = 1.0 - 2.0 * (xx + yy);
249 void Quaternion::rotateAroundAxis(
const matrix &m)
251 const qreal x = m[0][0] * v[
Q_X] + m[1][0] * v[
Q_Y] + m[2][0] * v[
Q_Z];
252 const qreal y = m[0][1] * v[
Q_X] + m[1][1] * v[
Q_Y] + m[2][1] * v[
Q_Z];
253 const qreal z = m[0][2] * v[
Q_X] + m[1][2] * v[
Q_Y] + m[2][2] * v[
Q_Z];
QDebug operator<<(QDebug debug, const Quaternion &q)
bool operator==(const DownloadPolicyKey &lhs, const DownloadPolicyKey &rhs)
void normalize(const QString &output)
Vec3 operator*(double r, const Vec3 &c1)