diff --git a/Code/GameLogic/CollisionManager.cpp b/Code/GameLogic/CollisionManager.cpp index 86f7c37a..253056cc 100644 --- a/Code/GameLogic/CollisionManager.cpp +++ b/Code/GameLogic/CollisionManager.cpp @@ -4,10 +4,11 @@ namespace GameLogic { - namespace CollisionManager { + + void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2) @@ -39,9 +40,43 @@ namespace GameLogic } + void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj) + { + Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyPlayer)); + Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj); + + switch (realObj->GetType()) + { + case Object::OBJECT_TYPE_BOX: + PlayerVBox(*player,(*(DynamicObject*) realObj)); + break; + case Object::OBJECT_TYPE_PLAYER: + + break; + } + + //spela ljud? ta skada? etc etc + } + void PlayerVBox(Player &player, DynamicObject &box) { //spela ljud? ta skada? etc etc } + + void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj) + { + DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyBox)); + Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj); + + switch (realObj->GetType()) + { + case Object::OBJECT_TYPE_BOX: + + break; + case Object::OBJECT_TYPE_PLAYER: + PlayerVBox(*(Player*)realObj,*box); + break; + } + } } } \ No newline at end of file diff --git a/Code/GameLogic/CollisionManager.h b/Code/GameLogic/CollisionManager.h index eedac2cc..878d6f25 100644 --- a/Code/GameLogic/CollisionManager.h +++ b/Code/GameLogic/CollisionManager.h @@ -9,14 +9,17 @@ namespace GameLogic { - RefManager refManager; namespace CollisionManager { + void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj); + void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj); - void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2); - void PlayerVBox(Player &player, DynamicObject &box); + + void PlayerVBox(Player &player, DynamicObject &box); + void BoxVBox(DynamicObject &box1, DynamicObject &box2); + }; } diff --git a/Code/GameLogic/Game.cpp b/Code/GameLogic/Game.cpp index 5b3af050..6d6d367d 100644 --- a/Code/GameLogic/Game.cpp +++ b/Code/GameLogic/Game.cpp @@ -31,7 +31,5 @@ void Game::Update(keyInput keyPressed) } void Game::Render() { - Oyster::Graphics::Model::Model* model_Arr; - model_Arr = player->Render(); - Oyster::Graphics::API::RenderScene(model_Arr, 1); + player->Render(); } \ No newline at end of file diff --git a/Code/GameLogic/Object.cpp b/Code/GameLogic/Object.cpp index 21087448..a83d1fb6 100644 --- a/Code/GameLogic/Object.cpp +++ b/Code/GameLogic/Object.cpp @@ -10,13 +10,24 @@ using namespace Oyster::Math; using namespace Oyster::Graphics::Model; using namespace Utility::DynamicMemory; +using namespace Oyster::Physics; Object::Object(void) { model = new Model(); model = Oyster::Graphics::API::CreateModel(L"bth.obj"); - refManager.AddMapping(*rigidBody, *this); + + ICustomBody* temp = rigidBody = API::Instance().CreateSimpleRigidBody().Release(); + + rigidBody->SetCenter(Float3(50,0,0)); + rigidBody->SetMass_KeepMomentum(30); + rigidBody->SetSize(Float3(2,2,2)); + rigidBody->SetSubscription(true); + rigidBody->SetMomentOfInertiaTensor_KeepMomentum(Float4x4(MomentOfInertia::CreateCuboidMatrix(30, 2, 2, 2))); + + + GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this); } @@ -27,13 +38,11 @@ Object::~Object(void) Oyster::Graphics::API::DeleteModel(model); } -Model* Object::Render() -{ - //Oyster::Graphics::API::RenderScene(model,1); - //model->info->Vertices.Apply(0); +void Object::Render() +{ this->rigidBody->GetOrientation(model->WorldMatrix); - return model; + Oyster::Graphics::API::RenderScene(model, 1); } diff --git a/Code/GameLogic/Object.h b/Code/GameLogic/Object.h index 57ec2c67..be2f77a6 100644 --- a/Code/GameLogic/Object.h +++ b/Code/GameLogic/Object.h @@ -28,7 +28,7 @@ namespace GameLogic OBJECT_TYPE_BOX, }; - Oyster::Graphics::Model::Model* Render(); + void Render(); OBJECT_TYPE GetType(); diff --git a/Code/GameLogic/Player.cpp b/Code/GameLogic/Player.cpp index f507e581..3a9ae029 100644 --- a/Code/GameLogic/Player.cpp +++ b/Code/GameLogic/Player.cpp @@ -13,16 +13,6 @@ Player::Player(void) :Object() { life = 100; - - Oyster::Physics::ICustomBody* temp = rigidBody = API::Instance().CreateSimpleRigidBody().Release(); - - rigidBody->SetCenter(Oyster::Math::Float3(50,0,0)); - rigidBody->SetMass_KeepMomentum(30); - rigidBody->SetSize(Oyster::Math::Float3(2,2,2)); - rigidBody->SetSubscription(true); - rigidBody->SetMomentOfInertiaTensor_KeepMomentum(Oyster::Math::Float4x4( Oyster::Physics::MomentOfInertia::CreateCuboidMatrix(30, 2, 2, 2))); - - //API::Instance().AddObject(temp); } diff --git a/Code/GameLogic/RefManager.cpp b/Code/GameLogic/RefManager.cpp index 022ec6bb..a119898c 100644 --- a/Code/GameLogic/RefManager.cpp +++ b/Code/GameLogic/RefManager.cpp @@ -4,6 +4,8 @@ using namespace GameLogic; typedef std::pair mapData; +RefManager* RefManager::instance = 0; + RefManager::RefManager(void) { } @@ -13,6 +15,25 @@ RefManager::~RefManager(void) { } +void RefManager::Release() +{ + if (instance) + { + delete instance; + instance = NULL; + } + +} + +RefManager* RefManager::getInstance( ) +{ + if (!instance) + { + instance = new RefManager(); + }; + return instance; +} + Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body) { return mapper[&body]; diff --git a/Code/GameLogic/RefManager.h b/Code/GameLogic/RefManager.h index 4ab0f1e4..b5fd91d2 100644 --- a/Code/GameLogic/RefManager.h +++ b/Code/GameLogic/RefManager.h @@ -19,13 +19,19 @@ namespace GameLogic RefManager(void); ~RefManager(void); + static RefManager* getInstance( ); + void Release(); + + Object* GetMap(Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value private: + static RefManager* instance; std::map mapper; //mapper points a rigidBody to an actual game object + }; } #endif \ No newline at end of file