Merge remote-tracking branch 'origin/GameLogic' into Camera-Merge-buffer

Conflicts:
	Code/Game/DanBiasGame/GameClientState/C_Object.h
	Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.cpp
	Code/Game/DanBiasGame/GameClientState/C_obj/C_Player.h
	Code/Game/DanBiasGame/GameClientState/GameState.cpp
This commit is contained in:
Dander7BD 2014-02-14 15:38:01 +01:00
commit ba7f9aaa38
34 changed files with 307 additions and 181 deletions

View File

@ -1,14 +1,31 @@
#include "C_Object.h"
using namespace DanBias::Client;
void C_Object::Init(ModelInitData modelInit)
C_Object::C_Object()
{
world = Oyster::Math::Float4x4::identity;
position = Oyster::Math::Float3::null;
rotation = Oyster::Math::Quaternion::identity;
scale = Oyster::Math::Float3::null;
id = 0;
model = NULL;
}
C_Object::~C_Object()
{
}
bool C_Object::Init(ModelInitData modelInit)
{
position = modelInit.position;
rotation = modelInit.rotation;
scale = modelInit.scale;
id = modelInit.id;
model = Oyster::Graphics::API::CreateModel(modelInit.modelPath);
if(model == NULL)
return false;
model->Visible = modelInit.visible;
updateWorld();
return true;
}
void C_Object::updateWorld()
{

View File

@ -5,6 +5,7 @@ namespace DanBias
{
namespace Client
{
struct ModelInitData
{
int id;
@ -15,52 +16,37 @@ namespace DanBias
bool visible;
};
class C_Object
{
protected:
Oyster::Graphics::Model::Model *model;
private:
Oyster::Math::Float4x4 world;
Oyster::Math::Float3 position;
Oyster::Math::Quaternion rotation;
Oyster::Math::Float3 scale;
class C_Object
{
private:
Oyster::Math::Float4x4 world;
Oyster::Math::Float3 position;
Oyster::Math::Quaternion rotation;
Oyster::Math::Float3 scale;
int id;
void updateWorld();
public:
int id;
void updateWorld();
protected:
Oyster::Graphics::Model::Model *model;
public:
C_Object();
virtual ~C_Object();
virtual bool Init(ModelInitData modelInit);
virtual void Init(ModelInitData modelInit);
void setWorld(Oyster::Math::Float4x4 world);
Oyster::Math::Float4x4 getWorld() const;
void setPos(Oyster::Math::Float3 newPos);
Oyster::Math::Float3 getPos() const;
void addPos(Oyster::Math::Float3 deltaPos);
void setRot(Oyster::Math::Quaternion newRot);
Oyster::Math::Quaternion getRotation() const;
void addRot(Oyster::Math::Quaternion deltaRot);
void setScale(Oyster::Math::Float3 newScale);
void addScale(Oyster::Math::Float3 deltaScale);
Oyster::Math::Float3 getScale() const;
virtual void Render();
virtual void Release();
virtual int GetId() const;
};
}
}
namespace Utility { namespace DynamicMemory
{ // template specializationto allowuse of dynamicmemory tools
template<>
inline void SafeDeleteInstance( ::DanBias::Client::C_Object *dynamicInstance )
{
if( dynamicInstance )
{
dynamicInstance->Release();
delete dynamicInstance;
}
}
} }
void setWorld(Oyster::Math::Float4x4 world);
Oyster::Math::Float4x4 getWorld() const;
void setPos(Oyster::Math::Float3 newPos);
Oyster::Math::Float3 getPos() const;
void addPos(Oyster::Math::Float3 deltaPos);
void setRot(Oyster::Math::Quaternion newRot);
Oyster::Math::Quaternion getRotation() const;
void addRot(Oyster::Math::Quaternion deltaRot);
void setScale(Oyster::Math::Float3 newScale);
void addScale(Oyster::Math::Float3 deltaScale);
Oyster::Math::Float3 getScale() const;
virtual void Render();
virtual void Release();
virtual int GetId() const;
};};};
#endif

View File

@ -11,7 +11,7 @@ C_DynamicObj::~C_DynamicObj(void)
{
}
void C_DynamicObj::Init(ModelInitData modelInit)
bool C_DynamicObj::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
return C_Object::Init(modelInit);
}

