Vector3.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. Polycore.__ptr_lookup[self.__ptr] = self
  35. end
  36. end
  37. function Vector3:set(x, y, z)
  38. local retVal = Polycore.Vector3_set(self.__ptr, x, y, z)
  39. end
  40. function Vector3:distance(vec2)
  41. local retVal = Polycore.Vector3_distance(self.__ptr, vec2.__ptr)
  42. return retVal
  43. end
  44. function Vector3:length()
  45. local retVal = Polycore.Vector3_length(self.__ptr)
  46. return retVal
  47. end
  48. function Vector3:dot(u)
  49. local retVal = Polycore.Vector3_dot(self.__ptr, u.__ptr)
  50. return retVal
  51. end
  52. function Vector3:crossProduct(vec2)
  53. local retVal = Polycore.Vector3_crossProduct(self.__ptr, vec2.__ptr)
  54. if Polycore.__ptr_lookup[retVal] ~= nil then
  55. return Polycore.__ptr_lookup[retVal]
  56. else
  57. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  58. Polycore.__ptr_lookup[retVal].__ptr = retVal
  59. return Polycore.__ptr_lookup[retVal]
  60. end
  61. end
  62. function Vector3:Normalize()
  63. local retVal = Polycore.Vector3_Normalize(self.__ptr)
  64. end