From d6a5baf471f054c0d2711bd6a24f5a309ed32e2a Mon Sep 17 00:00:00 2001 From: Mika Salmela Date: Tue, 8 Oct 2013 15:41:45 +0300 Subject: Aspect ratio preservation for surface slice view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTRD-2387 Change-Id: I51e9900d419931e75d5df2f5962590ee5f3cdbc7 Reviewed-by: Tomi Korpipää Reviewed-by: Miikka Heikkinen Reviewed-by: Pasi Keränen --- src/datavisualization/engine/selectionpointer.cpp | 14 ++++++-------- src/datavisualization/engine/surface3drenderer.cpp | 17 ++++++----------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp index d1a4c42a..6c3e0c8b 100644 --- a/src/datavisualization/engine/selectionpointer.cpp +++ b/src/datavisualization/engine/selectionpointer.cpp @@ -34,6 +34,8 @@ QT_DATAVISUALIZATION_BEGIN_NAMESPACE +const GLfloat sliceUnits = 2.5; + SelectionPointer::SelectionPointer(Drawer *drawer) : QObject(0), m_labelShader(0), @@ -102,11 +104,12 @@ void SelectionPointer::render(GLuint defaultFboHandle) QMatrix4x4 viewMatrix; QMatrix4x4 projectionMatrix; if (m_cachedIsSlicingActivated) { - GLfloat camZPosSliced = 5.0f / m_autoScaleAdjustment + zComp; - viewMatrix.lookAt(QVector3D(0.0f, 0.0f, camZPosSliced), + 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), QVector3D(0.0f, 1.0f, 0.0f)); - projectionMatrix.ortho(-3.0f, 3.0, -3.0, 3.0, 0.1f, 100.0f); + projectionMatrix.ortho(-sliceUnits * aspect, sliceUnits * aspect, + -sliceUnits, sliceUnits, -1.0f, 14.0f); } else { viewMatrix = camera->viewMatrix(); projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width() @@ -117,11 +120,6 @@ void SelectionPointer::render(GLuint defaultFboHandle) GLfloat scaledFontSize = 0.05f + m_drawer->font().pointSizeF() / 500.0f; GLfloat scaleFactor = scaledFontSize / (GLfloat)textureSize.height(); - // Set up projection matrix -// QMatrix4x4 projectionMatrix; -// projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width() -// / (GLfloat)m_mainViewPort.height(), 0.1f, 100.0f); - QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp index fdefe7f0..5b771684 100644 --- a/src/datavisualization/engine/surface3drenderer.cpp +++ b/src/datavisualization/engine/surface3drenderer.cpp @@ -55,6 +55,7 @@ const GLfloat backgroundBottom = 1.0f; const GLfloat gridLineWidth = 0.005f; const GLfloat sliceZScale = 0.1f; const GLfloat surfaceGridYOffsetValue = 0.001f; +const GLfloat sliceUnits = 2.5f; const int subViewDivider = 5; // The second offset to opposite direction is double because same matrix is translated twice const GLfloat surfaceGridYOffset[2] = {-surfaceGridYOffsetValue, 2.0f * surfaceGridYOffsetValue}; @@ -471,15 +472,14 @@ void Surface3DRenderer::drawSlicedScene() // Set up projection matrix QMatrix4x4 projectionMatrix; - projectionMatrix.ortho(-3.0f, 3.0, -3.0, 3.0, 0.1f, 100.0f); + + 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 // Set view matrix QMatrix4x4 viewMatrix; - - // Adjust scaling (zoom rate based on aspect ratio) - GLfloat camZPosSliced = 5.0f / m_autoScaleAdjustment + zComp; - - viewMatrix.lookAt(QVector3D(0.0f, 0.0f, camZPosSliced), + viewMatrix.lookAt(QVector3D(0.0f, 0.0f, zComp + 1.0f), QVector3D(0.0f, 0.0f, zComp), QVector3D(0.0f, 1.0f, 0.0f)); @@ -505,9 +505,6 @@ void Surface3DRenderer::drawSlicedScene() ShaderHelper *surfaceShader = m_shader; surfaceShader->bind(); - // For surface we can see climpses from underneath - glDisable(GL_CULL_FACE); - QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; QMatrix4x4 itModelMatrix; @@ -540,8 +537,6 @@ void Surface3DRenderer::drawSlicedScene() surfaceShader->release(); - glEnable(GL_CULL_FACE); - // Draw surface grid if (m_cachedSurfaceGridOn) { m_surfaceGridShader->bind(); -- cgit v1.2.3