From 8c9027c6e583cd9512e591a9df3fb9236f6c8fa8 Mon Sep 17 00:00:00 2001 From: Jonathan Bosson Date: Fri, 17 Mar 2017 12:11:08 -0600 Subject: [PATCH] allow for multiple interaction modes (mostly roll and zoom) --- modules/touch/include/TouchInteraction.h | 11 +++- modules/touch/src/TouchInteraction.cpp | 71 +++++++++++++----------- 2 files changed, 48 insertions(+), 34 deletions(-) diff --git a/modules/touch/include/TouchInteraction.h b/modules/touch/include/TouchInteraction.h index fabf060ac8..ac3c238b94 100644 --- a/modules/touch/include/TouchInteraction.h +++ b/modules/touch/include/TouchInteraction.h @@ -66,6 +66,13 @@ struct ScaleFactor { double globalRoll; double localRoll; }; +struct InteractionType { + bool rot; + bool pinch; + bool pan; + bool roll; + bool pick; +}; using Point = std::pair; @@ -76,7 +83,7 @@ class TouchInteraction : public properties::PropertyOwner ~TouchInteraction(); void update(const std::vector& list, std::vector& lastProcessed); - int interpret(const std::vector& list, const std::vector& lastProcessed); + void interpret(const std::vector& list, const std::vector& lastProcessed); void step(double dt); void configSensitivities(double dist); void decelerate(); @@ -100,7 +107,7 @@ class TouchInteraction : public properties::PropertyOwner globebrowsing::RenderableGlobe* _globe; double _minHeightFromSurface; - int _interactionMode; + InteractionType _interactionMode; double _baseSensitivity; double _baseFriction; glm::dvec3 _centroid; diff --git a/modules/touch/src/TouchInteraction.cpp b/modules/touch/src/TouchInteraction.cpp index c03fe9850a..8bff8b473f 100644 --- a/modules/touch/src/TouchInteraction.cpp +++ b/modules/touch/src/TouchInteraction.cpp @@ -60,7 +60,7 @@ TouchInteraction::TouchInteraction() _vel{ 0.0, glm::dvec2(0.0), glm::dvec2(0.0), 0.0, 0.0 }, _friction{ _baseFriction, _baseFriction/2.0, _baseFriction, _baseFriction, _baseFriction/4.0 }, _centroid{ glm::dvec3(0.0) }, - _sensitivity{ 2.0, 0.1, 0.1, 0.1, 0.5 }, + _sensitivity{ 2.0, 0.1, 0.1, 0.1, 0.2 }, _minHeightFromSurface{ 0.0 } { _origin.onChange([this]() { @@ -79,18 +79,16 @@ TouchInteraction::~TouchInteraction() { } void TouchInteraction::update(const std::vector& list, std::vector& lastProcessed) { TuioCursor cursor = list.at(0); - _interactionMode = interpret(list, lastProcessed); - if (_interactionMode != ROT) { + interpret(list, lastProcessed); + if (!_interactionMode.rot) { _centroid.x = std::accumulate(list.begin(), list.end(), 0.0f, [](double x, const TuioCursor& c) { return x + c.getX(); }) / list.size(); _centroid.y = std::accumulate(list.begin(), list.end(), 0.0f, [](double y, const TuioCursor& c) { return y + c.getY(); }) / list.size(); } - switch (_interactionMode) { - case ROT: { // add rotation velocity + if (_interactionMode.rot) { // add rotation velocity _vel.globalRot += glm::dvec2(cursor.getXSpeed(), cursor.getYSpeed()) * _sensitivity.globalRot; - break; } - case PINCH: { // add zooming velocity + if (_interactionMode.pinch) { // add zooming velocity double distance = std::accumulate(list.begin(), list.end(), 0.0, [&](double d, const TuioCursor& c) { return d + c.getDistance(_centroid.x, _centroid.y); }); @@ -100,13 +98,11 @@ void TouchInteraction::update(const std::vector& list, std::vector

positionVec3(), _camera->focusPositionVec3()); _vel.zoom += zoomFactor * _sensitivity.zoom; - break; } - case PAN: { // add local rotation velocity + if (_interactionMode.pan) { // add local rotation velocity _vel.localRot += glm::dvec2(cursor.getXSpeed(), cursor.getYSpeed()) * _sensitivity.localRot; - break; } - case ROLL: { // add global roll rotation velocity + if (_interactionMode.roll) { // add global roll rotation velocity /*double rollFactor = std::accumulate(list.begin(), list.end(), 0.0, [](double s, const TuioCursor& c) { return s + c.getXSpeed(); });*/ @@ -121,7 +117,8 @@ void TouchInteraction::update(const std::vector& list, std::vector

getX(), cTemp->getY()); + glm::dvec2 thumb = _centroid; //glm::dvec2(cTemp->getX(), cTemp->getY()); + id = -1; double rollFactor = std::accumulate(list.begin(), list.end(), 0.0, [&](double diff, const TuioCursor& c) { TuioPoint point = find_if(lastProcessed.begin(), lastProcessed.end(), [&c](const Point& p) { return p.first == c.getSessionID(); })->second; double res = diff; @@ -135,21 +132,20 @@ void TouchInteraction::update(const std::vector& list, std::vector

0.2) + _vel.localRoll += -rollFactor * _sensitivity.localRoll; } - case PICK: { // pick something in the scene as focus node + if (_interactionMode.pick) { // pick something in the scene as focus node //if(!cursor.isMoving()) - break; - } - default: - LINFO("Couldn't interpret touch input" << "\n"); } + //default: + //LINFO("Couldn't interpret touch input" << "\n"); + //} } -int TouchInteraction::interpret(const std::vector& list, const std::vector& lastProcessed) { +void TouchInteraction::interpret(const std::vector& list, const std::vector& lastProcessed) { double dist = 0; double lastDist = 0; TuioCursor cursor = list.at(0); @@ -162,18 +158,29 @@ int TouchInteraction::interpret(const std::vector& list, const std:: dist += glm::length(glm::dvec2(p.second.getX(), p.second.getY()) - glm::dvec2(point.getX(), point.getY())); point = p.second; } - - if (list.size() == 1) - return ROT; - else { - if (std::abs(dist - lastDist) / list.size() < 0.1 && list.size() == 2) - return PAN; - else if (list.size() == 5) - return ROLL; - else - return PINCH; + if (list.size() == 1) { + _interactionMode.rot = true; + _interactionMode.pinch = false; + _interactionMode.pan = false; + _interactionMode.roll = false; + _interactionMode.pick = false; } - + else { + if (std::abs(dist - lastDist) / list.size() < 0.1 && list.size() == 2) { + _interactionMode.rot = false; + _interactionMode.pinch = false; + _interactionMode.pan = true; + _interactionMode.roll = false; + _interactionMode.pick = false; + } + else { + _interactionMode.rot = false; + _interactionMode.pinch = true; + _interactionMode.pan = false; + _interactionMode.roll = true; + _interactionMode.pick = false; + } + } } void TouchInteraction::step(double dt) { @@ -276,7 +283,7 @@ void TouchInteraction::configSensitivities(double dist) { _sensitivity.globalRot = 0.1; _sensitivity.localRot = 0.1; _sensitivity.globalRoll = 0.1; - _sensitivity.localRoll = 0.5; + _sensitivity.localRoll = 0.2; }