fix sphere-vs-axis-aligned-cube logic

This commit is contained in:
Andrew Meadows 2014-04-21 18:19:59 -07:00
parent 06784aa960
commit 8d6fa8f904

View file

@ -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;