2013-11-06 22:52:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by Dan Andersson 2013
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Ray.h"
|
2013-11-12 00:10:48 +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-10 02:27:16 +01:00
|
|
|
Ray::Ray( ) : ICollideable(Type_ray), origin(), direction(), collisionDistance(0.0f) {}
|
|
|
|
Ray::Ray( const Float3 &o, const ::Oyster::Math::Float3 &d ) : ICollideable(Type_ray), origin(o), direction(d), collisionDistance(0.0f) {}
|
|
|
|
Ray::~Ray( ) {}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
Ray & Ray::operator = ( const Ray &ray )
|
|
|
|
{
|
|
|
|
this->origin = ray.origin;
|
|
|
|
this->direction = ray.direction;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
::Utility::Memory::UniquePointer<ICollideable> Ray::Clone( ) const
|
|
|
|
{ return ::Utility::Memory::UniquePointer<ICollideable>( new Ray(*this) ); }
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
bool Ray::Intersects( const ICollideable *target ) const
|
|
|
|
{
|
|
|
|
switch( target->type )
|
|
|
|
{
|
2013-11-10 02:27:16 +01:00
|
|
|
case Type_universe:
|
|
|
|
this->collisionDistance = 0.0f;
|
|
|
|
return true;
|
|
|
|
case Type_point: return Utility::Intersect( *this, *(Point*)target, this->collisionDistance );
|
|
|
|
case Type_ray: return Utility::Intersect( *this, *(Ray*)target, this->collisionDistance, ((Ray*)target)->collisionDistance );
|
|
|
|
case Type_sphere: return Utility::Intersect( *(Sphere*)target, *this, this->collisionDistance );
|
|
|
|
case Type_plane: return Utility::Intersect( *(Plane*)target, *this, this->collisionDistance );
|
|
|
|
case Type_triangle: return false; // TODO:
|
|
|
|
case Type_box_axis_aligned: return Utility::Intersect( *(BoxAxisAligned*)target, *this, this->collisionDistance );
|
|
|
|
case Type_box: return Utility::Intersect( *(Box*)target, *this, this->collisionDistance );
|
|
|
|
case Type_frustrum: return false; // TODO:
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Ray::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, this->collisionDistance );
|
|
|
|
case Type_ray: Utility::Contains( *this, *(Ray*)target );
|
2013-11-06 22:52:00 +01:00
|
|
|
default: return false;
|
|
|
|
}
|
2013-11-10 02:27:16 +01:00
|
|
|
}
|