WIP on deffered_rendering: a459a1c Skybox bugfix

This commit is contained in:
Tleety
2014-05-31 17:12:31 +02:00
19 changed files with 433 additions and 385 deletions
+1 -1
Submodule assets updated: e7ff07be10...463c9531be
-1
View File
@@ -7,7 +7,6 @@ namespace Components
{
struct TankSteering : Component
{
EntityID Player;
EntityID Turret;
EntityID Barrel;
TankSteering* Clone() const override { return new TankSteering(*this); }
+2 -1
View File
@@ -8,7 +8,8 @@ namespace Components
struct WheelPair : Component
{
// Flag for pair wheels
EntityID FakeWheelFront;
EntityID FakeWheelBack;
virtual WheelPair* Clone() const override { return new WheelPair(*this); }
};
+17 -1
View File
@@ -32,12 +32,14 @@ public:
, Rectangle()
, m_Name("UIParent")
, m_Layer(0)
, m_Hidden(false)
{ }
// Create a frame as a child
Frame(Frame* parent, std::string name)
: m_Name(name)
, m_Layer(0)
, m_Hidden(false)
{ SetParent(std::shared_ptr<Frame>(parent)); }
::RenderQueuePair RenderQueue;
@@ -74,6 +76,9 @@ public:
std::string Name() const { return m_Name; }
void SetName(std::string val) { m_Name = val; }
int Layer() const { return m_Layer; }
bool Hidden() const { return m_Hidden; }
void Hide() { m_Hidden = true; }
void Show() { m_Hidden = false; }
int Left() const override
{
@@ -105,6 +110,9 @@ public:
void UpdateLayered(double dt)
{
if (this->Hidden())
return;
// Update ourselves
this->Update(dt);
@@ -115,6 +123,8 @@ public:
for (auto &pairChild : children)
{
auto child = pairChild.second;
if (child->Hidden())
continue;
child->Update(dt);
}
}
@@ -123,6 +133,9 @@ public:
void DrawLayered(std::shared_ptr<Renderer> renderer)
{
if (this->Hidden())
return;
// Draw ourselves
renderer->SetViewport(AbsoluteRectangle());
this->Draw(renderer);
@@ -134,6 +147,8 @@ public:
for (auto &pairChild : children)
{
auto child = pairChild.second;
if (child->Hidden())
continue;
Rectangle rect = child->AbsoluteRectangle();
renderer->SetViewport(rect);
child->Draw(renderer);
@@ -149,7 +164,8 @@ protected:
std::string m_Name;
int m_Layer;
bool m_Hidden;
std::shared_ptr<Frame> m_Parent;
typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
+20 -5
View File
@@ -18,32 +18,47 @@ public:
GameFrame(Frame* parent, std::string name)
: Frame(parent, name)
{
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &GameFrame::OnKeyUp);
m_World = std::make_shared<GameWorld>(EventBroker, ResourceManager);
auto worldFrame = new WorldFrame(this, "GameWorldFrame", m_World);
{
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
vp1->X = 0;
vp1->Width = 640;
vp1->Height = 720 / 2;
//new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right();
vp2->Width = 640;
vp2->Height = 720 / 2;
//new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
auto vpc = new Viewport(worldFrame, "ViewportFreeCam", m_World);
vpc->Y = 720 / 2;
vpc->Height = 720 / 2;
m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport->Show();
}
m_World->Initialize();
}
private:
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
std::shared_ptr<GameWorld> m_World;
Viewport* vp1;
Viewport* vp2;
Viewport* m_FreeCamViewport;
bool OnKeyUp(const Events::KeyUp &event)
{
if (event.KeyCode == GLFW_KEY_1)
{
if (m_FreeCamViewport->Hidden())
m_FreeCamViewport->Show();
else
m_FreeCamViewport->Hide();
}
return true;
}
};
}
+8
View File
@@ -16,6 +16,13 @@ namespace GUI
, m_PlayerID(playerID)
{
m_HealthOverlay = new HealthOverlay(this, "HealthOverlay", m_World, m_PlayerID);
m_Crosshair = new TextureFrame(this, "Crosshair");
m_Crosshair->Width = 45;
m_Crosshair->Height = 45;
m_Crosshair->X = this->Width / 2.f - m_Crosshair->Width / 2.f;
m_Crosshair->Y = this->Height / 2.f - m_Crosshair->Height / 2.f;
m_Crosshair->SetTexture("Textures/GUI/crosshair.png");
m_Crosshair->SetColor(glm::vec4(1.f, 1.f, 1.f, 0.75f));
}
protected:
@@ -23,6 +30,7 @@ namespace GUI
int m_PlayerID;
HealthOverlay* m_HealthOverlay;
TextureFrame* m_Crosshair;
};
}
+304 -351
View File
@@ -53,12 +53,11 @@ void GameWorld::Initialize()
RegisterComponents();
#pragma region FreeCamera
auto camera = CreateEntity();
{
auto transform = AddComponent<Components::Transform>(camera);
transform->Position.z = 20.f;
transform->Position.y = 20.f;
transform->Position.z = 150.f;
transform->Position.y = 10.f;
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(camera);
cameraComp->FarClip = 2000.f;
@@ -70,34 +69,71 @@ void GameWorld::Initialize()
e.ViewportFrame = "ViewportFreeCam";
EventBroker->Publish(e);
}
#pragma endregion
{
auto road_base = CreateEntity();
auto transform = AddComponent<Components::Transform>(road_base);
transform->Position = glm::vec3(0, -50, 0);
auto model = AddComponent<Components::Model>(road_base);
model->ModelFile = "Models/TerrainFiveIstles/Roads/BaseRoad.obj";
auto physics = AddComponent<Components::Physics>(road_base);
physics->Mass = 10;
physics->Static = true;
physics->CollisionLayer = 1;
auto groundshape = CreateEntity(road_base);
auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape);
meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/BaseRoad.obj";
CommitEntity(groundshape);
CommitEntity(road_base);
}
{
auto road_middle = CreateEntity();
auto transform = AddComponent<Components::Transform>(road_middle);
transform->Position = glm::vec3(0, -50, 0);
auto model = AddComponent<Components::Model>(road_middle);
model->ModelFile = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj";
auto physics = AddComponent<Components::Physics>(road_middle);
physics->Mass = 10;
physics->Static = true;
physics->CollisionLayer = 1;
auto groundshape = CreateEntity(road_middle);
auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape);
meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/MiddleRoad.obj";
CommitEntity(groundshape);
CommitEntity(road_middle);
}
{
auto road_small = CreateEntity();
auto transform = AddComponent<Components::Transform>(road_small);
transform->Position = glm::vec3(0, -50, 0);
auto model = AddComponent<Components::Model>(road_small);
model->ModelFile = "Models/TerrainFiveIstles/Roads/SmallRoad.obj";
auto physics = AddComponent<Components::Physics>(road_small);
physics->Mass = 10;
physics->Static = true;
physics->CollisionLayer = 1;
auto groundshape = CreateEntity(road_small);
auto transformshape = AddComponent<Components::Transform>(groundshape);
auto meshShape = AddComponent<Components::MeshShape>(groundshape);
meshShape->ResourceName = "Models/TerrainFiveIstles/Roads/SmallRoad.obj";
CommitEntity(groundshape);
CommitEntity(road_small);
}
//{
// auto ground = CreateEntity();
// auto transform = AddComponent<Components::Transform>(ground);
// transform->Position = glm::vec3(0, -50, 0);
// //transform->Scale = glm::vec3(400.0f, 10.0f, 400.0f);
// transform->Orientation = glm::quat(glm::vec3(0.0f, 0.0f, 0.0f));
// auto model = AddComponent<Components::Model>(ground);
// model->ModelFile = "Models/TestScene3/testScene.obj";
// //model->ModelFile = "Models/Placeholders/Terrain/Terrain2.obj";
//
// auto physics = AddComponent<Components::Physics>(ground);
// physics->Mass = 10;
// physics->Static = true;
// auto groundshape = CreateEntity(ground);
// auto transformshape = AddComponent<Components::Transform>(groundshape);
// auto meshShape = AddComponent<Components::MeshShape>(groundshape);
// //meshShape->ResourceName = "Models/Placeholders/Terrain/Terrain2.obj";
// meshShape->ResourceName = "Models/TestScene3/testScene.obj";
//
// CommitEntity(groundshape);
// CommitEntity(ground);
//}
{
auto water = CreateEntity();
auto transform = AddComponent<Components::Transform>(water);
@@ -107,7 +143,7 @@ void GameWorld::Initialize()
auto model = AddComponent<Components::Model>(water);
model->ModelFile = "Models/Placeholders/PhysicsTest/Cube.obj";
auto blendmap = AddComponent<Components::BlendMap>(water);
blendmap->TextureRed = "Textures/Ground/WaterPlain0017_6_S.jpg";
blendmap->TextureRed = "Textures/Ground/WaterPlain0017_6_S.png";
blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png";
blendmap->TextureGreen = "Textures/Ground/WaterPlain0017_6_S.jpg";
blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png";
@@ -121,14 +157,14 @@ void GameWorld::Initialize()
physics->CollisionLayer = 1;
{
auto groundshape = CreateEntity(water);
auto box = AddComponent<Components::BoxShape>(groundshape);
box->Depth = 250.f;
box->Height = 5.f;
box->Width = 250.f;
auto groundshape = CreateEntity(water);
auto box = AddComponent<Components::BoxShape>(groundshape);
box->Depth = 250.f;
box->Height = 5.f;
box->Width = 250.f;
CommitEntity(groundshape);
CommitEntity(groundshape);
}
CommitEntity(water);
}
@@ -172,9 +208,12 @@ void GameWorld::Initialize()
auto model = AddComponent<Components::Model>(ground_small);
model->ModelFile = "Models/TerrainFiveIstles/Small.obj";
auto blendmap = AddComponent<Components::BlendMap>(ground_small);
blendmap->TextureRed = "Textures/Ground/Sand.png";
blendmap->TextureGreen = "Textures/Ground/Grass.png";
blendmap->TextureBlue = "Textures/Ground/Asphalt.png";
blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg";
blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png";
blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg";
blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png";
blendmap->TextureBlue = "Textures/Ground/Cliffs2.png";
blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png";
blendmap->TextureRepeats = 30.f;
auto physics = AddComponent<Components::Physics>(ground_small);
@@ -200,9 +239,12 @@ void GameWorld::Initialize()
auto model = AddComponent<Components::Model>(ground_small_mirrored);
model->ModelFile = "Models/TerrainFiveIstles/Small.obj";
auto blendmap = AddComponent<Components::BlendMap>(ground_small_mirrored);
blendmap->TextureRed = "Textures/Ground/Sand.png";
blendmap->TextureGreen = "Textures/Ground/Grass.png";
blendmap->TextureBlue = "Textures/Ground/Asphalt.png";
blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg";
blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png";
blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg";
blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png";
blendmap->TextureBlue = "Textures/Ground/Cliffs2.png";
blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png";
blendmap->TextureRepeats = 30.f;
auto physics = AddComponent<Components::Physics>(ground_small_mirrored);
@@ -228,9 +270,12 @@ void GameWorld::Initialize()
auto model = AddComponent<Components::Model>(ground_base);
model->ModelFile = "Models/TerrainFiveIstles/Base.obj";
auto blendmap = AddComponent<Components::BlendMap>(ground_base);
blendmap->TextureRed = "Textures/Ground/Sand.png";
blendmap->TextureGreen = "Textures/Ground/Grass.png";
blendmap->TextureBlue = "Textures/Ground/Asphalt.png";
blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg";
blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png";
blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg";
blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png";
blendmap->TextureBlue = "Textures/Ground/Cliffs2.png";
blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png";
blendmap->TextureRepeats = 30.f;
auto physics = AddComponent<Components::Physics>(ground_base);
@@ -256,9 +301,12 @@ void GameWorld::Initialize()
auto model = AddComponent<Components::Model>(ground_base_mirrored);
model->ModelFile = "Models/TerrainFiveIstles/Base.obj";
auto blendmap = AddComponent<Components::BlendMap>(ground_base_mirrored);
blendmap->TextureRed = "Textures/Ground/Sand.png";
blendmap->TextureGreen = "Textures/Ground/Grass.png";
blendmap->TextureBlue = "Textures/Ground/Asphalt.png";
blendmap->TextureRed = "Textures/Ground/SoilBeach0087_11_S.jpg";
blendmap->TextureRedNormal = "Textures/Ground/SoilBeach0087_11_SNM.png";
blendmap->TextureGreen = "Textures/Ground/Grass0126_2_S.jpg";
blendmap->TextureGreenNormal = "Textures/Ground/Grass0126_2_SNM.png";
blendmap->TextureBlue = "Textures/Ground/Cliffs2.png";
blendmap->TextureBlueNormal = "Textures/Ground/Cliffs2NM.png";
blendmap->TextureRepeats = 30.f;
auto physics = AddComponent<Components::Physics>(ground_base_mirrored);
@@ -290,7 +338,7 @@ void GameWorld::Initialize()
EntityID tank1 = CreateTank(1);
{
auto transform = GetComponent<Components::Transform>(tank1);
transform->Position.z = 50.f;
transform->Position.z = 50;
Events::SetViewportCamera e;
e.CameraEntity = GetProperty<EntityID>(tank1, "Camera");
@@ -358,6 +406,69 @@ void GameWorld::Initialize()
//}
{
auto gateBase = CreateEntity();
auto transform = AddComponent<Components::Transform>(gateBase);
transform->Position = glm::vec3(0, -50, 150);
auto model = AddComponent<Components::Model>(gateBase);
model->ModelFile = "Models/Gate/Lift/Lift.obj";
auto physics = AddComponent<Components::Physics>(gateBase);
physics->Static = true;
physics->CollisionLayer = 1; // Terrain-Layer
{
auto leftBaseShape = CreateEntity(gateBase);
auto transform = AddComponent<Components::Transform>(leftBaseShape);
transform->Position = glm::vec3(8.5f, 3, 0);
auto box = AddComponent<Components::BoxShape>(leftBaseShape);
box->Width = 3.f/2;
box->Height = 6.094f/2;
box->Depth = 4.f/2;
CommitEntity(leftBaseShape);
}
{
auto RightBaseShape = CreateEntity(gateBase);
auto transform = AddComponent<Components::Transform>(RightBaseShape);
transform->Position = glm::vec3(-8.5f, 3, 0);
auto box = AddComponent<Components::BoxShape>(RightBaseShape);
box->Width = 3.f/2;
box->Height = 6.094f/2;
box->Depth = 4.f/2;
CommitEntity(RightBaseShape);
}
{
auto LeftTopShape = CreateEntity(gateBase);
auto transform = AddComponent<Components::Transform>(LeftTopShape);
transform->Position = glm::vec3(7.5485f, 9.385f, 0);
auto box = AddComponent<Components::BoxShape>(LeftTopShape);
box->Width = 1.747f/2;
box->Height = 6.851f/2;
box->Depth = 1.767f/2;
CommitEntity(LeftTopShape);
}
{
auto RightTopShape = CreateEntity(gateBase);
auto transform = AddComponent<Components::Transform>(RightTopShape);
transform->Position = glm::vec3(-7.5485f, 9.385f, 0);
auto box = AddComponent<Components::BoxShape>(RightTopShape);
box->Width = 1.747f/2;
box->Height = 6.851f/2;
box->Depth = 1.767f/2;
CommitEntity(RightTopShape);
}
{
auto RampShape = CreateEntity(gateBase);
auto transform = AddComponent<Components::Transform>(RampShape);
transform->Position = glm::vec3(0, 0.24f, 0);
auto box = AddComponent<Components::BoxShape>(RampShape);
box->Width = 14.9f/2;
box->Height = 0.38f/2;
box->Depth = 1.484f/2;
CommitEntity(RampShape);
}
CommitEntity(gateBase);
}
}
void GameWorld::Update(double dt)
@@ -371,7 +482,6 @@ void GameWorld::RegisterComponents()
m_ComponentFactory.Register<Components::Template>([]() { return new Components::Template(); });
m_ComponentFactory.Register<Components::Player>([]() { return new Components::Player(); });
m_ComponentFactory.Register<Components::Flag>([]() { return new Components::Flag(); });
m_ComponentFactory.Register<Components::BlendMap>([]() { return new Components::BlendMap(); });
}
void GameWorld::RegisterSystems()
@@ -387,6 +497,7 @@ void GameWorld::RegisterSystems()
//m_SystemFactory.Register<Systems::PlayerSystem>([this]() { return new Systems::PlayerSystem(this); });
m_SystemFactory.Register<Systems::FreeSteeringSystem>([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::TankSteeringSystem>([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::WheelPairSystem>([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::SoundSystem>([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::PhysicsSystem>([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register<Systems::TriggerSystem>([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); });
@@ -406,6 +517,7 @@ void GameWorld::AddSystems()
//AddSystem<Systems::PlayerSystem>();
AddSystem<Systems::FreeSteeringSystem>();
AddSystem<Systems::TankSteeringSystem>();
AddSystem<Systems::WheelPairSystem>();
AddSystem<Systems::SoundSystem>();
AddSystem<Systems::PhysicsSystem>();
AddSystem<Systems::TriggerSystem>();
@@ -450,12 +562,6 @@ void GameWorld::BindGamepadButton(Gamepad::Button button, std::string command, f
EntityID GameWorld::CreateTank(int playerID)
{
auto playerEnt = CreateEntity();
{
auto player = AddComponent<Components::Player>(playerEnt);
player->ID = playerID;
}
auto tank = CreateEntity();
auto transform = AddComponent<Components::Transform>(tank);
transform->Position = glm::vec3(0, 5, 0);
@@ -470,7 +576,6 @@ EntityID GameWorld::CreateTank(int playerID)
auto player = AddComponent<Components::Player>(tank);
player->ID = playerID;
auto tankSteering = AddComponent<Components::TankSteering>(tank);
tankSteering->Player = playerEnt;
AddComponent<Components::Input>(tank);
auto health = AddComponent<Components::Health>(tank);
health->Amount = 100.f;
@@ -544,6 +649,20 @@ EntityID GameWorld::CreateTank(int playerID)
}
CommitEntity(shot);
barrelSteering->ShotTemplate = shot;
auto cameraTower = CreateEntity(barrel);
{
auto transform = AddComponent<Components::Transform>(cameraTower);
transform->Position.z = 16.f;
transform->Position.y = 4.f;
transform->Orientation = glm::quat(glm::vec3(-glm::radians(5.f), 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
//auto freeSteering = AddComponent<Components::FreeSteering>(cameraTower);
}
SetProperty(tank, "Camera", cameraTower);
}
CommitEntity(barrel);
tankSteering->Barrel = barrel;
@@ -552,18 +671,7 @@ EntityID GameWorld::CreateTank(int playerID)
tankSteering->Turret = tower;
auto cameraTower = CreateEntity(tower);
{
auto transform = AddComponent<Components::Transform>(cameraTower);
transform->Position.z = 16.f;
transform->Position.y = 4.f;
//transform->Orientation = glm::quat(glm::vec3(glm::pi<float>() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
//auto freeSteering = AddComponent<Components::FreeSteering>(cameraTower);
}
SetProperty(tank, "Camera", cameraTower);
}
//{
@@ -584,279 +692,17 @@ EntityID GameWorld::CreateTank(int playerID)
#pragma region Wheels
//Create wheels
float wheelOffset = 0.4f;
float springLength = 0.3f;
float suspensionStrength = 15.f;
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 0;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = true;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
//Back
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(2, -1.7, 2.0);
transformComponent->Scale = glm::vec3(3, 3, 3);
transformComponent->Orientation = glm::angleAxis(glm::pi<float>() / 2, glm::vec3(1, 0, 0));
auto emitterComponent = AddComponent<Components::ParticleEmitter>(entity);
emitterComponent->SpawnCount = 2;
emitterComponent->SpawnFrequency = 0.005;
emitterComponent->SpreadAngle = glm::pi<float>();
emitterComponent->UseGoalVelocity = false;
emitterComponent->LifeTime = 0.5;
//emitterComponent->AngularVelocitySpectrum.push_back(glm::pi<float>() / 100);
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
{
auto particleEntity = CreateEntity(entity);
auto templateComponent = AddComponent<Components::Template>(particleEntity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
}
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f);
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
}
{
auto wheel = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(wheel);
transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
auto model = AddComponent<Components::Model>(wheel);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
auto Wheel = AddComponent<Components::Wheel>(wheel);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = 1;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = false;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheel);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheel);
float wheelOffset = -0.83f;
const float suspensionStrength = 15.f;
const float springLength = 0.3f;
AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, -1.715f), 0, true);
AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, -1.715f), 0, true);
AddTankWheelPair(tank, glm::vec3(1.68f, wheelOffset, 2.375), 1, false);
AddTankWheelPair(tank, glm::vec3(-1.68f, wheelOffset, 2.375), 1, false);
#pragma endregion
{
auto entity = CreateEntity(tank);
auto transformComponent = AddComponent<Components::Transform>(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
@@ -872,16 +718,14 @@ EntityID GameWorld::CreateTank(int playerID)
emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
CommitEntity(entity);
{
auto particleEntity = CreateEntity(entity);
auto templateComponent = AddComponent<Components::Template>(particleEntity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
CommitEntity(particleEntity);
emitterComponent->ParticleTemplate = particleEntity;
}
auto particleEntity = CreateEntity(entity);
auto TEMP = AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
CommitEntity(particleEntity);
}
CommitEntity(tank);
@@ -889,6 +733,115 @@ EntityID GameWorld::CreateTank(int playerID)
return tank;
}
void GameWorld::AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front)
{
const float separation = 1.77f;
const float suspensionStrength = 15.f;
const float springLength = 0.3f;
bool steering = front;
auto wheelFront = CreateEntity(tankEntity);
{
auto transform = AddComponent<Components::Transform>(wheelFront);
transform->Position = position - glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
//transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
#ifdef DEBUG
auto model = AddComponent<Components::Model>(wheelFront);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
#endif
auto Wheel = AddComponent<Components::Wheel>(wheelFront);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = axleID;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = steering;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheelFront);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheelFront);
}
auto wheelBack = CreateEntity(tankEntity);
{
auto transform = AddComponent<Components::Transform>(wheelBack);
transform->Position = position + glm::vec3(0, 0, separation / 2.f); // glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
//transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
#ifdef DEBUG
auto model = AddComponent<Components::Model>(wheelBack);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
#endif
auto Wheel = AddComponent<Components::Wheel>(wheelBack);
Wheel->Hardpoint = transform->Position + glm::vec3(0.f, springLength, 0.f);
Wheel->AxleID = axleID;
Wheel->Mass = 2000;
Wheel->Radius = 0.6f;
Wheel->Steering = steering;
Wheel->SuspensionStrength = suspensionStrength;
Wheel->Friction = 3.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
{
auto shape = CreateEntity(wheelBack);
auto shapetransform = AddComponent<Components::Transform>(shape);
shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.7f;
boxShape->Height = 0.34f;
boxShape->Depth = 0.7f;
CommitEntity(shape);
}
CommitEntity(wheelBack);
}
auto wheelPair = CreateEntity(tankEntity);
{
{
auto transform = AddComponent<Components::Transform>(wheelPair);
transform->Position = position;
//transform->Orientation = glm::quat(glm::vec3(0, glm::pi<float>() / 4.f, 0));
auto pair = AddComponent<Components::WheelPair>(wheelPair);
pair->FakeWheelFront = wheelFront;
pair->FakeWheelBack = wheelBack;
}
auto modelEntity = CreateEntity(wheelPair);
{
auto transform = AddComponent<Components::Transform>(modelEntity);
//transform->Position = glm::vec3(0.f, 0.35f, 0.f);
if (front)
{
transform->Position = glm::vec3(0.f, 0.03f, 0.f);
transform->Orientation = glm::quat(glm::vec3(0, glm::pi<float>(), 0));
}
else
{
transform->Position = glm::vec3(0.f, 0.17f, 0.f);
transform->Scale = glm::vec3(1.f, 1.2f, 1.2f);
}
auto model = AddComponent<Components::Model>(modelEntity);
model->ModelFile = "Models/Tank/tankWheel.obj";
}
CommitEntity(modelEntity);
}
CommitEntity(wheelPair);
}
EntityID GameWorld::CreateJeep(int playerID)
{
auto jeep = CreateEntity();
+6 -4
View File
@@ -20,6 +20,7 @@
#include "Systems/TriggerSystem.h"
#include "Systems/TimerSystem.h"
#include "Systems/DamageSystem.h"
#include "Systems/WheelPairSystem.h"
#include "Components/Camera.h"
#include "Components/DirectionalLight.h"
@@ -33,7 +34,6 @@
#include "Components/Template.h"
#include "Components/Transform.h"
#include "Components/Viewport.h"
#include "Components/BlendMap.h"
#include "Components/Physics.h"
#include "Components/SphereShape.h"
@@ -48,6 +48,7 @@
#include "Components/Health.h"
#include "Components/Trigger.h"
#include "Components/Flag.h"
#include "Components/WheelPair.h"
class GameWorld : public World
{
@@ -58,9 +59,6 @@ public:
void Initialize();
EntityID CreateTank(int playerID);
EntityID CreateJeep(int playerID);
void RegisterSystems() override;
void AddSystems() override;
void RegisterComponents() override;
@@ -72,6 +70,10 @@ private:
void BindMouseButton(int button, std::string command, float value);
void BindGamepadAxis(Gamepad::Axis axis, std::string command, float value);
void BindGamepadButton(Gamepad::Button button, std::string command, float value);
EntityID CreateTank(int playerID);
void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool steering);
EntityID CreateJeep(int playerID);
};
#endif // GameWorld_h__
+1 -2
View File
@@ -183,7 +183,6 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultE
engine.m_maxRPM = vehicleComponent.MaxRPM;
engine.m_torqueFactorAtMinRPM = 0.8f;
engine.m_torqueFactorAtMaxRPM = 0.8f;
engine.m_resistanceFactorAtMinRPM = 0.05f;
@@ -200,7 +199,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultT
transmission.m_downshiftRPM = 3500.0f; //HACK: Should be in VehicleComponent
transmission.m_upshiftRPM = 7000.0f;
transmission.m_clutchDelayTime = 0.0f;
transmission.m_clutchDelayTime = 1.5f;
transmission.m_reverseGearRatio = 1.0f;
transmission.m_gearsRatio[0] = 3.0f;
transmission.m_gearsRatio[1] = 2.25f;
+2 -2
View File
@@ -163,7 +163,7 @@ void Renderer::LoadContent()
FrameBufferTextures();
m_sphereModel = ResourceManager->Load<Model>("Model", "Models/Placeholders/PhysicsTest/Sphere.obj");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/Sunset", "jpg");
m_Skybox = std::make_shared<Skybox>("Textures/Skybox/Sky34", "jpg");
}
void Renderer::Draw(double dt)
@@ -392,7 +392,7 @@ void Renderer::DrawWorld(RenderQueuePair &rq)
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
DrawSkybox();
//DrawSkybox();
DrawFBOScene(rq.Deferred);
/*
-1
View File
@@ -12,5 +12,4 @@ out vec4 FragColor;
void main()
{
FragColor = texture(CubemapTexture, Input.TextureCoord);
//FragColor = vec4(1.0, 1.0, 1.0, 0.0);
}
+57 -11
View File
@@ -138,6 +138,7 @@ void Systems::PhysicsSystem::Initialize()
e.Layer2 = EXPLOSION_LAYER;
EventBroker->Publish(e);
}*/
}
void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
@@ -155,6 +156,8 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf)
void Systems::PhysicsSystem::Update(double dt)
{
for (auto pair : *m_World->GetEntities())
{
EntityID entity = pair.first;
@@ -171,23 +174,36 @@ void Systems::PhysicsSystem::Update(double dt)
{
hkVector4 position;
hkQuaternion rotation;
hkVector4 velocity;
if (parent)
{
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(entity);
position = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Position);
rotation = GLMQUAT_TO_HKQUATERNION(absoluteTransform.Orientation);
velocity = GLMVEC3_TO_HKVECTOR4(absoluteTransform.Velocity);
}
else
{
position = GLMVEC3_TO_HKVECTOR4(transformComponent->Position);
rotation = GLMQUAT_TO_HKQUATERNION(transformComponent->Orientation);
velocity = GLMVEC3_TO_HKVECTOR4(transformComponent->Velocity);
}
m_PhysicsWorld->markForWrite();
m_RigidBodies[entity]->setPositionAndRotation(position, rotation);
m_RigidBodies[entity]->setLinearVelocity(velocity);
m_PhysicsWorld->unmarkForWrite();
}
/*
glm::vec3 pos1 = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[m_World->m_Terrain]->getPosition());
pos1 += glm::vec3(1, 1, 1)*(float)dt;
hkVector4 pos = GLMVEC3_TO_HKVECTOR4(pos1);
m_PhysicsWorld->markForWrite();
m_RigidBodies[m_World->m_Terrain]->setPositionAndRotation(pos, GLMQUAT_TO_HKQUATERNION(glm::quat()));
m_PhysicsWorld->unmarkForWrite();*/
}
static const double timestep = 1 / 60.0;
@@ -240,11 +256,12 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
else if(m_RigidBodies.find(entity) != m_RigidBodies.end())
{
auto transformComponentParent = m_World->GetComponent<Components::Transform>(parent);
transformComponent->Position = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getPosition());
transformComponent->Orientation = HKQUATERNION_TO_GLMQUAT(m_RigidBodies[entity]->getRotation());
transformComponent->Velocity = HKVECTOR4_TO_GLMVEC3(m_RigidBodies[entity]->getLinearVelocity());
// TODO: No support for Scale, MIGHT be possible
// HACK: WTF IS THIS?
if (transformComponentParent)
{
transformComponent->Position -= transformComponentParent->Position;
@@ -319,7 +336,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
}
// Create a hkpListShape* of all the childEntities collected in m_ShapeArrays
hkpListShape* listShape = new hkpListShape(shapeArray.begin(), shapeArray.getSize(), hkpShapeContainer::REFERENCE_POLICY_INCREMENT);
// Save the listShape for further use
@@ -377,6 +393,8 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
}
// Create RigidBody
hkpRigidBody* rigidBody = new hkpRigidBody(rigidBodyInfo);
m_RigidBodies[entity] = rigidBody;
m_RigidBodyEntities[rigidBody] = entity;
auto vehicleComponent = m_World->GetComponent<Components::Vehicle >(entity);
if (vehicleComponent && m_Vehicles.find(entity) == m_Vehicles.end())
@@ -393,7 +411,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
VehicleSetup vehicleSetup;
// Create the basic vehicle.
m_Vehicles[entity] = new hkpVehicleInstance(rigidBody);
m_Vehicles[entity] = new hkpVehicleInstance(m_RigidBodies[entity]);
m_PhysicsWorld->markForWrite();
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
// Add the vehicle's entities and phantoms to the world
@@ -402,8 +420,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBody->addContactListener( m_collisionResolution );
}
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
m_RigidBodies[entity] = rigidBody;
m_RigidBodyEntities[rigidBody] = entity;
// The vehicle is an action
@@ -423,8 +439,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
rigidBody->addContactListener( m_collisionResolution );
}
m_PhysicsWorld->addEntity(rigidBody);
m_RigidBodies[entity] = rigidBody;
m_RigidBodyEntities[rigidBody] = entity;
m_PhysicsWorld->unmarkForWrite();
shape->removeReference();
@@ -576,7 +591,6 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
if(triggerComponent)
{
auto parentTransformComponent = m_World->GetComponent<Components::Transform >(entityParent);
PhantomCallbackShape* phantom = new PhantomCallbackShape(this);
hkpBvShape* phantomShape = new hkpBvShape(boxShape, phantom);
@@ -707,11 +721,40 @@ void HK_CALL Systems::PhysicsSystem::HavokErrorReport(const char* msg, void*)
bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event)
{
auto vehicleComponent = m_World->GetComponent<Components::Vehicle>(event.Entity);
if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end())
{
hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus;
deviceStatus->m_positionX = event.PositionX;
deviceStatus->m_positionY = event.PositionY;
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
float steeringX = event.PositionX;
glm::vec3 velocityNormalized = glm::normalize(HKVECTOR4_TO_GLMVEC3(m_RigidBodies[event.Entity]->getLinearVelocity()));
glm::vec3 forward = glm::normalize(transformComponent->Orientation * glm::vec3(0, 0, -1));
float dotProduct = glm::dot(forward, velocityNormalized);
if(dotProduct < 0)
{
steeringX = (1 - (glm::clamp(abs(m_Vehicles[event.Entity]->calcKMPH() /vehicleComponent->TopSpeed), 0.f, 0.7f))) * steeringX;
}
if(abs(m_Vehicles[event.Entity]->calcKMPH()) < 2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
{
deviceStatus->m_positionY = -0.4f;
deviceStatus->m_positionX = steeringX;
}
// else if(m_Vehicles[event.Entity]->calcKMPH() > -2 && abs(m_Vehicles[event.Entity]->m_mainSteeringAngle) > 80.f * (HK_REAL_PI / 180))
// {
// deviceStatus->m_positionY = 0.4f;;
// deviceStatus->m_positionX = -steeringX;
// }
else
{
deviceStatus->m_positionX = steeringX;
deviceStatus->m_positionY = event.PositionY;
}
if(event.PositionY > 0)
{
deviceStatus->m_reverseButtonPressed = true;
@@ -728,6 +771,9 @@ bool Systems::PhysicsSystem::OnSetVelocity( const Events::SetVelocity &event )
{
m_PhysicsWorld->markForWrite();
m_RigidBodies[event.Entity]->setLinearVelocity(GLMVEC3_TO_HKVECTOR4(event.Velocity));
auto transformComponent = m_World->GetComponent<Components::Transform>(event.Entity);
transformComponent->Velocity = event.Velocity;
m_PhysicsWorld->unmarkForWrite();
}
return true;
@@ -813,4 +859,4 @@ bool Systems::PhysicsSystem::OnDisableCollisions( const Events::DisableCollision
m_PhysicsWorld->setCollisionFilter(m_CollisionFilter);
m_PhysicsWorld->unmarkForWrite();
return true;
}
}
+1
View File
@@ -15,6 +15,7 @@ void Systems::RenderSystem::RegisterComponents(ComponentFactory* cf)
cf->Register<Components::PointLight>([]() { return new Components::PointLight(); });
cf->Register<Components::DirectionalLight>([]() { return new Components::DirectionalLight(); });
cf->Register<Components::Viewport>([]() { return new Components::Viewport(); });
cf->Register<Components::BlendMap>([]() { return new Components::BlendMap(); });
}
void Systems::RenderSystem::OnEntityCommit(EntityID entity)
+1
View File
@@ -20,6 +20,7 @@
#include "Renderer.h"
#include "RenderQueue.h"
#include "Events/SetViewportCamera.h"
#include "Components/BlendMap.h"
namespace Systems
{
+4 -4
View File
@@ -33,7 +33,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
if(!tankSteeringComponent)
return;
auto playerComponent = m_World->GetComponent<Components::Player>(tankSteeringComponent->Player);
auto playerComponent = m_World->GetComponent<Components::Player>(entity);
if (!playerComponent)
return;
@@ -62,6 +62,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
if(barrelSteeringComponent)
{
auto tankTransform = m_World->GetComponent<Components::Transform>(entity);
auto transformComponent = m_World->GetComponent<Components::Transform>(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(tankSteeringComponent->Barrel);
glm::quat orientation = glm::angleAxis(barrelSteeringComponent->TurnSpeed * inputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis);
@@ -76,7 +77,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
cloneTransform->Orientation = absoluteTransform.Orientation * cloneTransform->Orientation;
Events::SetVelocity eSetVelocity;
eSetVelocity.Entity = clone;
eSetVelocity.Velocity = absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
eSetVelocity.Velocity = tankTransform->Velocity + absoluteTransform.Orientation * (glm::vec3(0.f, 0.f, -1.f) * barrelSteeringComponent->ShotSpeed);
EventBroker->Publish(eSetVelocity);
m_TimeSinceLastShot[tankSteeringComponent->Barrel] = 0;
@@ -257,13 +258,12 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
if (event.Command == "horizontal")
{
m_Horizontal = val;
m_Vertical = -0.4f;
}
else if (event.Command == "vertical")
{
m_Vertical = -val;
}
else if (event.Command == "handbrake")
{
Handbrake = val > 0;
+2
View File
@@ -29,6 +29,8 @@
#include "Components/FrameTimer.h"
#include "Events/Damage.h"
#include "Components/Vehicle.h"
#include "Components/Player.h"
namespace Systems
{
+1 -1
View File
@@ -82,7 +82,7 @@ void Systems::TriggerSystem::Flag( EntityID entity, EntityID phantomEntity )
m_World->RemoveComponent<Components::Trigger>(phantomEntity);
m_World->SetEntityParent(phantomEntity, entity);
auto phantomTransform = m_World->GetComponent<Components::Transform>(phantomEntity);
phantomTransform->Position = glm::vec3(1.f, 0.1f, 2.f);
phantomTransform->Position = glm::vec3(-1.5f, 0.1f, 2.f);
}
+2
View File
@@ -122,6 +122,7 @@
<ClCompile Include="..\..\src\Systems\TimerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TransformSystem.cpp" />
<ClCompile Include="..\..\src\Systems\TriggerSystem.cpp" />
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
<ClCompile Include="..\..\src\Texture.cpp" />
<ClCompile Include="..\..\src\World.cpp" />
</ItemGroup>
@@ -227,6 +228,7 @@
<ClInclude Include="..\..\src\Systems\TimerSystem.h" />
<ClInclude Include="..\..\src\Systems\TransformSystem.h" />
<ClInclude Include="..\..\src\Systems\TriggerSystem.h" />
<ClInclude Include="..\..\src\Systems\WheelPairSystem.h" />
<ClInclude Include="..\..\src\Texture.h" />
<ClInclude Include="..\..\src\Util\GLError.h" />
<ClInclude Include="..\..\src\Util\Rectangle.h" />
@@ -75,6 +75,7 @@
<ClCompile Include="..\..\src\Systems\DamageSystem.cpp">
<Filter>Gameplay\Systems</Filter>
</ClCompile>
<ClCompile Include="..\..\src\Systems\WheelPairSystem.cpp" />
</ItemGroup>
<ItemGroup>
<Filter Include="Util">
@@ -478,6 +479,9 @@
<ClInclude Include="..\..\src\GUI\PlayerHUD.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Systems\WheelPairSystem.h">
<Filter>Physics\Systems</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\BlendMap.h">
<Filter>Rendering\Components</Filter>
</ClInclude>