diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 538408c5..cce1dfcd 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -55,7 +55,7 @@ bool LobbyState::LoadModels(std::wstring file) modelData.world = Oyster::Math3D::Float4x4::identity; modelData.visible = true; - modelData.modelPath = L"..\\Content\\Models\\box_2.dan"; + modelData.modelPath = L"crate_colonists.dan"; // load models privData->object[0] = new C_StaticObj(); privData->object[0]->Init(modelData); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 81c71de6..14a5d140 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -72,11 +72,11 @@ void Level::InitiateLevel(float radius) //this->dynamicObjects = new DynamicArray< DynamicObject>; // add box API::SimpleBodyDescription sbDesc_TestBox; - sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0); + sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,1); sbDesc_TestBox.ignoreGravity = false; sbDesc_TestBox.mass = 20; - sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0); + sbDesc_TestBox.size = Oyster::Math::Float4(1,1,1,0); ICustomBody* rigidBody_TestBox; @@ -132,7 +132,7 @@ void Level::InitiateLevel(float radius) sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 1); sbDesc_Crystal.ignoreGravity = false; sbDesc_Crystal.mass = 80; - sbDesc_Crystal.size = Oyster::Math::Float3(2,3,2); + sbDesc_Crystal.size = Oyster::Math::Float3(1,2,1); ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release(); rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel); diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index ebd5c275..b7e392fe 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -158,10 +158,10 @@ void Object::EndFrame() } - if(currPhysicsState.GetGravityNormal()!= Float3::null) + //if(currPhysicsState.GetGravityNormal()!= Float3::null) { Oyster::Math::Float4 axis; - Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(currPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(currPhysicsState.GetGravityNormal()), axis); + Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(currPhysicsState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, Oyster::Math::Float4(currPhysicsState.GetCenterPosition().GetNormalized(), 0), axis); if(axis !=axis) { //error @@ -170,17 +170,17 @@ void Object::EndFrame() axis.Normalize(); currPhysicsState.SetRotation(axis.xyz); currPhysicsState.SetAngularMomentum(Float3::null); - Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); - debug += currPhysicsState.GetGravityNormal(); + //Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); + //debug += currPhysicsState.GetGravityNormal(); } - Oyster::Math::Float3 pos = currPhysicsState.GetCenterPosition(); - Oyster::Math::Float3 up = -currPhysicsState.GetGravityNormal(); + //Oyster::Math::Float3 pos = currPhysicsState.GetCenterPosition(); + //Oyster::Math::Float3 up = -currPhysicsState.GetGravityNormal(); //300, 0,0, //1,0,0 - /*if( pos.GetLength() < 303.5f) + /*if( pos.GetLength() < 301.5f) { - Oyster::Math::Float moveUp = 303.5 - pos.GetLength(); + Oyster::Math::Float moveUp = 301.5 - pos.GetLength(); up *= moveUp; currPhysicsState.SetCenterPosition(pos + up); diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 85b474d2..06319fba 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -178,9 +178,7 @@ namespace ICustomBody::State protoState; proto->GetState( protoState ); ICustomBody::State deuterState; deuter->GetState( deuterState ); - // calc from perspective of deuter. - // calc from perspective of deuter. - Float4 normal = (worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f )).GetNormalized(); // Init value is only borrowed + Float4 normal = (worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f )); // Init value is only borrowed if( normal.Dot(normal) > 0.0f ) { deuter->GetNormalAt( worldPointOfContact, normal ); @@ -208,7 +206,7 @@ namespace Float protoG_Magnitude = protoG.Dot( normal ), deuterG_Magnitude = deuterG.Dot( normal ); - if(protoState.GetMass() == 70) + if(protoState.GetMass() == 20) { const char *breakpoint = "STOP"; } @@ -234,7 +232,11 @@ namespace return; } - // calc from perspective of proto + // bounce + Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), + deuterState.GetMass(), deuterG_Magnitude, + protoState.GetMass(), protoG_Magnitude ); + normal = (worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f )).GetNormalized(); if( normal.Dot(normal) > 0.0f ) { @@ -260,10 +262,7 @@ namespace Float4(protoState.GetLinearMomentum(), 0), protoState.GetFrictionCoeff_Static(), protoState.GetFrictionCoeff_Kinetic(), protoState.GetMass(), Float4(deuterState.GetLinearMomentum(), 0), deuterState.GetFrictionCoeff_Static(), deuterState.GetFrictionCoeff_Kinetic(), deuterState.GetMass()); - if(protoState.GetMass() == 70) - { - const char *breakpoint = "STOP"; - } + protoState.ApplyFriction( -friction.xyz ); @@ -279,21 +278,7 @@ namespace } - if(protoState.GetMass() == 50) - { - const char* breakPoint = "Break"; - } - - // bounce - Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), - deuterState.GetMass(), deuterG_Magnitude, - protoState.GetMass(), protoG_Magnitude ); - - // calc from perspective of proto - proto->GetNormalAt( worldPointOfContact, normal ); - normal.Normalize(); - protoG_Magnitude = protoG.Dot( normal ); - deuterG_Magnitude = deuterG.Dot( normal ); + // bounce Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), @@ -411,7 +396,7 @@ void API_Impl::Update() { const char *breakpoint = "STOP"; } - Float force = Physics3D::Formula::ForceField( this->gravityConstant, state.GetMass(), this->gravity[i].well.mass, rSquared ); + Float force = 9.82*10; gravityImpulse += ((this->updateFrameLength * force)) * d.GetNormalized(); } break; @@ -430,7 +415,7 @@ void API_Impl::Update() if( gravityImpulse != gravityImpulse ) // debug: trap const char *breakpoint = "This should never happen"; Float posLength = state.GetCenterPosition().GetLength(); - if( gravityImpulse != Float4::null && posLength - 300 > 3.5 ) + if( gravityImpulse != Float4::null && posLength - 300 > state.GetReach().y ) { state.ApplyLinearImpulse( gravityImpulse.xyz ); state.SetGravityNormal( gravityImpulse.GetNormalized().xyz ); @@ -453,7 +438,7 @@ void API_Impl::Update() //LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp(state.SetOrientation(, Float4(state.GetGravityNormal(), 0.0f), 1.0f); - /*if( abs(lM.x) < this->epsilon ) + if( abs(lM.x) < this->epsilon ) { state.linearMomentum.x = 0; } @@ -464,7 +449,7 @@ void API_Impl::Update() if( abs(lM.z) < this->epsilon ) { state.linearMomentum.z = 0; - }*/ + } (*proto)->SetState( state ); diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index b57c2a97..f1c196f7 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -335,17 +335,17 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength ) timeStepLength *= 2.0f - this->collisionRebound.timeOfContact; // compensate for rebounded time this->collisionRebound.timeOfContact = 1.0f; } - + // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) Float4 temp; ::std::modf( this->rigid.axis * (0.5f / pi), temp.xyz ); this->rigid.axis -= ((2.0f * pi) * temp).xyz; - + // Update rebound data this->collisionRebound.previousSpatial.center = this->rigid.centerPos; this->collisionRebound.previousSpatial.axis = this->rigid.axis; this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; - + // Check if this is close enough to be set resting temp = Float4( this->rigid.impulse_Linear, 0.0f ) + Float4( this->rigid.impulse_Angular, 0.0f ); if( temp.Dot(temp) <= (Constant::epsilon * Constant::epsilon) ) diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index ac566abd..0ecb8b6e 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -257,17 +257,17 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength ) timeStepLength *= 2.0f - this->collisionRebound.timeOfContact; // compensate for rebounded time this->collisionRebound.timeOfContact = 1.0f; } - + // Maintain rotation resolution by keeping axis within [0, 2pi] (trigonometric methods gets faster too) Float4 temp; ::std::modf( this->rigid.axis * (0.5f / pi), temp.xyz ); this->rigid.axis -= ((2.0f * pi) * temp).xyz; - + // Update rebound data this->collisionRebound.previousSpatial.center = this->rigid.centerPos; this->collisionRebound.previousSpatial.axis = this->rigid.axis; this->collisionRebound.previousSpatial.reach = this->rigid.boundingReach; - + // Check if this is close enough to be set resting temp = Float4( this->rigid.impulse_Linear, 0.0f ) + Float4( this->rigid.impulse_Angular, 0.0f ); if( temp.Dot(temp) <= (Constant::epsilon * Constant::epsilon) ) diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index d9f2f69d..957d28a0 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -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; }