2013-11-06 22:52:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by Dan Andersson 2013
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Plane.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-27 15:20:29 +01:00
|
|
|
Plane::Plane( ) : ICollideable(Type_plane)
|
|
|
|
{
|
|
|
|
this->normal = Float3::standard_unit_z;
|
|
|
|
this->phasing = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
Plane::Plane( const Float3 &n, const Float &p ) : ICollideable(Type_plane)
|
|
|
|
{
|
|
|
|
this->normal = n;
|
|
|
|
this->phasing = p;
|
|
|
|
}
|
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
Plane::~Plane( ) {}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
Plane & Plane::operator = ( const Plane &plane )
|
|
|
|
{
|
|
|
|
this->normal = plane.normal;
|
|
|
|
this->phasing = plane.phasing;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:50:08 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer<ICollideable> Plane::Clone( ) const
|
|
|
|
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Plane(*this) ); }
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Plane::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-21 11:47:34 +01:00
|
|
|
// case Type_triangle: return false; // TODO:
|
2013-11-25 14:22:38 +01:00
|
|
|
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)&target, *this );
|
|
|
|
case Type_box: return Utility::Intersect( *(Box*)&target, *this );
|
2013-11-10 02:27:16 +01:00
|
|
|
case Type_frustrum: return false; // TODO:
|
|
|
|
case Type_line: return false; // TODO:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-16 09:55:59 +01:00
|
|
|
bool Plane::Intersects( const ICollideable &target, ::Oyster::Math::Float3 &worldPointOfContact ) const
|
2013-12-16 09:38:04 +01:00
|
|
|
{
|
|
|
|
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:
|
2013-12-16 10:03:29 +01:00
|
|
|
case Type_box_axis_aligned: return false; // return Utility::Intersect( *(BoxAxisAligned*)&target, *this, worldPointOfContact );
|
|
|
|
case Type_box: return false; // return Utility::Intersect( *(Box*)&target, *this, worldPointOfContact );
|
2013-12-16 09:38:04 +01:00
|
|
|
case Type_frustrum: return false; // TODO:
|
|
|
|
default: worldPointOfContact = NULL;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Plane::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-25 14:22:38 +01:00
|
|
|
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 );
|
2013-11-21 11:47:34 +01:00
|
|
|
// case Type_triangle: return false; // TODO:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
2013-11-10 02:27:16 +01:00
|
|
|
}
|