From 6818dda2b95ae64c10441b975e53f4dab8787350 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 5 Feb 2014 09:06:33 +0100 Subject: [PATCH 1/3] GL - testing --- Code/Game/GameLogic/CollisionManager.cpp | 2 +- Code/Game/GameLogic/Game_PlayerData.cpp | 2 ++ Code/Game/GameLogic/Object.cpp | 14 ++++++++++++++ Code/Game/GameLogic/Player.cpp | 4 ++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 24bb6bba..cb6862bb 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -84,7 +84,7 @@ using namespace GameLogic; if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough { damageDone = kineticEnergyLoss * 0.10f; - player.DamageLife(damageDone); + //player.DamageLife(damageDone); } } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index bf2cbcbe..e73b8255 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -11,6 +11,8 @@ Game::PlayerData::PlayerData() sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.mass = 70; sbDesc.restitutionCoeff = 0.5; + sbDesc.frictionCoeff_Static = 0.4; + sbDesc.frictionCoeff_Dynamic = 0.3; sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 8cb57aae..6f3ef28b 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -156,6 +156,8 @@ void Object::EndFrame() //error int i =0 ; } + + if(currPhysicsState.GetGravityNormal()!= Float3::null) { Oyster::Math::Float4 axis; @@ -170,6 +172,18 @@ void Object::EndFrame() 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(); + //300, 0,0, + //1,0,0 + + if( pos.GetLength() < 303.5f) + { + Oyster::Math::Float moveUp = 303.5 - pos.GetLength(); + up *= moveUp; + + //currPhysicsState.SetCenterPosition(pos + up); + } if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 54e246a7..6b7129d2 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 = 5000; +const int MOVE_FORCE = 500; Player::Player() :DynamicObject() { @@ -73,7 +73,7 @@ void Player::EndFrame() Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - currPhysicsState.AddRotation(deltaAxis); + //currPhysicsState.AddRotation(deltaAxis); dx = 0; this->newPhysicsState = this->currPhysicsState; } From 426444ca343c49a627a85075261e15ca0ee0ffc0 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 5 Feb 2014 11:46:04 +0100 Subject: [PATCH 2/3] GL - added more boxes and weaponfunctionality --- .../DanBiasGame/GameClientState/GameState.cpp | 82 +++++++++++++++---- .../GameClientState/LoginState.cpp | 13 +-- Code/Game/GameLogic/AttatchmentMassDriver.cpp | 2 +- Code/Game/GameLogic/CollisionManager.cpp | 8 ++ Code/Game/GameLogic/Game.h | 1 + Code/Game/GameLogic/GameAPI.h | 1 + Code/Game/GameLogic/Game_LevelData.cpp | 5 +- Code/Game/GameLogic/Game_PlayerData.cpp | 2 +- Code/Game/GameLogic/Level.cpp | 69 ++++++++++++---- Code/Game/GameLogic/Level.h | 3 +- Code/Game/GameLogic/Object.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 2 +- Code/Game/GameLogic/Player.h | 3 + Code/Game/GameProtocols/PlayerProtocols.h | 18 +++- .../Implementation/GameSession_Gameplay.cpp | 36 ++++---- .../Implementation/PhysicsAPI_Impl.cpp | 21 ++++- Code/GamePhysics/PhysicsAPI.h | 3 +- 17 files changed, 193 insertions(+), 78 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index bdab4dfb..ff30a596 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -49,15 +49,25 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient) GameState::gameStateState GameState::LoadGame() { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(0,15,5); - plight.Color = Oyster::Math::Float3(0,1,0); - plight.Radius = 50; - plight.Bright = 2; + plight.Pos = Oyster::Math::Float3(315, 0 ,5); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.2); + plight.Radius = 100; + plight.Bright = 0.9; Oyster::Graphics::API::AddLight(plight); - plight.Pos = Oyster::Math::Float3(10,15,5); - plight.Color = Oyster::Math::Float3(1,0,0); - plight.Radius = 50; - plight.Bright = 2; + plight.Pos = Oyster::Math::Float3(10,350,5); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Radius = 200; + plight.Bright = 0.7; + Oyster::Graphics::API::AddLight(plight); + plight.Pos = Oyster::Math::Float3(350,350,5); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Radius = 200; + plight.Bright = 0.7; + Oyster::Graphics::API::AddLight(plight); + plight.Pos = Oyster::Math::Float3(10,350,350); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Radius = 200; + plight.Bright = 0.7; Oyster::Graphics::API::AddLight(plight); plight.Pos = Oyster::Math::Float3(10,-15,5); plight.Color = Oyster::Math::Float3(0,0,1); @@ -74,7 +84,8 @@ bool GameState::LoadModels(std::wstring mapFile) // open file // read file // init models - privData->modelCount = 4; + int nrOfBoxex = 5; + privData->modelCount = 3+nrOfBoxex; myId += privData->modelCount; int id = 0; // add world model @@ -92,15 +103,20 @@ bool GameState::LoadModels(std::wstring mapFile) // add box model modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); - modelData.world = modelData.world * translate; modelData.modelPath = L"..\\Content\\Models\\box.dan"; - 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; + + for(int i =0; i< nrOfBoxex; i ++) + { + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); + modelData.world = modelData.world * translate; + 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 crystal model modelData.world = Oyster::Math3D::Float4x4::identity; @@ -330,7 +346,37 @@ void GameState::readKeyInput(InputClass* KeyInput) if(!key_Shoot) { GameLogic::Protocol_PlayerShot playerShot; - playerShot.hasShot = true; + playerShot.primaryPressed = true; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + privData->nwClient->Send(playerShot); + key_Shoot = true; + } + } + else + key_Shoot = false; + if(KeyInput->IsKeyPressed(DIK_X)) + { + if(!key_Shoot) + { + GameLogic::Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = true; + playerShot.utilityPressed = false; + privData->nwClient->Send(playerShot); + key_Shoot = true; + } + } + else + key_Shoot = false; + if(KeyInput->IsKeyPressed(DIK_C)) + { + if(!key_Shoot) + { + GameLogic::Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = true; privData->nwClient->Send(playerShot); key_Shoot = true; } @@ -339,7 +385,7 @@ void GameState::readKeyInput(InputClass* KeyInput) key_Shoot = false; // jump - if(KeyInput->IsKeyPressed(DIK_X)) + if(KeyInput->IsKeyPressed(DIK_SPACE)) { if(!key_Jump) { diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 9beb6657..301ab791 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -41,9 +41,9 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) bool LoginState::LoadModels(std::wstring file) { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(-2,3,0); - plight.Color = Oyster::Math::Float3(0,1,0); - plight.Radius = 10; + plight.Pos = Oyster::Math::Float3(0,0,5.4f); + plight.Color = Oyster::Math::Float3(1,1,1); + plight.Radius = 100; plight.Bright = 1; Oyster::Graphics::API::AddLight(plight); // open file @@ -55,12 +55,13 @@ bool LoginState::LoadModels(std::wstring file) modelData.world = Oyster::Math3D::Float4x4::identity; modelData.visible = true; - modelData.modelPath = L"..\\Content\\Models\\box_2.dan"; + modelData.modelPath = L"..\\Content\\Models\\box.dan"; // load models - privData->object[0] = new C_StaticObj(); + Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); + privData->object[0] = new C_DynamicObj(); privData->object[0]->Init(modelData); - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); modelData.world = modelData.world * translate; privData->object[1] = new C_DynamicObj(); diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 1d8e06a4..e0ca6c0f 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -42,7 +42,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(hasObject) { - ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES + //ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES break; } ForcePull(usage,dt); diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index cb6862bb..21c073f8 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -96,6 +96,14 @@ using namespace GameLogic; { return Physics::ICustomBody::SubscriptMessage_none; } + Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) + { + return Physics::ICustomBody::SubscriptMessage_player_collision_response; + } + Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + { + return Physics::ICustomBody::SubscriptMessage_none; + } //Oyster::Physics::ICustomBody::SubscriptMessage Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) { diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index ddcfc086..b57520e0 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -53,6 +53,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; OBJECT_TYPE GetObjectType() const override; + int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; Level *level; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index f0ce50b1..53931063 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -100,6 +100,7 @@ namespace GameLogic class ILevelData :public IObjectData { public: + virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; }; diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 1a5973e6..9bd3275a 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -35,7 +35,10 @@ OBJECT_TYPE Game::LevelData::GetObjectType() const return ((IObjectData*)this->level)->GetObjectType(); //return OBJECT_TYPE_UNKNOWN; } - +int Game::LevelData::getNrOfDynamicObj()const +{ + return this->level->getNrOfDynamicObj(); +} IObjectData* Game::LevelData::GetObjectAt(int ID) const { return this->level->GetObj(ID); diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index e73b8255..da441539 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -19,7 +19,7 @@ Game::PlayerData::PlayerData() Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); //create player with this rigid body - this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); + this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player->GetRigidBody()->SetCustomTag(this); /*Oyster::Physics::ICustomBody::State state; this->player->GetRigidBody()->GetState(state); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index a80c76f2..4abec0ab 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -20,6 +20,35 @@ void Level::InitiateLevel(std::string levelPath) } void Level::InitiateLevel(float radius) { + float heading = Utility::Value::Radian(180.0f); + float attitude = Utility::Value::Radian(0.0f); + float bank = Utility::Value::Radian(0); + + double c1 = cos(heading/2); + double s1 = sin(heading/2); + double c2 = cos(attitude/2); + double s2 = sin(attitude/2); + double c3 = cos(bank/2); + double s3 = sin(bank/2); + double c1c2 = c1*c2; + double s1s2 = s1*s2; + double w =c1c2*c3 - s1s2*s3; + double x =c1c2*s3 + s1s2*c3; + double y =s1*c2*c3 + c1*s2*s3; + double z =c1*s2*c3 - s1*c2*s3; + double angle = 2 * acos(w); + + double norm = x*x+y*y+z*z; + if (norm < 0.001) { // when all euler angles are zero angle =0 so + // we can set axis to anything to avoid divide by zero + x=1; + y=z=0; + } else { + norm = sqrt(norm); + x /= norm; + y /= norm; + z /= norm; + } // add level sphere API::SphericalBodyDescription sbDesc; @@ -29,6 +58,7 @@ void Level::InitiateLevel(float radius) sbDesc.mass = 10e12f; sbDesc.frictionCoeff_Static = 0; sbDesc.frictionCoeff_Dynamic = 0; + //sbDesc.rotation = ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody::State state; @@ -49,31 +79,35 @@ void Level::InitiateLevel(float radius) sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0); - ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); - rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); + ICustomBody* rigidBody_TestBox; + + int nrOfBoxex = 5; + for(int i =0; i< nrOfBoxex; i ++) + { + sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10 + ( i*5) ,320,0,0); + rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); + rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); + + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); + } + + + - 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); + rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); + // add house API::SimpleBodyDescription sbDesc_House; @@ -88,10 +122,7 @@ void Level::InitiateLevel(float radius) 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; @@ -116,6 +147,10 @@ void Level::RespawnPlayer(Player *player) this->teamManager.RespawnPlayerRandom(player); } +int Level::getNrOfDynamicObj() +{ + return this->dynamicObjects.Size(); +} Object* Level::GetObj( int ID) const { for (int i = 0; i< this->dynamicObjects.Size(); i++) diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 00fb76ef..cc34408b 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -59,7 +59,8 @@ namespace GameLogic ********************************************************/ static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - + + int getNrOfDynamicObj(); Object* GetObj( int ID ) const; static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 6f3ef28b..68297d46 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -182,7 +182,7 @@ void Object::EndFrame() Oyster::Math::Float moveUp = 303.5 - pos.GetLength(); up *= moveUp; - //currPhysicsState.SetCenterPosition(pos + up); + currPhysicsState.SetCenterPosition(pos + up); } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 6b7129d2..5b3657fe 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -73,7 +73,7 @@ void Player::EndFrame() Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - //currPhysicsState.AddRotation(deltaAxis); + currPhysicsState.AddRotation(deltaAxis); dx = 0; this->newPhysicsState = this->currPhysicsState; } diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index f609d197..4f406e31 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -73,6 +73,9 @@ namespace GameLogic void BeginFrame(); void EndFrame(); + static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); + static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + private: void Jump(); diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 216dec73..2192b361 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -142,7 +142,9 @@ namespace GameLogic struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject { - bool hasShot; + bool primaryPressed; + bool secondaryPressed; + bool utilityPressed; Protocol_PlayerShot() { @@ -150,19 +152,27 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; } Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p) { - hasShot = p[1].value.netBool; + primaryPressed = p[1].value.netBool; + secondaryPressed = p[2].value.netBool; + utilityPressed = p[3].value.netBool; } const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val) { - hasShot = val[1].value.netBool; + primaryPressed = val[1].value.netBool; + secondaryPressed = val[2].value.netBool; + utilityPressed = val[3].value.netBool; return *this; } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol[1].value = hasShot; + this->protocol[1].value = primaryPressed; + this->protocol[2].value = secondaryPressed; + this->protocol[3].value = utilityPressed; return &protocol; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index ee6cc385..367048f7 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -111,27 +111,19 @@ namespace DanBias } obj = NULL; - obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1); - if(obj) + int count = ((GameLogic::ILevelData*)movedObject)->getNrOfDynamicObj(); + for( int i = 0; i < count; i++ ) { - if(obj->GetObjectType() == OBJECT_TYPE_BOX) + obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(i+1); + if(obj) { - int id = obj->GetID(); - Oyster::Math::Float4x4 world = obj->GetOrientation(); - Protocol_ObjectPosition p(world, id); - 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()); + 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()); + } } } } @@ -197,9 +189,9 @@ namespace DanBias } void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c ) { - //c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); - c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); - //c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); + if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); } void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c ) { diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index ede0c289..e6f96c3e 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -27,7 +27,7 @@ namespace ICustomBody::State deuterState; deuter->GetState( deuterState ); // calc from perspective of deuter. - Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed + Float4 normal = (worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f )).GetNormalized(); // Init value is only borrowed if( normal.Dot(normal) > 0.0f ) { deuter->GetNormalAt( worldPointOfContact, normal ); @@ -47,9 +47,10 @@ namespace proto->GetNormalAt( worldPointOfContact, normal ); normal = -normal; } + normal.Normalize(); - Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ), - deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz ); + Float4 protoG = Float4(protoState.GetLinearMomentum( worldPointOfContact.xyz ), 0), + deuterG = Float4(deuterState.GetLinearMomentum( worldPointOfContact.xyz ), 0); if( normal != normal ) // debug: trap const char *breakpoint = "This should never happen"; @@ -89,6 +90,18 @@ namespace return; } + // PLayerHAck + /*if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_player_collision_response ) + { + Float3 linearMomentum = protoState.GetLinearMomentum(); + Float3 up = -protoState.GetGravityNormal(); + Float3 upForce = (linearMomentum.Dot(up) * up); + + Float3 noBounceForce = linearMomentum - upForce; + protoState.SetLinearMomentum(noBounceForce); + proto->SetState(protoState); + return; + }*/ // calculate and store time interpolation value, for later rebound. proto->SetTimeOfContact( worldPointOfContact ); @@ -100,7 +113,7 @@ namespace // calc from perspective of proto - normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f ); + normal = (worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f )).GetNormalized(); if( normal.Dot(normal) > 0.0f ) { proto->GetNormalAt( worldPointOfContact, normal ); diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index f636bb73..c3efef3e 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -242,7 +242,8 @@ namespace Oyster { SubscriptMessage_none, SubscriptMessage_kineticLoss, - SubscriptMessage_ignore_collision_response + SubscriptMessage_ignore_collision_response, + SubscriptMessage_player_collision_response }; typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter ); From 70a2cf27e3b68967dc8db26fb75d2afb259ec91e Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 5 Feb 2014 11:53:38 +0100 Subject: [PATCH 3/3] GL - almost ok, at least on the top of the world --- Code/Game/DanBiasGame/GameClientState/GameState.cpp | 2 +- Code/Game/GameLogic/Level.cpp | 2 +- Code/Game/GameLogic/Player.cpp | 5 ----- Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp | 4 ++-- 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index ff30a596..0102a027 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -454,7 +454,7 @@ void GameState::Protocol( ObjPos* pos ) camera->setRight(right); camera->setUp(up); - //camera->setLook(objForward); + camera->setLook(objForward); up *= 2; objForward *= -3; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 4abec0ab..0a2fd31b 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -84,7 +84,7 @@ void Level::InitiateLevel(float radius) int nrOfBoxex = 5; for(int i =0; i< nrOfBoxex; i ++) { - sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10 + ( i*5) ,320,0,0); + sbDesc_TestBox.centerPosition = Oyster::Math::Float4(20 ,320,0 + ( i*7),0); rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 5b3657fe..9b0c29ee 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -154,11 +154,6 @@ 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(); - - //newPhysicsState.SetRotation(oldOrt + deltaAxis); this->lookDir = lookDir.xyz; this->dx = lookDir.w; diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index e6f96c3e..7981322f 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -91,7 +91,7 @@ namespace } // PLayerHAck - /*if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_player_collision_response ) + if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_player_collision_response ) { Float3 linearMomentum = protoState.GetLinearMomentum(); Float3 up = -protoState.GetGravityNormal(); @@ -101,7 +101,7 @@ namespace protoState.SetLinearMomentum(noBounceForce); proto->SetState(protoState); return; - }*/ + } // calculate and store time interpolation value, for later rebound. proto->SetTimeOfContact( worldPointOfContact );