Bunch of implementations

This commit is contained in:
Dander7BD 2013-11-28 17:59:12 +01:00
parent 9d92b292d9
commit 834de9ba84
6 changed files with 158 additions and 43 deletions

View File

@ -51,7 +51,7 @@
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Implementation\Octree.cpp">
<Filter>Header Files\Implementation</Filter>
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -2,6 +2,9 @@
using namespace Oyster;
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)
{
@ -26,7 +29,7 @@ Octree& Octree::operator=(const Octree& orig)
return *this;
}
void Octree::AddObject(Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef)
void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef)
{
Data data;
//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->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);
@ -117,3 +120,52 @@ ICustomBody* Octree::GetCustomBody(const unsigned int tempRef)
{
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
}

View File

@ -15,6 +15,8 @@ namespace Oyster
class Octree
{
public:
static const unsigned int invalid_ref;
typedef void(*VistorAction)(Octree&, unsigned int, unsigned int);
struct Data
@ -52,11 +54,17 @@ namespace Oyster
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:
std::vector < Data > leafData;
std::vector < Data* > updateQueue;
std::map< ICustomBody*, unsigned int > mapReferences;
std::map< const ICustomBody*, unsigned int > mapReferences;
OctreeNode worldNode;
};

View File

@ -42,21 +42,24 @@ API & API::Instance()
}
API_Impl::API_Impl()
: gravityConstant( Constant::gravity_constant ),
updateFrameLength( 1.0f / 120.0f ),
destructionAction( Default::EventAction_Destruction )
{}
{
this->gravityConstant = Constant::gravity_constant;
this->updateFrameLength = 1.0f / 120.0f;
this->destructionAction = Default::EventAction_Destruction;
this->worldScene = Octree();
}
API_Impl::~API_Impl() {}
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 )
@ -98,68 +101,117 @@ void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef )
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 NULL;
return this->worldScene.Extract( 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 )
{
//! @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 )
{
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 )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
//! @todo TODO: implement stub
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepVelocity( localI );
}
}
void API_Impl::SetMomentOfInertiaTensor_KeepMomentum( const ICustomBody* objRef, const Float4x4 &localI )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
//! @todo TODO: implement stub
this->worldScene.GetCustomBody( tempRef )->SetMomentOfInertiaTensor_KeepMomentum( localI );
}
}
void API_Impl::SetMass_KeepVelocity( const ICustomBody* objRef, Float m )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
//! @todo TODO: implement stub
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepVelocity( m );
}
}
void API_Impl::SetMass_KeepMomentum( const ICustomBody* objRef, Float m )
{ // deprecated
unsigned int tempRef = this->worldScene.GetTemporaryReferenceOf( objRef );
if( tempRef != this->worldScene.invalid_ref )
{
//! @todo TODO: implement stub
this->worldScene.GetCustomBody( tempRef )->SetMass_KeepMomentum( m );
}
}
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 )
{
//! @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 )
{
//! @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 )
{
//! @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
@ -172,9 +224,10 @@ UniquePointer<ICustomBody> API_Impl::CreateRigidBody( const API::SphericalBodyDe
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. */ }
@ -182,5 +235,5 @@ namespace Oyster { namespace Physics { namespace Default
{ /* Do nothing except returning business as usual. */
return ::Oyster::Physics::ICustomBody::SubscriptMessage_none;
}
} } }
}
} }

View File

@ -2,6 +2,7 @@
#define PHYSICS_API_IMPL_H
#include "../PhysicsAPI.h"
#include "Octree.h"
namespace Oyster
{
@ -15,7 +16,7 @@ namespace Oyster
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 SetSubscription( EventAction_Destruction functionPointer );
@ -47,6 +48,7 @@ namespace Oyster
private:
::Oyster::Math::Float gravityConstant, updateFrameLength;
EventAction_Destruction destructionAction;
Octree worldScene;
};
namespace Default

View File

@ -64,7 +64,7 @@ namespace Oyster
/********************************************************
* 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