source: trunk/src/gui/math3d/qquaternion.h@ 599

Last change on this file since 599 was 561, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 9.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QQUATERNION_H
43#define QQUATERNION_H
44
45#include <QtGui/qvector3d.h>
46#include <QtGui/qvector4d.h>
47
48QT_BEGIN_HEADER
49
50QT_BEGIN_NAMESPACE
51
52QT_MODULE(Gui)
53
54#ifndef QT_NO_QUATERNION
55
56class QMatrix4x4;
57class QVariant;
58
59class Q_GUI_EXPORT QQuaternion
60{
61public:
62 QQuaternion();
63 QQuaternion(qreal scalar, qreal xpos, qreal ypos, qreal zpos);
64#ifndef QT_NO_VECTOR3D
65 QQuaternion(qreal scalar, const QVector3D& vector);
66#endif
67#ifndef QT_NO_VECTOR4D
68 explicit QQuaternion(const QVector4D& vector);
69#endif
70
71 bool isNull() const;
72 bool isIdentity() const;
73
74#ifndef QT_NO_VECTOR3D
75 QVector3D vector() const;
76 void setVector(const QVector3D& vector);
77#endif
78 void setVector(qreal x, qreal y, qreal z);
79
80 qreal x() const;
81 qreal y() const;
82 qreal z() const;
83 qreal scalar() const;
84
85 void setX(qreal x);
86 void setY(qreal y);
87 void setZ(qreal z);
88 void setScalar(qreal scalar);
89
90 qreal length() const;
91 qreal lengthSquared() const;
92
93 QQuaternion normalized() const;
94 void normalize();
95
96 QQuaternion conjugate() const;
97
98 QVector3D rotatedVector(const QVector3D& vector) const;
99
100 QQuaternion &operator+=(const QQuaternion &quaternion);
101 QQuaternion &operator-=(const QQuaternion &quaternion);
102 QQuaternion &operator*=(qreal factor);
103 QQuaternion &operator*=(const QQuaternion &quaternion);
104 QQuaternion &operator/=(qreal divisor);
105
106 friend inline bool operator==(const QQuaternion &q1, const QQuaternion &q2);
107 friend inline bool operator!=(const QQuaternion &q1, const QQuaternion &q2);
108 friend inline const QQuaternion operator+(const QQuaternion &q1, const QQuaternion &q2);
109 friend inline const QQuaternion operator-(const QQuaternion &q1, const QQuaternion &q2);
110 friend inline const QQuaternion operator*(qreal factor, const QQuaternion &quaternion);
111 friend inline const QQuaternion operator*(const QQuaternion &quaternion, qreal factor);
112 friend inline const QQuaternion operator*(const QQuaternion &q1, const QQuaternion& q2);
113 friend inline const QQuaternion operator-(const QQuaternion &quaternion);
114 friend inline const QQuaternion operator/(const QQuaternion &quaternion, qreal divisor);
115
116 friend inline bool qFuzzyCompare(const QQuaternion& q1, const QQuaternion& q2);
117
118#ifndef QT_NO_VECTOR4D
119 QVector4D toVector4D() const;
120#endif
121
122 operator QVariant() const;
123
124#ifndef QT_NO_VECTOR3D
125 static QQuaternion fromAxisAndAngle(const QVector3D& axis, qreal angle);
126#endif
127 static QQuaternion fromAxisAndAngle
128 (qreal x, qreal y, qreal z, qreal angle);
129
130 static QQuaternion slerp
131 (const QQuaternion& q1, const QQuaternion& q2, qreal t);
132 static QQuaternion nlerp
133 (const QQuaternion& q1, const QQuaternion& q2, qreal t);
134
135private:
136 qreal wp, xp, yp, zp;
137};
138
139inline QQuaternion::QQuaternion() : wp(1.0f), xp(0.0f), yp(0.0f), zp(0.0f) {}
140
141inline QQuaternion::QQuaternion(qreal aScalar, qreal xpos, qreal ypos, qreal zpos) : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}
142
143
144inline bool QQuaternion::isNull() const
145{
146 return qIsNull(xp) && qIsNull(yp) && qIsNull(zp) && qIsNull(wp);