summaryrefslogtreecommitdiff
path: root/doc/lua_api.txt
diff options
context:
space:
mode:
authorNetherEran <55532075+NetherEran@users.noreply.github.com>2020-06-09 17:38:39 +0000
committerGitHub <noreply@github.com>2020-06-09 19:38:39 +0200
commit7148834440d10bc211628aa2652e31166bdd58a0 (patch)
treeddf86be920acc50f61925cfd2d256945ebebd225 /doc/lua_api.txt
parentb16f841756ef86e83710ad2fddf2cd5bafdf4bcc (diff)
downloadminetest-7148834440d10bc211628aa2652e31166bdd58a0.tar.gz
minetest-7148834440d10bc211628aa2652e31166bdd58a0.tar.bz2
minetest-7148834440d10bc211628aa2652e31166bdd58a0.zip
Some vector functions useful for working with rotations (#9572)
* added vector.rotate * added vector.forward_from_rotation and vector.up_from_rotation * added vector.forward_up_to_rotatiton * fixed some bugs and formatting with vector functions * shortened name of some new vector functions and added documentation * made vector.rotate not require a unit vector as axis * fixed crash with vector.forward_up_to_rot * renamed new vector functions, made vector.rotate apply a rotation matrix, old vector.rotate is now called vector.rotate_around_axis * documented vector function changes * removed some whitespace to appease luacheck * implemented and fixed optimization of vector.rotate_around_axis by SmallJoker * added some unit tests for rotation vector functions * clarified that rotation vectors are in radians and according to the left hand rule * hopefully appeased luacheck * renamed rotation_to_horizontal to forward_at_rotation, rotation_to_vertical to up_at_rotation * handled cases where sin or cos are 0 in rotation vector functions * added more comments * clarified documentation of rotation vector functions * added more unit tests * changed way in which vector.rotate_around_axis is adjusted for left handed coordinate systems * made vector.rotate_around_axis actually left handed * unrolled matrix multiplication * removed vector.forward_at_rotation and vector.up_at_rotation * prettified vector.rotate_around_axis, made previous commits not break anything * removed references to removed vector.forward_at_rotation and vector.up_at_rotation * removed documentation of removed vector functions * clarified documentation and fixed styling of rotation vector functions * restyled comments minorly * spelling fixes and some hopefully better comments * allowed 'up' to be missing from vector.directions_to_rotation and removed requirement for unit vectors as arguments * made vector.rotate_around_axis() right handed again for consistency * documented previous changes * made matrix multiplication actually multiply * renamed vector.directions_to_rotation() to vector.dir_to_rotation() * optimized a distance comparison * Fixed potential false positive in unit tests. Co-authored-by: NetherEran <nethereran@hotmail.com>
Diffstat (limited to 'doc/lua_api.txt')
-rw-r--r--doc/lua_api.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index 898531880..ed060c4ad 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -3007,6 +3007,24 @@ For the following functions `x` can be either a vector or a number:
* `vector.divide(v, x)`:
* Returns a scaled vector or Schur quotient.
+For the following functions `a` is an angle in radians and `r` is a rotation
+vector ({x = <pitch>, y = <yaw>, z = <roll>}) where pitch, yaw and roll are
+angles in radians.
+
+* `vector.rotate(v, r)`:
+ * Applies the rotation `r` to `v` and returns the result.
+ * `vector.rotate({x = 0, y = 0, z = 1}, r)` and
+ `vector.rotate({x = 0, y = 1, z = 0}, r)` return vectors pointing
+ forward and up relative to an entity's rotation `r`.
+* `vector.rotate_around_axis(v1, v2, a)`:
+ * Returns `v1` rotated around axis `v2` by `a` radians according to
+ the right hand rule.
+* `vector.dir_to_rotation(direction[, up])`:
+ * Returns a rotation vector for `direction` pointing forward using `up`
+ as the up vector.
+ * If `up` is omitted, the roll of the returned vector defaults to zero.
+ * Otherwise `direction` and `up` need to be vectors in a 90 degree angle to each other.
+