From 508ad2e9b3af24f453720e3a3a8b7c561944abf3 Mon Sep 17 00:00:00 2001 From: Gunnar Sletta Date: Tue, 12 Nov 2013 12:13:11 +0100 Subject: Fix boundingbox calculation of rotated items. Task-number: QTBUG-34328 Change-Id: If0202a67d95500333a0fb6f4ca3eb19ecb027770 Reviewed-by: Lars Knoll --- src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp | 33 +++++++++++++++++++++++ src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h | 9 +------ 2 files changed, 34 insertions(+), 8 deletions(-) (limited to 'src/quick/scenegraph') diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index 940b8dd02b..3782cab5d3 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -113,6 +113,7 @@ struct QMatrix4x4_Accessor int flagBits; static bool isTranslate(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits <= 0x1; } + static bool isScale(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits <= 0x2; } static bool is2DSafe(const QMatrix4x4 &m) { return ((const QMatrix4x4_Accessor &) m).flagBits < 0x8; } }; @@ -533,6 +534,38 @@ int qsg_positionAttribute(QSGGeometry *g) { return -1; } + +void Rect::map(const QMatrix4x4 &matrix) +{ + const float *m = matrix.constData(); + if (QMatrix4x4_Accessor::isScale(matrix)) { + tl.x = tl.x * m[0] + m[12]; + tl.y = tl.y * m[5] + m[13]; + br.x = br.x * m[0] + m[12]; + br.y = br.y * m[5] + m[13]; + if (tl.x > br.x) + qSwap(tl.x, br.x); + if (tl.y > br.y) + qSwap(tl.y, br.y); + } else { + Pt mtl = tl; + Pt mtr = { br.x, tl.y }; + Pt mbl = { tl.x, br.y }; + Pt mbr = br; + + mtl.map(matrix); + mtr.map(matrix); + mbl.map(matrix); + mbr.map(matrix); + + set(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX); + (*this) |= mtl; + (*this) |= mtr; + (*this) |= mbl; + (*this) |= mbr; + } +} + void Element::computeBounds() { Q_ASSERT(!boundsComputed); diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 6d95f83d7a..aacf482ead 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -119,14 +119,7 @@ struct Rect { Q_ASSERT(tl.y <= br.y); } - void map(const QMatrix4x4 &m) { - tl.map(m); - br.map(m); - if (br.x < tl.x) - qSwap(br.x, tl.x); - if (br.y < tl.y) - qSwap(br.y, tl.y); - } + void map(const QMatrix4x4 &m); void set(float left, float top, float right, float bottom) { tl.set(left, top); -- cgit v1.2.3