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:

    Vector3
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:

    Vector3

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:

    Quat
Basis:get_row (row)
Returns the given row.

Parameters:

  • row int

Returns:

    Vector3
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:

    Vector3
Basis:inverse ()
Returns the inverse of the matrix.

Returns:

    Basis
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
Basis:rotated (axis, phi)
Introduce an additional rotation around the given axis by phi (radians). The axis must be a normalized vector.

Parameters:

Returns:

    Basis
Basis:scaled (scale)
Introduce an additional scaling specified by the given 3D scaling factor.

Parameters:

Returns:

    Basis
Basis:set_axis (axis, value)
Set a new value for axis (column).

Parameters:

Basis:set_row (row, value)
Set a new value for row.

Parameters:

Basis:slerp (b, t)
Assuming that the matrix is a proper rotation matrix, slerp performs a spherical-linear interpolation with another rotation matrix.

Parameters:

Returns:

    Basis
Basis:tdotx (with)
Transposed dot product with the X axis of the matrix.

Parameters:

Returns:

    number
Basis:tdoty (with)
Transposed dot product with the Y axis of the matrix.

Parameters:

Returns:

    number
Basis:tdotz (with)
Transposed dot product with the Z axis of the matrix.

Parameters:

Returns:

    number
Basis:transposed ()
Returns the transposed version of the matrix.

Returns:

    Basis
Basis:xform (v)
Returns a vector transformed (multiplied) by the matrix.

Parameters:

Returns:

    Vector3
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:

Returns:

    Vector3

Metamethods

Basis:__add (a, b)
Addition operation

Parameters:

Returns:

    Basis
Basis:__concat (a, b)
Concatenates values.

Parameters:

  • a First value, stringified with GD.str
  • b First value, stringified with GD.str

Returns:

    String
Basis:__eq (a, b)
Equality operation If either a or b are not of type Basis, always return false.

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 or Vector3
Basis:__new (...)

Basis constructor, called by the idiom Basis(...).

  • Basis(): IDENTITY basis matrix
  • Basis(Quat quat): pure rotation basis matrix from the given quaternion
  • Basis(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 vector
  • Basis(Vector3 x, Vector3 y, Vector3 z): basis matrix from 3 row vectors
  • Basis(Basis other): copy values from other

Parameters:

  • ...

Returns:

    Basis
Basis:__sub (a, b)
Subtraction operation

Parameters:

Returns:

    Basis
Basis:__tostring ()
Returns a Lua string representation of this basis.

Returns:

    string

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)
generated by LDoc 1.4.6 Last updated 2023-01-04 08:52:34