From fb2cf714c698ac68e9e7da7faf6ea3ddf58d6ef0 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Thu, 23 Jan 2014 14:28:53 +0100 Subject: [PATCH] GL - sending dir to server, forward and backward walking works --- .../DanBiasGame/GameClientState/GameState.cpp | 14 ++++++++------ Code/Game/DanBiasLauncher/Launcher.cpp | 2 +- Code/Game/GameLogic/Level.cpp | 6 +++--- Code/Game/GameLogic/Object.cpp | 10 ++++++---- Code/Game/GameLogic/Player.cpp | 16 +++++++++++++--- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index bb2703c4..e141c8be 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -273,8 +273,11 @@ void GameState::readKeyInput(InputClass* KeyInput) camera->Pitch(KeyInput->GetPitch()); camera->UpdateViewMatrix(); GameLogic::Protocol_PlayerLook playerLookDir; - //deltaMouseMove.camera->GetLook(); - //privData->nwClient->Send(playerLookDir); + Oyster::Math::Float3 look = camera->GetLook(); + playerLookDir.lookDirX = look.x; + playerLookDir.lookDirY = look.y; + playerLookDir.lookDirZ = look.z; + privData->nwClient->Send(playerLookDir); } @@ -313,12 +316,11 @@ 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->setUp((Oyster::Math::Float3(world[4], world[5], world[6]))); + //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14])); camera->UpdateViewMatrix(); - //privData->view = world; - //privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); } } diff --git a/Code/Game/DanBiasLauncher/Launcher.cpp b/Code/Game/DanBiasLauncher/Launcher.cpp index 38f499eb..95bad91c 100644 --- a/Code/Game/DanBiasLauncher/Launcher.cpp +++ b/Code/Game/DanBiasLauncher/Launcher.cpp @@ -18,7 +18,7 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh DanBias::DanBiasGameDesc gameDesc; gameDesc.port = 15151; //gameDesc.port = 15152; - //gameDesc.IP = "193.11.184.196"; + //gameDesc.IP = "193.11.184.109"; //gameDesc.IP = "193.11.184.31"; //gameDesc.IP = "194.47.150.56"; gameDesc.IP = "127.0.0.1"; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 1249dafa..ab25b059 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -29,7 +29,7 @@ void Level::InitiateLevel(float radius) ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); - rigidBody->SetCustomTag(levelObj); + //rigidBody->SetCustomTag(levelObj); ICustomBody::State state; rigidBody->GetState(state); @@ -38,14 +38,14 @@ void Level::InitiateLevel(float radius) levelObj = new StaticObject(rigidBody, LevelCollision, OBJECT_TYPE::OBJECT_TYPE_WORLD); - API::Gravity gravityWell; + /*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); - + */ } void Level::AddPlayerToTeam(Player *player, int teamID) diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 35c1765b..2ee2a613 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -54,7 +54,7 @@ Object::Object(ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type) Oyster::Physics::API::Instance().AddObject(rigidBody); rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc)); - + rigidBody->SetCustomTag(this); this->objectID = GID(); this->type = type; @@ -98,9 +98,11 @@ void Object::EndFrame() //Oyster::Math::Float rot = (setState.GetGravityNormal().xyz).Dot(getState.GetGravityNormal().xyz); //Oyster::Math::Float3 axis = (setState.GetGravityNormal().xyz).Cross(getState.GetGravityNormal().xyz); - Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis); - Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal()); - setState.SetOrientation(rotMatrix); + + // align with gravity normal + //Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis); + //Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal()); + //setState.SetOrientation(rotMatrix); this->getState = this->rigidBody->GetState(); diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index b24b5bf3..8c604a05 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -18,6 +18,7 @@ Player::Player() 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)); + //setState.SetRotation(Oyster::Math::Float4(0,0,0,0).Normalize()); } Player::~Player(void) @@ -64,6 +65,7 @@ void Player::MoveBackwards() void Player::MoveRight() { //Do cross product with forward vector and negative gravity vector + // temp up 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 * 20 * this->gameInstance->GetFrameTime()); @@ -72,6 +74,7 @@ void Player::MoveRight() void Player::MoveLeft() { //Do cross product with forward vector and negative gravity vector + // temp up 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 * 20 * this->gameInstance->GetFrameTime()); @@ -92,9 +95,16 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) void Player::Rotate(const Oyster::Math3D::Float3 lookDir) { - - //this->lookDir = lookDir; - + + this->lookDir = lookDir; + + Oyster::Math::Float4 up(0,1,0,0);//-setState.GetGravityNormal(); + Oyster::Math::Float4 pos = setState.GetCenterPosition(); + Oyster::Math::Float4x4 world = Oyster::Math3D::OrientationMatrix_LookAtDirection(lookDir, up.xyz, pos.xyz); + // cant set rotation + //setState.SetOrientation(world); + //this->lookDir = lookDir - up.xyz; + //this->setState.AddRotation(Oyster::Math::Float4(x, y)); //this->setState.SetRotation(); }