PhysicsScene.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. require "Physics3D/CollisionScene"
  2. class "PhysicsScene" (CollisionScene)
  3. function PhysicsScene:PhysicsScene(...)
  4. if type(arg[1]) == "table" and count(arg) == 1 then
  5. if ""..arg[1]:class() == "CollisionScene" 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 = Physics3D.PhysicsScene(unpack(arg))
  19. Polycore.__ptr_lookup[self.__ptr] = self
  20. end
  21. end
  22. function PhysicsScene:Update()
  23. local retVal = Physics3D.PhysicsScene_Update(self.__ptr)
  24. end
  25. function PhysicsScene:removePhysicsChild(entity)
  26. local retVal = Physics3D.PhysicsScene_removePhysicsChild(self.__ptr, entity.__ptr)
  27. end
  28. function PhysicsScene:getPhysicsEntityBySceneEntity(entity)
  29. local retVal = Physics3D.PhysicsScene_getPhysicsEntityBySceneEntity(self.__ptr, entity.__ptr)
  30. if retVal == nil then return nil end
  31. if Polycore.__ptr_lookup[retVal] ~= nil then
  32. return Polycore.__ptr_lookup[retVal]
  33. else
  34. Polycore.__ptr_lookup[retVal] = PhysicsSceneEntity("__skip_ptr__")
  35. Polycore.__ptr_lookup[retVal].__ptr = retVal
  36. return Polycore.__ptr_lookup[retVal]
  37. end
  38. end
  39. function PhysicsScene:addPhysicsChild(newEntity, type, mass, friction, restitution, group)
  40. local retVal = Physics3D.PhysicsScene_addPhysicsChild(self.__ptr, newEntity.__ptr, type, mass, friction, restitution, group)
  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] = PhysicsSceneEntity("__skip_ptr__")
  46. Polycore.__ptr_lookup[retVal].__ptr = retVal
  47. return Polycore.__ptr_lookup[retVal]
  48. end
  49. end
  50. function PhysicsScene:trackPhysicsChild(newEntity, type, mass, friction, restitution, group)
  51. local retVal = Physics3D.PhysicsScene_trackPhysicsChild(self.__ptr, newEntity.__ptr, type, mass, friction, restitution, group)
  52. if retVal == nil then return nil end
  53. if Polycore.__ptr_lookup[retVal] ~= nil then
  54. return Polycore.__ptr_lookup[retVal]
  55. else
  56. Polycore.__ptr_lookup[retVal] = PhysicsSceneEntity("__skip_ptr__")
  57. Polycore.__ptr_lookup[retVal].__ptr = retVal
  58. return Polycore.__ptr_lookup[retVal]
  59. end
  60. end
  61. function PhysicsScene:addCharacterChild(newEntity, mass, friction, stepSize, group)
  62. local retVal = Physics3D.PhysicsScene_addCharacterChild(self.__ptr, newEntity.__ptr, mass, friction, stepSize, group)
  63. if retVal == nil then return nil end
  64. if Polycore.__ptr_lookup[retVal] ~= nil then
  65. return Polycore.__ptr_lookup[retVal]
  66. else
  67. Polycore.__ptr_lookup[retVal] = PhysicsCharacter("__skip_ptr__")
  68. Polycore.__ptr_lookup[retVal].__ptr = retVal
  69. return Polycore.__ptr_lookup[retVal]
  70. end
  71. end
  72. function PhysicsScene:removeCharacterChild(character)
  73. local retVal = Physics3D.PhysicsScene_removeCharacterChild(self.__ptr, character.__ptr)
  74. end
  75. function PhysicsScene:addVehicleChild(newEntity, mass, friction, group)
  76. local retVal = Physics3D.PhysicsScene_addVehicleChild(self.__ptr, newEntity.__ptr, mass, friction, group)
  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] = PhysicsVehicle("__skip_ptr__")
  82. Polycore.__ptr_lookup[retVal].__ptr = retVal
  83. return Polycore.__ptr_lookup[retVal]
  84. end
  85. end
  86. function PhysicsScene:__delete()
  87. Polycore.__ptr_lookup[self.__ptr] = nil
  88. Physics3D.delete_PhysicsScene(self.__ptr)
  89. end