#[repr(C)]pub struct Gamepad {
pub buttons: Buttons,
pub left_trigger: u8,
pub right_trigger: u8,
pub left_thumb_x: i16,
pub left_thumb_y: i16,
pub right_thumb_x: i16,
pub right_thumb_y: i16,
}Expand description
[microsoft.com] XINPUT_GAMEPAD
Describes the state of an Xbox 360 controller.
§See Also
- Doing thumbstick dead zones right (strongly recommended reading!)
- Xbox 360 controller - Layout - Wikipedia
Fields§
Buttons of the gamepad that are currently held.
left_trigger: u8Analog trigger behind the left side of the gamepad.
| Value | Description |
|---|---|
| 0 | Not held |
| 30 | Gamepad::TRIGGER_THRESHOLD |
| 255 | Fully held |
right_trigger: u8Analog trigger behind the right side of the gamepad.
| Value | Description |
|---|---|
| 0 | Not held |
| 30 | Gamepad::TRIGGER_THRESHOLD |
| 255 | Fully held |
left_thumb_x: i16X-coordinate of the upper left thumbstick of the gamepad.
| Value | Description |
|---|---|
| -32768 | Fully left |
| -7849 | - Gamepad::LEFT_THUMB_DEADZONE |
| 0 | Centered |
| +7849 | + Gamepad::LEFT_THUMB_DEADZONE |
| +32767 | Fully right |
left_thumb_y: i16Y-coordinate of the upper left thumbstick of the gamepad.
| Value | Description |
|---|---|
| -32768 | Fully down |
| -7849 | - Gamepad::LEFT_THUMB_DEADZONE |
| 0 | Centered |
| +7849 | + Gamepad::LEFT_THUMB_DEADZONE |
| +32767 | Fully up |
right_thumb_x: i16X-coordinate of the right thumbstick of the gamepad.
| Value | Description |
|---|---|
| -32768 | Fully left |
| -8689 | - Gamepad::RIGHT_THUMB_DEADZONE |
| 0 | Centered |
| +8689 | + Gamepad::RIGHT_THUMB_DEADZONE |
| +32767 | Fully right |
right_thumb_y: i16Y-coordinate of the right thumbstick of the gamepad.
| Value | Description |
|---|---|
| -32768 | Fully down |
| -8689 | - Gamepad::RIGHT_THUMB_DEADZONE |
| 0 | Centered |
| +8689 | + Gamepad::RIGHT_THUMB_DEADZONE |
| +32767 | Fully up |
Implementations§
Source§impl Gamepad
impl Gamepad
Sourcepub const TRIGGER_THRESHOLD: u8 = 30u8
pub const TRIGGER_THRESHOLD: u8 = 30u8
An optional default threshhold to compare Gamepad::left_trigger or Gamepad::right_trigger to, before which you might avoid registering a trigger pull.
In my experience, Xbox 360 controllers all perfectly report 0 trigger when untouched, so this is somewhat optional. On the other hand, there’s no guarantee third party XInput compatible controllers behave the same, so perhaps you should use such a constant!
Sourcepub const LEFT_THUMB_DEADZONE: i16 = 7_849i16
pub const LEFT_THUMB_DEADZONE: i16 = 7_849i16
A default deadzone magnitude for the left thumbstick.
You might ignore Gamepad::left_thumb_x / Gamepad::left_thumb_y when they’re within this magnitude of (0,0).
While this is generally large enough to avoid drift on new controllers, I have seen more well used controllers rest outside of this magnitude, resulting in suprising drift.
For maximum flexibility, consider making the user’s deadzone customizeable, and perhaps using a higher threshhold for triggering game UI navigation.
I also strongly recommend reading Doing thumbstick dead zones right.
Sourcepub const RIGHT_THUMB_DEADZONE: i16 = 8_689i16
pub const RIGHT_THUMB_DEADZONE: i16 = 8_689i16
A default deadzone magnitude for the right thumbstick.
You might ignore Gamepad::right_thumb_x / Gamepad::right_thumb_y when they’re within this magnitude of (0,0).
While this is generally large enough to avoid drift on new controllers, I have seen more well used controllers rest outside of this magnitude, resulting in suprising drift.
For maximum flexibility, consider making the user’s deadzone customizeable, and perhaps using a higher threshhold for triggering game UI navigation.
I also strongly recommend reading Doing thumbstick dead zones right.
Trait Implementations§
Source§impl AsMut<Gamepad> for XINPUT_GAMEPAD
Available on crate feature winapi-0-3 only.
impl AsMut<Gamepad> for XINPUT_GAMEPAD
winapi-0-3 only.Source§impl AsMut<XINPUT_GAMEPAD> for Gamepad
Available on crate feature winapi-0-3 only.
impl AsMut<XINPUT_GAMEPAD> for Gamepad
winapi-0-3 only.Source§fn as_mut(&mut self) -> &mut XINPUT_GAMEPAD
fn as_mut(&mut self) -> &mut XINPUT_GAMEPAD
Source§impl AsRef<Gamepad> for XINPUT_GAMEPAD
Available on crate feature winapi-0-3 only.
impl AsRef<Gamepad> for XINPUT_GAMEPAD
winapi-0-3 only.Source§impl AsRef<XINPUT_GAMEPAD> for Gamepad
Available on crate feature winapi-0-3 only.
impl AsRef<XINPUT_GAMEPAD> for Gamepad
winapi-0-3 only.Source§fn as_ref(&self) -> &XINPUT_GAMEPAD
fn as_ref(&self) -> &XINPUT_GAMEPAD
Source§impl From<Gamepad> for XINPUT_GAMEPAD
Available on crate feature winapi-0-3 only.
impl From<Gamepad> for XINPUT_GAMEPAD
winapi-0-3 only.Source§impl From<XINPUT_GAMEPAD> for Gamepad
Available on crate feature winapi-0-3 only.
impl From<XINPUT_GAMEPAD> for Gamepad
winapi-0-3 only.Source§fn from(value: XINPUT_GAMEPAD) -> Self
fn from(value: XINPUT_GAMEPAD) -> Self
impl Copy for Gamepad
impl Pod for Gamepad
Auto Trait Implementations§
impl Freeze for Gamepad
impl RefUnwindSafe for Gamepad
impl Send for Gamepad
impl Sync for Gamepad
impl Unpin for Gamepad
impl UnwindSafe for Gamepad
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
Source§type Bits = T
type Bits = T
Self must have the same layout as the specified Bits except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern.Source§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self.