From ca15825ed4a1d4c8642c2292760726ebdcda863b Mon Sep 17 00:00:00 2001 From: Sean Harmer Date: Sat, 19 Apr 2014 16:36:35 +0100 Subject: Add viewport transform to QMatrix4x4 This allows to easily create a matrix that performs the transformation used by OpenGL fixed function to go from normalized device coordinates to window coordinates. This comes in useful if you need to perform the NDC->window coordinate conversion inside a shader. Change-Id: I183b3545bfb3eb1e8b13fc3172911b46926fcbb7 Reviewed-by: Paul Lemire Reviewed-by: Laszlo Agocs --- src/gui/math3d/qmatrix4x4.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/gui/math3d/qmatrix4x4.h') diff --git a/src/gui/math3d/qmatrix4x4.h b/src/gui/math3d/qmatrix4x4.h index d4ba7d64d8..c42ccc2dc5 100644 --- a/src/gui/math3d/qmatrix4x4.h +++ b/src/gui/math3d/qmatrix4x4.h @@ -148,6 +148,8 @@ public: #ifndef QT_NO_VECTOR3D void lookAt(const QVector3D& eye, const QVector3D& center, const QVector3D& up); #endif + void viewport(const QRectF &rect); + void viewport(float left, float bottom, float width, float height, float nearPlane = 0.0f, float farPlane = 1.0f); void flipCoordinates(); void copyDataTo(float *values) const; @@ -1077,6 +1079,11 @@ inline float *QMatrix4x4::data() return *m; } +inline void QMatrix4x4::viewport(const QRectF &rect) +{ + viewport(rect.x(), rect.y(), rect.width(), rect.height()); +} + #ifndef QT_NO_DEBUG_STREAM Q_GUI_EXPORT QDebug operator<<(QDebug dbg, const QMatrix4x4 &m); #endif -- cgit v1.2.3