Просмотр исходного кода

Particle emitter and 2D Physics fixes

Ivan Safrin 14 лет назад
Родитель
Сommit
30d0f0841f
84 измененных файлов с 3222 добавлено и 2312 удалено
  1. 307 347
      Bindings/Build/Mac OS X/Bindings.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
  2. 3 0
      Bindings/Contents/LUA/API/Polycode/BezierCurve.lua
  3. 9 0
      Bindings/Contents/LUA/API/Polycode/Bone.lua
  4. 1 0
      Bindings/Contents/LUA/API/Polycode/Config.lua
  5. 7 0
      Bindings/Contents/LUA/API/Polycode/Core.lua
  6. 3 0
      Bindings/Contents/LUA/API/Polycode/CoreInput.lua
  7. 13 0
      Bindings/Contents/LUA/API/Polycode/CoreServices.lua
  8. 1 0
      Bindings/Contents/LUA/API/Polycode/Data.lua
  9. 13 0
      Bindings/Contents/LUA/API/Polycode/Entity.lua
  10. 1 0
      Bindings/Contents/LUA/API/Polycode/Event.lua
  11. 1 0
      Bindings/Contents/LUA/API/Polycode/FixedShader.lua
  12. 1 0
      Bindings/Contents/LUA/API/Polycode/FixedShaderBinding.lua
  13. 1 0
      Bindings/Contents/LUA/API/Polycode/Font.lua
  14. 1 0
      Bindings/Contents/LUA/API/Polycode/FontManager.lua
  15. 2 0
      Bindings/Contents/LUA/API/Polycode/Image.lua
  16. 2 0
      Bindings/Contents/LUA/API/Polycode/InputEvent.lua
  17. 1 0
      Bindings/Contents/LUA/API/Polycode/Label.lua
  18. 3 0
      Bindings/Contents/LUA/API/Polycode/Material.lua
  19. 10 0
      Bindings/Contents/LUA/API/Polycode/MaterialManager.lua
  20. 4 0
      Bindings/Contents/LUA/API/Polycode/Matrix4.lua
  21. 9 0
      Bindings/Contents/LUA/API/Polycode/Mesh.lua
  22. 1 0
      Bindings/Contents/LUA/API/Polycode/OSBasics.lua
  23. 1 0
      Bindings/Contents/LUA/API/Polycode/ObjectEntry.lua
  24. 1 0
      Bindings/Contents/LUA/API/Polycode/ParticleEmitter.lua
  25. 4 0
      Bindings/Contents/LUA/API/Polycode/Polygon.lua
  26. 7 0
      Bindings/Contents/LUA/API/Polycode/Quaternion.lua
  27. 1 0
      Bindings/Contents/LUA/API/Polycode/QuaternionCurve.lua
  28. 9 0
      Bindings/Contents/LUA/API/Polycode/Renderer.lua
  29. 1 0
      Bindings/Contents/LUA/API/Polycode/ResourceManager.lua
  30. 7 0
      Bindings/Contents/LUA/API/Polycode/Scene.lua
  31. 1 0
      Bindings/Contents/LUA/API/Polycode/SceneLabel.lua
  32. 2 0
      Bindings/Contents/LUA/API/Polycode/SceneLight.lua
  33. 5 0
      Bindings/Contents/LUA/API/Polycode/SceneMesh.lua
  34. 2 0
      Bindings/Contents/LUA/API/Polycode/SceneParticleEmitter.lua
  35. 3 0
      Bindings/Contents/LUA/API/Polycode/SceneRenderTexture.lua
  36. 1 0
      Bindings/Contents/LUA/API/Polycode/SceneSound.lua
  37. 5 0
      Bindings/Contents/LUA/API/Polycode/Screen.lua
  38. 2 0
      Bindings/Contents/LUA/API/Polycode/ScreenEntity.lua
  39. 1 0
      Bindings/Contents/LUA/API/Polycode/ScreenLabel.lua
  40. 3 3
      Bindings/Contents/LUA/API/Polycode/ScreenLine.lua
  41. 2 0
      Bindings/Contents/LUA/API/Polycode/ScreenMesh.lua
  42. 2 0
      Bindings/Contents/LUA/API/Polycode/ScreenParticleEmitter.lua
  43. 1 0
      Bindings/Contents/LUA/API/Polycode/ScreenSound.lua
  44. 1 0
      Bindings/Contents/LUA/API/Polycode/Shader.lua
  45. 5 0
      Bindings/Contents/LUA/API/Polycode/ShaderBinding.lua
  46. 4 0
      Bindings/Contents/LUA/API/Polycode/Skeleton.lua
  47. 3 0
      Bindings/Contents/LUA/API/Polycode/Sound.lua
  48. 6 0
      Bindings/Contents/LUA/API/Polycode/String.lua
  49. 1 0
      Bindings/Contents/LUA/API/Polycode/Texture.lua
  50. 1 0
      Bindings/Contents/LUA/API/Polycode/Vector3.lua
  51. 2 0
      Bindings/Contents/LUA/API/Polycode/Vertex.lua
  52. 451 74
      Bindings/Contents/LUA/Include/PolycodeLUAWrappers.h
  53. 1 0
      Bindings/Contents/LUA/Source/PolycodeLUA.cpp
  54. 9 2
      Bindings/Scripts/create_lua_library/create_lua_library.py
  55. 230 452
      Core/Build/Mac OS X/PolyCore.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
  56. 6 0
      Core/Contents/Include/PolyMesh.h
  57. 143 10
      Core/Contents/Include/PolyParticleEmitter.h
  58. 7 6
      Core/Contents/Include/PolyScreenLine.h
  59. 8 0
      Core/Contents/Source/PolyMesh.cpp
  60. 2 2
      Core/Contents/Source/PolyParticleEmitter.cpp
  61. 34 24
      Core/Contents/Source/PolyScreenLine.cpp
  62. 1 0
      Modules/Bindings/2DPhysics/API/Physics2D.lua
  63. 34 22
      Modules/Bindings/2DPhysics/API/Physics2D/PhysicsScreen.lua
  64. 2 1
      Modules/Bindings/2DPhysics/API/Physics2D/PhysicsScreenEntity.lua
  65. 106 0
      Modules/Bindings/2DPhysics/API/Physics2D/PhysicsScreenEvent.lua
  66. 271 66
      Modules/Bindings/2DPhysics/Include/Physics2DLUAWrappers.h
  67. 12 2
      Modules/Bindings/2DPhysics/Source/Physics2DLUA.cpp
  68. 11 0
      Modules/Bindings/3DPhysics/API/Physics3D/CollisionScene.lua
  69. 30 0
      Modules/Bindings/3DPhysics/API/Physics3D/CollisionSceneEntity.lua
  70. 4 0
      Modules/Bindings/3DPhysics/API/Physics3D/PhysicsScene.lua
  71. 1 0
      Modules/Bindings/3DPhysics/API/Physics3D/PhysicsSceneEntity.lua
  72. 19 0
      Modules/Bindings/3DPhysics/API/Physics3D/PhysicsVehicle.lua
  73. 107 12
      Modules/Bindings/3DPhysics/Include/Physics3DLUAWrappers.h
  74. 5 0
      Modules/Bindings/3DPhysics/Source/Physics3DLUA.cpp
  75. 15 0
      Modules/Build/Mac OS X/Modules.xcodeproj/project.pbxproj
  76. 311 422
      Modules/Build/Mac OS X/Modules.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
  77. 5 0
      Modules/Build/Mac OS X/Modules.xcodeproj/xcuserdata/ivansafrin.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
  78. 77 29
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h
  79. 7 3
      Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h
  80. 122 138
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp
  81. 45 21
      Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp
  82. 0 4
      Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer.xcodeproj/project.pbxproj
  83. 442 240
      Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate
  84. 226 432
      Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate

Разница между файлами не показана из-за своего большого размера
+ 307 - 347
Bindings/Build/Mac OS X/Bindings.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 3 - 0
Bindings/Contents/LUA/API/Polycode/BezierCurve.lua

