Vector3.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 retVal == nil then return nil end
  55. if Polycore.__ptr_lookup[retVal] ~= nil then
  56. return Polycore.__ptr_lookup[retVal]
  57. else
  58. Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
  59. Polycore.__ptr_lookup[retVal].__ptr = retVal
  60. return Polycore.__ptr_lookup[retVal]
  61. end
  62. end
  63. function Vector3:Normalize()
  64. local retVal = Polycore.Vector3_Normalize(self.__ptr)
  65. end
  66. function Vector3:__delete()
  67. Polycore.__ptr_lookup[self.__ptr] = nil
  68. Polycore.delete_Vector3(self.__ptr)
  69. end