PhysicsScene.lua 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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:addPhysicsChild(newEntity, type, mass, friction, restitution, group)
  26. local retVal = Physics3D.PhysicsScene_addPhysicsChild(self.__ptr, newEntity.__ptr, type, mass, friction, restitution, group)
  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] = PhysicsSceneEntity("__skip_ptr__")
  32. Polycore.__ptr_lookup[retVal].__ptr = retVal
  33. return Polycore.__ptr_lookup[retVal]
  34. end
  35. end
  36. function PhysicsScene:trackPhysicsChild(newEntity, type, mass, friction, restitution, group)
  37. local retVal = Physics3D.PhysicsScene_trackPhysicsChild(self.__ptr, newEntity.__ptr, type, mass, friction, restitution, group)
  38. if retVal == nil then return nil end
  39. if Polycore.__ptr_lookup[retVal] ~= nil then
  40. return Polycore.__ptr_lookup[retVal]
  41. else
  42. Polycore.__ptr_lookup[retVal] = PhysicsSceneEntity("__skip_ptr__")
  43. Polycore.__ptr_lookup[retVal].__ptr = retVal
  44. return Polycore.__ptr_lookup[retVal]
  45. end
  46. end
  47. function PhysicsScene:addCharacterChild(newEntity, mass, friction, stepSize, group)
  48. local retVal = Physics3D.PhysicsScene_addCharacterChild(self.__ptr, newEntity.__ptr, mass, friction, stepSize, group)
  49. if retVal == nil then return nil end
  50. if Polycore.__ptr_lookup[retVal] ~= nil then
  51. return Polycore.__ptr_lookup[retVal]
  52. else
  53. Polycore.__ptr_lookup[retVal] = PhysicsCharacter("__skip_ptr__")
  54. Polycore.__ptr_lookup[retVal].__ptr = retVal
  55. return Polycore.__ptr_lookup[retVal]
  56. end
  57. end
  58. function PhysicsScene:addVehicleChild(newEntity, mass, friction, group)
  59. local retVal = Physics3D.PhysicsScene_addVehicleChild(self.__ptr, newEntity.__ptr, mass, friction, group)
  60. if retVal == nil then return nil end
  61. if Polycore.__ptr_lookup[retVal] ~= nil then
  62. return Polycore.__ptr_lookup[retVal]
  63. else
  64. Polycore.__ptr_lookup[retVal] = PhysicsVehicle("__skip_ptr__")
  65. Polycore.__ptr_lookup[retVal].__ptr = retVal
  66. return Polycore.__ptr_lookup[retVal]
  67. end
  68. end
  69. function PhysicsScene:__delete()
  70. Polycore.__ptr_lookup[self.__ptr] = nil
  71. Physics3D.delete_PhysicsScene(self.__ptr)
  72. end