Added basic functionality for container

This commit is contained in:
Robin Engman 2013-11-28 11:18:07 +01:00
commit 28dc57cf38
20 changed files with 513 additions and 86 deletions

View File

@ -152,13 +152,15 @@
<ClInclude Include="Implementation\Octree.h" /> <ClInclude Include="Implementation\Octree.h" />
<ClInclude Include="Implementation\PhysicsAPI_Impl.h" /> <ClInclude Include="Implementation\PhysicsAPI_Impl.h" />
<ClInclude Include="Implementation\SimpleRigidBody.h" /> <ClInclude Include="Implementation\SimpleRigidBody.h" />
<ClInclude Include="Implementation\SphericalRigidBody.h" />
<ClInclude Include="PhysicsAPI.h" /> <ClInclude Include="PhysicsAPI.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Implementation\Octree.cpp" /> <ClCompile Include="Implementation\Octree.cpp" />
<ClCompile Include="Implementation\DLLMain.cpp" />
<ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" /> <ClCompile Include="Implementation\PhysicsAPI_Impl.cpp" />
<ClCompile Include="Implementation\SimpleRigidBody.cpp" /> <ClCompile Include="Implementation\SimpleRigidBody.cpp" />
<ClCompile Include="DLLMain.cpp" /> <ClCompile Include="Implementation\SphericalRigidBody.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -30,6 +30,9 @@
<ClInclude Include="Implementation\SimpleRigidBody.h"> <ClInclude Include="Implementation\SimpleRigidBody.h">
<Filter>Header Files\Implementation</Filter> <Filter>Header Files\Implementation</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Implementation\SphericalRigidBody.h">
<Filter>Header Files\Implementation</Filter>
</ClInclude>
<ClInclude Include="Implementation\Octree.h"> <ClInclude Include="Implementation\Octree.h">
<Filter>Header Files\Implementation</Filter> <Filter>Header Files\Implementation</Filter>
</ClInclude> </ClInclude>
@ -41,7 +44,10 @@
<ClCompile Include="Implementation\SimpleRigidBody.cpp"> <ClCompile Include="Implementation\SimpleRigidBody.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="DLLMain.cpp"> <ClCompile Include="Implementation\DLLMain.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Implementation\SphericalRigidBody.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Implementation\Octree.cpp"> <ClCompile Include="Implementation\Octree.cpp">

View File

@ -10,14 +10,6 @@ using namespace ::Utility::DynamicMemory;
API_Impl API_instance; API_Impl API_instance;
// default API::EventAction_Collision
void defaultCollisionAction( const ICustomBody *proto, const ICustomBody *deuter )
{ /* do nothing */ }
// default API::EventAction_Destruction
void defaultDestructionAction( UniquePointer<ICustomBody> proto )
{ /* do nothing besides proto auto deleting itself. */ }
Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius) Float4x4 & MomentOfInertia::CreateSphereMatrix( const Float mass, const Float radius)
{ {
return Formula::MomentOfInertia::Sphere(mass, radius); return Formula::MomentOfInertia::Sphere(mass, radius);
@ -51,27 +43,36 @@ API & API::Instance()
API_Impl::API_Impl() API_Impl::API_Impl()
: gravityConstant( Constant::gravity_constant ), : gravityConstant( Constant::gravity_constant ),
updateFrameLength( 1.0f / 120.0f ), updateFrameLength( 1.0f / 120.0f ),
collisionAction( defaultCollisionAction ), destructionAction( Default::EventAction_Destruction )
destructionAction( defaultDestructionAction )
{} {}
API_Impl::~API_Impl() {} API_Impl::~API_Impl() {}
void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize )
{
//! @todo TODO: implement stub
}
void API_Impl::SetDeltaTime( float deltaTime ) void API_Impl::SetDeltaTime( float deltaTime )
{ {
updateFrameLength = deltaTime; updateFrameLength = deltaTime;
} }
void API_Impl::SetGravityConstant( float g ) void API_Impl::SetGravityConstant( float g )
{ {
this->gravityConstant = g; this->gravityConstant = g;
} }
void API_Impl::SetAction( API::EventAction_Collision functionPointer )
void API_Impl::SetSubscription( API::EventAction_Destruction functionPointer )
{ {
this->collisionAction = functionPointer; if( functionPointer )
} {
void API_Impl::SetAction( API::EventAction_Destruction functionPointer ) this->destructionAction = functionPointer;
{ }
this->destructionAction = functionPointer; else
{
this->destructionAction = Default::EventAction_Destruction;
}
} }
void API_Impl::Update() void API_Impl::Update()
@ -155,7 +156,25 @@ void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orient
//! @todo TODO: implement stub //! @todo TODO: implement stub
} }
void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
{
//! @todo TODO: implement stub
}
UniquePointer<ICustomBody> API_Impl::CreateSimpleRigidBody() const UniquePointer<ICustomBody> API_Impl::CreateSimpleRigidBody() const
{ {
return new SimpleRigidBody(); return new SimpleRigidBody();
} }
namespace Oyster { namespace Physics { namespace Default
{
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto )
{ /* Do nothing except allowing the proto uniquePointer destroy itself. */ }
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter )
{ /* Do nothing except returning business as usual. */
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
}
} } }

