Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Basis¶
A 3×3 matrix for representing 3D rotation and scale.
Description¶
The Basis built-in Variant type is a 3x3 matrix used to represent 3D rotation, scale, and shear. It is frequently used within a Transform3D.
A Basis is composed by 3 axis vectors, each representing a column of the matrix: x, y, and z. The length of each axis (Vector3.length) influences the basis's scale, while the direction of all axes influence the rotation. Usually, these axes are perpendicular to one another. However, when you rotate any axis individually, the basis becomes sheared. Applying a sheared basis to a 3D model will make the model appear distorted.
A Basis is orthogonal if its axes are perpendicular to each other. A basis is normalized if the length of every axis is 1
. A basis is uniform if all axes share the same length (see get_scale). A basis is orthonormal if it is both orthogonal and normalized, which allows it to only represent rotations. A basis is conformal if it is both orthogonal and uniform, which ensures it is not distorted.
For a general introduction, see the Matrices and transforms tutorial.
Note: Godot uses a right-handed coordinate system, which is a common standard. For directions, the convention for built-in types like Camera3D is for -Z to point forward (+X is right, +Y is up, and +Z is back). Other objects may use different direction conventions. For more information, see the Importing 3D Scenes tutorial.
Note: The basis matrices are exposed as column-major order, which is the same as OpenGL. However, they are stored internally in row-major order, which is the same as DirectX.
Note
There are notable differences when using this API with C#. See C# API differences to GDScript for more information.
Tutorials¶
Properties¶
|
||
|
||
|
Constructors¶
Basis ( ) |
|
Basis ( Quaternion from ) |
|
Methods¶
determinant ( ) const |
|
from_euler ( Vector3 euler, int order=2 ) static |
|
from_scale ( Vector3 scale ) static |
|
get_rotation_quaternion ( ) const |
|
get_scale ( ) const |
|
inverse ( ) const |
|
is_conformal ( ) const |
|
is_equal_approx ( Basis b ) const |
|
is_finite ( ) const |
|
looking_at ( Vector3 target, Vector3 up=Vector3(0, 1, 0), bool use_model_front=false ) static |
|
orthonormalized ( ) const |
|
transposed ( ) const |
Operators¶
operator != ( Basis right ) |
|
operator * ( Basis right ) |
|
operator * ( Vector3 right ) |
|
operator * ( float right ) |
|
operator * ( int right ) |
|
operator == ( Basis right ) |
|
operator [] ( int index ) |
Constants¶
IDENTITY = Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)
The identity basis. This is a basis with no rotation, no shear, and its scale being 1
. This means that:
The x points right (Vector3.RIGHT);
The y points up (Vector3.UP);
The z points back (Vector3.BACK).
var basis := Basis.IDENTITY
print("| X | Y | Z")
print("| %s | %s | %s" % [basis.x.x, basis.y.x, basis.z.x])
print("| %s | %s | %s" % [basis.x.y, basis.y.y, basis.z.y])
print("| %s | %s | %s" % [basis.x.z, basis.y.z, basis.z.z])
# Prints:
# | X | Y | Z
# | 1 | 0 | 0
# | 0 | 1 | 0
# | 0 | 0 | 1
This is identical to creating Basis without any parameters. This constant can be used to make your code clearer, and for consistency with C#.
FLIP_X = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1)
When any basis is multiplied by FLIP_X, it negates all components of the x axis (the X column).
When FLIP_X is multiplied by any basis, it negates the Vector3.x component of all axes (the X row).
FLIP_Y = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1)
When any basis is multiplied by FLIP_Y, it negates all components of the y axis (the Y column).
When FLIP_Y is multiplied by any basis, it negates the