diff options
author | ShadowNinja <noreply@gmail.com> | 2013-07-07 01:44:33 -0400 |
---|---|---|
committer | kwolekr <kwolekr@minetest.net> | 2013-07-07 01:49:11 -0400 |
commit | ae8ff4b8e2da35265ebbbe7afe99ed29e61efa7d (patch) | |
tree | efa3e6a19b16e829a8402c798cbce6aae7793ed9 /doc | |
parent | d22baa88edcdba21881310d0f5b728074c4c8876 (diff) | |
download | minetest-ae8ff4b8e2da35265ebbbe7afe99ed29e61efa7d.tar.gz minetest-ae8ff4b8e2da35265ebbbe7afe99ed29e61efa7d.tar.bz2 minetest-ae8ff4b8e2da35265ebbbe7afe99ed29e61efa7d.zip |
Add vector helpers
Diffstat (limited to 'doc')
-rw-r--r-- | doc/lua_api.txt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a9f2d0d46..5a2fdf102 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -988,12 +988,41 @@ Inventory location: - "nodemeta:<X>,<Y>,<Z>": Any node metadata - "detached:<name>": A detached inventory +Vector helpers +--------------- +vector.new([x[, y, z]]) -> vector + ^ x is a table or the x position. +vector.direction(p1, p2) -> vector +vector.distance(p1, p2) -> number +vector.length(v) -> number +vector.normalize(v) -> vector +vector.round(v) -> vector +vector.equal(v1, v2) -> bool +vector.add(v, x) -> vector + ^ x can be annother vector or a number +vector.subtract(v, x) -> vector +vector.multiply(v, x) -> vector +vector.divide(v, x) -> vector + +You can also use Lua operators on vectors. +For example: + v1 = vector.new() + v1 = v1 + 5 + v2 = vector.new(v1) + v1 = v1 * v2 + if v1 == v2 then + error("Math broke") + end + Helper functions ----------------- dump2(obj, name="_", dumped={}) ^ Return object serialized as a string, handles reference loops dump(obj, dumped={}) ^ Return object serialized as a string +math.hypot(x, y) +^ Get the hypotenuse of a triangle with legs x and y. + Usefull for distance calculation. string:split(separator) ^ eg. string:split("a,b", ",") == {"a","b"} string:trim() |