Merge branch 'GameLogic' of https://github.com/dean11/Danbias into GameLogic

This commit is contained in:
Pontus Fransson 2014-02-11 14:13:49 +01:00
commit a99a9b3e2e
24 changed files with 224 additions and 330 deletions

View File

@ -5,6 +5,9 @@ void C_Object::Init(ModelInitData modelInit)
position = modelInit.position;
rotation = modelInit.rotation;
scale = modelInit.scale;
id = modelInit.id;
model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
model->Visible = modelInit.visible;
updateWorld();
}
void C_Object::updateWorld()
@ -17,10 +20,12 @@ void C_Object::updateWorld()
scale.v[1].y = this->scale[1];
scale.v[2].z = this->scale[2];
world = translation * rot * scale;
model->WorldMatrix = world;
}
void C_Object::setWorld(Oyster::Math::Float4x4 world)
{
model->WorldMatrix = world;
}
Oyster::Math::Float4x4 C_Object::getWorld() const
{
@ -68,7 +73,15 @@ Oyster::Math::Float3 C_Object::getScale() const
{
return this->scale;
}
//int C_Object::GetId() const
//{
// return
//}
int C_Object::GetId() const
{
return id;
}
void C_Object::Render()
{
Oyster::Graphics::API::RenderModel(*(model));
}
void C_Object::Release()
{
Oyster::Graphics::API::DeleteModel(model);
}

View File

@ -23,6 +23,8 @@ private:
Oyster::Math::Float3 position;
Oyster::Math::Quaternion rotation;
Oyster::Math::Float3 scale;
Oyster::Graphics::Model::Model *model;
int id;
void updateWorld();
public:
@ -40,8 +42,8 @@ public:
void addScale(Oyster::Math::Float3 deltaScale);
Oyster::Math::Float3 getScale() const;
virtual void Render() = 0;
virtual void Release() = 0;
virtual int GetId() = 0;
virtual void Render();
virtual void Release();
virtual int GetId() const;
};};};
#endif

View File

