GameServer - merged with Camera

This commit is contained in:
Dennis Andersen 2014-02-16 01:28:34 +01:00
commit 97f9bfcb96
54 changed files with 773 additions and 1018 deletions

View File

@ -215,6 +215,7 @@
<ClCompile Include="GameClientState\LobbyState.cpp" />
<ClCompile Include="GameClientState\C_Object.cpp" />
<ClCompile Include="GameClientState\MainState.cpp" />
<ClCompile Include="GameClientState\NetLoadState.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameClientState\Camera_Basic.h" />
@ -237,6 +238,7 @@
<ClInclude Include="GameClientState\LevelLoader\ParseFunctions.h" />
<ClInclude Include="GameClientState\LobbyAdminState.h" />
<ClInclude Include="GameClientState\MainState.h" />
<ClInclude Include="GameClientState\NetLoadState.h" />
<ClInclude Include="Include\DanBiasGame.h" />
<ClInclude Include="GameClientState\LobbyState.h" />
<ClInclude Include="GameClientState\C_Object.h" />

View File

@ -8,6 +8,7 @@
#include "GameClientState\LobbyAdminState.h"
#include "GameClientState\MainState.h"
#include "GameClientState\LanMenuState.h"
#include "GameClientState\NetLoadState.h"
#include <Protocols.h>
#include "NetworkClient.h"
#include <GameServerAPI.h>
@ -56,7 +57,6 @@ namespace DanBias
//--------------------------------------------------------------------------------------
DanBiasClientReturn DanBiasGame::Initiate(DanBiasGameDesc& desc)
{
WindowShell::CreateConsoleWindow();
//if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC(L"Window", cPOINT(1600, 900), cPOINT())))
if(! data.window->CreateWin(WindowShell::WINDOW_INIT_DESC()))
@ -151,7 +151,21 @@ namespace DanBias
DanBiasGame::Result DanBiasGame::Update(float deltaTime)
{
data.inputObj->Update();
{ // updating mouse input
POINT mousePos;
GetCursorPos( &mousePos );
RECT windowVertex;
GetWindowRect( data.window->GetHWND(), &windowVertex );
float mouseNormalisedX = (float)(mousePos.x - windowVertex.left);
mouseNormalisedX /= (float)(windowVertex.right - windowVertex.left);
float mouseNormalisedY = (float)(mousePos.y - windowVertex.top);
mouseNormalisedY /= (float)(windowVertex.bottom - windowVertex.top);
data.inputObj->Update( mouseNormalisedX, mouseNormalisedY );
}
if( data.serverOwner )
{
@ -169,8 +183,8 @@ namespace DanBias
switch (state)
{
case Client::GameClientState::ClientState_LobbyCreate:
data.state = new Client::LobbyAdminState();
case Client::GameClientState::ClientState_Main:
data.state = new Client::MainState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_Lan:
@ -181,10 +195,18 @@ namespace DanBias
data.state = new Client::LobbyState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_LobbyCreate:
data.state = new Client::LobbyAdminState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_Game:
data.state = new Client::GameState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_NetLoad:
data.state = new Client::NetLoadState();
stateChanged = true;
break;
case Client::GameClientState::ClientState_Quit:
data.state->Release();
return Result_quit;

View File

@ -78,21 +78,24 @@ namespace DanBias
{
if(EventButton<Owner>::Enabled())
{
// let the using dev decide what is rendered
Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
//Render att xPos and yPos
//With width and height
if(EventButton<Owner>::GetState() == ButtonState_None)
{
//Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
}
else if(EventButton<Owner>::GetState() == ButtonState_Hover)
{
//Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
}
else
{
//Oyster::Graphics::API::RenderGuiElement(texture, pos.xy, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
}
//if(EventButton<Owner>::GetState() == ButtonState_None)
//{
// Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 1.0f, 1.0f));
//}
//else if(EventButton<Owner>::GetState() == ButtonState_Hover)
//{
// Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(0.0f, 1.0f, 0.0f));
//}
//else
//{
// Oyster::Graphics::API::RenderGuiElement(texture, pos, size, Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
//}
}
}
@ -101,7 +104,7 @@ namespace DanBias
{
if(buttonText.size() > 0)
{
//Oyster::Graphics::API::RenderText(buttonText, pos.xy, size, textColor);
Oyster::Graphics::API::RenderText(buttonText, pos - Float3(size.x * 0.5f, size.y * 0.25f, 0.0f), size*2.0f, size.y * 0.5f, textColor);
}
}

View File

@ -28,7 +28,7 @@ namespace DanBias { namespace Client
const ::std::wstring & operator[]( unsigned int i ) const;
::std::wstring & operator[]( unsigned int i );
void SetTextHeight( ::Oyster::Math::Float h );
void SetFontHeight( ::Oyster::Math::Float h );
void SetLineSpacing( ::Oyster::Math::Float ls );
void SetBottomAligned();
@ -46,7 +46,7 @@ namespace DanBias { namespace Client
private:
bool isBottomAligned;
::Oyster::Math::Float textHeight, lineSpacing;
::Oyster::Math::Float fontHeight, lineSpacing;
::std::vector<::std::wstring> lines;
};
@ -56,7 +56,7 @@ namespace DanBias { namespace Client
TextField<Owner>::TextField()
: ButtonRectangle()
{
this->textHeight = 0.025f;
this->fontHeight = 0.025f;
this->lineSpacing = 0.001f;
this->isBottomAligned = true;
}
@ -65,7 +65,7 @@ namespace DanBias { namespace Client
TextField<Owner>::TextField( ::std::wstring backgroundTexture, ::Oyster::Math::Float3 textColor, Owner owner, Oyster::Math::Float3 pos, Oyster::Math::Float2 size, ResizeAspectRatio resize )
: ButtonRectangle( backgroundTexture, L"", textColor, owner, pos, size, resize )
{
this->textHeight = 0.025f;
this->fontHeight = 0.025f;
this->lineSpacing = 0.001f;
this->isBottomAligned = true;
}
@ -76,39 +76,38 @@ namespace DanBias { namespace Client
template<typename Owner>
void TextField<Owner>::RenderText()
{
::Oyster::Math::Float lineStep = this->textHeight + this->lineSpacing;
::Oyster::Math::Float2 rowSize = ::Oyster::Math::Float2( this->size.x, this->textHeight );
::Oyster::Math::Float lineStep = this->fontHeight + this->lineSpacing;
::Oyster::Math::Float2 rowSize = ::Oyster::Math::Float2( this->size.x, this->fontHeight );
::Oyster::Math::Float3 fieldTopLeft = this->pos - Float3( this->size * 0.25f, 0.0f );
::Oyster::Math::Float3 topLeft = fieldTopLeft;
if( this->isBottomAligned )
{
::Oyster::Math::Float2 topLeft = this->pos;
topLeft.y += this->size.y - lineStep;
auto line = this->lines.rbegin();
for( ; line != this->lines.rend(); ++line )
{
if( topLeft.y - lineStep >= this->pos.y )
{
::Oyster::Graphics::API::RenderText( (*line), topLeft, rowSize, this->textColor );
if( topLeft.y < fieldTopLeft.y )
break;
::Oyster::Graphics::API::RenderText( (*line), topLeft, rowSize, this->fontHeight, this->textColor );
topLeft.y -= lineStep;
}
else break;
}
}
else
{
::Oyster::Math::Float2 topLeft = this->pos;
topLeft.y += this->lineSpacing;
auto line = this->lines.begin();
for( ; line != this->lines.end(); ++line )
{
if( topLeft.y + lineStep < this->size.y )
{
::Oyster::Graphics::API::RenderText( (*line), topLeft, rowSize, this->textColor );
if( topLeft.y >= fieldTopLeft.y + this->size.y )
break;
::Oyster::Graphics::API::RenderText( (*line), topLeft, rowSize, this->fontHeight, this->textColor );
topLeft.y += lineStep;
}
else break;
}
}
}
@ -125,9 +124,9 @@ namespace DanBias { namespace Client
}
template<typename Owner>
void TextField<Owner>::SetTextHeight( ::Oyster::Math::Float h )
void TextField<Owner>::SetFontHeight( ::Oyster::Math::Float h )
{
this->textHeight = h;
this->fontHeight = h;
}
template<typename Owner>
@ -173,7 +172,7 @@ namespace DanBias { namespace Client
split.reserve( 10 );
::Utility::String::Split( split, text, L"\n", 0 );
auto line = split.begin();
for( ; line != split.end; ++line )
for( ; line != split.end(); ++line )
{
this->lines.push_back( (*line) );
}

View File

@ -1,14 +1,31 @@
#include "C_Object.h"
using namespace DanBias::Client;
void C_Object::Init(ModelInitData modelInit)
C_Object::C_Object()
{
world = Oyster::Math::Float4x4::identity;
position = Oyster::Math::Float3::null;
rotation = Oyster::Math::Quaternion::identity;
scale = Oyster::Math::Float3::null;
id = 0;
model = NULL;
}
C_Object::~C_Object()
{
}
bool C_Object::Init(ModelInitData modelInit)
{
position = modelInit.position;
rotation = modelInit.rotation;
scale = modelInit.scale;
id = modelInit.id;
model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
if(model == NULL)
return false;
model->Visible = modelInit.visible;
updateWorld();
return true;
}
void C_Object::updateWorld()
{

View File

@ -5,6 +5,7 @@ namespace DanBias
{
namespace Client
{
struct ModelInitData
{
int id;
@ -17,8 +18,6 @@ namespace DanBias
class C_Object
{
protected:
Oyster::Graphics::Model::Model *model;
private:
Oyster::Math::Float4x4 world;
Oyster::Math::Float3 position;
@ -27,9 +26,12 @@ namespace DanBias
int id;
void updateWorld();
protected:
Oyster::Graphics::Model::Model *model;
public:
virtual void Init(ModelInitData modelInit);
C_Object();
virtual ~C_Object();
virtual bool Init(ModelInitData modelInit);
void setWorld(Oyster::Math::Float4x4 world);
Oyster::Math::Float4x4 getWorld() const;
@ -46,21 +48,5 @@ namespace DanBias
virtual void Render();
virtual void Release();
virtual int GetId() const;
};
}
}
namespace Utility { namespace DynamicMemory
{ // template specializationto allowuse of dynamicmemory tools
template<>
inline void SafeDeleteInstance( ::DanBias::Client::C_Object *dynamicInstance )
{
if( dynamicInstance )
{
dynamicInstance->Release();
delete dynamicInstance;
}
}
} }
};};};
#endif

View File

@ -11,7 +11,7 @@ C_DynamicObj::~C_DynamicObj(void)
{
}
void C_DynamicObj::Init(ModelInitData modelInit)
bool C_DynamicObj::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
return C_Object::Init(modelInit);
}

View File

@ -11,7 +11,7 @@ private:
public:
C_DynamicObj(void);
virtual ~C_DynamicObj(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
};};};
#endif

View File

@ -3,14 +3,22 @@
using namespace DanBias::Client;
C_Player::C_Player(void)
:C_DynamicObj() {}
C_Player::~C_Player(void) {}
void C_Player::Init(ModelInitData modelInit)
:C_DynamicObj()
{
C_Object::Init(modelInit);
Oyster::Graphics::API::PlayAnimation( this->model, L"movement" );
//Oyster::Graphics::API::Update(0.002f);
}
C_Player::~C_Player(void)
{
}
bool C_Player::Init(ModelInitData modelInit)
{
return C_Object::Init(modelInit);
}
void C_Player::playAnimation(std::wstring animation, bool loop)
{
if(model)
Oyster::Graphics::API::PlayAnimation(model, L"movement", loop);
}

View File

@ -11,9 +11,8 @@ namespace DanBias
public:
C_Player(void);
virtual ~C_Player(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
void playAnimation(std::wstring animation, bool loop);
};
}
}
};};};
#endif

