GameServer - Merged with gamelogic

This commit is contained in:
Dennis Andersen 2014-02-04 22:33:39 +01:00
commit db822fa832
12 changed files with 250 additions and 100 deletions

View File

@ -78,8 +78,9 @@ bool GameState::LoadModels(std::wstring mapFile)
// open file // open file
// read file // read file
// init models // init models
privData->modelCount = 2; privData->modelCount = 4;
myId += privData->modelCount;
int id = 0;
// add world model // add world model
ModelInitData modelData; ModelInitData modelData;
Oyster::Math3D::Float4x4 translate; Oyster::Math3D::Float4x4 translate;
@ -87,7 +88,7 @@ bool GameState::LoadModels(std::wstring mapFile)
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
modelData.world = translate ;//modelData.world * translate modelData.world = translate ;//modelData.world * translate
modelData.modelPath = L"world_earth.dan"; modelData.modelPath = L"world_earth.dan";
modelData.id = 0; modelData.id = id++;
obj = new C_Player(); obj = new C_Player();
privData->object.push_back(obj); 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)); translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(4,320,0));
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
modelData.modelPath = L"box.dan"; modelData.modelPath = L"box.dan";
modelData.id = 1; modelData.id = id++;
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);
modelData.world = Oyster::Math3D::Float4x4::identity; modelData.world = Oyster::Math3D::Float4x4::identity;
// add player model // add crystal model
modelData.world = Oyster::Math3D::Float4x4::identity; 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.world = modelData.world * translate;
modelData.visible = true; modelData.visible = true;
modelData.modelPath = L"char_white.dan"; modelData.modelPath = L"crystalformation_b.dan";
modelData.id = 2; 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_white.dan";
modelData.id = 3;
// load models // load models
obj = new C_Player(); obj = new C_Player();
privData->object.push_back(obj); privData->object.push_back(obj);
@ -138,25 +126,39 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.world = modelData.world * translate; modelData.world = modelData.world * translate;
modelData.visible = false; modelData.visible = false;
modelData.modelPath = L"building_corporation.dan"; modelData.modelPath = L"building_corporation.dan";
modelData.id = 4; modelData.id = id++;
// load models // load models
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 crystal model // add player model
modelData.world = Oyster::Math3D::Float4x4::identity; 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.world = modelData.world * translate;
modelData.visible = true; modelData.visible = true;
modelData.modelPath = L"crystalformation_b.dan"; modelData.modelPath = L"char_renderTest.dan";
modelData.id = 5; modelData.id = id++;
// load models // load models
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 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; return true;
} }
@ -313,8 +315,8 @@ void GameState::readKeyInput(InputClass* KeyInput)
if (KeyInput->IsMousePressed()) if (KeyInput->IsMousePressed())
{ {
camera->Yaw(-KeyInput->GetYaw()); camera->Yaw(-KeyInput->GetYaw());
//camera->Pitch(KeyInput->GetPitch()); camera->Pitch(KeyInput->GetPitch());
//pitch = KeyInput->GetPitch(); pitch = KeyInput->GetPitch();
camera->UpdateViewMatrix(); camera->UpdateViewMatrix();
GameLogic::Protocol_PlayerLook playerLookDir; GameLogic::Protocol_PlayerLook playerLookDir;
Oyster::Math::Float4 look = camera->GetLook(); Oyster::Math::Float4 look = camera->GetLook();
@ -389,28 +391,34 @@ void GameState::Protocol( ObjPos* pos )
if(privData->object[i]->GetId() == pos->object_ID) if(privData->object[i]->GetId() == pos->object_ID)
{ {
privData->object[i]->setPos(world); 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 if(i == myId) // playerobj
{ {
camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2]))); Oyster::Math::Float3 right = 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 up = Oyster::Math::Float3(world[4], world[5], world[6]); 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; up *= 2;
objForward *= -3; objForward *= -3;
Oyster::Math::Float3 cameraPos = up + pos + objForward; Oyster::Math::Float3 cameraPos = up + pos + objForward;
//camera->Pitch(pitch);
camera->SetPosition(cameraPos); camera->SetPosition(cameraPos);
//camera->LookAt(pos, dir, up);
//Oyster::Math::Float3 newLook = objForward;
camera->UpdateViewMatrix(); camera->UpdateViewMatrix();
} }
} }

View File

