From 1633129a2c28cb66ea035210f5c1ef0b7a77a73d Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Fri, 7 Feb 2014 13:09:44 +0100 Subject: [PATCH] Commit to Dennis --- .../DanBiasGame/GameClientState/GameState.cpp | 2 +- .../Implementation/PhysicsAPI_Impl.cpp | 34 ++++++++++--------- Code/OysterPhysics3D/RigidBody.cpp | 10 +++--- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index d8547943..8b47400a 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -353,7 +353,7 @@ void GameState::readKeyInput(InputClass* KeyInput) } //send delta mouse movement - if (KeyInput->IsMousePressed()) + //if (KeyInput->IsMousePressed()) { camera->Yaw(-KeyInput->GetYaw()); camera->Pitch(KeyInput->GetPitch()); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 06319fba..0203f87a 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -375,20 +375,21 @@ float API_Impl::GetFrameTimeLength() const void API_Impl::Update() { /** @todo TODO: Update is a temporary solution .*/ ::std::vector updateList; - auto proto = this->worldScene.Sample( Universe(), updateList ).begin(); + this->worldScene.Sample( Universe(), updateList ); ICustomBody::State state; - for( ; proto != updateList.end(); ++proto ) + for( int i = 0; i < updateList.size(); i++ ) { + auto proto = updateList[i]; // Step 1: Apply Gravity Float4 gravityImpulse = Float4::null; - (*proto)->GetState( state ); - for( ::std::vector::size_type i = 0; i < this->gravity.size(); ++i ) + proto->GetState( state ); + for( int j = 0; j < this->gravity.size(); ++j ) { - switch( this->gravity[i].gravityType ) + switch( this->gravity[j].gravityType ) { case Gravity::GravityType_Well: { - Float4 d = Float4( this->gravity[i].well.position, 1.0f ) - Float4( state.GetCenterPosition(), 1.0f ); + Float4 d = Float4( this->gravity[j].well.position, 1.0f ) - Float4( state.GetCenterPosition(), 1.0f ); Float rSquared = d.Dot( d ); if( rSquared != 0.0 ) { @@ -402,7 +403,7 @@ void API_Impl::Update() break; } case Gravity::GravityType_Directed: - gravityImpulse += Float4( this->gravity[i].directed.impulse, 0.0f ); + gravityImpulse += Float4( this->gravity[j].directed.impulse, 0.0f ); break; // case Gravity::GravityType_DirectedField: // //this->gravity[i].directedField. @@ -419,20 +420,21 @@ void API_Impl::Update() { state.ApplyLinearImpulse( gravityImpulse.xyz ); state.SetGravityNormal( gravityImpulse.GetNormalized().xyz ); - (*proto)->SetState( state ); + proto->SetState( state ); } if(state.GetMass() == 70) { const char *breakpoint = "STOP"; } // Step 2: Apply Collision Response - this->worldScene.Visit( *proto, OnPossibleCollision ); + this->worldScene.Visit( proto, OnPossibleCollision ); } - proto = updateList.begin(); - for( ; proto != updateList.end(); ++proto ) + + for( int i = 0; i < updateList.size(); i++ ) { - (*proto)->GetState( state ); + auto proto = updateList[i]; + proto->GetState( state ); Float3 lM = state.GetLinearMomentum(); //LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp(state.SetOrientation(, Float4(state.GetGravityNormal(), 0.0f), 1.0f); @@ -451,13 +453,13 @@ void API_Impl::Update() state.linearMomentum.z = 0; } - (*proto)->SetState( state ); + proto->SetState( state ); - switch( (*proto)->Update(this->updateFrameLength) ) + switch( proto->Update(this->updateFrameLength) ) { case UpdateState_altered: - this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(*proto) ); - (*proto)->CallSubscription_Move(); + this->worldScene.SetAsAltered( this->worldScene.GetTemporaryReferenceOf(proto) ); + proto->CallSubscription_Move(); case UpdateState_resting: default: break; diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 957d28a0..f7a5646e 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -51,8 +51,8 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) // 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; + 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 delta = AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); @@ -66,14 +66,14 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) // updating the angular // dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H - //this->axis += updateFrameLength * this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, AverageWithDelta(this->momentum_Angular, this->impulse_Angular) ); - //this->rotation = Rotation( this->axis ); + this->axis += updateFrameLength * this->momentOfInertiaTensor.CalculateAngularVelocity( this->rotation, AverageWithDelta(this->momentum_Angular, this->impulse_Angular) ); + this->rotation = Rotation( this->axis ); // update momentums and clear impulse_Linear and impulse_Angular this->momentum_Linear += this->impulse_Linear; this->impulse_Linear = Float4::null; - //this->momentum_Angular += this->impulse_Angular; //! HACK: @todo Rotation temporary disabled + this->momentum_Angular += this->impulse_Angular; //! HACK: @todo Rotation temporary disabled this->impulse_Angular = Float4::null; }