View File

@ -10,7 +10,7 @@ C_StaticObj::~C_StaticObj(void)
{
}
void C_StaticObj::Init(ModelInitData modelInit)
bool C_StaticObj::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
return C_Object::Init(modelInit);
}

View File

@ -11,7 +11,7 @@ private:
public:
C_StaticObj(void);
virtual ~C_StaticObj(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
};};};
#endif

View File

@ -10,7 +10,7 @@ C_UIobject::C_UIobject(void)
C_UIobject::~C_UIobject(void)
{
}
void C_UIobject::Init(ModelInitData modelInit)
bool C_UIobject::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
return C_Object::Init(modelInit);
}

View File

@ -12,7 +12,7 @@ namespace DanBias
public:
C_UIobject(void);
virtual ~C_UIobject(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
void setPos(Oyster::Math::Float4x4 world);
};};};
#endif

View File

@ -12,11 +12,12 @@ namespace DanBias { namespace Client
public:
enum ClientState
{
ClientState_Login,
ClientState_Main,
ClientState_Lan,
ClientState_Lobby,
ClientState_LobbyCreate,
ClientState_LobbyReady,
ClientState_NetLoad,
ClientState_Game,
ClientState_Same,
ClientState_Quit

View File

@ -2,19 +2,19 @@
#include "DllInterfaces/GFXAPI.h"
#include <Protocols.h>
#include "NetworkClient.h"
#include "Camera.h"
#include "Camera_FPS.h"
#include <GameServerAPI.h>
#include "LevelLoader\ObjectDefines.h"
using namespace GameLogic;
using namespace DanBias::Client;
using namespace Oyster::Math;
struct GameState::myData
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::Oyster::Math3D;
struct GameState::MyData
{
myData(){}
int modelCount;
Oyster::Network::NetworkClient* nwClient;
gameStateState state;
MyData(){}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
} privData;
GameState::GameState(void)
@ -23,145 +23,36 @@ GameState::GameState(void)
key_backward = false;
key_strafeRight = false;
key_strafeLeft = false;
timer = 0;
}
GameState::~GameState(void)
{
delete this->camera;
delete this->privData;
if( this->privData )
this->Release();
}
bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
bool GameState::Init(NetworkClient* nwClient)
{
// load models
camera = new Camera;
privData = new myData();
privData->state = gameStateState_loading;
privData->nwClient = nwClient;
privData->state = LoadGame();
pitch = 0;
privData = new MyData();
//tELL SERver ready
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
LoadGame();
//tell server ready
nwClient->Send( GameLogic::Protocol_General_Status(GameLogic::Protocol_General_Status::States_ready) );
return true;
}
GameState::gameStateState GameState::LoadGame()
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Float3(615, 0 ,5);
plight.Color = Float3(0.9f,0.7f,0.2f);
plight.Radius = 100;
plight.Bright = 0.5f;
Oyster::Graphics::API::AddLight(plight);
plight.Pos = Float3(10,800,5);
plight.Color = Float3(0.9f,0.7f,0.3f);
plight.Radius = 300;
plight.Bright = 0.5f;
Oyster::Graphics::API::AddLight(plight);
// use level loader
LoadModels("../Content/Worlds/ccc.bias");
// hardcoded objects
Float3 startPos = Float3(0,0,20.0f);
InitCamera(startPos);
return gameStateState_playing;
}
bool GameState::LoadModels()
{
// open file
// read file
// init models
int nrOfBoxex = 5;
int id = 100;
// add world model
ModelInitData modelData;
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(2,2,2);
modelData.modelPath = L"world_earth.dan";
modelData.id = id++;
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
// add box model
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"crate_colonists.dan";
for(int i =0; i< nrOfBoxex; i ++)
{
modelData.position = Oyster::Math::Float3(4,320,0);
modelData.id = id++;
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
}
// add crystal model
modelData.position = Oyster::Math::Float3(10, 601, 0);
modelData.modelPath = L"crystalformation_b.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add house model
modelData.position = Oyster::Math::Float3(-50, 590, 0);
//Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(Oyster::Math::Float3(0 ,Utility::Value::Radian(90.0f), 0));
modelData.visible = true;
modelData.modelPath = L"building_corporation.dan";
modelData.id = id++;
// load models
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
// add jumppad
modelData.position = Oyster::Math::Float3(4, 600.3f, 0);
modelData.modelPath = L"jumppad_round.dan";
modelData.id = id++;
// load models
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
// add player model
modelData.position = Oyster::Math::Float3(0, 602, 0);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add player model 2
modelData.position = Oyster::Math::Float3(50, 602, 0);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
// add sky sphere
modelData.position = Oyster::Math::Float3(0,0,0);
modelData.scale = Oyster::Math::Float3(800,800,800);
modelData.modelPath = L"skysphere.dan";
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
return true;
}
bool GameState::LoadModels(std::string mapFile)
{
GameLogic::LevelLoader levelLoader;
@ -169,7 +60,7 @@ bool GameState::LoadModels(std::string mapFile)
objects = levelLoader.LoadLevel(mapFile);
int objCount = objects.size();
int modelId = 100;
int modelId = 0;
ModelInitData modelData;
for (int i = 0; i < objCount; i++)
{
@ -186,9 +77,9 @@ bool GameState::LoadModels(std::string mapFile)
modelData.modelPath.assign(staticObjData->ModelFile.begin(), staticObjData->ModelFile.end());
modelData.visible = true;
modelData.position = staticObjData->position;
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(staticObjData->rotation), staticObjData->rotation[3]);
modelData.scale = staticObjData->scale;
//modelData.position = ;
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
//modelData.scale = Float3(2,2,2);
modelData.id = modelId++;
this->staticObjects.Push(new C_StaticObj());
@ -198,11 +89,11 @@ bool GameState::LoadModels(std::string mapFile)
case GameLogic::ObjectType::ObjectType_Dynamic:
{
GameLogic::ObjectHeader* dynamicObjData = ((GameLogic::ObjectHeader*)obj);
//modelData.position = ;
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
//modelData.scale = Float3(2,2,2);
modelData.modelPath.assign(dynamicObjData->ModelFile.begin(), dynamicObjData->ModelFile.end());
modelData.visible = true;
modelData.position = dynamicObjData->position;
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(dynamicObjData->rotation), dynamicObjData->rotation[3]);
modelData.scale = dynamicObjData->scale;
modelData.id = modelId++;
this->dynamicObjects.Push(new C_DynamicObj());
@ -213,14 +104,19 @@ bool GameState::LoadModels(std::string mapFile)
{
GameLogic::BasicLight* lightData = ((GameLogic::BasicLight*)obj);
if(lightData->lightType == GameLogic::LightType_PointLight)
switch( lightData->lightType )
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = ((GameLogic::BasicLight*)lightData)->position;
plight.Color = lightData->color;
plight.Radius = 100;
plight.Bright = 0.9f;
Oyster::Graphics::API::AddLight(plight);
case GameLogic::LightType_PointLight:
{
//Oyster::Graphics::Definitions::Pointlight plight;
//plight.Pos = ((GameLogic::PointLight*)lightData)->position;
//plight.Color = lightData->diffuseColor;
//plight.Radius = 100;
//plight.Bright = 0.9f;
//Oyster::Graphics::API::AddLight(plight);
}
break;
default: break;
}
}
break;
@ -228,67 +124,39 @@ bool GameState::LoadModels(std::string mapFile)
break;
}
}
myId += modelId++;
// add player model
//modelData.position = ;
//modelData.rotation = Quaternion(Float3(2,2,-2), 1);
//modelData.scale = Float3(2,2,2);
Oyster::Math::Quaternion first = Oyster::Math::Quaternion(Float3(0.3536,0.3536,-0.146), 0.8536);
Oyster::Math::Quaternion second = Oyster::Math::Quaternion(Float3(0.3536,0.3536,-0.146), 0.8536);
Oyster::Math::Quaternion result = first * second;
Oyster::Math::Quaternion total = Oyster::Math::Quaternion(Float3(0.5,0.5,-0.5), 0.5);
modelData.visible = true;
modelData.position = Oyster::Math::Float3(20, 127,0);
modelData.rotation = first;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = myId;
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
modelData.visible = true;
modelData.position = Oyster::Math::Float3(22, 127,0);
modelData.rotation = second;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = myId;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
modelData.visible = true;
modelData.position = Oyster::Math::Float3(24, 127,0);
modelData.rotation = result;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = myId;
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
modelData.visible = true;
modelData.position = Oyster::Math::Float3(26, 127,0);
modelData.rotation = total;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.modelPath = L"char_still_sizeref.dan";
modelData.id = myId;
this->staticObjects.Push(new C_StaticObj());
this->staticObjects[this->staticObjects.Size() -1 ]->Init(modelData);
/*C_Player* obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
*/
return true;
}
bool GameState::InitCamera(Float3 startPos)
{
Float3 dir = Float3(0,0,1);
Float3 up = Float3(0,1,0);
Float3 pos = Float3(0, 0, 20);
camera->LookAt(pos, dir, up);
camera->SetLens(pi/4, 1024/768, 1, 1000);
camera->UpdateViewMatrix();
Oyster::Graphics::API::SetProjection(camera->Proj());
camera.SetHeadOffset( Float3(0.0f, 1.0f, 1.0f) );
camera.SetPerspectiveProjection( pi / 4.0f, 1024.0f/768.0f, 1.0f, 1000.0f );
camera.UpdateOrientation();
Oyster::Graphics::API::SetProjection(camera.GetProjectionMatrix());
return true;
}
void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Float4x4 world)
void GameState::InitiatePlayer(int id, std::wstring modelName, Float4x4 world)
{
myId = id;
@ -296,9 +164,9 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo
C_Object* obj;
modelData.visible = true;
//modelData.world = world;
modelData.position = Oyster::Math::Float3(world[12], world[13], world[14]);
modelData.rotation = Oyster::Math::Quaternion(Oyster::Math::Float3(0,0,0), 1);
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.position = Float3(world[12], world[13], world[14]);
modelData.rotation = Quaternion(Float3(0,0,0), 1);
modelData.scale = Float3(1,1,1);
modelData.modelPath = modelName;
modelData.id = myId;
@ -306,77 +174,51 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo
this->dynamicObjects.Push(obj);
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
Float3 pos = Float3(world[12], world[13], world[14]);
Oyster::Math::Float3 right = Oyster::Math::Float3(world[0], world[1], world[2]);
Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]);
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]);
Oyster::Math::Float3 cameraLook = camera->GetLook();
Oyster::Math::Float3 cameraUp = camera->GetUp();
/*Oyster::Math::Float3 newUp = cameraUp.Dot(up);
up *= newUp;
up.Normalize();
Oyster::Math::Float3 newLook = up.Cross(right);
newLook.Normalize();*/
camera->setRight(right);
camera->setUp(up);
camera->setLook(objForward);
up *= 2;
objForward *= 3;
Oyster::Math::Float3 cameraPos = up + pos + objForward;
camera->SetPosition(cameraPos);
camera->UpdateViewMatrix();
camera.SetPosition( pos );
camera.UpdateOrientation();
}
GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput)
{
switch (privData->state)
{
case gameStateState_loading: //Will this ever happen in this scope??
{
// load map
// wait for all players
LoadGame();
GameLogic::Protocol_General_Status gameStatus;
gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
privData->nwClient->Send(gameStatus);
privData->state = gameStateState_playing;
}
break;
case gameStateState_playing:
// read server data
// update objects
{
timer += deltaTime;
if(timer > 0.03)
{
readKeyInput(KeyInput);
timer = 0;
}
camera->UpdateViewMatrix();
//switch (privData->state)
//{
//case gameStateState_loading: //Will this ever happen in this scope??
// {
// // load map
// // wait for all players
// LoadGame();
// GameLogic::Protocol_General_Status gameStatus;
// gameStatus.status = GameLogic::Protocol_General_Status::States_ready;
// privData->nwClient->Send(gameStatus);
// privData->state = gameStateState_playing;
// }
// break;
//case gameStateState_playing:
// // read server data
// // update objects
// {
// readKeyInput(KeyInput);
// camera.UpdateOrientation();
// }
// break;
//case gameStateState_end:
// return ClientState_Lobby;
// break;
//default:
// break;
//}
//
//// send key input to server.
//return ClientState_Same;
}
break;
case gameStateState_end:
return ClientState_Lobby;
break;
default:
break;
return this->privData->nextState;
}
// send key input to server.
return ClientState_Same;
}
bool GameState::Render(float dt)
bool GameState::Render()
{
Oyster::Graphics::API::SetView(camera->View());
Oyster::Graphics::API::SetView( camera.GetViewMatrix() );
Oyster::Graphics::API::NewFrame();
for (unsigned int i = 0; i < staticObjects.Size(); i++)
@ -387,34 +229,28 @@ bool GameState::Render(float dt)
{
dynamicObjects[i]->Render();
}
Oyster::Graphics::API::StartTextRender();
std::wstring fps;
float f = 1/dt;
fps = std::to_wstring(f);
//Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.2f,0.05f));
Oyster::Graphics::API::EndFrame();
return true;
}
bool GameState::Release()
{
/*for (unsigned int i = 0; i < privData->object.size(); i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}*/
delete privData;
privData = NULL;
return true;
}
void GameState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
void GameState::readKeyInput(InputClass* KeyInput)
{
if(KeyInput->IsKeyPressed(DIK_W))
{
//if(!key_forward)
if(!key_forward)
{
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementForward());
key_forward = true;
@ -425,7 +261,7 @@ void GameState::readKeyInput(InputClass* KeyInput)
if(KeyInput->IsKeyPressed(DIK_S))
{
//if(!key_backward)
if(!key_backward)
{
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementBackward());
key_backward = true;
@ -436,7 +272,7 @@ void GameState::readKeyInput(InputClass* KeyInput)
if(KeyInput->IsKeyPressed(DIK_A))
{
//if(!key_strafeLeft)
if(!key_strafeLeft)
{
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementLeft());
key_strafeLeft = true;
@ -447,7 +283,7 @@ void GameState::readKeyInput(InputClass* KeyInput)
if(KeyInput->IsKeyPressed(DIK_D))
{
//if(!key_strafeRight)
if(!key_strafeRight)
{
privData->nwClient->Send(GameLogic::Protocol_PlayerMovementRight());
key_strafeRight = true;
@ -458,17 +294,16 @@ void GameState::readKeyInput(InputClass* KeyInput)
//send delta mouse movement
if (KeyInput->IsMousePressed())
//if (KeyInput->IsMousePressed())
{
camera->Yaw(-KeyInput->GetYaw());
camera->Pitch(KeyInput->GetPitch());
pitch = KeyInput->GetPitch();
camera->UpdateViewMatrix();
Oyster::Math::Float3 look = camera->GetLook();
Oyster::Math::Float3 right = camera->GetRight();
GameLogic::Protocol_PlayerLook playerLook(look, right);
camera.YawRight( -KeyInput->GetYaw() );
camera.PitchUp( KeyInput->GetPitch() );
camera.UpdateOrientation();
privData->nwClient->Send(playerLook);
GameLogic::Protocol_PlayerLook playerLookDir;
Float4 look = camera.GetLook();
privData->nwClient->Send( playerLookDir );
}
// shoot
@ -486,7 +321,6 @@ void GameState::readKeyInput(InputClass* KeyInput)
}
else
key_Shoot = false;
if(KeyInput->IsKeyPressed(DIK_X))
{
if(!key_Shoot)
@ -501,7 +335,6 @@ void GameState::readKeyInput(InputClass* KeyInput)
}
else
key_Shoot = false;
if(KeyInput->IsKeyPressed(DIK_C))
{
if(!key_Shoot)
@ -531,98 +364,141 @@ void GameState::readKeyInput(InputClass* KeyInput)
// send event data
//
if(KeyInput->IsKeyPressed(DIK_L))
privData->state = GameState::gameStateState_end;
//if(KeyInput->IsKeyPressed(DIK_L))
// privData->state = GameState::gameStateState_end;
}
void GameState::Protocol(ProtocolStruct* pos)
{
using namespace ::Oyster::Network;
using namespace ::Utility::DynamicMemory;
// returns -1 if none found
int FindObject( const DynamicArray<SmartPointer<C_Object>> &collection, int id )
{
int num = collection.Size();
for( int i = 0; i < num; ++i ) if( id == collection[i]->GetId() )
return i;
return -1;
}
void GameState::Protocol( PlayerPos* pos )
void GameState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
{
//Oyster::Math::Float4x4 world, translate;
CustomNetProtocol data = e.args.data.protocol;
short ID = data[0].value.netShort; // fetching the id data.
//world = Oyster::Math::Float4x4::identity;
//translate = Oyster::Math::Float4x4::identity;
//translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(pos->playerPos[0],pos->playerPos[1],pos->playerPos[2]));
//world = world * translate;
////privData->object[0]->setPos( world );
//for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
//{
// dynamicObjects[i]->Render();
//}
if( ProtocolIsGameplay(ID) )
{
switch(ID)
{
case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectDamage: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectHealthStatus: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectPosition:
{
GameLogic::Protocol_ObjectPosition decoded(data);
// if is this player. Remember to change camera
if( this->myId == decoded.object_ID )
camera.SetPosition( decoded.position );
int i = FindObject( this->dynamicObjects, decoded.object_ID );
if( i > -1 )
this->dynamicObjects[i]->setPos( decoded.position );
}
break;
case protocol_Gameplay_ObjectScale:
{
GameLogic::Protocol_ObjectScale decoded(data);
int i = FindObject( this->dynamicObjects, decoded.object_ID );
if( i > -1 )
this->dynamicObjects[i]->setScale( decoded.scale );
}
break;
case protocol_Gameplay_ObjectRotation:
{
GameLogic::Protocol_ObjectRotation decoded(data);
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
// if is this player. Remember to change camera
if( this->myId == decoded.object_ID )
camera.SetAngular( AngularAxis(rotation) );
int i = FindObject( this->dynamicObjects, decoded.object_ID );
if( i > -1 )
this->dynamicObjects[i]->setRot( rotation );
}
break;
case protocol_Gameplay_ObjectPositionRotation:
{
GameLogic::Protocol_ObjectPositionRotation decoded(data);
Float3 position = decoded.position;
Quaternion rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
// if is this player. Remember to change camera
if( this->myId == decoded.object_ID )
{
camera.SetPosition( position );
camera.SetAngular( AngularAxis(rotation) );
}
void GameState::Protocol( ObjPos* pos )
int i = FindObject( this->dynamicObjects, decoded.object_ID );
if( i > -1 )
{
Oyster::Math::Float4x4 world;
for(int i = 0; i<16; i++)
{
world[i] = pos->worldPos[i];
}
for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
{
if(dynamicObjects[i]->GetId() == pos->object_ID)
{
dynamicObjects[i]->setPos(Float3(world[0], world[1], world[2]));
dynamicObjects[i]->setRot(Quaternion(Float3(world[3], world[4], world[5]), world[6]));
//dynamicObjects[i]->setWorld(world);
if(dynamicObjects[i]->GetId() == myId) // playerobj
{
Float3 pos = dynamicObjects[i]->getPos();
Float3 up = dynamicObjects[i]->getWorld().v[1];
Float3 objForward = dynamicObjects[i]->getWorld().v[2];
up *= 3;
objForward *= -4;
Oyster::Math::Float3 cameraPos = pos + up + objForward;
camera->SetPosition(cameraPos);
this->dynamicObjects[i]->setPos( position );
this->dynamicObjects[i]->setRot( rotation );
}
}
}
}
void GameState::Protocol( NewObj* newObj )
break;
case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectDisabled:
{
GameLogic::Protocol_ObjectDisable decoded(data);
Oyster::Math::Float4x4 world;
for(int i = 0; i<16; i++)
int i = FindObject( this->dynamicObjects, decoded.objectID );
if( i > -1 )
{
world[i] = newObj->worldPos[i];
this->dynamicObjects[i].Release();
this->dynamicObjects.Pop(i);
}
}
break;
case protocol_Gameplay_ObjectCreate:
{
GameLogic::Protocol_ObjectCreate decoded(data);
C_DynamicObj* object = new C_DynamicObj();
ModelInitData modelData;
//modelData.world = world;
{
modelData.position = Float3( decoded.position );
modelData.rotation = Quaternion( Float3(decoded.rotationQ), decoded.rotationQ[3] );
modelData.scale = Float3( decoded.scale );
modelData.visible = true;
modelData.id = newObj->object_ID;
//not sure if this is good parsing rom char* to wstring
const char* path = newObj->path;
modelData.modelPath = std::wstring(path, path + strlen(path));
// load models
C_DynamicObj* player = new C_DynamicObj();
player->Init(modelData);
modelData.id = decoded.object_ID;
dynamicObjects.Push(player);
::Utility::String::StringToWstring( decoded.name, modelData.modelPath );
}
object->Init(modelData);
dynamicObjects.Push(object);
}
void DanBias::Client::GameState::Protocol( RemoveObj* obj )
break;
case protocol_Gameplay_ObjectCreatePlayer: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectJoinTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectLeaveTeam: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponCooldown: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectRespawn: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */
default: break;
}
}
else if( ProtocolIsGeneral(ID) )
{
for (unsigned int i = 0; i < dynamicObjects.Size(); i++)
switch( ID )
{
if(dynamicObjects[i]->GetId() == obj->object_ID)
{
//dynamicObjects[i]->Release();
dynamicObjects[i].Release();
//dynamicObjects.erase(privData->object.begin() + i );
case protocol_General_Status: break; /** @todo TODO: implement */
case protocol_General_Text: break; /** @todo TODO: implement */
default: break;
}
}
//privData->object[obj->object_ID]->Release( );
}
//void GameState::Protocol(LightPos pos);

View File

@ -36,6 +36,7 @@ struct LanMenuState::MyData
} privData;
void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<LanMenuState*>& e );
void OnButtonInteract_Exit( Oyster::Event::ButtonEvent<LanMenuState*>& e );
LanMenuState::LanMenuState() {}
@ -55,19 +56,22 @@ bool LanMenuState::Init(Network::NetworkClient* nwClient)
this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" );
// create guiElements
ButtonRectangle<LanMenuState*> *guiElements;
//0.5f, 0.2f, 0.3f, 0.1f,
guiElements = new ButtonRectangle<LanMenuState*>( L"earth_md.png", L"Connect", Float3(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
this->privData->guiElements.AddButton( guiElements );
this->privData->connectIP = new TextField<LanMenuState*>( L"earth_md.png", Float3(1.0f), this, Float3(0.1f, 0.2f, 0.5f), Float2(0.45f, 0.1f), ResizeAspectRatio_Width );
this->privData->connectIP = new TextField<LanMenuState*>( L"earth_md.png", Float3(1.0f), this, Float3(0.5f, 0.3f, 0.5f), Float2(0.8f, 0.09f), ResizeAspectRatio_None );
this->privData->connectIP->ReserveLines( 1 );
(*this->privData->connectIP)[0] = L"127.0.0.1";
this->privData->connectIP->SetTextHeight( 0.1f );
this->privData->connectIP->SetLineSpacing( 0.0f );
this->privData->connectIP->AppendText( L"127.0.0.1" );
this->privData->connectIP->SetFontHeight( 0.08f );
this->privData->connectIP->SetLineSpacing( 0.005f );
this->privData->connectIP->SetTopAligned();
this->privData->guiElements.AddButton( this->privData->connectIP );
ButtonRectangle<LanMenuState*> *guiElements;
guiElements = new ButtonRectangle<LanMenuState*>( L"earth_md.png", L"Connect", Float3(1.0f), OnButtonInteract_Connect, this, Float3(0.5f, 0.4f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
this->privData->guiElements.AddButton( guiElements );
guiElements = new ButtonRectangle<LanMenuState*>( L"earth_md.png", L"Exit", Float3(1.0f), OnButtonInteract_Exit, this, Float3(0.5f, 0.5f, 0.5f), Float2(0.3f, 0.05f), ResizeAspectRatio_None );
this->privData->guiElements.AddButton( guiElements );
// bind guiElements collection to the singleton eventhandler
EventHandler::Instance().AddCollection( &this->privData->guiElements );
@ -80,8 +84,7 @@ GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* K
{
MouseInput mouseState;
{
mouseState.x = KeyInput->GetPitch();
mouseState.y = KeyInput->GetYaw();
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
}
@ -96,7 +99,7 @@ bool LanMenuState::Render( )
Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
this->privData->guiElements.RenderTexture();
Graphics::API::StartTextRender();
@ -118,8 +121,8 @@ void LanMenuState::ChangeState( ClientState next )
{
case GameClientState::ClientState_Lobby:
// attempt to connect to lobby
if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) )
return;
//if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) )
// return; // TODO: temporary commented out
break;
default: break;
}
@ -132,7 +135,18 @@ void OnButtonInteract_Connect( Oyster::Event::ButtonEvent<LanMenuState*>& e )
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_LobbyCreate );
e.owner->ChangeState( GameClientState::ClientState_Lobby );
break;
default: break;
}
}
void OnButtonInteract_Exit( Oyster::Event::ButtonEvent<LanMenuState*>& e )
{
switch( e.state )
{
case ButtonState_Released:
e.owner->ChangeState( GameClientState::ClientState_Main );
break;
default: break;
}

View File

@ -59,6 +59,27 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break;
}
case ObjectType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
SpawnPointAttributes* spawn = new SpawnPointAttributes;
spawn->typeID = header->typeID;
for(int i = 0; i < 3; i++)
{
spawn->position[i] = header->position[i];
}
delete header;
//objects.push_back(header);
objects.push_back(spawn);
break;
}
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
//Unless they are changed to not be the same.
case ObjectType_Static: case ObjectType_Dynamic:
@ -133,13 +154,8 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
objects.push_back(header);
break;
}
//this is a hotfix, fix so you only load the relevant data when the file is updated
case ObjectSpecialType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
}
default:
//Couldn't find specialType

View File

@ -16,6 +16,7 @@ namespace GameLogic
ObjectType_Static,
ObjectType_Dynamic,
ObjectType_Light,
ObjectType_SpawnPoint,
//Etc
ObjectType_NUM_OF_TYPES,
@ -38,7 +39,6 @@ namespace GameLogic
ObjectSpecialType_CrystalShard,
ObjectSpecialType_JumpPad,
ObjectSpecialType_Portal,
ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Player,
@ -206,6 +206,13 @@ namespace GameLogic
virtual ~ObjectHeader(){}
};
//inheritance from the base class because there is no use for ModelFile, Rotation and Scale
//so this is a special struct for just spawnpoints
struct SpawnPointAttributes : public ObjectTypeHeader
{
float position[3];
};
/************************************
Special objects
*************************************/
@ -234,6 +241,8 @@ namespace GameLogic
/************************************
Lights
*************************************/

View File

@ -70,8 +70,7 @@ GameClientState::ClientState LobbyAdminState::Update(float deltaTime, InputClass
MouseInput mouseState;
{
mouseState.x = KeyInput->GetPitch();
mouseState.y = KeyInput->GetYaw();
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
}
@ -84,7 +83,7 @@ bool LobbyAdminState::Render( )
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
this->privData->guiElements.RenderTexture();
Graphics::API::StartTextRender();
@ -121,9 +120,9 @@ void LobbyAdminState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::Clie
{
switch(ID)
{
case protocol_Lobby_Create: break; /** @todo TODO: implement */
case protocol_Lobby_Start: break; /** @todo TODO: implement */
case protocol_Lobby_Join: break; /** @todo TODO: implement */
case protocol_Lobby_CreateGame: break; /** @todo TODO: implement */
case protocol_Lobby_StartGame: break; /** @todo TODO: implement */
case protocol_Lobby_JoinGame: break; /** @todo TODO: implement */
case protocol_Lobby_Login: break; /** @todo TODO: implement */
case protocol_Lobby_Refresh: break; /** @todo TODO: implement */
case protocol_Lobby_ClientData: break; /** @todo TODO: implement */

View File

@ -48,7 +48,7 @@ bool LobbyState::Init(NetworkClient* nwClient)
// create buttons
ButtonRectangle<LobbyState*> *button;
button = new ButtonRectangle<LobbyState*>( L"earth_md.png", L"", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
button = new ButtonRectangle<LobbyState*>( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width );
this->privData->guiElements.AddButton( button );
// bind button collection to the singleton eventhandler
@ -70,8 +70,7 @@ GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* Key
MouseInput mouseState;
{
mouseState.x = KeyInput->GetPitch();
mouseState.y = KeyInput->GetYaw();
KeyInput->GetMousePos( mouseState.x, mouseState.y );
mouseState.mouseButtonPressed = KeyInput->IsMousePressed();
}
@ -84,7 +83,7 @@ bool LobbyState::Render( )
Graphics::API::NewFrame();
Graphics::API::StartGuiRender();
Graphics::API::RenderGuiElement( this->privData->background, Float2(0.5f), Float2(1.0f) );
Graphics::API::RenderGuiElement( this->privData->background, Float3(0.5f, 0.5f, 1.0f), Float2(1.0f) );
this->privData->guiElements.RenderTexture();
Graphics::API::StartTextRender();
@ -103,7 +102,7 @@ void LobbyState::ChangeState( ClientState next )
{
if( next == GameClientState::ClientState_LobbyReady )
{ // Send ready signal to server lobby
this->ChangeState( GameClientState::ClientState_NetLoad );
}
else
this->privData->nextState = next;
@ -121,9 +120,9 @@ void LobbyState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEve
{
switch(ID)
{
case protocol_Lobby_Create: break; /** @todo TODO: implement */
case protocol_Lobby_Start: break; /** @todo TODO: implement */
case protocol_Lobby_Join: break; /** @todo TODO: implement */
case protocol_Lobby_CreateGame: break; /** @todo TODO: implement */
case protocol_Lobby_StartGame: break; /** @todo TODO: implement */
case protocol_Lobby_JoinGame: break; /** @todo TODO: implement */
case protocol_Lobby_Login: break; /** @todo TODO: implement */
case protocol_Lobby_Refresh: break; /** @todo TODO: implement */
case protocol_Lobby_ClientData: break; /** @todo TODO: implement */

View File

@ -1,288 +0,0 @@
#include "LoginState.h"
#include "DllInterfaces/GFXAPI.h"
#include "OysterMath.h"
#include "C_obj/C_Player.h"
#include "C_obj/C_StaticObj.h"
#include "C_obj/C_DynamicObj.h"
#include <GameServerAPI.h>
using namespace DanBias::Client;
//Menu buttons
#include "Buttons/ButtonEllipse.h"
#include "Buttons/ButtonRectangle.h"
#include "../Misc/EventHandler/EventHandler.h"
using namespace Oyster::Event;
struct LoginState::myData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
C_Object* object[2];
int modelCount;
// UI object
// game client*
//Menu button collection
EventButtonCollection collection;
bool createGame;
int testNumber;
}privData;
enum TestEnum
{
Create,
Options,
Incr,
Decr,
Exit,
};
LoginState::LoginState(void)
{
}
void LoginState::ButtonCallback(Oyster::Event::ButtonEvent<LoginState*>& e)
{
TestEnum type = TestEnum((int)e.userData);
switch(type)
{
case Create:
if(e.state == ButtonState_None)
{
int a = 0;
std::cout << "None" << std::endl;
}
else if(e.state == ButtonState_Hover)
{
int a = 0;
std::cout << "Hover" << std::endl;
}
else if(e.state == ButtonState_Down)
{
int a = 0;
std::cout << "Down" << std::endl;
}
else if(e.state == ButtonState_Pressed)
{
int a = 0;
std::cout << "Pressed" << std::endl;
}
else if(e.state == ButtonState_Released)
{
//Change to create state or something similar
int a = 0;
std::cout << "Released" << std::endl;
e.owner->privData->createGame = true;
}
break;
case Options:
break;
case Exit:
break;
case Incr:
if(e.state == ButtonState_Released)
e.owner->privData->testNumber++;
break;
case Decr:
if(e.state == ButtonState_Released)
e.owner->privData->testNumber--;
break;
}
}
LoginState::~LoginState(void)
{
}
bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
{
privData = new myData();
this->nwClient = nwClient;
// load models
//LoadModels(L"UImodels.txt");
InitCamera(Oyster::Math::Float3(0,0,5.4f));
//Create menu buttons
EventHandler::Instance().AddCollection(&privData->collection);
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", L"Hej", Oyster::Math::Float3(1, 1, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.2f, 0.2f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width));
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.2f, 0.3f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width));
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.2f, 0.4f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width));
privData->collection.AddButton(new ButtonEllipse<LoginState*>(L"circle.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.2f, 0.5f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f), ResizeAspectRatio_Width));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.15f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f)));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.25f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f)));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.35f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f)));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Options, Oyster::Math::Float3(0.45f, 0.05f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f)));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"Create Game", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Create, Oyster::Math::Float3(0.5f, 0.5f, 0.0f), Oyster::Math::Float2(0.3f, 0.3f)));
//Incr/decr buttons .
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Incr, Oyster::Math::Float3(0.85f, 0.2f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f)));
privData->collection.AddButton(new ButtonRectangle<LoginState*>(L"button.png", L"Hej", Oyster::Math::Float3(1, 0, 0), &LoginState::ButtonCallback, this,
(void*)Decr, Oyster::Math::Float3(0.55f, 0.2f, 0.0f), Oyster::Math::Float2(0.1f, 0.1f)));
privData->createGame = false;
privData->testNumber = 0;
return true;
}
bool LoginState::LoadModels(std::wstring file)
{
Oyster::Graphics::Definitions::Pointlight plight;
plight.Pos = Oyster::Math::Float3(0,0,5);
plight.Color = Oyster::Math::Float3(1,0,1);
plight.Radius = 100;
plight.Bright = 1;
Oyster::Graphics::API::AddLight(plight);
// open file
// read file
// init models
privData->modelCount = 2;
ModelInitData modelData;
modelData.rotation = Oyster::Math::Quaternion::identity;
modelData.scale = Oyster::Math::Float3(1,1,1);
modelData.visible = true;
modelData.modelPath = L"box.dan";
modelData.position = Oyster::Math::Float3(2,2,2);
privData->object[0] = new C_StaticObj();
privData->object[0]->Init(modelData);
modelData.position = Oyster::Math::Float3(-2,0,-2);
privData->object[1] = new C_StaticObj();
privData->object[1]->Init(modelData);
return true;
}
bool LoginState::InitCamera(Oyster::Math::Float3 startPos)
{
privData->proj = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1024.0f/768.0f,.1f,1000);
//privData->proj = Oyster::Math3D::ProjectionMatrix_Orthographic(1024, 768, 1, 1000);
Oyster::Graphics::API::SetProjection(privData->proj);
privData->view = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),startPos);
privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view);
return true;
}
GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* KeyInput)
{
// picking
// mouse events
// different menus
// play sounds
// update animation
// send data to server
// check data from server
// create game
if( KeyInput->IsKeyPressed(DIK_C) || privData->createGame)
{
DanBias::GameServerAPI::ServerInitDesc desc;
DanBias::GameServerAPI::ServerInitiate(desc);
DanBias::GameServerAPI::ServerStart();
// my ip
nwClient->Connect(15152, "127.0.0.1");
if (!nwClient->IsConnected())
{
// failed to connect
return ClientState_Same;
}
privData->collection.SetState(EventCollectionState_Disabled);
return ClientState_LobbyCreated;
}
// join game
if( KeyInput->IsKeyPressed(DIK_J))
{
// game ip
nwClient->Connect(15152, "127.0.0.1");
//nwClient->Connect(15152, "83.254.217.248");
if (!nwClient->IsConnected())
{
// failed to connect
return ClientState_Same;
}
privData->collection.SetState(EventCollectionState_Disabled);
return ClientState_Lobby;
}
return ClientState_Same;
}
bool LoginState::Render(float dt)
{
Oyster::Graphics::API::SetView(privData->view);
Oyster::Graphics::API::SetProjection( privData->proj);
Oyster::Graphics::API::NewFrame();
// render objects
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Render();
}
// render effects
// render lights
//Render buttons
Oyster::Graphics::API::StartGuiRender();
EventHandler::Instance().RenderTexture();
std::wstring number;
wchar_t temp[10];
_itow_s(privData->testNumber, temp, 10);
number = temp;
Oyster::Graphics::API::StartTextRender();
EventHandler::Instance().RenderText();
//Oyster::Graphics::API::RenderText(number, Oyster::Math::Float2(0.7f, 0.2f), Oyster::Math::Float2(0.1f, 0.1f*(1008.0f/730.0f)), Oyster::Math::Float3(1.0f, 0.0f, 0.0f));
Oyster::Graphics::API::EndFrame();
return true;
}
bool LoginState::Release()
{
Oyster::Graphics::API::ClearLights();
for (int i = 0; i < privData->modelCount; i++)
{
privData->object[i]->Release();
delete privData->object[i];
privData->object[i] = NULL;
}
EventHandler::Instance().ReleaseCollection(&privData->collection);
delete privData;
privData = NULL;
return true;
}
void LoginState::Protocol(ProtocolStruct* protocol)
{
if((PlayerName*)protocol)
PlayerJoinProtocol((PlayerName*)protocol);
}
void LoginState::PlayerJoinProtocol(PlayerName* name)
{
}

