From 0971bc407e74a94ccab21617481bbe6dfc24b6d6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 14:23:38 +0100 Subject: [PATCH 1/6] Small fix --- Code/Game/GameClient/GameClientState/GameState.cpp | 6 +++--- Code/OysterGraphics/FileLoader/ModelLoader.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 79f3c471..1afba43d 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,7 +81,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Math::pi/8, aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -108,7 +108,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBInitData RBData; RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); - RBData.scale = Float3( 3 ); + RBData.scale = Float3( 1 ); if( isMyPlayer ) { @@ -170,7 +170,7 @@ bool GameState::Render() Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 2, 2, 2)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); Oyster::Math3D::Float4x4 world = translation * scale; Oyster::Graphics::API::RenderDebugCube( world ); Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index ba0928cc..0c7125fd 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -700,7 +700,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, return hr; } //todo check calc - int TexSize = twidth * theight * bpp; + int TexSize = twidth * theight * (int)bpp; Oyster::Graphics::Core::UsedMem += TexSize; if ( autogen ) From e8b0e75ed7773623e1fef3bbb0cbb305f0be101e Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 15:07:40 +0100 Subject: [PATCH 2/6] Render rigid body from lvl format --- .../GameClient/GameClientState/C_Object.cpp | 8 +++++- .../GameClient/GameClientState/C_Object.h | 25 ++++++++++++------- .../GameClient/GameClientState/GameState.cpp | 12 ++++++--- .../GameClientState/NetLoadState.cpp | 6 +++++ Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index dc22f34d..ccea9a86 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -9,6 +9,10 @@ C_Object::C_Object() id = 0; model = NULL; + + // RB DEBUG + type = RB_Type_None; + // !RB DEBUG } C_Object::~C_Object() { @@ -104,6 +108,7 @@ bool C_Object::InitRB(RBInitData RBInit) RBposition = RBInit.position; RBrotation = RBInit.rotation; RBscale = RBInit.scale; + type = RBInit.type; return true; } Oyster::Math::Float4x4 C_Object::getRBWorld() const @@ -142,4 +147,5 @@ Oyster::Math::Float3 C_Object::getRBScale() const RB_Type C_Object::getBRtype()const { return this->type; -} \ No newline at end of file +} +// !RB DEBUG \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index d0b86a41..dcc2731c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -5,11 +5,22 @@ namespace DanBias { namespace Client { + // RB DEBUG enum RB_Type { RB_Type_Cube, - RB_Type_Sphere + RB_Type_Sphere, + RB_Type_None, }; + struct RBInitData + { + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + RB_Type type; + }; + // !RB DEBUG + struct ModelInitData { int id; @@ -19,13 +30,6 @@ namespace DanBias Oyster::Math::Float3 scale; bool visible; }; - struct RBInitData - { - Oyster::Math::Float3 position; - Oyster::Math::Quaternion rotation; - Oyster::Math::Float3 scale; - RB_Type type; - }; class C_Object { @@ -40,7 +44,8 @@ namespace DanBias Oyster::Math::Quaternion RBrotation; Oyster::Math::Float3 RBscale; RB_Type type; - + // !RB DEBUG + int id; protected: @@ -71,6 +76,8 @@ namespace DanBias void setRBScale(Oyster::Math::Float3 newScale); Oyster::Math::Float3 getRBScale() const; RB_Type getBRtype()const; + // !RB DEBUG + virtual void Render(); virtual void Release(); virtual int GetId() const; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1afba43d..ba333061 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,7 +81,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Math::pi/8, aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Math::pi/2, aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -109,6 +109,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); RBData.scale = Float3( 1 ); + // !RB DEBUG if( isMyPlayer ) { @@ -116,6 +117,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { // RB DEBUG this->privData->player.InitRB( RBData ); + // !RB DEBUG this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); @@ -132,6 +134,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { // RB DEBUG this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[id] = p; } @@ -168,14 +171,13 @@ bool GameState::Render() // RB DEBUG render wire frame Oyster::Graphics::API::StartRenderWireFrame(); - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); Oyster::Math3D::Float4x4 world = translation * scale; Oyster::Graphics::API::RenderDebugCube( world ); Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); - + staticObject = this->privData->staticObjects->begin(); for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { if( staticObject->second->getBRtype() == RB_Type_Cube) @@ -188,7 +190,7 @@ bool GameState::Render() } } - + dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { if( dynamicObject->second->getBRtype() == RB_Type_Cube) @@ -200,6 +202,8 @@ bool GameState::Render() Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); } } + // !RB DEBUG + Oyster::Graphics::API::EndFrame(); return true; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 706e0d53..2fe143d6 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -146,6 +146,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; staticObject->InitRB( RBData ); } @@ -154,8 +155,10 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; staticObject->InitRB( RBData ); } + // !RB DEBUG (*this->privData->staticObjects)[objectID] = staticObject; } @@ -187,6 +190,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; dynamicObject->InitRB( RBData ); } @@ -195,8 +199,10 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; dynamicObject->InitRB( RBData ); } + // !RB DEBUG (*this->privData->dynamicObjects)[objectID] = dynamicObject; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..96e2bbe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -197,6 +197,7 @@ namespace Oyster void API::StartRenderWireFrame() { Core::deviceContext->RSSetState(wire); + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); } void API::RenderDebugCube(Math::Matrix world) From 60d44d76d8d5ef19aaf54ca67403a87f50d8d0bf Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 15:20:53 +0100 Subject: [PATCH 3/6] using new models --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..cd164f1c 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -24,6 +24,8 @@ namespace Oyster Model::Model* sphere; ID3D11RasterizerState* wire; + + ID3D11ShaderResourceView* debugSRV; #endif } @@ -50,8 +52,14 @@ namespace Oyster Render::Preparations::Basic::SetViewPort(); #ifdef _DEBUG //fix load model - cube = CreateModel(L"debug_cube.dan"); - sphere = CreateModel(L"debug_sphere.dan"); + + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + + cube = CreateModel(L"generic_cube.dan"); + cube->Tint = Math::Float3(0.0f,0.0f,1.0f); + sphere = CreateModel(L"generic_sphere.dan"); + D3D11_RASTERIZER_DESC desc; desc.CullMode = D3D11_CULL_BACK; @@ -196,6 +204,7 @@ namespace Oyster void API::StartRenderWireFrame() { + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); Core::deviceContext->RSSetState(wire); } From 02312c53a4f55135e9b3a9829285b361d7ba225a Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 15:41:59 +0100 Subject: [PATCH 4/6] changed debug models and tinted pink spheres --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 93052730..ccb811c1 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -59,6 +59,7 @@ namespace Oyster cube = CreateModel(L"generic_cube.dan"); cube->Tint = Math::Float3(0.0f,0.0f,1.0f); sphere = CreateModel(L"generic_sphere.dan"); + sphere->Tint = Math::Float3(1.0f,0.5f,182/255.0f); D3D11_RASTERIZER_DESC desc; From 611e75b5052c420f3449cb36d3b1fff56b9dd741 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 15:54:09 +0100 Subject: [PATCH 5/6] Toggle wireframe with "T" --- .../GameClient/GameClientState/GameState.cpp | 134 ++++++++++++------ 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index ba333061..66b8fc61 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -36,7 +36,11 @@ struct GameState::MyData bool key_Shoot; bool key_Jump; + // DEGUG KEYS bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS C_Player player; Camera_FPS camera; @@ -90,7 +94,12 @@ bool GameState::Init( SharedStateContent &shared ) // Debugg hack this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); // end debug hack - + // DEGUG KEYS + this->privData->key_Reload_Shaders = false; + this->privData->key_Wireframe_Toggle = false; + this->privData->renderWhireframe = false; + // !DEGUG KEYS + return true; } @@ -169,37 +178,40 @@ bool GameState::Render() } // RB DEBUG render wire frame - Oyster::Graphics::API::StartRenderWireFrame(); - - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); - Oyster::Math3D::Float4x4 world = translation * scale; - Oyster::Graphics::API::RenderDebugCube( world ); - Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); - - staticObject = this->privData->staticObjects->begin(); - for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + if(this->privData->renderWhireframe) { - if( staticObject->second->getBRtype() == RB_Type_Cube) - { - Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); - } - if( staticObject->second->getBRtype() == RB_Type_Sphere) - { - Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); - } - } + Oyster::Graphics::API::StartRenderWireFrame(); - dynamicObject = this->privData->dynamicObjects->begin(); - for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) - { - if( dynamicObject->second->getBRtype() == RB_Type_Cube) + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); + Oyster::Math3D::Float4x4 world = translation * scale; + Oyster::Graphics::API::RenderDebugCube( world ); + Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + + staticObject = this->privData->staticObjects->begin(); + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { - Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + if( staticObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); + } + if( staticObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); + } } - if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + + dynamicObject = this->privData->dynamicObjects->begin(); + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } } } // !RB DEBUG @@ -283,21 +295,6 @@ void GameState::ReadKeyInput() else this->privData->key_strafeRight = false; - if( this->privData->input->IsKeyPressed(DIK_R) ) - { - if( !this->privData->key_Reload_Shaders ) - { - //this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); -#ifdef _DEBUG - Graphics::API::ReloadShaders(); -#endif - this->privData->key_Reload_Shaders = true; - } - } - else - this->privData->key_Reload_Shaders = false; - - //send delta mouse movement { this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); @@ -363,6 +360,35 @@ void GameState::ReadKeyInput() else this->privData->key_Jump = false; + + // DEGUG KEYS + + // Reload shaders + if( this->privData->input->IsKeyPressed(DIK_R) ) + { + if( !this->privData->key_Reload_Shaders ) + { +#ifdef _DEBUG + Graphics::API::ReloadShaders(); +#endif + this->privData->key_Reload_Shaders = true; + } + } + else + this->privData->key_Reload_Shaders = false; + + // toggle wire frame render + if( this->privData->input->IsKeyPressed(DIK_T) ) + { + if( !this->privData->key_Wireframe_Toggle ) + { + this->privData->renderWhireframe = !this->privData->renderWhireframe; + this->privData->key_Wireframe_Toggle = true; + } + } + else + this->privData->key_Wireframe_Toggle = false; + // !DEGUG KEYS // TODO: implement sub-menu } @@ -387,12 +413,18 @@ void GameState::DataRecieved( NetEventprivData->camera.SetPosition( decoded.position ); (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectRotation: @@ -405,6 +437,9 @@ void GameState::DataRecieved( NetEventprivData->camera.SetAngular( AngularAxis(rotation) ); (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectPositionRotation: @@ -423,6 +458,10 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]; object->setPos( position ); object->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( position ); + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ @@ -446,7 +485,7 @@ void GameState::DataRecieved( NetEventInit(modelData); + // RB DEBUG + // Is just using the model position since the rigid body data should never be sent to the client + RBInitData RBData; + RBData.position = decoded.position; + RBData.rotation = ArrayToQuaternion( decoded.position ); + RBData.scale = Float3( decoded.scale ); + + this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[decoded.object_ID] = object; From 6ef0a7caa676b74a0e661138f3fe8368261563ca Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 10:59:23 +0100 Subject: [PATCH 6/6] Added lights to client --- Code/Game/GameClient/GameClient.vcxproj | 2 + .../GameClient/GameClientState/C_Light.cpp | 37 +++++++++++++++++++ .../Game/GameClient/GameClientState/C_Light.h | 29 +++++++++++++++ .../GameClient/GameClientState/GameState.cpp | 25 ++++++++++++- .../GameClientState/NetLoadState.cpp | 26 ++++++++++++- .../GameClientState/SharedStateContent.h | 2 + .../OysterGraphics.vcxproj.user | 2 +- 7 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/C_Light.cpp create mode 100644 Code/Game/GameClient/GameClientState/C_Light.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 3daafff3..7a962975 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -202,6 +202,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/Code/Game/GameClient/GameClientState/C_Light.cpp b/Code/Game/GameClient/GameClientState/C_Light.cpp new file mode 100644 index 00000000..17016ae5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.cpp @@ -0,0 +1,37 @@ +#include "C_Light.h" +using namespace DanBias::Client; +C_Light::C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ) +{ + this->pointLightDesc = pointLightDesc; + this->id = id; +} +C_Light::~C_Light() +{ + +} +Oyster::Graphics::Definitions::Pointlight C_Light::getLightDesc() const +{ + return this->pointLightDesc; +} +void C_Light::setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ) +{ + this->pointLightDesc = pointLightDesc; +} +Oyster::Math::Float3 C_Light::getPos() const +{ + return this->pointLightDesc.Pos; +} +void C_Light::setPos( Oyster::Math::Float3 newPos) +{ + this->pointLightDesc.Pos = newPos; +} + +int C_Light::GetId() const +{ + return this->id; +} +void C_Light::Render() +{ + // will be changed to new API + Oyster::Graphics::API::AddLight(pointLightDesc); +} diff --git a/Code/Game/GameClient/GameClientState/C_Light.h b/Code/Game/GameClient/GameClientState/C_Light.h new file mode 100644 index 00000000..4802339d --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_CLIGHT_H +#define DANBIAS_CLIENT_CLIGHT_H +#include "DllInterfaces/GFXAPI.h" +namespace DanBias +{ + namespace Client + { + class C_Light + { + private: + Oyster::Graphics::Definitions::Pointlight pointLightDesc; + int id; + + public: + C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ); + virtual ~C_Light(); + + Oyster::Graphics::Definitions::Pointlight getLightDesc() const; + void setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ); + + Oyster::Math::Float3 getPos() const; + void setPos( Oyster::Math::Float3 newPos); + void Render(); + int GetId() const; + }; + } +} + +#endif diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 66b8fc61..59a16f6b 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -4,7 +4,7 @@ #include "NetworkClient.h" #include "Camera_FPS.h" #include - +#include "C_Light.h" #include "C_obj/C_Player.h" #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" @@ -28,6 +28,7 @@ struct GameState::MyData ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool key_forward; bool key_backward; @@ -82,10 +83,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->input = shared.input; this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; + this->privData->lights = &shared.lights; Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Math::pi/2, aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -100,6 +102,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->renderWhireframe = false; // !DEGUG KEYS + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } return true; } @@ -177,6 +184,13 @@ bool GameState::Render() dynamicObject->second->Render(); } + + /*auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + }*/ + // RB DEBUG render wire frame if(this->privData->renderWhireframe) { @@ -236,8 +250,15 @@ bool GameState::Release() dynamicObject->second = nullptr; } + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } + this->privData->staticObjects->clear(); this->privData->dynamicObjects->clear(); + this->privData->lights->clear(); privData = NULL; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 2fe143d6..2f8fbe6c 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -6,6 +6,7 @@ #include "Utilities.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -23,6 +24,7 @@ struct NetLoadState::MyData Graphics::API::Texture background; ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool loading; }; @@ -49,6 +51,7 @@ bool NetLoadState::Init( SharedStateContent &shared ) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->dynamicObjects = &shared.dynamicObjects; this->privData->staticObjects = &shared.staticObjects; + this->privData->lights = &shared.lights; this->privData->loading = false; @@ -214,12 +217,33 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) break; case ObjectType::ObjectType_Light: { - /* TODO: implement light into the leveformat */ + BasicLight *light = (BasicLight*)oth; + Graphics::Definitions::Pointlight pointLight; + + pointLight.Color = light->color; + pointLight.Pos = light->position; + pointLight.Bright = light->intensity; + pointLight.Radius = light->raduis; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; } break; default: break; } } + // DEBUG added a static light for testing + Graphics::Definitions::Pointlight pointLight; + pointLight.Color = Float3(1,1,0); + pointLight.Pos = Float3( 0,132, 10); + pointLight.Bright = 2; + pointLight.Radius = 50; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; + this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index da9dc759..49d01775 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -13,6 +13,7 @@ #include "C_Object.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" #include "NetworkClient.h" #include "L_inputClass.h" @@ -23,6 +24,7 @@ namespace DanBias { namespace Client public: ::std::map> staticObjects; ::std::map> dynamicObjects; + ::std::map> lights; ::Oyster::Network::NetworkClient *network; InputClass* input; }; diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 3f030911..9a0b0ae0 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@  - false + true \ No newline at end of file