PhysicsScreen.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. require "Polycode/Screen"
  2. class "PhysicsScreen" (Screen)
  3. function PhysicsScreen:PhysicsScreen(...)
  4. if type(arg[1]) == "table" and count(arg) == 1 then
  5. if ""..arg[1]:class() == "Screen" then
  6. self.__ptr = arg[1].__ptr
  7. return
  8. end
  9. end
  10. for k,v in pairs(arg) do
  11. if type(v) == "table" then
  12. if v.__ptr ~= nil then
  13. arg[k] = v.__ptr
  14. end
  15. end
  16. end
  17. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  18. self.__ptr = Physics2D.PhysicsScreen(unpack(arg))
  19. Polycore.__ptr_lookup[self.__ptr] = self
  20. end
  21. end
  22. function PhysicsScreen:Update()
  23. local retVal = Physics2D.PhysicsScreen_Update(self.__ptr)
  24. end
  25. function PhysicsScreen:addPhysicsChild(newEntity, entType, isStatic, friction, density, restitution, isSensor, fixedRotation)
  26. local retVal = Physics2D.PhysicsScreen_addPhysicsChild(self.__ptr, newEntity.__ptr, entType, isStatic, friction, density, restitution, isSensor, fixedRotation)
  27. if retVal == nil then return nil end
  28. if Polycore.__ptr_lookup[retVal] ~= nil then
  29. return Polycore.__ptr_lookup[retVal]
  30. else
  31. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  32. Polycore.__ptr_lookup[retVal].__ptr = retVal
  33. return Polycore.__ptr_lookup[retVal]
  34. end
  35. end
  36. function PhysicsScreen:removePhysicsChild(entityToRemove)
  37. local retVal = Physics2D.PhysicsScreen_removePhysicsChild(self.__ptr, entityToRemove.__ptr)
  38. end
  39. function PhysicsScreen:addCollisionChild(newEntity, entType)
  40. local retVal = Physics2D.PhysicsScreen_addCollisionChild(self.__ptr, newEntity.__ptr, entType)
  41. if retVal == nil then return nil end
  42. if Polycore.__ptr_lookup[retVal] ~= nil then
  43. return Polycore.__ptr_lookup[retVal]
  44. else
  45. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  46. Polycore.__ptr_lookup[retVal].__ptr = retVal
  47. return Polycore.__ptr_lookup[retVal]
  48. end
  49. end
  50. function PhysicsScreen:destroyJoint(joint)
  51. local retVal = Physics2D.PhysicsScreen_destroyJoint(self.__ptr, joint.__ptr)
  52. end
  53. function PhysicsScreen:createDistanceJoint(ent1, ent2, collideConnected)
  54. local retVal = Physics2D.PhysicsScreen_createDistanceJoint(self.__ptr, ent1.__ptr, ent2.__ptr, collideConnected)
  55. if retVal == nil then return nil end
  56. if Polycore.__ptr_lookup[retVal] ~= nil then
  57. return Polycore.__ptr_lookup[retVal]
  58. else
  59. Polycore.__ptr_lookup[retVal] = PhysicsJoint("__skip_ptr__")
  60. Polycore.__ptr_lookup[retVal].__ptr = retVal
  61. return Polycore.__ptr_lookup[retVal]
  62. end
  63. end
  64. function PhysicsScreen:createPrismaticJoint(ent1, ent2, worldAxis, ax, ay, collideConnected, lowerTranslation, upperTranslation, enableLimit, motorSpeed, motorForce, motorEnabled)
  65. local retVal = Physics2D.PhysicsScreen_createPrismaticJoint(self.__ptr, ent1.__ptr, ent2.__ptr, worldAxis.__ptr, ax, ay, collideConnected, lowerTranslation, upperTranslation, enableLimit, motorSpeed, motorForce, motorEnabled)
  66. if retVal == nil then return nil end
  67. if Polycore.__ptr_lookup[retVal] ~= nil then
  68. return Polycore.__ptr_lookup[retVal]
  69. else
  70. Polycore.__ptr_lookup[retVal] = PhysicsJoint("__skip_ptr__")
  71. Polycore.__ptr_lookup[retVal].__ptr = retVal
  72. return Polycore.__ptr_lookup[retVal]
  73. end
  74. end
  75. function PhysicsScreen:createRevoluteJoint(ent1, ent2, ax, ay, collideConnected, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
  76. local retVal = Physics2D.PhysicsScreen_createRevoluteJoint(self.__ptr, ent1.__ptr, ent2.__ptr, ax, ay, collideConnected, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
  77. if retVal == nil then return nil end
  78. if Polycore.__ptr_lookup[retVal] ~= nil then
  79. return Polycore.__ptr_lookup[retVal]
  80. else
  81. Polycore.__ptr_lookup[retVal] = PhysicsJoint("__skip_ptr__")
  82. Polycore.__ptr_lookup[retVal].__ptr = retVal
  83. return Polycore.__ptr_lookup[retVal]
  84. end
  85. end
  86. function PhysicsScreen:applyForce(ent, fx, fy)
  87. local retVal = Physics2D.PhysicsScreen_applyForce(self.__ptr, ent.__ptr, fx, fy)
  88. end
  89. function PhysicsScreen:applyImpulse(ent, fx, fy)
  90. local retVal = Physics2D.PhysicsScreen_applyImpulse(self.__ptr, ent.__ptr, fx, fy)
  91. end
  92. function PhysicsScreen:setGravity(newGravity)
  93. local retVal = Physics2D.PhysicsScreen_setGravity(self.__ptr, newGravity.__ptr)
  94. end
  95. function PhysicsScreen:setTransform(ent, pos, angle)
  96. local retVal = Physics2D.PhysicsScreen_setTransform(self.__ptr, ent.__ptr, pos.__ptr, angle)
  97. end
  98. function PhysicsScreen:getPhysicsEntityByShape(shape)
  99. local retVal = Physics2D.PhysicsScreen_getPhysicsEntityByShape(self.__ptr, shape.__ptr)
  100. if retVal == nil then return nil end
  101. if Polycore.__ptr_lookup[retVal] ~= nil then
  102. return Polycore.__ptr_lookup[retVal]
  103. else
  104. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  105. Polycore.__ptr_lookup[retVal].__ptr = retVal
  106. return Polycore.__ptr_lookup[retVal]
  107. end
  108. end
  109. function PhysicsScreen:getPhysicsEntityByFixture(fixture)
  110. local retVal = Physics2D.PhysicsScreen_getPhysicsEntityByFixture(self.__ptr, fixture.__ptr)
  111. if retVal == nil then return nil end
  112. if Polycore.__ptr_lookup[retVal] ~= nil then
  113. return Polycore.__ptr_lookup[retVal]
  114. else
  115. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  116. Polycore.__ptr_lookup[retVal].__ptr = retVal
  117. return Polycore.__ptr_lookup[retVal]
  118. end
  119. end
  120. function PhysicsScreen:setVelocity(ent, fx, fy)
  121. local retVal = Physics2D.PhysicsScreen_setVelocity(self.__ptr, ent.__ptr, fx, fy)
  122. end
  123. function PhysicsScreen:setVelocityX(ent, fx)
  124. local retVal = Physics2D.PhysicsScreen_setVelocityX(self.__ptr, ent.__ptr, fx)
  125. end
  126. function PhysicsScreen:setVelocityY(ent, fy)
  127. local retVal = Physics2D.PhysicsScreen_setVelocityY(self.__ptr, ent.__ptr, fy)
  128. end
  129. function PhysicsScreen:setSpin(ent, spin)
  130. local retVal = Physics2D.PhysicsScreen_setSpin(self.__ptr, ent.__ptr, spin)
  131. end
  132. function PhysicsScreen:getVelocity(ent)
  133. local retVal = Physics2D.PhysicsScreen_getVelocity(self.__ptr, ent.__ptr)
  134. if retVal == nil then return nil end
  135. if Polycore.__ptr_lookup[retVal] ~= nil then
  136. return Polycore.__ptr_lookup[retVal]
  137. else
  138. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  139. Polycore.__ptr_lookup[retVal].__ptr = retVal
  140. return Polycore.__ptr_lookup[retVal]
  141. end
  142. end
  143. function PhysicsScreen:BeginContact(contact)
  144. local retVal = Physics2D.PhysicsScreen_BeginContact(self.__ptr, contact.__ptr)
  145. end
  146. function PhysicsScreen:EndContact(contact)
  147. local retVal = Physics2D.PhysicsScreen_EndContact(self.__ptr, contact.__ptr)
  148. end
  149. function PhysicsScreen:PostSolve(contact, impulse)
  150. local retVal = Physics2D.PhysicsScreen_PostSolve(self.__ptr, contact.__ptr, impulse.__ptr)
  151. end
  152. function PhysicsScreen:wakeUp(ent)
  153. local retVal = Physics2D.PhysicsScreen_wakeUp(self.__ptr, ent.__ptr)
  154. end
  155. function PhysicsScreen:getEntityAtPosition(x, y)
  156. local retVal = Physics2D.PhysicsScreen_getEntityAtPosition(self.__ptr, x, y)
  157. if retVal == nil then return nil end
  158. if Polycore.__ptr_lookup[retVal] ~= nil then
  159. return Polycore.__ptr_lookup[retVal]
  160. else
  161. Polycore.__ptr_lookup[retVal] = ScreenEntity("__skip_ptr__")
  162. Polycore.__ptr_lookup[retVal].__ptr = retVal
  163. return Polycore.__ptr_lookup[retVal]
  164. end
  165. end
  166. function PhysicsScreen:testEntityAtPosition(ent, x, y)
  167. local retVal = Physics2D.PhysicsScreen_testEntityAtPosition(self.__ptr, ent.__ptr, x, y)
  168. return retVal
  169. end
  170. function PhysicsScreen:Shutdown()
  171. local retVal = Physics2D.PhysicsScreen_Shutdown(self.__ptr)
  172. end
  173. function PhysicsScreen:getPhysicsByScreenEntity(ent)
  174. local retVal = Physics2D.PhysicsScreen_getPhysicsByScreenEntity(self.__ptr, ent.__ptr)
  175. if retVal == nil then return nil end
  176. if Polycore.__ptr_lookup[retVal] ~= nil then
  177. return Polycore.__ptr_lookup[retVal]
  178. else
  179. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  180. Polycore.__ptr_lookup[retVal].__ptr = retVal
  181. return Polycore.__ptr_lookup[retVal]
  182. end
  183. end
  184. function PhysicsScreen:destroyMouseJoint(mJoint)
  185. local retVal = Physics2D.PhysicsScreen_destroyMouseJoint(self.__ptr, mJoint.__ptr)
  186. end
  187. function PhysicsScreen:__delete()
  188. Polycore.__ptr_lookup[self.__ptr] = nil
  189. Physics2D.delete_PhysicsScreen(self.__ptr)
  190. end