View File

@ -0,0 +1,84 @@
#include "NetLoadState.h"
#include "NetworkClient.h"
#include "../Game/GameProtocols/Protocols.h"
using namespace ::DanBias::Client;
using namespace ::Oyster;
using namespace ::Oyster::Network;
using namespace ::GameLogic;
struct NetLoadState::MyData
{
MyData() {}
GameClientState::ClientState nextState;
NetworkClient *nwClient;
bool loading;
};
NetLoadState::NetLoadState(void) {}
NetLoadState::~NetLoadState(void)
{
if( this->privData )
this->Release();
}
bool NetLoadState::Init( NetworkClient* nwClient )
{
this->privData = new MyData();
this->privData->nextState = GameClientState::ClientState_Same;
this->privData->nwClient = nwClient;
this->privData->loading = false;
// we may assume that nwClient is properly connected to the server
// signals querry to server for loading instructions
nwClient->Send( Protocol_QuerryGameType() );
return true;
}
GameClientState::ClientState NetLoadState::Update(float deltaTime, InputClass* KeyInput)
{
return this->privData->nextState;
}
bool NetLoadState::Render()
{
return true;
}
bool NetLoadState::Release()
{
if( this->privData )
{
this->privData = NULL;
}
return true;
}
void NetLoadState::ChangeState( ClientState next )
{
this->privData->nextState = next;
}
void NetLoadState::DataRecieved( NetEvent<NetworkClient*, NetworkClient::ClientEventArgs> e )
{
// fetching the id data.
short ID = e.args.data.protocol[0].value.netShort;
if( ID == protocol_Lobby_CreateGame && !this->privData->loading )
{
this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName );
}
}
void NetLoadState::LoadGame( const ::std::string &fileName )
{
this->privData->loading = true;
// TODO: ask Sam about level loader
this->privData->nextState = ClientState::ClientState_Game;
}

