Struct ludomath::vec2d::Rotation
[−]
[src]
#[repr(C)]pub struct Rotation { pub cos: f32, pub sin: f32, }
Represents a 2D rotation or direction.
Stores the sine and cosine of the angle of rotation, which makes the rotation faster if the same angle is used multiple times. The drawbacks are memory usage, and that combining multiple rotations is more expensive.
Fields
cos: f32
The cosine of the angle.
sin: f32
The sine of the angle.
Methods
impl Rotation
[src]
pub fn new_in_direction(dir: Vector) -> Rotation
[src]
Constructs a rotation from the direction of a vector.
The angle of the rotation is the angle from the positive x-axis to the vector.
pub fn new_rad(angle: f32) -> Rotation
[src]
Constructs a rotation of a specified angle, in radians.
pub fn new_deg(angle: f32) -> Rotation
[src]
Constructs a rotation of a specified angle, in degrees.
pub fn between(from: Vector, to: Vector) -> Rotation
[src]
Gets the rotation from one vector to another.
Rotating the first vector by the returned rotation yields a vector with the same direction as the second vector.
pub fn negate(self) -> Rotation
[src]
Negates the angle of a rotation.
pub fn add(self, other: Rotation) -> Rotation
[src]
Adds the angles of two rotations together.
pub fn sub(self, other: Rotation) -> Rotation
[src]
Subtracts the angle of one rotation from another.
Equivalent to self.add(other.negate())
.
pub fn angle_rad(self) -> f32
[src]
Returns the angle of rotation, in radians.
Return values are contained in (-τ/2, τ/2], aka. (-π, π].
pub fn angle_deg(self) -> f32
[src]
Returns the angle of rotation, in degrees.
Return values are approximately contained in (-180, 180].
pub fn to_vector(self) -> Vector
[src]
Converts the rotation to a unit vector.
pub fn slerp(self, other: Rotation, t: f32) -> Rotation
[src]
Linearly interpolates the angle between two rotations.
The angle moves between the endpoints at contant speed.
Like the other lerp functions, works even for t outside [0, 1].
Fairly slow, like the analogous common quaternion slerp
function.
pub fn nlerp(self, other: Rotation, t: f32) -> Rotation
[src]
Quickly interpolates between two rotations.
Significantly faster than slerp, but doesn't have constant angle speed. This gets jerkier the further the two rotations are from eachother.
Treats the rotations as direction vectors, linearly interpolates between them, and normalizes the result to a new direction vector, which is used as the new rotation.
Trait Implementations
impl Clone for Rotation
[src]
fn clone(&self) -> Rotation
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Rotation
[src]
impl PartialEq for Rotation
[src]
fn eq(&self, __arg_0: &Rotation) -> bool
[src]
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Rotation) -> bool
[src]
This method tests for !=
.