Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get PE0k7NQY CVF
- CVF = {}
- function CVF.add(pos, delta)
- local dy = delta.y
- if not delta.y then dy = 0 end
- if pos.y then dy = dy + pos.y end
- return {x = pos.x + delta.x, y = dy, z = pos.z + delta.z}
- end
- function CVF.sub(pos, delta)
- local dy = 0
- if delta.y then dy = -delta.y end
- if pos.y then dy = pos.y + dy end
- return {x = pos.x - delta.x, y = dy, z = pos.z - delta.z}
- end
- function CVF.mult(s, vec)
- local newVec = {}
- for k, v in pairs(vec) do
- newVec[k] = s * v
- end
- return newVec
- end
- function CVF.equalCoords(coord1, coord2)
- return coord1.x == coord2.x and coord1.y == coord2.y and coord1.z == coord2.z
- end
- function CVF.getRightDir(orientation)
- return {x = -orientation.z, z = orientation.x}
- end
- function CVF.getLeftDir(orientation)
- return {x = orientation.z, z = -orientation.x}
- end
- function CVF.isXDir(dir)
- if dir.x ~= 0 then return true end
- return false
- end
- function CVF.getTurnDirection(from, to)
- local function vectorsEqual(a, b)
- return a.x == b.x and a.z == b.z
- end
- if vectorsEqual(from, to) then return nil end
- local left = {x = from.z, z = -from.x}
- local right = {x = -from.z, z = from.x}
- local back = {x = -from.x, z = -from.z}
- if vectorsEqual(to, left) then
- return "left"
- elseif vectorsEqual(to, right) then
- return "right"
- elseif vectorsEqual(to, back) then
- return "around"
- else
- error("Invalid target direction")
- end
- end
- return CVF
Advertisement
Add Comment
Please, Sign In to add comment