1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Add vector helpers

This commit is contained in:
ShadowNinja 2013-07-07 01:44:33 -04:00 committed by kwolekr
parent d22baa88ed
commit ae8ff4b8e2
4 changed files with 192 additions and 15 deletions

View file

@ -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()