diff --git a/modules/touch/src/touchinteraction.cpp b/modules/touch/src/touchinteraction.cpp index 36d30b6154..367fef5668 100644 --- a/modules/touch/src/touchinteraction.cpp +++ b/modules/touch/src/touchinteraction.cpp @@ -277,8 +277,8 @@ TouchInteraction::TouchInteraction() 0.25f ) , _zoomBoundarySphereMultiplier(ZoomBoundarySphereMultiplierInfo, 1.001f, 1.f, 1.01f) - , _zoomOutLimit(ZoomOutLimitInfo, std::numeric_limits::max(), 1000.0f, std::numeric_limits::max()) - , _zoomInLimit(ZoomInLimitInfo, -1.0f, 0.0f, std::numeric_limits::max()) + , _zoomOutLimit(ZoomOutLimitInfo, std::numeric_limits::max(), 1000.0, std::numeric_limits::max()) + , _zoomInLimit(ZoomInLimitInfo, -1.0, 0.0, std::numeric_limits::max()) , _inputStillThreshold(InputSensitivityInfo, 0.0005f, 0.f, 0.001f) // used to void wrongly interpreted roll interactions , _centroidStillThreshold(StationaryCentroidInfo, 0.0018f, 0.f, 0.01f) @@ -1024,7 +1024,7 @@ void TouchInteraction::step(double dt) { const double boundingSphere = anchor->boundingSphere(); const double distance = std::max(length(centerToCamera) - boundingSphere, 0.0); - _currentRadius = boundingSphere / + _currentRadius = boundingSphere / std::max(distance * _projectionScaleFactor, 1.0); { @@ -1069,13 +1069,11 @@ void TouchInteraction::step(double dt) { // Zooming // This is a rough estimate of the node surface - const double zoomInBounds = boundingSphere * _zoomBoundarySphereMultiplier; + // If nobody has set another zoom in limit, use this as default zoom in bounds + double zoomInBounds = boundingSphere * _zoomBoundarySphereMultiplier; + bool isZoomInLimitSet = (_zoomInLimit.value() >= 0.0); - // If nobody has set another zoom in limit, use the default zoom in bounds - if (_zoomInLimit.value() < 0) { - _zoomInLimit.setValue(zoomInBounds); - } - else if (_zoomInLimit.value() < zoomInBounds) { + if (isZoomInLimitSet && _zoomInLimit.value() < zoomInBounds) { // If zoom in limit is less than the estimated node radius we need to // make sure we do not get too close to possible height maps SurfacePositionHandle posHandle = anchor->calculateSurfacePositionHandle( @@ -1094,12 +1092,12 @@ void TouchInteraction::step(double dt) { LINFO(fmt::format("{}: Zoom In limit should be larger than anchor " "center to surface, setting it to {}", _loggerCat, zoomInBounds)); #endif - _zoomInLimit.setValue(zoomInBounds); + zoomInBounds = _zoomInLimit.value(); } } // Make sure zoom in limit is not larger than zoom out limit - if (_zoomInLimit.value() > _zoomOutLimit.value()) { + if (zoomInBounds > _zoomOutLimit.value()) { LWARNING(fmt::format( "{}: Zoom In Limit should be smaller than Zoom Out Limit", _loggerCat, _zoomOutLimit.value() @@ -1116,10 +1114,11 @@ void TouchInteraction::step(double dt) { (currentPosDistance >= _zoomOutLimit.value()); const bool willNewPositionViolateZoomOutLimit = (newPosDistance >= _zoomOutLimit.value()); - const bool willNewPositionViolateZoomInLimit = - (newPosDistance < _zoomInLimit.value()); + bool willNewPositionViolateZoomInLimit = + (newPosDistance < zoomInBounds); - if (!willNewPositionViolateZoomInLimit && !willNewPositionViolateZoomOutLimit){ + if (!willNewPositionViolateZoomInLimit + && !willNewPositionViolateZoomOutLimit) { camPos += zoomDistanceIncrement; } else if (currentPosViolatingZoomOutLimit) { diff --git a/modules/touch/touchmodule.cpp b/modules/touch/touchmodule.cpp index a436f1107a..721d2280ac 100644 --- a/modules/touch/touchmodule.cpp +++ b/modules/touch/touchmodule.cpp @@ -42,9 +42,13 @@ using namespace TUIO; namespace { - constexpr const double ONE_MS = 0.001; -} // namespace - + constexpr openspace::properties::Property::PropertyInfo TouchActiveInfo = { + "TouchActive", + "True if we want to use touch input as 3d navigation", + "Use this if we want to turn on or off Touch input navigation. " + "Disabling this will reset all current touch inputs to the navigation. " + }; +} namespace openspace { bool TouchModule::processNewInput() { @@ -157,7 +161,7 @@ void TouchModule::removeTouchInput(TouchInput input) { //Magic values taken from tuioear.cpp: const bool isWithinTapTime = totalTime < 0.18; const bool wasStationary = totalDistance < 0.0004f; - if (isWithinTapTime && wasStationary && _touchPoints.size() == 1 && + if (isWithinTapTime && wasStationary && _touchPoints.size() == 1 && _deferredRemovals.size() == 1) { _tap = true; @@ -169,9 +173,15 @@ void TouchModule::removeTouchInput(TouchInput input) { TouchModule::TouchModule() : OpenSpaceModule("Touch") + , _touchActive(TouchActiveInfo, true) { addPropertySubOwner(_touch); addPropertySubOwner(_markers); + addProperty(_touchActive); + _touchActive.onChange([&] { + _touch.resetAfterInput(); + _lastTouchInputs.clear(); + }); } TouchModule::~TouchModule() { @@ -224,7 +234,7 @@ void TouchModule::internalInitialize(const ghoul::Dictionary& /*dictionary*/){ _touch.setCamera(global::navigationHandler.camera()); _touch.setFocusNode(global::navigationHandler.orbitalNavigator().anchorNode()); - if (processNewInput() && global::windowDelegate.isMaster()) { + if (processNewInput() && global::windowDelegate.isMaster() && _touchActive) { _touch.updateStateFromInput(_touchPoints, _lastTouchInputs); } else if (_touchPoints.empty()) { diff --git a/modules/touch/touchmodule.h b/modules/touch/touchmodule.h index f32b28d854..9ce8b73f92 100644 --- a/modules/touch/touchmodule.h +++ b/modules/touch/touchmodule.h @@ -64,6 +64,7 @@ private: std::vector _deferredRemovals; std::vector _lastTouchInputs; + properties::BoolProperty _touchActive; // contains an id and the Point that was processed last frame glm::ivec2 _webPositionCallback = glm::ivec2(0,0); #ifdef WIN32