2013-11-06 22:52:00 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by Dan Andersson 2013
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Line.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
|
|
|
Line::Line( ) : ICollideable(Type_line)
|
|
|
|
{
|
|
|
|
this->ray = Ray();
|
|
|
|
this->length = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
Line::Line( const class Ray &_ray, const Float &_length ) : ICollideable(Type_line)
|
|
|
|
{
|
|
|
|
this->ray = _ray;
|
|
|
|
this->length = _length;
|
|
|
|
}
|
|
|
|
|
|
|
|
Line::Line( const Float3 &origin, const Float3 &normalizedDirection, const Float &_length ) : ICollideable(Type_line)
|
|
|
|
{
|
|
|
|
this->ray = Ray( origin, normalizedDirection );
|
|
|
|
this->length = _length;
|
|
|
|
}
|
|
|
|
|
2013-11-10 02:27:16 +01:00
|
|
|
Line::~Line( ) {}
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
Line & Line::operator = ( const Line &line )
|
|
|
|
{
|
|
|
|
this->ray = line.ray;
|
|
|
|
this->length = line.length;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2013-11-13 14:50:08 +01:00
|
|
|
::Utility::DynamicMemory::UniquePointer<ICollideable> Line::Clone( ) const
|
|
|
|
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Line(*this) ); }
|
2013-11-06 22:52:00 +01:00
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Line::Intersects( const ICollideable &target ) const
|
2013-11-06 22:52:00 +01:00
|
|
|
{
|
2013-11-25 14:22:38 +01:00
|
|
|
if( target.type == Type_universe )
|
2013-11-10 02:27:16 +01:00
|
|
|
{
|
|
|
|
this->ray.collisionDistance = 0.0f;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-06 22:52:00 +01:00
|
|
|
if( this->ray.Intersects( target ) ) if( this->ray.collisionDistance >= 0.0f ) if( this->ray.collisionDistance <= this->length )
|
2013-11-10 02:27:16 +01:00
|
|
|
return true;
|
2013-11-06 22:52:00 +01:00
|
|
|
|
|
|
|
this->ray.collisionDistance = 0.0f;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-25 14:22:38 +01:00
|
|
|
bool Line::Contains( const ICollideable &target ) const
|
2013-11-10 02:27:16 +01:00
|
|
|
{ /* TODO: : */ return false; }
|