Struct leafwing_input_manager::axislike::DualAxisData
source · pub struct DualAxisData { /* private fields */ }
Expand description
A wrapped Vec2
that represents the combination 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§
source§impl DualAxisData
impl DualAxisData
sourcepub fn new(x: f32, y: f32) -> DualAxisData
pub fn new(x: f32, y: f32) -> DualAxisData
Creates a new DualAxisData
from the provided (x,y) coordinates
sourcepub fn from_xy(xy: Vec2) -> DualAxisData
pub fn from_xy(xy: Vec2) -> DualAxisData
Creates a new DualAxisData
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 DualAxisData
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 DualAxisData::clamp_length
to limit the resulting direction.
source§impl 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§
source§impl Clone for DualAxisData
impl Clone for DualAxisData
source§fn clone(&self) -> DualAxisData
fn clone(&self) -> DualAxisData
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for DualAxisData
impl Debug for DualAxisData
source§impl Default for DualAxisData
impl Default for DualAxisData
source§fn default() -> DualAxisData
fn default() -> DualAxisData
source§impl<'de> Deserialize<'de> for DualAxisData
impl<'de> Deserialize<'de> for DualAxisData
source§fn 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>,
source§impl From<DualAxisData> for Vec2
impl From<DualAxisData> for Vec2
source§fn from(data: DualAxisData) -> Vec2
fn from(data: DualAxisData) -> Vec2
source§impl FromReflect for DualAxisDatawhere
Vec2: FromReflect,
impl FromReflect for DualAxisDatawhere
Vec2: FromReflect,
source§fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
Self
from a reflected value.§fn take_from_reflect(
reflect: Box<dyn Reflect>
) -> Result<Self, Box<dyn Reflect>>
fn take_from_reflect( reflect: Box<dyn Reflect> ) -> Result<Self, Box<dyn Reflect>>
Self
using,
constructing the value using from_reflect
if that fails. Read moresource§impl GetTypeRegistration for DualAxisDatawhere
Vec2: FromReflect,
impl GetTypeRegistration for DualAxisDatawhere
Vec2: FromReflect,
fn get_type_registration() -> TypeRegistration
source§impl PartialEq for DualAxisData
impl PartialEq for DualAxisData
source§fn eq(&self, other: &DualAxisData) -> bool
fn eq(&self, other: &DualAxisData) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl Reflect for DualAxisDatawhere
Vec2: FromReflect,
impl Reflect for DualAxisDatawhere
Vec2: FromReflect,
source§fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
fn get_represented_type_info(&self) -> Option<&'static TypeInfo>
TypeInfo
] of the type represented by this value. Read moresource§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
.source§fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
source§fn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
source§fn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
source§fn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read moresource§fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
source§fn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
source§fn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
source§fn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
source§fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
§fn type_name(&self) -> &str
fn type_name(&self) -> &str
§fn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
§fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
§fn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
§fn is_dynamic(&self) -> bool
fn is_dynamic(&self) -> bool
source§impl Serialize for DualAxisData
impl Serialize for DualAxisData
source§impl Struct for DualAxisDatawhere
Vec2: FromReflect,
impl Struct for DualAxisDatawhere
Vec2: FromReflect,
source§fn field(&self, name: &str) -> Option<&dyn Reflect>
fn field(&self, name: &str) -> Option<&dyn Reflect>
name
as a &dyn Reflect
.source§fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>
fn field_mut(&mut self, name: &str) -> Option<&mut dyn Reflect>
name
as a
&mut dyn Reflect
.source§fn field_at(&self, index: usize) -> Option<&dyn Reflect>
fn field_at(&self, index: usize) -> Option<&dyn Reflect>
index
as a
&dyn Reflect
.source§fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
index
as a &mut dyn Reflect
.source§fn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
index
.source§fn iter_fields(&self) -> FieldIter<'_>
fn iter_fields(&self) -> FieldIter<'_>
source§fn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
].source§impl TypePath for DualAxisDatawhere
Vec2: FromReflect,
impl TypePath for DualAxisDatawhere
Vec2: FromReflect,
source§fn type_path() -> &'static str
fn type_path() -> &'static str
source§fn short_type_path() -> &'static str
fn short_type_path() -> &'static str
source§fn type_ident() -> Option<&'static str>
fn type_ident() -> Option<&'static str>
source§fn crate_name() -> Option<&'static str>
fn crate_name() -> Option<&'static str>
source§impl Typed for DualAxisDatawhere
Vec2: FromReflect,
impl Typed for DualAxisDatawhere
Vec2: FromReflect,
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
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T
[ShaderType
] for self
. When used in [AsBindGroup
]
derives, it is safe to assume that all images in self
exist.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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DynamicTypePath for Twhere
T: TypePath,
impl<T> DynamicTypePath for Twhere
T: TypePath,
§fn reflect_type_path(&self) -> &str
fn reflect_type_path(&self) -> &str
TypePath::type_path
].§fn reflect_short_type_path(&self) -> &str
fn reflect_short_type_path(&self) -> &str
TypePath::short_type_path
].§fn reflect_type_ident(&self) -> Option<&str>
fn reflect_type_ident(&self) -> Option<&str>
TypePath::type_ident
].§fn reflect_crate_name(&self) -> Option<&str>
fn reflect_crate_name(&self) -> Option<&str>
TypePath::crate_name
].§fn reflect_module_path(&self) -> Option<&str>
fn reflect_module_path(&self) -> Option<&str>
TypePath::module_path
].§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given [World
].§impl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
§impl<T> GetPath for Twhere
T: Reflect + ?Sized,
impl<T> GetPath for Twhere
T: Reflect + ?Sized,
§fn reflect_path<'p>(
&self,
path: impl ReflectPath<'p>
) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more§fn reflect_path_mut<'p>(
&mut self,
path: impl ReflectPath<'p>
) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read more