#[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
Dimension | Orthogonal basis | Affine transform | Projective transform |
---|---|---|---|
2D | Transform2D (2x3) | ||
3D | Basis (3x3) | Transform3D (3x4) | Projection (4x4) |
§Godot docs
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
impl Basis
Sourcepub const IDENTITY: Basis
pub const IDENTITY: Basis
The identity basis, with no rotation or scaling applied.
Godot equivalent: Basis.IDENTITY
Sourcepub const FLIP_X: Basis
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
Sourcepub const FLIP_Y: Basis
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
Sourcepub const FLIP_Z: Basis
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
Sourcepub const fn from_rows(x: Vector3, y: Vector3, z: Vector3) -> Basis
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.
Sourcepub const fn from_cols(a: Vector3, b: Vector3, c: Vector3) -> Basis
pub const fn from_cols(a: Vector3, b: Vector3, c: Vector3) -> Basis
Create a new basis from 3 column vectors.
Sourcepub fn from_axis_angle(axis: Vector3, angle: f32) -> Basis
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)
Sourcepub const fn from_diagonal(x: f32, y: f32, z: f32) -> Basis
pub const fn from_diagonal(x: f32, y: f32, z: f32) -> Basis
Create a diagonal matrix from the given values.
Sourcepub const fn from_scale(scale: Vector3) -> Basis
pub const fn from_scale(scale: Vector3) -> Basis
Create a diagonal matrix from the given values.
_Godot equivalent: Basis.from_scale(Vector3 scale)
Sourcepub fn from_quaternion(quat: Quaternion) -> Basis
pub fn from_quaternion(quat: Quaternion) -> Basis
Create a Basis
from a Quaternion
.
Godot equivalent: Basis(Quaternion from)
Sourcepub fn from_euler(order: EulerOrder, angles: Vector3) -> Basis
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)
Sourcepub fn looking_at(target: Vector3, up: Vector3, use_model_front: bool) -> Basis
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()
Sourcepub fn get_quaternion(&self) -> Quaternion
pub fn get_quaternion(&self) -> Quaternion
Creates a Quaternion
representing the same rotation as this basis.
Godot equivalent: Basis.get_rotation_quaternion()
Sourcepub fn get_scale(&self) -> Vector3
pub fn get_scale(&self) -> Vector3
Returns the scale of the matrix.
Godot equivalent: Basis.get_scale()
Sourcepub fn get_euler(&self) -> Vector3
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.
Sourcepub fn get_euler_with(&self, order: EulerOrder) -> Vector3
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()
Sourcepub fn determinant(&self) -> f32
pub fn determinant(&self) -> f32
Returns the determinant of the matrix.
Godot equivalent: Basis.determinant()
Sourcepub fn scaled(&self, scale: Vector3) -> Basis
pub fn scaled(&self, scale: Vector3) -> Basis
Introduce an additional scaling specified by the given 3D scaling factor.
Godot equivalent: Basis.scaled()
Sourcepub fn inverse(&self) -> Basis
pub fn inverse(&self) -> Basis
Returns the inverse of the matrix.
Godot equivalent: Basis.inverse()
Sourcepub fn transposed(&self) -> Basis
pub fn transposed(&self) -> Basis
Returns the transposed version of the matrix.
Godot equivalent: Basis.transposed()
Sourcepub fn orthonormalized(&self) -> Basis
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()
Sourcepub fn rotated(&self, axis: Vector3, angle: f32) -> Basis
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()
Sourcepub fn slerp(&self, other: &Basis, weight: f32) -> Basis
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()
Sourcepub fn tdotx(&self, with: Vector3) -> f32
pub fn tdotx(&self, with: Vector3) -> f32
Transposed dot product with the X axis (column) of the matrix.
Godot equivalent: Basis.tdotx()
Sourcepub fn tdoty(&self, with: Vector3) -> f32
pub fn tdoty(&self, with: Vector3) -> f32
Transposed dot product with the Y axis (column) of the matrix.
Godot equivalent: Basis.tdoty()
Sourcepub fn tdotz(&self, with: Vector3) -> f32
pub fn tdotz(&self, with: Vector3) -> f32
Transposed dot product with the Z axis (column) of the matrix.
Godot equivalent: Basis.tdotz()
Sourcepub fn is_finite(&self) -> bool
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()
Sourcepub fn col_a(&self) -> Vector3
pub fn col_a(&self) -> Vector3
Returns the first column of the matrix,
Godot equivalent: Basis.x
, see Basis
for why it’s changed
Sourcepub fn col_b(&self) -> Vector3
pub fn col_b(&self) -> Vector3
Returns the second column of the matrix,
Godot equivalent: Basis.y
, see Basis
for why it’s changed
Trait Implementations§
Source§impl DynamicSend for Basis
impl DynamicSend for Basis
Source§impl Export for Basis
impl Export for Basis
Source§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
Source§impl From<Basis> for Transform3D
impl From<Basis> for Transform3D
Source§fn from(basis: Basis) -> Transform3D
fn from(basis: Basis) -> Transform3D
Create a new transform with origin (0,0,0)
from this basis.
Source§impl FromGodot for Basis
impl FromGodot for Basis
Source§fn try_from_godot(
via: <Basis as GodotConvert>::Via,
) -> Result<Basis, ConvertError>
fn try_from_godot( via: <Basis as GodotConvert>::Via, ) -> Result<Basis, ConvertError>
Err
on failure.Source§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
Source§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.Source§impl GodotConvert for Basis
impl GodotConvert for Basis
Source§impl IntoDynamicSend for Basis
impl IntoDynamicSend for Basis
type Target = Basis
fn into_dynamic_send(self) -> <Basis as IntoDynamicSend>::Target
Source§impl MulAssign<f32> for Basis
impl MulAssign<f32> for Basis
Source§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read moreSource§impl ParamType for Basis
impl ParamType for Basis
type ArgPassing = ByValue
Source§fn owned_to_arg(self) -> impl AsArg<Self>
fn owned_to_arg(self) -> impl AsArg<Self>
Source§impl ToGodot for Basis
impl ToGodot for Basis
Source§impl Var for Basis
impl Var for Basis
fn get_property(&self) -> <Basis as GodotConvert>::Via
fn set_property(&mut self, value: <Basis as GodotConvert>::Via)
Source§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.Source§impl XformInv<Vector3> for Basis
impl XformInv<Vector3> for Basis
Source§fn xform_inv(&self, rhs: Vector3) -> Vector3
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