Vector3.lua 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. class "Vector3"
  2. function Vector3:__index__(name)
  3. if name == "x" then
  4. return Polycore.Vector3_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycore.Vector3_get_y(self.__ptr)
  7. elseif name == "z" then
  8. return Polycore.Vector3_get_z(self.__ptr)
  9. end
  10. end
  11. function Vector3:__set_callback(name,value)
  12. if name == "x" then
  13. Polycore.Vector3_set_x(self.__ptr, value)
  14. return true
  15. elseif name == "y" then
  16. Polycore.Vector3_set_y(self.__ptr, value)
  17. return true
  18. elseif name == "z" then
  19. Polycore.Vector3_set_z(self.__ptr, value)
  20. return true
  21. end
  22. return false
  23. end
  24. function Vector3:Vector3(...)
  25. for k,v in pairs(arg) do
  26. if type(v) == "table" then
  27. if v.__ptr ~= nil then
  28. arg[k] = v.__ptr
  29. end
  30. end
  31. end
  32. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  33. self.__ptr = Polycore.Vector3(unpack(arg))
  34. end
  35. end
  36. function Vector3:set(x, y, z)
  37. local retVal = Polycore.Vector3_set(self.__ptr, x, y, z)
  38. end
  39. function Vector3:distance(vec2)
  40. local retVal = Polycore.Vector3_distance(self.__ptr, vec2.__ptr)
  41. return retVal
  42. end
  43. function Vector3:length()
  44. local retVal = Polycore.Vector3_length(self.__ptr)
  45. return retVal
  46. end
  47. function Vector3:dot(u)
  48. local retVal = Polycore.Vector3_dot(self.__ptr, u.__ptr)
  49. return retVal
  50. end
  51. function Vector3:crossProduct(vec2)
  52. local retVal = Polycore.Vector3_crossProduct(self.__ptr, vec2.__ptr)
  53. if Polycore.__ptr_lookup[retVal] ~= nil then
  54. return Polycore.__ptr_lookup[retVal]
  55. else
  56. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  57. Polycore.__ptr_lookup[retVal].__ptr = retVal
  58. return Polycore.__ptr_lookup[retVal]
  59. end
  60. end
  61. function Vector3:Normalize()
  62. local retVal = Polycore.Vector3_Normalize(self.__ptr)
  63. end