summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2018-09-11 12:01:48 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2018-09-11 09:52:07 +0000
commit261ba65ad6497184dc77c1e49872d92884bb3f8b (patch)
tree678572ea61598779f50098e5fdb0cf846b901187
parentfbb9ce1194f30e76f1ab0cb299774d7de0a6aa47 (diff)
Fix focusing non-physical objects
Fake a bounding box when focusing a camera, a light, or an empty group in perspective view. Task-number: QT3DS-2282 Change-Id: Ia9fe83233e3d45ff480a8311bd4aa6a4430cf6b9 Reviewed-by: Teemu Tamminen <teemu.tamminen@qt.io> Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
-rw-r--r--src/Authoring/Studio/Render/StudioRenderer.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/Authoring/Studio/Render/StudioRenderer.cpp b/src/Authoring/Studio/Render/StudioRenderer.cpp
index 7c2eda44..304bc9bd 100644
--- a/src/Authoring/Studio/Render/StudioRenderer.cpp
+++ b/src/Authoring/Studio/Render/StudioRenderer.cpp
@@ -496,15 +496,17 @@ struct SRendererImpl : public IStudioRenderer,
|| m_Translation->GetOrCreateTranslator(theInstance) == nullptr
|| GraphObjectTypes::IsNodeType(
m_Translation->GetOrCreateTranslator(theInstance)->GetGraphObject().m_Type)
- == false)
+ == false) {
theInstance = m_Doc.GetActiveLayer();
+ }
// If we *still* aren't pointed at a node then bail.
if (m_Translation->GetOrCreateTranslator(theInstance) == nullptr
|| GraphObjectTypes::IsNodeType(
m_Translation->GetOrCreateTranslator(theInstance)->GetGraphObject().m_Type)
- == false)
+ == false) {
return;
+ }
SNode &theNode = static_cast<SNode &>(
m_Translation->GetOrCreateTranslator(theInstance)->GetGraphObject());
@@ -523,10 +525,24 @@ struct SRendererImpl : public IStudioRenderer,
}
}
}
- } else
+ } else {
theBounds =
theNode.GetBounds(m_Context->GetBufferManager(), m_Context->GetPathManager());
+ }
+
+ // Fake bounds for non-physical objects
+ if (theBounds.isEmpty()) {
+ const int dim = 50.0f; // Dimensions of a default sized cube
+ theBounds = qt3ds::NVBounds3(QT3DSVec3(-dim, -dim, -dim), QT3DSVec3(dim, dim, dim));
+ }
+
+ // Empty groups don't have proper global transform, so we need to recalculate it.
+ // For simplicity's sake, we recalculate for all groups, not just empty ones.
+ if (theNode.m_Type == GraphObjectTypes::Node)
+ theNode.CalculateGlobalVariables();
+
QT3DSVec3 theCenter = theNode.m_GlobalTransform.transform(theBounds.getCenter());
+
// Center the edit camera so that it points directly at the bounds center point
m_Translation->m_EditCameraInfo.m_Position = theCenter;
// Now we need to adjust the camera's zoom such that the view frustum contains the bounding