View File

@ -0,0 +1,34 @@
#ifndef DANBIAS_CLIENT_NETLOADSTATE_H
#define DANBIAS_CLIENT_NETLOADSTATE_H
#include "GameClientState.h"
#include "NetworkClient.h"
namespace DanBias
{
namespace Client
{
class NetLoadState : public GameClientState
{
public:
NetLoadState( );
virtual ~NetLoadState( );
bool Init( Oyster::Network::NetworkClient* nwClient );
ClientState Update( float deltaTime, InputClass* KeyInput );
bool Render();
bool Release();
void ChangeState( ClientState next );
void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e );
private:
struct MyData;
::Utility::DynamicMemory::UniquePointer<MyData> privData;
void LoadGame( const ::std::string &fileName );
};
}
}
#endif // ! DANBIAS_CLIENT_LOGINSTATE_H

View File

@ -95,8 +95,28 @@ using namespace GameLogic;
{
int forceThreashHold = 200000; //how much force for the box to explode of the impact
Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed?
if(kineticEnergyLoss > forceThreashHold)
switch (realObj->GetObjectType())
{
case ObjectSpecialType::ObjectSpecialType_Generic:
break;
case ObjectSpecialType::ObjectSpecialType_StandardBox:
break;
case ObjectSpecialType::ObjectSpecialType_Player:
ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag());
Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos;
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius);
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
delete hitSphere;
break;
}
/*if(kineticEnergyLoss > forceThreashHold)
{
ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag());
@ -107,7 +127,7 @@ using namespace GameLogic;
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
delete hitSphere;
}
}*/
}
void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args)
@ -123,7 +143,7 @@ using namespace GameLogic;
{
Player *hitPlayer = (Player*)realObj;
hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision());
//hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision());
//do shredding damage
}