View File

@ -13,10 +13,11 @@ namespace Oyster
API_Impl(); API_Impl();
virtual ~API_Impl(); virtual ~API_Impl();
void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize );
void SetDeltaTime( float deltaTime ); void SetDeltaTime( float deltaTime );
void SetGravityConstant( float g ); void SetGravityConstant( float g );
void SetAction( EventAction_Collision functionPointer ); void SetSubscription( EventAction_Destruction functionPointer );
void SetAction( EventAction_Destruction functionPointer );
void Update(); void Update();
@ -38,15 +39,20 @@ namespace Oyster
void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos ); void SetCenter( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation ); void SetRotation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ); void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size );
::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateSimpleRigidBody() const; ::Utility::DynamicMemory::UniquePointer<ICustomBody> CreateSimpleRigidBody() const;
private: private:
::Oyster::Math::Float gravityConstant, updateFrameLength; ::Oyster::Math::Float gravityConstant, updateFrameLength;
EventAction_Collision collisionAction;
EventAction_Destruction destructionAction; EventAction_Destruction destructionAction;
}; };
}
namespace Default
{
void EventAction_Destruction( ::Utility::DynamicMemory::UniquePointer<::Oyster::Physics::ICustomBody> proto );
::Oyster::Physics::ICustomBody::SubscriptMessage EventAction_Collision( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter );
}
}
} }
#endif #endif

View File

@ -7,7 +7,11 @@ using namespace ::Oyster::Collision3D;
using namespace ::Utility::DynamicMemory; using namespace ::Utility::DynamicMemory;
using namespace ::Utility::Value; using namespace ::Utility::Value;
SimpleRigidBody::SimpleRigidBody() : previous(), current() {} SimpleRigidBody::SimpleRigidBody()
: previous(), current(),
gravityNormal(0.0f),
collisionAction(Default::EventAction_Collision),
ignoreGravity(false) {}
SimpleRigidBody::~SimpleRigidBody() {} SimpleRigidBody::~SimpleRigidBody() {}
@ -16,9 +20,9 @@ UniquePointer<ICustomBody> SimpleRigidBody::Clone() const
return new SimpleRigidBody( *this ); return new SimpleRigidBody( *this );
} }
bool SimpleRigidBody::IsSubscribingCollisions() const bool SimpleRigidBody::IsAffectedByGravity() const
{ // Assumption {
return true; return !this->ignoreGravity;
} }
bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const bool SimpleRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const
@ -51,6 +55,11 @@ Float3 & SimpleRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem
return targetMem = (worldPos - this->current.box.center).GetNormalized(); return targetMem = (worldPos - this->current.box.center).GetNormalized();
} }
Float3 & SimpleRigidBody::GetGravityNormal( Float3 &targetMem ) const
{
return targetMem = this->gravityNormal;
}
Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const Float3 & SimpleRigidBody::GetCenter( Float3 &targetMem ) const
{ {
return targetMem = this->current.box.center; return targetMem = this->current.box.center;
@ -78,7 +87,30 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
this->current.Update_LeapFrog( timeStepLength ); this->current.Update_LeapFrog( timeStepLength );
// compare previous and new state and return result // compare previous and new state and return result
return this->current == this->previous ? resting : altered; return this->current == this->previous ? UpdateState_resting : UpdateState_altered;
}
void SimpleRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
{
if( functionPointer )
{
this->collisionAction = functionPointer;
}
else
{
this->collisionAction = Default::EventAction_Collision;
}
}
void SimpleRigidBody::SetGravity( bool ignore)
{
this->ignoreGravity = ignore;
this->gravityNormal = Float3::null;
}
void SimpleRigidBody::SetGravityNormal( const Float3 &normalizedVector )
{
this->gravityNormal = normalizedVector;
} }
void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI ) void SimpleRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
@ -114,4 +146,9 @@ void SimpleRigidBody::SetRotation( const Float4x4 &rotation )
void SimpleRigidBody::SetOrientation( const Float4x4 &orientation ) void SimpleRigidBody::SetOrientation( const Float4x4 &orientation )
{ {
this->current.SetOrientation( orientation ); this->current.SetOrientation( orientation );
}
void SimpleRigidBody::SetSize( const Float3 &size )
{
this->current.SetSize( size );
} }

View File

