diff --git a/Code/Game/DanBiasGame/GameClientState/GameState.cpp b/Code/Game/DanBiasGame/GameClientState/GameState.cpp index bdab4dfb..0102a027 100644 --- a/Code/Game/DanBiasGame/GameClientState/GameState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/GameState.cpp @@ -49,15 +49,25 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient) GameState::gameStateState GameState::LoadGame() { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(0,15,5); - plight.Color = Oyster::Math::Float3(0,1,0); - plight.Radius = 50; - plight.Bright = 2; + plight.Pos = Oyster::Math::Float3(315, 0 ,5); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.2); + plight.Radius = 100; + plight.Bright = 0.9; Oyster::Graphics::API::AddLight(plight); - plight.Pos = Oyster::Math::Float3(10,15,5); - plight.Color = Oyster::Math::Float3(1,0,0); - plight.Radius = 50; - plight.Bright = 2; + plight.Pos = Oyster::Math::Float3(10,350,5); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Radius = 200; + plight.Bright = 0.7; + Oyster::Graphics::API::AddLight(plight); + plight.Pos = Oyster::Math::Float3(350,350,5); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Radius = 200; + plight.Bright = 0.7; + Oyster::Graphics::API::AddLight(plight); + plight.Pos = Oyster::Math::Float3(10,350,350); + plight.Color = Oyster::Math::Float3(0.9,0.7,0.3); + plight.Radius = 200; + plight.Bright = 0.7; Oyster::Graphics::API::AddLight(plight); plight.Pos = Oyster::Math::Float3(10,-15,5); plight.Color = Oyster::Math::Float3(0,0,1); @@ -74,7 +84,8 @@ bool GameState::LoadModels(std::wstring mapFile) // open file // read file // init models - privData->modelCount = 4; + int nrOfBoxex = 5; + privData->modelCount = 3+nrOfBoxex; myId += privData->modelCount; int id = 0; // add world model @@ -92,15 +103,20 @@ bool GameState::LoadModels(std::wstring mapFile) // add box model modelData.world = Oyster::Math3D::Float4x4::identity; - translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); - modelData.world = modelData.world * translate; modelData.modelPath = L"..\\Content\\Models\\box.dan"; - modelData.id = id++; - obj = new C_Player(); - privData->object.push_back(obj); - privData->object[privData->object.size() -1 ]->Init(modelData); - modelData.world = Oyster::Math3D::Float4x4::identity; + + for(int i =0; i< nrOfBoxex; i ++) + { + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0)); + modelData.world = modelData.world * translate; + modelData.id = id++; + + obj = new C_Player(); + privData->object.push_back(obj); + privData->object[privData->object.size() -1 ]->Init(modelData); + modelData.world = Oyster::Math3D::Float4x4::identity; + } // add crystal model modelData.world = Oyster::Math3D::Float4x4::identity; @@ -330,7 +346,37 @@ void GameState::readKeyInput(InputClass* KeyInput) if(!key_Shoot) { GameLogic::Protocol_PlayerShot playerShot; - playerShot.hasShot = true; + playerShot.primaryPressed = true; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = false; + privData->nwClient->Send(playerShot); + key_Shoot = true; + } + } + else + key_Shoot = false; + if(KeyInput->IsKeyPressed(DIK_X)) + { + if(!key_Shoot) + { + GameLogic::Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = true; + playerShot.utilityPressed = false; + privData->nwClient->Send(playerShot); + key_Shoot = true; + } + } + else + key_Shoot = false; + if(KeyInput->IsKeyPressed(DIK_C)) + { + if(!key_Shoot) + { + GameLogic::Protocol_PlayerShot playerShot; + playerShot.primaryPressed = false; + playerShot.secondaryPressed = false; + playerShot.utilityPressed = true; privData->nwClient->Send(playerShot); key_Shoot = true; } @@ -339,7 +385,7 @@ void GameState::readKeyInput(InputClass* KeyInput) key_Shoot = false; // jump - if(KeyInput->IsKeyPressed(DIK_X)) + if(KeyInput->IsKeyPressed(DIK_SPACE)) { if(!key_Jump) { @@ -408,7 +454,7 @@ void GameState::Protocol( ObjPos* pos ) camera->setRight(right); camera->setUp(up); - //camera->setLook(objForward); + camera->setLook(objForward); up *= 2; objForward *= -3; diff --git a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp index 9beb6657..301ab791 100644 --- a/Code/Game/DanBiasGame/GameClientState/LoginState.cpp +++ b/Code/Game/DanBiasGame/GameClientState/LoginState.cpp @@ -41,9 +41,9 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient) bool LoginState::LoadModels(std::wstring file) { Oyster::Graphics::Definitions::Pointlight plight; - plight.Pos = Oyster::Math::Float3(-2,3,0); - plight.Color = Oyster::Math::Float3(0,1,0); - plight.Radius = 10; + plight.Pos = Oyster::Math::Float3(0,0,5.4f); + plight.Color = Oyster::Math::Float3(1,1,1); + plight.Radius = 100; plight.Bright = 1; Oyster::Graphics::API::AddLight(plight); // open file @@ -55,12 +55,13 @@ bool LoginState::LoadModels(std::wstring file) modelData.world = Oyster::Math3D::Float4x4::identity; modelData.visible = true; - modelData.modelPath = L"..\\Content\\Models\\box_2.dan"; + modelData.modelPath = L"..\\Content\\Models\\box.dan"; // load models - privData->object[0] = new C_StaticObj(); + Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2)); + privData->object[0] = new C_DynamicObj(); privData->object[0]->Init(modelData); - Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); + translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2)); modelData.world = modelData.world * translate; privData->object[1] = new C_DynamicObj(); diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 1d8e06a4..e0ca6c0f 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -42,7 +42,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(hasObject) { - ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES + //ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES break; } ForcePull(usage,dt); diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 24bb6bba..21c073f8 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -84,7 +84,7 @@ using namespace GameLogic; if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough { damageDone = kineticEnergyLoss * 0.10f; - player.DamageLife(damageDone); + //player.DamageLife(damageDone); } } @@ -96,6 +96,14 @@ using namespace GameLogic; { return Physics::ICustomBody::SubscriptMessage_none; } + Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) + { + return Physics::ICustomBody::SubscriptMessage_player_collision_response; + } + Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss) + { + return Physics::ICustomBody::SubscriptMessage_none; + } //Oyster::Physics::ICustomBody::SubscriptMessage Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj) { diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index ddcfc086..b57520e0 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -53,6 +53,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; OBJECT_TYPE GetObjectType() const override; + int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; Level *level; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index f0ce50b1..53931063 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -100,6 +100,7 @@ namespace GameLogic class ILevelData :public IObjectData { public: + virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; }; diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 1a5973e6..9bd3275a 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -35,7 +35,10 @@ OBJECT_TYPE Game::LevelData::GetObjectType() const return ((IObjectData*)this->level)->GetObjectType(); //return OBJECT_TYPE_UNKNOWN; } - +int Game::LevelData::getNrOfDynamicObj()const +{ + return this->level->getNrOfDynamicObj(); +} IObjectData* Game::LevelData::GetObjectAt(int ID) const { return this->level->GetObj(ID); diff --git a/Code/Game/GameLogic/Game_PlayerData.cpp b/Code/Game/GameLogic/Game_PlayerData.cpp index bf2cbcbe..da441539 100644 --- a/Code/Game/GameLogic/Game_PlayerData.cpp +++ b/Code/Game/GameLogic/Game_PlayerData.cpp @@ -11,13 +11,15 @@ Game::PlayerData::PlayerData() sbDesc.size = Oyster::Math::Float3(4,7,4); sbDesc.mass = 70; sbDesc.restitutionCoeff = 0.5; + sbDesc.frictionCoeff_Static = 0.4; + sbDesc.frictionCoeff_Dynamic = 0.3; sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0); //create rigid body Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release(); //create player with this rigid body - this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); + this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER); this->player->GetRigidBody()->SetCustomTag(this); /*Oyster::Physics::ICustomBody::State state; this->player->GetRigidBody()->GetState(state); diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index a80c76f2..0a2fd31b 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -20,6 +20,35 @@ void Level::InitiateLevel(std::string levelPath) } void Level::InitiateLevel(float radius) { + float heading = Utility::Value::Radian(180.0f); + float attitude = Utility::Value::Radian(0.0f); + float bank = Utility::Value::Radian(0); + + double c1 = cos(heading/2); + double s1 = sin(heading/2); + double c2 = cos(attitude/2); + double s2 = sin(attitude/2); + double c3 = cos(bank/2); + double s3 = sin(bank/2); + double c1c2 = c1*c2; + double s1s2 = s1*s2; + double w =c1c2*c3 - s1s2*s3; + double x =c1c2*s3 + s1s2*c3; + double y =s1*c2*c3 + c1*s2*s3; + double z =c1*s2*c3 - s1*c2*s3; + double angle = 2 * acos(w); + + double norm = x*x+y*y+z*z; + if (norm < 0.001) { // when all euler angles are zero angle =0 so + // we can set axis to anything to avoid divide by zero + x=1; + y=z=0; + } else { + norm = sqrt(norm); + x /= norm; + y /= norm; + z /= norm; + } // add level sphere API::SphericalBodyDescription sbDesc; @@ -29,6 +58,7 @@ void Level::InitiateLevel(float radius) sbDesc.mass = 10e12f; sbDesc.frictionCoeff_Static = 0; sbDesc.frictionCoeff_Dynamic = 0; + //sbDesc.rotation = ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release(); ICustomBody::State state; @@ -49,31 +79,35 @@ void Level::InitiateLevel(float radius) sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0); - ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); - rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); + ICustomBody* rigidBody_TestBox; + + int nrOfBoxex = 5; + for(int i =0; i< nrOfBoxex; i ++) + { + sbDesc_TestBox.centerPosition = Oyster::Math::Float4(20 ,320,0 + ( i*7),0); + rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release(); + rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); + + this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); + rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]); + } + + + - this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[0]); - rigidBody_TestBox->GetState(state); - state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); - rigidBody_TestBox->SetState(state); // add crystal API::SimpleBodyDescription sbDesc_Crystal; sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0); sbDesc_Crystal.ignoreGravity = false; - sbDesc_Crystal.mass = 70; sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0); - ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release(); rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel); this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_Crystal->SetCustomTag(this->dynamicObjects[1]); - rigidBody_Crystal->GetState(state); - state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); - rigidBody_Crystal->SetState(state); + rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]); + // add house API::SimpleBodyDescription sbDesc_House; @@ -88,10 +122,7 @@ void Level::InitiateLevel(float radius) rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel); this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC)); rigidBody_House->SetCustomTag(this->staticObjects[0]); - rigidBody_House->GetState(state); - state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); - rigidBody_House->SetState(state); - + // add gravitation API::Gravity gravityWell; @@ -116,6 +147,10 @@ void Level::RespawnPlayer(Player *player) this->teamManager.RespawnPlayerRandom(player); } +int Level::getNrOfDynamicObj() +{ + return this->dynamicObjects.Size(); +} Object* Level::GetObj( int ID) const { for (int i = 0; i< this->dynamicObjects.Size(); i++) diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index 00fb76ef..cc34408b 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -59,7 +59,8 @@ namespace GameLogic ********************************************************/ static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); - + + int getNrOfDynamicObj(); Object* GetObj( int ID ) const; static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); diff --git a/Code/Game/GameLogic/Object.cpp b/Code/Game/GameLogic/Object.cpp index 8cb57aae..68297d46 100644 --- a/Code/Game/GameLogic/Object.cpp +++ b/Code/Game/GameLogic/Object.cpp @@ -156,6 +156,8 @@ void Object::EndFrame() //error int i =0 ; } + + if(currPhysicsState.GetGravityNormal()!= Float3::null) { Oyster::Math::Float4 axis; @@ -170,6 +172,18 @@ void Object::EndFrame() Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y); debug += currPhysicsState.GetGravityNormal(); } + Oyster::Math::Float3 pos = currPhysicsState.GetCenterPosition(); + Oyster::Math::Float3 up = -currPhysicsState.GetGravityNormal(); + //300, 0,0, + //1,0,0 + + if( pos.GetLength() < 303.5f) + { + Oyster::Math::Float moveUp = 303.5 - pos.GetLength(); + up *= moveUp; + + currPhysicsState.SetCenterPosition(pos + up); + } if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum()) diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 54e246a7..9b0c29ee 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -6,7 +6,7 @@ using namespace GameLogic; using namespace Oyster::Physics; -const int MOVE_FORCE = 5000; +const int MOVE_FORCE = 500; Player::Player() :DynamicObject() { @@ -154,11 +154,6 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir) { int i =0 ; } - //Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; - //Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; - //Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); - - //newPhysicsState.SetRotation(oldOrt + deltaAxis); this->lookDir = lookDir.xyz; this->dx = lookDir.w; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index f609d197..4f406e31 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -73,6 +73,9 @@ namespace GameLogic void BeginFrame(); void EndFrame(); + static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj); + static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss); + private: void Jump(); diff --git a/Code/Game/GameProtocols/PlayerProtocols.h b/Code/Game/GameProtocols/PlayerProtocols.h index 216dec73..2192b361 100644 --- a/Code/Game/GameProtocols/PlayerProtocols.h +++ b/Code/Game/GameProtocols/PlayerProtocols.h @@ -142,7 +142,9 @@ namespace GameLogic struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject { - bool hasShot; + bool primaryPressed; + bool secondaryPressed; + bool utilityPressed; Protocol_PlayerShot() { @@ -150,19 +152,27 @@ namespace GameLogic this->protocol[0].type = Oyster::Network::NetAttributeType_Short; this->protocol[1].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[2].type = Oyster::Network::NetAttributeType_Bool; + this->protocol[3].type = Oyster::Network::NetAttributeType_Bool; } Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p) { - hasShot = p[1].value.netBool; + primaryPressed = p[1].value.netBool; + secondaryPressed = p[2].value.netBool; + utilityPressed = p[3].value.netBool; } const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val) { - hasShot = val[1].value.netBool; + primaryPressed = val[1].value.netBool; + secondaryPressed = val[2].value.netBool; + utilityPressed = val[3].value.netBool; return *this; } Oyster::Network::CustomNetProtocol* GetProtocol() override { - this->protocol[1].value = hasShot; + this->protocol[1].value = primaryPressed; + this->protocol[2].value = secondaryPressed; + this->protocol[3].value = utilityPressed; return &protocol; } diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index ee6cc385..367048f7 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -111,27 +111,19 @@ namespace DanBias } obj = NULL; - obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1); - if(obj) + int count = ((GameLogic::ILevelData*)movedObject)->getNrOfDynamicObj(); + for( int i = 0; i < count; i++ ) { - if(obj->GetObjectType() == OBJECT_TYPE_BOX) + obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(i+1); + if(obj) { - int id = obj->GetID(); - Oyster::Math::Float4x4 world = obj->GetOrientation(); - Protocol_ObjectPosition p(world, id); - GameSession::gameSession->Send(*p.GetProtocol()); - } - } - obj = NULL; - obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(2); - if(obj) - { - if(obj->GetObjectType() == OBJECT_TYPE_BOX) - { - int id = obj->GetID(); - Oyster::Math::Float4x4 world = obj->GetOrientation(); - Protocol_ObjectPosition p(world, id); - GameSession::gameSession->Send(*p.GetProtocol()); + if(obj->GetObjectType() == OBJECT_TYPE_BOX) + { + int id = obj->GetID(); + Oyster::Math::Float4x4 world = obj->GetOrientation(); + Protocol_ObjectPosition p(world, id); + GameSession::gameSession->Send(*p.GetProtocol()); + } } } } @@ -197,9 +189,9 @@ namespace DanBias } void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c ) { - //c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); - c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); - //c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS); + if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS); + if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS); } void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c ) { diff --git a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp index ede0c289..7981322f 100644 --- a/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp +++ b/Code/GamePhysics/Implementation/PhysicsAPI_Impl.cpp @@ -27,7 +27,7 @@ namespace ICustomBody::State deuterState; deuter->GetState( deuterState ); // calc from perspective of deuter. - Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed + Float4 normal = (worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f )).GetNormalized(); // Init value is only borrowed if( normal.Dot(normal) > 0.0f ) { deuter->GetNormalAt( worldPointOfContact, normal ); @@ -47,9 +47,10 @@ namespace proto->GetNormalAt( worldPointOfContact, normal ); normal = -normal; } + normal.Normalize(); - Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ), - deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz ); + Float4 protoG = Float4(protoState.GetLinearMomentum( worldPointOfContact.xyz ), 0), + deuterG = Float4(deuterState.GetLinearMomentum( worldPointOfContact.xyz ), 0); if( normal != normal ) // debug: trap const char *breakpoint = "This should never happen"; @@ -89,6 +90,18 @@ namespace return; } + // PLayerHAck + if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_player_collision_response ) + { + Float3 linearMomentum = protoState.GetLinearMomentum(); + Float3 up = -protoState.GetGravityNormal(); + Float3 upForce = (linearMomentum.Dot(up) * up); + + Float3 noBounceForce = linearMomentum - upForce; + protoState.SetLinearMomentum(noBounceForce); + proto->SetState(protoState); + return; + } // calculate and store time interpolation value, for later rebound. proto->SetTimeOfContact( worldPointOfContact ); @@ -100,7 +113,7 @@ namespace // calc from perspective of proto - normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f ); + normal = (worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f )).GetNormalized(); if( normal.Dot(normal) > 0.0f ) { proto->GetNormalAt( worldPointOfContact, normal ); diff --git a/Code/GamePhysics/PhysicsAPI.h b/Code/GamePhysics/PhysicsAPI.h index f636bb73..c3efef3e 100644 --- a/Code/GamePhysics/PhysicsAPI.h +++ b/Code/GamePhysics/PhysicsAPI.h @@ -242,7 +242,8 @@ namespace Oyster { SubscriptMessage_none, SubscriptMessage_kineticLoss, - SubscriptMessage_ignore_collision_response + SubscriptMessage_ignore_collision_response, + SubscriptMessage_player_collision_response }; typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter ); diff --git a/Code/GamePhysics/PhysicsStructs-Impl.h b/Code/GamePhysics/PhysicsStructs-Impl.h index d3907b54..30e1a605 100644 --- a/Code/GamePhysics/PhysicsStructs-Impl.h +++ b/Code/GamePhysics/PhysicsStructs-Impl.h @@ -322,10 +322,14 @@ namespace Oyster inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal ) { ::Oyster::Math::Float3 offset = at - this->centerPos; - ::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset ); - this->linearImpulse += j - ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset ); + if( offset.Dot(offset) > 0.0f ) + { + ::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset ); - this->angularImpulse += deltaAngularImpulse; + this->linearImpulse -= ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset ); + this->angularImpulse += deltaAngularImpulse; + } + this->linearImpulse += j; this->isDisturbed = true; } diff --git a/Code/OysterPhysics3D/RigidBody.cpp b/Code/OysterPhysics3D/RigidBody.cpp index ca6dcdec..3563c77e 100644 --- a/Code/OysterPhysics3D/RigidBody.cpp +++ b/Code/OysterPhysics3D/RigidBody.cpp @@ -148,7 +148,12 @@ Float3 RigidBody::GetVelocity_Angular() const Float3 RigidBody::GetLinearMomentum( const Float3 &atWorldPos ) const { // by Dan Andersson - return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, atWorldPos - this->centerPos ); + Float3 offset = atWorldPos - this->centerPos; + if( offset.Dot(offset) > 0.0f ) + { + return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, offset ); + } + return this->momentum_Linear; } void RigidBody::SetMomentOfInertia_KeepVelocity( const MomentOfInertia &localTensorI )