Camera.lua 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. require "Polycode/Entity"
  2. class "Camera" (Entity)
  3. Camera.ORTHO_SIZE_MANUAL = 0
  4. Camera.ORTHO_SIZE_LOCK_HEIGHT = 1
  5. Camera.ORTHO_SIZE_LOCK_WIDTH = 2
  6. Camera.ORTHO_SIZE_VIEWPORT = 3
  7. Camera.PERSPECTIVE_FOV = 4
  8. Camera.PERSPECTIVE_FRUSTUM = 5
  9. Camera.MANUAL_MATRIX = 6
  10. function Camera:__getvar(name)
  11. if name == "frustumCulling" then
  12. return Polycode.Camera_get_frustumCulling(self.__ptr)
  13. elseif name == "topLeftOrtho" then
  14. return Polycode.Camera_get_topLeftOrtho(self.__ptr)
  15. elseif name == "cameraShift" then
  16. local retVal = Polycode.Camera_get_cameraShift(self.__ptr)
  17. if retVal == nil then return nil end
  18. local __c = _G["Vector2"]("__skip_ptr__")
  19. __c.__ptr = retVal
  20. return __c
  21. end
  22. if Entity["__getvar"] ~= nil then
  23. return Entity.__getvar(self, name)
  24. end
  25. end
  26. function Camera:__setvar(name,value)
  27. if name == "frustumCulling" then
  28. Polycode.Camera_set_frustumCulling(self.__ptr, value)
  29. return true
  30. elseif name == "topLeftOrtho" then
  31. Polycode.Camera_set_topLeftOrtho(self.__ptr, value)
  32. return true
  33. elseif name == "cameraShift" then
  34. Polycode.Camera_set_cameraShift(self.__ptr, value.__ptr)
  35. return true
  36. end
  37. if Entity["__setvar"] ~= nil then
  38. return Entity.__setvar(self, name, value)
  39. else
  40. return false
  41. end
  42. end
  43. function Camera:Camera(...)
  44. local arg = {...}
  45. if type(arg[1]) == "table" and count(arg) == 1 then
  46. if ""..arg[1].__classname == "Entity" then
  47. self.__ptr = arg[1].__ptr
  48. return
  49. end
  50. end
  51. for k,v in pairs(arg) do
  52. if type(v) == "table" then
  53. if v.__ptr ~= nil then
  54. arg[k] = v.__ptr
  55. end
  56. end
  57. end
  58. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  59. self.__ptr = Polycode.Camera(unpack(arg))
  60. end
  61. end
  62. function Camera:buildFrustumPlanes()
  63. local retVal = Polycode.Camera_buildFrustumPlanes(self.__ptr)
  64. end
  65. function Camera:isSphereInFrustum(pos, fRadius)
  66. local retVal = Polycode.Camera_isSphereInFrustum(self.__ptr, pos.__ptr, fRadius)
  67. return retVal
  68. end
  69. function Camera:isAABBInFrustum(aabb)
  70. local retVal = Polycode.Camera_isAABBInFrustum(self.__ptr, aabb.__ptr)
  71. return retVal
  72. end
  73. function Camera:setOrthoMode(mode)
  74. local retVal = Polycode.Camera_setOrthoMode(self.__ptr, mode)
  75. end
  76. function Camera:setOrthoSize(orthoSizeX, orthoSizeY)
  77. local retVal = Polycode.Camera_setOrthoSize(self.__ptr, orthoSizeX, orthoSizeY)
  78. end
  79. function Camera:setFrustumMode(left, right, bottom, top, front, back)
  80. local retVal = Polycode.Camera_setFrustumMode(self.__ptr, left, right, bottom, top, front, back)
  81. end
  82. function Camera:getOrthoMode()
  83. local retVal = Polycode.Camera_getOrthoMode(self.__ptr)
  84. return retVal
  85. end
  86. function Camera:getOrthoSizeX()
  87. local retVal = Polycode.Camera_getOrthoSizeX(self.__ptr)
  88. return retVal
  89. end
  90. function Camera:getOrthoSizeY()
  91. local retVal = Polycode.Camera_getOrthoSizeY(self.__ptr)
  92. return retVal
  93. end
  94. function Camera:setFOV(fov)
  95. local retVal = Polycode.Camera_setFOV(self.__ptr, fov)
  96. end
  97. function Camera:getFOV()
  98. local retVal = Polycode.Camera_getFOV(self.__ptr)
  99. return retVal
  100. end
  101. function Camera:setClippingPlanes(nearClipPlane, farClipPlane)
  102. local retVal = Polycode.Camera_setClippingPlanes(self.__ptr, nearClipPlane, farClipPlane)
  103. end
  104. function Camera:getNearClippingPlane()
  105. local retVal = Polycode.Camera_getNearClippingPlane(self.__ptr)
  106. return retVal
  107. end
  108. function Camera:getFarClippingPlane()
  109. local retVal = Polycode.Camera_getFarClippingPlane(self.__ptr)
  110. return retVal
  111. end
  112. function Camera:createProjectionMatrix()
  113. local retVal = Polycode.Camera_createProjectionMatrix(self.__ptr)
  114. if retVal == nil then return nil end
  115. local __c = _G["Matrix4"]("__skip_ptr__")
  116. __c.__ptr = retVal
  117. return __c
  118. end
  119. function Camera:hasFilterShader()
  120. local retVal = Polycode.Camera_hasFilterShader(self.__ptr)
  121. return retVal
  122. end
  123. function Camera:setPostFilter(material)
  124. local retVal = Polycode.Camera_setPostFilter(self.__ptr, material.__ptr)
  125. end
  126. function Camera:removePostFilter()
  127. local retVal = Polycode.Camera_removePostFilter(self.__ptr)
  128. end
  129. function Camera:getScreenShaderMaterial()
  130. local retVal = Polycode.Camera_getScreenShaderMaterial(self.__ptr)
  131. if retVal == nil then return nil end
  132. local __c = _G["shared_ptr<Material>"]("__skip_ptr__")
  133. __c.__ptr = retVal
  134. return __c
  135. end
  136. function Camera:getProjectionMatrix()
  137. local retVal = Polycode.Camera_getProjectionMatrix(self.__ptr)
  138. if retVal == nil then return nil end
  139. local __c = _G["Matrix4"]("__skip_ptr__")
  140. __c.__ptr = retVal
  141. return __c
  142. end
  143. function Camera:setCustomProjectionMatrix(matrix)
  144. local retVal = Polycode.Camera_setCustomProjectionMatrix(self.__ptr, matrix.__ptr)
  145. end
  146. function Camera:getViewport()
  147. local retVal = Polycode.Camera_getViewport(self.__ptr)
  148. if retVal == nil then return nil end
  149. local __c = _G["Rectangle"]("__skip_ptr__")
  150. __c.__ptr = retVal
  151. return __c
  152. end
  153. function Camera:setViewport(viewport)
  154. local retVal = Polycode.Camera_setViewport(self.__ptr, viewport.__ptr)
  155. end
  156. function Camera:setOrthoSizeMode(orthoSizeMode)
  157. local retVal = Polycode.Camera_setOrthoSizeMode(self.__ptr, orthoSizeMode)
  158. end
  159. function Camera:getOrthoSizeMode()
  160. local retVal = Polycode.Camera_getOrthoSizeMode(self.__ptr)
  161. return retVal
  162. end
  163. function Camera:setProjectionMode(mode)
  164. local retVal = Polycode.Camera_setProjectionMode(self.__ptr, mode)
  165. end
  166. function Camera:getProjectionMode()
  167. local retVal = Polycode.Camera_getProjectionMode(self.__ptr)
  168. return retVal
  169. end
  170. function Camera:projectRayFrom2DCoordinate(coordinate, viewport)
  171. local retVal = Polycode.Camera_projectRayFrom2DCoordinate(self.__ptr, coordinate.__ptr, viewport.__ptr)
  172. if retVal == nil then return nil end
  173. local __c = _G["Vector3"]("__skip_ptr__")
  174. __c.__ptr = retVal
  175. return __c
  176. end
  177. function Camera:getShaderPass(index)
  178. local retVal = Polycode.Camera_getShaderPass(self.__ptr, index)
  179. if retVal == nil then return nil end
  180. local __c = _G["ShaderPass"]("__skip_ptr__")
  181. __c.__ptr = retVal
  182. return __c
  183. end
  184. function Camera:getNumShaderPasses()
  185. local retVal = Polycode.Camera_getNumShaderPasses(self.__ptr)
  186. return retVal
  187. end
  188. function Camera:__delete()
  189. if self then Polycode.delete_Camera(self.__ptr) end
  190. end