View File

@ -11,7 +11,7 @@ private:
public:
C_DynamicObj(void);
virtual ~C_DynamicObj(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
};};};
#endif

View File

@ -3,14 +3,22 @@
using namespace DanBias::Client;
C_Player::C_Player(void)
:C_DynamicObj() {}
C_Player::~C_Player(void) {}
void C_Player::Init(ModelInitData modelInit)
:C_DynamicObj()
{
C_Object::Init(modelInit);
Oyster::Graphics::API::PlayAnimation( this->model, L"movement" );
//Oyster::Graphics::API::Update(0.002f);
}
C_Player::~C_Player(void)
{
}
bool C_Player::Init(ModelInitData modelInit)
{
return C_Object::Init(modelInit);
}
void C_Player::playAnimation(std::wstring animation, bool loop)
{
if(model)
Oyster::Graphics::API::PlayAnimation(model, L"movement", loop);
}

View File

@ -5,15 +5,14 @@ namespace DanBias
{
namespace Client
{
class C_Player : public C_DynamicObj
{
private:
public:
C_Player(void);
virtual ~C_Player(void);
void Init(ModelInitData modelInit);
class C_Player : public C_DynamicObj
{
private:
public:
C_Player(void);
virtual ~C_Player(void);
bool Init(ModelInitData modelInit);
void playAnimation(std::wstring animation, bool loop);
};
}
}
};};};
#endif

View File

@ -10,7 +10,7 @@ C_StaticObj::~C_StaticObj(void)
{
}
void C_StaticObj::Init(ModelInitData modelInit)
bool C_StaticObj::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
return C_Object::Init(modelInit);
}

View File

@ -11,7 +11,7 @@ private:
public:
C_StaticObj(void);
virtual ~C_StaticObj(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
};};};
#endif

View File

@ -10,7 +10,7 @@ C_UIobject::C_UIobject(void)
C_UIobject::~C_UIobject(void)
{
}
void C_UIobject::Init(ModelInitData modelInit)
bool C_UIobject::Init(ModelInitData modelInit)
{
C_Object::Init(modelInit);
return C_Object::Init(modelInit);
}

View File

@ -12,7 +12,7 @@ namespace DanBias
public:
C_UIobject(void);
virtual ~C_UIobject(void);
void Init(ModelInitData modelInit);
bool Init(ModelInitData modelInit);
void setPos(Oyster::Math::Float4x4 world);
};};};
#endif

View File

@ -59,6 +59,27 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break;
}
case ObjectType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
SpawnPointAttributes* spawn = new SpawnPointAttributes;
spawn->typeID = header->typeID;
for(int i = 0; i < 3; i++)
{
spawn->position[i] = header->position[i];
}
delete header;
//objects.push_back(header);
objects.push_back(spawn);
break;
}
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
//Unless they are changed to not be the same.
case ObjectType_Static: case ObjectType_Dynamic:
@ -133,13 +154,8 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
objects.push_back(header);
break;
}
//this is a hotfix, fix so you only load the relevant data when the file is updated
case ObjectSpecialType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
}
default:
//Couldn't find specialType

View File

@ -16,6 +16,7 @@ namespace GameLogic
ObjectType_Static,
ObjectType_Dynamic,
ObjectType_Light,
ObjectType_SpawnPoint,
//Etc
ObjectType_NUM_OF_TYPES,
@ -38,7 +39,6 @@ namespace GameLogic
ObjectSpecialType_CrystalShard,
ObjectSpecialType_JumpPad,
ObjectSpecialType_Portal,
ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Player,
@ -206,6 +206,13 @@ namespace GameLogic
virtual ~ObjectHeader(){}
};
//inheritance from the base class because there is no use for ModelFile, Rotation and Scale
//so this is a special struct for just spawnpoints
struct SpawnPointAttributes : public ObjectTypeHeader
{
float position[3];
};
/************************************
Special objects
*************************************/
@ -234,6 +241,8 @@ namespace GameLogic
/************************************
Lights
*************************************/

View File

