From 4858f573e625bd3672f618ae8b9536b52857fe2c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Mon, 16 Dec 2013 10:31:26 +0100 Subject: [PATCH] Added more collision subs --- Code/OysterPhysics3D/OysterCollision3D.cpp | 72 ++++++++++++++++++++++ Code/OysterPhysics3D/OysterCollision3D.h | 28 ++++++--- Code/OysterPhysics3D/Plane.cpp | 4 +- Code/OysterPhysics3D/Point.cpp | 4 +- Code/OysterPhysics3D/Ray.cpp | 4 +- Code/OysterPhysics3D/Sphere.cpp | 4 +- 6 files changed, 98 insertions(+), 18 deletions(-) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 994513a6..25a8948b 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -251,6 +251,7 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Point &pointA, const Point &pointB, ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } @@ -286,6 +287,7 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Ray &ray, const Point &point, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } @@ -338,11 +340,13 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Sphere &sphere, const Point &point, ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } @@ -411,21 +415,25 @@ namespace Oyster { namespace Collision3D { namespace Utility bool Intersect( const Plane &plane, const Point &point, const ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } bool Intersect( const Plane &plane, const Ray &ray, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } bool Intersect( const Plane &plane, const Sphere &sphere, const ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } bool Intersect( const Plane &planeA, const Plane &planeB, const ::Oyster::Math::Float3& worldPointOfContact ) { + //! @todo TODO: implement Stub return false; } @@ -440,6 +448,16 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const BoxAxisAligned &box, const Point &point, Float3 &worldPointOfContact ) + { // by Dan Andersson + if( Intersect(box, point) ) + { + worldPointOfContact = point.center; + return true; + } + return false; + } + bool Intersect( const BoxAxisAligned &box, const Ray &ray, Float &connectDistance ) { // by Dan Andersson Float tMin = ::std::numeric_limits::max(), @@ -456,6 +474,16 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const BoxAxisAligned &box, const Ray &ray, Float &connectDistance, Float3 &worldPointOfContact ) + { // by Dan Andersson + if( Intersect(box, ray, connectDistance) ) + { + worldPointOfContact = ray.origin + ray.direction * connectDistance; + return true; + } + return false; + } + bool Intersect( const BoxAxisAligned &box, const Sphere &sphere ) { // by Dan Andersson Float4 e = Max( Float4(box.minVertex - sphere.center, 0.0f), Float4::null ); @@ -465,6 +493,12 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const BoxAxisAligned &box, const Sphere &sphere, Float3 &worldPointOfContact ) + { + //! @todo TODO: implement stub + return Intersect( box, sphere ); + } + bool Intersect( const BoxAxisAligned &box, const Plane &plane ) { // by Dan Andersson Float e, d; @@ -474,6 +508,12 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const BoxAxisAligned &box, const Plane &plane, Float3 &worldPointOfContact ) + { + //! @todo TODO: implement stub + return Intersect( box, plane ); + } + // bool Intersect( const BoxAxisAligned &box, const Triangle &triangle ) // { return false; /* TODO: */ } @@ -507,6 +547,16 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const Box &box, const Point &point, Float3 &worldPointOfContact ) + { // by Dan Andersson + if( Intersect(box, point) ) + { + worldPointOfContact = point.center; + return true; + } + return false; + } + bool Intersect( const Box &box, const Ray &ray, Float &connectDistance ) { // by Dan Andersson Float tMin = ::std::numeric_limits::max(), @@ -522,6 +572,16 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const Box &box, const Ray &ray, Float &connectDistance, Float3 &worldPointOfContact ) + { // by Dan Andersson + if( Intersect(box, ray, connectDistance) ) + { + worldPointOfContact = ray.origin + ray.direction * connectDistance; + return true; + } + return false; + } + bool Intersect( const Box &box, const Sphere &sphere ) { // by Dan Andersson // center: sphere's center in the box's view space @@ -534,6 +594,12 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const Box &box, const Sphere &sphere, Float3 &worldPointOfContact ) + { + //! @todo TODO: implement stub + return Intersect( box, sphere ); + } + bool Intersect( const Box &box, const Plane &plane ) {// by Dan Andersson Float e, d; @@ -543,6 +609,12 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; } + bool Intersect( const Box &box, const Plane &plane, Float3 &worldPointOfContact ) + { + //! @todo TODO: implement stub + return Intersect( box, plane ); + } + bool Intersect( const Box &boxA, const BoxAxisAligned &boxB ) { // by Dan Andersson Float3 alignedOffsetBoundaries = (boxB.maxVertex - boxB.minVertex) * 0.5f, diff --git a/Code/OysterPhysics3D/OysterCollision3D.h b/Code/OysterPhysics3D/OysterCollision3D.h index 7920a885..6ec28625 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.h +++ b/Code/OysterPhysics3D/OysterCollision3D.h @@ -25,28 +25,28 @@ namespace Oyster { namespace Collision3D { namespace Utility void Compare( ::Oyster::Math::Float &connectOffset, const Plane &plane, const Point &point ); bool Intersect( const Point &pointA, const Point &pointB ); - bool Intersect( const Point &pointA, const Point &pointB, ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Point &pointA, const Point &pointB, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Ray &ray, const Point &point, ::Oyster::Math::Float &connectDistance ); bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB ); - bool Intersect( const Ray &ray, const Point &point, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ); - bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB, ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Ray &ray, const Point &point, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3 &worldPointOfContact ); + bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Sphere &sphere, const Point &point ); bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance ); bool Intersect( const Sphere &sphereA, const Sphere &sphereB ); - bool Intersect( const Sphere &sphere, const Point &point, ::Oyster::Math::Float3& worldPointOfContact ); - bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ); - bool Intersect( const Sphere &sphereA, const Sphere &sphereB, ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Sphere &sphere, const Point &point, ::Oyster::Math::Float3 &worldPointOfContact ); + bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3 &worldPointOfContact ); + bool Intersect( const Sphere &sphereA, const Sphere &sphereB, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Plane &plane, const Point &point ); bool Intersect( const Plane &plane, const Ray &ray, ::Oyster::Math::Float &connectDistance ); bool Intersect( const Plane &plane, const Sphere &sphere ); bool Intersect( const Plane &planeA, const Plane &planeB ); - bool Intersect( const Plane &plane, const Point &point, ::Oyster::Math::Float3& worldPointOfContact ); - bool Intersect( const Plane &plane, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3& worldPointOfContact ); - bool Intersect( const Plane &plane, const Sphere &sphere, ::Oyster::Math::Float3& worldPointOfContact ); - bool Intersect( const Plane &planeA, const Plane &planeB, ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Plane &plane, const Point &point, ::Oyster::Math::Float3 &worldPointOfContact ); + bool Intersect( const Plane &plane, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3 &worldPointOfContact ); + bool Intersect( const Plane &plane, const Sphere &sphere, ::Oyster::Math::Float3 &worldPointOfContact ); + bool Intersect( const Plane &planeA, const Plane &planeB, ::Oyster::Math::Float3 &worldPointOfContact ); // bool Intersect( const Triangle &triangle, const Point &point, ? ); // bool Intersect( const Triangle &triangle, const Ray &ray, ? ); @@ -55,16 +55,24 @@ namespace Oyster { namespace Collision3D { namespace Utility // bool Intersect( const Triangle &triangleA, const Triangle &triangleB, ? ); bool Intersect( const BoxAxisAligned &box, const Point &point ); + bool Intersect( const BoxAxisAligned &box, const Point &point, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const BoxAxisAligned &box, const Ray &ray, ::Oyster::Math::Float &connectDistance ); + bool Intersect( const BoxAxisAligned &box, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const BoxAxisAligned &box, const Sphere &sphere ); + bool Intersect( const BoxAxisAligned &box, const Sphere &sphere, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const BoxAxisAligned &box, const Plane &plane ); + bool Intersect( const BoxAxisAligned &box, const Plane &plane, ::Oyster::Math::Float3 &worldPointOfContact ); // bool Intersect( const BoxAxisAligned &box, const Triangle &triangle ); bool Intersect( const BoxAxisAligned &boxA, const BoxAxisAligned &boxB ); bool Intersect( const Box &box, const Point &point ); + bool Intersect( const Box &box, const Point &point, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Box &box, const Ray &ray, ::Oyster::Math::Float &connectDistance ); + bool Intersect( const Box &box, const Ray &ray, ::Oyster::Math::Float &connectDistance, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Box &box, const Sphere &sphere ); + bool Intersect( const Box &box, const Sphere &sphere, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Box &box, const Plane &plane ); + bool Intersect( const Box &box, const Plane &plane, ::Oyster::Math::Float3 &worldPointOfContact ); // bool Intersect( const Box &box, const Triangle &triangle, ? ); bool Intersect( const Box &boxA, const BoxAxisAligned &boxB ); bool Intersect( const Box &boxA, const Box &boxB ); diff --git a/Code/OysterPhysics3D/Plane.cpp b/Code/OysterPhysics3D/Plane.cpp index f44ba810..87d20c84 100644 --- a/Code/OysterPhysics3D/Plane.cpp +++ b/Code/OysterPhysics3D/Plane.cpp @@ -60,8 +60,8 @@ bool Plane::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worl case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target, 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 ); + case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this, worldPointOfContact ); + case Type_box: return Utility::Intersect( *(Box*)&target, *this, worldPointOfContact ); case Type_frustrum: return false; // TODO: default: worldPointOfContact = NULL; return false; diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index ea6691a7..8b1ab081 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -58,8 +58,8 @@ bool Point::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worl case Type_sphere: return Utility::Intersect( *(Sphere*)&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 ); + case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this, worldPointOfContact ); + case Type_box: return Utility::Intersect( *(Box*)&target, *this, worldPointOfContact ); case Type_frustrum: return false; // TODO: default: worldPointOfContact = NULL; return false; diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index 86823b69..d1e81974 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -67,8 +67,8 @@ bool Ray::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worldP case Type_sphere: return Utility::Intersect( *(Sphere*)&target, *this, this->collisionDistance, worldPointOfContact ); case Type_plane: return Utility::Intersect( *(Plane*)&target, *this, this->collisionDistance, worldPointOfContact ); // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return false; // return Utility::Intersect( *(BoxAxisAligned*)&target, *this, this->collisionDistance, worldPointOfContact ); - case Type_box: return false; // return Utility::Intersect( *(Box*)&target, *this, this->collisionDistance, worldPointOfContact ); + case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this, this->collisionDistance, worldPointOfContact ); + case Type_box: return Utility::Intersect( *(Box*)&target, *this, this->collisionDistance, worldPointOfContact ); case Type_frustrum: return false; // TODO: default: worldPointOfContact = NULL; return false; diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index 6c7ae223..efec7c20 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -55,8 +55,8 @@ bool Sphere::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &wor case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target, 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 ); + case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this, worldPointOfContact ); + case Type_box: return Utility::Intersect( *(Box*)&target, *this, worldPointOfContact ); case Type_frustrum: return false; // TODO: default: worldPointOfContact = Float3::null; return false;