diff --git a/Code/Game/GameClient/GameClientState/C_Object.cpp b/Code/Game/GameClient/GameClientState/C_Object.cpp index b168b92c..8e84da8e 100644 --- a/Code/Game/GameClient/GameClientState/C_Object.cpp +++ b/Code/Game/GameClient/GameClientState/C_Object.cpp @@ -91,7 +91,10 @@ void C_Object::Render() { if( this->model ) { - Oyster::Graphics::API::RenderModel(model); + if(this->model->Visible) + { + Oyster::Graphics::API::RenderModel(model); + } } } void C_Object::Release() diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 1c3cf881..f3ce8117 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -158,19 +158,28 @@ void GameState::InitiatePlayer( int id, const std::string &modelName, const floa GameClientState::ClientState GameState::Update( float deltaTime ) { - GameStateUI::UIState UIstate = this->currGameUI->Update( deltaTime ); + GameStateUI::UIState UIstate = this->gameUI->Update( deltaTime ); switch (UIstate) { + case DanBias::Client::GameStateUI::UIState_shut_down: + { + this->privData->nextState = ClientState_Quit; + // disconnect + } + + break; case DanBias::Client::GameStateUI::UIState_same: break; case DanBias::Client::GameStateUI::UIState_gaming: break; case DanBias::Client::GameStateUI::UIState_main_menu: - //this->privData->nextState = - break; - case DanBias::Client::GameStateUI::UIState_shut_down: - this->privData->nextState = ClientState_Quit; + { + this->privData->nextState = ClientState_Main; + // disconnect + } + break; + default: break; } @@ -603,6 +612,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) @@ -620,6 +635,12 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState { // if it is not a player object = (*this->privData->dynamicObjects)[decoded.objectID]; + + if(!object) + { + //If it is a static object + object = (*this->privData->staticObjects)[decoded.objectID]; + } } if( object ) @@ -757,6 +778,15 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case GameLogic::PlayerAction::PlayerAction_Idle: player->playAnimation(L"idle", true); break; + + case GameLogic::WeaponAction::WeaponAction_PrimaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_SecondaryShoot: + break; + case GameLogic::WeaponAction::WeaponAction_Reload: + break; + + default: break; } @@ -764,6 +794,28 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState } } return GameClientState::event_processed; + case protocol_Gameplay_ObjectCollision: + { + Protocol_ObjectCollision decoded(data); + C_Object *object; + object = (this->privData->players)[decoded.objectID]; + if( !object) + { + // if it is not a player + object = (*this->privData->dynamicObjects)[decoded.objectID]; + } + if( object ) + { + switch (decoded.collisionID) + { + case GameLogic::CollisionEvent::CollisionEvent_BasicCollision: + break; + default: + break; + } + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameClient/GameClientState/GamingUI.cpp b/Code/Game/GameClient/GameClientState/GamingUI.cpp index 58b370be..19fad94c 100644 --- a/Code/Game/GameClient/GameClientState/GamingUI.cpp +++ b/Code/Game/GameClient/GameClientState/GamingUI.cpp @@ -17,6 +17,7 @@ GamingUI::GamingUI() : this->camera = nullptr; this->plane = nullptr; this->text = nullptr; + this->nextState = GameStateUI::UIState_same; } GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) : @@ -24,6 +25,7 @@ GamingUI::GamingUI( SharedStateContent* shared, Camera_FPSV2 *camera ) : { this->sharedData = shared; this->camera = camera; + this->nextState = GameStateUI::UIState_same; } GamingUI::~GamingUI() { /* Do nothing */ } diff --git a/Code/Game/GameLogic/AttatchmentMassDriver.cpp b/Code/Game/GameLogic/AttatchmentMassDriver.cpp index 62f3599e..13ef8fef 100644 --- a/Code/Game/GameLogic/AttatchmentMassDriver.cpp +++ b/Code/Game/GameLogic/AttatchmentMassDriver.cpp @@ -1,7 +1,7 @@ #include "AttatchmentMassDriver.h" #include "PhysicsAPI.h" #include "GameLogicStates.h" - +#include "Game.h" using namespace GameLogic; @@ -48,6 +48,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForcePush(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_PrimaryShoot); } break; @@ -55,7 +57,9 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, if(currentEnergy >= 1.0f) { currentEnergy -= 1.0f; - ForcePull(usage,dt); + ForcePull(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_SecondaryShoot); } break; @@ -64,6 +68,8 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage, { currentEnergy -= 90.0f; ForceZip(usage,dt); + // add CD + ((Game*)&Game::Instance())->onActionEventFnc(this->owner, WeaponAction::WeaponAction_UtilityActivate); } break; } diff --git a/Code/Game/GameLogic/CollisionManager.cpp b/Code/Game/GameLogic/CollisionManager.cpp index 3e931f8e..c355fd04 100644 --- a/Code/Game/GameLogic/CollisionManager.cpp +++ b/Code/Game/GameLogic/CollisionManager.cpp @@ -44,7 +44,6 @@ using namespace GameLogic; realObjB = realObjA; } - switch (realObjB->GetObjectType()) { case ObjectSpecialType::ObjectSpecialType_Generic: @@ -69,7 +68,8 @@ using namespace GameLogic; //player->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; break; } - + // send collision event message + ((Game*)&Game::Instance())->onCollisionEventFnc(player, CollisionEvent::CollisionEvent_BasicCollision); //return Physics::ICustomBody::SubscriptMessage_none; } @@ -255,16 +255,18 @@ using namespace GameLogic; { //realobjA is the affectedObject, transfer this to realobjB realObjB->SetAffectedBy(*realObjA->getAffectingPlayer()); + return; } if(realObjB->getAffectingPlayer() != NULL && realObjA->getAffectingPlayer() == NULL) { //realobjB is the affectedObject, transfer this to realobjA realObjA->SetAffectedBy(*realObjB->getAffectingPlayer()); + return; } - if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL) + if(realObjA->getAffectingPlayer() != NULL && realObjB->getAffectingPlayer() != NULL && ( realObjA->getAffectingPlayer()->GetID() != realObjB->getAffectingPlayer()->GetID())) { //Both objects have a player affecting them, now use the special case if(realObjA->GetRigidBody()->GetState().previousVelocity.GetMagnitude() > realObjB->GetRigidBody()->GetState().previousVelocity.GetMagnitude() ) @@ -368,14 +370,19 @@ using namespace GameLogic; Object* a = (Object*)objA->GetCustomTag(); Object* b = (Object*)objB->GetCustomTag(); - if(!a) + if(!a) return; - if(!b) + if(!b) return; if(b->GetObjectType() == ObjectSpecialType_Player) { - ((Pickup*)a)->OnCollision((Player*)(b)); + //Only update if it is active. And if the player is alive + if(((Pickup*)a)->IsActive() && ((Player*)b)->GetState() != PLAYER_STATE_DEAD && ((Player*)b)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)a)->OnCollision((Player*)(b)); + } + return; } else if(a->GetObjectType() != ObjectSpecialType_Player) { @@ -383,6 +390,10 @@ using namespace GameLogic; //Do nothing. return; } - - ((Pickup*)b)->OnCollision((Player*)a); + + //Only update if it is active. And if the player is alive + if(((Pickup*)b)->IsActive() && ((Player*)a)->GetState() != PLAYER_STATE_DEAD && ((Player*)a)->GetState() != PLAYER_STATE_DIED) + { + ((Pickup*)b)->OnCollision((Player*)a); + } } \ No newline at end of file diff --git a/Code/Game/GameLogic/DynamicObject.cpp b/Code/Game/GameLogic/DynamicObject.cpp index 844deaf2..d785b4d4 100644 --- a/Code/Game/GameLogic/DynamicObject.cpp +++ b/Code/Game/GameLogic/DynamicObject.cpp @@ -90,11 +90,6 @@ void DynamicObject::Activate() void DynamicObject::SetAffectedBy(Player &player) { this->affectedBy = &player; - if(this->type != ObjectSpecialType::ObjectSpecialType_Player) //should not add itself to its own list if its a player - { - player.AddAffectedObject(*this); - } - } Player* DynamicObject::getAffectingPlayer() diff --git a/Code/Game/GameLogic/Game.cpp b/Code/Game/GameLogic/Game.cpp index e4782582..87216b3b 100644 --- a/Code/Game/GameLogic/Game.cpp +++ b/Code/Game/GameLogic/Game.cpp @@ -182,12 +182,16 @@ void Game::SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) } void Game::SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) { - this->onPlayerActionEventFnc = functionPointer; + this->onActionEventFnc = functionPointer; } void Game::SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) { this->onPickupEventFnc = functionPointer; } +void Game::SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) +{ + this->onCollisionEventFnc = functionPointer; +} bool Game::Initiate() { API::Instance().Init(); diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 22b9fbda..28ad9772 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -87,6 +87,7 @@ namespace GameLogic void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) override; void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) override; void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) override; + void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) override; bool Initiate() override; float GetFrameTime() const; @@ -106,8 +107,9 @@ namespace GameLogic GameEvent::ObjectHpFunction onDamageTakenFnc; GameEvent::ObjectRespawnedFunction onRespawnFnc; GameEvent::ObjectDeadFunction onDeadFnc; - GameEvent::AnimationEventFunction onPlayerActionEventFnc; + GameEvent::AnimationEventFunction onActionEventFnc; GameEvent::PickupEventFunction onPickupEventFnc; + GameEvent::CollisionEventFunction onCollisionEventFnc; }; } diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 653fc26b..80b255bd 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -33,6 +33,7 @@ namespace GameLogic typedef void(*ObjectDeadFunction)(IObjectData* victim, IObjectData* killer, float seconds); // Callback method that sends killer and death timer typedef void(*PickupEventFunction)(IObjectData* player, int pickupEffectID ); // Callback method that sends killer and death timer typedef void(*AnimationEventFunction)(IObjectData* player, int actionID ); // Callback method that sends killer and death timer + typedef void(*CollisionEventFunction)(IObjectData*object, int collisionID); //etc... }; @@ -188,7 +189,7 @@ namespace GameLogic virtual void SetDeadSubscription(GameEvent::ObjectDeadFunction functionPointer) = 0; virtual void SetActionSubscription(GameEvent::AnimationEventFunction functionPointer) = 0; virtual void SetPickupSubscription(GameEvent::PickupEventFunction functionPointer) = 0; - + virtual void SetCollisionSubscription(GameEvent::CollisionEventFunction functionPointer) = 0; }; } diff --git a/Code/Game/GameLogic/Level.cpp b/Code/Game/GameLogic/Level.cpp index 5a6bfa09..be970c04 100644 --- a/Code/Game/GameLogic/Level.cpp +++ b/Code/Game/GameLogic/Level.cpp @@ -16,12 +16,11 @@ using namespace Oyster::Math; Level::Level(void) { - objID = 100; + srand (time(NULL)); + objIDCounter = 100; } Level::~Level(void) { - delete this->levelObj; - this->levelObj = NULL; } Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { @@ -31,7 +30,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) { case ObjectSpecialType_None: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; @@ -49,22 +48,22 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float worldSize = ((WorldAttributes*)obj)->worldSize; float atmosphereSize = ((WorldAttributes*)obj)->atmoSphereSize; - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Building: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Stone: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_StandardBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_RedExplosiveBox: @@ -72,7 +71,7 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) Oyster::Math::Float dmg = 120; Oyster::Math::Float force = 500; Oyster::Math::Float radie = 3; - gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++, dmg, force, radie); + gameObj = new ExplosiveCrate(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, dmg, force, radie); } break; //case ObjectSpecialType_BlueExplosiveBox: @@ -81,24 +80,24 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) // break; case ObjectSpecialType_SpikeBox: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_Spike: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalFormation: { int dmg = 50; //gameObj = new Crystal(rigidBody); - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_CrystalShard: { - gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new DynamicObject(rigidBody, DynamicObject::DynamicDefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_JumpPad: @@ -106,39 +105,28 @@ Object* Level::CreateGameObj(ObjectHeader* obj, ICustomBody* rigidBody) float power = 500; //((JumpPadAttributes*)obj)->power; Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction; Oyster::Math::Float3 pushForce = dir * power; - gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID , pushForce); + gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter , pushForce); } break; case ObjectSpecialType_Portal: { Oyster::Math::Float3 destination = ((PortalAttributes*)obj)->destination; - gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID, destination); - } - break; - //case ObjectSpecialType_SpawnPoint: - //{ - // save - - //} - break; - case ObjectSpecialType_Player: - { - // should not be read from the lvl format + gameObj = new Portal(rigidBody, (ObjectSpecialType)obj->specialTypeID, objIDCounter, destination); } break; case ObjectSpecialType_Generic: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; case ObjectSpecialType_PickupHealth: { - gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objID, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); + gameObj = new PickupHealth(rigidBody, obj->specialTypeID, objIDCounter, ((PickupHealthAttributes*)obj)->spawnTime, ((PickupHealthAttributes*)obj)->healthValue); } break; default: { - gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objID); + gameObj = new StaticObject(rigidBody, Object::DefaultOnCollision, (ObjectSpecialType)obj->specialTypeID, objIDCounter); } break; } @@ -264,7 +252,7 @@ bool Level::InitiateLevel(std::wstring levelPath) for (int i = 0; i < objCount; i++) { - ++this->objID; + ++this->objIDCounter; ObjectTypeHeader* obj = objects.at(i); switch (obj->typeID) { @@ -272,6 +260,7 @@ bool Level::InitiateLevel(std::wstring levelPath) { LevelMetaData* LevelObjData = ((LevelMetaData*)obj); std::string levelName = LevelObjData->levelName; + // LevelObjData->worldSize; } break; @@ -372,71 +361,6 @@ bool Level::InitiateLevel(std::wstring levelPath) return true; } -bool Level::InitiateLevel(float radius) -{ - API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0)); - API::Instance().SetGravity(200); - int idCount = 100; - // add level sphere - ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f); - - levelObj = new StaticObject(rigidBody, LevelCollisionAfter, ObjectSpecialType_World, idCount++); - - //this->levelObj->objectID = idCount++; - rigidBody->SetCustomTag(levelObj); - - - ICustomBody* rigidBody_TestBox; - - int nrOfBoxex = 5; - int offset = 0; - 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.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(0.0f, 605.0f + i*5.0f, 10.0f), 5.0f, 0.5f, 0.8f, 0.6f); - - 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::DefaultOnCollision, OBJECT_TYPE::OBJECT_TYPE_BOX)); - rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i+offset]); - - } - 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(200, 620 + ( i*7), 0), 5); - - 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; - 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(5, 605 + i*5, 0), 5); - - 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.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(10.0f, 605.0f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultOnCollision, ObjectSpecialType_StandardBox, idCount++)); - - // add house - ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20.0f, 20.0f, 20.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(-50.0f, 590.0f, 0.0f), 0.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultOnCollision, ObjectSpecialType_Generic, idCount++)); - - // add jumppad - - ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1.0f, 1.0f, 1.0f), Oyster::Math::Float4(0.0f, 0.0f, 0.0f, 1.0f), Oyster::Math::Float3(4.0f, 600.3f, 0.0f), 5.0f, 0.5f, 0.8f, 0.6f); - this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0))); - return true; -} void Level::AddPlayerToTeam(Player *player, int teamID) { @@ -444,6 +368,15 @@ void Level::AddPlayerToTeam(Player *player, int teamID) } void Level::AddPlayerToGame(Player *player) { + for(int i = 0; i < (int)this->playerObjects.Size(); i++) + { + if (!this->playerObjects[i]) + { + this->playerObjects[i] = player; + return; + } + } + // if no free space, allocate a new spot this->playerObjects.Push(player); } void Level::RemovePlayerFromGame(Player *player) @@ -452,7 +385,7 @@ void Level::RemovePlayerFromGame(Player *player) { if ((Player*)this->playerObjects[i] == player) { - //this->playerObjects[i]. + this->playerObjects[i] = nullptr; } } } @@ -465,14 +398,22 @@ void Level::RespawnPlayer(Player *player) { //this->teamManager.RespawnPlayerRandom(player); - Float3 spawnPoint = spawnPoints[0]; + int i = rand() % spawnPoints.Size(); + Float3 spawnPoint = spawnPoints[i]; player->Respawn(spawnPoint); } void Level::Update(float deltaTime) { // update lvl-things + + for(int i = 0; i < (int)this->playerObjects.Size(); i++) { + if(this->playerObjects[i]->getAffectingPlayer() != NULL) + { + + } + if (this->playerObjects[i]->GetState() == PLAYER_STATE::PLAYER_STATE_DEAD) { // true when timer reaches 0 @@ -483,9 +424,41 @@ void Level::Update(float deltaTime) { this->playerObjects[i]->setDeathTimer(DEATH_TIMER); // HACK to avoid crasch. affected by tag is NULL + //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID Player* killer = this->playerObjects[i]->getAffectingPlayer(); - ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i], DEATH_TIMER); // add killer ID - //((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], this->playerObjects[i]->getAffectingPlayer(), DEATH_TIMER); // add killer ID + if(!killer) //if there is no killer then you commited suicide + { + killer = this->playerObjects[i]; + } + ((Game*)&Game::Instance())->onDeadFnc(this->playerObjects[i], killer, DEATH_TIMER); // add killer ID + } + } + + for(int i = 0; i < dynamicObjects.Size(); i++) + { + if(dynamicObjects[i]->getAffectingPlayer() != NULL) + { + Oyster::Math::Float vel = dynamicObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude(); + + if(vel <= 0.1f) // is bearly moving + { + //set the tag AffectedBy to NULL + dynamicObjects[i]->RemoveAffectedBy(); + } + } + } + + for(int i = 0; i < playerObjects.Size(); i++) + { + if(playerObjects[i]->getAffectingPlayer() != NULL) + { + Oyster::Math::Float vel = playerObjects[i]->GetRigidBody()->GetLinearVelocity().GetMagnitude(); + + if(vel <= 0.1f) // is bearly moving + { + //set the tag AffectedBy to NULL + playerObjects[i]->RemoveAffectedBy(); + } } } @@ -511,7 +484,7 @@ void Level::PhysicsOnMoveLevel(const ICustomBody *object) Object* temp = (Object*)object->GetCustomTag(); ((Game*)&Game::Instance())->onMoveFnc(temp); } -Utility::DynamicMemory::DynamicArray> Level::GetPlayers() +Utility::DynamicMemory::DynamicArray Level::GetPlayers() { return this->playerObjects; } diff --git a/Code/Game/GameLogic/Level.h b/Code/Game/GameLogic/Level.h index ecd51018..1811c9af 100644 --- a/Code/Game/GameLogic/Level.h +++ b/Code/Game/GameLogic/Level.h @@ -35,7 +35,6 @@ namespace GameLogic * @param levelPath: Path to a file that contains all information on the level ********************************************************/ bool InitiateLevel(std::wstring levelPath); - bool InitiateLevel(float radius); Oyster::Physics::ICustomBody* InitRigidBodyCube( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodySphere( const ObjectHeader* obj); Oyster::Physics::ICustomBody* InitRigidBodyMesh( const ObjectHeader* obj); @@ -79,19 +78,19 @@ namespace GameLogic static void PlayerDied( Player* player ); static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object); - Utility::DynamicMemory::DynamicArray> GetPlayers(); + Utility::DynamicMemory::DynamicArray GetPlayers(); Utility::DynamicMemory::DynamicArray> GetStaticObjects(); Utility::DynamicMemory::DynamicArray> GetDynamicObject(); private: - Utility::DynamicMemory::DynamicArray> playerObjects; + Utility::DynamicMemory::DynamicArray playerObjects; TeamManager teamManager; Utility::DynamicMemory::DynamicArray> staticObjects; Utility::DynamicMemory::DynamicArray> dynamicObjects; GameModeType gameMode; - Utility::DynamicMemory::SmartPointer rigidBodyLevel; - StaticObject *levelObj; - int objID; + //Utility::DynamicMemory::SmartPointer rigidBodyLevel; +// //StaticObject *levelObj; + int objIDCounter; Utility::DynamicMemory::DynamicArray spawnPoints; PickupSystem pickupSystem; diff --git a/Code/Game/GameLogic/PickupSystem/Pickup.cpp b/Code/Game/GameLogic/PickupSystem/Pickup.cpp index 73a319f8..a7bcaf14 100644 --- a/Code/Game/GameLogic/PickupSystem/Pickup.cpp +++ b/Code/Game/GameLogic/PickupSystem/Pickup.cpp @@ -9,6 +9,7 @@ Pickup::Pickup(Oyster::Physics::ICustomBody *rigidBody, EventOnCollision collisi this->active = true; this->spawnTime = spawnTime; timer.reset(); + this->GetRigidBody()->MoveToLimbo(); } Pickup::~Pickup() diff --git a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp index 56cbef1e..5473c44c 100644 --- a/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp +++ b/Code/Game/GameLogic/PickupSystem/PickupHealth.cpp @@ -1,4 +1,5 @@ #include "PickupHealth.h" +#include "../Game.h" using namespace GameLogic; @@ -14,5 +15,8 @@ PickupHealth::~PickupHealth() void PickupHealth::OnCollision(Player *player) { timer.reset(); + ((Game*)&Game::Instance())->onDisableFnc(this); + + this->active = false; player->DamageLife(-hpValue); } \ No newline at end of file diff --git a/Code/Game/GameLogic/Player.cpp b/Code/Game/GameLogic/Player.cpp index 2800f1e8..4cd0f354 100644 --- a/Code/Game/GameLogic/Player.cpp +++ b/Code/Game/GameLogic/Player.cpp @@ -8,11 +8,11 @@ using namespace GameLogic; using namespace Oyster::Physics; const float MOVE_FORCE = 30; const float KEY_TIMER = 0.03f; +const float AFFECTED_TIMER = 1.0f; Player::Player() :DynamicObject() { Player::initPlayerData(); - AffectedObjects.Reserve(15); this->weapon = NULL; this->teamID = -1; } @@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision) { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } @@ -31,16 +30,15 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom { this->weapon = new Weapon(2,this); Player::initPlayerData(); - AffectedObjects.Reserve(15); this->teamID = teamID; } Player::~Player(void) { - if(weapon) + if(this->weapon) { - delete weapon; - weapon = NULL; + delete this->weapon; + this->weapon = NULL; } } void Player::initPlayerData() @@ -57,7 +55,7 @@ void Player::initPlayerData() this->key_strafeRight = 0; this->key_strafeLeft = 0; this->key_jump = 0; - this->invincibleCooldown = 0; + this->RecentlyAffected = 0; this->deathTimer = 0; this->rotationUp = 0; @@ -65,16 +63,19 @@ void Player::initPlayerData() void Player::BeginFrame() { - if( this->playerState != PLAYER_STATE_DEAD && PLAYER_STATE_DIED) + if( this->playerState != PLAYER_STATE_DEAD && this->playerState != PLAYER_STATE_DIED) { - weapon->Update(0.002f); + weapon->Update(0.002f); + + + Oyster::Math::Float maxSpeed = 30; // Rotate player accordingly this->rigidBody->AddRotationAroundY(this->rotationUp); this->rigidBody->SetUp(this->rigidBody->GetState().centerPos.GetNormalized()); - this->rotationUp = 0.0f; + this->rotationUp = 0; // Direction data Oyster::Math::Float4x4 xform; xform = this->rigidBody->GetState().GetOrientation(); @@ -138,7 +139,7 @@ void Player::BeginFrame() if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_IDLE) - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } } @@ -174,7 +175,7 @@ void Player::BeginFrame() if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) { if(this->playerState != PLAYER_STATE::PLAYER_STATE_WALKING) - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Walk); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Walk); this->playerState = PLAYER_STATE::PLAYER_STATE_WALKING; } } @@ -189,14 +190,14 @@ void Player::BeginFrame() //Jump if(key_jump > 0.001) { - this->key_jump -= this->gameInstance->GetFrameTime(); - if(IsWalking()) + this->key_jump -= this->gameInstance->GetFrameTime(); + if(IsWalking()) { Oyster::Math::Float3 up = this->rigidBody->GetState().centerPos.GetNormalized(); this->rigidBody->ApplyImpulse(up*this->rigidBody->GetState().mass * 20); if(this->playerState != PLAYER_STATE::PLAYER_STATE_JUMPING) - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Jump); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Jump); this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING; } } @@ -204,7 +205,7 @@ void Player::BeginFrame() { if(this->playerState == PLAYER_STATE::PLAYER_STATE_JUMPING) { - this->gameInstance->onPlayerActionEventFnc( this, PlayerAction::PlayerAction_Idle); + this->gameInstance->onActionEventFnc( this, PlayerAction::PlayerAction_Idle); this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE; } } @@ -213,16 +214,6 @@ void Player::BeginFrame() void Player::EndFrame() { - //check if there are any objects that can be removed from the AffectedObjects list - for(int i = 0; i < this->AffectedObjects.Size(); i++) - { - if(this->AffectedObjects[i] && (this->AffectedObjects[i]->GetRigidBody()->GetState().previousVelocity).GetMagnitude() <= 0.1f) - { - this->AffectedObjects[i]->RemoveAffectedBy(); - this->AffectedObjects.Remove(i); - } - - } } void Player::Move(const PLAYER_MOVEMENT &movement) @@ -292,7 +283,7 @@ void Player::SetLookDir(const Oyster::Math3D::Float3& lookDir) } void Player::TurnLeft(Oyster::Math3D::Float deltaRadians) { - this->rotationUp = deltaRadians; + this->rotationUp += deltaRadians; } void Player::Jump() @@ -341,32 +332,24 @@ PLAYER_STATE Player::GetState() const void Player::DamageLife(int damage) { - this->playerStats.hp -= damage; - // send hp to client - this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); - - if(this->playerStats.hp <= 0) + if(damage != 0) { - this->playerStats.hp = 0; - this->playerState = PLAYER_STATE_DIED; - } + this->playerStats.hp -= damage; -} + if(this->playerStats.hp > 100) + this->playerStats.hp = 100; -void Player::AddAffectedObject(DynamicObject &AffectedObject) -{ - //check if object already exists in the list, if so then do not add - for(int i = 0; i < AffectedObjects.Size(); i++) - { - if(AffectedObjects[i]->GetID() == AffectedObject.GetID()) + // send hp to client + this->gameInstance->onDamageTakenFnc( this, this->playerStats.hp); + + if(this->playerStats.hp <= 0) { - //object already exists, exit function - return; + this->playerStats.hp = 0; + this->playerState = PLAYER_STATE_DIED; } } - //else you add the object to the stack - AffectedObjects.Push(&AffectedObject); } + bool Player::deathTimerTick(float dt) { this->deathTimer -= dt; diff --git a/Code/Game/GameLogic/Player.h b/Code/Game/GameLogic/Player.h index c64ba066..edb4cc79 100644 --- a/Code/Game/GameLogic/Player.h +++ b/Code/Game/GameLogic/Player.h @@ -67,8 +67,6 @@ namespace GameLogic void SetLookDir(const Oyster::Math3D::Float3& lookDir); void TurnLeft(Oyster::Math3D::Float deltaRadians); - - void AddAffectedObject(DynamicObject &AffectedObject); /******************************************************** * Collision function for player, this is to be sent to physics through the subscribe function with the rigidbody @@ -90,6 +88,7 @@ namespace GameLogic Oyster::Math::Float4x4 GetOrientation() const; int GetTeamID() const; PLAYER_STATE GetState() const; + Oyster::Math::Float GetRecentlyAffected(); void DamageLife(int damage); void setDeathTimer(float deathTimer); @@ -104,8 +103,6 @@ namespace GameLogic void initPlayerData(); private: - - Utility::DynamicMemory::DynamicArray AffectedObjects; int teamID; Weapon *weapon; PLAYER_STATE playerState; @@ -122,7 +119,7 @@ namespace GameLogic float deathTimer; bool hasTakenDamage; - float invincibleCooldown; + Oyster::Math::Float RecentlyAffected; PlayerStats playerStats; PlayerScore playerScore; diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index 48fa71f7..9b469bbc 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -969,7 +969,7 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; } -//#define protocol_Gameplay_ObjectAction 369 + //#define protocol_Gameplay_ObjectAction 369 struct Protocol_ObjectAction :public Oyster::Network::CustomProtocolObject { short objectID; @@ -1010,4 +1010,46 @@ namespace GameLogic private: Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectCollision 370 + struct Protocol_ObjectCollision :public Oyster::Network::CustomProtocolObject + { + short objectID; + int collisionID; + // TODO: maybe position, impact, and velocity + + Protocol_ObjectCollision() + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = -1; + this->collisionID = -1; + } + Protocol_ObjectCollision(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netShort; + this->collisionID = p[2].value.netInt; + } + Protocol_ObjectCollision( int id, int collisionID) + { + this->protocol[0].value = protocol_Gameplay_ObjectCollision; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Short; + this->protocol[2].type = Oyster::Network::NetAttributeType_Int; + + this->objectID = id; + this->collisionID = collisionID; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = objectID; + this->protocol[2].value = collisionID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 02b1084a..eea1e945 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -73,6 +73,7 @@ #define protocol_Gameplay_ObjectDie 367 #define protocol_Gameplay_ObjectDisconnectPlayer 368 #define protocol_Gameplay_ObjectAction 369 +#define protocol_Gameplay_ObjectCollision 370 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 79b50395..d449ff2d 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -105,6 +105,7 @@ namespace DanBias static void ObjectDead ( GameLogic::IObjectData* victim, GameLogic::IObjectData* killer, float seconds ); static void PickupEvent ( GameLogic::IObjectData* movedObject, int pickupEffectID ); static void ActionEvent ( GameLogic::IObjectData* movedObject , int actionID ); + static void CollisionEvent ( GameLogic::IObjectData* Object , int collisionID ); //Private member variables private: Utility::DynamicMemory::DynamicArray gClients; diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 98d0f075..b993cb79 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -25,9 +25,6 @@ GameClient::GameClient(Utility::DynamicMemory::SmartPointerplayer) - this->player->Inactivate(); - delete this->player; this->isReady = false; diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index fd000a0c..ceb22431 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -152,7 +152,7 @@ using namespace DanBias; } void GameSession::ObjectEnabled( GameLogic::IObjectData* movedObject ) { - GameSession::gameSession->Send(Protocol_ObjectDisable(movedObject->GetID()).GetProtocol()); + GameSession::gameSession->Send(Protocol_ObjectEnable(movedObject->GetID()).GetProtocol()); } void GameSession::ObjectDamaged( GameLogic::IObjectData* movedObject, float hp ) { @@ -176,6 +176,11 @@ using namespace DanBias; // send action protocol GameSession::gameSession->Send(Protocol_ObjectAction(movedObject->GetID(), actionID).GetProtocol()); } + void GameSession::CollisionEvent( GameLogic::IObjectData* movedObject , int collisionID ) + { + // send action protocol + GameSession::gameSession->Send(Protocol_ObjectCollision(movedObject->GetID(), collisionID).GetProtocol()); + } //*****************************************************// //****************** Protocol methods *****************// //******************************************************************************************************************// diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index ca869fb7..d19fcecf 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -114,6 +114,7 @@ bool GameSession::Create(GameDescription& desc, bool forceStart) this->gameInstance.SetDeadSubscription(GameSession::ObjectDead); this->gameInstance.SetActionSubscription(GameSession::ActionEvent); this->gameInstance.SetPickupSubscription(GameSession::PickupEvent); + this->gameInstance.SetCollisionSubscription(GameSession::CollisionEvent); this->gameInstance.SetFPS(60); this->description.clients.Clear(); diff --git a/Code/Game/LevelLoader/LevelParser.cpp b/Code/Game/LevelLoader/LevelParser.cpp index 680b0358..f94513b0 100644 --- a/Code/Game/LevelLoader/LevelParser.cpp +++ b/Code/Game/LevelLoader/LevelParser.cpp @@ -167,6 +167,14 @@ std::vector> LevelParser::Parse(std::string filen ParseObject(&buffer[counter], &header->healthValue, 4); counter += 4; + + // DEBUG + header->position[1] = 150; + header->spawnTime = 5; + header->boundingVolume.box.mass = 0; + header->typeID = ObjectType_Static; + header->healthValue = 50; + // !DEBUG objects.push_back(header); break; diff --git a/Code/Game/LevelLoader/ObjectDefines.h b/Code/Game/LevelLoader/ObjectDefines.h index 3eae71a5..e77174f7 100644 --- a/Code/Game/LevelLoader/ObjectDefines.h +++ b/Code/Game/LevelLoader/ObjectDefines.h @@ -95,16 +95,26 @@ namespace GameLogic enum PlayerAction { - PlayerAction_Jump, - PlayerAction_Walk, - PlayerAction_Idle, + PlayerAction_Jump = 0, + PlayerAction_Walk = 1, + PlayerAction_Idle = 2, }; + // continue ID counting from playerAction enum WeaponAction { - WeaponAtcion_PrimaryShoot, - WeaponAction_SecondaryShoot + WeaponAction_PrimaryShoot = 3, + WeaponAction_SecondaryShoot = 4, + WeaponAction_UtilityActivate = 5, + WeaponAction_Reload = 6, + WeaponAction_EnergyDepleted = 7, + }; + // TODO: add more collision Events + enum CollisionEvent + { + CollisionEvent_BasicCollision, + }; enum PickupType { PickupType_Health, diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp index 7fbd44e8..7a8665a1 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.cpp @@ -177,7 +177,6 @@ void SimpleRigidBody::AddRotationAroundY(::Oyster::Math::Float angle) this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w()); } - void SimpleRigidBody::SetAngularFactor(Float factor) { this->rigidBody->setAngularFactor(factor); @@ -246,18 +245,18 @@ void SimpleRigidBody::SetUp(::Oyster::Math::Float3 up) btQuaternion q; btVector3 a = v1.cross(v2); - - if (v1.dot(v2) < -0.999999) + + if (v1.dot(v2) < -0.999999) { btVector3 xCrossPre = btVector3(1, 0 ,0).cross(v1); if(xCrossPre.length() < 0.000001) xCrossPre = btVector3(0, 1 ,0).cross(v1); xCrossPre.normalize(); q.setRotation(xCrossPre, 3.1415); - } - else if (v1.dot(v2) > 0.999999) + } + else if (v1.dot(v2) > 0.999999) { - q = btQuaternion(0, 0, 0, 1); + q = btQuaternion(0, 0, 0, 1); } else { diff --git a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h index dc1158d7..3e478524 100644 --- a/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h +++ b/Code/Physics/GamePhysics/Implementation/SimpleRigidBody.h @@ -29,7 +29,7 @@ namespace Oyster void SetRotation(Math::Quaternion quaternion); void SetRotation(Math::Float3 eulerAngles); void SetRotation(::Oyster::Math::Float4x4 rotation); - void AddRotationAroundY(Math::Float angle); + void AddRotationAroundY(::Oyster::Math::Float angle); void SetAngularFactor(Math::Float factor); void SetMass(Math::Float mass);