vector
Language: | English • Deutsch |
---|
Table, {x = …, y = …, z = …}
Used as both positions and offsets in the Minetest API. There are some helper functions that operate on vectors:
Function | Return value | Comments |
---|---|---|
vector.new([x, [y, z]]) | vector | x can be either be a vector or the position x of the new vector (requires x and y to be set too) |
vector.direction(p1, p2) | vector | direction from p1 to p2, maximal values are: {x=-1,y=-1,z=-1} and {x=1,y=1,z=1} |
vector.distance(p1, p2) | number | same as vector.length(vector.subtract(p2, p1)) |
vector.length(v) | number | |
vector.normalize(v) | vector | |
vector.round(v) | vector | same as vector.apply(v, function(c) return math.floor(c + 0.5) end) |
vector.equals(v1, v2) | bool | |
vector.add(v, x) | vector | x can be either a vector or a number. |
vector.subtract(v, x) | vector | x can be either a vector or a number. same as vector.add(v, -x) or vector.add(v, vector.multiply(x, -1)) |
vector.multiply(v, x) | vector | x can be either a vector or a number. |
vector.divide(v, x) | vector | x can be either a vector or a number. |
Coordinate System
Minetest uses a left-handed coordinate system. In the world coordinate system, the x-direction is to the east (according to the sunrise), the y-direction is up, and the z-direction is north. In the player/camera coordinate system (used by e.g. Player:set_eye_offset(), the x-direction is to the right, the y-direction is up, and the z-direction is forward.
Interestingly, though, yaw direction (as reported by Player:get_look_yaw() is right-handed. Angle 0 is in the x-direction (east), π/2 is in the z-direction (north), π is in the -x-direction (west), and 3π/2 is in the -z-direction (south).