1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Improve docs

This commit is contained in:
Lars Mueller 2025-06-02 19:32:31 +02:00
parent c3cb0a6d4e
commit f66b787ca6

View file

@ -4203,17 +4203,17 @@ Rotations can also be converted to matrices using `Matrix4.rotation(rot)`.
Methods Methods
------- -------
* `Rotation:apply(vec)`: Returns the result of applying the rotation to the given vector. * `rot:apply(vec)`: Returns the result of applying the rotation to the given vector.
* `Rotation.compose(...)`: Returns the composition of the given rotations. * `Rotation.compose(...)`: Returns the composition of the given rotations.
* `Rotation.compose()` is an alias for `Rotation.identity()`. * `Rotation.compose()` is an alias for `Rotation.identity()`.
* `Rotation.compose(rot)` copies the rotation. * `Rotation.compose(rot)` copies the rotation.
* `rot:compose(...)` is shorthand for `Rotation.compose(rot, ...)`. * `rot:compose(...)` is shorthand for `Rotation.compose(rot, ...)`.
* Right-to-left order: `second:compose(first):apply(v)` * Right-to-left order: `second:compose(first):apply(v)`
is equivalent to `second:apply(first:apply(v))`. is equivalent to `second:apply(first:apply(v))`.
* `Rotation:invert()`: Returns the inverse rotation. * `rot:invert()`: Returns the inverse rotation.
* `Rotation.slerp(from, to, time)`: Interpolate from one rotation to another. * `from:slerp(to, time)`: Interpolate from one rotation to another.
* `time = 0` is all `from`, `time = 1` is all `to`. * `time = 0` is all `from`, `time = 1` is all `to`.
* `Rotation:angle_to(other)`: Returns the absolute angle between two quaternions. * `rot:angle_to(other)`: Returns the absolute angle between two quaternions.
* Useful to measure similarity. * Useful to measure similarity.
Rotations implement `__tostring`. The format is only intended for human-readability, Rotations implement `__tostring`. The format is only intended for human-readability,
@ -4260,24 +4260,24 @@ Methods
Storage: Storage:
* `Matrix4:get(row, col)` * `mat:get(row, col)`
* `Matrix4:set(row, col, number)` * `mat:set(row, col, number)`
* `x, y, z, w = Matrix4:get_row(row)` * `x, y, z, w = mat:get_row(row)`
* `Matrix4:set_row(row, x, y, z, w)` * `mat:set_row(row, x, y, z, w)`
* `x, y, z, w = Matrix4:get_column(col)` * `x, y, z, w = Matrix4:get_column(col)`
* `Matrix4:set_column(col, x, y, z, w)` * `mat:set_column(col, x, y, z, w)`
* `Matrix4:copy()` * `mat:copy()`
* `... = Matrix4:unpack()`: Get the 16 numbers in the matrix in row-major order * `... = mat:unpack()`: Get the 16 numbers in the matrix in row-major order
(inverse of `Matrix4.new`). (inverse of `Matrix4.new`).
Linear algebra: Linear algebra:
* Vector transformations: * Vector transformations:
* `x, y, z, w = Matrix4:transform_4d(x, y, z, w)`: Apply the matrix to a 4d vector. * `x, y, z, w = mat:transform_4d(x, y, z, w)`: Apply the matrix to a 4d vector.
* `Matrix4:transform_position(pos)`: * `mat:transform_position(pos)`:
* Apply the matrix to a vector representing a position. * Apply the matrix to a vector representing a position.
* Applies the transformation as if w = 1 and discards the resulting w component. * Applies the transformation as if w = 1 and discards the resulting w component.
* `Matrix4:transform_direction(dir)`: * `mat:transform_direction(dir)`:
* Apply the matrix to a vector representing a direction. * Apply the matrix to a vector representing a direction.
* Ignores the fourth row and column; does not apply the translation (w = 0). * Ignores the fourth row and column; does not apply the translation (w = 0).
* `Matrix4.compose(...)`: Returns the composition of the given matrices. * `Matrix4.compose(...)`: Returns the composition of the given matrices.
@ -4286,27 +4286,27 @@ Linear algebra:
* `mat:compose(...)` is shorthand for `Matrix4.compose(mat, ...)`. * `mat:compose(...)` is shorthand for `Matrix4.compose(mat, ...)`.
* Right-to-left order: `second:compose(first):apply(v)` * Right-to-left order: `second:compose(first):apply(v)`
is equivalent to `second:apply(first:apply(v))`. is equivalent to `second:apply(first:apply(v))`.
* `Matrix4:determinant()`: Returns the determinant. * `mat:determinant()`: Returns the determinant.
* `Matrix4:invert()`: Returns a newly created inverse, or `nil` if the matrix is (close to being) singular. * `mat:invert()`: Returns a newly created inverse, or `nil` if the matrix is (close to being) singular.
* `Matrix4:transpose()`: Returns a transposed copy of the matrix. * `mat:transpose()`: Returns a transposed copy of the matrix.
* `Matrix4:equals(other, [tolerance = 0])`: * `mat:equals(other, [tolerance = 0])`:
Returns whether all components differ in absolute value at most by the given tolerance. Returns whether all components differ in absolute value at most by the given tolerance.
* `m1 == m2`: Returns whether `m1` and `m2` are identical (`tolerance = 0`). * `m1 == m2`: Returns whether `m1` and `m2` are identical (`tolerance = 0`).
* `Matrix4:is_affine_transform([tolerance = 0])`: * `mat:is_affine_transform([tolerance = 0])`:
Whether the matrix is an affine transformation in 3d space, Whether the matrix is an affine transformation in 3d space,
meaning it is a 3d linear transformation plus a translation. meaning it is a 3d linear transformation plus a translation.
(This is the case if the last column is approximately 0, 0, 0, 1.) (This is the case if the last column is approximately 0, 0, 0, 1.)
For working with affine transforms, the following methods are available: For working with affine transforms, the following methods are available:
* `Matrix4:get_translation()`: Returns the translation as a vector. * `mat:get_translation()`: Returns the translation as a vector.
* `Matrix4:set_translation(vec)`: Sets (overwrites) the translation in the last row. * `mat:set_translation(vec)`: Sets (overwrites) the translation in the last row.
For TRS transforms specifically, For TRS transforms specifically,
let `self = Matrix4.compose(Matrix4.translation(t), Matrix4.rotation(r), Matrix4.scale(s))`. let `self = Matrix4.compose(Matrix4.translation(t), Matrix4.rotation(r), Matrix4.scale(s))`.
Then we can decompose `self` further. Note that `self` must not shear or reflect. Then we can decompose `self` further. Note that `self` must not shear or reflect.
* `rotation, scale = Matrix4:get_rs()`: * `rotation, scale = mat:get_rs()`:
Extracts a `Rotation` equivalent to `r`, Extracts a `Rotation` equivalent to `r`,
along with the corresponding component-wise scaling factors as a vector. along with the corresponding component-wise scaling factors as a vector.