From d8b323e230d62dba18b9dc61c93738c880fdb240 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 16 Dec 2013 10:28:49 +0100 Subject: [PATCH] Extractable collision point for SphereVSSphere --- Code/OysterPhysics3D/OysterCollision3D.cpp | 26 ++++++++++++++++------ Code/OysterPhysics3D/Point.cpp | 2 +- Code/OysterPhysics3D/Sphere.cpp | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index a5d4117c..994513a6 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -249,7 +249,7 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; // Passed all tests, is in same position } - bool Intersect( const Point &pointA, const Point &pointB, const ::Oyster::Math::Float3& worldPointOfContact ) + bool Intersect( const Point &pointA, const Point &pointB, ::Oyster::Math::Float3& worldPointOfContact ) { return false; } @@ -284,12 +284,12 @@ namespace Oyster { namespace Collision3D { namespace Utility return false; } - bool Intersect( const Ray &ray, const Point &point, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ) + bool Intersect( const Ray &ray, const Point &point, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ) { return false; } - bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB, const ::Oyster::Math::Float3& worldPointOfContact ) + bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB, ::Oyster::Math::Float3& worldPointOfContact ) { return false; } @@ -336,20 +336,32 @@ namespace Oyster { namespace Collision3D { namespace Utility return false; } - bool Intersect( const Sphere &sphere, const Point &point, const ::Oyster::Math::Float3& worldPointOfContact ) + bool Intersect( const Sphere &sphere, const Point &point, ::Oyster::Math::Float3& worldPointOfContact ) { return false; } - bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ) + bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ) { return false; } - bool Intersect( const Sphere &sphereA, const Sphere &sphereB, const ::Oyster::Math::Float3& worldPointOfContact ) + bool Intersect( const Sphere &sphereA, const Sphere &sphereB, ::Oyster::Math::Float3& worldPointOfContact ) { - Ray sphereRay(sphereA.center, Float3(sphereB.center-sphereA.center).Normalize()); + //Float3 C = sphereA.center; + //C -= sphereB.center; + //Float r = (sphereA.radius + sphereB.radius); + //if (r*r >= C.Dot(C)) + //{ + // Float distance; + + // Intersect(sphereA, Ray(sphereB.center, C.Normalize()), distance); + + // worldPointOfContact = sphereB.center+C.Normalize()*distance; + + // return true; // Intersect detected! + //} return false; } diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index 2981f268..ea6691a7 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -56,7 +56,7 @@ bool Point::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worl case Type_point: return Utility::Intersect( *this, *(Point*)&target, worldPointOfContact ); case Type_ray: return Utility::Intersect( *(Ray*)&target, *this, ((Ray*)&target)->collisionDistance, worldPointOfContact ); case Type_sphere: return Utility::Intersect( *(Sphere*)&target, *this, worldPointOfContact ); - case Type_plane: return Utility::Intersect( *(Plane*)&target, *this, worldPointOfContact ); + //case Type_plane: return Utility::Intersect( *(Plane*)&target, *this, worldPointOfContact ); // case Type_triangle: return false; // TODO: case Type_box_axis_aligned: return false; // return Utility::Intersect( *(BoxAxisAligned*)&target, *this, worldPointOfContact ); case Type_box: return false; // return Utility::Intersect( *(Box*)&target, *this, worldPointOfContact ); diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index e31a361c..6c7ae223 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -53,7 +53,7 @@ bool Sphere::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &wor case Type_point: return Utility::Intersect( *this, *(Point*)&target, worldPointOfContact ); case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance, worldPointOfContact ); case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target, worldPointOfContact ); - case Type_plane: return Utility::Intersect( *(Plane*)&target, *this, worldPointOfContact ); + //case Type_plane: return Utility::Intersect( *(Plane*)&target, *this, worldPointOfContact ); // case Type_triangle: return false; // TODO: case Type_box_axis_aligned: return false; // return Utility::Intersect( *(BoxAxisAligned*)&target, *this, worldPointOfContact ); case Type_box: return false; // return Utility::Intersect( *(Box*)&target, *this, worldPointOfContact );