collision and refrence managers updated

This commit is contained in:
Erik Persson 2013-11-28 11:23:11 +01:00
parent 9bddfc9ffa
commit 42948a1412
8 changed files with 86 additions and 24 deletions

View File

@ -4,10 +4,11 @@
namespace GameLogic namespace GameLogic
{ {
namespace CollisionManager namespace CollisionManager
{ {
void ColisionEvent(Oyster::Physics::ICustomBody &obj1, Oyster::Physics::ICustomBody &obj2) 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) void PlayerVBox(Player &player, DynamicObject &box)
{ {
//spela ljud? ta skada? etc etc //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;
}
}
} }
} }

View File

@ -9,14 +9,17 @@
namespace GameLogic namespace GameLogic
{ {
RefManager refManager;
namespace CollisionManager 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);
}; };
} }

View File

@ -31,7 +31,5 @@ void Game::Update(keyInput keyPressed)
} }
void Game::Render() void Game::Render()
{ {
Oyster::Graphics::Model::Model* model_Arr; player->Render();
model_Arr = player->Render();
Oyster::Graphics::API::RenderScene(model_Arr, 1);
} }

View File

@ -10,13 +10,24 @@ using namespace Oyster::Math;
using namespace Oyster::Graphics::Model; using namespace Oyster::Graphics::Model;
using namespace Utility::DynamicMemory; using namespace Utility::DynamicMemory;
using namespace Oyster::Physics;
Object::Object(void) Object::Object(void)
{ {
model = new Model(); model = new Model();
model = Oyster::Graphics::API::CreateModel(L"bth.obj"); 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); 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); this->rigidBody->GetOrientation(model->WorldMatrix);
return model; Oyster::Graphics::API::RenderScene(model, 1);
} }

View File

@ -28,7 +28,7 @@ namespace GameLogic
OBJECT_TYPE_BOX, OBJECT_TYPE_BOX,
}; };
Oyster::Graphics::Model::Model* Render(); void Render();
OBJECT_TYPE GetType(); OBJECT_TYPE GetType();

View File

@ -13,16 +13,6 @@ Player::Player(void)
:Object() :Object()
{ {
life = 100; 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);
} }

View File

@ -4,6 +4,8 @@ using namespace GameLogic;
typedef std::pair<Oyster::Physics::ICustomBody*, Object*> mapData; typedef std::pair<Oyster::Physics::ICustomBody*, Object*> mapData;
RefManager* RefManager::instance = 0;
RefManager::RefManager(void) 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) Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body)
{ {
return mapper[&body]; return mapper[&body];

View File

@ -19,13 +19,19 @@ namespace GameLogic
RefManager(void); RefManager(void);
~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 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 void AddMapping(Oyster::Physics::ICustomBody &body, Object &obj); //adds a mapping with body as key and the object as a value
private: private:
static RefManager* instance;
std::map<Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object std::map<Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
}; };
} }
#endif #endif