summaryrefslogtreecommitdiffstats
path: root/src/datavis3d
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-04-25 06:57:31 +0300
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-04-25 09:45:21 +0300
commita488b9ab2ca8e2379911083bd1f722d26f896edf (patch)
treecb85ec018d270c4bde05857451faf2f488a7ca8f /src/datavis3d
parentc41dd491dc4a793d9e0d726d974d9565f1e0a66e (diff)
Autozoom based on aspect ratio
Change-Id: I3bdc9863d08f0d8c9aa1629871397729ce207bb9 Change-Id: I3bdc9863d08f0d8c9aa1629871397729ce207bb9 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavis3d')
-rw-r--r--src/datavis3d/engine/q3dbars.cpp30
-rw-r--r--src/datavis3d/engine/q3dbars_p.h1
2 files changed, 17 insertions, 14 deletions
diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp
index eef8d9b7..838ad8ab 100644
--- a/src/datavis3d/engine/q3dbars.cpp
+++ b/src/datavis3d/engine/q3dbars.cpp
@@ -76,6 +76,7 @@ QTCOMMERCIALDATAVIS3D_BEGIN_NAMESPACE
const GLfloat zComp = 10.0f; // Compensation for z position; move all objects to positive z, as shader can't handle negative values correctly
const QVector3D defaultLightPos = QVector3D(0.0f, 3.0f, zComp);
+const GLfloat defaultRatio = 1.0f / 1.6f; // default aspect ratio 16:10
Q3DBars::Q3DBars()
: d_ptr(new Q3DBarsPrivate(this))
@@ -250,7 +251,6 @@ void Q3DBars::render(QPainter *painter)
#endif
}
-// TODO: Adjust overall zoom level (= view matrix scale) if aspect ratio is closer to 1:1 than 16:10
void Q3DBars::drawZoomScene()
{
// Set clear color
@@ -281,7 +281,8 @@ void Q3DBars::drawZoomScene()
#ifdef ROTATE_ZOOM_SELECTION
// Calculate view matrix
QMatrix4x4 viewMatrix = CameraHelper::calculateViewMatrix(d_ptr->m_mousePos,
- d_ptr->m_zoomLevel,
+ d_ptr->m_zoomLevel
+ * d_ptr->m_zoomAdjustment,
d_ptr->m_zoomViewPort.width(),
d_ptr->m_zoomViewPort.height());
@@ -301,11 +302,8 @@ void Q3DBars::drawZoomScene()
QVector3D(0.0f, 0.0f, zComp),
QVector3D(0.0f, 1.0f, 0.0f));
- if (d_ptr->m_zoomViewPort.height() > d_ptr->m_zoomViewPort.width()) {
- viewMatrix.scale((GLfloat)d_ptr->m_zoomViewPort.width()
- / (GLfloat)d_ptr->m_zoomViewPort.height());
- // TODO: Center shrunk view
- }
+ // Adjust scaling (zoom rate based on aspect ratio)
+ viewMatrix.scale(d_ptr->m_zoomAdjustment);
// Set light position a bit above the camera (depends on do we have row or column zoom)
if (ZoomColumn == d_ptr->m_selectionMode)
@@ -443,7 +441,6 @@ void Q3DBars::drawZoomScene()
#endif
}
-// TODO: Adjust overall zoom level (= view matrix scale) if aspect ratio is closer to 1:1 than 16:10
void Q3DBars::drawScene()
{
GLint startBar = 0;
@@ -472,14 +469,10 @@ void Q3DBars::drawScene()
// Calculate view matrix
QMatrix4x4 viewMatrix = CameraHelper::calculateViewMatrix(d_ptr->m_mousePos,
- d_ptr->m_zoomLevel,
+ d_ptr->m_zoomLevel
+ * d_ptr->m_zoomAdjustment,
d_ptr->m_sceneViewPort.width(),
d_ptr->m_sceneViewPort.height());
- if (d_ptr->m_sceneViewPort.height() > d_ptr->m_sceneViewPort.width()) {
- viewMatrix.scale((GLfloat)d_ptr->m_sceneViewPort.width()
- / (GLfloat)d_ptr->m_sceneViewPort.height());
- // TODO: Center shrunk view
- }
// Calculate drawing order
// Draw order is reversed to optimize amount of drawing (ie. draw front objects first, depth test handles not needing to draw objects behind them)
@@ -1175,6 +1168,14 @@ void Q3DBars::resizeEvent(QResizeEvent *event)
else
d_ptr->m_sceneViewPort = QRect(0, 0, width(), height());
d_ptr->m_zoomViewPort = QRect(0, 0, width(), height());
+
+ // Calculate zoom level based on aspect ratio
+ GLfloat div;
+ GLfloat zoomAdjustment;
+ div = qMin(width(), height());
+ zoomAdjustment = defaultRatio * ((width() / div) / (height() / div));
+ qDebug() << "zoom adjustment" << zoomAdjustment;
+ d_ptr->m_zoomAdjustment = qMin(zoomAdjustment, 1.0f); // clamp to 1.0f
}
void Q3DBars::setBarSpecs(QSizeF thickness, QSizeF spacing, bool relative)
@@ -1477,6 +1478,7 @@ Q3DBarsPrivate::Q3DBarsPrivate(Q3DBars *q)
m_mousePressed(MouseNone),
m_mousePos(QPoint(0, 0)),
m_zoomLevel(100),
+ m_zoomAdjustment(1.0f),
m_horizontalRotation(-45.0f),
m_verticalRotation(15.0f),
m_barThickness(QSizeF(0.75f, 0.75f)),
diff --git a/src/datavis3d/engine/q3dbars_p.h b/src/datavis3d/engine/q3dbars_p.h
index f9fde889..0d4568d2 100644
--- a/src/datavis3d/engine/q3dbars_p.h
+++ b/src/datavis3d/engine/q3dbars_p.h
@@ -123,6 +123,7 @@ public:
MousePressType m_mousePressed;
QPoint m_mousePos;
GLint m_zoomLevel;
+ GLfloat m_zoomAdjustment;
GLfloat m_horizontalRotation;
GLfloat m_verticalRotation;
QSizeF m_barThickness;