Gamepad

Struct Gamepad 

Source
#[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

Fields§

§buttons: Buttons

Buttons of the gamepad that are currently held.

§left_trigger: u8

Analog trigger behind the left side of the gamepad.

ValueDescription
0Not held
30Gamepad::TRIGGER_THRESHOLD
255Fully held
§right_trigger: u8

Analog trigger behind the right side of the gamepad.

ValueDescription
0Not held
30Gamepad::TRIGGER_THRESHOLD
255Fully held
§left_thumb_x: i16

X-coordinate of the upper left thumbstick of the gamepad.

ValueDescription
-32768Fully left
-7849- Gamepad::LEFT_THUMB_DEADZONE
0Centered
+7849+ Gamepad::LEFT_THUMB_DEADZONE
+32767Fully right
§left_thumb_y: i16

Y-coordinate of the upper left thumbstick of the gamepad.

ValueDescription
-32768Fully down
-7849- Gamepad::LEFT_THUMB_DEADZONE
0Centered
+7849+ Gamepad::LEFT_THUMB_DEADZONE
+32767Fully up
§right_thumb_x: i16

X-coordinate of the right thumbstick of the gamepad.

ValueDescription
-32768Fully left
-8689- Gamepad::RIGHT_THUMB_DEADZONE
0Centered
+8689+ Gamepad::RIGHT_THUMB_DEADZONE
+32767Fully right
§right_thumb_y: i16

Y-coordinate of the right thumbstick of the gamepad.

ValueDescription
-32768Fully down
-8689- Gamepad::RIGHT_THUMB_DEADZONE
0Centered
+8689+ Gamepad::RIGHT_THUMB_DEADZONE
+32767Fully up

Implementations§

Source§

impl Gamepad

Source

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!

Source

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.

Source

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 Gamepad

Source§

fn as_mut(&mut self) -> &mut Self

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<Gamepad> for XINPUT_GAMEPAD

Available on crate feature winapi-0-3 only.
Source§

fn as_mut(&mut self) -> &mut Gamepad

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl AsMut<Gamepad> for XINPUT_GAMEPAD

Available on crate feature windows-sys-0-52 only.
§

fn as_mut(&mut self) -> &mut Gamepad

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsMut<XINPUT_GAMEPAD> for Gamepad

Available on crate feature winapi-0-3 only.
Source§

fn as_mut(&mut self) -> &mut XINPUT_GAMEPAD

Converts this type into a mutable reference of the (usually inferred) input type.
§

impl AsMut<XINPUT_GAMEPAD> for Gamepad

Available on crate feature windows-sys-0-52 only.
§

fn as_mut(&mut self) -> &mut XINPUT_GAMEPAD

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl AsRef<Gamepad> for Gamepad

Source§

fn as_ref(&self) -> &Self

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<Gamepad> for XINPUT_GAMEPAD

Available on crate feature winapi-0-3 only.
Source§

fn as_ref(&self) -> &Gamepad

Converts this type into a shared reference of the (usually inferred) input type.
§

impl AsRef<Gamepad> for XINPUT_GAMEPAD

Available on crate feature windows-sys-0-52 only.
§

fn as_ref(&self) -> &Gamepad

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<XINPUT_GAMEPAD> for Gamepad

Available on crate feature winapi-0-3 only.
Source§

fn as_ref(&self) -> &XINPUT_GAMEPAD

Converts this type into a shared reference of the (usually inferred) input type.
§

impl AsRef<XINPUT_GAMEPAD> for Gamepad

Available on crate feature windows-sys-0-52 only.
§

fn as_ref(&self) -> &XINPUT_GAMEPAD

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Gamepad

Source§

fn clone(&self) -> Gamepad

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Gamepad

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Gamepad

Source§

fn default() -> Gamepad

Returns the “default value” for a type. Read more
Source§

impl From<Gamepad> for XINPUT_GAMEPAD

Available on crate feature winapi-0-3 only.
Source§

fn from(value: Gamepad) -> Self

Converts to this type from the input type.
§

impl From<Gamepad> for XINPUT_GAMEPAD

Available on crate feature windows-sys-0-52 only.
§

fn from(value: Gamepad) -> Self

Converts to this type from the input type.
Source§

impl From<XINPUT_GAMEPAD> for Gamepad

Available on crate feature winapi-0-3 only.
Source§

fn from(value: XINPUT_GAMEPAD) -> Self

Converts to this type from the input type.
§

impl From<XINPUT_GAMEPAD> for Gamepad

Available on crate feature windows-sys-0-52 only.
§

fn from(value: XINPUT_GAMEPAD) -> Self

Converts to this type from the input type.
Source§

impl Zeroable for Gamepad

Source§

fn zeroed() -> Self

Source§

impl Copy for Gamepad

Source§

impl Pod for Gamepad

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

Source§

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

If this function returns true, then it must be valid to reinterpret bits as &Self.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> AnyBitPattern for T
where T: Pod,

Source§

impl<T> NoUninit for T
where T: Pod,