Struct leafwing_input_manager::axislike::DualAxisData
source · [−]pub struct DualAxisData { /* private fields */ }
Expand description
A wrapped Vec2
that represents the combaination of two input axes.
The neutral origin is always at 0, 0.
When working with gamepad axes, both x
and y
values are bounded by [-1.0, 1.0].
For other input axes (such as mousewheel data), this may not be true!
This struct should store the processed form of your raw inputs in a device-agnostic fashion. Any deadzone correction, rescaling or drift-correction should be done at an earlier level.
Implementations
sourceimpl DualAxisData
impl DualAxisData
sourcepub fn new(x: f32, y: f32) -> DualAxisData
pub fn new(x: f32, y: f32) -> DualAxisData
Creates a new [AxisPair
] from the provided (x,y) coordinates
sourcepub fn from_xy(xy: Vec2) -> DualAxisData
pub fn from_xy(xy: Vec2) -> DualAxisData
Creates a new [AxisPair
] directly from a Vec2
sourcepub fn merged_with(&self, other: DualAxisData) -> DualAxisData
pub fn merged_with(&self, other: DualAxisData) -> DualAxisData
Merge the state of this [AxisPair
] with another.
This is useful if you have multiple sticks bound to the same game action, and you want to get their combined position.
Warning
This method can result in values with a greater maximum magnitude than expected!
Use [AxisPair::clamp_length
] to limit the resulting direction.
sourceimpl DualAxisData
impl DualAxisData
sourcepub fn direction(&self) -> Option<Direction>
pub fn direction(&self) -> Option<Direction>
The Direction
that this axis is pointing towards, if any
If the axis is neutral (x,y) = (0,0), a (0, 0) None
will be returned
sourcepub fn rotation(&self) -> Option<Rotation>
pub fn rotation(&self) -> Option<Rotation>
The Rotation
(measured clockwise from midnight) that this axis is pointing towards, if any
If the axis is neutral (x,y) = (0,0), this will be None
sourcepub fn length(&self) -> f32
pub fn length(&self) -> f32
How far from the origin is this axis’s position?
Typically bounded by 0 and 1.
If you only need to compare relative magnitudes, use magnitude_squared
instead for faster computation.
sourcepub fn length_squared(&self) -> f32
pub fn length_squared(&self) -> f32
The square of the axis’ magnitude
Typically bounded by 0 and 1.
This is faster than magnitude
, as it avoids a square root, but will generally have less natural behavior.
sourcepub fn clamp_length(&mut self, max: f32)
pub fn clamp_length(&mut self, max: f32)
Clamps the magnitude of the axis
Trait Implementations
sourceimpl Clone for DualAxisData
impl Clone for DualAxisData
sourcefn clone(&self) -> DualAxisData
fn clone(&self) -> DualAxisData
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for DualAxisData
impl Debug for DualAxisData
sourceimpl Default for DualAxisData
impl Default for DualAxisData
sourcefn default() -> DualAxisData
fn default() -> DualAxisData
Returns the “default value” for a type. Read more
sourceimpl<'de> Deserialize<'de> for DualAxisData
impl<'de> Deserialize<'de> for DualAxisData
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<DualAxisData> for Vec2
impl From<DualAxisData> for Vec2
sourcefn from(data: DualAxisData) -> Vec2
fn from(data: DualAxisData) -> Vec2
Converts to this type from the input type.
sourceimpl PartialEq<DualAxisData> for DualAxisData
impl PartialEq<DualAxisData> for DualAxisData
sourcefn eq(&self, other: &DualAxisData) -> bool
fn eq(&self, other: &DualAxisData) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &DualAxisData) -> bool
fn ne(&self, other: &DualAxisData) -> bool
This method tests for !=
.
sourceimpl Serialize for DualAxisData
impl Serialize for DualAxisData
impl Copy for DualAxisData
impl StructuralPartialEq for DualAxisData
Auto Trait Implementations
impl RefUnwindSafe for DualAxisData
impl Send for DualAxisData
impl Sync for DualAxisData
impl Unpin for DualAxisData
impl UnwindSafe for DualAxisData
Blanket Implementations
impl<T, U> AsBindGroupShaderType<U> for T where
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for T where
U: ShaderType,
&'a T: for<'a> Into<U>,
fn as_bind_group_shader_type(
&self,
_images: &HashMap<Handle<Image>, <Image as RenderAsset>::PreparedAsset, RandomState, Global>
) -> U
fn as_bind_group_shader_type(
&self,
_images: &HashMap<Handle<Image>, <Image as RenderAsset>::PreparedAsset, RandomState, Global>
) -> U
Return the T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist. Read more
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Downcast for T where
T: Any,
impl<T> Downcast for T where
T: Any,
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Convert Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Convert Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read more
fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert &Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read more
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert &mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read more
impl<T> FromWorld for T where
T: Default,
impl<T> FromWorld for T where
T: Default,
fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Creates Self
using data from the given [World]
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Serialize for T where
T: Serialize + ?Sized,
impl<T> Serialize for T where
T: Serialize + ?Sized,
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<Ok, Error>
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
impl<T> TypeData for T where
T: 'static + Send + Sync + Clone,
fn clone_type_data(&self) -> Box<dyn TypeData + 'static, Global>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more