Bunch of implementations
This commit is contained in:
parent
9d92b292d9
commit
834de9ba84
|
@ -51,7 +51,7 @@
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Implementation\Octree.cpp">
|
<ClCompile Include="Implementation\Octree.cpp">
|
||||||
<Filter>Header Files\Implementation</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -2,6 +2,9 @@
|
||||||
|
|
||||||
using namespace Oyster;
|
using namespace Oyster;
|
||||||
using namespace Physics;
|
using namespace Physics;
|
||||||
|
using namespace ::Utility::DynamicMemory;
|
||||||
|
|
||||||
|
const unsigned int Octree::invalid_ref = ::Utility::Value::numeric_limits<unsigned int>::max();
|
||||||
|
|
||||||
Octree::Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize)
|
Octree::Octree(unsigned int bufferSize, unsigned char numLayers, Math::Float3 worldSize)
|
||||||
{
|
{
|
||||||
|
@ -26,7 +29,7 @@ Octree& Octree::operator=(const Octree& orig)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef)
|
void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef)
|
||||||
{
|
{
|
||||||
Data data;
|
Data data;
|
||||||
//Data* tempPtr = this->worldNode.dataPtr;
|
//Data* tempPtr = this->worldNode.dataPtr;
|
||||||
|
@ -54,15 +57,15 @@ void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > cust
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::MoveToUpdateQueue(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef)
|
void Octree::MoveToUpdateQueue(UniquePointer< ICustomBody > customBodyRef)
|
||||||
{
|
{
|
||||||
/*this->leafData[this->mapReferences[customBodyRef]].queueRef = this->updateQueue.size();
|
/*this->leafData[this->mapReferences[customBodyRef]].queueRef = this->updateQueue.size();
|
||||||
this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/
|
this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void Octree::DestroyObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef)
|
void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef)
|
||||||
{
|
{
|
||||||
std::map<ICustomBody*, unsigned int>::iterator it = this->mapReferences.find(customBodyRef);
|
std::map<const ICustomBody*, unsigned int>::iterator it = this->mapReferences.find(customBodyRef);
|
||||||
|
|
||||||
this->mapReferences.erase(it);
|
this->mapReferences.erase(it);
|
||||||
|
|
||||||
|
@ -117,3 +120,52 @@ ICustomBody* Octree::GetCustomBody(const unsigned int tempRef)
|
||||||
{
|
{
|
||||||
return this->leafData[tempRef].customBodyRef;
|
return this->leafData[tempRef].customBodyRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UniquePointer<ICustomBody> Octree::Extract( const ICustomBody* objRef )
|
||||||
|
{ // Dan Andersson
|
||||||
|
auto iter = this->mapReferences.find( objRef );
|
||||||
|
if( iter != this->mapReferences.end() )
|
||||||
|
{
|
||||||
|
return this->Extract( iter->second );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UniquePointer<ICustomBody> Octree::Extract( unsigned int tempRef )
|
||||||
|
{
|
||||||
|
if( tempRef != Octree::invalid_ref )
|
||||||
|
{
|
||||||
|
//! @todo TODO: implement stub
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int Octree::GetTemporaryReferenceOf( const ICustomBody* objRef ) const
|
||||||
|
{ // Dan Andersson
|
||||||
|
auto iter = this->mapReferences.find( objRef );
|
||||||
|
if( iter != this->mapReferences.end() )
|
||||||
|
{
|
||||||
|
return iter->second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Octree::invalid_ref;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Octree::SetAsAltered( unsigned int tempRef )
|
||||||
|
{
|
||||||
|
//! @todo TODO: implement stub
|
||||||
|
}
|
||||||
|
|
||||||
|
void Octree::EvaluatePosition( unsigned int tempRef )
|
||||||
|
{
|
||||||
|
//! @todo TODO: implement stub
|
||||||
|
}
|
|
@ -15,6 +15,8 @@ namespace Oyster
|
||||||
class Octree
|
class Octree
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static const unsigned int invalid_ref;
|
||||||
|
|
||||||
typedef void(*VistorAction)(Octree&, unsigned int, unsigned int);
|
typedef void(*VistorAction)(Octree&, unsigned int, unsigned int);
|
||||||
|
|
||||||
struct Data
|
struct Data
|
||||||
|
@ -52,11 +54,17 @@ namespace Oyster
|
||||||
|
|
||||||
ICustomBody* GetCustomBody(const unsigned int tempRef);
|
ICustomBody* GetCustomBody(const unsigned int tempRef);
|
||||||
|
|
||||||
|
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( const ICustomBody* objRef );
|
||||||
|
::Utility::DynamicMemory::UniquePointer<ICustomBody> Extract( unsigned int tempRef ); // Dan vill ha
|
||||||
|
unsigned int GetTemporaryReferenceOf( const ICustomBody* objRef ) const; // Dan vill ha
|
||||||
|
void SetAsAltered( unsigned int tempRef ); // Dan vill ha
|
||||||
|
void EvaluatePosition( unsigned int tempRef ); // Dan vill ha
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector < Data > leafData;
|
std::vector < Data > leafData;
|
||||||
std::vector < Data* > updateQueue;
|
std::vector < Data* > updateQueue;
|
||||||
|
|
||||||
std::map< ICustomBody*, unsigned int > mapReferences;
|
std::map< const ICustomBody*, unsigned int > mapReferences;
|
||||||
|
|
||||||
OctreeNode worldNode;
|
OctreeNode worldNode;
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,21 +42,24 @@ API & API::Instance()
|
||||||
}
|
}
|
||||||
|
|
||||||
API_Impl::API_Impl()
|
API_Impl::API_Impl()
|
||||||
: gravityConstant( Constant::gravity_constant ),
|
{
|
||||||
updateFrameLength( 1.0f / 120.0f ),
|
this->gravityConstant = Constant::gravity_constant;
|
||||||
destructionAction( Default::EventAction_Destruction )
|
this->updateFrameLength = 1.0f / 120.0f;
|
||||||
{}
|
this->destructionAction = Default::EventAction_Destruction;
|
||||||
|
this->worldScene = Octree();
|
||||||
|
}
|
||||||
|
|
||||||
API_Impl::~API_Impl() {}
|
API_Impl::~API_Impl() {}
|
||||||
|
|
||||||
void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize )
|
void API_Impl::Init( unsigned int numObjects, unsigned int numGravityWells , const Float3 &worldSize )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned char numLayers = 4; //!< @todo TODO: calc numLayers from worldSize
|
||||||
|
this->worldScene = Octree( numObjects, numLayers, worldSize );
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetDeltaTime( float deltaTime )
|
void API_Impl::SetFrameTimeLength( float deltaTime )
|
||||||
{
|
{
|
||||||
updateFrameLength = deltaTime;
|
this->updateFrameLength = deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetGravityConstant( float g )
|
void API_Impl::SetGravityConstant( float g )
|
||||||
|
@ -98,68 +101,117 @@ void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef )
|
||||||
|
|
||||||
void API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle )
|
void API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle )
|
||||||
{
|
{
|
||||||
/** @todo TODO: Fix this function.*/
|
this->worldScene.AddObject( handle );
|
||||||
}
|
}
|
||||||
|
|
||||||
::Utility::DynamicMemory::UniquePointer<ICustomBody> API_Impl::ExtractObject( const ICustomBody* objRef )
|
UniquePointer<ICustomBody> API_Impl::ExtractObject( const ICustomBody* objRef )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
return this->worldScene.Extract( objRef );
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::DestroyObject( const ICustomBody* objRef )
|
void API_Impl::DestroyObject( const ICustomBody* objRef )
|
||||||
{
|
{
|
||||||
/** @todo TODO: Fix this function.*/
|
UniquePointer<ICustomBody> object = this->worldScene.Extract( objRef );
|
||||||
|
if( object != NULL )
|
||||||
|
{
|
||||||
|
this->destructionAction( object );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
|
void API_Impl::ApplyForceAt( const ICustomBody* objRef, const Float3 &worldPos, const Float3 &worldF )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
//this->worldScene.GetCustomBody( tempRef )->Apply //!< @todo TODO: need function
|
||||||
|
this->worldScene.SetAsAltered( tempRef );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::ApplyCollisionResponse( const ICustomBody* objRefA, const ICustomBody* objRefB, Float &deltaWhen, Float3 &worldPointOfContact )
|
void API_Impl::ApplyCollisionResponse( const ICustomBody* objRefA, const ICustomBody* objRefB, Float &deltaWhen, Float3 &worldPointOfContact )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRefA );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
//! @todo TODO: implement stub
|
||||||
|
this->worldScene.SetAsAltered( tempRef );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const Float4x4 &localI )
|
void API_Impl::SetMomentOfInertiaTensor_KeepVelocity( const ICustomBody* objRef, const Float4x4 &localI )
|
||||||
{
|
{ // deprecated
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepVelocity( localI );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI )
|
void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI )
|
||||||
{
|
{ // deprecated
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepMomentum( localI );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m )
|
void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m )
|
||||||
{
|
{ // deprecated
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepVelocity( m );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m )
|
void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m )
|
||||||
{
|
{ // deprecated
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepMomentum( m );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetCenter( const ICustomBody* objRef, const Float3 &worldPos )
|
void API_Impl::SetCenter( const ICustomBody* objRef, const Float3 &worldPos )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
//this->worldScene.GetCustomBody( tempRef )->Set //!< @todo TODO: need function
|
||||||
|
this->worldScene.EvaluatePosition( tempRef );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetRotation( const ICustomBody* objRef, const Float4x4 &rotation )
|
void API_Impl::SetRotation( const ICustomBody* objRef, const Float4x4 &rotation )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetRotation( rotation );
|
||||||
|
this->worldScene.EvaluatePosition( tempRef );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orientation )
|
void API_Impl::SetOrientation( const ICustomBody* objRef, const Float4x4 &orientation )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetOrientation( orientation );
|
||||||
|
this->worldScene.EvaluatePosition( tempRef );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
|
void API_Impl::SetSize( const ICustomBody* objRef, const Float3 &size )
|
||||||
{
|
{
|
||||||
//! @todo TODO: implement stub
|
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
|
||||||
|
if( tempRef != this->worldScene.invalid_ref )
|
||||||
|
{
|
||||||
|
this->worldScene.GetCustomBody( tempRef )->SetSize( size );
|
||||||
|
this->worldScene.EvaluatePosition( tempRef );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SimpleBodyDescription &desc ) const
|
UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SimpleBodyDescription &desc ) const
|
||||||
|
@ -172,15 +224,16 @@ UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SphericalBodyDe
|
||||||
return new SphericalRigidBody( desc );
|
return new SphericalRigidBody( desc );
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Oyster { namespace Physics { namespace Default
|
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. */ }
|
||||||
|
|
||||||
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 )
|
||||||
{ /* Do nothing except allowing the proto uniquePointer destroy itself. */ }
|
{ /* Do nothing except returning business as usual. */
|
||||||
|
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
|
||||||
::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;
|
|
||||||
}
|
}
|
||||||
|
} }
|
||||||
} } }
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define PHYSICS_API_IMPL_H
|
#define PHYSICS_API_IMPL_H
|
||||||
|
|
||||||
#include "../PhysicsAPI.h"
|
#include "../PhysicsAPI.h"
|
||||||
|
#include "Octree.h"
|
||||||
|
|
||||||
namespace Oyster
|
namespace Oyster
|
||||||
{
|
{
|
||||||
|
@ -15,7 +16,7 @@ namespace Oyster
|
||||||
|
|
||||||
void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize );
|
void Init( unsigned int numObjects, unsigned int numGravityWells , const ::Oyster::Math::Float3 &worldSize );
|
||||||
|
|
||||||
void SetDeltaTime( float deltaTime );
|
void SetFrameTimeLength( float deltaTime );
|
||||||
void SetGravityConstant( float g );
|
void SetGravityConstant( float g );
|
||||||
void SetSubscription( EventAction_Destruction functionPointer );
|
void SetSubscription( EventAction_Destruction functionPointer );
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ namespace Oyster
|
||||||
private:
|
private:
|
||||||
::Oyster::Math::Float gravityConstant, updateFrameLength;
|
::Oyster::Math::Float gravityConstant, updateFrameLength;
|
||||||
EventAction_Destruction destructionAction;
|
EventAction_Destruction destructionAction;
|
||||||
|
Octree worldScene;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Default
|
namespace Default
|
||||||
|
|
|
@ -64,7 +64,7 @@ namespace Oyster
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* Sets the time length of each physics update frame.
|
* Sets the time length of each physics update frame.
|
||||||
********************************************************/
|
********************************************************/
|
||||||
virtual void SetDeltaTime( float seconds ) = 0;
|
virtual void SetFrameTimeLength( float seconds ) = 0;
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* Sets the Gravityconstant in the physics that will be
|
* Sets the Gravityconstant in the physics that will be
|
||||||
|
|
Loading…
Reference in New Issue