diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-06-26 15:19:03 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2019-06-28 16:48:13 +0300 |
commit | 86f94b5c836244e1c0c74f34c92efd28fba9f03f (patch) | |
tree | 114774e8a66fc1d0f95dbc4b679fc8fc1c2187ef | |
parent | f1f2afc17083eae1979b67d6d22f40bca13075e9 (diff) |
Stop adjusting properties if drag plane intersection goes behind camera
When doing widget drags, depending on the widget orientation, the drag
plane can be such that mouse cursor position and drag plane
intersection can sometimes be behind the camera. These cases manifest
in sudden flipping of sign of dragged property values, which is not
desirable. The issue is fixed by preventing property adjustment when
intersection is behind camera.
Task-number: QT3DS-3521
Change-Id: I25a3b73e9e0dc819be22b0585013c49c7046e2b1
Reviewed-by: Janne Koskinen <janne.p.koskinen@qt.io>
-rw-r--r-- | src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp | 24 | ||||
-rw-r--r-- | src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h | 1 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp index 13413793..ecb30a61 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.cpp @@ -3725,6 +3725,23 @@ STranslation::PrepareWidgetDrag(qt3ds::widgets::StudioWidgetComponentIds::Enum i retval.m_OriginalPlaneCoords = theOriginalRay.Intersect(retval.m_Plane); retval.m_CurrentPlaneCoords = theCurrentRay.Intersect(retval.m_Plane); retval.m_PreviousPlaneCoords = thePreviousRay.Intersect(retval.m_Plane); + + // Resolve t-value from current ray intersection calculation + // Its sign indicates the position relative to the camera + float t = 0.f; + + // Ray direction is normalized, so one of the components must be > .1f + if (qAbs(theCurrentRay.m_Direction.x) > .1f) { + t = (retval.m_CurrentPlaneCoords->x - theCurrentRay.m_Origin.x) + / theCurrentRay.m_Direction.x; + } else if (qAbs(theCurrentRay.m_Direction.y) > .1f) { + t = (retval.m_CurrentPlaneCoords->y - theCurrentRay.m_Origin.y) + / theCurrentRay.m_Direction.y; + } else if (qAbs(theCurrentRay.m_Direction.z) > .1f) { + t = (retval.m_CurrentPlaneCoords->z - theCurrentRay.m_Origin.z) + / theCurrentRay.m_Direction.z; + } + retval.m_isBehindCamera = t < 0; return retval; } @@ -3747,6 +3764,7 @@ void STranslation::PerformWidgetDrag(int inWidgetSubComponent, CPt inOriginalCoo Option<QT3DSVec3> theCurrentPlaneCoords(thePrepResult->m_CurrentPlaneCoords); QT3DSVec3 globalPos(thePrepResult->m_GlobalPos); bool isPlane(thePrepResult->m_IsPlane); + bool isBehindCamera(thePrepResult->m_isBehindCamera); QT3DSVec3 theAxis(thePrepResult->m_Axis); QT3DSU32 axisIndex(thePrepResult->m_AxisIndex); SNode *theNode(thePrepResult->m_Node); @@ -3761,7 +3779,8 @@ void STranslation::PerformWidgetDrag(int inWidgetSubComponent, CPt inOriginalCoo QT3DS_ASSERT(false); return; case qt3ds::widgets::StudioWidgetTypes::Scale: { - if (theOriginalPlaneCoords.hasValue() && theCurrentPlaneCoords.hasValue()) { + if (theOriginalPlaneCoords.hasValue() && theCurrentPlaneCoords.hasValue() + && !isBehindCamera) { QT3DSVec3 objToOriginal = globalPos - *theOriginalPlaneCoords; QT3DSVec3 objToCurrent = globalPos - *theCurrentPlaneCoords; QT3DSVec3 theScaleMultiplier(1, 1, 1); @@ -3879,7 +3898,8 @@ void STranslation::PerformWidgetDrag(int inWidgetSubComponent, CPt inOriginalCoo } } break; case qt3ds::widgets::StudioWidgetTypes::Translation: { - if (theOriginalPlaneCoords.hasValue() && theCurrentPlaneCoords.hasValue()) { + if (theOriginalPlaneCoords.hasValue() && theCurrentPlaneCoords.hasValue() + && !isBehindCamera) { QT3DSVec3 theDiff = *theCurrentPlaneCoords - *theOriginalPlaneCoords; if (isPlane) { ApplyPositionalChange(theDiff, *theNode, inEditor); diff --git a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h index 2d3e965a..86e39cdb 100644 --- a/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h +++ b/src/Authoring/Qt3DStudio/Render/StudioRendererTranslation.h @@ -326,6 +326,7 @@ namespace studio { Option<QT3DSVec3> m_CurrentPlaneCoords; Option<QT3DSVec3> m_PreviousPlaneCoords; bool m_IsPlane; + bool m_isBehindCamera; SDragPreparationResult() {} }; |