Struct gamemath::Quat[][src]

pub struct Quat {
    pub x: f32,
    pub y: f32,
    pub z: f32,
    pub w: f32,
}

A quaternion data type used for representing spatial rotation in a 3D enviornment.

Fields

The X/first component of the quaternion.

The Y/first component of the quaternion.

The Z/first component of the quaternion.

The W/first component of the quaternion.

Methods

impl Quat
[src]

Constructs an identity quaternion.

Examples

use gamemath::Quat;

let q = Quat::identity();

assert_eq!(q, (0.0, 0.0, 0.0, 1.0).into());

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());

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());

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());

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);

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);

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());

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());

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]

Performs the conversion.

impl Copy for Quat
[src]

impl Clone for Quat
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Quat
[src]

Formats the value using the given formatter. Read more

impl PartialEq for Quat
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Default for Quat
[src]

Returns the "default value" for a type. Read more

impl From<f32> for Quat
[src]

Performs the conversion.

impl From<Vec4<f32>> for Quat
[src]

Performs the conversion.

impl From<(f32, f32, f32, f32)> for Quat
[src]

Performs the conversion.

impl From<[f32; 4]> for Quat
[src]

Performs the conversion.

impl Mul<Quat> for Quat
[src]

The resulting type after applying the * operator.

Performs the * operation.

impl MulAssign<Quat> for Quat
[src]

Performs the *= operation.

impl Add<Quat> for Quat
[src]

The resulting type after applying the + operator.

Performs the + operation.

impl AddAssign<Quat> for Quat
[src]

Performs the += operation.

Auto Trait Implementations

impl Send for Quat

impl Sync for Quat