Struct gamemath::Quat [−][src]
A quaternion data type used for representing spatial rotation in a 3D enviornment.
Fields
x: f32
The X/first component of the quaternion.
y: f32
The Y/first component of the quaternion.
z: f32
The Z/first component of the quaternion.
w: f32
The W/first component of the quaternion.
Methods
impl Quat
[src]
impl Quat
pub fn identity() -> Quat
[src]
pub fn identity() -> Quat
Constructs an identity quaternion.
Examples
use gamemath::Quat; let q = Quat::identity(); assert_eq!(q, (0.0, 0.0, 0.0, 1.0).into());
pub fn rotation(radians: f32, axis: Vec3<f32>) -> Quat
[src]
pub fn rotation(radians: f32, axis: Vec3<f32>) -> Quat
Constructs a rotation quaternion from an angle and an axis.
Examples
use gamemath::{Vec3, Quat}; let q = Quat::rotation(1.0, Vec3::new(1.0, 2.0, 3.0)); assert_eq!(q, (0.12813187, 0.25626373, 0.38439557, 0.87758255).into());
pub fn rotated(&self, radians: f32, axis: Vec3<f32>) -> Quat
[src]
pub fn rotated(&self, radians: f32, axis: Vec3<f32>) -> Quat
Calculate and returns a quaternion representing the calling object rotated by an angle around an axis.
Examples
use gamemath::{Vec3, Quat}; let q = Quat::identity(); assert_eq!(q.rotated(1.0, Vec3::new(1.0, 2.0, 3.0)), (0.12813187, 0.25626373, 0.38439557, 0.87758255).into());
pub fn rotate(&mut self, radians: f32, axis: Vec3<f32>)
[src]
pub fn rotate(&mut self, radians: f32, axis: Vec3<f32>)
Applies a rotation around and axis by an angle on the calling Quat
object.
Examples
use gamemath::{Vec3, Quat}; let mut q = Quat::identity(); q.rotate(1.0, Vec3::new(1.0, 2.0, 3.0)); assert_eq!(q, (0.12813187, 0.25626373, 0.38439557, 0.87758255).into());
pub fn length_squared(&self) -> f32
[src]
pub fn length_squared(&self) -> f32
Calculates the squared length/magnitude/norm of a Quat
.
This saves an expensive square root calculation compared to calculating the actual length,
and comparing two squared lengths can therefore often be cheaper than, and yield the same
result as, computing two real lengths.
Examples
use gamemath::Quat; let q: Quat = (1.0, 2.0, 3.0, 4.0).into(); assert_eq!(q.length_squared(), 30.0);
pub fn length(&self) -> f32
[src]
pub fn length(&self) -> f32
Calculates the real length/magnitude/norm of a Quat
.
This results in an expensive square root calculation, and you might want to consider using
a squared length instead when possible.
Examples
use gamemath::Quat; let q: Quat = (1.0, 4.0, 4.0, 16.0).into(); assert_eq!(q.length(), 17.0);
pub fn normalized(&self) -> Quat
[src]
pub fn normalized(&self) -> Quat
Calculates and returns the unit quaternion representation of a Quat
.
This results in an an expensive square root calculation.
Examples
use gamemath::Quat; let q: Quat = (1.0, 2.0, 2.0, 4.0).into(); assert_eq!(q.normalized(), (0.2, 0.4, 0.4, 0.8).into());
pub fn normalize(&mut self)
[src]
pub fn normalize(&mut self)
Normalizes a Quat
into its unit quaternion representation.
This results in an an expensive square root calculation.
Examples
use gamemath::Quat; let mut q: Quat = (1.0, 2.0, 2.0, 4.0).into(); q.normalize(); assert_eq!(q, (0.2, 0.4, 0.4, 0.8).into());
pub fn extract_matrix(&self) -> Mat4
[src]
pub fn extract_matrix(&self) -> Mat4
Calculates and returns a Mat4
object representing the rotation of the calling Quat
object.
Examples
use gamemath::{Vec3, Mat4, Quat}; let q = Quat::rotation(1.0, Vec3::new(1.0, 2.0, 3.0)); assert_eq!(q.extract_matrix(), (( 0.5731379, 0.74034876, -0.35127854, 0.0), (-0.6090066, 0.67164457, 0.42190588, 0.0), ( 0.5482918, -0.027879298, 0.8358222, 0.0), ( 0.0, 0.0, 0.0, 1.0)).into());
Trait Implementations
impl From<Quat> for Mat4
[src]
impl From<Quat> for Mat4
impl Copy for Quat
[src]
impl Copy for Quat
impl Clone for Quat
[src]
impl Clone for Quat
fn clone(&self) -> Quat
[src]
fn clone(&self) -> Quat
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for Quat
[src]
impl Debug for Quat
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl PartialEq for Quat
[src]
impl PartialEq for Quat
fn eq(&self, other: &Quat) -> bool
[src]
fn eq(&self, other: &Quat) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Quat) -> bool
[src]
fn ne(&self, other: &Quat) -> bool
This method tests for !=
.
impl Default for Quat
[src]
impl Default for Quat
impl From<f32> for Quat
[src]
impl From<f32> for Quat
impl From<Vec4<f32>> for Quat
[src]
impl From<Vec4<f32>> for Quat
impl From<(f32, f32, f32, f32)> for Quat
[src]
impl From<(f32, f32, f32, f32)> for Quat
impl From<[f32; 4]> for Quat
[src]
impl From<[f32; 4]> for Quat
impl Mul<Quat> for Quat
[src]
impl Mul<Quat> for Quat
type Output = Quat
The resulting type after applying the *
operator.
fn mul(self, right: Quat) -> Quat
[src]
fn mul(self, right: Quat) -> Quat
Performs the *
operation.
impl MulAssign<Quat> for Quat
[src]
impl MulAssign<Quat> for Quat
fn mul_assign(&mut self, right: Quat)
[src]
fn mul_assign(&mut self, right: Quat)
Performs the *=
operation.
impl Add<Quat> for Quat
[src]
impl Add<Quat> for Quat
type Output = Quat
The resulting type after applying the +
operator.
fn add(self, right: Quat) -> Quat
[src]
fn add(self, right: Quat) -> Quat
Performs the +
operation.
impl AddAssign<Quat> for Quat
[src]
impl AddAssign<Quat> for Quat
fn add_assign(&mut self, right: Quat)
[src]
fn add_assign(&mut self, right: Quat)
Performs the +=
operation.