diff options
author | Andy Nichols <andy.nichols@qt.io> | 2017-11-13 13:56:39 +0100 |
---|---|---|
committer | Andy Nichols <andy.nichols@qt.io> | 2017-11-13 13:56:39 +0100 |
commit | ab2d05d06b37fe875d360f92fe67e103ae17d80b (patch) | |
tree | 770a5c8a08f80baafe96cc349686ce6deadcd8b7 /src/render/backend/renderview.cpp | |
parent | 18ce3e68e6db896e9c01cf4df0dd7e9fa714b37c (diff) | |
parent | 764b715b5f682ddb1bdb52f67b5a35d85af7ccf1 (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Change-Id: I2d373d538df3a65ac2d41238e5c6a214a151be68
Diffstat (limited to 'src/render/backend/renderview.cpp')
-rw-r--r-- | src/render/backend/renderview.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp index 07311824e..bdf7605db 100644 --- a/src/render/backend/renderview.cpp +++ b/src/render/backend/renderview.cpp @@ -596,7 +596,12 @@ QVector<RenderCommand *> RenderView::buildDrawRenderCommands(const QVector<Entit for (const RenderPassParameterData &passData : renderPassData) { // Add the RenderPass Parameters RenderCommand *command = new RenderCommand(); - command->m_depth = m_data.m_eyePos.distanceToPoint(entity->worldBoundingVolume()->center()); + + // Project the camera-to-object-center vector onto the camera + // view vector. This gives a depth value suitable as the key + // for BackToFront sorting. + command->m_depth = QVector3D::dotProduct(entity->worldBoundingVolume()->center() - m_data.m_eyePos, m_data.m_eyeViewDir); + command->m_geometry = geometryHandle; command->m_geometryRenderer = geometryRendererHandle; command->m_material = materialHandle; @@ -754,6 +759,12 @@ void RenderView::updateMatrices() const QMatrix4x4 inverseWorldTransform = viewMatrix().inverted(); const QVector3D eyePosition(inverseWorldTransform.column(3)); setEyePosition(eyePosition); + + // Get the viewing direction of the camera. Use the normal matrix to + // ensure non-uniform scale works too. + QMatrix3x3 normalMat = m_data.m_viewMatrix.normalMatrix(); + // dir = normalize(QVector3D(0, 0, -1) * normalMat) + setEyeViewDirection(QVector3D(-normalMat(2, 0), -normalMat(2, 1), -normalMat(2, 2)).normalized()); } } |