From d2f3adb07e95f941729e7643bff1752711f276b6 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 22 Apr 2014 01:46:29 +0200 Subject: [PATCH] Vehicle keyboard steering! Steering: Direction keys Handbrake: Right control --- src/GameWorld.cpp | 1 + src/Systems/PhysicsSystem.cpp | 11 ++++++++++- src/Systems/PhysicsSystem.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/GameWorld.cpp b/src/GameWorld.cpp index 2d0c4f3..1b82b1a 100755 --- a/src/GameWorld.cpp +++ b/src/GameWorld.cpp @@ -53,6 +53,7 @@ void GameWorld::Initialize() box->Height = 0.5f; box->Depth = 2.5f; auto vehicle = AddComponent(car, "Vehicle"); + AddComponent(car, "Input"); } for(int i = 0; i < 50; i++) diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 39d2e93..c7c6306 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -115,7 +115,16 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p transformComponent->Orientation = glm::quat(orientation(3),orientation(0), orientation(1), orientation(2)); } - + // HACK: Vehicle test-controls + auto vehicleComponent = m_World->GetComponent(entity, "Vehicle"); + auto inputComponent = m_World->GetComponent(entity, "Input"); + if (vehicleComponent && inputComponent) + { + hkpVehicleDriverInputAnalogStatus* deviceStatus = (hkpVehicleDriverInputAnalogStatus*)m_Vehicles[entity]->m_deviceStatus; + deviceStatus->m_positionY = inputComponent->KeyState[GLFW_KEY_UP] * -1 + inputComponent->KeyState[GLFW_KEY_DOWN] * 1; + deviceStatus->m_positionX = inputComponent->KeyState[GLFW_KEY_LEFT] * -1 + inputComponent->KeyState[GLFW_KEY_RIGHT] * 1; + deviceStatus->m_handbrakeButtonPressed = inputComponent->KeyState[GLFW_KEY_RIGHT_CONTROL]; + } } void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent) diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 77c4c21..1bbffdd 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -11,6 +11,7 @@ #include "Components/Sphere.h" #include "Components/Box.h" #include "Components/Vehicle.h" +#include "Components/Input.h" // Math and base include