From 283633c6c6747ef7420c0b466f977cee7d696001 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 16 Dec 2013 09:38:04 +0100 Subject: [PATCH] Added stub functions More funcitonallity for intersect functions. --- Code/OysterPhysics3D/OysterCollision3D.cpp | 53 ++++++++++++++++++++++ Code/OysterPhysics3D/OysterCollision3D.h | 10 ++++ Code/OysterPhysics3D/Plane.cpp | 18 ++++++++ Code/OysterPhysics3D/Plane.h | 1 + Code/OysterPhysics3D/Point.cpp | 18 ++++++++ Code/OysterPhysics3D/Point.h | 1 + Code/OysterPhysics3D/Ray.cpp | 20 ++++++++ Code/OysterPhysics3D/Ray.h | 1 + Code/OysterPhysics3D/Sphere.cpp | 18 ++++++++ Code/OysterPhysics3D/Sphere.h | 1 + 10 files changed, 141 insertions(+) diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 5df9761c..6d437511 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -249,6 +249,11 @@ 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 ) + { + return false; + } + bool Intersect( const Ray &ray, const Point &point, Float &connectDistance ) { // by Dan Andersson Float connectOffsetSquared; @@ -279,6 +284,16 @@ 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 ) + { + return false; + } + + bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + bool Intersect( const Sphere &sphere, const Point &point ) { // by Dan Andersson Float3 dP = point.center - sphere.center; @@ -321,6 +336,24 @@ namespace Oyster { namespace Collision3D { namespace Utility return false; } + bool Intersect( const Sphere &sphere, const Point &point, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + + bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + + bool Intersect( const Sphere &sphereA, const Sphere &sphereB, const ::Oyster::Math::Float3& worldPointOfContact ) + { + Ray sphereRay(sphereA, Float3(sphereB.center-sphereA.center).Normalize()); + + + return false; + } + bool Intersect( const Plane &plane, const Point &point ) { // by Dan Andersson Float connectOffset; @@ -364,6 +397,26 @@ namespace Oyster { namespace Collision3D { namespace Utility return true; // none parallell planes ALWAYS intersects somewhere } + bool Intersect( const Plane &plane, const Point &point, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + + bool Intersect( const Plane &plane, const Ray &ray, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + + bool Intersect( const Plane &plane, const Sphere &sphere, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + + bool Intersect( const Plane &planeA, const Plane &planeB, const ::Oyster::Math::Float3& worldPointOfContact ) + { + return false; + } + bool Intersect( const BoxAxisAligned &box, const Point &point ) { // by Dan Andersson if( point.center.x < box.minVertex.x ) return false; diff --git a/Code/OysterPhysics3D/OysterCollision3D.h b/Code/OysterPhysics3D/OysterCollision3D.h index 24d6a568..2b1f820f 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.h +++ b/Code/OysterPhysics3D/OysterCollision3D.h @@ -25,18 +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, const ::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, const ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Ray &rayA, const Ray &rayB, ::Oyster::Math::Float &connectDistanceA, ::Oyster::Math::Float &connectDistanceB, const ::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, const ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Sphere &sphere, const Ray &ray, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Sphere &sphereA, const Sphere &sphereB, const ::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, const ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Plane &plane, const Ray &ray, ::Oyster::Math::Float &connectDistance, const ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Plane &plane, const Sphere &sphere, const ::Oyster::Math::Float3& worldPointOfContact ); + bool Intersect( const Plane &planeA, const Plane &planeB, const ::Oyster::Math::Float3& worldPointOfContact ); // bool Intersect( const Triangle &triangle, const Point &point, ? ); // bool Intersect( const Triangle &triangle, const Ray &ray, ? ); diff --git a/Code/OysterPhysics3D/Plane.cpp b/Code/OysterPhysics3D/Plane.cpp index a1a16b14..0bc14982 100644 --- a/Code/OysterPhysics3D/Plane.cpp +++ b/Code/OysterPhysics3D/Plane.cpp @@ -50,6 +50,24 @@ bool Plane::Intersects( const ICollideable &target ) const } } +bool Plane::Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const +{ + switch( target.type ) + { + case Type_universe: return true; + 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_triangle: return false; // TODO: + 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; + } +} + bool Plane::Contains( const ICollideable &target ) const { switch( target.type ) diff --git a/Code/OysterPhysics3D/Plane.h b/Code/OysterPhysics3D/Plane.h index b69c5c9f..e38240f3 100644 --- a/Code/OysterPhysics3D/Plane.h +++ b/Code/OysterPhysics3D/Plane.h @@ -29,6 +29,7 @@ namespace Oyster { namespace Collision3D virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; bool Intersects( const ICollideable &target ) const; + bool Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; }; } } diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index d81c91a3..7bcce9ae 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -48,6 +48,24 @@ bool Point::Intersects( const ICollideable &target ) const } } +bool Point::Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const +{ + switch( target.type ) + { + case Type_universe: return true; + 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_triangle: return false; // TODO: + 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; + } +} + bool Point::Contains( const ICollideable &target ) const { switch( target.type ) diff --git a/Code/OysterPhysics3D/Point.h b/Code/OysterPhysics3D/Point.h index 42561909..60b74659 100644 --- a/Code/OysterPhysics3D/Point.h +++ b/Code/OysterPhysics3D/Point.h @@ -28,6 +28,7 @@ namespace Oyster { namespace Collision3D virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; bool Intersects( const ICollideable &target ) const; + bool Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; }; } } diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index 79e4dbd5..2a640163 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -55,6 +55,26 @@ bool Ray::Intersects( const ICollideable &target ) const } } +bool Ray::Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const +{ + switch( target.type ) + { + case Type_universe: + this->collisionDistance = 0.0f; + return true; + 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_triangle: return false; // TODO: + 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; + } +} + bool Ray::Contains( const ICollideable &target ) const { switch( target.type ) diff --git a/Code/OysterPhysics3D/Ray.h b/Code/OysterPhysics3D/Ray.h index 5f24ea81..34f32ebe 100644 --- a/Code/OysterPhysics3D/Ray.h +++ b/Code/OysterPhysics3D/Ray.h @@ -37,6 +37,7 @@ namespace Oyster { namespace Collision3D virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; bool Intersects( const ICollideable &target ) const; + bool Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; }; } } diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index 4f6f76f7..eb907e59 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -45,6 +45,24 @@ bool Sphere::Intersects( const ICollideable &target ) const } } +bool Sphere::Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const +{ + switch( target.type ) + { + case Type_universe: return true; + 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_triangle: return false; // TODO: + 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; + } +} + bool Sphere::Contains( const ICollideable &target ) const { switch( target.type ) diff --git a/Code/OysterPhysics3D/Sphere.h b/Code/OysterPhysics3D/Sphere.h index 8e73de0b..0c4b8094 100644 --- a/Code/OysterPhysics3D/Sphere.h +++ b/Code/OysterPhysics3D/Sphere.h @@ -28,6 +28,7 @@ namespace Oyster { namespace Collision3D virtual ::Utility::DynamicMemory::UniquePointer Clone( ) const; bool Intersects( const ICollideable &target ) const; + bool Intersects( const ICollideable &target, const ::Oyster::Math::Float3 &worldPointOfContact ) const; bool Contains( const ICollideable &target ) const; }; } }