@ -14,12 +14,13 @@ namespace Oyster { namespace Physics
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const; ::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
bool IsSubscribingCollisions() const; bool IsAffectedByGravity() const;
bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const; bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const;
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const; bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const; ::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const;
::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const; ::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; ::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const; ::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
@ -27,6 +28,9 @@ namespace Oyster { namespace Physics
UpdateState Update( ::Oyster::Math::Float timeStepLength ); UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetSubscription( EventAction_Collision functionPointer );
void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ); void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ); void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( ::Oyster::Math::Float m ); void SetMass_KeepVelocity( ::Oyster::Math::Float m );
@ -34,9 +38,13 @@ namespace Oyster { namespace Physics
void SetCenter( const ::Oyster::Math::Float3 &worldPos ); void SetCenter( const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation ); void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ); void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ::Oyster::Math::Float3 &size );
private: private:
::Oyster::Physics3D::RigidBody previous, current; ::Oyster::Physics3D::RigidBody previous, current;
::Oyster::Math::Float3 gravityNormal;
EventAction_Collision collisionAction;
bool ignoreGravity;
}; };
} } } }

View File

@ -0,0 +1,159 @@
#include "SphericalRigidBody.h"
#include "PhysicsAPI_Impl.h"
using namespace ::Oyster::Physics;
using namespace ::Oyster::Math3D;
using namespace ::Oyster::Collision3D;
using namespace ::Utility::DynamicMemory;
using namespace ::Utility::Value;
SphericalRigidBody::SphericalRigidBody()
: previous(), current( Box(Float4x4::identity, Float3::null, Float3(1.0f)) ),
gravityNormal( 0.0f ),
collisionAction(Default::EventAction_Collision),
ignoreGravity( false ),
body( Float3::null, 0.5f ) {}
SphericalRigidBody::~SphericalRigidBody() {}
UniquePointer<ICustomBody> SphericalRigidBody::Clone() const
{
return new SphericalRigidBody( *this );
}
bool SphericalRigidBody::IsAffectedByGravity() const
{
return !this->ignoreGravity;
}
bool SphericalRigidBody::Intersects( const ICustomBody &object, Float timeStepLength, Float &deltaWhen, Float3 &worldPointOfContact ) const
{
if( object.Intersects(this->body) )
{ //! @todo TODO: better implementation needed
deltaWhen = timeStepLength;
worldPointOfContact = Average( this->body.center, object.GetCenter() );
return true;
}
else
{
return false;
}
}
bool SphericalRigidBody::Intersects( const ICollideable &shape ) const
{
return this->current.box.Intersects( shape );
}
Sphere & SphericalRigidBody::GetBoundingSphere( Sphere &targetMem ) const
{
return targetMem = this->body;
}
Float3 & SphericalRigidBody::GetNormalAt( const Float3 &worldPos, Float3 &targetMem ) const
{
//! @todo TODO: better implementation needed
return targetMem = (worldPos - this->current.box.center).GetNormalized();
}
Float3 & SphericalRigidBody::GetGravityNormal( Float3 &targetMem ) const
{
return targetMem = this->gravityNormal;
}
Float3 & SphericalRigidBody::GetCenter( Float3 &targetMem ) const
{
return targetMem = this->current.box.center;
}
Float4x4 & SphericalRigidBody::GetRotation( Float4x4 &targetMem ) const
{
return targetMem = this->current.box.rotation;
}
Float4x4 & SphericalRigidBody::GetOrientation( Float4x4 &targetMem ) const
{
return targetMem = this->current.GetOrientation();
}
Float4x4 & SphericalRigidBody::GetView( Float4x4 &targetMem ) const
{
return targetMem = this->current.GetView();
}
UpdateState SphericalRigidBody::Update( Float timeStepLength )
{
this->previous = this->current; // memorizing the old state
this->current.Update_LeapFrog( timeStepLength );
this->body.center = this->current.GetCenter();
// compare previous and new state and return result
return this->current == this->previous ? UpdateState_resting : UpdateState_altered;
}
void SphericalRigidBody::SetSubscription( ICustomBody::EventAction_Collision functionPointer )
{
if( functionPointer )
{
this->collisionAction = functionPointer;
}
else
{
this->collisionAction = Default::EventAction_Collision;
}
}
void SphericalRigidBody::SetGravity( bool ignore)
{
this->ignoreGravity = ignore;
this->gravityNormal = Float3::null;
}
void SphericalRigidBody::SetGravityNormal( const Float3 &normalizedVector )
{
this->gravityNormal = normalizedVector;
}
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepVelocity( const Float4x4 &localI )
{
this->current.SetMomentOfInertia_KeepVelocity( localI );
}
void SphericalRigidBody::SetMomentOfInertiaTensor_KeepMomentum( const Float4x4 &localI )
{
this->current.SetMomentOfInertia_KeepMomentum( localI );
}
void SphericalRigidBody::SetMass_KeepVelocity( Float m )
{
this->current.SetMass_KeepVelocity( m );
}
void SphericalRigidBody::SetMass_KeepMomentum( Float m )
{
this->current.SetMass_KeepMomentum( m );
}
void SphericalRigidBody::SetCenter( const Float3 &worldPos )
{
this->current.SetCenter( worldPos );
this->body.center = worldPos;
}
void SphericalRigidBody::SetRotation( const Float4x4 &rotation )
{
this->current.SetRotation( rotation );
}
void SphericalRigidBody::SetOrientation( const Float4x4 &orientation )
{
this->current.SetOrientation( orientation );
this->body.center = orientation.v[3].xyz;
}
void SphericalRigidBody::SetSize( const Float3 &size )
{
this->current.SetSize( size );
this->body.radius = 0.5f * Min( Min( size.x, size.y ), size.z ); // inline Min( FloatN )?
}

