diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c403a3c3dc..17e435e2ea 100755 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1727,9 +1727,8 @@ bool Application::isLookingAtOtherAvatar(glm::vec3 &mouseRayOrigin, glm::vec3 &m if (node->getLinkedData() != NULL && node->getType() == NODE_TYPE_AGENT) { Avatar *avatar = (Avatar *)node->getLinkedData(); glm::vec3 headPosition = avatar->getHead().getPosition(); - glm::vec3 intersectionPosition, intersectionNormal; printf("x: %f y: %f z: %f \n", mouseRayOrigin.x, mouseRayOrigin.y, mouseRayOrigin.z); - if (glm::intersectRaySphere(mouseRayOrigin, mouseRayDirection, headPosition, 10, intersectionPosition, intersectionNormal)) { + if (rayIntersectsSphere(mouseRayOrigin, mouseRayDirection, headPosition, 0.07)) { printf("lalala\n"); eyePosition = avatar->getHead().getEyeLevelPosition(); return true; @@ -1760,8 +1759,6 @@ void Application::update(float deltaTime) { glm::vec3 mouseRayOrigin, mouseRayDirection; _viewFrustum.computePickRay(_mouseX / (float)_glWidget->width(), _mouseY / (float)_glWidget->height(), mouseRayOrigin, mouseRayDirection); - // printf("x: %d y: %d \n", _mouseX, _mouseY); - // printf("x: %f y: %f z: %f \n", mouseRayOrigin.x, mouseRayOrigin.y, mouseRayOrigin.z); // tell my avatar the posiion and direction of the ray projected ino the world based on the mouse position _myAvatar.setMouseRay(mouseRayOrigin, mouseRayDirection); diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 4bfdb1f587..3e961cd43f 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -509,3 +509,13 @@ float loadSetting(QSettings* settings, const char* name, float defaultValue) { } return value; } + +bool rayIntersectsSphere(glm::vec3 &rayStarting, glm::vec3 &rayNormalizedDirection, glm::vec3 &sphereCenter, double sphereRadius) { + glm::vec3 vecFromRayToSphereCenter = sphereCenter - rayStarting; + double projection = glm::dot(vecFromRayToSphereCenter, rayNormalizedDirection); + double shortestDistance = sqrt(glm::dot(vecFromRayToSphereCenter, vecFromRayToSphereCenter) - projection*projection); + if (shortestDistance <= sphereRadius) { + return true; + } + return false; +} \ No newline at end of file diff --git a/interface/src/Util.h b/interface/src/Util.h index 2005b76438..6a4a25995c 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -71,4 +71,6 @@ void runTimingTests(); float loadSetting(QSettings* settings, const char* name, float defaultValue); +bool rayIntersectsSphere(glm::vec3 &rayStarting, glm::vec3 &rayNormalizedDirection, glm::vec3 &sphereCenter, double sphereRadius); + #endif