#include <quaternion.h>
Inheritance diagram for Quaternion< T >:


Public Member Functions | |
| void | getAxisAngle (Vector3< T > &axis, T &angle) const |
| bool | isPure () const |
| bool | isReal () const |
| T | normalize () |
| Quaternion & | operator *= (Quaternion) |
| Quaternion & | operator *= (T) |
| Quaternion | operator+ () const |
| Quaternion & | operator+= (Quaternion) |
| Quaternion | operator- () const |
| Quaternion & | operator-= (Quaternion) |
| Quaternion | operator~ () const |
| Quaternion (const Matrix3< T > &) | |
| Quaternion (T, T, T, T) | |
| Quaternion (T, const Vector3< T > &) | |
| Quaternion (const Vector3< T > &) | |
| Quaternion (T) | |
| Quaternion (const Quaternion< T > &) | |
| Quaternion () | |
| void | rotate (Vector3< T > axis, T angle) |
| void | setAxisAngle (Vector3< T > axis, T angle) |
| Matrix3< T > | toMatrix3 () const |
| Matrix4< T > | toMatrix4 () const |
| void | xrotate (T angle) |
| void | yrotate (T angle) |
| void | zrotate (T angle) |
Static Public Member Functions | |
| static Quaternion< T > | slerp (Quaternion< T >, Quaternion< T >, T) |
| static Quaternion< T > | xrotation (T) |
| static Quaternion< T > | yrotation (T) |
| static Quaternion< T > | zrotation (T) |
Public Attributes | |
| T | w |
| T | x |
| T | y |
| T | z |
|
|||||||||
|
Definition at line 119 of file quaternion.h.
|
|
||||||||||
|
Definition at line 123 of file quaternion.h.
|
|
||||||||||
|
Definition at line 128 of file quaternion.h.
|
|
||||||||||
|
Definition at line 134 of file quaternion.h.
|
|
||||||||||||||||
|
Definition at line 139 of file quaternion.h.
|
|
||||||||||||||||||||||||
|
Definition at line 144 of file quaternion.h.
|
|
||||||||||
|
Definition at line 150 of file quaternion.h. References sqrt(), Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. 00151 {
00152 T trace = m[0][0] + m[1][1] + m[2][2];
00153 T root;
00154
00155 if (trace > 0)
00156 {
00157 root = (T) sqrt(trace + 1);
00158 w = (T) 0.5 * root;
00159 root = (T) 0.5 / root;
00160 x = (m[2][1] - m[1][2]) * root;
00161 y = (m[0][2] - m[2][0]) * root;
00162 z = (m[1][0] - m[0][1]) * root;
00163 }
00164 else
00165 {
00166 int i = 0;
00167 if (m[1][1] > m[i][i])
00168 i = 1;
00169 if (m[2][2] > m[i][i])
00170 i = 2;
00171 int j = (i == 2) ? 0 : i + 1;
00172 int k = (j == 2) ? 0 : j + 1;
00173
00174 root = (T) sqrt(m[i][i] - m[j][j] - m[k][k] + 1);
00175 T* xyz[3] = { &x, &y, &z };
00176 *xyz[i] = (T) 0.5 * root;
00177 root = (T) 0.5 / root;
00178 w = (m[k][j] - m[j][k]) * root;
00179 *xyz[j] = (m[j][i] + m[i][j]) * root;
00180 *xyz[k] = (m[k][i] + m[i][k]) * root;
00181 }
00182 }
|
|
||||||||||||||||
|
Definition at line 503 of file quaternion.h. References sqrt(), Quaternion< T >::w, Vector3< T >::x, Quaternion< T >::x, Vector3< T >::y, Quaternion< T >::y, Vector3< T >::z, and Quaternion< T >::z. Referenced by CommandParser::parseCommand(), and WriteFavoritesList(). 00505 {
00506 // The quaternion has the form:
00507 // w = cos(angle/2), (x y z) = sin(angle/2)*axis
00508
00509 T magSquared = x * x + y * y + z * z;
00510 if (magSquared > (T) 1e-10)
00511 {
00512 T s = (T) 1 / (T) sqrt(magSquared);
00513 axis.x = x * s;
00514 axis.y = y * s;
00515 axis.z = z * s;
00516 if (w <= -1 || w >= 1)
00517 angle = 0;
00518 else
00519 angle = (T) acos(w) * 2;
00520 }
00521 else
00522 {
00523 // The angle is zero, so we pick an arbitrary unit axis
00524 axis.x = 1;
00525 axis.y = 0;
00526 axis.z = 0;
00527 angle = 0;
00528 }
00529 }
|
|
|||||||||
|
Definition at line 470 of file quaternion.h. References Quaternion< T >::w. 00471 {
00472 return w == 0;
00473 }
|
|
|||||||||
|
Definition at line 465 of file quaternion.h. References Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. Referenced by cos(), exp(), log(), sin(), and sqrt(). 00466 {
00467 return (x == 0 && y == 0 && z == 0);
00468 }
|
|
|||||||||
|
Definition at line 475 of file quaternion.h. References sqrt(), Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. Referenced by CelestiaCore::mouseMove(), Observer::orbit(), and Observer::update(). 00476 {
00477 T s = (T) sqrt(w * w + x * x + y * y + z * z);
00478 T invs = (T) 1 / (T) s;
00479 x *= invs;
00480 y *= invs;
00481 z *= invs;
00482 w *= invs;
00483
00484 return s;
00485 }
|
|
||||||||||
|
Definition at line 197 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. 00198 {
00199 *this = Quaternion<T>(w * q.w - x * q.x - y * q.y - z * q.z,
00200 w * q.x + x * q.w + y * q.z - z * q.y,
00201 w * q.y + y * q.w + z * q.x - x * q.z,
00202 w * q.z + z * q.w + x * q.y - y * q.x);
00203
00204 return *this;
00205 }
|
|
||||||||||
|
Definition at line 207 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.
|
|
|||||||||
|
Definition at line 224 of file quaternion.h. 00225 {
00226 return *this;
00227 }
|
|
||||||||||
|
Definition at line 185 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.
|
|
|||||||||
|
Definition at line 219 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. 00220 {
00221 return Quaternion<T>(-w, -x, -y, -z);
00222 }
|
|
||||||||||
|
Definition at line 191 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z.
|
|
|||||||||
|
Definition at line 214 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. 00215 {
00216 return Quaternion<T>(w, -x, -y, -z);
00217 }
|
|
||||||||||||||||
|
Definition at line 604 of file quaternion.h. References Quaternion< T >::setAxisAngle(). Referenced by CommandRotate::process(). 00605 {
00606 Quaternion q;
00607 q.setAxisAngle(axis, angle);
00608 *this = q * *this;
00609 }
|
|
||||||||||||||||
|
Definition at line 489 of file quaternion.h. References Math< T >::sincos(), Quaternion< T >::w, Vector3< T >::x, Quaternion< T >::x, Vector3< T >::y, Quaternion< T >::y, Vector3< T >::z, and Quaternion< T >::z. Referenced by celestia_newrotation(), Observer::computeCenterCOParameters(), DeepSkyObject::load(), CelestiaCore::mouseMove(), Universe::pickDeepSkyObject(), Universe::pickStar(), CommandSetOrientation::process(), CommandRotate::process(), CommandOrbit::process(), ReadFavoritesList(), renderBumpMappedMesh(), renderSmoothMesh(), Quaternion< T >::rotate(), and rotation_setaxisangle(). 00490 {
00491 T s, c;
00492
00493 Math<T>::sincos(angle * (T) 0.5, s, c);
00494 x = s * axis.x;
00495 y = s * axis.y;
00496 z = s * axis.z;
00497 w = c;
00498 }
|
|
||||||||||||||||||||
|
Definition at line 577 of file quaternion.h. References abs(), dot(), and sin(). 00580 {
00581 T c = dot(q0, q1);
00582
00583 // Because of potential rounding errors, we must clamp c to the domain of acos.
00584 if (c > (T) 1.0)
00585 c = (T) 1.0;
00586 else if (c < (T) -1.0)
00587 c = (T) -1.0;
00588
00589 T angle = (T) acos(c);
00590
00591 if (abs(angle) < (T) 1.0e-5)
00592 return q0;
00593
00594 T s = (T) sin(angle);
00595 T is = (T) 1.0 / s;
00596
00597 return q0 * ((T) sin((1 - t) * angle) * is) +
00598 q1 * ((T) sin(t * angle) * is);
00599 }
|
|
|||||||||
|
Definition at line 553 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. Referenced by Observer::computeCenterCOParameters(), displayLocationInfo(), FrameOfReference::fromUniversal(), Location::getPlanetocentricPosition(), Observer::gotoSurface(), Observer::orbit(), SynchronousOrbit::positionAtTime(), Galaxy::renderGalaxyPointSprites(), Renderer::renderParticles(), rotation_transform(), FrameOfReference::toUniversal(), and Observer::update(). 00554 {
00555 T wx = w * x * 2;
00556 T wy = w * y * 2;
00557 T wz = w * z * 2;
00558 T xx = x * x * 2;
00559 T xy = x * y * 2;
00560 T xz = x * z * 2;
00561 T yy = y * y * 2;
00562 T yz = y * z * 2;
00563 T zz = z * z * 2;
00564
00565 return Matrix3<T>(Vector3<T>(1 - yy - zz, xy - wz, xz + wy),
00566 Vector3<T>(xy + wz, 1 - xx - zz, yz - wx),
00567 Vector3<T>(xz - wy, yz + wx, 1 - xx - yy));
00568 }
|
|
|||||||||
|
Definition at line 533 of file quaternion.h. References Quaternion< T >::w, Quaternion< T >::x, Quaternion< T >::y, and Quaternion< T >::z. Referenced by Observer::computeCenterParameters(), FrameOfReference::fromUniversal(), Body::getGeographicToHeliocentric(), Simulation::pickObject(), Renderer::renderObject(), Observer::setTargetSpeed(), and FrameOfReference::toUniversal(). 00534 {
00535 T wx = w * x * 2;
00536 T wy = w * y * 2;
00537 T wz = w * z * 2;
00538 T xx = x * x * 2;
00539 T xy = x * y * 2;
00540 T xz = x * z * 2;
00541 T yy = y * y * 2;
00542 T yz = y * z * 2;
00543 T zz = z * z * 2;
00544
00545 return Matrix4<T>(Vector4<T>(1 - yy - zz, xy - wz, xz + wy, 0),
00546 Vector4<T>(xy + wz, 1 - xx - zz, yz - wx, 0),
00547 Vector4<T>(xz - wy, yz + wx, 1 - xx - yy, 0),
00548 Vector4<T>(0, 0, 0, 1));
00549 }
|
|
||||||||||
|
Definition at line 614 of file quaternion.h. References Math< T >::sincos(). Referenced by CelestiaCore::mouseMove(). 00615 {
00616 T s, c;
00617
00618 Math<T>::sincos(angle * (T) 0.5, s, c);
00619 *this = Quaternion<T>(c, s, 0, 0) * *this;
00620 }
|
|
||||||||||
|
Definition at line 643 of file quaternion.h. References Math< T >::sincos(). 00644 {
00645 T s, c;
00646 Math<T>::sincos(angle * (T) 0.5, s, c);
00647 return Quaternion<T>(c, s, 0, 0);
00648 }
|
|
||||||||||
|
Definition at line 624 of file quaternion.h. References Math< T >::sincos(). Referenced by RotationElements::equatorialToPlanetographic(), Body::getEquatorialToGeographic(), CelestiaCore::mouseMove(), Renderer::renderPlanet(), Renderer::renderStar(), and Observer::reverseOrientation(). 00625 {
00626 T s, c;
00627
00628 Math<T>::sincos(angle * (T) 0.5, s, c);
00629 *this = Quaternion<T>(c, 0, s, 0) * *this;
00630 }
|
|
||||||||||
|
Definition at line 650 of file quaternion.h. References Math< T >::sincos(). 00651 {
00652 T s, c;
00653 Math<T>::sincos(angle * (T) 0.5, s, c);
00654 return Quaternion<T>(c, 0, s, 0);
00655 }
|
|
||||||||||
|
Definition at line 634 of file quaternion.h. References Math< T >::sincos(). 00635 {
00636 T s, c;
00637
00638 Math<T>::sincos(angle * (T) 0.5, s, c);
00639 *this = Quaternion<T>(c, 0, 0, s) * *this;
00640 }
|
|
||||||||||
|
Definition at line 657 of file quaternion.h. References Math< T >::sincos(). 00658 {
00659 T s, c;
00660 Math<T>::sincos(angle * (T) 0.5, s, c);
00661 return Quaternion<T>(c, 0, 0, s);
00662 }
|
|
|||||
|
|||||
|
|||||
|
|||||
1.4.1