GL - can send object position from level objects, gravity and frustrum problems.

This commit is contained in:
lindaandersson 2014-01-28 15:04:25 +01:00
parent e11dc6551c
commit a56fcbcb9b
18 changed files with 120 additions and 48 deletions

View File

@ -46,6 +46,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DanBiasServerLauncher", "Ga
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Physics lab", "Physics lab\Physics lab.vcxproj", "{5128BD77-6472-4C4A-BE6F-724AD0E589C2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "aDanBiasGameLauncher", "Game\aDanBiasGameLauncher\aDanBiasGameLauncher.vcxproj", "{666FEA52-975F-41CD-B224-B19AF3C0ABBA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Mixed Platforms = Debug|Mixed Platforms
@ -284,6 +286,18 @@ Global
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|Win32.Build.0 = Release|Win32
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.ActiveCfg = Release|x64
{5128BD77-6472-4C4A-BE6F-724AD0E589C2}.Release|x64.Build.0 = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.ActiveCfg = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|Win32.Build.0 = Debug|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.ActiveCfg = Debug|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Debug|x64.Build.0 = Debug|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Mixed Platforms.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.ActiveCfg = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|Win32.Build.0 = Release|Win32
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.ActiveCfg = Release|x64
{666FEA52-975F-41CD-B224-B19AF3C0ABBA}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -93,14 +93,14 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
modelData.id ++;
obj = new C_DynamicObj();
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
/*translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(-2,-2,-2));
modelData.world = modelData.world * translate;
modelData.modelPath = L"..\\Content\\Models\\char_white.dan";
modelData.id ++;
modelData.id ++;*/
translate = Oyster::Math3D::TranslationMatrix(Oyster::Math::Float3(0,0,0));
Oyster::Math3D::Float4x4 scale = Oyster::Math3D::Float4x4::identity;
@ -111,7 +111,7 @@ bool GameState::LoadModels(std::wstring mapFile)
modelData.modelPath = L"ball.dan";
modelData.id ++;
obj = new C_DynamicObj();
obj = new C_Player();
privData->object.push_back(obj);
privData->object[privData->object.size() -1 ]->Init(modelData);
@ -328,9 +328,11 @@ void GameState::Protocol( ObjPos* pos )
//camera->setRight((Oyster::Math::Float3(world[0], world[1], world[2])));
//camera->setUp((Oyster::Math::Float3(world[4], world[5], world[6])));
//camera->setLook((Oyster::Math::Float3(world[8], world[9], world[10])));
if(i == 0)
{
camera->SetPosition(Oyster::Math::Float3(world[12], world[13], world[14]));
camera->UpdateViewMatrix();
}
}
}
}

View File

@ -30,7 +30,7 @@ namespace DanBias
NetworkSession* owner;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<LobbyClient>> clients;
};
static GameSession* gameSession;
public:
GameSession();
virtual~GameSession();

View File

@ -11,7 +11,6 @@
#include <Windows.h>
using namespace Utility::DynamicMemory;
using namespace Oyster;
using namespace Oyster::Network;
@ -113,10 +112,19 @@ namespace DanBias
void GameSession::ObjectMove(GameLogic::IObjectData* movedObject)
{
/*int id= movedObject->GetID();
Oyster::Math::Float4x4 world = movedObject->GetOrientation();
Protocol_ObjectPosition p(world, 2);
Send(p.GetProtocol());*/
GameLogic::IObjectData* obj = NULL;
if(dynamic_cast<GameLogic::ILevelData*>(movedObject))
obj =((GameLogic::ILevelData*)movedObject)->GetObjectAt(0);
if(obj)
{
if(obj->GetType() == OBJECT_TYPE_BOX)
{
obj->GetID();
Oyster::Math::Float4x4 world =obj->GetOrientation();
Protocol_ObjectPosition p(world, 1);
GameSession::gameSession->Send(p.GetProtocol());
}
}
}

View File

@ -19,6 +19,7 @@ using namespace GameLogic;
namespace DanBias
{
GameSession* GameSession::gameSession = nullptr;
GameSession::GameSession()
:gameInstance(GameAPI::Instance())
{
@ -26,6 +27,7 @@ namespace DanBias
this->box = 0;
this->isCreated = false;
this->isRunning = false;
this->gameSession = this;
}
GameSession::~GameSession()

View File

@ -80,7 +80,7 @@ namespace DanBias
if(clients.Size() >= 1 && clients[0])
{
Oyster::Math::Float4x4 world = this->clients[0]->GetPlayer()->GetOrientation();
Protocol_ObjectPosition p(world, 1);
Protocol_ObjectPosition p(world, 0);
Send(p.GetProtocol());
}
}

View File