@ -95,9 +95,16 @@ using namespace GameLogic;
{
int forceThreashHold = 200000; //how much force for the box to explode of the impact
Object *realObj = (Object*)obj->GetCustomTag(); //needs to be changed?
if(kineticEnergyLoss > forceThreashHold)
switch (realObj->GetObjectType())
{
case ObjectSpecialType::ObjectSpecialType_Generic:
break;
case ObjectSpecialType::ObjectSpecialType_StandardBox:
break;
case ObjectSpecialType::ObjectSpecialType_Player:
ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag());
@ -107,7 +114,20 @@ using namespace GameLogic;
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
delete hitSphere;
break;
}
/*if(kineticEnergyLoss > forceThreashHold)
{
ExplosiveCrate* crate = ((ExplosiveCrate*)rigidBodyCrate->GetCustomTag());
Oyster::Math::Float3 pos = rigidBodyCrate->GetState().centerPos;
Oyster::Collision3D::Sphere *hitSphere = new Oyster::Collision3D::Sphere(pos,crate->ExplosionRadius);
Oyster::Physics::API::Instance().ApplyEffect(hitSphere,crate,Explode);
delete hitSphere;
}*/
}
void ExplosiveCrate::Explode(Oyster::Physics::ICustomBody *obj, void* args)
@ -123,7 +143,7 @@ using namespace GameLogic;
{
Player *hitPlayer = (Player*)realObj;
hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision());
//hitPlayer->DamageLife(ExplosionSource->getExtraDamageOnCollision());
//do shredding damage
}

View File

@ -22,7 +22,7 @@ Game::PlayerData::PlayerData()
//create player with this rigid body
this->player = new Player(rigidBody, Player::PlayerCollision, ObjectSpecialType_Player,0,0);
this->player->GetRigidBody()->SetCustomTag(this);
//this->player->GetRigidBody()->SetCustomTag(this);
player->EndFrame();
}
Game::PlayerData::PlayerData(int playerID,int teamID)

View File

