diff --git a/openVulkanoCpp/Controller/FreeCamCameraController.cpp b/openVulkanoCpp/Controller/FreeCamCameraController.cpp index 911e07a..cefbb0c 100644 --- a/openVulkanoCpp/Controller/FreeCamCameraController.cpp +++ b/openVulkanoCpp/Controller/FreeCamCameraController.cpp @@ -55,12 +55,16 @@ namespace OpenVulkano { m_actionForward->BindKey(Input::InputKey::Controller::AXIS_LEFT_Y); m_actionForward->BindAxisButtons(Input::InputKey::Keyboard::KEY_W, Input::InputKey::Keyboard::KEY_S); + m_actionForward->BindKey(Input::InputKey::Touch::AXIS_PAN_TWO_FINGERS_Y, -0.01f); m_actionSide->BindKey(Input::InputKey::Controller::AXIS_LEFT_X); m_actionSide->BindAxisButtons(Input::InputKey::Keyboard::KEY_D, Input::InputKey::Keyboard::KEY_A); + m_actionSide->BindKey(Input::InputKey::Touch::AXIS_PAN_TWO_FINGERS_X, 0.01f); m_actionLookUp->BindKey(Input::InputKey::Controller::AXIS_RIGHT_Y); - m_actionLookSide->BindKey(Input::InputKey::Controller::AXIS_RIGHT_X); m_actionLookUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_DOWN, Input::InputKey::Keyboard::KEY_UP); + m_actionLookUp->BindKey(Input::InputKey::Touch::AXIS_PAN_Y, 0.10f); + m_actionLookSide->BindKey(Input::InputKey::Controller::AXIS_RIGHT_X); m_actionLookSide->BindAxisButtons(Input::InputKey::Keyboard::KEY_RIGHT, Input::InputKey::Keyboard::KEY_LEFT); + m_actionLookSide->BindKey(Input::InputKey::Touch::AXIS_PAN_X, 0.10f); m_actionLookUp->BindKey(Input::InputKey::Mouse::AXIS_Y); m_actionLookSide->BindKey(Input::InputKey::Mouse::AXIS_X); m_actionUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_SPACE, Input::InputKey::Keyboard::KEY_LEFT_CONTROL); diff --git a/openVulkanoCpp/Input/InputAction.hpp b/openVulkanoCpp/Input/InputAction.hpp index 64c36fc..7e97e35 100644 --- a/openVulkanoCpp/Input/InputAction.hpp +++ b/openVulkanoCpp/Input/InputAction.hpp @@ -11,33 +11,54 @@ namespace OpenVulkano::Input { + struct KeyBinding + { + InputKey key; + float scale; + + KeyBinding(InputKey keyBinding, float scaleFactor) + : key(keyBinding), scale(scaleFactor) + {} + }; + + struct AxisButtonBinding + { + InputKey positive; + InputKey negative; + float scale; + + AxisButtonBinding(InputKey pos, InputKey neg, float scaleFactor) + : positive(pos), negative(neg), scale(scaleFactor) + {} + }; + class InputAction final : public BaseInputAction { - std::vector keys; - std::vector> axisButtons; + std::vector keys; + std::vector axisButtons; public: InputAction(const std::string& name) : BaseInputAction(name) {} - [[nodiscard]] const std::vector& GetKeys() const + [[nodiscard]] const std::vector& GetKeys() const { return keys; } - [[nodiscard]] const std::vector>& GetAxisButtons() const + [[nodiscard]] const std::vector& GetAxisButtons() const { return axisButtons; } - void BindKey(InputKey key) + void BindKey(InputKey key, float scale = 1) { - keys.push_back(key); + keys.emplace_back(key, scale); } - void BindAxisButtons(InputKey keyPositive, InputKey keyNegative) + void BindAxisButtons(InputKey keyPositive, InputKey keyNegative, float scale = 1) { - axisButtons.emplace_back(keyPositive, keyNegative); + axisButtons.emplace_back(keyPositive, keyNegative, scale); } }; } \ No newline at end of file diff --git a/openVulkanoCpp/Input/InputManager.cpp b/openVulkanoCpp/Input/InputManager.cpp index 0368f7c..b17ca6a 100644 --- a/openVulkanoCpp/Input/InputManager.cpp +++ b/openVulkanoCpp/Input/InputManager.cpp @@ -36,13 +36,15 @@ namespace OpenVulkano::Input const std::vector& testDevices = action->GetDevices().empty() ? devices : action->GetDevices(); for (const InputDevice* device : testDevices) { - for(InputKey key : action->GetKeys()) + for(KeyBinding binding : action->GetKeys()) { - value += device->GetAxis(key); + if (binding.key.GetInputDeviceType() != device->GetType()) continue; + value += device->GetAxis(binding.key) * binding.scale; } - for(const auto& keys : action->GetAxisButtons()) + for(const auto& binding : action->GetAxisButtons()) { - value += GetAxis(keys.first) - GetAxis(keys.second); + if (binding.positive.GetInputDeviceType() != device->GetType()) continue; + value += (GetAxis(binding.positive) - GetAxis(binding.negative)) * binding.scale; } } return value; @@ -53,6 +55,7 @@ namespace OpenVulkano::Input float value = 0; for (const InputDevice* device : devices) { + if (key.GetInputDeviceType() != device->GetType()) continue; value += device->GetAxis(key); } return value; @@ -63,9 +66,10 @@ namespace OpenVulkano::Input const std::vector& testDevices = action->GetDevices().empty() ? devices : action->GetDevices(); for (const InputDevice* device : testDevices) { - for (const InputKey key : action->GetKeys()) + for (const KeyBinding binding : action->GetKeys()) { - if (device->GetButton(key)) return true; + if (binding.key.GetInputDeviceType() != device->GetType()) continue; + if (device->GetButton(binding.key)) return true; } } return false; @@ -75,6 +79,7 @@ namespace OpenVulkano::Input { for(const InputDevice* device : devices) { + if (key.GetInputDeviceType() != device->GetType()) continue; if (device->GetButton(key)) return true; } return false;