Struct Basis

Source
#[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.

§All matrix types

DimensionOrthogonal basisAffine transformProjective transform
2DTransform2D (2x3)
3DBasis (3x3)Transform3D (3x4)Projection (4x4)

§Godot docs

Basis (stable)

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§

Source§

impl Basis

Source

pub const IDENTITY: Basis

The identity basis, with no rotation or scaling applied.

Godot equivalent: Basis.IDENTITY

Source

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

Source

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

Source

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

Source

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.

Source

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

Create a new basis from 3 column vectors.

Source

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)

Source

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

Create a diagonal matrix from the given values.

Source

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

Create a diagonal matrix from the given values.

_Godot equivalent: Basis.from_scale(Vector3 scale)

Source

pub fn from_quaternion(quat: Quaternion) -> Basis

Create a Basis from a Quaternion.

Godot equivalent: Basis(Quaternion from)

Source

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)

Source

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

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

Source

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

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

Source

pub fn get_quaternion(&self) -> Quaternion

Creates a Quaternion representing the same rotation as this basis.

Godot equivalent: Basis.get_rotation_quaternion()

Source

pub fn get_scale(&self) -> Vector3

Returns the scale of the matrix.

Godot equivalent: Basis.get_scale()

Source

pub fn get_euler(&self) -> Vector3

Returns the rotation of the matrix in euler angles, with the order YXZ.

See get_euler_with() for custom angle orders.

Source

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

Returns the rotation of the matrix in euler angles.

The order of the angles are given by order. To use the default order YXZ, see get_euler().

Godot equivalent: Basis.get_euler()

Source

pub fn determinant(&self) -> f32

Returns the determinant of the matrix.

Godot equivalent: Basis.determinant()

Source

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

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

Godot equivalent: Basis.scaled()

Source

pub fn inverse(&self) -> Basis

Returns the inverse of the matrix.

Godot equivalent: Basis.inverse()

Source

pub fn transposed(&self) -> Basis

Returns the transposed version of the matrix.

Godot equivalent: Basis.transposed()

Source

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

Source

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

Source

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

Source

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

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

Godot equivalent: Basis.tdotx()

Source

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

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

Godot equivalent: Basis.tdoty()

Source

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

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

Godot equivalent: Basis.tdotz()

Source

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

Source

pub fn col_a(&self) -> Vector3

Returns the first column of the matrix,

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

Source

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

Set the values of the first column of the matrix.

Source

pub fn col_b(&self) -> Vector3

Returns the second column of the matrix,

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

Source

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

Set the values of the second column of the matrix.

Source

pub fn col_c(&self) -> Vector3

Returns the third column of the matrix,

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

Source

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

Set the values of the third column of the matrix.

Trait Implementations§

Source§

impl ApproxEq for Basis

Source§

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

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

Source§

impl Clone for Basis

Source§

fn clone(&self) -> Basis

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 Basis

Source§

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

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

impl Default for Basis

Source§

fn default() -> Basis

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

impl Display for Basis

Source§

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

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

impl DynamicSend for Basis

Source§

impl Export for Basis

Source§

fn export_hint() -> PropertyHintInfo

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

impl From<Basis> for Transform3D

Source§

fn from(basis: Basis) -> Transform3D

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

Source§

impl FromGodot for Basis

Source§

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

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

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

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

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

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

fn from_variant(variant: &Variant) -> Self

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

impl GodotConvert for Basis

Source§

type Via = Basis

The type through which Self is represented in Godot.
Source§

impl IntoDynamicSend for Basis

Source§

impl Mul<Vector3> for Basis

Source§

type Output = Vector3

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul<f32> for Basis

Source§

type Output = Basis

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl Mul for Basis

Source§

type Output = Basis

The resulting type after applying the * operator.
Source§

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

Performs the * operation. Read more
Source§

impl MulAssign<f32> for Basis

Source§

fn mul_assign(&mut self, rhs: f32)

Performs the *= operation. Read more
Source§

impl ParamType for Basis

Source§

type ArgPassing = ByValue

Source§

fn owned_to_arg(self) -> impl AsArg<Self>

👎Deprecated since 0.3.2: This method is no longer needed and will be removed in 0.4
Source§

impl PartialEq for Basis

Source§

fn eq(&self, other: &Basis) -> 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 ToGodot for Basis

Source§

type ToVia<'v> = <Basis as GodotConvert>::Via

Target type of to_godot(), which can differ from Via for pass-by-reference types. Read more
Source§

fn to_godot(&self) -> <Basis as ToGodot>::ToVia<'_>

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

fn to_variant(&self) -> Variant

Converts this type to a Variant.
Source§

impl Var for Basis

Source§

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

Source§

fn set_property(&mut self, value: <Basis as GodotConvert>::Via)

Source§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
Source§

impl XformInv<Vector3> for Basis

Source§

fn xform_inv(&self, rhs: Vector3) -> Vector3

Inversely transforms given Vector3 by this basis, under the assumption that the basis is orthonormal (i.e. rotation/reflection is fine, scaling/skew is not).

Since given basis is assumed to be orthonormal (i.e. it is both orthogonal – with all axis perpendicular to each other – and all the axis are normalized), basis.transposed() (matrix flipped over its diagonal) is equal to basis.inverse() (i.e. basis * basis.transposed() == basis * basis.inverse() == Basis::Identity), thus basis.xform_inv(vector) is equivalent both to basis.transposed() * vector and basis.inverse() * vector.

See Basis::transposed() and Godot docs (stable) for Basis with following Matrices and Transform tutorial.

For transforming by inverse of a non-orthonormal basis (e.g. with scaling) basis.inverse() * vector can be used instead. See Basis::inverse().

Godot equivalent: vector * basis

Source§

impl ArrayElement for Basis

Source§

impl BuiltinExport for Basis

Source§

impl Copy for Basis

Source§

impl GodotType for Basis

Source§

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> AsArg<T> for T
where T: ToGodot + ParamType<ArgPassing = ByValue>,

Source§

fn into_arg<'r>(self) -> CowArg<'r, T>
where T: 'r,

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

Source§

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

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.