GameServer - Merged with gamelogic
This commit is contained in:
commit
db822fa832
|
@ -78,8 +78,9 @@ bool GameState::LoadModels(std::wstring mapFile)
|
|||
// open file
|
||||
// read file
|
||||
// init models
|
||||
privData->modelCount = 2;
|
||||
|
||||
privData->modelCount = 4;
|
||||
myId += privData->modelCount;
|
||||
int id = 0;
|
||||
// add world model
|
||||
ModelInitData modelData;
|
||||
Oyster::Math3D::Float4x4 translate;
|
||||
|
@ -87,7 +88,7 @@ bool GameState::LoadModels(std::wstring mapFile)
|
|||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
|
||||
modelData.world = translate ;//modelData.world * translate
|
||||
modelData.modelPath = L"world_earth.dan";
|
||||
modelData.id = 0;
|
||||
modelData.id = id++;
|
||||
|
||||
obj = new C_Player();
|
||||
privData->object.push_back(obj);
|
||||
|
@ -98,34 +99,21 @@ bool GameState::LoadModels(std::wstring mapFile)
|
|||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
|
||||
modelData.world = modelData.world * translate;
|
||||
modelData.modelPath = L"box.dan";
|
||||
modelData.id = 1;
|
||||
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 player model
|
||||
// add crystal model
|
||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0));
|
||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 305, 0));
|
||||
|
||||
modelData.world = modelData.world * translate;
|
||||
modelData.visible = true;
|
||||
modelData.modelPath = L"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);
|
||||
|
||||
// add player model 2
|
||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0));
|
||||
|
||||
modelData.world = modelData.world * translate;
|
||||
modelData.visible = true;
|
||||
modelData.modelPath = L"char_white.dan";
|
||||
modelData.id = 3;
|
||||
modelData.modelPath = L"crystalformation_b.dan";
|
||||
modelData.id = id++;
|
||||
// load models
|
||||
obj = new C_Player();
|
||||
privData->object.push_back(obj);
|
||||
|
@ -138,25 +126,39 @@ bool GameState::LoadModels(std::wstring mapFile)
|
|||
modelData.world = modelData.world * translate;
|
||||
modelData.visible = false;
|
||||
modelData.modelPath = L"building_corporation.dan";
|
||||
modelData.id = 4;
|
||||
modelData.id = id++;
|
||||
// load models
|
||||
obj = new C_Player();
|
||||
privData->object.push_back(obj);
|
||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||
|
||||
// add crystal model
|
||||
// add player model
|
||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(10, 305, 0));
|
||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0, 320, 0));
|
||||
|
||||
modelData.world = modelData.world * translate;
|
||||
modelData.visible = true;
|
||||
modelData.modelPath = L"crystalformation_b.dan";
|
||||
modelData.id = 5;
|
||||
modelData.modelPath = L"char_renderTest.dan";
|
||||
modelData.id = id++;
|
||||
// load models
|
||||
obj = new C_Player();
|
||||
privData->object.push_back(obj);
|
||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||
|
||||
// add player model 2
|
||||
modelData.world = Oyster::Math3D::Float4x4::identity;
|
||||
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(50, 320, 0));
|
||||
|
||||
modelData.world = modelData.world * translate;
|
||||
modelData.visible = true;
|
||||
modelData.modelPath = L"char_renderTest.dan";
|
||||
modelData.id = id++;
|
||||
// load models
|
||||
obj = new C_Player();
|
||||
privData->object.push_back(obj);
|
||||
privData->object[privData->object.size() -1 ]->Init(modelData);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -313,8 +315,8 @@ void GameState::readKeyInput(InputClass* KeyInput)
|
|||
if (KeyInput->IsMousePressed())
|
||||
{
|
||||
camera->Yaw(-KeyInput->GetYaw());
|
||||
//camera->Pitch(KeyInput->GetPitch());
|
||||
//pitch = KeyInput->GetPitch();
|
||||
camera->Pitch(KeyInput->GetPitch());
|
||||
pitch = KeyInput->GetPitch();
|
||||
camera->UpdateViewMatrix();
|
||||
GameLogic::Protocol_PlayerLook playerLookDir;
|
||||
Oyster::Math::Float4 look = camera->GetLook();
|
||||
|
@ -389,28 +391,34 @@ void GameState::Protocol( ObjPos* pos )
|
|||
if(privData->object[i]->GetId() == pos->object_ID)
|
||||
{
|
||||
privData->object[i]->setPos(world);
|
||||
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
|
||||
//
|
||||
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
|
||||
|
||||
if(i == myId) // playerobj
|
||||
{
|
||||
camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
|
||||
camera->setUp(Oyster::Math::Float3(world[4], world[5], world[6]));
|
||||
Oyster::Math::Float3 cameraLook = camera->GetLook();
|
||||
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
|
||||
|
||||
camera->setLook(objForward);
|
||||
camera->UpdateViewMatrix();
|
||||
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]);
|
||||
Oyster::Math::Float3 right = Oyster::Math::Float3(world[0], world[1], world[2]);
|
||||
Oyster::Math::Float3 up = Oyster::Math::Float3(world[4], world[5], world[6]);
|
||||
Oyster::Math::Float3 objForward = (Oyster::Math::Float3(world[8], world[9], world[10]));
|
||||
Oyster::Math::Float3 pos = Oyster::Math::Float3(world[12], world[13], world[14]);
|
||||
|
||||
Oyster::Math::Float3 cameraLook = camera->GetLook();
|
||||
Oyster::Math::Float3 cameraUp = camera->GetUp();
|
||||
|
||||
|
||||
|
||||
/*Oyster::Math::Float3 newUp = cameraUp.Dot(up);
|
||||
up *= newUp;
|
||||
up.Normalize();
|
||||
Oyster::Math::Float3 newLook = up.Cross(right);
|
||||
newLook.Normalize();*/
|
||||
|
||||
camera->setRight(right);
|
||||
camera->setUp(up);
|
||||
//camera->setLook(objForward);
|
||||
|
||||
up *= 2;
|
||||
objForward *= -3;
|
||||
Oyster::Math::Float3 cameraPos = up + pos + objForward;
|
||||
//camera->Pitch(pitch);
|
||||
camera->SetPosition(cameraPos);
|
||||
//camera->LookAt(pos, dir, up);
|
||||
//Oyster::Math::Float3 newLook = objForward;
|
||||
|
||||
camera->UpdateViewMatrix();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@ using namespace Oyster::Physics;
|
|||
|
||||
|
||||
Level::Level(void)
|
||||
:levelObj(0)
|
||||
,testBox(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -16,9 +14,6 @@ Level::~Level(void)
|
|||
{
|
||||
delete this->levelObj;
|
||||
this->levelObj = 0;
|
||||
|
||||
delete this->testBox;
|
||||
this->testBox = 0;
|
||||
}
|
||||
|
||||
void Level::InitiateLevel(std::string levelPath)
|
||||
|
@ -30,7 +25,7 @@ void Level::InitiateLevel(float radius)
|
|||
|
||||
// add level sphere
|
||||
API::SphericalBodyDescription sbDesc;
|
||||
sbDesc.centerPosition = Oyster::Math::Float3(0,0,0);
|
||||
sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
|
||||
sbDesc.ignoreGravity = true;
|
||||
sbDesc.radius = 300;
|
||||
sbDesc.mass = 10e12f;
|
||||
|
@ -40,36 +35,70 @@ void Level::InitiateLevel(float radius)
|
|||
|
||||
ICustomBody::State state;
|
||||
rigidBody->GetState(state);
|
||||
state.SetRestitutionCoeff(0.2f);
|
||||
state.SetRestitutionCoeff(0.2);
|
||||
rigidBody->SetState(state);
|
||||
|
||||
this->levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD);
|
||||
levelObj = new StaticObject(rigidBody, LevelCollisionBefore, LevelCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_WORLD);
|
||||
rigidBody->SetCustomTag(levelObj);
|
||||
|
||||
|
||||
//this->dynamicObjects = new DynamicArray< DynamicObject>;
|
||||
// add box
|
||||
API::SimpleBodyDescription sbDesc_TestBox;
|
||||
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0);
|
||||
sbDesc_TestBox.ignoreGravity = false;
|
||||
|
||||
sbDesc_TestBox.mass = 50;
|
||||
sbDesc_TestBox.size = Oyster::Math::Float4(4,4,4,0);
|
||||
sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0);
|
||||
|
||||
|
||||
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
|
||||
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||
|
||||
testBox = new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX);
|
||||
rigidBody_TestBox->SetCustomTag(testBox);
|
||||
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
|
||||
API::SimpleBodyDescription sbDesc_Crystal;
|
||||
sbDesc_Crystal.centerPosition = Oyster::Math::Float4(10, 305, 0, 0);
|
||||
sbDesc_Crystal.ignoreGravity = false;
|
||||
|
||||
sbDesc_Crystal.mass = 70;
|
||||
sbDesc_Crystal.size = Oyster::Math::Float4(2,3,2,0);
|
||||
|
||||
|
||||
ICustomBody* rigidBody_Crystal = API::Instance().CreateRigidBody(sbDesc_Crystal).Release();
|
||||
rigidBody_Crystal->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
|
||||
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[1]);
|
||||
rigidBody_Crystal->GetState(state);
|
||||
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
|
||||
rigidBody_Crystal->SetState(state);
|
||||
|
||||
// add house
|
||||
API::SimpleBodyDescription sbDesc_House;
|
||||
sbDesc_House.centerPosition = Oyster::Math::Float4(50, 300, 0, 0);
|
||||
sbDesc_House.ignoreGravity = false;
|
||||
|
||||
sbDesc_House.mass = 70;
|
||||
sbDesc_House.size = Oyster::Math::Float4(2,3,2,0);
|
||||
|
||||
|
||||
ICustomBody* rigidBody_House = API::Instance().CreateRigidBody(sbDesc_House).Release();
|
||||
rigidBody_House->SetSubscription(Level::PhysicsOnMoveLevel);
|
||||
this->staticObjects.Push(new StaticObject(rigidBody_House,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_GENERIC));
|
||||
rigidBody_House->SetCustomTag(this->staticObjects[0]);
|
||||
rigidBody_House->GetState(state);
|
||||
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
|
||||
rigidBody_House->SetState(state);
|
||||
|
||||
|
||||
// add gravitation
|
||||
API::Gravity gravityWell;
|
||||
gravityWell.gravityType = API::Gravity::GravityType_Well;
|
||||
gravityWell.well.mass = 1e18f;
|
||||
gravityWell.well.mass = 1e17f;
|
||||
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
|
||||
API::Instance().AddGravity(gravityWell);
|
||||
}
|
||||
|
@ -91,10 +120,12 @@ void Level::RespawnPlayer(Player *player)
|
|||
|
||||
Object* Level::GetObj( int ID) const
|
||||
{
|
||||
if( ID == 0 )
|
||||
return (Object*)levelObj;
|
||||
else
|
||||
return (Object*)testBox;
|
||||
for (int i = 0; i< this->dynamicObjects.Size(); i++)
|
||||
{
|
||||
if(this->dynamicObjects[i]->GetID() == ID)
|
||||
return this->dynamicObjects[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void Level::PhysicsOnMoveLevel(const ICustomBody *object)
|
||||
{
|
||||
|
|
|
@ -71,7 +71,6 @@ namespace GameLogic
|
|||
GameMode gameMode;
|
||||
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
|
||||
StaticObject *levelObj;
|
||||
DynamicObject *testBox;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -120,16 +120,42 @@ void Object::BeginFrame()
|
|||
{
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
if(currPhysicsState.GetCenterPosition() !=currPhysicsState.GetCenterPosition())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
if(currPhysicsState.GetAngularAxis() !=currPhysicsState.GetAngularAxis())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
this->rigidBody->SetState(this->newPhysicsState);
|
||||
}
|
||||
// update physic
|
||||
void Object::EndFrame()
|
||||
{
|
||||
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
this->currPhysicsState = this->rigidBody->GetState();
|
||||
|
||||
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
if(currPhysicsState.GetGravityNormal() !=currPhysicsState.GetGravityNormal())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
if(currPhysicsState.GetGravityNormal()!= Float3::null)
|
||||
{
|
||||
Oyster::Math::Float4 axis;
|
||||
|
@ -144,6 +170,14 @@ void Object::EndFrame()
|
|||
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
|
||||
debug += currPhysicsState.GetGravityNormal();
|
||||
}
|
||||
|
||||
|
||||
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
|
||||
{
|
||||
//error
|
||||
int i =0 ;
|
||||
}
|
||||
|
||||
this->newPhysicsState = this->currPhysicsState;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
using namespace GameLogic;
|
||||
using namespace Oyster::Physics;
|
||||
|
||||
const int MOVE_FORCE = 5000;
|
||||
Player::Player()
|
||||
:DynamicObject()
|
||||
{
|
||||
|
@ -66,8 +66,16 @@ void Player::BeginFrame()
|
|||
|
||||
void Player::EndFrame()
|
||||
{
|
||||
|
||||
// snap to axis
|
||||
Object::EndFrame();
|
||||
// rotate
|
||||
|
||||
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
||||
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
|
||||
|
||||
currPhysicsState.AddRotation(deltaAxis);
|
||||
dx = 0;
|
||||
this->newPhysicsState = this->currPhysicsState;
|
||||
}
|
||||
|
||||
void Player::Move(const PLAYER_MOVEMENT &movement)
|
||||
|
@ -100,13 +108,13 @@ void Player::MoveForward()
|
|||
{
|
||||
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||
//Oyster::Math::Float3 forward = lookDir;
|
||||
newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime()));
|
||||
newPhysicsState.ApplyLinearImpulse(forward * (MOVE_FORCE * this->gameInstance->GetFrameTime()));
|
||||
}
|
||||
void Player::MoveBackwards()
|
||||
{
|
||||
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||
//Oyster::Math::Float3 forward = lookDir;
|
||||
newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime());
|
||||
newPhysicsState.ApplyLinearImpulse(-forward * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
||||
}
|
||||
void Player::MoveRight()
|
||||
{
|
||||
|
@ -114,7 +122,7 @@ void Player::MoveRight()
|
|||
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||
//Oyster::Math::Float3 forward = lookDir;
|
||||
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward);
|
||||
newPhysicsState.ApplyLinearImpulse(-r * 30000 * this->gameInstance->GetFrameTime());
|
||||
newPhysicsState.ApplyLinearImpulse(-r * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
||||
|
||||
}
|
||||
void Player::MoveLeft()
|
||||
|
@ -123,7 +131,7 @@ void Player::MoveLeft()
|
|||
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||
//Oyster::Math::Float3 forward = lookDir;
|
||||
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero
|
||||
newPhysicsState.ApplyLinearImpulse(r * 30000 * this->gameInstance->GetFrameTime());
|
||||
newPhysicsState.ApplyLinearImpulse(r * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
||||
}
|
||||
|
||||
void Player::UseWeapon(const WEAPON_FIRE &usage)
|
||||
|
@ -146,19 +154,20 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
|
|||
{
|
||||
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();
|
||||
//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);
|
||||
//newPhysicsState.SetRotation(oldOrt + deltaAxis);
|
||||
|
||||
this->lookDir = lookDir.xyz;
|
||||
this->dx = lookDir.w;
|
||||
}
|
||||
|
||||
void Player::Jump()
|
||||
{
|
||||
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
||||
newPhysicsState.ApplyLinearImpulse(up * 30000 * this->gameInstance->GetFrameTime());
|
||||
newPhysicsState.ApplyLinearImpulse(up * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
||||
}
|
||||
|
||||
bool Player::IsWalking()
|
||||
|
|
|
@ -83,6 +83,7 @@ namespace GameLogic
|
|||
Weapon *weapon;
|
||||
PLAYER_STATE playerState;
|
||||
Oyster::Math::Float3 lookDir;
|
||||
Oyster::Math::Float dx;
|
||||
|
||||
bool hasTakenDamage;
|
||||
float invincibleCooldown;
|
||||
|
|
|
@ -141,5 +141,7 @@ void Weapon::SelectAttatchment(int socketID)
|
|||
|
||||
void Weapon::Update(float dt)
|
||||
{
|
||||
if(!selectedAttatchment) return;
|
||||
|
||||
selectedAttatchment->Update(dt);
|
||||
}
|
|
@ -86,18 +86,18 @@ namespace DanBias
|
|||
{
|
||||
gameSession->networkTimer.reset();
|
||||
|
||||
GameLogic::IObjectData* obj = movedObject;
|
||||
|
||||
if(dynamic_cast<IPlayerData*> (movedObject))
|
||||
{
|
||||
int id = movedObject->GetID();
|
||||
Oyster::Math::Float4x4 world = movedObject->GetOrientation();
|
||||
int id = obj->GetID();
|
||||
Oyster::Math::Float4x4 world = obj->GetOrientation();
|
||||
|
||||
Protocol_ObjectPosition p(world, id);
|
||||
GameSession::gameSession->Send(p.GetProtocol());
|
||||
}
|
||||
|
||||
if(dynamic_cast<GameLogic::ILevelData*>(movedObject))
|
||||
else if(dynamic_cast<GameLogic::ILevelData*>(obj))
|
||||
{
|
||||
GameLogic::IObjectData* obj = NULL;
|
||||
obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
|
||||
if(obj)
|
||||
{
|
||||
|
@ -111,7 +111,6 @@ namespace DanBias
|
|||
}
|
||||
}
|
||||
|
||||
obj = NULL;
|
||||
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
|
||||
if(obj)
|
||||
{
|
||||
|
@ -123,6 +122,18 @@ namespace DanBias
|
|||
gameSession->Send(p.GetProtocol());
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ API_Impl API_instance;
|
|||
namespace
|
||||
{
|
||||
void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef )
|
||||
{ /** @todo TODO: OnPossibleCollision is a temporary solution .*/
|
||||
{
|
||||
auto proto = worldScene.GetCustomBody( protoTempRef );
|
||||
auto deuter = worldScene.GetCustomBody( deuterTempRef );
|
||||
|
||||
|
@ -26,11 +26,40 @@ namespace
|
|||
ICustomBody::State protoState; proto->GetState( protoState );
|
||||
ICustomBody::State deuterState; deuter->GetState( deuterState );
|
||||
|
||||
Float4 protoG = protoState.GetLinearMomentum(worldPointOfContact.xyz ),
|
||||
// calc from perspective of deuter.
|
||||
Float4 normal = worldPointOfContact - Float4(deuterState.GetCenterPosition(), 1.0f ); // Init value is only borrowed
|
||||
if( normal.Dot(normal) > 0.0f )
|
||||
{
|
||||
deuter->GetNormalAt( worldPointOfContact, normal );
|
||||
}
|
||||
else
|
||||
{ // special case: deuter is completly contained within proto or they have overlapping centers.
|
||||
|
||||
normal = Float4( protoState.GetCenterPosition() - deuterState.GetCenterPosition(), 0.0f );
|
||||
if( normal.Dot(normal) == 0.0f )
|
||||
{ // they have overlapping centers. Rebound at least
|
||||
// calculate and store time interpolation value, for later rebound.
|
||||
proto->SetTimeOfContact( worldPointOfContact );
|
||||
return;
|
||||
}
|
||||
|
||||
// borrowing the negated normal of proto.
|
||||
proto->GetNormalAt( worldPointOfContact, normal );
|
||||
normal = -normal;
|
||||
}
|
||||
|
||||
Float4 protoG = protoState.GetLinearMomentum( worldPointOfContact.xyz ),
|
||||
deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
|
||||
|
||||
// calc from perspective of deuter
|
||||
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal );
|
||||
if( normal != normal ) // debug: trap
|
||||
const char *breakpoint = "This should never happen";
|
||||
|
||||
if( protoG != protoG ) // debug: trap
|
||||
const char *breakpoint = "This should never happen";
|
||||
|
||||
if( deuterG != deuterG ) // debug: trap
|
||||
const char *breakpoint = "This should never happen";
|
||||
|
||||
Float protoG_Magnitude = protoG.Dot( normal ),
|
||||
deuterG_Magnitude = deuterG.Dot( normal );
|
||||
|
||||
|
@ -70,9 +99,25 @@ namespace
|
|||
|
||||
|
||||
// calc from perspective of proto
|
||||
|
||||
normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f );
|
||||
if( normal.Dot(normal) > 0.0f )
|
||||
{
|
||||
proto->GetNormalAt( worldPointOfContact, normal );
|
||||
protoG_Magnitude = protoG.Dot( normal ),
|
||||
protoG_Magnitude = protoG.Dot( normal );
|
||||
deuterG_Magnitude = deuterG.Dot( normal );
|
||||
}
|
||||
else
|
||||
{ // special case: proto is completly contained within deuter.
|
||||
// borrowing the negated normal of deuter.
|
||||
deuter->GetNormalAt( worldPointOfContact, normal );
|
||||
normal = -normal;
|
||||
protoG_Magnitude = -protoG_Magnitude;
|
||||
deuterG_Magnitude = -deuterG_Magnitude;
|
||||
}
|
||||
|
||||
if( normal != normal ) // debug: trap
|
||||
const char *breakpoint = "This should never happen";
|
||||
|
||||
// bounce
|
||||
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(),
|
||||
|
@ -190,6 +235,9 @@ void API_Impl::Update()
|
|||
}
|
||||
}
|
||||
|
||||
if( gravityImpulse != gravityImpulse ) // debug: trap
|
||||
const char *breakpoint = "This should never happen";
|
||||
|
||||
if( gravityImpulse != Float4::null )
|
||||
{
|
||||
state.ApplyLinearImpulse( gravityImpulse.xyz );
|
||||
|
|
|
@ -332,6 +332,7 @@ UpdateState SimpleRigidBody::Update( Float timeStepLength )
|
|||
this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact );
|
||||
this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) );
|
||||
this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact );
|
||||
timeStepLength *= 2.0f - this->collisionRebound.timeOfContact; // compensate for rebounded time
|
||||
this->collisionRebound.timeOfContact = 1.0f;
|
||||
}
|
||||
|
||||
|
|
|
@ -254,6 +254,7 @@ UpdateState SphericalRigidBody::Update( Float timeStepLength )
|
|||
this->rigid.centerPos = Lerp( this->collisionRebound.previousSpatial.center, this->rigid.centerPos, this->collisionRebound.timeOfContact );
|
||||
this->rigid.SetRotation( Lerp(this->collisionRebound.previousSpatial.axis, this->rigid.axis, this->collisionRebound.timeOfContact) );
|
||||
this->rigid.boundingReach = Lerp( this->collisionRebound.previousSpatial.reach, this->rigid.boundingReach, this->collisionRebound.timeOfContact );
|
||||
timeStepLength *= 2.0f - this->collisionRebound.timeOfContact; // compensate for rebounded time
|
||||
this->collisionRebound.timeOfContact = 1.0f;
|
||||
}
|
||||
|
||||
|
|
|
@ -159,7 +159,12 @@ namespace Oyster
|
|||
|
||||
inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const
|
||||
{
|
||||
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, at - this->centerPos );
|
||||
::Oyster::Math::Float3 offset = at - this->centerPos;
|
||||
if( offset.Dot(offset) > 0.0f )
|
||||
{
|
||||
return this->linearMomentum + ::Oyster::Physics3D::Formula::TangentialLinearMomentum( this->angularMomentum, offset );
|
||||
}
|
||||
return this->linearMomentum;
|
||||
}
|
||||
|
||||
inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const
|
||||
|
|
Loading…
Reference in New Issue