Add XInput implementation of GetDPadAxis, GetLeftTriggerNormalized, GetRightTriggerNormalized.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
// TODO: Keep prev_state, so we can fire Events when buttons are pressed/releaed, etc.
|
||||
|
||||
#define MAX_DEVICES 4
|
||||
#define SHORT_RANGE 32768.f;
|
||||
|
||||
bool device_exists[MAX_DEVICES];
|
||||
XINPUT_STATE cur_state[MAX_DEVICES];
|
||||
@@ -21,6 +22,25 @@ bool jstick::Cleanup() { return true; }
|
||||
|
||||
void jstick::JoystickServiceUpdate() { }
|
||||
|
||||
Vector2 jstick::GetDPadAxis(float deadzone, int hwid)
|
||||
{
|
||||
// "Synthesize" a DPad vector based upon whether the buttons are pressed.
|
||||
// This vector will not be analog as is the case with the linux/jsdev implementation.
|
||||
Vector2 dpad;
|
||||
|
||||
if (IsButtonDown(XBoxButton::DPadDown))
|
||||
dpad.y += SHORT_RANGE;
|
||||
if (IsButtonDown(XBoxButton::DPadRight))
|
||||
dpad.x += SHORT_RANGE;
|
||||
if (IsButtonDown(XBoxButton::DPadLeft))
|
||||
dpad.x -= SHORT_RANGE;
|
||||
if (IsButtonDown(XBoxButton::DPadUp))
|
||||
dpad.y -= SHORT_RANGE;
|
||||
|
||||
return dpad;
|
||||
|
||||
}
|
||||
|
||||
/// XInput treats the DPad as buttons.
|
||||
bool jstick::GetDPadIsAxisOrButtons() { return false; }
|
||||
|
||||
@@ -144,6 +164,15 @@ Vector2 jstick::GetLeftThumbstickAxisNormalized(float deadzone, int hwid)
|
||||
|
||||
|
||||
|
||||
float jstick::GetLeftTriggerNormalized(int hwid) {
|
||||
return GetLeftTrigger(hwid) / SHORT_RANGE;
|
||||
}
|
||||
|
||||
float jstick::GetRightTriggerNormalized(int hwid) {
|
||||
return GetRightTrigger(hwid) / SHORT_RANGE;
|
||||
}
|
||||
|
||||
|
||||
bool jstick::IsButtonDown(const XBoxButton& btn, int hwid)
|
||||
{
|
||||
XINPUT_STATE state;
|
||||
|
Reference in New Issue
Block a user