diff --git a/cmake/android/AndroidManifest.xml.in b/cmake/android/AndroidManifest.xml.in index 32c657444b..3f231d427c 100755 --- a/cmake/android/AndroidManifest.xml.in +++ b/cmake/android/AndroidManifest.xml.in @@ -52,7 +52,7 @@ android:launchMode="singleTask" android:screenOrientation="landscape" android:configChanges="screenSize|orientation|keyboardHidden|keyboard"> --> - + diff --git a/gvr-interface/src/RenderingClient.cpp b/gvr-interface/src/RenderingClient.cpp index ed0716d4da..3feb340407 100644 --- a/gvr-interface/src/RenderingClient.cpp +++ b/gvr-interface/src/RenderingClient.cpp @@ -17,9 +17,13 @@ #include "RenderingClient.h" +RenderingClient* RenderingClient::_instance = NULL; + RenderingClient::RenderingClient(QObject *parent) : Client(parent) { + _instance = this; + // tell the NodeList which node types all rendering clients will want to know about DependencyManager::get()->addSetOfNodeTypesToNodeInterestSet(NodeSet() << NodeType::AudioMixer); @@ -27,6 +31,9 @@ RenderingClient::RenderingClient(QObject *parent) : QThread* audioThread = new QThread(this); auto audioClient = DependencyManager::set(); + audioClient->setPositionGetter(getPositionForAudio); + audioClient->setOrientationGetter(getOrientationForAudio); + audioClient->moveToThread(audioThread); connect(audioThread, &QThread::started, audioClient.data(), &AudioClient::start); @@ -83,4 +90,35 @@ void RenderingClient::processVerifiedPacket(const HifiSockAddr& senderSockAddr, Client::processVerifiedPacket(senderSockAddr, incomingPacket); break; } +} + +void RenderingClient::goToLocation(const glm::vec3& newPosition, + bool hasOrientationChange, const glm::quat& newOrientation, + bool shouldFaceLocation) { + qDebug().nospace() << "RenderingClient goToLocation - moving to " << newPosition.x << ", " + << newPosition.y << ", " << newPosition.z; + + glm::vec3 shiftedPosition = newPosition; + + if (hasOrientationChange) { + qDebug().nospace() << "RenderingClient goToLocation - new orientation is " + << newOrientation.x << ", " << newOrientation.y << ", " << newOrientation.z << ", " << newOrientation.w; + + // orient the user to face the target + 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 + const float DISTANCE_TO_USER = 2.0f; + shiftedPosition = newPosition - quatOrientation * glm::vec3( 0.0f, 0.0f,-1.0f) * DISTANCE_TO_USER; + } + + _orientation = quatOrientation; + } + + _position = shiftedPosition; + } \ No newline at end of file diff --git a/gvr-interface/src/RenderingClient.h b/gvr-interface/src/RenderingClient.h index f20b567548..dad70699e3 100644 --- a/gvr-interface/src/RenderingClient.h +++ b/gvr-interface/src/RenderingClient.h @@ -13,6 +13,9 @@ #ifndef hifi_RenderingClient_h #define hifi_RenderingClient_h +#include +#include + #include "Client.h" class RenderingClient : public Client { @@ -20,8 +23,24 @@ class RenderingClient : public Client { public: RenderingClient(QObject* parent = 0); ~RenderingClient(); + + const glm::vec3& getPosition() const { return _position; } + const glm::quat& getOrientation() const { return _orientation; } + + static glm::vec3 getPositionForAudio() { return _instance->getPosition(); } + static glm::quat getOrientationForAudio() { return _instance->getOrientation(); } + +private slots: + void goToLocation(const glm::vec3& newPosition, + bool hasOrientationChange, const glm::quat& newOrientation, + bool shouldFaceLocation); private: virtual void processVerifiedPacket(const HifiSockAddr& senderSockAddr, const QByteArray& incomingPacket); + + static RenderingClient* _instance; + + glm::vec3 _position; + glm::quat _orientation; }; #endif // hifi_RenderingClient_h