From 561418c4274a425386e6907d8c9ad8d06e6be1f6 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 21 Jan 2014 14:28:27 +0100 Subject: [PATCH] GL - gravity working --- .../DanBiasGame/GameClientState/GameState.cpp | 25 ++++++++++-- Code/Game/GameLogic/Game.cpp | 24 ++++++++++++ Code/Game/GameLogic/Level.cpp | 38 ++++++++++--------- Code/Game/GameLogic/Object.cpp | 1 - Code/Game/GameLogic/Player.cpp | 12 ++++-- .../Implementation/PhysicsAPI_Impl.cpp | 2 +- 6 files changed, 76 insertions(+), 26 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index f1474eed..9bb3d620 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -47,13 +47,23 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient) GameState::gameStateState GameState::LoadGame() { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(0,3,0); + plight.Pos = Oyster::Math::Float3(0,15,5); plight.Color = Oyster::Math::Float3(0,1,0); - plight.Radius = 5; + plight.Radius = 50; + plight.Bright = 2; + 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; + Oyster::Graphics::API::AddLight(plight); + plight.Pos = Oyster::Math::Float3(10,-15,5); + plight.Color = Oyster::Math::Float3(0,0,1); + plight.Radius = 50; plight.Bright = 2; Oyster::Graphics::API::AddLight(plight); LoadModels(L"map"); - InitCamera(Oyster::Math::Float3(0,0,5.4f)); + InitCamera(Oyster::Math::Float3(0,0,20.0f)); return gameStateState_playing; } bool GameState::LoadModels(std::wstring mapFile) @@ -89,6 +99,15 @@ bool GameState::LoadModels(std::wstring mapFile) modelData.world = modelData.world * translate; modelData.modelPath = L"..\\Content\\Models\\char_white.dan"; modelData.id ++; + + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity; + scale.v[0].x = 8; + scale.v[1].y = 8; + scale.v[2].z = 8; + modelData.world = scale; //modelData.world * translate + modelData.modelPath = L"ball.dan"; + modelData.id ++; obj = new C_DynamicObj(); privData->object.push_back(obj); diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 4380777e..b22b3522 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -100,6 +100,30 @@ bool Game::NewFrame() API::Instance().Update(); + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->EndFrame(); + } + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->BeginFrame(); + } + + API::Instance().Update(); + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->EndFrame(); + } + + for (unsigned int i = 0; i < this->players.Size(); i++) + { + if(this->players[i]->player) this->players[i]->player->BeginFrame(); + } + + API::Instance().Update(); + for (unsigned int i = 0; i < this->players.Size(); i++) { if(this->players[i]->player) this->players[i]->player->EndFrame(); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 90dc1865..b2bbe60c 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -19,24 +19,28 @@ void Level::InitiateLevel(std::string levelPath) } void Level::InitiateLevel(float radius) { - //API::SphericalBodyDescription sbDesc; - //sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1); - //sbDesc.ignoreGravity = true; - //sbDesc.radius = radius; - //sbDesc.mass = 1e16f; //10^16 + API::SphericalBodyDescription sbDesc; + sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1); + sbDesc.ignoreGravity = true; + sbDesc.radius = 8; //radius; + sbDesc.mass = 10e12f; //sbDesc.mass = 0; //10^16 - //sbDesc.subscription_onCollision = CollisionManager::LevelCollision; - // - //ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); - //API::Instance().AddObject(rigidBody); - - //API::Gravity gravityWell; - // - //gravityWell.gravityType = API::Gravity::GravityType_Well; - //gravityWell.well.mass = 1e16f; - //gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); - // - //API::Instance().AddGravity(gravityWell); + sbDesc.subscription_onCollision = CollisionManager::LevelCollision; + + ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); + API::Instance().AddObject(rigidBody); + ICustomBody::State state; + rigidBody->GetState(state); + state.SetRestitutionCoeff(0.1); + rigidBody->SetState(state); + + API::Gravity gravityWell; + + gravityWell.gravityType = API::Gravity::GravityType_Well; + gravityWell.well.mass = 10e12f; + gravityWell.well.position = Oyster::Math::Float4(0,0,0,1); + + API::Instance().AddGravity(gravityWell); } diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 7e137c37..2937c605 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -34,7 +34,6 @@ Object::Object() Object::Object(void* collisionFunc, OBJECT_TYPE type) { API::SimpleBodyDescription sbDesc; - //sbDesc.centerPosition = //poi this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 96ee5cfd..dd65c375 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -16,6 +16,10 @@ Player::Player() teamID = -1; playerState = PLAYER_STATE::PLAYER_STATE_IDLE; lookDir = Oyster::Math::Float4(0,0,-1,0); + setState.SetCenterPosition(Oyster::Math::Float4(0,15,0,1)); + setState.SetReach(Oyster::Math::Float4(2,3.5,2,0)); + + } Player::~Player(void) @@ -53,18 +57,18 @@ void Player::Move(const PLAYER_MOVEMENT &movement) void Player::MoveForward() { - setState.ApplyLinearImpulse(this->lookDir * (100 * this->gameInstance->GetFrameTime())); + setState.ApplyLinearImpulse(this->lookDir * (20 * this->gameInstance->GetFrameTime())); } void Player::MoveBackwards() { - setState.ApplyLinearImpulse(-this->lookDir * 100 * this->gameInstance->GetFrameTime()); + setState.ApplyLinearImpulse(-this->lookDir * 20 * this->gameInstance->GetFrameTime()); } void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); //Oyster::Math::Float4 r = (-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); - setState.ApplyLinearImpulse(r * 100 * this->gameInstance->GetFrameTime()); + setState.ApplyLinearImpulse(r * 20 * this->gameInstance->GetFrameTime()); } void Player::MoveLeft() @@ -72,7 +76,7 @@ void Player::MoveLeft() //Do cross product with forward vector and negative gravity vector Oyster::Math::Float4 r = Oyster::Math::Float4(1, 0, 0, 0 ); //Oyster::Math::Float4 r1 = -(-rigidBody->GetGravityNormal()).Cross((Oyster::Math::Float3)this->lookDir); //Still get zero - setState.ApplyLinearImpulse(-r * 100 * this->gameInstance->GetFrameTime()); + setState.ApplyLinearImpulse(-r * 20 * this->gameInstance->GetFrameTime()); } void Player::UseWeapon(const WEAPON_FIRE &usage) diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 7bec7852..46346099 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -36,7 +36,7 @@ namespace // calc from perspective of deuter Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal ); - Float protoG_Magnitude = protoG.Dot( normal ), + Float protoG_Magnitude = protoG.Dot( normal ), deuterG_Magnitude = deuterG.Dot( normal ); // if they are not relatively moving towards eachother, there is no collision