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)
+= operation. Read moresourceimpl Orientation for Rotation
impl Orientation for Rotation
sourcefn assert_approx_eq(self, other: impl Orientation)
fn assert_approx_eq(self, other: impl Orientation)
sourcefn rotation_direction(&self, target: Self) -> RotationDirection
fn rotation_direction(&self, target: Self) -> RotationDirection
sourcefn rotate_towards(
&mut self,
target_orientation: Self,
max_rotation: Option<Rotation>
)
fn rotate_towards(
&mut self,
target_orientation: Self,
max_rotation: Option<Rotation>
)
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>
1.0.0 · sourceconst fn le(&self, other: &Rhs) -> bool
const fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresourceimpl SubAssign<Rotation> for Rotation
impl SubAssign<Rotation> for Rotation
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moresourceimpl TryFrom<Vec2> for Rotation
impl TryFrom<Vec2> for Rotation
type Error = NearlySingularConversion
type Error = NearlySingularConversion
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 Twhere
U: ShaderType,
&'a T: for<'a> Into<U>,
impl<T, U> AsBindGroupShaderType<U> for Twhere
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
T [ShaderType] for self. When used in [AsBindGroup]
derives, it is safe to assume that all images in self exist. Read moresourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn 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, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
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 morefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read morefn 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. Read morefn 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. Read moreimpl<T> DynHash for Twhere
T: DynEq + Hash,
impl<T> DynHash for Twhere
T: DynEq + Hash,
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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]