@ -33,7 +33,7 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
case ObjectSpecialType_Sky:
{
float skySize = ((SkyAttributes*)obj)->skySize;
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++);
//gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++);
}
break;
case ObjectSpecialType_World:
@ -96,7 +96,7 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
break;
case ObjectSpecialType_JumpPad:
{
float power = ((JumpPadAttributes*)obj)->power;
float power = 500; //((JumpPadAttributes*)obj)->power;
Oyster::Math::Float3 dir = ((JumpPadAttributes*)obj)->direction;
Oyster::Math::Float3 pushForce = dir * power;
gameObj = new JumpPad(rigidBody, (ObjectSpecialType)obj->specialTypeID, objID++ , pushForce);
@ -111,13 +111,12 @@ Object* Level::createGameObj(ObjectHeader* obj, ICustomBody* rigidBody)
case ObjectSpecialType_SpawnPoint:
{
// save
gameObj = new StaticObject(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID, objID++);
}
break;
case ObjectSpecialType_Player:
{
// should not be read from the lvl format
//gameObj = new Player(rigidBody, Object::DefaultCollisionAfter, (ObjectSpecialType)obj->specialTypeID,objID++);
}
break;
case ObjectSpecialType_Generic:
@ -206,12 +205,10 @@ void Level::InitiateLevel(std::string levelPath)
API::Instance().SetGravityPoint(Oyster::Math3D::Float3(0,0,0));
API::Instance().SetGravity(200);
int objCount = objects.size();
int modelCount = 100;
for (int i = 0; i < objCount; i++)
{
ObjectTypeHeader* obj = objects.at(i);
int id = obj->typeID;
switch (obj->typeID)
{
case ObjectType::ObjectType_LevelMetaData:
@ -223,7 +220,6 @@ void Level::InitiateLevel(std::string levelPath)
break;
case ObjectType::ObjectType_Static:
{
ObjectHeader* staticObjData = ((ObjectHeader*)obj);
staticObjData->ModelFile;
@ -237,7 +233,6 @@ void Level::InitiateLevel(std::string levelPath)
else if(staticObjData->boundingVolume.geoType == CollisionGeometryType_Box)
{
rigidBody_Static = InitRigidBodyCube(staticObjData);
}
@ -248,22 +243,13 @@ void Level::InitiateLevel(std::string levelPath)
if(rigidBody_Static != NULL)
{
// create game object
Object* staticGameObj = createGameObj(staticObjData, rigidBody_Static);
//Object* staticGameObj = new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID);
if(staticGameObj != NULL)
{
this->staticObjects.Push((StaticObject*)staticGameObj);
//this->staticObjects[this->staticObjects.Size()-1]->objectID = modelCount++;
//rigidBody_Static->SetCustomTag(this->staticObjects[this->staticObjects.Size()-1]);
}
//this->staticObjects.Push(new StaticObject(rigidBody_Static, Object::DefaultCollisionAfter, (ObjectSpecialType)staticObjData->specialTypeID, 0));
//this->staticObjects[staticObjCount]->objectID = modelCount++;
}
}
break;
case ObjectType::ObjectType_Dynamic:
@ -293,12 +279,9 @@ void Level::InitiateLevel(std::string levelPath)
{
// create game object
Object* dynamicGameObj = createGameObj(dynamicObjData, rigidBody_Dynamic);
//Object* dynamicGameObj =new DynamicObject(rigidBody_Dynamic, Object::DefaultCollisionAfter, (ObjectSpecialType)dynamicObjData->specialTypeID);
if (dynamicGameObj != NULL)
{
this->dynamicObjects.Push((DynamicObject*)dynamicGameObj);
//this->dynamicObjects[this->dynamicObjects.Size()-1]->objectID = modelCount++;
//rigidBody_Dynamic->SetCustomTag(this->dynamicObjects[this->dynamicObjects.Size()-1]);
}
}
}
@ -334,9 +317,6 @@ void Level::InitiateLevel(float radius)
rigidBody_TestBox = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(0, 605 + i*5, 10), 5, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_TestBox, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++));
//this->dynamicObjects[i]->objectID = idCount++;
rigidBody_TestBox->SetCustomTag(this->dynamicObjects[i]);
}
/*offset += nrOfBoxex;
for(int i =0; i< nrOfBoxex; i ++)
@ -365,31 +345,18 @@ void Level::InitiateLevel(float radius)
}*/
// add crystal
ICustomBody* rigidBody_Crystal = API::Instance().AddCollisionBox(Oyster::Math::Float3(0.5f, 0.5f, 0.5f), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(10, 605, 0), 5, 0.5f, 0.8f, 0.6f);
this->dynamicObjects.Push(new DynamicObject(rigidBody_Crystal, Object::DefaultCollisionAfter, ObjectSpecialType_StandardBox, idCount++));
rigidBody_Crystal->SetCustomTag(this->dynamicObjects[nrOfBoxex]);
//this->dynamicObjects[nrOfBoxex]->objectID = idCount++;
// add house
ICustomBody* rigidBody_House =API::Instance().AddCollisionBox(Oyster::Math::Float3(20, 20, 20), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(-50, 590, 0), 0, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new StaticObject(rigidBody_House, Object::DefaultCollisionAfter, ObjectSpecialType_Generic, idCount++));
rigidBody_House->SetCustomTag(this->staticObjects[0]);
//this->staticObjects[0]->objectID = idCount++;
// add jumppad
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 0, 0.5f, 0.8f, 0.6f);
ICustomBody* rigidBody_Jumppad = API::Instance().AddCollisionBox(Oyster::Math::Float3(1, 1, 1), Oyster::Math::Float4(0, 0, 0, 1), Oyster::Math::Float3(4, 600.3, 0), 5, 0.5f, 0.8f, 0.6f);
this->staticObjects.Push(new JumpPad(rigidBody_Jumppad, ObjectSpecialType_JumpPad,idCount++ ,Oyster::Math::Float3(0,2000,0)));
rigidBody_Jumppad->SetCustomTag(this->staticObjects[1]);
//this->staticObjects[1]->objectID = idCount++;
}
void Level::AddPlayerToTeam(Player *player, int teamID)

View File

@ -77,6 +77,7 @@ namespace GameLogic
Utility::DynamicMemory::SmartPointer<Oyster::Physics::ICustomBody> rigidBodyLevel;
StaticObject *levelObj;
int objID;
Utility::DynamicMemory::DynamicArray<Oyster::Math::Float3> spawnPoints;
};

View File

