summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-06-02 01:55:31 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-06-02 01:55:31 (GMT)
commit02a8ba7ce8e5ca07ed8e3e83f10a18acd6e38a10 (patch)
tree6c4261c5066c2e07df0b530c28bbd3fe02cbe59b /src/gui/math3d
parent215026062fb2156fe9b9d86b5c2e9999bd94be62 (diff)
downloadQt-02a8ba7ce8e5ca07ed8e3e83f10a18acd6e38a10.zip
Qt-02a8ba7ce8e5ca07ed8e3e83f10a18acd6e38a10.tar.gz
Qt-02a8ba7ce8e5ca07ed8e3e83f10a18acd6e38a10.tar.bz2
QMatrix4x4::scale(qreal,qreal) and QMatrix4x4::translate(qreal,qreal) methods
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp77
-rw-r--r--src/gui/math3d/qmatrix4x4.h6
2 files changed, 81 insertions, 2 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index 976315f..fd4f69a 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -740,6 +740,43 @@ QMatrix4x4& QMatrix4x4::scale(const QVector3D& vector)
\overload
Multiplies this matrix by another that scales coordinates by the
+ components \a x, and \a y. Returns this matrix.
+
+ \sa translate(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::scale(qreal x, qreal y)
+{
+ float vx(x);
+ float vy(y);
+ if (flagBits == Identity) {
+ m[0][0] = vx;
+ m[1][1] = vy;
+ flagBits = Scale;
+ } else if (flagBits == Scale || flagBits == (Scale | Translation)) {
+ m[0][0] *= vx;
+ m[1][1] *= vy;
+ } else if (flagBits == Translation) {
+ m[0][0] = vx;
+ m[1][1] = vy;
+ flagBits |= Scale;
+ } else {
+ m[0][0] *= vx;
+ m[0][1] *= vx;
+ m[0][2] *= vx;
+ m[0][3] *= vx;
+ m[1][0] *= vy;
+ m[1][1] *= vy;
+ m[1][2] *= vy;
+ m[1][3] *= vy;
+ flagBits = General;
+ }
+ return *this;
+}
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that scales coordinates by the
components \a x, \a y, and \a z. Returns this matrix.
\sa translate(), rotate()
@@ -872,6 +909,46 @@ QMatrix4x4& QMatrix4x4::translate(const QVector3D& vector)
\overload
Multiplies this matrix by another that translates coordinates
+ by the components \a x, and \a y. Returns this matrix.
+
+ \sa scale(), rotate()
+*/
+QMatrix4x4& QMatrix4x4::translate(qreal x, qreal y)
+{
+ float vx(x);
+ float vy(y);
+ if (flagBits == Identity) {
+ m[3][0] = vx;
+ m[3][1] = vy;
+ flagBits = Translation;
+ } else if (flagBits == Translation) {
+ m[3][0] += vx;
+ m[3][1] += vy;
+ } else if (flagBits == Scale) {
+ m[3][0] = m[0][0] * vx;
+ m[3][1] = m[1][1] * vy;
+ m[3][2] = 0.;
+ flagBits |= Translation;
+ } else if (flagBits == (Scale | Translation)) {
+ m[3][0] += m[0][0] * vx;
+ m[3][1] += m[1][1] * vy;
+ } else {
+ m[3][0] += m[0][0] * vx + m[1][0] * vy;
+ m[3][1] += m[0][1] * vx + m[1][1] * vy;
+ m[3][2] += m[0][2] * vx + m[1][2] * vy;
+ m[3][3] += m[0][3] * vx + m[1][3] * vy;
+ if (flagBits == Rotation)
+ flagBits |= Translation;
+ else if (flagBits != (Rotation | Translation))
+ flagBits = General;
+ }
+ return *this;
+}
+
+/*!
+ \overload
+
+ Multiplies this matrix by another that translates coordinates
by the components \a x, \a y, and \a z. Returns this matrix.
\sa scale(), rotate()
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index f946da8..79613a0 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -130,9 +130,11 @@ public:
QMatrix4x4& translate(const QVector3D& vector);
QMatrix4x4& rotate(qreal angle, const QVector3D& vector);
#endif
- QMatrix4x4& scale(qreal x, qreal y, qreal z = 1.0f);
+ QMatrix4x4& scale(qreal x, qreal y);
+ QMatrix4x4& scale(qreal x, qreal y, qreal z);
QMatrix4x4& scale(qreal factor);
- QMatrix4x4& translate(qreal x, qreal y, qreal z = 0.0f);
+ QMatrix4x4& translate(qreal x, qreal y);
+ QMatrix4x4& translate(qreal x, qreal y, qreal z);
QMatrix4x4& rotate(qreal angle, qreal x, qreal y, qreal z = 0.0f);
#ifndef QT_NO_QUATERNION
QMatrix4x4& rotate(const QQuaternion& quaternion);