From 843a4db650110ac242e2e6a2c70b4dfd4dcc97c0 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 Jul 2014 13:50:27 -0700 Subject: [PATCH 1/4] rotation offset for hydra controllers --- interface/src/devices/SixenseManager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 1b7baf2ee1..b0e49013b3 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -154,6 +154,11 @@ void SixenseManager::update(float deltaTime) { // no latency. float velocityFilter = glm::clamp(1.0f - glm::length(rawVelocity), 0.0f, 1.0f); palm->setRawPosition(palm->getRawPosition() * velocityFilter + position * (1.0f - velocityFilter)); + + // adjustment for hydra controllers fit into hands + float sign = (i == 0) ? -1.0f : 1.0f; + rotation *= glm::angleAxis(sign * PI/4.0f, glm::vec3(0.0f, 0.0f, 1.0f)); + palm->setRawRotation(safeMix(palm->getRawRotation(), rotation, 1.0f - velocityFilter)); // use the velocity to determine whether there's any movement (if the hand isn't new) From 0f7859bf83ef139b757d3ae9c011260c4a1cb091 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 Jul 2014 14:09:14 -0700 Subject: [PATCH 2/4] fix return to default pose after hydra disconnect --- interface/src/devices/SixenseManager.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index b0e49013b3..7cdd2a64ae 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -71,6 +71,15 @@ void SixenseManager::setFilter(bool filter) { void SixenseManager::update(float deltaTime) { #ifdef HAVE_SIXENSE + // if the controllers haven't been moved in a while, disable + const unsigned int MOVEMENT_DISABLE_SECONDS = 3; + if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) { + Hand* hand = Application::getInstance()->getAvatar()->getHand(); + for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { + it->setActive(false); + } + } + if (sixenseGetNumActiveControllers() == 0) { _hydrasConnected = false; return; @@ -185,14 +194,6 @@ void SixenseManager::update(float deltaTime) { if (numActiveControllers == 2) { updateCalibration(controllers); } - - // if the controllers haven't been moved in a while, disable - const unsigned int MOVEMENT_DISABLE_SECONDS = 3; - if (usecTimestampNow() - _lastMovement > (MOVEMENT_DISABLE_SECONDS * USECS_PER_SECOND)) { - for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { - it->setActive(false); - } - } #endif // HAVE_SIXENSE } From 662136f01c4936e18aa2ef425c782bf3887a15d2 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Thu, 3 Jul 2014 14:13:27 -0700 Subject: [PATCH 3/4] reset timer as optimization --- interface/src/devices/SixenseManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 7cdd2a64ae..c50fc887d6 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -78,6 +78,7 @@ void SixenseManager::update(float deltaTime) { for (std::vector::iterator it = hand->getPalms().begin(); it != hand->getPalms().end(); it++) { it->setActive(false); } + _lastMovement = usecTimestampNow(); } if (sixenseGetNumActiveControllers() == 0) { From 8e1b8334a1f084cb5a00f3580ec5c08056afe552 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Thu, 3 Jul 2014 14:46:17 -0700 Subject: [PATCH 4/4] Fixed invokeMethod unable to find method + fixed children in different thread --- assignment-client/src/Agent.cpp | 11 +++++++---- interface/src/Application.cpp | 11 +++++++---- libraries/networking/src/NetworkAccessManager.cpp | 12 ++++++++++++ libraries/networking/src/NetworkAccessManager.h | 5 ++++- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/assignment-client/src/Agent.cpp b/assignment-client/src/Agent.cpp index fcd983873d..4a3346fc83 100644 --- a/assignment-client/src/Agent.cpp +++ b/assignment-client/src/Agent.cpp @@ -210,12 +210,15 @@ void Agent::run() { NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); QNetworkReply *reply = networkAccessManager.get(QNetworkRequest(scriptURL)); - QNetworkDiskCache* cache = new QNetworkDiskCache(&networkAccessManager); + + // Make sure cache on same thread than its parent (NetworkAccessManager) + QNetworkDiskCache* cache = new QNetworkDiskCache(); + cache->moveToThread(networkAccessManager.thread()); + cache->setParent(&networkAccessManager); + QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation); cache->setCacheDirectory(!cachePath.isEmpty() ? cachePath : "agentCache"); - QMetaObject::invokeMethod(&networkAccessManager, "setCache", - Qt::BlockingQueuedConnection, - Q_ARG(QAbstractNetworkCache*, cache)); + networkAccessManager.setCache(cache); qDebug() << "Downloading script at" << scriptURL.toString(); diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9b2ed7b63d..c263b71238 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -316,11 +316,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : QString cachePath = QStandardPaths::writableLocation(QStandardPaths::DataLocation); NetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance(); - QNetworkDiskCache* cache = new QNetworkDiskCache(&networkAccessManager); + + // Make sure cache on same thread than its parent (NetworkAccessManager) + QNetworkDiskCache* cache = new QNetworkDiskCache(); + cache->moveToThread(networkAccessManager.thread()); + cache->setParent(&networkAccessManager); + cache->setCacheDirectory(!cachePath.isEmpty() ? cachePath : "interfaceCache"); - QMetaObject::invokeMethod(&networkAccessManager, "setCache", - Qt::BlockingQueuedConnection, - Q_ARG(QAbstractNetworkCache*, cache)); + networkAccessManager.setCache(cache); ResourceCache::setRequestLimit(3); diff --git a/libraries/networking/src/NetworkAccessManager.cpp b/libraries/networking/src/NetworkAccessManager.cpp index b9eda27947..c2b4bfcd11 100644 --- a/libraries/networking/src/NetworkAccessManager.cpp +++ b/libraries/networking/src/NetworkAccessManager.cpp @@ -10,6 +10,7 @@ // #include +#include #include #include "NetworkAccessManager.h" @@ -146,4 +147,15 @@ QNetworkReply* NetworkAccessManager::sendCustomRequest(const QNetworkRequest& re return result; } return QNetworkAccessManager::sendCustomRequest(request, verb, data); +} + +void NetworkAccessManager::setCache(QAbstractNetworkCache* cache) { + if (QThread::currentThread() != thread()) { + qRegisterMetaType(); + QMetaObject::invokeMethod(this, + "setCache", + Qt::QueuedConnection, + Q_ARG(QAbstractNetworkCache*, cache)); + } + QNetworkAccessManager::setCache(cache); } \ No newline at end of file diff --git a/libraries/networking/src/NetworkAccessManager.h b/libraries/networking/src/NetworkAccessManager.h index ba97f12552..1b49cc9dee 100644 --- a/libraries/networking/src/NetworkAccessManager.h +++ b/libraries/networking/src/NetworkAccessManager.h @@ -18,7 +18,9 @@ /// Wrapper around QNetworkAccessManager wo that we only use one instance /// For any other method you should need, make sure to be on the right thread -/// or call the method using QMetaObject::invokeMethod() +/// or if it is not but is a slot, use QMetaObject::invokeMethod() +/// In the case what you want to call isn't a slot and you aren't on the same thread, +/// then add then method to the method to the wrapper with the Q_INVKABLE flag class NetworkAccessManager : public QNetworkAccessManager { Q_OBJECT public: @@ -33,6 +35,7 @@ public: Q_INVOKABLE QNetworkReply* put(const QNetworkRequest& request, QHttpMultiPart* multiPart); Q_INVOKABLE QNetworkReply* put(const QNetworkRequest& request, const QByteArray& data); Q_INVOKABLE QNetworkReply* sendCustomRequest(const QNetworkRequest& request, const QByteArray& verb, QIODevice* data = 0); + Q_INVOKABLE void setCache(QAbstractNetworkCache* cache); private: NetworkAccessManager();