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§
source§impl 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.
source§impl 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
source§impl 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§
source§impl AddAssign<Rotation> for Rotation
impl AddAssign<Rotation> for Rotation
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+= operation. Read moresource§impl Orientation for Rotation
impl Orientation for Rotation
source§fn assert_approx_eq(self, other: impl Orientation)
fn assert_approx_eq(self, other: impl Orientation)
source§fn rotation_direction(&self, target: Self) -> RotationDirection
fn rotation_direction(&self, target: Self) -> RotationDirection
source§impl PartialEq<Rotation> for Rotation
impl PartialEq<Rotation> for Rotation
source§impl PartialOrd<Rotation> for Rotation
impl PartialOrd<Rotation> for Rotation
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moresource§impl SubAssign<Rotation> for Rotation
impl SubAssign<Rotation> for Rotation
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-= operation. Read moresource§impl 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: &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.§impl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere C: Component,
fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> Cwhere F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a, Aligned>,
fn get_components( self, func: &mut impl FnMut(StorageType, OwningPtr<'_, Aligned>) )
§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.§fn 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.§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.source§impl<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,
source§fn 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]