7#include <QtGui/qtguiglobal.h>
8#include <QtGui/qgenericmatrix.h>
9#include <QtGui/qvector3d.h>
10#include <QtGui/qvector4d.h>
15#ifndef QT_NO_QUATERNION
25 constexpr QQuaternion(
float scalar,
float xpos,
float ypos,
float zpos)
noexcept;
33 constexpr bool isNull() const noexcept;
34 constexpr
bool isIdentity() const noexcept;
40 constexpr void setVector(
float x,
float y,
float z)
noexcept;
42 constexpr float x() const noexcept;
43 constexpr
float y() const noexcept;
44 constexpr
float z() const noexcept;
45 constexpr
float scalar() const noexcept;
47 constexpr
void setX(
float x) noexcept;
48 constexpr
void setY(
float y) noexcept;
49 constexpr
void setZ(
float z) noexcept;
50 constexpr
void setScalar(
float scalar) noexcept;
56 QT7_ONLY(Q_GUI_EXPORT)
float length() const;
57 QT7_ONLY(Q_GUI_EXPORT)
float lengthSquared() const;
64 [[nodiscard]] constexpr
QQuaternion conjugated() const noexcept;
70 constexpr
QQuaternion &operator*=(
float factor) noexcept;
78 return q1.wp == q2.wp && q1.xp == q2.xp && q1.yp == q2.yp && q1.zp == q2.zp;
97 constexpr QVector4D toVector4D() const noexcept;
100 QT7_ONLY(Q_GUI_EXPORT)
operator QVariant()
const;
102#ifndef QT_NO_VECTOR3D
106 QT7_ONLY(Q_GUI_EXPORT)
void getAxisAndAngle(
float *
x,
float *
y,
float *
z,
float *
angle)
const;
107 QT7_ONLY(Q_GUI_EXPORT)
static QQuaternion fromAxisAndAngle(
float x,
float y,
float z,
110#ifndef QT_NO_VECTOR3D
114 QT7_ONLY(Q_GUI_EXPORT)
void getEulerAngles(
float *pitch,
float *yaw,
float *roll)
const;
115 QT7_ONLY(Q_GUI_EXPORT)
static QQuaternion fromEulerAngles(
float pitch,
float yaw,
float roll);
117 QT7_ONLY(Q_GUI_EXPORT)
QMatrix3x3 toRotationMatrix()
const;
120#ifndef QT_NO_VECTOR3D
139 float wp, xp, yp, zp;
144constexpr QQuaternion::QQuaternion() noexcept : wp(1.0
f), xp(0.0
f), yp(0.0
f), zp(0.0
f) {}
146constexpr QQuaternion::QQuaternion(
float aScalar,
float xpos,
float ypos,
float zpos) noexcept
147 : wp(aScalar), xp(xpos), yp(ypos), zp(zpos) {}
152constexpr bool QQuaternion::isNull() const noexcept
154 return wp == 0.0f && xp == 0.0f && yp == 0.0f && zp == 0.0f;
157constexpr bool QQuaternion::isIdentity() const noexcept
159 return wp == 1.0f && xp == 0.0f && yp == 0.0f && zp == 0.0f;
163constexpr float QQuaternion::x() const noexcept {
return xp; }
164constexpr float QQuaternion::y() const noexcept {
return yp; }
165constexpr float QQuaternion::z() const noexcept {
return zp; }
166constexpr float QQuaternion::scalar() const noexcept {
return wp; }
168constexpr void QQuaternion::setX(
float aX)
noexcept { xp = aX; }
169constexpr void QQuaternion::setY(
float aY)
noexcept { yp = aY; }
170constexpr void QQuaternion::setZ(
float aZ)
noexcept { zp = aZ; }
171constexpr void QQuaternion::setScalar(
float aScalar)
noexcept { wp = aScalar; }
175 return q1.wp * q2.wp + q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp;
178constexpr QQuaternion QQuaternion::inverted() const noexcept
181 double len = double(wp) * double(wp) +
182 double(xp) * double(xp) +
183 double(yp) * double(yp) +
184 double(zp) * double(zp);
187 float(
double(-yp) /
len),
float(
double(-zp) /
len));
191constexpr QQuaternion QQuaternion::conjugated() const noexcept
214constexpr QQuaternion &QQuaternion::operator*=(
float factor)
noexcept
225 float yy = (q1.wp - q1.yp) * (q2.wp + q2.zp);
226 float zz = (q1.wp + q1.yp) * (q2.wp - q2.zp);
227 float ww = (q1.zp + q1.xp) * (q2.xp + q2.yp);
228 float xx = ww + yy + zz;
229 float qq = 0.5f * (xx + (q1.zp - q1.xp) * (q2.xp - q2.yp));
231 float w = qq - ww + (q1.zp - q1.yp) * (q2.yp - q2.zp);
232 float x = qq - xx + (q1.xp + q1.wp) * (q2.xp + q2.wp);
233 float y = qq - yy + (q1.wp - q1.xp) * (q2.yp + q2.zp);
234 float z = qq - zz + (q1.zp + q1.yp) * (q2.wp - q2.xp);
241 *
this = *
this * quaternion;
256 return QQuaternion(q1.wp + q2.wp, q1.xp + q2.xp, q1.yp + q2.yp, q1.zp + q2.zp);
261 return QQuaternion(q1.wp - q2.wp, q1.xp - q2.xp, q1.yp - q2.yp, q1.zp - q2.zp);
266 return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
271 return QQuaternion(quaternion.wp * factor, quaternion.xp * factor, quaternion.yp * factor, quaternion.zp * factor);
276 return QQuaternion(-quaternion.wp, -quaternion.xp, -quaternion.yp, -quaternion.zp);
292#ifndef QT_NO_VECTOR3D
294constexpr QQuaternion::QQuaternion(
float aScalar,
const QVector3D &aVector) noexcept
295 : wp(aScalar), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}
297constexpr void QQuaternion::setVector(
const QVector3D &aVector)
noexcept
304constexpr QVector3D QQuaternion::vector() const noexcept
311 return quaternion.rotatedVector(vec);
314inline void QQuaternion::getAxisAndAngle(
QVector3D *axis,
float *
angle)
const
317 getAxisAndAngle(&aX, &aY, &aZ,
angle);
321inline QVector3D QQuaternion::toEulerAngles()
const
323 float pitch, yaw, roll;
324 getEulerAngles(&pitch, &yaw, &roll);
330 return QQuaternion::fromEulerAngles(eulerAngles.x(), eulerAngles.y(), eulerAngles.z());
335constexpr void QQuaternion::setVector(
float aX,
float aY,
float aZ)
noexcept
342#ifndef QT_NO_VECTOR4D
344constexpr QQuaternion::QQuaternion(
const QVector4D &aVector) noexcept
345 : wp(aVector.w()), xp(aVector.x()), yp(aVector.y()), zp(aVector.z()) {}
347constexpr QVector4D QQuaternion::toVector4D() const noexcept
354#ifndef QT_NO_DEBUG_STREAM
358#ifndef QT_NO_DATASTREAM
\inmodule QtCore\reentrant
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
The QVector3D class represents a vector or vertex in 3D space.
The QVector4D class represents a vector or vertex in 4D space.
Combined button and popup list for selecting options.
#define QT_WARNING_DISABLE_FLOAT_COMPARE
constexpr bool operator!=(const timespec &t1, const timespec &t2)
constexpr timespec operator+(const timespec &t1, const timespec &t2)
constexpr timespec operator*(const timespec &t1, int mul)
constexpr timespec operator-(const timespec &t1, const timespec &t2)
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
constexpr QMargins operator/(const QMargins &margins, int divisor)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLenum GLsizei length
GLdouble GLdouble GLdouble GLdouble q
GLint GLenum GLboolean normalized
static void normalize(double &x, double &y)
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)