View File

@ -17,12 +17,12 @@ Game::PlayerData::PlayerData()
//sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0);
//create rigid body
Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCharacter(2.0f, 0.5f, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
rigidBody->SetAngularFactor(0.0f);
//create player with this rigid body
this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0);
this->player->GetRigidBody()->SetCustomTag(this);
//this->player->GetRigidBody()->SetCustomTag(this);
player->EndFrame();
}
Game::PlayerData::PlayerData(int playerID,int teamID)

View File

@ -33,7 +33,7 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
case ObjectSpecialType_Sky:
{
float skySize = ((SkyAttributes*)obj)->skySize;
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++);
//gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++);
}
break;
case ObjectSpecialType_World:
@ -96,7 +96,7 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
break;
case ObjectSpecialType_JumpPad:
{
float power = ((JumpPadAttributes*)obj)->power;
float power = 500; //((JumpPadAttributes*)obj)->power;
Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction;
Oyster::Math::Float3 pushForce = dir * power;
gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++ , pushForce);
@ -108,16 +108,15 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, destination);
}
break;
case ObjectSpecialType_SpawnPoint:
{
//case ObjectSpecialType_SpawnPoint:
//{
// save
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++);
}
//}
break;
case ObjectSpecialType_Player:
{
// should not be read from the lvl format
//gameObj = new Player(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++);
}
break;
case ObjectSpecialType_Generic:
@ -206,12 +205,10 @@ void Level::InitiateLevel(std::string levelPath)
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
API::Instance().SetGravity(200);
int objCount = objects.size();
int modelCount = 100;
for (int i = 0; i < objCount; i++)
{
ObjectTypeHeader* obj = objects.at(i);
int id = obj->typeID;
switch (obj->typeID)
{
case ObjectType::ObjectType_LevelMetaData:
@ -223,7 +220,6 @@ void Level::InitiateLevel(std::string levelPath)
break;
case ObjectType::ObjectType_Static:
{
ObjectHeader* staticObjData = ((ObjectHeader*)obj);
staticObjData->ModelFile;
@ -237,7 +233,6 @@ void Level::InitiateLevel(std::string levelPath)
else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box)
{
rigidBody_Static = InitRigidBodyCube(staticObjData);
}
@ -248,22 +243,13 @@ void Level::InitiateLevel(std::string levelPath)
if(rigidBody_Static != NULL)
{
// create game object
Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static);
//Object* staticGameObj = new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID);
if(staticGameObj != NULL)
{
this->staticObjects.Push((StaticObject*)staticGameObj);
//this->staticObjects[this->staticObjects.Size()-1]->objectID = modelCount++;
//rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]);
}
//this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID, 0));
//this->staticObjects[staticObjCount]->objectID = modelCount++;
}
}
break;
case ObjectType::ObjectType_Dynamic:
@ -293,12 +279,9 @@ void Level::InitiateLevel(std::string levelPath)
{
// create game object
Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic);
//Object* dynamicGameObj =new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID);
if (dynamicGameObj != NULL)
{
this->dynamicObjects.Push((DynamicObject*)dynamicGameObj);
//this->dynamicObjects[this->dynamicObjects.Size()-1]->objectID = modelCount++;
//rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]);
}
}
}
@ -334,9 +317,6 @@ void Level::InitiateLevel(float radius)
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++));
//this->dynamicObjects[i]->objectID = idCount++;
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
}
/*offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
@ -365,31 +345,18 @@ void Level::InitiateLevel(float radius)
}*/
// add crystal
ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++));
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
//this->dynamicObjects[nrOfBoxex]->objectID = idCount++;
// add house
ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++));
rigidBody_House->SetCustomTag(this->staticObjects[0]);
//this->staticObjects[0]->objectID = idCount++;
// add jumppad
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 0, 0.5f, 0.8f, 0.6f);
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0)));
rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]);
//this->staticObjects[1]->objectID = idCount++;
}
void Level::AddPlayerToTeam(Player *player, int teamID)