@ -1,15 +1,7 @@
#include "C_DynamicObj.h"
#include "DllInterfaces/GFXAPI.h"
using namespace DanBias::Client;
struct C_DynamicObj::myData
{
myData(){}
Oyster::Graphics::Model::Model *model;
int ID;
// light
// sound
// effect
}privData;
C_DynamicObj::C_DynamicObj(void)
{
}
@ -22,24 +14,4 @@ C_DynamicObj::~C_DynamicObj(void)
void C_DynamicObj::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
// load models
privData = new myData();
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->Visible = modelInit.visible;
privData->model->WorldMatrix = getWorld();
privData->ID = modelInit.id;
}
void C_DynamicObj::Render()
{
Oyster::Graphics::API::RenderModel(*(privData->model));
}
void C_DynamicObj::Release()
{
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_DynamicObj::GetId()
{
return privData->ID;
}

View File

@ -8,15 +8,10 @@ namespace DanBias
class C_DynamicObj : public C_Object
{
private:
struct myData;
myData* privData;
public:
C_DynamicObj(void);
virtual ~C_DynamicObj(void);
void Init(ModelInitData modelInit);
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -2,21 +2,11 @@
#include "DllInterfaces/GFXAPI.h"
using namespace DanBias::Client;
struct C_Player::myData
{
myData(){}
Oyster::Math3D::Float4x4 view;
Oyster::Math3D::Float4x4 proj;
Oyster::Graphics::Model::Model *model;
Oyster::Math3D::Float4 lookDir;
int ID;
}privData;
C_Player::C_Player(void)
:C_DynamicObj()
{
}
}
C_Player::~C_Player(void)
{
@ -26,26 +16,4 @@ C_Player::~C_Player(void)
void C_Player::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
// load models
privData = new myData();
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->Visible = modelInit.visible;
privData->model->WorldMatrix = getWorld();
privData->ID = modelInit.id;
privData->lookDir = Oyster::Math3D::Float4 (0,0,1,0);
}
void C_Player::Render()
{
Oyster::Graphics::API::RenderModel(*(privData->model));
}
void C_Player::Release()
{
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_Player::GetId()
{
return privData->ID;
}

View File

@ -8,18 +8,11 @@ namespace DanBias
class C_Player : public C_DynamicObj
{
private:
struct myData;
myData* privData;
public:
C_Player(void);
virtual ~C_Player(void);
void Init(ModelInitData modelInit);
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -3,18 +3,10 @@
#include "DllInterfaces/GFXAPI.h"
using namespace DanBias::Client;
struct C_StaticObj::myData
{
myData(){}
Oyster::Graphics::Model::Model *model;
int ID;
}privData;
C_StaticObj::C_StaticObj(void)
{
}
C_StaticObj::~C_StaticObj(void)
{
@ -22,26 +14,4 @@ C_StaticObj::~C_StaticObj(void)
void C_StaticObj::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
// load models
privData = new myData();
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->Visible = modelInit.visible;
privData->model->WorldMatrix = getWorld();
privData->ID = modelInit.id;
}
void C_StaticObj::Render()
{
Oyster::Graphics::API::RenderModel(*(privData->model));
}
void C_StaticObj::Release()
{
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_StaticObj::GetId()
{
return privData->ID;
}

View File

@ -8,15 +8,10 @@ namespace DanBias
class C_StaticObj : public C_Object
{
private:
struct myData;
myData* privData;
public:
C_StaticObj(void);
virtual ~C_StaticObj(void);
void Init(ModelInitData modelInit);
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -2,13 +2,6 @@
#include "DllInterfaces/GFXAPI.h"
using namespace DanBias::Client;
struct C_UIobject::myData
{
myData(){}
Oyster::Graphics::Model::Model *model;
int ID;
}privData;
C_UIobject::C_UIobject(void)
{
}
@ -20,29 +13,4 @@ C_UIobject::~C_UIobject(void)
void C_UIobject::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
// load models
privData = new myData();
privData->model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
privData->model->Visible = modelInit.visible;
privData->model->WorldMatrix = getWorld();
privData->ID = modelInit.id;
}
void C_UIobject::setPos(Oyster::Math::Float4x4 world)
{
privData->model->WorldMatrix = world;
}
void C_UIobject::Render()
{
Oyster::Graphics::API::RenderModel(*(privData->model));
}
void C_UIobject::Release()
{
Oyster::Graphics::API::DeleteModel(privData->model);
delete privData;
}
int C_UIobject::GetId()
{
return privData->ID;
}

View File

@ -8,16 +8,11 @@ namespace DanBias
class C_UIobject : public C_Object
{
private:
struct myData;
myData* privData;
public:
C_UIobject(void);
virtual ~C_UIobject(void);
void Init(ModelInitData modelInit);
void setPos(Oyster::Math::Float4x4 world);
void Render();
void Release();
int GetId();
};};};
#endif

View File

@ -122,7 +122,7 @@ bool GameState::LoadModels()
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
}
/*
// add crystal model
modelData.position = Oyster::Math::Float3(10, 301, 0);
modelData.modelPath = L"crystalformation_b.dan";
@ -174,7 +174,7 @@ bool GameState::LoadModels()
modelData.id = id++;
// load models
this->dynamicObjects.Push(new C_DynamicObj());
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);
this->dynamicObjects[this->dynamicObjects.Size() -1 ]->Init(modelData);*/
return true;
}
bool GameState::LoadModels(std::string mapFile)
@ -316,7 +316,7 @@ void GameState::InitiatePlayer(int id, std::wstring modelName, Oyster::Math::Flo
camera->setLook(objForward);
up *= 2;
objForward *= -3;
objForward *= 3;
Oyster::Math::Float3 cameraPos = up + pos + objForward;
camera->SetPosition(cameraPos);
@ -453,14 +453,14 @@ void GameState::readKeyInput(InputClass* KeyInput)
}
//send delta mouse movement
//if (KeyInput->IsMousePressed())
if (KeyInput->IsMousePressed())
{
camera->Yaw(-KeyInput->GetYaw());
camera->Pitch(KeyInput->GetPitch());
pitch = KeyInput->GetPitch();
camera->UpdateViewMatrix();
GameLogic::Protocol_PlayerLook playerLookDir;
Oyster::Math::Float4 look = camera->GetLook();
Oyster::Math::Float4 look = camera->GetRight();
playerLookDir.lookDirX = look.x;
playerLookDir.lookDirY = look.y;
playerLookDir.lookDirZ = look.z;
@ -565,9 +565,8 @@ void GameState::Protocol( ObjPos* pos )
{
if(dynamicObjects[i]->GetId() == pos->object_ID)
{
dynamicObjects[i]->setPos(Float3(world[12], world[13], world[14]));
//dynamicObjects[i]->setPos(Float3(world[12], world[13], world[14]));
dynamicObjects[i]->setWorld(world);
if(dynamicObjects[i]->GetId() == myId) // playerobj
{
@ -591,10 +590,10 @@ void GameState::Protocol( ObjPos* pos )
//camera->setUp(up);
//camera->setLook(objForward);
up *= 1;
up *= 2;
objForward *= -2;
Oyster::Math::Float3 cameraPos = pos + up + objForward;
//camera->SetPosition(cameraPos);
camera->SetPosition(cameraPos);
//camera->UpdateViewMatrix();
}

View File

@ -8,7 +8,7 @@ Game::PlayerData::PlayerData()
//set some stats that are appropriate to a player
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,608,-5);
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f);
Oyster::Math::Float mass = 15;
Oyster::Math::Float mass = 60;
Oyster::Math::Float restitutionCoeff = 0.5;
Oyster::Math::Float frictionCoeff_Static = 0.4;
Oyster::Math::Float frictionCoeff_Dynamic = 0.3;
@ -16,7 +16,7 @@ Game::PlayerData::PlayerData()
//create rigid body
Oyster::Physics::ICustomBody* rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
rigidBody->SetAngularFactor(0.0f);
//create player with this rigid body
this->player = new Player(rigidBody,Level::LevelCollisionBefore, Player::PlayerCollision, OBJECT_TYPE::OBJECT_TYPE_PLAYER);
this->player->GetRigidBody()->SetCustomTag(this);

View File

@ -112,36 +112,8 @@ void Level::InitiateLevel(std::string levelPath)
}
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;
}
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
API::Instance().SetGravity(50);
int idCount = 100;
// add level sphere
ICustomBody* rigidBody = API::Instance().AddCollisionSphere(599.2f, Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);

