7 Commits

Author SHA1 Message Date
Jace 0ad3d8ed76 Fixed vehicle selection hiding on selection 2014-06-03 03:55:35 +02:00
Jace 4596fffb91 Vehicle spawning 2014-06-03 03:55:34 +02:00
Jace 46f377c94c Interface input revised 2014-06-03 03:55:34 +02:00
Jace 68abdbb4e0 SpawnVehicle event 2014-06-03 03:55:34 +02:00
Jace c55b9333a9 MKLINK made a corrupt FMOD DLL for some reason. Switching to COPY. 2014-06-03 03:53:47 +02:00
Jace 826f390d28 Merge remote-tracking branch 'origin/FMOD' 2014-06-02 23:03:47 +02:00
Jace 78cf4a0223 Multiple binds per input 2014-06-02 22:38:11 +02:00
16 changed files with 594 additions and 387 deletions
+1 -1
Submodule assets updated: 4a7b5c236d...3c4d81137f
+4 -4
View File
@@ -15,12 +15,12 @@ MKLINK "%ConfigPath%\Sounds\" "assets\Sounds\" /J
:: Shaders
MKLINK "%ConfigPath%\Shaders\" "src\Shaders\" /J
:: DLLs
MKLINK "%ConfigPath%\glfw3.dll" "libs\glfw-3.0.4\lib\%Configuration%\glfw3.dll" /H
MKLINK "%ConfigPath%\fmodex.dll" "libs\FMOD\lib\fmodex.dll" /H
COPY "libs\glfw-3.0.4\lib\%Configuration%\glfw3.dll" "%ConfigPath%\glfw3.dll"
COPY "libs\FMOD\lib\fmodex.dll" "%ConfigPath%\fmodex.dll"
IF %~1==Debug (
MKLINK "%ConfigPath%\glew32d.dll" "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32d.dll" /H
COPY "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32d.dll" "%ConfigPath%\glew32d.dll"
)
IF %~1==Release (
MKLINK "%ConfigPath%\glew32.dll" "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32.dll" /H
COPY "libs\glew-1.10.0\bin\%Configuration%\Win32\glew32.dll" "%ConfigPath%\glew32.dll"
)
GOTO:eof
+16
View File
@@ -0,0 +1,16 @@
#ifndef Components_VehicleSpawn_h__
#define Components_VehicleSpawn_h__
#include "Component.h"
namespace Components
{
struct SpawnPoint : Component
{
virtual SpawnPoint* Clone() const override { return new SpawnPoint(*this); }
};
}
#endif // Components_VehicleSpawn_h__
+16
View File
@@ -0,0 +1,16 @@
#ifndef Events_SpawnVehicle_h__
#define Events_SpawnVehicle_h__
#include "Entity.h"
#include "EventBroker.h"
namespace Events
{
struct SpawnVehicle : Event
{
int PlayerID;
std::string VehicleType;
};
}
#endif // Events_SpawnVehicle_h__
+18 -6
View File
@@ -6,6 +6,9 @@
#include "Util/Rectangle.h"
#include "EventBroker.h"
#include "Events/KeyDown.h"
#include "Events/KeyUp.h"
#include "Events/InputCommand.h"
#include "ResourceManager.h"
#include "Renderer.h"
#include "RenderQueue.h"
@@ -79,7 +82,13 @@ 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; }
bool Hidden() const
{
if (m_Parent)
return m_Parent->Hidden() || m_Hidden;
else
return m_Hidden;
}
void Hide() { m_Hidden = true; }
void Show() { m_Hidden = false; }
@@ -129,11 +138,6 @@ public:
return Rectangle(left, top, width, height);
}
virtual bool OnKeyDown(const Events::KeyDown &event) { return false; }
virtual bool OnKeyUp(const Events::KeyUp &event) { return false; }
//virtual bool OnMouseDown(const Events::KeyDown &event) { }
//virtual bool OnMouseUp(const Events::KeyDown &event) { }
void UpdateLayered(double dt)
{
if (this->Hidden())
@@ -196,14 +200,22 @@ protected:
typedef std::multimap<std::string, std::shared_ptr<Frame>> Children_t; // name -> frame
std::map<int, Children_t> m_Children; // layer -> Children_t
virtual bool OnKeyDown(const Events::KeyDown &event) { return false; }
virtual bool OnKeyUp(const Events::KeyUp &event) { return false; }
//virtual bool OnMouseDown(const Events::KeyDown &event) { }
//virtual bool OnMouseUp(const Events::KeyDown &event) { }
virtual bool OnCommand(const Events::InputCommand &event) { return false; }
private:
EventRelay<Frame, Events::KeyDown> m_EKeyDown;
EventRelay<Frame, Events::KeyUp> m_EKeyUp;
EventRelay<Frame, Events::InputCommand> m_EInputCommand;
void Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EKeyDown, &Frame::OnKeyDown);
EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &Frame::OnKeyUp);
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &Frame::OnCommand);
}
};
+3 -3
View File
@@ -25,13 +25,13 @@ public:
vp1 = new Viewport(worldFrame, "Viewport1", m_World);
vp1->X = 0;
vp1->Width = this->Width / 2.f;
new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
//new VehicleSelection(vp1, "VehicleSelection", m_World, 1);
//new PlayerHUD(vp1, "PlayerHUD", m_World, 1);
auto vehicleSelection = new VehicleSelection(vp1, "VehicleSelection", m_World, 1);
vp2 = new Viewport(worldFrame, "Viewport2", m_World);
vp2->X = vp1->Right();
vp2->Width = this->Width / 2.f;
new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
//new PlayerHUD(vp2, "PlayerHUD", m_World, 2);
m_FreeCamViewport = new Viewport(worldFrame, "ViewportFreeCam", m_World);
m_FreeCamViewport->Hide();
+72 -27
View File
@@ -3,6 +3,7 @@
#include "GUI/Frame.h"
#include "GUI/HealthOverlay.h"
#include "Events/SpawnVehicle.h"
namespace GUI
{
@@ -37,35 +38,8 @@ namespace GUI
m_Background->SetTexture("Textures/GUI/VehicleSelection/1.png");
}
bool OnKeyUp(const Events::KeyUp &event) override
{
if (event.KeyCode == GLFW_KEY_LEFT)
{
m_CurrentSelection--;
}
else if (event.KeyCode == GLFW_KEY_RIGHT)
{
m_CurrentSelection++;
}
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 3) ? 3 : m_CurrentSelection);
std::stringstream ss;
ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png";
m_Background->FadeToTexture(ss.str(), 1.f);
glm::vec2 scale = Scale();
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f);
glm::vec2 size = m_SelectionSizes[m_CurrentSelection];
m_TargetSize = size * scale;
return true;
}
void Update(double dt) override
{
glm::vec2 posDiff = m_TargetCoordinate - m_CurrentCoordinate;
m_CurrentCoordinate += posDiff * 2.f * (float)dt;
@@ -94,6 +68,77 @@ namespace GUI
float m_CurrentAlpha;
TextureFrame* m_Background;
bool OnCommand(const Events::InputCommand &event) override
{
if (Hidden())
return false;
if (event.PlayerID != m_PlayerID)
return false;
// Menu movement
if (event.Command == "interface_horizontal" || event.Command == "interface_vertical")
{
// Horizontal scrolling
if (event.Command == "interface_horizontal")
{
if (event.Value > 0)
m_CurrentSelection++;
else if (event.Value < 0)
m_CurrentSelection--;
}
// Vertical scrolling to switch between "rows" in an intuitive way
else if (event.Command == "interface_vertical")
{
if (event.Value > 0)
{
if (m_CurrentSelection == 0)
m_CurrentSelection++;
else if (m_CurrentSelection == 3)
m_CurrentSelection--;
}
else if (event.Value < 0)
{
if (m_CurrentSelection == 1)
m_CurrentSelection--;
else if (m_CurrentSelection == 2)
m_CurrentSelection++;
}
}
m_CurrentSelection = (m_CurrentSelection < 0) ? 0 : ((m_CurrentSelection > 3) ? 3 : m_CurrentSelection);
std::stringstream ss;
ss << "Textures/GUI/VehicleSelection/" << m_CurrentSelection + 1 << ".png";
m_Background->FadeToTexture(ss.str(), 1.f);
glm::vec2 scale = Scale();
glm::vec2 coord = -m_SelectionCoordinates[m_CurrentSelection];
m_TargetCoordinate = coord * scale + glm::vec2(Width / 2.f, Height / 2.f);
glm::vec2 size = m_SelectionSizes[m_CurrentSelection];
m_TargetSize = size * scale;
}
// Vehicle select
if (event.Command == "interface_confirm" && event.Value > 0)
{
Events::SpawnVehicle e;
e.PlayerID = m_PlayerID;
if (m_CurrentSelection == 0)
e.VehicleType = "Tank"; // HACK: Base on selected vehicle ID
else if (m_CurrentSelection == 1)
e.VehicleType = "Helicopter";
else if (m_CurrentSelection == 2)
e.VehicleType = "HRSV";
else if (m_CurrentSelection == 3)
e.VehicleType = "Jeep";
EventBroker->Publish(e);
Hide();
}
return true;
}
};
glm::vec2 VehicleSelection::m_SelectionCoordinates[4] = {
+45 -287
View File
@@ -8,6 +8,22 @@ void GameWorld::Initialize()
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj");
ResourceManager->Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj");
// Interface
BindKey(GLFW_KEY_A, "interface_horizontal", -1.f);
BindKey(GLFW_KEY_D, "interface_horizontal", 1.f);
BindGamepadAxis(Gamepad::Axis::LeftX, "interface_horizontal", 1.f);
BindGamepadButton(Gamepad::Button::Left, "interface_horizontal", -1.f);
BindGamepadButton(Gamepad::Button::Right, "interface_horizontal", 1.f);
BindKey(GLFW_KEY_W, "interface_vertical", 1.f);
BindKey(GLFW_KEY_S, "interface_vertical", -1.f);
BindGamepadAxis(Gamepad::Axis::LeftY, "interface_vertical", 1.f);
BindGamepadButton(Gamepad::Button::Up, "interface_vertical", 1.f);
BindGamepadButton(Gamepad::Button::Down, "interface_vertical", -1.f);
BindKey(GLFW_KEY_SPACE, "interface_confirm", 1.f);
BindGamepadButton(Gamepad::Button::A, "interface_confirm", 1.f);
BindKey(GLFW_KEY_W, "vertical", 1.f);
BindKey(GLFW_KEY_S, "vertical", -1.f);
BindKey(GLFW_KEY_A, "horizontal", -1.f);
@@ -28,6 +44,9 @@ void GameWorld::Initialize()
BindKey(GLFW_KEY_Z, "shoot", 1.f);
BindGamepadAxis(Gamepad::Axis::RightTrigger, "shoot", 1.f);
BindKey(GLFW_KEY_X, "use", 1.f);
BindGamepadButton(Gamepad::Button::X, "use", 1.f);
BindMouseButton(GLFW_MOUSE_BUTTON_1, "cam_lock", 1.f);
BindKey(GLFW_KEY_Y, "cam_vertical", 1.f);
BindKey(GLFW_KEY_H, "cam_vertical", -1.f);
@@ -98,17 +117,17 @@ void GameWorld::Initialize()
CommitEntity(ground);
}
EntityID tank1 = CreateTank(1);
/*EntityID tank1 = CreateTank(1);
{
auto transform = GetComponent<Components::Transform>(tank1);
transform->Position.z = -125.f;
transform->Position.y = -20.f;
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
Events::SetViewportCamera e;
e.CameraEntity = GetProperty<EntityID>(tank1, "Camera");
e.ViewportFrame = "Viewport1";
EventBroker->Publish(e);
}
auto transform = GetComponent<Components::Transform>(tank1);
transform->Position.z = -125.f;
transform->Position.y = -20.f;
transform->Orientation = glm::angleAxis(glm::pi<float>(), glm::vec3(0, 1, 0));
Events::SetViewportCamera e;
e.CameraEntity = GetProperty<EntityID>(tank1, "Camera");
e.ViewportFrame = "Viewport1";
EventBroker->Publish(e);
}*/
/*EntityID tank2 = CreateTank(2);
{
@@ -160,6 +179,10 @@ void GameWorld::Initialize()
auto garage = CreateEntity();
auto transform = AddComponent<Components::Transform>(garage);
transform->Position = Position;
auto player = AddComponent<Components::Player>(garage);
player->ID = 1;
auto ElevatorBase = CreateEntity(garage);
{
@@ -266,6 +289,14 @@ void GameWorld::Initialize()
box->Depth = 6.86f;
CommitEntity(shape);
}
auto spawnPoint = CreateEntity(elevator);
{
auto transform = AddComponent<Components::Transform>(spawnPoint);
transform->Position.y = 1.f;
auto spawnPointComponent = AddComponent<Components::SpawnPoint>(spawnPoint);
}
CommitEntity(spawnPoint);
}
CommitEntity(elevator);
@@ -298,16 +329,16 @@ void GameWorld::Initialize()
auto trigger = CreateEntity(garage);
SetProperty(trigger, "Name", "ElevatorShaftTrigger");
auto transform = AddComponent<Components::Transform>(trigger);
transform->Position = glm::vec3(0.69385f, -6.7997f, 2.39938f);
transform->Position = glm::vec3(0.69385f, -6.7997f, -2.0f);
auto triggerComponent = AddComponent<Components::Trigger>(trigger);
{
auto shape = CreateEntity(trigger);
auto transform = AddComponent<Components::Transform>(shape);
transform->Position = glm::vec3(0, 0, 0);
auto box = AddComponent<Components::BoxShape>(shape);
box->Width = 1.0f;
box->Height = 10.f;
box->Depth = 1.0f;
box->Width = 2.0f;
box->Height = 12.f;
box->Depth = 2.0f;
CommitEntity(shape);
}
CommitEntity(trigger);
@@ -548,279 +579,6 @@ void GameWorld::CreateGate(glm::vec3 Position)
}
}
EntityID GameWorld::CreateTank(int playerID)
{
auto tank = CreateEntity();
auto transform = AddComponent<Components::Transform>(tank);
transform->Position = glm::vec3(0, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = AddComponent<Components::Physics>(tank);
physics->Mass = 63000 - 16000;
physics->Static = false;
auto vehicle = AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 8000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
auto player = AddComponent<Components::Player>(tank);
player->ID = playerID;
auto tankSteering = AddComponent<Components::TankSteering>(tank);
AddComponent<Components::Input>(tank);
auto health = AddComponent<Components::Health>(tank);
health->Amount = 100.f;
{
auto shape = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(shape);
auto meshShape = AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Tank/TankCollisionShape.obj";
CommitEntity(shape);
}
{
auto shapeTower = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(shapeTower);
transform->Position = glm::vec3(0, 1.10633f, 1.03024f);
auto box = AddComponent<Components::BoxShape>(shapeTower);
box->Width = 1.298f;
box->Height = 0.502f;
box->Depth = 1.211f;
CommitEntity(shapeTower);
}
{
auto chassis = CreateEntity(tank);
auto transform = AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/tankBody.obj";
}
{
auto tower = CreateEntity(tank);
SetProperty(tower, "Name", "tower");
auto transform = AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 0.68f, 0.9f);
auto model = AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/tankTop.obj";
auto towerSteering = AddComponent<Components::TowerSteering>(tower);
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
towerSteering->TurnSpeed = glm::pi<float>() / 4.f;
{
auto barrel = CreateEntity(tower);
auto transform = AddComponent<Components::Transform>(barrel);
transform->Position = glm::vec3(-0.012f, 0.3f, -0.95);
auto model = AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/tankBarrel.obj";
auto barrelSteering = AddComponent<Components::BarrelSteering>(barrel);
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->TurnSpeed = glm::pi<float>() / 4.f;
barrelSteering->ShotSpeed = 70.f;
barrelSteering->LowerRotationLimit = glm::radians(-10.f);
barrelSteering->UpperRotationLimit = glm::radians(40.f);
{
auto shot = CreateEntity(barrel);
auto transform = AddComponent<Components::Transform>(shot);
transform->Position = glm::vec3(0.35f, 0.f, -2.f);
transform->Orientation = glm::angleAxis(-glm::pi<float>() / 2.f, glm::vec3(1, 0, 0));
transform->Scale = glm::vec3(3.f);
AddComponent<Components::Template>(shot);
auto physics = AddComponent<Components::Physics>(shot);
physics->Mass = 25.f;
physics->Static = false;
physics->CollisionEvent = true;
auto modelComponent = AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
auto tankShellComponent = AddComponent<Components::TankShell>(shot);
tankShellComponent->Damage = 20.f;
tankShellComponent->ExplosionRadius = 30.f;
tankShellComponent->ExplosionStrength = 300000.f;
{
auto shape = CreateEntity(shot);
auto transform = AddComponent<Components::Transform>(shape);
auto boxShape = AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Depth = 0.5f;
CommitEntity(shape);
}
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 follow = AddComponent<Components::Follow>(cameraTower);
follow->Entity = barrel;
follow->Distance = 15.f;
follow->FollowAxis = glm::vec3(1, 1, 1);*/
}
SetProperty(tank, "Camera", cameraTower);
}
CommitEntity(barrel);
tankSteering->Barrel = barrel;
}
CommitEntity(tower);
tankSteering->Turret = tower;
}
//{
// auto lightentity = CreateEntity(tank);
// auto transform = AddComponent<Components::Transform>(lightentity);
// transform->Position = glm::vec3(0, 0, 0);
// auto light = AddComponent<Components::PointLight>(lightentity);
// //light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f);
// //light->Specular = glm::vec3(1.f);
// /*light->ConstantAttenuation = 0.3f;
// light->LinearAttenuation = 0.003f;
// light->QuadraticAttenuation = 0.002f;*/
//}
// auto wheelpair = CreateEntity(tank);
// SetProperty(wheelpair, "Name", "WheelPair");
// AddComponent(wheelpair, "WheelPairThingy");
#pragma region Wheels
//Create wheels
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);
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 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);
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 = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
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 = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
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();
+39 -1
View File
@@ -5,12 +5,14 @@
void Systems::GarageSystem::RegisterComponents( ComponentFactory* cf )
{
cf->Register<Components::Garage>([]() { return new Components::Garage(); });
cf->Register<Components::SpawnPoint>([]() { return new Components::SpawnPoint(); });
}
void Systems::GarageSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_EEnterTrigger, &Systems::GarageSystem::OnEnterTrigger);
EVENT_SUBSCRIBE_MEMBER(m_ELeaveTrigger, &Systems::GarageSystem::OnLeaveTrigger);
EVENT_SUBSCRIBE_MEMBER(m_ECommand, &Systems::GarageSystem::OnCommand);
}
void Systems::GarageSystem::Update(double dt)
@@ -34,11 +36,13 @@ bool Systems::GarageSystem::OnEnterTrigger(const Events::EnterTrigger &event)
std::string name = m_World->GetProperty<std::string>(event.Trigger, "Name");
if (name == "BoundsTrigger" || name == "ElevatorShaftTrigger")
if (name == "BoundsTrigger")
{
ToggleGarage(garageComponent);
}
m_EntitiesInTrigger[event.Trigger].insert(event.Entity);
return true;
}
@@ -59,6 +63,40 @@ bool Systems::GarageSystem::OnLeaveTrigger(const Events::LeaveTrigger &event)
ToggleGarage(garageComponent);
}
m_EntitiesInTrigger[event.Trigger].erase(event.Entity);
return true;
}
bool Systems::GarageSystem::OnCommand(const Events::InputCommand &event)
{
if (event.Command == "use" && event.Value > 0)
{
for (auto &pair : m_EntitiesInTrigger)
{
EntityID trigger = pair.first;
auto entities = pair.second;
std::string name = m_World->GetProperty<std::string>(trigger, "Name");
if (name != "ElevatorShaftTrigger")
continue;
auto triggerBaseParent = m_World->GetEntityBaseParent(trigger);
auto triggerPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
for (EntityID entity : entities)
{
auto entityPlayerComponent = m_World->GetComponent<Components::Player>(triggerBaseParent);
if (triggerPlayerComponent == entityPlayerComponent)
{
EntityID garage = m_World->GetEntityParent(trigger);
auto garageComponent = m_World->GetComponent<Components::Garage>(garage);
ToggleGarage(garageComponent);
}
}
}
}
return true;
}
+9
View File
@@ -1,13 +1,17 @@
#ifndef GarageSystem_h__
#define GarageSystem_h__
#include <set>
#include "System.h"
#include "Components/Transform.h"
#include "Components/Trigger.h"
#include "Components/Garage.h"
#include "Components/SpawnPoint.h"
#include "Events/EnterTrigger.h"
#include "Events/LeaveTrigger.h"
#include "Events/SpawnVehicle.h"
#include "Events/InputCommand.h"
#include "Components/Player.h"
#include "Events/Move.h"
@@ -30,12 +34,17 @@ namespace Systems
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
std::map<EntityID, std::set<EntityID>> m_EntitiesInTrigger;
EventRelay<GarageSystem, Events::EnterTrigger> m_EEnterTrigger;
bool OnEnterTrigger(const Events::EnterTrigger &event);
EventRelay<GarageSystem, Events::LeaveTrigger> m_ELeaveTrigger;
bool OnLeaveTrigger(const Events::LeaveTrigger &event);
EventRelay<GarageSystem, Events::InputCommand> m_ECommand;
bool OnCommand(const Events::InputCommand &event);
void ToggleGarage(Components::Garage* garageComponent);
};
}
+30 -47
View File
@@ -46,8 +46,8 @@ void Systems::InputSystem::Update(double dt)
bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
{
auto bindingIt = m_KeyBindings.find(event.KeyCode);
if (bindingIt != m_KeyBindings.end())
auto range = m_KeyBindings.equal_range(event.KeyCode);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -61,8 +61,8 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event)
bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
{
auto bindingIt = m_KeyBindings.find(event.KeyCode);
if (bindingIt != m_KeyBindings.end())
auto range = m_KeyBindings.equal_range(event.KeyCode);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -76,8 +76,8 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event)
bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
{
auto bindingIt = m_MouseButtonBindings.find(event.Button);
if (bindingIt != m_MouseButtonBindings.end())
auto range = m_MouseButtonBindings.equal_range(event.Button);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -91,8 +91,8 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event)
bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
{
auto bindingIt = m_MouseButtonBindings.find(event.Button);
if (bindingIt != m_MouseButtonBindings.end())
auto range = m_MouseButtonBindings.equal_range(event.Button);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -106,8 +106,8 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event)
bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
{
auto bindingIt = m_GamepadAxisBindings.find(event.Axis);
if (bindingIt != m_GamepadAxisBindings.end())
auto range = m_GamepadAxisBindings.equal_range(event.Axis);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -121,8 +121,8 @@ bool Systems::InputSystem::OnGamepadAxis(const Events::GamepadAxis &event)
bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &event)
{
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
if (bindingIt != m_GamepadButtonBindings.end())
auto range = m_GamepadButtonBindings.equal_range(event.Button);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -136,8 +136,8 @@ bool Systems::InputSystem::OnGamepadButtonDown(const Events::GamepadButtonDown &
bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &event)
{
auto bindingIt = m_GamepadButtonBindings.find(event.Button);
if (bindingIt != m_GamepadButtonBindings.end())
auto range = m_GamepadButtonBindings.equal_range(event.Button);
for (auto bindingIt = range.first; bindingIt != range.second; bindingIt++)
{
std::string command;
float value;
@@ -149,18 +149,13 @@ bool Systems::InputSystem::OnGamepadButtonUp(const Events::GamepadButtonUp &even
return true;
}
bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
{
if (event.Command.empty())
{
m_KeyBindings.erase(event.KeyCode);
}
else
{
m_KeyBindings[event.KeyCode] = std::make_tuple(event.Command, event.Value);
LOG_DEBUG("Input: Bound key %i:%c to %s", event.KeyCode, (char)event.KeyCode, event.Command.c_str());
}
return false;
m_KeyBindings.insert(std::make_pair(event.KeyCode, std::make_tuple(event.Command, event.Value)));
LOG_DEBUG("Input: Bound key %i to %s", event.KeyCode, event.Command.c_str());
return true;
}
@@ -168,14 +163,10 @@ bool Systems::InputSystem::OnBindKey(const Events::BindKey &event)
bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &event)
{
if (event.Command.empty())
{
m_MouseButtonBindings.erase(event.Button);
}
else
{
m_MouseButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
}
return false;
m_MouseButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value)));
LOG_DEBUG("Input: Bound mouse button %i to %s", event.Button, event.Command.c_str());
return true;
}
@@ -183,14 +174,10 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even
bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &event)
{
if (event.Command.empty())
{
m_GamepadAxisBindings.erase(event.Axis);
}
else
{
m_GamepadAxisBindings[event.Axis] = std::make_tuple(event.Command, event.Value);
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
}
return false;
m_GamepadAxisBindings.insert(std::make_pair(event.Axis, std::make_tuple(event.Command, event.Value)));
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Axis, event.Command.c_str());
return true;
}
@@ -198,14 +185,10 @@ bool Systems::InputSystem::OnBindGamepadAxis(const Events::BindGamepadAxis &even
bool Systems::InputSystem::OnBindGamepadButton(const Events::BindGamepadButton &event)
{
if (event.Command.empty())
{
m_GamepadButtonBindings.erase(event.Button);
}
else
{
m_GamepadButtonBindings[event.Button] = std::make_tuple(event.Command, event.Value);
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
}
return false;
m_GamepadButtonBindings.insert(std::make_pair(event.Button, std::make_tuple(event.Command, event.Value)));
LOG_DEBUG("Input: Bound gamepad axis %i to %s", event.Button, event.Command.c_str());
return true;
}
+4 -4
View File
@@ -40,10 +40,10 @@ private:
std::unordered_map<std::string, std::unordered_map<Gamepad::Axis, float>> m_CommandGamepadAxisValues; // command string -> gamepad axis value for command
std::unordered_map<std::string, std::unordered_map<Gamepad::Button, float>> m_CommandGamepadButtonValues; // command string -> gamepad button value for command
// Input binding tables
std::unordered_map<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
std::unordered_map<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
std::unordered_map<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
std::unordered_map<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
std::unordered_multimap<int, std::tuple<std::string, float>> m_KeyBindings; // GLFW_KEY... -> command string & value
std::unordered_multimap<int, std::tuple<std::string, float>> m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string
std::unordered_multimap<Gamepad::Axis, std::tuple<std::string, float>> m_GamepadAxisBindings; // Gamepad::Axis -> command string & value
std::unordered_multimap<Gamepad::Button, std::tuple<std::string, float>> m_GamepadButtonBindings; // Gamepad::Button -> command string
// Input events
EventRelay<InputSystem, Events::KeyDown> m_EKeyDown;
+310 -4
View File
@@ -2,7 +2,7 @@
#include "TankSteeringSystem.h"
#include "World.h"
void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
void Systems::TankSteeringSystem::RegisterComponents(ComponentFactory* cf)
{
cf->Register<Components::TankSteering>([]() { return new Components::TankSteering(); });
cf->Register<Components::TowerSteering>([]() { return new Components::TowerSteering(); });
@@ -12,6 +12,7 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf )
void Systems::TankSteeringSystem::Initialize()
{
EVENT_SUBSCRIBE_MEMBER(m_ECollision, &Systems::TankSteeringSystem::OnCollision);
EVENT_SUBSCRIBE_MEMBER(m_ESpawnVehicle, &Systems::TankSteeringSystem::OnSpawnVehicle);
for (int i = 0; i < 4; i++)
{
@@ -110,7 +111,7 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit
}
}
bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
bool Systems::TankSteeringSystem::OnCollision(const Events::Collision &e)
{
if(m_World->ValidEntity(e.Entity1) && m_World->ValidEntity(e.Entity2))
{
@@ -251,6 +252,313 @@ bool Systems::TankSteeringSystem::OnCollision( const Events::Collision &e )
return true;
}
bool Systems::TankSteeringSystem::OnSpawnVehicle(const Events::SpawnVehicle &event)
{
if (event.VehicleType != "Tank")
return false;
auto spawnPointComponents = m_World->GetComponentsOfType<Components::SpawnPoint>();
for (auto &spawnPointComponent : *spawnPointComponents)
{
auto spawnPoint = spawnPointComponent->Entity;
auto spawnPointBaseParent = m_World->GetEntityBaseParent(spawnPoint);
auto playerComponent = m_World->GetComponent<Components::Player>(spawnPointBaseParent);
if (!playerComponent || playerComponent->ID != event.PlayerID)
continue;
Components::Transform absoluteTransform = m_World->GetSystem<Systems::TransformSystem>()->AbsoluteTransform(spawnPoint);
// Create a tank
EntityID tank = CreateTank(event.PlayerID);
auto tankTransform = m_World->GetComponent<Components::Transform>(tank);
tankTransform->Position = absoluteTransform.Position;
tankTransform->Orientation = absoluteTransform.Orientation;
// Set the viewport correctly
Events::SetViewportCamera e;
e.CameraEntity = m_World->GetProperty<EntityID>(tank, "Camera");
if (event.PlayerID == 1)
e.ViewportFrame = "Viewport1";
else if (event.PlayerID == 2)
e.ViewportFrame = "Viewport2";
EventBroker->Publish(e);
}
return true;
}
EntityID Systems::TankSteeringSystem::CreateTank(int playerID)
{
auto tank = m_World->CreateEntity();
auto transform = m_World->AddComponent<Components::Transform>(tank);
transform->Position = glm::vec3(0, 5, 0);
//transform->Orientation = glm::angleAxis(0.f, glm::vec3(0, 1, 0));
auto physics = m_World->AddComponent<Components::Physics>(tank);
physics->Mass = 63000 - 16000;
physics->Static = false;
auto vehicle = m_World->AddComponent<Components::Vehicle>(tank);
vehicle->MaxTorque = 8000.f;
vehicle->MaxSteeringAngle = 90.f;
vehicle->MaxSpeedFullSteeringAngle = 4.f;
auto player = m_World->AddComponent<Components::Player>(tank);
player->ID = playerID;
auto tankSteering = m_World->AddComponent<Components::TankSteering>(tank);
m_World->AddComponent<Components::Input>(tank);
auto health = m_World->AddComponent<Components::Health>(tank);
health->Amount = 100.f;
{
auto shape = m_World->CreateEntity(tank);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto meshShape = m_World->AddComponent<Components::MeshShape>(shape);
meshShape->ResourceName = "Models/Tank/TankCollisionShape.obj";
m_World->CommitEntity(shape);
}
{
auto shapeTower = m_World->CreateEntity(tank);
auto transform = m_World->AddComponent<Components::Transform>(shapeTower);
transform->Position = glm::vec3(0, 1.10633f, 1.03024f);
auto box = m_World->AddComponent<Components::BoxShape>(shapeTower);
box->Width = 1.298f;
box->Height = 0.502f;
box->Depth = 1.211f;
m_World->CommitEntity(shapeTower);
}
{
auto chassis = m_World->CreateEntity(tank);
auto transform = m_World->AddComponent<Components::Transform>(chassis);
transform->Position = glm::vec3(0, 0, 0);
auto model = m_World->AddComponent<Components::Model>(chassis);
model->ModelFile = "Models/Tank/tankBody.obj";
}
{
auto tower = m_World->CreateEntity(tank);
m_World->SetProperty(tower, "Name", "tower");
auto transform = m_World->AddComponent<Components::Transform>(tower);
transform->Position = glm::vec3(0.f, 0.68f, 0.9f);
auto model = m_World->AddComponent<Components::Model>(tower);
model->ModelFile = "Models/Tank/tankTop.obj";
auto towerSteering = m_World->AddComponent<Components::TowerSteering>(tower);
towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f);
towerSteering->TurnSpeed = glm::pi<float>() / 4.f;
{
auto barrel = m_World->CreateEntity(tower);
auto transform = m_World->AddComponent<Components::Transform>(barrel);
transform->Position = glm::vec3(-0.012f, 0.3f, -0.95);
auto model = m_World->AddComponent<Components::Model>(barrel);
model->ModelFile = "Models/Tank/tankBarrel.obj";
auto barrelSteering = m_World->AddComponent<Components::BarrelSteering>(barrel);
barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f);
barrelSteering->TurnSpeed = glm::pi<float>() / 4.f;
barrelSteering->ShotSpeed = 70.f;
barrelSteering->LowerRotationLimit = glm::radians(-10.f);
barrelSteering->UpperRotationLimit = glm::radians(40.f);
{
auto shot = m_World->CreateEntity(barrel);
auto transform = m_World->AddComponent<Components::Transform>(shot);
transform->Position = glm::vec3(0.35f, 0.f, -2.f);
transform->Orientation = glm::angleAxis(-glm::pi<float>() / 2.f, glm::vec3(1, 0, 0));
transform->Scale = glm::vec3(3.f);
m_World->AddComponent<Components::Template>(shot);
auto physics = m_World->AddComponent<Components::Physics>(shot);
physics->Mass = 25.f;
physics->Static = false;
physics->CollisionEvent = true;
auto modelComponent = m_World->AddComponent<Components::Model>(shot);
modelComponent->ModelFile = "Models/Placeholders/rocket/Rocket.obj";
auto tankShellComponent = m_World->AddComponent<Components::TankShell>(shot);
tankShellComponent->Damage = 20.f;
tankShellComponent->ExplosionRadius = 30.f;
tankShellComponent->ExplosionStrength = 300000.f;
{
auto shape = m_World->CreateEntity(shot);
auto transform = m_World->AddComponent<Components::Transform>(shape);
auto boxShape = m_World->AddComponent<Components::BoxShape>(shape);
boxShape->Width = 0.5f;
boxShape->Height = 0.5f;
boxShape->Depth = 0.5f;
m_World->CommitEntity(shape);
}
m_World->CommitEntity(shot);
barrelSteering->ShotTemplate = shot;
auto cameraTower = m_World->CreateEntity(barrel);
{
auto transform = m_World->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 = m_World->AddComponent<Components::Camera>(cameraTower);
cameraComp->FarClip = 2000.f;
/*auto follow = m_World->AddComponent<Components::Follow>(cameraTower);
follow->Entity = barrel;
follow->Distance = 15.f;
follow->FollowAxis = glm::vec3(1, 1, 1);*/
}
m_World->SetProperty(tank, "Camera", cameraTower);
}
m_World->CommitEntity(barrel);
tankSteering->Barrel = barrel;
}
m_World->CommitEntity(tower);
tankSteering->Turret = tower;
}
//{
// auto lightentity = m_World->CreateEntity(tank);
// auto transform = m_World->AddComponent<Components::Transform>(lightentity);
// transform->Position = glm::vec3(0, 0, 0);
// auto light = m_World->AddComponent<Components::PointLight>(lightentity);
// //light->Diffuse = glm::vec3(128.f/255.f, 172.f/255.f, 242.f/255.f);
// //light->Specular = glm::vec3(1.f);
// /*light->ConstantAttenuation = 0.3f;
// light->LinearAttenuation = 0.003f;
// light->QuadraticAttenuation = 0.002f;*/
//}
// auto wheelpair = m_World->CreateEntity(tank);
// SetProperty(wheelpair, "Name", "WheelPair");
// AddComponent(wheelpair, "WheelPairThingy");
#pragma region Wheels
//Create wheels
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 = m_World->CreateEntity(tank);
auto transformComponent = m_World->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 = m_World->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));
m_World->CommitEntity(entity);
auto particleEntity = m_World->CreateEntity(entity);
auto TEMP = m_World->AddComponent<Components::Transform>(particleEntity);
TEMP->Scale = glm::vec3(0);
auto spriteComponent = m_World->AddComponent<Components::Sprite>(particleEntity);
spriteComponent->SpriteFile = "Models/Textures/Sprites/Dust.png";
emitterComponent->ParticleTemplate = particleEntity;
m_World->CommitEntity(particleEntity);
}
m_World->CommitEntity(tank);
return tank;
}
void Systems::TankSteeringSystem::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 = m_World->CreateEntity(tankEntity);
{
auto transform = m_World->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 = m_World->AddComponent<Components::Model>(wheelFront);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
#endif
auto Wheel = m_World->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 = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
m_World->CommitEntity(wheelFront);
}
auto wheelBack = m_World->CreateEntity(tankEntity);
{
auto transform = m_World->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 = m_World->AddComponent<Components::Model>(wheelBack);
model->ModelFile = "Models/Tank/Fix/WheelPhysics.obj";
#endif
auto Wheel = m_World->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 = 4.f;
Wheel->ConnectedToHandbrake = true;
Wheel->TorqueRatio = 0.125f;
Wheel->Width = 0.6f;
m_World->CommitEntity(wheelBack);
}
auto wheelPair = m_World->CreateEntity(tankEntity);
{
{
auto transform = m_World->AddComponent<Components::Transform>(wheelPair);
transform->Position = position;
//transform->Orientation = glm::quat(glm::vec3(0, glm::pi<float>() / 4.f, 0));
auto pair = m_World->AddComponent<Components::WheelPair>(wheelPair);
pair->FakeWheelFront = wheelFront;
pair->FakeWheelBack = wheelBack;
}
auto modelEntity = m_World->CreateEntity(wheelPair);
{
auto transform = m_World->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 = m_World->AddComponent<Components::Model>(modelEntity);
model->ModelFile = "Models/Tank/tankWheel.obj";
}
m_World->CommitEntity(modelEntity);
}
m_World->CommitEntity(wheelPair);
}
void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt )
{
PositionX = m_Horizontal;
@@ -315,5 +623,3 @@ bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const E
return true;
}
+18 -1
View File
@@ -32,6 +32,18 @@
#include "Components/Vehicle.h"
#include "Components/Player.h"
#include "Events/SpawnVehicle.h"
#include "Components/SpawnPoint.h"
#include "Components/Wheel.h"
#include "Components/MeshShape.h"
#include "Components/Camera.h"
#include "Components/BoxShape.h"
#include "Components/WheelPair.h"
#include "Components/Input.h"
#include "Events/SetViewportCamera.h"
namespace Systems
{
@@ -49,13 +61,18 @@ namespace Systems
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
private:
std::map<EntityID, double> m_TimeSinceLastShot;
EventRelay<TankSteeringSystem, Events::Collision> m_ECollision;
bool OnCollision(const Events::Collision &e);
EventRelay<TankSteeringSystem, Events::SpawnVehicle> m_ESpawnVehicle;
bool OnSpawnVehicle(const Events::SpawnVehicle &e);
class TankSteeringInputController;
std::array<std::shared_ptr<TankSteeringInputController>, 4> m_TankInputControllers;
std::map<EntityID, double> m_TimeSinceLastShot;
EntityID CreateTank(int playerID);
void AddTankWheelPair(EntityID tankEntity, glm::vec3 position, int axleID, bool front);
};
class TankSteeringSystem::TankSteeringInputController : InputController<TankSteeringSystem>
+2
View File
@@ -170,6 +170,7 @@
<ClInclude Include="..\..\src\Components\Trigger.h" />
<ClInclude Include="..\..\src\Components\TriggerRotate.h" />
<ClInclude Include="..\..\src\Components\Vehicle.h" />
<ClInclude Include="..\..\src\Components\SpawnPoint.h" />
<ClInclude Include="..\..\src\Components\Viewport.h" />
<ClInclude Include="..\..\src\Components\Wheel.h" />
<ClInclude Include="..\..\src\Components\WheelPair.h" />
@@ -203,6 +204,7 @@
<ClInclude Include="..\..\src\Events\Rotate.h" />
<ClInclude Include="..\..\src\Events\SetVelocity.h" />
<ClInclude Include="..\..\src\Events\SetViewportCamera.h" />
<ClInclude Include="..\..\src\Events\SpawnVehicle.h" />
<ClInclude Include="..\..\src\Events\StopSound.h" />
<ClInclude Include="..\..\src\Events\TankSteer.h" />
<ClInclude Include="..\..\src\Events\EnterTrigger.h" />
@@ -184,8 +184,7 @@
</Filter>
<Filter Include="Game\Systems">
<UniqueIdentifier>{3c2ea0e5-41a1-4b11-a891-1d59ead7223c}</UniqueIdentifier>
</Filter>
</Filter>
<Filter Include="Base\Events">
<UniqueIdentifier>{3cbe68d9-2446-45ee-8637-ffb805997dcd}</UniqueIdentifier>
</Filter>
@@ -545,6 +544,12 @@
<ClInclude Include="..\..\src\GUI\VehicleSelection.h">
<Filter>GUI</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Events\SpawnVehicle.h">
<Filter>Game\Events</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\SpawnPoint.h">
<Filter>Game\Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\Fragment2.glsl">