diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-08-12 08:30:11 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-08-12 08:35:36 +0300 |
commit | ee49988bc5f47440c0cc5450bc34a4c9a8f43d1d (patch) | |
tree | 5a9df17437f35ba771edee40704bad237c157c90 /src/datavis3d/engine/scatter3drenderer.cpp | |
parent | f45da18aa8ad56d1cd9ce3ff73ab222fa61c26e4 (diff) |
Q3DScatter: Implemented viewing scatter chart from below
Task-number: QTRD-2180
Change-Id: I89facfb8f3afca17a63a3b69e1613c37a86e484c
Change-Id: I89facfb8f3afca17a63a3b69e1613c37a86e484c
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src/datavis3d/engine/scatter3drenderer.cpp')
-rw-r--r-- | src/datavis3d/engine/scatter3drenderer.cpp | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/src/datavis3d/engine/scatter3drenderer.cpp b/src/datavis3d/engine/scatter3drenderer.cpp index 6ce34b72..19801ce6 100644 --- a/src/datavis3d/engine/scatter3drenderer.cpp +++ b/src/datavis3d/engine/scatter3drenderer.cpp @@ -85,6 +85,7 @@ Scatter3DRenderer::Scatter3DRenderer(Scatter3DController *controller) m_previouslySelectedItem(0), m_xFlipped(false), m_zFlipped(false), + m_yFlipped(false), m_updateLabels(false), m_dotShader(0), m_depthShader(0), @@ -309,7 +310,8 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, QMatrix4x4 viewMatrix = m_controller->calculateViewMatrix( m_cachedZoomLevel * m_autoScaleAdjustment, m_mainViewPort.width(), - m_mainViewPort.height()); + m_mainViewPort.height(), + true); // Calculate label flipping if (viewMatrix.row(0).x() > 0) @@ -321,6 +323,12 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, else m_xFlipped = true; + // Check if we're viewing the scene from below + if (viewMatrix.row(2).y() < 0) + m_yFlipped = true; + else + m_yFlipped = false; + // Calculate background rotation if (!m_zFlipped && !m_xFlipped) backgroundRotation = 270.0f; @@ -743,7 +751,13 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, #endif // We can copy modelMatrix to itModelMatrix as it has not been translated itModelMatrix = modelMatrix; - modelMatrix.rotate(backgroundRotation, 0.0f, 1.0f, 0.0f); + // If we're viewing from below, background object must be flipped + if (m_yFlipped) { + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + modelMatrix.rotate(270.0f - backgroundRotation, 0.0f, 1.0f, 0.0f); + } else { + modelMatrix.rotate(backgroundRotation, 0.0f, 1.0f, 0.0f); + } #ifdef SHOW_DEPTH_TEXTURE_SCENE MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; @@ -832,9 +846,15 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(0.0f, - -backgroundMargin, - linePos / m_scaleFactor + zComp); + if (m_yFlipped) { + modelMatrix.translate(0.0f, + backgroundMargin, + linePos / m_scaleFactor + zComp); + } else { + modelMatrix.translate(0.0f, + -backgroundMargin, + linePos / m_scaleFactor + zComp); + } #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z modelMatrix.scale( QVector3D( @@ -851,6 +871,10 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, gridLineWidth, gridLineWidth)); #endif + // If we're viewing from below, grid line object must be flipped + if (m_yFlipped) + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; @@ -902,9 +926,15 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(linePos / m_scaleFactor, - -backgroundMargin, - zComp); + if (m_yFlipped) { + modelMatrix.translate(linePos / m_scaleFactor, + backgroundMargin, + zComp); + } else { + modelMatrix.translate(linePos / m_scaleFactor, + -backgroundMargin, + zComp); + } #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z modelMatrix.scale( QVector3D( @@ -921,6 +951,10 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, aspectRatio * backgroundMargin)); #endif + // If we're viewing from below, grid line object must be flipped + if (m_yFlipped) + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; @@ -1187,6 +1221,7 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, if (axisCacheMax->labelItems().size() > labelNbr) { GLfloat labelXTrans = aspectRatio * backgroundMargin; #endif + GLfloat labelYTrans = -backgroundMargin; GLfloat rotLabelX = -90.0f; GLfloat rotLabelY = 0.0f; GLfloat rotLabelZ = 0.0f; @@ -1197,10 +1232,16 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, labelXTrans = -labelXTrans; alignment = Qt::AlignLeft; } + if (m_yFlipped) { + rotLabelZ += 180.0f; + rotLabelY += 180.0f; + labelYTrans = -labelYTrans; + } QVector3D labelTrans = QVector3D(labelXTrans, - -backgroundMargin, + labelYTrans, labelPos / m_scaleFactor + zComp); + // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); #ifndef USE_UNIFORM_SCALING @@ -1241,6 +1282,7 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, if (axisCacheMax->labelItems().size() > labelNbr) { GLfloat labelZTrans = aspectRatio * backgroundMargin; #endif + GLfloat labelYTrans = -backgroundMargin; GLfloat rotLabelX = -90.0f; GLfloat rotLabelY = 90.0f; GLfloat rotLabelZ = 0.0f; @@ -1251,8 +1293,13 @@ void Scatter3DRenderer::drawScene(CameraHelper *camera, labelZTrans = -labelZTrans; alignment = Qt::AlignRight; } + if (m_yFlipped) { + rotLabelZ += 180.0f; + rotLabelY += 180.0f; + labelYTrans = -labelYTrans; + } QVector3D labelTrans = QVector3D(labelPos / m_scaleFactor, - -backgroundMargin, + labelYTrans, labelZTrans + zComp); // Draw the label here |