From 261ba65ad6497184dc77c1e49872d92884bb3f8b Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Tue, 11 Sep 2018 12:01:48 +0300 Subject: Fix focusing non-physical objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Mahmoud Badri Reviewed-by: Tomi Korpipää --- src/Authoring/Studio/Render/StudioRenderer.cpp | 22 +++++++++++++++++++--- 1 file 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( 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 -- cgit v1.2.3