View File

@ -20,8 +20,6 @@ Object::Object()
this->type = OBJECT_TYPE::OBJECT_TYPE_UNKNOWN;
this->objectID = GID();
this->currPhysicsState = this->rigidBody->GetState();
this->newPhysicsState = this->currPhysicsState;
}
Object::Object(OBJECT_TYPE type)
@ -29,8 +27,6 @@ Object::Object(OBJECT_TYPE type)
this->rigidBody = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.0f, 0.0f, 0.0f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 0, 0), 0, 0.5f, 0.8f, 0.6f);
this->type = type;
this->objectID = GID();
this->currPhysicsState = this->rigidBody->GetState();
this->newPhysicsState = this->currPhysicsState;
}
Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
@ -38,8 +34,6 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
this->rigidBody = rigidBody;
this->type = type;
this->objectID = GID();
this->currPhysicsState = this->rigidBody->GetState();
this->newPhysicsState = this->currPhysicsState;
}
Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
@ -48,8 +42,6 @@ Object::Object(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE
this->type = type;
this->objectID = GID();
this->currPhysicsState = this->rigidBody->GetState();
this->newPhysicsState = this->currPhysicsState;
}
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
@ -58,19 +50,14 @@ Object::Object(Oyster::Physics::ICustomBody *rigidBody ,void* collisionFuncBefor
this->type = type;
this->objectID = GID();
this->currPhysicsState = this->rigidBody->GetState();
this->newPhysicsState = this->currPhysicsState;
}
Object::Object(Oyster::Physics::ICustomBody *rigidBody ,Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter), Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncAfter)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
{
this->rigidBody = rigidBody;
this->type = type;
this->objectID = GID();
this->currPhysicsState = this->rigidBody->GetState();
this->newPhysicsState = this->currPhysicsState;
}
void Object::ApplyLinearImpulse(Oyster::Math::Float3 force)
@ -102,12 +89,11 @@ Oyster::Physics::ICustomBody* Object::GetRigidBody()
void Object::BeginFrame()
{
this->rigidBody->SetState(this->newPhysicsState);
}
// update physic
void Object::EndFrame()
{
this->newPhysicsState = this->currPhysicsState;
}
void Object::setBeforeCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage (*collisionFuncBefore)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter))
@ -119,15 +105,37 @@ void Object::setAfterCollisonFunc(Oyster::Physics::ICustomBody::SubscriptMessage
this->rigidBody->SetSubscription((Oyster::Physics::ICustomBody::EventAction_AfterCollisionResponse)(collisionFuncAfter));
}
Oyster::Math::Float3 Object::GetPosition()
{
Oyster::Physics::ICustomBody::State state;
state = this->rigidBody->GetState();
return state.centerPos;
}
Oyster::Math::Float4x4 Object::GetOrientation()
{
Oyster::Physics::ICustomBody::State state;
state = this->rigidBody->GetState();
return state.GetOrientation();
}
Oyster::Math::Float3 Object::GetPosition()
{
return this->position;
}
Oyster::Math::Float3 Object::GetRotation()
{
return this->rotation;
}
Oyster::Math::Float3 Object::GetScaling()
{
return this->scale;
}
void Object::SetPosition(Oyster::Math::Float3 position)
{
this->position = position;
}
void Object::SetRotation(Oyster::Math::Float3 rotation)
{
this->rotation = rotation;
}
void Object::SetScaling(Oyster::Math::Float3 scale)
{
this->scale = scale;
}