@ -3,7 +3,6 @@
/////////////////////////////////////
#include "LevelParser.h"
#include "Loader.h"
#include "ParseFunctions.h"
@ -59,6 +58,27 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break;
}
case ObjectType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
SpawnPointAttributes* spawn = new SpawnPointAttributes;
spawn->typeID = header->typeID;
for(int i = 0; i < 3; i++)
{
spawn->position[i] = header->position[i];
}
delete header;
//objects.push_back(header);
objects.push_back(spawn);
break;
}
//This is by design, static and dynamic is using the same converter. Do not add anything inbetween them.
//Unless they are changed to not be the same.
case ObjectType_Static: case ObjectType_Dynamic:
@ -134,13 +154,6 @@ std::vector<SmartPointer<ObjectTypeHeader>> LevelParser::Parse(std::string filen
break;
}
case ObjectSpecialType_SpawnPoint:
{
loadCgf = false;
ObjectHeader* header = new ObjectHeader;
ParseObject(&buffer[counter], *header, counter, loadCgf);
}
default:
//Couldn't find specialType
break;

View File

@ -16,6 +16,7 @@ namespace GameLogic
ObjectType_Static,
ObjectType_Dynamic,
ObjectType_Light,
ObjectType_SpawnPoint,
//Etc
ObjectType_NUM_OF_TYPES,
@ -38,7 +39,6 @@ namespace GameLogic
ObjectSpecialType_CrystalShard,
ObjectSpecialType_JumpPad,
ObjectSpecialType_Portal,
ObjectSpecialType_SpawnPoint,
ObjectSpecialType_Player,
ObjectSpecialType_Generic,
@ -207,6 +207,11 @@ namespace GameLogic
virtual ~ObjectHeader(){}
};
struct SpawnPointAttributes : public ObjectTypeHeader
{
ObjectSpecialType specialTypeID;
float position[3];
};
/************************************
Special objects
*************************************/

View File

@ -20,33 +20,24 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, void (*EventOnCollision)
weapon = new Weapon(2,this);
this->life = 100;
this->teamID = -1;
this->teamID = teamID;
this->playerState = PLAYER_STATE_IDLE;
this->lookDir = Oyster::Math::Float3(0,0,-1);
this->moveDir = Oyster::Math::Float3(0,0,0);
key_forward = 0;
key_backward = 0;
key_strafeRight = 0;
key_strafeLeft = 0;
this->previousPosition = Oyster::Math::Float3(0,0,0);
this->moveDir = Oyster::Math::Float3(0,0,0);
this->moveSpeed = 100;
this->previousMoveSpeed = Oyster::Math::Float3(0,0,0);
}
Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, int teamID)
:DynamicObject(rigidBody, EventOnCollision, type, objectID)
{
this->rigidBody = rigidBody;
Oyster::Math::Float3 centerPosition = Oyster::Math::Float3(0,400,0);
Oyster::Math::Float3 size = Oyster::Math::Float3(0.25f,1.0f,0.5f);
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;
this->rigidBody = Oyster::Physics::API::Instance().AddCollisionBox(size, Oyster::Math::Float4(0, 0, 0, 1), centerPosition, mass, 0.5f, 0.8f, 0.6f );
this->rigidBody->SetAngularFactor(0.0f);
weapon = new Weapon(2,this);
this->life = 100;
@ -58,10 +49,10 @@ Player::Player(Oyster::Physics::ICustomBody *rigidBody, Oyster::Physics::ICustom
key_strafeRight = 0;
key_strafeLeft = 0;
this->previousPosition = Oyster::Math::Float3(0,0,0);
this->moveDir = Oyster::Math::Float3(0,0,0);
this->moveSpeed = 100;
this->previousMoveSpeed = Oyster::Math::Float3(0,0,0);
}
Player::~Player(void)
@ -78,12 +69,29 @@ void Player::BeginFrame()
//weapon->Update(0.002f);
Object::BeginFrame();
if(this->moveDir != Oyster::Math::Float3::null)
//Oyster::Math::Float3 previousFall = this->previousMoveSpeed*-this->rigidBody->GetState().centerPos.GetNormalized();
//Oyster::Math::Float3 currentFall = this->rigidBody->GetLinearVelocity()*-this->rigidBody->GetState().centerPos.GetNormalized();
if(this->moveDir != Oyster::Math::Float3::null && this->playerState != PLAYER_STATE_JUMPING)
{
Oyster::Math::Float3 velocity = this->rigidBody->GetLinearVelocity();
Oyster::Math::Float3 lostVelocity = (this->previousMoveSpeed - velocity).GetMagnitude()*this->moveDir;
this->rigidBody->SetLinearVelocity(velocity + lostVelocity - this->moveDir*this->moveSpeed );
}
else
{
if(this->rigidBody->GetLamda() == 1.0f)
{
this->playerState = PLAYER_STATE_WALKING;
}
if(this->moveDir != Oyster::Math::Float3::null)
{
Oyster::Math::Float3 velocity = this->rigidBody->GetLinearVelocity();
this->rigidBody->SetLinearVelocity(velocity - this->moveDir*this->moveSpeed );
}
}
this->moveDir = Oyster::Math::Float3::null;
@ -116,9 +124,11 @@ void Player::BeginFrame()
{
this->moveDir.Normalize();
this->rigidBody->SetLinearVelocity(this->moveDir*this->moveSpeed + this->rigidBody->GetLinearVelocity());
this->previousMoveSpeed = this->rigidBody->GetLinearVelocity();
}
this->previousMoveSpeed = this->rigidBody->GetLinearVelocity();
this->previousPosition = this->rigidBody->GetState().centerPos;
this->weapon->Update(0.01f);
}
@ -195,15 +205,18 @@ void Player::Rotate(const Oyster::Math3D::Float3 lookDir, const Oyster::Math3D::
// this is the camera right vector
this->lookDir = lookDir;
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1];
this->rigidBody->SetUpAndRight(up, right);
//Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1];
//this->rigidBody->SetUpAndRight(up, right);
}
void Player::Jump()
{
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized();
this->rigidBody->ApplyImpulse(up *1500);
this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING;
if(this->rigidBody->GetLamda() < 1.0f)
{
Oyster::Math::Float3 up = this->rigidBody->GetState().GetOrientation().v[1].GetNormalized();
this->rigidBody->ApplyImpulse(up *1500);
this->playerState = PLAYER_STATE::PLAYER_STATE_JUMPING;
}
}
bool Player::IsWalking()

