summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qquaternion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/math3d/qquaternion.cpp')
-rw-r--r--src/gui/math3d/qquaternion.cpp101
1 files changed, 85 insertions, 16 deletions
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index 72a01554750..99061fb7163 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -336,6 +336,9 @@ QVector3D QQuaternion::rotatedVector(const QVector3D &vector) const
Extracts a 3D axis \a axis and a rotating angle \a angle (in degrees)
that corresponds to this quaternion.
+ Both \a axis and \a angle must be valid, non-\nullptr pointers,
+ otherwise the behavior is undefined.
+
\sa fromAxisAndAngle()
*/
@@ -366,6 +369,9 @@ QQuaternion QQuaternion::fromAxisAndAngle(const QVector3D &axis, float angle)
Extracts a 3D axis (\a x, \a y, \a z) and a rotating angle \a angle (in degrees)
that corresponds to this quaternion.
+ All of \a x, \a y, \a z, and \a angle must be valid, non-\nullptr pointers,
+ otherwise the behavior is undefined.
+
\sa fromAxisAndAngle()
*/
void QQuaternion::getAxisAndAngle(float *x, float *y, float *z, float *angle) const
@@ -421,7 +427,7 @@ QQuaternion QQuaternion::fromAxisAndAngle
\since 5.5
Calculates roll, pitch, and yaw Euler angles (in degrees)
- that corresponds to this quaternion.
+ that correspond to this quaternion.
\sa fromEulerAngles()
*/
@@ -432,8 +438,9 @@ QQuaternion QQuaternion::fromAxisAndAngle
\overload
Creates a quaternion that corresponds to a rotation of \a angles:
- angles.z() degrees around the z axis, angles.x() degrees around the x axis,
- and angles.y() degrees around the y axis (in that order).
+ angles.\l{QVector3D::}{z()} degrees around the z axis,
+ angles.\l{QVector3D::}{x()} degrees around the x axis, and
+ angles.\l{QVector3D::}{y()} degrees around the y axis (in that order).
\sa toEulerAngles()
*/
@@ -446,6 +453,9 @@ QQuaternion QQuaternion::fromAxisAndAngle
Calculates \a roll, \a pitch, and \a yaw Euler angles (in degrees)
that corresponds to this quaternion.
+ All of \a pitch, \a yaw, and \a roll must be valid, non-\nullptr pointers,
+ otherwise the behavior is undefined.
+
\sa fromEulerAngles()
*/
void QQuaternion::getEulerAngles(float *pitch, float *yaw, float *roll) const
@@ -547,7 +557,7 @@ QQuaternion QQuaternion::fromEulerAngles(float pitch, float yaw, float roll)
\note If this quaternion is not normalized,
the resulting rotation matrix will contain scaling information.
- \sa fromRotationMatrix(), getAxes()
+ \sa fromRotationMatrix(), toAxes()
*/
QMatrix3x3 QQuaternion::toRotationMatrix() const
{
@@ -585,9 +595,9 @@ QMatrix3x3 QQuaternion::toRotationMatrix() const
/*!
\since 5.5
- Creates a quaternion that corresponds to a rotation matrix \a rot3x3.
+ Creates a quaternion that corresponds to the rotation matrix \a rot3x3.
- \note If a given rotation matrix is not normalized,
+ \note If the given rotation matrix is not normalized,
the resulting quaternion will contain scaling information.
\sa toRotationMatrix(), fromAxes()
@@ -630,23 +640,71 @@ QQuaternion QQuaternion::fromRotationMatrix(const QMatrix3x3 &rot3x3)
#ifndef QT_NO_VECTOR3D
/*!
- \since 5.5
+ \since 6.11
+ \class QQuaternion::Axes
+ \ingroup painting-3D
+ \inmodule QtGui
- Returns the 3 orthonormal axes (\a xAxis, \a yAxis, \a zAxis) defining the quaternion.
+ A struct containing the three orthonormal axes that define a
+ \l{QQuaternion}{quaternion}.
- \sa fromAxes(), toRotationMatrix()
+
+ \sa QQuaternion::toAxes(), QQuaternion::fromAxes(Axes)
+*/
+
+/*!
+ \variable QQuaternion::Axes::x
+
+ The x orthonormal axis that, together with \l{y} and \l{z}, defines a
+ quaternion.
+*/
+
+/*!
+ \variable QQuaternion::Axes::y
+
+ The y orthonormal axis that, together with \l{x} and \l{z}, defines a
+ quaternion.
+*/
+
+/*!
+ \variable QQuaternion::Axes::z
+
+ The z orthonormal axis that, together with \l{x} and \l{y}, defines a
+ quaternion.
*/
-void QQuaternion::getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const
-{
- Q_ASSERT(xAxis && yAxis && zAxis);
+/*!
+ \since 6.11
+
+ Returns the three orthonormal axes that define this quaternion.
+
+ \sa QQuaternion::Axes, fromAxes(QQuaternion::Axes), toRotationMatrix()
+*/
+auto QQuaternion::toAxes() const -> Axes
+{
const QMatrix3x3 rot3x3(toRotationMatrix());
- *xAxis = QVector3D(rot3x3(0, 0), rot3x3(1, 0), rot3x3(2, 0));
- *yAxis = QVector3D(rot3x3(0, 1), rot3x3(1, 1), rot3x3(2, 1));
- *zAxis = QVector3D(rot3x3(0, 2), rot3x3(1, 2), rot3x3(2, 2));
+ return { {rot3x3(0, 0), rot3x3(1, 0), rot3x3(2, 0)},
+ {rot3x3(0, 1), rot3x3(1, 1), rot3x3(2, 1)},
+ {rot3x3(0, 2), rot3x3(1, 2), rot3x3(2, 2)} };
}
+
+/*!
+ \fn void QQuaternion::getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const
+ \since 5.5
+
+ \obsolete
+ Use toAxes() instead.
+
+ Returns the 3 orthonormal axes (\a xAxis, \a yAxis, \a zAxis) defining the quaternion.
+
+ All of \a xAxis, \a yAxis, and \a zAxis must be valid, non-\nullptr pointers,
+ otherwise the behavior is undefined.
+
+ \sa fromAxes(), toRotationMatrix()
+*/
+
/*!
\since 5.5
@@ -654,7 +712,7 @@ void QQuaternion::getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis)
\note The axes are assumed to be orthonormal.
- \sa getAxes(), fromRotationMatrix()
+ \sa toAxes(), fromRotationMatrix()
*/
QQuaternion QQuaternion::fromAxes(const QVector3D &xAxis, const QVector3D &yAxis, const QVector3D &zAxis)
{
@@ -673,6 +731,17 @@ QQuaternion QQuaternion::fromAxes(const QVector3D &xAxis, const QVector3D &yAxis
}
/*!
+ \since 6.11
+ \overload
+
+ \sa toAxes(), fromRotationMatrix()
+*/
+QQuaternion QQuaternion::fromAxes(Axes axes) // clazy:exclude=function-args-by-ref
+{
+ return fromAxes(axes.x, axes.y, axes.z);
+}
+
+/*!
\since 5.5
Constructs the quaternion using specified forward direction \a direction