GL - added some testing things in player and more objects to the world

This commit is contained in:
lindaandersson 2014-02-04 16:08:28 +01:00
parent 502d0c8586
commit d8c7220569
8 changed files with 155 additions and 69 deletions

View File

@ -163,9 +163,9 @@ namespace DanBias
DanBias::GameServerAPI::GameStart();
m_data->recieverObj->gameClientState = new Client::GameState();
if(m_data->serverOwner)
((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(2);
((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(0);
else
((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(3);
((Client::GameState*)m_data->recieverObj->gameClientState)->setClientId(1);
break;
default:
return E_FAIL;

View File

@ -74,8 +74,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;
@ -83,7 +84,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);
@ -94,34 +95,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"..\\Content\\Models\\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_renderTest.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_renderTest.dan";
modelData.id = 3;
modelData.modelPath = L"crystalformation_b.dan";
modelData.id = id++;
// load models
obj = new C_Player();
privData->object.push_back(obj);
@ -134,25 +122,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;
}
@ -309,8 +311,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();
@ -385,28 +387,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();
}
}

View File

@ -39,30 +39,64 @@ void Level::InitiateLevel(float radius)
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);
}
@ -84,10 +118,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)
{

View File

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

View File

@ -120,9 +120,21 @@ 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
@ -130,6 +142,11 @@ void Object::EndFrame()
{
this->currPhysicsState = this->rigidBody->GetState();
if(currPhysicsState.GetGravityNormal() !=currPhysicsState.GetGravityNormal())
{
//error
int i =0 ;
}
if(currPhysicsState.GetGravityNormal()!= Float3::null)
{
Oyster::Math::Float4 axis;
@ -144,6 +161,9 @@ void Object::EndFrame()
Oyster::Math::Float3 debug = ::LinearAlgebra3D::WorldAxisOf(::LinearAlgebra3D::Rotation(axis.xyz), Oyster::Math::Float3::standard_unit_y);
debug += currPhysicsState.GetGravityNormal();
}
this->newPhysicsState = this->currPhysicsState;
}

View File

@ -6,7 +6,7 @@
using namespace GameLogic;
using namespace Oyster::Physics;
const int MOVE_FORCE = 50000;
Player::Player()
:DynamicObject()
{
@ -67,8 +67,17 @@ 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) ;
Oyster::Math::Float3 oldOrt = currPhysicsState.GetRotation();
currPhysicsState.AddRotation(deltaAxis);
dx = 0;
this->newPhysicsState = this->currPhysicsState;
}
void Player::Move(const PLAYER_MOVEMENT &movement)
@ -101,13 +110,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()
{
@ -115,7 +124,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()
@ -124,7 +133,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)
@ -147,19 +156,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()

View File

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

View File

@ -122,6 +122,18 @@ namespace DanBias
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());
}
}
}
}