Xbox Controller support
This commit is contained in:
@@ -33,7 +33,6 @@ public:
|
||||
|
||||
void Initialize();
|
||||
|
||||
static const short MAX_GAMEPADS = 4;
|
||||
|
||||
void Update(double dt);
|
||||
|
||||
@@ -50,12 +49,6 @@ private:
|
||||
std::array<int, GLFW_KEY_LAST+1> m_LastKeyState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_CurrentMouseState;
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST+1> m_LastMouseState;
|
||||
typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
|
||||
std::array<GamepadAxisState, MAX_GAMEPADS> m_CurrentGamepadAxisState;
|
||||
std::array<GamepadAxisState, MAX_GAMEPADS> m_LastGamepadAxisState;
|
||||
typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
|
||||
std::array<GamepadButtonState, MAX_GAMEPADS> m_CurrentGamepadButtonState;
|
||||
std::array<GamepadButtonState, MAX_GAMEPADS> m_LastGamepadButtonState;
|
||||
|
||||
double m_CurrentMouseX, m_CurrentMouseY;
|
||||
double m_LastMouseX, m_LastMouseY;
|
||||
@@ -64,6 +57,11 @@ private:
|
||||
|
||||
void PublishGamepadAxisIfChanged(int gamepadID, Gamepad::Axis axis);
|
||||
void PublishGamepadButtonIfChanged(int gamepadID, Gamepad::Button button);
|
||||
|
||||
static void GLFWMouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
|
||||
{
|
||||
LOG_DEBUG("Click! %i %i %i", button, action, mods);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifndef XboxControllerInputHandler_h__
|
||||
#define XboxControllerInputHandler_h__
|
||||
|
||||
#include "InputHandler.h"
|
||||
#include "Core/EKeyDown.h"
|
||||
#include "Core/EKeyUp.h"
|
||||
|
||||
struct _XINPUT_STATE;
|
||||
typedef _XINPUT_STATE XINPUT_STATE;
|
||||
|
||||
class XboxControllerInputHandler : public InputHandler
|
||||
{
|
||||
public:
|
||||
XboxControllerInputHandler(EventBroker* eventBroker, InputProxy* inputProxy);
|
||||
|
||||
|
||||
bool BindOrigin(std::string origin, std::string command, float value) override;
|
||||
|
||||
void Update(double dt) override;
|
||||
|
||||
virtual float GetCommandValue(std::string command) override;
|
||||
private:
|
||||
std::unordered_map<std::string, int> m_OriginButtons;
|
||||
std::unordered_map<std::string, int> m_OriginAxes;
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_ButtonBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<int, std::tuple<std::string, float>> m_AxisBindings; // GLFW_KEY... -> command string & value
|
||||
std::unordered_map<std::string, float> m_CommandValues;
|
||||
|
||||
static const short MAX_GAMEPADS = 4;
|
||||
|
||||
float getAxisValue(XINPUT_STATE& state, int axis);
|
||||
//typedef std::array<float, static_cast<int>(Gamepad::Axis::LAST) + 1> GamepadAxisState;
|
||||
//std::array<GamepadAxisState, MAX_GAMEPADS> m_CurrentGamepadAxisState;
|
||||
//std::array<GamepadAxisState, MAX_GAMEPADS> m_LastGamepadAxisState;
|
||||
//typedef std::array<bool, static_cast<int>(Gamepad::Button::LAST) + 1> GamepadButtonState;
|
||||
//std::array<GamepadButtonState, MAX_GAMEPADS> m_CurrentGamepadButtonState;
|
||||
//std::array<GamepadButtonState, MAX_GAMEPADS> m_LastGamepadButtonState;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
if (e.Command == "Right") {
|
||||
float value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
m_Velocity.x = value;
|
||||
LOG_INFO("%f", value);
|
||||
}
|
||||
if (e.Command == "Forward") {
|
||||
float value = std::max(-1.f, std::min(e.Value, 1.f));
|
||||
@@ -37,12 +38,12 @@ public:
|
||||
void Update(double dt)
|
||||
{
|
||||
if (glm::length2(m_Velocity) > 0) {
|
||||
m_Position += m_Orientation * (glm::normalize(m_Velocity) * m_BaseSpeed);
|
||||
m_Position += (m_Orientation * (m_Velocity * m_BaseSpeed)) * (float)dt;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
glm::vec3 m_Position = glm::vec3(0, 0, 0);
|
||||
glm::vec3 m_Velocity = glm::vec3(0, 0, 0);
|
||||
float m_BaseSpeed = 0.1f;
|
||||
float m_BaseSpeed = 2.0f;
|
||||
};
|
||||
Reference in New Issue
Block a user