View File

@ -0,0 +1,54 @@
#ifndef OYSTER_PHYSICS_SPHERICAL_RIGIDBODY_H
#define OYSTER_PHYSICS_SPHERICAL_RIGIDBODY_H
#include "..\PhysicsAPI.h"
#include "RigidBody.h"
#include "Sphere.h"
namespace Oyster { namespace Physics
{
class SphericalRigidBody : public ICustomBody
{
public:
SphericalRigidBody();
virtual ~SphericalRigidBody();
::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const;
bool IsSubscribingCollisions() const;
bool IsAffectedByGravity() const;
bool Intersects( const ICustomBody &object, ::Oyster::Math::Float timeStepLength, ::Oyster::Math::Float &deltaWhen, ::Oyster::Math::Float3 &worldPointOfContact ) const;
bool Intersects( const ::Oyster::Collision3D::ICollideable &shape ) const;
::Oyster::Collision3D::Sphere & GetBoundingSphere( ::Oyster::Collision3D::Sphere &targetMem = ::Oyster::Collision3D::Sphere() ) const;
::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float3 & GetCenter( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const;
::Oyster::Math::Float4x4 & GetRotation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetOrientation( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const;
UpdateState Update( ::Oyster::Math::Float timeStepLength );
void SetSubscription( EventAction_Collision functionPointer );
void SetGravity( bool ignore);
void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector );
void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI );
void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI );
void SetMass_KeepVelocity( ::Oyster::Math::Float m );
void SetMass_KeepMomentum( ::Oyster::Math::Float m );
void SetCenter( const ::Oyster::Math::Float3 &worldPos );
void SetRotation( const ::Oyster::Math::Float4x4 &rotation );
void SetOrientation( const ::Oyster::Math::Float4x4 &orientation );
void SetSize( const ::Oyster::Math::Float3 &size );
private:
::Oyster::Physics3D::RigidBody previous, current;
::Oyster::Math::Float3 gravityNormal;
EventAction_Collision collisionAction;
bool ignoreGravity;
::Oyster::Collision3D::Sphere body;
};
} }
#endif

View File

