diff --git a/Code/OysterPhysics3D/Box.cpp b/Code/OysterPhysics3D/Box.cpp index 59c98372..7d67754c 100644 --- a/Code/OysterPhysics3D/Box.cpp +++ b/Code/OysterPhysics3D/Box.cpp @@ -41,35 +41,48 @@ bool Box::Intersects( const ICollideable &target ) const { switch( target.type ) { - case Type_universe: return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); - case Type_plane: return Utility::Intersect( *this, *(Plane*)&target ); - // case Type_triangle: return false; // TODO: : - case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)&target ); - case Type_box: return Utility::Intersect( *this, *(Box*)&target ); - // case Type_frustrum: return false; // TODO: : - default: return false; + case Type_universe: return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target ); + case Type_plane: return Utility::Intersect( *this, (const Plane&)target ); + // case Type_triangle: return false; // TODO: : + case Type_box_axis_aligned: return Utility::Intersect( *this, (const BoxAxisAligned&)target ); + case Type_box: return Utility::Intersect( *this, (const Box&)target ); + // case Type_frustrum: return false; // TODO: : + default: return false; } } bool Box::Intersects( const ICollideable &target, Float3 &worldPointOfContact ) const { - //! @todo TODO: implement stub properly - return this->Intersects( target ); + switch( target.type ) + { + case Type_universe: + worldPointOfContact = this->center; + return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target, worldPointOfContact ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance, worldPointOfContact ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target, worldPointOfContact ); + case Type_plane: return Utility::Intersect( *this, (const Plane&)target, worldPointOfContact ); + // case Type_triangle: return false; // TODO: : + case Type_box_axis_aligned: return Utility::Intersect( *this, (const BoxAxisAligned&)target, worldPointOfContact ); + case Type_box: return Utility::Intersect( *this, (const Box&)target, worldPointOfContact ); + // case Type_frustrum: return false; // TODO: : + default: return false; + } } bool Box::Contains( const ICollideable &target ) const { switch( target.type ) { - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - // case Type_sphere: return false; // TODO: - // case Type_triangle: return false; // TODO: - // case Type_box_axis_aligned: return false; // TODO: - // case Type_box: return false; // TODO: - // case Type_frustrum: return false; // TODO: + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + //case Type_sphere: return false; // TODO: + //case Type_triangle: return false; // TODO: + //case Type_box_axis_aligned: return false; // TODO: + //case Type_box: return false; // TODO: + //case Type_frustrum: return false; // TODO: default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/BoxAxisAligned.cpp b/Code/OysterPhysics3D/BoxAxisAligned.cpp index f1fc2a78..a0ebdd63 100644 --- a/Code/OysterPhysics3D/BoxAxisAligned.cpp +++ b/Code/OysterPhysics3D/BoxAxisAligned.cpp @@ -44,16 +44,16 @@ bool BoxAxisAligned::Intersects( const ICollideable &target ) const { switch( target.type ) { - case Type_universe: return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); - case Type_plane: return Utility::Intersect( *this, *(Plane*)&target ); - // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)&target ); - // case Type_box: return false; // TODO: - // case Type_frustrum: return false; // TODO: - default: return false; + case Type_universe: return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target ); + case Type_plane: return Utility::Intersect( *this, (const Plane&)target ); + // case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( *this, (const BoxAxisAligned&)target ); + // case Type_box: return false; // TODO: + // case Type_frustrum: return false; // TODO: + default: return false; } } @@ -65,14 +65,15 @@ bool BoxAxisAligned::Intersects( const ICollideable &target, Float3 &worldPointO bool BoxAxisAligned::Contains( const ICollideable &target ) const { - switch( target.type ) - { - // case Type_point: return false; // TODO: - // case Type_sphere: return false; // TODO: - // case Type_triangle: return false; // TODO: - // case Type_box_axis_aligned: return false; // TODO: - // case Type_box: return false; // TODO: - // case Type_frustrum: return false; // TODO: - default: return false; - } + //switch( target.type ) + //{ + ////case Type_point: return false; // TODO: + ////case Type_sphere: return false; // TODO: + ////case Type_triangle: return false; // TODO: + ////case Type_box_axis_aligned: return false; // TODO: + ////case Type_box: return false; // TODO: + ////case Type_frustrum: return false; // TODO: + //default: return false; + //} + return false; } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Frustrum.cpp b/Code/OysterPhysics3D/Frustrum.cpp index 39e27318..e8aa65fa 100644 --- a/Code/OysterPhysics3D/Frustrum.cpp +++ b/Code/OysterPhysics3D/Frustrum.cpp @@ -198,23 +198,25 @@ void Frustrum::WriteToByte( unsigned int &nextIndex, unsigned char targetMem[] ) } ::Utility::DynamicMemory::UniquePointer Frustrum::Clone( ) const -{ return ::Utility::DynamicMemory::UniquePointer( new Frustrum(*this) ); } +{ + return ::Utility::DynamicMemory::UniquePointer( new Frustrum(*this) ); +} bool Frustrum::Intersects( const ICollideable &target ) const { switch( target.type ) { - case Type_universe: return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); - case Type_plane: return Utility::Intersect( *this, *(Plane*)&target ); - // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)&target ); - case Type_box: return Utility::Intersect( *this, *(Box*)&target ); - case Type_frustrum: return Utility::Intersect( *this, *(Frustrum*)&target ); - // case Type_line: return false; // TODO: - default: return false; + case Type_universe: return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target ); + case Type_plane: return Utility::Intersect( *this, (const Plane&)target ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( *this, (const BoxAxisAligned&)target ); + case Type_box: return Utility::Intersect( *this, (const Box&)target ); + case Type_frustrum: return Utility::Intersect( *this, (const Frustrum&)target ); + //case Type_line: return false; // TODO: + default: return false; } } @@ -228,15 +230,15 @@ bool Frustrum::Contains( const ICollideable &target ) const { switch( target.type ) { - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - // case Type_ray: return false; // TODO: - // case Type_sphere: return false; // TODO: - // case Type_plane: return false; // TODO: - // case Type_triangle: return false; // TODO: - // case Type_box_axis_aligned: return false; // TODO: - // case Type_box: return false; // TODO: - // case Type_frustrum: return false; // TODO: - // case Type_line: return false; // TODO: - default: return false; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + //case Type_ray: return false; // TODO: + //case Type_sphere: return false; // TODO: + //case Type_plane: return false; // TODO: + //case Type_triangle: return false; // TODO: + //case Type_box_axis_aligned: return false; // TODO: + //case Type_box: return false; // TODO: + //case Type_frustrum: return false; // TODO: + //case Type_line: return false; // TODO: + default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 98aacd24..9f8a9fe1 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -796,6 +796,20 @@ namespace Oyster { namespace Collision3D { namespace Utility return Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries.xyz, boxA.boundingOffset, boxA.rotation, offset ); } + bool Intersect( const Box &boxA, const BoxAxisAligned &boxB, ::Oyster::Math::Float3 &worldPointOfContact ) + { // by Dan Andersson + Float4 alignedOffsetBoundaries = (Float4(boxB.maxVertex, 1.0f) - Float4(boxB.minVertex, 1.0f)) * 0.5f, + offset = Float4(boxA.center, 1.0f) - Average( Float4(boxB.maxVertex, 1.0f), Float4(boxB.minVertex, 1.0f) ); + + Float4 pointOfContact; + if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( alignedOffsetBoundaries.xyz, boxA.boundingOffset, boxA.rotation, offset, pointOfContact ) ) + { + worldPointOfContact = pointOfContact.xyz; + return true; + } + else return false; + } + bool Intersect( const Box &boxA, const Box &boxB ) { // by Dan Andersson Float4x4 rotationB = TransformMatrix( InverseRotationMatrix(boxA.rotation), boxB.rotation ); @@ -812,7 +826,7 @@ namespace Oyster { namespace Collision3D { namespace Utility Float4 pointOfContact; if( Private::SeperatingAxisTest_AxisAlignedVsTransformedBox( boxA.boundingOffset, boxB.boundingOffset, rotationB, posB, pointOfContact ) ) { - TransformVector( boxA.rotation, pointOfContact, pointOfContact ); + worldPointOfContact = TransformVector( boxA.rotation, pointOfContact, pointOfContact ).xyz; return true; } else return false; diff --git a/Code/OysterPhysics3D/OysterCollision3D.h b/Code/OysterPhysics3D/OysterCollision3D.h index 5234b31e..603dfc7c 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.h +++ b/Code/OysterPhysics3D/OysterCollision3D.h @@ -75,6 +75,7 @@ namespace Oyster { namespace Collision3D { namespace Utility 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 BoxAxisAligned &boxB, ::Oyster::Math::Float3 &worldPointOfContact ); bool Intersect( const Box &boxA, const Box &boxB ); bool Intersect( const Box &boxA, const Box &boxB, ::Oyster::Math::Float3 &worldPointOfContact ); diff --git a/Code/OysterPhysics3D/Plane.cpp b/Code/OysterPhysics3D/Plane.cpp index 87d20c84..863b0c5a 100644 --- a/Code/OysterPhysics3D/Plane.cpp +++ b/Code/OysterPhysics3D/Plane.cpp @@ -30,40 +30,45 @@ Plane & Plane::operator = ( const Plane &plane ) } ::Utility::DynamicMemory::UniquePointer Plane::Clone( ) const -{ return ::Utility::DynamicMemory::UniquePointer( new Plane(*this) ); } +{ + return ::Utility::DynamicMemory::UniquePointer( new Plane(*this) ); +} bool Plane::Intersects( const ICollideable &target ) const { switch( target.type ) { - case Type_universe: return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); - case Type_plane: return Utility::Intersect( *this, *(Plane*)&target ); - // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); - case Type_box: return Utility::Intersect( *(Box*)&target, *this ); - case Type_frustrum: return false; // TODO: - case Type_line: return false; // TODO: - default: return false; + case Type_universe: return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target ); + case Type_plane: return Utility::Intersect( *this, (const Plane&)target ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this ); + case Type_box: return Utility::Intersect( (const Box&)target, *this ); + //case Type_frustrum: return false; // TODO: + //case Type_line: return false; // TODO: + default: return false; } } -bool Plane::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worldPointOfContact ) const +bool Plane::Intersects( const ICollideable &target, 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; + case Type_universe: + worldPointOfContact = this->normal * this->phasing; + return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target, worldPointOfContact ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance, worldPointOfContact ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target, worldPointOfContact ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this, worldPointOfContact ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this, worldPointOfContact ); + case Type_box: return Utility::Intersect( (const Box&)target, *this, worldPointOfContact ); + //case Type_frustrum: return false; // TODO: + default: + worldPointOfContact = Float3::null; return false; } } @@ -72,10 +77,10 @@ bool Plane::Contains( const ICollideable &target ) const { switch( target.type ) { - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Contains( *this, *(Ray*)&target ); - case Type_plane: return Utility::Contains( *this, *(Plane*)&target ); - // case Type_triangle: return false; // TODO: - default: return false; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Contains( *this, (const Ray&)target ); + case Type_plane: return Utility::Contains( *this, (const Plane&)target ); + //case Type_triangle: return false; // TODO: + default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Point.cpp b/Code/OysterPhysics3D/Point.cpp index 8b1ab081..7a40c7cc 100644 --- a/Code/OysterPhysics3D/Point.cpp +++ b/Code/OysterPhysics3D/Point.cpp @@ -35,33 +35,36 @@ bool Point::Intersects( const ICollideable &target ) const { switch( target.type ) { - case Type_universe: return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Intersect( *(Ray*)&target, *this, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *(Sphere*)&target, *this ); - case Type_plane: return Utility::Intersect( *(Plane*)&target, *this ); - //case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); - case Type_box: return Utility::Intersect( *(Box*)&target, *this ); - case Type_frustrum: return false; // TODO: - default: return false; + case Type_universe: return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Intersect( (const Ray&)target, *this, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( (const Sphere&)target, *this ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this ); + case Type_box: return Utility::Intersect( (const Box&)target, *this ); + //case Type_frustrum: return false; // TODO: + default: return false; } } -bool Point::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worldPointOfContact ) const +bool Point::Intersects( const ICollideable &target, 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( *(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_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; + case Type_universe: + worldPointOfContact = this->center; + return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target, worldPointOfContact ); + case Type_ray: return Utility::Intersect( (const Ray&)target, *this, ((const Ray&)target).collisionDistance, worldPointOfContact ); + case Type_sphere: return Utility::Intersect( (const Sphere&)target, *this, worldPointOfContact ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this, worldPointOfContact ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this, worldPointOfContact ); + case Type_box: return Utility::Intersect( (const Box&)target, *this, worldPointOfContact ); + case Type_frustrum: return false; // TODO: + default: + worldPointOfContact = Float3::null; return false; } } @@ -70,7 +73,7 @@ bool Point::Contains( const ICollideable &target ) const { switch( target.type ) { - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - default: return false; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Ray.cpp b/Code/OysterPhysics3D/Ray.cpp index d1e81974..6d65fe7f 100644 --- a/Code/OysterPhysics3D/Ray.cpp +++ b/Code/OysterPhysics3D/Ray.cpp @@ -43,34 +43,36 @@ bool Ray::Intersects( const ICollideable &target ) const case Type_universe: this->collisionDistance = 0.0f; return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target, this->collisionDistance ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, this->collisionDistance, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *(Sphere*)&target, *this, this->collisionDistance ); - case Type_plane: return Utility::Intersect( *(Plane*)&target, *this, this->collisionDistance ); + case Type_point: return Utility::Intersect( *this, (const Point&)target, this->collisionDistance ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, this->collisionDistance, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( (const Sphere&)target, *this, this->collisionDistance ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this, this->collisionDistance ); // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this, this->collisionDistance ); - case Type_box: return Utility::Intersect( *(Box*)&target, *this, this->collisionDistance ); - case Type_frustrum: return false; // TODO: - default: return false; + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this, this->collisionDistance ); + case Type_box: return Utility::Intersect( (const Box&)target, *this, this->collisionDistance ); + case Type_frustrum: return false; // TODO: + default: return false; } } -bool Ray::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worldPointOfContact ) const +bool Ray::Intersects( const ICollideable &target, Float3 &worldPointOfContact ) const { switch( target.type ) { case Type_universe: this->collisionDistance = 0.0f; + worldPointOfContact = this->origin; return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target, this->collisionDistance, worldPointOfContact ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, this->collisionDistance, ((Ray*)&target)->collisionDistance, worldPointOfContact ); - 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 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; + case Type_point: return Utility::Intersect( *this, (const Point&)target, this->collisionDistance, worldPointOfContact ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, this->collisionDistance, ((const Ray&)target).collisionDistance, worldPointOfContact ); + case Type_sphere: return Utility::Intersect( (const Sphere&)target, *this, this->collisionDistance, worldPointOfContact ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this, this->collisionDistance, worldPointOfContact ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this, this->collisionDistance, worldPointOfContact ); + case Type_box: return Utility::Intersect( (const Box&)target, *this, this->collisionDistance, worldPointOfContact ); + //case Type_frustrum: return false; // TODO: + default: + worldPointOfContact = Float3::null; return false; } } @@ -79,8 +81,8 @@ bool Ray::Contains( const ICollideable &target ) const { switch( target.type ) { - case Type_point: return Utility::Intersect( *this, *(Point*)&target, this->collisionDistance ); - case Type_ray: return Utility::Contains( *this, *(Ray*)&target ); - default: return false; + case Type_point: return Utility::Intersect( *this, (const Point&)target, this->collisionDistance ); + case Type_ray: return Utility::Contains( *this, (const Ray&)target ); + default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Sphere.cpp b/Code/OysterPhysics3D/Sphere.cpp index efec7c20..8c786f54 100644 --- a/Code/OysterPhysics3D/Sphere.cpp +++ b/Code/OysterPhysics3D/Sphere.cpp @@ -26,39 +26,44 @@ Sphere & Sphere::operator = ( const Sphere &sphere ) } ::Utility::DynamicMemory::UniquePointer Sphere::Clone( ) const -{ return ::Utility::DynamicMemory::UniquePointer( new Sphere(*this) ); } +{ + return ::Utility::DynamicMemory::UniquePointer( new Sphere(*this) ); +} bool Sphere::Intersects( const ICollideable &target ) const { switch( target.type ) { - case Type_universe: return true; - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_ray: return Utility::Intersect( *this, *(Ray*)&target, ((Ray*)&target)->collisionDistance ); - case Type_sphere: return Utility::Intersect( *this, *(Sphere*)&target ); - case Type_plane: return Utility::Intersect( *(Plane*)&target, *this ); - // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this ); - case Type_box: return Utility::Intersect( *(Box*)&target, *this ); - case Type_frustrum: return false; // TODO: - default: return false; + case Type_universe: return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this ); + case Type_box: return Utility::Intersect( (const Box&)target, *this ); + //case Type_frustrum: return false; // TODO: + default: return false; } } -bool Sphere::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worldPointOfContact ) const +bool Sphere::Intersects( const ICollideable &target, 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; + case Type_universe: + worldPointOfContact = this->center; + return true; + case Type_point: return Utility::Intersect( *this, (const Point&)target, worldPointOfContact ); + case Type_ray: return Utility::Intersect( *this, (const Ray&)target, ((const Ray&)target).collisionDistance, worldPointOfContact ); + case Type_sphere: return Utility::Intersect( *this, (const Sphere&)target, worldPointOfContact ); + case Type_plane: return Utility::Intersect( (const Plane&)target, *this, worldPointOfContact ); + //case Type_triangle: return false; // TODO: + case Type_box_axis_aligned: return Utility::Intersect( (const BoxAxisAligned&)target, *this, worldPointOfContact ); + case Type_box: return Utility::Intersect( (const Box&)target, *this, worldPointOfContact ); + //case Type_frustrum: return false; // TODO: + default: + worldPointOfContact = Float3::null; return false; } } @@ -67,12 +72,12 @@ bool Sphere::Contains( const ICollideable &target ) const { switch( target.type ) { - case Type_point: return Utility::Intersect( *this, *(Point*)&target ); - case Type_sphere: return Utility::Contains( *this, *(Sphere*)&target ); - // case Type_triangle: return false; // TODO: - case Type_box_axis_aligned: return false; // TODO: - case Type_box: return false; // TODO: - case Type_frustrum: return false; // TODO: - default: return false; + case Type_point: return Utility::Intersect( *this, (const Point&)target ); + case Type_sphere: return Utility::Contains( *this, (const Sphere&)target ); + //case Type_triangle: return false; // TODO: + //case Type_box_axis_aligned: return false; // TODO: + //case Type_box: return false; // TODO: + //case Type_frustrum: return false; // TODO: + default: return false; } } \ No newline at end of file diff --git a/Code/OysterPhysics3D/Universe.cpp b/Code/OysterPhysics3D/Universe.cpp index f1887e0b..c2308690 100644 --- a/Code/OysterPhysics3D/Universe.cpp +++ b/Code/OysterPhysics3D/Universe.cpp @@ -10,20 +10,24 @@ Universe::Universe() : ICollideable(Type_universe) {} Universe::~Universe() {} Universe & Universe::operator = ( const Universe &universe ) -{ return *this; } +{ + return *this; +} UniquePointer Universe::Clone( ) const -{ return UniquePointer( new Universe(*this) ); } +{ + return UniquePointer( new Universe(*this) ); +} bool Universe::Intersects( const ICollideable &target ) const { // universe touches everything switch( target.type ) { case Type_ray: - ((Ray*)&target)->collisionDistance = 0.0f; + ((const Ray&)target).collisionDistance = 0.0f; break; case Type_line: - ((Line*)&target)->ray.collisionDistance = 0.0f; + ((const Line&)target).ray.collisionDistance = 0.0f; break; default: break; } @@ -36,32 +40,32 @@ bool Universe::Intersects( const ICollideable &target, Float3 &worldPointOfConta switch( target.type ) { case Type_point: - worldPointOfContact = ((Point*)&target)->center; + worldPointOfContact = ((const Point&)target).center; break; case Type_sphere: - worldPointOfContact = ((Sphere*)&target)->center; + worldPointOfContact = ((const Sphere&)target).center; break; case Type_plane: - worldPointOfContact = ((Plane*)&target)->normal * ((Plane*)&target)->phasing; + worldPointOfContact = ((const Plane&)target).normal * ((const Plane&)target).phasing; break; case Type_box_axis_aligned: - worldPointOfContact = Average( ((BoxAxisAligned*)&target)->minVertex, ((BoxAxisAligned*)&target)->maxVertex ); + worldPointOfContact = Average( ((const BoxAxisAligned&)target).minVertex, ((const BoxAxisAligned&)target).maxVertex ); break; case Type_box: - worldPointOfContact = ((Box*)&target)->center; + worldPointOfContact = ((const Box&)target).center; break; case Type_frustrum: - worldPointOfContact = Average( ((Frustrum*)&target)->leftPlane.normal * ((Frustrum*)&target)->leftPlane.phasing, ((Frustrum*)&target)->rightPlane.normal * ((Frustrum*)&target)->rightPlane.phasing ); - worldPointOfContact = Average( worldPointOfContact, Average( ((Frustrum*)&target)->bottomPlane.normal * ((Frustrum*)&target)->bottomPlane.phasing, ((Frustrum*)&target)->topPlane.normal * ((Frustrum*)&target)->topPlane.phasing ) ); - worldPointOfContact = Average( worldPointOfContact, Average( ((Frustrum*)&target)->nearPlane.normal * ((Frustrum*)&target)->nearPlane.phasing, ((Frustrum*)&target)->farPlane.normal * ((Frustrum*)&target)->farPlane.phasing ) ); + worldPointOfContact = Average( ((const Frustrum&)target).leftPlane.normal * ((const Frustrum&)target).leftPlane.phasing, ((const Frustrum&)target).rightPlane.normal * ((const Frustrum&)target).rightPlane.phasing ); + worldPointOfContact = Average( worldPointOfContact, Average( ((const Frustrum&)target).bottomPlane.normal * ((const Frustrum&)target).bottomPlane.phasing, ((const Frustrum&)target).topPlane.normal * ((const Frustrum&)target).topPlane.phasing ) ); + worldPointOfContact = Average( worldPointOfContact, Average( ((const Frustrum&)target).nearPlane.normal * ((const Frustrum&)target).nearPlane.phasing, ((const Frustrum&)target).farPlane.normal * ((const Frustrum&)target).farPlane.phasing ) ); break; case Type_ray: - ((Ray*)&target)->collisionDistance = 0.0f; - worldPointOfContact = ((Ray*)&target)->origin; + ((const Ray&)target).collisionDistance = 0.0f; + worldPointOfContact = ((const Ray&)target).origin; break; case Type_line: - ((Line*)&target)->ray.collisionDistance = 0.0f; - worldPointOfContact = ((Line*)&target)->ray.origin; + ((const Line&)target).ray.collisionDistance = 0.0f; + worldPointOfContact = ((const Line&)target).ray.origin; break; default: worldPointOfContact = Float3::null; @@ -72,5 +76,6 @@ bool Universe::Intersects( const ICollideable &target, Float3 &worldPointOfConta } bool Universe::Contains( const ICollideable &target ) const -{ return true; } // universe contains everything - +{ // universe contains everything + return true; +} \ No newline at end of file