Struct Quaternion

Source
pub struct Quaternion(/* private fields */);

Implementations§

Source§

impl Quaternion

Source

pub fn dot_product(&self, b: &Quaternion) -> f32

§b

A Quaternion

Source

pub fn get_rotation_angle(&self) -> f32

Source

pub fn get_rotation_axis(&self) -> f32

§vector3

an allocated 3-float array

Source

pub fn init(&mut self, angle: f32, x: f32, y: f32, z: f32)

Initializes a quaternion that rotates angle degrees around the axis vector (x, y, z). The axis vector does not need to be normalized.

§angle

The angle you want to rotate around the given axis

§x

The x component of your axis vector about which you want to rotate.

§y

The y component of your axis vector about which you want to rotate.

§z

The z component of your axis vector about which you want to rotate.

Source

pub fn init_from_angle_vector(&mut self, angle: f32, axis3f: &[f32; 3])

Initializes a quaternion that rotates angle degrees around the given axis vector. The axis vector does not need to be normalized.

§angle

The angle to rotate around axis3f

§axis3f

your 3 component axis vector about which you want to rotate.

Source

pub fn init_from_array(&mut self, array: &[f32])

Initializes a [w (x, y,z)] quaternion directly from an array of 4 floats: [w,x,y,z].

§array

An array of 4 floats w,(x,y,z)

Source

pub fn init_from_euler(&mut self, euler: &Euler)

§euler

A Euler with which to initialize the quaternion

Source

pub fn init_from_matrix(&mut self, matrix: &Matrix)

Initializes a quaternion from a rotation matrix.

§matrix

A rotation matrix with which to initialize the quaternion

Source

pub fn init_from_quaternion(&mut self, src: &mut Quaternion)

§src

A Quaternion with which to initialize self

Source

pub fn init_from_x_rotation(&mut self, angle: f32)

XXX: check which direction this rotates

§angle

The angle to rotate around the x axis

Source

pub fn init_from_y_rotation(&mut self, angle: f32)

§angle

The angle to rotate around the y axis

Source

pub fn init_from_z_rotation(&mut self, angle: f32)

§angle

The angle to rotate around the z axis

Source

pub fn init_identity(&mut self)

Initializes the quaternion with the canonical quaternion identity [1 (0, 0, 0)] which represents no rotation. Multiplying a quaternion with this identity leaves the quaternion unchanged.

You might also want to consider using cogl_get_static_identity_quaternion.

Source

pub fn invert(&mut self)

Source

pub fn multiply(&mut self, left: &Quaternion, right: &Quaternion)

This combines the rotations of two quaternions into self. The operation is not commutative so the order is important because AxB != BxA. Cogl follows the standard convention for quaternions here so the rotations are applied right to left. This is similar to the combining of matrices.

<note>It is possible to multiply the a quaternion in-place, so self can be equal to a but can’t be equal to b.</note>

§left

The second Quaternion rotation to apply

The first Quaternion rotation to apply

Source

pub fn nlerp(&mut self, a: &Quaternion, b: &Quaternion, t: f32)

Performs a normalized linear interpolation between two quaternions. That is it does a linear interpolation of the quaternion components and then normalizes the result. This will follow the shortest arc between the two orientations (just like the slerp function) but will not progress at a constant speed. Unlike slerp nlerp is commutative which is useful if you are blending animations together. (I.e. nlerp (tmp, a, b) followed by nlerp (result, tmp, d) is the same as nlerp (tmp, a, d) followed by nlerp (result, tmp, b)). Finally nlerp is cheaper than slerp so it can be a good choice if you don’t need the constant speed property of the slerp function.

Notable properties: <itemizedlist> <listitem> commutative: Yes </listitem> <listitem> constant velocity: No </listitem> <listitem> torque minimal (travels along the surface of the 4-sphere): Yes </listitem> <listitem> faster than Quaternion::slerp </listitem> </itemizedlist>

§a

The first Quaternion

§b

The second Quaternion

§t

The factor in the range [0,1] used to interpolate between quaterion a and b.

Source

pub fn normalize(&mut self)

Source

pub fn pow(&mut self, exponent: f32)

§exponent

the exponent

Source

pub fn slerp(&mut self, a: &Quaternion, b: &Quaternion, t: f32)

Performs a spherical linear interpolation between two quaternions.

Noteable properties: <itemizedlist> <listitem> commutative: No </listitem> <listitem> constant velocity: Yes </listitem> <listitem> torque minimal (travels along the surface of the 4-sphere): Yes </listitem> <listitem> more expensive than Quaternion::nlerp </listitem> </itemizedlist>

§a

The first Quaternion

§b

The second Quaternion

§t

The factor in the range [0,1] used to interpolate between quaternion a and b.

Source

pub fn squad( &mut self, prev: &Quaternion, a: &Quaternion, b: &Quaternion, next: &Quaternion, t: f32, )

§prev

A Quaternion used before a

§a

The first Quaternion

§b

The second Quaternion

§next

A Quaternion that will be used after b

§t

The factor in the range [0,1] used to interpolate between quaternion a and b.

Trait Implementations§

Source§

impl Clone for Quaternion

Source§

fn clone(&self) -> Quaternion

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Quaternion

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for Quaternion

Source§

fn cmp(&self, other: &Quaternion) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Quaternion

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Quaternion

Source§

fn partial_cmp(&self, other: &Quaternion) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StaticType for Quaternion

Source§

fn static_type() -> Type

Returns the type identifier of Self.
Source§

impl Eq for Quaternion

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

Source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToValue for T
where T: SetValue + ?Sized,

Source§

fn to_value(&self) -> Value

Returns a Value clone of self.
Source§

fn to_value_type(&self) -> Type

Returns the type identifer of self. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.