Advertisement
neo34rd

vector.lua

Mar 24th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. function makeZero()
  2. local v = {}
  3. v['x'] = 0
  4. v['y'] = 0
  5. v['z'] = 0
  6. return v
  7. end
  8.  
  9. function make(x, y, z)
  10. local v = makeZero()
  11. v.x = x
  12. v.y = y
  13. v.z = z
  14. return v
  15. end
  16.  
  17. function scale(lhs, coeff)
  18. local d = makeZero()
  19. d.x = lhs.x * coeff
  20. d.y = lhs.y * coeff
  21. d.z = lhs.z * coeff
  22. return d
  23. end
  24.  
  25. function add(lhs, rhs)
  26. local d = makeZero()
  27. d.x = lhs.x + rhs.x
  28. d.y = lhs.y + rhs.y
  29. d.z = lhs.z + rhs.z
  30. return d
  31. end
  32.  
  33. function sub(lhs, rhs)
  34. local d = makeZero()
  35. d = add(lhs, scale(rhs, -1))
  36. return d
  37. end
  38.  
  39. function distance(lhs, rhs)
  40. return sub(lhs, rhs)
  41. end
  42.  
  43. function toString(v)
  44. return v.x .. "," .. v.y .. "," .. v.z
  45. end
  46.  
  47. function equalDirection(lhs, rhs)
  48. return lhs.x == rhs.x and lhs.y == rhs.y and lhs.z == rhs.z
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement