GL - set pos function for C_models

This commit is contained in:
Linda Andersson 2013-12-16 11:08:10 +01:00
parent b351a7bac4
commit dc3221ee11
14 changed files with 83 additions and 40 deletions

Binary file not shown.

View File

@ -34,28 +34,32 @@ namespace DanBias
Client::GameClientState::ProtocolStruct* protocolData;
switch (pType)
{
case protocol_PlayerNavigation:
case protocol_Gamplay_PlayerNavigation:
break;
case protocol_PlayerPosition:
case protocol_Gamplay_PlayerPosition:
protocolData = new Client::GameClientState::PlayerPos;
for(int i = 0; i< 3; i++)
{
((Client::GameClientState::PlayerPos*)protocolData)->playerPos[i] = p[i].value.netFloat;
}
gameClientState->Protocol(protocolData);
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
break;
case protocol_ObjectPosition:
case protocol_Gamplay_ObjectPosition:
protocolData = new Client::GameClientState::ObjPos;
for(int i = 0; i< 16; i++)
{
((Client::GameClientState::ObjPos*)protocolData)->worldPos[i] = p[i].value.netFloat;
}
gameClientState->Protocol(protocolData);
if(dynamic_cast<Client::GameState*>(gameClientState))
((Client::GameState*)gameClientState)->Protocol(protocolData);
delete protocolData;
protocolData = NULL;
break;
@ -79,9 +83,9 @@ namespace DanBias
}
public:
Client::GameClientState* gameClientState;
//Client::GameClientState* gameClientState;
InputClass* inputObj;
MyRecieverObject* r;
MyRecieverObject* recieverObj;
} data;
#pragma endregion
@ -110,17 +114,17 @@ namespace DanBias
prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
m_data->r = new MyRecieverObject;
m_data->r->nwClient = new Oyster::Network::NetworkClient();
m_data->r->nwClient->Connect(desc.port, desc.IP);
if (!m_data->r->nwClient->IsConnected())
m_data->recieverObj = new MyRecieverObject;
m_data->recieverObj->nwClient = new Oyster::Network::NetworkClient();
m_data->recieverObj->nwClient->Connect(desc.port, desc.IP);
if (!m_data->recieverObj->nwClient->IsConnected())
{
// failed to connect
return DanBiasClientReturn_Error;
}
// Start in lobby state
m_data->gameClientState = new Client::LobbyState();
m_data->gameClientState->Init(m_data->r->nwClient);
m_data->recieverObj->gameClientState = new Client::LobbyState();
m_data->recieverObj->gameClientState->Init(m_data->recieverObj->nwClient);
return DanBiasClientReturn_Sucess;
@ -237,27 +241,27 @@ namespace DanBias
m_data->inputObj->Update();
DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same;
state = m_data->gameClientState->Update(deltaTime, m_data->inputObj);
state = m_data->recieverObj->gameClientState->Update(deltaTime, m_data->inputObj);
if(state != Client::GameClientState::ClientState_Same)
{
m_data->gameClientState->Release();
delete m_data->gameClientState;
m_data->gameClientState = NULL;
m_data->recieverObj->gameClientState->Release();
delete m_data->recieverObj->gameClientState;
m_data->recieverObj->gameClientState = NULL;
switch (state)
{
case Client::GameClientState::ClientState_Lobby:
m_data->gameClientState = new Client::LobbyState();
m_data->recieverObj->gameClientState = new Client::LobbyState();
break;
case Client::GameClientState::ClientState_Game:
m_data->gameClientState = new Client::GameState();
m_data->recieverObj->gameClientState = new Client::GameState();
break;
default:
return E_FAIL;
break;
}
m_data->gameClientState->Init(m_data->r->nwClient); // send game client
m_data->recieverObj->gameClientState->Init(m_data->recieverObj->nwClient); // send game client
}
return S_OK;
@ -275,15 +279,18 @@ namespace DanBias
swprintf(title, sizeof(title), L"| Pressing A: %d | \n", (int)(isPressed));
SetWindowText(g_hWnd, title);
m_data->gameClientState->Render();
m_data->recieverObj->gameClientState->Render();
return S_OK;
}
HRESULT DanBiasGame::CleanUp()
{
m_data->gameClientState->Release();
delete m_data->gameClientState;
m_data->recieverObj->gameClientState->Release();
delete m_data->recieverObj->gameClientState;
m_data->recieverObj->nwClient->Disconnect();
delete m_data->recieverObj->nwClient;
delete m_data->recieverObj;
delete m_data->inputObj;
delete m_data;

View File

@ -20,7 +20,7 @@ private:
public:
virtual void Init(ModelInitData modelInit) = 0;
virtual void setPos() = 0;
virtual void setPos(Oyster::Math::Float4x4 world) = 0;
virtual void Render() = 0;
virtual void Release() = 0;

View File

@ -26,9 +26,9 @@ void C_DynamicObj::Init(ModelInitData modelInit)
privData->model->WorldMatrix = modelInit.world;
privData->model->Visible = modelInit.visible;
}
void C_DynamicObj::setPos()
void C_DynamicObj::setPos(Oyster::Math::Float4x4 world)
{
privData->model->WorldMatrix = world;
}
void C_DynamicObj::Render()

