From a637e177e39e98f448e9527439a0b2659d145bf2 Mon Sep 17 00:00:00 2001 From: "Way, No" Date: Wed, 17 Dec 2014 01:17:03 +1000 Subject: [PATCH] added first person view --- Sources/Client/Client.h | 1 + Sources/Client/Client_Input.cpp | 4 ++++ Sources/Client/Client_Scene.cpp | 16 +++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/Client/Client.h b/Sources/Client/Client.h index e226928e..bfd658b8 100644 --- a/Sources/Client/Client.h +++ b/Sources/Client/Client.h @@ -138,6 +138,7 @@ namespace spades { KeypadInput keypadInput; Player::ToolType lastTool; bool hasLastTool; + bool FirstPersonSpectate; Vector3 lastFront; float lastPosSentTime; int lastHealth; diff --git a/Sources/Client/Client_Input.cpp b/Sources/Client/Client_Input.cpp index cdc5e255..2fcb1307 100644 --- a/Sources/Client/Client_Input.cpp +++ b/Sources/Client/Client_Input.cpp @@ -92,6 +92,7 @@ namespace spades { return readyToClose; } + bool FirstPersonSpectate = false; void Client::Closing() { SPADES_MARK_FUNCTION(); @@ -382,6 +383,9 @@ namespace spades { }else if(CheckKey(cg_keySneak, name)){ playerInput.sneak = down; }else if(CheckKey(cg_keyJump, name)){ + if(down){ + FirstPersonSpectate = !FirstPersonSpectate; + } playerInput.jump = down; }else if(CheckKey(cg_keyAttack, name)){ weapInput.primary = down; diff --git a/Sources/Client/Client_Scene.cpp b/Sources/Client/Client_Scene.cpp index f28f4698..dd0254ce 100644 --- a/Sources/Client/Client_Scene.cpp +++ b/Sources/Client/Client_Scene.cpp @@ -196,11 +196,17 @@ namespace spades { Vector3 front = center - eye; front = front.Normalize(); - def.viewOrigin = eye; - def.viewAxis[0] = -Vector3::Cross(up, front).Normalize(); - def.viewAxis[1] = -Vector3::Cross(front, def.viewAxis[0]).Normalize(); - def.viewAxis[2] = front; - + if(FirstPersonSpectate == false){ + def.viewOrigin = eye; + def.viewAxis[0] = -Vector3::Cross(up, front).Normalize(); + def.viewAxis[1] = -Vector3::Cross(front, def.viewAxis[0]).Normalize(); + def.viewAxis[2] = front; + }else{ + def.viewOrigin = player->GetEye(); + def.viewAxis[0] = player->GetRight(); + def.viewAxis[1] = player->GetUp(); + def.viewAxis[2] = player->GetFront(); + } def.fovY = (float)cg_fov * static_cast(M_PI) /180.f; def.fovX = atanf(tanf(def.fovY * .5f) *