2013-11-06 22:52:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by Dan Andersson 2013
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Box.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;
|
|
|
|
using namespace ::Oyster::Math3D;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-27 15:20:29 +01:00
|
|
|
Box::Box( ) : ICollideable(Type_box)
|
|
|
|
{
|
|
|
|
this->rotation = Float4x4::identity;
|
|
|
|
this->center =0.0f;
|
|
|
|
this->boundingOffset = Float3(0.5f);
|
|
|
|
}
|
2013-11-20 16:58:56 +01:00
|
|
|
|
2013-11-27 15:20:29 +01:00
|
|
|
Box::Box( const Float4x4 &r, const Float3 &p, const Float3 &s ) : ICollideable(Type_box)
|
|
|
|
{
|
|
|
|
this->rotation = r;
|
|
|
|
this->center = p;
|
|
|
|
this->boundingOffset = Float3(s*0.5);
|
|
|
|
}
|
2013-11-20 16:58:56 +01:00
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
Box::~Box( ) {}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
Box & Box::operator = ( const Box &box )
|
|
|
|
{
|
2013-11-20 16:58:56 +01:00
|
|
|
this->rotation = box.rotation;
|
|
|
|
this->center = box.center;
|
2013-11-06 22:52:00 +01:00
|
|
|
this->boundingOffset = box.boundingOffset;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:50:08 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer<ICollideable> Box::Clone( ) const
|
2013-11-20 16:58:56 +01:00
|
|
|
{
|
|
|
|
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Box(*this) );
|
|
|
|
}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Box::Intersects( const ICollideable &target ) const
|
2013-11-06 22:52:00 +01:00
|
|
|
{
|
2013-11-25 14:22:38 +01:00
|
|
|
switch( target.type )
|
2013-11-06 22:52:00 +01:00
|
|
|
{
|
2013-12-17 14:14:54 +01:00
|
|
|
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;
|
2013-11-06 22:52:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 09:36:41 +01:00
|
|
|
bool Box::Intersects( const ICollideable &target, Float3 &worldPointOfContact ) const
|
|
|
|
{
|
2013-12-17 14:14:54 +01:00
|
|
|
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;
|
|
|
|
}
|
2013-12-16 09:36:41 +01:00
|
|
|
}
|
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Box::Contains( const ICollideable &target ) const
|
2013-11-06 22:52:00 +01:00
|
|
|
{
|
2013-11-25 14:22:38 +01:00
|
|
|
switch( target.type )
|
2013-11-06 22:52:00 +01:00
|
|
|
{
|
2013-12-17 14:14:54 +01:00
|
|
|
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:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
2013-11-10 02:27:16 +01:00
|
|
|
}
|