diff options
author | Marianne Yrjänä <marianne.yrjana@qt.io> | 2018-04-19 09:42:01 +0300 |
---|---|---|
committer | Marianne Yrjänä <marianne.yrjana@qt.io> | 2018-04-19 12:11:57 +0000 |
commit | 6b3abff1e16666eb90c03dd7c54b777ced7b898d (patch) | |
tree | b1da4fd17f17231a21bd24c60f2ec7f37407615c /src/Authoring/Studio/Render/StudioRendererTranslation.cpp | |
parent | 6570e1c866a6d7fdb261ae2dd032529a15366718 (diff) |
Fix drag getting stuck
In some cases when searching better angle for drag the object
got moved further away from camera instead of bringing it closer.
Task-number: QT3DS-66
Change-Id: I44d88da4b7000e122e1098f324c524908f298b6b
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'src/Authoring/Studio/Render/StudioRendererTranslation.cpp')
-rw-r--r-- | src/Authoring/Studio/Render/StudioRendererTranslation.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp index 0d150027..6ce0e260 100644 --- a/src/Authoring/Studio/Render/StudioRendererTranslation.cpp +++ b/src/Authoring/Studio/Render/StudioRendererTranslation.cpp @@ -3357,12 +3357,18 @@ STranslation::PrepareWidgetDrag(qt3ds::widgets::StudioWidgetComponentIds::Enum i theAxis.normalize(); QT3DSVec3 theCameraToObj = globalPos - camGlobalPos; QT3DSVec3 theTemp = theAxis.cross(theOriginalRay.m_Direction); - // Then the axis is parallel to the camera, we can't drag meaningfullly + // When the axis is parallel to the camera, we can't drag meaningfully if (theTemp.magnitudeSquared() < .05f) { // Attempt to find a better axis by moving the object back towards the camera. QT3DSF32 theSign = theCameraToObj.dot(theCamDirection) > 0.0 ? -1.0f : 1.0f; QT3DSF32 theDistance = theCameraToObj.dot(theCamDirection); QT3DSVec3 thePoint = globalPos + (theDistance * theSign) * theAxis; + // Check if we actually moved to right direction + QT3DSVec3 theNewCameraToObj = thePoint - camGlobalPos; + QT3DSF32 theNewDistance = theNewCameraToObj.dot(theCamDirection); + if (theNewDistance > theDistance) + thePoint = globalPos - (theDistance * theSign) * theAxis; + QT3DSVec3 theNewDir = thePoint - camGlobalPos; theNewDir.normalize(); theTemp = theAxis.cross(theNewDir); |