@@ -22,6 +22,7 @@ end
 
 function BezierCurve:getControlPoint(index)
 	local retVal = Polycore.BezierCurve_getControlPoint(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -63,6 +64,7 @@ end
 
 function BezierCurve:getPointAt(a)
 	local retVal = Polycore.BezierCurve_getPointAt(self.__ptr, a)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -74,6 +76,7 @@ end
 
 function BezierCurve:getPointBetween(a, bp1, bp2)
 	local retVal = Polycore.BezierCurve_getPointBetween(self.__ptr, a, bp1.__ptr, bp2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 9 - 0
Bindings/Contents/LUA/API/Polycode/Bone.lua

@@ -90,6 +90,7 @@ end
 
 function Bone:getParentBone()
 	local retVal =  Polycore.Bone_getParentBone(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -106,6 +107,7 @@ end
 
 function Bone:getChildBone(index)
 	local retVal = Polycore.Bone_getChildBone(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -117,6 +119,7 @@ end
 
 function Bone:getBoneMatrix()
 	local retVal =  Polycore.Bone_getBoneMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -132,6 +135,7 @@ end
 
 function Bone:getRestMatrix()
 	local retVal =  Polycore.Bone_getRestMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -143,6 +147,7 @@ end
 
 function Bone:getFullRestMatrix()
 	local retVal =  Polycore.Bone_getFullRestMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -154,6 +159,7 @@ end
 
 function Bone:getParentRestMatrix()
 	local retVal =  Polycore.Bone_getParentRestMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -165,6 +171,7 @@ end
 
 function Bone:getFinalMatrix()
 	local retVal =  Polycore.Bone_getFinalMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -184,6 +191,7 @@ end
 
 function Bone:getBaseMatrix()
 	local retVal =  Polycore.Bone_getBaseMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -195,6 +203,7 @@ end
 
 function Bone:getFullBaseMatrix()
 	local retVal =  Polycore.Bone_getFullBaseMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Config.lua

@@ -30,6 +30,7 @@ end
 
 function Config:getEntry(configNamespace, key)
 	local retVal = Polycore.Config_getEntry(self.__ptr, configNamespace, key)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 7 - 0
Bindings/Contents/LUA/API/Polycode/Core.lua

@@ -36,6 +36,7 @@ end
 
 function Core:createMutex()
 	local retVal =  Polycore.Core_createMutex(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -51,6 +52,7 @@ end
 
 function Core:getClipboardString()
 	local retVal =  Polycore.Core_getClipboardString(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -62,6 +64,7 @@ end
 
 function Core:getServices()
 	local retVal =  Polycore.Core_getServices(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -92,6 +95,7 @@ end
 
 function Core:getInput()
 	local retVal =  Polycore.Core_getInput(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -134,6 +138,7 @@ end
 
 function Core:openFolderPicker()
 	local retVal =  Polycore.Core_openFolderPicker(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -166,6 +171,7 @@ end
 
 function Core:getTicks()
 	local retVal =  Polycore.Core_getTicks(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -186,6 +192,7 @@ end
 
 function Core:getUserPointer()
 	local retVal =  Polycore.Core_getUserPointer(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 3 - 0
Bindings/Contents/LUA/API/Polycode/CoreInput.lua

@@ -33,6 +33,7 @@ end
 
 function CoreInput:getMousePosition()
 	local retVal =  Polycore.CoreInput_getMousePosition(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -49,6 +50,7 @@ end
 
 function CoreInput:getMouseDelta()
 	local retVal =  Polycore.CoreInput_getMouseDelta(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -89,6 +91,7 @@ end
 
 function CoreInput:createEvent(event)
 	local retVal = Polycore.CoreInput_createEvent(event.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 13 - 0
Bindings/Contents/LUA/API/Polycode/CoreServices.lua

@@ -10,6 +10,7 @@ class "CoreServices" (EventDispatcher)
 
 function CoreServices:getInstance()
 	local retVal =  Polycore.CoreServices_getInstance()
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -25,6 +26,7 @@ end
 
 function CoreServices:getRenderMutex()
 	local retVal =  Polycore.CoreServices_getRenderMutex()
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -40,6 +42,7 @@ end
 
 function CoreServices:getRenderer()
 	local retVal =  Polycore.CoreServices_getRenderer(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -59,6 +62,7 @@ end
 
 function CoreServices:getCore()
 	local retVal =  Polycore.CoreServices_getCore(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -74,6 +78,7 @@ end
 
 function CoreServices:getMaterialManager()
 	local retVal =  Polycore.CoreServices_getMaterialManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -85,6 +90,7 @@ end
 
 function CoreServices:getScreenManager()
 	local retVal =  Polycore.CoreServices_getScreenManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -96,6 +102,7 @@ end
 
 function CoreServices:getSceneManager()
 	local retVal =  Polycore.CoreServices_getSceneManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -107,6 +114,7 @@ end
 
 function CoreServices:getTimerManager()
 	local retVal =  Polycore.CoreServices_getTimerManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -118,6 +126,7 @@ end
 
 function CoreServices:getTweenManager()
 	local retVal =  Polycore.CoreServices_getTweenManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -129,6 +138,7 @@ end
 
 function CoreServices:getResourceManager()
 	local retVal =  Polycore.CoreServices_getResourceManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -140,6 +150,7 @@ end
 
 function CoreServices:getSoundManager()
 	local retVal =  Polycore.CoreServices_getSoundManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -151,6 +162,7 @@ end
 
 function CoreServices:getFontManager()
 	local retVal =  Polycore.CoreServices_getFontManager(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -162,6 +174,7 @@ end
 
 function CoreServices:getConfig()
 	local retVal =  Polycore.CoreServices_getConfig(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Data.lua

@@ -40,6 +40,7 @@ end
 
 function Data:getData()
 	local retVal =  Polycore.Data_getData(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 13 - 0
Bindings/Contents/LUA/API/Polycode/Entity.lua

@@ -150,6 +150,7 @@ end
 
 function Entity:getTransformMatrix()
 	local retVal =  Polycore.Entity_getTransformMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -161,6 +162,7 @@ end
 
 function Entity:getConcatenatedMatrix()
 	local retVal =  Polycore.Entity_getConcatenatedMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -172,6 +174,7 @@ end
 
 function Entity:getConcatenatedRollMatrix()
 	local retVal =  Polycore.Entity_getConcatenatedRollMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -191,6 +194,7 @@ end
 
 function Entity:getLookAtMatrix(loc, upVector)
 	local retVal = Polycore.Entity_getLookAtMatrix(self.__ptr, loc.__ptr, upVector.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -218,6 +222,7 @@ end
 
 function Entity:getParentEntity()
 	local retVal =  Polycore.Entity_getParentEntity(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -229,6 +234,7 @@ end
 
 function Entity:getPosition()
 	local retVal =  Polycore.Entity_getPosition(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -240,6 +246,7 @@ end
 
 function Entity:getCombinedPosition()
 	local retVal =  Polycore.Entity_getCombinedPosition(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -291,6 +298,7 @@ end
 
 function Entity:getCompoundScale()
 	local retVal =  Polycore.Entity_getCompoundScale(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -302,6 +310,7 @@ end
 
 function Entity:getScale()
 	local retVal =  Polycore.Entity_getScale(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -375,6 +384,7 @@ end
 
 function Entity:getRotationQuat()
 	local retVal =  Polycore.Entity_getRotationQuat(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -394,6 +404,7 @@ end
 
 function Entity:getCombinedColor()
 	local retVal =  Polycore.Entity_getCombinedColor(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -443,6 +454,7 @@ end
 
 function Entity:getChildCenter()
 	local retVal =  Polycore.Entity_getChildCenter(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -463,6 +475,7 @@ end
 
 function Entity:buildPositionMatrix()
 	local retVal =  Polycore.Entity_buildPositionMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Event.lua

@@ -29,6 +29,7 @@ end
 
 function Event:getDispatcher()
 	local retVal =  Polycore.Event_getDispatcher(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/FixedShader.lua

@@ -30,6 +30,7 @@ end
 
 function FixedShader:createBinding()
 	local retVal =  Polycore.FixedShader_createBinding(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/FixedShaderBinding.lua

@@ -42,6 +42,7 @@ end
 
 function FixedShaderBinding:getDiffuseTexture()
 	local retVal =  Polycore.FixedShaderBinding_getDiffuseTexture(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Font.lua

@@ -22,6 +22,7 @@ end
 
 function Font:getFace()
 	local retVal =  Polycore.Font_getFace(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/FontManager.lua

@@ -26,6 +26,7 @@ end
 
 function FontManager:getFontByName(fontName)
 	local retVal = Polycore.FontManager_getFontByName(self.__ptr, fontName)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/Image.lua

@@ -46,6 +46,7 @@ end
 
 function Image:getPixel(x, y)
 	local retVal = Polycore.Image_getPixel(self.__ptr, x, y)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -143,6 +144,7 @@ end
 
 function Image:getPixels()
 	local retVal =  Polycore.Image_getPixels(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/InputEvent.lua

@@ -85,6 +85,7 @@ end
 
 function InputEvent:getMousePosition()
 	local retVal =  Polycore.InputEvent_getMousePosition(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -96,6 +97,7 @@ end
 
 function InputEvent:getKey()
 	local retVal =  Polycore.InputEvent_getKey(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Label.lua

@@ -51,6 +51,7 @@ end
 
 function Label:getFont()
 	local retVal =  Polycore.Label_getFont(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 3 - 0
Bindings/Contents/LUA/API/Polycode/Material.lua

@@ -48,6 +48,7 @@ end
 
 function Material:getShaderRenderTarget(index)
 	local retVal = Polycore.Material_getShaderRenderTarget(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -64,6 +65,7 @@ end
 
 function Material:getShader(index)
 	local retVal = Polycore.Material_getShader(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -75,6 +77,7 @@ end
 
 function Material:getShaderBinding(index)
 	local retVal = Polycore.Material_getShaderBinding(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 10 - 0
Bindings/Contents/LUA/API/Polycode/MaterialManager.lua

@@ -26,6 +26,7 @@ end
 
 function MaterialManager:createFramebufferTexture(width, height, type)
 	local retVal = Polycore.MaterialManager_createFramebufferTexture(self.__ptr, width, height, type)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -37,6 +38,7 @@ end
 
 function MaterialManager:createTexture(width, height, imageData, clamp, type)
 	local retVal = Polycore.MaterialManager_createTexture(self.__ptr, width, height, imageData.__ptr, clamp, type)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -48,6 +50,7 @@ end
 
 function MaterialManager:createNewTexture(width, height, clamp, type)
 	local retVal = Polycore.MaterialManager_createNewTexture(self.__ptr, width, height, clamp, type)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -59,6 +62,7 @@ end
 
 function MaterialManager:createTextureFromImage(image, clamp)
 	local retVal = Polycore.MaterialManager_createTextureFromImage(self.__ptr, image.__ptr, clamp)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -70,6 +74,7 @@ end
 
 function MaterialManager:createTextureFromFile(fileName, clamp)
 	local retVal = Polycore.MaterialManager_createTextureFromFile(self.__ptr, fileName, clamp)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -101,6 +106,7 @@ end
 
 function MaterialManager:getTextureByResourcePath(resourcePath)
 	local retVal = Polycore.MaterialManager_getTextureByResourcePath(self.__ptr, resourcePath)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -112,6 +118,7 @@ end
 
 function MaterialManager:cubemapFromXMLNode(node)
 	local retVal = Polycore.MaterialManager_cubemapFromXMLNode(self.__ptr, node.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -127,6 +134,7 @@ end
 
 function MaterialManager:materialFromXMLNode(node)
 	local retVal = Polycore.MaterialManager_materialFromXMLNode(self.__ptr, node.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -138,6 +146,7 @@ end
 
 function MaterialManager:setShaderFromXMLNode(node)
 	local retVal = Polycore.MaterialManager_setShaderFromXMLNode(self.__ptr, node.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -149,6 +158,7 @@ end
 
 function MaterialManager:createShaderFromXMLNode(node)
 	local retVal = Polycore.MaterialManager_createShaderFromXMLNode(self.__ptr, node.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 4 - 0
Bindings/Contents/LUA/API/Polycode/Matrix4.lua

@@ -26,6 +26,7 @@ end
 
 function Matrix4:rotateVector(v2)
 	local retVal = Polycore.Matrix4_rotateVector(self.__ptr, v2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -37,6 +38,7 @@ end
 
 function Matrix4:getPosition()
 	local retVal =  Polycore.Matrix4_getPosition(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -60,6 +62,7 @@ end
 
 function Matrix4:inverse()
 	local retVal =  Polycore.Matrix4_inverse(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -71,6 +74,7 @@ end
 
 function Matrix4:inverseAffine()
 	local retVal =  Polycore.Matrix4_inverseAffine(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 9 - 0
Bindings/Contents/LUA/API/Polycode/Mesh.lua

@@ -59,8 +59,14 @@ function Mesh:getPolygonCount()
 	return retVal
 end
 
+function Mesh:getVertexCount()
+	local retVal =  Polycore.Mesh_getVertexCount(self.__ptr)
+	return retVal
+end
+
 function Mesh:getPolygon(index)
 	local retVal = Polycore.Mesh_getPolygon(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -92,6 +98,7 @@ end
 
 function Mesh:recenterMesh()
 	local retVal =  Polycore.Mesh_recenterMesh(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -111,6 +118,7 @@ end
 
 function Mesh:getVertexBuffer()
 	local retVal =  Polycore.Mesh_getVertexBuffer(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -140,6 +148,7 @@ end
 
 function Mesh:calculateBBox()
 	local retVal =  Polycore.Mesh_calculateBBox(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/OSBasics.lua

@@ -8,6 +8,7 @@ class "OSBasics"
 
 function OSBasics:open(filename, opts)
 	local retVal = Polycore.OSBasics_open(filename, opts)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/ObjectEntry.lua

@@ -70,6 +70,7 @@ end
 
 function ObjectEntry:addChild(name)
 	local retVal = Polycore.ObjectEntry_addChild(self.__ptr, name)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/ParticleEmitter.lua

@@ -202,6 +202,7 @@ end
 
 function ParticleEmitter:getBaseMatrix()
 	local retVal =  Polycore.ParticleEmitter_getBaseMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 4 - 0
Bindings/Contents/LUA/API/Polycode/Polygon.lua

@@ -39,6 +39,7 @@ end
 
 function Polygon:getVertex(index)
 	local retVal = Polycore.Polygon_getVertex(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -50,6 +51,7 @@ end
 
 function Polygon:addVertex(x, y, z)
 	local retVal = Polycore.Polygon_addVertex(self.__ptr, x, y, z)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -69,6 +71,7 @@ end
 
 function Polygon:getFaceNormal()
 	local retVal =  Polycore.Polygon_getFaceNormal(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -80,6 +83,7 @@ end
 
 function Polygon:getBounds2D()
 	local retVal =  Polycore.Polygon_getBounds2D(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 7 - 0
Bindings/Contents/LUA/API/Polycode/Quaternion.lua

@@ -53,6 +53,7 @@ end
 
 function Quaternion:Slerp(fT, rkP, rkQ, shortestPath)
 	local retVal = Polycore.Quaternion_Slerp(fT, rkP.__ptr, rkQ.__ptr, shortestPath)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -69,6 +70,7 @@ end
 
 function Quaternion:Log()
 	local retVal =  Polycore.Quaternion_Log(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -80,6 +82,7 @@ end
 
 function Quaternion:Exp()
 	local retVal =  Polycore.Quaternion_Exp(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -109,6 +112,7 @@ end
 
 function Quaternion:Squad(fT, rkP, rkA, rkB, rkQ, shortestPath)
 	local retVal = Polycore.Quaternion_Squad(fT, rkP.__ptr, rkA.__ptr, rkB.__ptr, rkQ.__ptr, shortestPath)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -120,6 +124,7 @@ end
 
 function Quaternion:Inverse()
 	local retVal =  Polycore.Quaternion_Inverse(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -135,6 +140,7 @@ end
 
 function Quaternion:inverse()
 	local retVal =  Polycore.Quaternion_inverse(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -167,6 +173,7 @@ end
 
 function Quaternion:createMatrix()
 	local retVal =  Polycore.Quaternion_createMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/QuaternionCurve.lua

@@ -22,6 +22,7 @@ end
 
 function QuaternionCurve:interpolate(t, useShortestPath)
 	local retVal = Polycore.QuaternionCurve_interpolate(self.__ptr, t, useShortestPath)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 9 - 0
Bindings/Contents/LUA/API/Polycode/Renderer.lua

@@ -71,6 +71,7 @@ end
 
 function Renderer:createCubemap(t0, t1, t2, t3, t4, t5)
 	local retVal = Polycore.Renderer_createCubemap(self.__ptr, t0.__ptr, t1.__ptr, t2.__ptr, t3.__ptr, t4.__ptr, t5.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -82,6 +83,7 @@ end
 
 function Renderer:createTexture(width, height, textureData, clamp, type)
 	local retVal = Polycore.Renderer_createTexture(self.__ptr, width, height, textureData.__ptr, clamp, type)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -97,6 +99,7 @@ end
 
 function Renderer:createFramebufferTexture(width, height)
 	local retVal = Polycore.Renderer_createFramebufferTexture(self.__ptr, width, height)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -192,6 +195,7 @@ end
 
 function Renderer:createRenderDataArrayForMesh(mesh, arrayType)
 	local retVal = Polycore.Renderer_createRenderDataArrayForMesh(self.__ptr, mesh.__ptr, arrayType)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -203,6 +207,7 @@ end
 
 function Renderer:createRenderDataArray(arrayType)
 	local retVal = Polycore.Renderer_createRenderDataArray(self.__ptr, arrayType)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -331,6 +336,7 @@ end
 
 function Renderer:getCameraMatrix()
 	local retVal =  Polycore.Renderer_getCameraMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -402,6 +408,7 @@ end
 
 function Renderer:getProjectionMatrix()
 	local retVal =  Polycore.Renderer_getProjectionMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -413,6 +420,7 @@ end
 
 function Renderer:getModelviewMatrix()
 	local retVal =  Polycore.Renderer_getModelviewMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -428,6 +436,7 @@ end
 
 function Renderer:Unproject(x, y)
 	local retVal = Polycore.Renderer_Unproject(self.__ptr, x, y)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/ResourceManager.lua

@@ -63,6 +63,7 @@ end
 
 function ResourceManager:getResource(resourceType, resourceName)
 	local retVal = Polycore.ResourceManager_getResource(self.__ptr, resourceType, resourceName)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 7 - 0
Bindings/Contents/LUA/API/Polycode/Scene.lua

@@ -87,6 +87,7 @@ end
 
 function Scene:getDefaultCamera()
 	local retVal =  Polycore.Scene_getDefaultCamera(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -137,6 +138,7 @@ end
 
 function Scene:getEntity(index)
 	local retVal = Polycore.Scene_getEntity(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -148,6 +150,7 @@ end
 
 function Scene:getEntityAtScreenPosition(x, y)
 	local retVal = Polycore.Scene_getEntityAtScreenPosition(self.__ptr, x, y)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -184,6 +187,7 @@ end
 
 function Scene:getNearestLight(pos)
 	local retVal = Polycore.Scene_getNearestLight(self.__ptr, pos.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -212,6 +216,7 @@ end
 
 function Scene:getStaticGeometry(index)
 	local retVal = Polycore.Scene_getStaticGeometry(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -232,6 +237,7 @@ end
 
 function Scene:getLight(index)
 	local retVal = Polycore.Scene_getLight(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -243,6 +249,7 @@ end
 
 function Scene:getCustomEntityByType(type)
 	local retVal = Polycore.Scene_getCustomEntityByType(self.__ptr, type)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/SceneLabel.lua

@@ -39,6 +39,7 @@ end
 
 function SceneLabel:getLabel()
 	local retVal =  Polycore.SceneLabel_getLabel(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/SceneLight.lua

@@ -80,6 +80,7 @@ end
 
 function SceneLight:getLightViewMatrix()
 	local retVal =  Polycore.SceneLight_getLightViewMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -91,6 +92,7 @@ end
 
 function SceneLight:getZBufferTexture()
 	local retVal =  Polycore.SceneLight_getZBufferTexture(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 5 - 0
Bindings/Contents/LUA/API/Polycode/SceneMesh.lua

@@ -55,6 +55,7 @@ end
 
 function SceneMesh:getLocalShaderOptions()
 	local retVal =  Polycore.SceneMesh_getLocalShaderOptions(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -66,6 +67,7 @@ end
 
 function SceneMesh:getMesh()
 	local retVal =  Polycore.SceneMesh_getMesh(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -77,6 +79,7 @@ end
 
 function SceneMesh:getTexture()
 	local retVal =  Polycore.SceneMesh_getTexture(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -88,6 +91,7 @@ end
 
 function SceneMesh:getMaterial()
 	local retVal =  Polycore.SceneMesh_getMaterial(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -127,6 +131,7 @@ end
 
 function SceneMesh:getSkeleton()
 	local retVal =  Polycore.SceneMesh_getSkeleton(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/SceneParticleEmitter.lua

@@ -30,6 +30,7 @@ end
 
 function SceneParticleEmitter:getEmitter()
 	local retVal =  Polycore.SceneParticleEmitter_getEmitter(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -45,6 +46,7 @@ end
 
 function SceneParticleEmitter:getBaseMatrix()
 	local retVal =  Polycore.SceneParticleEmitter_getBaseMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 3 - 0
Bindings/Contents/LUA/API/Polycode/SceneRenderTexture.lua

@@ -26,6 +26,7 @@ end
 
 function SceneRenderTexture:getTargetTexture()
 	local retVal =  Polycore.SceneRenderTexture_getTargetTexture(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -37,6 +38,7 @@ end
 
 function SceneRenderTexture:getTargetScene()
 	local retVal =  Polycore.SceneRenderTexture_getTargetScene(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -48,6 +50,7 @@ end
 
 function SceneRenderTexture:getTargetCamera()
 	local retVal =  Polycore.SceneRenderTexture_getTargetCamera(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/SceneSound.lua

@@ -34,6 +34,7 @@ end
 
 function SceneSound:getSound()
 	local retVal =  Polycore.SceneSound_getSound(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 5 - 0
Bindings/Contents/LUA/API/Polycode/Screen.lua

@@ -42,6 +42,7 @@ end
 
 function Screen:addChild(newEntity)
 	local retVal = Polycore.Screen_addChild(self.__ptr, newEntity.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -53,6 +54,7 @@ end
 
 function Screen:removeChild(entityToRemove)
 	local retVal = Polycore.Screen_removeChild(self.__ptr, entityToRemove.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -68,6 +70,7 @@ end
 
 function Screen:getScreenOffset()
 	local retVal =  Polycore.Screen_getScreenOffset(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -87,6 +90,7 @@ end
 
 function Screen:getEntityAt(x, y)
 	local retVal = Polycore.Screen_getEntityAt(self.__ptr, x, y)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -155,6 +159,7 @@ end
 
 function Screen:getRootEntity()
 	local retVal =  Polycore.Screen_getRootEntity(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/ScreenEntity.lua

@@ -139,6 +139,7 @@ end
 
 function ScreenEntity:buildPositionMatrix()
 	local retVal =  Polycore.ScreenEntity_buildPositionMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -212,6 +213,7 @@ end
 
 function ScreenEntity:getPosition2D()
 	local retVal =  Polycore.ScreenEntity_getPosition2D(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/ScreenLabel.lua

@@ -43,6 +43,7 @@ end
 
 function ScreenLabel:getLabel()
 	local retVal =  Polycore.ScreenLabel_getLabel(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 3 - 3
Bindings/Contents/LUA/API/Polycode/ScreenLine.lua

@@ -1,6 +1,6 @@
-require "Polycode/ScreenEntity"
+require "Polycode/ScreenMesh"
 
-class "ScreenLine" (ScreenEntity)
+class "ScreenLine" (ScreenMesh)
 
 
 
@@ -10,7 +10,7 @@ class "ScreenLine" (ScreenEntity)
 
 function ScreenLine:ScreenLine(...)
 	if type(arg[1]) == "table" and count(arg) == 1 then
-		if ""..arg[1]:class() == "ScreenEntity" then
+		if ""..arg[1]:class() == "ScreenMesh" then
 			self.__ptr = arg[1].__ptr
 			return
 		end

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/ScreenMesh.lua

@@ -34,6 +34,7 @@ end
 
 function ScreenMesh:getMesh()
 	local retVal =  Polycore.ScreenMesh_getMesh(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -45,6 +46,7 @@ end
 
 function ScreenMesh:getTexture()
 	local retVal =  Polycore.ScreenMesh_getTexture(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/ScreenParticleEmitter.lua

@@ -30,6 +30,7 @@ end
 
 function ScreenParticleEmitter:getEmitter()
 	local retVal =  Polycore.ScreenParticleEmitter_getEmitter(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -45,6 +46,7 @@ end
 
 function ScreenParticleEmitter:getBaseMatrix()
 	local retVal =  Polycore.ScreenParticleEmitter_getBaseMatrix(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/ScreenSound.lua

@@ -34,6 +34,7 @@ end
 
 function ScreenSound:getSound()
 	local retVal =  Polycore.ScreenSound_getSound(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Shader.lua

@@ -43,6 +43,7 @@ end
 
 function Shader:createBinding()
 	local retVal =  Polycore.Shader_createBinding(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 5 - 0
Bindings/Contents/LUA/API/Polycode/ShaderBinding.lua

@@ -43,6 +43,7 @@ end
 
 function ShaderBinding:getLocalParam(index)
 	local retVal = Polycore.ShaderBinding_getLocalParam(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -54,6 +55,7 @@ end
 
 function ShaderBinding:getLocalParamByName(name)
 	local retVal = Polycore.ShaderBinding_getLocalParamByName(self.__ptr, name)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -74,6 +76,7 @@ end
 
 function ShaderBinding:getRenderTargetBinding(index)
 	local retVal = Polycore.ShaderBinding_getRenderTargetBinding(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -90,6 +93,7 @@ end
 
 function ShaderBinding:getInTargetBinding(index)
 	local retVal = Polycore.ShaderBinding_getInTargetBinding(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -106,6 +110,7 @@ end
 
 function ShaderBinding:getOutTargetBinding(index)
 	local retVal = Polycore.ShaderBinding_getOutTargetBinding(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 4 - 0
Bindings/Contents/LUA/API/Polycode/Skeleton.lua

@@ -46,6 +46,7 @@ end
 
 function Skeleton:getAnimation(name)
 	local retVal = Polycore.Skeleton_getAnimation(self.__ptr, name)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -61,6 +62,7 @@ end
 
 function Skeleton:getBoneByName(name)
 	local retVal = Polycore.Skeleton_getBoneByName(self.__ptr, name)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -85,6 +87,7 @@ end
 
 function Skeleton:getBone(index)
 	local retVal = Polycore.Skeleton_getBone(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -96,6 +99,7 @@ end
 
 function Skeleton:getCurrentAnimation()
 	local retVal =  Polycore.Skeleton_getCurrentAnimation(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 3 - 0
Bindings/Contents/LUA/API/Polycode/Sound.lua

@@ -58,6 +58,7 @@ end
 
 function Sound:loadWAV(fileName)
 	local retVal = Polycore.Sound_loadWAV(self.__ptr, fileName)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -69,6 +70,7 @@ end
 
 function Sound:loadOGG(fileName)
 	local retVal = Polycore.Sound_loadOGG(self.__ptr, fileName)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -80,6 +82,7 @@ end
 
 function Sound:GenSource(buffer)
 	local retVal = Polycore.Sound_GenSource(self.__ptr, buffer.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 6 - 0
Bindings/Contents/LUA/API/Polycode/String.lua

@@ -57,6 +57,7 @@ end
 
 function String:getSTLString()
 	local retVal =  Polycore.String_getSTLString(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -68,6 +69,7 @@ end
 
 function String:getSTLWString()
 	local retVal =  Polycore.String_getSTLWString(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -119,6 +121,7 @@ end
 
 function String:c_str()
 	local retVal =  Polycore.String_c_str(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -130,6 +133,7 @@ end
 
 function String:wc_str()
 	local retVal =  Polycore.String_wc_str(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -141,6 +145,7 @@ end
 
 function String:data()
 	local retVal =  Polycore.String_data(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -152,6 +157,7 @@ end
 
 function String:getDataWithEncoding(encoding)
 	local retVal = Polycore.String_getDataWithEncoding(self.__ptr, encoding)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Texture.lua

@@ -67,6 +67,7 @@ end
 
 function Texture:getTextureData()
 	local retVal =  Polycore.Texture_getTextureData(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Bindings/Contents/LUA/API/Polycode/Vector3.lua

@@ -63,6 +63,7 @@ end
 
 function Vector3:crossProduct(vec2)
 	local retVal = Polycore.Vector3_crossProduct(self.__ptr, vec2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 0
Bindings/Contents/LUA/API/Polycode/Vertex.lua

@@ -87,6 +87,7 @@ end
 
 function Vertex:getBoneAssignment(index)
 	local retVal = Polycore.Vertex_getBoneAssignment(self.__ptr, index)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -102,6 +103,7 @@ end
 
 function Vertex:getTexCoord()
 	local retVal =  Polycore.Vertex_getTexCoord(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

Разница между файлами не показана из-за своего большого размера
+ 451 - 74
Bindings/Contents/LUA/Include/PolycodeLUAWrappers.h


+ 1 - 0
Bindings/Contents/LUA/Source/PolycodeLUA.cpp

@@ -427,6 +427,7 @@ int luaopen_Polycode(lua_State *L) {
 		{"Mesh_saveToFile", Polycore_Mesh_saveToFile},
 		{"Mesh_loadFromFile", Polycore_Mesh_loadFromFile},
 		{"Mesh_getPolygonCount", Polycore_Mesh_getPolygonCount},
+		{"Mesh_getVertexCount", Polycore_Mesh_getVertexCount},
 		{"Mesh_getPolygon", Polycore_Mesh_getPolygon},
 		{"Mesh_createPlane", Polycore_Mesh_createPlane},
 		{"Mesh_createBox", Polycore_Mesh_createBox},

+ 9 - 2
Bindings/Scripts/create_lua_library/create_lua_library.py

@@ -56,6 +56,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 				cppHeader = CppHeaderParser.CppHeader(contents, "string")
 				ignore_classes = ["PolycodeShaderModule", "Object", "Threaded", "OpenGLCubemap"]
 				for ckey in cppHeader.classes:
+					print ">> Parsing class %s" % ckey
 					c = cppHeader.classes[ckey]
 		#			if ckey == "ParticleEmitter":
 		#				print c
@@ -325,7 +326,12 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 										basicType = True
 	
 									if pm["rtnType"].find("*") > -1:
-										out += "\t%s(L, (void*)%s%s);\n" % (outfunc, call, retFunc)
+										out += "\tvoid *ptrRetVal = (void*)%s%s;\n" % (call, retFunc)
+										out += "\tif(ptrRetVal == NULL) {\n"
+										out += "\t\tlua_pushnil(L);\n"
+										out += "\t} else {\n"
+										out += "\t\t%s(L, ptrRetVal);\n" % (outfunc)
+										out += "\t}\n"
 									elif basicType == True:
 										out += "\t%s(L, %s%s);\n" % (outfunc, call, retFunc)
 									else:
@@ -382,6 +388,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 										lout += "\treturn retVal\n"
 									else:
 										className = pm["rtnType"].replace("const", "").replace("&", "").replace("inline", "").replace("virtual", "").replace("static", "").replace("*","").replace(" ", "")
+										lout += "\tif retVal == nil then return nil end\n"
 										lout += "\tif Polycore.__ptr_lookup[retVal] ~= nil then\n"
 										lout += "\t\treturn Polycore.__ptr_lookup[retVal]\n"
 										lout += "\telse\n"
@@ -401,7 +408,7 @@ def createLUABindings(inputPath, prefix, mainInclude, libSmallName, libName, api
 					out += "\tdelete inst;\n"
 					out += "\treturn 0;\n"
 					out += "}\n\n"
-	
+
 					lout += "\n\n"
 					lout += "function %s:__delete()\n" % (ckey)
 					lout += "\tPolycore.__ptr_lookup[self.__ptr] = nil\n"

Разница между файлами не показана из-за своего большого размера
+ 230 - 452
Core/Build/Mac OS X/PolyCore.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 6 - 0
Core/Contents/Include/PolyMesh.h

@@ -148,6 +148,12 @@ namespace Polycode {
 			*/						
 			unsigned int getPolygonCount();
 			
+			/**
+			* Returns the total vertex count in the mesh.
+			* @return Number of vertices in the mesh.
+			*/
+			unsigned int getVertexCount();
+			
 			/**
 			* Returns a polygon at specified index.
 			* @param index Index of polygon.

+ 143 - 10
Core/Contents/Include/PolyParticleEmitter.h

@@ -33,6 +33,10 @@ THE SOFTWARE.
 using std::vector;
 
 namespace Polycode {
+
+	/** 
+	* Particle emitter base.
+	*/
 	class _PolyExport ParticleEmitter {
 		public:
 			ParticleEmitter(String imageFile, Mesh *particleMesh, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation);
@@ -40,55 +44,159 @@ namespace Polycode {
 		
 			void createParticles();
 			
+			/**
+			* Sets the speed at which particles rotate
+			* @param speed New rotation speed.
+			*/ 
 			void setRotationSpeed(Number speed);
+			
+			/**
+			* Sets the blending mode used for the particles. See documentation for the Entity for information on blending modes.
+			* @param mode New blending mode.
+			*/ 			
 			void setParticleBlendingMode(int mode);
+			
+			/**
+			* Turns depth write on and off for particles.
+			*/ 						
 			void setDepthWrite(bool val);
+			
+			/**
+			* Turns depth test on and off for particles.
+			*/ 									
 			void setDepthTest(bool val);		
+			
+			/**
+			* Turns alpha testing on and off for particles.
+			*/ 												
 			void setAlphaTest(bool val);
-		
+
+			/**
+			* Enables perlin noise movement for particles.
+			*/ 														
 			void enablePerlin(bool val);
+			
+			/**
+			* Enables perlin noise movement size.
+			*/ 														
+			void setPerlinModSize(Number size);
+
+			/**
+			* Enables or disables billboard mode for particles.
+			*/ 																	
 			void setBillboardMode(bool mode);
+			
+			/**
+			* Enables or disables the emitter
+			*/ 																				
 			void enableEmitter(bool val);
-			bool emitterEnabled();
 			
+			/**
+			* Returns true if the emitter is enabled, false otherwise.
+			*/ 																							
+			bool emitterEnabled();
+
+			/**
+			* Sets the emitter radius on all 3 axises.
+			*/ 																										
 			void setEmitterRadius(Vector3 rad);
-			
+
+			/**
+			* If set to true, will release all particles at once.
+			*/ 																													
 			void setAllAtOnce(bool val);
 			
+			/**
+			* If emitter mode is TRIGGERED_EMITTER, calling this method will trigger particle emission.
+			*/ 																													
 			void Trigger();
+			
 			void resetParticle(Particle *particle);
 			
-			void setPerlinModSize(Number size);
+			/**
+			* Changes the particle count in the emitter.
+			*/ 																													
 			void setParticleCount(int count);
 		
 			virtual void addParticleBody(Entity *particleBody) {}
 			virtual Matrix4 getBaseMatrix() {Matrix4 m; return m;}
 		
+			/**
+			* Particle movement speed multiplier
+			*/ 																																								
 			Number particleSpeedMod;
+			
+			/**
+			* Particle brightness deviation
+			*/ 																																										
 			Number brightnessDeviation;
 			
 			void updateEmitter();
 
+			/**
+			* Continuous emitter setting.
+			*/ 																													
 			static const int CONTINUOUS_EMITTER = 0;
+
+			/**
+			* Triggered emitter setting.
+			*/ 																																
 			static const int TRIGGERED_EMITTER = 1;
-		//	static const int CLOUD_EMITTER = 2;
 			
+			/**
+			* Particle direction deviation
+			*/ 																																							
 			Vector3 deviation;
+			/**
+			* Particle direction and emission strength vector
+			*/ 																																								
 			Vector3 dirVector;
+			
+			/**
+			* Particle gravity strength vector
+			*/ 																																								
 			Vector3 gravVector;			
 
+			/**
+			* Lifespan of particles.
+			*/ 																																						
 			Number lifespan;
 		
+			/**
+			* If set to true, particles' rotation will follow their movement.
+			*/ 																																		
 			bool rotationFollowsPath;
-		
+
+			/**
+			* Bezier curve that controls the scale of the particles.
+			*/ 																																				
 			BezierCurve scaleCurve;
-		
+
+			/**
+			* Bezier curve that controls the red component of particles' color.
+			*/ 																																						
 			BezierCurve colorCurveR;
+			/**
+			* Bezier curve that controls the green component of particles' color.
+			*/ 																																								
 			BezierCurve colorCurveG;
+			/**
+			* Bezier curve that controls the blue component of particles' color.
+			*/ 																																								
 			BezierCurve colorCurveB;
+			/**
+			* Bezier curve that controls the alpha component of particles' color.
+			*/ 																																								
 			BezierCurve colorCurveA;
 			
+			/**
+			* If set to true, will use the color curves to control particle color. False by default.
+			*/
 			bool useColorCurves;
+			
+			/**
+			* If set to true, will use the scale curve to control particle scale. False by default.
+			*/			
 			bool useScaleCurves;
 		
 		protected:
@@ -119,11 +227,31 @@ namespace Polycode {
 			Timer *timer;
 	};
 
+	/**
+	* 3D particle emitter.
+	*/
 	class _PolyExport SceneParticleEmitter : public SceneEntity, public ParticleEmitter {
 	public:
-		SceneParticleEmitter(String imageFile, Scene *particleParentScene, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Mesh *particleMesh = NULL, SceneMesh *emitter = NULL);
+		/**
+		* Constructor.
+		* @param materialName Name of the material to use for particles.
+		* @param particleParentScene Scene to create particles in.
+		* @param particleType Type of particles to create. Can be Particle::BILLBOARD_PARTICLE or Particle::MESH_PARTICLE
+		* @param emitterType Type of emitter to create. Can be ParticleEmitter::CONTINUOUS_EMITTER or ParticleEmitter::TRIGGERED_EMITTER
+		* @param lifespan Lifetime of particles in seconds.
+		* @param numParticles Total number of particles to create.
+		* @param direction Direction of the emitter, length of this vector controls emitter strength
+		* @param gravity Gravity direction and strength
+		* @param deviation Emitter deviation on each axis
+		* @param particleMesh If particle type is Particle::MESH_PARTICLE, this must be set to the mesh to use for each particle
+		* @param emitter If this is specified, particles will be emitted from this meshe's vertices.
+		*/
+		SceneParticleEmitter(String materialName, Scene *particleParentScene, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Mesh *particleMesh = NULL, SceneMesh *emitter = NULL);
 		~SceneParticleEmitter();		
 		
+		/**
+		* Returns the emitter (helper method for LUA).
+		*/ 
 		ParticleEmitter *getEmitter() { return this; }
 		
 		void addParticleBody(Entity *particleBody);
@@ -134,13 +262,18 @@ namespace Polycode {
 		SceneMesh *emitterMesh;		
 		Scene *particleParentScene;
 	};	
-	
-	
+		
+	/**
+	* 3D particle emitter.
+	*/
 	class _PolyExport ScreenParticleEmitter : public ScreenEntity, public ParticleEmitter {
 	public:
 		ScreenParticleEmitter(String imageFile, Screen *particleParentScreen, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Mesh *particleMesh = NULL, ScreenMesh *emitter = NULL);
 		~ScreenParticleEmitter();		
 		
+		/**
+		* Returns the emitter (helper method for LUA).
+		*/ 		
 		ParticleEmitter *getEmitter() { return this; }		
 		
 		void addParticleBody(Entity *particleBody);

+ 7 - 6
Core/Contents/Include/PolyScreenLine.h

@@ -23,7 +23,7 @@ THE SOFTWARE.
 #pragma once
 #include "PolyString.h"
 #include "PolyGlobals.h"
-#include "PolyScreenEntity.h"
+#include "PolyScreenMesh.h"
 #include "PolyCoreServices.h"
 #include "PolyMesh.h"
 
@@ -35,7 +35,7 @@ namespace Polycode {
 	/**
 	* A 2D line between two points or two ScreenEntity instances.
 	*/ 
-	class _PolyExport ScreenLine : public ScreenEntity {
+	class _PolyExport ScreenLine : public ScreenMesh {
 		public:
 			/**
 			* Create a line between two points.
@@ -51,6 +51,7 @@ namespace Polycode {
 			*/			
 			ScreenLine(ScreenEntity* target1, ScreenEntity* target2);
 			~ScreenLine();
+			
 
 			void Update();
 			void Render();
@@ -63,13 +64,13 @@ namespace Polycode {
 			
 		protected:
 		
+			void initMesh();
+		
 			Number lineWidth;
 			
-			Vertex startVertex;
-			Vertex endVertex;
+			Vertex *startVertex;
+			Vertex *endVertex;
 		
-			RenderDataArray *vertexDataArray;
-
 			ScreenEntity *target1;
 			ScreenEntity *target2;
 			

+ 8 - 0
Core/Contents/Source/PolyMesh.cpp

@@ -349,6 +349,14 @@ namespace Polycode {
 		arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;										
 		
 	}
+	
+	unsigned int Mesh::getVertexCount() {
+		unsigned int total = 0;
+		for(int i=0; i < polygons.size(); i++) {
+			total += polygons[i]->getVertexCount();
+		}
+		return total;
+	}
 
 	void Mesh::createCylinder(Number height, Number radius, int numSegments) {
 	

+ 2 - 2
Core/Contents/Source/PolyParticleEmitter.cpp

@@ -24,8 +24,8 @@
 
 using namespace Polycode;
 
-SceneParticleEmitter::SceneParticleEmitter(String imageFile, Scene *particleParentScene, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Mesh *particleMesh, SceneMesh *emitter)
-: ParticleEmitter(imageFile, particleMesh, particleType, emitterType, lifespan, numParticles,  direction, gravity, deviation),
+SceneParticleEmitter::SceneParticleEmitter(String materialName, Scene *particleParentScene, int particleType, int emitterType, Number lifespan, unsigned int numParticles, Vector3 direction, Vector3 gravity, Vector3 deviation, Mesh *particleMesh, SceneMesh *emitter)
+: ParticleEmitter(materialName, particleMesh, particleType, emitterType, lifespan, numParticles,  direction, gravity, deviation),
 SceneEntity()
 {
 	isScreenEmitter = false;

+ 34 - 24
Core/Contents/Source/PolyScreenLine.cpp

@@ -24,21 +24,33 @@
 
 using namespace Polycode;
 
-ScreenLine::ScreenLine(Vector2* start, Vector2* end) {
+ScreenLine::ScreenLine(Vector2* start, Vector2* end) : ScreenMesh(Mesh::LINE_MESH) {
 	target1 = NULL;
-	startVertex.x = start->x;
-	startVertex.y = start->y;
-	endVertex.x = end->x;
-	endVertex.y = end->y;
-	
-	vertexDataArray = CoreServices::getInstance()->getRenderer()->createRenderDataArray(RenderDataArray::VERTEX_DATA_ARRAY);	
+	initMesh();
+		
+	startVertex->x = start->x;
+	startVertex->y = start->y;
+	endVertex->x = end->x;
+	endVertex->y = end->y;
+	mesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;	
 }
 
-ScreenLine::ScreenLine(ScreenEntity* target1, ScreenEntity* target2) : ScreenEntity() {
+ScreenLine::ScreenLine(ScreenEntity* target1, ScreenEntity* target2) : ScreenMesh(Mesh::LINE_MESH) {
+	initMesh();	
 	this->target1 = target1;
 	this->target2 = target2;
 	lineWidth = 1.0f;
-	vertexDataArray = CoreServices::getInstance()->getRenderer()->createRenderDataArray(RenderDataArray::VERTEX_DATA_ARRAY);
+
+}
+
+void ScreenLine::initMesh() {
+	Polygon *poly = new Polygon();
+	startVertex = poly->addVertex(0, 0, 0, 0,0);
+	endVertex = poly->addVertex(0,0,0,1,0);	
+	mesh->addPolygon(poly);
+	mesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;			
+	mesh->arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;			
+	mesh->arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;				
 }
 
 ScreenLine::~ScreenLine() {
@@ -57,24 +69,22 @@ void ScreenLine::Update() {
 	Vector3 pos2 = target2->getPosition();
 	
 	setPosition(pos1.x, pos1.y);
-	endVertex.x = pos2.x-pos1.x;
-	endVertex.y = pos2.y-pos1.y;
+	endVertex->x = pos2.x-pos1.x;
+	endVertex->y = pos2.y-pos1.y;
+
+	mesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;			
+	
 }
 
 
 void ScreenLine::Render() {
-	Renderer *renderer = CoreServices::getInstance()->getRenderer();	
-	int rmode = renderer->getRenderMode();
-
-	renderer->setRenderMode(Renderer::RENDER_MODE_WIREFRAME);
+	Renderer *renderer = CoreServices::getInstance()->getRenderer();
 	renderer->setLineSize(lineWidth);
-	renderer->setTexture(NULL);
-	
-//	renderer->draw2DVertex(&startVertex);
-//	renderer->draw2DVertex(&endVertex);		
-	renderer->pushRenderDataArray(vertexDataArray);
-	renderer->drawArrays(Mesh::TRIFAN_MESH);
-	
-	
-	renderer->setRenderMode(rmode);
+	renderer->setTexture(texture);
+	if(mesh->useVertexColors) {
+		renderer->pushDataArrayForMesh(mesh, RenderDataArray::COLOR_DATA_ARRAY);
+	}
+	renderer->pushDataArrayForMesh(mesh, RenderDataArray::VERTEX_DATA_ARRAY);
+	renderer->pushDataArrayForMesh(mesh, RenderDataArray::TEXCOORD_DATA_ARRAY);	
+	renderer->drawArrays(mesh->getMeshType());
 }

+ 1 - 0
Modules/Bindings/2DPhysics/API/Physics2D.lua

@@ -1,3 +1,4 @@
 require "Physics2D/PhysicsScreen"
 require "Physics2D/PhysicsJoint"
+require "Physics2D/PhysicsScreenEvent"
 require "Physics2D/PhysicsScreenEntity"

+ 34 - 22
Modules/Bindings/2DPhysics/API/Physics2D/PhysicsScreen.lua

@@ -32,8 +32,9 @@ function PhysicsScreen:Update()
 	local retVal =  Physics2D.PhysicsScreen_Update(self.__ptr)
 end
 
-function PhysicsScreen:addPhysicsChild(newEntity, entType, friction, density, restitution, isSensor, fixedRotation)
-	local retVal = Physics2D.PhysicsScreen_addPhysicsChild(self.__ptr, newEntity.__ptr, entType, friction, density, restitution, isSensor, fixedRotation)
+function PhysicsScreen:addPhysicsChild(newEntity, entType, isStatic, friction, density, restitution, isSensor, fixedRotation)
+	local retVal = Physics2D.PhysicsScreen_addPhysicsChild(self.__ptr, newEntity.__ptr, entType, isStatic, friction, density, restitution, isSensor, fixedRotation)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -49,6 +50,7 @@ end
 
 function PhysicsScreen:addCollisionChild(newEntity, entType)
 	local retVal = Physics2D.PhysicsScreen_addCollisionChild(self.__ptr, newEntity.__ptr, entType)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -64,14 +66,31 @@ end
 
 function PhysicsScreen:createDistanceJoint(ent1, ent2, collideConnected)
 	local retVal = Physics2D.PhysicsScreen_createDistanceJoint(self.__ptr, ent1.__ptr, ent2.__ptr, collideConnected)
+	if retVal == nil then return nil end
+	if Polycore.__ptr_lookup[retVal] ~= nil then
+		return Polycore.__ptr_lookup[retVal]
+	else
+		Polycore.__ptr_lookup[retVal] = PhysicsJoint("__skip_ptr__")
+		Polycore.__ptr_lookup[retVal].__ptr = retVal
+		return Polycore.__ptr_lookup[retVal]
+	end
 end
 
-function PhysicsScreen:createPrismaticJoint(ent1, ent2, collideConnected)
-	local retVal = Physics2D.PhysicsScreen_createPrismaticJoint(self.__ptr, ent1.__ptr, ent2.__ptr, collideConnected)
+function PhysicsScreen:createPrismaticJoint(ent1, ent2, worldAxis, ax, ay, collideConnected, lowerTranslation, upperTranslation, enableLimit, motorSpeed, motorForce, motorEnabled)
+	local retVal = Physics2D.PhysicsScreen_createPrismaticJoint(self.__ptr, ent1.__ptr, ent2.__ptr, worldAxis.__ptr, ax, ay, collideConnected, lowerTranslation, upperTranslation, enableLimit, motorSpeed, motorForce, motorEnabled)
+	if retVal == nil then return nil end
+	if Polycore.__ptr_lookup[retVal] ~= nil then
+		return Polycore.__ptr_lookup[retVal]
+	else
+		Polycore.__ptr_lookup[retVal] = PhysicsJoint("__skip_ptr__")
+		Polycore.__ptr_lookup[retVal].__ptr = retVal
+		return Polycore.__ptr_lookup[retVal]
+	end
 end
 
-function PhysicsScreen:createRevoluteJoint(ent1, ent2, ax, ay, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
-	local retVal = Physics2D.PhysicsScreen_createRevoluteJoint(self.__ptr, ent1.__ptr, ent2.__ptr, ax, ay, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
+function PhysicsScreen:createRevoluteJoint(ent1, ent2, ax, ay, collideConnected, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
+	local retVal = Physics2D.PhysicsScreen_createRevoluteJoint(self.__ptr, ent1.__ptr, ent2.__ptr, ax, ay, collideConnected, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -99,6 +118,7 @@ end
 
 function PhysicsScreen:getPhysicsEntityByShape(shape)
 	local retVal = Physics2D.PhysicsScreen_getPhysicsEntityByShape(self.__ptr, shape.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -110,6 +130,7 @@ end
 
 function PhysicsScreen:getPhysicsEntityByFixture(fixture)
 	local retVal = Physics2D.PhysicsScreen_getPhysicsEntityByFixture(self.__ptr, fixture.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -137,6 +158,7 @@ end
 
 function PhysicsScreen:getVelocity(ent)
 	local retVal = Physics2D.PhysicsScreen_getVelocity(self.__ptr, ent.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -154,28 +176,17 @@ function PhysicsScreen:EndContact(contact)
 	local retVal = Physics2D.PhysicsScreen_EndContact(self.__ptr, contact.__ptr)
 end
 
-function PhysicsScreen:wakeUp(ent)
-	local retVal = Physics2D.PhysicsScreen_wakeUp(self.__ptr, ent.__ptr)
-end
-
-function PhysicsScreen:getEntityCollisionNormal(ent1, ent2)
-	local retVal = Physics2D.PhysicsScreen_getEntityCollisionNormal(self.__ptr, ent1.__ptr, ent2.__ptr)
-	if Polycore.__ptr_lookup[retVal] ~= nil then
-		return Polycore.__ptr_lookup[retVal]
-	else
-		Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
-		Polycore.__ptr_lookup[retVal].__ptr = retVal
-		return Polycore.__ptr_lookup[retVal]
-	end
+function PhysicsScreen:PostSolve(contact, impulse)
+	local retVal = Physics2D.PhysicsScreen_PostSolve(self.__ptr, contact.__ptr, impulse.__ptr)
 end
 
-function PhysicsScreen:areEntitiesColliding(ent1, ent2)
-	local retVal = Physics2D.PhysicsScreen_areEntitiesColliding(self.__ptr, ent1.__ptr, ent2.__ptr)
-	return retVal
+function PhysicsScreen:wakeUp(ent)
+	local retVal = Physics2D.PhysicsScreen_wakeUp(self.__ptr, ent.__ptr)
 end
 
 function PhysicsScreen:getEntityAtPosition(x, y)
 	local retVal = Physics2D.PhysicsScreen_getEntityAtPosition(self.__ptr, x, y)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -196,6 +207,7 @@ end
 
 function PhysicsScreen:getPhysicsByScreenEntity(ent)
 	local retVal = Physics2D.PhysicsScreen_getPhysicsByScreenEntity(self.__ptr, ent.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 2 - 1
Modules/Bindings/2DPhysics/API/Physics2D/PhysicsScreenEntity.lua

@@ -4,7 +4,7 @@ class "PhysicsScreenEntity"
 
 ENTITY_RECT = 1
 ENTITY_CIRCLE = 2
-ENTITY_STATICRECT = 3
+ENTITY_MESH = 3
 function PhysicsScreenEntity:__index__(name)
 	if name == "collisionOnly" then
 		return Physics2D.PhysicsScreenEntity_get_collisionOnly(self.__ptr)
@@ -37,6 +37,7 @@ end
 
 function PhysicsScreenEntity:getScreenEntity()
 	local retVal =  Physics2D.PhysicsScreenEntity_getScreenEntity(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 106 - 0
Modules/Bindings/2DPhysics/API/Physics2D/PhysicsScreenEvent.lua

@@ -0,0 +1,106 @@
+require "Polycode/Event"
+
+class "PhysicsScreenEvent" (Event)
+
+
+
+EVENT_NEW_SHAPE_COLLISION = 0
+EVENT_END_SHAPE_COLLISION = 1
+function PhysicsScreenEvent:__index__(name)
+	if name == "localCollisionNormal" then
+		retVal = Physics2D.PhysicsScreenEvent_get_localCollisionNormal(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
+	elseif name == "worldCollisionNormal" then
+		retVal = Physics2D.PhysicsScreenEvent_get_worldCollisionNormal(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
+	elseif name == "localCollisionPoint" then
+		retVal = Physics2D.PhysicsScreenEvent_get_localCollisionPoint(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = Vector2("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
+	elseif name == "impactStrength" then
+		return Physics2D.PhysicsScreenEvent_get_impactStrength(self.__ptr)
+	elseif name == "frictionStrength" then
+		return Physics2D.PhysicsScreenEvent_get_frictionStrength(self.__ptr)
+	end
+end
+
+
+function PhysicsScreenEvent:__set_callback(name,value)
+	if name == "impactStrength" then
+		Physics2D.PhysicsScreenEvent_set_impactStrength(self.__ptr, value)
+		return true
+	elseif name == "frictionStrength" then
+		Physics2D.PhysicsScreenEvent_set_frictionStrength(self.__ptr, value)
+		return true
+	end
+	return false
+end
+
+
+function PhysicsScreenEvent:PhysicsScreenEvent(...)
+	if type(arg[1]) == "table" and count(arg) == 1 then
+		if ""..arg[1]:class() == "Event" then
+			self.__ptr = arg[1].__ptr
+			return
+		end
+	end
+	for k,v in pairs(arg) do
+		if type(v) == "table" then
+			if v.__ptr ~= nil then
+				arg[k] = v.__ptr
+			end
+		end
+	end
+	if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
+		self.__ptr = Physics2D.PhysicsScreenEvent(unpack(arg))
+		Polycore.__ptr_lookup[self.__ptr] = self
+	end
+end
+
+function PhysicsScreenEvent:getFirstEntity()
+	local retVal =  Physics2D.PhysicsScreenEvent_getFirstEntity(self.__ptr)
+	if retVal == nil then return nil end
+	if Polycore.__ptr_lookup[retVal] ~= nil then
+		return Polycore.__ptr_lookup[retVal]
+	else
+		Polycore.__ptr_lookup[retVal] = ScreenEntity("__skip_ptr__")
+		Polycore.__ptr_lookup[retVal].__ptr = retVal
+		return Polycore.__ptr_lookup[retVal]
+	end
+end
+
+function PhysicsScreenEvent:getSecondEntity()
+	local retVal =  Physics2D.PhysicsScreenEvent_getSecondEntity(self.__ptr)
+	if retVal == nil then return nil end
+	if Polycore.__ptr_lookup[retVal] ~= nil then
+		return Polycore.__ptr_lookup[retVal]
+	else
+		Polycore.__ptr_lookup[retVal] = ScreenEntity("__skip_ptr__")
+		Polycore.__ptr_lookup[retVal].__ptr = retVal
+		return Polycore.__ptr_lookup[retVal]
+	end
+end
+
+
+
+function PhysicsScreenEvent:__delete()
+	Polycore.__ptr_lookup[self.__ptr] = nil
+	Physics2D.delete_PhysicsScreenEvent(self.__ptr)
+end

+ 271 - 66
Modules/Bindings/2DPhysics/Include/Physics2DLUAWrappers.h

@@ -33,37 +33,44 @@ static int Physics2D_PhysicsScreen_addPhysicsChild(lua_State *L) {
 	ScreenEntity * newEntity = (ScreenEntity *)lua_topointer(L, 2);
 	luaL_checktype(L, 3, LUA_TNUMBER);
 	int entType = lua_tointeger(L, 3);
+	luaL_checktype(L, 4, LUA_TBOOLEAN);
+	bool isStatic = lua_toboolean(L, 4);
 	Number friction;
-	if(lua_isnumber(L, 4)) {
-		friction = lua_tonumber(L, 4);
+	if(lua_isnumber(L, 5)) {
+		friction = lua_tonumber(L, 5);
 	} else {
 		friction = 0.1;
 	}
 	Number density;
-	if(lua_isnumber(L, 5)) {
-		density = lua_tonumber(L, 5);
+	if(lua_isnumber(L, 6)) {
+		density = lua_tonumber(L, 6);
 	} else {
 		density = 1;
 	}
 	Number restitution;
-	if(lua_isnumber(L, 6)) {
-		restitution = lua_tonumber(L, 6);
+	if(lua_isnumber(L, 7)) {
+		restitution = lua_tonumber(L, 7);
 	} else {
 		restitution = 0;
 	}
 	bool isSensor;
-	if(lua_isboolean(L, 7)) {
-		isSensor = lua_toboolean(L, 7);
+	if(lua_isboolean(L, 8)) {
+		isSensor = lua_toboolean(L, 8);
 	} else {
 		isSensor = false;
 	}
 	bool fixedRotation;
-	if(lua_isboolean(L, 8)) {
-		fixedRotation = lua_toboolean(L, 8);
+	if(lua_isboolean(L, 9)) {
+		fixedRotation = lua_toboolean(L, 9);
 	} else {
 		fixedRotation = false;
 	}
-	lua_pushlightuserdata(L, (void*)inst->addPhysicsChild(newEntity, entType, friction, density, restitution, isSensor, fixedRotation));
+	void *ptrRetVal = (void*)inst->addPhysicsChild(newEntity, entType, isStatic, friction, density, restitution, isSensor, fixedRotation);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -83,7 +90,12 @@ static int Physics2D_PhysicsScreen_addCollisionChild(lua_State *L) {
 	ScreenEntity * newEntity = (ScreenEntity *)lua_topointer(L, 2);
 	luaL_checktype(L, 3, LUA_TNUMBER);
 	int entType = lua_tointeger(L, 3);
-	lua_pushlightuserdata(L, (void*)inst->addCollisionChild(newEntity, entType));
+	void *ptrRetVal = (void*)inst->addCollisionChild(newEntity, entType);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -105,8 +117,13 @@ static int Physics2D_PhysicsScreen_createDistanceJoint(lua_State *L) {
 	ScreenEntity * ent2 = (ScreenEntity *)lua_topointer(L, 3);
 	luaL_checktype(L, 4, LUA_TBOOLEAN);
 	bool collideConnected = lua_toboolean(L, 4);
-	inst->createDistanceJoint(ent1, ent2, collideConnected);
-	return 0;
+	void *ptrRetVal = (void*)inst->createDistanceJoint(ent1, ent2, collideConnected);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
+	return 1;
 }
 
 static int Physics2D_PhysicsScreen_createPrismaticJoint(lua_State *L) {
@@ -116,10 +133,61 @@ static int Physics2D_PhysicsScreen_createPrismaticJoint(lua_State *L) {
 	ScreenEntity * ent1 = (ScreenEntity *)lua_topointer(L, 2);
 	luaL_checktype(L, 3, LUA_TLIGHTUSERDATA);
 	ScreenEntity * ent2 = (ScreenEntity *)lua_topointer(L, 3);
-	luaL_checktype(L, 4, LUA_TBOOLEAN);
-	bool collideConnected = lua_toboolean(L, 4);
-	inst->createPrismaticJoint(ent1, ent2, collideConnected);
-	return 0;
+	luaL_checktype(L, 4, LUA_TLIGHTUSERDATA);
+	Vector2 worldAxis = *(Vector2*)lua_topointer(L, 4);
+	luaL_checktype(L, 5, LUA_TNUMBER);
+	Number ax = lua_tonumber(L, 5);
+	luaL_checktype(L, 6, LUA_TNUMBER);
+	Number ay = lua_tonumber(L, 6);
+	bool collideConnected;
+	if(lua_isboolean(L, 7)) {
+		collideConnected = lua_toboolean(L, 7);
+	} else {
+		collideConnected = false;
+	}
+	Number lowerTranslation;
+	if(lua_isnumber(L, 8)) {
+		lowerTranslation = lua_tonumber(L, 8);
+	} else {
+		lowerTranslation = 0;
+	}
+	Number upperTranslation;
+	if(lua_isnumber(L, 9)) {
+		upperTranslation = lua_tonumber(L, 9);
+	} else {
+		upperTranslation = 0;
+	}
+	bool enableLimit;
+	if(lua_isboolean(L, 10)) {
+		enableLimit = lua_toboolean(L, 10);
+	} else {
+		enableLimit = false;
+	}
+	Number motorSpeed;
+	if(lua_isnumber(L, 11)) {
+		motorSpeed = lua_tonumber(L, 11);
+	} else {
+		motorSpeed = 0;
+	}
+	Number motorForce;
+	if(lua_isnumber(L, 12)) {
+		motorForce = lua_tonumber(L, 12);
+	} else {
+		motorForce = 0;
+	}
+	bool motorEnabled;
+	if(lua_isboolean(L, 13)) {
+		motorEnabled = lua_toboolean(L, 13);
+	} else {
+		motorEnabled = false;
+	}
+	void *ptrRetVal = (void*)inst->createPrismaticJoint(ent1, ent2, worldAxis, ax, ay, collideConnected, lowerTranslation, upperTranslation, enableLimit, motorSpeed, motorForce, motorEnabled);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
+	return 1;
 }
 
 static int Physics2D_PhysicsScreen_createRevoluteJoint(lua_State *L) {
@@ -133,19 +201,54 @@ static int Physics2D_PhysicsScreen_createRevoluteJoint(lua_State *L) {
 	Number ax = lua_tonumber(L, 4);
 	luaL_checktype(L, 5, LUA_TNUMBER);
 	Number ay = lua_tonumber(L, 5);
-	luaL_checktype(L, 6, LUA_TBOOLEAN);
-	bool enableLimit = lua_toboolean(L, 6);
-	luaL_checktype(L, 7, LUA_TNUMBER);
-	Number lowerLimit = lua_tonumber(L, 7);
-	luaL_checktype(L, 8, LUA_TNUMBER);
-	Number upperLimit = lua_tonumber(L, 8);
-	luaL_checktype(L, 9, LUA_TBOOLEAN);
-	bool motorEnabled = lua_toboolean(L, 9);
-	luaL_checktype(L, 10, LUA_TNUMBER);
-	Number motorSpeed = lua_tonumber(L, 10);
-	luaL_checktype(L, 11, LUA_TNUMBER);
-	Number maxTorque = lua_tonumber(L, 11);
-	lua_pushlightuserdata(L, (void*)inst->createRevoluteJoint(ent1, ent2, ax, ay, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque));
+	bool collideConnected;
+	if(lua_isboolean(L, 6)) {
+		collideConnected = lua_toboolean(L, 6);
+	} else {
+		collideConnected = false;
+	}
+	bool enableLimit;
+	if(lua_isboolean(L, 7)) {
+		enableLimit = lua_toboolean(L, 7);
+	} else {
+		enableLimit = false;
+	}
+	Number lowerLimit;
+	if(lua_isnumber(L, 8)) {
+		lowerLimit = lua_tonumber(L, 8);
+	} else {
+		lowerLimit = 0;
+	}
+	Number upperLimit;
+	if(lua_isnumber(L, 9)) {
+		upperLimit = lua_tonumber(L, 9);
+	} else {
+		upperLimit = 0;
+	}
+	bool motorEnabled;
+	if(lua_isboolean(L, 10)) {
+		motorEnabled = lua_toboolean(L, 10);
+	} else {
+		motorEnabled = false;
+	}
+	Number motorSpeed;
+	if(lua_isnumber(L, 11)) {
+		motorSpeed = lua_tonumber(L, 11);
+	} else {
+		motorSpeed = 0;
+	}
+	Number maxTorque;
+	if(lua_isnumber(L, 12)) {
+		maxTorque = lua_tonumber(L, 12);
+	} else {
+		maxTorque = 0;
+	}
+	void *ptrRetVal = (void*)inst->createRevoluteJoint(ent1, ent2, ax, ay, collideConnected, enableLimit, lowerLimit, upperLimit, motorEnabled, motorSpeed, maxTorque);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -202,7 +305,12 @@ static int Physics2D_PhysicsScreen_getPhysicsEntityByShape(lua_State *L) {
 	PhysicsScreen *inst = (PhysicsScreen*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
 	b2Shape * shape = (b2Shape *)lua_topointer(L, 2);
-	lua_pushlightuserdata(L, (void*)inst->getPhysicsEntityByShape(shape));
+	void *ptrRetVal = (void*)inst->getPhysicsEntityByShape(shape);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -211,7 +319,12 @@ static int Physics2D_PhysicsScreen_getPhysicsEntityByFixture(lua_State *L) {
 	PhysicsScreen *inst = (PhysicsScreen*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
 	b2Fixture * fixture = (b2Fixture *)lua_topointer(L, 2);
-	lua_pushlightuserdata(L, (void*)inst->getPhysicsEntityByFixture(fixture));
+	void *ptrRetVal = (void*)inst->getPhysicsEntityByFixture(fixture);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -290,37 +403,24 @@ static int Physics2D_PhysicsScreen_EndContact(lua_State *L) {
 	return 0;
 }
 
-static int Physics2D_PhysicsScreen_wakeUp(lua_State *L) {
-	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
-	PhysicsScreen *inst = (PhysicsScreen*)lua_topointer(L, 1);
-	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	ScreenEntity * ent = (ScreenEntity *)lua_topointer(L, 2);
-	inst->wakeUp(ent);
-	return 0;
-}
-
-static int Physics2D_PhysicsScreen_getEntityCollisionNormal(lua_State *L) {
+static int Physics2D_PhysicsScreen_PostSolve(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	PhysicsScreen *inst = (PhysicsScreen*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	ScreenEntity * ent1 = (ScreenEntity *)lua_topointer(L, 2);
+	b2Contact * contact = (b2Contact *)lua_topointer(L, 2);
 	luaL_checktype(L, 3, LUA_TLIGHTUSERDATA);
-	ScreenEntity * ent2 = (ScreenEntity *)lua_topointer(L, 3);
-	Vector2 *retInst = new Vector2();
-	*retInst = inst->getEntityCollisionNormal(ent1, ent2);
-	lua_pushlightuserdata(L, retInst);
-	return 1;
+	const b2ContactImpulse * impulse = (const b2ContactImpulse *)lua_topointer(L, 3);
+	inst->PostSolve(contact, impulse);
+	return 0;
 }
 
-static int Physics2D_PhysicsScreen_areEntitiesColliding(lua_State *L) {
+static int Physics2D_PhysicsScreen_wakeUp(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	PhysicsScreen *inst = (PhysicsScreen*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
-	ScreenEntity * ent1 = (ScreenEntity *)lua_topointer(L, 2);
-	luaL_checktype(L, 3, LUA_TLIGHTUSERDATA);
-	ScreenEntity * ent2 = (ScreenEntity *)lua_topointer(L, 3);
-	lua_pushboolean(L, inst->areEntitiesColliding(ent1, ent2));
-	return 1;
+	ScreenEntity * ent = (ScreenEntity *)lua_topointer(L, 2);
+	inst->wakeUp(ent);
+	return 0;
 }
 
 static int Physics2D_PhysicsScreen_getEntityAtPosition(lua_State *L) {
@@ -330,7 +430,12 @@ static int Physics2D_PhysicsScreen_getEntityAtPosition(lua_State *L) {
 	Number x = lua_tonumber(L, 2);
 	luaL_checktype(L, 3, LUA_TNUMBER);
 	Number y = lua_tonumber(L, 3);
-	lua_pushlightuserdata(L, (void*)inst->getEntityAtPosition(x, y));
+	void *ptrRetVal = (void*)inst->getEntityAtPosition(x, y);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -359,7 +464,12 @@ static int Physics2D_PhysicsScreen_getPhysicsByScreenEntity(lua_State *L) {
 	PhysicsScreen *inst = (PhysicsScreen*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
 	ScreenEntity * ent = (ScreenEntity *)lua_topointer(L, 2);
-	lua_pushlightuserdata(L, (void*)inst->getPhysicsByScreenEntity(ent));
+	void *ptrRetVal = (void*)inst->getPhysicsByScreenEntity(ent);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -392,6 +502,94 @@ static int Physics2D_delete_PhysicsJoint(lua_State *L) {
 	return 0;
 }
 
+static int Physics2D_PhysicsScreenEvent_get_localCollisionNormal(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->localCollisionNormal);
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_get_worldCollisionNormal(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->worldCollisionNormal);
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_get_localCollisionPoint(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->localCollisionPoint);
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_get_impactStrength(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	lua_pushnumber(L, inst->impactStrength);
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_get_frictionStrength(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	lua_pushnumber(L, inst->frictionStrength);
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_set_impactStrength(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	Number param = lua_tonumber(L, 2);
+	inst->impactStrength = param;
+	return 0;
+}
+
+static int Physics2D_PhysicsScreenEvent_set_frictionStrength(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	Number param = lua_tonumber(L, 2);
+	inst->frictionStrength = param;
+	return 0;
+}
+
+static int Physics2D_PhysicsScreenEvent(lua_State *L) {
+	PhysicsScreenEvent *inst = new PhysicsScreenEvent();
+	lua_pushlightuserdata(L, (void*)inst);
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_getFirstEntity(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	void *ptrRetVal = (void*)inst->getFirstEntity();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
+	return 1;
+}
+
+static int Physics2D_PhysicsScreenEvent_getSecondEntity(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	void *ptrRetVal = (void*)inst->getSecondEntity();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
+	return 1;
+}
+
+static int Physics2D_delete_PhysicsScreenEvent(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsScreenEvent *inst = (PhysicsScreenEvent*)lua_topointer(L, 1);
+	delete inst;
+	return 0;
+}
+
 static int Physics2D_PhysicsScreenEntity_get_collisionOnly(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	PhysicsScreenEntity *inst = (PhysicsScreenEntity*)lua_topointer(L, 1);
@@ -416,17 +614,19 @@ static int Physics2D_PhysicsScreenEntity(lua_State *L) {
 	Number worldScale = lua_tonumber(L, 3);
 	luaL_checktype(L, 4, LUA_TNUMBER);
 	int entType = lua_tointeger(L, 4);
-	luaL_checktype(L, 5, LUA_TNUMBER);
-	Number friction = lua_tonumber(L, 5);
+	luaL_checktype(L, 5, LUA_TBOOLEAN);
+	bool isStatic = lua_toboolean(L, 5);
 	luaL_checktype(L, 6, LUA_TNUMBER);
-	Number density = lua_tonumber(L, 6);
+	Number friction = lua_tonumber(L, 6);
 	luaL_checktype(L, 7, LUA_TNUMBER);
-	Number restitution = lua_tonumber(L, 7);
-	luaL_checktype(L, 8, LUA_TBOOLEAN);
-	bool isSensor = lua_toboolean(L, 8);
+	Number density = lua_tonumber(L, 7);
+	luaL_checktype(L, 8, LUA_TNUMBER);
+	Number restitution = lua_tonumber(L, 8);
 	luaL_checktype(L, 9, LUA_TBOOLEAN);
-	bool fixedRotation = lua_toboolean(L, 9);
-	PhysicsScreenEntity *inst = new PhysicsScreenEntity(entity, world, worldScale, entType, friction, density, restitution, isSensor, fixedRotation);
+	bool isSensor = lua_toboolean(L, 9);
+	luaL_checktype(L, 10, LUA_TBOOLEAN);
+	bool fixedRotation = lua_toboolean(L, 10);
+	PhysicsScreenEntity *inst = new PhysicsScreenEntity(entity, world, worldScale, entType, isStatic, friction, density, restitution, isSensor, fixedRotation);
 	lua_pushlightuserdata(L, (void*)inst);
 	return 1;
 }
@@ -434,7 +634,12 @@ static int Physics2D_PhysicsScreenEntity(lua_State *L) {
 static int Physics2D_PhysicsScreenEntity_getScreenEntity(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	PhysicsScreenEntity *inst = (PhysicsScreenEntity*)lua_topointer(L, 1);
-	lua_pushlightuserdata(L, (void*)inst->getScreenEntity());
+	void *ptrRetVal = (void*)inst->getScreenEntity();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 

+ 12 - 2
Modules/Bindings/2DPhysics/Source/Physics2DLUA.cpp

@@ -26,9 +26,8 @@ CoreServices::setInstance(inst);
 		{"PhysicsScreen_getVelocity", Physics2D_PhysicsScreen_getVelocity},
 		{"PhysicsScreen_BeginContact", Physics2D_PhysicsScreen_BeginContact},
 		{"PhysicsScreen_EndContact", Physics2D_PhysicsScreen_EndContact},
+		{"PhysicsScreen_PostSolve", Physics2D_PhysicsScreen_PostSolve},
 		{"PhysicsScreen_wakeUp", Physics2D_PhysicsScreen_wakeUp},
-		{"PhysicsScreen_getEntityCollisionNormal", Physics2D_PhysicsScreen_getEntityCollisionNormal},
-		{"PhysicsScreen_areEntitiesColliding", Physics2D_PhysicsScreen_areEntitiesColliding},
 		{"PhysicsScreen_getEntityAtPosition", Physics2D_PhysicsScreen_getEntityAtPosition},
 		{"PhysicsScreen_testEntityAtPosition", Physics2D_PhysicsScreen_testEntityAtPosition},
 		{"PhysicsScreen_Shutdown", Physics2D_PhysicsScreen_Shutdown},
@@ -37,6 +36,17 @@ CoreServices::setInstance(inst);
 		{"delete_PhysicsScreen", Physics2D_delete_PhysicsScreen},
 		{"PhysicsJoint", Physics2D_PhysicsJoint},
 		{"delete_PhysicsJoint", Physics2D_delete_PhysicsJoint},
+		{"PhysicsScreenEvent_get_localCollisionNormal", Physics2D_PhysicsScreenEvent_get_localCollisionNormal},
+		{"PhysicsScreenEvent_get_worldCollisionNormal", Physics2D_PhysicsScreenEvent_get_worldCollisionNormal},
+		{"PhysicsScreenEvent_get_localCollisionPoint", Physics2D_PhysicsScreenEvent_get_localCollisionPoint},
+		{"PhysicsScreenEvent_get_impactStrength", Physics2D_PhysicsScreenEvent_get_impactStrength},
+		{"PhysicsScreenEvent_get_frictionStrength", Physics2D_PhysicsScreenEvent_get_frictionStrength},
+		{"PhysicsScreenEvent_set_impactStrength", Physics2D_PhysicsScreenEvent_set_impactStrength},
+		{"PhysicsScreenEvent_set_frictionStrength", Physics2D_PhysicsScreenEvent_set_frictionStrength},
+		{"PhysicsScreenEvent", Physics2D_PhysicsScreenEvent},
+		{"PhysicsScreenEvent_getFirstEntity", Physics2D_PhysicsScreenEvent_getFirstEntity},
+		{"PhysicsScreenEvent_getSecondEntity", Physics2D_PhysicsScreenEvent_getSecondEntity},
+		{"delete_PhysicsScreenEvent", Physics2D_delete_PhysicsScreenEvent},
 		{"PhysicsScreenEntity_get_collisionOnly", Physics2D_PhysicsScreenEntity_get_collisionOnly},
 		{"PhysicsScreenEntity_set_collisionOnly", Physics2D_PhysicsScreenEntity_set_collisionOnly},
 		{"PhysicsScreenEntity", Physics2D_PhysicsScreenEntity},

+ 11 - 0
Modules/Bindings/3DPhysics/API/Physics3D/CollisionScene.lua

@@ -42,6 +42,7 @@ end
 
 function CollisionScene:getCollisionEntityByObject(collisionObject)
 	local retVal = Physics3D.CollisionScene_getCollisionEntityByObject(self.__ptr, collisionObject.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -53,6 +54,7 @@ end
 
 function CollisionScene:getFirstEntityInRay(origin, dest)
 	local retVal = Physics3D.CollisionScene_getFirstEntityInRay(self.__ptr, origin.__ptr, dest.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -64,6 +66,7 @@ end
 
 function CollisionScene:getCollisionByScreenEntity(ent)
 	local retVal = Physics3D.CollisionScene_getCollisionByScreenEntity(self.__ptr, ent.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -75,6 +78,7 @@ end
 
 function CollisionScene:testCollision(ent1, ent2)
 	local retVal = Physics3D.CollisionScene_testCollision(self.__ptr, ent1.__ptr, ent2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -86,6 +90,7 @@ end
 
 function CollisionScene:testCollisionOnCollisionChild(cEnt1, cEnt2)
 	local retVal = Physics3D.CollisionScene_testCollisionOnCollisionChild(self.__ptr, cEnt1.__ptr, cEnt2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -97,6 +102,7 @@ end
 
 function CollisionScene:testCollisionOnCollisionChild_Convex(cEnt1, cEnt2)
 	local retVal = Physics3D.CollisionScene_testCollisionOnCollisionChild_Convex(self.__ptr, cEnt1.__ptr, cEnt2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -108,6 +114,7 @@ end
 
 function CollisionScene:testCollisionOnCollisionChild_RayTest(cEnt1, cEnt2)
 	local retVal = Physics3D.CollisionScene_testCollisionOnCollisionChild_RayTest(self.__ptr, cEnt1.__ptr, cEnt2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -119,6 +126,7 @@ end
 
 function CollisionScene:getCollisionNormalFromCollisionEnts(cEnt1, cEnt2)
 	local retVal = Physics3D.CollisionScene_getCollisionNormalFromCollisionEnts(self.__ptr, cEnt1.__ptr, cEnt2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -130,6 +138,7 @@ end
 
 function CollisionScene:getCollisionNormal(ent1, ent2)
 	local retVal = Physics3D.CollisionScene_getCollisionNormal(self.__ptr, ent1.__ptr, ent2.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -157,6 +166,7 @@ end
 
 function CollisionScene:addCollisionChild(newEntity, autoCollide, type, group)
 	local retVal = Physics3D.CollisionScene_addCollisionChild(self.__ptr, newEntity.__ptr, autoCollide, type, group)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -168,6 +178,7 @@ end
 
 function CollisionScene:trackCollision(newEntity, autoCollide, type, group)
 	local retVal = Physics3D.CollisionScene_trackCollision(self.__ptr, newEntity.__ptr, autoCollide, type, group)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 30 - 0
Modules/Bindings/3DPhysics/API/Physics3D/CollisionSceneEntity.lua

@@ -16,8 +16,35 @@ function CollisionSceneEntity:__index__(name)
 		return Physics3D.CollisionSceneEntity_get_gravityEnabled(self.__ptr)
 	elseif name == "autoCollide" then
 		return Physics3D.CollisionSceneEntity_get_autoCollide(self.__ptr)
+	elseif name == "gravityVector" then
+		retVal = Physics3D.CollisionSceneEntity_get_gravityVector(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
+	elseif name == "gVelocity" then
+		retVal = Physics3D.CollisionSceneEntity_get_gVelocity(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
 	elseif name == "gravityStrength" then
 		return Physics3D.CollisionSceneEntity_get_gravityStrength(self.__ptr)
+	elseif name == "lastPosition" then
+		retVal = Physics3D.CollisionSceneEntity_get_lastPosition(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = Vector3("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
 	elseif name == "enabled" then
 		return Physics3D.CollisionSceneEntity_get_enabled(self.__ptr)
 	end
@@ -58,6 +85,7 @@ end
 
 function CollisionSceneEntity:getSceneEntity()
 	local retVal =  Physics3D.CollisionSceneEntity_getSceneEntity(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -78,6 +106,7 @@ end
 
 function CollisionSceneEntity:getConvexShape()
 	local retVal =  Physics3D.CollisionSceneEntity_getConvexShape(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -89,6 +118,7 @@ end
 
 function CollisionSceneEntity:createCollisionShape(entity, type)
 	local retVal = Physics3D.CollisionSceneEntity_createCollisionShape(self.__ptr, entity.__ptr, type)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 4 - 0
Modules/Bindings/3DPhysics/API/Physics3D/PhysicsScene.lua

@@ -34,6 +34,7 @@ end
 
 function PhysicsScene:addPhysicsChild(newEntity, type, mass, friction, restitution, group)
 	local retVal = Physics3D.PhysicsScene_addPhysicsChild(self.__ptr, newEntity.__ptr, type, mass, friction, restitution, group)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -45,6 +46,7 @@ end
 
 function PhysicsScene:trackPhysicsChild(newEntity, type, mass, friction, restitution, group)
 	local retVal = Physics3D.PhysicsScene_trackPhysicsChild(self.__ptr, newEntity.__ptr, type, mass, friction, restitution, group)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -56,6 +58,7 @@ end
 
 function PhysicsScene:addCharacterChild(newEntity, mass, friction, stepSize, group)
 	local retVal = Physics3D.PhysicsScene_addCharacterChild(self.__ptr, newEntity.__ptr, mass, friction, stepSize, group)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else
@@ -67,6 +70,7 @@ end
 
 function PhysicsScene:addVehicleChild(newEntity, mass, friction, group)
 	local retVal = Physics3D.PhysicsScene_addVehicleChild(self.__ptr, newEntity.__ptr, mass, friction, group)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 1 - 0
Modules/Bindings/3DPhysics/API/Physics3D/PhysicsSceneEntity.lua

@@ -51,6 +51,7 @@ end
 
 function PhysicsSceneEntity:getSceneEntity()
 	local retVal =  Physics3D.PhysicsSceneEntity_getSceneEntity(self.__ptr)
+	if retVal == nil then return nil end
 	if Polycore.__ptr_lookup[retVal] ~= nil then
 		return Polycore.__ptr_lookup[retVal]
 	else

+ 19 - 0
Modules/Bindings/3DPhysics/API/Physics3D/PhysicsVehicle.lua

@@ -4,8 +4,23 @@ class "PhysicsVehicle" (PhysicsSceneEntity)
 
 
 
+function PhysicsVehicle:__index__(name)
+	if name == "tuning" then
+		retVal = Physics3D.PhysicsVehicle_get_tuning(self.__ptr)
+		if Polycore.__ptr_lookup[retVal] ~= nil then
+			return Polycore.__ptr_lookup[retVal]
+		else
+			Polycore.__ptr_lookup[retVal] = btRaycastVehicle::btVehicleTuning("__skip_ptr__")
+			Polycore.__ptr_lookup[retVal].__ptr = retVal
+			return Polycore.__ptr_lookup[retVal]
+		end
+	end
+end
 
 
+function PhysicsVehicle:__set_callback(name,value)
+	return false
+end
 
 
 function PhysicsVehicle:PhysicsVehicle(...)
@@ -44,6 +59,10 @@ function PhysicsVehicle:setBrake(value, wheelIndex)
 	local retVal = Physics3D.PhysicsVehicle_setBrake(self.__ptr, value, wheelIndex)
 end
 
+function PhysicsVehicle:ResetVehicle()
+	local retVal =  Physics3D.PhysicsVehicle_ResetVehicle(self.__ptr)
+end
+
 function PhysicsVehicle:Update()
 	local retVal =  Physics3D.PhysicsVehicle_Update(self.__ptr)
 end

+ 107 - 12
Modules/Bindings/3DPhysics/Include/Physics3DLUAWrappers.h

@@ -45,7 +45,12 @@ static int Physics3D_CollisionScene_getCollisionEntityByObject(lua_State *L) {
 	CollisionScene *inst = (CollisionScene*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
 	btCollisionObject * collisionObject = (btCollisionObject *)lua_topointer(L, 2);
-	lua_pushlightuserdata(L, (void*)inst->getCollisionEntityByObject(collisionObject));
+	void *ptrRetVal = (void*)inst->getCollisionEntityByObject(collisionObject);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -67,7 +72,12 @@ static int Physics3D_CollisionScene_getCollisionByScreenEntity(lua_State *L) {
 	CollisionScene *inst = (CollisionScene*)lua_topointer(L, 1);
 	luaL_checktype(L, 2, LUA_TLIGHTUSERDATA);
 	SceneEntity * ent = (SceneEntity *)lua_topointer(L, 2);
-	lua_pushlightuserdata(L, (void*)inst->getCollisionByScreenEntity(ent));
+	void *ptrRetVal = (void*)inst->getCollisionByScreenEntity(ent);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -226,7 +236,12 @@ static int Physics3D_CollisionScene_addCollisionChild(lua_State *L) {
 	} else {
 		group = 0;
 	}
-	lua_pushlightuserdata(L, (void*)inst->addCollisionChild(newEntity, autoCollide, type, group));
+	void *ptrRetVal = (void*)inst->addCollisionChild(newEntity, autoCollide, type, group);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -249,7 +264,12 @@ static int Physics3D_CollisionScene_trackCollision(lua_State *L) {
 	} else {
 		group = 0;
 	}
-	lua_pushlightuserdata(L, (void*)inst->trackCollision(newEntity, autoCollide, type, group));
+	void *ptrRetVal = (void*)inst->trackCollision(newEntity, autoCollide, type, group);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -283,6 +303,20 @@ static int Physics3D_CollisionSceneEntity_get_autoCollide(lua_State *L) {
 	return 1;
 }
 
+static int Physics3D_CollisionSceneEntity_get_gravityVector(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->gravityVector);
+	return 1;
+}
+
+static int Physics3D_CollisionSceneEntity_get_gVelocity(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->gVelocity);
+	return 1;
+}
+
 static int Physics3D_CollisionSceneEntity_get_gravityStrength(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
@@ -290,6 +324,13 @@ static int Physics3D_CollisionSceneEntity_get_gravityStrength(lua_State *L) {
 	return 1;
 }
 
+static int Physics3D_CollisionSceneEntity_get_lastPosition(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->lastPosition);
+	return 1;
+}
+
 static int Physics3D_CollisionSceneEntity_get_enabled(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
@@ -344,7 +385,12 @@ static int Physics3D_CollisionSceneEntity(lua_State *L) {
 static int Physics3D_CollisionSceneEntity_getSceneEntity(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
-	lua_pushlightuserdata(L, (void*)inst->getSceneEntity());
+	void *ptrRetVal = (void*)inst->getSceneEntity();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -365,7 +411,12 @@ static int Physics3D_CollisionSceneEntity_getType(lua_State *L) {
 static int Physics3D_CollisionSceneEntity_getConvexShape(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	CollisionSceneEntity *inst = (CollisionSceneEntity*)lua_topointer(L, 1);
-	lua_pushlightuserdata(L, (void*)inst->getConvexShape());
+	void *ptrRetVal = (void*)inst->getConvexShape();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -376,7 +427,12 @@ static int Physics3D_CollisionSceneEntity_createCollisionShape(lua_State *L) {
 	SceneEntity * entity = (SceneEntity *)lua_topointer(L, 2);
 	luaL_checktype(L, 3, LUA_TNUMBER);
 	int type = lua_tointeger(L, 3);
-	lua_pushlightuserdata(L, (void*)inst->createCollisionShape(entity, type));
+	void *ptrRetVal = (void*)inst->createCollisionShape(entity, type);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -435,7 +491,12 @@ static int Physics3D_PhysicsScene_addPhysicsChild(lua_State *L) {
 	} else {
 		group = 1;
 	}
-	lua_pushlightuserdata(L, (void*)inst->addPhysicsChild(newEntity, type, mass, friction, restitution, group));
+	void *ptrRetVal = (void*)inst->addPhysicsChild(newEntity, type, mass, friction, restitution, group);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -474,7 +535,12 @@ static int Physics3D_PhysicsScene_trackPhysicsChild(lua_State *L) {
 	} else {
 		group = 1;
 	}
-	lua_pushlightuserdata(L, (void*)inst->trackPhysicsChild(newEntity, type, mass, friction, restitution, group));
+	void *ptrRetVal = (void*)inst->trackPhysicsChild(newEntity, type, mass, friction, restitution, group);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -495,7 +561,12 @@ static int Physics3D_PhysicsScene_addCharacterChild(lua_State *L) {
 	} else {
 		group = 1;
 	}
-	lua_pushlightuserdata(L, (void*)inst->addCharacterChild(newEntity, mass, friction, stepSize, group));
+	void *ptrRetVal = (void*)inst->addCharacterChild(newEntity, mass, friction, stepSize, group);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -514,7 +585,12 @@ static int Physics3D_PhysicsScene_addVehicleChild(lua_State *L) {
 	} else {
 		group = 1;
 	}
-	lua_pushlightuserdata(L, (void*)inst->addVehicleChild(newEntity, mass, friction, group));
+	void *ptrRetVal = (void*)inst->addVehicleChild(newEntity, mass, friction, group);
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -559,7 +635,12 @@ static int Physics3D_PhysicsSceneEntity(lua_State *L) {
 static int Physics3D_PhysicsSceneEntity_getSceneEntity(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	PhysicsSceneEntity *inst = (PhysicsSceneEntity*)lua_topointer(L, 1);
-	lua_pushlightuserdata(L, (void*)inst->getSceneEntity());
+	void *ptrRetVal = (void*)inst->getSceneEntity();
+	if(ptrRetVal == NULL) {
+		lua_pushnil(L);
+	} else {
+		lua_pushlightuserdata(L, ptrRetVal);
+	}
 	return 1;
 }
 
@@ -637,6 +718,13 @@ static int Physics3D_delete_PhysicsCharacter(lua_State *L) {
 	return 0;
 }
 
+static int Physics3D_PhysicsVehicle_get_tuning(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsVehicle *inst = (PhysicsVehicle*)lua_topointer(L, 1);
+	lua_pushlightuserdata(L, &inst->tuning);
+	return 1;
+}
+
 static int Physics3D_PhysicsVehicle(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	SceneEntity * entity = (SceneEntity *)lua_topointer(L, 1);
@@ -735,6 +823,13 @@ static int Physics3D_PhysicsVehicle_setBrake(lua_State *L) {
 	return 0;
 }
 
+static int Physics3D_PhysicsVehicle_ResetVehicle(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
+	PhysicsVehicle *inst = (PhysicsVehicle*)lua_topointer(L, 1);
+	inst->ResetVehicle();
+	return 0;
+}
+
 static int Physics3D_PhysicsVehicle_Update(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TLIGHTUSERDATA);
 	PhysicsVehicle *inst = (PhysicsVehicle*)lua_topointer(L, 1);

+ 5 - 0
Modules/Bindings/3DPhysics/Source/Physics3DLUA.cpp

@@ -27,7 +27,10 @@ CoreServices::setInstance(inst);
 		{"delete_CollisionScene", Physics3D_delete_CollisionScene},
 		{"CollisionSceneEntity_get_gravityEnabled", Physics3D_CollisionSceneEntity_get_gravityEnabled},
 		{"CollisionSceneEntity_get_autoCollide", Physics3D_CollisionSceneEntity_get_autoCollide},
+		{"CollisionSceneEntity_get_gravityVector", Physics3D_CollisionSceneEntity_get_gravityVector},
+		{"CollisionSceneEntity_get_gVelocity", Physics3D_CollisionSceneEntity_get_gVelocity},
 		{"CollisionSceneEntity_get_gravityStrength", Physics3D_CollisionSceneEntity_get_gravityStrength},
+		{"CollisionSceneEntity_get_lastPosition", Physics3D_CollisionSceneEntity_get_lastPosition},
 		{"CollisionSceneEntity_get_enabled", Physics3D_CollisionSceneEntity_get_enabled},
 		{"CollisionSceneEntity_set_gravityEnabled", Physics3D_CollisionSceneEntity_set_gravityEnabled},
 		{"CollisionSceneEntity_set_autoCollide", Physics3D_CollisionSceneEntity_set_autoCollide},
@@ -60,11 +63,13 @@ CoreServices::setInstance(inst);
 		{"PhysicsCharacter_jump", Physics3D_PhysicsCharacter_jump},
 		{"PhysicsCharacter_Update", Physics3D_PhysicsCharacter_Update},
 		{"delete_PhysicsCharacter", Physics3D_delete_PhysicsCharacter},
+		{"PhysicsVehicle_get_tuning", Physics3D_PhysicsVehicle_get_tuning},
 		{"PhysicsVehicle", Physics3D_PhysicsVehicle},
 		{"PhysicsVehicle_addWheel", Physics3D_PhysicsVehicle_addWheel},
 		{"PhysicsVehicle_applyEngineForce", Physics3D_PhysicsVehicle_applyEngineForce},
 		{"PhysicsVehicle_setSteeringValue", Physics3D_PhysicsVehicle_setSteeringValue},
 		{"PhysicsVehicle_setBrake", Physics3D_PhysicsVehicle_setBrake},
+		{"PhysicsVehicle_ResetVehicle", Physics3D_PhysicsVehicle_ResetVehicle},
 		{"PhysicsVehicle_Update", Physics3D_PhysicsVehicle_Update},
 		{"delete_PhysicsVehicle", Physics3D_delete_PhysicsVehicle},
 		{NULL, NULL}

+ 15 - 0
Modules/Build/Mac OS X/Modules.xcodeproj/project.pbxproj

@@ -1160,6 +1160,20 @@
 				GCC_ENABLE_OBJC_EXCEPTIONS = YES;
 				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
 				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+				HEADER_SEARCH_PATHS = (
+					/usr/local/include/,
+					/usr/local/include/libfreenect,
+					../../../Core/Dependencies/box2d/Box2D,
+					../../../Core/Contents/Include,
+					../../../Core/Dependencies/bullet/src,
+					../../../Core/Dependencies/libvorbis/include,
+					../../../Core/Dependencies/libogg/include,
+					/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenAL.framework/Versions/A/Headers,
+					../../../Core/Dependencies/freetype/include,
+					../../../Core/Dependencies/libpng,
+					../../../Core/Dependencies/physfs,
+					../../../Core/Dependencies/luajit/src,
+				);
 				LIBRARY_SEARCH_PATHS = (
 					"$(inherited)",
 					"\"$(SRCROOT)/../../../Release/Mac OS X/Framework/Core/Lib\"",
@@ -1168,6 +1182,7 @@
 					"\"$(SRCROOT)/../../../Core/Dependencies/lua/src\"",
 				);
 				MACOSX_DEPLOYMENT_TARGET = 10.6;
+				ONLY_ACTIVE_ARCH = YES;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SDKROOT = macosx;
 			};

Разница между файлами не показана из-за своего большого размера
+ 311 - 422
Modules/Build/Mac OS X/Modules.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


+ 5 - 0
Modules/Build/Mac OS X/Modules.xcodeproj/xcuserdata/ivansafrin.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Bucket
+   type = "1"
+   version = "1.0">
+</Bucket>

+ 77 - 29
Modules/Contents/2DPhysics/Include/PolyPhysicsScreen.h

@@ -33,16 +33,70 @@ THE SOFTWARE.
 #define MAX_B2DCONTACTPOINTS 2048
 
 namespace Polycode {
-	
+
+/**
+* Event sent out by the PhysicsScreen class when collisions begin and end.
+*/	
 class _PolyExport PhysicsScreenEvent : public Event {
 	public:	
+		PhysicsScreenEvent();
+		~PhysicsScreenEvent();
+		
+		/**
+		* First colliding entity.
+		*/
+		ScreenEntity *entity1;	
+		
+		/**
+		* Second colliding entity.
+		*/		
+		ScreenEntity *entity2;	
+
+		/**
+		* First colliding entity.
+		*/
+		ScreenEntity *getFirstEntity();	
 		
-		PhysicsScreenEntity *entity1;	
-		PhysicsScreenEntity *entity2;	
+		/**
+		* Second colliding entity.
+		*/		
+		ScreenEntity *getSecondEntity();	
+
 	
+		/**
+		* Local collision normal.
+		*/
+		Vector2 localCollisionNormal;
+
+		/**
+		* Collision normal in world space
+		*/		
+		Vector2 worldCollisionNormal;
+		
+		/**
+		* Collision point
+		*/			
+		Vector2 localCollisionPoint;
+			
+		/**
+		* Strength of the collision impact.
+		*/
+		Number impactStrength;	
+		
+		/**
+		* Friction strength of the impact
+		*/		
+		Number frictionStrength;	
+							
+		/**
+		* Event sent out when a collision begins
+		*/					
 		static const int EVENT_NEW_SHAPE_COLLISION = 0;
+		
+		/**
+		* Event sent out when a collision ends
+		*/							
 		static const int EVENT_END_SHAPE_COLLISION = 1;
-		static const int EVENT_PERSIST_SHAPE_COLLISION = 2;	
 };		
 
 
@@ -97,7 +151,8 @@ public:
 	/**
 	* Adds a ScreenEntity as a physics enabled child. 
 	* @param newEntity Screen entity to add.
-	* @param entType Physics entity type to add as. Possible values are PhysicsScreenEntity::ENTITY_RECT, PhysicsScreenEntity::ENTITY_CIRCLE and PhysicsScreenEntity::ENTITY_STATICRECT
+	* @param entType Physics entity type to add as. Possible values are PhysicsScreenEntity::ENTITY_RECT, PhysicsScreenEntity::ENTITY_CIRCLE and PhysicsScreenEntity::ENTITY_MESH. If the type is ENTITY_MESH, the ScreenEntity passed must be a ScreenMesh!
+	* @param isStatic If this parameter is true, the body is static (doesn't move on its own).
 	* @param friction Friction of the physics entity. Friction controls how entities drag along each other.
 	* @param density Density of the physics entity. Density controls how heavy the entity is.
 	* @param restitution Restitution of the physics entity. Restitution controls how bouncy the entity is.
@@ -105,7 +160,7 @@ public:
 	* @param fixedRotation If this is set to true, the entity will always have a locked rotation.
 	* @return The physics entity wrapper.
 	*/
-	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, Number friction=0.1, Number density=1, Number restitution = 0, bool isSensor = false, bool fixedRotation = false);
+	PhysicsScreenEntity *addPhysicsChild(ScreenEntity *newEntity, int entType, bool isStatic, Number friction=0.1, Number density=1, Number restitution = 0, bool isSensor = false, bool fixedRotation = false);
 	
 	/**
 	* Removes a physics child from the screen.
@@ -132,16 +187,27 @@ public:
 	* @param ent1 First entity to join.
 	* @param ent2 Second entity to join.	
 	* @param collideConnected If set to true, both entities will collide with each other, if false, they will not.
+	* @return Created physics joint.	
 	*/ 
-	void createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected);
+	PhysicsJoint *createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected);
 	
 	/**
 	* Creates a new prismatic joint. Prismatic joints provide one degree of freedom between two entities. 
 	* @param ent1 First entity to join.
 	* @param ent2 Second entity to join.	
 	* @param collideConnected If set to true, both entities will collide with each other, if false, they will not.
+	* @param ax Anchor point x (relative to first entity)
+	* @param ay Anchor point y (relative to first entity)
+	* @param enableLimit If true, the rotation will be limited to the specified values 
+	* @param lowerTranslation If enableLimit is true, specifies the lower translation limit.
+	* @param upperTranslation If enableLimit is true, specifies the upper translation limit.
+	* @param motorEnabled If enabled, applies a constant motor to the rotation joint.
+	* @param motorSpeed If motorEnabled is true, controls the speed at which the motor rotates.
+	* @param maxTorque	If motorEnabled is true, specifies the maximum force applied.		
+	* @param worldAxis Specifies the relative world axis for the prismatic joint.	
+	* @return Created physics joint.	
 	*/ 	
-	void createPrismaticJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected);
+	PhysicsJoint *createPrismaticJoint(ScreenEntity *ent1, ScreenEntity *ent2, Vector2 worldAxis, Number ax, Number ay, bool collideConnected=false, Number lowerTranslation=0, Number upperTranslation=0, bool enableLimit=false, Number motorSpeed=0, Number motorForce=0, bool motorEnabled=false);
 
 	/**
 	* Creates a new revolute joint. Revolute joints enable one entity to rotate around a point on another entity.
@@ -157,7 +223,7 @@ public:
 	* @param maxTorque	If motorEnabled is true, specifies the maximum torque applied.		
 	* @return Created physics joint.
 	*/ 		
-	PhysicsJoint *createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, Number ax, Number ay, bool enableLimit, Number lowerLimit, Number upperLimit, bool motorEnabled, Number motorSpeed, Number maxTorque);
+	PhysicsJoint *createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, Number ax, Number ay, bool collideConnected=false, bool enableLimit=false, Number lowerLimit=0, Number upperLimit=0, bool motorEnabled=false, Number motorSpeed=0, Number maxTorque=0);
 	
 //	b2MouseJoint *createMouseJoint(ScreenEntity *ent1, Vector2 *mp);
 
@@ -233,6 +299,7 @@ public:
 			
 	void BeginContact (b2Contact *contact);
 	void EndContact (b2Contact *contact);	
+	void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
 
 	/**
 	* Wake up a sleeping entity. The physics engine puts non-moving entities to sleep automatically. Use this to wake them up.
@@ -242,22 +309,6 @@ public:
 	
 	void handleEvent(Event *event);
 
-	/**
-	* Returns the collision normal between two collision-tracked or physics entities.
-	* @param ent1 First entity to check.
-	* @param ent2 Second entity to check.	
-	* @return If the specified entities are colliding, this will return the collision normal or (0,0) otherwise.
-	*/ 											
-	Vector2 getEntityCollisionNormal(ScreenEntity *ent1, ScreenEntity *ent2);
-
-	/**
-	* Returns the collision status between two collision-tracked or physics entities.
-	* @param ent1 First entity to check.
-	* @param ent2 Second entity to check.	
-	* @return If the specified entities are colliding, will return true, and false if they are not.
-	*/ 												
-	bool areEntitiesColliding(ScreenEntity *ent1, ScreenEntity *ent2);
-	
 	/**
 	* Returns the entity at the specified position.
 	* @param x X position.
@@ -295,10 +346,7 @@ protected:
 
 	Timer *updateTimer;
 	vector <PhysicsScreenEntity*> physicsChildren;
-	
-	ContactPoint m_points[MAX_B2DCONTACTPOINTS];
-	int32 numContactPoints;
-	
+	vector<b2Contact*> contacts;
 	b2World *world;
 	Number timeStep;
 	int32 iterations;

+ 7 - 3
Modules/Contents/2DPhysics/Include/PolyPhysicsScreenEntity.h

@@ -23,6 +23,7 @@ THE SOFTWARE.
 #pragma once
 #include "PolyGlobals.h"
 #include "PolyScreenEntity.h"
+#include "PolyScreenMesh.h"
 #include "Box2D/Box2D.h"
 
 namespace Polycode {
@@ -32,9 +33,12 @@ namespace Polycode {
 	*/	
 	class _PolyExport PhysicsScreenEntity {
 		public:
-			PhysicsScreenEntity(ScreenEntity *entity, b2World *world, Number worldScale, int entType, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation);
+			PhysicsScreenEntity(ScreenEntity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation);
 			~PhysicsScreenEntity();		
 			
+			/**
+			* Returns the screen entity associated with this physics entity.
+			*/
 			ScreenEntity *getScreenEntity();
 			
 			/**
@@ -60,9 +64,9 @@ namespace Polycode {
 			*/ 			
 			static const int ENTITY_CIRCLE = 2;	
 			/**
-			* Static rectangular entity.
+			* Mesh entity.
 			*/ 						
-			static const int ENTITY_STATICRECT = 3;
+			static const int ENTITY_MESH = 3;
 		
 			b2Fixture *fixture;		
 			b2Body* body;

+ 122 - 138
Modules/Contents/2DPhysics/Source/PolyPhysicsScreen.cpp

@@ -25,65 +25,98 @@ THE SOFTWARE.
 
 using namespace Polycode;
 
-/*
-void PhysicsScreen::Add(const b2ContactPoint* point) {
-	if (numContactPoints == MAX_B2DCONTACTPOINTS) {
-		return;
-	}
-	
-	ContactPoint* cp = m_points + numContactPoints;
-	cp->shape1 = point->shape1;
-	cp->shape2 = point->shape2;
-	cp->position = point->position;
-	cp->normal = point->normal;
-	cp->id = point->id;
-	cp->state = e_contactAdded;
-	
-	++numContactPoints;
+PhysicsScreenEvent::PhysicsScreenEvent() : Event() {
+
 }
 
-void PhysicsScreen::Persist(const b2ContactPoint* point) {
-	if (numContactPoints == MAX_B2DCONTACTPOINTS) {
-		return;
-	}
-	
-	ContactPoint* cp = m_points + numContactPoints;
-	cp->shape1 = point->shape1;
-	cp->shape2 = point->shape2;
-	cp->position = point->position;
-	cp->normal = point->normal;
-	cp->id = point->id;
-	cp->state = e_contactPersisted;
-	
-	++numContactPoints;
+PhysicsScreenEvent::~PhysicsScreenEvent() {
+
 }
 
-void PhysicsScreen::Remove(const b2ContactPoint* point) {
-	if (numContactPoints == MAX_B2DCONTACTPOINTS) {
+ScreenEntity *PhysicsScreenEvent::getFirstEntity() {
+	return entity1;
+}
+
+ScreenEntity *PhysicsScreenEvent::getSecondEntity() {
+	return entity2;
+}
+
+
+void PhysicsScreen::BeginContact (b2Contact *contact) {
+
+	if(!contact->GetFixtureA()->IsSensor() && !contact->GetFixtureB()->IsSensor()) {
 		return;
 	}
 	
-	ContactPoint* cp = m_points + numContactPoints;
-	cp->shape1 = point->shape1;
-	cp->shape2 = point->shape2;
-	cp->position = point->position;
-	cp->normal = point->normal;
-	cp->id = point->id;
-	cp->state = e_contactRemoved;
+	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
+	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA())->getScreenEntity();
+	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB())->getScreenEntity();			
+
+	b2Manifold *manifold = contact->GetManifold();
+	b2Vec2 nor = manifold->localNormal;
+	b2Vec2 point = manifold->localPoint;
 	
-	++numContactPoints;
+
+	b2WorldManifold w_manifold;
+	contact->GetWorldManifold(&w_manifold);
+	b2Vec2 w_nor = w_manifold.normal;
+
+	newEvent->localCollisionNormal.x = nor.x;
+	newEvent->localCollisionNormal.y = nor.y;	
+	newEvent->worldCollisionNormal.x = w_nor.x;
+	newEvent->worldCollisionNormal.y = w_nor.y;	
+
+	newEvent->localCollisionPoint.x = point.x;
+	newEvent->localCollisionPoint.y = point.y;	
+	
+	newEvent->impactStrength = 0;
+	newEvent->frictionStrength = 0;
+
+	dispatchEvent(newEvent, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
 }
-*/
 
-void PhysicsScreen::BeginContact (b2Contact *contact) {
+void PhysicsScreen::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse) {
 	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
-	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA());
-	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB());			
+	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA())->getScreenEntity();
+	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB())->getScreenEntity();			
+
+	b2Manifold *manifold = contact->GetManifold();
+	b2Vec2 nor = manifold->localNormal;
+	b2Vec2 point = manifold->localPoint;
+	
+
+	b2WorldManifold w_manifold;
+	contact->GetWorldManifold(&w_manifold);
+	b2Vec2 w_nor = w_manifold.normal;
+
+	newEvent->localCollisionNormal.x = nor.x;
+	newEvent->localCollisionNormal.y = nor.y;	
+	newEvent->worldCollisionNormal.x = w_nor.x;
+	newEvent->worldCollisionNormal.y = w_nor.y;	
+
+	newEvent->localCollisionPoint.x = point.x;
+	newEvent->localCollisionPoint.y = point.y;	
+	
+	newEvent->impactStrength = 0;
+	newEvent->frictionStrength = 0;
+
+	for(int i=0; i < manifold->pointCount; i++) {
+		if(impulse->normalImpulses[i] > newEvent->impactStrength)
+			newEvent->impactStrength = impulse->normalImpulses[i];
+			
+		if(impulse->tangentImpulses[i] > newEvent->frictionStrength)
+			newEvent->frictionStrength = impulse->tangentImpulses[i];		
+	}
+
 	dispatchEvent(newEvent, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
 }
 
 void PhysicsScreen::EndContact (b2Contact *contact) {
-	
+	PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
+	newEvent->entity1 = getPhysicsEntityByFixture(contact->GetFixtureA())->getScreenEntity();
+	newEvent->entity2 = getPhysicsEntityByFixture(contact->GetFixtureB())->getScreenEntity();		
+		
+	dispatchEvent(newEvent, PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION);
 }
 
 
@@ -99,7 +132,6 @@ void PhysicsScreen::init(Number worldScale, Number physicsTimeStep, int physicsI
 	
 	this->worldScale = worldScale;
 	
-	numContactPoints = 0;	
 	timeStep = physicsTimeStep;
 	iterations = physicsIterations;
 	
@@ -109,8 +141,8 @@ void PhysicsScreen::init(Number worldScale, Number physicsTimeStep, int physicsI
 	
 	world->SetContactListener(this);
 
-	updateTimer = new Timer(true, 3);
-	updateTimer->addEventListener(this, Timer::EVENT_TRIGGER);
+//	updateTimer = new Timer(true, 3);
+//	updateTimer->addEventListener(this, Timer::EVENT_TRIGGER);
 }
 
 void PhysicsScreen::setGravity(Vector2 newGravity) {
@@ -130,7 +162,7 @@ void PhysicsScreen::destroyJoint(PhysicsJoint *joint) {
 }
 
 
-PhysicsJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, Number ax, Number ay, bool enableLimit, Number lowerLimit, Number upperLimit, bool motorEnabled, Number motorSpeed, Number maxTorque) {
+PhysicsJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntity *ent2, Number ax, Number ay, bool collideConnected, bool enableLimit, Number lowerLimit, Number upperLimit, bool motorEnabled, Number motorSpeed, Number maxTorque) {
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
 	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);
 	if(pEnt1 == NULL || pEnt2 == NULL)
@@ -138,7 +170,7 @@ PhysicsJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntit
 	
 	b2Vec2 anchor((ent1->getPosition().x+ax)/worldScale, (ent1->getPosition().y+ay)/worldScale);
 	b2RevoluteJointDef *jointDef = new b2RevoluteJointDef();
-	jointDef->collideConnected = false;
+	jointDef->collideConnected = collideConnected;
 	jointDef->lowerAngle = lowerLimit * (PI/180.0f);
 	jointDef->upperAngle = upperLimit * (PI/180.0f);
 	jointDef->enableLimit = enableLimit;
@@ -147,14 +179,38 @@ PhysicsJoint *PhysicsScreen::createRevoluteJoint(ScreenEntity *ent1, ScreenEntit
 	jointDef->enableMotor = motorEnabled;	
 	jointDef->Initialize(pEnt1->body, pEnt2->body, anchor);
 	
-	PhysicsJoint *joint = new PhysicsJoint();
-	
+	PhysicsJoint *joint = new PhysicsJoint();	
 	joint->box2DJoint = world->CreateJoint(jointDef);
 	return joint;
 	
 }
 
-void PhysicsScreen::createPrismaticJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected) {
+PhysicsJoint *PhysicsScreen::createPrismaticJoint(ScreenEntity *ent1, ScreenEntity *ent2, Vector2 worldAxis, Number ax, Number ay, bool collideConnected, Number lowerTranslation, Number upperTranslation, bool enableLimit, Number motorSpeed, Number motorForce, bool motorEnabled) {
+	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
+	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);
+	if(pEnt1 == NULL || pEnt2 == NULL)
+		return NULL;
+	
+	b2Vec2 anchor((ent1->getPosition().x+ax)/worldScale, (ent1->getPosition().y+ay)/worldScale);
+	
+	b2PrismaticJointDef *jointDef = new b2PrismaticJointDef();
+	jointDef->collideConnected = collideConnected;
+	
+	jointDef->lowerTranslation = lowerTranslation/worldScale;
+	jointDef->upperTranslation = upperTranslation/worldScale;
+	jointDef->enableLimit = enableLimit;
+	
+	jointDef->motorSpeed = motorSpeed;
+	jointDef->maxMotorForce = motorForce;
+	jointDef->enableMotor = motorEnabled;	
+	
+	b2Vec2 _worldAxis(worldAxis.x, worldAxis.y);
+	
+	jointDef->Initialize(pEnt1->body, pEnt2->body, anchor, _worldAxis);
+	
+	PhysicsJoint *joint = new PhysicsJoint();	
+	joint->box2DJoint = world->CreateJoint(jointDef);
+	return joint;
 
 }
 
@@ -225,7 +281,7 @@ void PhysicsScreen::setVelocityY(ScreenEntity *ent, Number fy) {
 
 PhysicsScreenEntity *PhysicsScreen::addCollisionChild(ScreenEntity *newEntity, int entType) {
 	PhysicsScreenEntity *ret;
-	ret = addPhysicsChild(newEntity, entType, 0,0.1,0, true);
+	ret = addPhysicsChild(newEntity, entType, false, 0,0.1,0, true);
 	ret->collisionOnly = true; 
 	return ret;
 }
@@ -262,18 +318,21 @@ void PhysicsScreen::applyImpulse(ScreenEntity *ent, Number fx, Number fy) {
 
 
 
-void PhysicsScreen::createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected) {
+PhysicsJoint *PhysicsScreen::createDistanceJoint(ScreenEntity *ent1, ScreenEntity *ent2, bool collideConnected) {
 	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
 	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);
 	if(pEnt1 == NULL || pEnt2 == NULL)
-		return;
+		return NULL;
 	
 	b2Vec2 a1(ent1->getPosition().x/worldScale, ent1->getPosition().y/worldScale);
 	b2Vec2 a2(ent2->getPosition().x/worldScale, ent2->getPosition().y/worldScale);
 	b2DistanceJointDef *jointDef = new b2DistanceJointDef();
 	jointDef->Initialize(pEnt1->body, pEnt2->body, a1, a2);
 	jointDef->collideConnected = collideConnected;
-	world->CreateJoint(jointDef);
+	
+	PhysicsJoint *joint = new PhysicsJoint();	
+	joint->box2DJoint = world->CreateJoint(jointDef);
+	return joint;	
 }
 /*
 b2MouseJoint *PhysicsScreen::createMouseJoint(ScreenEntity *ent1, Vector2 *mp) {
@@ -300,52 +359,6 @@ b2MouseJoint *PhysicsScreen::createMouseJoint(ScreenEntity *ent1, Vector2 *mp) {
 }
 */
 
-Vector2 PhysicsScreen::getEntityCollisionNormal(ScreenEntity *ent1, ScreenEntity *ent2) {
-	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
-	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);	
-	if(pEnt1 == NULL || pEnt2 == NULL)
-		return Vector2(0,0);	
-	
-	PhysicsScreenEntity *rEnt1;
-	PhysicsScreenEntity *rEnt2;
-	for (int32 i = 0; i < numContactPoints; ++i)
-	{
-		ContactPoint* point = m_points + i;		
-		if (point->state == 0 || point->state == 1) {	
-			rEnt1= getPhysicsEntityByShape(point->shape1);
-			rEnt2 = getPhysicsEntityByShape(point->shape2);						
-			if((rEnt1 == pEnt1 && rEnt2 == pEnt2) || 
-			   (rEnt1 == pEnt2 && rEnt2 == pEnt1)) {
-				return Vector2(point->normal.x,point->normal.y);
-			}
-		}
-	}
-	return Vector2(0,0);	
-}
-
-bool PhysicsScreen::areEntitiesColliding(ScreenEntity *ent1, ScreenEntity *ent2) {
-	PhysicsScreenEntity *pEnt1 = getPhysicsByScreenEntity(ent1);
-	PhysicsScreenEntity *pEnt2 = getPhysicsByScreenEntity(ent2);	
-	if(pEnt1 == NULL || pEnt2 == NULL)
-		return false;
-	
-	PhysicsScreenEntity *rEnt1;
-	PhysicsScreenEntity *rEnt2;
-	for (int32 i = 0; i < numContactPoints; ++i)
-	{
-		ContactPoint* point = m_points + i;		
-		if (point->state == 0 || point->state == 1) {	
-			rEnt1= getPhysicsEntityByShape(point->shape1);
-			rEnt2 = getPhysicsEntityByShape(point->shape2);						
-			if((rEnt1 == pEnt1 && rEnt2 == pEnt2) || 
-			   (rEnt1 == pEnt2 && rEnt2 == pEnt1)) {
-				return true;
-			}
-		}
-	}
-	return false;
-}
-
 ScreenEntity *PhysicsScreen::getEntityAtPosition(Number x, Number y) {
 	ScreenEntity *ret = NULL;
 	
@@ -383,10 +396,10 @@ void PhysicsScreen::destroyMouseJoint(b2MouseJoint *mJoint) {
 		mJoint = NULL;
 }
 
-PhysicsScreenEntity *PhysicsScreen::addPhysicsChild(ScreenEntity *newEntity, int entType, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation) {
+PhysicsScreenEntity *PhysicsScreen::addPhysicsChild(ScreenEntity *newEntity, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation) {
 	addChild(newEntity);
 	newEntity->setPositionMode(ScreenEntity::POSITION_CENTER);
-	PhysicsScreenEntity *newPhysicsEntity = new PhysicsScreenEntity(newEntity, world, worldScale, entType, friction, density, restitution, isSensor,fixedRotation);
+	PhysicsScreenEntity *newPhysicsEntity = new PhysicsScreenEntity(newEntity, world, worldScale, entType, isStatic, friction, density, restitution, isSensor,fixedRotation);
 	physicsChildren.push_back(newPhysicsEntity);
 	newPhysicsEntity->body->SetAwake(true);
 	return newPhysicsEntity;
@@ -430,42 +443,13 @@ PhysicsScreenEntity *PhysicsScreen::getPhysicsEntityByShape(b2Shape *shape) {
 	return NULL;
 }
 	
-void PhysicsScreen::handleEvent(Event *event) {
-	
-	numContactPoints = 0;
-	
-	if(event->getDispatcher() == updateTimer) {		
-		world->Step(timeStep, iterations,iterations);
-	}
-	/*
-	for (int32 i = 0; i < numContactPoints; ++i)
-	{
-		ContactPoint* point = m_points + i;		
-		if (point->state == 0) {	
-			PhysicsScreenEvent *newEvent = new PhysicsScreenEvent();
-			newEvent->entity1 = getPhysicsEntityByShape(point->shape1);
-			newEvent->entity2 = getPhysicsEntityByShape(point->shape2);			
-	
-			dispatchEvent(newEvent, PhysicsScreenEvent::EVENT_NEW_SHAPE_COLLISION);
-		} else if (point->state == 1) {
-			// Persist
-//			DrawPoint(point->position, 5.0f, b2Color(0.3f, 0.3f, 0.95f));
-		} else {
-			// Remove
-//			DrawPoint(point->position, 10.0f, b2Color(0.95f, 0.3f, 0.3f));
-			dispatchEvent(new PhysicsScreenEvent(), PhysicsScreenEvent::EVENT_END_SHAPE_COLLISION);			
-		}
-	}
-	*/
+void PhysicsScreen::handleEvent(Event *event) {	
 	Screen::handleEvent(event);
 }
 
 void PhysicsScreen::Update() {
-//	unsigned int elapsed = updateTimer->getTicks();	
-//	if(updateTimer->hasElapsed()) {
-//		world->Step(timeStep, iterations);
-		for(int i=0; i<physicsChildren.size();i++) {
-			physicsChildren[i]->Update();
-		}
-//	}
+	for(int i=0; i<physicsChildren.size();i++) {
+		physicsChildren[i]->Update();
+	}
+	world->Step(timeStep, iterations,iterations);	
 }

+ 45 - 21
Modules/Contents/2DPhysics/Source/PolyPhysicsScreenEntity.cpp

@@ -26,7 +26,7 @@ THE SOFTWARE.
 
 using namespace Polycode;
 
-PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, Number worldScale, int entType, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation) {
+PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, Number worldScale, int entType, bool isStatic, Number friction, Number density, Number restitution, bool isSensor, bool fixedRotation) {
 	
 	this->worldScale = worldScale;
 	
@@ -38,9 +38,11 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	bodyDef->bullet = isSensor;	
 	bodyDef->fixedRotation = fixedRotation;
 	
-	if(entType != ENTITY_STATICRECT)
+	if(isStatic) {
+		bodyDef->type = b2_staticBody;		
+	} else {
 		bodyDef->type = b2_dynamicBody;	
-	
+	}
 	body = world->CreateBody(bodyDef);
 		
 	b2FixtureDef fDef;
@@ -50,25 +52,47 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	fDef.isSensor = isSensor;
 		
 	switch(entType) {
-		case ENTITY_STATICRECT:
+		case ENTITY_MESH:
 		{
-			b2PolygonShape b2shape;			
-			b2shape.SetAsBox(screenEntity->getWidth()/(worldScale*2.0f), screenEntity->getHeight()/(worldScale*2.0f));
-			fDef.shape = &b2shape;			
+			b2PolygonShape *b2shape = new b2PolygonShape;			
+			
+			ScreenMesh* screenMesh = dynamic_cast<ScreenMesh*>(entity);
+			if(screenMesh != NULL) {
+				b2Vec2 *vertices = (b2Vec2*)malloc(sizeof(b2Vec2) * screenMesh->getMesh()->getVertexCount());
+	
+				int index = 0;
+				for(int i=0; i < screenMesh->getMesh()->getPolygonCount(); i++) {
+					Polycode::Polygon *poly = screenMesh->getMesh()->getPolygon(i);
+					for(int j = 0; j < poly->getVertexCount(); j++) {
+						vertices[index].x = poly->getVertex(j)->x/worldScale;
+						vertices[index].y = poly->getVertex(j)->y/worldScale;						
+						index++;
+					}
+				}
+				b2shape->Set(vertices, screenMesh->getMesh()->getVertexCount());	
+				free(vertices);
+			} else {
+				Logger::log("Tried to make a mesh collision object from a non-mesh\n");							
+			}
+
+			fDef.shape = b2shape;				
+			shape = b2shape;
 		}
 		break;
 		case ENTITY_RECT: 
 		{
-			b2PolygonShape b2shape;			
-			b2shape.SetAsBox(screenEntity->getWidth()/(worldScale*2.0f), screenEntity->getHeight()/(worldScale*2.0f));
-			fDef.shape = &b2shape;						
+			b2PolygonShape *b2shape = new b2PolygonShape;			
+			b2shape->SetAsBox(screenEntity->getWidth()/(worldScale*2.0f), screenEntity->getHeight()/(worldScale*2.0f));
+			fDef.shape = b2shape;						
+			shape = b2shape;
 		}
 		break;			
 		case ENTITY_CIRCLE:
 		{			
-			b2CircleShape b2shape;
-			b2shape.m_radius = screenEntity->getWidth()/(worldScale*2.0f);
-			fDef.shape = &b2shape;
+			b2CircleShape *b2shape = new b2CircleShape;
+			b2shape->m_radius = screenEntity->getWidth()/(worldScale*2.0f);
+			fDef.shape = b2shape;
+			shape = b2shape;
 		}
 		break;
 	}
@@ -79,6 +103,7 @@ PhysicsScreenEntity::PhysicsScreenEntity(ScreenEntity *entity, b2World *world, N
 	lastPosition.y = screenEntity->getPosition2D().y;
 
 	collisionOnly = false;
+	
 }
 
 void PhysicsScreenEntity::applyTorque(Number torque) {
@@ -104,13 +129,13 @@ void PhysicsScreenEntity::Update() {
 	Number angle = body->GetAngle();
 
 	
-//	if(lastRotation != screenEntity->getRotation() || collisionOnly) {
-//		body->SetTransform(position, screenEntity->getRotation()*(PI/180.0f));		
-//	} else {
+	if(collisionOnly) {
+		body->SetTransform(position, screenEntity->getRotation()*(PI/180.0f));		
+	} else {
 		screenEntity->setRotation(angle*(180.0f/PI));	
-//	}
-/*	
-	if(lastPosition != screenEntity->getPosition2D() || collisionOnly) {
+	}
+	
+	if(collisionOnly) {
 		b2Vec2 newPos;
 		newPos.x = screenEntity->getPosition2D().x/worldScale; 
 		newPos.y = screenEntity->getPosition2D().y/worldScale;				
@@ -118,9 +143,8 @@ void PhysicsScreenEntity::Update() {
 		position.x = screenEntity->getPosition2D().x/worldScale; 
 		position.y = screenEntity->getPosition2D().y/worldScale; 				
 	} else {
- */
 		screenEntity->setPosition(position.x*worldScale, position.y*worldScale);
-//	}
+	}
 	
 	screenEntity->dirtyMatrix(true);
 	screenEntity->rebuildTransformMatrix();

+ 0 - 4
Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer.xcodeproj/project.pbxproj

@@ -23,7 +23,6 @@
 		6DE45BF0138DA6C3000BDFBA /* libogg.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DE45BED138DA6C3000BDFBA /* libogg.a */; };
 		6DE45BF1138DA6C3000BDFBA /* libvorbis.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DE45BEE138DA6C3000BDFBA /* libvorbis.a */; };
 		6DE45BF2138DA6C3000BDFBA /* libvorbisfile.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DE45BEF138DA6C3000BDFBA /* libvorbisfile.a */; };
-		6DE45BF6138DA6F8000BDFBA /* libPolycodeGLSL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DE45BF3138DA6F8000BDFBA /* libPolycodeGLSL.a */; };
 		6DE45BF7138DA6F8000BDFBA /* libPolyCore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DE45BF4138DA6F8000BDFBA /* libPolyCore.a */; };
 		6DE45BF8138DA6F8000BDFBA /* libPolycodeLUA.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6DE45BF5138DA6F8000BDFBA /* libPolycodeLUA.a */; };
 		6DE45BFB138DA707000BDFBA /* PolycodeView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6DE45BFA138DA707000BDFBA /* PolycodeView.mm */; };
@@ -56,7 +55,6 @@
 		6DE45BED138DA6C3000BDFBA /* libogg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libogg.a; path = "../../../../Release/Mac OS X/Framework/Dependencies/Lib/libogg.a"; sourceTree = "<group>"; };
 		6DE45BEE138DA6C3000BDFBA /* libvorbis.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbis.a; path = "../../../../Release/Mac OS X/Framework/Dependencies/Lib/libvorbis.a"; sourceTree = "<group>"; };
 		6DE45BEF138DA6C3000BDFBA /* libvorbisfile.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libvorbisfile.a; path = "../../../../Release/Mac OS X/Framework/Dependencies/Lib/libvorbisfile.a"; sourceTree = "<group>"; };
-		6DE45BF3138DA6F8000BDFBA /* libPolycodeGLSL.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPolycodeGLSL.a; path = "../../../../../../../Library/Developer/Xcode/DerivedData/Modules-epduxiffqrcazabvaazmexadjpgk/Build/Products/Debug/libPolycodeGLSL.a"; sourceTree = "<group>"; };
 		6DE45BF4138DA6F8000BDFBA /* libPolyCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPolyCore.a; path = "../../../../../../../Library/Developer/Xcode/DerivedData/PolyCore-ecbhldydhvplehavgvhjdlapyvwd/Build/Products/Debug/libPolyCore.a"; sourceTree = "<group>"; };
 		6DE45BF5138DA6F8000BDFBA /* libPolycodeLUA.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPolycodeLUA.a; path = "../../../../../../../Library/Developer/Xcode/DerivedData/Bindings-bojbiqnjfgqgjpgcdihwtncgpnvk/Build/Products/Debug/libPolycodeLUA.a"; sourceTree = "<group>"; };
 		6DE45BF9138DA707000BDFBA /* PolycodeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PolycodeView.h; path = "../../../../../Release/Mac OS X/Framework/Core/PolycodeView/PolycodeView.h"; sourceTree = "<group>"; };
@@ -85,7 +83,6 @@
 				6DE45BF0138DA6C3000BDFBA /* libogg.a in Frameworks */,
 				6DE45BF1138DA6C3000BDFBA /* libvorbis.a in Frameworks */,
 				6DE45BF2138DA6C3000BDFBA /* libvorbisfile.a in Frameworks */,
-				6DE45BF6138DA6F8000BDFBA /* libPolycodeGLSL.a in Frameworks */,
 				6DE45BF7138DA6F8000BDFBA /* libPolyCore.a in Frameworks */,
 				6DE45BF8138DA6F8000BDFBA /* libPolycodeLUA.a in Frameworks */,
 			);
@@ -114,7 +111,6 @@
 		6DE45BB7138DA66C000BDFBA /* Frameworks */ = {
 			isa = PBXGroup;
 			children = (
-				6DE45BF3138DA6F8000BDFBA /* libPolycodeGLSL.a */,
 				6DE45BF4138DA6F8000BDFBA /* libPolyCore.a */,
 				6DE45BF5138DA6F8000BDFBA /* libPolycodeLUA.a */,
 				6DE45BED138DA6C3000BDFBA /* libogg.a */,

Разница между файлами не показана из-за своего большого размера
+ 442 - 240
Player/Build/Mac OS X Standalone/StandalonePlayer/StandalonePlayer.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


Разница между файлами не показана из-за своего большого размера
+ 226 - 432
Player/Build/Mac OS X/Polycode Player.xcodeproj/project.xcworkspace/xcuserdata/ivansafrin.xcuserdatad/UserInterfaceState.xcuserstate


Некоторые файлы не были показаны из-за большого количества измененных файлов