@ -19,8 +19,8 @@ namespace Oyster
enum UpdateState enum UpdateState
{ {
resting, UpdateState_resting,
altered UpdateState_altered
}; };
namespace Constant namespace Constant
@ -45,12 +45,19 @@ namespace Oyster
class PHYSICS_DLL_USAGE API class PHYSICS_DLL_USAGE API
{ {
public: public:
typedef void (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer<ICustomBody> proto ); typedef void (*EventAction_Destruction)( ::Utility::DynamicMemory::UniquePointer<ICustomBody> proto );
/** Gets the Physics instance. */ /** Gets the Physics instance. */
static API & Instance(); static API & Instance();
/********************************************************
* Clears all content and reset Engine assetts such as buffers.
* @param numObjects: The predicted max number of active objects.
* @param numGravityWells: The predicted max number of active gravity wells.
* @param worldSize: The size of acceptable physics space.
********************************************************/
virtual void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize ) = 0;
/******************************************************** /********************************************************
* Sets the time length of each physics update frame. * Sets the time length of each physics update frame.
********************************************************/ ********************************************************/
@ -62,20 +69,15 @@ namespace Oyster
* @param g: Default is the real world Constant::gravity_constant [N(m/kg)^2] * @param g: Default is the real world Constant::gravity_constant [N(m/kg)^2]
********************************************************/ ********************************************************/
virtual void SetGravityConstant( float g ) = 0; virtual void SetGravityConstant( float g ) = 0;
/********************************************************
* Sets the function that will be called by the engine
* whenever a subscribed collision occurs.
********************************************************/
virtual void SetAction( EventAction_Collision functionPointer ) = 0;
/******************************************************** /********************************************************
* Sets the function that will be called by the engine * Sets the function that will be called by the engine
* whenever an object is being destroyed for some reason. * whenever an object is being destroyed for some reason.
* - Because DestroyObject(...) were called. * - Because DestroyObject(...) were called.
* - Out of memory forced engine to destroy an object. * - Out of memory forced engine to destroy an object.
* @param functionPointer: If NULL, an empty default function will be set.
********************************************************/ ********************************************************/
virtual void SetAction( EventAction_Destruction functionPointer ) = 0; virtual void SetSubscription( EventAction_Destruction functionPointer ) = 0;
/******************************************************** /********************************************************
* Triggers the engine to run next update frame. * Triggers the engine to run next update frame.
@ -133,7 +135,7 @@ namespace Oyster
* @param worldF: Vector with the direction and magnitude of the force. [N] * @param worldF: Vector with the direction and magnitude of the force. [N]
********************************************************/ ********************************************************/
virtual void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ) = 0; virtual void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ) = 0;
/******************************************************** /********************************************************
* Apply force on an object. * Apply force on an object.
* @param objRefA: A pointer to the ICustomBody representing a physical object. * @param objRefA: A pointer to the ICustomBody representing a physical object.
@ -196,6 +198,13 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0; virtual void SetOrientation( const ICustomBody* objRef, const ::Oyster::Math::Float4x4 &orientation ) = 0;
/********************************************************
* Resizes the boundingBox.
* @param objRef: A pointer to the ICustomBody representing a physical object.
* @param size: New size of this [m]
********************************************************/
virtual void SetSize( const ICustomBody* objRef, const ::Oyster::Math::Float3 &size ) = 0;
/******************************************************** /********************************************************
* Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies. * Creates a new dynamically allocated object that can be used as a component for more complex ICustomBodies.
* @return A pointer along with the responsibility to delete. * @return A pointer along with the responsibility to delete.
@ -210,6 +219,14 @@ namespace Oyster
class PHYSICS_DLL_USAGE ICustomBody class PHYSICS_DLL_USAGE ICustomBody
{ {
public: public:
enum SubscriptMessage
{
SubscriptMessage_none,
SubscriptMessage_ignore_collision_response
};
typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
virtual ~ICustomBody() {}; virtual ~ICustomBody() {};
/******************************************************** /********************************************************
@ -217,11 +234,11 @@ namespace Oyster
* @return An ICustomBody pointer along with the responsibility to delete. * @return An ICustomBody pointer along with the responsibility to delete.
********************************************************/ ********************************************************/
virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const = 0; virtual ::Utility::DynamicMemory::UniquePointer<ICustomBody> Clone() const = 0;
/******************************************************** /********************************************************
* @return true if Engine should call the EventAction_Collision function. * @return true if Engine should apply gravity on this object.
********************************************************/ ********************************************************/
virtual bool IsSubscribingCollisions() const = 0; virtual bool IsAffectedByGravity() const = 0;
/******************************************************** /********************************************************
* Performs a detailed Intersect test and returns if, when and where. * Performs a detailed Intersect test and returns if, when and where.
@ -254,6 +271,13 @@ namespace Oyster
********************************************************/ ********************************************************/
virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0; virtual ::Oyster::Math::Float3 & GetNormalAt( const ::Oyster::Math::Float3 &worldPos, ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
/********************************************************
* The gravity normal will have same direction as the total gravity force pulling on this and have the magnitude of 1.0f.
* @param targetMem: Provided memory that written into and then returned.
* @return a normalized vector in worldSpace. Exception: Null vector if no gravity been applied.
********************************************************/
virtual ::Oyster::Math::Float3 & GetGravityNormal( ::Oyster::Math::Float3 &targetMem = ::Oyster::Math::Float3() ) const = 0;
/******************************************************** /********************************************************
* The world position of this center of gravity. * The world position of this center of gravity.
* @param targetMem: Provided memory that written into and then returned. * @param targetMem: Provided memory that written into and then returned.
@ -280,52 +304,76 @@ namespace Oyster
virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0; virtual ::Oyster::Math::Float4x4 & GetView( ::Oyster::Math::Float4x4 &targetMem = ::Oyster::Math::Float4x4() ) const = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Is called during API::Update * Is called during API::Update
********************************************************/ ********************************************************/
virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0; virtual UpdateState Update( ::Oyster::Math::Float timeStepLength ) = 0;
/********************************************************
* Sets the function that will be called by the engine
* whenever a collision occurs.
* @param functionPointer: If NULL, an empty default function will be set.
********************************************************/
virtual void SetSubscription( EventAction_Collision functionPointer ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * @param ignore: True if Engine should not apply Gravity.
********************************************************/
virtual void SetGravity( bool ignore) = 0;
/********************************************************
* Used by Engine
* @param normalizedVector: Should have same direction as the pullinggravity.
********************************************************/
virtual void SetGravityNormal( const ::Oyster::Math::Float3 &normalizedVector ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead * Use API::SetMomentOfInertiaTensor_KeepVelocity(...) instead
********************************************************/ ********************************************************/
virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0; virtual void SetMomentOfInertiaTensor_KeepVelocity( const ::Oyster::Math::Float4x4 &localI ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetMomentOfInertiaTensor_KeepMomentum(...) * Use API::SetMomentOfInertiaTensor_KeepMomentum(...)
********************************************************/ ********************************************************/
virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0; virtual void SetMomentOfInertiaTensor_KeepMomentum( const ::Oyster::Math::Float4x4 &localI ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetMass_KeepVelocity(...) * Use API::SetMass_KeepVelocity(...)
********************************************************/ ********************************************************/
virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0; virtual void SetMass_KeepVelocity( ::Oyster::Math::Float m ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetMass_KeepMomentum(...) * Use API::SetMass_KeepMomentum(...)
********************************************************/ ********************************************************/
virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0; virtual void SetMass_KeepMomentum( ::Oyster::Math::Float m ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetCenter(...) * Use API::SetCenter(...)
********************************************************/ ********************************************************/
virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0; virtual void SetCenter( const ::Oyster::Math::Float3 &worldPos ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetRotation(...) * Use API::SetRotation(...)
********************************************************/ ********************************************************/
virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0; virtual void SetRotation( const ::Oyster::Math::Float4x4 &rotation ) = 0;
/******************************************************** /********************************************************
* To be only called by Engine * To not be called if is in Engine
* Use API::SetOrientation(...) * Use API::SetOrientation(...)
********************************************************/ ********************************************************/
virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0; virtual void SetOrientation( const ::Oyster::Math::Float4x4 &orientation ) = 0;
/********************************************************
* To not be called if is in Engine
* Use API::SetSize(...)
********************************************************/
virtual void SetSize( const ::Oyster::Math::Float3 &size ) = 0;
}; };
} }
} }

View File

@ -29,7 +29,7 @@ namespace LinearAlgebra
Matrix2x2( ); Matrix2x2( );
Matrix2x2( const ScalarType &m11, const ScalarType &m12, Matrix2x2( const ScalarType &m11, const ScalarType &m12,
const ScalarType &m21, const ScalarType &m22 ); const ScalarType &m21, const ScalarType &m22 );
Matrix2x2( const Vector2<ScalarType> vec[2] ); explicit Matrix2x2( const Vector2<ScalarType> vec[2] );
Matrix2x2( const Vector2<ScalarType> &vec1, const Vector2<ScalarType> &vec2 ); Matrix2x2( const Vector2<ScalarType> &vec1, const Vector2<ScalarType> &vec2 );
explicit Matrix2x2( const ScalarType element[4] ); explicit Matrix2x2( const ScalarType element[4] );
Matrix2x2( const Matrix2x2<ScalarType> &matrix ); Matrix2x2( const Matrix2x2<ScalarType> &matrix );
@ -80,7 +80,7 @@ namespace LinearAlgebra
Matrix3x3( const ScalarType &m11, const ScalarType &m12, const ScalarType &m13, Matrix3x3( const ScalarType &m11, const ScalarType &m12, const ScalarType &m13,
const ScalarType &m21, const ScalarType &m22, const ScalarType &m23, const ScalarType &m21, const ScalarType &m22, const ScalarType &m23,
const ScalarType &m31, const ScalarType &m32, const ScalarType &m33 ); const ScalarType &m31, const ScalarType &m32, const ScalarType &m33 );
Matrix3x3( const Vector3<ScalarType> vec[3] ); explicit Matrix3x3( const Vector3<ScalarType> vec[3] );
Matrix3x3( const Vector3<ScalarType> &vec1, const Vector3<ScalarType> &vec2, const Vector3<ScalarType> &vec3 ); Matrix3x3( const Vector3<ScalarType> &vec1, const Vector3<ScalarType> &vec2, const Vector3<ScalarType> &vec3 );
explicit Matrix3x3( const ScalarType element[9] ); explicit Matrix3x3( const ScalarType element[9] );
Matrix3x3( const Matrix3x3<ScalarType> &matrix ); Matrix3x3( const Matrix3x3<ScalarType> &matrix );
@ -132,7 +132,7 @@ namespace LinearAlgebra
const ScalarType &m21, const ScalarType &m22, const ScalarType &m23, const ScalarType &m24, const ScalarType &m21, const ScalarType &m22, const ScalarType &m23, const ScalarType &m24,
const ScalarType &m31, const ScalarType &m32, const ScalarType &m33, const ScalarType &m34, const ScalarType &m31, const ScalarType &m32, const ScalarType &m33, const ScalarType &m34,
const ScalarType &m41, const ScalarType &m42, const ScalarType &m43, const ScalarType &m44 ); const ScalarType &m41, const ScalarType &m42, const ScalarType &m43, const ScalarType &m44 );
Matrix4x4( const Vector4<ScalarType> vec[4] ); explicit Matrix4x4( const Vector4<ScalarType> vec[4] );
Matrix4x4( const Vector4<ScalarType> &vec1, const Vector4<ScalarType> &vec2, const Vector4<ScalarType> &vec3, const Vector4<ScalarType> &vec4 ); Matrix4x4( const Vector4<ScalarType> &vec1, const Vector4<ScalarType> &vec2, const Vector4<ScalarType> &vec3, const Vector4<ScalarType> &vec4 );
explicit Matrix4x4( const ScalarType element[16] ); explicit Matrix4x4( const ScalarType element[16] );
Matrix4x4( const Matrix4x4<ScalarType> &matrix ); Matrix4x4( const Matrix4x4<ScalarType> &matrix );