@ -46,7 +46,10 @@ void AttatchmentMassDriver::UseAttatchment(const GameLogic::WEAPON_FIRE &usage,
void AttatchmentMassDriver::ForcePush(const GameLogic::WEAPON_FIRE &usage, float dt)
{
//Oyster::Math::Float4 pushForce = Oyster::Math::Float4(this->owner->GetLookDir()) * (500 * dt);
Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), owner->GetPosition());
Oyster::Math::Float3 weaponPos;
weaponPos = owner->GetPosition() + 5 * owner->GetLookDir();
Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), Oyster::Math::Float3(0,0,1), weaponPos);
//Oyster::Math::Float4x4 aim = Oyster::Math3D::ViewMatrix_LookAtDirection(owner->GetLookDir(), owner->GetRigidBody()->GetGravityNormal(), weaponPos);
Oyster::Math::Float4x4 hitSpace = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/4,1,1,20);
Oyster::Collision3D::Frustrum hitFrustum = Oyster::Collision3D::Frustrum(Oyster::Math3D::ViewProjectionMatrix(aim,hitSpace));

View File

@ -72,7 +72,7 @@ using namespace GameLogic;
void AttatchmentMassDriver::ForcePushAction(Oyster::Physics::ICustomBody *obj)
{
Oyster::Math::Float4 pushForce = Oyster::Math::Float4(1,0,0,0) * (500);
Oyster::Math::Float4 pushForce = Oyster::Math::Float4(1,0,0,0) * (20);
Oyster::Physics::ICustomBody::State state;
state = obj->GetState();
state.ApplyLinearImpulse(pushForce);

View File

@ -128,6 +128,7 @@ bool Game::NewFrame()
{
if(this->players[i]->player) this->players[i]->player->EndFrame();
}
//gameInstance.onMoveFnc(this->level);
return true;
}

View File

@ -32,15 +32,14 @@ namespace GameLogic
~PlayerData();
void Move(const PLAYER_MOVEMENT &movement) override;
void Rotate(const Oyster::Math3D::Float3 lookDir) override;
void UseWeapon(const WEAPON_FIRE &usage) override;
int GetTeamID() const override;
PLAYER_STATE GetState() const override;
Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
OBJECT_TYPE GetObjectType() const override;
void Rotate(const Oyster::Math3D::Float3 lookDir) override;
OBJECT_TYPE GetType() const override;
Player *player;
};
@ -52,7 +51,8 @@ namespace GameLogic
Oyster::Math::Float3 GetPosition() override;
Oyster::Math::Float4x4 GetOrientation() override;
int GetID() const override;
OBJECT_TYPE GetObjectType() const override;
OBJECT_TYPE GetType() const override;
IObjectData* GetObjectAt( int ID ) const override;
Level *level;
};

View File

@ -13,7 +13,6 @@
#include "GameLogicStates.h"
#include <OysterMath.h>
namespace GameLogic
{
class IObjectData;
@ -62,7 +61,7 @@ namespace GameLogic
/** Get the type of the object
* @return The OBJECT_TYPE of the object is returned
*/
virtual OBJECT_TYPE GetObjectType() const = 0;
virtual OBJECT_TYPE GetType() const = 0;
};
class IPlayerData :public IObjectData
@ -100,6 +99,8 @@ namespace GameLogic
class ILevelData :public IObjectData
{
public:
virtual IObjectData* GetObjectAt( int ID) const = 0;
};
class DANBIAS_GAMELOGIC_DLL GameAPI

View File

@ -25,13 +25,18 @@ Oyster::Math::Float4x4 Game::LevelData::GetOrientation()
//return this->level->GetOrientation();
return Oyster::Math::Float4x4();
}
int Game::LevelData::GetID() const
{
//this->level->GetID();
return -1;
return ((IObjectData*)this->level)->GetID();
}
OBJECT_TYPE Game::LevelData::GetObjectType() const
OBJECT_TYPE Game::LevelData::GetType() const
{
//return this->level->GetType();
return OBJECT_TYPE_UNKNOWN;
return ((IObjectData*)this->level)->GetType();
//return OBJECT_TYPE_UNKNOWN;
}
IObjectData* Game::LevelData::GetObjectAt(int ID) const
{
return this->level->GetObj(ID);
}

View File

