Vector2.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. class "Vector2"
  2. function Vector2:__getvar(name)
  3. if name == "x" then
  4. return Polycode.Vector2_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycode.Vector2_get_y(self.__ptr)
  7. end
  8. end
  9. function Vector2:__setvar(name,value)
  10. if name == "x" then
  11. Polycode.Vector2_set_x(self.__ptr, value)
  12. return true
  13. elseif name == "y" then
  14. Polycode.Vector2_set_y(self.__ptr, value)
  15. return true
  16. end
  17. return false
  18. end
  19. function Vector2:Vector2(...)
  20. local arg = {...}
  21. for k,v in pairs(arg) do
  22. if type(v) == "table" then
  23. if v.__ptr ~= nil then
  24. arg[k] = v.__ptr
  25. end
  26. end
  27. end
  28. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  29. self.__ptr = Polycode.Vector2(unpack(arg))
  30. end
  31. end
  32. function Vector2:set(x, y)
  33. local retVal = Polycode.Vector2_set(self.__ptr, x, y)
  34. end
  35. function Vector2:distance(vec2)
  36. local retVal = Polycode.Vector2_distance(self.__ptr, vec2.__ptr)
  37. return retVal
  38. end
  39. function Vector2:length()
  40. local retVal = Polycode.Vector2_length(self.__ptr)
  41. return retVal
  42. end
  43. function Vector2:dot(u)
  44. local retVal = Polycode.Vector2_dot(self.__ptr, u.__ptr)
  45. return retVal
  46. end
  47. function Vector2:crossProduct(vec2)
  48. local retVal = Polycode.Vector2_crossProduct(self.__ptr, vec2.__ptr)
  49. return retVal
  50. end
  51. function Vector2:angle(vec2)
  52. local retVal = Polycode.Vector2_angle(self.__ptr, vec2.__ptr)
  53. return retVal
  54. end
  55. function Vector2:Normalize()
  56. local retVal = Polycode.Vector2_Normalize(self.__ptr)
  57. end
  58. function Vector2:__delete()
  59. if self then Polycode.delete_Vector2(self.__ptr) end
  60. end