View File

@ -89,6 +89,7 @@ namespace GameLogic
float key_jump;
Oyster::Math::Float3 previousPosition;
Oyster::Math::Float3 moveDir;
Oyster::Math::Float moveSpeed;
Oyster::Math::Float3 previousMoveSpeed;

View File

@ -14,25 +14,25 @@ StaticObject::StaticObject()
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
:Object(rigidBody, EventOnCollision, type, objectID)
{
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID)
:Object(rigidBody, EventOnCollision, type, objectID)
{
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , void (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
{
this->extraDamageOnCollision = extraDamageOnCollision;
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody , Oyster::Physics::ICustomBody::SubscriptMessage (*EventOnCollision)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), ObjectSpecialType type, int objectID, Oyster::Math::Float extraDamageOnCollision)
{
this->extraDamageOnCollision = extraDamageOnCollision;
//use setMass(when it is made) and set the mass to 0 in order to ensure that the object is static
rigidBody->SetMass(0);
}
StaticObject::~StaticObject(void)
{

View File

@ -210,7 +210,7 @@ ICustomBody* API_Impl::AddCharacter(::Oyster::Math::Float height, ::Oyster::Math
this->customBodies.push_back(body);
state.centerPos = position;
state.reach = Float3(radius, height*0.5f, radius);
state.reach = Float3(radius, height, radius);
state.dynamicFrictionCoeff = 0.5f;
state.staticFrictionCoeff = 0.5f;
state.quaternion = Quaternion(Float3(rotation.xyz), rotation.w);
@ -230,7 +230,9 @@ void API_Impl::UpdateWorld()
{
for(unsigned int i = 0; i < this->customBodies.size(); i++ )
{
SimpleRigidBody* simpleBody = dynamic_cast<SimpleRigidBody*>(this->customBodies[i]);
this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity);
simpleBody->PreStep(this->dynamicsWorld);
}
this->dynamicsWorld->stepSimulation(this->timeStep, 1, this->timeStep);

View File

@ -345,3 +345,60 @@ void SimpleRigidBody::SetCustomTag( void *ref )
{
this->customTag = ref;
}
void SimpleRigidBody::PreStep (const btCollisionWorld* collisionWorld)
{
btTransform xform;
this->rigidBody->getMotionState()->getWorldTransform (xform);
btVector3 down = -xform.getBasis()[1];
btVector3 forward = xform.getBasis()[2];
down.normalize ();
forward.normalize();
this->raySource[0] = xform.getOrigin();
this->raySource[1] = xform.getOrigin();
this->rayTarget[0] = this->raySource[0] + down * this->state.reach.y * btScalar(1.1);
this->rayTarget[1] = this->raySource[1] + forward * this->state.reach.y * btScalar(1.1);
class ClosestNotMe : public btCollisionWorld::ClosestRayResultCallback
{
public:
ClosestNotMe (btRigidBody* me) : btCollisionWorld::ClosestRayResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0))
{
m_me = me;
}
virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
{
if (rayResult.m_collisionObject == m_me)
return 1.0;
return ClosestRayResultCallback::addSingleResult (rayResult, normalInWorldSpace);
}
protected:
btRigidBody* m_me;
};
ClosestNotMe rayCallback(this->rigidBody);
int i = 0;
for (i = 0; i < 2; i++)
{
rayCallback.m_closestHitFraction = 1.0;
if((this->raySource[i] - this->rayTarget[i]).length() != 0)
collisionWorld->rayTest (this->raySource[i], this->rayTarget[i], rayCallback);
if (rayCallback.hasHit())
{
this->rayLambda[i] = rayCallback.m_closestHitFraction;
} else {
this->rayLambda[i] = 1.0;
}
}
}
float SimpleRigidBody::GetLamda() const
{
return this->rayLambda[0];
}

View File

@ -58,11 +58,17 @@ namespace Oyster
void SetCustomTag( void *ref );
void* GetCustomTag() const;
// Class specific
void SetCollisionShape(btCollisionShape* shape);
void SetMotionState(btDefaultMotionState* motionState);
void SetRigidBody(btRigidBody* rigidBody);
void PreStep(const btCollisionWorld* collisionWorld);
float GetLamda() const;
private:
btCollisionShape* collisionShape;
@ -76,7 +82,11 @@ namespace Oyster
void *customTag;
::Oyster::Math::Float3 gravity;
Math::Float3 gravity;
btVector3 raySource[2];
btVector3 rayTarget[2];
btScalar rayLambda[2];
};
}
}

