From 298e5e4ab12d8542c42bf4ed9118ab3f579d8456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Mon, 21 Oct 2013 08:42:58 +0300 Subject: Removed zComp Task-number: QTRD-2488 Change-Id: I7d7b067a1d82a44aa349f553f0aff7c173969ea9 Change-Id: I7d7b067a1d82a44aa349f553f0aff7c173969ea9 Reviewed-by: Miikka Heikkinen --- src/datavisualization/engine/bars3drenderer.cpp | 98 +++++++++++----------- src/datavisualization/engine/q3dcamera.cpp | 3 +- src/datavisualization/engine/scatter3drenderer.cpp | 57 ++++++------- src/datavisualization/engine/selectionpointer.cpp | 10 +-- src/datavisualization/engine/surface3drenderer.cpp | 60 +++++++------ .../global/datavisualizationglobal_p.h | 4 +- 6 files changed, 114 insertions(+), 118 deletions(-) (limited to 'src/datavisualization') diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index 5944b3d7..a7dcb70f 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -219,8 +219,8 @@ 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 + zComp), - QVector3D(0.0f, -m_yAdjustment, zComp), + scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance), + QVector3D(0.0f, -m_yAdjustment, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); m_hasHeightAdjustmentChanged = false; } @@ -283,14 +283,14 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, QMatrix4x4 viewMatrix; // Adjust scaling (zoom rate based on aspect ratio) - GLfloat camZPosSliced = 5.0f / m_autoScaleAdjustment + zComp; + GLfloat camZPosSliced = 5.0f / m_autoScaleAdjustment; viewMatrix.lookAt(QVector3D(0.0f, 0.0f, camZPosSliced), - QVector3D(0.0f, 0.0f, zComp), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); // Set light position - lightPos = QVector3D(0.0f, -m_yAdjustment, zComp); + lightPos = QVector3D(0.0f, -m_yAdjustment, 0.0f); // Bind bar shader m_barShader->bind(); @@ -321,8 +321,8 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) barPosX = item->translation().x(); else - barPosX = -(item->translation().z() - zComp); // flip z; frontmost bar to the left - modelMatrix.translate(barPosX, barPosY, zComp); + 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)); @@ -379,35 +379,40 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) { if (m_sliceTitleItem) { m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, zComp), + 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); + m_labelObj, m_cachedScene->activeCamera(), + false, false, Drawer::LabelTop); } m_drawer->drawLabel(*dummyItem, zLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, zComp), + 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); + m_labelObj, m_cachedScene->activeCamera(), + false, false, Drawer::LabelBottom); } else { m_drawer->drawLabel(*dummyItem, xLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, zComp), + 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); + m_labelObj, m_cachedScene->activeCamera(), + false, false, Drawer::LabelBottom); if (m_sliceTitleItem) { m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, zComp), + 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); + m_labelObj, m_cachedScene->activeCamera(), + false, false, Drawer::LabelTop); } } m_drawer->drawLabel(*dummyItem, yLabel, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, zComp), + QVector3D(0.0f, m_autoScaleAdjustment, 0.0f), QVector3D(0.0f, 0.0f, 90.0f), 0, m_cachedSelectionMode, m_labelShader, - m_labelObj, m_cachedScene->activeCamera(), false, false, Drawer::LabelLeft); + m_labelObj, m_cachedScene->activeCamera(), + false, false, Drawer::LabelLeft); // Draw labels for bars for (int col = 0; col < stopBar; col++) { @@ -415,7 +420,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, // Draw values if (negativesComp == 1.0f) { m_drawer->drawLabel(*item, item->sliceLabelItem(), viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(0.0f, 0.0f, 90.0f), item->height(), m_cachedSelectionMode, m_labelShader, @@ -423,7 +428,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, Drawer::LabelOver, Qt::AlignTop); } else { m_drawer->drawLabel(*item, item->sliceLabelItem(), viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(0.0f, 0.0f, 0.0f), negativesComp * negativesComp * item->height(), m_cachedSelectionMode, m_labelShader, @@ -435,7 +440,7 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, const LabelItem *labelItem(0); labelItem = m_sliceCache->labelItems().at(col); m_drawer->drawLabel(*item, *labelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_autoScaleAdjustment, zComp), + 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, @@ -547,8 +552,8 @@ 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, zComp), 0.0f, 1.5f / m_autoScaleAdjustment); - depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, -m_yAdjustment, zComp), + QVector3D(0.0f, 0.0f, 0.0f), 0.0f, 3.5f / m_autoScaleAdjustment); + depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, -m_yAdjustment, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); // TODO: Why does depthViewMatrix.column(3).y() goes to zero when we're directly above? @@ -590,7 +595,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // shadows through the ground modelMatrix.translate((colPos - m_rowWidth) / m_scaleFactor, item.height() - m_yAdjustment + shadowOffset, - (m_columnDepth - rowPos) / m_scaleFactor + zComp); + (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)); @@ -632,10 +637,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f + zComp), - QVector3D(0.0f, 0.0f, zComp), + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, @@ -683,7 +687,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) modelMatrix.translate((colPos - m_rowWidth) / m_scaleFactor, item.height() - m_yAdjustment, - (m_columnDepth - rowPos) / m_scaleFactor + zComp); + (m_columnDepth - rowPos) / m_scaleFactor); modelMatrix.scale(QVector3D(m_scaleX, item.height(), m_scaleZ)); MVPMatrix = projectionMatrix * viewMatrix * modelMatrix; @@ -740,10 +744,9 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f + zComp), - QVector3D(0.0f, 0.0f, zComp), + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_selectionTexture); @@ -804,7 +807,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) modelMatrix.translate((colPos - m_rowWidth) / m_scaleFactor, item.height() - m_yAdjustment, - (m_columnDepth - rowPos) / m_scaleFactor + zComp); + (m_columnDepth - rowPos) / m_scaleFactor); modelMatrix.scale(QVector3D(m_scaleX, item.height(), m_scaleZ)); itModelMatrix.scale(QVector3D(m_scaleX, item.height(), m_scaleZ)); #ifdef SHOW_DEPTH_TEXTURE_SCENE @@ -949,7 +952,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(0.0f, 1.0f - m_yAdjustment, zComp); + modelMatrix.translate(0.0f, 1.0f - m_yAdjustment, 0.0f); modelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, 1.0f, m_columnDepth / m_scaleFactor)); @@ -1035,7 +1038,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) rowPos = row * m_cachedBarSpacing.height(); modelMatrix.translate(0.0f, -m_yAdjustment, - (m_columnDepth - rowPos) / m_scaleFactor + zComp); + (m_columnDepth - rowPos) / m_scaleFactor); modelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, gridLineWidth)); itModelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, @@ -1083,7 +1086,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) colPos = bar * m_cachedBarSpacing.width(); modelMatrix.translate((m_rowWidth - colPos) / m_scaleFactor, - -m_yAdjustment, zComp); + -m_yAdjustment, 0.0f); modelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, m_columnDepth / m_scaleFactor)); itModelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, @@ -1141,11 +1144,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) if (m_zFlipped) { modelMatrix.translate(0.0f, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - m_columnDepth / m_scaleFactor + zComp); + m_columnDepth / m_scaleFactor); } else { modelMatrix.translate(0.0f, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - -m_columnDepth / m_scaleFactor + zComp); + -m_columnDepth / m_scaleFactor); } modelMatrix.scale(QVector3D(m_rowWidth / m_scaleFactor, gridLineWidth, gridLineWidth)); @@ -1193,11 +1196,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) if (m_xFlipped) { modelMatrix.translate(m_rowWidth / m_scaleFactor, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - zComp); + 0.0f); } else { modelMatrix.translate(-m_rowWidth / m_scaleFactor, 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - zComp); + 0.0f); } modelMatrix.scale(QVector3D(gridLineWidth, gridLineWidth, m_columnDepth / m_scaleFactor)); @@ -1272,14 +1275,14 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } QVector3D labelPos = QVector3D(colPos, -m_yAdjustment + 0.005f, // raise a bit over background to avoid depth "glimmering" - (m_columnDepth - rowPos) / m_scaleFactor + zComp); + (m_columnDepth - rowPos) / m_scaleFactor); m_dummyBarRenderItem.setTranslation(labelPos); const LabelItem &axisLabelItem = *m_axisCacheX.labelItems().at(row); //qDebug() << "labelPos, row" << row + 1 << ":" << labelPos << m_axisCacheX.labels().at(row); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(rotLabelX, rotLabelY, rotLabelZ), 0, m_cachedSelectionMode, m_labelShader, m_labelObj, m_cachedScene->activeCamera(), @@ -1311,13 +1314,13 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } QVector3D labelPos = QVector3D((colPos - m_rowWidth) / m_scaleFactor, -m_yAdjustment + 0.005f, // raise a bit over background to avoid depth "glimmering" - rowPos + zComp); + 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, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(rotLabelX, rotLabelY, rotLabelZ), 0, m_cachedSelectionMode, m_labelShader, m_labelObj, m_cachedScene->activeCamera(), @@ -1360,13 +1363,13 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Back wall QVector3D labelTrans = QVector3D(labelXTrans, labelYTrans, - labelZTrans + labelMarginZTrans + zComp); + labelZTrans + labelMarginZTrans); //qDebug() << "labelPos, value:" << labelTrans; m_dummyBarRenderItem.setTranslation(labelTrans); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(rotLabelX, rotLabelY, rotLabelZ), 0, m_cachedSelectionMode, m_labelShader, m_labelObj, m_cachedScene->activeCamera(), @@ -1382,12 +1385,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) else rotLabelY = 0.0f; - labelTrans = QVector3D(-labelXTrans - labelMarginXTrans, labelYTrans, - -labelZTrans + zComp); + labelTrans = QVector3D(-labelXTrans - labelMarginXTrans, labelYTrans, -labelZTrans); m_dummyBarRenderItem.setTranslation(labelTrans); m_drawer->drawLabel(m_dummyBarRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(rotLabelX, rotLabelY, rotLabelZ), 0, m_cachedSelectionMode, m_labelShader, m_labelObj, m_cachedScene->activeCamera(), @@ -1468,7 +1470,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } m_drawer->drawLabel(*selectedBar, labelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, m_yAdjustment, zComp), + QVector3D(0.0f, m_yAdjustment, 0.0f), QVector3D(0.0f, 0.0f, 0.0f), selectedBar->height(), m_cachedSelectionMode, m_labelShader, m_labelObj, m_cachedScene->activeCamera(), true, false); diff --git a/src/datavisualization/engine/q3dcamera.cpp b/src/datavisualization/engine/q3dcamera.cpp index 26329eb7..86505ccb 100644 --- a/src/datavisualization/engine/q3dcamera.cpp +++ b/src/datavisualization/engine/q3dcamera.cpp @@ -518,7 +518,7 @@ QVector3D Q3DCamera::calculatePositionRelativeToCamera(const QVector3D &relative qreal distanceModifier) const { // Move the position with camera - GLfloat radiusFactor = relativePosition.z() * (1.5f + distanceModifier); + GLfloat radiusFactor = cameraDistance * (1.5f + distanceModifier); GLfloat xAngle; GLfloat yAngle; if (!fixedRotation) { @@ -532,6 +532,7 @@ QVector3D Q3DCamera::calculatePositionRelativeToCamera(const QVector3D &relative GLfloat zPos = radius * qCos(xAngle) * qCos(yAngle); GLfloat xPos = radius * qSin(xAngle) * qCos(yAngle); GLfloat yPos = (radiusFactor + relativePosition.y()) * qSin(yAngle); + // Keep in the set position in relation to camera return QVector3D(-xPos + relativePosition.x(), yPos + relativePosition.y(), diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index d2f983f1..43a86be3 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -182,8 +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 + zComp), - QVector3D(0.0f, 0.0f, zComp), + scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); m_hasHeightAdjustmentChanged = false; } @@ -269,7 +269,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) m_depthShader->bind(); // Set viewport for depth map rendering. Must match texture size. Larger values give smoother shadows. - glViewport(m_mainViewPort.x(), m_mainViewPort.y(), + glViewport(0, 0, m_mainViewPort.width() * m_shadowQualityMultiplier, m_mainViewPort.height() * m_shadowQualityMultiplier); @@ -283,8 +283,8 @@ 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( - defaultLightPos, 0.0f, 1.0f / m_autoScaleAdjustment); - depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, 0.0f, zComp), + 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)); // 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 @@ -364,10 +364,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f + zComp), - QVector3D(0.0f, 0.0f, zComp), + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, @@ -456,10 +455,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f + zComp), - QVector3D(0.0f, 0.0f, zComp), + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.0f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, @@ -601,7 +599,6 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) backgroundMargin, (aspectRatio * backgroundMargin)); #endif - modelMatrix.translate(0.0f, 0.0f, zComp); modelMatrix.scale(bgScale); itModelMatrix.scale(bgScale); // If we're viewing from below, background object must be flipped @@ -702,9 +699,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; if (m_yFlipped) - modelMatrix.translate(0.0f, backgroundMargin, linePos / m_scaleFactor + zComp); + modelMatrix.translate(0.0f, backgroundMargin, linePos / m_scaleFactor); else - modelMatrix.translate(0.0f, -backgroundMargin, linePos / m_scaleFactor + zComp); + 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( @@ -775,7 +772,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(lineXTrans, 0.0f, linePos / m_scaleFactor + zComp); + modelMatrix.translate(lineXTrans, 0.0f, linePos / m_scaleFactor); modelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); itModelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); @@ -832,9 +829,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; if (m_yFlipped) - modelMatrix.translate(linePos / m_scaleFactor, backgroundMargin, zComp); + modelMatrix.translate(linePos / m_scaleFactor, backgroundMargin, 0.0f); else - modelMatrix.translate(linePos / m_scaleFactor, -backgroundMargin, zComp); + 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( @@ -904,7 +901,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(linePos / m_scaleFactor, 0.0f, lineZTrans + zComp); + modelMatrix.translate(linePos / m_scaleFactor, 0.0f, lineZTrans); modelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); itModelMatrix.scale(QVector3D(gridLineWidth, backgroundMargin, gridLineWidth)); @@ -963,7 +960,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(0.0f, linePos / m_heightNormalizer, lineZTrans + zComp); + 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( @@ -1029,7 +1026,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(lineXTrans, linePos / m_heightNormalizer, zComp); + 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( @@ -1133,7 +1130,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } QVector3D labelTrans = QVector3D(labelXTrans, labelYTrans, - labelPos / m_scaleFactor + zComp); + labelPos / m_scaleFactor); // Draw the label here @@ -1145,7 +1142,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, zComp), + 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, @@ -1194,7 +1191,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } QVector3D labelTrans = QVector3D(labelPos / m_scaleFactor, labelYTrans, - labelZTrans + zComp); + labelZTrans); // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); @@ -1205,7 +1202,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, zComp), + 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, @@ -1253,12 +1250,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Back wall QVector3D labelTrans = QVector3D(labelXTrans, labelYTrans, - labelZTrans + labelMarginZTrans + zComp); + labelZTrans + labelMarginZTrans); // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, zComp), + 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, @@ -1275,12 +1272,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) rotLabelY = 0.0f; labelTrans = QVector3D(-labelXTrans - labelMarginXTrans, labelYTrans, - -labelZTrans + zComp); + -labelZTrans); // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); m_drawer->drawLabel(m_dummyRenderItem, axisLabelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, zComp), + 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, @@ -1348,7 +1345,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) } m_drawer->drawLabel(*selectedItem, labelItem, viewMatrix, projectionMatrix, - QVector3D(0.0f, 0.0f, zComp), + 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, @@ -1489,7 +1486,7 @@ void Scatter3DRenderer::calculateTranslation(ScatterRenderItem &item) GLfloat xTrans = (aspectRatio * item.position().x()) / m_scaleFactor; GLfloat zTrans = -(aspectRatio * item.position().z()) / m_scaleFactor; GLfloat yTrans = item.position().y() / m_heightNormalizer; - item.setTranslation(QVector3D(xTrans, yTrans, zTrans + zComp)); + item.setTranslation(QVector3D(xTrans, yTrans, zTrans)); //qDebug() << item.translation(); } diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp index 4fa9f688..b2c776f9 100644 --- a/src/datavisualization/engine/selectionpointer.cpp +++ b/src/datavisualization/engine/selectionpointer.cpp @@ -105,11 +105,11 @@ 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, zComp + 1.0), - QVector3D(0.0f, 0.0f, zComp), + viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 1.0f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); projectionMatrix.ortho(-sliceUnits * aspect, sliceUnits * aspect, - -sliceUnits, sliceUnits, -1.0f, 14.0f); + -sliceUnits, sliceUnits, -1.0f, 4.0f); } else { viewMatrix = camera->viewMatrix(); projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width() @@ -124,7 +124,7 @@ void SelectionPointer::render(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; // Position the pointer ball - modelMatrix.translate(m_position + QVector3D(0.0f, 0.0f, zComp)); + modelMatrix.translate(m_position + QVector3D(0.0f, 0.0f, 0.0f)); // Scale the point with fixed values (at this point) modelMatrix.scale(QVector3D(0.05f, 0.05f, 0.05f)); @@ -161,7 +161,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, zComp)); + modelMatrixLabel.translate(m_position + labelAlign + QVector3D(0.0f, 0.0f, 0.0f)); // 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 6dbdbe7c..4ce8d2c7 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -422,8 +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 + zComp), - QVector3D(0.0f, 0.0f, zComp), + scene->activeCamera()->setBaseOrientation(QVector3D(0.0f, 0.0f, cameraDistance), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); // For now this is used just to make things once. Proper use will come m_hasHeightAdjustmentChanged = false; @@ -479,12 +479,12 @@ void Surface3DRenderer::drawSlicedScene() GLfloat aspect = (GLfloat)m_mainViewPort.width() / (GLfloat)m_mainViewPort.height(); projectionMatrix.ortho(-sliceUnits * aspect, sliceUnits * aspect, - -sliceUnits, sliceUnits, -1.0f, 14.0f); // 14.0 because of zComp + -sliceUnits, sliceUnits, -1.0f, 4.0f); // Set view matrix QMatrix4x4 viewMatrix; - viewMatrix.lookAt(QVector3D(0.0f, 0.0f, zComp + 1.0f), - QVector3D(0.0f, 0.0f, zComp), + viewMatrix.lookAt(QVector3D(0.0f, 0.0f, 1.0f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); // Set light position @@ -513,7 +513,7 @@ void Surface3DRenderer::drawSlicedScene() QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(offset, 0.0f, zComp); + modelMatrix.translate(offset, 0.0f, 0.0f); QVector3D scaling(scaleX, 1.0f, sliceZScale); modelMatrix.scale(scaling); itModelMatrix.scale(scaling); @@ -589,7 +589,7 @@ void Surface3DRenderer::drawSlicedScene() QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(0.0f, linePos, zComp - sliceZScale); + modelMatrix.translate(0.0f, linePos, -sliceZScale); modelMatrix.scale(gridLineScaleX); itModelMatrix.scale(gridLineScaleX); @@ -630,7 +630,7 @@ void Surface3DRenderer::drawSlicedScene() QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(linePos, 0.0f, zComp - sliceZScale); + modelMatrix.translate(linePos, 0.0f, -sliceZScale); modelMatrix.scale(gridLineScaleY); itModelMatrix.scale(gridLineScaleY); @@ -667,9 +667,9 @@ void Surface3DRenderer::drawSlicedScene() GLfloat labelPos = -1.0f; int labelNbr = 0; - QVector3D positionComp(0.0f, 0.0f, zComp); + QVector3D positionComp(0.0f, 0.0f, 0.0f); QVector3D rotation(0.0f, 0.0f, 0.0f); - QVector3D labelTrans = QVector3D(scaleXBackground + labelMargin, labelPos, zComp); + QVector3D labelTrans = QVector3D(scaleXBackground + labelMargin, labelPos, 0.0f); for (int segment = 0; segment <= m_axisCacheY.segmentCount(); segment++) { if (m_axisCacheY.labelItems().size() > labelNbr) { labelTrans.setY(labelPos); @@ -783,7 +783,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QVector3D surfaceScaler(m_surfaceScaleX, 1.0f, m_surfaceScaleZ); - QVector3D surfaceOffset(m_surfaceOffsetX, 0.0f, m_surfaceOffsetZ + zComp); + QVector3D surfaceOffset(m_surfaceOffsetX, 0.0f, m_surfaceOffsetZ); // Draw depth buffer #if !defined(QT_OPENGL_ES_2) @@ -805,8 +805,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, zComp), 0.0f, 1.5f / m_autoScaleAdjustment); - depthViewMatrix.lookAt(depthLightPos, QVector3D(0.0f, 0.0f, zComp), + 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)); // TODO: Why does depthViewMatrix.column(3).y() goes to zero when we're directly above? @@ -876,10 +876,9 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); QMatrix4x4 modelMatrix; QMatrix4x4 viewmatrix; - viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f + zComp), - QVector3D(0.0f, 0.0f, zComp), + viewmatrix.lookAt(QVector3D(0.0f, 0.0f, 2.5f), + QVector3D(0.0f, 0.0f, 0.0f), QVector3D(0.0f, 1.0f, 0.0f)); - modelMatrix.translate(0.0, 0.0, zComp); QMatrix4x4 MVPMatrix = projectionMatrix * viewmatrix * modelMatrix; m_labelShader->setUniformValue(m_labelShader->MVP(), MVPMatrix); m_drawer->drawObject(m_labelShader, m_labelObj, m_depthTexture); @@ -1026,7 +1025,6 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(0.0f, 0.0f, zComp); QVector3D bgScale(m_scaleXWithBackground, backgroundMargin, m_scaleZWithBackground); modelMatrix.scale(bgScale); itModelMatrix.scale(bgScale); @@ -1106,7 +1104,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) if (m_axisCacheZ.segmentCount() > 0) { // Floor lines GLfloat lineStep = 2.0f * aspectRatio * m_axisCacheZ.subSegmentStep() / m_scaleFactor; - GLfloat linePos = m_scaleZ + zComp; // Start line + GLfloat linePos = m_scaleZ; // Start line int lastSegment = m_axisCacheZ.subSegmentCount() * m_axisCacheZ.segmentCount(); for (int segment = 0; segment <= lastSegment; segment++) { @@ -1160,7 +1158,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Side wall lines GLfloat lineXTrans = m_scaleXWithBackground; - linePos = m_scaleZ + zComp; // Start line + linePos = m_scaleZ; // Start line if (!m_xFlipped) lineXTrans = -lineXTrans; @@ -1222,9 +1220,9 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; if (m_yFlipped) - modelMatrix.translate(linePos, backgroundMargin, zComp); + modelMatrix.translate(linePos, backgroundMargin, 0.0f); else - modelMatrix.translate(linePos, -backgroundMargin, zComp); + modelMatrix.translate(linePos, -backgroundMargin, 0.0f); modelMatrix.scale(gridLineScaleZ); itModelMatrix.scale(gridLineScaleZ); @@ -1265,11 +1263,11 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) } // Back wall lines - GLfloat lineZTrans = m_scaleZWithBackground + zComp; + GLfloat lineZTrans = m_scaleZWithBackground; linePos = m_scaleX; if (!m_zFlipped) - lineZTrans = -lineZTrans + zComp + zComp; + lineZTrans = -lineZTrans; for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; @@ -1320,10 +1318,10 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) GLfloat linePos = -1.0f; int lastSegment = m_axisCacheY.subSegmentCount() * m_axisCacheY.segmentCount(); - GLfloat lineZTrans = m_scaleZWithBackground + zComp; + GLfloat lineZTrans = m_scaleZWithBackground; if (!m_zFlipped) - lineZTrans = -lineZTrans + zComp + zComp; + lineZTrans = -lineZTrans; for (int segment = 0; segment <= lastSegment; segment++) { QMatrix4x4 modelMatrix; @@ -1381,7 +1379,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 depthMVPMatrix; QMatrix4x4 itModelMatrix; - modelMatrix.translate(lineXTrans, linePos, zComp); + modelMatrix.translate(lineXTrans, linePos, 0.0f); modelMatrix.scale(gridLineScaleZ); itModelMatrix.scale(gridLineScaleZ); @@ -1429,10 +1427,10 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Z Labels - QVector3D positionZComp(0.0f, 0.0f, zComp); + QVector3D positionZComp(0.0f, 0.0f, 0.0f); if (m_axisCacheZ.segmentCount() > 0) { GLfloat posStep = 2.0f * aspectRatio * m_axisCacheZ.segmentStep() / m_scaleFactor; - GLfloat labelPos = m_scaleZ + zComp; + GLfloat labelPos = m_scaleZ; int lastSegment = m_axisCacheZ.segmentCount(); int labelNbr = 0; GLfloat labelXTrans = m_scaleXWithBackground + labelMargin; @@ -1500,7 +1498,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) } QVector3D labelTrans = QVector3D(labelPos, labelYTrans, - labelZTrans + zComp); + labelZTrans); QVector3D rotation(rotLabelX, rotLabelY, rotLabelZ); for (int segment = 0; segment <= lastSegment; segment++) { @@ -1553,7 +1551,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Side wall QVector3D labelTrans = QVector3D(labelXTrans, labelPos, - labelZTrans + labelMarginZTrans + zComp); + labelZTrans + labelMarginZTrans); if (m_xFlipped) rotation.setY(-90.0f); else @@ -1581,7 +1579,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) rotation.setY(0.0f); labelTrans = QVector3D(-labelXTrans - labelMarginXTrans, labelPos, - -labelZTrans + zComp); + -labelZTrans); // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); diff --git a/src/datavisualization/global/datavisualizationglobal_p.h b/src/datavisualization/global/datavisualizationglobal_p.h index 4da1023c..6d0ee916 100644 --- a/src/datavisualization/global/datavisualizationglobal_p.h +++ b/src/datavisualization/global/datavisualizationglobal_p.h @@ -38,15 +38,13 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE // Constants used in several files -// Compensation for z position; move all objects to positive z, as shader can't handle negative values correctly -const GLfloat zComp = 10.0f; // Distance from camera to origin const GLfloat cameraDistance = 6.0f; // Size of font to be used in label texture rendering. Doesn't affect the actual font size. const int textureFontSize = 50; // Default light position. To have shadows working correctly, light should be as far as camera, or a bit further // y position is added to the minimum height (or can be thought to be that much above or below the camera) -const QVector3D defaultLightPos = QVector3D(0.0f, 0.5f, zComp); +const QVector3D defaultLightPos = QVector3D(0.0f, 0.5f, 0.0f); const GLfloat defaultRatio = 1.0f / 1.6f; // default aspect ratio 16:10 QT_DATAVISUALIZATION_END_NAMESPACE -- cgit v1.2.3