diff --git a/assets b/assets
index 8e4988f..e077e44 160000
--- a/assets
+++ b/assets
@@ -1 +1 @@
-Subproject commit 8e4988fc2ba2582098f9a2e870cb981df7218985
+Subproject commit e077e4412bad4e43a6ae88454efd25880b5d03f2
diff --git a/src/Components/WheelPair.h b/src/Components/WheelPair.h
index 4e74a82..24bc598 100644
--- a/src/Components/WheelPair.h
+++ b/src/Components/WheelPair.h
@@ -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); }
};
diff --git a/src/GUI/Frame.h b/src/GUI/Frame.h
index a2acb8e..e502fea 100644
--- a/src/GUI/Frame.h
+++ b/src/GUI/Frame.h
@@ -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(parent)); }
::RenderQueue 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)
{
+ 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 m_Parent;
typedef std::multimap> Children_t; // name -> frame
std::map m_Children; // layer -> Children_t
diff --git a/src/GUI/GameFrame.h b/src/GUI/GameFrame.h
index 8286997..19f66ac 100644
--- a/src/GUI/GameFrame.h
+++ b/src/GUI/GameFrame.h
@@ -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(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 m_EKeyUp;
+
std::shared_ptr 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;
+ }
};
}
diff --git a/src/GUI/PlayerHUD.h b/src/GUI/PlayerHUD.h
index 648230a..b094d4c 100644
--- a/src/GUI/PlayerHUD.h
+++ b/src/GUI/PlayerHUD.h
@@ -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;
};
}
diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp
index 8fb8c34..c635246 100755
--- a/src/GameWorld.cpp
+++ b/src/GameWorld.cpp
@@ -56,8 +56,8 @@ void GameWorld::Initialize()
auto camera = CreateEntity();
{
auto transform = AddComponent(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() / 8.f, 0.f, 0.f));
auto cameraComp = AddComponent(camera);
cameraComp->FarClip = 2000.f;
@@ -126,7 +126,7 @@ void GameWorld::Initialize()
EntityID tank1 = CreateTank(1);
{
auto transform = GetComponent(tank1);
- transform->Position.z = 50.f;
+ transform->Position.z = 145.f;
Events::SetViewportCamera e;
e.CameraEntity = GetProperty(tank1, "Camera");
@@ -340,6 +340,7 @@ void GameWorld::RegisterSystems()
//m_SystemFactory.Register([this]() { return new Systems::PlayerSystem(this); });
m_SystemFactory.Register([this]() { return new Systems::FreeSteeringSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register([this]() { return new Systems::TankSteeringSystem(this, EventBroker, ResourceManager); });
+ m_SystemFactory.Register([this]() { return new Systems::WheelPairSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register([this]() { return new Systems::SoundSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register([this]() { return new Systems::PhysicsSystem(this, EventBroker, ResourceManager); });
m_SystemFactory.Register([this]() { return new Systems::TriggerSystem(this, EventBroker, ResourceManager); });
@@ -359,6 +360,7 @@ void GameWorld::AddSystems()
//AddSystem();
AddSystem();
AddSystem();
+ AddSystem();
AddSystem();
AddSystem();
AddSystem();
@@ -533,277 +535,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(wheel);
- transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -2.6f);
- transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0));
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(shape);
- boxShape->Width = 0.7f;
- boxShape->Height = 0.34f;
- boxShape->Depth = 0.7f;
- CommitEntity(shape);
- }
- CommitEntity(wheel);
- }
- {
- auto wheel = CreateEntity(tank);
- auto transform = AddComponent(wheel);
- transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, -0.83f);
- transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0));
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(shape);
- boxShape->Width = 0.7f;
- boxShape->Height = 0.34f;
- boxShape->Depth = 0.7f;
- CommitEntity(shape);
- }
- CommitEntity(wheel);
- }
-
- {
- auto wheel = CreateEntity(tank);
- auto transform = AddComponent(wheel);
- transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -2.6f);
- transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0));
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(shape);
- boxShape->Width = 0.7f;
- boxShape->Height = 0.34f;
- boxShape->Depth = 0.7f;
- CommitEntity(shape);
- }
- CommitEntity(wheel);
- }
- {
- auto wheel = CreateEntity(tank);
- auto transform = AddComponent(wheel);
- transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, -0.83f);
- transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0));
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(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(wheel);
- transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 1.f);
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(shape);
- boxShape->Width = 0.7f;
- boxShape->Height = 0.34f;
- boxShape->Depth = 0.7f;
- CommitEntity(shape);
- }
- CommitEntity(wheel);
- }
- {
- auto wheel = CreateEntity(tank);
- auto transform = AddComponent(wheel);
- transform->Position = glm::vec3(1.68f, -0.83f - wheelOffset, 2.95f);
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(shape);
- boxShape->Width = 0.7f;
- boxShape->Height = 0.34f;
- boxShape->Depth = 0.7f;
- CommitEntity(shape);
- }
- CommitEntity(wheel);
-
- auto entity = CreateEntity(tank);
- auto transformComponent = AddComponent(entity);
- transformComponent->Position = glm::vec3(2, -1.7, 2.0);
- transformComponent->Scale = glm::vec3(3, 3, 3);
- transformComponent->Orientation = glm::angleAxis(glm::pi() / 2, glm::vec3(1, 0, 0));
- auto emitterComponent = AddComponent(entity);
- emitterComponent->SpawnCount = 2;
- emitterComponent->SpawnFrequency = 0.005;
- emitterComponent->SpreadAngle = glm::pi();
- emitterComponent->UseGoalVelocity = false;
- emitterComponent->LifeTime = 0.5;
- //emitterComponent->AngularVelocitySpectrum.push_back(glm::pi() / 100);
- emitterComponent->ScaleSpectrum.push_back(glm::vec3(0.05));
- CommitEntity(entity);
-
- auto particleEntity = CreateEntity(entity);
- auto TEMP = AddComponent(particleEntity);
- TEMP->Scale = glm::vec3(0);
- auto spriteComponent = AddComponent(particleEntity);
- spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
- emitterComponent->ParticleTemplate = particleEntity;
-
- CommitEntity(particleEntity);
- }
-
- {
- auto wheel = CreateEntity(tank);
- auto transform = AddComponent(wheel);
- transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 1.f);
- transform->Orientation = glm::angleAxis(glm::pi(), glm::vec3(0, 1, 0));
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(shape);
- boxShape->Width = 0.7f;
- boxShape->Height = 0.34f;
- boxShape->Depth = 0.7f;
- CommitEntity(shape);
- }
- CommitEntity(wheel);
- }
- {
- auto wheel = CreateEntity(tank);
- auto transform = AddComponent(wheel);
- transform->Position = glm::vec3(-1.68f, -0.83f - wheelOffset, 2.95f);
- auto model = AddComponent(wheel);
- model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
- auto Wheel = AddComponent(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(shape);
- shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
- auto boxShape = AddComponent(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(entity);
transformComponent->Position = glm::vec3(-2, -1.7, 2.0);
@@ -834,6 +576,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(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(), glm::vec3(0, 1, 0));
+#ifdef DEBUG
+ auto model = AddComponent(wheelFront);
+ model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
+#endif
+ auto Wheel = AddComponent(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(shape);
+ shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
+ auto boxShape = AddComponent(shape);
+ boxShape->Width = 0.7f;
+ boxShape->Height = 0.34f;
+ boxShape->Depth = 0.7f;
+ CommitEntity(shape);
+ }
+ CommitEntity(wheelFront);
+ }
+
+ auto wheelBack = CreateEntity(tankEntity);
+ {
+ auto transform = AddComponent(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(), glm::vec3(0, 1, 0));
+#ifdef DEBUG
+ auto model = AddComponent(wheelBack);
+ model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
+#endif
+ auto Wheel = AddComponent(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(shape);
+ shapetransform->Position = glm::vec3(0.f, 0.32f, 0.f) + transform->Position;
+ auto boxShape = AddComponent(shape);
+ boxShape->Width = 0.7f;
+ boxShape->Height = 0.34f;
+ boxShape->Depth = 0.7f;
+ CommitEntity(shape);
+ }
+ CommitEntity(wheelBack);
+ }
+
+ auto wheelPair = CreateEntity(tankEntity);
+ {
+ {
+ auto transform = AddComponent(wheelPair);
+ transform->Position = position;
+ //transform->Orientation = glm::quat(glm::vec3(0, glm::pi() / 4.f, 0));
+
+ auto pair = AddComponent(wheelPair);
+ pair->FakeWheelFront = wheelFront;
+ pair->FakeWheelBack = wheelBack;
+ }
+
+ auto modelEntity = CreateEntity(wheelPair);
+ {
+ auto transform = AddComponent(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(), 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(modelEntity);
+ model->ModelFile = "Models/Tank/tankWheel.obj";
+ }
+ CommitEntity(modelEntity);
+ }
+ CommitEntity(wheelPair);
+}
+
EntityID GameWorld::CreateJeep(int playerID)
{
auto jeep = CreateEntity();
diff --git a/src/GameWorld.h b/src/GameWorld.h
index b777975..aae2472 100755
--- a/src/GameWorld.h
+++ b/src/GameWorld.h
@@ -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"
@@ -47,6 +48,7 @@
#include "Components/Health.h"
#include "Components/Trigger.h"
#include "Components/Flag.h"
+#include "Components/WheelPair.h"
class GameWorld : public World
{
@@ -57,9 +59,6 @@ public:
void Initialize();
- EntityID CreateTank(int playerID);
- EntityID CreateJeep(int playerID);
-
void RegisterSystems() override;
void AddSystems() override;
void RegisterComponents() override;
@@ -71,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__
diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp
index 1d028d9..cc1008b 100644
--- a/src/Systems/TankSteeringSystem.cpp
+++ b/src/Systems/TankSteeringSystem.cpp
@@ -62,6 +62,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
if(barrelSteeringComponent)
{
+ auto tankTransform = m_World->GetComponent(entity);
auto transformComponent = m_World->GetComponent(tankSteeringComponent->Barrel);
auto absoluteTransform = m_World->GetSystem()->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;
diff --git a/src/Systems/WheelPairSystem.cpp b/src/Systems/WheelPairSystem.cpp
new file mode 100644
index 0000000..b8b6c4a
--- /dev/null
+++ b/src/Systems/WheelPairSystem.cpp
@@ -0,0 +1,33 @@
+#include "PrecompiledHeader.h"
+#include "WheelPairSystem.h"
+#include "World.h"
+
+void Systems::WheelPairSystem::RegisterComponents(ComponentFactory* cf)
+{
+ cf->Register([]() { return new Components::WheelPair(); });
+}
+
+void Systems::WheelPairSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
+{
+ auto wheelPair = m_World->GetComponent(entity);
+ if (!wheelPair)
+ return;
+
+ auto transform = m_World->GetComponent(entity);
+ if (!transform)
+ return;
+ auto transformFakeFront = m_World->GetComponent(wheelPair->FakeWheelFront);
+ if (!transformFakeFront)
+ return;
+ auto transformFakeBack = m_World->GetComponent(wheelPair->FakeWheelBack);
+ if (!transformFakeBack)
+ return;
+
+ glm::vec3 thing = transformFakeBack->Position - transformFakeFront->Position;
+
+ float height = ((transformFakeFront->Position + transformFakeBack->Position) / 2.f).y;
+ float angle = std::atan2f(thing.y, thing.z);
+
+ transform->Position.y = height;
+ transform->Orientation = glm::quat(glm::eulerAngles(transform->Orientation) * glm::vec3(0, 1, 1) + glm::vec3(-angle, 0, 0));
+}
\ No newline at end of file
diff --git a/src/Systems/WheelPairSystem.h b/src/Systems/WheelPairSystem.h
new file mode 100644
index 0000000..a2bd224
--- /dev/null
+++ b/src/Systems/WheelPairSystem.h
@@ -0,0 +1,22 @@
+#ifndef Systems_WheelPairSystem_h__
+#define Systems_WheelPairSystem_h__
+
+#include "World.h"
+#include "System.h"
+#include "Components/Transform.h"
+#include "Components/WheelPair.h"
+
+namespace Systems
+{
+ class WheelPairSystem : public System
+ {
+ public:
+
+ WheelPairSystem(World* world, std::shared_ptr<::EventBroker> eventBroker, std::shared_ptr<::ResourceManager> resourceManager)
+ : System(world, eventBroker, resourceManager) { }
+
+ void RegisterComponents(ComponentFactory* cf) override;
+ void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
+ };
+}
+#endif // Systems_WheelPairSystem_h__
diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj
index f40a752..1be4904 100755
--- a/vs11/Returngeance/Returngeance.vcxproj
+++ b/vs11/Returngeance/Returngeance.vcxproj
@@ -122,6 +122,7 @@
+
@@ -229,6 +230,7 @@
+
diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters
index 3e4492b..624a222 100755
--- a/vs11/Returngeance/Returngeance.vcxproj.filters
+++ b/vs11/Returngeance/Returngeance.vcxproj.filters
@@ -75,6 +75,7 @@
Gameplay\Systems
+
@@ -481,8 +482,8 @@
GUI
-
- Physics\Components
+
+ Physics\Systems
Base\Events