GL - player moving
This commit is contained in:
parent
489115840d
commit
d16d223c2b
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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;
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
|
||||
|
@ -566,8 +566,9 @@ 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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -51,8 +51,6 @@ 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;
|
||||
|
|
|
@ -70,12 +70,11 @@ void Player::EndFrame()
|
|||
Object::EndFrame();
|
||||
// rotate
|
||||
|
||||
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
||||
Oyster::Math::Float3 deltaAxis = up * (-dx * 0.02) ;
|
||||
//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 +105,32 @@ void Player::Move(const PLAYER_MOVEMENT &movement)
|
|||
|
||||
void Player::MoveForward()
|
||||
{
|
||||
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
|
||||
//Oyster::Math::Float3 forward = lookDir;
|
||||
//newPhysicsState.ApplyLinearImpulse(forward * (MOVE_FORCE * this->gameInstance->GetFrameTime()));
|
||||
//rigidBody->SetLinearVelocity( 10 * this->gameInstance->GetFrameTime() );
|
||||
rigidBody->SetLinearVelocity( 10 * forward.GetNormalized() );
|
||||
}
|
||||
void Player::MoveBackwards()
|
||||
{
|
||||
Oyster::Math::Float3 forward = currPhysicsState.GetOrientation().v[2];
|
||||
Oyster::Math::Float3 forward = this->rigidBody->GetState().GetOrientation().v[2];
|
||||
//Oyster::Math::Float3 forward = lookDir;
|
||||
//newPhysicsState.ApplyLinearImpulse(-forward * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
||||
rigidBody->SetLinearVelocity( 10 * -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 = this->rigidBody->GetState().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 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward);
|
||||
rigidBody->SetLinearVelocity(r * 10);
|
||||
}
|
||||
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 = this->rigidBody->GetState().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 r = (-this->rigidBody->GetState().centerPos.Normalize()).Cross(forward);
|
||||
rigidBody->SetLinearVelocity(-r * 10);
|
||||
}
|
||||
|
||||
void Player::UseWeapon(const WEAPON_FIRE &usage)
|
||||
|
@ -145,7 +143,7 @@ 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->newPhysicsState.centerPos = spawnPoint;
|
||||
}
|
||||
|
||||
void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
|
||||
|
@ -162,7 +160,7 @@ void Player::Rotate(const Oyster::Math3D::Float4 lookDir)
|
|||
|
||||
void Player::Jump()
|
||||
{
|
||||
Oyster::Math::Float3 up = currPhysicsState.GetOrientation().v[1];
|
||||
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1];
|
||||
//newPhysicsState.ApplyLinearImpulse(up * MOVE_FORCE * this->gameInstance->GetFrameTime());
|
||||
}
|
||||
|
||||
|
@ -181,11 +179,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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue