From 38482431a1b07a79d2483862b3defdb4a5773cf6 Mon Sep 17 00:00:00 2001 From: ViktorLjung Date: Mon, 12 May 2014 22:33:53 +0200 Subject: [PATCH] Tank tower and barrel steering working --- src/Components/BarrelSteering.h | 20 ++++ src/Components/TowerSteering.h | 20 ++++ src/Components/Vehicle.h | 3 +- src/Events/BindKey.h | 3 + src/Events/InputCommand.h | 2 +- src/GameWorld.cpp | 73 ++++++++----- src/GameWorld.h | 6 +- src/Physics/VehicleSetup.cpp | 9 +- src/Systems/InputSystem.cpp | 27 +++-- src/Systems/InputSystem.h | 6 +- src/Systems/PhysicsSystem.cpp | 11 +- src/Systems/PhysicsSystem.h | 1 + src/Systems/TankSteeringSystem.cpp | 103 +++++++++++------- src/Systems/TankSteeringSystem.h | 45 +++++++- src/World.h | 5 + vs11/Returngeance/Returngeance.vcxproj | 2 + .../Returngeance/Returngeance.vcxproj.filters | 6 + 17 files changed, 246 insertions(+), 96 deletions(-) create mode 100644 src/Components/BarrelSteering.h create mode 100644 src/Components/TowerSteering.h diff --git a/src/Components/BarrelSteering.h b/src/Components/BarrelSteering.h new file mode 100644 index 0000000..58ab2fa --- /dev/null +++ b/src/Components/BarrelSteering.h @@ -0,0 +1,20 @@ +#ifndef BarrelSteering_h__ +#define BarrelSteering_h__ + +#include "Component.h" + +namespace Components +{ + + struct BarrelSteering : Component + { + BarrelSteering() + : Velocity(1.f), Axis(glm::vec3(0,1,0)){ } + + float Velocity; + glm::vec3 Axis; + }; + +} + +#endif // BarrelSteering_h__ \ No newline at end of file diff --git a/src/Components/TowerSteering.h b/src/Components/TowerSteering.h new file mode 100644 index 0000000..38a2320 --- /dev/null +++ b/src/Components/TowerSteering.h @@ -0,0 +1,20 @@ +#ifndef TowerSteering_h__ +#define TowerSteering_h__ + +#include "Component.h" + + namespace Components +{ + +struct TowerSteering : Component +{ + TowerSteering() + : Velocity(1.f), Axis(glm::vec3(0,1,0)){ } + + float Velocity; + glm::vec3 Axis; +}; + +} + +#endif // TowerSteering_h__ \ No newline at end of file diff --git a/src/Components/Vehicle.h b/src/Components/Vehicle.h index 388d9f2..6522a1f 100644 --- a/src/Components/Vehicle.h +++ b/src/Components/Vehicle.h @@ -11,7 +11,7 @@ struct Vehicle : Component { Vehicle() : MaxTorque(1000.0f), MinRPM(1000.0f), OptimalRPM(3000.0f), MaxRPM(4000.0f), MaxSteeringAngle(35), TopSpeed(130.0f), - MaxSpeedFullSteeringAngle(40.0f){ } + MaxSpeedFullSteeringAngle(40.0f), SpringDamping(1.f){ } float MaxTorque; float MinRPM; @@ -22,6 +22,7 @@ struct Vehicle : Component //TopSpeed not working fully yet float TopSpeed; float MaxSpeedFullSteeringAngle; + float SpringDamping; }; } diff --git a/src/Events/BindKey.h b/src/Events/BindKey.h index a774942..17c786f 100644 --- a/src/Events/BindKey.h +++ b/src/Events/BindKey.h @@ -1,6 +1,8 @@ #ifndef Events_BindKey_h__ #define Events_BindKey_h__ +#include + #include "EventBroker.h" namespace Events @@ -10,6 +12,7 @@ struct BindKey : Event { int KeyCode; std::string Command; + float Value; }; } diff --git a/src/Events/InputCommand.h b/src/Events/InputCommand.h index bd18f6a..cde1dab 100644 --- a/src/Events/InputCommand.h +++ b/src/Events/InputCommand.h @@ -12,7 +12,7 @@ struct InputCommand : Event { unsigned int PlayerID; std::string Command; - boost::any Value; + float Value; }; } diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 979376b..2d743f9 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -8,11 +8,25 @@ void GameWorld::Initialize() m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/Plane.obj"); m_ResourceManager.Preload("Model", "Models/Placeholders/PhysicsTest/ArrowCube.obj"); - BindKey(GLFW_KEY_W, "+forward"); - BindKey(GLFW_KEY_S, "+backward"); - BindKey(GLFW_KEY_A, "+left"); - BindKey(GLFW_KEY_D, "+right"); - BindKey(GLFW_KEY_SPACE, "+handbrake"); + BindKey(GLFW_KEY_W, "vertical", -1.f); + BindKey(GLFW_KEY_S, "vertical", 1.f); + BindKey(GLFW_KEY_A, "horizontal", -1.f); + BindKey(GLFW_KEY_D, "horizontal", 1.f); + + BindKey(GLFW_KEY_UP, "barrel_rotation", 1.f); + BindKey(GLFW_KEY_DOWN, "barrel_rotation", -1.f); + BindKey(GLFW_KEY_LEFT, "tower_rotation", 1.f); + BindKey(GLFW_KEY_RIGHT, "tower_rotation", -1.f); + + BindKey(GLFW_KEY_SPACE, "handbrake", 1.f); +// +// BindKey(GLFW_KEY_UP, "vertical", -1.f); +// BindKey(GLFW_KEY_DOWN, "vertical", 1.f); +// BindKey(GLFW_KEY_LEFT, "horizontal", -1.f); +// BindKey(GLFW_KEY_RIGHT, "horizontal", 1.f); + /* + BindKey(GLFW_KEY_Q, "+tower_right"); + BindKey(GLFW_KEY_E, "+tower_left"); BindKey(GLFW_KEY_Q, "+up"); BindKey(GLFW_KEY_LEFT_CONTROL, "+down"); @@ -25,8 +39,8 @@ void GameWorld::Initialize() BindKey(GLFW_KEY_UP, "+cam_forward"); BindKey(GLFW_KEY_DOWN, "+cam_backward"); - BindKey(GLFW_KEY_LEFT, "+cam_right"); - BindKey(GLFW_KEY_RIGHT, "+cam_left"); + BindKey(GLFW_KEY_LEFT, "+cam_left"); + BindKey(GLFW_KEY_RIGHT, "+cam_right");*/ RegisterComponents(); @@ -242,23 +256,29 @@ void GameWorld::Initialize() { auto chassis = CreateEntity(tank); auto transform = AddComponent(chassis, "Transform"); - transform->Position = glm::vec3(0, 0, 0); // 0.6577f + transform->Position = glm::vec3(0, 0, 0); auto model = AddComponent(chassis, "Model"); model->ModelFile = "Models/Tank/Fix/Chassi.obj"; } { - auto top = CreateEntity(tank); - auto transform = AddComponent(top, "Transform"); - transform->Position = glm::vec3(0, 1.2, 1.95); // 0.6577f - auto model = AddComponent(top, "Model"); + auto tower = CreateEntity(tank); + SetProperty(tower, "Name", "tower"); + auto transform = AddComponent(tower, "Transform"); + transform->Position = glm::vec3(0, 1.2, 1.95); + auto model = AddComponent(tower, "Model"); model->ModelFile = "Models/Tank/Fix/Top.obj"; - + auto towerSteering = AddComponent(tower, "TowerSteering"); + towerSteering->Axis = glm::vec3(0.f, 1.f, 0.f); + towerSteering->Velocity = glm::pi()/4.f; { - auto top = CreateEntity(tank); - auto transform = AddComponent(top, "Transform"); - transform->Position = glm::vec3(0, 1, 0.5); // 0.6577f - auto model = AddComponent(top, "Model"); + auto barrel = CreateEntity(tower); + auto transform = AddComponent(barrel, "Transform"); + transform->Position = glm::vec3(0, 0, -2.f); + auto model = AddComponent(barrel, "Model"); model->ModelFile = "Models/Tank/Fix/Barrel.obj"; + auto barrelSteering = AddComponent(barrel, "BarrelSteering"); + barrelSteering->Axis = glm::vec3(1.f, 0.f, 0.f); + barrelSteering->Velocity = glm::pi()/4.f; } } @@ -297,7 +317,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -316,7 +336,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -336,7 +356,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = true; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -355,7 +375,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -376,7 +396,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -394,7 +414,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -414,7 +434,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -432,7 +452,7 @@ void GameWorld::Initialize() Wheel->Radius = 0.6f; Wheel->Steering = false; Wheel->SuspensionStrength = suspensionStrength; - Wheel->Friction = 3.f; + Wheel->Friction = 4.f; Wheel->ConnectedToHandbrake = true; Wheel->TorqueRatio = 0.125f; CommitEntity(wheel); @@ -573,11 +593,12 @@ void GameWorld::AddSystems() AddSystem("RenderSystem"); } -void GameWorld::BindKey(int keyCode, std::string command) +void GameWorld::BindKey(int keyCode, std::string command, float value) { Events::BindKey e; e.KeyCode = keyCode; e.Command = command; + e.Value = value; m_EventBroker->Publish(e); } diff --git a/src/GameWorld.h b/src/GameWorld.h index 6e9c9e4..2dfcb96 100755 --- a/src/GameWorld.h +++ b/src/GameWorld.h @@ -34,6 +34,10 @@ #include "Components/Vehicle.h" #include "Components/Wheel.h" #include "Components/HingeConstraint.h" +#include "Components/TankSteering.h" +#include "Components/TowerSteering.h" +#include "Components/BarrelSteering.h" + class GameWorld : public World { @@ -52,7 +56,7 @@ public: private: std::shared_ptr m_Renderer; - void BindKey(int keyCode, std::string command); + void BindKey(int keyCode, std::string command, float value); void BindMouseButton(int button, std::string command); }; diff --git a/src/Physics/VehicleSetup.cpp b/src/Physics/VehicleSetup.cpp index 1babfcb..90e65dc 100644 --- a/src/Physics/VehicleSetup.cpp +++ b/src/Physics/VehicleSetup.cpp @@ -104,7 +104,7 @@ void VehicleSetup::setupVehicleData(const hkpWorld* world, hkpVehicleData& data data.m_torquePitchFactor = 0.5f; data.m_torqueYawFactor = 0.35f; - data.m_chassisUnitInertiaYaw = 1.0f; + data.m_chassisUnitInertiaYaw = 0.8f; data.m_chassisUnitInertiaRoll = 1.0f; data.m_chassisUnitInertiaPitch = 1.0f; @@ -246,9 +246,8 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultS suspension.m_wheelParams[i].m_length = suspensionLength; suspension.m_wheelSpringParams[i].m_strength = m_Wheels[i].WheelComponent->SuspensionStrength; - const float wd = 3.0f; - suspension.m_wheelSpringParams[i].m_dampingCompression = wd; - suspension.m_wheelSpringParams[i].m_dampingRelaxation = wd; + suspension.m_wheelSpringParams[i].m_dampingCompression = vehicleComponent.SpringDamping; + suspension.m_wheelSpringParams[i].m_dampingRelaxation = vehicleComponent.SpringDamping; suspension.m_wheelParams[i].m_hardpointChassisSpace.set(m_Wheels[i].WheelComponent->Hardpoint.x, m_Wheels[i].WheelComponent->Hardpoint.y, m_Wheels[i].WheelComponent->Hardpoint.z); @@ -285,7 +284,7 @@ void VehicleSetup::setupComponent(const hkpVehicleData& data, hkpVehicleDefaultV // The threshold in m/s at which the algorithm switches from // using the normalSpinDamping to the collisionSpinDamping. - velocityDamper.m_collisionThreshold = 100.0f; + velocityDamper.m_collisionThreshold = 1.0f; } void VehicleSetup::setupWheelCollide(const hkpWorld* world, const hkpVehicleInstance& vehicle, hkpVehicleRayCastWheelCollide& wheelCollide) diff --git a/src/Systems/InputSystem.cpp b/src/Systems/InputSystem.cpp index 18a21aa..4868213 100755 --- a/src/Systems/InputSystem.cpp +++ b/src/Systems/InputSystem.cpp @@ -44,7 +44,11 @@ bool Systems::InputSystem::OnKeyDown(const Events::KeyDown &event) auto bindingIt = m_KeyBindings.find(event.KeyCode); if (bindingIt != m_KeyBindings.end()) { - PublishCommand(0, bindingIt->second, 1.f, false); + std::string command; + float value; + std::tie(command, value) = bindingIt->second; + m_KeyBindingValues[command] += value; + PublishCommand(0, command, std::max(-1.f, std::min(m_KeyBindingValues[command], 1.f))); } return true; @@ -55,7 +59,11 @@ bool Systems::InputSystem::OnKeyUp(const Events::KeyUp &event) auto bindingIt = m_KeyBindings.find(event.KeyCode); if (bindingIt != m_KeyBindings.end()) { - PublishCommand(0, bindingIt->second, 1.f, true); + std::string command; + float value; + std::tie(command, value) = bindingIt->second; + m_KeyBindingValues[command] -= value; + PublishCommand(0, command, std::max(-1.f, std::min(m_KeyBindingValues[command], 1.f))); } return true; @@ -66,7 +74,7 @@ bool Systems::InputSystem::OnMousePress(const Events::MousePress &event) auto bindingIt = m_MouseButtonBindings.find(event.Button); if (bindingIt != m_MouseButtonBindings.end()) { - PublishCommand(0, bindingIt->second, 1.f, false); + PublishCommand(0, bindingIt->second, 1.f); } return true; @@ -77,7 +85,7 @@ bool Systems::InputSystem::OnMouseRelease(const Events::MouseRelease &event) auto bindingIt = m_MouseButtonBindings.find(event.Button); if (bindingIt != m_MouseButtonBindings.end()) { - PublishCommand(0, bindingIt->second, 1.f, true); + PublishCommand(0, bindingIt->second, 1.f); } return true; @@ -91,7 +99,7 @@ bool Systems::InputSystem::OnBindKey(const Events::BindKey &event) } else { - m_KeyBindings[event.KeyCode] = event.Command; + m_KeyBindings[event.KeyCode] = std::make_tuple(event.Command, event.Value); LOG_DEBUG("Input: Bound key %c to %s", (char)event.KeyCode, event.Command.c_str()); } @@ -113,18 +121,13 @@ bool Systems::InputSystem::OnBindMouseButton(const Events::BindMouseButton &even return true; } -void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value, bool release /*= false*/) +void Systems::InputSystem::PublishCommand(int playerID, std::string command, float value) { - if (release && command.at(0) == '+') - { - command[0] = '-'; - } - Events::InputCommand e; e.PlayerID = playerID; e.Command = command; e.Value = value; EventBroker->Publish(e); - LOG_DEBUG("Input: Published command %s for player %i", e.Command.c_str(), playerID); + LOG_DEBUG("Input: Published command %s=%f for player %i", e.Command.c_str(), e.Value, playerID); } diff --git a/src/Systems/InputSystem.h b/src/Systems/InputSystem.h index f912de0..b9461a2 100755 --- a/src/Systems/InputSystem.h +++ b/src/Systems/InputSystem.h @@ -3,6 +3,7 @@ #include #include +#include #include "System.h" #include "Components/Input.h" @@ -30,7 +31,8 @@ public: private: // Input binding tables - std::unordered_map m_KeyBindings; // GLFW_KEY... -> command string + std::unordered_map> m_KeyBindings; // GLFW_KEY... -> command string & value + std::unordered_map m_KeyBindingValues; // command string -> command value std::unordered_map m_MouseButtonBindings; // GLFW_MOUSE_BUTTON... -> command string // Input events @@ -48,7 +50,7 @@ private: EventRelay m_EBindMouseButton; bool OnBindMouseButton(const Events::BindMouseButton &event); - void PublishCommand(int playerID, std::string command, float value, bool release = false); + void PublishCommand(int playerID, std::string command, float value); }; } diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 5fad34c..02259ad 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -31,7 +31,7 @@ void Systems::PhysicsSystem::Initialize() // Events EVENT_SUBSCRIBE_MEMBER(m_ETankSteer, &Systems::PhysicsSystem::OnTankSteer); - + hkMemorySystem::FrameInfo finfo(6000 * 1024); // Allocate 6MB of Physics solver buffer hkMemoryRouter* memoryRouter = hkMemoryInitUtil::initDefault(hkMallocAllocator::m_defaultMallocAllocator, finfo); hkBaseSystem::init(memoryRouter, HavokErrorReport); @@ -115,7 +115,6 @@ void Systems::PhysicsSystem::RegisterComponents(ComponentFactory* cf) cf->Register("MeshShape", []() { return new Components::MeshShape(); }); cf->Register("HingeConstraint", []() { return new Components::HingeConstraint(); }); cf->Register("WheelPair", []() { return new Components::WheelPair(); }); - } void Systems::PhysicsSystem::Update(double dt) @@ -550,7 +549,9 @@ glm::quat Systems::PhysicsSystem::ConvertRotation(const hkQuaternion &hkRotation const hkQuaternion& Systems::PhysicsSystem::ConvertRotation(glm::quat glmRotation) { - return hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w); + hkQuaternion quat = hkQuaternion(glmRotation.x, glmRotation.y, glmRotation.z, glmRotation.w); + quat.normalize(); + return quat; } glm::vec3 Systems::PhysicsSystem::ConvertScale(const hkVector4 &hkScale) @@ -566,8 +567,7 @@ const hkVector4& Systems::PhysicsSystem::ConvertScale(glm::vec3 glmScale) bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) { auto vehicleComponent = m_World->GetComponent(event.Entity, "Vehicle"); - auto inputComponent = m_World->GetComponent(event.Entity, "Input"); - if (vehicleComponent && inputComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) + if (vehicleComponent && m_Vehicles.find(event.Entity) != m_Vehicles.end() && m_RigidBodies.find(event.Entity) != m_RigidBodies.end()) { m_PhysicsWorld->markForWrite(); hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[event.Entity]->m_deviceStatus; @@ -579,4 +579,3 @@ bool Systems::PhysicsSystem::OnTankSteer(const Events::TankSteer &event) return true; } - diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index b8fc262..968db95 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -12,6 +12,7 @@ #include "Components/MeshShape.h" #include "Components/HingeConstraint.h" #include "Components/WheelPair.h" +#include "Components/TowerSteering.h" #include "Events/TankSteer.h" #include "OBJ.h" diff --git a/src/Systems/TankSteeringSystem.cpp b/src/Systems/TankSteeringSystem.cpp index f0a4e30..eee50cc 100644 --- a/src/Systems/TankSteeringSystem.cpp +++ b/src/Systems/TankSteeringSystem.cpp @@ -5,19 +5,20 @@ void Systems::TankSteeringSystem::RegisterComponents( ComponentFactory* cf ) { cf->Register("TankSteering", []() { return new Components::TankSteering(); }); + cf->Register("TowerSteering", []() { return new Components::TowerSteering(); }); + cf->Register("BarrelSteering", []() { return new Components::BarrelSteering(); }); } void Systems::TankSteeringSystem::Initialize() { - m_InputController = std::unique_ptr(new TankSteeringInputController(EventBroker)); - m_InputController->PositionX = 0; - m_InputController->PositionY = 0; - m_InputController->Handbrake = false; + m_TankInputController = std::unique_ptr(new TankSteeringInputController(EventBroker)); + m_TowerInputController = std::unique_ptr(new TowerSteeringInputController(EventBroker)); } void Systems::TankSteeringSystem::Update(double dt) { - + m_TankInputController->Update(dt); + m_TowerInputController->Update(dt); } void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, EntityID parent) @@ -27,61 +28,85 @@ void Systems::TankSteeringSystem::UpdateEntity(double dt, EntityID entity, Entit { Events::TankSteer e; e.Entity = entity; - e.PositionX = m_InputController->PositionX; - e.PositionY = m_InputController->PositionY; - e.Handbrake = m_InputController->Handbrake; + e.PositionX = m_TankInputController->PositionX; + e.PositionY = m_TankInputController->PositionY; + e.Handbrake = m_TankInputController->Handbrake; EventBroker->Publish(e); } + + auto towerSteeringComponent = m_World->GetComponent(entity, "TowerSteering"); + if(towerSteeringComponent) + { + auto transformComponent = m_World->GetComponent(entity, "Transform"); + glm::quat orientation = glm::angleAxis(towerSteeringComponent->Velocity * m_TowerInputController->TowerDirection * (float)dt, towerSteeringComponent->Axis); + transformComponent->Orientation *= orientation; + } + + auto barrelSteeringComponent = m_World->GetComponent(entity, "BarrelSteering"); + if(barrelSteeringComponent) + { + auto transformComponent = m_World->GetComponent(entity, "Transform"); + glm::quat orientation = glm::angleAxis(barrelSteeringComponent->Velocity * m_TowerInputController->BarrelDirection * (float)dt, barrelSteeringComponent->Axis); + transformComponent->Orientation *= orientation; + } +} + +void Systems::TankSteeringSystem::TankSteeringInputController::Update( double dt ) +{ + PositionX = m_Horizontal; + PositionY = m_Vertical; +} + +void Systems::TankSteeringSystem::TowerSteeringInputController::Update( double dt ) +{ + TowerDirection = m_TowerDirection; + BarrelDirection = m_BarrelDirection; } bool Systems::TankSteeringSystem::TankSteeringInputController::OnCommand(const Events::InputCommand &event) { - float val = boost::any_cast(event.Value); - if (event.Command == "+right") + float val = event.Value; + if (event.Command == "horizontal") { - PositionX += val; + m_Horizontal = val; } - else if (event.Command == "-right") + else if (event.Command == "vertical") { - PositionX -= val; + m_Vertical = val; } - else if (event.Command == "+left") + + else if (event.Command == "handbrake") { - PositionX += -val; - } - else if (event.Command == "-left") - { - PositionX -= -val; - } - else if (event.Command == "+forward") - { - PositionY += -val; - } - else if (event.Command == "-forward") - { - PositionY -= -val; - } - else if (event.Command == "+backward") - { - PositionY += val; - } - else if (event.Command == "-backward") - { - PositionY -= val; + Handbrake = val; } - else if (event.Command == "+handbrake") + return true; +} + +bool Systems::TankSteeringSystem::TowerSteeringInputController::OnCommand( const Events::InputCommand &event ) +{ + float val = event.Value; + if(event.Command == "tower_rotation") { - Handbrake = true; + m_TowerDirection = val; } - else if (event.Command == "-handbrake") + else if(event.Command == "barrel_rotation") { - Handbrake = false; + m_BarrelDirection = val; } return true; } +bool Systems::TankSteeringSystem::TowerSteeringInputController::OnMouseMove( const Events::MouseMove &event ) +{ + return false; +} + bool Systems::TankSteeringSystem::TankSteeringInputController::OnMouseMove( const Events::MouseMove &event ) { return false; } + + + + diff --git a/src/Systems/TankSteeringSystem.h b/src/Systems/TankSteeringSystem.h index 5c7a02e..dee4707 100644 --- a/src/Systems/TankSteeringSystem.h +++ b/src/Systems/TankSteeringSystem.h @@ -4,6 +4,8 @@ #include "Events/TankSteer.h" #include "Components/Transform.h" #include "Components/TankSteering.h" +#include "Components/TowerSteering.h" +#include "Components/BarrelSteering.h" #include "Components/Vehicle.h" #include "InputController.h" @@ -24,22 +26,59 @@ namespace Systems private: class TankSteeringInputController; - std::unique_ptr m_InputController; + std::unique_ptr m_TankInputController; + class TowerSteeringInputController; + std::unique_ptr m_TowerInputController; }; class TankSteeringSystem::TankSteeringInputController : InputController { public: TankSteeringInputController(std::shared_ptr<::EventBroker> eventBroker) - : InputController(eventBroker) { } + : InputController(eventBroker) + { + m_Horizontal = 0.f; + m_Vertical = 0.f; + PositionX = 0; + PositionY = 0; + Handbrake = false; + } float PositionY; float PositionX; bool Handbrake; - + void Update(double dt); protected: virtual bool OnCommand(const Events::InputCommand &event); virtual bool OnMouseMove(const Events::MouseMove &event); + + private: + float m_Horizontal; + float m_Vertical; + }; + + class TankSteeringSystem::TowerSteeringInputController : InputController + { + public: + TowerSteeringInputController(std::shared_ptr<::EventBroker> eventBroker) + : InputController(eventBroker) + { + m_TowerDirection = 0.f; + m_BarrelDirection = 0.f; + TowerDirection = 0.f; + BarrelDirection = 0.f; + } + + float TowerDirection; + float BarrelDirection; + void Update(double dt); + protected: + virtual bool OnCommand(const Events::InputCommand &event); + virtual bool OnMouseMove(const Events::MouseMove &event); + + private: + float m_TowerDirection; + float m_BarrelDirection; }; } \ No newline at end of file diff --git a/src/World.h b/src/World.h index 3581be1..7ce77db 100755 --- a/src/World.h +++ b/src/World.h @@ -61,6 +61,11 @@ public: m_EntityProperties[entity][property] = value; } + void SetProperty(EntityID entity, std::string property, char* value) + { + m_EntityProperties[entity][property] = std::string(value); + } + template std::shared_ptr AddComponent(EntityID entity, std::string componentType); std::shared_ptr AddComponent(EntityID entity, std::string componentType); diff --git a/vs11/Returngeance/Returngeance.vcxproj b/vs11/Returngeance/Returngeance.vcxproj index 47fff50..9affcba 100755 --- a/vs11/Returngeance/Returngeance.vcxproj +++ b/vs11/Returngeance/Returngeance.vcxproj @@ -124,6 +124,7 @@ + @@ -141,6 +142,7 @@ + diff --git a/vs11/Returngeance/Returngeance.vcxproj.filters b/vs11/Returngeance/Returngeance.vcxproj.filters index 8b1f1a3..0323b51 100755 --- a/vs11/Returngeance/Returngeance.vcxproj.filters +++ b/vs11/Returngeance/Returngeance.vcxproj.filters @@ -322,6 +322,12 @@ Physics\Systems + + Physics\Components + + + Physics\Components +