2013-11-06 22:52:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by Dan Andersson 2013
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "BoxAxisAligned.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
|
|
|
BoxAxisAligned::BoxAxisAligned( ) : ICollideable(Type_box_axis_aligned)
|
|
|
|
{
|
|
|
|
this->minVertex = Float3(-0.5f,-0.5f,-0.5f );
|
|
|
|
this->maxVertex = Float3( 0.5f, 0.5f, 0.5f );
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxAxisAligned::BoxAxisAligned( const Float3 &_minVertex, const Float3 &_maxVertex ) : ICollideable(Type_box_axis_aligned)
|
|
|
|
{
|
|
|
|
this->minVertex = _minVertex;
|
|
|
|
this->maxVertex = _maxVertex;
|
|
|
|
}
|
|
|
|
|
|
|
|
BoxAxisAligned::BoxAxisAligned( const Float &leftClip, const Float &rightClip, const Float &topClip, const Float &bottomClip, const Float &nearClip, const Float &farClip ) : ICollideable(Type_box_axis_aligned)
|
|
|
|
{
|
|
|
|
this->minVertex = Float3( leftClip, bottomClip, nearClip );
|
|
|
|
this->maxVertex = Float3( rightClip, topClip, farClip );
|
|
|
|
}
|
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
BoxAxisAligned::~BoxAxisAligned( ) {}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
BoxAxisAligned & BoxAxisAligned::operator = ( const BoxAxisAligned &box )
|
|
|
|
{
|
|
|
|
this->minVertex = box.minVertex;
|
|
|
|
this->maxVertex = box.maxVertex;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:50:08 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer<ICollideable> BoxAxisAligned::Clone( ) const
|
2013-11-27 15:20:29 +01:00
|
|
|
{
|
|
|
|
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new BoxAxisAligned(*this) );
|
|
|
|
}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool BoxAxisAligned::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-11-10 02:27:16 +01:00
|
|
|
case Type_universe: return true;
|
2013-11-25 14:22:38 +01:00
|
|
|
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 );
|
2013-11-20 13:48:54 +01:00
|
|
|
// case Type_triangle: return false; // TODO:
|
2013-11-25 14:22:38 +01:00
|
|
|
case Type_box_axis_aligned: return Utility::Intersect( *this, *(BoxAxisAligned*)&target );
|
2013-11-20 13:48:54 +01:00
|
|
|
// 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-25 14:22:38 +01:00
|
|
|
bool BoxAxisAligned::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-11-20 13:48:54 +01:00
|
|
|
// 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:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
2013-11-10 02:27:16 +01:00
|
|
|
}
|