From 866f2005bd2ccd13c083560226842c34504870fc Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 16 Sep 2014 10:08:21 -0700 Subject: [PATCH] handle case where a location should be faced --- interface/src/avatar/MyAvatar.cpp | 1 + libraries/networking/src/AddressManager.cpp | 10 ++++++---- libraries/networking/src/AddressManager.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 66a867ec0f..9eb6589306 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1783,6 +1783,7 @@ void MyAvatar::goToLocation(const glm::vec3& newPosition, glm::quat quatOrientation = newOrientation; if (shouldFaceLocation) { + quatOrientation = newOrientation * glm::angleAxis(PI, glm::vec3(0.0f, 1.0f, 0.0f)); // move the user a couple units away diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 400121a49b..8ea6d1107a 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -132,9 +132,11 @@ void AddressManager::handleAPIResponse(const QJsonObject &jsonObject) { returnedPath = domainObject[LOCATION_KEY].toObject()[LOCATION_PATH_KEY].toString(); } + bool shouldFaceViewpoint = dataObject.contains(ADDRESS_API_ONLINE_KEY); + if (!returnedPath.isEmpty()) { // try to parse this returned path as a viewpoint, that's the only thing it could be for now - if (!handleRelativeViewpoint(returnedPath)) { + if (!handleRelativeViewpoint(returnedPath, shouldFaceViewpoint)) { qDebug() << "Received a location path that was could not be handled as a viewpoint -" << returnedPath; } } @@ -191,7 +193,7 @@ bool AddressManager::handleNetworkAddress(const QString& lookupString) { return false; } -bool AddressManager::handleRelativeViewpoint(const QString& lookupString) { +bool AddressManager::handleRelativeViewpoint(const QString& lookupString, bool shouldFace) { const QString FLOAT_REGEX_STRING = "([-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?)"; const QString SPACED_COMMA_REGEX_STRING = "\\s*,\\s*"; const QString POSITION_REGEX_STRING = QString("\\/") + FLOAT_REGEX_STRING + SPACED_COMMA_REGEX_STRING + @@ -224,14 +226,14 @@ bool AddressManager::handleRelativeViewpoint(const QString& lookupString) { if (!isNaN(newOrientation.x) && !isNaN(newOrientation.y) && !isNaN(newOrientation.z) && !isNaN(newOrientation.w)) { - emit locationChangeRequired(newPosition, true, newOrientation, false); + emit locationChangeRequired(newPosition, true, newOrientation, shouldFace); return true; } else { qDebug() << "Orientation parsed from lookup string is invalid. Will not use for location change."; } } - emit locationChangeRequired(newPosition, false, newOrientation, false); + emit locationChangeRequired(newPosition, false, newOrientation, shouldFace); } else { qDebug() << "Could not jump to position from lookup string because it has an invalid value."; diff --git a/libraries/networking/src/AddressManager.h b/libraries/networking/src/AddressManager.h index ef97b59a1b..2590e8f80c 100644 --- a/libraries/networking/src/AddressManager.h +++ b/libraries/networking/src/AddressManager.h @@ -49,7 +49,7 @@ private: bool handleUrl(const QUrl& lookupUrl); bool handleNetworkAddress(const QString& lookupString); - bool handleRelativeViewpoint(const QString& pathSubsection); + bool handleRelativeViewpoint(const QString& pathSubsection, bool shouldFace = false); bool handleUsername(const QString& lookupString); };