Struct godot::builtin::Basis

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

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

Indexing into a Basis is done in row-major order. So mat[1] would return the first row and not the first column/basis vector. This means that indexing into the matrix happens in the same order it usually does in math, except that we index starting at 0.

The basis vectors are the columns of the matrix, whereas the rows field represents the row vectors.

Note that the names of the column vectors here are a, b, and c, which differs from Godot’s convention of x, y, and z. This is because columns are the basis vectors of the transform, while rows represent the X/Y/Z coordinates of each vector. Although basis vectors are the transformed unit vectors of X/Y/Z axes, they have no direct relation to those axes in the transformed coordinate system. Thus, an independent notion of a, b, c does not suggest such a relation. Furthermore, there are sometimes expressions such as x.x, x.y, y.x etc. They are typically hard to read and error-prone to write. Having a.x, a.y, b.x makes things more understandable.

Fields§

§rows: [Vector3; 3]

The rows of the matrix. These are not the basis vectors.

To access the basis vectors see col_a(), set_col_a(), col_b(), set_col_b(), col_c, set_col_c().

Implementations§

§

impl Basis

pub const IDENTITY: Basis = _

The identity basis, with no rotation or scaling applied.

Godot equivalent: Basis.IDENTITY

pub const FLIP_X: Basis = _

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

Godot equivalent: Basis.FLIP_X

pub const FLIP_Y: Basis = _

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

Godot equivalent: Basis.FLIP_Y

pub const FLIP_Z: Basis = _

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

Godot equivalent: Basis.FLIP_Z

pub const fn from_rows(x: Vector3, y: Vector3, z: Vector3) -> Basis

Create a new basis from 3 row vectors. These are not basis vectors.

pub const fn from_cols(a: Vector3, b: Vector3, c: Vector3) -> Basis

Create a new basis from 3 column vectors.

pub fn from_axis_angle(axis: Vector3, angle: f32) -> Basis

Create a Basis from an axis and angle.

Godot equivalent: Basis(Vector3 axis, float angle)

pub const fn from_diagonal(x: f32, y: f32, z: f32) -> Basis

Create a diagonal matrix from the given values.

pub const fn from_scale(scale: Vector3) -> Basis

Create a diagonal matrix from the given values.

_Godot equivalent: Basis.from_scale(Vector3 scale)

pub fn from_quat(quat: Quaternion) -> Basis

Create a Basis from a Quaternion.

Godot equivalent: Basis(Quaternion from)

pub fn from_euler(order: EulerOrder, angles: Vector3) -> Basis

Create a Basis from three angles a, b, and c interpreted as Euler angles according to the given EulerOrder.

Godot equivalent: Basis.from_euler(Vector3 euler, int order)

pub fn new_looking_at( target: Vector3, up: Vector3, use_model_front: bool, ) -> Basis

Available on since_api="4.1" only.

If use_model_front is true, the +Z axis (asset front) is treated as forward (implies +X is left) and points toward the target position. By default, the -Z axis (camera forward) is treated as forward (implies +X is right).

Godot equivalent: Basis.looking_at()

pub fn to_cols(&self) -> [Vector3; 3]

Creates a [Vector3; 3] with the columns of the Basis.

pub fn to_quat(&self) -> Quaternion

Creates a Quaternion representing the same rotation as this basis.

Godot equivalent: Basis.get_rotation_quaternion()

pub fn scale(&self) -> Vector3

Returns the scale of the matrix.

Godot equivalent: Basis.get_scale()

pub fn to_euler(&self, order: EulerOrder) -> Vector3

Returns the rotation of the matrix in euler angles.

The order of the angles are given by order.

Godot equivalent: Basis.get_euler()

pub fn determinant(&self) -> f32

Returns the determinant of the matrix.

Godot equivalent: Basis.determinant()

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

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

Godot equivalent: Basis.scaled()

pub fn inverse(&self) -> Basis

Returns the inverse of the matrix.

Godot equivalent: Basis.inverse()

pub fn transposed(&self) -> Basis

Returns the transposed version of the matrix.

Godot equivalent: Basis.transposed()

pub fn orthonormalized(&self) -> Basis

⚠️ Returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). This performs a Gram-Schmidt orthonormalization on the basis of the matrix.

§Panics

If the determinant of the matrix is 0.

Godot equivalent: Basis.orthonormalized()

pub fn rotated(&self, axis: Vector3, angle: f32) -> Basis

Introduce an additional rotation around the given axis by angle (in radians). The axis must be a normalized vector.

Godot equivalent: Basis.rotated()

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

Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.

Godot equivalent: Basis.slerp()

pub fn tdotx(&self, with: Vector3) -> f32

Transposed dot product with the X axis (column) of the matrix.

Godot equivalent: Basis.tdotx()

pub fn tdoty(&self, with: Vector3) -> f32

Transposed dot product with the Y axis (column) of the matrix.

Godot equivalent: Basis.tdoty()

pub fn tdotz(&self, with: Vector3) -> f32

Transposed dot product with the Z axis (column) of the matrix.

Godot equivalent: Basis.tdotz()

pub fn is_finite(&self) -> bool

Returns true if this basis is finite. Meaning each element of the matrix is not NaN, positive infinity, or negative infinity.

Godot equivalent: Basis.is_finite()

pub fn col_a(&self) -> Vector3

Returns the first column of the matrix,

Godot equivalent: Basis.x, see Basis for why it’s changed

pub fn set_col_a(&mut self, col: Vector3)

Set the values of the first column of the matrix.

pub fn col_b(&self) -> Vector3

Returns the second column of the matrix,

Godot equivalent: Basis.y, see Basis for why it’s changed

pub fn set_col_b(&mut self, col: Vector3)

Set the values of the second column of the matrix.

pub fn col_c(&self) -> Vector3

Returns the third column of the matrix,

Godot equivalent: Basis.z, see Basis for why it’s changed

pub fn set_col_c(&mut self, col: Vector3)

Set the values of the third column of the matrix.

Trait Implementations§

§

impl ApproxEq for Basis

§

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

Returns if this basis and other are approximately equal, by calling is_equal_approx on each row.

§

impl Clone for Basis

§

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
§

impl Debug for Basis

§

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

Formats the value using the given formatter. Read more
§

impl Default for Basis

§

fn default() -> Basis

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

impl Display for Basis

§

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

Formats the value using the given formatter. Read more
§

impl Export for Basis

§

fn default_export_info() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
§

impl From<Basis> for Transform3D

§

fn from(basis: Basis) -> Transform3D

Create a new transform with origin (0,0,0) from this basis.

§

impl FromGodot for Basis

§

fn try_from_godot( via: <Basis as GodotConvert>::Via, ) -> Result<Basis, ConvertError>

Converts the Godot representation to this type, returning Err on failure.
§

fn from_godot(via: Self::Via) -> Self

⚠️ Converts the Godot representation to this type. Read more
§

fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>

Performs the conversion from a Variant, returning Err on failure.
§

fn from_variant(variant: &Variant) -> Self

⚠️ Performs the conversion from a Variant. Read more
§

impl GodotConvert for Basis

§

type Via = Basis

The type through which Self is represented in Godot.
§

impl Mul<Vector3> for Basis

§

type Output = Vector3

The resulting type after applying the * operator.
§

fn mul(self, rhs: Vector3) -> <Basis as Mul<Vector3>>::Output

Performs the * operation. Read more
§

impl Mul<f32> for Basis

§

type Output = Basis

The resulting type after applying the * operator.
§

fn mul(self, rhs: f32) -> <Basis as Mul<f32>>::Output

Performs the * operation. Read more
§

impl Mul for Basis

§

type Output = Basis

The resulting type after applying the * operator.
§

fn mul(self, rhs: Basis) -> <Basis as Mul>::Output

Performs the * operation. Read more
§

impl MulAssign<f32> for Basis

§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
§

impl PartialEq for Basis

§

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.
§

impl ToGodot for Basis

§

fn to_godot(&self) -> <Basis as GodotConvert>::Via

Converts this type to the Godot type by reference, usually by cloning.
§

fn into_godot(self) -> <Basis as GodotConvert>::Via

Converts this type to the Godot type. Read more
§

fn to_variant(&self) -> Variant

Converts this type to a Variant.
§

impl TypeStringHint for Basis

§

fn type_string() -> String

Returns the representation of this type as a type string. Read more
§

impl Var for Basis

§

impl ArrayElement for Basis

§

impl Copy for Basis

§

impl GodotType for Basis

§

impl StructuralPartialEq for Basis

Auto Trait Implementations§

§

impl Freeze for Basis

§

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 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: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

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

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.