2013-11-06 22:52:00 +01:00
|
|
|
#include "Sphere.h"
|
2013-11-12 12:33:52 +01:00
|
|
|
#include "OysterCollision3D.h"
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
using namespace ::Oyster::Collision3D;
|
2013-11-06 22:52:00 +01:00
|
|
|
using namespace ::Oyster::Math;
|
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
Sphere::Sphere( ) : ICollideable(Type_sphere), center(), radius(0.0f) { }
|
|
|
|
Sphere::Sphere( const Float3 &_position, const Float &_radius ) : ICollideable(Type_sphere), center(_position), radius(_radius) {}
|
|
|
|
Sphere::~Sphere( ) {}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
Sphere & Sphere::operator = ( const Sphere &sphere )
|
|
|
|
{
|
|
|
|
this->center = sphere.center;
|
|
|
|
this->radius = sphere.radius;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:50:08 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer<ICollideable> Sphere::Clone( ) const
|
|
|
|
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Sphere(*this) ); }
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
bool Sphere::Intersects( const ICollideable *target ) const
|
|
|
|
{
|
|
|
|
switch( target->type )
|
|
|
|
{
|
2013-11-10 02:27:16 +01:00
|
|
|
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: Utility::Intersect( *this, *(Sphere*)target );
|
|
|
|
case Type_plane: return Utility::Intersect( *(Plane*)target, *this );
|
2013-11-21 11:47:34 +01:00
|
|
|
// case Type_triangle: return false; // TODO:
|
2013-11-10 02:27:16 +01:00
|
|
|
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:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Sphere::Contains( const ICollideable *target ) const
|
|
|
|
{
|
|
|
|
switch( target->type )
|
|
|
|
{
|
2013-11-10 02:27:16 +01:00
|
|
|
case Type_point: return Utility::Intersect( *this, *(Point*)target );
|
|
|
|
case Type_sphere: return Utility::Contains( *this, *(Sphere*)target );
|
2013-11-21 11:47:34 +01:00
|
|
|
// case Type_triangle: return false; // TODO:
|
2013-11-10 02:27:16 +01:00
|
|
|
case Type_box_axis_aligned: return false; // TODO:
|
|
|
|
case Type_box: return false; // TODO:
|
|
|
|
case Type_frustrum: return false; // TODO:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
2013-11-10 02:27:16 +01:00
|
|
|
}
|