GL - updated constructors to set before and after collision response functions

This commit is contained in:
lindaandersson 2014-01-29 14:33:21 +01:00
parent 3a9c47722a
commit 446bdd412b
13 changed files with 173 additions and 128 deletions

View File

@ -64,10 +64,18 @@ using namespace GameLogic;
}
}
//Oyster::Physics::ICustomBody::SubscriptMessage
void Level::LevelCollision(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
Oyster::Physics::ICustomBody::SubscriptMessage Object::DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{
//return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
return Physics::ICustomBody::SubscriptMessage_none;
}
//Oyster::Physics::ICustomBody::SubscriptMessage
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
{
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
}
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
{
return Physics::ICustomBody::SubscriptMessage_ignore_collision_response;
}
void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj, void* args)

View File

@ -7,21 +7,34 @@ using namespace GameLogic;
DynamicObject::DynamicObject()
:Object()
{
}
DynamicObject::DynamicObject(void* collisionFunc, OBJECT_TYPE type)
:Object(collisionFunc, type)
}
DynamicObject::DynamicObject(OBJECT_TYPE type)
:Object(type)
{
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
:Object(rigidBody,type)
{
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFunc, type)
DynamicObject::DynamicObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:Object(collisionFuncBefore,collisionFuncAfter,type)
{
}
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
{
}
DynamicObject::DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
{
}
DynamicObject::~DynamicObject(void)
{

View File

@ -14,8 +14,12 @@ namespace GameLogic
public:
DynamicObject();
DynamicObject(void* collisionFunc, OBJECT_TYPE type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
DynamicObject(OBJECT_TYPE type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
DynamicObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
DynamicObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~DynamicObject(void);
private:

View File

@ -100,30 +100,6 @@ bool Game::NewFrame()
API::Instance().Update();
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->BeginFrame();
}
API::Instance().Update();
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->BeginFrame();
}
API::Instance().Update();
for (unsigned int i = 0; i < this->players.Size(); i++)
{
if(this->players[i]->player) this->players[i]->player->EndFrame();

View File

@ -4,16 +4,19 @@
using namespace GameLogic;
Game::PlayerData::PlayerData()
{
Oyster::Physics::API::SimpleBodyDescription sbDesc;
{
//set some stats that are appropriate to a player
Oyster::Physics::API::SimpleBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float3(0,15,0);
sbDesc.size = Oyster::Math::Float3(4,7,4);
//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,Player::PlayerCollision,OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this);
}
Game::PlayerData::PlayerData(int playerID,int teamID)
{

View File

@ -20,6 +20,7 @@ void Level::InitiateLevel(std::string levelPath)
}
void Level::InitiateLevel(float radius)
{
// add level sphere
API::SphericalBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
@ -33,8 +34,8 @@ void Level::InitiateLevel(float radius)
rigidBody->GetState(state);
state.SetRestitutionCoeff(0.01);
rigidBody->SetState(state);
levelObj = new StaticObject(rigidBody, LevelCollision, OBJECT_TYPE::OBJECT_TYPE_WORLD);
levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD);
rigidBody->SetCustomTag(levelObj);
@ -47,7 +48,8 @@ void Level::InitiateLevel(float radius)
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
testBox = new DynamicObject(rigidBody_TestBox,LevelCollision,OBJECT_TYPE::OBJECT_TYPE_BOX);
testBox = new DynamicObject(rigidBody_TestBox, OBJECT_TYPE::OBJECT_TYPE_BOX);
rigidBody_TestBox->SetCustomTag(testBox);
rigidBody_TestBox->GetState(state);
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,4));

View File

@ -57,8 +57,9 @@ namespace GameLogic
* @param rigidBodyLevel: physics object of the level
* @param obj: physics object for the object that collided with the level
********************************************************/
static void LevelCollision(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
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);
Object* GetObj( int ID ) const;
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);

View File

@ -16,59 +16,78 @@ const Game *Object::gameInstance = (Game*)(&Game::Instance());
Object::Object()
{
API::SimpleBodyDescription sbDesc;
//sbDesc.centerPosition =
//poi
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
//rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
this->objectID = GID();
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
Object::Object(void* collisionFunc, OBJECT_TYPE type)
Object::Object(OBJECT_TYPE type)
{
API::SimpleBodyDescription sbDesc;
//poi
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
//rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
//rigidBody->gameObjectRef = this;
this->objectID = GID();
this->type = type;
this->objectID = GID();
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
Object::Object(ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type)
Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
{
Oyster::Physics::API::Instance().AddObject(rigidBody);
//rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
this->objectID = GID();
this->type = type;
}
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
{
Oyster::Physics::API::Instance().AddObject(rigidBody);
//rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
this->rigidBody = rigidBody;
this->type = type;
this->objectID = GID();
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
{
API::SimpleBodyDescription sbDesc;
this->rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
Oyster::Physics::API::Instance().AddObject(rigidBody);
this->type = type;
this->objectID = GID();
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
{
Oyster::Physics::API::Instance().AddObject(rigidBody);
this->rigidBody = rigidBody;
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
this->type = type;
this->objectID = GID();
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
{
Oyster::Physics::API::Instance().AddObject(rigidBody);
this->rigidBody = rigidBody;
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_BeforeCollisionResponse)(collisionFuncBefore));
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
this->type = type;
this->objectID = GID();
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
void Object::ApplyLinearImpulse(Oyster::Math::Float3 force)
@ -107,19 +126,12 @@ void Object::BeginFrame()
void Object::EndFrame()
{
//Oyster::Math::Float rot = (setState.GetGravityNormal().xyz).Dot(getState.GetGravityNormal().xyz);
//Oyster::Math::Float3 axis = (setState.GetGravityNormal().xyz).Cross(getState.GetGravityNormal().xyz);
Oyster::Math::Float4x4 rotMatrix = setState.GetOrientation(); //Oyster::Math3D::RotationMatrix(rot, axis);
//Oyster::Math3D::SnapAxisYToNormal_UsingNlerp(rotMatrix, -setState.GetGravityNormal());
//setState.SetOrientation(rotMatrix);
this->getState = this->rigidBody->GetState();
this->setState = this->getState;
}
Oyster::Math::Float3 Object::GetPosition()
{

View File

@ -18,9 +18,11 @@ namespace GameLogic
{
public:
Object();
Object(void* collisionFunc, OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
Object(OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Object(void);
// API overrides
@ -35,7 +37,7 @@ namespace GameLogic
void BeginFrame();
void EndFrame();
static Oyster::Physics::ICustomBody::SubscriptMessage DefaultCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
private:
OBJECT_TYPE type;
int objectID;

View File

@ -8,20 +8,38 @@ using namespace GameLogic;
using namespace Oyster::Physics;
Player::Player()
:DynamicObject(Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER)
:DynamicObject()
{
weapon = new Weapon();
life = 100;
teamID = -1;
playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float4(0,0,-1,0);
setState.SetCenterPosition(Oyster::Math::Float3(0,15,0));
setState.SetReach(Oyster::Math::Float3(2,3.5,2));
}
Player::Player(OBJECT_TYPE type)
:DynamicObject(type)
{
InitPlayer();
}
Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
:DynamicObject(rigidBody,type)
{
InitPlayer();
}
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:DynamicObject(rigidBody, collisionFunc, type)
Player::Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:DynamicObject(collisionFuncBefore,collisionFuncAfter,type)
{
InitPlayer();
}
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
{
InitPlayer();
}
Player::Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:DynamicObject(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
{
InitPlayer();
}
void Player::InitPlayer()
{
weapon = new Weapon(2,this);
@ -29,9 +47,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oy
this->teamID = -1;
this->playerState = PLAYER_STATE_IDLE;
lookDir = Oyster::Math::Float4(0,0,-1,0);
setState.SetCenterPosition(Oyster::Math::Float3(0,15,0));
setState.SetReach(Oyster::Math::Float3(2,3.5,2));
}
Player::~Player(void)
@ -40,11 +55,9 @@ Player::~Player(void)
{
delete weapon;
weapon = NULL;
}
}
}
void Player::Move(const PLAYER_MOVEMENT &movement)
{
switch(movement)

View File

@ -16,8 +16,13 @@ namespace GameLogic
{
public:
Player(void);
Player(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
Player(OBJECT_TYPE type);
Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
Player(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
Player(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Player(void);
void InitPlayer();
/********************************************************
* Moves the player based on input

View File

@ -8,29 +8,33 @@ StaticObject::StaticObject()
:Object()
{
}
StaticObject::StaticObject(void* collisionFunc, OBJECT_TYPE type)
:Object(collisionFunc,type)
{
}
StaticObject::StaticObject(OBJECT_TYPE type)
:Object(NULL,type)
:Object(type)
{
}
/*StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisionFunc, OBJECT_TYPE type)
:Object(rigidBody,collisionFunc,type)
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
:Object(rigidBody,type)
{
}*/
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFunc, type)
{
}
StaticObject::StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:Object(collisionFuncBefore,collisionFuncAfter,type)
{
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
{
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFuncBefore, collisionFuncAfter, type)
{
}
StaticObject::~StaticObject(void)
{

View File

@ -16,10 +16,12 @@ namespace GameLogic
public:
StaticObject();
StaticObject(void* collisionFunc, OBJECT_TYPE type);
//StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisionFunc, OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
StaticObject(OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type);
StaticObject(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type);
StaticObject(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~StaticObject(void);
private: