#[repr(C)]
pub struct Basis { pub elements: [Vector3; 3], }
Expand description

A 3x3 matrix, typically used as an orthogonal basis for Transform.

The basis vectors are the column vectors of the matrix, while the elements field represents the row vectors.

See also Basis in the Godot API doc.

Fields§

§elements: [Vector3; 3]

Matrix rows. These are not the basis vectors!

This is a transposed view for performance.
To read basis vectors, see a(), b(), c().
To write them, see set_a(), set_b(), set_c().

Implementations§

source§

impl Basis

source

pub const IDENTITY: Self = _

The identity basis. Basis vectors are unit vectors along each axis X, Y and Z.

Equivalent to calling Basis::default().

source

pub const FLIP_X: Self = _

The basis that will flip something along the X axis when used in a transformation.

source

pub const FLIP_Y: Self = _

The basis that will flip something along the Y axis when used in a transformation.

source

pub const FLIP_Z: Self = _

The basis that will flip something along the Z axis when used in a transformation.

source

pub const fn from_basis_vectors(a: Vector3, b: Vector3, c: Vector3) -> Self

Constructs a basis matrix from 3 linearly independent basis vectors (matrix columns).

This is the typical way to construct a basis. If you want to fill in the elements one-by-one, consider using Self::from_rows().

source

pub const fn from_rows(
    x_components: Vector3,
    y_components: Vector3,
    z_components: Vector3
) -> Self

Creates a basis from 3 row vectors. These are not basis vectors.

This constructor is mostly useful if you want to write matrix elements in matrix syntax:

let basis = Basis::from_rows(
    Vector3::new(a.x, b.x, c.x),
    Vector3::new(a.y, b.y, c.y),
    Vector3::new(a.z, b.z, c.z),
);

The vectors a, b and c are the basis vectors.
In this particular case, you could also use Self::from_basis_vectors(a, b, c) instead.

source

pub const fn from_diagonal(scale: Vector3) -> Self

Creates a diagonal matrix from the given vector.

Can be used as a basis for a scaling transform. Each component of scale represents the scale factor in the corresponding direction.

source

pub fn from_euler(euler_angles: Vector3) -> Self

Creates a rotation matrix from Euler angles.

The angle vector has XYZ components. However, the angles are applied in YXZ convention: first Z, then X, and Y last.

source

pub fn from_quat(quat: Quat) -> Self

Constructs a pure rotation basis matrix from the given quaternion.

source

pub fn from_axis_angle(axis: Vector3, phi: f32) -> Self

Rotation matrix from axis and angle.

See https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle

Panics

If axis is not normalized.

source

pub fn inverse(&self) -> Self

Returns the inverse of the matrix.

Panics

If the determinant of self is zero.

source

pub fn inverted(&self) -> Self

👎Deprecated: Use inverse instead.
source

pub fn slerp(&self, other: &Basis, weight: f32) -> Self

Returns linear interpolation on a sphere between two basis by weight amount (on the range of 0.0 to 1.0).

source

pub fn lerp(&self, other: &Basis, weight: f32) -> Self

Returns linear interpolation between two basis by weight amount (on the range of 0.0 to 1.0).

source

pub fn transposed(&self) -> Self

Returns the transposed version of the matrix.

source

pub fn determinant(&self) -> f32

Returns the determinant of the matrix.

source

pub fn orthogonalized(&self) -> Self

source

pub fn orthonormalized(&self) -> Self

Returns an orthonormalized version of the matrix: 3 orthogonal basis vectors of unit length.

source

pub fn is_equal_approx(&self, other: &Basis) -> bool

Returns true if self and other are approximately equal.

source

pub fn rotated(&self, axis: Vector3, phi: f32) -> Self

Multiplies the matrix from left with the rotation matrix: M -> R·M

The main use of Basis is as a Transform.basis, which is used as the transformation matrix of the 3D object. rotated() here refers to rotation of the object (which is R * self), not the matrix itself.

source

pub fn scale(&self) -> Vector3

Returns the scale of the matrix.

source

pub fn scaled(&self, scale: Vector3) -> Self

Introduce an additional scaling specified by the given 3D scaling factor.

source

pub fn to_quat(&self) -> Quat

Converts matrix into a quaternion.

Quaternions are frequently used in 3D graphics, because they enable easy and cheap interpolation. However, they are less human-readable. For Euler angles, see Basis::to_euler().

Panics

If self is not normalized.

source

pub fn to_euler(&self) -> Vector3

Returns the Basis’s rotation in the form of Euler angles.

In the YXZ convention: first Z, then X, and Y last.

The returned Vector3 contains the rotation angles in the format (X angle, Y angle, Z angle).

See Basis::to_quat if you need a quaternion instead.

source

pub fn xform(&self, v: Vector3) -> Vector3

Returns a vector transformed (multiplied) by the matrix.

source

pub fn xform_inv(&self, v: Vector3) -> Vector3

Returns a vector transformed (multiplied) by the transposed matrix.

Note: This results in a multiplication by the inverse of the matrix only if it represents a rotation-reflection.

source

pub fn a(&self) -> Vector3

Get the 1st basis vector (first column vector of the matrix).

source

pub fn set_a(&mut self, v: Vector3)

Set the 1st basis vector (first column vector of the matrix).

source

pub fn b(&self) -> Vector3

Get the 2nd basis vector (second column vector of the matrix).

source

pub fn set_b(&mut self, v: Vector3)

Set the 2nd basis vector (second column vector of the matrix).

source

pub fn c(&self) -> Vector3

Get the 3rd basis vector (third column vector of the matrix).

source

pub fn set_c(&mut self, v: Vector3)

Set the 3rd basis vector (third column vector of the matrix).

Trait Implementations§

source§

impl Clone for Basis

source§

fn clone(&self) -> Basis

Returns a copy 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 CoerceFromVariant for Basis

source§

impl Debug for Basis

source§

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

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

impl Default for Basis

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Export for Basis

§

type Hint = NoHint

A type-specific hint type that is valid for the type being exported. Read more
source§

fn export_info(_hint: Option<Self::Hint>) -> ExportInfo

Returns ExportInfo given an optional typed hint.
source§

impl FromVariant for Basis

source§

impl Mul<Basis> for Basis

§

type Output = Basis

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self) -> Self

Performs the * operation. Read more
source§

impl Mul<Vector3> for Basis

§

type Output = Vector3

The resulting type after applying the * operator.
source§

fn mul(self, rhs: Self::Output) -> Self::Output

Performs the * operation. Read more
source§

impl PartialEq<Basis> for Basis

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl ToVariant for Basis

source§

impl Copy for Basis

source§

impl StructuralPartialEq for Basis

Auto Trait Implementations§

§

impl RefUnwindSafe for Basis

§

impl Send for Basis

§

impl Sync for Basis

§

impl Unpin for Basis

§

impl UnwindSafe for Basis

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere
    T: Clone,

§

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, U> TryFrom<U> for Twhere
    U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.