diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2013-10-21 13:42:34 +0300 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-10-22 08:47:40 +0300 |
commit | c889c9bcd25b5a2c750c30edf3dab0bbda72c51a (patch) | |
tree | b221f7a60c88ebe835db438ca574baf48074b3fc /src/datavisualization/engine | |
parent | 1344723a7fee31853d27acdf25387df6d25eacba (diff) |
Minor optimizations and cleanup to bars and scatter rendering
Change-Id: I4fc5b83bfb41ff9bcd54438710b68c8132334cd3
Reviewed-by: Tomi Korpipää <tomi.korpipaa@digia.com>
Diffstat (limited to 'src/datavisualization/engine')
-rw-r--r-- | src/datavisualization/engine/bars3drenderer.cpp | 459 | ||||
-rw-r--r-- | src/datavisualization/engine/scatter3drenderer.cpp | 478 | ||||
-rw-r--r-- | src/datavisualization/engine/selectionpointer.cpp | 8 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3drenderer.cpp | 19 |
4 files changed, 436 insertions, 528 deletions
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index d5c9ddc5..a0ff9262 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -219,9 +219,9 @@ void Bars3DRenderer::updateScene(Q3DScene *scene) if (m_hasHeightAdjustmentChanged) { // Set initial camera position. Also update if height adjustment has changed. - scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance), + scene->activeCamera()->setBaseOrientation(cameraDistanceVector, QVector3D(0.0f, -m_yAdjustment, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + upVector); m_hasHeightAdjustmentChanged = false; } @@ -285,9 +285,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, // Adjust scaling (zoom rate based on aspect ratio) GLfloat camZPosSliced = 5.0f / m_autoScaleAdjustment; - viewMatrix.lookAt(QVector3D(0.0f, 0.0f, camZPosSliced), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + viewMatrix.lookAt(QVector3D(0.0f, 0.0f, camZPosSliced), zeroVector, upVector); // Set light position lightPos = QVector3D(0.0f, -m_yAdjustment, 0.0f); @@ -301,8 +299,15 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, m_barShader->setUniformValue(m_barShader->lightS(), 0.5f); m_barShader->setUniformValue(m_barShader->ambientS(), m_cachedTheme.m_ambientStrength * 2.0f); - // Draw bars + // Draw the selected row / column + // We need some room for labels underneath; add +0.2f + GLfloat barPosYAdjustment = m_yAdjustment / 2.0f - 0.2f; + QVector3D modelMatrixScaler(m_scaleX, 0.0f, m_scaleZ); + QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix; + QVector3D barHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor)); + QVector3D rowHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor)); + QVector3D columnHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor)); for (int bar = startBar; bar != stopBar; bar += stepBar) { BarRenderItem *item = m_sliceSelection->at(bar); if (!item) @@ -317,36 +322,37 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - GLfloat barPosY = negativesComp * item->translation().y() - m_yAdjustment / 2.0f + 0.2f; // we need some room for labels underneath; add +0.2f + GLfloat barPosY = negativesComp * item->translation().y() - barPosYAdjustment; if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) barPosX = item->translation().x(); else barPosX = -(item->translation().z()); // flip z; frontmost bar to the left modelMatrix.translate(barPosX, barPosY, 0.0f); - modelMatrix.scale(QVector3D(m_scaleX, negativesComp * item->height(), m_scaleZ)); - itModelMatrix.scale(QVector3D(m_scaleX, negativesComp * item->height(), m_scaleZ)); + modelMatrixScaler.setY(negativesComp * item->height()); + modelMatrix.scale(modelMatrixScaler); + itModelMatrix.scale(modelMatrixScaler); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; #if 0 QVector3D baseColor; if (m_selection.x() == item->position().x() && m_selection.y() == item->position().y()) - baseColor = Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor); + baseColor = barHighlightColor; else if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) - baseColor = Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor); + baseColor = rowHighlightColor; else - baseColor = Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor); + baseColor = columnHighlightColor; QVector3D heightColor = Utils::vectorFromColor(m_cachedTheme.m_heightColor) * item->height(); QVector3D barColor = baseColor + heightColor; #else QVector3D barColor; if (m_selection.x() == item->position().x() && m_selection.y() == item->position().y()) - barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor); + barColor = barHighlightColor; else if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) - barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor); + barColor = rowHighlightColor; else - barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor); + barColor = columnHighlightColor; #endif if (item->height() != 0) { @@ -376,75 +382,57 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, // Draw labels for axes BarRenderItem *dummyItem(0); const LabelItem &sliceSelectionLabel = *m_sliceTitleItem; + QVector3D positionComp(0.0f, m_autoScaleAdjustment, 0.0f); + const Q3DCamera *activeCamera = m_cachedScene->activeCamera(); if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) { if (m_sliceTitleItem) { m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), 0, - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), - false, false, Drawer::LabelTop); + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelTop); } m_drawer->drawLabel(*dummyItem, zLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), 0, - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), - false, false, Drawer::LabelBottom); + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelBottom); } else { m_drawer->drawLabel(*dummyItem, xLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), 0, - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), - false, false, Drawer::LabelBottom); + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelBottom); if (m_sliceTitleItem) { m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), 0, - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), - false, false, Drawer::LabelTop); + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelTop); } } m_drawer->drawLabel(*dummyItem, yLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 90.0f), 0, - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), + positionComp, QVector3D(0.0f, 0.0f, 90.0f), 0, + m_cachedSelectionMode, m_labelShader, m_labelObj, activeCamera, false, false, Drawer::LabelLeft); // Draw labels for bars + QVector3D valuePositionComp(0.0f, m_yAdjustment, 0.0f); + QVector3D negativesRotation(0.0f, 0.0f, 90.0f); + QVector3D sliceLabelRotation(0.0f, 0.0f, -45.0f); + GLfloat negativesCompPow2 = negativesComp * negativesComp; for (int col = 0; col < stopBar; col++) { BarRenderItem *item = m_sliceSelection->at(col); // Draw values - if (negativesComp == 1.0f) { + if (!m_hasNegativeValues) { m_drawer->drawLabel(*item, item->sliceLabelItem(), viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 90.0f), - item->height(), - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), false, false, - Drawer::LabelOver, Qt::AlignTop); + valuePositionComp, negativesRotation, item->height(), + m_cachedSelectionMode, m_labelShader, m_labelObj, activeCamera, + false, false, Drawer::LabelOver, Qt::AlignTop); } else { m_drawer->drawLabel(*item, item->sliceLabelItem(), viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), - negativesComp * negativesComp * item->height(), - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera()); + valuePositionComp, zeroVector, negativesCompPow2 * item->height(), + m_cachedSelectionMode, m_labelShader, m_labelObj, activeCamera); } // Draw labels if (m_sliceCache->labelItems().size() > col) { - const LabelItem *labelItem(0); - labelItem = m_sliceCache->labelItems().at(col); - m_drawer->drawLabel(*item, *labelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, -45.0f), item->height(), - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), false, false, - Drawer::LabelBelow); + m_drawer->drawLabel(*item, *m_sliceCache->labelItems().at(col), viewMatrix, + projectionMatrix, positionComp, sliceLabelRotation, + item->height(), m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelBelow); } } @@ -471,17 +459,19 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) GLfloat colPos = 0; GLfloat rowPos = 0; + const Q3DCamera *activeCamera = m_cachedScene->activeCamera(); + // Specify viewport glViewport(m_mainViewPort.x(), m_mainViewPort.y(), m_mainViewPort.width(), m_mainViewPort.height()); // Set up projection matrix QMatrix4x4 projectionMatrix; - projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width() - / (GLfloat)m_mainViewPort.height(), 0.1f, 100.0f); + GLfloat viewPortRatio = (GLfloat)m_mainViewPort.width() / (GLfloat)m_mainViewPort.height(); + projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f); // Get the view matrix - QMatrix4x4 viewMatrix = m_cachedScene->activeCamera()->viewMatrix(); + QMatrix4x4 viewMatrix = activeCamera->viewMatrix(); // Calculate drawing order // Draw order is reversed to optimize amount of drawing (ie. draw front objects first, @@ -532,6 +522,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Introduce regardless of shadow quality to simplify logic QMatrix4x4 depthViewMatrix; QMatrix4x4 depthProjectionMatrix; + QMatrix4x4 depthProjectionViewMatrix; + + QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix; #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { @@ -551,20 +544,21 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Get the depth view matrix // It may be possible to hack lightPos here if we want to make some tweaks to shadow - QVector3D depthLightPos = m_cachedScene->activeCamera()->calculatePositionRelativeToCamera( - QVector3D(0.0f, 0.0f, 0.0f), 0.0f, 3.5f / m_autoScaleAdjustment); + QVector3D depthLightPos = activeCamera->calculatePositionRelativeToCamera( + zeroVector, 0.0f, 3.5f / m_autoScaleAdjustment); depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, -m_yAdjustment, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + upVector); // TODO: Why does depthViewMatrix.column(3).y() goes to zero when we're directly above? // That causes the scene to be not drawn from above -> must be fixed // qDebug() << lightPos << depthViewMatrix << depthViewMatrix.column(3); // Set the depth projection matrix - depthProjectionMatrix.perspective(10.0f, (GLfloat)m_mainViewPort.width() - / (GLfloat)m_mainViewPort.height(), 3.0f, 100.0f); + depthProjectionMatrix.perspective(10.0f, viewPortRatio, 3.0f, 100.0f); + depthProjectionViewMatrix = depthProjectionMatrix * depthViewMatrix; // Draw bars to depth buffer + QVector3D shadowScaler(m_scaleX * 0.9f, 0.0f, m_scaleZ * 0.9f); for (int row = startRow; row != stopRow; row += stepRow) { for (int bar = startBar; bar != stopBar; bar += stepBar) { const BarRenderItem &item = m_renderItemArray.at(row).at(bar); @@ -597,9 +591,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) item.height() - m_yAdjustment + shadowOffset, (m_columnDepth - rowPos) / m_scaleFactor); // Scale the bars down in X and Z to reduce self-shadowing issues - modelMatrix.scale(QVector3D(m_scaleX * 0.9f, item.height(), m_scaleZ * 0.9f)); + shadowScaler.setY(item.height()); + modelMatrix.scale(shadowScaler); - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = depthProjectionViewMatrix * modelMatrix; m_depthShader->setUniformValue(m_depthShader->MVP(), MVPMatrix); @@ -637,13 +632,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); - QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), zeroVector, upVector); + QMatrix4x4 MVPMatrix = projectionViewMatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); - m_drawer->drawObject(m_labelShader, m_labelObj, - m_depthTexture); + m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); glDisable(GL_TEXTURE_2D); m_labelShader->release(); #endif @@ -664,8 +656,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Draw bars to selection buffer glBindFramebuffer(GL_FRAMEBUFFER, m_selectionFrameBuffer); glEnable(GL_DEPTH_TEST); // Needed, otherwise the depth render buffer is not used - glClearColor(selectionSkipColor.x() / 255, selectionSkipColor.y() / 255, - selectionSkipColor.z() / 255, 1.0f); // Set clear color to white (= selectionSkipColor) + glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Set clear color to white (= selectionSkipColor) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Needed for clearing the frame buffer glDisable(GL_DITHER); // disable dithering, it may affect colors if enabled for (int row = startRow; row != stopRow; row += stepRow) { @@ -690,7 +681,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) (m_columnDepth - rowPos) / m_scaleFactor); modelMatrix.scale(QVector3D(m_scaleX, item.height(), m_scaleZ)); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; //#if !defined(QT_OPENGL_ES_2) // QVector3D barColor = QVector3D((GLdouble)row / 32767.0, @@ -744,10 +735,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); - QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f), zeroVector, upVector); + QMatrix4x4 MVPMatrix = projectionViewMatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_selectionTexture); glDisable(GL_TEXTURE_2D); @@ -786,8 +775,17 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } // Draw bars + QVector3D barHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor)); + QVector3D rowHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor)); + QVector3D columnHighlightColor(Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor)); + QVector3D baseColor(Utils::vectorFromColor(m_cachedTheme.m_baseColor)); + + GLfloat adjustedLightStrength = m_cachedTheme.m_lightStrength / 10.0f; + GLfloat adjustedHighlightStrength = m_cachedTheme.m_highlightLightStrength / 10.0f; + bool barSelectionFound = false; BarRenderItem *selectedBar(0); + QVector3D modelScaler(m_scaleX, 0.0f, m_scaleZ); for (int row = startRow; row != stopRow; row += stepRow) { for (int bar = startBar; bar != stopBar; bar += stepBar) { BarRenderItem &item = m_renderItemArray[row][bar]; @@ -800,7 +798,6 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 modelMatrix; QMatrix4x4 itModelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; colPos = (bar + 0.5f) * (m_cachedBarSpacing.width()); rowPos = (row + 0.5f) * (m_cachedBarSpacing.height()); @@ -808,17 +805,16 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) modelMatrix.translate((colPos - m_rowWidth) / m_scaleFactor, item.height() - m_yAdjustment, (m_columnDepth - rowPos) / m_scaleFactor); - modelMatrix.scale(QVector3D(m_scaleX, item.height(), m_scaleZ)); - itModelMatrix.scale(QVector3D(m_scaleX, item.height(), m_scaleZ)); + modelScaler.setY(item.height()); + modelMatrix.scale(modelScaler); + itModelMatrix.scale(modelScaler); #ifdef SHOW_DEPTH_TEXTURE_SCENE - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = depthProjectionViewMatrix * modelMatrix; #else - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; #endif - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; #if 0 - QVector3D baseColor = Utils::vectorFromColor(m_cachedTheme.m_baseColor); QVector3D heightColor = Utils::vectorFromColor(m_cachedTheme.m_heightColor) * item.height(); QVector3D depthColor = Utils::vectorFromColor(m_cachedTheme.m_depthColor) @@ -826,18 +822,20 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) QVector3D barColor = baseColor + heightColor + depthColor; #else - QVector3D barColor = Utils::vectorFromColor(m_cachedTheme.m_baseColor); + QVector3D barColor = baseColor; #endif GLfloat lightStrength = m_cachedTheme.m_lightStrength; + GLfloat shadowLightStrength = adjustedLightStrength; if (m_cachedSelectionMode > QDataVis::SelectionModeNone) { Bars3DController::SelectionType selectionType = isSelected(row, bar); switch (selectionType) { case Bars3DController::SelectionItem: { - barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightBarColor); + barColor = barHighlightColor; lightStrength = m_cachedTheme.m_highlightLightStrength; + shadowLightStrength = adjustedHighlightStrength; // Insert position data into render item. We have no ownership, don't delete the previous one if (!m_cachedIsSlicingActivated) { selectedBar = &item; @@ -870,8 +868,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionRow: { // Current bar is on the same row as the selected bar - barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightRowColor); + barColor = rowHighlightColor; lightStrength = m_cachedTheme.m_highlightLightStrength; + shadowLightStrength = adjustedHighlightStrength; if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) { item.setTranslation(modelMatrix.column(3).toVector3D()); item.setPosition(QPoint(row, bar)); @@ -882,8 +881,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } case Bars3DController::SelectionColumn: { // Current bar is on the same column as the selected bar - barColor = Utils::vectorFromColor(m_cachedTheme.m_highlightColumnColor); + barColor = columnHighlightColor; lightStrength = m_cachedTheme.m_highlightLightStrength; + shadowLightStrength = adjustedHighlightStrength; if (QDataVis::SelectionModeSliceColumn == m_cachedSelectionMode) { item.setTranslation(modelMatrix.column(3).toVector3D()); item.setPosition(QPoint(row, bar)); @@ -912,9 +912,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; m_barShader->setUniformValue(m_barShader->shadowQ(), m_shadowQualityToShader); m_barShader->setUniformValue(m_barShader->depth(), depthMVPMatrix); - m_barShader->setUniformValue(m_barShader->lightS(), lightStrength / 10.0f); + m_barShader->setUniformValue(m_barShader->lightS(), shadowLightStrength); // Draw the object m_drawer->drawObject(m_barShader, m_barObj, 0, m_depthTexture); @@ -946,29 +947,26 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glCullFace(GL_BACK); // Draw background + GLfloat rowScaleFactor = m_rowWidth / m_scaleFactor; + GLfloat columnScaleFactor = m_columnDepth / m_scaleFactor; + if (m_cachedIsBackgroundEnabled && m_backgroundObj) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; + QVector3D backgroundScaler(rowScaleFactor, 1.0f, columnScaleFactor); modelMatrix.translate(0.0f, 1.0f - m_yAdjustment, 0.0f); - modelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, - 1.0f, - m_columnDepth / m_scaleFactor)); + modelMatrix.scale(backgroundScaler); modelMatrix.rotate(backgroundRotation, 0.0f, 1.0f, 0.0f); - itModelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, - 1.0f, - m_columnDepth / m_scaleFactor)); + itModelMatrix.scale(backgroundScaler); itModelMatrix.rotate(backgroundRotation, 0.0f, 1.0f, 0.0f); #ifdef SHOW_DEPTH_TEXTURE_SCENE - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = depthProjectionViewMatrix * modelMatrix; #else - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; #endif - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; - QVector3D backgroundColor = Utils::vectorFromColor(m_cachedTheme.m_backgroundColor); // Set shader bindings @@ -985,11 +983,12 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; m_backgroundShader->setUniformValue(m_backgroundShader->shadowQ(), m_shadowQualityToShader); m_backgroundShader->setUniformValue(m_backgroundShader->depth(), depthMVPMatrix); m_backgroundShader->setUniformValue(m_backgroundShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + adjustedLightStrength); // Draw the object m_drawer->drawObject(m_backgroundShader, m_backgroundObj, 0, m_depthTexture); @@ -1030,28 +1029,26 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->color(), barColor); lineShader->setUniformValue(lineShader->ambientS(), m_cachedTheme.m_ambientStrength); + QVector3D gridLineScaler(rowScaleFactor, gridLineWidth, gridLineWidth); + // Floor lines: rows for (GLfloat row = 0.0f; row <= m_cachedRowCount; row++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; rowPos = row * m_cachedBarSpacing.height(); modelMatrix.translate(0.0f, -m_yAdjustment, (m_columnDepth - rowPos) / m_scaleFactor); - modelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, - gridLineWidth)); - itModelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, - gridLineWidth)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); // 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); itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); } - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -1062,10 +1059,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -1081,19 +1078,17 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } // Floor lines: columns + gridLineScaler = QVector3D(gridLineWidth, gridLineWidth, columnScaleFactor); for (GLfloat bar = 0.0f; bar <= m_cachedColumnCount; bar++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; colPos = bar * m_cachedBarSpacing.width(); modelMatrix.translate((m_rowWidth - colPos) / m_scaleFactor, -m_yAdjustment, 0.0f); - modelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - m_columnDepth / m_scaleFactor)); - itModelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - m_columnDepth / m_scaleFactor)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); // If we're viewing from below, grid line object must be flipped if (m_yFlipped) { @@ -1101,8 +1096,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); } - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -1113,10 +1107,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -1139,29 +1133,26 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) if (m_hasNegativeValues) startLine = -m_heightNormalizer; + gridLineScaler = QVector3D(rowScaleFactor, gridLineWidth, gridLineWidth); for (GLfloat lineHeight = startLine; lineHeight <= m_heightNormalizer; lineHeight += heightStep) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; if (m_zFlipped) { modelMatrix.translate(0.0f, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - m_columnDepth / m_scaleFactor); + columnScaleFactor); } else { modelMatrix.translate(0.0f, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - -m_columnDepth / m_scaleFactor); + -columnScaleFactor); } - modelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, - gridLineWidth)); - itModelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, - gridLineWidth)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -1172,10 +1163,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -1191,29 +1182,26 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } // Wall lines: side wall + gridLineScaler = QVector3D(gridLineWidth, gridLineWidth, columnScaleFactor); for (GLfloat lineHeight = startLine; lineHeight <= m_heightNormalizer; lineHeight += heightStep) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; if (m_xFlipped) { - modelMatrix.translate(m_rowWidth / m_scaleFactor, + modelMatrix.translate(rowScaleFactor, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, 0.0f); } else { - modelMatrix.translate(-m_rowWidth / m_scaleFactor, + modelMatrix.translate(-rowScaleFactor, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, 0.0f); } - modelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - m_columnDepth / m_scaleFactor)); - itModelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - m_columnDepth / m_scaleFactor)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -1224,10 +1212,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -1255,31 +1243,35 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Calculate the positions for row and column labels and store them + GLfloat labelYAdjustment = -m_yAdjustment + 0.005f; + GLfloat scaledRowWidth = rowScaleFactor; + GLfloat scaledColumnDepth = columnScaleFactor; + GLfloat colPosValue = scaledRowWidth + labelMargin; + GLfloat rowPosValue = scaledColumnDepth + labelMargin; + QVector3D positionComp(0.0f, m_yAdjustment, 0.0f); + QVector3D labelRotation(-90.0f, 0.0f, 0.0f); + if (m_zFlipped) + labelRotation.setY(180.0f); + if (m_yFlipped) { + if (m_zFlipped) + labelRotation.setY(0.0f); + else + labelRotation.setY(180.0f); + labelRotation.setZ(180.0f); + } + Qt::AlignmentFlag alignment = m_xFlipped ? Qt::AlignLeft : Qt::AlignRight; for (int row = 0; row != m_cachedRowCount; row++) { if (m_axisCacheX.labelItems().size() > row) { // Go through all rows and get position of max+1 or min-1 column, depending on x flip // We need only positions for them, labels have already been generated at QDataSetPrivate. Just add LabelItems rowPos = (row + 0.5f) * m_cachedBarSpacing.height(); - colPos = (m_rowWidth / m_scaleFactor) + labelMargin; - GLfloat rotLabelX = -90.0f; - GLfloat rotLabelY = 0.0f; - GLfloat rotLabelZ = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignRight; - if (m_zFlipped) - rotLabelY = 180.0f; - if (m_xFlipped) { - colPos = -(m_rowWidth / m_scaleFactor) - labelMargin; - alignment = Qt::AlignLeft; - } - if (m_yFlipped) { - if (m_zFlipped) - rotLabelY = 0.0f; - else - rotLabelY = 180.0f; - rotLabelZ = 180.0f; - } + if (m_xFlipped) + colPos = -colPosValue; + else + colPos = colPosValue; + QVector3D labelPos = QVector3D(colPos, - -m_yAdjustment + 0.005f, // raise a bit over background to avoid depth "glimmering" + labelYAdjustment, // raise a bit over background to avoid depth "glimmering" (m_columnDepth - rowPos) / m_scaleFactor); m_dummyBarRenderItem.setTranslation(labelPos); @@ -1287,48 +1279,43 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) //qDebug() << "labelPos, row" << row + 1 << ":" << labelPos << m_axisCacheX.labels().at(row); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), + positionComp, labelRotation, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, true, Drawer::LabelMid, alignment); } } + labelRotation = QVector3D(-90.0f, 90.0f, 0.0f); + if (m_xFlipped) + labelRotation.setY(-90.0f); + if (m_yFlipped) { + if (m_xFlipped) + labelRotation.setY(90.0f); + else + labelRotation.setY(-90.0f); + labelRotation.setZ(180.0f); + } + + alignment = m_zFlipped ? Qt::AlignRight : Qt::AlignLeft; for (int column = 0; column != m_cachedColumnCount; column += 1) { if (m_axisCacheZ.labelItems().size() > column) { // Go through all columns and get position of max+1 or min-1 row, depending on z flip // We need only positions for them, labels have already been generated at QDataSetPrivate. Just add LabelItems colPos = (column + 0.5f) * m_cachedBarSpacing.width(); - rowPos = (m_columnDepth / m_scaleFactor) + labelMargin; - GLfloat rotLabelX = -90.0f; - GLfloat rotLabelY = 90.0f; - GLfloat rotLabelZ = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignLeft; - if (m_xFlipped) - rotLabelY = -90.0f; - if (m_zFlipped) { - rowPos = -(m_columnDepth / m_scaleFactor) - labelMargin; - alignment = Qt::AlignRight; - } - if (m_yFlipped) { - if (m_xFlipped) - rotLabelY = -90.0f; - else - rotLabelY = 90.0f; - rotLabelZ = 180.0f; - } + if (m_zFlipped) + rowPos = -rowPosValue; + else + rowPos = rowPosValue; + QVector3D labelPos = QVector3D((colPos - m_rowWidth) / m_scaleFactor, - -m_yAdjustment + 0.005f, // raise a bit over background to avoid depth "glimmering" + labelYAdjustment, // raise a bit over background to avoid depth "glimmering" rowPos); m_dummyBarRenderItem.setTranslation(labelPos); const LabelItem &axisLabelItem = *m_axisCacheZ.labelItems().at(column); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), + positionComp, labelRotation, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, true, Drawer::LabelMid, alignment); } } @@ -1341,64 +1328,51 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) if (m_hasNegativeValues) startLine = -m_heightNormalizer; GLfloat labelPos = startLine; + GLfloat labelMarginXTrans = labelMargin; + GLfloat labelMarginZTrans = labelMargin; + GLfloat labelXTrans = rowScaleFactor; + GLfloat labelZTrans = columnScaleFactor; + QVector3D backLabelRotation(0.0f, -90.0f, 0.0f); + QVector3D sideLabelRotation(0.0f, 0.0f, 0.0f); + Qt::AlignmentFlag backAlignment = Qt::AlignLeft; + Qt::AlignmentFlag sideAlignment = Qt::AlignLeft; + if (!m_xFlipped) { + labelXTrans = -labelXTrans; + labelMarginXTrans = -labelMargin; + backLabelRotation.setY(90.0f); + sideAlignment = Qt::AlignRight; + } + if (m_zFlipped) { + labelZTrans = -labelZTrans; + labelMarginZTrans = -labelMargin; + backAlignment = Qt::AlignRight; + sideLabelRotation.setY(180.f); + } + QVector3D backLabelTrans = QVector3D(labelXTrans, 0.0f, + labelZTrans + labelMarginZTrans); + QVector3D sideLabelTrans = QVector3D(-labelXTrans - labelMarginXTrans, + 0.0f, -labelZTrans); for (int i = 0; i < labelCount; i++) { if (m_axisCacheY.labelItems().size() > labelNbr) { - GLfloat labelMarginXTrans = labelMargin; - GLfloat labelMarginZTrans = labelMargin; - GLfloat labelXTrans = m_rowWidth / m_scaleFactor; - GLfloat labelZTrans = m_columnDepth / m_scaleFactor; - GLfloat labelYTrans = 2.0f * labelPos / m_heightNormalizer - m_yAdjustment; - GLfloat rotLabelX = 0.0f; - GLfloat rotLabelY = -90.0f; - GLfloat rotLabelZ = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignLeft; - if (!m_xFlipped) { - labelXTrans = -labelXTrans; - labelMarginXTrans = -labelMargin; - rotLabelY = 90.0f; - } - if (m_zFlipped) { - labelZTrans = -labelZTrans; - labelMarginZTrans = -labelMargin; - alignment = Qt::AlignRight; - } + backLabelTrans.setY(2.0f * labelPos / m_heightNormalizer - m_yAdjustment); + sideLabelTrans.setY(backLabelTrans.y()); const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr); // Back wall - QVector3D labelTrans = QVector3D(labelXTrans, labelYTrans, - labelZTrans + labelMarginZTrans); - - //qDebug() << "labelPos, value:" << labelTrans; - - m_dummyBarRenderItem.setTranslation(labelTrans); + m_dummyBarRenderItem.setTranslation(backLabelTrans); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), - true, true, Drawer::LabelMid, alignment); + positionComp, backLabelRotation, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, + true, true, Drawer::LabelMid, backAlignment); // Side wall - if (m_xFlipped) - alignment = Qt::AlignLeft; - else - alignment = Qt::AlignRight; - if (m_zFlipped) - rotLabelY = 180.0f; - else - rotLabelY = 0.0f; - - labelTrans = QVector3D(-labelXTrans - labelMarginXTrans, labelYTrans, -labelZTrans); - - m_dummyBarRenderItem.setTranslation(labelTrans); + m_dummyBarRenderItem.setTranslation(sideLabelTrans); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), - true, true, Drawer::LabelMid, alignment); + positionComp, sideLabelRotation, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, + true, true, Drawer::LabelMid, sideAlignment); } labelNbr++; labelPos += heightStep; @@ -1475,10 +1449,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } m_drawer->drawLabel(*selectedBar, labelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), selectedBar->height(), + positionComp, zeroVector, selectedBar->height(), m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), true, false); + m_labelObj, activeCamera, true, false); // Reset label update flag; they should have been updated when we get here m_updateLabels = false; diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index 1da5dd99..3090433c 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -182,9 +182,8 @@ void Scatter3DRenderer::updateScene(Q3DScene *scene) if (m_hasHeightAdjustmentChanged) { // Set initial m_cachedScene->activeCamera() position. Also update if height adjustment has changed. - scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + scene->activeCamera()->setBaseOrientation(cameraDistanceVector, + zeroVector, upVector); m_hasHeightAdjustmentChanged = false; } @@ -208,17 +207,21 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) { GLfloat backgroundRotation = 0; + const Q3DCamera *activeCamera = m_cachedScene->activeCamera(); + // Specify viewport glViewport(m_mainViewPort.x(), m_mainViewPort.y(), m_mainViewPort.width(), m_mainViewPort.height()); // Set up projection matrix QMatrix4x4 projectionMatrix; - projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width() - / (GLfloat)m_mainViewPort.height(), 0.1f, 100.0f); + GLfloat viewPortRatio = (GLfloat)m_mainViewPort.width() / (GLfloat)m_mainViewPort.height(); + projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f); // Calculate view matrix - QMatrix4x4 viewMatrix = m_cachedScene->activeCamera()->viewMatrix(); + QMatrix4x4 viewMatrix = activeCamera->viewMatrix(); + + QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix; // Calculate label flipping if (viewMatrix.row(0).x() > 0) @@ -257,10 +260,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) GLfloat heightScaler = 0.0f; GLfloat widthScaler = 0.0f; GLfloat depthScaler = 0.0f; - + QVector3D modelScaler(widthMultiplier + widthScaler, + heightMultiplier + heightScaler, + depthMultiplier + depthScaler); // Introduce regardless of shadow quality to simplify logic QMatrix4x4 depthViewMatrix; QMatrix4x4 depthProjectionMatrix; + QMatrix4x4 depthProjectionViewMatrix; #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { @@ -282,28 +288,28 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Get the depth view matrix // It may be possible to hack lightPos here if we want to make some tweaks to shadow - QVector3D depthLightPos = m_cachedScene->activeCamera()->calculatePositionRelativeToCamera( - QVector3D(0.0f, 0.0f, 0.0f), 0.0f, 2.5f / m_autoScaleAdjustment); - depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + QVector3D depthLightPos = activeCamera->calculatePositionRelativeToCamera( + zeroVector, 0.0f, 2.5f / m_autoScaleAdjustment); + depthViewMatrix.lookAt(depthLightPos, zeroVector, upVector); // TODO: Why does depthViewMatrix.column(3).y() goes to zero when we're directly above? // That causes the scene to be not drawn from above -> must be fixed // qDebug() << lightPos << depthViewMatrix << depthViewMatrix.column(3); // Set the depth projection matrix #ifndef USE_WIDER_SHADOWS // Use this for perspective shadows - depthProjectionMatrix.perspective(15.0f, (GLfloat)m_mainViewPort.width() - / (GLfloat)m_mainViewPort.height(), 3.0f, 100.0f); + depthProjectionMatrix.perspective(15.0f, viewPortRatio, 3.0f, 100.0f); #else // Use these for orthographic shadows //depthProjectionMatrix.ortho(-aspectRatio * 2.0f, aspectRatio * 2.0f, // -m_heightNormalizer * 2.0f, m_heightNormalizer * 2.0f, // 0.0f, 100.0f); - GLfloat testAspectRatio = (GLfloat)m_mainViewPort.width() / (GLfloat)m_mainViewPort.height(); + GLfloat testAspectRatio = viewPortRatio; depthProjectionMatrix.ortho(-testAspectRatio * 2.0f, testAspectRatio * 2.0f, -m_heightNormalizer * 2.0f, m_heightNormalizer * 2.0f, 0.0f, 100.0f); #endif + depthProjectionViewMatrix = depthProjectionMatrix * depthViewMatrix; + // Draw dots to depth buffer for (int dot = 0; dot < m_renderItemArray.size(); dot++) { const ScatterRenderItem &item = m_renderItemArray.at(dot); @@ -313,17 +319,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - modelMatrix.translate(item.translation().x(), - item.translation().y(), - item.translation().z()); - modelMatrix.scale(QVector3D(widthMultiplier + widthScaler, - heightMultiplier + heightScaler, - depthMultiplier + depthScaler)); + modelMatrix.translate(item.translation()); + modelMatrix.scale(modelScaler); //modelMatrix.scale(QVector3D(widthMultiplier * item.size() + widthScaler, // heightMultiplier * item.size() + heightScaler, // depthMultiplier * item.size() + depthScaler)); - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = depthProjectionViewMatrix * modelMatrix; m_depthShader->setUniformValue(m_depthShader->MVP(), MVPMatrix); @@ -364,13 +366,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); - QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), zeroVector, upVector); + QMatrix4x4 MVPMatrix = projectionViewMatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); - m_drawer->drawObject(m_labelShader, m_labelObj, - m_depthTexture); + m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); glDisable(GL_TEXTURE_2D); m_labelShader->release(); #endif @@ -401,17 +400,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - modelMatrix.translate(item.translation().x(), - item.translation().y(), - item.translation().z()); - modelMatrix.scale(QVector3D(widthMultiplier + widthScaler, - heightMultiplier + heightScaler, - depthMultiplier + depthScaler)); + modelMatrix.translate(item.translation()); + modelMatrix.scale(modelScaler); //modelMatrix.scale(QVector3D(widthMultiplier * item.size() + widthScaler, // heightMultiplier * item.size() + heightScaler, // depthMultiplier * item.size() + depthScaler)); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; QVector3D dotColor = indexToSelectionColor(dot); dotColor /= 255.0f; @@ -455,13 +450,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); - QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f), zeroVector, upVector); + QMatrix4x4 MVPMatrix = projectionViewMatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); - m_drawer->drawObject(m_labelShader, m_labelObj, - m_selectionTexture); + m_drawer->drawObject(m_labelShader, m_labelObj, m_selectionTexture); glDisable(GL_TEXTURE_2D); m_labelShader->release(); #endif @@ -496,6 +488,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) ScatterRenderItem *selectedItem(0); + QVector3D baseColor = Utils::vectorFromColor(m_cachedTheme.m_baseColor); + for (int dot = 0; dot < m_renderItemArray.size(); dot++) { ScatterRenderItem &item = m_renderItemArray[dot]; if (!item.isVisible()) @@ -503,40 +497,31 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(item.translation().x(), - item.translation().y(), - item.translation().z()); - modelMatrix.scale(QVector3D(widthMultiplier + widthScaler, - heightMultiplier + heightScaler, - depthMultiplier + depthScaler)); + modelMatrix.translate(item.translation()); + modelMatrix.scale(modelScaler); //modelMatrix.scale(QVector3D(widthMultiplier * item.size() + widthScaler, // heightMultiplier * item.size() + heightScaler, // depthMultiplier * item.size() + depthScaler)); - itModelMatrix.scale(QVector3D(widthMultiplier + widthScaler, - heightMultiplier + heightScaler, - depthMultiplier + depthScaler)); + itModelMatrix.scale(modelScaler); //itModelMatrix.scale(QVector3D(widthMultiplier * item.size() + widthScaler, // heightMultiplier * item.size() + heightScaler, // depthMultiplier * item.size() + depthScaler)); #ifdef SHOW_DEPTH_TEXTURE_SCENE - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = depthProjectionViewMatrix * modelMatrix; #else - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; #endif - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; #if 0 - QVector3D baseColor = Utils::vectorFromColor(m_cachedTheme.m_baseColor); QVector3D heightColor = Utils::vectorFromColor(m_cachedTheme.m_heightColor) * item.translation().y(); QVector3D dotColor = baseColor + heightColor; #else - QVector3D dotColor = Utils::vectorFromColor(m_cachedTheme.m_baseColor); + QVector3D dotColor = baseColor; #endif GLfloat lightStrength = m_cachedTheme.m_lightStrength; @@ -558,6 +543,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; m_dotShader->setUniformValue(m_dotShader->shadowQ(), m_shadowQualityToShader); m_dotShader->setUniformValue(m_dotShader->depth(), depthMVPMatrix); m_dotShader->setUniformValue(m_dotShader->lightS(), lightStrength / 10.0f); @@ -583,11 +569,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glCullFace(GL_BACK); + GLfloat adjustedLightStrength = m_cachedTheme.m_lightStrength / 10.0f; + // Draw background if (m_cachedIsBackgroundEnabled && m_backgroundObj) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z @@ -610,12 +597,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) itModelMatrix = modelMatrix; // Only scaling and rotations, can be used directly #ifdef SHOW_DEPTH_TEXTURE_SCENE - MVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = depthProjectionViewMatrix * modelMatrix; #else - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; #endif - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; - QVector3D backgroundColor = Utils::vectorFromColor(m_cachedTheme.m_backgroundColor); // Set shader bindings @@ -632,11 +617,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; m_backgroundShader->setUniformValue(m_backgroundShader->shadowQ(), m_shadowQualityToShader); m_backgroundShader->setUniformValue(m_backgroundShader->depth(), depthMVPMatrix); m_backgroundShader->setUniformValue(m_backgroundShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + adjustedLightStrength); // Draw the object m_drawer->drawObject(m_backgroundShader, m_backgroundObj, 0, m_depthTexture); @@ -692,6 +678,15 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) int lastSegment = axisCacheMax->subSegmentCount() * axisCacheMax->segmentCount(); #endif +#ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z + QVector3D gridLineScaler( + (aspectRatio * backgroundMargin * m_areaSize.width()) / m_scaleFactor, + gridLineWidth, gridLineWidth); +#else // ..and this if we want uniform scaling based on largest dimension + QVector3D gridLineScaler((aspectRatio * backgroundMargin), + gridLineWidth, gridLineWidth); +#endif + for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; @@ -702,21 +697,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) modelMatrix.translate(0.0f, backgroundMargin, linePos / m_scaleFactor); else modelMatrix.translate(0.0f, -backgroundMargin, linePos / m_scaleFactor); -#ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z - modelMatrix.scale( - QVector3D( - (aspectRatio * backgroundMargin * m_areaSize.width()) / m_scaleFactor, - gridLineWidth, gridLineWidth)); - itModelMatrix.scale( - QVector3D( - (aspectRatio * backgroundMargin * m_areaSize.width()) / m_scaleFactor, - gridLineWidth, gridLineWidth)); -#else // ..and this if we want uniform scaling based on largest dimension - modelMatrix.scale(QVector3D((aspectRatio * backgroundMargin), - gridLineWidth, gridLineWidth)); - itModelMatrix.scale(QVector3D(aspectRatio * backgroundMargin, - gridLineWidth, gridLineWidth)); -#endif + + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); // If we're viewing from below, grid line object must be flipped if (m_yFlipped) { @@ -724,8 +707,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); } - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; + depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -738,8 +721,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Set shadow shader bindings lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -757,6 +739,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } // Side wall lines + gridLineScaler = QVector3D(gridLineWidth, backgroundMargin, gridLineWidth); #ifndef USE_UNIFORM_SCALING GLfloat lineXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) / m_scaleFactor; @@ -771,15 +754,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; modelMatrix.translate(lineXTrans, 0.0f, linePos / m_scaleFactor); - modelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); - itModelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -790,10 +771,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -818,37 +799,28 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) GLfloat lineStep = aspectRatio * m_axisCacheX.subSegmentStep(); GLfloat linePos = aspectRatio * m_axisCacheX.min(); int lastSegment = m_axisCacheX.subSegmentCount() * m_axisCacheX.segmentCount(); + QVector3D gridLineScaler( + gridLineWidth, gridLineWidth, + (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor); #else GLfloat lineStep = aspectRatio * axisCacheMax->subSegmentStep(); GLfloat linePos = -aspectRatio * m_scaleFactor; int lastSegment = axisCacheMax->subSegmentCount() * axisCacheMax->segmentCount(); + QVector3D gridLineScaler(gridLineWidth, gridLineWidth, + aspectRatio * backgroundMargin); #endif for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; if (m_yFlipped) modelMatrix.translate(linePos / m_scaleFactor, backgroundMargin, 0.0f); else modelMatrix.translate(linePos / m_scaleFactor, -backgroundMargin, 0.0f); -#ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z - modelMatrix.scale( - QVector3D( - gridLineWidth, gridLineWidth, - (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor)); - itModelMatrix.scale( - QVector3D( - gridLineWidth, gridLineWidth, - (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor)); -#else // ..and this if we want uniform scaling based on largest dimension - modelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - aspectRatio * backgroundMargin)); - itModelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - aspectRatio * backgroundMargin)); -#endif + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); // If we're viewing from below, grid line object must be flipped if (m_yFlipped) { @@ -856,8 +828,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); } - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -868,10 +839,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -899,18 +870,18 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) if (!m_zFlipped) lineZTrans = -lineZTrans; + gridLineScaler = QVector3D(gridLineWidth, backgroundMargin, gridLineWidth); + for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; modelMatrix.translate(linePos / m_scaleFactor, 0.0f, lineZTrans); - modelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); - itModelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -921,10 +892,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -952,8 +923,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z GLfloat lineZTrans = (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor; + QVector3D gridLineScaler( + (aspectRatio * backgroundMargin * m_areaSize.width() / m_scaleFactor), + gridLineWidth, gridLineWidth); #else // ..and this if we want uniform scaling based on largest dimension GLfloat lineZTrans = aspectRatio * backgroundMargin; + QVector3D gridLineScaler((aspectRatio * backgroundMargin), + gridLineWidth, gridLineWidth); #endif if (!m_zFlipped) lineZTrans = -lineZTrans; @@ -961,28 +937,14 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; modelMatrix.translate(0.0f, linePos / m_heightNormalizer, lineZTrans); -#ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z - modelMatrix.scale( - QVector3D( - (aspectRatio * backgroundMargin * m_areaSize.width() / m_scaleFactor), - gridLineWidth, gridLineWidth)); - itModelMatrix.scale( - QVector3D( - (aspectRatio * backgroundMargin * m_areaSize.width() / m_scaleFactor), - gridLineWidth, gridLineWidth)); -#else // ..and this if we want uniform scaling based on largest dimension - modelMatrix.scale(QVector3D((aspectRatio * backgroundMargin), - gridLineWidth, gridLineWidth)); - itModelMatrix.scale(QVector3D(aspectRatio * backgroundMargin, - gridLineWidth, gridLineWidth)); -#endif - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); + + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -993,10 +955,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -1018,8 +980,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z GLfloat lineXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) / m_scaleFactor; + gridLineScaler = QVector3D( + gridLineWidth, gridLineWidth, + (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor); #else // ..and this if we want uniform scaling based on largest dimension GLfloat lineXTrans = aspectRatio * backgroundMargin; + gridLineScaler = QVector3D(gridLineWidth, gridLineWidth, + aspectRatio * backgroundMargin); #endif if (!m_xFlipped) lineXTrans = -lineXTrans; @@ -1027,29 +994,14 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; - QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; modelMatrix.translate(lineXTrans, linePos / m_heightNormalizer, 0.0f); -#ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z - modelMatrix.scale( - QVector3D( - gridLineWidth, gridLineWidth, - (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor)); - itModelMatrix.scale( - QVector3D( - gridLineWidth, gridLineWidth, - (aspectRatio * backgroundMargin * m_areaSize.height()) / m_scaleFactor)); -#else // ..and this if we want uniform scaling based on largest dimension - modelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - (aspectRatio * backgroundMargin))); - itModelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, - aspectRatio * backgroundMargin)); + modelMatrix.scale(gridLineScaler); + itModelMatrix.scale(gridLineScaler); -#endif - MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; - depthMVPMatrix = depthProjectionMatrix * depthViewMatrix * modelMatrix; + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings lineShader->setUniformValue(lineShader->model(), modelMatrix); @@ -1060,10 +1012,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #if !defined(QT_OPENGL_ES_2) if (m_cachedShadowQuality > QDataVis::ShadowQualityNone) { // Set shadow shader bindings + QMatrix4x4 depthMVPMatrix = depthProjectionViewMatrix * modelMatrix; lineShader->setUniformValue(lineShader->shadowQ(), m_shadowQualityToShader); lineShader->setUniformValue(lineShader->depth(), depthMVPMatrix); - lineShader->setUniformValue(lineShader->lightS(), - m_cachedTheme.m_lightStrength / 10.0f); + lineShader->setUniformValue(lineShader->lightS(), adjustedLightStrength); // Draw the object m_drawer->drawObject(lineShader, m_gridLineObj, 0, m_depthTexture); @@ -1101,41 +1053,40 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) GLfloat posStep = aspectRatio * m_axisCacheZ.segmentStep(); GLfloat labelPos = -aspectRatio * m_axisCacheZ.min(); int lastSegment = m_axisCacheZ.segmentCount(); + GLfloat labelXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) + / m_scaleFactor + labelMargin; #else GLfloat posStep = aspectRatio * axisCacheMax->segmentStep(); GLfloat labelPos = aspectRatio * m_scaleFactor; int lastSegment = axisCacheMax->segmentCount(); + GLfloat labelXTrans = aspectRatio * backgroundMargin + labelMargin; #endif int labelNbr = 0; + GLfloat labelYTrans = -backgroundMargin; + GLfloat rotLabelX = -90.0f; + GLfloat rotLabelY = 0.0f; + GLfloat rotLabelZ = 0.0f; + Qt::AlignmentFlag alignment = Qt::AlignRight; + if (m_zFlipped) + rotLabelY = 180.0f; + if (m_xFlipped) { + labelXTrans = -labelXTrans; + alignment = Qt::AlignLeft; + } + if (m_yFlipped) { + rotLabelZ += 180.0f; + rotLabelY += 180.0f; + labelYTrans = -labelYTrans; + } + QVector3D labelRotateVector(rotLabelX, rotLabelY, rotLabelZ); + QVector3D labelTrans = QVector3D(labelXTrans, labelYTrans, 0.0f); for (int segment = 0; segment <= lastSegment; segment++) { #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z if (m_axisCacheZ.labelItems().size() > labelNbr) { - GLfloat labelXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) - / m_scaleFactor + labelMargin; #else // ..and this if we want uniform scaling based on largest dimension if (axisCacheMax->labelItems().size() > labelNbr) { - GLfloat labelXTrans = aspectRatio * backgroundMargin + labelMargin; #endif - GLfloat labelYTrans = -backgroundMargin; - GLfloat rotLabelX = -90.0f; - GLfloat rotLabelY = 0.0f; - GLfloat rotLabelZ = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignRight; - if (m_zFlipped) - rotLabelY = 180.0f; - if (m_xFlipped) { - labelXTrans = -labelXTrans; - alignment = Qt::AlignLeft; - } - if (m_yFlipped) { - rotLabelZ += 180.0f; - rotLabelY += 180.0f; - labelYTrans = -labelYTrans; - } - QVector3D labelTrans = QVector3D(labelXTrans, - labelYTrans, - labelPos / m_scaleFactor); - + labelTrans.setZ(labelPos / m_scaleFactor); // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); @@ -1146,11 +1097,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), true, true, Drawer::LabelMid, - alignment); + zeroVector, labelRotateVector, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, true, + Drawer::LabelMid, alignment); } labelNbr++; labelPos -= posStep; @@ -1162,40 +1111,40 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) GLfloat posStep = aspectRatio * m_axisCacheX.segmentStep(); GLfloat labelPos = aspectRatio * m_axisCacheX.min(); int lastSegment = m_axisCacheX.segmentCount(); + GLfloat labelZTrans = (aspectRatio * backgroundMargin * m_areaSize.height()) + / m_scaleFactor + labelMargin; #else GLfloat posStep = aspectRatio * axisCacheMax->segmentStep(); GLfloat labelPos = -aspectRatio * m_scaleFactor; int lastSegment = axisCacheMax->segmentCount(); + GLfloat labelZTrans = aspectRatio * backgroundMargin + labelMargin; #endif int labelNbr = 0; + GLfloat labelYTrans = -backgroundMargin; + GLfloat rotLabelX = -90.0f; + GLfloat rotLabelY = 90.0f; + GLfloat rotLabelZ = 0.0f; + Qt::AlignmentFlag alignment = Qt::AlignLeft; + if (m_xFlipped) + rotLabelY = -90.0f; + if (m_zFlipped) { + labelZTrans = -labelZTrans; + alignment = Qt::AlignRight; + } + if (m_yFlipped) { + rotLabelZ += 180.0f; + rotLabelY += 180.0f; + labelYTrans = -labelYTrans; + } + QVector3D labelRotateVector(rotLabelX, rotLabelY, rotLabelZ); + QVector3D labelTrans = QVector3D(0.0f, labelYTrans, labelZTrans); for (int segment = 0; segment <= lastSegment; segment++) { #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z if (m_axisCacheX.labelItems().size() > labelNbr) { - GLfloat labelZTrans = (aspectRatio * backgroundMargin * m_areaSize.height()) - / m_scaleFactor + labelMargin; #else // ..and this if we want uniform scaling based on largest dimension if (axisCacheMax->labelItems().size() > labelNbr) { - GLfloat labelZTrans = aspectRatio * backgroundMargin + labelMargin; #endif - GLfloat labelYTrans = -backgroundMargin; - GLfloat rotLabelX = -90.0f; - GLfloat rotLabelY = 90.0f; - GLfloat rotLabelZ = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignLeft; - if (m_xFlipped) - rotLabelY = -90.0f; - if (m_zFlipped) { - labelZTrans = -labelZTrans; - alignment = Qt::AlignRight; - } - if (m_yFlipped) { - rotLabelZ += 180.0f; - rotLabelY += 180.0f; - labelYTrans = -labelYTrans; - } - QVector3D labelTrans = QVector3D(labelPos / m_scaleFactor, - labelYTrans, - labelZTrans); + labelTrans.setX(labelPos / m_scaleFactor); // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); @@ -1206,11 +1155,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), true, true, Drawer::LabelMid, - alignment); + zeroVector, labelRotateVector, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, true, + Drawer::LabelMid, alignment); } labelNbr++; labelPos += posStep; @@ -1221,71 +1168,69 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) GLfloat posStep = m_axisCacheY.segmentStep(); GLfloat labelPos = m_axisCacheY.min(); int labelNbr = 0; - for (int segment = 0; segment <= m_axisCacheY.segmentCount(); segment++) { - if (m_axisCacheY.labelItems().size() > labelNbr) { #ifndef USE_UNIFORM_SCALING // Use this if we want to use autoscaling for x and z - GLfloat labelXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) - / m_scaleFactor; - GLfloat labelZTrans = (aspectRatio * backgroundMargin * m_areaSize.height()) - / m_scaleFactor; + GLfloat labelXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) + / m_scaleFactor; + GLfloat labelZTrans = (aspectRatio * backgroundMargin * m_areaSize.height()) + / m_scaleFactor; #else // ..and this if we want uniform scaling based on largest dimension - GLfloat labelXTrans = aspectRatio * backgroundMargin; - GLfloat labelZTrans = labelXTrans; + GLfloat labelXTrans = aspectRatio * backgroundMargin; + GLfloat labelZTrans = labelXTrans; #endif - GLfloat labelMarginXTrans = labelMargin; - GLfloat labelMarginZTrans = labelMargin; - GLfloat labelYTrans = labelPos / m_heightNormalizer; - GLfloat rotLabelX = 0.0f; - GLfloat rotLabelY = -90.0f; - GLfloat rotLabelZ = 0.0f; - Qt::AlignmentFlag alignment = Qt::AlignLeft; - if (!m_xFlipped) { - labelXTrans = -labelXTrans; - labelMarginXTrans = -labelMargin; - rotLabelY = 90.0f; - } - if (m_zFlipped) { - labelZTrans = -labelZTrans; - labelMarginZTrans = -labelMargin; - alignment = Qt::AlignRight; - } + // Back wall init + GLfloat labelMarginXTrans = labelMargin; + GLfloat labelMarginZTrans = labelMargin; + GLfloat rotLabelX = 0.0f; + GLfloat rotLabelY = -90.0f; + GLfloat rotLabelZ = 0.0f; + Qt::AlignmentFlag alignmentBack = Qt::AlignLeft; + if (!m_xFlipped) { + labelXTrans = -labelXTrans; + labelMarginXTrans = -labelMargin; + rotLabelY = 90.0f; + } + if (m_zFlipped) { + labelZTrans = -labelZTrans; + labelMarginZTrans = -labelMargin; + alignmentBack = Qt::AlignRight; + } + QVector3D labelRotateVectorBack(rotLabelX, rotLabelY, rotLabelZ); + QVector3D labelTransBack = QVector3D(labelXTrans, 0.0f, labelZTrans + labelMarginZTrans); + + // Side wall init + Qt::AlignmentFlag alignmentSide = Qt::AlignLeft; + if (m_xFlipped) + alignmentSide = Qt::AlignLeft; + else + alignmentSide = Qt::AlignRight; + if (m_zFlipped) + rotLabelY = 180.0f; + else + rotLabelY = 0.0f; + + QVector3D labelRotateVectorSide(rotLabelX, rotLabelY, rotLabelZ); + QVector3D labelTransSide(-labelXTrans - labelMarginXTrans, 0.0f, -labelZTrans); + for (int segment = 0; segment <= m_axisCacheY.segmentCount(); segment++) { + if (m_axisCacheY.labelItems().size() > labelNbr) { const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr); + const GLfloat labelYTrans = labelPos / m_heightNormalizer; // Back wall - QVector3D labelTrans = QVector3D(labelXTrans, labelYTrans, - labelZTrans + labelMarginZTrans); - - // Draw the label here - m_dummyRenderItem.setTranslation(labelTrans); + labelTransBack.setY(labelYTrans); + m_dummyRenderItem.setTranslation(labelTransBack); m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), true, true, Drawer::LabelMid, - alignment); + zeroVector, labelRotateVectorBack, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, true, + Drawer::LabelMid, alignmentBack); // Side wall - if (m_xFlipped) - alignment = Qt::AlignLeft; - else - alignment = Qt::AlignRight; - if (m_zFlipped) - rotLabelY = 180.0f; - else - rotLabelY = 0.0f; - - labelTrans = QVector3D(-labelXTrans - labelMarginXTrans, labelYTrans, - -labelZTrans); - - // Draw the label here - m_dummyRenderItem.setTranslation(labelTrans); + labelTransSide.setY(labelYTrans); + m_dummyRenderItem.setTranslation(labelTransSide); m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(rotLabelX, rotLabelY, rotLabelZ), - 0, m_cachedSelectionMode, - m_labelShader, m_labelObj, m_cachedScene->activeCamera(), true, true, Drawer::LabelMid, - alignment); + zeroVector, labelRotateVectorSide, 0, m_cachedSelectionMode, + m_labelShader, m_labelObj, activeCamera, true, true, + Drawer::LabelMid, alignmentSide); } labelNbr++; labelPos += posStep; @@ -1349,11 +1294,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } m_drawer->drawLabel(*selectedItem, labelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 0.0f, 0.0f), 0, - m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), true, false, - Drawer::LabelMid); + zeroVector, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, true, false, Drawer::LabelMid); // Reset label update flag; they should have been updated when we get here m_updateLabels = false; diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp index b2c776f9..d665b948 100644 --- a/src/datavisualization/engine/selectionpointer.cpp +++ b/src/datavisualization/engine/selectionpointer.cpp @@ -105,9 +105,7 @@ void SelectionPointer::render(GLuint defaultFboHandle) QMatrix4x4 projectionMatrix; if (m_cachedIsSlicingActivated) { GLfloat aspect = (GLfloat)m_mainViewPort.width() / (GLfloat)m_mainViewPort.height(); - viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 1.0f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 1.0f), zeroVector, upVector); projectionMatrix.ortho(-sliceUnits * aspect, sliceUnits * aspect, -sliceUnits, sliceUnits, -1.0f, 4.0f); } else { @@ -124,7 +122,7 @@ void SelectionPointer::render(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; // Position the pointer ball - modelMatrix.translate(m_position + QVector3D(0.0f, 0.0f, 0.0f)); + modelMatrix.translate(m_position + zeroVector); // Scale the point with fixed values (at this point) modelMatrix.scale(QVector3D(0.05f, 0.05f, 0.05f)); @@ -161,7 +159,7 @@ void SelectionPointer::render(GLuint defaultFboHandle) // Position label QVector3D labelAlign(0.0f, 1.0f * scaledFontSize + 0.05f, 0.0f); - modelMatrixLabel.translate(m_position + labelAlign + QVector3D(0.0f, 0.0f, 0.0f)); + modelMatrixLabel.translate(m_position + labelAlign + zeroVector); // Position the label towards the camera qreal camRotationsX = camera->xRotation(); diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 67ad66d4..3bb8cee0 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -422,9 +422,8 @@ void Surface3DRenderer::updateScene(Q3DScene *scene) // Set initial camera position // X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later if (m_hasHeightAdjustmentChanged) { - scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + scene->activeCamera()->setBaseOrientation(cameraDistanceVector, + zeroVector, upVector); // For now this is used just to make things once. Proper use will come m_hasHeightAdjustmentChanged = false; } @@ -484,8 +483,8 @@ void Surface3DRenderer::drawSlicedScene() // Set view matrix QMatrix4x4 viewMatrix; viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 1.0f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + zeroVector, + upVector); // Set light position lightPos = m_cachedScene->activeLight()->position(); @@ -781,7 +780,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 depthProjectionMatrix; QMatrix4x4 depthProjectionViewMatrix; - QVector3D surfaceScaler(m_surfaceScaleX, 1.0f, m_surfaceScaleZ); QVector3D surfaceOffset(m_surfaceOffsetX, 0.0f, m_surfaceOffsetZ); @@ -805,9 +803,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Get the depth view matrix // It may be possible to hack lightPos here if we want to make some tweaks to shadow QVector3D depthLightPos = m_cachedScene->activeCamera()->calculatePositionRelativeToCamera( - QVector3D(0.0f, 0.0f, 0.0f), 0.0f, 3.5f / m_autoScaleAdjustment); - depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + zeroVector, 0.0f, 3.5f / m_autoScaleAdjustment); + depthViewMatrix.lookAt(depthLightPos, zeroVector, upVector); // TODO: Why does depthViewMatrix.column(3).y() goes to zero when we're directly above? // That causes the scene to be not drawn from above -> must be fixed @@ -876,9 +873,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), - QVector3D(0.0f, 0.0f, 0.0f), - QVector3D(0.0f, 1.0f, 0.0f)); + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), zeroVector, upVector); QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); |