Merge remote-tracking branch 'origin/Physics' into GameLogic

This commit is contained in:
Erik Persson 2014-02-03 15:38:36 +01:00
commit f1f56fc769
4 changed files with 51 additions and 9 deletions

View File

@ -40,6 +40,7 @@ void Octree::AddObject(UniquePointer< ICustomBody > customBodyRef)
data.next = NULL;
data.prev = NULL;
data.customBodyRef = customBodyRef;
data.limbo = false;
this->mapReferences.insert(std::pair <ICustomBody*, unsigned int> (data.customBodyRef, this->leafData.size()));
this->leafData.push_back(data);
@ -64,6 +65,33 @@ void Octree::MoveToUpdateQueue(UniquePointer< ICustomBody > customBodyRef)
this->updateQueue.push_back(&this->leafData[this->mapReferences[customBodyRef]]);*/
}
void Octree::MoveToLimbo(const ICustomBody* customBodyRef)
{
auto object = this->mapReferences.find(customBodyRef);
unsigned int tempRef = object->second;
this->leafData[tempRef].limbo = true;
}
bool Octree::IsInLimbo(const ICustomBody* customBodyRef)
{
auto object = this->mapReferences.find(customBodyRef);
unsigned int tempRef = object->second;
return this->leafData[tempRef].limbo;
}
void Octree::ReleaseFromLimbo(const ICustomBody* customBodyRef)
{
auto object = this->mapReferences.find(customBodyRef);
unsigned int tempRef = object->second;
this->leafData[tempRef].limbo = false;
}
void Octree::DestroyObject(UniquePointer< ICustomBody > customBodyRef)
{
std::map<const ICustomBody*, unsigned int>::iterator it = this->mapReferences.find(customBodyRef);
@ -86,7 +114,7 @@ std::vector<ICustomBody*>& Octree::Sample(ICustomBody* customBodyRef, std::vecto
for(unsigned int i = 0; i<this->leafData.size(); i++)
{
if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
if(tempRef != i && !this->leafData[i].limbo) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
{
updateList.push_back(this->leafData[i].customBodyRef);
}
@ -99,7 +127,7 @@ std::vector<ICustomBody*>& Octree::Sample(const Oyster::Collision3D::ICollideabl
{
for(unsigned int i = 0; i<this->leafData.size(); i++)
{
if(this->leafData[i].container.Intersects(collideable))
if(!this->leafData[i].limbo && this->leafData[i].container.Intersects(collideable))
{
updateList.push_back(this->leafData[i].customBodyRef);
}
@ -121,7 +149,7 @@ void Octree::Visit(ICustomBody* customBodyRef, VisitorAction hitAction )
for(unsigned int i = 0; i<this->leafData.size(); i++)
{
if(tempRef != i) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
if(tempRef != i && !this->leafData[i].limbo) if(this->leafData[tempRef].container.Intersects(this->leafData[i].container))
{
hitAction(*this, tempRef, i);
}
@ -132,7 +160,7 @@ void Octree::Visit(const Oyster::Collision3D::ICollideable& collideable, void* a
{
for(unsigned int i = 0; i<this->leafData.size(); i++)
{
if(collideable.Intersects(this->leafData[i].container))
if(!this->leafData[i].limbo && collideable.Intersects(this->leafData[i].container))
{
hitAction( this->GetCustomBody(i), args );
}

View File

@ -29,6 +29,8 @@ namespace Oyster
::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef;
bool limbo;
unsigned int queueRef;
};
@ -48,6 +50,10 @@ namespace Oyster
void MoveToUpdateQueue(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
void MoveToLimbo(const ICustomBody* customBodyRef);
bool IsInLimbo(const ICustomBody* customBodyRef);
void ReleaseFromLimbo(const ICustomBody* customBodyRef);
void DestroyObject(::Utility::DynamicMemory::UniquePointer< ICustomBody > customBodyRef);
std::vector<ICustomBody*>& Sample(ICustomBody* customBodyRef, std::vector<ICustomBody*>& updateList);
@ -66,6 +72,7 @@ namespace Oyster
private:
std::vector < Data > leafData;
std::vector < Data* > updateQueue;
std::vector < Data* > limbo;
std::map< const ICustomBody*, unsigned int > mapReferences;

View File

@ -78,10 +78,14 @@ namespace
deuterState.GetMass(), deuterG_Magnitude );
Float4 bounce = Average( bounceD, bounceP );
Float4 friction = Formula::CollisionResponse::Friction( protoG_Magnitude, normal,
Float4(protoState.GetLinearMomentum(), 0), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(),
Float4(deuterState.GetLinearMomentum(), 0), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass());
Float kineticEnergyPBefore = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), protoState.GetLinearMomentum()/protoState.GetMass() );
protoState.ApplyImpulse( bounce.xyz, worldPointOfContact.xyz, normal.xyz );
protoState.ApplyImpulse( bounce.xyz - friction.xyz, worldPointOfContact.xyz, normal.xyz );
proto->SetState( protoState );
Float kineticEnergyPAFter = Oyster::Physics3D::Formula::LinearKineticEnergy( protoState.GetMass(), (protoState.GetLinearMomentum() + protoState.GetLinearImpulse())/protoState.GetMass() );
@ -233,17 +237,16 @@ void API_Impl::Update()
bool API_Impl::IsInLimbo( const ICustomBody* objRef )
{
//! @todo TODO: implement stub
return true;
return this->worldScene.IsInLimbo( objRef );
}
void API_Impl::MoveToLimbo( const ICustomBody* objRef )
{
/** @todo TODO: Fix this function.*/
this->worldScene.MoveToLimbo( objRef );
}
void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef )
{
/** @todo TODO: Fix this function.*/
this->worldScene.ReleaseFromLimbo( objRef );
}
void API_Impl::AddObject( ::Utility::DynamicMemory::UniquePointer<ICustomBody> handle )

View File

@ -49,6 +49,10 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength )
{ // by Dan Andersson: Euler leap frog update when Runga Kutta is not needed
// updating the linear
//Decrease momentum with 1% as "fall-off"
//! HACK: @todo Add real solution with fluid drag
this->momentum_Linear = this->momentum_Linear*0.99f;
this->momentum_Angular = this->momentum_Angular*0.99f;
// ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G
Float3 deltaPos = ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear );
if( deltaPos.GetLength() < 0.001f )