From c85cecd05a51e2e0d68e3adf1e12e32790865f71 Mon Sep 17 00:00:00 2001 From: Dander7BD Date: Fri, 14 Feb 2014 15:19:10 +0100 Subject: [PATCH] som more stuff created another version of Quaternion to Angular Axis conversion. --- .../GameClientState/LanMenuState.cpp | 6 ++-- .../GameClientState/LobbyState.cpp | 2 +- .../GameClientState/NetLoadState.cpp | 32 +++++++++++++++++-- .../GameClientState/NetLoadState.h | 9 ++++-- Code/OysterMath/LinearMath.h | 8 +++++ Code/OysterMath/OysterMath.cpp | 6 ++++ Code/OysterMath/OysterMath.h | 3 ++ 7 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp index f5699ce5..6a836a36 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp @@ -121,8 +121,8 @@ void LanMenuState::ChangeState( ClientState next ) { case GameClientState::ClientState_Lobby: // attempt to connect to lobby - if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) - return; + //if( !this->privData->nwClient->Connect(this->privData->connectPort, (*this->privData->connectIP)[0]) ) + // return; // TODO: temporary commented out break; default: break; } @@ -135,7 +135,7 @@ void OnButtonInteract_Connect( Oyster::Event::ButtonEvent& e ) switch( e.state ) { case ButtonState_Released: - e.owner->ChangeState( GameClientState::ClientState_LobbyCreate ); + e.owner->ChangeState( GameClientState::ClientState_Lobby ); break; default: break; } diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 96ac9ca5..e3bfa68a 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -48,7 +48,7 @@ bool LobbyState::Init(NetworkClient* nwClient) // create buttons ButtonRectangle *button; - button = new ButtonRectangle( L"earth_md.png", L"", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); + button = new ButtonRectangle( L"earth_md.png", L"Ready", Float3(1.0f), OnButtonInteract_Ready, this, Float3(0.5f, 0.2f, 0.5f), Float2(0.3f, 0.1f), ResizeAspectRatio_Width ); this->privData->guiElements.AddButton( button ); // bind button collection to the singleton eventhandler diff --git a/Code/Game/DanBiasGame/GameClientState/NetLoadState.cpp b/Code/Game/DanBiasGame/GameClientState/NetLoadState.cpp index 4c1f711c..e3f419bf 100644 --- a/Code/Game/DanBiasGame/GameClientState/NetLoadState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/NetLoadState.cpp @@ -1,5 +1,6 @@ #include "NetLoadState.h" #include "NetworkClient.h" +#include "../Game/GameProtocols/ProtocolIdentificationID.h" using namespace ::DanBias::Client; using namespace ::Oyster; @@ -10,7 +11,7 @@ struct NetLoadState::MyData MyData() {} GameClientState::ClientState nextState; - NetworkClient *nwClient; + //NetworkClient *nwClient; needed? }; NetLoadState::NetLoadState(void) {} @@ -26,9 +27,12 @@ bool NetLoadState::Init( NetworkClient* nwClient ) this->privData = new MyData(); this->privData->nextState = GameClientState::ClientState_Same; - this->privData->nwClient = nwClient; + //this->privData->nwClient = nwClient; needed? + + // we may assume that nwClient is properly connected to the server + this->privData->nextState = GameClientState::ClientState_Main; return true; } @@ -55,4 +59,28 @@ bool NetLoadState::Release() void NetLoadState::ChangeState( ClientState next ) { this->privData->nextState = next; +} + +void NetLoadState::DataRecieved( NetEvent e ) +{ + CustomNetProtocol data = e.args.data.protocol; + short ID = data[0].value.netShort; // fetching the id data. + + //if( ProtocolIsGameplay(ID) ) + //{ + // switch(ID) + // { + // //case protocol_Gameplay_ObjectPickup: break; /** @todo TODO: implement */ + // default: break; + // } + //} + //else if( ProtocolIsGeneral(ID) ) + //{ + // switch( ID ) + // { + // case protocol_General_Status: break; /** @todo TODO: implement */ + // case protocol_General_Text: break; /** @todo TODO: implement */ + // default: break; + // } + //} } \ No newline at end of file diff --git a/Code/Game/DanBiasGame/GameClientState/NetLoadState.h b/Code/Game/DanBiasGame/GameClientState/NetLoadState.h index f147bfe8..e2688a4e 100644 --- a/Code/Game/DanBiasGame/GameClientState/NetLoadState.h +++ b/Code/Game/DanBiasGame/GameClientState/NetLoadState.h @@ -10,9 +10,6 @@ namespace DanBias { class NetLoadState : public GameClientState { - private: - struct MyData; - ::Utility::DynamicMemory::UniquePointer privData; public: NetLoadState( ); virtual ~NetLoadState( ); @@ -23,6 +20,12 @@ namespace DanBias bool Render(); bool Release(); void ChangeState( ClientState next ); + + void DataRecieved( ::Oyster::Network::NetEvent<::Oyster::Network::NetworkClient*, ::Oyster::Network::NetworkClient::ClientEventArgs> e ); + + private: + struct MyData; + ::Utility::DynamicMemory::UniquePointer privData; }; } } diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index a6d48eb2..e0c7bf9f 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -373,6 +373,14 @@ namespace LinearAlgebra3D return (rotation*localAxis*rotation.GetConjugate()).imaginary; } + template + inline ::LinearAlgebra::Vector3 AngularAxis( const ::LinearAlgebra::Quaternion &rotation ) + { + ScalarType angle = ScalarType(2) * (ScalarType)::std::acos( rotation.real ), + multiplier = angle / (ScalarType)::std::sqrt( rotation.real ); + return multiplier * rotation.imaginary; + } + // All Matrix to AngularAxis conversions here is incorrect //template //inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix ) diff --git a/Code/OysterMath/OysterMath.cpp b/Code/OysterMath/OysterMath.cpp index 3906a1db..8db4e175 100644 --- a/Code/OysterMath/OysterMath.cpp +++ b/Code/OysterMath/OysterMath.cpp @@ -81,6 +81,12 @@ namespace Oyster { namespace Math2D namespace Oyster { namespace Math3D { + //! Converts a rotationQuaternion to an angularAxis + Float3 AngularAxis( const Quaternion &rotation ) + { + return ::LinearAlgebra3D::AngularAxis( rotation ); + } + //Float4 AngularAxis( const Float3x3 &rotationMatrix ) //{ // return ::LinearAlgebra3D::AngularAxis( rotationMatrix ); diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index 23ba55ff..8de2759a 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -140,6 +140,9 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized { using namespace ::Oyster::Math; // deliberate inheritance from ::Oyster::Math namespace + //! Converts a rotationQuaternion to an angularAxis + Float3 AngularAxis( const Quaternion &rotation ); + //! Extracts the angularAxis from rotationMatrix //Float4 AngularAxis( const Float3x3 &rotationMatrix );