2013-11-10 02:27:16 +01:00
|
|
|
#include "Universe.h"
|
2013-11-12 12:33:52 +01:00
|
|
|
#include "OysterCollision3D.h"
|
2013-11-10 02:27:16 +01:00
|
|
|
|
2013-12-16 09:36:41 +01:00
|
|
|
using namespace ::Utility::Value;
|
|
|
|
using namespace ::Oyster::Math;
|
2013-11-10 02:27:16 +01:00
|
|
|
using namespace ::Oyster::Collision3D;
|
2013-11-13 14:50:08 +01:00
|
|
|
using namespace ::Utility::DynamicMemory;
|
2013-11-10 02:27:16 +01:00
|
|
|
|
|
|
|
Universe::Universe() : ICollideable(Type_universe) {}
|
|
|
|
Universe::~Universe() {}
|
|
|
|
|
|
|
|
Universe & Universe::operator = ( const Universe &universe )
|
|
|
|
{ return *this; }
|
|
|
|
|
|
|
|
UniquePointer<ICollideable> Universe::Clone( ) const
|
|
|
|
{ return UniquePointer<ICollideable>( new Universe(*this) ); }
|
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Universe::Intersects( const ICollideable &target ) const
|
2013-11-10 02:27:16 +01:00
|
|
|
{ // universe touches everything
|
2013-11-25 14:22:38 +01:00
|
|
|
switch( target.type )
|
2013-11-10 02:27:16 +01:00
|
|
|
{
|
|
|
|
case Type_ray:
|
2013-11-25 14:22:38 +01:00
|
|
|
((Ray*)&target)->collisionDistance = 0.0f;
|
2013-11-10 02:27:16 +01:00
|
|
|
break;
|
|
|
|
case Type_line:
|
2013-11-25 14:22:38 +01:00
|
|
|
((Line*)&target)->ray.collisionDistance = 0.0f;
|
2013-11-10 02:27:16 +01:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-16 09:36:41 +01:00
|
|
|
bool Universe::Intersects( const ICollideable &target, Float3 &worldPointOfContact ) const
|
|
|
|
{ // universe touches everything
|
|
|
|
switch( target.type )
|
|
|
|
{
|
|
|
|
case Type_point:
|
|
|
|
worldPointOfContact = ((Point*)&target)->center;
|
|
|
|
break;
|
|
|
|
case Type_sphere:
|
|
|
|
worldPointOfContact = ((Sphere*)&target)->center;
|
|
|
|
break;
|
|
|
|
case Type_plane:
|
|
|
|
worldPointOfContact = ((Plane*)&target)->normal * ((Plane*)&target)->phasing;
|
|
|
|
break;
|
|
|
|
case Type_box_axis_aligned:
|
|
|
|
worldPointOfContact = Average( ((BoxAxisAligned*)&target)->minVertex, ((BoxAxisAligned*)&target)->maxVertex );
|
|
|
|
break;
|
|
|
|
case Type_box:
|
|
|
|
worldPointOfContact = ((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 ) );
|
|
|
|
break;
|
|
|
|
case Type_ray:
|
|
|
|
((Ray*)&target)->collisionDistance = 0.0f;
|
|
|
|
worldPointOfContact = ((Ray*)&target)->origin;
|
|
|
|
break;
|
|
|
|
case Type_line:
|
|
|
|
((Line*)&target)->ray.collisionDistance = 0.0f;
|
|
|
|
worldPointOfContact = ((Line*)&target)->ray.origin;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
worldPointOfContact = Float3::null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Universe::Contains( const ICollideable &target ) const
|
2013-11-10 02:27:16 +01:00
|
|
|
{ return true; } // universe contains everything
|
|
|
|
|