From 50d895d37c5d305f7de05df9dc5a75040bc13286 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 3 Feb 2014 10:45:25 +0100 Subject: [PATCH 1/3] Applied friction Needs to be tested. --- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 12c46cd5..ee47eeba 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -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() ); From b8e6b83148014baa487bb47b44ddd9964255a678 Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 3 Feb 2014 11:10:04 +0100 Subject: [PATCH 2/3] Momentum "fall-off" added Temporary till real fluid drag is implemented. --- Code/OysterPhysics3D/RigidBody.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index f053e8dd..70ded863 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -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 ) From f527d329a270b78e4a0a86783d4d4c0363afcb0f Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Mon, 3 Feb 2014 15:15:47 +0100 Subject: [PATCH 3/3] Added limbo functionality --- Code/GamePhysics/Implementation/Octree.cpp | 36 ++++++++++++++++--- Code/GamePhysics/Implementation/Octree.h | 7 ++++ .../Implementation/PhysicsAPI_Impl.cpp | 7 ++-- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/Code/GamePhysics/Implementation/Octree.cpp b/Code/GamePhysics/Implementation/Octree.cpp index b4395516..47bf3e39 100644 --- a/Code/GamePhysics/Implementation/Octree.cpp +++ b/Code/GamePhysics/Implementation/Octree.cpp @@ -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 (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::iterator it = this->mapReferences.find(customBodyRef); @@ -86,7 +114,7 @@ std::vector& Octree::Sample(ICustomBody* customBodyRef, std::vecto for(unsigned int i = 0; ileafData.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& Octree::Sample(const Oyster::Collision3D::ICollideabl { for(unsigned int i = 0; ileafData.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; ileafData.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; ileafData.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 ); } diff --git a/Code/GamePhysics/Implementation/Octree.h b/Code/GamePhysics/Implementation/Octree.h index 50b9569a..573738f2 100644 --- a/Code/GamePhysics/Implementation/Octree.h +++ b/Code/GamePhysics/Implementation/Octree.h @@ -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& Sample(ICustomBody* customBodyRef, std::vector& 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; diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index ee47eeba..9880526d 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -237,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 handle )