View File

@ -29,10 +29,17 @@ namespace GameLogic
OBJECT_TYPE GetObjectType() const;
void setID(int id);
int GetID() const;
Oyster::Math::Float3 GetPosition();
Oyster::Math::Float4x4 GetOrientation();
Oyster::Math::Float3 GetPosition();
Oyster::Math::Float3 GetRotation();
Oyster::Math::Float3 GetScaling();
void SetPosition(Oyster::Math::Float3 position);
void SetRotation(Oyster::Math::Float3 rotation);
void SetScaling(Oyster::Math::Float3 scale);
Oyster::Physics::ICustomBody* GetRigidBody();
void ApplyLinearImpulse(Oyster::Math::Float3 force);
@ -51,12 +58,15 @@ namespace GameLogic
protected:
Oyster::Physics::ICustomBody *rigidBody;
Oyster::Physics::ICustomBody::State newPhysicsState;
Oyster::Physics::ICustomBody::State currPhysicsState;
static const Game* gameInstance;
Oyster::Math::Float3 currLook;
Oyster::Math::Float3 newLook;
Oyster::Math::Float3 position;
Oyster::Math::Float3 rotation;
Oyster::Math::Float3 scale;
};
}

View File

@ -6,7 +6,7 @@
using namespace GameLogic;
using namespace Oyster::Physics;
const int MOVE_FORCE = 500;
const int MOVE_FORCE = 30;
Player::Player()
:DynamicObject()
{
@ -22,7 +22,6 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, OBJECT_TYPE type)
{
InitPlayer();
}
Player::Player(void* collisionFuncBefore, void* collisionFuncAfter, OBJECT_TYPE type)
:DynamicObject(collisionFuncBefore,collisionFuncAfter,type)
{
@ -60,22 +59,16 @@ Player::~Player(void)
void Player::BeginFrame()
{
weapon->Update(0.002f);
//weapon->Update(0.002f);
Object::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)
@ -106,33 +99,27 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
void Player::MoveForward()
{
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir;
//newPhysicsState.ApplyLinearImpulse(forward * (MOVE_FORCE * this->gameInstance->GetFrameTime()));
//rigidBody->SetLinearVelocity( 10 * this->gameInstance->GetFrameTime() );
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
rigidBody->SetLinearVelocity( MOVE_FORCE * forward.GetNormalized() );
}
void Player::MoveBackwards()
{
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir;
//newPhysicsState.ApplyLinearImpulse(-forward * MOVE_FORCE * this->gameInstance->GetFrameTime());
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
rigidBody->SetLinearVelocity( MOVE_FORCE * -forward.GetNormalized() );
}
void Player::MoveRight()
{
//Do cross product with forward vector and negative gravity vector
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
//Oyster::Math::Float3 forward = lookDir;
Oyster::Math::Float3 r = (-currPhysicsState.centerPos.Normalize()).Cross(forward);
//rigidBody->SetLinearVelocity(-r * 10 * this->gameInstance->GetFrameTime() );
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
Oyster::Math::Float3 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward);
rigidBody->SetLinearVelocity(r * MOVE_FORCE);
}
void Player::MoveLeft()
{
//Do cross product with forward vector and negative gravity vector
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 * MOVE_FORCE * this->gameInstance->GetFrameTime());
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
Oyster::Math::Float3 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward);
rigidBody->SetLinearVelocity(-r * MOVE_FORCE);
}
void Player::UseWeapon(const WEAPON_FIRE &usage)
@ -145,11 +132,12 @@ void Player::Respawn(Oyster::Math::Float3 spawnPoint)
this->life = 100;
this->playerState = PLAYER_STATE::PLAYER_STATE_IDLE;
this->lookDir = Oyster::Math::Float4(1,0,0);
this->newPhysicsState.centerPos = spawnPoint;
this->rigidBody->SetPosition(spawnPoint);
}
void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
{
// right
Oyster::Math::Float dx = lookDir.w;
if(dx > 0.0f)
{
@ -158,12 +146,18 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
this->lookDir = lookDir.xyz;
this->dx = lookDir.w;
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1];
this->rigidBody->SetUpAndRight(up, lookDir.xyz);
this->rigidBody->SetUpAndRight(this->rigidBody->GetState().centerPos.GetNormalized(), this->rigidBody->GetState().GetOrientation().v[0].xyz.GetNormalized());
}
void Player::Jump()
{
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
//newPhysicsState.ApplyLinearImpulse(up * MOVE_FORCE * this->gameInstance->GetFrameTime());
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1];
//this->rigidBody->GetState().SetLinearVelocity(up *10);
}
bool Player::IsWalking()
@ -181,11 +175,11 @@ bool Player::IsIdle()
Oyster::Math::Float3 Player::GetPosition() const
{
return (Oyster::Math::Float3)currPhysicsState.centerPos;
return (Oyster::Math::Float3) this->rigidBody->GetState().centerPos;
}
Oyster::Math::Float4x4 Player::GetOrientation() const
{
return this->currPhysicsState.GetOrientation();
return this->rigidBody->GetState().GetOrientation();
}
Oyster::Math::Float3 Player::GetLookDir() const
{

View File

@ -97,59 +97,10 @@ namespace DanBias
GameSession::gameSession->networkTimer.reset();
GameLogic::IObjectData* obj = movedObject;
if(movedObject->GetID() == testID) //TODO: TEST
{
float sec = (float)testTimer.getElapsedSeconds();
sec = 0;
}
int id = obj->GetID();
Protocol_ObjectPosition p(obj->GetOrientation(), id);
//if(id != 1)
GameSession::gameSession->Send(p.GetProtocol());
/*
if(dynamic_cast<GameLogic::ILevelData*>(obj))
{
obj = ((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
if(obj)
{
if(obj->GetObjectType() == OBJECT_TYPE_WORLD)
{
int id = obj->GetID();
Oyster::Math::Float4x4 world =obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
gameSession->Send(p.GetProtocol());
}
}
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(1);
if(obj)
{
if(obj->GetObjectType() == OBJECT_TYPE_BOX)
{
int id = obj->GetID();
Oyster::Math::Float4x4 world = obj->GetOrientation();
Protocol_ObjectPosition p(world, id);
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

@ -136,7 +136,7 @@ namespace DanBias
}
else
{
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation());
Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_temporary.dan", readyList[i]->GetPlayer()->GetOrientation());
readyList[i]->GetClient()->Send(p);
}
}
@ -156,7 +156,7 @@ namespace DanBias
{
if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID())
{
Protocol_ObjectCreate p(this->clients[k]->GetPlayer()->GetOrientation(), this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later..
Protocol_ObjectCreate p(this->clients[k]->GetPlayer()->GetOrientation(), this->clients[k]->GetPlayer()->GetID(), "char_temporary.dan"); //The model name will be custom later..
readyList[i]->GetClient()->Send(p);
}
}

View File

@ -24,6 +24,11 @@ API_Impl::API_Impl()
this->dispatcher = NULL;
this->solver = NULL;
this->dynamicsWorld = NULL;
this->timeStep = 1.0f/120.0f;
this->gravityPoint = Float3(0.0f, 0.0f, 0.0f);
this->gravity = 10.0f;
}
API_Impl::~API_Impl()
@ -39,13 +44,23 @@ API_Impl::~API_Impl()
delete this->broadphase;
this->broadphase = NULL;
for(int i = 0; i < this->customBodies.size(); i++)
for(unsigned int i = 0; i < this->customBodies.size(); i++)
{
delete this->customBodies[i];
this->customBodies[i] = NULL;
}
}
void API_Impl::SetGravityPoint(::Oyster::Math::Float3 gravityPoint)
{
this->gravityPoint = gravityPoint;
}
void API_Impl::SetGravity(float gravity)
{
this->gravity = gravity;
}
// Bullet physics
ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction)
{
@ -164,27 +179,38 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O
return body;
}
void API_Impl::SetTimeStep(float timeStep)
{
this->timeStep = timeStep;
}
void API_Impl::UpdateWorld()
{
this->dynamicsWorld->stepSimulation(1.0f/60.0f, 1.0f, 1.0f/60.0f);
for(unsigned int i = 0; i < this->customBodies.size(); i++ )
{
this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity);
}
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep);
ICustomBody::State state;
for(unsigned int i = 0; i < this->customBodies.size(); i++ )
{
SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]);
btTransform trans;
dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->GetMotionState()->getWorldTransform(trans);
simpleBody->GetMotionState()->getWorldTransform(trans);
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));
if(dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->GetRigidBody()->getActivationState() == ACTIVE_TAG)
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
{
dynamic_cast<SimpleRigidBody*>(this->customBodies[i])->CallSubscription_Move();
simpleBody->CallSubscription_Move();
}
}
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();
for (int i=0;i<numManifolds;i++)
for (int i = 0; i < numManifolds; i++)
{
btPersistentManifold* contactManifold = this->dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
const btCollisionObject* obA = contactManifold->getBody0();
@ -195,18 +221,6 @@ void API_Impl::UpdateWorld()
dynamic_cast<SimpleRigidBody*>(bodyA)->CallSubscription_AfterCollisionResponse(bodyA, bodyB, 0.0f);
dynamic_cast<SimpleRigidBody*>(bodyB)->CallSubscription_AfterCollisionResponse(bodyB, bodyA, 0.0f);
int numContacts = contactManifold->getNumContacts();
for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
if (pt.getDistance()<0.f)
{
const btVector3& ptA = pt.getPositionWorldOnA();
const btVector3& ptB = pt.getPositionWorldOnB();
const btVector3& normalOnB = pt.m_normalWorldOnB;
}
}
}
}
@ -257,9 +271,7 @@ namespace Oyster
}
void EventAction_AfterCollisionResponse( const ::Oyster::Physics::ICustomBody *proto, const ::Oyster::Physics::ICustomBody *deuter, ::Oyster::Math::Float kineticEnergyLoss )
{ /* Do nothing except returning business as usual. */
}
{ /* Do nothing except returning business as usual. */ }
void EventAction_Move( const ::Oyster::Physics::ICustomBody *object )
{ /* Do nothing. */ }

