PhysicsScreen.lua 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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, friction, density, restitution, isSensor, fixedRotation)
  26. local retVal = Physics2D.PhysicsScreen_addPhysicsChild(self.__ptr, newEntity.__ptr, entType, friction, density, restitution, isSensor, fixedRotation)
  27. if Polycore.__ptr_lookup[retVal] ~= nil then
  28. return Polycore.__ptr_lookup[retVal]
  29. else
  30. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  31. Polycore.__ptr_lookup[retVal].__ptr = retVal
  32. return Polycore.__ptr_lookup[retVal]
  33. end
  34. end
  35. function PhysicsScreen:removePhysicsChild(entityToRemove)
  36. local retVal = Physics2D.PhysicsScreen_removePhysicsChild(self.__ptr, entityToRemove.__ptr)
  37. end
  38. function PhysicsScreen:addCollisionChild(newEntity, entType)
  39. local retVal = Physics2D.PhysicsScreen_addCollisionChild(self.__ptr, newEntity.__ptr, entType)
  40. if Polycore.__ptr_lookup[retVal] ~= nil then
  41. return Polycore.__ptr_lookup[retVal]
  42. else
  43. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  44. Polycore.__ptr_lookup[retVal].__ptr = retVal
  45. return Polycore.__ptr_lookup[retVal]
  46. end
  47. end
  48. function PhysicsScreen:destroyJoint(joint)
  49. local retVal = Physics2D.PhysicsScreen_destroyJoint(self.__ptr, joint.__ptr)
  50. end
  51. function PhysicsScreen:createDistanceJoint(ent1, ent2, collideConnected)
  52. local retVal = Physics2D.PhysicsScreen_createDistanceJoint(self.__ptr, ent1.__ptr, ent2.__ptr, collideConnected)
  53. end
  54. function PhysicsScreen:createPrismaticJoint(ent1, ent2, collideConnected)
  55. local retVal = Physics2D.PhysicsScreen_createPrismaticJoint(self.__ptr, ent1.__ptr, ent2.__ptr, collideConnected)
  56. end
  57. function PhysicsScreen:createRevoluteJoint(ent1, ent2, ax, ay, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
  58. local retVal = Physics2D.PhysicsScreen_createRevoluteJoint(self.__ptr, ent1.__ptr, ent2.__ptr, ax, ay, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
  59. if Polycore.__ptr_lookup[retVal] ~= nil then
  60. return Polycore.__ptr_lookup[retVal]
  61. else
  62. Polycore.__ptr_lookup[retVal] = PhysicsJoint("__skip_ptr__")
  63. Polycore.__ptr_lookup[retVal].__ptr = retVal
  64. return Polycore.__ptr_lookup[retVal]
  65. end
  66. end
  67. function PhysicsScreen:applyForce(ent, fx, fy)
  68. local retVal = Physics2D.PhysicsScreen_applyForce(self.__ptr, ent.__ptr, fx, fy)
  69. end
  70. function PhysicsScreen:applyImpulse(ent, fx, fy)
  71. local retVal = Physics2D.PhysicsScreen_applyImpulse(self.__ptr, ent.__ptr, fx, fy)
  72. end
  73. function PhysicsScreen:setGravity(newGravity)
  74. local retVal = Physics2D.PhysicsScreen_setGravity(self.__ptr, newGravity.__ptr)
  75. end
  76. function PhysicsScreen:setTransform(ent, pos, angle)
  77. local retVal = Physics2D.PhysicsScreen_setTransform(self.__ptr, ent.__ptr, pos.__ptr, angle)
  78. end
  79. function PhysicsScreen:getPhysicsEntityByShape(shape)
  80. local retVal = Physics2D.PhysicsScreen_getPhysicsEntityByShape(self.__ptr, shape.__ptr)
  81. if Polycore.__ptr_lookup[retVal] ~= nil then
  82. return Polycore.__ptr_lookup[retVal]
  83. else
  84. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  85. Polycore.__ptr_lookup[retVal].__ptr = retVal
  86. return Polycore.__ptr_lookup[retVal]
  87. end
  88. end
  89. function PhysicsScreen:getPhysicsEntityByFixture(fixture)
  90. local retVal = Physics2D.PhysicsScreen_getPhysicsEntityByFixture(self.__ptr, fixture.__ptr)
  91. if Polycore.__ptr_lookup[retVal] ~= nil then
  92. return Polycore.__ptr_lookup[retVal]
  93. else
  94. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  95. Polycore.__ptr_lookup[retVal].__ptr = retVal
  96. return Polycore.__ptr_lookup[retVal]
  97. end
  98. end
  99. function PhysicsScreen:setVelocity(ent, fx, fy)
  100. local retVal = Physics2D.PhysicsScreen_setVelocity(self.__ptr, ent.__ptr, fx, fy)
  101. end
  102. function PhysicsScreen:setVelocityX(ent, fx)
  103. local retVal = Physics2D.PhysicsScreen_setVelocityX(self.__ptr, ent.__ptr, fx)
  104. end
  105. function PhysicsScreen:setVelocityY(ent, fy)
  106. local retVal = Physics2D.PhysicsScreen_setVelocityY(self.__ptr, ent.__ptr, fy)
  107. end
  108. function PhysicsScreen:setSpin(ent, spin)
  109. local retVal = Physics2D.PhysicsScreen_setSpin(self.__ptr, ent.__ptr, spin)
  110. end
  111. function PhysicsScreen:getVelocity(ent)
  112. local retVal = Physics2D.PhysicsScreen_getVelocity(self.__ptr, ent.__ptr)
  113. if Polycore.__ptr_lookup[retVal] ~= nil then
  114. return Polycore.__ptr_lookup[retVal]
  115. else
  116. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  117. Polycore.__ptr_lookup[retVal].__ptr = retVal
  118. return Polycore.__ptr_lookup[retVal]
  119. end
  120. end
  121. function PhysicsScreen:BeginContact(contact)
  122. local retVal = Physics2D.PhysicsScreen_BeginContact(self.__ptr, contact.__ptr)
  123. end
  124. function PhysicsScreen:EndContact(contact)
  125. local retVal = Physics2D.PhysicsScreen_EndContact(self.__ptr, contact.__ptr)
  126. end
  127. function PhysicsScreen:wakeUp(ent)
  128. local retVal = Physics2D.PhysicsScreen_wakeUp(self.__ptr, ent.__ptr)
  129. end
  130. function PhysicsScreen:getEntityCollisionNormal(ent1, ent2)
  131. local retVal = Physics2D.PhysicsScreen_getEntityCollisionNormal(self.__ptr, ent1.__ptr, ent2.__ptr)
  132. if Polycore.__ptr_lookup[retVal] ~= nil then
  133. return Polycore.__ptr_lookup[retVal]
  134. else
  135. Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
  136. Polycore.__ptr_lookup[retVal].__ptr = retVal
  137. return Polycore.__ptr_lookup[retVal]
  138. end
  139. end
  140. function PhysicsScreen:areEntitiesColliding(ent1, ent2)
  141. local retVal = Physics2D.PhysicsScreen_areEntitiesColliding(self.__ptr, ent1.__ptr, ent2.__ptr)
  142. return retVal
  143. end
  144. function PhysicsScreen:getEntityAtPosition(x, y)
  145. local retVal = Physics2D.PhysicsScreen_getEntityAtPosition(self.__ptr, x, y)
  146. if Polycore.__ptr_lookup[retVal] ~= nil then
  147. return Polycore.__ptr_lookup[retVal]
  148. else
  149. Polycore.__ptr_lookup[retVal] = ScreenEntity("__skip_ptr__")
  150. Polycore.__ptr_lookup[retVal].__ptr = retVal
  151. return Polycore.__ptr_lookup[retVal]
  152. end
  153. end
  154. function PhysicsScreen:testEntityAtPosition(ent, x, y)
  155. local retVal = Physics2D.PhysicsScreen_testEntityAtPosition(self.__ptr, ent.__ptr, x, y)
  156. return retVal
  157. end
  158. function PhysicsScreen:Shutdown()
  159. local retVal = Physics2D.PhysicsScreen_Shutdown(self.__ptr)
  160. end
  161. function PhysicsScreen:getPhysicsByScreenEntity(ent)
  162. local retVal = Physics2D.PhysicsScreen_getPhysicsByScreenEntity(self.__ptr, ent.__ptr)
  163. if Polycore.__ptr_lookup[retVal] ~= nil then
  164. return Polycore.__ptr_lookup[retVal]
  165. else
  166. Polycore.__ptr_lookup[retVal] = PhysicsScreenEntity("__skip_ptr__")
  167. Polycore.__ptr_lookup[retVal].__ptr = retVal
  168. return Polycore.__ptr_lookup[retVal]
  169. end
  170. end
  171. function PhysicsScreen:destroyMouseJoint(mJoint)
  172. local retVal = Physics2D.PhysicsScreen_destroyMouseJoint(self.__ptr, mJoint.__ptr)
  173. end
  174. function PhysicsScreen:__delete()
  175. Polycore.__ptr_lookup[self.__ptr] = nil
  176. Physics2D.delete_PhysicsScreen(self.__ptr)
  177. end