View File

@ -8,13 +8,19 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math3D; using namespace ::Oyster::Math3D;
Box::Box( ) Box::Box( ) : ICollideable(Type_box)
: ICollideable(Type_box), rotation(Float4x4::identity), center(0.0f), boundingOffset(0.5f) {
{} this->rotation = Float4x4::identity;
this->center =0.0f;
this->boundingOffset = Float3(0.5f);
}
Box::Box( const Float4x4 &r, const Float3 &p, const Float3 &s ) Box::Box( const Float4x4 &r, const Float3 &p, const Float3 &s ) : ICollideable(Type_box)
: ICollideable(Type_box), rotation(r), center(p), boundingOffset(s*0.5) {
{} this->rotation = r;
this->center = p;
this->boundingOffset = Float3(s*0.5);
}
Box::~Box( ) {} Box::~Box( ) {}

View File

@ -8,10 +8,24 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math3D; using namespace ::Oyster::Math3D;
BoxAxisAligned::BoxAxisAligned( ) : ICollideable(Type_box_axis_aligned), minVertex(-0.5f,-0.5f,-0.5f), maxVertex(0.5f,0.5f,0.5f) {} BoxAxisAligned::BoxAxisAligned( ) : ICollideable(Type_box_axis_aligned)
BoxAxisAligned::BoxAxisAligned( const Float3 &_minVertex, const Float3 &_maxVertex ) : ICollideable(Type_box_axis_aligned), minVertex(_minVertex), maxVertex(_maxVertex) {} {
BoxAxisAligned::BoxAxisAligned( const Float &leftClip, const Float &rightClip, const Float &topClip, const Float &bottomClip, const Float &nearClip, const Float &farClip ) this->minVertex = Float3(-0.5f,-0.5f,-0.5f );
: ICollideable(Type_box_axis_aligned), minVertex(leftClip, bottomClip, nearClip), maxVertex(rightClip, topClip, farClip) {} 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 );
}
BoxAxisAligned::~BoxAxisAligned( ) {} BoxAxisAligned::~BoxAxisAligned( ) {}
BoxAxisAligned & BoxAxisAligned::operator = ( const BoxAxisAligned &box ) BoxAxisAligned & BoxAxisAligned::operator = ( const BoxAxisAligned &box )
@ -22,7 +36,9 @@ BoxAxisAligned & BoxAxisAligned::operator = ( const BoxAxisAligned &box )
} }
::Utility::DynamicMemory::UniquePointer<ICollideable> BoxAxisAligned::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> BoxAxisAligned::Clone( ) const
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new BoxAxisAligned(*this) ); } {
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new BoxAxisAligned(*this) );
}
bool BoxAxisAligned::Intersects( const ICollideable &target ) const bool BoxAxisAligned::Intersects( const ICollideable &target ) const
{ {

View File

@ -74,13 +74,22 @@ namespace PrivateStatic
} }
} }
Frustrum::Frustrum() : ICollideable(Type_frustrum), Frustrum::Frustrum() : ICollideable(Type_frustrum)
leftPlane(Float3::standard_unit_x, -0.5f), rightPlane(-Float3::standard_unit_x, 0.5f), {
bottomPlane(Float3::standard_unit_y, -0.5f), topPlane(-Float3::standard_unit_y, 0.5f), this->leftPlane = Plane( Float3::standard_unit_x, -0.5f );
nearPlane(Float3::standard_unit_z, -0.5f), farPlane(-Float3::standard_unit_z, 0.5f) {} this->rightPlane = Plane(-Float3::standard_unit_x, 0.5f ),
this->bottomPlane = Plane( Float3::standard_unit_y, -0.5f );
this->topPlane = Plane(-Float3::standard_unit_y, 0.5f );
this->nearPlane = Plane( Float3::standard_unit_z, -0.5f );
this->farPlane = Plane(-Float3::standard_unit_z, 0.5f );
}
Frustrum::Frustrum( const Float4x4 &vp ) : ICollideable(Type_frustrum) Frustrum::Frustrum( const Float4x4 &vp ) : ICollideable(Type_frustrum)
{ PrivateStatic::VP_ToPlanes( this->leftPlane, this->rightPlane, this->bottomPlane, this->topPlane, this->nearPlane, this->farPlane, vp ); } {
PrivateStatic::VP_ToPlanes( this->leftPlane, this->rightPlane, this->bottomPlane,
this->topPlane, this->nearPlane, this->farPlane,
vp );
}
Frustrum::~Frustrum() {} Frustrum::~Frustrum() {}

