summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d/qmatrix4x4.h
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-09-22 00:55:02 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-09-22 00:55:02 (GMT)
commit8416ae1af3f13ad865b25a87e3e94e298b3a0ca2 (patch)
tree21fd4e9e878792bbc1ba8694aa404e428e98667e /src/gui/math3d/qmatrix4x4.h
parent40bdb6a5bed66385c3c2320447b1530e99befeb3 (diff)
downloadQt-8416ae1af3f13ad865b25a87e3e94e298b3a0ca2.zip
Qt-8416ae1af3f13ad865b25a87e3e94e298b3a0ca2.tar.gz
Qt-8416ae1af3f13ad865b25a87e3e94e298b3a0ca2.tar.bz2
QMatrix4x4::mapVector() to transform by top-left 3x3
It is useful to be able to map direction vectors by the top-left 3x3 component of a 4x4 matrix, ignoring the translation and projection components. Reviewed-by: Sarah Smith
Diffstat (limited to 'src/gui/math3d/qmatrix4x4.h')
-rw-r--r--src/gui/math3d/qmatrix4x4.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 7631ae7..cfa3f2a 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -165,6 +165,7 @@ public:
QPointF map(const QPointF& point) const;
#ifndef QT_NO_VECTOR3D
QVector3D map(const QVector3D& point) const;
+ QVector3D mapVector(const QVector3D& vector) const;
#endif
#ifndef QT_NO_VECTOR4D
QVector4D map(const QVector4D& point) const;
@@ -940,6 +941,27 @@ inline QVector3D QMatrix4x4::map(const QVector3D& point) const
return *this * point;
}
+inline QVector3D QMatrix4x4::mapVector(const QVector3D& vector) const
+{
+ if (flagBits == Identity || flagBits == Translation) {
+ return vector;
+ } else if (flagBits == Scale || flagBits == (Translation | Scale)) {
+ return QVector3D(vector.x() * m[0][0],
+ vector.y() * m[1][1],
+ vector.z() * m[2][2]);
+ } else {
+ return QVector3D(vector.x() * m[0][0] +
+ vector.y() * m[1][0] +
+ vector.z() * m[2][0],
+ vector.x() * m[0][1] +
+ vector.y() * m[1][1] +
+ vector.z() * m[2][1],
+ vector.x() * m[0][2] +
+ vector.y() * m[1][2] +
+ vector.z() * m[2][2]);
+ }
+}
+
#endif
#ifndef QT_NO_VECTOR4D