GL - collision working, going to merge with physics
This commit is contained in:
parent
3b552d5361
commit
16334ea2db
|
@ -3,6 +3,10 @@
|
||||||
|
|
||||||
namespace DanBias
|
namespace DanBias
|
||||||
{
|
{
|
||||||
|
inline bool IsLobbyProtocol(short ID) { return (ID >= protocol_LobbyMIN && ID <= protocol_LobbyMAX); }
|
||||||
|
inline bool IsGeneralProtocol(short ID) { return (ID >= protocol_GeneralMIN && ID <= protocol_GeneralMAX); }
|
||||||
|
inline bool IsGameplayProtocol(short ID) { return (ID >= protocol_GameplayMIN && ID <= protocol_GameplayMAX); }
|
||||||
|
|
||||||
struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
|
struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
|
||||||
{
|
{
|
||||||
Oyster::Network::NetworkClient* nwClient;
|
Oyster::Network::NetworkClient* nwClient;
|
||||||
|
@ -12,6 +16,13 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
|
||||||
// parsing protocols and sending it to the gameState
|
// parsing protocols and sending it to the gameState
|
||||||
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
|
void NetworkCallback(Oyster::Network::CustomNetProtocol& p) override
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//if( IsGameplayProtocol(p[protocol_INDEX_ID].value.netShort) )
|
||||||
|
//ParseGameplayEvent(e.protocol, e.gameClient);
|
||||||
|
|
||||||
|
//if( IsGeneralProtocol(p[protocol_INDEX_ID].value.netShort) )
|
||||||
|
//ParseGeneralEvent(e.protocol, e.gameClient);
|
||||||
|
|
||||||
int pType = p[0].value.netInt;
|
int pType = p[0].value.netInt;
|
||||||
switch (pType)
|
switch (pType)
|
||||||
{
|
{
|
||||||
|
@ -106,6 +117,8 @@ struct GameRecieverObject :public Oyster::Network::ProtocolRecieverObject
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,33 +75,10 @@ bool GameState::LoadModels(std::wstring mapFile)
|
||||||
// init models
|
// init models
|
||||||
privData->modelCount = 2;
|
privData->modelCount = 2;
|
||||||
|
|
||||||
|
// add world model
|
||||||
ModelInitData modelData;
|
ModelInitData modelData;
|
||||||
|
Oyster::Math3D::Float4x4 translate;
|
||||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
C_Object* obj;
|
||||||
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
|
|
||||||
modelData.world = modelData.world * translate;
|
|
||||||
modelData.visible = true;
|
|
||||||
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
|
|
||||||
modelData.id = 0;
|
|
||||||
// load models
|
|
||||||
C_Object* obj = new C_Player();
|
|
||||||
privData->object.push_back(obj);
|
|
||||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
|
||||||
|
|
||||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,2,2));
|
|
||||||
modelData.world = modelData.world * translate;
|
|
||||||
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
|
|
||||||
modelData.id ++;
|
|
||||||
|
|
||||||
obj = new C_Player();
|
|
||||||
privData->object.push_back(obj);
|
|
||||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
|
||||||
|
|
||||||
/*translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
|
|
||||||
modelData.world = modelData.world * translate;
|
|
||||||
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
|
|
||||||
modelData.id ++;*/
|
|
||||||
|
|
||||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
|
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
|
||||||
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
|
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
|
||||||
scale.v[0].x = 8;
|
scale.v[0].x = 8;
|
||||||
|
@ -109,12 +86,40 @@ bool GameState::LoadModels(std::wstring mapFile)
|
||||||
scale.v[2].z = 8;
|
scale.v[2].z = 8;
|
||||||
modelData.world = scale; //modelData.world * translate
|
modelData.world = scale; //modelData.world * translate
|
||||||
modelData.modelPath = L"ball.dan";
|
modelData.modelPath = L"ball.dan";
|
||||||
modelData.id ++;
|
modelData.id = 0;
|
||||||
|
|
||||||
obj = new C_Player();
|
obj = new C_Player();
|
||||||
privData->object.push_back(obj);
|
privData->object.push_back(obj);
|
||||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||||
|
|
||||||
|
// add box model
|
||||||
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
|
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-5,15,0));
|
||||||
|
modelData.world = modelData.world * translate;
|
||||||
|
modelData.modelPath = L"box.dan";
|
||||||
|
modelData.id = 1;
|
||||||
|
|
||||||
|
obj = new C_Player();
|
||||||
|
privData->object.push_back(obj);
|
||||||
|
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||||
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
|
|
||||||
|
// add player model
|
||||||
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
|
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 15, 0));
|
||||||
|
modelData.world = modelData.world * translate;
|
||||||
|
modelData.visible = true;
|
||||||
|
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
|
||||||
|
modelData.id = 2;
|
||||||
|
// load models
|
||||||
|
obj = new C_Player();
|
||||||
|
privData->object.push_back(obj);
|
||||||
|
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -328,10 +333,10 @@ void GameState::Protocol( ObjPos* pos )
|
||||||
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
|
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
|
||||||
//camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6])));
|
//camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6])));
|
||||||
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
|
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
|
||||||
if(i == 0)
|
if(i == 2) // playerobj
|
||||||
{
|
{
|
||||||
camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
|
//camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
|
||||||
camera->UpdateViewMatrix();
|
//camera->UpdateViewMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,15 +114,34 @@ namespace DanBias
|
||||||
{
|
{
|
||||||
GameLogic::IObjectData* obj = NULL;
|
GameLogic::IObjectData* obj = NULL;
|
||||||
if(dynamic_cast<GameLogic::ILevelData*>(movedObject))
|
if(dynamic_cast<GameLogic::ILevelData*>(movedObject))
|
||||||
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
|
|
||||||
if(obj)
|
|
||||||
{
|
{
|
||||||
if(obj->GetType() == OBJECT_TYPE_BOX)
|
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
|
||||||
|
if(obj)
|
||||||
{
|
{
|
||||||
obj->GetID();
|
if(obj->GetType() == OBJECT_TYPE_WORLD)
|
||||||
Oyster::Math::Float4x4 world =obj->GetOrientation();
|
{
|
||||||
Protocol_ObjectPosition p(world, 1);
|
obj->GetID();
|
||||||
GameSession::gameSession->Send(p.GetProtocol());
|
Oyster::Math::Float4x4 world =obj->GetOrientation();
|
||||||
|
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
|
||||||
|
scale.v[0].x = 8;
|
||||||
|
scale.v[1].y = 8;
|
||||||
|
scale.v[2].z = 8;
|
||||||
|
world = world * scale;
|
||||||
|
Protocol_ObjectPosition p(world, 0);
|
||||||
|
GameSession::gameSession->Send(p.GetProtocol());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
obj = NULL;
|
||||||
|
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
|
||||||
|
if(obj)
|
||||||
|
{
|
||||||
|
if(obj->GetType() == OBJECT_TYPE_BOX)
|
||||||
|
{
|
||||||
|
obj->GetID();
|
||||||
|
Oyster::Math::Float4x4 world = obj->GetOrientation();
|
||||||
|
Protocol_ObjectPosition p(world, 1);
|
||||||
|
GameSession::gameSession->Send(p.GetProtocol());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ namespace DanBias
|
||||||
if(clients.Size() >= 1 && clients[0])
|
if(clients.Size() >= 1 && clients[0])
|
||||||
{
|
{
|
||||||
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
|
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
|
||||||
Protocol_ObjectPosition p(world, 0);
|
Protocol_ObjectPosition p(world, 2);
|
||||||
Send(p.GetProtocol());
|
Send(p.GetProtocol());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,10 @@ Game::PlayerData::PlayerData()
|
||||||
Oyster::Physics::API::SimpleBodyDescription sbDesc;
|
Oyster::Physics::API::SimpleBodyDescription sbDesc;
|
||||||
//set some stats that are appropriate to a player
|
//set some stats that are appropriate to a player
|
||||||
|
|
||||||
//create rigidbody
|
//create rigid body
|
||||||
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
|
Oyster::Physics::ICustomBody *rigidBody = Oyster::Physics::API::Instance().CreateRigidBody(sbDesc).Release();
|
||||||
|
|
||||||
|
//create player with this rigid body
|
||||||
//create player with this rigidbody
|
|
||||||
|
|
||||||
|
|
||||||
this->player = new Player(rigidBody,Player::PlayerCollision,OBJECT_TYPE::OBJECT_TYPE_PLAYER);
|
this->player = new Player(rigidBody,Player::PlayerCollision,OBJECT_TYPE::OBJECT_TYPE_PLAYER);
|
||||||
this->player->GetRigidBody()->SetCustomTag(this);
|
this->player->GetRigidBody()->SetCustomTag(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,51 +20,45 @@ void Level::InitiateLevel(std::string levelPath)
|
||||||
}
|
}
|
||||||
void Level::InitiateLevel(float radius)
|
void Level::InitiateLevel(float radius)
|
||||||
{
|
{
|
||||||
|
// add level sphere
|
||||||
API::SphericalBodyDescription sbDesc;
|
API::SphericalBodyDescription sbDesc;
|
||||||
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
|
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
|
||||||
sbDesc.ignoreGravity = true;
|
sbDesc.ignoreGravity = true;
|
||||||
sbDesc.radius = 8; //radius;
|
sbDesc.radius = 8;
|
||||||
sbDesc.mass = 10e12f;
|
sbDesc.mass = 10e12f;
|
||||||
//sbDesc.mass = 0; //10^16
|
|
||||||
|
|
||||||
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
||||||
|
|
||||||
|
|
||||||
ICustomBody::State state;
|
ICustomBody::State state;
|
||||||
rigidBody->GetState(state);
|
rigidBody->GetState(state);
|
||||||
state.SetRestitutionCoeff(0.1);
|
state.SetRestitutionCoeff(0.01);
|
||||||
rigidBody->SetState(state);
|
rigidBody->SetState(state);
|
||||||
|
|
||||||
levelObj = new StaticObject(rigidBody, LevelCollision, OBJECT_TYPE::OBJECT_TYPE_WORLD);
|
levelObj = new StaticObject(rigidBody, LevelCollision, OBJECT_TYPE::OBJECT_TYPE_WORLD);
|
||||||
rigidBody->SetCustomTag(levelObj);
|
rigidBody->SetCustomTag(levelObj);
|
||||||
|
|
||||||
|
|
||||||
/*
|
// add box
|
||||||
API::SimpleBodyDescription sbDesc_TestBox;
|
API::SimpleBodyDescription sbDesc_TestBox;
|
||||||
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(5,15,0,0);
|
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(-5,15,0,0);
|
||||||
sbDesc_TestBox.ignoreGravity = false;
|
sbDesc_TestBox.ignoreGravity = false;
|
||||||
sbDesc_TestBox.mass = 10;
|
sbDesc_TestBox.mass = 10;
|
||||||
sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0);
|
sbDesc_TestBox.size = Oyster::Math::Float4(0.5f,0.5f,0.5f,0);
|
||||||
//sbDesc.mass = 0; //10^16
|
|
||||||
|
|
||||||
|
|
||||||
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
|
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
|
||||||
|
|
||||||
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
|
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||||
testBox = new DynamicObject(rigidBody_TestBox,LevelCollision,OBJECT_TYPE::OBJECT_TYPE_BOX);
|
testBox = new DynamicObject(rigidBody_TestBox,LevelCollision,OBJECT_TYPE::OBJECT_TYPE_BOX);
|
||||||
rigidBody_TestBox->SetCustomTag(testBox);
|
rigidBody_TestBox->SetCustomTag(testBox);
|
||||||
rigidBody_TestBox->GetState(state);
|
rigidBody_TestBox->GetState(state);
|
||||||
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,4));
|
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,4));
|
||||||
rigidBody_TestBox->SetState(state);
|
rigidBody_TestBox->SetState(state);
|
||||||
API::Instance().AddObject(rigidBody_TestBox);
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
// add gravitation
|
||||||
API::Gravity gravityWell;
|
API::Gravity gravityWell;
|
||||||
|
|
||||||
gravityWell.gravityType = API::Gravity::GravityType_Well;
|
gravityWell.gravityType = API::Gravity::GravityType_Well;
|
||||||
gravityWell.well.mass = 10e12f;
|
gravityWell.well.mass = 10e12f;
|
||||||
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
|
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
|
||||||
|
|
||||||
API::Instance().AddGravity(gravityWell);
|
API::Instance().AddGravity(gravityWell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +79,10 @@ void Level::RespawnPlayer(Player *player)
|
||||||
|
|
||||||
Object* Level::GetObj( int ID) const
|
Object* Level::GetObj( int ID) const
|
||||||
{
|
{
|
||||||
return (Object*)testBox;
|
if( ID == 0 )
|
||||||
|
return (Object*)levelObj;
|
||||||
|
else
|
||||||
|
return (Object*)testBox;
|
||||||
}
|
}
|
||||||
void Level::PhysicsOnMoveLevel(const ICustomBody *object)
|
void Level::PhysicsOnMoveLevel(const ICustomBody *object)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ Object::Object(void* collisionFunc, OBJECT_TYPE type)
|
||||||
|
|
||||||
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
||||||
|
|
||||||
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
//rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
||||||
|
|
||||||
//rigidBody->gameObjectRef = this;
|
//rigidBody->gameObjectRef = this;
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ Object::Object(ICustomBody *rigidBody ,void* collisionFunc, OBJECT_TYPE type)
|
||||||
{
|
{
|
||||||
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
||||||
|
|
||||||
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
//rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
||||||
|
|
||||||
this->objectID = GID();
|
this->objectID = GID();
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ Object::Object(ICustomBody *rigidBody ,void* collisionFunc, OBJECT_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)
|
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);
|
Oyster::Physics::API::Instance().AddObject(rigidBody);
|
||||||
rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
//rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_Collision)(collisionFunc));
|
||||||
|
|
||||||
this->rigidBody = rigidBody;
|
this->rigidBody = rigidBody;
|
||||||
this->type = type;
|
this->type = type;
|
||||||
|
|
Loading…
Reference in New Issue