View File

@ -77,6 +77,7 @@ namespace GameLogic
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
StaticObject *levelObj;
int objID;
Utility::DynamicMemory::DynamicArray<Oyster::Math::Float3> spawnPoints;
};

View File

@ -3,7 +3,6 @@
/////////////////////////////////////
#include "LevelParser.h"
#include "Loader.h"
#include "ParseFunctions.h"
@ -59,6 +58,27 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break;
}
case ObjectType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
SpawnPointAttributes* spawn = new SpawnPointAttributes;
spawn->typeID = header->typeID;
for(int i = 0; i < 3; i++)
{
spawn->position[i] = header->position[i];
}
delete header;
//objects.push_back(header);
objects.push_back(spawn);
break;
}
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
//Unless they are changed to not be the same.
case ObjectType_Static: case ObjectType_Dynamic:
@ -134,13 +154,6 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break;
}
case ObjectSpecialType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
}
default:
//Couldn't find specialType
break;

View File

@ -16,6 +16,7 @@ namespace GameLogic
ObjectType_Static,
ObjectType_Dynamic,
ObjectType_Light,
ObjectType_SpawnPoint,
//Etc
ObjectType_NUM_OF_TYPES,
@ -38,7 +39,6 @@ namespace GameLogic
ObjectSpecialType_CrystalShard,
ObjectSpecialType_JumpPad,
ObjectSpecialType_Portal,
ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Player,
ObjectSpecialType_Generic,
@ -207,6 +207,11 @@ namespace GameLogic
virtual ~ObjectHeader(){}
};
struct SpawnPointAttributes : public ObjectTypeHeader
{
ObjectSpecialType specialTypeID;
float position[3];
};
/************************************
Special objects
*************************************/

View File

@ -20,16 +20,16 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
weapon = new Weapon(2,this);
this->life = 100;
this->teamID = -1;
this->teamID = teamID;
this->playerState = PLAYER_STATE_IDLE;
this->lookDir = Oyster::Math::Float3(0,0,-1);
this->moveDir = Oyster::Math::Float3(0,0,0);
key_forward = 0;
key_backward = 0;
key_strafeRight = 0;
key_strafeLeft = 0;
this->previousPosition = Oyster::Math::Float3(0,0,0);
this->moveDir = Oyster::Math::Float3(0,0,0);
this->moveSpeed = 100;
this->previousMoveSpeed = Oyster::Math::Float3(0,0,0);
@ -38,20 +38,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
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)
:DynamicObject(rigidBody, EventOnCollision, type, objectID)
{
this->rigidBody = rigidBody;
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0);
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f);
Oyster::Math::Float mass = 60;
Oyster::Math::Float restitutionCoeff = 0.5;
Oyster::Math::Float frictionCoeff_Static = 0.4;
Oyster::Math::Float frictionCoeff_Dynamic = 0.3;
this->rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
this->rigidBody->SetAngularFactor(0.0f);
weapon = new Weapon(2,this);
this->life = 100;
@ -67,7 +53,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
this->moveDir = Oyster::Math::Float3(0,0,0);
this->moveSpeed = 100;
this->previousMoveSpeed = Oyster::Math::Float3(0,0,0);
}
Player::~Player(void)

View File

