Class Basis
Basis metatype, wrapper for godot_basis
.
Constructed using the idiom Basis(...)
, which calls __new.
The matrix rows may be accessed through rows
or in bulk through elements
:
typedef union godot_basis { uint8_t data[36]; float elements[9]; Vector3 rows[3]; } godot_basis;
Methods
Basis:determinant () | Returns the determinant of the basis matrix. |
Basis:get_axis (axis) | Returns the given axis (column). |
Basis:get_euler () | Returns the basis's rotation in the form of Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last). |
Basis:get_orthogonal_index () | This function considers a discretization of rotations into 24 points on unit sphere, lying along the vectors (x,y,z) with each component being either -1, 0, or 1, and returns the index of the point best representing the orientation of the object. |
Basis:get_rotation_quat () | Returns the basis's rotation in the form of a quaternion. |
Basis:get_row (row) | Returns the given row . |
Basis:get_scale () | Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis. |
Basis:inverse () | Returns the inverse of the matrix. |
Basis:orthonormalized () | Returns the orthonormalized version of the matrix (useful to call from time to time to avoid rounding error for orthogonal matrices). |
Basis:rotated (axis, phi) | Introduce an additional rotation around the given axis by phi (radians). |
Basis:scaled (scale) | Introduce an additional scaling specified by the given 3D scaling factor. |
Basis:set_axis (axis, value) | Set a new value for axis (column). |
Basis:set_row (row, value) | Set a new value for row . |
Basis:slerp (b, t) | Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix. |
Basis:tdotx (with) | Transposed dot product with the X axis of the matrix. |
Basis:tdoty (with) | Transposed dot product with the Y axis of the matrix. |
Basis:tdotz (with) | Transposed dot product with the Z axis of the matrix. |
Basis:transposed () | Returns the transposed version of the matrix. |
Basis:xform (v) | Returns a vector transformed (multiplied) by the matrix. |
Basis:xform_inv (v) | Returns a vector transformed (multiplied) by the transposed basis matrix. |
Metamethods
Basis:__add (a, b) | Addition operation |
Basis:__concat (a, b) | Concatenates values. |
Basis:__eq (a, b) | Equality operation
If either a or b are not of type Basis, always return false . |
Basis:__mul (self, b) | Multiplication operation |
Basis:__new (...) | Basis constructor, called by the idiom Basis(...) . |
Basis:__sub (a, b) | Subtraction operation |
Basis:__tostring () | Returns a Lua string representation of this basis. |
Constants
Basis.FLIP_X | The basis that will flip something along the X axis when used in a transformation. |
Basis.FLIP_Y | The basis that will flip something along the Y axis when used in a transformation. |
Basis.FLIP_Z | The basis that will flip something along the Z axis when used in a transformation. |
Basis.IDENTITY | The identity basis, with no rotation or scaling applied. |
Methods
- Basis:determinant ()
-
Returns the determinant of the basis matrix. If the basis is uniformly scaled, its determinant is the square of the scale.
A negative determinant means the basis has a negative scale.
A zero determinant means the basis isn't invertible, and is usually considered invalid.
Returns:
-
number
- Basis:get_axis (axis)
-
Returns the given
axis
(column).Parameters:
- axis int
Returns:
- Basis:get_euler ()
-
Returns the basis's rotation in the form of Euler angles (in the YXZ convention: when decomposing, first Z, then X, and Y last).
The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
Consider using the get_rotation_quat method instead, which returns a quaternion instead of Euler angles.
Returns:
See also:
- Basis:get_orthogonal_index ()
-
This function considers a discretization of rotations into 24 points on unit sphere, lying along the vectors (x,y,z) with each component being either -1, 0, or 1, and returns the index of the point best representing the orientation of the object.
It is mainly used by the GridMap editor.
For further details, refer to the Godot source code.
Returns:
-
int
- Basis:get_rotation_quat ()
-
Returns the basis's rotation in the form of a quaternion.
See get_euler if you need Euler angles, but keep in mind quaternions should generally be preferred to Euler angles.
Returns:
- Basis:get_row (row)
-
Returns the given
row
.Parameters:
- row int
Returns:
- Basis:get_scale ()
-
Assuming that the matrix is the combination of a rotation and scaling, return the absolute value of scaling factors along each axis.
Returns:
- Basis:inverse ()
-
Returns the inverse of the matrix.
Returns:
- Basis:orthonormalized ()
-
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.
Returns:
- Basis:rotated (axis, phi)
-
Introduce an additional rotation around the given
axis
byphi
(radians). Theaxis
must be a normalized vector.Parameters:
- axis Vector3
- phi number
Returns:
- Basis:scaled (scale)
-
Introduce an additional scaling specified by the given 3D scaling factor.
Parameters:
- scale Vector3
Returns:
- Basis:set_axis (axis, value)
-
Set a new value for
axis
(column).Parameters:
- axis int
- value Vector3
- Basis:set_row (row, value)
-
Set a new value for
row
.Parameters:
- row int
- value Vector3
- Basis:slerp (b, t)
-
Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.
Parameters:
- b Basis
- t number
Returns:
- Basis:tdotx (with)
-
Transposed dot product with the X axis of the matrix.
Parameters:
- with Vector3
Returns:
-
number
- Basis:tdoty (with)
-
Transposed dot product with the Y axis of the matrix.
Parameters:
- with Vector3
Returns:
-
number
- Basis:tdotz (with)
-
Transposed dot product with the Z axis of the matrix.
Parameters:
- with Vector3
Returns:
-
number
- Basis:transposed ()
-
Returns the transposed version of the matrix.
Returns:
- Basis:xform (v)
-
Returns a vector transformed (multiplied) by the matrix.
Parameters:
- v Vector3
Returns:
- Basis:xform_inv (v)
-
Returns a vector transformed (multiplied) by the transposed basis matrix.
Note: This results in a multiplication by the inverse of the matrix only if it represents a rotation-reflection.
Parameters:
- v Vector3
Returns:
Metamethods
- Basis:__add (a, b)
-
Addition operation
Parameters:
Returns:
- Basis:__concat (a, b)
-
Concatenates values.
Parameters:
Returns:
- Basis:__eq (a, b)
-
Equality operation
If either
a
orb
are not of type Basis, always returnfalse
.Parameters:
Returns:
-
bool
- Basis:__mul (self, b)
-
Multiplication operation
Parameters:
- self Basis
- b
Basis, Vector3 or number
If a Basis is passed, returns the multiplied matrices.
If a Vector3 is passed, calls xform.
Otherwise, returns a Basis with each component multiplied by
b
.
Returns:
- Basis:__new (...)
-
Basis constructor, called by the idiom
Basis(...)
.Basis()
: IDENTITY basis matrixBasis(Quat quat)
: pure rotation basis matrix from the given quaternionBasis(Vector3 euler)
: pure rotation basis matrix from the given Euler angles (in the YXZ convention: when composing, first Y, then X, and Z last)Basis(Vector3 axis, number angle)
: pure rotation basis matrix, rotated around the given axis by angle, in radians. The axis must be a normalized vectorBasis(Vector3 x, Vector3 y, Vector3 z)
: basis matrix from 3 row vectorsBasis(Basis other)
: copy values fromother
Parameters:
- ...
Returns:
- Basis:__sub (a, b)
-
Subtraction operation
Parameters:
Returns:
- Basis:__tostring ()
-
Returns a Lua string representation of this basis.
Returns:
Constants
- Basis.FLIP_X
-
The basis that will flip something along the X axis when used in a transformation.
- FLIP_X Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1)
- Basis.FLIP_Y
-
The basis that will flip something along the Y axis when used in a transformation.
- FLIP_Y Basis(1, 0, 0, 0, -1, 0, 0, 0, 1)
- Basis.FLIP_Z
-
The basis that will flip something along the Z axis when used in a transformation.
- FLIP_Z Basis(1, 0, 0, 0, 1, 0, 0, 0, -1)
- Basis.IDENTITY
-
The identity basis, with no rotation or scaling applied.
- IDENTITY Basis(1, 0, 0, 0, 1, 0, 0, 0, 1)