From 9622d37d3f8f33f4068e864be8b7b9872c05554b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 15:43:17 +0100 Subject: [PATCH 1/6] bug fixes in Physics collision handling --- .../Implementation/PhysicsAPI_Impl.cpp | 39 +++++++++++++------ Code/GamePhysics/PhysicsStructs-Impl.h | 7 +++- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 614014e2..8ca9235b 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -15,7 +15,7 @@ API_Impl API_instance; namespace { void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef ) - { /** @todo TODO: OnPossibleCollision is a temporary solution .*/ + { auto proto = worldScene.GetCustomBody( protoTempRef ); auto deuter = worldScene.GetCustomBody( deuterTempRef ); @@ -26,13 +26,30 @@ namespace ICustomBody::State protoState; proto->GetState( protoState ); ICustomBody::State deuterState; deuter->GetState( deuterState ); - Float4 protoG = protoState.GetLinearMomentum(worldPointOfContact.xyz ), - deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz ); - // calc from perspective of deuter Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal ); + + if( normal.Dot(normal) == 0.0f ) + { // special case: deuter is completly contained within proto or they have overlapping centers. + + normal = Float4( protoState.GetCenterPosition() - deuterState.GetCenterPosition(), 0.0f ); + if( normal.Dot(normal) == 0.0f ) + { // they have overlapping centers. Rebound at least + // calculate and store time interpolation value, for later rebound. + proto->SetTimeOfContact( worldPointOfContact ); + return; + } + + // borrowing the negated normal of proto. + proto->GetNormalAt( worldPointOfContact, normal ); + normal = -normal; + } + + Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ), + deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz ); + Float protoG_Magnitude = protoG.Dot( normal ), - deuterG_Magnitude = deuterG.Dot( normal ); + deuterG_Magnitude = deuterG.Dot( normal ); // if they are not relatively moving towards eachother, there is no collision Float deltaPos = normal.Dot( Float4(deuterState.GetCenterPosition(), 1) - Float4(protoState.GetCenterPosition(), 1) ); @@ -65,8 +82,8 @@ namespace // bounce Float4 bounceD = normal * -Formula::CollisionResponse::Bounce( deuterState.GetRestitutionCoeff(), - deuterState.GetMass(), deuterG_Magnitude, - protoState.GetMass(), protoG_Magnitude ); + deuterState.GetMass(), deuterG_Magnitude, + protoState.GetMass(), protoG_Magnitude ); // calc from perspective of proto @@ -76,14 +93,14 @@ namespace // bounce Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), - protoState.GetMass(), protoG_Magnitude, - deuterState.GetMass(), deuterG_Magnitude ); + protoState.GetMass(), protoG_Magnitude, + 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()); + 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() ); diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 311b81f8..d3907b54 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -159,7 +159,12 @@ namespace Oyster inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const { - return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos ); + ::Oyster::Math::Float3 offset = at - this->centerPos; + if( offset.Dot(offset) > 0.0f ) + { + return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, offset ); + } + return this->linearMomentum; } inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const From d8c72205695d16e2f421083559c70ceeb350211b Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 4 Feb 2014 16:08:28 +0100 Subject: [PATCH 2/6] GL - added some testing things in player and more objects to the world --- Code/Game/DanBiasGame/DanBiasGame_Impl.cpp | 4 +- .../DanBiasGame/GameClientState/GameState.cpp | 94 ++++++++++--------- Code/Game/GameLogic/Level.cpp | 54 +++++++++-- Code/Game/GameLogic/Level.h | 1 - Code/Game/GameLogic/Object.cpp | 26 ++++- Code/Game/GameLogic/Player.cpp | 32 ++++--- Code/Game/GameLogic/Player.h | 1 + .../Implementation/GameSession_Gameplay.cpp | 12 +++ 8 files changed, 155 insertions(+), 69 deletions(-) diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 83e48713..581a7505 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -163,9 +163,9 @@ namespace DanBias DanBias::GameServerAPI::GameStart(); m_data->recieverObj->gameClientState = new Client::GameState(); if(m_data->serverOwner) - ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(2); + ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(0); else - ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(3); + ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(1); break; default: return E_FAIL; diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index ad86797f..bdab4dfb 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -74,8 +74,9 @@ bool GameState::LoadModels(std::wstring mapFile) // open file // read file // init models - privData->modelCount = 2; - + privData->modelCount = 4; + myId += privData->modelCount; + int id = 0; // add world model ModelInitData modelData; Oyster::Math3D::Float4x4 translate; @@ -83,7 +84,7 @@ bool GameState::LoadModels(std::wstring mapFile) translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0)); modelData.world = translate ;//modelData.world * translate modelData.modelPath = L"world_earth.dan"; - modelData.id = 0; + modelData.id = id++; obj = new C_Player(); privData->object.push_back(obj); @@ -94,34 +95,21 @@ bool GameState::LoadModels(std::wstring mapFile) translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); modelData.world = modelData.world * translate; modelData.modelPath = L"..\\Content\\Models\\box.dan"; - modelData.id = 1; + modelData.id = id++; obj = new C_Player(); privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); modelData.world = Oyster::Math3D::Float4x4::identity; - // add player model + // add crystal model modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0)); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 305, 0)); modelData.world = modelData.world * translate; modelData.visible = true; - modelData.modelPath = L"char_renderTest.dan"; - modelData.id = 2; - // load models - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - - // add player model 2 - modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0)); - - modelData.world = modelData.world * translate; - modelData.visible = true; - modelData.modelPath = L"char_renderTest.dan"; - modelData.id = 3; + modelData.modelPath = L"crystalformation_b.dan"; + modelData.id = id++; // load models obj = new C_Player(); privData->object.push_back(obj); @@ -134,25 +122,39 @@ bool GameState::LoadModels(std::wstring mapFile) modelData.world = modelData.world * translate; modelData.visible = false; modelData.modelPath = L"building_corporation.dan"; - modelData.id = 4; + modelData.id = id++; // load models obj = new C_Player(); privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); - // add crystal model + // add player model modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 305, 0)); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0)); modelData.world = modelData.world * translate; modelData.visible = true; - modelData.modelPath = L"crystalformation_b.dan"; - modelData.id = 5; + modelData.modelPath = L"char_renderTest.dan"; + modelData.id = id++; // load models obj = new C_Player(); privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); - + + // add player model 2 + modelData.world = Oyster::Math3D::Float4x4::identity; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0)); + + modelData.world = modelData.world * translate; + modelData.visible = true; + modelData.modelPath = L"char_renderTest.dan"; + modelData.id = id++; + // load models + obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); + + return true; } @@ -309,8 +311,8 @@ void GameState::readKeyInput(InputClass* KeyInput) if (KeyInput->IsMousePressed()) { camera->Yaw(-KeyInput->GetYaw()); - //camera->Pitch(KeyInput->GetPitch()); - //pitch = KeyInput->GetPitch(); + camera->Pitch(KeyInput->GetPitch()); + pitch = KeyInput->GetPitch(); camera->UpdateViewMatrix(); GameLogic::Protocol_PlayerLook playerLookDir; Oyster::Math::Float4 look = camera->GetLook(); @@ -385,28 +387,34 @@ void GameState::Protocol( ObjPos* pos ) if(privData->object[i]->GetId() == pos->object_ID) { privData->object[i]->setPos(world); - //camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); - // - //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); + if(i == myId) // playerobj { - camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); - camera->setUp(Oyster::Math::Float3(world[4], world[5], world[6])); - Oyster::Math::Float3 cameraLook = camera->GetLook(); - Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10])); - - camera->setLook(objForward); - camera->UpdateViewMatrix(); - Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]); + Oyster::Math::Float3 right = Oyster::Math::Float3(world[0], world[1], world[2]); Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]); + Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10])); + Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]); + + Oyster::Math::Float3 cameraLook = camera->GetLook(); + Oyster::Math::Float3 cameraUp = camera->GetUp(); + + + + /*Oyster::Math::Float3 newUp = cameraUp.Dot(up); + up *= newUp; + up.Normalize(); + Oyster::Math::Float3 newLook = up.Cross(right); + newLook.Normalize();*/ + + camera->setRight(right); + camera->setUp(up); + //camera->setLook(objForward); up *= 2; objForward *= -3; Oyster::Math::Float3 cameraPos = up + pos + objForward; - //camera->Pitch(pitch); camera->SetPosition(cameraPos); - //camera->LookAt(pos, dir, up); - //Oyster::Math::Float3 newLook = objForward; + camera->UpdateViewMatrix(); } } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 858818f6..a80c76f2 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -39,30 +39,64 @@ void Level::InitiateLevel(float radius) levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); rigidBody->SetCustomTag(levelObj); - + //this->dynamicObjects = new DynamicArray< DynamicObject>; // add box API::SimpleBodyDescription sbDesc_TestBox; sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0); sbDesc_TestBox.ignoreGravity = false; sbDesc_TestBox.mass = 50; - sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0); + sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0); ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); - testBox = new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX); - rigidBody_TestBox->SetCustomTag(testBox); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + rigidBody_TestBox->SetCustomTag(this->dynamicObjects[0]); rigidBody_TestBox->GetState(state); state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); rigidBody_TestBox->SetState(state); + + // add crystal + API::SimpleBodyDescription sbDesc_Crystal; + sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0); + sbDesc_Crystal.ignoreGravity = false; + + sbDesc_Crystal.mass = 70; + sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0); + + + ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release(); + rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + rigidBody_Crystal->SetCustomTag(this->dynamicObjects[1]); + rigidBody_Crystal->GetState(state); + state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); + rigidBody_Crystal->SetState(state); + + // add house + API::SimpleBodyDescription sbDesc_House; + sbDesc_House.centerPosition = Oyster::Math::Float4(50, 300, 0, 0); + sbDesc_House.ignoreGravity = false; + + sbDesc_House.mass = 70; + sbDesc_House.size = Oyster::Math::Float4(2,3,2,0); + + + ICustomBody* rigidBody_House = API::Instance().CreateRigidBody(sbDesc_House).Release(); + rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel); + this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); + rigidBody_House->SetCustomTag(this->staticObjects[0]); + rigidBody_House->GetState(state); + state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); + rigidBody_House->SetState(state); // add gravitation API::Gravity gravityWell; gravityWell.gravityType = API::Gravity::GravityType_Well; - gravityWell.well.mass = 1e18f; + gravityWell.well.mass = 1e17f; gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); API::Instance().AddGravity(gravityWell); } @@ -84,10 +118,12 @@ void Level::RespawnPlayer(Player *player) Object* Level::GetObj( int ID) const { - if( ID == 0 ) - return (Object*)levelObj; - else - return (Object*)testBox; + for (int i = 0; i< this->dynamicObjects.Size(); i++) + { + if(this->dynamicObjects[i]->GetID() == ID) + return this->dynamicObjects[i]; + } + return NULL; } void Level::PhysicsOnMoveLevel(const ICustomBody *object) { diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 60f7a932..00fb76ef 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -71,7 +71,6 @@ namespace GameLogic GameMode gameMode; Utility::DynamicMemory::SmartPointer rigidBodyLevel; StaticObject *levelObj; - DynamicObject *testBox; }; diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index a000eaed..c7813e61 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -120,9 +120,21 @@ void Object::BeginFrame() { - - - + if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) + { + //error + int i =0 ; + } + if(currPhysicsState.GetCenterPosition() !=currPhysicsState.GetCenterPosition()) + { + //error + int i =0 ; + } + if(currPhysicsState.GetAngularAxis() !=currPhysicsState.GetAngularAxis()) + { + //error + int i =0 ; + } this->rigidBody->SetState(this->newPhysicsState); } // update physic @@ -130,6 +142,11 @@ void Object::EndFrame() { this->currPhysicsState = this->rigidBody->GetState(); + if(currPhysicsState.GetGravityNormal() !=currPhysicsState.GetGravityNormal()) + { + //error + int i =0 ; + } if(currPhysicsState.GetGravityNormal()!= Float3::null) { Oyster::Math::Float4 axis; @@ -144,6 +161,9 @@ void Object::EndFrame() Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); debug += currPhysicsState.GetGravityNormal(); } + + + this->newPhysicsState = this->currPhysicsState; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 29fc77cb..aa649461 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -6,7 +6,7 @@ using namespace GameLogic; using namespace Oyster::Physics; - +const int MOVE_FORCE = 50000; Player::Player() :DynamicObject() { @@ -67,8 +67,17 @@ void Player::BeginFrame() void Player::EndFrame() { - + // snap to axis Object::EndFrame(); + // rotate + + Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; + Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; + Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); + + currPhysicsState.AddRotation(deltaAxis); + dx = 0; + this->newPhysicsState = this->currPhysicsState; } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -101,13 +110,13 @@ void Player::MoveForward() { Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; //Oyster::Math::Float3 forward = lookDir; - newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime())); + newPhysicsState.ApplyLinearImpulse(forward * (MOVE_FORCE * this->gameInstance->GetFrameTime())); } void Player::MoveBackwards() { Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; //Oyster::Math::Float3 forward = lookDir; - newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(-forward * MOVE_FORCE * this->gameInstance->GetFrameTime()); } void Player::MoveRight() { @@ -115,7 +124,7 @@ void Player::MoveRight() Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; //Oyster::Math::Float3 forward = lookDir; Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); - newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(-r * MOVE_FORCE * this->gameInstance->GetFrameTime()); } void Player::MoveLeft() @@ -124,7 +133,7 @@ void Player::MoveLeft() Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; //Oyster::Math::Float3 forward = lookDir; Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero - newPhysicsState.ApplyLinearImpulse(r * 30000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(r * MOVE_FORCE * this->gameInstance->GetFrameTime()); } void Player::UseWeapon(const WEAPON_FIRE &usage) @@ -147,19 +156,20 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir) { int i =0 ; } - Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; - Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); + //Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; + //Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; + //Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); - newPhysicsState.SetRotation(oldOrt + deltaAxis); + //newPhysicsState.SetRotation(oldOrt + deltaAxis); this->lookDir = lookDir.xyz; + this->dx = lookDir.w; } void Player::Jump() { Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; - newPhysicsState.ApplyLinearImpulse(up * 30000 * this->gameInstance->GetFrameTime()); + newPhysicsState.ApplyLinearImpulse(up * MOVE_FORCE * this->gameInstance->GetFrameTime()); } bool Player::IsWalking() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index fddf4b44..f609d197 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -83,6 +83,7 @@ namespace GameLogic Weapon *weapon; PLAYER_STATE playerState; Oyster::Math::Float3 lookDir; + Oyster::Math::Float dx; bool hasTakenDamage; float invincibleCooldown; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 73ccba1a..ee6cc385 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -122,6 +122,18 @@ namespace DanBias GameSession::gameSession->Send(*p.GetProtocol()); } } + obj = NULL; + obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(2); + if(obj) + { + if(obj->GetObjectType() == OBJECT_TYPE_BOX) + { + int id = obj->GetID(); + Oyster::Math::Float4x4 world = obj->GetOrientation(); + Protocol_ObjectPosition p(world, id); + GameSession::gameSession->Send(*p.GetProtocol()); + } + } } } From 1952ff9aba78dd6a5bc6d09fca8ea1d0e7ae11d1 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 16:10:18 +0100 Subject: [PATCH 3/6] more fixes of potential bugs in Physics collision handling --- .../Implementation/PhysicsAPI_Impl.cpp | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 8ca9235b..61bcb706 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -26,12 +26,15 @@ namespace ICustomBody::State protoState; proto->GetState( protoState ); ICustomBody::State deuterState; deuter->GetState( deuterState ); - // calc from perspective of deuter - Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal ); - - if( normal.Dot(normal) == 0.0f ) + // calc from perspective of deuter. + Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed + if( normal.Dot(normal) > 0.0f ) + { + deuter->GetNormalAt( worldPointOfContact, normal ); + } + else { // special case: deuter is completly contained within proto or they have overlapping centers. - + normal = Float4( protoState.GetCenterPosition() - deuterState.GetCenterPosition(), 0.0f ); if( normal.Dot(normal) == 0.0f ) { // they have overlapping centers. Rebound at least @@ -87,9 +90,22 @@ namespace // calc from perspective of proto - proto->GetNormalAt( worldPointOfContact, normal ); - protoG_Magnitude = protoG.Dot( normal ), - deuterG_Magnitude = deuterG.Dot( normal ); + + normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f ); + if( normal.Dot(normal) > 0.0f ) + { + proto->GetNormalAt( worldPointOfContact, normal ); + protoG_Magnitude = protoG.Dot( normal ); + deuterG_Magnitude = deuterG.Dot( normal ); + } + else + { // special case: proto is completly contained within deuter. + // borrowing the negated normal of deuter. + deuter->GetNormalAt( worldPointOfContact, normal ); + normal = -normal; + protoG_Magnitude = -protoG_Magnitude; + deuterG_Magnitude = -deuterG_Magnitude; + } // bounce Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), From 68dc5be9cbb798a6efe33684072d1ef9ade62298 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 16:33:52 +0100 Subject: [PATCH 4/6] added lost rebound deltatime compensation --- Code/GamePhysics/Implementation/SimpleRigidBody.cpp | 1 + Code/GamePhysics/Implementation/SphericalRigidBody.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index 034cedea..b57c2a97 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -332,6 +332,7 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength ) this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + timeStepLength *= 2.0f - this->collisionRebound.timeOfContact; // compensate for rebounded time this->collisionRebound.timeOfContact = 1.0f; } diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 6b4cd4ed..ac566abd 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -254,6 +254,7 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength ) this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact ); this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) ); this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact ); + timeStepLength *= 2.0f - this->collisionRebound.timeOfContact; // compensate for rebounded time this->collisionRebound.timeOfContact = 1.0f; } From c8e8d3510d495dfb2eb94cd0de5bda9139e63410 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Tue, 4 Feb 2014 16:38:42 +0100 Subject: [PATCH 5/6] Added debug traps --- .../Implementation/PhysicsAPI_Impl.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 61bcb706..ede0c289 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -51,6 +51,15 @@ namespace Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ), deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz ); + if( normal != normal ) // debug: trap + const char *breakpoint = "This should never happen"; + + if( protoG != protoG ) // debug: trap + const char *breakpoint = "This should never happen"; + + if( deuterG != deuterG ) // debug: trap + const char *breakpoint = "This should never happen"; + Float protoG_Magnitude = protoG.Dot( normal ), deuterG_Magnitude = deuterG.Dot( normal ); @@ -106,7 +115,10 @@ namespace protoG_Magnitude = -protoG_Magnitude; deuterG_Magnitude = -deuterG_Magnitude; } - + + if( normal != normal ) // debug: trap + const char *breakpoint = "This should never happen"; + // bounce Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), protoState.GetMass(), protoG_Magnitude, @@ -223,6 +235,9 @@ void API_Impl::Update() } } + if( gravityImpulse != gravityImpulse ) // debug: trap + const char *breakpoint = "This should never happen"; + if( gravityImpulse != Float4::null ) { state.ApplyLinearImpulse( gravityImpulse.xyz ); From ec4d34b131bb5f699417d38215be9deb01d72967 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 4 Feb 2014 16:39:01 +0100 Subject: [PATCH 6/6] GL - added error checking --- Code/Game/GameLogic/Object.cpp | 16 +++++++++++++++- Code/Game/GameLogic/Player.cpp | 3 +-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index c7813e61..8cb57aae 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -140,8 +140,17 @@ void Object::BeginFrame() // update physic void Object::EndFrame() { + if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) + { + //error + int i =0 ; + } this->currPhysicsState = this->rigidBody->GetState(); - + if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) + { + //error + int i =0 ; + } if(currPhysicsState.GetGravityNormal() !=currPhysicsState.GetGravityNormal()) { //error @@ -163,6 +172,11 @@ void Object::EndFrame() } + if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) + { + //error + int i =0 ; + } this->newPhysicsState = this->currPhysicsState; } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index aa649461..f01e4d46 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -6,7 +6,7 @@ using namespace GameLogic; using namespace Oyster::Physics; -const int MOVE_FORCE = 50000; +const int MOVE_FORCE = 5000; Player::Player() :DynamicObject() { @@ -73,7 +73,6 @@ void Player::EndFrame() Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); currPhysicsState.AddRotation(deltaAxis); dx = 0;