@ -7,8 +7,6 @@ using namespace Oyster::Physics;
Level::Level(void) Level::Level(void)
:levelObj(0)
,testBox(0)
{ {
} }
@ -16,9 +14,6 @@ Level::~Level(void)
{ {
delete this->levelObj; delete this->levelObj;
this->levelObj = 0; this->levelObj = 0;
delete this->testBox;
this->testBox = 0;
} }
void Level::InitiateLevel(std::string levelPath) void Level::InitiateLevel(std::string levelPath)
@ -30,7 +25,7 @@ void Level::InitiateLevel(float radius)
// add level sphere // add level sphere
API::SphericalBodyDescription sbDesc; API::SphericalBodyDescription sbDesc;
sbDesc.centerPosition = Oyster::Math::Float3(0,0,0); sbDesc.centerPosition = Oyster::Math::Float4(0,0,0,1);
sbDesc.ignoreGravity = true; sbDesc.ignoreGravity = true;
sbDesc.radius = 300; sbDesc.radius = 300;
sbDesc.mass = 10e12f; sbDesc.mass = 10e12f;
@ -40,36 +35,70 @@ void Level::InitiateLevel(float radius)
ICustomBody::State state; ICustomBody::State state;
rigidBody->GetState(state); rigidBody->GetState(state);
state.SetRestitutionCoeff(0.2f); state.SetRestitutionCoeff(0.2);
rigidBody->SetState(state); 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); rigidBody->SetCustomTag(levelObj);
//this->dynamicObjects = new DynamicArray< DynamicObject>;
// add box // add box
API::SimpleBodyDescription sbDesc_TestBox; API::SimpleBodyDescription sbDesc_TestBox;
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0); sbDesc_TestBox.centerPosition = Oyster::Math::Float4(10,320,0,0);
sbDesc_TestBox.ignoreGravity = false; sbDesc_TestBox.ignoreGravity = false;
sbDesc_TestBox.mass = 50; 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(); ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel); rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
testBox = new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX); this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox,Object::DefaultCollisionBefore, Object::DefaultCollisionAfter, OBJECT_TYPE::OBJECT_TYPE_BOX));
rigidBody_TestBox->SetCustomTag(testBox); rigidBody_TestBox->SetCustomTag(this->dynamicObjects[0]);
rigidBody_TestBox->GetState(state); rigidBody_TestBox->GetState(state);
state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0)); state.ApplyLinearImpulse(Oyster::Math::Float3(0,0,0));
rigidBody_TestBox->SetState(state); 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 // add gravitation
API::Gravity gravityWell; API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well; gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = 1e18f; gravityWell.well.mass = 1e17f;
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);
} }
@ -91,10 +120,12 @@ void Level::RespawnPlayer(Player *player)
Object* Level::GetObj( int ID) const Object* Level::GetObj( int ID) const
{ {
if( ID == 0 ) for (int i = 0; i< this->dynamicObjects.Size(); i++)
return (Object*)levelObj; {
else if(this->dynamicObjects[i]->GetID() == ID)
return (Object*)testBox; return this->dynamicObjects[i];
}
return NULL;
} }
void Level::PhysicsOnMoveLevel(const ICustomBody *object) void Level::PhysicsOnMoveLevel(const ICustomBody *object)
{ {

View File

@ -71,7 +71,6 @@ namespace GameLogic
GameMode gameMode; GameMode gameMode;
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel; Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
StaticObject *levelObj; StaticObject *levelObj;
DynamicObject *testBox;
}; };

View File

@ -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); this->rigidBody->SetState(this->newPhysicsState);
} }
// update physic // update physic
void Object::EndFrame() void Object::EndFrame()
{ {
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
{
//error
int i =0 ;
}
this->currPhysicsState = this->rigidBody->GetState(); 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) if(currPhysicsState.GetGravityNormal()!= Float3::null)
{ {
Oyster::Math::Float4 axis; 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); Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
debug += currPhysicsState.GetGravityNormal(); debug += currPhysicsState.GetGravityNormal();
} }
if(currPhysicsState.GetLinearMomentum() !=currPhysicsState.GetLinearMomentum())
{
//error
int i =0 ;
}
this->newPhysicsState = this->currPhysicsState; this->newPhysicsState = this->currPhysicsState;
} }

View File