View File

@ -14,7 +14,7 @@ public:
C_DynamicObj(void);
virtual ~C_DynamicObj(void);
void Init(ModelInitData modelInit);
void setPos();
void setPos(Oyster::Math::Float4x4 world);
void Render();
void Release();

View File

@ -30,9 +30,9 @@ void C_Player::Init(ModelInitData modelInit)
}
void C_Player::setPos()
void C_Player::setPos(Oyster::Math::Float4x4 world)
{
privData->model->WorldMatrix = world;
}
void C_Player::Render()

View File

@ -15,7 +15,7 @@ public:
C_Player(void);
~C_Player(void);
void Init(ModelInitData modelInit);
void setPos();
void setPos(Oyster::Math::Float4x4 world);
void Render();
void Release();

View File

@ -29,9 +29,9 @@ void C_StaticObj::Init(ModelInitData modelInit)
privData->model->Visible = modelInit.visible;
}
void C_StaticObj::setPos()
void C_StaticObj::setPos(Oyster::Math::Float4x4 world)
{
privData->model->WorldMatrix = world;
}
void C_StaticObj::Render()

View File

@ -14,7 +14,7 @@ public:
C_StaticObj(void);
virtual ~C_StaticObj(void);
void Init(ModelInitData modelInit);
void setPos();
void setPos(Oyster::Math::Float4x4 world);
void Render();
void Release();

View File

@ -27,9 +27,9 @@ void C_UIobject::Init(ModelInitData modelInit)
privData->model->Visible = modelInit.visible;
}
void C_UIobject::setPos()
void C_UIobject::setPos(Oyster::Math::Float4x4 world)
{
privData->model->WorldMatrix = world;
}
void C_UIobject::Render()

View File

@ -14,7 +14,7 @@ namespace DanBias
C_UIobject(void);
virtual ~C_UIobject(void);
void Init(ModelInitData modelInit);
void setPos();
void setPos(Oyster::Math::Float4x4 world);
void Render();
void Release();

View File

@ -118,7 +118,8 @@ GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyI
{
movePlayer.bStrafeRight = true;
}
//PlayerPos* posPlayer;
//Protocol(posPlayer);
privData->nwClient->Send(movePlayer);
@ -169,12 +170,45 @@ void GameState::Protocol(ProtocolStruct* pos)
else if((PlayerPos*)pos)
PlayerPosProtocol((PlayerPos*)pos);
}
void DanBias::Client::GameState::Protocol( PlayerPos* pos )
{
Oyster::Math::Float4x4 world, translate;
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 = translate;
privData->object[0]->setPos( world );
}
void DanBias::Client::GameState::Protocol( ObjPos* pos )
{
Oyster::Math::Float4x4 world;
for(int i = 0; i<16; i++)
{
world[i] = pos->worldPos[i];
}
privData->object[1]->setPos(world);
}
void GameState::PlayerPosProtocol(PlayerPos* pos)
{
Oyster::Math::Float4x4 world, translate;
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 = translate;
privData->object[0]->setPos( world );
}
void GameState::ObjectPosProtocol(ObjPos* pos)
{
Oyster::Math::Float4x4 world;
for(int i = 0; i<16; i++)
{
world[i] = pos->worldPos[i];
}
privData->object[1]->setPos(world);
}
//void GameState::Protocol(LightPos pos);

View File

@ -32,6 +32,8 @@ public:
bool Release()override;
void Protocol(ProtocolStruct* pos)override;
void Protocol(PlayerPos* pos);
void Protocol(ObjPos* pos);
void PlayerPosProtocol(PlayerPos* pos);
void ObjectPosProtocol(ObjPos* pos);
//void Protocol(LightPos pos);

View File

@ -29,8 +29,8 @@ int WINAPI WinMain( HINSTANCE hinst, HINSTANCE prevInst, PSTR cmdLine, int cmdSh
}
// Game client starter code goes here
DanBias::DanBiasGameDesc gameDesc;
gameDesc.port = 1;
gameDesc.IP = "10.1010.303";
gameDesc.port = 15151;
gameDesc.IP = "193.11.186.101";
gameDesc.hinst = hinst;
gameDesc.nCmdShow = cmdShow;