Struct 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.
§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§
§impl Basis
impl Basis
pub const IDENTITY: Basis = _
pub const IDENTITY: Basis = _
The identity basis, with no rotation or scaling applied.
Godot equivalent: Basis.IDENTITY
pub 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
pub 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
pub 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
pub 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.
pub 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.
pub 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)
pub 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.
pub 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)
pub fn from_quat(quat: Quaternion) -> Basis
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
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
pub fn new_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()
pub fn to_quat(&self) -> Quaternion
pub fn to_quat(&self) -> Quaternion
Creates a Quaternion
representing the same rotation as this basis.
Godot equivalent: Basis.get_rotation_quaternion()
pub fn to_euler(&self, order: EulerOrder) -> Vector3
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
pub fn determinant(&self) -> f32
Returns the determinant of the matrix.
Godot equivalent: Basis.determinant()
pub 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()
pub fn transposed(&self) -> Basis
pub fn transposed(&self) -> Basis
Returns the transposed version of the matrix.
Godot equivalent: Basis.transposed()
pub 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()
pub 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()
pub 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()
pub 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()
pub 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()
pub 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()
pub 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()
pub 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
pub 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§
§impl Export for Basis
impl Export for Basis
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§impl From<Basis> for Transform3D
impl From<Basis> for Transform3D
§fn from(basis: Basis) -> Transform3D
fn from(basis: Basis) -> Transform3D
Create a new transform with origin (0,0,0)
from this basis.
§impl FromGodot for Basis
impl FromGodot for Basis
§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.§fn from_godot(via: Self::Via) -> Self
fn from_godot(via: Self::Via) -> Self
§fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
fn try_from_variant(variant: &Variant) -> Result<Self, ConvertError>
Variant
, returning Err
on failure.§fn from_variant(variant: &Variant) -> Self
fn from_variant(variant: &Variant) -> Self
§impl MulAssign<f32> for Basis
impl MulAssign<f32> for Basis
§fn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
*=
operation. Read more§impl ParamType for Basis
impl ParamType for Basis
§fn owned_to_arg<'v>(self) -> <Basis as ParamType>::Arg<'v>
fn owned_to_arg<'v>(self) -> <Basis as ParamType>::Arg<'v>
impl AsArg<T>
. Read more§impl ToGodot for Basis
impl ToGodot for Basis
§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)
§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.