From 7ad60969fc24912293276b04070c80f0cb55215b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 4 Dec 2013 14:12:06 +0100 Subject: [PATCH] Sphere Vs Box collision detect fix second ed. ... Works now! :3 --- Code/OysterPhysics3D/OysterCollision3D.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 95c56f81..5df9761c 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -459,12 +459,11 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Box &box, const Sphere &sphere ) { // by Dan Andersson - Float4 vCenter = Float4( sphere.center - box.center, 1.0f ); // sphere's center in the box's view space - vCenter = InverseRotationMatrix( box.rotation ) * vCenter; - vCenter.w = 0.0f; + // center: sphere's center in the box's view space + Float4 center = TransformVector( InverseRotationMatrix(box.rotation), Float4(sphere.center - box.center, 0.0f) ); - Float4 e = Max( Float4(-box.boundingOffset, 0.0f) - vCenter, Float4::null ); - e += Max( vCenter - Float4(-box.boundingOffset, 0.0f), Float4::null ); + Float4 e = Max( Float4(-box.boundingOffset, 0.0f) - center, Float4::null ); + e += Max( center - Float4(box.boundingOffset, 0.0f), Float4::null ); if( e.Dot(e) > (sphere.radius * sphere.radius) ) return false; return true;