View File

@ -179,6 +179,8 @@ namespace Oyster
* @param ref: Anything castable to a void pointer, the engine won't care.
********************************************************/
virtual void SetCustomTag( void *ref ) = 0;
virtual float GetLamda() const = 0;
};
}
}

View File

@ -10,9 +10,10 @@ namespace Oyster
{
namespace Struct
{
inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float dynamicFrictionCoeff, const ::Oyster::Math::Float3 &centerPos, const ::Oyster::Math::Quaternion& quaternion)
inline CustomBodyState::CustomBodyState( ::Oyster::Math::Float mass, ::Oyster::Math::Float3 reach, ::Oyster::Math::Float restitutionCoeff, ::Oyster::Math::Float staticFrictionCoeff, ::Oyster::Math::Float dynamicFrictionCoeff, const ::Oyster::Math::Float3 &centerPos, const ::Oyster::Math::Quaternion& quaternion)
{
this->mass = mass;
this->reach = reach;
this->restitutionCoeff = restitutionCoeff;
this->staticFrictionCoeff = staticFrictionCoeff;
this->dynamicFrictionCoeff = dynamicFrictionCoeff;
@ -24,6 +25,7 @@ namespace Oyster
{
this->mass = state.mass;
this->restitutionCoeff = state.restitutionCoeff;
this->reach = state.reach;
this->staticFrictionCoeff = state.staticFrictionCoeff;
this->dynamicFrictionCoeff = state.dynamicFrictionCoeff;
this->centerPos = state.centerPos;

View File

@ -16,6 +16,7 @@ namespace Oyster
public:
// Default constructor
CustomBodyState( ::Oyster::Math::Float mass = 1.0f,
::Oyster::Math::Float3 reach = ::Oyster::Math::Float3(0,0,0),
::Oyster::Math::Float restitutionCoeff = 0.5f,
::Oyster::Math::Float staticFrictionCoeff = 1.0f,
::Oyster::Math::Float dynamicFrictionCoeff = 1.0f,

View File

@ -170,7 +170,7 @@ namespace Utility
template <typename T> void DynamicArray<T>::Remove(unsigned int index)
{
assert(index > (unsigned int) this->size);
assert(index < (unsigned int) this->size);
T* temp = new T[this->capacity - 1];

View File

@ -27,8 +27,6 @@ namespace Oyster
Oyster::Math::Float3 pos;
Oyster::Math::Float2 uv;
Oyster::Math::Float3 normal;
Oyster::Math::Float3 tangent;
Oyster::Math::Float3 biTangent;
Oyster::Math::Float4 boneIndex;
Oyster::Math::Float4 boneWeights;
};

View File

@ -5,12 +5,11 @@
#include <fstream>
#include <string>
#define DANFILEVERSIONMAJOR 1
#define DANFILEVERSIONMAJOR 2
#define DANFILEVERSIONMINOR 1
#define FILEHEADERSIZE 8
#define VERTEXHEADERSIZE 4
#define VERTEXSIZE 88
@ -220,7 +219,7 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
delete[] buffer; // ( note: may crash here.)
// Fetch all vertices
unsigned int bufferSize = VERTEXSIZE * vertexHeader.numVertices;
unsigned int bufferSize = sizeof(Vertex) * vertexHeader.numVertices;
buffer = new char[bufferSize];
danFile.read(buffer, bufferSize);

View File

@ -91,7 +91,7 @@ namespace Oyster
{
tmpInst.coff=(1.0f/TEXT_NR_LETTERS);
tmpInst.offset=text[i]-32;
tmpInst.pos=i*(FontSize * 0.8f * TEXT_SPACING);
tmpInst.pos=i*(FontSize * 0.7f * TEXT_SPACING);
if(tmpInst.pos > size.x)
{
text = text.substr(0,i-1);

View File

@ -340,13 +340,11 @@ namespace Oyster
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BITANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BONEINDEX", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 56, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "BONEWEIGHT", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 72, D3D11_INPUT_PER_VERTEX_DATA, 0 }
};
Shader::CreateInputLayout(indesc,7,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout);
Shader::CreateInputLayout(indesc,5,GetShader::Vertex(L"Gather"),Gather::Pass.IAStage.Layout);
Gather::Pass.IAStage.Topology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
Gather::Pass.CBuffers.Vertex.push_back(Gather::AnimationData);
Gather::Pass.CBuffers.Vertex.push_back(Gather::ModelData);

View File

@ -3,8 +3,6 @@ struct VertexIn
float3 pos : POSITION;
float2 UV : TEXCOORD;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float3 biTangent : BITANGENT;
float4 boneIndex : BONEINDEX;
float4 boneWeight : BONEWEIGHT;
};

View File

@ -170,10 +170,10 @@ HRESULT InitDirect3D()
return E_FAIL;
}
m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan");
//m->WorldMatrix.m[0][0] = 50;
//m->WorldMatrix.m[1][1] = 50;
//m->WorldMatrix.m[2][2] = 0.00000005f;
m = Oyster::Graphics::API::CreateModel(L"building_corporation.dan");
m->WorldMatrix.m[0][0] = 0.0002f;
m->WorldMatrix.m[1][1] = 0.0002f;
m->WorldMatrix.m[2][2] = 0.0002f;
m2 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
m2->Tint = Oyster::Math::Float3(0.1f,0.1f,1);
m3 = Oyster::Graphics::API::CreateModel(L"char_temporary.dan");
@ -223,7 +223,11 @@ HRESULT Update(float deltaTime)
m->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0) * angle,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * angle,Oyster::Math::Float3(4,0,0),Oyster::Math::Float3::null);
m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0) * -angle,Oyster::Math::Float3(-4,0,0),Oyster::Math::Float3::null);
//Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity;
Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity;
ma.m[0][0] = 0.2f;
ma.m[1][1] = 0.2f;
ma.m[2][2] = 0.2f;
m->WorldMatrix = m->WorldMatrix * ma;
Oyster::Graphics::API::Update(deltaTime);
//m2->Animation.data.AnimationTime += deltaTime;// * 0.5f;
return S_OK;