Struct leafwing_input_manager::orientation::Rotation
source · [−]pub struct Rotation { /* private fields */ }
Expand description
A discretized 2-dimensional rotation
Internally, these are stored in tenths of a degree, and so can be cleanly added and reversed without accumulating error.
Example
use leafwing_input_manager::orientation::{Rotation, Direction, Orientation};
use core::f32::consts::{FRAC_PI_2, PI, TAU};
let east = Rotation::from_radians(0.0);
let north = Rotation::from_radians(FRAC_PI_2);
let west = Rotation::from_radians(PI);
Rotation::default().assert_approx_eq(Rotation::from_radians(0.0));
Rotation::default().assert_approx_eq(Rotation::from_radians(TAU));
Rotation::default().assert_approx_eq(500.0 * Rotation::from_radians(TAU));
(north + north).assert_approx_eq(west);
(west - east).assert_approx_eq(west);
(2.0 * north).assert_approx_eq(west);
(west / 2.0).assert_approx_eq(north);
north.assert_approx_eq(Rotation::NORTH);
Direction::from(west).assert_approx_eq(Direction::WEST);
Implementations
sourceimpl Rotation
impl Rotation
sourcepub const fn new(deci_degrees: u16) -> Rotation
pub const fn new(deci_degrees: u16) -> Rotation
Creates a new Rotation
from a whole number of tenths of a degree
Measured clockwise from midnight.
sourcepub const fn deci_degrees(&self) -> u16
pub const fn deci_degrees(&self) -> u16
Returns the exact internal mesaurement, stored in tenths of a degree
Measured clockwise from midnight (x=0, y=1). 3600 make up a full circle.
sourceimpl Rotation
impl Rotation
sourcepub const FULL_CIRCLE: u16 = 3_600u16
pub const FULL_CIRCLE: u16 = 3_600u16
The number of deci-degrees that make up a full circle
sourceimpl Rotation
impl Rotation
sourcepub fn from_xy(xy: Vec2) -> Result<Rotation, NearlySingularConversion>
pub fn from_xy(xy: Vec2) -> Result<Rotation, NearlySingularConversion>
Constructs a Rotation
from an (x,y) Euclidean coordinate
If both x and y are nearly 0 (the magnitude is less than EPSILON
),
[Err(NearlySingularConversion)
] will be returned instead.
Example
use bevy::math::Vec2;
use leafwing_input_manager::orientation::Rotation;
assert_eq!(Rotation::from_xy(Vec2::new(0.0, 1.0)), Ok(Rotation::NORTH));
sourcepub fn from_radians(radians: impl Into<f32>) -> Rotation
pub fn from_radians(radians: impl Into<f32>) -> Rotation
Construct a Direction
from radians,
measured counterclockwise from the positive x axis
sourcepub fn into_radians(self) -> f32
pub fn into_radians(self) -> f32
Converts this direction into radians, measured counterclockwise from the positive x axis
sourcepub fn from_degrees(degrees: impl Into<f32>) -> Rotation
pub fn from_degrees(degrees: impl Into<f32>) -> Rotation
Construct a Direction
from degrees, measured counterclockwise from the positive x axis
sourcepub fn into_degrees(self) -> f32
pub fn into_degrees(self) -> f32
Converts this direction into degrees, measured counterclockwise from the positive x axis
Trait Implementations
sourceimpl AddAssign<Rotation> for Rotation
impl AddAssign<Rotation> for Rotation
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the +=
operation. Read more
sourceimpl Orientation for Rotation
impl Orientation for Rotation
sourcefn assert_approx_eq(self, other: impl Orientation)
fn assert_approx_eq(self, other: impl Orientation)
Asserts that self
is approximately equal to other
Read more
sourcefn rotation_direction(&self, target: Self) -> RotationDirection
fn rotation_direction(&self, target: Self) -> RotationDirection
Which RotationDirection
is the shortest to rotate towards to reach target
? Read more
sourcefn rotate_towards(
&mut self,
target_orientation: Self,
max_rotation: Option<Rotation>
)
fn rotate_towards(
&mut self,
target_orientation: Self,
max_rotation: Option<Rotation>
)
Rotates self
towards target_orientation
by up to max_rotation
Read more
sourceimpl PartialOrd<Rotation> for Rotation
impl PartialOrd<Rotation> for Rotation
sourcefn partial_cmp(&self, other: &Rotation) -> Option<Ordering>
fn partial_cmp(&self, other: &Rotation) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SubAssign<Rotation> for Rotation
impl SubAssign<Rotation> for Rotation
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the -=
operation. Read more
sourceimpl TryFrom<Vec2> for Rotation
impl TryFrom<Vec2> for Rotation
type Error = NearlySingularConversion
type Error = NearlySingularConversion
The type returned in the event of a conversion error.
impl Copy for Rotation
impl Eq for Rotation
impl StructuralEq for Rotation
impl StructuralPartialEq for Rotation
Auto Trait Implementations
impl RefUnwindSafe for Rotation
impl Send for Rotation
impl Sync for Rotation
impl Unpin for Rotation
impl UnwindSafe for Rotation
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> DynHash for T where
T: DynEq + Hash,
impl<T> DynHash for T where
T: DynEq + Hash,
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.
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>
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