summaryrefslogtreecommitdiffstats
path: root/src/render/backend/renderview.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-10-30 08:42:18 +0100
committerLiang Qi <liang.qi@qt.io>2017-10-31 09:19:01 +0100
commit4c32d8f66280b8db9256f199afb2bae6b92ad7a5 (patch)
tree81d6ad319b4d48faba7f829054d1ef113ff465d4 /src/render/backend/renderview.cpp
parentced895b361e4fff97f1b2d21e7f1bb33c82f34cd (diff)
parent294eefef0f8cfdba2edd73b5bd2ba7435b102ce5 (diff)
Merge remote-tracking branch 'origin/5.9' into 5.10
Conflicts: .qmake.conf src/render/backend/renderview.cpp src/render/backend/renderview_p.h Change-Id: I6c1122632f2c481da31a63e3abd42b760d1ff211
Diffstat (limited to 'src/render/backend/renderview.cpp')
-rw-r--r--src/render/backend/renderview.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp
index c0d3c983c..572cda229 100644
--- a/src/render/backend/renderview.cpp
+++ b/src/render/backend/renderview.cpp
@@ -572,7 +572,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;
@@ -731,6 +736,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());
}
}