@ -6,7 +6,7 @@
using namespace GameLogic; using namespace GameLogic;
using namespace Oyster::Physics; using namespace Oyster::Physics;
const int MOVE_FORCE = 5000;
Player::Player() Player::Player()
:DynamicObject() :DynamicObject()
{ {
@ -66,8 +66,16 @@ void Player::BeginFrame()
void Player::EndFrame() void Player::EndFrame()
{ {
// snap to axis
Object::EndFrame(); 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) 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 = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir; //Oyster::Math::Float3 forward = lookDir;
newPhysicsState.ApplyLinearImpulse(forward * (30000 * this->gameInstance->GetFrameTime())); newPhysicsState.ApplyLinearImpulse(forward * (MOVE_FORCE * this->gameInstance->GetFrameTime()));
} }
void Player::MoveBackwards() void Player::MoveBackwards()
{ {
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir; //Oyster::Math::Float3 forward = lookDir;
newPhysicsState.ApplyLinearImpulse(-forward * 30000 * this->gameInstance->GetFrameTime()); newPhysicsState.ApplyLinearImpulse(-forward * MOVE_FORCE * this->gameInstance->GetFrameTime());
} }
void Player::MoveRight() void Player::MoveRight()
{ {
@ -114,7 +122,7 @@ void Player::MoveRight()
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir; //Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); 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() void Player::MoveLeft()
@ -123,7 +131,7 @@ void Player::MoveLeft()
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2]; Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir; //Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-currPhysicsState.GetGravityNormal()).Cross(forward); //Still get zero 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) void Player::UseWeapon(const WEAPON_FIRE &usage)
@ -146,19 +154,20 @@ 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 up = currPhysicsState.GetOrientation().v[1];
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ; //Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation(); //Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
newPhysicsState.SetRotation(oldOrt + deltaAxis); //newPhysicsState.SetRotation(oldOrt + deltaAxis);
this->lookDir = lookDir.xyz; this->lookDir = lookDir.xyz;
this->dx = lookDir.w;
} }
void Player::Jump() void Player::Jump()
{ {
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1]; 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() bool Player::IsWalking()

View File

@ -83,6 +83,7 @@ namespace GameLogic
Weapon *weapon; Weapon *weapon;
PLAYER_STATE playerState; PLAYER_STATE playerState;
Oyster::Math::Float3 lookDir; Oyster::Math::Float3 lookDir;
Oyster::Math::Float dx;
bool hasTakenDamage; bool hasTakenDamage;
float invincibleCooldown; float invincibleCooldown;

View File

@ -141,5 +141,7 @@ void Weapon::SelectAttatchment(int socketID)
void Weapon::Update(float dt) void Weapon::Update(float dt)
{ {
if(!selectedAttatchment) return;
selectedAttatchment->Update(dt); selectedAttatchment->Update(dt);
} }

View File

@ -86,18 +86,18 @@ namespace DanBias
{ {
gameSession->networkTimer.reset(); gameSession->networkTimer.reset();
GameLogic::IObjectData* obj = movedObject;
if(dynamic_cast<IPlayerData*> (movedObject)) if(dynamic_cast<IPlayerData*> (movedObject))
{ {
int id = movedObject->GetID(); int id = obj->GetID();
Oyster::Math::Float4x4 world = movedObject->GetOrientation(); Oyster::Math::Float4x4 world = obj->GetOrientation();
Protocol_ObjectPosition p(world, id); Protocol_ObjectPosition p(world, id);
GameSession::gameSession->Send(p.GetProtocol()); GameSession::gameSession->Send(p.GetProtocol());
} }
else if(dynamic_cast<GameLogic::ILevelData*>(obj))
if(dynamic_cast<GameLogic::ILevelData*>(movedObject))
{ {
GameLogic::IObjectData* obj = NULL;
obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0); obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
if(obj) if(obj)
{ {
@ -111,7 +111,6 @@ namespace DanBias
} }
} }
obj = NULL;
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1); obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
if(obj) if(obj)
{ {
@ -123,6 +122,18 @@ namespace DanBias
gameSession->Send(p.GetProtocol()); 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());
}
}
} }
} }

View File

@ -15,7 +15,7 @@ API_Impl API_instance;
namespace namespace
{ {
void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef ) void OnPossibleCollision( Octree& worldScene, unsigned int protoTempRef, unsigned int deuterTempRef )
{ /** @todo TODO: OnPossibleCollision is a temporary solution .*/ {
auto proto = worldScene.GetCustomBody( protoTempRef ); auto proto = worldScene.GetCustomBody( protoTempRef );
auto deuter = worldScene.GetCustomBody( deuterTempRef ); auto deuter = worldScene.GetCustomBody( deuterTempRef );
@ -26,11 +26,40 @@ namespace
ICustomBody::State protoState; proto->GetState( protoState ); ICustomBody::State protoState; proto->GetState( protoState );
ICustomBody::State deuterState; deuter->GetState( deuterState ); 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 ); deuterG = deuterState.GetLinearMomentum( worldPointOfContact.xyz );
// calc from perspective of deuter if( normal != normal ) // debug: trap
Float4 normal; deuter->GetNormalAt( worldPointOfContact, normal ); 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 ), Float protoG_Magnitude = protoG.Dot( normal ),
deuterG_Magnitude = deuterG.Dot( normal ); deuterG_Magnitude = deuterG.Dot( normal );
@ -70,9 +99,25 @@ namespace
// calc from perspective of proto // calc from perspective of proto
normal = worldPointOfContact - Float4(protoState.GetCenterPosition(), 1.0f );
if( normal.Dot(normal) > 0.0f )
{
proto->GetNormalAt( worldPointOfContact, normal ); proto->GetNormalAt( worldPointOfContact, normal );
protoG_Magnitude = protoG.Dot( normal ), protoG_Magnitude = protoG.Dot( normal );
deuterG_Magnitude = deuterG.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 // bounce
Float4 bounceP = normal * Formula::CollisionResponse::Bounce( protoState.GetRestitutionCoeff(), 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 ) if( gravityImpulse != Float4::null )
{ {
state.ApplyLinearImpulse( gravityImpulse.xyz ); state.ApplyLinearImpulse( gravityImpulse.xyz );

View File

@ -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.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.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 ); 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; this->collisionRebound.timeOfContact = 1.0f;
} }

View File

@ -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.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.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 ); 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; this->collisionRebound.timeOfContact = 1.0f;
} }

View File

@ -159,7 +159,12 @@ namespace Oyster
inline ::Oyster::Math::Float3 CustomBodyState::GetLinearMomentum( const ::Oyster::Math::Float3 &at ) const 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 inline const ::Oyster::Math::Float3 & CustomBodyState::GetAngularMomentum() const