From f0c581ca04c564745db3232066ac461a93eeb98e Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 19 Feb 2014 13:47:49 +0100 Subject: [PATCH 1/2] GameLogic - Added functions for relative rotation --- Code/Game/GameLogic/Game.h | 23 ++++++++++++----------- Code/Game/GameLogic/GameAPI.h | 7 ++++++- Code/Game/GameLogic/Game_PlayerData.cpp | 6 +++++- Code/Game/GameLogic/Player.cpp | 7 ++++++- Code/Game/GameLogic/Player.h | 4 +++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 6623756f..5ab19ba2 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -31,17 +31,18 @@ namespace GameLogic PlayerData(int playerID,int teamID); ~PlayerData(); - void Move(const PLAYER_MOVEMENT &movement) override; - void UseWeapon(const WEAPON_FIRE &usage) override; - int GetTeamID() const override; - PLAYER_STATE GetState() const override; - Oyster::Math::Float3 GetPosition() override; - Oyster::Math::Quaternion GetRotation() override; - Oyster::Math::Float3 GetScale() override; - Oyster::Math::Float4x4 GetOrientation() override; - int GetID() const override; - void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; - ObjectSpecialType GetObjectType() const override; + void Move(const PLAYER_MOVEMENT &movement) override; + void UseWeapon(const WEAPON_FIRE &usage) override; + int GetTeamID() const override; + PLAYER_STATE GetState() const override; + Oyster::Math::Float3 GetPosition() override; + Oyster::Math::Quaternion GetRotation() override; + Oyster::Math::Float3 GetScale() override; + Oyster::Math::Float4x4 GetOrientation() override; + int GetID() const override; + void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) override; + void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) override; + ObjectSpecialType GetObjectType() const override; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 65d606d8..b4ef9fa6 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -85,7 +85,12 @@ namespace GameLogic * @param x: The relative x axis * @param y: The relative y axis **/ - virtual void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) = 0; + virtual void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) = 0; + + /** Relative rotation around given axis + * @param leftRadians: The relative amount of radians to turn + **/ + virtual void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) = 0; /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 3858d370..c669cbc7 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -85,7 +85,11 @@ ObjectSpecialType Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } -void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) +void Game::PlayerData::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) { this->player->Rotate(lookDir, right); +} +void Game::PlayerData::TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) +{ + this->player->TurnLeft(deltaLeftRadians); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 80969b29..a531461c 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -220,7 +220,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->rigidBody->SetPosition(spawnPoint); } -void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) +void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) { // this is the camera right vector this->lookDir = lookDir; @@ -228,6 +228,11 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D:: //Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; //this->rigidBody->SetUpAndRight(up, right); } +void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) +{ + //TODO: Conver delta radians to something that phyhsics use... + //this->rigidBody->; +} void Player::Jump() { diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index f2707cb3..73737d60 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -46,7 +46,9 @@ namespace GameLogic void Respawn(Oyster::Math::Float3 spawnPoint); - void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right); + void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right); + + void TurnLeft(Oyster::Math3D::Float deltaRadians); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody From 3520062577bd0a2b476bd729cfffaf523c9ffb4c Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 19 Feb 2014 13:59:59 +0100 Subject: [PATCH 2/2] Implemented TurnLeft function --- Code/Game/GameLogic/Player.cpp | 8 ++++++-- Code/Game/GameLogic/Player.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 00d098fa..b067d036 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -33,6 +33,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 100; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID) @@ -53,6 +55,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 20; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::~Player(void) @@ -229,8 +233,8 @@ void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D: } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - //TODO: Conver delta radians to something that phyhsics use... - //this->rigidBody->; + this->rotationUp += deltaRadians; + this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); } void Player::Jump() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 73737d60..13c6e300 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -96,6 +96,8 @@ namespace GameLogic Oyster::Math::Float moveSpeed; Oyster::Math::Float3 previousMoveSpeed; + Oyster::Math::Float rotationUp; + bool hasTakenDamage; float invincibleCooldown;