Vector4.lua 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. class "Vector4"
  2. function Vector4:__getvar(name)
  3. if name == "x" then
  4. return Polycode.Vector4_get_x(self.__ptr)
  5. elseif name == "y" then
  6. return Polycode.Vector4_get_y(self.__ptr)
  7. elseif name == "z" then
  8. return Polycode.Vector4_get_z(self.__ptr)
  9. elseif name == "w" then
  10. return Polycode.Vector4_get_w(self.__ptr)
  11. end
  12. end
  13. function Vector4:__setvar(name,value)
  14. if name == "x" then
  15. Polycode.Vector4_set_x(self.__ptr, value)
  16. return true
  17. elseif name == "y" then
  18. Polycode.Vector4_set_y(self.__ptr, value)
  19. return true
  20. elseif name == "z" then
  21. Polycode.Vector4_set_z(self.__ptr, value)
  22. return true
  23. elseif name == "w" then
  24. Polycode.Vector4_set_w(self.__ptr, value)
  25. return true
  26. end
  27. return false
  28. end
  29. function Vector4:Vector4(...)
  30. local arg = {...}
  31. for k,v in pairs(arg) do
  32. if type(v) == "table" then
  33. if v.__ptr ~= nil then
  34. arg[k] = v.__ptr
  35. end
  36. end
  37. end
  38. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  39. self.__ptr = Polycode.Vector4(unpack(arg))
  40. end
  41. end
  42. function Vector4:set(x, y, z, w)
  43. local retVal = Polycode.Vector4_set(self.__ptr, x, y, z, w)
  44. end
  45. function Vector4:dot(u)
  46. local retVal = Polycode.Vector4_dot(self.__ptr, u.__ptr)
  47. return retVal
  48. end
  49. function Vector4:__delete()
  50. if self then Polycode.delete_Vector4(self.__ptr) end
  51. end