diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-02 01:55:31 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-06-02 02:54:23 (GMT) |
commit | 5a7d208ee0730021b79310132d4dd384d7d15801 (patch) | |
tree | 3efca16854f3ccf5d56e0f957b8e9aca6cc3cacd /src/gui | |
parent | cef61c5c660410e2db8418c8a23b68d9e523c75d (diff) | |
download | Qt-5a7d208ee0730021b79310132d4dd384d7d15801.zip Qt-5a7d208ee0730021b79310132d4dd384d7d15801.tar.gz Qt-5a7d208ee0730021b79310132d4dd384d7d15801.tar.bz2 |
QMatrix4x4::scale(qreal,qreal) and QMatrix4x4::translate(qreal,qreal) methods
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/math3d/qmatrix4x4.cpp | 77 | ||||
-rw-r--r-- | src/gui/math3d/qmatrix4x4.h | 6 |
2 files changed, 81 insertions, 2 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index d2f1ded..8ef4da3 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 00543f5..cff4c1e 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); |