5#include <QtCore/qdatastream.h>
6#include <QtCore/qmath.h>
7#include <QtCore/qvariant.h>
8#include <QtCore/qdebug.h>
14#ifndef QT_NO_QUATERNION
201 return qHypot(xp, yp, zp, wp);
214 return xp * xp + yp * yp + zp * zp + wp * wp;
232 return *
this /
scale;
329#ifndef QT_NO_VECTOR3D
355 float s = std::sin(
a);
356 float c = std::cos(
a);
403 (
float x,
float y,
float z,
float angle)
412 float s = std::sin(
a);
413 float c = std::cos(
a);
417#ifndef QT_NO_VECTOR3D
465 const float xps = rescale ? xp /
len : xp;
466 const float yps = rescale ? yp /
len : yp;
467 const float zps = rescale ? zp /
len : zp;
468 const float wps = rescale ? wp /
len : wp;
470 const float xx = xps * xps;
471 const float xy = xps * yps;
472 const float xz = xps * zps;
473 const float xw = xps * wps;
474 const float yy = yps * yps;
475 const float yz = yps * zps;
476 const float yw = yps * wps;
477 const float zz = zps * zps;
478 const float zw = zps * wps;
484 constexpr float epsilon = 0.00001f;
486 const float sinp = -2.0f * (yz - xw);
487 if (std::abs(sinp) < 1.0f -
epsilon) {
488 *pitch = std::asin(sinp);
489 *yaw = std::atan2(2.0f * (xz + yw), 1.0f - 2.0f * (xx + yy));
490 *roll = std::atan2(2.0f * (xy + zw), 1.0f - 2.0f * (xx + zz));
494 *pitch = std::copysign(
static_cast<float>(
M_PI_2), sinp);
495 *yaw = 2.0f * std::atan2(yps, wps);
526 const float c1 = std::cos(yaw);
527 const float s1 = std::sin(yaw);
528 const float c2 = std::cos(roll);
529 const float s2 = std::sin(roll);
530 const float c3 = std::cos(pitch);
531 const float s3 = std::sin(pitch);
532 const float c1c2 = c1 *
c2;
533 const float s1s2 =
s1 *
s2;
535 const float w = c1c2 * c3 + s1s2 *
s3;
536 const float x = c1c2 *
s3 + s1s2 * c3;
537 const float y =
s1 *
c2 * c3 - c1 *
s2 *
s3;
538 const float z = c1 *
s2 * c3 -
s1 *
c2 *
s3;
560 const float f2x = xp + xp;
561 const float f2y = yp + yp;
562 const float f2z = zp + zp;
563 const float f2xw = f2x * wp;
564 const float f2yw = f2y * wp;
565 const float f2zw = f2z * wp;
566 const float f2xx = f2x * xp;
567 const float f2xy = f2x * yp;
568 const float f2xz = f2x * zp;
569 const float f2yy = f2y * yp;
570 const float f2yz = f2y * zp;
571 const float f2zz = f2z * zp;
573 rot3x3(0, 0) = 1.0f - (f2yy + f2zz);
574 rot3x3(0, 1) = f2xy - f2zw;
575 rot3x3(0, 2) = f2xz + f2yw;
576 rot3x3(1, 0) = f2xy + f2zw;
577 rot3x3(1, 1) = 1.0f - (f2xx + f2zz);
578 rot3x3(1, 2) = f2yz - f2xw;
579 rot3x3(2, 0) = f2xz - f2yw;
580 rot3x3(2, 1) = f2yz + f2xw;
581 rot3x3(2, 2) = 1.0f - (f2xx + f2yy);
604 const float trace = rot3x3(0, 0) + rot3x3(1, 1) + rot3x3(2, 2);
605 if (
trace > 0.00000001f) {
606 const float s = 2.0f * std::sqrt(
trace + 1.0f);
608 axis[0] = (rot3x3(2, 1) - rot3x3(1, 2)) /
s;
609 axis[1] = (rot3x3(0, 2) - rot3x3(2, 0)) /
s;
610 axis[2] = (rot3x3(1, 0) - rot3x3(0, 1)) /
s;
612 static int s_next[3] = { 1, 2, 0 };
614 if (rot3x3(1, 1) > rot3x3(0, 0))
616 if (rot3x3(2, 2) > rot3x3(
i,
i))
621 const float s = 2.0f * std::sqrt(rot3x3(
i,
i) - rot3x3(
j,
j) - rot3x3(k, k) + 1.0f);
623 scalar = (rot3x3(k,
j) - rot3x3(
j, k)) /
s;
624 axis[
j] = (rot3x3(
j,
i) + rot3x3(
i,
j)) /
s;
625 axis[k] = (rot3x3(k,
i) + rot3x3(
i, k)) /
s;
631#ifndef QT_NO_VECTOR3D
646 *xAxis =
QVector3D(rot3x3(0, 0), rot3x3(1, 0), rot3x3(2, 0));
647 *yAxis =
QVector3D(rot3x3(0, 1), rot3x3(1, 1), rot3x3(2, 1));
648 *zAxis =
QVector3D(rot3x3(0, 2), rot3x3(1, 2), rot3x3(2, 2));
663 rot3x3(0, 0) = xAxis.
x();
664 rot3x3(1, 0) = xAxis.
y();
665 rot3x3(2, 0) = xAxis.
z();
666 rot3x3(0, 1) = yAxis.
x();
667 rot3x3(1, 1) = yAxis.
y();
668 rot3x3(2, 1) = yAxis.
z();
669 rot3x3(0, 2) = zAxis.
x();
670 rot3x3(1, 2) = zAxis.
y();
671 rot3x3(2, 2) = zAxis.
z();
732 d = std::sqrt(2.0f *
d);
826#ifndef QT_NO_VECTOR3D
876 float factor1 = 1.0f -
t;
878 if ((1.0f -
dot) > 0.0000001) {
880 float sinOfAngle = std::sin(
angle);
881 if (sinOfAngle > 0.0000001) {
882 factor1 = std::sin((1.0f -
t) *
angle) / sinOfAngle;
883 factor2 = std::sin(
t *
angle) / sinOfAngle;
888 return q1 * factor1 + q2b * factor2;
933#ifndef QT_NO_DEBUG_STREAM
938 dbg.nospace() <<
"QQuaternion(scalar:" <<
q.scalar()
939 <<
", vector:(" <<
q.x() <<
", "
940 <<
q.y() <<
", " <<
q.z() <<
"))";
946#ifndef QT_NO_DATASTREAM
961 << quaternion.
y() << quaternion.
z();
977 float scalar,
x,
y,
z;
\inmodule QtCore\reentrant
The QQuaternion class represents a quaternion consisting of a vector and scalar.
float lengthSquared() const
Returns the squared length of the quaternion.
void getEulerAngles(float *pitch, float *yaw, float *roll) const
QQuaternion conjugated() const
void getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const
static QQuaternion fromEulerAngles(const QVector3D &eulerAngles)
void normalize()
Normalizes the current quaternion in place.
static QQuaternion rotationTo(const QVector3D &from, const QVector3D &to)
QQuaternion()
Constructs an identity quaternion (1, 0, 0, 0), i.e.
static QQuaternion fromDirection(const QVector3D &direction, const QVector3D &up)
friend bool qFuzzyCompare(const QQuaternion &q1, const QQuaternion &q2)
Returns true if q1 and q2 are equal, allowing for a small fuzziness factor for floating-point compari...
QVector3D vector() const
Returns the vector component of this quaternion.
static QQuaternion slerp(const QQuaternion &q1, const QQuaternion &q2, float t)
Interpolates along the shortest spherical path between the rotational positions q1 and q2.
static QQuaternion fromRotationMatrix(const QMatrix3x3 &rot3x3)
static QQuaternion fromAxes(const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis)
float z() const
Returns the z coordinate of this quaternion's vector.
void setScalar(float scalar)
Sets the scalar component of this quaternion to scalar.
float scalar() const
Returns the scalar component of this quaternion.
void getAxisAndAngle(QVector3D *axis, float *angle) const
void setX(float x)
Sets the x coordinate of this quaternion's vector to the given x coordinate.
void setZ(float z)
Sets the z coordinate of this quaternion's vector to the given z coordinate.
float x() const
Returns the x coordinate of this quaternion's vector.
static QQuaternion nlerp(const QQuaternion &q1, const QQuaternion &q2, float t)
Interpolates along the shortest linear path between the rotational positions q1 and q2.
QQuaternion normalized() const
Returns the normalized unit form of this quaternion.
float y() const
Returns the y coordinate of this quaternion's vector.
static constexpr float dotProduct(const QQuaternion &q1, const QQuaternion &q2)
void setY(float y)
Sets the y coordinate of this quaternion's vector to the given y coordinate.
QMatrix3x3 toRotationMatrix() const
QVector3D rotatedVector(const QVector3D &vector) const
Rotates vector with this quaternion to produce a new vector in 3D space.
static QQuaternion fromAxisAndAngle(const QVector3D &axis, float angle)
Creates a normalized quaternion that corresponds to rotating through angle degrees about the specifie...
float length() const
Returns the length of the quaternion.
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
The QVector3D class represents a vector or vertex in 3D space.
QVector3D normalized() const noexcept
Returns the normalized unit vector form of this vector.
constexpr float lengthSquared() const noexcept
Returns the squared length of the vector from the origin.
constexpr float y() const noexcept
Returns the y coordinate of this point.
constexpr float x() const noexcept
Returns the x coordinate of this point.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
static constexpr QVector3D crossProduct(QVector3D v1, QVector3D v2) noexcept
Returns the cross-product of vectors v1 and v2, which is normal to the plane spanned by v1 and v2.
void normalize() noexcept
Normalizes the current vector in place.
constexpr float z() const noexcept
Returns the z coordinate of this point.
Combined button and popup list for selecting options.
constexpr Initialization Uninitialized
bool qFuzzyIsNull(qfloat16 f) noexcept
auto qHypot(qfloat16 x, qfloat16 y)
constexpr float qRadiansToDegrees(float radians)
constexpr float qDegreesToRadians(float degrees)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat z
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat s1
GLenum GLuint GLenum GLsizei length
GLdouble GLdouble GLdouble GLdouble q
GLenum GLenum GLenum GLenum GLenum scale
static qreal dot(const QPointF &a, const QPointF &b)
QDebug operator<<(QDebug dbg, const QQuaternion &q)
QDataStream & operator>>(QDataStream &stream, QQuaternion &quaternion)
static const qreal epsilon