View File

@ -21,11 +21,16 @@ namespace Oyster
void MoveToLimbo( const ICustomBody* objRef );
void ReleaseFromLimbo( const ICustomBody* objRef );
void SetGravityPoint(::Oyster::Math::Float3 gravityPoint);
void SetGravity(float gravity);
// Bullet physics
ICustomBody* AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction);
void SetTimeStep(float timeStep);
void UpdateWorld();
void ApplyEffect( const Oyster::Collision3D::ICollideable& collideable, void* args, void(hitAction)(ICustomBody*, void*) );
@ -37,6 +42,11 @@ namespace Oyster
btSequentialImpulseConstraintSolver* solver;
btDiscreteDynamicsWorld* dynamicsWorld;
std::vector<ICustomBody*> customBodies;
float timeStep;
::Oyster::Math::Float3 gravityPoint;
float gravity;
};
namespace Default

View File

@ -134,6 +134,54 @@ void SimpleRigidBody::SetRotation(Float3 eulerAngles)
this->state.quaternion = Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w());
}
void SimpleRigidBody::SetAngularFactor(Float factor)
{
this->rigidBody->setAngularFactor(factor);
}
void SimpleRigidBody::SetGravity(Float3 gravity)
{
this->rigidBody->setGravity(btVector3(gravity.x, gravity.y, gravity.z));
this->gravity = gravity;
}
void SimpleRigidBody::SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right)
{
btTransform trans;
btMatrix3x3 rotation;
btVector3 upVector(up.x, up.y, up.z);
btVector3 rightVector(right.x, right.y, right.z);
rotation[1] = upVector.normalized();
rotation[0] = rightVector.normalized();
rotation[2] = rightVector.cross(upVector).normalized();
trans = this->rigidBody->getWorldTransform();
trans.setBasis(rotation);
this->rigidBody->setWorldTransform(trans);
btQuaternion quaternion;
quaternion = trans.getRotation();
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
}
void SimpleRigidBody::SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward)
{
btTransform trans;
btMatrix3x3 rotation;
btVector3 upVector(up.x, up.y, up.z);
btVector3 forwardVector(forward.x, forward.y, forward.z);
rotation[1] = upVector.normalized();
rotation[2] = forwardVector.normalized();
rotation[0] = forwardVector.cross(upVector).normalized();
trans = this->rigidBody->getWorldTransform();
trans.setBasis(rotation);
this->rigidBody->setWorldTransform(trans);
btQuaternion quaternion;
quaternion = trans.getRotation();
this->state.quaternion = Quaternion(Float3(quaternion.x(), quaternion.y(), quaternion.z()), quaternion.w());
}
Float4x4 SimpleRigidBody::GetRotation() const
{
return this->state.GetRotation();

View File

@ -26,10 +26,16 @@ namespace Oyster
void SetSubscription(EventAction_Move function);
void SetLinearVelocity(Math::Float3 velocity);
void SetPosition(::Oyster::Math::Float3 position);
void SetPosition(Math::Float3 position);
void SetRotation(Math::Float4 quaternion);
void SetRotation(::Oyster::Math::Quaternion quaternion);
void SetRotation(Math::Quaternion quaternion);
void SetRotation(Math::Float3 eulerAngles);
void SetAngularFactor(Math::Float factor);
void SetGravity(Math::Float3 gravity);
void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right);
void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward);
Math::Float4x4 GetRotation() const;
Math::Float4x4 GetOrientation() const;
@ -47,6 +53,7 @@ namespace Oyster
void* GetCustomTag() const;
private:
btCollisionShape* collisionShape;
btDefaultMotionState* motionState;
btRigidBody* rigidBody;
@ -57,6 +64,8 @@ namespace Oyster
EventAction_Move onMovement;
void *customTag;
::Oyster::Math::Float3 gravity;
};
}
}

