diff --git a/Code/Dokumentation/Other/Slerp rotation axis towards new up normal.odt b/Code/Dokumentation/Other/Slerp rotation axis towards new up normal.odt new file mode 100644 index 00000000..6ed3d36f Binary files /dev/null and b/Code/Dokumentation/Other/Slerp rotation axis towards new up normal.odt differ diff --git a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp index 91bfaa1d..d9726205 100644 --- a/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp +++ b/Code/Game/DanBiasGame/DanBiasGame_Impl.cpp @@ -38,7 +38,7 @@ namespace DanBias public: WindowShell* window; InputClass* inputObj; - Utility::WinTimer* timer; + Utility::WinTimer timer; GameRecieverObject* recieverObj; bool serverOwner; @@ -69,12 +69,11 @@ namespace DanBias m_data->serverOwner = false; // Start in lobby state - m_data->recieverObj->gameClientState = new Client::LoginState(); + m_data->recieverObj->gameClientState = new Client::LoginState(); if(!m_data->recieverObj->gameClientState->Init(m_data->recieverObj)) return DanBiasClientReturn_Error; - m_data->timer = new Utility::WinTimer(); //why dynamic memory? - m_data->timer->reset(); + m_data->timer.reset(); return DanBiasClientReturn_Sucess; } @@ -83,8 +82,8 @@ namespace DanBias // Main message loop while(m_data->window->Frame()) { - float dt = (float)m_data->timer->getElapsedSeconds(); - m_data->timer->reset(); + float dt = (float)m_data->timer.getElapsedSeconds(); + m_data->timer.reset(); capFrame += dt; if(capFrame > 0.03) @@ -131,8 +130,9 @@ namespace DanBias HRESULT DanBiasGame::Update(float deltaTime) { + if(m_data->recieverObj->IsConnected()) + m_data->recieverObj->Update(); - m_data->recieverObj->Update(); m_data->inputObj->Update(); if(m_data->serverOwner) @@ -157,7 +157,13 @@ namespace DanBias m_data->recieverObj->gameClientState = new Client::LobbyState(); break; case Client::GameClientState::ClientState_Game: + if(m_data->serverOwner) + DanBias::GameServerAPI::GameStart(); m_data->recieverObj->gameClientState = new Client::GameState(); + if(m_data->serverOwner) + ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(2); + else + ((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(3); break; default: return E_FAIL; @@ -192,7 +198,6 @@ namespace DanBias delete m_data->recieverObj->gameClientState; m_data->recieverObj->Disconnect(); delete m_data->recieverObj; - delete m_data->timer; delete m_data->inputObj; delete m_data; diff --git a/Code/Game/DanBiasGame/GameClientRecieverFunc.h b/Code/Game/DanBiasGame/GameClientRecieverFunc.h index 36b831a0..6d4a2fda 100644 --- a/Code/Game/DanBiasGame/GameClientRecieverFunc.h +++ b/Code/Game/DanBiasGame/GameClientRecieverFunc.h @@ -2,6 +2,8 @@ #define DANBIAS_CLIENTRECIEVEROBJECT_H //WTF!? No headers included??? +#include "../DanBiasGame/Include/DanBiasGame.h" +#include "../GameProtocols/GeneralProtocols.h" namespace DanBias { @@ -100,6 +102,18 @@ namespace DanBias ((Client::GameState*)gameClientState)->Protocol(&protocolData); } break; + case protocol_Lobby_Start: + { + /* + if(dynamic_cast(gameClientState)) + { + gameClientState->Release(); + delete gameClientState; + gameClientState = new Client::GameState(); + gameClientState->Init(m_data->recieverObj); + }*/ + } + break; default: break; @@ -128,8 +142,8 @@ namespace DanBias break; case protocol_Lobby_GameData: //this->LobbyGameData (Protocol_LobbyGameData (p), c); { - GameLogic::Protocol_LobbyGameData temp(p); - printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion); + //GameLogic::Protocol_LobbyGameData temp(p); + //printf("%s, %i.%i\n", temp.mapName.c_str(), temp.majorVersion, temp.minorVersion); } break; case protocol_Lobby_ClientData: //this->LobbyMainData (Protocol_LobbyClientData (p), c); diff --git a/Code/Game/DanBiasGame/GameClientState/GameClientState.h b/Code/Game/DanBiasGame/GameClientState/GameClientState.h index a369233a..378eeefc 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameClientState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameClientState.h @@ -53,6 +53,7 @@ public: { ClientState_Login, ClientState_Lobby, + ClientState_Lan, ClientState_LobbyCreated, ClientState_Game, ClientState_Same, diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index 43b25ba7..cd281717 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -114,6 +114,18 @@ bool GameState::LoadModels(std::wstring mapFile) privData->object.push_back(obj); privData->object[privData->object.size() -1 ]->Init(modelData); + // add player model 2 + modelData.world = Oyster::Math3D::Float4x4::identity; + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 320, 0)); + + modelData.world = modelData.world * translate; + modelData.visible = true; + modelData.modelPath = L"..\\Content\\Models\\char_white.dan"; + modelData.id = 3; + // load models + obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); return true; @@ -137,7 +149,10 @@ bool GameState::InitCamera(Oyster::Math::Float3 startPos) privData->view = Oyster::Math3D::InverseOrientationMatrix(privData->view); return true; } - +void GameState::setClientId(int id) +{ + myId = id; +} GameClientState::ClientState GameState::Update(float deltaTime, InputClass* KeyInput) { switch (privData->state) @@ -344,7 +359,7 @@ void GameState::Protocol( ObjPos* pos ) //camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); //camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6]))); //camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10]))); - if(i == 2) // playerobj + if(i == myId) // playerobj { camera->SetPosition(Oyster::Math::Float3(world[12], world[13]+2.2f, world[14]-1)); camera->UpdateViewMatrix(); diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.h b/Code/Game/DanBiasGame/GameClientState/GameState.h index f8f1b67b..04d5b791 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.h +++ b/Code/Game/DanBiasGame/GameClientState/GameState.h @@ -26,6 +26,7 @@ private: bool key_Jump; Camera* camera; + int myId; struct myData; myData* privData; public: @@ -36,7 +37,7 @@ public: bool LoadModels(std::wstring mapFile) ; bool InitCamera(Oyster::Math::Float3 startPos) ; gameStateState LoadGame(); - + void setClientId(int id); void readKeyInput(InputClass* KeyInput); bool Render()override; bool Release()override; diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp index fdb02fa9..8df39bfa 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.cpp @@ -5,6 +5,10 @@ #include "C_obj/C_DynamicObj.h" #include "DllInterfaces/GFXAPI.h" +#include "LobbyState.h" +#include "GameState.h" +#include "../GameClientRecieverFunc.h" + #include using namespace DanBias::Client; @@ -16,6 +20,10 @@ struct LanMenuState::myData Oyster::Math3D::Float4x4 proj; C_Object* object[2]; int modelCount; + + GameRecieverObject* recieverObj; + bool serverOwner; + // UI object // game client* }privData; @@ -83,6 +91,49 @@ bool LanMenuState::InitCamera(Oyster::Math::Float3 startPos) } GameClientState::ClientState LanMenuState::Update(float deltaTime, InputClass* KeyInput) +{ + /*ChangeState(KeyInput); + + if(privData->recieverObj->IsConnected()) + privData->recieverObj->Update(); + KeyInput->Update(); + + if(privData->serverOwner) + { + DanBias::GameServerAPI::ServerUpdate(); + } + + DanBias::Client::GameClientState::ClientState state = DanBias::Client::GameClientState::ClientState_Same; + state = privData->recieverObj->gameClientState->Update(deltaTime, KeyInput); + + if(state != Client::GameClientState::ClientState_Same) + { + privData->recieverObj->gameClientState->Release(); + delete privData->recieverObj->gameClientState; + privData->recieverObj->gameClientState = NULL; + + switch (state) + { + case Client::GameClientState::ClientState_LobbyCreated: + privData->serverOwner = true; + case Client::GameClientState::ClientState_Lobby: + privData->recieverObj->gameClientState = new Client::LobbyState(); + break; + case Client::GameClientState::ClientState_Game: + privData->recieverObj->gameClientState = new Client::GameState(); + break; + default: + //return E_FAIL; + break; + } + privData->recieverObj->gameClientState->Init(privData->recieverObj); // send game client + + }*/ + + return ChangeState(KeyInput); +} + +GameClientState::ClientState LanMenuState::ChangeState(InputClass* KeyInput) { // create game if( KeyInput->IsKeyPressed(DIK_C)) diff --git a/Code/Game/DanBiasGame/GameClientState/LanMenuState.h b/Code/Game/DanBiasGame/GameClientState/LanMenuState.h index 5182c80c..6b11fd20 100644 --- a/Code/Game/DanBiasGame/GameClientState/LanMenuState.h +++ b/Code/Game/DanBiasGame/GameClientState/LanMenuState.h @@ -17,6 +17,8 @@ namespace DanBias virtual bool Init(Oyster::Network::NetworkClient* nwClient); virtual ClientState Update(float deltaTime, InputClass* KeyInput); + ClientState ChangeState(InputClass* KeyInput); + bool LoadModels(std::wstring file); bool InitCamera(Oyster::Math::Float3 startPos); diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp index 35a5f295..538408c5 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.cpp @@ -87,12 +87,9 @@ GameClientState::ClientState LobbyState::Update(float deltaTime, InputClass* Key // update animation // send data to server // check data from server - if( KeyInput->IsKeyPressed(DIK_G)) { - if(!DanBias::GameServerAPI::GameStart()) - return GameClientState::ClientState_Same; return ClientState_Game; } diff --git a/Code/Game/DanBiasGame/GameClientState/LobbyState.h b/Code/Game/DanBiasGame/GameClientState/LobbyState.h index 057fc850..6a8d9772 100644 --- a/Code/Game/DanBiasGame/GameClientState/LobbyState.h +++ b/Code/Game/DanBiasGame/GameClientState/LobbyState.h @@ -36,6 +36,7 @@ public: bool Release(); void Protocol(ProtocolStruct* protocol)override; void PlayerJoinProtocol(PlayerName* name); + void GameStarted(); };};}; #endif // ! DANBIAS_CLIENT_GAMECLIENTSTATE_H diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index cd1e4663..9beb6657 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -109,7 +109,7 @@ GameClientState::ClientState LoginState::Update(float deltaTime, InputClass* Key if( KeyInput->IsKeyPressed(DIK_J)) { // game ip - nwClient->Connect(15151, "194.47.150.56"); + nwClient->Connect(15151, "127.0.0.1"); if (!nwClient->IsConnected()) { diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 94efbb71..a63b6e1d 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,5 +1,6 @@ #include "AttatchmentMassDriver.h" #include "PhysicsAPI.h" +#include "GameLogicStates.h" using namespace GameLogic; @@ -45,17 +46,16 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, ********************************************************/ void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt) { - //Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); - Oyster::Math::Float3 look = owner->GetLookDir(); - Oyster::Math::Float3 up = -owner->GetRigidBody()->GetGravityNormal(); - Oyster::Math::Float3 pos = owner->GetPosition(); - Oyster::Math::Float4x4 aim = Oyster::Math3D::OrientationMatrix_LookAtDirection(owner->GetLookDir(), -owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); + Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt); + Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition()); + Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20); Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace)); - int arg = 0; + forcePushData args; + args.pushForce = pushForce; - Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,&arg,ForcePushAction); + Oyster::Physics::API::Instance().ApplyEffect(hitFrustum,&args,ForcePushAction); } /******************************************************** diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 196aed09..019df6f4 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -84,20 +84,13 @@ using namespace GameLogic; void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj, void *args) { - Oyster::Math::Float3 pushForce = Oyster::Math::Float4(1,0,0) * (500); Oyster::Physics::ICustomBody::State state; Object *realObj = (Object*)obj->GetCustomTag(); - if(realObj->GetObjectType() == OBJECT_TYPE_BOX) - { - state = obj->GetState(); - state.SetOrientation(Oyster::Math::Float3(1,0.5,1),Oyster::Math::Float3(1,0.5,1)); - obj->SetState(state); - } if(realObj->GetObjectType() == OBJECT_TYPE_PLAYER || realObj->GetObjectType() == OBJECT_TYPE_WORLD) return; + state = obj->GetState(); - state.ApplyLinearImpulse(pushForce); + state.ApplyLinearImpulse(((forcePushData*)(args))->pushForce); obj->SetState(state); - //((Object*)obj->GetCustomTag())->ApplyLinearImpulse(pushForce); } \ No newline at end of file diff --git a/Code/Game/GameLogic/GameLogicStates.h b/Code/Game/GameLogic/GameLogicStates.h index 2b0d0b8b..00c2e7ff 100644 --- a/Code/Game/GameLogic/GameLogicStates.h +++ b/Code/Game/GameLogic/GameLogicStates.h @@ -1,5 +1,6 @@ #ifndef GAMELOGICSTATES_H #define GAMELOGICSTATES_H +#include "OysterMath.h" namespace GameLogic { @@ -46,6 +47,12 @@ namespace GameLogic WEAPON_STATE_RELOADING = 2, }; + struct forcePushData + { + Oyster::Math::Float3 pushForce; + }; + + }; diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index 93fcfba6..e19af2f3 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -7,9 +7,10 @@ Game::PlayerData::PlayerData() { //set some stats that are appropriate to a player Oyster::Physics::API::SimpleBodyDescription sbDesc; - sbDesc.centerPosition = Oyster::Math::Float3(10,350,0); + sbDesc.centerPosition = Oyster::Math::Float3(0,308,0); sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.mass = 70; + sbDesc.restitutionCoeff = 0.5; //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index e09f9bb0..50737eb9 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -32,7 +32,7 @@ void Level::InitiateLevel(float radius) ICustomBody::State state; rigidBody->GetState(state); - state.SetRestitutionCoeff(0.01); + state.SetRestitutionCoeff(0.2); rigidBody->SetState(state); levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD); @@ -41,10 +41,10 @@ void Level::InitiateLevel(float radius) // add box API::SimpleBodyDescription sbDesc_TestBox; - sbDesc_TestBox.centerPosition = Oyster::Math::Float4(0,320,0,0); + sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0); sbDesc_TestBox.ignoreGravity = false; sbDesc_TestBox.mass = 50; - sbDesc_TestBox.size = Oyster::Math::Float4(1,1,1,0); + sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0); ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 3b8094fb..a0823247 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -118,18 +118,22 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody() void Object::BeginFrame() { + Oyster::Math::Float4 axis; + if(setState.GetGravityNormal()!= Float3::null) + { + Oyster::Math3D::SnapAngularAxis(Oyster::Math::Float4(setState.GetAngularAxis(), 0), Oyster::Math::Float4::standard_unit_y, -Oyster::Math::Float4(setState.GetGravityNormal()), axis); + setState.SetRotation(axis.xyz); + setState.SetAngularMomentum(Float3::null); + Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); + debug += setState.GetGravityNormal(); + } + this->rigidBody->SetState(this->setState); - } // update physic void Object::EndFrame() { - - Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis); - //Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal()); - //setState.SetOrientation(rotMatrix); - this->getState = this->rigidBody->GetState(); this->setState = this->getState; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index cc3c9740..f68aad4b 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -86,13 +86,15 @@ namespace DanBias if(dynamic_cast (movedObject)) { IPlayerData* temp = (IPlayerData*)movedObject; - temp->GetID(); + + int id = temp->GetID(); Oyster::Math::Float4x4 world = temp->GetOrientation(); - Protocol_ObjectPosition p(world, 2); + Protocol_ObjectPosition p(world, id); GameSession::gameSession->Send(*p.GetProtocol()); } - else if(dynamic_cast(movedObject)) + + if(dynamic_cast(movedObject)) { GameLogic::IObjectData* obj = NULL; obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0); @@ -100,10 +102,10 @@ namespace DanBias { if(obj->GetObjectType() == OBJECT_TYPE_WORLD) { - obj->GetID(); + int id = obj->GetID(); Oyster::Math::Float4x4 world =obj->GetOrientation(); - Protocol_ObjectPosition p(world, 0); + Protocol_ObjectPosition p(world, id); GameSession::gameSession->Send(*p.GetProtocol()); } } @@ -114,9 +116,9 @@ namespace DanBias { if(obj->GetObjectType() == OBJECT_TYPE_BOX) { - obj->GetID(); + int id = obj->GetID(); Oyster::Math::Float4x4 world = obj->GetOrientation(); - Protocol_ObjectPosition p(world, 1); + Protocol_ObjectPosition p(world, id); GameSession::gameSession->Send(*p.GetProtocol()); } } diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index 5fa3a982..12c46cd5 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -187,7 +187,7 @@ void API_Impl::Update() if( gravityImpulse != Float4::null ) { state.ApplyLinearImpulse( gravityImpulse.xyz ); - (*proto)->SetGravityNormal( gravityImpulse.GetNormalized().xyz ); + state.SetGravityNormal( gravityImpulse.GetNormalized().xyz ); (*proto)->SetState( state ); } @@ -198,24 +198,27 @@ void API_Impl::Update() proto = updateList.begin(); for( ; proto != updateList.end(); ++proto ) { - Float3 lM = state.GetLinearMomentum() + state.GetLinearImpulse(); + (*proto)->GetState( state ); + Float3 lM = state.GetLinearMomentum(); - if( lM.x < this->epsilon ) + //LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp(state.SetOrientation(, Float4(state.GetGravityNormal(), 0.0f), 1.0f); + + + if( abs(lM.x) < this->epsilon ) { - state.SetLinearMomentum( Float3(0, lM.y, lM.z) ); - state.SetLinearImpulse( Float3(0, lM.y, lM.z) ); + state.linearMomentum.x = 0; } - if( lM.y < this->epsilon ) + if( abs(lM.y) < this->epsilon ) { - state.SetLinearMomentum( Float3(lM.x, 0, lM.z) ); - state.SetLinearImpulse( Float3(lM.x, 0, lM.z) ); + state.linearMomentum.y = 0; } - if( lM.z < this->epsilon ) + if( abs(lM.z) < this->epsilon ) { - state.SetLinearMomentum( Float3(lM.x, lM.y, 0) ); - state.SetLinearImpulse( Float3(lM.x, lM.y, 0) ); + state.linearMomentum.z = 0; } + (*proto)->SetState( state ); + switch( (*proto)->Update(this->updateFrameLength) ) { case UpdateState_altered: diff --git a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp index ef3027ee..a2871229 100644 --- a/Code/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -128,7 +128,7 @@ SimpleRigidBody::State & SimpleRigidBody::GetState( SimpleRigidBody::State &targ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state ) { this->rigid.centerPos = state.GetCenterPosition(); - //this->rigid.SetRotation( state.GetRotation() ); //! HACK: @todo Rotation temporary disabled + this->rigid.axis = state.GetAngularAxis(); this->rigid.boundingReach = state.GetReach(); this->rigid.momentum_Linear = state.GetLinearMomentum(); this->rigid.momentum_Angular = state.GetAngularMomentum(); diff --git a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp index 539093db..f6f89c64 100644 --- a/Code/GamePhysics/Implementation/SphericalRigidBody.cpp +++ b/Code/GamePhysics/Implementation/SphericalRigidBody.cpp @@ -94,7 +94,7 @@ SphericalRigidBody::State & SphericalRigidBody::GetState( SphericalRigidBody::St void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) { this->rigid.centerPos = state.GetCenterPosition(); - //this->rigid.SetRotation( state.GetRotation() ); //! HACK: @todo Rotation temporary disabled + this->rigid.axis = state.GetAngularAxis(); this->rigid.boundingReach = state.GetReach(); this->rigid.momentum_Linear = state.GetLinearMomentum(); this->rigid.momentum_Angular = state.GetAngularMomentum(); @@ -105,6 +105,7 @@ void SphericalRigidBody::SetState( const SphericalRigidBody::State &state ) this->rigid.frictionCoeff_Kinetic = state.GetFrictionCoeff_Kinetic(); this->rigid.SetMass_KeepMomentum( state.GetMass() ); this->rigid.SetMomentOfInertia_KeepMomentum( state.GetMomentOfInertia() ); + this->rigid.gravityNormal = state.GetGravityNormal(); if( state.IsForwarded() ) { diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index 78b65f5e..080b8d30 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -34,7 +34,7 @@ namespace Oyster namespace Constant { const float gravity_constant = (const float)6.67284e-11; //!< The _big_G_! ( N(m/kg)^2 ) Used in real gravityforcefields. - const float epsilon = (const float)1.0e-7; + const float epsilon = (const float)1.0e-3; } class PHYSICS_DLL_USAGE API diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index 05cba2da..af2fb91c 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -124,7 +124,7 @@ namespace Oyster inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularAxis() const { - return ::Utility::Value::Radian(this->angularAxis); + return this->angularAxis; } inline ::Oyster::Math::Float4x4 CustomBodyState::GetRotation() const diff --git a/Code/GamePhysics/PhysicsStructs.h b/Code/GamePhysics/PhysicsStructs.h index 00c07b2d..aef157a8 100644 --- a/Code/GamePhysics/PhysicsStructs.h +++ b/Code/GamePhysics/PhysicsStructs.h @@ -115,11 +115,13 @@ namespace Oyster { namespace Physics bool IsDisturbed() const; bool IsForwarded() const; + ::Oyster::Math::Float3 linearMomentum; + private: ::Oyster::Math::Float mass, restitutionCoeff, staticFrictionCoeff, kineticFrictionCoeff; ::Oyster::Physics3D::MomentOfInertia inertiaTensor; ::Oyster::Math::Float3 reach, centerPos, angularAxis; - ::Oyster::Math::Float3 linearMomentum, angularMomentum; + ::Oyster::Math::Float3 angularMomentum; ::Oyster::Math::Float3 linearImpulse, angularImpulse; ::Oyster::Math::Float3 deltaPos, deltaAxis; // Forwarding data sum ::Oyster::Math::Float3 gravityNormal; diff --git a/Code/OysterMath/LinearMath.h b/Code/OysterMath/LinearMath.h index 50bcd36b..dce7a026 100644 --- a/Code/OysterMath/LinearMath.h +++ b/Code/OysterMath/LinearMath.h @@ -325,6 +325,12 @@ namespace LinearAlgebra2D namespace LinearAlgebra3D { + template + inline ::LinearAlgebra::Vector3 WorldAxisOf( const ::LinearAlgebra::Quaternion &rotation, const ::LinearAlgebra::Vector3 &localAxis ) + { + return (rotation*localAxis*rotation.GetConjugate()).imaginary; + } + // All Matrix to AngularAxis conversions here is incorrect //template //inline ::LinearAlgebra::Vector4 AngularAxis( const ::LinearAlgebra::Matrix3x3 &rotationMatrix ) @@ -741,6 +747,23 @@ namespace LinearAlgebra3D inline ::LinearAlgebra::Vector4 NormalProjection( const ::LinearAlgebra::Vector4 &vector, const ::LinearAlgebra::Vector4 &normalizedAxis ) { return normalizedAxis * ( vector.Dot(normalizedAxis) ); } + template + ::LinearAlgebra::Vector4 & SnapAngularAxis( ::LinearAlgebra::Vector4 &startAngularAxis, const ::LinearAlgebra::Vector4 &localStartNormal, const ::LinearAlgebra::Vector4 &worldEndNormal, ::LinearAlgebra::Vector4 &targetMem = ::LinearAlgebra::Vector4() ) + { + ::LinearAlgebra::Vector4 worldStartNormal( WorldAxisOf(Rotation(startAngularAxis.xyz), localStartNormal.xyz), (ScalarType)0 ); + targetMem = ::LinearAlgebra::Vector4( worldStartNormal.xyz.Cross(worldEndNormal.xyz), (ScalarType)0); + targetMem *= (ScalarType)::std::acos( worldStartNormal.Dot(worldEndNormal) ); + return targetMem += startAngularAxis; + } + + template + ::LinearAlgebra::Vector3 & SnapAngularAxis( ::LinearAlgebra::Vector3 &startAngularAxis, const ::LinearAlgebra::Vector3 &localStartNormal, const ::LinearAlgebra::Vector3 &worldEndNormal, ::LinearAlgebra::Vector3 &targetMem = ::LinearAlgebra::Vector3() ) + { + return targetMem = SnapAngularAxis( ::LinearAlgebra::Vector4(startAngularAxis, (ScalarType)0), + ::LinearAlgebra::Vector4(localStartNormal, (ScalarType)0), + ::LinearAlgebra::Vector4(worldEndNormal, (ScalarType)0) ).xyz; + } + template ::LinearAlgebra::Matrix4x4 & SnapAxisYToNormal_UsingNlerp( ::LinearAlgebra::Matrix4x4 &rotation, const ::LinearAlgebra::Vector4 &normalizedAxis ) { diff --git a/Code/OysterMath/OysterMath.h b/Code/OysterMath/OysterMath.h index 5970face..7e123183 100644 --- a/Code/OysterMath/OysterMath.h +++ b/Code/OysterMath/OysterMath.h @@ -324,6 +324,7 @@ namespace Oyster { namespace Math3D //! Oyster's native math library specialized using ::LinearAlgebra3D::InterpolateAxisYToNormal_UsingNlerp; using ::LinearAlgebra3D::InterpolateOrientation_UsingNonRigidNlerp; using ::LinearAlgebra3D::InterpolateOrientation_UsingSlerp; + using ::LinearAlgebra3D::SnapAngularAxis; } } #endif \ No newline at end of file diff --git a/Code/OysterPhysics3D/OysterCollision3D.cpp b/Code/OysterPhysics3D/OysterCollision3D.cpp index 169b5add..89b3af8a 100644 --- a/Code/OysterPhysics3D/OysterCollision3D.cpp +++ b/Code/OysterPhysics3D/OysterCollision3D.cpp @@ -784,8 +784,8 @@ namespace Oyster { namespace Collision3D { namespace Utility if( Intersect(box, sphere) ) { Float distance; - Ray ray( box.center, sphere.center - box.center ); - + Ray ray( box.center, (sphere.center - box.center).Normalize() ); + Intersect( sphere, ray, distance ); worldPointOfContact = ray.origin + ray.direction*distance; return true; diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index 0c60c597..f053e8dd 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -50,7 +50,12 @@ void RigidBody::Update_LeapFrog( Float updateFrameLength ) // updating the linear // ds = dt * Formula::LinearVelocity( m, avg_G ) = dt * avg_G / m = (dt / m) * avg_G - this->centerPos += ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); + Float3 deltaPos = ( updateFrameLength / this->mass ) * AverageWithDelta( this->momentum_Linear, this->impulse_Linear ); + if( deltaPos.GetLength() < 0.001f ) + { + deltaPos = Float3::null; + } + this->centerPos += deltaPos; // updating the angular // dO = dt * Formula::AngularVelocity( (RI)^-1, avg_H ) = dt * (RI)^-1 * avg_H