summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/qquaternion.cpp80
-rw-r--r--src/gui/math3d/qquaternion.h22
2 files changed, 89 insertions, 13 deletions
diff --git a/src/gui/math3d/qquaternion.cpp b/src/gui/math3d/qquaternion.cpp
index b91215fdf4a..99061fb7163 100644
--- a/src/gui/math3d/qquaternion.cpp
+++ b/src/gui/math3d/qquaternion.cpp
@@ -557,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
{
@@ -640,8 +640,63 @@ QQuaternion QQuaternion::fromRotationMatrix(const QMatrix3x3 &rot3x3)
#ifndef QT_NO_VECTOR3D
/*!
+ \since 6.11
+ \class QQuaternion::Axes
+ \ingroup painting-3D
+ \inmodule QtGui
+
+ A struct containing the three orthonormal axes that define a
+ \l{QQuaternion}{quaternion}.
+
+
+ \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.
+*/
+
+/*!
+ \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());
+
+ 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,
@@ -649,16 +704,6 @@ QQuaternion QQuaternion::fromRotationMatrix(const QMatrix3x3 &rot3x3)
\sa fromAxes(), toRotationMatrix()
*/
-void QQuaternion::getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const
-{
- Q_ASSERT(xAxis && yAxis && zAxis);
-
- 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));
-}
/*!
\since 5.5
@@ -667,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)
{
@@ -686,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
diff --git a/src/gui/math3d/qquaternion.h b/src/gui/math3d/qquaternion.h
index 0ea844ae41f..ffc95a852ce 100644
--- a/src/gui/math3d/qquaternion.h
+++ b/src/gui/math3d/qquaternion.h
@@ -118,7 +118,14 @@ QT_WARNING_POP
QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromRotationMatrix(const QMatrix3x3 &rot3x3);
#ifndef QT_NO_VECTOR3D
- QT7_ONLY(Q_GUI_EXPORT) void getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const;
+ struct Axes
+ {
+ QVector3D x, y, z;
+ };
+ QT7_ONLY(Q_GUI_EXPORT) Axes toAxes() const;
+ QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromAxes(Axes axes); // clazy:exclude=function-args-by-ref
+ QT_GUI_INLINE_SINCE(6, 11)
+ void getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const;
QT7_ONLY(Q_GUI_EXPORT) static QQuaternion fromAxes(const QVector3D &xAxis,
const QVector3D &yAxis,
const QVector3D &zAxis);
@@ -330,6 +337,19 @@ QQuaternion QQuaternion::fromEulerAngles(const QVector3D &angles)
return QQuaternion::fromEulerAngles(angles.x(), angles.y(), angles.z());
}
+#if QT_GUI_INLINE_IMPL_SINCE(6, 11)
+void QQuaternion::getAxes(QVector3D *xAxis, QVector3D *yAxis, QVector3D *zAxis) const
+{
+ Q_PRE(xAxis);
+ Q_PRE(yAxis);
+ Q_PRE(zAxis);
+ const Axes axes = toAxes();
+ *xAxis = axes.x;
+ *yAxis = axes.y;
+ *zAxis = axes.z;
+}
+#endif // QT_GUI_INLINE_IMPL_SINCE(6, 11)
+
#endif // QT_NO_VECTOR3D
constexpr void QQuaternion::setVector(float aX, float aY, float aZ) noexcept