View File

@ -6,7 +6,5 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
ICollideable::ICollideable( Type _type ) ICollideable::ICollideable( Type _type ) : type(_type) {}
: type(_type) {}
ICollideable::~ICollideable() {} ICollideable::~ICollideable() {}

View File

@ -8,9 +8,24 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math3D; using namespace ::Oyster::Math3D;
Line::Line( ) : ICollideable(Type_line), ray(), length(0.0f) {} Line::Line( ) : ICollideable(Type_line)
Line::Line( const class Ray &_ray, const Float &_length ) : ICollideable(Type_line), ray(_ray), length(_length) {} {
Line::Line( const Float3 &origin, const Float3 &normalizedDirection, const Float &_length ) : ICollideable(Type_line), ray(origin, normalizedDirection), length(_length) {} 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;
}
Line::~Line( ) {} Line::~Line( ) {}
Line & Line::operator = ( const Line &line ) Line & Line::operator = ( const Line &line )

View File

@ -8,8 +8,18 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math; using namespace ::Oyster::Math;
Plane::Plane( ) : ICollideable(Type_plane), normal(), phasing(0.0f) {} Plane::Plane( ) : ICollideable(Type_plane)
Plane::Plane( const Float3 &n, const Float &p ) : ICollideable(Type_plane), normal(n), phasing(p) {} {
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;
}
Plane::~Plane( ) {} Plane::~Plane( ) {}
Plane & Plane::operator = ( const Plane &plane ) Plane & Plane::operator = ( const Plane &plane )

