diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 8d053a4d66..d883aafe2c 100755 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -652,13 +652,12 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic PROFILE_RANGE(simulation_physics, __FUNCTION__); float distance = (float)INT_MAX; // with FLT_MAX bullet rayTest does not return results - - std::vector physicsResults = _myAvatar->getCharacterController()->rayTest(glmToBullet(ray.origin), glmToBullet(ray.direction), distance, QVector()); - + glm::vec3 rayDirection = glm::normalize(ray.direction); + std::vector physicsResults = _myAvatar->getCharacterController()->rayTest(glmToBullet(ray.origin), glmToBullet(rayDirection), distance, QVector()); if (physicsResults.size() > 0) { - glm::vec3 rayDirectionInv = { ray.direction.x != 0 ? 1.0f / ray.direction.x : INFINITY, - ray.direction.y != 0.0f ? 1.0f / ray.direction.y : INFINITY, - ray.direction.z != 0.0f ? 1.0f / ray.direction.z : INFINITY }; + glm::vec3 rayDirectionInv = { rayDirection.x != 0.0f ? 1.0f / rayDirection.x : INFINITY, + rayDirection.y != 0.0f ? 1.0f / rayDirection.y : INFINITY, + rayDirection.z != 0.0f ? 1.0f / rayDirection.z : INFINITY }; MyCharacterController::RayAvatarResult rayAvatarResult; AvatarPointer avatar = nullptr; @@ -697,12 +696,12 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic BoxFace face; glm::vec3 surfaceNormal; auto &bbox = mSphere.getBoundingBox(); - if (bbox.findRayIntersection(ray.origin, ray.direction, rayDirectionInv, boundDistance, face, surfaceNormal)) { + if (bbox.findRayIntersection(ray.origin, rayDirection, rayDirectionInv, boundDistance, face, surfaceNormal)) { MyCharacterController::RayAvatarResult boxHit; boxHit._distance = boundDistance; boxHit._intersect = true; boxHit._intersectionNormal = surfaceNormal; - boxHit._intersectionPoint = ray.origin + boundDistance * glm::normalize(ray.direction); + boxHit._intersectionPoint = ray.origin + boundDistance * rayDirection; boxHit._intersectWithAvatar = avatarID; boxHit._intersectWithJoint = mSphere.getJointIndex(); boxHits.push_back(boxHit); @@ -722,7 +721,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic } if (pickAgainstMesh) { glm::vec3 localRayOrigin = avatar->worldToJointPoint(ray.origin, rayAvatarResult._intersectWithJoint); - glm::vec3 localRayPoint = avatar->worldToJointPoint(ray.origin + ray.direction, rayAvatarResult._intersectWithJoint); + glm::vec3 localRayPoint = avatar->worldToJointPoint(ray.origin + rayDirection, rayAvatarResult._intersectWithJoint); auto avatarOrientation = avatar->getWorldOrientation(); auto avatarPosition = avatar->getWorldPosition(); @@ -737,7 +736,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic if (avatar->getSkeletonModel()->findRayIntersectionAgainstSubMeshes(defaultFrameRayOrigin, defaultFrameRayDirection, distance, face, surfaceNormal, extraInfo, true, false)) { auto newDistance = glm::length(vec3FromVariant(extraInfo["worldIntersectionPoint"]) - defaultFrameRayOrigin); rayAvatarResult._distance = newDistance; - rayAvatarResult._intersectionPoint = ray.origin + newDistance * glm::normalize(ray.direction); + rayAvatarResult._intersectionPoint = ray.origin + newDistance * rayDirection; rayAvatarResult._intersectionNormal = surfaceNormal; extraInfo["worldIntersectionPoint"] = vec3toVariant(rayAvatarResult._intersectionPoint); break; @@ -752,7 +751,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic result.distance = rayAvatarResult._distance; result.surfaceNormal = rayAvatarResult._intersectionNormal; result.jointIndex = rayAvatarResult._intersectWithJoint; - result.intersection = ray.origin + rayAvatarResult._distance * glm::normalize(ray.direction); + result.intersection = ray.origin + rayAvatarResult._distance * rayDirection; result.extraInfo = extraInfo; result.face = face; } diff --git a/libraries/physics/src/MultiSphereShape.cpp b/libraries/physics/src/MultiSphereShape.cpp index 656fb64e39..98fb6dd34d 100644 --- a/libraries/physics/src/MultiSphereShape.cpp +++ b/libraries/physics/src/MultiSphereShape.cpp @@ -286,6 +286,9 @@ void MultiSphereShape::spheresFromAxes(const std::vector& points, con minAverageRadius = glm::min(averageRadius, minAverageRadius); spheres[j]._radius = averageRadius; } + if (maxAverageRadius == 0.0f) { + maxAverageRadius = 1.0f; + } float radiusRatio = maxRadius / maxAverageRadius; // Push the sphere into the bounding box float contractionRatio = 0.8f; @@ -299,7 +302,7 @@ void MultiSphereShape::spheresFromAxes(const std::vector& points, con } spheres[j]._radius = radius; if (distance - radius > 0.0f) { - spheres[j]._position = (distance - radius) * glm::normalize(axis); + spheres[j]._position = ((distance - radius) / distance) * axis; } else { spheres[j]._position = glm::vec3(0.0f); } @@ -356,15 +359,15 @@ void MultiSphereShape::calculateDebugLines() { axis.x != 0.0f ? glm::abs(axis.y) / axis.y : 0.0f , axis.z != 0.0f ? glm::abs(axis.z) / axis.z : 0.0f }; bool add = false; - if (sign.x == 0) { + if (sign.x == 0.0f) { if (sign.y == CORNER_SIGNS[i].y && sign.z == CORNER_SIGNS[i].z) { add = true; } - } else if (sign.y == 0) { + } else if (sign.y == 0.0f) { if (sign.x == CORNER_SIGNS[i].x && sign.z == CORNER_SIGNS[i].z) { add = true; } - } else if (sign.z == 0) { + } else if (sign.z == 0.0f) { if (sign.x == CORNER_SIGNS[i].x && sign.y == CORNER_SIGNS[i].y) { add = true; } @@ -459,14 +462,14 @@ void MultiSphereShape::calculateSphereLines(std::vector