Added lights to client

This commit is contained in:
lindaandersson 2014-02-19 10:59:23 +01:00
parent 95c70fe0b2
commit 6ef0a7caa6
7 changed files with 119 additions and 4 deletions

View File

@ -202,6 +202,7 @@
<ClCompile Include="GameClientState\Camera_Basic.cpp" />
<ClCompile Include="GameClientState\Camera.cpp" />
<ClCompile Include="GameClientState\Camera_FPS.cpp" />
<ClCompile Include="GameClientState\C_Light.cpp" />
<ClCompile Include="GameClientState\C_obj\C_DynamicObj.cpp" />
<ClCompile Include="GameClientState\C_obj\C_Player.cpp" />
<ClCompile Include="GameClientState\C_obj\C_StaticObj.cpp" />
@ -227,6 +228,7 @@
<ClInclude Include="GameClientState\Buttons\ButtonRectangle.h" />
<ClInclude Include="GameClientState\Camera.h" />
<ClInclude Include="GameClientState\Camera_FPS.h" />
<ClInclude Include="GameClientState\C_Light.h" />
<ClInclude Include="GameClientState\C_obj\C_DynamicObj.h" />
<ClInclude Include="GameClientState\C_obj\C_Player.h" />
<ClInclude Include="GameClientState\C_obj\C_StaticObj.h" />

View File

@ -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);
}

View File

@ -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

View File

@ -4,7 +4,7 @@
#include "NetworkClient.h"
#include "Camera_FPS.h"
#include <GameServerAPI.h>
#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<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> *staticObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> *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;
}

View File

@ -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<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> *staticObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> *dynamicObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> *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;
}

View File

@ -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<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_StaticObj>> staticObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_DynamicObj>> dynamicObjects;
::std::map<int, ::Utility::DynamicMemory::UniquePointer<::DanBias::Client::C_Light>> lights;
::Oyster::Network::NetworkClient *network;
InputClass* input;
};

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
</Project>