Vector3.lua 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. class "Vector3"
  2. function Vector3:__getvar(name)
  3. if name == "x" then
  4. return Polycode.Vector3_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycode.Vector3_get_y(self.__ptr)
  7. elseif name == "z" then
  8. return Polycode.Vector3_get_z(self.__ptr)
  9. end
  10. end
  11. function Vector3:__setvar(name,value)
  12. if name == "x" then
  13. Polycode.Vector3_set_x(self.__ptr, value)
  14. return true
  15. elseif name == "y" then
  16. Polycode.Vector3_set_y(self.__ptr, value)
  17. return true
  18. elseif name == "z" then
  19. Polycode.Vector3_set_z(self.__ptr, value)
  20. return true
  21. end
  22. return false
  23. end
  24. function Vector3:Vector3(...)
  25. local arg = {...}
  26. for k,v in pairs(arg) do
  27. if type(v) == "table" then
  28. if v.__ptr ~= nil then
  29. arg[k] = v.__ptr
  30. end
  31. end
  32. end
  33. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  34. self.__ptr = Polycode.Vector3(unpack(arg))
  35. end
  36. end
  37. function Vector3:set(x, y, z)
  38. local retVal = Polycode.Vector3_set(self.__ptr, x, y, z)
  39. end
  40. function Vector3:distance(vec2)
  41. local retVal = Polycode.Vector3_distance(self.__ptr, vec2.__ptr)
  42. return retVal
  43. end
  44. function Vector3:angleBetween(dest)
  45. local retVal = Polycode.Vector3_angleBetween(self.__ptr, dest.__ptr)
  46. return retVal
  47. end
  48. function Vector3:length()
  49. local retVal = Polycode.Vector3_length(self.__ptr)
  50. return retVal
  51. end
  52. function Vector3:lengthSquared()
  53. local retVal = Polycode.Vector3_lengthSquared(self.__ptr)
  54. return retVal
  55. end
  56. function Vector3:setLength(newLength)
  57. local retVal = Polycode.Vector3_setLength(self.__ptr, newLength)
  58. if retVal == nil then return nil end
  59. local __c = _G["Vector3"]("__skip_ptr__")
  60. __c.__ptr = retVal
  61. return __c
  62. end
  63. function Vector3:dot(u)
  64. local retVal = Polycode.Vector3_dot(self.__ptr, u.__ptr)
  65. return retVal
  66. end
  67. function Vector3:crossProduct(vec2)
  68. local retVal = Polycode.Vector3_crossProduct(self.__ptr, vec2.__ptr)
  69. if retVal == nil then return nil end
  70. local __c = _G["Vector3"]("__skip_ptr__")
  71. __c.__ptr = retVal
  72. return __c
  73. end
  74. function Vector3:Normalize()
  75. local retVal = Polycode.Vector3_Normalize(self.__ptr)
  76. end
  77. function Vector3:__delete()
  78. if self then Polycode.delete_Vector3(self.__ptr) end
  79. end