@ -27,8 +27,7 @@ Game::PlayerData::~PlayerData()
delete this->player;
}
void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement)
{
void Game::PlayerData::Move(const PLAYER_MOVEMENT &movement){
this->player->Move(movement);
}
void Game::PlayerData::UseWeapon(const WEAPON_FIRE &usage)
@ -55,11 +54,12 @@ int Game::PlayerData::GetTeamID() const
{
return this->player->GetTeamID();
}
OBJECT_TYPE Game::PlayerData::GetObjectType() const
OBJECT_TYPE Game::PlayerData::GetType() const
{
return this->player->GetType();
}
void Game::PlayerData::Rotate(const Oyster::Math3D::Float3 lookDir)
{
//this->player->Rotate(lookDir);
this->player->Rotate(lookDir);
}

View File

@ -8,6 +8,7 @@ using namespace Oyster::Physics;
Level::Level(void)
{
}
Level::~Level(void)
{
@ -29,7 +30,7 @@ void Level::InitiateLevel(float radius)
ICustomBody* rigidBody = API::Instance().CreateRigidBody(sbDesc).Release();
//rigidBody->SetCustomTag(levelObj);
ICustomBody::State state;
rigidBody->GetState(state);
@ -37,29 +38,34 @@ void Level::InitiateLevel(float radius)
rigidBody->SetState(state);
levelObj = new StaticObject(rigidBody, LevelCollision, OBJECT_TYPE::OBJECT_TYPE_WORLD);
rigidBody->SetCustomTag(levelObj);
API::Instance().AddObject(rigidBody);
API::SimpleBodyDescription sbDesc_TestBox;
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(3,15,0,0);
sbDesc_TestBox.centerPosition = Oyster::Math::Float4(5,15,0,0);
sbDesc_TestBox.ignoreGravity = false;
sbDesc_TestBox.mass = 10;
sbDesc_TestBox.size = Oyster::Math::Float4(2,2,2,0);
//sbDesc.mass = 0; //10^16
ICustomBody* rigidBody_TestBox = API::Instance().CreateRigidBody(sbDesc_TestBox).Release();
rigidBody_TestBox->SetSubscription(Level::PhysicsOnMoveLevel);
testBox = new DynamicObject(rigidBody_TestBox,LevelCollision,OBJECT_TYPE::OBJECT_TYPE_BOX);
rigidBody_TestBox->SetCustomTag(testBox);
rigidBody_TestBox->GetState(state);
state.ApplyLinearImpulse(Oyster::Math::Float4(0,0,4,0));
rigidBody_TestBox->SetState(state);
API::Instance().AddObject(rigidBody_TestBox);
/*API::Gravity gravityWell;
API::Gravity gravityWell;
gravityWell.gravityType = API::Gravity::GravityType_Well;
gravityWell.well.mass = 10e12f;
gravityWell.well.position = Oyster::Math::Float4(0,0,0,1);
API::Instance().AddGravity(gravityWell);
*/
}
void Level::AddPlayerToTeam(Player *player, int teamID)
@ -77,4 +83,12 @@ void Level::RespawnPlayer(Player *player)
this->teamManager.RespawnPlayerRandom(player);
}
Object* Level::GetObj( int ID) const
{
return (Object*)testBox;
}
void Level::PhysicsOnMoveLevel(const ICustomBody *object)
{
// function call from physics update when object was moved
Object* temp = (Object*)object->GetCustomTag();
}

View File

@ -59,6 +59,10 @@ namespace GameLogic
********************************************************/
static void LevelCollision(Oyster::Physics::ICustomBody *rigidBodyLevel, Oyster::Physics::ICustomBody *obj, Oyster::Math::Float kineticEnergyLoss);
Object* GetObj( int ID ) const;
static void PhysicsOnMoveLevel(const Oyster::Physics::ICustomBody *object);
private:
TeamManager teamManager;
Utility::DynamicMemory::DynamicArray<Utility::DynamicMemory::SmartPointer<StaticObject>> staticObjects;

View File

@ -121,3 +121,15 @@ void Object::EndFrame()
this->setState = this->getState;
}
Oyster::Math::Float3 Object::GetPosition()
{
Oyster::Physics::ICustomBody::State state;
state = this->rigidBody->GetState();
return state.GetCenterPosition();
}
Oyster::Math::Float4x4 Object::GetOrientation()
{
Oyster::Physics::ICustomBody::State state;
state = this->rigidBody->GetState();
return state.GetOrientation();
}

View File

@ -7,13 +7,14 @@
#define OBJECT_H
#include "GameLogicStates.h"
#include "GameAPI.h"
#include <PhysicsAPI.h>
namespace GameLogic
{
class Game;
class Object
class Object :public IObjectData
{
public:
Object();
@ -22,8 +23,13 @@ namespace GameLogic
Object(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type);
~Object(void);
// API overrides
OBJECT_TYPE GetType() const;
int GetID() const;
Oyster::Math::Float3 GetPosition();
Oyster::Math::Float4x4 GetOrientation();
Oyster::Physics::ICustomBody* GetRigidBody();
void ApplyLinearImpulse(Oyster::Math::Float4 force);

View File

@ -20,11 +20,11 @@ StaticObject::StaticObject(OBJECT_TYPE type)
{
}
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisionFunc, OBJECT_TYPE type)
/*StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody,void* collisionFunc, OBJECT_TYPE type)
:Object(rigidBody,collisionFunc,type)
{
}
}*/
StaticObject::StaticObject(Oyster::Physics::ICustomBody *rigidBody ,void (*collisionFunc)(Oyster::Physics::ICustomBody *proto,Oyster::Physics::ICustomBody *deuter,Oyster::Math::Float kineticEnergyLoss), OBJECT_TYPE type)
:Object(rigidBody, collisionFunc, type)
{