From bfa748047ff73e7d2209d9a370f41ed85e484c7d Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 13:31:36 +0100 Subject: [PATCH 01/21] GL - added RigidBody data on client for debuging output --- .../GameClient/GameClientState/C_Object.cpp | 75 ++++++++++++++----- .../GameClient/GameClientState/C_Object.h | 36 +++++++-- .../GameClient/GameClientState/GameState.cpp | 47 ++++++++++++ .../GameClientState/NetLoadState.cpp | 39 +++++++++- 4 files changed, 172 insertions(+), 25 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index 92b55c53..dc22f34d 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -31,32 +31,27 @@ void C_Object::updateWorld() { Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); - //Oyster::Math3D::Float4x4 scale = Oyster::Math3D::; - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Matrix::identity; - scale.v[0].x = this->scale[0]; - scale.v[1].y = this->scale[1]; - scale.v[2].z = this->scale[2]; + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); world = translation * rot * scale; model->WorldMatrix = world; } -void C_Object::setWorld(Oyster::Math::Float4x4 world) -{ - model->WorldMatrix = world; -} Oyster::Math::Float4x4 C_Object::getWorld() const { + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->position); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->rotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->scale); + Oyster::Math3D::Float4x4 world = translation * rot * scale; + return world; } void C_Object::setPos(Oyster::Math::Float3 newPos) { this->position = newPos; - updateWorld(); } void C_Object::addPos(Oyster::Math::Float3 deltaPos) { this->position += deltaPos; - updateWorld(); } Oyster::Math::Float3 C_Object::getPos() const { @@ -65,12 +60,6 @@ Oyster::Math::Float3 C_Object::getPos() const void C_Object::setRot(Oyster::Math::Quaternion newRot) { this->rotation = newRot; - updateWorld(); -} -void C_Object::addRot(Oyster::Math::Quaternion deltaRot) -{ - this->rotation += deltaRot; - updateWorld(); } Oyster::Math::Quaternion C_Object::getRotation() const { @@ -79,12 +68,10 @@ Oyster::Math::Quaternion C_Object::getRotation() const void C_Object::setScale(Oyster::Math::Float3 newScale) { this->scale = newScale; - updateWorld(); } void C_Object::addScale(Oyster::Math::Float3 deltaScale) { this->scale += deltaScale; - updateWorld(); } Oyster::Math::Float3 C_Object::getScale() const { @@ -105,4 +92,54 @@ void C_Object::Release() Oyster::Graphics::API::DeleteModel(model); this->model = nullptr; } +} + + + +//////////////////////////////////////////////// +// RB DEBUG +//////////////////////////////////////////////// +bool C_Object::InitRB(RBInitData RBInit) +{ + RBposition = RBInit.position; + RBrotation = RBInit.rotation; + RBscale = RBInit.scale; + return true; +} +Oyster::Math::Float4x4 C_Object::getRBWorld() const +{ + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(this->RBposition); + Oyster::Math3D::Float4x4 rot = Oyster::Math3D::RotationMatrix(this->RBrotation); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(this->RBscale); + Oyster::Math3D::Float4x4 world = translation * rot * scale; + + return world; +} +void C_Object::setRBPos(Oyster::Math::Float3 newPos) +{ + this->RBposition = newPos; +} +Oyster::Math::Float3 C_Object::getRBPos() const +{ + return this->RBposition; +} +void C_Object::setRBRot(Oyster::Math::Quaternion newRot) +{ + this->RBrotation = newRot; +} +Oyster::Math::Quaternion C_Object::getRBRotation() const +{ + return this->RBrotation; +} +void C_Object::setRBScale(Oyster::Math::Float3 newScale) +{ + this->RBscale = newScale; +} +Oyster::Math::Float3 C_Object::getRBScale() const +{ + return this->RBscale; +} +RB_Type C_Object::getBRtype()const +{ + return this->type; } \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index 20e0eb60..d0b86a41 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -5,7 +5,11 @@ namespace DanBias { namespace Client { - + enum RB_Type + { + RB_Type_Cube, + RB_Type_Sphere + }; struct ModelInitData { int id; @@ -15,6 +19,13 @@ namespace DanBias Oyster::Math::Float3 scale; bool visible; }; + struct RBInitData + { + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + RB_Type type; + }; class C_Object { @@ -23,28 +34,43 @@ namespace DanBias Oyster::Math::Float3 position; Oyster::Math::Quaternion rotation; Oyster::Math::Float3 scale; + + // RB DEBUG + Oyster::Math::Float3 RBposition; + Oyster::Math::Quaternion RBrotation; + Oyster::Math::Float3 RBscale; + RB_Type type; int id; - void updateWorld(); + protected: Oyster::Graphics::Model::Model *model; public: C_Object(); virtual ~C_Object(); virtual bool Init(ModelInitData modelInit); - - void setWorld(Oyster::Math::Float4x4 world); + void updateWorld(); + //void setWorld(Oyster::Math::Float4x4 world); Oyster::Math::Float4x4 getWorld() const; void setPos(Oyster::Math::Float3 newPos); Oyster::Math::Float3 getPos() const; void addPos(Oyster::Math::Float3 deltaPos); void setRot(Oyster::Math::Quaternion newRot); Oyster::Math::Quaternion getRotation() const; - void addRot(Oyster::Math::Quaternion deltaRot); void setScale(Oyster::Math::Float3 newScale); void addScale(Oyster::Math::Float3 deltaScale); Oyster::Math::Float3 getScale() const; + // RB DEBUG + bool InitRB(RBInitData modelInit); + Oyster::Math::Float4x4 getRBWorld() const; + void setRBPos(Oyster::Math::Float3 newPos); + Oyster::Math::Float3 getRBPos() const; + void setRBRot(Oyster::Math::Quaternion newRot); + Oyster::Math::Quaternion getRBRotation() const; + void setRBScale(Oyster::Math::Float3 newScale); + Oyster::Math::Float3 getRBScale() const; + RB_Type getBRtype()const; virtual void Render(); virtual void Release(); virtual int GetId() const; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index f590f366..cf35b7c1 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -108,10 +108,19 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa StringToWstring( modelName, modelData.modelPath ); modelData.id = id; + // RB DEBUG + RBInitData RBData; + RBData.position = position; + RBData.rotation = ArrayToQuaternion( rotation ); + RBData.scale = Float3( 3 ); + if( isMyPlayer ) { if( this->privData->player.Init(modelData) ) { + // RB DEBUG + this->privData->player.InitRB( RBData ); + this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); Float3 offset = Float3( 0.0f ); @@ -125,6 +134,9 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa C_DynamicObj *p = new C_DynamicObj(); if( p->Init(modelData) ) { + // RB DEBUG + this->privData->player.InitRB( RBData ); + (*this->privData->dynamicObjects)[id] = p; } } @@ -157,6 +169,41 @@ bool GameState::Render() dynamicObject->second->Render(); } + // RB DEBUG render wire frame + Oyster::Graphics::API::StartRenderWireFrame(); + + + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 2, 2, 2)); + Oyster::Math3D::Float4x4 world = translation * scale; + Oyster::Graphics::API::RenderDebugCube( world ); + Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + + + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + { + if( staticObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); + } + if( staticObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); + } + } + + + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) + { + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } + } Oyster::Graphics::API::EndFrame(); return true; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 7443344e..706e0d53 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -134,10 +134,29 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) desc.rotation = ArrayToQuaternion( oh->rotation ); desc.scale = oh->scale; desc.visible = true; - + C_StaticObj *staticObject = new C_StaticObj(); if( staticObject->Init( desc ) ) { + + // RB DEBUG + RBInitData RBData; + if(oh->boundingVolume.geoType == CollisionGeometryType_Box) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + staticObject->InitRB( RBData ); + } + + if(oh->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + staticObject->InitRB( RBData ); + } + (*this->privData->staticObjects)[objectID] = staticObject; } else @@ -161,6 +180,24 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) C_DynamicObj *dynamicObject = new C_DynamicObj(); if( dynamicObject->Init( desc ) ) { + // RB DEBUG + RBInitData RBData; + if(oh->boundingVolume.geoType == CollisionGeometryType_Box) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + dynamicObject->InitRB( RBData ); + } + + if(oh->boundingVolume.geoType == CollisionGeometryType_Sphere) + { + RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; + RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation + RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + dynamicObject->InitRB( RBData ); + } + (*this->privData->dynamicObjects)[objectID] = dynamicObject; } else From 0971bc407e74a94ccab21617481bbe6dfc24b6d6 Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 14:23:38 +0100 Subject: [PATCH 02/21] Small fix --- Code/Game/GameClient/GameClientState/GameState.cpp | 6 +++--- Code/OysterGraphics/FileLoader/ModelLoader.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 79f3c471..1afba43d 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,7 +81,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Math::pi/8, aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -108,7 +108,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBInitData RBData; RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); - RBData.scale = Float3( 3 ); + RBData.scale = Float3( 1 ); if( isMyPlayer ) { @@ -170,7 +170,7 @@ bool GameState::Render() Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 2, 2, 2)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); Oyster::Math3D::Float4x4 world = translation * scale; Oyster::Graphics::API::RenderDebugCube( world ); Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); diff --git a/Code/OysterGraphics/FileLoader/ModelLoader.cpp b/Code/OysterGraphics/FileLoader/ModelLoader.cpp index ba0928cc..0c7125fd 100644 --- a/Code/OysterGraphics/FileLoader/ModelLoader.cpp +++ b/Code/OysterGraphics/FileLoader/ModelLoader.cpp @@ -700,7 +700,7 @@ static HRESULT CreateTextureFromWIC( _In_ ID3D11Device* d3dDevice, return hr; } //todo check calc - int TexSize = twidth * theight * bpp; + int TexSize = twidth * theight * (int)bpp; Oyster::Graphics::Core::UsedMem += TexSize; if ( autogen ) From e8b0e75ed7773623e1fef3bbb0cbb305f0be101e Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 15:07:40 +0100 Subject: [PATCH 03/21] Render rigid body from lvl format --- .../GameClient/GameClientState/C_Object.cpp | 8 +++++- .../GameClient/GameClientState/C_Object.h | 25 ++++++++++++------- .../GameClient/GameClientState/GameState.cpp | 12 ++++++--- .../GameClientState/NetLoadState.cpp | 6 +++++ Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index dc22f34d..ccea9a86 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -9,6 +9,10 @@ C_Object::C_Object() id = 0; model = NULL; + + // RB DEBUG + type = RB_Type_None; + // !RB DEBUG } C_Object::~C_Object() { @@ -104,6 +108,7 @@ bool C_Object::InitRB(RBInitData RBInit) RBposition = RBInit.position; RBrotation = RBInit.rotation; RBscale = RBInit.scale; + type = RBInit.type; return true; } Oyster::Math::Float4x4 C_Object::getRBWorld() const @@ -142,4 +147,5 @@ Oyster::Math::Float3 C_Object::getRBScale() const RB_Type C_Object::getBRtype()const { return this->type; -} \ No newline at end of file +} +// !RB DEBUG \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/C_Object.h b/Code/Game/GameClient/GameClientState/C_Object.h index d0b86a41..dcc2731c 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.h +++ b/Code/Game/GameClient/GameClientState/C_Object.h @@ -5,11 +5,22 @@ namespace DanBias { namespace Client { + // RB DEBUG enum RB_Type { RB_Type_Cube, - RB_Type_Sphere + RB_Type_Sphere, + RB_Type_None, }; + struct RBInitData + { + Oyster::Math::Float3 position; + Oyster::Math::Quaternion rotation; + Oyster::Math::Float3 scale; + RB_Type type; + }; + // !RB DEBUG + struct ModelInitData { int id; @@ -19,13 +30,6 @@ namespace DanBias Oyster::Math::Float3 scale; bool visible; }; - struct RBInitData - { - Oyster::Math::Float3 position; - Oyster::Math::Quaternion rotation; - Oyster::Math::Float3 scale; - RB_Type type; - }; class C_Object { @@ -40,7 +44,8 @@ namespace DanBias Oyster::Math::Quaternion RBrotation; Oyster::Math::Float3 RBscale; RB_Type type; - + // !RB DEBUG + int id; protected: @@ -71,6 +76,8 @@ namespace DanBias void setRBScale(Oyster::Math::Float3 newScale); Oyster::Math::Float3 getRBScale() const; RB_Type getBRtype()const; + // !RB DEBUG + virtual void Render(); virtual void Release(); virtual int GetId() const; diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1afba43d..ba333061 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -81,7 +81,7 @@ bool GameState::Init( SharedStateContent &shared ) Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Math::pi/8, aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Math::pi/2, aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -109,6 +109,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); RBData.scale = Float3( 1 ); + // !RB DEBUG if( isMyPlayer ) { @@ -116,6 +117,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { // RB DEBUG this->privData->player.InitRB( RBData ); + // !RB DEBUG this->privData->myId = id; this->privData->camera.SetPosition( this->privData->player.getPos() ); @@ -132,6 +134,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa { // RB DEBUG this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[id] = p; } @@ -168,14 +171,13 @@ bool GameState::Render() // RB DEBUG render wire frame Oyster::Graphics::API::StartRenderWireFrame(); - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); Oyster::Math3D::Float4x4 world = translation * scale; Oyster::Graphics::API::RenderDebugCube( world ); Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); - + staticObject = this->privData->staticObjects->begin(); for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { if( staticObject->second->getBRtype() == RB_Type_Cube) @@ -188,7 +190,7 @@ bool GameState::Render() } } - + dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { if( dynamicObject->second->getBRtype() == RB_Type_Cube) @@ -200,6 +202,8 @@ bool GameState::Render() Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); } } + // !RB DEBUG + Oyster::Graphics::API::EndFrame(); return true; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 706e0d53..2fe143d6 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -146,6 +146,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; staticObject->InitRB( RBData ); } @@ -154,8 +155,10 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; staticObject->InitRB( RBData ); } + // !RB DEBUG (*this->privData->staticObjects)[objectID] = staticObject; } @@ -187,6 +190,7 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.box.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * (Float3)oh->boundingVolume.box.size; + RBData.type = RB_Type_Cube; dynamicObject->InitRB( RBData ); } @@ -195,8 +199,10 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) RBData.position = (Float3)oh->position + (Float3)oh->boundingVolume.sphere.position; RBData.rotation = ArrayToQuaternion( oh->rotation ); // Only model rotation RBData.scale = (Float3)oh->scale * oh->boundingVolume.sphere.radius; + RBData.type = RB_Type_Sphere; dynamicObject->InitRB( RBData ); } + // !RB DEBUG (*this->privData->dynamicObjects)[objectID] = dynamicObject; } diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..96e2bbe2 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -197,6 +197,7 @@ namespace Oyster void API::StartRenderWireFrame() { Core::deviceContext->RSSetState(wire); + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); } void API::RenderDebugCube(Math::Matrix world) From 60d44d76d8d5ef19aaf54ca67403a87f50d8d0bf Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 15:20:53 +0100 Subject: [PATCH 04/21] using new models --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index bdfa0bde..cd164f1c 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -24,6 +24,8 @@ namespace Oyster Model::Model* sphere; ID3D11RasterizerState* wire; + + ID3D11ShaderResourceView* debugSRV; #endif } @@ -50,8 +52,14 @@ namespace Oyster Render::Preparations::Basic::SetViewPort(); #ifdef _DEBUG //fix load model - cube = CreateModel(L"debug_cube.dan"); - sphere = CreateModel(L"debug_sphere.dan"); + + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + debugSRV = (ID3D11ShaderResourceView*)API::CreateTexture(L"color_white.png"); + + cube = CreateModel(L"generic_cube.dan"); + cube->Tint = Math::Float3(0.0f,0.0f,1.0f); + sphere = CreateModel(L"generic_sphere.dan"); + D3D11_RASTERIZER_DESC desc; desc.CullMode = D3D11_CULL_BACK; @@ -196,6 +204,7 @@ namespace Oyster void API::StartRenderWireFrame() { + Core::deviceContext->OMSetRenderTargets(Render::Resources::Gather::Pass.RTV.size(),&Render::Resources::Gather::Pass.RTV[0],NULL); Core::deviceContext->RSSetState(wire); } From 02312c53a4f55135e9b3a9829285b361d7ba225a Mon Sep 17 00:00:00 2001 From: lanariel Date: Tue, 18 Feb 2014 15:41:59 +0100 Subject: [PATCH 05/21] changed debug models and tinted pink spheres --- Code/OysterGraphics/DllInterfaces/GFXAPI.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp index 93052730..ccb811c1 100644 --- a/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp +++ b/Code/OysterGraphics/DllInterfaces/GFXAPI.cpp @@ -59,6 +59,7 @@ namespace Oyster cube = CreateModel(L"generic_cube.dan"); cube->Tint = Math::Float3(0.0f,0.0f,1.0f); sphere = CreateModel(L"generic_sphere.dan"); + sphere->Tint = Math::Float3(1.0f,0.5f,182/255.0f); D3D11_RASTERIZER_DESC desc; From 611e75b5052c420f3449cb36d3b1fff56b9dd741 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Tue, 18 Feb 2014 15:54:09 +0100 Subject: [PATCH 06/21] Toggle wireframe with "T" --- .../GameClient/GameClientState/GameState.cpp | 134 ++++++++++++------ 1 file changed, 91 insertions(+), 43 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index ba333061..66b8fc61 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -36,7 +36,11 @@ struct GameState::MyData bool key_Shoot; bool key_Jump; + // DEGUG KEYS bool key_Reload_Shaders; + bool key_Wireframe_Toggle; + bool renderWhireframe; + // !DEGUG KEYS C_Player player; Camera_FPS camera; @@ -90,7 +94,12 @@ bool GameState::Init( SharedStateContent &shared ) // Debugg hack this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); // end debug hack - + // DEGUG KEYS + this->privData->key_Reload_Shaders = false; + this->privData->key_Wireframe_Toggle = false; + this->privData->renderWhireframe = false; + // !DEGUG KEYS + return true; } @@ -169,37 +178,40 @@ bool GameState::Render() } // RB DEBUG render wire frame - Oyster::Graphics::API::StartRenderWireFrame(); - - Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); - Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); - Oyster::Math3D::Float4x4 world = translation * scale; - Oyster::Graphics::API::RenderDebugCube( world ); - Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); - - staticObject = this->privData->staticObjects->begin(); - for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) + if(this->privData->renderWhireframe) { - if( staticObject->second->getBRtype() == RB_Type_Cube) - { - Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); - } - if( staticObject->second->getBRtype() == RB_Type_Sphere) - { - Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); - } - } + Oyster::Graphics::API::StartRenderWireFrame(); - dynamicObject = this->privData->dynamicObjects->begin(); - for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) - { - if( dynamicObject->second->getBRtype() == RB_Type_Cube) + Oyster::Math3D::Float4x4 translation = Oyster::Math3D::TranslationMatrix(Float3( 0,132, 20)); + Oyster::Math3D::Float4x4 scale = Oyster::Math3D::ScalingMatrix(Float3( 0.5f, 0.5f, 0.5f)); + Oyster::Math3D::Float4x4 world = translation * scale; + Oyster::Graphics::API::RenderDebugCube( world ); + Oyster::Graphics::API::RenderDebugCube(this->privData->player.getRBWorld()); + + staticObject = this->privData->staticObjects->begin(); + for( ; staticObject != this->privData->staticObjects->end(); ++staticObject ) { - Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + if( staticObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( staticObject->second->getRBWorld()); + } + if( staticObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( staticObject->second->getRBWorld()); + } } - if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + + dynamicObject = this->privData->dynamicObjects->begin(); + for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } } } // !RB DEBUG @@ -283,21 +295,6 @@ void GameState::ReadKeyInput() else this->privData->key_strafeRight = false; - if( this->privData->input->IsKeyPressed(DIK_R) ) - { - if( !this->privData->key_Reload_Shaders ) - { - //this->privData->nwClient->Send( Protocol_PlayerMovementRight() ); -#ifdef _DEBUG - Graphics::API::ReloadShaders(); -#endif - this->privData->key_Reload_Shaders = true; - } - } - else - this->privData->key_Reload_Shaders = false; - - //send delta mouse movement { this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); @@ -363,6 +360,35 @@ void GameState::ReadKeyInput() else this->privData->key_Jump = false; + + // DEGUG KEYS + + // Reload shaders + if( this->privData->input->IsKeyPressed(DIK_R) ) + { + if( !this->privData->key_Reload_Shaders ) + { +#ifdef _DEBUG + Graphics::API::ReloadShaders(); +#endif + this->privData->key_Reload_Shaders = true; + } + } + else + this->privData->key_Reload_Shaders = false; + + // toggle wire frame render + if( this->privData->input->IsKeyPressed(DIK_T) ) + { + if( !this->privData->key_Wireframe_Toggle ) + { + this->privData->renderWhireframe = !this->privData->renderWhireframe; + this->privData->key_Wireframe_Toggle = true; + } + } + else + this->privData->key_Wireframe_Toggle = false; + // !DEGUG KEYS // TODO: implement sub-menu } @@ -387,12 +413,18 @@ void GameState::DataRecieved( NetEventprivData->camera.SetPosition( decoded.position ); (*this->privData->dynamicObjects)[decoded.object_ID]->setPos( decoded.position ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( decoded.position ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectScale: { Protocol_ObjectScale decoded(data); (*this->privData->dynamicObjects)[decoded.object_ID]->setScale( decoded.scale ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBScale ( decoded.scale ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectRotation: @@ -405,6 +437,9 @@ void GameState::DataRecieved( NetEventprivData->camera.SetAngular( AngularAxis(rotation) ); (*this->privData->dynamicObjects)[decoded.object_ID]->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectPositionRotation: @@ -423,6 +458,10 @@ void GameState::DataRecieved( NetEventprivData->dynamicObjects)[decoded.object_ID]; object->setPos( position ); object->setRot( rotation ); + // RB DEBUG + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBPos ( position ); + (*this->privData->dynamicObjects)[decoded.object_ID]->setRBRot ( rotation ); + // !RB DEBUG } break; case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */ @@ -446,7 +485,7 @@ void GameState::DataRecieved( NetEventInit(modelData); + // RB DEBUG + // Is just using the model position since the rigid body data should never be sent to the client + RBInitData RBData; + RBData.position = decoded.position; + RBData.rotation = ArrayToQuaternion( decoded.position ); + RBData.scale = Float3( decoded.scale ); + + this->privData->player.InitRB( RBData ); + // !RB DEBUG (*this->privData->dynamicObjects)[decoded.object_ID] = object; From c2ef8350cfa7288bc3093c307952f3a41eb8ef9e Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Wed, 19 Feb 2014 10:15:52 +0100 Subject: [PATCH 07/21] GL - players created with unique ids --- Code/Game/GameLogic/Game.cpp | 39 +++++++++++++++++-------- Code/Game/GameLogic/Game_PlayerData.cpp | 18 +++++++++--- Code/Misc/Utilities/Utilities.h | 6 +--- 3 files changed, 42 insertions(+), 21 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index ba294349..8b77dea4 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -68,12 +68,33 @@ void Game::GetAllPlayerPositions() const Game::PlayerData* Game::CreatePlayer() { // Find a free space in array or insert at end - int i = InsertObject(this->players, (PlayerData*)0); + int insert = InsertObject(this->players, (PlayerData*)0); + int freeID = 0; + bool found = false; - this->players[i] = new PlayerData(); - this->players[i]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + for(int i = 0; i < 100; i++) + { + found = true; + freeID = i; - return this->players[i]; + for(int j = 0; j < players.Size(); j++) + { + + if(this->players[j] && this->players[j]->GetID() == freeID) + { + found = false; + } + + if(!found) break; + } + + if(found) break; + } + + this->players[insert] = new PlayerData(freeID, 0); // user constructor with objectID and teamID + this->players[insert]->player->GetRigidBody()->SetSubscription(Game::PhysicsOnMove); + + return this->players[insert]; } Game::LevelData* Game::CreateLevel(const wchar_t mapName[255]) @@ -95,21 +116,15 @@ bool Game::NewFrame() { for (unsigned int i = 0; i < this->players.Size(); i++) { - if(this->players[i]->player) this->players[i]->player->BeginFrame(); + if(this->players[i] && this->players[i]->player) this->players[i]->player->BeginFrame(); } API::Instance().UpdateWorld(); for (unsigned int i = 0; i < this->players.Size(); i++) { - if(this->players[i]->player) this->players[i]->player->EndFrame(); - gameInstance.onMoveFnc(this->players[i]); + if(this->players[i] && this->players[i]->player) this->players[i]->player->EndFrame(); } - for (unsigned int i = 0; i < this->level->level->dynamicObjects.Size(); i++) - { - gameInstance.onMoveFnc(this->level->level->dynamicObjects[i]); - } - return true; } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index e7a77bbd..3858d370 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -21,13 +21,23 @@ Game::PlayerData::PlayerData() 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); - player->EndFrame(); } Game::PlayerData::PlayerData(int playerID,int teamID) { - this->player = new Player(); + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); + + Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); + Oyster::Math::Float mass = 60; + Oyster::Math::Float restitutionCoeff = 0.5f; + Oyster::Math::Float frictionCoeff_Static = 0.4f; + Oyster::Math::Float frictionCoeff_Dynamic = 0.3f; + //sbDesc.quaternion = Oyster::Math::Float3(0, Oyster::Math::pi, 0); + + //create rigid body + 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,playerID,teamID); } Game::PlayerData::~PlayerData() { diff --git a/Code/Misc/Utilities/Utilities.h b/Code/Misc/Utilities/Utilities.h index b97d62d7..c259a845 100644 --- a/Code/Misc/Utilities/Utilities.h +++ b/Code/Misc/Utilities/Utilities.h @@ -337,11 +337,7 @@ namespace Utility template inline ValueType Clamp( const ValueType &value, const ValueType &min, const ValueType &max ) - { - if( value < min ) return min; - if( value > max ) return max; - return value; - } + { return value < min ? Max( value, max ) : min; } template inline ValueType Average( const ValueType &valueA, const ValueType &valueB ) From 0e23bcfc8271ce57f08b70aca7790971c8307323 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 19 Feb 2014 10:36:45 +0100 Subject: [PATCH 08/21] GameLogic - Modified some names and cleand up some junk --- Code/Game/GameLogic/CollisionManager.cpp | 4 +- Code/Game/GameLogic/Level.cpp | 36 +++++++++--------- Code/Game/GameLogic/Object.cpp | 47 ++---------------------- Code/Game/GameLogic/Object.h | 46 ++++++++++------------- 4 files changed, 43 insertions(+), 90 deletions(-) diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 0b817975..b740199c 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -46,7 +46,7 @@ using namespace GameLogic; break; case ObjectSpecialType::ObjectSpecialType_CrystalFormation: - PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,realObj->getExtraDamageOnCollision()); + PlayerVLethalObject(*player,*realObj, kineticEnergyLoss,realObj->GetExtraDamageOnCollision()); //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } @@ -181,7 +181,7 @@ using namespace GameLogic; } } - Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) { return Physics::ICustomBody::SubscriptMessage_none; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 030f0eca..10fb213f 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -26,14 +26,14 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Sky: { float skySize = ((SkyAttributes*)obj)->skySize; - //gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + //gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_World: @@ -44,21 +44,21 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_RedExplosiveBox: @@ -75,24 +75,24 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new DynamicObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; case ObjectSpecialType_JumpPad: @@ -122,12 +122,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody) break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID++); } break; } @@ -355,14 +355,14 @@ 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.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); } /*offset += nrOfBoxex; for(int i =0; i< nrOfBoxex; i ++) { 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,5, -605 -( i*5)), 5); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); } @@ -371,7 +371,7 @@ 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(200, 620 + ( i*7), 0), 5); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); } offset += nrOfBoxex; @@ -379,18 +379,18 @@ 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(5, 605 + i*5, 0), 5); - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); }*/ // 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++)); + this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, 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++)); + this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++)); // add jumppad diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 751dc454..1f43263b 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -15,11 +15,11 @@ const Game *Object::gameInstance = (Game*)(&Game::Instance()); Object::Object() { - this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); this->type = ObjectSpecialType_Unknown; this->objectID = -1; + this->scale = Float3(1.0f, 1.0f, 1.0f); } Object::Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID) @@ -48,39 +48,12 @@ Object::~Object(void) } -ObjectSpecialType Object::GetObjectType() const + +void Object::SetOnCollision(OnCollisionCallback func) { - return this->type; -} -int Object::GetID() const -{ - return this->objectID; + this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(func)); } -Oyster::Physics::ICustomBody* Object::GetRigidBody() -{ - return this->rigidBody; -} - - -void Object::BeginFrame() -{ - -} -// update physic -void Object::EndFrame() -{ - -} - -void Object::setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)) -{ - //this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore)); -} -void Object::setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)) -{ - this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter)); -} Oyster::Math::Float3 Object::GetPosition() { @@ -94,21 +67,9 @@ Oyster::Math::Quaternion Object::GetRotation() state = this->rigidBody->GetState(); return state.quaternion; } -Oyster::Math::Float3 Object::GetScale() -{ - Oyster::Physics::ICustomBody::State state; - state = this->rigidBody->GetState(); - return Float3(); -} Oyster::Math::Float4x4 Object::GetOrientation() { Oyster::Physics::ICustomBody::State state; state = this->rigidBody->GetState(); return state.GetOrientation(); } - - -Oyster::Math::Float Object::getExtraDamageOnCollision() -{ - return this->extraDamageOnCollision; -} \ No newline at end of file diff --git a/Code/Game/GameLogic/Object.h b/Code/Game/GameLogic/Object.h index 73853bd8..075236fe 100644 --- a/Code/Game/GameLogic/Object.h +++ b/Code/Game/GameLogic/Object.h @@ -16,47 +16,39 @@ namespace GameLogic class Object :public IObjectData { + public: + typedef Oyster::Physics::ICustomBody::SubscriptMessage (*OnCollisionCallback)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss); + public: Object(); - Object(Oyster::Physics::ICustomBody *rigidBody, void (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); Object(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID); ~Object(void); - ObjectSpecialType GetObjectType() const override; - int GetID() const override; - void setID(int id); - Oyster::Math::Float3 GetPosition() override; - Oyster::Math::Quaternion GetRotation() override; - Oyster::Math::Float3 GetScale() override; - Oyster::Math::Float4x4 GetOrientation() override; + inline ObjectSpecialType GetObjectType() const override { return this->type; } + inline int GetID() const override { return this->objectID; } + inline Oyster::Math::Float3 GetScale() override { return this->scale; } + inline Oyster::Math::Float3 GetPosition() override; + inline Oyster::Math::Quaternion GetRotation() override; + inline Oyster::Math::Float4x4 GetOrientation() override; + inline Oyster::Physics::ICustomBody* GetRigidBody() { return this->rigidBody; } + inline Oyster::Math::Float GetExtraDamageOnCollision() { return this->extraDamageOnCollision; } - Oyster::Math::Float getExtraDamageOnCollision(); + virtual void BeginFrame() { }; + virtual void EndFrame() { }; - // API overrides - - - - Oyster::Physics::ICustomBody* GetRigidBody(); - - virtual void BeginFrame(); - virtual void EndFrame(); - - void setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter)); - void setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss)); - - static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - - - public: //TODO: Hax This should be private when level is dynamic + void SetOnCollision(OnCollisionCallback func); + static Oyster::Physics::ICustomBody::SubscriptMessage DefaultOnCollision(Oyster::Physics::ICustomBody *rigidBodyObject, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); protected: Oyster::Physics::ICustomBody *rigidBody; static const Game* gameInstance; - Oyster::Math::Float3 currLook; - Oyster::Math::Float3 newLook; + + Oyster::Math::Float3 lookDirection; //The look direction for the camera + Oyster::Math::Float3 forwardDirection; //The forward direction of the rigid body + Oyster::Math::Float3 scale; //The scale of both rigid body and the mesh ObjectSpecialType type; int objectID; From 6ef0a7caa676b74a0e661138f3fe8368261563ca Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 10:59:23 +0100 Subject: [PATCH 09/21] Added lights to client --- Code/Game/GameClient/GameClient.vcxproj | 2 + .../GameClient/GameClientState/C_Light.cpp | 37 +++++++++++++++++++ .../Game/GameClient/GameClientState/C_Light.h | 29 +++++++++++++++ .../GameClient/GameClientState/GameState.cpp | 25 ++++++++++++- .../GameClientState/NetLoadState.cpp | 26 ++++++++++++- .../GameClientState/SharedStateContent.h | 2 + .../OysterGraphics.vcxproj.user | 2 +- 7 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/C_Light.cpp create mode 100644 Code/Game/GameClient/GameClientState/C_Light.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 3daafff3..7a962975 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -202,6 +202,7 @@ + @@ -227,6 +228,7 @@ + diff --git a/Code/Game/GameClient/GameClientState/C_Light.cpp b/Code/Game/GameClient/GameClientState/C_Light.cpp new file mode 100644 index 00000000..17016ae5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.cpp @@ -0,0 +1,37 @@ +#include "C_Light.h" +using namespace DanBias::Client; +C_Light::C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ) +{ + this->pointLightDesc = pointLightDesc; + this->id = id; +} +C_Light::~C_Light() +{ + +} +Oyster::Graphics::Definitions::Pointlight C_Light::getLightDesc() const +{ + return this->pointLightDesc; +} +void C_Light::setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ) +{ + this->pointLightDesc = pointLightDesc; +} +Oyster::Math::Float3 C_Light::getPos() const +{ + return this->pointLightDesc.Pos; +} +void C_Light::setPos( Oyster::Math::Float3 newPos) +{ + this->pointLightDesc.Pos = newPos; +} + +int C_Light::GetId() const +{ + return this->id; +} +void C_Light::Render() +{ + // will be changed to new API + Oyster::Graphics::API::AddLight(pointLightDesc); +} diff --git a/Code/Game/GameClient/GameClientState/C_Light.h b/Code/Game/GameClient/GameClientState/C_Light.h new file mode 100644 index 00000000..4802339d --- /dev/null +++ b/Code/Game/GameClient/GameClientState/C_Light.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_CLIGHT_H +#define DANBIAS_CLIENT_CLIGHT_H +#include "DllInterfaces/GFXAPI.h" +namespace DanBias +{ + namespace Client + { + class C_Light + { + private: + Oyster::Graphics::Definitions::Pointlight pointLightDesc; + int id; + + public: + C_Light( Oyster::Graphics::Definitions::Pointlight pointLightDesc, int id ); + virtual ~C_Light(); + + Oyster::Graphics::Definitions::Pointlight getLightDesc() const; + void setLightDesc( Oyster::Graphics::Definitions::Pointlight pointLightDesc ); + + Oyster::Math::Float3 getPos() const; + void setPos( Oyster::Math::Float3 newPos); + void Render(); + int GetId() const; + }; + } +} + +#endif diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 66b8fc61..59a16f6b 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -4,7 +4,7 @@ #include "NetworkClient.h" #include "Camera_FPS.h" #include - +#include "C_Light.h" #include "C_obj/C_Player.h" #include "C_obj/C_DynamicObj.h" #include "C_obj/C_StaticObj.h" @@ -28,6 +28,7 @@ struct GameState::MyData ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool key_forward; bool key_backward; @@ -82,10 +83,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->input = shared.input; this->privData->staticObjects = &shared.staticObjects; this->privData->dynamicObjects = &shared.dynamicObjects; + this->privData->lights = &shared.lights; Graphics::API::Option gfxOp = Graphics::API::GetOption(); Float aspectRatio = gfxOp.Resolution.x / gfxOp.Resolution.y; - this->privData->camera.SetPerspectiveProjection( Math::pi/2, aspectRatio, 0.1f, 1000.0f ); + this->privData->camera.SetPerspectiveProjection( Utility::Value::Radian(90.0f), aspectRatio, 0.1f, 1000.0f ); Graphics::API::SetProjection( this->privData->camera.GetProjectionMatrix() ); //tell server ready @@ -100,6 +102,11 @@ bool GameState::Init( SharedStateContent &shared ) this->privData->renderWhireframe = false; // !DEGUG KEYS + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } return true; } @@ -177,6 +184,13 @@ bool GameState::Render() dynamicObject->second->Render(); } + + /*auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + }*/ + // RB DEBUG render wire frame if(this->privData->renderWhireframe) { @@ -236,8 +250,15 @@ bool GameState::Release() dynamicObject->second = nullptr; } + auto light = this->privData->lights->begin(); + for( ; light != this->privData->lights->end(); ++light ) + { + light->second->Render(); + } + this->privData->staticObjects->clear(); this->privData->dynamicObjects->clear(); + this->privData->lights->clear(); privData = NULL; } diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 2fe143d6..2f8fbe6c 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -6,6 +6,7 @@ #include "Utilities.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -23,6 +24,7 @@ struct NetLoadState::MyData Graphics::API::Texture background; ::std::map> *staticObjects; ::std::map> *dynamicObjects; + ::std::map> *lights; bool loading; }; @@ -49,6 +51,7 @@ bool NetLoadState::Init( SharedStateContent &shared ) this->privData->background = Graphics::API::CreateTexture( L"grass_md.png" ); this->privData->dynamicObjects = &shared.dynamicObjects; this->privData->staticObjects = &shared.staticObjects; + this->privData->lights = &shared.lights; this->privData->loading = false; @@ -214,12 +217,33 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) break; case ObjectType::ObjectType_Light: { - /* TODO: implement light into the leveformat */ + BasicLight *light = (BasicLight*)oth; + Graphics::Definitions::Pointlight pointLight; + + pointLight.Color = light->color; + pointLight.Pos = light->position; + pointLight.Bright = light->intensity; + pointLight.Radius = light->raduis; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; } break; default: break; } } + // DEBUG added a static light for testing + Graphics::Definitions::Pointlight pointLight; + pointLight.Color = Float3(1,1,0); + pointLight.Pos = Float3( 0,132, 10); + pointLight.Bright = 2; + pointLight.Radius = 50; + + C_Light *newLight = new C_Light( pointLight, objectID ); + + (*this->privData->lights)[objectID] = newLight; + this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameClient/GameClientState/SharedStateContent.h b/Code/Game/GameClient/GameClientState/SharedStateContent.h index da9dc759..49d01775 100644 --- a/Code/Game/GameClient/GameClientState/SharedStateContent.h +++ b/Code/Game/GameClient/GameClientState/SharedStateContent.h @@ -13,6 +13,7 @@ #include "C_Object.h" #include "C_obj\C_StaticObj.h" #include "C_obj\C_DynamicObj.h" +#include "C_Light.h" #include "NetworkClient.h" #include "L_inputClass.h" @@ -23,6 +24,7 @@ namespace DanBias { namespace Client public: ::std::map> staticObjects; ::std::map> dynamicObjects; + ::std::map> lights; ::Oyster::Network::NetworkClient *network; InputClass* input; }; diff --git a/Code/OysterGraphics/OysterGraphics.vcxproj.user b/Code/OysterGraphics/OysterGraphics.vcxproj.user index 3f030911..9a0b0ae0 100644 --- a/Code/OysterGraphics/OysterGraphics.vcxproj.user +++ b/Code/OysterGraphics/OysterGraphics.vcxproj.user @@ -1,6 +1,6 @@  - false + true \ No newline at end of file From 0a664bd0dd675b599b8a6e4ee9a9597fe71bd067 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 19 Feb 2014 11:02:44 +0100 Subject: [PATCH 10/21] GameServer - Added dynamic player alias and model names --- Code/Game/GameServer/Implementation/GameClient.cpp | 4 ++-- .../GameServer/Implementation/GameSession_General.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 81066450..9c04007f 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -17,7 +17,7 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerclient = nwClient; this->player = 0; isReady = false; - this->character = L"Unknown"; + this->character = L"crate_colonists.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; } @@ -25,7 +25,7 @@ GameClient::~GameClient() { this->player = 0; this->isReady = false; - this->character = L"Unknown"; + this->character = L"crate_colonists.dan"; this->alias = L"Unknown"; this->secondsSinceLastResponse = 0.0f; } diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index 933807a4..30eabed2 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -165,7 +165,8 @@ void GameSession::ThreadEntry( ) IPlayerData* pl = this->gClients[k]->GetPlayer(); Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(), - /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + Utility::String::WStringToString(this->gClients[k]->GetAlias(), std::string()), + Utility::String::WStringToString(this->gClients[k]->GetCharacter(), std::string())); readyList[i]->GetClient()->Send(p); } } @@ -204,7 +205,8 @@ bool GameSession::Join(gClient gameClient) { Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(), playerData->GetID(), true, playerData->GetTeamID(), - /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); + Utility::String::WStringToString(gameClient->GetAlias(), std::string()), + Utility::String::WStringToString(gameClient->GetCharacter(), std::string())); nwClient->Send(oc); } @@ -217,7 +219,8 @@ bool GameSession::Join(gClient gameClient) IPlayerData* temp = this->gClients[i]->GetPlayer(); Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), temp->GetID(), false, temp->GetTeamID(), - /*nwClient->GetAlias()*/"Unknown", /*playerData->GetMesh()*/"char_white.dan"); + Utility::String::WStringToString(this->gClients[i]->GetAlias(), std::string()), + Utility::String::WStringToString(this->gClients[i]->GetCharacter(), std::string())); nwClient->Send(oc); } } From 932ef429c2e8e0e541a192c52e8bb899c7daf2bf Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 12:09:42 +0100 Subject: [PATCH 11/21] GameClient - removed hardcoding for lvl, use 2ofAll map for correct world. Init player gets wrong scale and isMyPlayer. Need to verify camera on client --- .../GameClient/GameClientState/GameState.cpp | 6 +--- .../GameClientState/NetLoadState.cpp | 19 ------------- Code/Game/GameLogic/Game_PlayerData.cpp | 2 +- Code/Game/GameLogic/Level.cpp | 28 +------------------ 4 files changed, 3 insertions(+), 52 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 5d756cf4..41518db6 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -93,9 +93,6 @@ bool GameState::Init( SharedStateContent &shared ) //tell server ready this->privData->nwClient->Send( Protocol_General_Status(Protocol_General_Status::States_ready) ); - // Debugg hack - this->InitiatePlayer( 0, "crate_generic.dan",Float3( 0,132, 10), Quaternion::identity, Float3(1), true ); - // end debug hack // DEGUG KEYS this->privData->key_Reload_Shaders = false; this->privData->key_Wireframe_Toggle = false; @@ -127,7 +124,6 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBData.rotation = ArrayToQuaternion( rotation ); RBData.scale = Float3( 1 ); // !RB DEBUG - if( isMyPlayer ) { if( this->privData->player.Init(modelData) ) @@ -483,7 +479,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState // if is this player. Remember to change camera if( this->privData->myId == decoded.object_ID ) { - this->privData->camera.SetPosition( position ); + //this->privData->camera.SetPosition( position ); //this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); //this->privData->player.setRot( rotation ); diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 1c4fbf65..b2475cc6 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -144,14 +144,6 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) desc.scale = oh->scale; desc.visible = true; - // HACK: untill the world is right in lvl format - if( oh->specialTypeID == ObjectSpecialType_World) - { - desc.position = Float3(0,0,0); - desc.rotation = Quaternion::identity; - desc.scale = Float3(300,300,300); - } - C_StaticObj *staticObject = new C_StaticObj(); if( staticObject->Init( desc ) ) { @@ -248,16 +240,5 @@ void NetLoadState::LoadGame( const ::std::string &fileName ) } } - // DEBUG added a static light for testing - Graphics::Definitions::Pointlight pointLight; - pointLight.Color = Float3(1,1,0); - pointLight.Pos = Float3( 0,132, 10); - pointLight.Bright = 2; - pointLight.Radius = 50; - - C_Light *newLight = new C_Light( pointLight, objectID ); - - (*this->privData->lights)[objectID] = newLight; - this->privData->nextState = ClientState::ClientState_Game; } diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index ca0746e8..9ff82b2b 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -24,7 +24,7 @@ Game::PlayerData::PlayerData() } Game::PlayerData::PlayerData(int playerID,int teamID) { - Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(50,130,0); + Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(-50,180,0); Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,2.0f,0.5f); Oyster::Math::Float mass = 60; diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index a3a1c07f..b3a8b101 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -242,34 +242,8 @@ bool Level::InitiateLevel(std::wstring levelPath) ICustomBody* rigidBody_Static = NULL; - // HACK: untill the world is right in lvl format - if((ObjectSpecialType)staticObjData->specialTypeID == ObjectSpecialType_World) - { - Oyster::Math::Float3 rigidWorldPos; - Oyster::Math::Float4 rigidWorldRotation; - float rigidBodyMass; - float rigidBodyRadius; - - //offset the rigidPosition from modelspace to worldspace; - rigidWorldPos = Oyster::Math::Float3(0,0,0); - //scales the position so the collision geomentry is in the right place - - //offset the rigidRotation from modelspace to worldspace; - - rigidWorldRotation = Oyster::Math::Float4(0,0,0,1); - - //mass scaled - rigidBodyMass = 0; - - //Radius scaled - rigidBodyRadius = 150; - - //create the rigid body - rigidBody_Static = API::Instance().AddCollisionSphere( rigidBodyRadius , rigidWorldRotation , rigidWorldPos , rigidBodyMass, 1,1,1); - - } // collision shape - else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) + if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Sphere) { rigidBody_Static = InitRigidBodySphere(staticObjData); } From 8a3cd796caaffdf441aa16caf2fa1c0ab9baf3f3 Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 19 Feb 2014 12:46:05 +0100 Subject: [PATCH 12/21] GameServer - Pontus found idiot bug that dennis made --- Code/Game/GameLogic/Game.cpp | 1 + Code/Game/GameLogic/Player.cpp | 1 - Code/Game/GameProtocols/ObjectProtocols.h | 23 ++++++++++--------- .../Implementation/GameSession_Gameplay.cpp | 4 ++-- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index 8b77dea4..aee57be8 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -123,6 +123,7 @@ bool Game::NewFrame() for (unsigned int i = 0; i < this->players.Size(); i++) { + this->onMoveFnc(this->players[i]); if(this->players[i] && this->players[i]->player) this->players[i]->player->EndFrame(); } diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 80969b29..c87f7d74 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -160,7 +160,6 @@ void Player::EndFrame() this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - Object::EndFrame(); } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index ff6aa6e5..fc02a4bd 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -561,11 +561,11 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; //PLAYER_ID - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; //OWNER - this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Int; //PLAYER-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; //MESH-NAME @@ -585,9 +585,10 @@ namespace GameLogic } Protocol_ObjectCreatePlayer(Oyster::Network::CustomNetProtocol& p) { - this->object_ID = p[1].value.netInt; - this->teamId = this->protocol[2].value.netInt; - this->owner = this->protocol[3].value.netBool; + this->owner = p[1].value.netBool; + this->object_ID = p[2].value.netInt; + this->teamId = p[3].value.netInt; + this->name.assign(p[4].value.netCharPtr); this->meshName.assign(p[5].value.netCharPtr); @@ -610,11 +611,11 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; //PLAYER_ID - this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; //TEAM_ID this->protocol[2].type = Oyster::Network::NetAttributeType_Int; //OWNER - this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Int; //PLAYER-NAME this->protocol[4].type = Oyster::Network::NetAttributeType_CharArray; //MESH-NAME @@ -644,10 +645,10 @@ namespace GameLogic } Oyster::Network::CustomNetProtocol GetProtocol() override { - - this->protocol[1].value = this->object_ID; - this->protocol[2].value = this->teamId; - this->protocol[3].value = this->owner; + this->protocol[1].value = this->owner; + this->protocol[2].value = this->object_ID; + this->protocol[3].value = this->teamId; + this->protocol.Set(4, this->name); this->protocol.Set(5, this->meshName); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 6a9c09c2..4044cfdb 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -66,10 +66,10 @@ using namespace DanBias; break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToSend: printf("\t(%i : %s) - EventType_ProtocolFailedToSend\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); - this->Detach(e.sender); + //this->Detach(e.sender); break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: - printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); + //printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); this->ParseProtocol(e.args.data.protocol, cl); break; } From 8816efafc83b234b9139756eb9690fbde58dc600 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 13:15:19 +0100 Subject: [PATCH 13/21] GameState pre-work for subStates --- Code/Game/GameClient/GameClient.vcxproj | 6 + Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClientState/GameClientState.h | 2 +- .../GameClientState/GameStateUI.cpp | 17 ++ .../GameClient/GameClientState/GameStateUI.h | 58 +++++++ .../GameClient/GameClientState/GamingUI.cpp | 153 ++++++++++++++++++ .../GameClient/GameClientState/GamingUI.h | 33 ++++ .../GameClient/GameClientState/RespawnUI.cpp | 58 +++++++ .../GameClient/GameClientState/RespawnUI.h | 29 ++++ Code/Misc/Input/L_inputClass.h | 1 + 10 files changed, 357 insertions(+), 2 deletions(-) create mode 100644 Code/Game/GameClient/GameClientState/GameStateUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/GameStateUI.h create mode 100644 Code/Game/GameClient/GameClientState/GamingUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/GamingUI.h create mode 100644 Code/Game/GameClient/GameClientState/RespawnUI.cpp create mode 100644 Code/Game/GameClient/GameClientState/RespawnUI.h diff --git a/Code/Game/GameClient/GameClient.vcxproj b/Code/Game/GameClient/GameClient.vcxproj index 349a88ec..082a9344 100644 --- a/Code/Game/GameClient/GameClient.vcxproj +++ b/Code/Game/GameClient/GameClient.vcxproj @@ -211,6 +211,8 @@ + + @@ -221,6 +223,7 @@ + @@ -237,6 +240,8 @@ + + @@ -246,6 +251,7 @@ + diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 2e28d6f7..4b847ee6 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - true + false $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/GameClientState.h b/Code/Game/GameClient/GameClientState/GameClientState.h index 9891a16c..d336e196 100644 --- a/Code/Game/GameClient/GameClientState/GameClientState.h +++ b/Code/Game/GameClient/GameClientState/GameClientState.h @@ -35,7 +35,7 @@ namespace DanBias { namespace Client /****************************************************************** * @param message of the event - * @return message or GameClientState::event_processed. + * @return message or a reference to GameClientState::event_processed. ******************************************************************/ virtual const NetEvent & DataRecieved( const NetEvent &message ); }; diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.cpp b/Code/Game/GameClient/GameClientState/GameStateUI.cpp new file mode 100644 index 00000000..6b8b7ed5 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GameStateUI.cpp @@ -0,0 +1,17 @@ +#include "GameStateUI.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; + +GameStateUI::GameStateUI() +{ + this->nextState = GameStateUI::UIState_same; +} + +GameStateUI::~GameStateUI() { /* Do nothing */ } + +const GameStateUI::NetEvent & GameStateUI::DataRecieved( const GameStateUI::NetEvent &message ) +{ + /* Do nothing */ + return message; +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GameStateUI.h b/Code/Game/GameClient/GameClientState/GameStateUI.h new file mode 100644 index 00000000..40350211 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GameStateUI.h @@ -0,0 +1,58 @@ +#ifndef DANBIAS_CLIENT_GAMECLIENTSTATE_H +#define DANBIAS_CLIENT_GAMECLIENTSTATE_H + +#include "Utilities.h" +#include "NetworkClient.h" + +namespace DanBias { namespace Client +{ + class GameStateUI + { + public: + enum UIState + { + UIState_same, + UIState_gaming, + + + UIState_main_menu, + UIState_shut_down + }; + + typedef ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> NetEvent; + static const NetEvent event_processed; + + GameStateUI(); + virtual ~GameStateUI(); + virtual UIState Update( float deltaTime ) = 0; + virtual bool HaveGUIRender() const = 0; + virtual bool HaveTextRender() const = 0; + virtual void RenderGUI() const = 0; + virtual void RenderText() const = 0; + virtual bool Release() = 0; + + /****************************************************************** + * @param message of the event + * @return message or a reference to GameStateUI::event_processed. + ******************************************************************/ + virtual const NetEvent & DataRecieved( const NetEvent &message ); + + protected: + UIState nextState; + }; +} } + +namespace Utility { namespace DynamicMemory +{ // template specializationto allowuse of dynamicmemory tools + template<> + inline void SafeDeleteInstance( ::DanBias::Client::GameStateUI *dynamicInstance ) + { + if( dynamicInstance ) + { + dynamicInstance->Release(); + delete dynamicInstance; + } + } +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp new file mode 100644 index 00000000..a2edc28f --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -0,0 +1,153 @@ +#include "GamingUI.h" +#include + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; +using namespace ::GameLogic; + +GamingUI::GamingUI() : + GameStateUI() +{ + /* Should never be called! */ + this->input = nullptr; + this->netClient = nullptr; + this->camera = nullptr; +} + +GamingUI::GamingUI( InputClass *input, NetworkClient *connection, Camera_FPSV2 *camera ) : + GameStateUI() +{ + this->input = input; + this->netClient = connection; + this->camera = camera; +} + +GamingUI::~GamingUI() { /* Do nothing */ } + +GameStateUI::UIState GamingUI::Update( float deltaTime ) +{ + return this->nextState; +} + +bool GamingUI::HaveGUIRender() const +{ + return false; // TODO: change to true when we want UI elements like a crosshair +} + +bool GamingUI::HaveTextRender() const +{ + return false; // TODO: change to true when we want UI elements like a chat window +} + +void GamingUI::RenderGUI() const +{ + // TODO: Render crosshairs and such here. Don't forget to adjust GamingUI::HaveGUIRender +} + +void GamingUI::RenderText() const +{ + // TODO: Render chattext and such here. Don't forget to adjust GamingUI::HaveGUIRender +} + +bool GamingUI::Release() +{ + // TODO: Release UI components here. + return true; +} + +void GamingUI::ReadKeyInput() +{ + if( this->input->IsKeyPressed(DIK_W) ) + { + this->netClient->Send( Protocol_PlayerMovementForward() ); + } + + if( this->input->IsKeyPressed(DIK_S) ) + { + this->netClient->Send( Protocol_PlayerMovementBackward() ); + } + + if( this->input->IsKeyPressed(DIK_A) ) + { + this->netClient->Send( Protocol_PlayerMovementLeft() ); + } + + if( this->input->IsKeyPressed(DIK_D) ) + { + this->netClient->Send( Protocol_PlayerMovementRight() ); + } + +// if( this->input->IsKeyPressed(DIK_R) ) +// { +// if( !this->key_Reload_Shaders ) +// { +//#ifdef _DEBUG +// Graphics::API::ReloadShaders(); +//#endif +// this->key_Reload_Shaders = true; +// } +// } +// else +// this->key_Reload_Shaders = false; + + //send delta mouse movement + { + this->camera->YawRight( this->input->GetYaw() * 0.017f ); + this->camera->PitchDown( this->input->GetPitch() * 0.017f ); + this->camera->UpdateOrientation(); + + this->netClient->Send( Protocol_PlayerLook(this->camera->GetLook(), this->camera->GetRight()) ); + } + + // shoot + //if( this->input->IsKeyPressed(DIK_Z) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = true; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = false; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + //if( this->input->IsKeyPressed(DIK_X) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = true; + // playerShot.utilityPressed = false; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + //if( this->input->IsKeyPressed(DIK_C) ) + //{ + // if( !this->key_Shoot ) + // { + // Protocol_PlayerShot playerShot; + // playerShot.primaryPressed = false; + // playerShot.secondaryPressed = false; + // playerShot.utilityPressed = true; + // this->netClient->Send( playerShot ); + // this->key_Shoot = true; + // } + //} + //else + // this->key_Shoot = false; + + // jump + if( this->input->IsKeyPressed(DIK_SPACE) ) + { + this->netClient->Send( Protocol_PlayerJump() ); + } +} \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/GamingUI.h b/Code/Game/GameClient/GameClientState/GamingUI.h new file mode 100644 index 00000000..9f93674b --- /dev/null +++ b/Code/Game/GameClient/GameClientState/GamingUI.h @@ -0,0 +1,33 @@ +#ifndef DANBIAS_CLIENT_GAMING_UI_H +#define DANBIAS_CLIENT_GAMING_UI_H + +#include "GameStateUI.h" +#include "L_inputClass.h" +#include "Camera_FPSV2.h" + +namespace DanBias { namespace Client +{ + class GamingUI : public GameStateUI + { + public: + GamingUI( InputClass *input, ::Oyster::Network::NetworkClient *connection, Camera_FPSV2 *camera ); + virtual ~GamingUI(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + + private: + InputClass *input; + ::Oyster::Network::NetworkClient *netClient; + Camera_FPSV2 *camera; + + GamingUI(); + void ReadKeyInput(); + }; +} } + +#endif \ No newline at end of file diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.cpp b/Code/Game/GameClient/GameClientState/RespawnUI.cpp new file mode 100644 index 00000000..4588d367 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/RespawnUI.cpp @@ -0,0 +1,58 @@ +#include "RespawnUI.h" + +using namespace ::DanBias::Client; +using namespace ::Oyster::Network; +using namespace ::Utility::Value; + +RespawnUI::RespawnUI() : + GameStateUI() +{ + /* Should never be called! */ + this->netClient = nullptr; + this->countDown = 0.0f; +} + +RespawnUI::RespawnUI( NetworkClient *connection, float delay ) : + GameStateUI() +{ + this->netClient = connection; + this->countDown = delay; +} + +RespawnUI::~RespawnUI() { /* Do nothing */ } + +GameStateUI::UIState RespawnUI::Update( float deltaTime ) +{ + this->countDown = Max( this->countDown - deltaTime, 0.0f ); + return this->nextState; +} + +bool RespawnUI::HaveGUIRender() const +{ + return false; // TODO: change to true when we want UI elements like a crosshair +} + +bool RespawnUI::HaveTextRender() const +{ + return false; // TODO: change to true when we want UI elements like a chat window +} + +void RespawnUI::RenderGUI() const +{ + // TODO: We need? +} + +void RespawnUI::RenderText() const +{ + // TODO: Text countdown somewhere on screen would be nice +} + +bool RespawnUI::Release() +{ + // TODO: Release UI components here. + return true; +} + + + + diff --git a/Code/Game/GameClient/GameClientState/RespawnUI.h b/Code/Game/GameClient/GameClientState/RespawnUI.h new file mode 100644 index 00000000..c45616b7 --- /dev/null +++ b/Code/Game/GameClient/GameClientState/RespawnUI.h @@ -0,0 +1,29 @@ +#ifndef DANBIAS_CLIENT_RESPAWN_UI_H +#define DANBIAS_CLIENT_RESPAWN_UI_H + +#include "GameStateUI.h" + +namespace DanBias { namespace Client +{ + class RespawnUI : public GameStateUI + { + public: + RespawnUI( ::Oyster::Network::NetworkClient *connection, float delay ); + virtual ~RespawnUI(); + + UIState Update( float deltaTime ); + bool HaveGUIRender() const; + bool HaveTextRender() const; + void RenderGUI() const; + void RenderText() const; + bool Release(); + + private: + ::Oyster::Network::NetworkClient *netClient; + float countDown; + + RespawnUI(); + }; +} } + +#endif \ No newline at end of file diff --git a/Code/Misc/Input/L_inputClass.h b/Code/Misc/Input/L_inputClass.h index 8ed8e528..5511102a 100644 --- a/Code/Misc/Input/L_inputClass.h +++ b/Code/Misc/Input/L_inputClass.h @@ -7,6 +7,7 @@ #ifndef _INPUTCLASS_H_ #define _INPUTCLASS_H_ +#define NOMINMAX #define DIRECTINPUT_VERSION 0x0800 #pragma comment(lib, "dinput8.lib") From 3fe02213423f4e5625b7d0c26fdebb9e315fb430 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 13:41:05 +0100 Subject: [PATCH 14/21] GameClient - fixed render RB --- .../GameClient/GameClientState/GameState.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 41518db6..7ab0aeac 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -122,7 +122,7 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa RBInitData RBData; RBData.position = position; RBData.rotation = ArrayToQuaternion( rotation ); - RBData.scale = Float3( 1 ); + RBData.scale = scale; // !RB DEBUG if( isMyPlayer ) { @@ -216,13 +216,16 @@ bool GameState::Render() dynamicObject = this->privData->dynamicObjects->begin(); for( ; dynamicObject != this->privData->dynamicObjects->end(); ++dynamicObject ) { - if( dynamicObject->second->getBRtype() == RB_Type_Cube) + if( dynamicObject->second ) { - Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); - } - if( dynamicObject->second->getBRtype() == RB_Type_Sphere) - { - Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + if( dynamicObject->second->getBRtype() == RB_Type_Cube) + { + Oyster::Graphics::API::RenderDebugCube( dynamicObject->second->getRBWorld()); + } + if( dynamicObject->second->getBRtype() == RB_Type_Sphere) + { + Oyster::Graphics::API::RenderDebugSphere( dynamicObject->second->getRBWorld()); + } } } } @@ -479,8 +482,8 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState // if is this player. Remember to change camera if( this->privData->myId == decoded.object_ID ) { - //this->privData->camera.SetPosition( position ); - //this->privData->camera.SetRotation( rotation ); + this->privData->camera.SetPosition( position ); + this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); //this->privData->player.setRot( rotation ); } From 7ece3b62a0f84afd36d383e46a5e4ffabe4b1cff Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 13:42:43 +0100 Subject: [PATCH 15/21] Changed Player_Look protocol to Player_LeftTurn --- Code/Game/GameProtocols/PlayerProtocols.h | 73 ++++++------------- .../GameProtocols/ProtocolIdentificationID.h | 2 +- Code/Game/GameServer/GameSession.h | 2 +- .../Implementation/GameSession_Gameplay.cpp | 9 +-- 4 files changed, 27 insertions(+), 59 deletions(-) diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index b7d79d6c..57137fb4 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -74,69 +74,40 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; - struct Protocol_PlayerLook :public Oyster::Network::CustomProtocolObject + //protocol_Gameplay_PlayerLeftTurn + struct Protocol_PlayerLeftTurn : public ::Oyster::Network::CustomProtocolObject { - // can be swapped to a quaternion later - float lookDir[3]; - float right[3]; - - Protocol_PlayerLook() + public: + float deltaRadian; + + Protocol_PlayerLeftTurn() { - this->protocol[0].value = protocol_Gameplay_PlayerLookDir; - this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - // LookDir - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - // Right - this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - this->protocol[6].type = Oyster::Network::NetAttributeType_Float; - - memset(&this->lookDir[0], 0, sizeof(float) * 3); - memset(&this->right[0], 0, sizeof(float) * 3); + this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn; + this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short; + // deltaRadian + this->protocol[1].type = ::Oyster::Network::NetAttributeType_Float; } - Protocol_PlayerLook(Oyster::Network::CustomNetProtocol& p) - { - this->lookDir[0] = p[1].value.netFloat; - this->lookDir[1] = p[2].value.netFloat; - this->lookDir[2] = p[3].value.netFloat; - this->right[0] = p[4].value.netFloat; - this->right[1] = p[5].value.netFloat; - this->right[2] = p[6].value.netFloat; + Protocol_PlayerLeftTurn( const ::Oyster::Network::CustomNetProtocol &p ) + { + this->deltaRadian = p[1].value.netFloat; } - Protocol_PlayerLook(float l[3], float r[3]) + + Protocol_PlayerLeftTurn( float deltaRadian ) { - this->protocol[0].value = protocol_Gameplay_PlayerLookDir; - this->protocol[0].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[1].type = Oyster::Network::NetAttributeType_Float; - this->protocol[2].type = Oyster::Network::NetAttributeType_Float; - this->protocol[3].type = Oyster::Network::NetAttributeType_Float; - - this->protocol[4].type = Oyster::Network::NetAttributeType_Float; - this->protocol[5].type = Oyster::Network::NetAttributeType_Float; - this->protocol[6].type = Oyster::Network::NetAttributeType_Float; - - memcpy(&this->lookDir[0], &l[0], sizeof(float) * 3); - memcpy(&this->right[0], &r[0], sizeof(float) * 3); + this->protocol[0].value = protocol_Gameplay_PlayerLeftTurn; + this->protocol[0].type = ::Oyster::Network::NetAttributeType_Short; + this->deltaRadian = deltaRadian; } - Oyster::Network::CustomNetProtocol GetProtocol() override + ::Oyster::Network::CustomNetProtocol GetProtocol() override { - this->protocol[1].value = this->lookDir[0]; - this->protocol[2].value = this->lookDir[1]; - this->protocol[3].value = this->lookDir[2]; - this->protocol[4].value = this->right[0]; - this->protocol[5].value = this->right[1]; - this->protocol[6].value = this->right[2]; - + this->protocol[1].value = this->deltaRadian; return protocol; } - private: - Oyster::Network::CustomNetProtocol protocol; + private: + ::Oyster::Network::CustomNetProtocol protocol; }; struct Protocol_PlayerChangeWeapon :public Oyster::Network::CustomProtocolObject diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 25df7b78..4394a1a1 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -47,7 +47,7 @@ #define protocol_Gameplay_PlayerMovementLeft 301 #define protocol_Gameplay_PlayerMovementForward 302 #define protocol_Gameplay_PlayerMovementBackward 303 -#define protocol_Gameplay_PlayerLookDir 304 +#define protocol_Gameplay_PlayerLeftTurn 304 #define protocol_Gameplay_PlayerChangeWeapon 305 #define protocol_Gameplay_PlayerShot 306 #define protocol_Gameplay_PlayerJump 307 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 28e8bde3..ad9440e9 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -84,7 +84,7 @@ namespace DanBias void Gameplay_PlayerMovementBack ( DanBias::GameClient* c ); void Gameplay_PlayerMovementForth ( DanBias::GameClient* c ); void Gameplay_PlayerJump ( DanBias::GameClient* c ); - void Gameplay_PlayerLookDir ( GameLogic::Protocol_PlayerLook& p, DanBias::GameClient* c ); + void Gameplay_PlayerLeftTurn ( GameLogic::Protocol_PlayerLeftTurn& p, DanBias::GameClient* c ); void Gameplay_PlayerChangeWeapon ( GameLogic::Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ); void Gameplay_PlayerShot ( GameLogic::Protocol_PlayerShot& p, DanBias::GameClient* c ); void Gameplay_ObjectPickup ( GameLogic::Protocol_ObjectPickup& p, DanBias::GameClient* c ); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index 4044cfdb..8cbb542d 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -156,7 +156,7 @@ using namespace DanBias; break; case protocol_Gameplay_PlayerJump: this->Gameplay_PlayerJump ( c ); break; - case protocol_Gameplay_PlayerLookDir: this->Gameplay_PlayerLookDir ( Protocol_PlayerLook (p), c ); + case protocol_Gameplay_PlayerLeftTurn: this->Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn (p), c ); break; case protocol_Gameplay_PlayerChangeWeapon: this->Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon (p), c ); break; @@ -203,12 +203,9 @@ using namespace DanBias; { c->GetPlayer()->Move(GameLogic::PLAYER_MOVEMENT_JUMP); } - void GameSession::Gameplay_PlayerLookDir ( Protocol_PlayerLook& p, DanBias::GameClient* c ) + void GameSession::Gameplay_PlayerLeftTurn ( Protocol_PlayerLeftTurn& p, DanBias::GameClient* c ) { - Oyster::Math3D::Float3 lookDir = p.lookDir; - Oyster::Math3D::Float3 right = p.right; - - c->GetPlayer()->Rotate(lookDir, right); + c->GetPlayer()->TurnLeft( p.deltaRadian ); } void GameSession::Gameplay_PlayerChangeWeapon ( Protocol_PlayerChangeWeapon& p, DanBias::GameClient* c ) { From f0c581ca04c564745db3232066ac461a93eeb98e Mon Sep 17 00:00:00 2001 From: dean11 Date: Wed, 19 Feb 2014 13:47:49 +0100 Subject: [PATCH 16/21] GameLogic - Added functions for relative rotation --- Code/Game/GameLogic/Game.h | 23 ++++++++++++----------- Code/Game/GameLogic/GameAPI.h | 7 ++++++- Code/Game/GameLogic/Game_PlayerData.cpp | 6 +++++- Code/Game/GameLogic/Player.cpp | 7 ++++++- Code/Game/GameLogic/Player.h | 4 +++- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 6623756f..5ab19ba2 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -31,17 +31,18 @@ namespace GameLogic PlayerData(int playerID,int teamID); ~PlayerData(); - void Move(const PLAYER_MOVEMENT &movement) override; - void UseWeapon(const WEAPON_FIRE &usage) override; - int GetTeamID() const override; - PLAYER_STATE GetState() const override; - Oyster::Math::Float3 GetPosition() override; - Oyster::Math::Quaternion GetRotation() override; - Oyster::Math::Float3 GetScale() override; - Oyster::Math::Float4x4 GetOrientation() override; - int GetID() const override; - void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) override; - ObjectSpecialType GetObjectType() const override; + void Move(const PLAYER_MOVEMENT &movement) override; + void UseWeapon(const WEAPON_FIRE &usage) override; + int GetTeamID() const override; + PLAYER_STATE GetState() const override; + Oyster::Math::Float3 GetPosition() override; + Oyster::Math::Quaternion GetRotation() override; + Oyster::Math::Float3 GetScale() override; + Oyster::Math::Float4x4 GetOrientation() override; + int GetID() const override; + void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) override; + void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) override; + ObjectSpecialType GetObjectType() const override; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 65d606d8..b4ef9fa6 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -85,7 +85,12 @@ namespace GameLogic * @param x: The relative x axis * @param y: The relative y axis **/ - virtual void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) = 0; + virtual void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) = 0; + + /** Relative rotation around given axis + * @param leftRadians: The relative amount of radians to turn + **/ + virtual void TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) = 0; /******************************************************** * Uses the chosen players weapon based on input diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 3858d370..c669cbc7 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -85,7 +85,11 @@ ObjectSpecialType Game::PlayerData::GetObjectType() const { return this->player->GetObjectType(); } -void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) +void Game::PlayerData::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) { this->player->Rotate(lookDir, right); +} +void Game::PlayerData::TurnLeft(Oyster::Math3D::Float deltaLeftRadians ) +{ + this->player->TurnLeft(deltaLeftRadians); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 80969b29..a531461c 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -220,7 +220,7 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint) this->rigidBody->SetPosition(spawnPoint); } -void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right) +void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right) { // this is the camera right vector this->lookDir = lookDir; @@ -228,6 +228,11 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D:: //Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1]; //this->rigidBody->SetUpAndRight(up, right); } +void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) +{ + //TODO: Conver delta radians to something that phyhsics use... + //this->rigidBody->; +} void Player::Jump() { diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index f2707cb3..73737d60 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -46,7 +46,9 @@ namespace GameLogic void Respawn(Oyster::Math::Float3 spawnPoint); - void Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::Float3 right); + void Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D::Float3& right); + + void TurnLeft(Oyster::Math3D::Float deltaRadians); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody From b25a08ff901bba661546adf0d3888a051f3cb774 Mon Sep 17 00:00:00 2001 From: lindaandersson Date: Wed, 19 Feb 2014 13:57:00 +0100 Subject: [PATCH 17/21] Fix in lvl loader - can now load shere RB --- Code/Game/LevelLoader/ParseFunctions.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Code/Game/LevelLoader/ParseFunctions.cpp b/Code/Game/LevelLoader/ParseFunctions.cpp index b6b57d83..09adb298 100644 --- a/Code/Game/LevelLoader/ParseFunctions.cpp +++ b/Code/Game/LevelLoader/ParseFunctions.cpp @@ -152,10 +152,9 @@ namespace GameLogic start = 0; LevelLoaderInternal::FormatVersion version; memcpy(&version, &buf[0], sizeof(version)); - start += 4; + start += 8; memcpy(&volume.geoType, &buf[start], sizeof(volume.geoType)); - start += sizeof(volume.geoType); switch(volume.geoType) { From 3520062577bd0a2b476bd729cfffaf523c9ffb4c Mon Sep 17 00:00:00 2001 From: Robin Engman Date: Wed, 19 Feb 2014 13:59:59 +0100 Subject: [PATCH 18/21] Implemented TurnLeft function --- Code/Game/GameLogic/Player.cpp | 8 ++++++-- Code/Game/GameLogic/Player.h | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 00d098fa..b067d036 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -33,6 +33,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 100; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } 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) @@ -53,6 +55,8 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom this->moveDir = Oyster::Math::Float3(0,0,0); this->moveSpeed = 20; this->previousMoveSpeed = Oyster::Math::Float3(0,0,0); + + this->rotationUp = 0; } Player::~Player(void) @@ -229,8 +233,8 @@ void Player::Rotate(const Oyster::Math3D::Float3& lookDir, const Oyster::Math3D: } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - //TODO: Conver delta radians to something that phyhsics use... - //this->rigidBody->; + this->rotationUp += deltaRadians; + this->rigidBody->SetRotationAsAngularAxis(Oyster::Math3D::Float4(this->rigidBody->GetState().centerPos.GetNormalized(), this->rotationUp)); } void Player::Jump() diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index 73737d60..13c6e300 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -96,6 +96,8 @@ namespace GameLogic Oyster::Math::Float moveSpeed; Oyster::Math::Float3 previousMoveSpeed; + Oyster::Math::Float rotationUp; + bool hasTakenDamage; float invincibleCooldown; From cd4e5ae0ec8c7ee97679eca8c57604f39d95ec5b Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:00:36 +0100 Subject: [PATCH 19/21] compilation error fixes --- Code/Game/GameClient/GameClientState/GameState.cpp | 8 +++----- Code/Game/GameClient/GameClientState/GamingUI.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 7ab0aeac..af5f467e 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -319,11 +319,9 @@ void GameState::ReadKeyInput() //send delta mouse movement { - this->privData->camera.YawRight( this->privData->input->GetYaw() * 0.017f ); - this->privData->camera.PitchDown( this->privData->input->GetPitch() * 0.017f ); - this->privData->camera.UpdateOrientation(); - - privData->nwClient->Send( Protocol_PlayerLook(this->privData->camera.GetLook(), this->privData->camera.GetRight()) ); + static const float mouseSensitivity = Radian( 1.0f ); + this->privData->camera.PitchDown( this->privData->input->GetPitch() * mouseSensitivity ); + this->privData->nwClient->Send( Protocol_PlayerLeftTurn(this->privData->input->GetYaw() * mouseSensitivity) ); } // shoot diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index a2edc28f..8ff43d88 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -1,9 +1,11 @@ #include "GamingUI.h" #include +#include "Utilities.h" using namespace ::DanBias::Client; using namespace ::Oyster::Network; using namespace ::GameLogic; +using namespace ::Utility::Value; GamingUI::GamingUI() : GameStateUI() @@ -92,11 +94,9 @@ void GamingUI::ReadKeyInput() //send delta mouse movement { - this->camera->YawRight( this->input->GetYaw() * 0.017f ); - this->camera->PitchDown( this->input->GetPitch() * 0.017f ); - this->camera->UpdateOrientation(); - - this->netClient->Send( Protocol_PlayerLook(this->camera->GetLook(), this->camera->GetRight()) ); + static const float mouseSensitivity = Radian( 1.0f ); + this->camera->PitchDown( this->input->GetPitch() * mouseSensitivity ); + this->netClient->Send( Protocol_PlayerLeftTurn(this->input->GetYaw() * mouseSensitivity) ); } // shoot From 8917caf08af4b8078998c9b0ffa9a78b5074880c Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:20:46 +0100 Subject: [PATCH 20/21] removed debug comment --- Code/Game/GameClient/GameClientState/GameState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index af5f467e..ed04c009 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -483,7 +483,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState this->privData->camera.SetPosition( position ); this->privData->camera.SetRotation( rotation ); this->privData->player.setPos( position ); - //this->privData->player.setRot( rotation ); + this->privData->player.setRot( rotation ); } C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; From 706395680f6d1914dd4a1d05fc269ff1a365bd23 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Wed, 19 Feb 2014 14:51:37 +0100 Subject: [PATCH 21/21] Added bunch of Quaternion functions Needed one of them to create a bug trap --- Code/Misc/OysterMath/Quaternion.h | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/Code/Misc/OysterMath/Quaternion.h b/Code/Misc/OysterMath/Quaternion.h index f5ea5951..b2390a2d 100644 --- a/Code/Misc/OysterMath/Quaternion.h +++ b/Code/Misc/OysterMath/Quaternion.h @@ -49,7 +49,16 @@ namespace LinearAlgebra Quaternion operator - ( const Quaternion &quaternion ) const; Quaternion operator - ( ) const; + Quaternion & Conjugate( ); + Quaternion & Normalize( ); + Quaternion & Inverse( ); + Quaternion GetConjugate( ) const; + Quaternion GetNormalized( ) const; + Quaternion GetInversed( ) const; + ScalarType GetNorm( ) const; + ScalarType GetModulus( ) const; + }; /////////////////////////////////////////////////////////////////////////////////// @@ -205,11 +214,54 @@ namespace LinearAlgebra return Quaternion(-this->imaginary, -this->real); } + template + inline Quaternion & Quaternion::Conjugate( ) + { + this->imaginary = -this->imaginary; + return *this; + } + + template + inline Quaternion & Quaternion::Normalize( ) + { + return *this /= this->GetModulus(); + } + + template + inline Quaternion & Quaternion::Inverse( ) + { + return this->Conjugate() /= this->GetNorm(); + } + template inline Quaternion Quaternion::GetConjugate( ) const { return Quaternion(-this->imaginary, this->real ); } + + template + inline Quaternion Quaternion::GetNormalized( ) const + { + return *this / this->GetModulus(); + } + + template + inline Quaternion Quaternion::GetInversed( ) const + { + return this->GetConjugate() /= this->GetNorm(); + } + + template + inline ScalarType Quaternion::GetNorm( ) const + { + return this->imaginary.Dot(this->imaginary) + this->real * this->real; + } + + template + inline ScalarType Quaternion::GetModulus( ) const + { + return (ScalarType)::std::sqrt( this->GetNorm() ); + } } #endif \ No newline at end of file