diff options
author | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-10-29 09:19:16 +0200 |
---|---|---|
committer | Tomi Korpipää <tomi.korpipaa@digia.com> | 2013-10-29 10:26:58 +0200 |
commit | 233d5c02638903e96687d580ada7188f0e6a9756 (patch) | |
tree | 9ae6823ace3225bd426515135a28110a4179d06a | |
parent | 913bd7311c554f14de80a5ff5027f266903bf73e (diff) |
Grid line bars replaced by flats
Task-number: QTRD-2509
+ polygon offset added to labels
Change-Id: I9d56a2001943d2d817f32c503790c07c241297b5
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
-rw-r--r-- | src/datavisualization/engine/bars3drenderer.cpp | 134 | ||||
-rw-r--r-- | src/datavisualization/engine/scatter3drenderer.cpp | 86 | ||||
-rw-r--r-- | src/datavisualization/engine/surface3drenderer.cpp | 78 | ||||
-rw-r--r-- | src/datavisualization/global/datavisualizationglobal_p.h | 1 |
4 files changed, 191 insertions, 108 deletions
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp index c7c2f64c..0b0ae9aa 100644 --- a/src/datavisualization/engine/bars3drenderer.cpp +++ b/src/datavisualization/engine/bars3drenderer.cpp @@ -384,34 +384,10 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - // 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, - positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, - m_labelObj, activeCamera, false, false, Drawer::LabelTop); - } - m_drawer->drawLabel(*dummyItem, zLabel, viewMatrix, projectionMatrix, - positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, - m_labelObj, activeCamera, false, false, Drawer::LabelBottom); - } else { - m_drawer->drawLabel(*dummyItem, xLabel, viewMatrix, projectionMatrix, - positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, - m_labelObj, activeCamera, false, false, Drawer::LabelBottom); - if (m_sliceTitleItem) { - m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, - positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, - m_labelObj, activeCamera, false, false, Drawer::LabelTop); - } - } - m_drawer->drawLabel(*dummyItem, yLabel, viewMatrix, projectionMatrix, - 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); @@ -441,6 +417,31 @@ void Bars3DRenderer::drawSlicedScene(const LabelItem &xLabel, } } + // Draw labels for axes + if (QDataVis::SelectionModeSliceRow == m_cachedSelectionMode) { + if (m_sliceTitleItem) { + m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelTop); + } + m_drawer->drawLabel(*dummyItem, zLabel, viewMatrix, projectionMatrix, + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelBottom); + } else { + m_drawer->drawLabel(*dummyItem, xLabel, viewMatrix, projectionMatrix, + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelBottom); + if (m_sliceTitleItem) { + m_drawer->drawLabel(*dummyItem, sliceSelectionLabel, viewMatrix, projectionMatrix, + positionComp, zeroVector, 0, m_cachedSelectionMode, m_labelShader, + m_labelObj, activeCamera, false, false, Drawer::LabelTop); + } + } + m_drawer->drawLabel(*dummyItem, yLabel, viewMatrix, projectionMatrix, + positionComp, QVector3D(0.0f, 0.0f, 90.0f), 0, + m_cachedSelectionMode, m_labelShader, m_labelObj, activeCamera, + false, false, Drawer::LabelLeft); + glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); @@ -1024,6 +1025,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) // Draw grid lines if (m_cachedIsGridEnabled && m_heightNormalizer) { ShaderHelper *lineShader = m_backgroundShader; + QQuaternion lineRotation = QQuaternion(); // Bind bar shader lineShader->bind(); @@ -1047,8 +1049,19 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->lightS(), m_cachedTheme.m_lightStrength / 2.5f); } + GLfloat yFloorLinePosition = -m_yAdjustment; + if (m_yFlipped) + yFloorLinePosition -= gridLineOffset; + else + yFloorLinePosition += gridLineOffset; + QVector3D gridLineScaler(rowScaleFactor, gridLineWidth, gridLineWidth); + if (m_yFlipped) + lineRotation = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, 90.0f); + else + lineRotation = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -90.0f); + // Floor lines: rows for (GLfloat row = 0.0f; row <= m_cachedRowCount; row++) { QMatrix4x4 modelMatrix; @@ -1056,15 +1069,12 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; rowPos = row * m_cachedBarSpacing.height(); - modelMatrix.translate(0.0f, -m_yAdjustment, + modelMatrix.translate(0.0f, yFloorLinePosition, (m_columnDepth - rowPos) / m_scaleFactor); 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); - } + modelMatrix.rotate(lineRotation); + itModelMatrix.rotate(lineRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -1098,15 +1108,11 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) colPos = bar * m_cachedBarSpacing.width(); modelMatrix.translate((m_rowWidth - colPos) / m_scaleFactor, - -m_yAdjustment, 0.0f); + yFloorLinePosition, 0.0f); 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); - } + modelMatrix.rotate(lineRotation); + itModelMatrix.rotate(lineRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -1136,6 +1142,10 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) GLfloat heightStep = m_axisCacheY.subSegmentStep(); GLfloat startLine = 0.0f; + GLfloat zWallLinePosition = -columnScaleFactor + gridLineOffset; + if (m_zFlipped) + zWallLinePosition = -zWallLinePosition; + if (m_hasNegativeValues) startLine = -m_heightNormalizer; @@ -1146,17 +1156,15 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - if (m_zFlipped) { - modelMatrix.translate(0.0f, - 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - columnScaleFactor); - } else { - modelMatrix.translate(0.0f, - 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - -columnScaleFactor); - } + modelMatrix.translate(0.0f, + 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, + zWallLinePosition); modelMatrix.scale(gridLineScaler); itModelMatrix.scale(gridLineScaler); + if (m_zFlipped) { + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + } MVPMatrix = projectionViewMatrix * modelMatrix; @@ -1182,6 +1190,15 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) } // Wall lines: side wall + GLfloat xWallLinePosition = -rowScaleFactor + gridLineOffset; + if (m_xFlipped) + xWallLinePosition = -xWallLinePosition; + + if (m_xFlipped) + lineRotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, -90.0f); + else + lineRotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f); + gridLineScaler = QVector3D(gridLineWidth, gridLineWidth, columnScaleFactor); for (GLfloat lineHeight = startLine; lineHeight <= m_heightNormalizer; lineHeight += heightStep) { @@ -1189,17 +1206,13 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - if (m_xFlipped) { - modelMatrix.translate(rowScaleFactor, - 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - 0.0f); - } else { - modelMatrix.translate(-rowScaleFactor, - 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, - 0.0f); - } + modelMatrix.translate(xWallLinePosition, + 2.0f * lineHeight / m_heightNormalizer - m_yAdjustment, + 0.0f); modelMatrix.scale(gridLineScaler); itModelMatrix.scale(gridLineScaler); + modelMatrix.rotate(lineRotation); + itModelMatrix.rotate(lineRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -1235,6 +1248,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_POLYGON_OFFSET_FILL); // Calculate the positions for row and column labels and store them GLfloat labelYAdjustment = -m_yAdjustment + 0.005f; @@ -1253,6 +1267,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) 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) { @@ -1264,6 +1279,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) else colPos = colPosValue; + glPolygonOffset(GLfloat(row) / -10.0f, 1.0f); + QVector3D labelPos = QVector3D(colPos, labelYAdjustment, // raise a bit over background to avoid depth "glimmering" (m_columnDepth - rowPos) / m_scaleFactor); @@ -1300,6 +1317,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) else rowPos = rowPosValue; + glPolygonOffset(GLfloat(column) / -10.0f, 1.0f); + QVector3D labelPos = QVector3D((colPos - m_rowWidth) / m_scaleFactor, labelYAdjustment, // raise a bit over background to avoid depth "glimmering" rowPos); @@ -1352,6 +1371,8 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) backLabelTrans.setY(2.0f * labelPos / m_heightNormalizer - m_yAdjustment); sideLabelTrans.setY(backLabelTrans.y()); + glPolygonOffset(GLfloat(i) / -10.0f, 1.0f); + const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr); // Back wall @@ -1371,6 +1392,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle) labelNbr++; labelPos += heightStep; } + glDisable(GL_POLYGON_OFFSET_FILL); // Handle slice activation and selection label drawing if (!barSelectionFound) { @@ -1614,7 +1636,7 @@ void Bars3DRenderer::loadGridLineMesh() { if (m_gridLineObj) delete m_gridLineObj; - m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/bar")); + m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/label")); m_gridLineObj->load(); } diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp index a457b545..62163d6c 100644 --- a/src/datavisualization/engine/scatter3drenderer.cpp +++ b/src/datavisualization/engine/scatter3drenderer.cpp @@ -675,6 +675,23 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->lightS(), m_cachedTheme.m_lightStrength / 2.5f); } + QQuaternion lineYRotation = QQuaternion(); + QQuaternion lineXRotation = QQuaternion(); + + if (m_xFlipped) + lineYRotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, -90.0f); + else + lineYRotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f); + + if (m_yFlipped) + lineXRotation = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, 90.0f); + else + lineXRotation = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -90.0f); + + GLfloat yFloorLinePosition = -backgroundMargin + gridLineOffset; + if (m_yFlipped) + yFloorLinePosition = -yFloorLinePosition; + // Rows (= Z) if (m_axisCacheZ.segmentCount() > 0) { // Floor lines @@ -702,19 +719,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - if (m_yFlipped) - modelMatrix.translate(0.0f, backgroundMargin, linePos / m_scaleFactor); - else - modelMatrix.translate(0.0f, -backgroundMargin, linePos / m_scaleFactor); + modelMatrix.translate(0.0f, yFloorLinePosition, linePos / m_scaleFactor); 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); - } + modelMatrix.rotate(lineXRotation); + itModelMatrix.rotate(lineXRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -744,10 +755,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) gridLineScaler = QVector3D(gridLineWidth, backgroundMargin, gridLineWidth); #ifndef USE_UNIFORM_SCALING GLfloat lineXTrans = (aspectRatio * backgroundMargin * m_areaSize.width()) - / m_scaleFactor; + / m_scaleFactor - gridLineOffset; linePos = -aspectRatio * m_axisCacheZ.min(); // Start line #else - GLfloat lineXTrans = aspectRatio * backgroundMargin; + GLfloat lineXTrans = aspectRatio * backgroundMargin - gridLineOffset; linePos = -aspectRatio * m_scaleFactor; // Start line #endif if (!m_xFlipped) @@ -759,9 +770,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; modelMatrix.translate(lineXTrans, 0.0f, linePos / m_scaleFactor); + modelMatrix.scale(gridLineScaler); itModelMatrix.scale(gridLineScaler); + modelMatrix.rotate(lineYRotation); + itModelMatrix.rotate(lineYRotation); + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -810,18 +825,13 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - if (m_yFlipped) - modelMatrix.translate(linePos / m_scaleFactor, backgroundMargin, 0.0f); - else - modelMatrix.translate(linePos / m_scaleFactor, -backgroundMargin, 0.0f); + modelMatrix.translate(linePos / m_scaleFactor, yFloorLinePosition, 0.0f); + 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); - } + modelMatrix.rotate(lineXRotation); + itModelMatrix.rotate(lineXRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -850,10 +860,10 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) // Back wall lines #ifndef USE_UNIFORM_SCALING GLfloat lineZTrans = (aspectRatio * backgroundMargin * m_areaSize.height()) - / m_scaleFactor; + / m_scaleFactor - gridLineOffset; linePos = aspectRatio * m_axisCacheX.min(); #else - GLfloat lineZTrans = aspectRatio * backgroundMargin; + GLfloat lineZTrans = aspectRatio * backgroundMargin - gridLineOffset; linePos = -aspectRatio * m_scaleFactor; #endif if (!m_zFlipped) @@ -867,9 +877,15 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; modelMatrix.translate(linePos / m_scaleFactor, 0.0f, lineZTrans); + modelMatrix.scale(gridLineScaler); itModelMatrix.scale(gridLineScaler); + if (m_zFlipped) { + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + } + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -904,12 +920,12 @@ 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; + / m_scaleFactor - gridLineOffset; 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; + GLfloat lineZTrans = aspectRatio * backgroundMargin - gridLineOffset; QVector3D gridLineScaler((aspectRatio * backgroundMargin), gridLineWidth, gridLineWidth); #endif @@ -926,6 +942,11 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) modelMatrix.scale(gridLineScaler); itModelMatrix.scale(gridLineScaler); + if (m_zFlipped) { + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + } + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -955,12 +976,12 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) lastSegment = m_axisCacheY.subSegmentCount() * m_axisCacheY.segmentCount(); #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; + / m_scaleFactor - gridLineOffset; 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; + GLfloat lineXTrans = aspectRatio * backgroundMargin - gridLineOffset; gridLineScaler = QVector3D(gridLineWidth, gridLineWidth, aspectRatio * backgroundMargin); #endif @@ -977,6 +998,9 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) modelMatrix.scale(gridLineScaler); itModelMatrix.scale(gridLineScaler); + modelMatrix.rotate(lineYRotation); + itModelMatrix.rotate(lineYRotation); + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -1015,6 +1039,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_POLYGON_OFFSET_FILL); // Z Labels if (m_axisCacheZ.segmentCount() > 0) { @@ -1057,6 +1082,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif labelTrans.setZ(labelPos / m_scaleFactor); + glPolygonOffset(GLfloat(segment) / -10.0f, 1.0f); + // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); #ifndef USE_UNIFORM_SCALING @@ -1115,6 +1142,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) #endif labelTrans.setX(labelPos / m_scaleFactor); + glPolygonOffset(GLfloat(segment) / -10.0f, 1.0f); + // Draw the label here m_dummyRenderItem.setTranslation(labelTrans); #ifndef USE_UNIFORM_SCALING @@ -1185,6 +1214,8 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr); const GLfloat labelYTrans = labelPos / m_heightNormalizer; + glPolygonOffset(GLfloat(segment) / -10.0f, 1.0f); + // Back wall labelTransBack.setY(labelYTrans); m_dummyRenderItem.setTranslation(labelTransBack); @@ -1205,6 +1236,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle) labelPos += posStep; } } + glDisable(GL_POLYGON_OFFSET_FILL); // Handle selection clearing and selection label drawing if (!dotSelectionFound) { @@ -1368,7 +1400,7 @@ void Scatter3DRenderer::loadGridLineMesh() { if (m_gridLineObj) delete m_gridLineObj; - m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/bar")); + m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/label")); m_gridLineObj->load(); } diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index 63bd93a7..68b88bec 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -1103,6 +1103,23 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) lineShader->setUniformValue(lineShader->lightS(), m_cachedTheme.m_lightStrength / 2.5f); } + QQuaternion lineYRotation = QQuaternion(); + QQuaternion lineXRotation = QQuaternion(); + + if (m_xFlipped) + lineYRotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, -90.0f); + else + lineYRotation = QQuaternion::fromAxisAndAngle(0.0f, 1.0f, 0.0f, 90.0f); + + if (m_yFlipped) + lineXRotation = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, 90.0f); + else + lineXRotation = QQuaternion::fromAxisAndAngle(1.0f, 0.0f, 0.0f, -90.0f); + + GLfloat yFloorLinePosition = -backgroundMargin + gridLineOffset; + if (m_yFlipped) + yFloorLinePosition = -yFloorLinePosition; + // Rows (= Z) if (m_axisCacheZ.segmentCount() > 0) { // Floor lines @@ -1115,19 +1132,13 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - if (m_yFlipped) - modelMatrix.translate(0.0f, backgroundMargin, linePos); - else - modelMatrix.translate(0.0f, -backgroundMargin, linePos); + modelMatrix.translate(0.0f, yFloorLinePosition, linePos); modelMatrix.scale(gridLineScaleX); itModelMatrix.scale(gridLineScaleX); - // 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); - } + modelMatrix.rotate(lineXRotation); + itModelMatrix.rotate(lineXRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -1154,7 +1165,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) } // Side wall lines - GLfloat lineXTrans = m_scaleXWithBackground; + GLfloat lineXTrans = m_scaleXWithBackground - gridLineOffset; linePos = m_scaleZ; // Start line if (!m_xFlipped) @@ -1166,9 +1177,13 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; modelMatrix.translate(lineXTrans, 0.0f, linePos); + modelMatrix.scale(gridLineScaleY); itModelMatrix.scale(gridLineScaleY); + modelMatrix.rotate(lineYRotation); + itModelMatrix.rotate(lineYRotation); + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -1206,19 +1221,13 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; - if (m_yFlipped) - modelMatrix.translate(linePos, backgroundMargin, 0.0f); - else - modelMatrix.translate(linePos, -backgroundMargin, 0.0f); + modelMatrix.translate(linePos, yFloorLinePosition, 0.0f); modelMatrix.scale(gridLineScaleZ); itModelMatrix.scale(gridLineScaleZ); - // 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); - } + modelMatrix.rotate(lineXRotation); + itModelMatrix.rotate(lineXRotation); MVPMatrix = projectionViewMatrix * modelMatrix; @@ -1245,7 +1254,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) } // Back wall lines - GLfloat lineZTrans = m_scaleZWithBackground; + GLfloat lineZTrans = m_scaleZWithBackground - gridLineOffset; linePos = m_scaleX; if (!m_zFlipped) @@ -1257,9 +1266,15 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) QMatrix4x4 itModelMatrix; modelMatrix.translate(linePos, 0.0f, lineZTrans); + modelMatrix.scale(gridLineScaleY); itModelMatrix.scale(gridLineScaleY); + if (m_zFlipped) { + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + } + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -1292,7 +1307,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) GLfloat linePos = -1.0f; int lastSegment = m_axisCacheY.subSegmentCount() * m_axisCacheY.segmentCount(); - GLfloat lineZTrans = m_scaleZWithBackground; + GLfloat lineZTrans = m_scaleZWithBackground - gridLineOffset; if (!m_zFlipped) lineZTrans = -lineZTrans; @@ -1307,6 +1322,11 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) modelMatrix.scale(gridLineScaleX); itModelMatrix.scale(gridLineScaleX); + if (m_zFlipped) { + modelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + itModelMatrix.rotate(180.0f, 1.0, 0.0, 0.0); + } + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -1334,7 +1354,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) // Side wall linePos = -1.0f; lastSegment = m_axisCacheY.subSegmentCount() * m_axisCacheY.segmentCount(); - GLfloat lineXTrans = m_scaleXWithBackground; + GLfloat lineXTrans = m_scaleXWithBackground - gridLineOffset; if (!m_xFlipped) lineXTrans = -lineXTrans; @@ -1349,6 +1369,9 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) modelMatrix.scale(gridLineScaleZ); itModelMatrix.scale(gridLineScaleZ); + modelMatrix.rotate(lineYRotation); + itModelMatrix.rotate(lineYRotation); + MVPMatrix = projectionViewMatrix * modelMatrix; // Set the rest of the shader bindings @@ -1383,6 +1406,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_POLYGON_OFFSET_FILL); // Z Labels QVector3D positionZComp(0.0f, 0.0f, 0.0f); @@ -1415,9 +1439,9 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) for (int segment = 0; segment <= lastSegment; segment++) { if (m_axisCacheZ.labelItems().size() > labelNbr) { - labelTrans.setZ(labelPos); - + glPolygonOffset(GLfloat(segment) / -10.0f, 1.0f); // Draw the label here + labelTrans.setZ(labelPos); m_dummyRenderItem.setTranslation(labelTrans); const LabelItem &axisLabelItem = *m_axisCacheZ.labelItems().at(labelNbr); @@ -1461,6 +1485,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) for (int segment = 0; segment <= lastSegment; segment++) { if (m_axisCacheX.labelItems().size() > labelNbr) { + glPolygonOffset(GLfloat(segment) / -10.0f, 1.0f); // Draw the label here labelTrans.setX(labelPos); m_dummyRenderItem.setTranslation(labelTrans); @@ -1521,6 +1546,8 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) if (m_axisCacheY.labelItems().size() > labelNbr) { const LabelItem &axisLabelItem = *m_axisCacheY.labelItems().at(labelNbr); + glPolygonOffset(GLfloat(segment) / -10.0f, 1.0f); + // Back wall labelTransBack.setY(labelPos); m_dummyRenderItem.setTranslation(labelTransBack); @@ -1541,6 +1568,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle) labelPos += posStep; } } + glDisable(GL_POLYGON_OFFSET_FILL); glDisable(GL_TEXTURE_2D); @@ -1782,7 +1810,7 @@ void Surface3DRenderer::loadGridLineMesh() { if (m_gridLineObj) delete m_gridLineObj; - m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/bar")); + m_gridLineObj = new ObjectHelper(QStringLiteral(":/defaultMeshes/label")); m_gridLineObj->load(); } diff --git a/src/datavisualization/global/datavisualizationglobal_p.h b/src/datavisualization/global/datavisualizationglobal_p.h index b37dbf91..ce616ee7 100644 --- a/src/datavisualization/global/datavisualizationglobal_p.h +++ b/src/datavisualization/global/datavisualizationglobal_p.h @@ -43,6 +43,7 @@ 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; const GLfloat defaultRatio = 1.0f / 1.6f; // default aspect ratio 16:10 +const float gridLineOffset = 0.0001f; // Offset for lifting grid lines off background // 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(0.0f, 0.5f, 0.0f); |