From 8d6fa8f90471a5cc60ea444e52c1e03e2614d562 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Mon, 21 Apr 2014 18:19:59 -0700 Subject: [PATCH] fix sphere-vs-axis-aligned-cube logic --- libraries/shared/src/ShapeCollider.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/shared/src/ShapeCollider.cpp b/libraries/shared/src/ShapeCollider.cpp index 1b49caab22..c0de3cb90b 100644 --- a/libraries/shared/src/ShapeCollider.cpp +++ b/libraries/shared/src/ShapeCollider.cpp @@ -15,6 +15,7 @@ #include "GeometryUtil.h" #include "ShapeCollider.h" +#include "StreamUtils.h" // NOTE: // @@ -601,9 +602,9 @@ bool sphereAACube(const glm::vec3& sphereCenter, float sphereRadius, const glm:: // compute the nearest point on cube float maxBA = glm::max(glm::max(fabs(BA.x), fabs(BA.y)), fabs(BA.z)); glm::vec3 surfaceB = cubeCenter - (0.5f * cubeSide / maxBA) * BA; - // collision happens when "vector to surfaceB from surfaceA" dots with BA to produce a positive value + // collision happens when "vector to surfaceB from surfaceA" dots with BA to produce a negative value glm::vec3 surfaceBA = surfaceB - surfaceA; - if (glm::dot(surfaceBA, BA) > 0.f) { + if (glm::dot(surfaceBA, BA) < 0.f) { CollisionInfo* collision = collisions.getNewCollision(); if (collision) { collision->_penetration = surfaceBA;