Ray.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. class "Ray"
  2. function Ray:__getvar(name)
  3. if name == "origin" then
  4. local retVal = Polycode.Ray_get_origin(self.__ptr)
  5. if retVal == nil then return nil end
  6. local __c = _G["Vector3"]("__skip_ptr__")
  7. __c.__ptr = retVal
  8. return __c
  9. elseif name == "direction" then
  10. local retVal = Polycode.Ray_get_direction(self.__ptr)
  11. if retVal == nil then return nil end
  12. local __c = _G["Vector3"]("__skip_ptr__")
  13. __c.__ptr = retVal
  14. return __c
  15. elseif name == "inv_direction" then
  16. local retVal = Polycode.Ray_get_inv_direction(self.__ptr)
  17. if retVal == nil then return nil end
  18. local __c = _G["Vector3"]("__skip_ptr__")
  19. __c.__ptr = retVal
  20. return __c
  21. end
  22. end
  23. function Ray:__setvar(name,value)
  24. if name == "origin" then
  25. Polycode.Ray_set_origin(self.__ptr, value.__ptr)
  26. return true
  27. elseif name == "direction" then
  28. Polycode.Ray_set_direction(self.__ptr, value.__ptr)
  29. return true
  30. elseif name == "inv_direction" then
  31. Polycode.Ray_set_inv_direction(self.__ptr, value.__ptr)
  32. return true
  33. end
  34. return false
  35. end
  36. function Ray:Ray(...)
  37. local arg = {...}
  38. for k,v in pairs(arg) do
  39. if type(v) == "table" then
  40. if v.__ptr ~= nil then
  41. arg[k] = v.__ptr
  42. end
  43. end
  44. end
  45. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  46. self.__ptr = Polycode.Ray(unpack(arg))
  47. end
  48. end
  49. function Ray:boxIntersect(box, transformMatrix, near, far)
  50. local retVal = Polycode.Ray_boxIntersect(self.__ptr, box.__ptr, transformMatrix.__ptr, near, far)
  51. return retVal
  52. end
  53. function Ray:planeIntersectPoint(planeNormal, planeDistance)
  54. local retVal = Polycode.Ray_planeIntersectPoint(self.__ptr, planeNormal.__ptr, planeDistance)
  55. if retVal == nil then return nil end
  56. local __c = _G["Vector3"]("__skip_ptr__")
  57. __c.__ptr = retVal
  58. return __c
  59. end
  60. function Ray:tranformByMatrix(matrix)
  61. local retVal = Polycode.Ray_tranformByMatrix(self.__ptr, matrix.__ptr)
  62. if retVal == nil then return nil end
  63. local __c = _G["Ray"]("__skip_ptr__")
  64. __c.__ptr = retVal
  65. return __c
  66. end
  67. function Ray:closestPointOnRay(point)
  68. local retVal = Polycode.Ray_closestPointOnRay(self.__ptr, point.__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 Ray:closestPointsBetween(ray2, point1, point2)
  75. local retVal = Polycode.Ray_closestPointsBetween(self.__ptr, ray2.__ptr, point1.__ptr, point2.__ptr)
  76. return retVal
  77. end
  78. function Ray:polygonIntersect(v1, v2, v3)
  79. local retVal = Polycode.Ray_polygonIntersect(self.__ptr, v1.__ptr, v2.__ptr, v3.__ptr)
  80. return retVal
  81. end
  82. function Ray:__delete()
  83. if self then Polycode.delete_Ray(self.__ptr) end
  84. end