Struct leafwing_input_manager::orientation::Rotation
source · [−]pub struct Rotation { /* private fields */ }
Expand description
A discretized 2-dimensional rotation
Internally, these are stored in normalized 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::{PI, TAU};
let three_o_clock = Rotation::from_degrees(90.0);
let six_o_clock = Rotation::from_radians(PI);
let nine_o_clock = Rotation::from_degrees(-90.0);
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));
(three_o_clock + six_o_clock).assert_approx_eq(nine_o_clock);
(nine_o_clock - three_o_clock).assert_approx_eq(six_o_clock);
(2.0 * nine_o_clock).assert_approx_eq(six_o_clock);
(six_o_clock / 2.0).assert_approx_eq(three_o_clock);
six_o_clock.assert_approx_eq(Rotation::SOUTH);
Direction::from(nine_o_clock).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
sourcepub const EAST: Rotation = Rotation { deci_degrees: 900 }
pub const EAST: Rotation = Rotation { deci_degrees: 900 }
The direction that points straight right
sourcepub const SOUTH: Rotation = Rotation { deci_degrees: 1800 }
pub const SOUTH: Rotation = Rotation { deci_degrees: 1800 }
The direction that points straight down
sourcepub const WEST: Rotation = Rotation { deci_degrees: 2700 }
pub const WEST: Rotation = Rotation { deci_degrees: 2700 }
The direction that points straight left
sourcepub const NORTHEAST: Rotation = Rotation { deci_degrees: 450 }
pub const NORTHEAST: Rotation = Rotation { deci_degrees: 450 }
The direction that points halfway between up and right
sourcepub const SOUTHEAST: Rotation = Rotation { deci_degrees: 1350 }
pub const SOUTHEAST: Rotation = Rotation { deci_degrees: 1350 }
The direction that points halfway between down and right
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 clockwise from midnight
sourcepub fn into_radians(self) -> f32
pub fn into_radians(self) -> f32
Converts this direction into radians, measured clockwise from midnight
sourcepub fn from_degrees(degrees: impl Into<f32>) -> Rotation
pub fn from_degrees(degrees: impl Into<f32>) -> Rotation
Construct a Direction
from degrees, measured clockwise from midnight
sourcepub fn into_degrees(self) -> f32
pub fn into_degrees(self) -> f32
Converts this direction into degrees, measured clockwise from midnight
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 From<GlobalTransform> for Rotation
impl From<GlobalTransform> for Rotation
sourcefn from(transform: GlobalTransform) -> Self
fn from(transform: GlobalTransform) -> Self
Converts to this type from the input type.
sourceimpl From<Rotation> for GlobalTransform
impl From<Rotation> for GlobalTransform
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
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
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.
sourceimpl<T> FromWorld for T where
T: Default,
impl<T> FromWorld for T where
T: Default,
sourcefn 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> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
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>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
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