GL uppdate game test progam for physics
This commit is contained in:
parent
10c786b745
commit
804c5df7a9
|
@ -1,6 +1,6 @@
|
|||
#include "CollisionManager.h"
|
||||
|
||||
|
||||
using namespace Oyster;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
@ -8,10 +8,10 @@ namespace GameLogic
|
|||
namespace CollisionManager
|
||||
{
|
||||
|
||||
void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj)
|
||||
Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj)
|
||||
{
|
||||
Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyPlayer));
|
||||
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj);
|
||||
Player *player = ((Player*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyPlayer));
|
||||
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj);
|
||||
|
||||
switch (realObj->GetType())
|
||||
{
|
||||
|
@ -24,6 +24,7 @@ namespace GameLogic
|
|||
}
|
||||
|
||||
//spela ljud? ta skada? etc etc
|
||||
return Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
|
||||
void PlayerVBox(Player &player, DynamicObject &box)
|
||||
|
@ -31,10 +32,10 @@ namespace GameLogic
|
|||
//spela ljud? ta skada? etc etc
|
||||
}
|
||||
|
||||
void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj)
|
||||
Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj)
|
||||
{
|
||||
DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(rigidBodyBox));
|
||||
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(obj);
|
||||
DynamicObject *box = ((DynamicObject*)GameLogic::RefManager::getInstance()->GetMap(*rigidBodyBox));
|
||||
Object *realObj = GameLogic::RefManager::getInstance()->GetMap(*obj);
|
||||
|
||||
switch (realObj->GetType())
|
||||
{
|
||||
|
@ -45,6 +46,8 @@ namespace GameLogic
|
|||
PlayerVBox(*(Player*)realObj,*box);
|
||||
break;
|
||||
}
|
||||
|
||||
return Physics::ICustomBody::SubscriptMessage_none;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,8 +13,9 @@ namespace GameLogic
|
|||
namespace CollisionManager
|
||||
{
|
||||
//these are the main collision functions
|
||||
void PlayerCollision(Oyster::Physics::ICustomBody &rigidBodyPlayer,Oyster::Physics::ICustomBody &obj);
|
||||
void BoxCollision(Oyster::Physics::ICustomBody &rigidBodyBox, Oyster::Physics::ICustomBody &obj);
|
||||
//typedef SubscriptMessage (*EventAction_Collision)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||
Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollision(const Oyster::Physics::ICustomBody *rigidBodyPlayer, const Oyster::Physics::ICustomBody *obj);
|
||||
Oyster::Physics::ICustomBody::SubscriptMessage BoxCollision(const Oyster::Physics::ICustomBody *rigidBodyBox, const Oyster::Physics::ICustomBody *obj);
|
||||
|
||||
//these are the specific collision case functions
|
||||
void PlayerVBox(Player &player, DynamicObject &box);
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#include "DynamicObject.h"
|
||||
#include "CollisionManager.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
using namespace Oyster::Physics;
|
||||
using namespace Utility::DynamicMemory;
|
||||
|
||||
DynamicObject::DynamicObject(void)
|
||||
:Object()
|
||||
DynamicObject::DynamicObject(std::wstring objFile)
|
||||
:Object(objFile)
|
||||
{
|
||||
rigidBody->SetSubscription(CollisionManager::BoxCollision);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace GameLogic
|
|||
{
|
||||
|
||||
public:
|
||||
DynamicObject(void);
|
||||
DynamicObject(std::wstring objFile);
|
||||
~DynamicObject(void);
|
||||
|
||||
void Update();
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Game.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
|
||||
Game::Game(void)
|
||||
|
@ -26,7 +27,13 @@ Game::~Game(void)
|
|||
|
||||
void Game::Init()
|
||||
{
|
||||
player = new Player();
|
||||
//Oyster::Physics::API::SetSubscription("remove object");
|
||||
|
||||
player = new Player(L"worldDummy");
|
||||
|
||||
box = new DynamicObject(L"crate");
|
||||
//poi
|
||||
//box = new physcTestObj("box");
|
||||
camera = new Camera();
|
||||
}
|
||||
void Game::StartGame()
|
||||
|
@ -60,9 +67,11 @@ void Game::Update(keyInput keyPressed, float pitch, float yaw)
|
|||
camera->Walk(0.1);
|
||||
}
|
||||
camera->UpdateViewMatrix();
|
||||
//poi Oyster::Physics::API::Update();
|
||||
}
|
||||
void Game::Render()
|
||||
{
|
||||
Oyster::Graphics::API::NewFrame(camera->View(), camera->Proj());
|
||||
player->Render();
|
||||
box->Render();
|
||||
}
|
|
@ -21,6 +21,7 @@ namespace GameLogic
|
|||
|
||||
private:
|
||||
Level* level;
|
||||
DynamicObject* box;
|
||||
Player* player;
|
||||
Camera* camera;
|
||||
};
|
||||
|
|
|
@ -12,15 +12,16 @@ using namespace Oyster::Graphics::Model;
|
|||
using namespace Utility::DynamicMemory;
|
||||
using namespace Oyster::Physics;
|
||||
|
||||
Object::Object(void)
|
||||
Object::Object(std::wstring objFile)
|
||||
{
|
||||
|
||||
model = new Model();
|
||||
model = Oyster::Graphics::API::CreateModel(L"orca");
|
||||
//model = new Model();
|
||||
model = Oyster::Graphics::API::CreateModel(objFile);
|
||||
|
||||
API::SimpleBodyDescription sbDesc;
|
||||
//sbDesc.centerPosition =
|
||||
|
||||
//poi
|
||||
ICustomBody* temp = rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
||||
|
||||
GameLogic::RefManager::getInstance()->AddMapping(*rigidBody, *this);
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace GameLogic
|
|||
OBJECT_TYPE_PLAYER,
|
||||
OBJECT_TYPE_BOX,
|
||||
};
|
||||
Object(void);
|
||||
Object(std::wstring objFile );
|
||||
virtual ~Object(void);
|
||||
|
||||
void Render();
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#include "Player.h"
|
||||
#include "OysterMath.h"
|
||||
#include "CollisionManager.h"
|
||||
|
||||
using namespace GameLogic;
|
||||
using namespace Oyster::Physics;
|
||||
|
||||
Player::Player(void)
|
||||
:Object()
|
||||
Player::Player(std::wstring objFile)
|
||||
:Object( objFile )
|
||||
{
|
||||
life = 100;
|
||||
rigidBody->SetSubscription(CollisionManager::PlayerCollision);
|
||||
}
|
||||
Player::~Player(void)
|
||||
{
|
||||
|
@ -16,6 +18,7 @@ Player::~Player(void)
|
|||
|
||||
void Player::Update(keyInput keyPressed)
|
||||
{
|
||||
|
||||
if(keyPressed != keyInput_none)
|
||||
{
|
||||
Move(keyPressed);
|
||||
|
@ -24,6 +27,7 @@ void Player::Update(keyInput keyPressed)
|
|||
|
||||
void Player::Move(keyInput keyPressed)
|
||||
{
|
||||
|
||||
if(keyPressed == keyInput_A)
|
||||
{
|
||||
Oyster::Math::Float3 pos = this->rigidBody->GetCenter();
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace GameLogic
|
|||
{
|
||||
|
||||
public:
|
||||
Player(void);
|
||||
Player(std::wstring objFile);
|
||||
~Player(void);
|
||||
|
||||
/********************************************************
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
using namespace GameLogic;
|
||||
|
||||
typedef std::pair<Oyster::Physics::ICustomBody*, Object*> mapData;
|
||||
typedef std::pair<const Oyster::Physics::ICustomBody*, Object*> mapData;
|
||||
|
||||
RefManager* RefManager::instance = 0;
|
||||
|
||||
|
@ -34,12 +34,12 @@ RefManager* RefManager::getInstance( )
|
|||
return instance;
|
||||
}
|
||||
|
||||
Object* RefManager::GetMap(Oyster::Physics::ICustomBody &body)
|
||||
Object* RefManager::GetMap(const Oyster::Physics::ICustomBody &body)
|
||||
{
|
||||
return mapper[&body];
|
||||
}
|
||||
|
||||
void RefManager::AddMapping(Oyster::Physics::ICustomBody &body, Object &obj)
|
||||
void RefManager::AddMapping( const Oyster::Physics::ICustomBody &body, Object &obj)
|
||||
{
|
||||
mapper.insert(mapData(&body,&obj));
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ namespace GameLogic
|
|||
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
|
||||
Object* GetMap(const Oyster::Physics::ICustomBody &body); //returns the object of an rigidBody, mainly used for CollisionHandler
|
||||
void AddMapping(const 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<Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
|
||||
std::map<const Oyster::Physics::ICustomBody*,Object*> mapper; //mapper points a rigidBody to an actual game object
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
using namespace GameLogic;
|
||||
|
||||
StaticObject::StaticObject(void)
|
||||
StaticObject::StaticObject(std::wstring objFile)
|
||||
:Object(objFile)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace GameLogic
|
|||
{
|
||||
|
||||
public:
|
||||
StaticObject(void);
|
||||
StaticObject(std::wstring objFile);
|
||||
~StaticObject(void);
|
||||
|
||||
};
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
using namespace GameLogic;
|
||||
|
||||
Weapon::Weapon(void)
|
||||
Weapon::Weapon(std::wstring objFile)
|
||||
:Object(objFile)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace GameLogic
|
|||
{
|
||||
|
||||
public:
|
||||
Weapon(void);
|
||||
Weapon(std::wstring objFile);
|
||||
~Weapon(void);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue