File indexing completed on 2024-04-21 03:49:53

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2004-2007 Torsten Rahn <tackat@kde.org>
0004 // SPDX-FileCopyrightText: 2007 Inge Wallin <ingwa@kde.org>
0005 // SPDX-FileCopyrightText: 2011 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0006 // SPDX-FileCopyrightText: 2014 Dennis Nienhüser <nienhueser@kde.org>
0007 //
0008 
0009 //
0010 // Quaternions provides a class that deals with quaternion operations.
0011 
0012 // krazy:excludeall=dpointer,inline
0013 
0014 #ifndef MARBLE_QUATERNION_H
0015 #define MARBLE_QUATERNION_H
0016 
0017 #include "marble_export.h"
0018 #include <cmath>
0019 #include <QtGlobal>
0020 
0021 namespace Marble
0022 {
0023 
0024 enum
0025 {
0026     Q_X = 0,
0027     Q_Y = 1,
0028     Q_Z = 2,
0029     Q_W = 3
0030 };
0031 
0032 
0033 typedef qreal    xmmfloat[4];
0034 typedef xmmfloat  matrix[3];
0035 
0036 
0037 class MARBLE_EXPORT Quaternion
0038 {
0039  public:
0040     Quaternion();
0041     Quaternion(qreal w, qreal x, qreal y, qreal z);
0042 
0043     /*!\brief used to generate Quaternion from longitude and latitude
0044      * 
0045      * \param lon longitude
0046      * \param lat latitude
0047      */
0048     static Quaternion   fromSpherical(qreal lon, qreal lat);
0049     static Quaternion   fromEuler(qreal pitch, qreal yaw, qreal roll);
0050 
0051     static Quaternion slerp(const Quaternion &q1, const Quaternion &q2, qreal t);
0052     static Quaternion nlerp(const Quaternion &q1, const Quaternion &q2, qreal t);
0053 
0054     // Operators
0055     Quaternion  operator*(const Quaternion &q) const;
0056     Quaternion  operator+(const Quaternion &q) const;
0057     Quaternion  operator*(qreal factor) const;
0058     bool        operator==(const Quaternion &q) const;
0059     Quaternion& operator*=(const Quaternion &q);
0060     Quaternion& operator*=(qreal);
0061 
0062     void        getSpherical(qreal &lon, qreal &lat) const;
0063 
0064     void        normalize();
0065 
0066     qreal       length() const;
0067 
0068     Quaternion  inverse() const;
0069     Quaternion  log() const;
0070     Quaternion  exp() const;
0071 
0072     qreal       pitch() const;
0073     qreal       yaw() const;
0074     qreal       roll() const;
0075 
0076 
0077     void        rotateAroundAxis(const Quaternion &q);
0078 
0079     void        toMatrix(matrix &m) const;
0080     void        rotateAroundAxis(const matrix &m);
0081 
0082     // TODO: Better add accessors...
0083     xmmfloat    v;
0084 };
0085 
0086 }
0087 
0088 #ifndef QT_NO_DEBUG_STREAM
0089 MARBLE_EXPORT QDebug operator<<(QDebug, const Marble::Quaternion &);
0090 #endif
0091 
0092 #endif // MARBLE_QUATERNION_H