Struct leafwing_input_manager::orientation::Rotation
source · pub struct Rotation { /* private fields */ }
Expand description
A discretized 2-dimensional rotation
Internally, these are stored in millionths 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(micro_degrees: u32) -> Rotation
pub const fn new(micro_degrees: u32) -> Rotation
Creates a new Rotation
from a whole number of millionths of a degree
Measured clockwise from midnight.
sourcepub const fn micro_degrees(&self) -> u32
pub const fn micro_degrees(&self) -> u32
Returns the exact internal measurement, stored in millionths of a degree
Measured clockwise from midnight (x=0, y=1).
360_000_000
make up a full circle.
source§impl Rotation
impl Rotation
sourcepub const HALF_CIRCLE: u32 = 180_000_000u32
pub const HALF_CIRCLE: u32 = 180_000_000u32
The number of micro-degrees that make up a half circle
sourcepub const FULL_CIRCLE: u32 = 360_000_000u32
pub const FULL_CIRCLE: u32 = 360_000_000u32
The number of micro-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 const fn from_degrees_int(degrees: u32) -> Rotation
pub const fn from_degrees_int(degrees: u32) -> Rotation
Construct a Direction
from a whole number of 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 for Rotation
impl AddAssign 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 for Rotation
impl PartialEq for Rotation
source§impl PartialOrd for Rotation
impl PartialOrd 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 for Rotation
impl SubAssign 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 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<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) -> C
§impl<T> CallHasher for T
impl<T> CallHasher for 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> DynEq for T
impl<T> DynEq for T
§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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
].