@ -14,25 +14,25 @@ StaticObject::StaticObject()
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
:Object(rigidBody, EventOnCollision, type, objectID)
{
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::StaticObject(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)
:Object(rigidBody, EventOnCollision, type, objectID)
{
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
{
this->extraDamageOnCollision = extraDamageOnCollision;
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::StaticObject(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, Oyster::Math::Float extraDamageOnCollision)
{
this->extraDamageOnCollision = extraDamageOnCollision;
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::~StaticObject(void)
{

View File

@ -21,6 +21,24 @@
namespace GameLogic
{
struct Protocol_QuerryGameType :public Oyster::Network::CustomProtocolObject
{
public:
Protocol_QuerryGameType()
{
this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short;
this->protocol[0].value = protocol_Lobby_QuerryGameType;
}
::Oyster::Network::CustomNetProtocol GetProtocol() override
{
return this->protocol;
}
private:
Oyster::Network::CustomNetProtocol protocol;
};
struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject
{
short clientID; // The unuiqe id reprsenting a specific client
@ -30,7 +48,7 @@ namespace GameLogic
Protocol_LobbyCreateGame()
{
int c = 0;
this->protocol[c].value = protocol_Lobby_Create;
this->protocol[c].value = protocol_Lobby_CreateGame;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
@ -43,7 +61,7 @@ namespace GameLogic
Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16])
{
int c = 0;
this->protocol[c].value = protocol_Lobby_Create;
this->protocol[c].value = protocol_Lobby_CreateGame;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
this->protocol[c++].type = Oyster::Network::NetAttributeType_Short;
@ -92,14 +110,14 @@ namespace GameLogic
Protocol_LobbyStartGame()
{
this->protocol[0].value = protocol_Lobby_Start;
this->protocol[0].value = protocol_Lobby_StartGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
seconds = 0;
}
Protocol_LobbyStartGame(float _seconds)
{
this->protocol[0].value = protocol_Lobby_Start;
this->protocol[0].value = protocol_Lobby_StartGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Float;
seconds = _seconds;
@ -119,17 +137,17 @@ namespace GameLogic
};
struct Protocol_LobbyLogin :public Oyster::Network::CustomProtocolObject
struct Protocol_LobbyJoinGame :public Oyster::Network::CustomProtocolObject
{
// Login stuff
Protocol_LobbyLogin()
Protocol_LobbyJoinGame()
{
this->protocol[0].value = protocol_Lobby_Join;
this->protocol[0].value = protocol_Lobby_JoinGame;
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
this->protocol[1].type = Oyster::Network::NetAttributeType_Short;
}
Protocol_LobbyLogin(Oyster::Network::CustomNetProtocol& p)
Protocol_LobbyJoinGame(Oyster::Network::CustomNetProtocol& p)
{
}

View File

@ -27,14 +27,15 @@
/********* LOBBY PROTOCOLS ***************************************************************************************************/
/***********[ 200 - 299 ]***********/
#define protocol_LobbyMIN 200
#define protocol_Lobby_Create 200
#define protocol_Lobby_Start 201
#define protocol_Lobby_Join 202
#define protocol_Lobby_CreateGame 200
#define protocol_Lobby_StartGame 201
#define protocol_Lobby_JoinGame 202
#define protocol_Lobby_Login 203
#define protocol_Lobby_Refresh 204
#define protocol_Lobby_ClientData 205
#define protocol_Lobby_GameData 206
#define protocol_Lobby_ClientReadyState 207
#define protocol_Lobby_QuerryGameType 207
#define protocol_Lobby_ClientReadyState 208
#define protocol_LobbyMAX 299

View File

@ -41,7 +41,7 @@ namespace DanBias
//void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create:
void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start:
//void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join:
void LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login:
void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh:
void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData:
void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData:

View File

@ -15,11 +15,11 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie
break;
//case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c);
//break;
case protocol_Lobby_Start: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c);
break;
//case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c);
//break;
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyLogin (p), c);
case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c);
break;
case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c);
break;
@ -82,7 +82,7 @@ void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Ne
// // }
// //}
//}
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyLogin& p, Oyster::Network::NetworkClient* c)
void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c)
{
}

View File

@ -38,7 +38,7 @@ void ClientFnc()
gameDesc.IP = "127.0.0.1";
//gameDesc.IP = "194.47.150.184";
if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Sucess)
if( DanBias::DanBiasGame::Initiate(gameDesc) == DanBias::DanBiasClientReturn_Success)
{
DanBias::DanBiasGame::Run();
DanBias::DanBiasGame::Release();

View File

@ -71,7 +71,7 @@ const wchar_t* FindResourceKey(std::map<std::wstring, ResourceData*>& resources,
{
for (auto i = resources.begin(); i != resources.end() ; i++)
{
if(i->second->resource == h)
if(i->second && i->second->resource == h)
{
return i->first.c_str();
}

View File

@ -362,6 +362,7 @@ namespace Oyster
}
Core::deviceContext->RSSetState(se.RenderStates.Rasterizer);
Core::deviceContext->PSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState);
Core::deviceContext->CSSetSamplers(0,se.RenderStates.SampleCount,se.RenderStates.SampleState);
Core::deviceContext->OMSetDepthStencilState(se.RenderStates.DepthStencil,0);
float test[4] = {0};
Core::deviceContext->OMSetBlendState(se.RenderStates.BlendState,test,-1);

View File

@ -27,8 +27,6 @@ namespace Oyster
Oyster::Math::Float3 pos;
Oyster::Math::Float2 uv;
Oyster::Math::Float3 normal;
Oyster::Math::Float3 tangent;
Oyster::Math::Float3 biTangent;
Oyster::Math::Float4 boneIndex;
Oyster::Math::Float4 boneWeights;
};

View File

@ -94,6 +94,8 @@ namespace Oyster
if(!mi || mi->Vertices->GetBufferPointer() == NULL)
{
delete m;
Core::loader.ReleaseResource(mi);
delete mi;
return NULL;
}
@ -176,6 +178,8 @@ namespace Oyster
float API::PlayAnimation(Model::Model* m, std::wstring name,bool looping)
{
if(m==NULL)
return 0;
m->Animation.AnimationPlaying = &(*m->info->Animations.find(name)).second;
m->Animation.AnimationTime=0;
m->Animation.LoopAnimation = looping;

View File

@ -5,12 +5,11 @@
#include <fstream>
#include <string>
#define DANFILEVERSIONMAJOR 1
#define DANFILEVERSIONMAJOR 2
#define DANFILEVERSIONMINOR 1
#define FILEHEADERSIZE 8
#define VERTEXHEADERSIZE 4
#define VERTEXSIZE 88
@ -176,7 +175,6 @@ static void ReadData(void* Destination, std::ifstream& file, int size)
///
void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
{
//
Oyster::Graphics::Model::ModelInfo* modelInfo = new Oyster::Graphics::Model::ModelInfo();
modelInfo->Indexed = false;
modelInfo->Animated = false;
@ -185,7 +183,10 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
std::ifstream danFile;
danFile.open(filename, std::ios::binary);
if (!danFile.is_open())
{
delete modelInfo;
return NULL;
}
// Read file header
char* buffer = new char[sizeof(FileHeader)];
@ -196,6 +197,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
// If problem with compatability then close file and return from method
if (fileHeader.versionMajor != DANFILEVERSIONMAJOR)
{
delete modelInfo;
danFile.close();
return NULL;
}
@ -220,7 +222,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
delete[] buffer; // ( note: may crash here.)
// Fetch all vertices
unsigned int bufferSize = VERTEXSIZE * vertexHeader.numVertices;
unsigned int bufferSize = sizeof(Vertex) * vertexHeader.numVertices;
buffer = new char[bufferSize];
danFile.read(buffer, bufferSize);
@ -291,7 +293,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
//read normal map name length
ReadData(&materialHeader.normalMapPathLength,danFile,4);
//read difuse map name
//read normal map name
materialHeader.normalMapPath = new char[materialHeader.normalMapPathLength + 1];
ReadData(materialHeader.normalMapPath,danFile,materialHeader.normalMapPathLength);
materialHeader.normalMapPath[materialHeader.normalMapPathLength] = 0;

View File

@ -645,6 +645,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice,
if ( SUCCEEDED(hr) && ( fmtSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN ) )
{
autogen = true;
autogen = false;
}
}

View File

@ -91,8 +91,8 @@ namespace Oyster
{
tmpInst.coff=(1.0f/TEXT_NR_LETTERS);
tmpInst.offset=text[i]-32;
tmpInst.pos=i*(FontSize * 0.8f * TEXT_SPACING);
if(tmpInst.pos > size.x)
tmpInst.pos=i*(FontSize * 0.7f * TEXT_SPACING);
if(tmpInst.pos > size.x*2)
{
text = text.substr(0,i-1);
break;

View File

@ -340,13 +340,11 @@ namespace Oyster
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BONEINDEX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 56, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 72, D3D11_INPUT_PER_VERTEX_DATA, 0 }
{ "BONEINDEX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
Shader::CreateInputLayout(indesc,7,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout);
Shader::CreateInputLayout(indesc,5,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout);
Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData);
Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData);

View File

@ -4,19 +4,19 @@
void main(point Vertex2DIn input[1],inout TriangleStream<Pixel2DIn> Quads)
{
Pixel2DIn output;
output.Pos = mul(float4(-1,-1,0,1) ,Translation);
output.Pos = mul(float4(-1,-1,1,1) ,Translation);
output.Uv = float2(0,1);
Quads.Append(output);
output.Pos = mul(float4(-1,1,0,1), Translation);
output.Pos = mul(float4(-1,1,1,1), Translation);
output.Uv = float2(0,0);
Quads.Append(output);
output.Pos = mul(float4(1,-1,0,1), Translation);
output.Pos = mul(float4(1,-1,1,1), Translation);
output.Uv = float2(1,1);
Quads.Append(output);
output.Pos = mul(float4(1,1,0,1), Translation);
output.Pos = mul(float4(1,1,1,1), Translation);
output.Uv = float2(1,0);
Quads.Append(output);
}

View File

@ -7,22 +7,22 @@ void main(point Text2DIn input[1],inout TriangleStream<Pixel2DIn> Quads)
float endoff=startoff+input[0].coff;
Pixel2DIn output;
output.Pos = mul(float4(-1,-1,0,1), Translation);
output.Pos = mul(float4(-1,-1,1,1), Translation);
output.Pos.x += input[0].Pos;
output.Uv = float2(startoff,1);
Quads.Append(output);
output.Pos = mul(float4(-1,1,0,1), Translation);
output.Pos = mul(float4(-1,1,1,1), Translation);
output.Pos.x += input[0].Pos;
output.Uv = float2(startoff,0);
Quads.Append(output);
output.Pos = mul(float4(1,-1,0,1), Translation);
output.Pos = mul(float4(1,-1,1,1), Translation);
output.Pos.x += input[0].Pos;
output.Uv = float2(endoff,1);
Quads.Append(output);
output.Pos = mul(float4(1,1,0,1), Translation);
output.Pos = mul(float4(1,1,1,1), Translation);
output.Pos.x += input[0].Pos;
output.Uv = float2(endoff,0);
Quads.Append(output);

View File

@ -3,8 +3,6 @@ struct VertexIn
float3 pos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 biTangent : BITANGENT;
float4 boneIndex : BONEINDEX;
float4 boneWeight : BONEWEIGHT;
};
@ -15,8 +13,6 @@ struct VertexOut
float4 ViewPos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
//float3 tangent : TANGENT;
//float3 biTangent : BITANGENT;
};
struct PixelOut

View File

@ -36,7 +36,8 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID )
float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2);
Ambient[DTid.xy/2] = float4(DiffuseGlow[DTid.xy].xyz, AmbValue);
Ambient[DTid.xy/2 + float2(Pixels.x/2, 0)] = GUI[DTid.xy];
Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffuseGlow[DTid.xy].xyz * DiffuseGlow[DTid.xy].w*10,1);
Ambient[DTid.xy/2 + float2(0, Pixels.y/2)] = float4(DiffuseGlow[DTid.xy].xyz * DiffuseGlow[DTid.xy].w,1);
Ambient[DTid.xy/2 + Pixels/2] = float4(NormalSpec[DTid.xy].xyz,1);
}
}

