summaryrefslogtreecommitdiffstats
path: root/src/gui/math3d
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-04 09:26:33 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-06-04 09:26:33 (GMT)
commit95c0a8de7af1e631485117f5764f4e2677ec6d0b (patch)
tree9f1fd8726b7f33a6958f3cf395c3ea1300c2d580 /src/gui/math3d
parenta800e1d5e7fa69a3bfa21d74c5db47f5a41ed65c (diff)
parent397c3bb494e220af5ef1cf6e47cfdfc84b61540b (diff)
downloadQt-95c0a8de7af1e631485117f5764f4e2677ec6d0b.zip
Qt-95c0a8de7af1e631485117f5764f4e2677ec6d0b.tar.gz
Qt-95c0a8de7af1e631485117f5764f4e2677ec6d0b.tar.bz2
Merge commit 'mainline/master' into kinetic-declarativeui
Conflicts: configure.exe src/gui/math3d/qmatrix4x4.cpp src/gui/math3d/qmatrix4x4.h tools/qdoc3/htmlgenerator.cpp
Diffstat (limited to 'src/gui/math3d')
-rw-r--r--src/gui/math3d/qgenericmatrix.cpp2
-rw-r--r--src/gui/math3d/qgenericmatrix.h4
-rw-r--r--src/gui/math3d/qmatrix4x4.cpp72
-rw-r--r--src/gui/math3d/qmatrix4x4.h148
4 files changed, 143 insertions, 83 deletions
diff --git a/src/gui/math3d/qgenericmatrix.cpp b/src/gui/math3d/qgenericmatrix.cpp
index 2b48161..61df367 100644
--- a/src/gui/math3d/qgenericmatrix.cpp
+++ b/src/gui/math3d/qgenericmatrix.cpp
@@ -116,7 +116,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn void QGenericMatrix::fill(qreal value)
+ \fn void QGenericMatrix::fill(T value)
Fills all elements of this matrix with \a value.
*/
diff --git a/src/gui/math3d/qgenericmatrix.h b/src/gui/math3d/qgenericmatrix.h
index d0b22de..b4d3707 100644
--- a/src/gui/math3d/qgenericmatrix.h
+++ b/src/gui/math3d/qgenericmatrix.h
@@ -65,7 +65,7 @@ public:
bool isIdentity() const;
void setIdentity();
- void fill(qreal value);
+ void fill(T value);
QGenericMatrix<M, N, T, InnerT> transposed() const;
@@ -175,7 +175,7 @@ Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T, InnerT>::setIdentity()
}
template <int N, int M, typename T, typename InnerT>
-Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T, InnerT>::fill(qreal value)
+Q_OUTOFLINE_TEMPLATE void QGenericMatrix<N, M, T, InnerT>::fill(T value)
{
for (int col = 0; col < N; ++col)
for (int row = 0; row < M; ++row)
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp
index fd4f69a..8ef4da3 100644
--- a/src/gui/math3d/qmatrix4x4.cpp
+++ b/src/gui/math3d/qmatrix4x4.cpp
@@ -1488,8 +1488,6 @@ QTransform QMatrix4x4::toTransform() const
#endif
/*!
- \fn QRect QMatrix4x4::mapRect(const QRect& rect) const
-
Maps \a rect by multiplying this matrix by the corners
of \a rect and then forming a new rectangle from the results.
The returned rectangle will be an ordinary 2D rectangle
@@ -1497,10 +1495,43 @@ QTransform QMatrix4x4::toTransform() const
\sa map()
*/
+QRect QMatrix4x4::mapRect(const QRect& rect) const
+{
+ if (flagBits == (Translation | Scale) || flagBits == Scale) {
+ qreal x = rect.x() * m[0][0] + m[3][0];
+ qreal y = rect.y() * m[1][1] + m[3][1];
+ qreal w = rect.width() * m[0][0];
+ qreal h = rect.height() * m[1][1];
+ if (w < 0) {
+ w = -w;
+ x -= w;
+ }
+ if (h < 0) {
+ h = -h;
+ y -= h;
+ }
+ return QRect(qRound(x), qRound(y), qRound(w), qRound(h));
+ } else if (flagBits == Translation) {
+ return QRect(qRound(rect.x() + m[3][0]),
+ qRound(rect.y() + m[3][1]),
+ rect.width(), rect.height());
+ }
-/*!
- \fn QRectF QMatrix4x4::mapRect(const QRectF& rect) const
+ QPoint tl = map(rect.topLeft());
+ QPoint tr = map(QPoint(rect.x() + rect.width(), rect.y()));
+ QPoint bl = map(QPoint(rect.x(), rect.y() + rect.height()));
+ QPoint br = map(QPoint(rect.x() + rect.width(),
+ rect.y() + rect.height()));
+ int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
+ int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
+ int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
+ int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
+
+ return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
+}
+
+/*!
Maps \a rect by multiplying this matrix by the corners
of \a rect and then forming a new rectangle from the results.
The returned rectangle will be an ordinary 2D rectangle
@@ -1510,24 +1541,22 @@ QTransform QMatrix4x4::toTransform() const
*/
QRectF QMatrix4x4::mapRect(const QRectF& rect) const
{
- if (flagBits & Translation) {
- if (flagBits & Scale) {
- qreal x = rect.x() * m[0][0] + m[3][0];
- qreal y = rect.y() * m[1][1] + m[3][1];
- qreal w = rect.width() * m[0][0];
- qreal h = rect.height() * m[1][1];
- if (w < 0) {
- w = -w;
- x -= w;
- }
- if (h < 0) {
- h = -h;
- y -= h;
- }
- return QRectF(x, y, w, h);
- } else {
- return rect.translated(m[3][0], m[3][1]);
+ if (flagBits == (Translation | Scale) || flagBits == Scale) {
+ qreal x = rect.x() * m[0][0] + m[3][0];
+ qreal y = rect.y() * m[1][1] + m[3][1];
+ qreal w = rect.width() * m[0][0];
+ qreal h = rect.height() * m[1][1];
+ if (w < 0) {
+ w = -w;
+ x -= w;
+ }
+ if (h < 0) {
+ h = -h;
+ y -= h;
}
+ return QRectF(x, y, w, h);
+ } else if (flagBits == Translation) {
+ return rect.translated(m[3][0], m[3][1]);
}
QPointF tl = map(rect.topLeft()); QPointF tr = map(rect.topRight());
@@ -1541,7 +1570,6 @@ QRectF QMatrix4x4::mapRect(const QRectF& rect) const
return QRectF(QPointF(xmin, ymin), QPointF(xmax, ymax));
}
-
/*!
\fn float *QMatrix4x4::data()
diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h
index 79613a0..ba7f67f 100644
--- a/src/gui/math3d/qmatrix4x4.h
+++ b/src/gui/math3d/qmatrix4x4.h
@@ -631,26 +631,43 @@ inline QVector3D operator*(const QVector3D& vector, const QMatrix4x4& matrix)
inline QVector3D operator*(const QMatrix4x4& matrix, const QVector3D& vector)
{
float x, y, z, w;
- x = vector.xp * matrix.m[0][0] +
- vector.yp * matrix.m[1][0] +
- vector.zp * matrix.m[2][0] +
- matrix.m[3][0];
- y = vector.xp * matrix.m[0][1] +
- vector.yp * matrix.m[1][1] +
- vector.zp * matrix.m[2][1] +
- matrix.m[3][1];
- z = vector.xp * matrix.m[0][2] +
- vector.yp * matrix.m[1][2] +
- vector.zp * matrix.m[2][2] +
- matrix.m[3][2];
- w = vector.xp * matrix.m[0][3] +
- vector.yp * matrix.m[1][3] +
- vector.zp * matrix.m[2][3] +
- matrix.m[3][3];
- if (w == 1.0f)
- return QVector3D(x, y, z, 1);
- else
- return QVector3D(x / w, y / w, z / w, 1);
+ if (matrix.flagBits == QMatrix4x4::Identity) {
+ return vector;
+ } else if (matrix.flagBits == QMatrix4x4::Translation) {
+ return QVector3D(vector.xp + matrix.m[3][0],
+ vector.yp + matrix.m[3][1],
+ vector.zp + matrix.m[3][2], 1);
+ } else if (matrix.flagBits ==
+ (QMatrix4x4::Translation | QMatrix4x4::Scale)) {
+ return QVector3D(vector.xp * matrix.m[0][0] + matrix.m[3][0],
+ vector.yp * matrix.m[1][1] + matrix.m[3][1],
+ vector.zp * matrix.m[2][2] + matrix.m[3][2], 1);
+ } else if (matrix.flagBits == QMatrix4x4::Scale) {
+ return QVector3D(vector.xp * matrix.m[0][0],
+ vector.yp * matrix.m[1][1],
+ vector.zp * matrix.m[2][2], 1);
+ } else {
+ x = vector.xp * matrix.m[0][0] +
+ vector.yp * matrix.m[1][0] +
+ vector.zp * matrix.m[2][0] +
+ matrix.m[3][0];
+ y = vector.xp * matrix.m[0][1] +
+ vector.yp * matrix.m[1][1] +
+ vector.zp * matrix.m[2][1] +
+ matrix.m[3][1];
+ z = vector.xp * matrix.m[0][2] +
+ vector.yp * matrix.m[1][2] +
+ vector.zp * matrix.m[2][2] +
+ matrix.m[3][2];
+ w = vector.xp * matrix.m[0][3] +
+ vector.yp * matrix.m[1][3] +
+ vector.zp * matrix.m[2][3] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QVector3D(x, y, z, 1);
+ else
+ return QVector3D(x / w, y / w, z / w, 1);
+ }
}
#endif
@@ -752,19 +769,33 @@ inline QPoint operator*(const QMatrix4x4& matrix, const QPoint& point)
float x, y, w;
xin = point.x();
yin = point.y();
- x = xin * matrix.m[0][0] +
- yin * matrix.m[1][0] +
- matrix.m[3][0];
- y = xin * matrix.m[0][1] +
- yin * matrix.m[1][1] +
- matrix.m[3][1];
- w = xin * matrix.m[0][3] +
- yin * matrix.m[1][3] +
- matrix.m[3][3];
- if (w == 1.0f)
- return QPoint(qRound(x), qRound(y));
- else
- return QPoint(qRound(x / w), qRound(y / w));
+ if (matrix.flagBits == QMatrix4x4::Identity) {
+ return point;
+ } else if (matrix.flagBits == QMatrix4x4::Translation) {
+ return QPoint(qRound(xin + matrix.m[3][0]),
+ qRound(yin + matrix.m[3][1]));
+ } else if (matrix.flagBits ==
+ (QMatrix4x4::Translation | QMatrix4x4::Scale)) {
+ return QPoint(qRound(xin * matrix.m[0][0] + matrix.m[3][0]),
+ qRound(yin * matrix.m[1][1] + matrix.m[3][1]));
+ } else if (matrix.flagBits == QMatrix4x4::Scale) {
+ return QPoint(qRound(xin * matrix.m[0][0]),
+ qRound(yin * matrix.m[1][1]));
+ } else {
+ x = xin * matrix.m[0][0] +
+ yin * matrix.m[1][0] +
+ matrix.m[3][0];
+ y = xin * matrix.m[0][1] +
+ yin * matrix.m[1][1] +
+ matrix.m[3][1];
+ w = xin * matrix.m[0][3] +
+ yin * matrix.m[1][3] +
+ matrix.m[3][3];
+ if (w == 1.0f)
+ return QPoint(qRound(x), qRound(y));
+ else
+ return QPoint(qRound(x / w), qRound(y / w));
+ }
}
inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
@@ -773,19 +804,33 @@ inline QPointF operator*(const QMatrix4x4& matrix, const QPointF& point)
float x, y, w;
xin = point.x();
yin = point.y();
- x = xin * matrix.m[0][0] +
- yin * matrix.m[1][0] +
- matrix.m[3][0];
- y = xin * matrix.m[0][1] +
- yin * matrix.m[1][1] +
- matrix.m[3][1];
- w = xin * matrix.m[0][3] +
- yin * matrix.m[1][3] +
- matrix.m[3][3];
- if (w == 1.0f) {
- return QPointF(qreal(x), qreal(y));
+ if (matrix.flagBits == QMatrix4x4::Identity) {
+ return point;
+ } else if (matrix.flagBits == QMatrix4x4::Translation) {
+ return QPointF(xin + matrix.m[3][0],
+ yin + matrix.m[3][1]);
+ } else if (matrix.flagBits ==
+ (QMatrix4x4::Translation | QMatrix4x4::Scale)) {
+ return QPointF(xin * matrix.m[0][0] + matrix.m[3][0],
+ yin * matrix.m[1][1] + matrix.m[3][1]);
+ } else if (matrix.flagBits == QMatrix4x4::Scale) {
+ return QPointF(xin * matrix.m[0][0],
+ yin * matrix.m[1][1]);
} else {
- return QPointF(qreal(x / w), qreal(y / w));
+ x = xin * matrix.m[0][0] +
+ yin * matrix.m[1][0] +
+ matrix.m[3][0];
+ y = xin * matrix.m[0][1] +
+ yin * matrix.m[1][1] +
+ matrix.m[3][1];
+ w = xin * matrix.m[0][3] +
+ yin * matrix.m[1][3] +
+ matrix.m[3][3];
+ if (w == 1.0f) {
+ return QPointF(qreal(x), qreal(y));
+ } else {
+ return QPointF(qreal(x / w), qreal(y / w));
+ }
}
}
@@ -903,19 +948,6 @@ inline QVector4D QMatrix4x4::map(const QVector4D& point) const
#endif
-inline QRect QMatrix4x4::mapRect(const QRect& rect) const
-{
- QPoint tl = map(rect.topLeft()); QPoint tr = map(rect.topRight());
- QPoint bl = map(rect.bottomLeft()); QPoint br = map(rect.bottomRight());
-
- int xmin = qMin(qMin(tl.x(), tr.x()), qMin(bl.x(), br.x()));
- int xmax = qMax(qMax(tl.x(), tr.x()), qMax(bl.x(), br.x()));
- int ymin = qMin(qMin(tl.y(), tr.y()), qMin(bl.y(), br.y()));
- int ymax = qMax(qMax(tl.y(), tr.y()), qMax(bl.y(), br.y()));
-
- return QRect(QPoint(xmin, ymin), QPoint(xmax, ymax));
-}
-
inline float *QMatrix4x4::data()
{
// We have to assume that the caller will modify the matrix elements,