From 7c448792dd61ee6af1e2b49554620a3c1319f500 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 17 Jan 2014 13:30:07 +0100 Subject: [PATCH] Gravity normal fix Forgot to update that value. Done --- .../Implementation/PhysicsAPI_Impl.cpp | 15 +++++++++++---- Code/GamePhysics/Implementation/PhysicsAPI_Impl.h | 6 +++--- Code/GamePhysics/PhysicsAPI.h | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index ae190608..9c12f7b0 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -163,7 +163,7 @@ void API_Impl::Update() for( ; proto != updateList.end(); ++proto ) { // Step 1: Apply Gravity - (*proto)->GetState( state ); + Float4 gravityImpulse = Float4::null; for( ::std::vector::size_type i = 0; i < this->gravity.size(); ++i ) { switch( this->gravity[i].gravityType ) @@ -175,12 +175,12 @@ void API_Impl::Update() if( rSquared != 0.0 ) { Float force = Physics3D::Formula::ForceField( this->gravityConstant, state.GetMass(), this->gravity[i].well.mass, rSquared ); - state.ApplyLinearImpulse( (this->updateFrameLength * force / ::std::sqrt(rSquared)) * d ); + gravityImpulse += (this->updateFrameLength * force / ::std::sqrt(rSquared)) * d; } break; } case Gravity::GravityType_Directed: - state.ApplyLinearImpulse( Float4(this->gravity[i].directed.impulse, 0.0f) ); + gravityImpulse += Float4( this->gravity[i].directed.impulse, 0.0f ); break; // case Gravity::GravityType_DirectedField: // //this->gravity[i].directedField. @@ -189,7 +189,14 @@ void API_Impl::Update() default: break; } } - (*proto)->SetState( state ); + + if( gravityImpulse != Float4::null ) + { + (*proto)->GetState( state ); + state.ApplyLinearImpulse( gravityImpulse ); + (*proto)->SetGravityNormal( gravityImpulse.GetNormalized().xyz ); + (*proto)->SetState( state ); + } // Step 2: Apply Collision Response this->worldScene.Visit( *proto, OnPossibleCollision ); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h index 314e0657..f62c973b 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.h @@ -32,8 +32,8 @@ namespace Oyster ::Utility::DynamicMemory::UniquePointer ExtractObject( const ICustomBody* objRef ); void DestroyObject( const ICustomBody* objRef ); - void AddGravity( const Gravity &g ); - void RemoveGravity( const Gravity &g ); + void AddGravity( const API::Gravity &g ); + void RemoveGravity( const API::Gravity &g ); //void ApplyForceAt( const ICustomBody* objRef, const ::Oyster::Math::Float3 &worldPos, const ::Oyster::Math::Float3 &worldF ); @@ -52,7 +52,7 @@ namespace Oyster private: ::Oyster::Math::Float gravityConstant, updateFrameLength; EventAction_Destruction destructionAction; - ::std::vector gravity; + ::std::vector gravity; Octree worldScene; }; diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 019a4af7..b42630e6 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -129,12 +129,12 @@ namespace Oyster /******************************************************** * TODO: @todo doc ********************************************************/ - virtual void AddGravity( const Gravity &g ) = 0; + virtual void AddGravity( const API::Gravity &g ) = 0; /******************************************************** * TODO: @todo doc ********************************************************/ - virtual void RemoveGravity( const Gravity &g ) = 0; + virtual void RemoveGravity( const API::Gravity &g ) = 0; ///******************************************************** // * Apply force on an object.