View File

@ -11,7 +11,7 @@ cbuffer Size : register(b0)
int2 Pixels;
}
#define AmbFactor 0.8f;
#define AmbFactor 0.1f;
float4 SuperSample(float4 Glow, uint3 DTid)
{
@ -20,12 +20,7 @@ float4 SuperSample(float4 Glow, uint3 DTid)
index += float2(0,Output.Length.y/2);
index = index / Output.Length;
Glow = Ambient.SampleLevel(S1, index,1);
//Line Y+1
//Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)+1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)+1)];
//Line Y-1
//Glow += Ambient[DTid.xy/2 + uint2(1,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(0,(Output.Length.y/2)-1)] + Ambient[DTid.xy/2 + uint2(-1,(Output.Length.y/2)-1)];
//Glow = Glow/9;
Glow = Glow * Glow.w*10;
return Glow;
}
@ -43,10 +38,10 @@ void main( uint3 DTid : SV_DispatchThreadID )
float4 GUI;
uint2 index = DTid.xy/2 + uint2((uint)Pixels.x/(uint)2,0);
float3 PostLight = Amb.xyz * AmbFactor;
PostLight = PostLight + Light.xyz; // + Glow;
PostLight = PostLight + Light.xyz + Glow;
GUI = float4(Ambient[index]);
PostLight = PostLight * (1 - GUI.w);
Output[DTid.xy] = float4((GUI.xyz * GUI.w) + PostLight, 1);
//Output[DTid.xy] = Glow;
//Output[DTid.xy] = Ambient[DTid.xy];
}

View File

@ -373,6 +373,14 @@ namespace LinearAlgebra3D
return (rotation*localAxis*rotation.GetConjugate()).imaginary;
}
template<typename ScalarType>
inline ::LinearAlgebra::Vector3<ScalarType> AngularAxis( const ::LinearAlgebra::Quaternion<ScalarType> &rotation )
{ // see http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
ScalarType angle = ScalarType(2) * (ScalarType)::std::acos( rotation.real ),
multiplier = angle / (ScalarType)::std::sqrt( ScalarType(1) - rotation.real * rotation.real );
return multiplier * rotation.imaginary;
}
// All Matrix to AngularAxis conversions here is incorrect
//template<typename ScalarType>
//inline ::LinearAlgebra::Vector4<ScalarType> AngularAxis( const ::LinearAlgebra::Matrix3x3<ScalarType> &rotationMatrix )

View File

@ -81,6 +81,12 @@ namespace Oyster { namespace Math2D
namespace Oyster { namespace Math3D
{
//! Converts a rotationQuaternion to an angularAxis
Float3 AngularAxis( const Quaternion &rotation )
{
return ::LinearAlgebra3D::AngularAxis( rotation );
}
//Float4 AngularAxis( const Float3x3 &rotationMatrix )
//{
// return ::LinearAlgebra3D::AngularAxis( rotationMatrix );
@ -96,52 +102,6 @@ namespace Oyster { namespace Math3D
// return ::LinearAlgebra3D::ExtractAngularAxis( orientationMatrix );
//}
Float4 QuaternionToAngularAxis(Float4 quaternion)
{
Float4 axis = Float4::null;
Float s = sqrtf(1 - quaternion.w*quaternion.w);
axis.w = 2*acos(quaternion.w*quaternion.w);
if(1 - quaternion.w > 0.001f)
{
axis.x = quaternion.x/s;
axis.y = quaternion.y/s;
axis.z = quaternion.z/s;
}
else
{
axis.x = quaternion.x;
axis.y = quaternion.y;
axis.z = quaternion.z;
}
return axis;
}
Float4 QuaternionToAngularAxis(Quaternion quaternion)
{
Float4 axis = Float4::null;
Float s = sqrtf(1 - quaternion.real*quaternion.real);
axis.w = 2*acos(quaternion.real*quaternion.real);
if(1 - quaternion.real > 0.001f)
{
axis.x = quaternion.imaginary.x/s;
axis.y = quaternion.imaginary.y/s;
axis.z = quaternion.imaginary.z/s;
}
else
{
axis.x = quaternion.imaginary.x;
axis.y = quaternion.imaginary.y;
axis.z = quaternion.imaginary.z;
}
return axis;
}
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem )
{
return ::LinearAlgebra3D::TranslationMatrix( position, targetMem );

View File

@ -140,6 +140,9 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
{
using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace
//! Converts a rotationQuaternion to an angularAxis
Float3 AngularAxis( const Quaternion &rotation );
//! Extracts the angularAxis from rotationMatrix
//Float4 AngularAxis( const Float3x3 &rotationMatrix );
@ -149,12 +152,6 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized
////! Extracts the angularAxis from orientationMatrix
//Float4 ExtractAngularAxis( const Float4x4 &orientationMatrix );
//! Converts a quaternion as Float4 to angular axis as Float4
Float4 QuaternionToAngularAxis(Float4 quaternion);
//! Converts a quaternion to angular axis as Float4
Float4 QuaternionToAngularAxis(Quaternion quaternion);
//! Sets and returns targetMem to a translationMatrix with position as translation.
Float4x4 & TranslationMatrix( const Float3 &position, Float4x4 &targetMem = Float4x4() );

View File

@ -171,18 +171,14 @@ HRESULT InitDirect3D()
}
m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan");
//m->WorldMatrix.m[0][0] = 50;
//m->WorldMatrix.m[1][1] = 50;
//m->WorldMatrix.m[2][2] = 0.00000005f;
m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
m2 = Oyster::Graphics::API::CreateModel(L"char_orca.dan");
m2->Tint = Oyster::Math::Float3(0.1f,0.1f,1);
m3 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
Oyster::Graphics::API::PlayAnimation(m2, L"movement", true);
m3 = Oyster::Graphics::API::CreateModel(L"char_orca.dan");
//Oyster::Graphics::API::PlayAnimation(m2, L"movement", true);
Oyster::Graphics::API::PlayAnimation(m3, L"movement", true);
t = Oyster::Graphics::API::CreateTexture(L"structure_corp_mdg.png");
t2 = Oyster::Graphics::API::CreateTexture(L"whiteGui.png");
t2 = Oyster::Graphics::API::CreateTexture(L"color_white.png");
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000);
Oyster::Graphics::API::SetProjection(P);
@ -217,15 +213,13 @@ HRESULT InitDirect3D()
return S_OK;
}
float angle = 0;
float z=0;
HRESULT Update(float deltaTime)
{
//angle += Oyster::Math::pi/16 * deltaTime;
m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0) * angle,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null);
m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(0,0,z),Oyster::Math::Float3::null);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null);
//Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity;
Oyster::Graphics::API::Update(deltaTime);
//m2->Animation.data.AnimationTime += deltaTime;// * 0.5f;
return S_OK;
}
@ -238,7 +232,7 @@ HRESULT Render(float deltaTime)
Oyster::Graphics::API::RenderModel(m2);
Oyster::Graphics::API::RenderModel(m3);
Oyster::Graphics::API::StartGuiRender();
//Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1), Oyster::Math::Float3(0,0,1));
Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float3(0.5f,0.7f,0.1f),Oyster::Math::Float2(0.2f,0.2f), Oyster::Math::Float3(1,1,1));
//Oyster::Graphics::API::RenderGuiElement(t2,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(1,1),Oyster::Math::Float3(1,0,0));
Oyster::Graphics::API::StartTextRender();
std::wstring fps;
@ -246,7 +240,7 @@ HRESULT Render(float deltaTime)
fps = std::to_wstring(f);
//Oyster::Graphics::API::RenderText(L"Lanariel",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
//Oyster::Graphics::API::RenderText(L"Lanariel WAS HERE",Oyster::Math::Float2(0.5f,0.1f),Oyster::Math::Float2(0.5f,0.1f));
Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float3(0.5f,0.1f,1.0f),Oyster::Math::Float2(0.5f,0.1f), 0.08f, Oyster::Math::Float3(0,1,0));
Oyster::Graphics::API::RenderText(fps,Oyster::Math::Float3(0.5f,0.1f,0.1f),Oyster::Math::Float2(0.5f,0.1f), 0.08f, Oyster::Math::Float3(0,1,0));
Oyster::Graphics::API::EndFrame();
return S_OK;
@ -286,16 +280,26 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
break;
//Z -
case 0x5A:
//m2->AnimationTime -= 0.1f;
//if(m2->AnimationTime < 0)
//m2->AnimationTime = 0;
angle += Oyster::Math::pi / 16;
break;
//X +
case 0x58:
//m2->AnimationTime += 0.1f;
angle -= Oyster::Math::pi / 16;
break;
//A
case 0x41:
break;
//D
case 0x44:
break;
//W
case 0x57:
z-=0.5f;
break;
//S
case 0x53:
z+=0.5f;
break;
}
break;