View File

@ -78,12 +78,16 @@ namespace Oyster
********************************************************/
virtual void ReleaseFromLimbo( const ICustomBody* objRef ) = 0;
virtual void SetGravityPoint(::Oyster::Math::Float3 gravityPoint) = 0;
virtual void SetGravity(float gravity) = 0;
// Bullet physics
virtual ICustomBody* AddCollisionSphere(float radius, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
virtual ICustomBody* AddCollisionBox(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
virtual ICustomBody* AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::Oyster::Math::Float4 rotation, ::Oyster::Math::Float3 position, float mass, float restitution, float staticFriction, float dynamicFriction) = 0;
virtual void SetTimeStep(float timeStep) = 0;
virtual void UpdateWorld() = 0;
@ -135,6 +139,12 @@ namespace Oyster
virtual void SetRotation(::Oyster::Math::Float4 quaternion) = 0;
virtual void SetRotation(::Oyster::Math::Quaternion quaternion) = 0;
virtual void SetRotation(::Oyster::Math::Float3 eulerAngles) = 0;
virtual void SetAngularFactor(::Oyster::Math::Float factor) = 0;
virtual void SetGravity(::Oyster::Math::Float3 gravity) = 0;
virtual void SetUpAndRight(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 right) = 0;
virtual void SetUpAndForward(::Oyster::Math::Float3 up, ::Oyster::Math::Float3 forward) = 0;
::Oyster::Math::Float4x4 GetRotation() const;
::Oyster::Math::Float4x4 GetOrientation() const;