diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f4b9b0999a..b369edb812 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2252,7 +2252,7 @@ Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3 if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { Avatar* avatar = (Avatar *) node->getLinkedData(); glm::vec3 headPosition = avatar->getHead().getPosition(); - if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS)) { + if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, HEAD_SPHERE_RADIUS * avatar->getScale())) { eyePosition = avatar->getHead().getEyePosition(); _lookatIndicatorScale = avatar->getScale(); _lookatOtherPosition = headPosition; @@ -2264,6 +2264,16 @@ Avatar* Application::isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3 return NULL; } +bool Application::isLookingAtMyAvatar(Avatar* avatar) { + glm::vec3 theirLookat = avatar->getHead().getLookAtPosition(); + glm::vec3 myHeadPosition = _myAvatar.getHead().getPosition(); + + if (pointInSphere(theirLookat, myHeadPosition, HEAD_SPHERE_RADIUS * _myAvatar.getScale())) { + return true; + } + return false; +} + void Application::renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera) { const float DISTANCE_FROM_HEAD_SPHERE = 0.1f * _lookatIndicatorScale; @@ -3013,6 +3023,9 @@ void Application::displaySide(Camera& whichCamera) { if (!avatar->isInitialized()) { avatar->init(); } + if (isLookingAtMyAvatar(avatar)) { + avatar->getHead().setLookAtPosition(_myCamera.getPosition()); + } avatar->render(false, _renderAvatarBalls->isChecked()); avatar->setDisplayingLookatVectors(_renderLookatOn->isChecked()); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 1e84de91e8..36d90c9b19 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -212,6 +212,7 @@ private: void update(float deltaTime); Avatar* isLookingAtOtherAvatar(glm::vec3& mouseRayOrigin, glm::vec3& mouseRayDirection, glm::vec3& eyePosition, uint16_t& nodeID); + bool isLookingAtMyAvatar(Avatar* avatar); void renderLookatIndicator(glm::vec3 pointOfInterest, Camera& whichCamera); void updateAvatar(float deltaTime); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 61b9b2d7ca..743957128c 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -607,3 +607,12 @@ bool rayIntersectsSphere(glm::vec3& rayStarting, glm::vec3& rayNormalizedDirecti } return false; } + +bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadius) { + glm::vec3 diff = point - sphereCenter; + double mag = sqrt(glm::dot(diff, diff)); + if (mag <= sphereRadius) { + return true; + } + return false; +} \ No newline at end of file diff --git a/interface/src/Util.h b/interface/src/Util.h index 6fc797e3e3..c1bb2949fa 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -76,4 +76,6 @@ float loadSetting(QSettings* settings, const char* name, float defaultValue); bool rayIntersectsSphere(glm::vec3& rayStarting, glm::vec3& rayNormalizedDirection, glm::vec3& sphereCenter, double sphereRadius); +bool pointInSphere(glm::vec3& point, glm::vec3& sphereCenter, double sphereRadius); + #endif