View File

@ -8,8 +8,16 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math3D; using namespace ::Oyster::Math3D;
Point::Point( ) : ICollideable(Type_point), center() {} Point::Point( ) : ICollideable(Type_point)
Point::Point( const Float3 &pos ) : ICollideable(Type_point), center(pos) {} {
this->center = Float3::null;
}
Point::Point( const Float3 &pos ) : ICollideable(Type_point)
{
this->center = pos;
}
Point::~Point( ) {} Point::~Point( ) {}
Point & Point::operator = ( const Point &point ) Point & Point::operator = ( const Point &point )
@ -19,7 +27,9 @@ Point & Point::operator = ( const Point &point )
} }
::Utility::DynamicMemory::UniquePointer<ICollideable> Point::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Point::Clone( ) const
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Point(*this) ); } {
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Point(*this) );
}
bool Point::Intersects( const ICollideable &target ) const bool Point::Intersects( const ICollideable &target ) const
{ {

View File

@ -8,8 +8,20 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math3D; using namespace ::Oyster::Math3D;
Ray::Ray( ) : ICollideable(Type_ray), origin(), direction(), collisionDistance(0.0f) {} Ray::Ray( ) : ICollideable(Type_ray)
Ray::Ray( const Float3 &o, const ::Oyster::Math::Float3 &d ) : ICollideable(Type_ray), origin(o), direction(d), collisionDistance(0.0f) {} {
this->origin = Float3::null;
this->direction = Float3::standard_unit_z;
this->collisionDistance = 0.0f;
}
Ray::Ray( const Float3 &o, const ::Oyster::Math::Float3 &d ) : ICollideable(Type_ray)
{
this->origin = o;
this->direction = d;
this->collisionDistance = 0.0f;
}
Ray::~Ray( ) {} Ray::~Ray( ) {}
Ray & Ray::operator = ( const Ray &ray ) Ray & Ray::operator = ( const Ray &ray )
@ -20,7 +32,9 @@ Ray & Ray::operator = ( const Ray &ray )
} }
::Utility::DynamicMemory::UniquePointer<ICollideable> Ray::Clone( ) const ::Utility::DynamicMemory::UniquePointer<ICollideable> Ray::Clone( ) const
{ return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Ray(*this) ); } {
return ::Utility::DynamicMemory::UniquePointer<ICollideable>( new Ray(*this) );
}
bool Ray::Intersects( const ICollideable &target ) const bool Ray::Intersects( const ICollideable &target ) const
{ {

View File

@ -4,8 +4,18 @@
using namespace ::Oyster::Collision3D; using namespace ::Oyster::Collision3D;
using namespace ::Oyster::Math; using namespace ::Oyster::Math;
Sphere::Sphere( ) : ICollideable(Type_sphere), center(), radius(0.0f) { } Sphere::Sphere( ) : ICollideable(Type_sphere)
Sphere::Sphere( const Float3 &_position, const Float &_radius ) : ICollideable(Type_sphere), center(_position), radius(_radius) {} {
this->center = Float3::null;
this->radius = 0.0f;
}
Sphere::Sphere( const Float3 &_position, const Float &_radius ) : ICollideable(Type_sphere)
{
this->center = _position;
this->radius = _radius;
}
Sphere::~Sphere( ) {} Sphere::~Sphere( ) {}
Sphere & Sphere::operator = ( const Sphere &sphere ) Sphere & Sphere::operator = ( const Sphere &sphere )