Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic
This commit is contained in:
commit
a3cea997ba
|
@ -49,15 +49,25 @@ bool GameState::Init(Oyster::Network::NetworkClient* nwClient)
|
||||||
GameState::gameStateState GameState::LoadGame()
|
GameState::gameStateState GameState::LoadGame()
|
||||||
{
|
{
|
||||||
Oyster::Graphics::Definitions::Pointlight plight;
|
Oyster::Graphics::Definitions::Pointlight plight;
|
||||||
plight.Pos = Oyster::Math::Float3(0,15,5);
|
plight.Pos = Oyster::Math::Float3(315, 0 ,5);
|
||||||
plight.Color = Oyster::Math::Float3(0,1,0);
|
plight.Color = Oyster::Math::Float3(0.9,0.7,0.2);
|
||||||
plight.Radius = 50;
|
plight.Radius = 100;
|
||||||
plight.Bright = 2;
|
plight.Bright = 0.9;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
plight.Pos = Oyster::Math::Float3(10,15,5);
|
plight.Pos = Oyster::Math::Float3(10,350,5);
|
||||||
plight.Color = Oyster::Math::Float3(1,0,0);
|
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
|
||||||
plight.Radius = 50;
|
plight.Radius = 200;
|
||||||
plight.Bright = 2;
|
plight.Bright = 0.7;
|
||||||
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
|
plight.Pos = Oyster::Math::Float3(350,350,5);
|
||||||
|
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
|
||||||
|
plight.Radius = 200;
|
||||||
|
plight.Bright = 0.7;
|
||||||
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
|
plight.Pos = Oyster::Math::Float3(10,350,350);
|
||||||
|
plight.Color = Oyster::Math::Float3(0.9,0.7,0.3);
|
||||||
|
plight.Radius = 200;
|
||||||
|
plight.Bright = 0.7;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
plight.Pos = Oyster::Math::Float3(10,-15,5);
|
plight.Pos = Oyster::Math::Float3(10,-15,5);
|
||||||
plight.Color = Oyster::Math::Float3(0,0,1);
|
plight.Color = Oyster::Math::Float3(0,0,1);
|
||||||
|
@ -74,7 +84,8 @@ bool GameState::LoadModels(std::wstring mapFile)
|
||||||
// open file
|
// open file
|
||||||
// read file
|
// read file
|
||||||
// init models
|
// init models
|
||||||
privData->modelCount = 4;
|
int nrOfBoxex = 5;
|
||||||
|
privData->modelCount = 3+nrOfBoxex;
|
||||||
myId += privData->modelCount;
|
myId += privData->modelCount;
|
||||||
int id = 0;
|
int id = 0;
|
||||||
// add world model
|
// add world model
|
||||||
|
@ -92,15 +103,20 @@ bool GameState::LoadModels(std::wstring mapFile)
|
||||||
|
|
||||||
// add box model
|
// add box model
|
||||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
|
|
||||||
modelData.world = modelData.world * translate;
|
|
||||||
modelData.modelPath = L"..\\Content\\Models\\box.dan";
|
modelData.modelPath = L"..\\Content\\Models\\box.dan";
|
||||||
modelData.id = id++;
|
|
||||||
|
|
||||||
obj = new C_Player();
|
|
||||||
privData->object.push_back(obj);
|
for(int i =0; i< nrOfBoxex; i ++)
|
||||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
{
|
||||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
|
||||||
|
modelData.world = modelData.world * translate;
|
||||||
|
modelData.id = id++;
|
||||||
|
|
||||||
|
obj = new C_Player();
|
||||||
|
privData->object.push_back(obj);
|
||||||
|
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||||
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
|
}
|
||||||
|
|
||||||
// add crystal model
|
// add crystal model
|
||||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
|
@ -330,7 +346,37 @@ void GameState::readKeyInput(InputClass* KeyInput)
|
||||||
if(!key_Shoot)
|
if(!key_Shoot)
|
||||||
{
|
{
|
||||||
GameLogic::Protocol_PlayerShot playerShot;
|
GameLogic::Protocol_PlayerShot playerShot;
|
||||||
playerShot.hasShot = true;
|
playerShot.primaryPressed = true;
|
||||||
|
playerShot.secondaryPressed = false;
|
||||||
|
playerShot.utilityPressed = false;
|
||||||
|
privData->nwClient->Send(playerShot);
|
||||||
|
key_Shoot = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
key_Shoot = false;
|
||||||
|
if(KeyInput->IsKeyPressed(DIK_X))
|
||||||
|
{
|
||||||
|
if(!key_Shoot)
|
||||||
|
{
|
||||||
|
GameLogic::Protocol_PlayerShot playerShot;
|
||||||
|
playerShot.primaryPressed = false;
|
||||||
|
playerShot.secondaryPressed = true;
|
||||||
|
playerShot.utilityPressed = false;
|
||||||
|
privData->nwClient->Send(playerShot);
|
||||||
|
key_Shoot = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
key_Shoot = false;
|
||||||
|
if(KeyInput->IsKeyPressed(DIK_C))
|
||||||
|
{
|
||||||
|
if(!key_Shoot)
|
||||||
|
{
|
||||||
|
GameLogic::Protocol_PlayerShot playerShot;
|
||||||
|
playerShot.primaryPressed = false;
|
||||||
|
playerShot.secondaryPressed = false;
|
||||||
|
playerShot.utilityPressed = true;
|
||||||
privData->nwClient->Send(playerShot);
|
privData->nwClient->Send(playerShot);
|
||||||
key_Shoot = true;
|
key_Shoot = true;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +385,7 @@ void GameState::readKeyInput(InputClass* KeyInput)
|
||||||
key_Shoot = false;
|
key_Shoot = false;
|
||||||
|
|
||||||
// jump
|
// jump
|
||||||
if(KeyInput->IsKeyPressed(DIK_X))
|
if(KeyInput->IsKeyPressed(DIK_SPACE))
|
||||||
{
|
{
|
||||||
if(!key_Jump)
|
if(!key_Jump)
|
||||||
{
|
{
|
||||||
|
@ -408,7 +454,7 @@ void GameState::Protocol( ObjPos* pos )
|
||||||
|
|
||||||
camera->setRight(right);
|
camera->setRight(right);
|
||||||
camera->setUp(up);
|
camera->setUp(up);
|
||||||
//camera->setLook(objForward);
|
camera->setLook(objForward);
|
||||||
|
|
||||||
up *= 2;
|
up *= 2;
|
||||||
objForward *= -3;
|
objForward *= -3;
|
||||||
|
|
|
@ -41,9 +41,9 @@ bool LoginState::Init(Oyster::Network::NetworkClient* nwClient)
|
||||||
bool LoginState::LoadModels(std::wstring file)
|
bool LoginState::LoadModels(std::wstring file)
|
||||||
{
|
{
|
||||||
Oyster::Graphics::Definitions::Pointlight plight;
|
Oyster::Graphics::Definitions::Pointlight plight;
|
||||||
plight.Pos = Oyster::Math::Float3(-2,3,0);
|
plight.Pos = Oyster::Math::Float3(0,0,5.4f);
|
||||||
plight.Color = Oyster::Math::Float3(0,1,0);
|
plight.Color = Oyster::Math::Float3(1,1,1);
|
||||||
plight.Radius = 10;
|
plight.Radius = 100;
|
||||||
plight.Bright = 1;
|
plight.Bright = 1;
|
||||||
Oyster::Graphics::API::AddLight(plight);
|
Oyster::Graphics::API::AddLight(plight);
|
||||||
// open file
|
// open file
|
||||||
|
@ -55,12 +55,13 @@ bool LoginState::LoadModels(std::wstring file)
|
||||||
|
|
||||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||||
modelData.visible = true;
|
modelData.visible = true;
|
||||||
modelData.modelPath = L"..\\Content\\Models\\box_2.dan";
|
modelData.modelPath = L"..\\Content\\Models\\box.dan";
|
||||||
// load models
|
// load models
|
||||||
privData->object[0] = new C_StaticObj();
|
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(2,2,2));
|
||||||
|
privData->object[0] = new C_DynamicObj();
|
||||||
privData->object[0]->Init(modelData);
|
privData->object[0]->Init(modelData);
|
||||||
|
|
||||||
Oyster::Math3D::Float4x4 translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
|
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
|
||||||
modelData.world = modelData.world * translate;
|
modelData.world = modelData.world * translate;
|
||||||
|
|
||||||
privData->object[1] = new C_DynamicObj();
|
privData->object[1] = new C_DynamicObj();
|
||||||
|
|
|
@ -42,7 +42,7 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
|
||||||
|
|
||||||
if(hasObject)
|
if(hasObject)
|
||||||
{
|
{
|
||||||
ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES
|
//ForcePush(usage,dt);//WARNING THIS IS A CRAP TEST TO MAKE SURE YOU CAN SHOOT BOXES
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ForcePull(usage,dt);
|
ForcePull(usage,dt);
|
||||||
|
|
|
@ -84,7 +84,7 @@ using namespace GameLogic;
|
||||||
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
|
if(kineticEnergyLoss > forceThreashHold) //should only take damage if the force is high enough
|
||||||
{
|
{
|
||||||
damageDone = kineticEnergyLoss * 0.10f;
|
damageDone = kineticEnergyLoss * 0.10f;
|
||||||
player.DamageLife(damageDone);
|
//player.DamageLife(damageDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,14 @@ using namespace GameLogic;
|
||||||
{
|
{
|
||||||
return Physics::ICustomBody::SubscriptMessage_none;
|
return Physics::ICustomBody::SubscriptMessage_none;
|
||||||
}
|
}
|
||||||
|
Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
|
||||||
|
{
|
||||||
|
return Physics::ICustomBody::SubscriptMessage_player_collision_response;
|
||||||
|
}
|
||||||
|
Oyster::Physics::ICustomBody::SubscriptMessage Player::PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss)
|
||||||
|
{
|
||||||
|
return Physics::ICustomBody::SubscriptMessage_none;
|
||||||
|
}
|
||||||
//Oyster::Physics::ICustomBody::SubscriptMessage
|
//Oyster::Physics::ICustomBody::SubscriptMessage
|
||||||
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
|
Oyster::Physics::ICustomBody::SubscriptMessage Level::LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace GameLogic
|
||||||
Oyster::Math::Float4x4 GetOrientation() override;
|
Oyster::Math::Float4x4 GetOrientation() override;
|
||||||
int GetID() const override;
|
int GetID() const override;
|
||||||
OBJECT_TYPE GetObjectType() const override;
|
OBJECT_TYPE GetObjectType() const override;
|
||||||
|
int getNrOfDynamicObj()const override;
|
||||||
IObjectData* GetObjectAt(int ID) const override;
|
IObjectData* GetObjectAt(int ID) const override;
|
||||||
Level *level;
|
Level *level;
|
||||||
};
|
};
|
||||||
|
|
|
@ -100,6 +100,7 @@ namespace GameLogic
|
||||||
class ILevelData :public IObjectData
|
class ILevelData :public IObjectData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual int getNrOfDynamicObj()const = 0;
|
||||||
virtual IObjectData* GetObjectAt(int ID) const = 0;
|
virtual IObjectData* GetObjectAt(int ID) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,10 @@ OBJECT_TYPE Game::LevelData::GetObjectType() const
|
||||||
return ((IObjectData*)this->level)->GetObjectType();
|
return ((IObjectData*)this->level)->GetObjectType();
|
||||||
//return OBJECT_TYPE_UNKNOWN;
|
//return OBJECT_TYPE_UNKNOWN;
|
||||||
}
|
}
|
||||||
|
int Game::LevelData::getNrOfDynamicObj()const
|
||||||
|
{
|
||||||
|
return this->level->getNrOfDynamicObj();
|
||||||
|
}
|
||||||
IObjectData* Game::LevelData::GetObjectAt(int ID) const
|
IObjectData* Game::LevelData::GetObjectAt(int ID) const
|
||||||
{
|
{
|
||||||
return this->level->GetObj(ID);
|
return this->level->GetObj(ID);
|
||||||
|
|
|
@ -11,13 +11,15 @@ Game::PlayerData::PlayerData()
|
||||||
sbDesc.size = Oyster::Math::Float3(4,7,4);
|
sbDesc.size = Oyster::Math::Float3(4,7,4);
|
||||||
sbDesc.mass = 70;
|
sbDesc.mass = 70;
|
||||||
sbDesc.restitutionCoeff = 0.5;
|
sbDesc.restitutionCoeff = 0.5;
|
||||||
|
sbDesc.frictionCoeff_Static = 0.4;
|
||||||
|
sbDesc.frictionCoeff_Dynamic = 0.3;
|
||||||
sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0);
|
sbDesc.rotation = Oyster::Math::Float3(0, Oyster::Math::pi, 0);
|
||||||
|
|
||||||
//create rigid body
|
//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 rigid body
|
||||||
this->player = new Player(rigidBody,Object::DefaultCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
|
this->player = new Player(rigidBody,Player::PlayerCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
|
||||||
this->player->GetRigidBody()->SetCustomTag(this);
|
this->player->GetRigidBody()->SetCustomTag(this);
|
||||||
/*Oyster::Physics::ICustomBody::State state;
|
/*Oyster::Physics::ICustomBody::State state;
|
||||||
this->player->GetRigidBody()->GetState(state);
|
this->player->GetRigidBody()->GetState(state);
|
||||||
|
|
|
@ -20,6 +20,35 @@ void Level::InitiateLevel(std::string levelPath)
|
||||||
}
|
}
|
||||||
void Level::InitiateLevel(float radius)
|
void Level::InitiateLevel(float radius)
|
||||||
{
|
{
|
||||||
|
float heading = Utility::Value::Radian(180.0f);
|
||||||
|
float attitude = Utility::Value::Radian(0.0f);
|
||||||
|
float bank = Utility::Value::Radian(0);
|
||||||
|
|
||||||
|
double c1 = cos(heading/2);
|
||||||
|
double s1 = sin(heading/2);
|
||||||
|
double c2 = cos(attitude/2);
|
||||||
|
double s2 = sin(attitude/2);
|
||||||
|
double c3 = cos(bank/2);
|
||||||
|
double s3 = sin(bank/2);
|
||||||
|
double c1c2 = c1*c2;
|
||||||
|
double s1s2 = s1*s2;
|
||||||
|
double w =c1c2*c3 - s1s2*s3;
|
||||||
|
double x =c1c2*s3 + s1s2*c3;
|
||||||
|
double y =s1*c2*c3 + c1*s2*s3;
|
||||||
|
double z =c1*s2*c3 - s1*c2*s3;
|
||||||
|
double angle = 2 * acos(w);
|
||||||
|
|
||||||
|
double norm = x*x+y*y+z*z;
|
||||||
|
if (norm < 0.001) { // when all euler angles are zero angle =0 so
|
||||||
|
// we can set axis to anything to avoid divide by zero
|
||||||
|
x=1;
|
||||||
|
y=z=0;
|
||||||
|
} else {
|
||||||
|
norm = sqrt(norm);
|
||||||
|
x /= norm;
|
||||||
|
y /= norm;
|
||||||
|
z /= norm;
|
||||||
|
}
|
||||||
|
|
||||||
// add level sphere
|
// add level sphere
|
||||||
API::SphericalBodyDescription sbDesc;
|
API::SphericalBodyDescription sbDesc;
|
||||||
|
@ -29,6 +58,7 @@ void Level::InitiateLevel(float radius)
|
||||||
sbDesc.mass = 10e12f;
|
sbDesc.mass = 10e12f;
|
||||||
sbDesc.frictionCoeff_Static = 0;
|
sbDesc.frictionCoeff_Static = 0;
|
||||||
sbDesc.frictionCoeff_Dynamic = 0;
|
sbDesc.frictionCoeff_Dynamic = 0;
|
||||||
|
//sbDesc.rotation =
|
||||||
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
|
||||||
|
|
||||||
ICustomBody::State state;
|
ICustomBody::State state;
|
||||||
|
@ -49,31 +79,35 @@ void Level::InitiateLevel(float radius)
|
||||||
sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0);
|
sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0);
|
||||||
|
|
||||||
|
|
||||||
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
|
ICustomBody* rigidBody_TestBox;
|
||||||
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
|
|
||||||
|
int nrOfBoxex = 5;
|
||||||
|
for(int i =0; i< nrOfBoxex; i ++)
|
||||||
|
{
|
||||||
|
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(20 ,320,0 + ( i*7),0);
|
||||||
|
rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
|
||||||
|
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||||
|
|
||||||
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
||||||
|
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
|
||||||
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[0]);
|
|
||||||
rigidBody_TestBox->GetState(state);
|
|
||||||
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
|
|
||||||
rigidBody_TestBox->SetState(state);
|
|
||||||
|
|
||||||
// add crystal
|
// add crystal
|
||||||
API::SimpleBodyDescription sbDesc_Crystal;
|
API::SimpleBodyDescription sbDesc_Crystal;
|
||||||
sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0);
|
sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0);
|
||||||
sbDesc_Crystal.ignoreGravity = false;
|
sbDesc_Crystal.ignoreGravity = false;
|
||||||
|
|
||||||
sbDesc_Crystal.mass = 70;
|
sbDesc_Crystal.mass = 70;
|
||||||
sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0);
|
sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0);
|
||||||
|
|
||||||
|
|
||||||
ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release();
|
ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release();
|
||||||
rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel);
|
rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||||
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
||||||
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[1]);
|
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
|
||||||
rigidBody_Crystal->GetState(state);
|
|
||||||
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
|
|
||||||
rigidBody_Crystal->SetState(state);
|
|
||||||
|
|
||||||
// add house
|
// add house
|
||||||
API::SimpleBodyDescription sbDesc_House;
|
API::SimpleBodyDescription sbDesc_House;
|
||||||
|
@ -88,10 +122,7 @@ void Level::InitiateLevel(float radius)
|
||||||
rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel);
|
rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||||
this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
|
this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
|
||||||
rigidBody_House->SetCustomTag(this->staticObjects[0]);
|
rigidBody_House->SetCustomTag(this->staticObjects[0]);
|
||||||
rigidBody_House->GetState(state);
|
|
||||||
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
|
|
||||||
rigidBody_House->SetState(state);
|
|
||||||
|
|
||||||
|
|
||||||
// add gravitation
|
// add gravitation
|
||||||
API::Gravity gravityWell;
|
API::Gravity gravityWell;
|
||||||
|
@ -116,6 +147,10 @@ void Level::RespawnPlayer(Player *player)
|
||||||
this->teamManager.RespawnPlayerRandom(player);
|
this->teamManager.RespawnPlayerRandom(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Level::getNrOfDynamicObj()
|
||||||
|
{
|
||||||
|
return this->dynamicObjects.Size();
|
||||||
|
}
|
||||||
Object* Level::GetObj( int ID) const
|
Object* Level::GetObj( int ID) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i< this->dynamicObjects.Size(); i++)
|
for (int i = 0; i< this->dynamicObjects.Size(); i++)
|
||||||
|
|
|
@ -59,7 +59,8 @@ namespace GameLogic
|
||||||
********************************************************/
|
********************************************************/
|
||||||
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
|
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);
|
static Oyster::Physics::ICustomBody::SubscriptMessage LevelCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
|
||||||
|
|
||||||
|
int getNrOfDynamicObj();
|
||||||
Object* GetObj( int ID ) const;
|
Object* GetObj( int ID ) const;
|
||||||
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);
|
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);
|
||||||
|
|
||||||
|
|
|
@ -156,6 +156,8 @@ void Object::EndFrame()
|
||||||
//error
|
//error
|
||||||
int i =0 ;
|
int i =0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(currPhysicsState.GetGravityNormal()!= Float3::null)
|
if(currPhysicsState.GetGravityNormal()!= Float3::null)
|
||||||
{
|
{
|
||||||
Oyster::Math::Float4 axis;
|
Oyster::Math::Float4 axis;
|
||||||
|
@ -170,6 +172,18 @@ void Object::EndFrame()
|
||||||
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
|
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
|
||||||
debug += currPhysicsState.GetGravityNormal();
|
debug += currPhysicsState.GetGravityNormal();
|
||||||
}
|
}
|
||||||
|
Oyster::Math::Float3 pos = currPhysicsState.GetCenterPosition();
|
||||||
|
Oyster::Math::Float3 up = -currPhysicsState.GetGravityNormal();
|
||||||
|
//300, 0,0,
|
||||||
|
//1,0,0
|
||||||
|
|
||||||
|
if( pos.GetLength() < 303.5f)
|
||||||
|
{
|
||||||
|
Oyster::Math::Float moveUp = 303.5 - pos.GetLength();
|
||||||
|
up *= moveUp;
|
||||||
|
|
||||||
|
currPhysicsState.SetCenterPosition(pos + up);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
using namespace GameLogic;
|
using namespace GameLogic;
|
||||||
using namespace Oyster::Physics;
|
using namespace Oyster::Physics;
|
||||||
const int MOVE_FORCE = 5000;
|
const int MOVE_FORCE = 500;
|
||||||
Player::Player()
|
Player::Player()
|
||||||
:DynamicObject()
|
:DynamicObject()
|
||||||
{
|
{
|
||||||
|
@ -154,11 +154,6 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
|
||||||
{
|
{
|
||||||
int i =0 ;
|
int i =0 ;
|
||||||
}
|
}
|
||||||
//Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
|
||||||
//Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
|
|
||||||
//Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
|
|
||||||
|
|
||||||
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
|
|
||||||
|
|
||||||
this->lookDir = lookDir.xyz;
|
this->lookDir = lookDir.xyz;
|
||||||
this->dx = lookDir.w;
|
this->dx = lookDir.w;
|
||||||
|
|
|
@ -73,6 +73,9 @@ namespace GameLogic
|
||||||
|
|
||||||
void BeginFrame();
|
void BeginFrame();
|
||||||
void EndFrame();
|
void EndFrame();
|
||||||
|
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionBefore(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj);
|
||||||
|
static Oyster::Physics::ICustomBody::SubscriptMessage PlayerCollisionAfter(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Jump();
|
void Jump();
|
||||||
|
|
|
@ -142,7 +142,9 @@ namespace GameLogic
|
||||||
|
|
||||||
struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject
|
struct Protocol_PlayerShot :public Oyster::Network::CustomProtocolObject
|
||||||
{
|
{
|
||||||
bool hasShot;
|
bool primaryPressed;
|
||||||
|
bool secondaryPressed;
|
||||||
|
bool utilityPressed;
|
||||||
|
|
||||||
Protocol_PlayerShot()
|
Protocol_PlayerShot()
|
||||||
{
|
{
|
||||||
|
@ -150,19 +152,27 @@ namespace GameLogic
|
||||||
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
this->protocol[0].type = Oyster::Network::NetAttributeType_Short;
|
||||||
|
|
||||||
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
|
this->protocol[1].type = Oyster::Network::NetAttributeType_Bool;
|
||||||
|
this->protocol[2].type = Oyster::Network::NetAttributeType_Bool;
|
||||||
|
this->protocol[3].type = Oyster::Network::NetAttributeType_Bool;
|
||||||
}
|
}
|
||||||
Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p)
|
Protocol_PlayerShot(Oyster::Network::CustomNetProtocol& p)
|
||||||
{
|
{
|
||||||
hasShot = p[1].value.netBool;
|
primaryPressed = p[1].value.netBool;
|
||||||
|
secondaryPressed = p[2].value.netBool;
|
||||||
|
utilityPressed = p[3].value.netBool;
|
||||||
}
|
}
|
||||||
const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val)
|
const Protocol_PlayerShot& operator=(Oyster::Network::CustomNetProtocol& val)
|
||||||
{
|
{
|
||||||
hasShot = val[1].value.netBool;
|
primaryPressed = val[1].value.netBool;
|
||||||
|
secondaryPressed = val[2].value.netBool;
|
||||||
|
utilityPressed = val[3].value.netBool;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
Oyster::Network::CustomNetProtocol* GetProtocol() override
|
||||||
{
|
{
|
||||||
this->protocol[1].value = hasShot;
|
this->protocol[1].value = primaryPressed;
|
||||||
|
this->protocol[2].value = secondaryPressed;
|
||||||
|
this->protocol[3].value = utilityPressed;
|
||||||
return &protocol;
|
return &protocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -111,27 +111,19 @@ namespace DanBias
|
||||||
}
|
}
|
||||||
|
|
||||||
obj = NULL;
|
obj = NULL;
|
||||||
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
|
int count = ((GameLogic::ILevelData*)movedObject)->getNrOfDynamicObj();
|
||||||
if(obj)
|
for( int i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
|
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(i+1);
|
||||||
|
if(obj)
|
||||||
{
|
{
|
||||||
int id = obj->GetID();
|
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
|
||||||
Oyster::Math::Float4x4 world = obj->GetOrientation();
|
{
|
||||||
Protocol_ObjectPosition p(world, id);
|
int id = obj->GetID();
|
||||||
GameSession::gameSession->Send(*p.GetProtocol());
|
Oyster::Math::Float4x4 world = obj->GetOrientation();
|
||||||
}
|
Protocol_ObjectPosition p(world, id);
|
||||||
}
|
GameSession::gameSession->Send(*p.GetProtocol());
|
||||||
obj = NULL;
|
}
|
||||||
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(2);
|
|
||||||
if(obj)
|
|
||||||
{
|
|
||||||
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
|
|
||||||
{
|
|
||||||
int id = obj->GetID();
|
|
||||||
Oyster::Math::Float4x4 world = obj->GetOrientation();
|
|
||||||
Protocol_ObjectPosition p(world, id);
|
|
||||||
GameSession::gameSession->Send(*p.GetProtocol());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,9 +189,9 @@ namespace DanBias
|
||||||
}
|
}
|
||||||
void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c )
|
void GameSession::Gameplay_PlayerShot ( Protocol_PlayerShot& p, DanBias::GameClient* c )
|
||||||
{
|
{
|
||||||
//c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS);
|
if(p.primaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS);
|
||||||
c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS);
|
if(p.secondaryPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_SECONDARY_PRESS);
|
||||||
//c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_PRIMARY_PRESS);
|
if(p.utilityPressed) c->GetPlayer()->UseWeapon(GameLogic::WEAPON_USE_UTILLITY_PRESS);
|
||||||
}
|
}
|
||||||
void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c )
|
void GameSession::Gameplay_PlayerJump ( Protocol_PlayerJump& p, DanBias::GameClient* c )
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace
|
||||||
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
||||||
|
|
||||||
// calc from perspective of deuter.
|
// calc from perspective of deuter.
|
||||||
Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed
|
Float4 normal = (worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f )).GetNormalized(); // Init value is only borrowed
|
||||||
if( normal.Dot(normal) > 0.0f )
|
if( normal.Dot(normal) > 0.0f )
|
||||||
{
|
{
|
||||||
deuter->GetNormalAt( worldPointOfContact, normal );
|
deuter->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
@ -47,9 +47,10 @@ namespace
|
||||||
proto->GetNormalAt( worldPointOfContact, normal );
|
proto->GetNormalAt( worldPointOfContact, normal );
|
||||||
normal = -normal;
|
normal = -normal;
|
||||||
}
|
}
|
||||||
|
normal.Normalize();
|
||||||
|
|
||||||
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
|
Float4 protoG = Float4(protoState.GetLinearMomentum( worldPointOfContact.xyz ), 0),
|
||||||
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
|
deuterG = Float4(deuterState.GetLinearMomentum( worldPointOfContact.xyz ), 0);
|
||||||
|
|
||||||
if( normal != normal ) // debug: trap
|
if( normal != normal ) // debug: trap
|
||||||
const char *breakpoint = "This should never happen";
|
const char *breakpoint = "This should never happen";
|
||||||
|
@ -89,6 +90,18 @@ namespace
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PLayerHAck
|
||||||
|
if( proto->CallSubscription_BeforeCollisionResponse(proto) == ICustomBody::SubscriptMessage_player_collision_response )
|
||||||
|
{
|
||||||
|
Float3 linearMomentum = protoState.GetLinearMomentum();
|
||||||
|
Float3 up = -protoState.GetGravityNormal();
|
||||||
|
Float3 upForce = (linearMomentum.Dot(up) * up);
|
||||||
|
|
||||||
|
Float3 noBounceForce = linearMomentum - upForce;
|
||||||
|
protoState.SetLinearMomentum(noBounceForce);
|
||||||
|
proto->SetState(protoState);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// calculate and store time interpolation value, for later rebound.
|
// calculate and store time interpolation value, for later rebound.
|
||||||
proto->SetTimeOfContact( worldPointOfContact );
|
proto->SetTimeOfContact( worldPointOfContact );
|
||||||
|
|
||||||
|
@ -100,7 +113,7 @@ namespace
|
||||||
|
|
||||||
// calc from perspective of proto
|
// calc from perspective of proto
|
||||||
|
|
||||||
normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f );
|
normal = (worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f )).GetNormalized();
|
||||||
if( normal.Dot(normal) > 0.0f )
|
if( normal.Dot(normal) > 0.0f )
|
||||||
{
|
{
|
||||||
proto->GetNormalAt( worldPointOfContact, normal );
|
proto->GetNormalAt( worldPointOfContact, normal );
|
||||||
|
|
|
@ -242,7 +242,8 @@ namespace Oyster
|
||||||
{
|
{
|
||||||
SubscriptMessage_none,
|
SubscriptMessage_none,
|
||||||
SubscriptMessage_kineticLoss,
|
SubscriptMessage_kineticLoss,
|
||||||
SubscriptMessage_ignore_collision_response
|
SubscriptMessage_ignore_collision_response,
|
||||||
|
SubscriptMessage_player_collision_response
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter );
|
typedef SubscriptMessage (*EventAction_BeforeCollisionResponse)( const ICustomBody *proto, const ICustomBody *deuter );
|
||||||
|
|
|
@ -322,10 +322,14 @@ namespace Oyster
|
||||||
inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal )
|
inline void CustomBodyState::ApplyImpulse( const ::Oyster::Math::Float3 &j, const ::Oyster::Math::Float3 &at, const ::Oyster::Math::Float3 &normal )
|
||||||
{
|
{
|
||||||
::Oyster::Math::Float3 offset = at - this->centerPos;
|
::Oyster::Math::Float3 offset = at - this->centerPos;
|
||||||
::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
|
if( offset.Dot(offset) > 0.0f )
|
||||||
this->linearImpulse += j - ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset );
|
{
|
||||||
|
::Oyster::Math::Float3 deltaAngularImpulse = ::Oyster::Physics3D::Formula::AngularMomentum( j, offset );
|
||||||
|
|
||||||
this->angularImpulse += deltaAngularImpulse;
|
this->linearImpulse -= ::Oyster::Physics3D::Formula::TangentialLinearMomentum( deltaAngularImpulse, offset );
|
||||||
|
this->angularImpulse += deltaAngularImpulse;
|
||||||
|
}
|
||||||
|
this->linearImpulse += j;
|
||||||
this->isDisturbed = true;
|
this->isDisturbed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,12 @@ Float3 RigidBody::GetVelocity_Angular() const
|
||||||
|
|
||||||
Float3 RigidBody::GetLinearMomentum( const Float3 &atWorldPos ) const
|
Float3 RigidBody::GetLinearMomentum( const Float3 &atWorldPos ) const
|
||||||
{ // by Dan Andersson
|
{ // by Dan Andersson
|
||||||
return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, atWorldPos - this->centerPos );
|
Float3 offset = atWorldPos - this->centerPos;
|
||||||
|
if( offset.Dot(offset) > 0.0f )
|
||||||
|
{
|
||||||
|
return this->momentum_Linear + Formula::TangentialLinearMomentum( this->momentum_Angular, offset );
|
||||||
|
}
|
||||||
|
return this->momentum_Linear;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RigidBody::SetMomentOfInertia_KeepVelocity( const MomentOfInertia &localTensorI )
|
void RigidBody::SetMomentOfInertia_KeepVelocity( const MomentOfInertia &localTensorI )
|
||||||
|
|
Loading…
Reference in New Issue