Browse Source

Update Bullet to 3.06+ (#2714)

1vanK 5 years ago
parent
commit
68edfa2a6f
100 changed files with 8975 additions and 9192 deletions
  1. 1 1
      Docs/Urho3D.dox
  2. 1 1
      README.md
  3. 7 2
      Source/ThirdParty/Bullet/AUTHORS.txt
  4. 141 107
      Source/ThirdParty/Bullet/README.md
  5. 3 0
      Source/ThirdParty/Bullet/Urho3DNotes.txt
  6. 1 1
      Source/ThirdParty/Bullet/VERSION
  7. 4 8
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp
  8. 1 998
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h
  9. 954 0
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3Internal.h
  10. 24 27
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
  11. 1 0
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp
  12. 85 106
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
  13. 0 1
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp
  14. 18 24
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h
  15. 393 338
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvt.cpp
  16. 424 346
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvt.h
  17. 438 430
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
  18. 75 76
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
  19. 0 2
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.cpp
  20. 41 44
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.h
  21. 171 192
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
  22. 168 206
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
  23. 8 7
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h
  24. 228 270
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
  25. 149 187
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
  26. 64 88
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
  27. 42 65
      Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
  28. 79 73
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
  29. 8 16
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
  30. 14 14
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp
  31. 7 8
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h
  32. 48 58
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp
  33. 11 14
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h
  34. 13 17
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
  35. 11 14
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h
  36. 637 588
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
  37. 4 8
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h
  38. 3 9
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h
  39. 4 6
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
  40. 79 114
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
  41. 43 49
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
  42. 162 0
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcherMt.cpp
  43. 38 0
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcherMt.h
  44. 53 40
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
  45. 210 199
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.h
  46. 19 13
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h
  47. 315 316
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
  48. 165 180
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
  49. 312 354
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp
  50. 39 60
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.h
  51. 119 131
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
  52. 20 25
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
  53. 139 182
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp
  54. 19 26
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h
  55. 34 65
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp
  56. 20 29
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h
  57. 141 113
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
  58. 32 42
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
  59. 464 407
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
  60. 19 27
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
  61. 47 49
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
  62. 22 24
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
  63. 99 120
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
  64. 38 49
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
  65. 2 6
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp
  66. 8 10
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h
  67. 46 51
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btGhostObject.cpp
  68. 33 46
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btGhostObject.h
  69. 29 61
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp
  70. 43 66
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.h
  71. 454 392
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
  72. 8 11
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h
  73. 94 82
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp
  74. 45 40
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.h
  75. 142 147
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
  76. 18 24
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h
  77. 42 47
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
  78. 18 20
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h
  79. 17 19
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
  80. 12 14
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h
  81. 15 17
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
  82. 13 17
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h
  83. 21 29
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btUnionFind.cpp
  84. 83 89
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btUnionFind.h
  85. 10 15
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBox2dShape.cpp
  86. 160 192
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBox2dShape.h
  87. 14 20
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBoxShape.cpp
  88. 147 170
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBoxShape.h
  89. 168 173
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
  90. 38 43
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
  91. 30 51
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp
  92. 59 61
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCapsuleShape.h
  93. 2 5
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCollisionMargin.h
  94. 31 31
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCollisionShape.cpp
  95. 51 47
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCollisionShape.h
  96. 85 109
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
  97. 47 52
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCompoundShape.h
  98. 0 3
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btConcaveShape.cpp
  99. 10 10
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btConcaveShape.h
  100. 51 56
      Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btConeShape.cpp

+ 1 - 1
Docs/Urho3D.dox

@@ -243,7 +243,7 @@ Urho3D uses the following third-party libraries:
 - AngelScript 2.33.0+ (http://www.angelcode.com/angelscript)
 - AngelScript 2.33.0+ (http://www.angelcode.com/angelscript)
 - Boost 1.64.0 (http://www.boost.org) - only used for AngelScript generic bindings
 - Boost 1.64.0 (http://www.boost.org) - only used for AngelScript generic bindings
 - Box2D 2.3.2 WIP (http://box2d.org)
 - Box2D 2.3.2 WIP (http://box2d.org)
-- Bullet 2.86.1 (http://www.bulletphysics.org)
+- Bullet 3.06+ (http://www.bulletphysics.org)
 - Civetweb 1.7 (https://github.com/civetweb/civetweb)
 - Civetweb 1.7 (https://github.com/civetweb/civetweb)
 - FreeType 2.8 (https://www.freetype.org)
 - FreeType 2.8 (https://www.freetype.org)
 - GLEW 1.13.0 (http://glew.sourceforge.net)
 - GLEW 1.13.0 (http://glew.sourceforge.net)

+ 1 - 1
README.md

@@ -207,7 +207,7 @@ Urho3D uses the following third-party libraries:
 - AngelScript 2.33.0+ (http://www.angelcode.com/angelscript)
 - AngelScript 2.33.0+ (http://www.angelcode.com/angelscript)
 - Boost 1.64.0 (http://www.boost.org) - only used for AngelScript generic bindings
 - Boost 1.64.0 (http://www.boost.org) - only used for AngelScript generic bindings
 - Box2D 2.3.2 WIP (http://box2d.org)
 - Box2D 2.3.2 WIP (http://box2d.org)
-- Bullet 2.86.1 (http://www.bulletphysics.org)
+- Bullet 3.06+ (http://www.bulletphysics.org)
 - Civetweb 1.7 (https://github.com/civetweb/civetweb)
 - Civetweb 1.7 (https://github.com/civetweb/civetweb)
 - FreeType 2.8 (https://www.freetype.org)
 - FreeType 2.8 (https://www.freetype.org)
 - GLEW 1.13.0 (http://glew.sourceforge.net)
 - GLEW 1.13.0 (http://glew.sourceforge.net)

+ 7 - 2
Source/ThirdParty/Bullet/AUTHORS.txt

@@ -2,17 +2,21 @@ Bullet Physics is created by Erwin Coumans with contributions from the following
 
 
 AMD
 AMD
 Apple
 Apple
+Yunfei Bai
 Steve Baker
 Steve Baker
 Gino van den Bergen
 Gino van den Bergen
+Jeff Bingham
 Nicola Candussi
 Nicola Candussi
 Erin Catto
 Erin Catto
 Lawrence Chai
 Lawrence Chai
 Erwin Coumans
 Erwin Coumans
-Christer Ericson
 Disney Animation
 Disney Animation
+Benjamin Ellenberger
+Christer Ericson
 Google
 Google
 Dirk Gregorius
 Dirk Gregorius
 Marcus Hennix
 Marcus Hennix
+Jasmine Hsu
 MBSim Development Team
 MBSim Development Team
 Takahiro Harada
 Takahiro Harada
 Simon Hobbs
 Simon Hobbs
@@ -20,6 +24,7 @@ John Hsu
 Ole Kniemeyer
 Ole Kniemeyer
 Jay Lee
 Jay Lee
 Francisco Leon
 Francisco Leon
+lunkhound
 Vsevolod Klementjev
 Vsevolod Klementjev
 Phil Knight
 Phil Knight
 John McCutchan
 John McCutchan
@@ -32,9 +37,9 @@ Russel Smith
 Sony
 Sony
 Jakub Stephien
 Jakub Stephien
 Marten Svanfeldt
 Marten Svanfeldt
+Jie Tan
 Pierre Terdiman
 Pierre Terdiman
 Steven Thompson
 Steven Thompson
 Tamas Umenhoffer
 Tamas Umenhoffer
-Yunfei Bai
 
 
 If your name is missing, please send an email to [email protected] or file an issue at http://github.com/bulletphysics/bullet3
 If your name is missing, please send an email to [email protected] or file an issue at http://github.com/bulletphysics/bullet3

+ 141 - 107
Source/ThirdParty/Bullet/README.md

@@ -1,107 +1,141 @@
-
-[![Travis Build Status](https://api.travis-ci.org/bulletphysics/bullet3.png?branch=master)](https://travis-ci.org/bulletphysics/bullet3)
-[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/6sly9uxajr6xsstq)](https://ci.appveyor.com/project/erwincoumans/bullet3)
-
-# Bullet Physics SDK
-
-This is the official C++ source code repository of the Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.
-
-New in Bullet 2.85: pybullet Python bindings, improved support for robotics and VR
-
-The Bullet 2 API will stay default and up-to-date while slowly moving to a new API.
-The steps towards a new API is in a nutshell:
-
-1. The old Bullet2 demos are being merged into the examples/ExampleBrowser
-2. A new physics-engine agnostic C-API is created, see examples/SharedMemory/PhysicsClientC_API.h
-3. Python bindings in pybullet are on top of this C-API, see examples/pybullet
-4. A Virtual Reality sandbox using openvr for HTC Vive and Oculus Rift is available
-5. The OpenCL examples in the ExampleBrowser can be enabled using --enable_experimental_opencl
-
-You can still use svn or svn externals using the github git repository: use svn co https://github.com/bulletphysics/bullet3/trunk
-
-## Requirements for Bullet 2
-
-A C++ compiler for C++ 2003. The library is tested on Windows, Linux, Mac OSX, iOS, Android,
-but should likely work on any platform with C++ compiler. 
-Some optional demos require OpenGL 2 or OpenGL 3, there are some non-graphical demos and unit tests too.
-
-## Contributors and Coding Style information
-
-https://docs.google.com/document/d/1u9vyzPtrVoVhYqQOGNWUgjRbfwfCdIts_NzmvgiJ144/edit
-
-## Requirements for experimental OpenCL GPGPU support
-
-The entire collision detection and rigid body dynamics can be executed on the GPU.
-
-A high-end desktop GPU, such as an AMD Radeon 7970 or NVIDIA GTX 680 or better.
-We succesfully tested the software under Windows, Linux and Mac OSX.
-The software currently doesn't work on OpenCL CPU devices. It might run
-on a laptop GPU but performance will not likely be very good. Note that
-often an OpenCL drivers fails to compile a kernel. Some unit tests exist to
-track down the issue, but more work is required to cover all OpenCL kernels.
-
-## License
-
-All source code files are licensed under the permissive zlib license
-(http://opensource.org/licenses/Zlib) unless marked differently in a particular folder/file.
-
-## Build instructions for Bullet using premake. You can also use cmake instead.
-
-**Windows**
-
-Click on build_visual_studio.bat and open build3/vs2010/0MySolution.sln
-
-**Windows Virtual Reality sandbox for HTC Vive and Oculus Rift**
-
-Click on build_visual_studio_vr_pybullet_double.bat and open build3/vs2010/0MySolution.sln
-Edit this batch file to choose where Python include/lib directories are located.
-Build and run the App_SharedMemoryPhysics_VR project, preferably in Release/optimized build.
-You can connect from Python pybullet to the sandbox using:
-
-```
-import pybullet as p
-p.connect(p.SHARED_MEMORY)
-```
-
-**Linux and Mac OSX gnu make**
-
-In a terminal type:
-
-	cd build3
-
-Depending on your system (Linux 32bit, 64bit or Mac OSX) use one of the following lines
-
-	./premake4_linux gmake
-	./premake4_linux64 gmake
-	./premake4_osx gmake
-
-Then
-
-	cd gmake
-	make
-
-**Mac OSX Xcode**
-	
-Click on build3/xcode4.command or in a terminal window execute
-	
-	./premake_osx xcode4
-
-## Usage
-
-The App_ExampleBrowser executables will be located in the bin folder.
-You can just run it though a terminal/command prompt, or by clicking it.
-
-
-```
-[--start_demo_name="Demo Name"]     Start with a selected demo  
-[--mp4=moviename.mp4]               Create a mp4 movie of the window, requires ffmpeg installed
-[--mouse_move_multiplier=0.400000]  Set the mouse move sensitivity
-[--mouse_wheel_multiplier=0.01]     Set the mouse wheel sensitivity
-[--background_color_red= 0.9]       Set the red component for background color. Same for green and blue
-[--fixed_timestep= 0.0]             Use either a real-time delta time (0.0) or a fixed step size (0.016666)
-```
-
-You can use mouse picking to grab objects. When holding the ALT or CONTROL key, you have Maya style camera mouse controls.
-Press F1 to create a series of screenshots. Hit ESCAPE to exit the demo app.
-
-Check out the docs folder and the Bullet physics forums for further information.
+[![Travis Build Status](https://api.travis-ci.org/bulletphysics/bullet3.png?branch=master)](https://travis-ci.org/bulletphysics/bullet3)
+[![Appveyor Build status](https://ci.appveyor.com/api/projects/status/6sly9uxajr6xsstq)](https://ci.appveyor.com/project/erwincoumans/bullet3)
+
+# Bullet Physics SDK
+
+This is the official C++ source code repository of the Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.
+
+![PyBullet](https://pybullet.org/wordpress/wp-content/uploads/2019/03/cropped-pybullet.png)
+
+## PyBullet ##
+New in Bullet 2.85: pybullet Python bindings, improved support for robotics and VR. Use pip install pybullet and checkout the [PyBullet Quickstart Guide](https://docs.google.com/document/d/10sXEhzFRSnvFcl3XxNGhnD4N2SedqwdAvK3dsihxVUA/edit#heading=h.2ye70wns7io3).
+
+Installation is simple:
+```
+pip3 install pybullet --upgrade --user
+python3 -m pybullet_envs.examples.enjoy_TF_AntBulletEnv_v0_2017may
+python3 -m pybullet_envs.examples.enjoy_TF_HumanoidFlagrunHarderBulletEnv_v1_2017jul
+python3 -m pybullet_envs.deep_mimic.testrl --arg_file run_humanoid3d_backflip_args.txt
+```
+
+If you use PyBullet in your research, please cite it like this:
+
+```
+@MISC{coumans2019,
+author =   {Erwin Coumans and Yunfei Bai},
+title =    {PyBullet, a Python module for physics simulation for games, robotics and machine learning},
+howpublished = {\url{http://pybullet.org}},
+year = {2016--2019}
+}
+```
+
+## Requirements for Bullet Physics C++
+
+A C++ compiler for C++ 2003. The library is tested on Windows, Linux, Mac OSX, iOS, Android,
+but should likely work on any platform with C++ compiler. 
+Some optional demos require OpenGL 2 or OpenGL 3, there are some non-graphical demos and unit tests too.
+
+## Contributors and Coding Style information
+
+https://docs.google.com/document/d/1u9vyzPtrVoVhYqQOGNWUgjRbfwfCdIts_NzmvgiJ144/edit
+
+## Requirements for experimental OpenCL GPGPU support
+
+The entire collision detection and rigid body dynamics can be executed on the GPU.
+
+A high-end desktop GPU, such as an AMD Radeon 7970 or NVIDIA GTX 680 or better.
+We succesfully tested the software under Windows, Linux and Mac OSX.
+The software currently doesn't work on OpenCL CPU devices. It might run
+on a laptop GPU but performance will not likely be very good. Note that
+often an OpenCL drivers fails to compile a kernel. Some unit tests exist to
+track down the issue, but more work is required to cover all OpenCL kernels.
+
+## License
+
+All source code files are licensed under the permissive zlib license
+(http://opensource.org/licenses/Zlib) unless marked differently in a particular folder/file.
+
+## Build instructions for Bullet using vcpkg
+
+You can download and install Bullet using the [vcpkg](https://github.com/Microsoft/vcpkg/) dependency manager:
+
+    git clone https://github.com/Microsoft/vcpkg.git
+    cd vcpkg
+    ./bootstrap-vcpkg.sh
+    ./vcpkg integrate install
+    vcpkg install bullet3
+
+The Bullet port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
+
+## Build instructions for Bullet using premake. You can also use cmake instead.
+
+**Windows**
+
+Click on build_visual_studio_vr_pybullet_double.bat and open build3/vs2010/0_Bullet3Solution.sln
+When asked, convert the projects to a newer version of Visual Studio.
+If you installed Python in the C:\ root directory, the batch file should find it automatically.
+Otherwise, edit this batch file to choose where Python include/lib directories are located.
+
+**Windows Virtual Reality sandbox for HTC Vive and Oculus Rift**
+
+Build and run the App_SharedMemoryPhysics_VR project, preferably in Release/optimized build.
+You can connect from Python pybullet to the sandbox using:
+
+```
+import pybullet as p
+p.connect(p.SHARED_MEMORY) #or (p.TCP, "localhost", 6667) or (p.UDP, "192.168.86.10",1234)
+```
+
+**Linux and Mac OSX gnu make**
+
+Make sure cmake is installed (sudo apt-get install cmake, brew install cmake, or https://cmake.org)
+
+In a terminal type:
+
+	./build_cmake_pybullet_double.sh
+
+This script will invoke cmake and build in the build_cmake directory. You can find pybullet in Bullet/examples/pybullet.
+The BulletExampleBrowser binary will be in Bullet/examples/ExampleBrowser.
+
+You can also build Bullet using premake. There are premake executables in the build3 folder.
+Depending on your system (Linux 32bit, 64bit or Mac OSX) use one of the following lines
+Using premake:
+```
+	cd build3
+	./premake4_linux --double gmake
+	./premake4_linux64 --double gmake
+	./premake4_osx --double --enable_pybullet gmake
+```
+Then
+```
+	cd gmake
+	make
+```
+
+Note that on Linux, you need to use cmake to build pybullet, since the compiler has issues of mixing shared and static libraries.
+
+**Mac OSX Xcode**
+	
+Click on build3/xcode4.command or in a terminal window execute
+	
+	./premake_osx xcode4
+
+## Usage
+
+The App_ExampleBrowser executables will be located in the bin folder.
+You can just run it though a terminal/command prompt, or by clicking it.
+
+
+```
+[--start_demo_name="Demo Name"]     Start with a selected demo  
+[--mp4=moviename.mp4]               Create a mp4 movie of the window, requires ffmpeg installed
+[--mouse_move_multiplier=0.400000]  Set the mouse move sensitivity
+[--mouse_wheel_multiplier=0.01]     Set the mouse wheel sensitivity
+[--background_color_red= 0.9]       Set the red component for background color. Same for green and blue
+[--fixed_timestep= 0.0]             Use either a real-time delta time (0.0) or a fixed step size (0.016666)
+```
+
+You can use mouse picking to grab objects. When holding the ALT or CONTROL key, you have Maya style camera mouse controls.
+Press F1 to create a series of screenshots. Hit ESCAPE to exit the demo app.
+
+Check out the docs folder and the Bullet physics forums for further information.

+ 3 - 0
Source/ThirdParty/Bullet/Urho3DNotes.txt

@@ -0,0 +1,3 @@
+URL: https://github.com/bulletphysics/bullet3
+Date: 01.11.2020
+Latest commit: https://github.com/bulletphysics/bullet3/commit/62684840bd26fd5c4a15d5150f3502b29390b638

+ 1 - 1
Source/ThirdParty/Bullet/VERSION

@@ -1 +1 @@
-2.86
+3.05

+ 4 - 8
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3.cpp

@@ -2,7 +2,6 @@
 //Bullet Continuous Collision Detection and Physics Library
 //Bullet Continuous Collision Detection and Physics Library
 //Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
 //Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
 
 
-
 //
 //
 // btAxisSweep3
 // btAxisSweep3
 //
 //
@@ -19,18 +18,15 @@
 // 3. This notice may not be removed or altered from any source distribution.
 // 3. This notice may not be removed or altered from any source distribution.
 #include "btAxisSweep3.h"
 #include "btAxisSweep3.h"
 
 
-
-btAxisSweep3::btAxisSweep3(const btVector3& worldAabbMin,const btVector3& worldAabbMax, unsigned short int maxHandles, btOverlappingPairCache* pairCache, bool disableRaycastAccelerator)
-:btAxisSweep3Internal<unsigned short int>(worldAabbMin,worldAabbMax,0xfffe,0xffff,maxHandles,pairCache,disableRaycastAccelerator)
+btAxisSweep3::btAxisSweep3(const btVector3& worldAabbMin, const btVector3& worldAabbMax, unsigned short int maxHandles, btOverlappingPairCache* pairCache, bool disableRaycastAccelerator)
+	: btAxisSweep3Internal<unsigned short int>(worldAabbMin, worldAabbMax, 0xfffe, 0xffff, maxHandles, pairCache, disableRaycastAccelerator)
 {
 {
 	// 1 handle is reserved as sentinel
 	// 1 handle is reserved as sentinel
 	btAssert(maxHandles > 1 && maxHandles < 32767);
 	btAssert(maxHandles > 1 && maxHandles < 32767);
-
 }
 }
 
 
-
-bt32BitAxisSweep3::bt32BitAxisSweep3(const btVector3& worldAabbMin,const btVector3& worldAabbMax, unsigned int maxHandles , btOverlappingPairCache* pairCache , bool disableRaycastAccelerator)
-:btAxisSweep3Internal<unsigned int>(worldAabbMin,worldAabbMax,0xfffffffe,0x7fffffff,maxHandles,pairCache,disableRaycastAccelerator)
+bt32BitAxisSweep3::bt32BitAxisSweep3(const btVector3& worldAabbMin, const btVector3& worldAabbMax, unsigned int maxHandles, btOverlappingPairCache* pairCache, bool disableRaycastAccelerator)
+	: btAxisSweep3Internal<unsigned int>(worldAabbMin, worldAabbMax, 0xfffffffe, 0x7fffffff, maxHandles, pairCache, disableRaycastAccelerator)
 {
 {
 	// 1 handle is reserved as sentinel
 	// 1 handle is reserved as sentinel
 	btAssert(maxHandles > 1 && maxHandles < 2147483647);
 	btAssert(maxHandles > 1 && maxHandles < 2147483647);

File diff suppressed because it is too large
+ 1 - 998
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h


+ 954 - 0
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3Internal.h

@@ -0,0 +1,954 @@
+//Bullet Continuous Collision Detection and Physics Library
+//Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
+
+//
+// btAxisSweep3.h
+//
+// Copyright (c) 2006 Simon Hobbs
+//
+// This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+
+#ifndef BT_AXIS_SWEEP_3_INTERNAL_H
+#define BT_AXIS_SWEEP_3_INTERNAL_H
+
+#include "LinearMath/btVector3.h"
+#include "btOverlappingPairCache.h"
+#include "btBroadphaseInterface.h"
+#include "btBroadphaseProxy.h"
+#include "btOverlappingPairCallback.h"
+#include "btDbvtBroadphase.h"
+
+//#define DEBUG_BROADPHASE 1
+#define USE_OVERLAP_TEST_ON_REMOVES 1
+
+/// The internal templace class btAxisSweep3Internal implements the sweep and prune broadphase.
+/// It uses quantized integers to represent the begin and end points for each of the 3 axis.
+/// Dont use this class directly, use btAxisSweep3 or bt32BitAxisSweep3 instead.
+template <typename BP_FP_INT_TYPE>
+class btAxisSweep3Internal : public btBroadphaseInterface
+{
+protected:
+	BP_FP_INT_TYPE m_bpHandleMask;
+	BP_FP_INT_TYPE m_handleSentinel;
+
+public:
+	BT_DECLARE_ALIGNED_ALLOCATOR();
+
+	class Edge
+	{
+	public:
+		BP_FP_INT_TYPE m_pos;  // low bit is min/max
+		BP_FP_INT_TYPE m_handle;
+
+		BP_FP_INT_TYPE IsMax() const { return static_cast<BP_FP_INT_TYPE>(m_pos & 1); }
+	};
+
+public:
+	class Handle : public btBroadphaseProxy
+	{
+	public:
+		BT_DECLARE_ALIGNED_ALLOCATOR();
+
+		// indexes into the edge arrays
+		BP_FP_INT_TYPE m_minEdges[3], m_maxEdges[3];  // 6 * 2 = 12
+													  //		BP_FP_INT_TYPE m_uniqueId;
+		btBroadphaseProxy* m_dbvtProxy;               //for faster raycast
+		//void* m_pOwner; this is now in btBroadphaseProxy.m_clientObject
+
+		SIMD_FORCE_INLINE void SetNextFree(BP_FP_INT_TYPE next) { m_minEdges[0] = next; }
+		SIMD_FORCE_INLINE BP_FP_INT_TYPE GetNextFree() const { return m_minEdges[0]; }
+	};  // 24 bytes + 24 for Edge structures = 44 bytes total per entry
+
+protected:
+	btVector3 m_worldAabbMin;  // overall system bounds
+	btVector3 m_worldAabbMax;  // overall system bounds
+
+	btVector3 m_quantize;  // scaling factor for quantization
+
+	BP_FP_INT_TYPE m_numHandles;  // number of active handles
+	BP_FP_INT_TYPE m_maxHandles;  // max number of handles
+	Handle* m_pHandles;           // handles pool
+
+	BP_FP_INT_TYPE m_firstFreeHandle;  // free handles list
+
+	Edge* m_pEdges[3];  // edge arrays for the 3 axes (each array has m_maxHandles * 2 + 2 sentinel entries)
+	void* m_pEdgesRawPtr[3];
+
+	btOverlappingPairCache* m_pairCache;
+
+	///btOverlappingPairCallback is an additional optional user callback for adding/removing overlapping pairs, similar interface to btOverlappingPairCache.
+	btOverlappingPairCallback* m_userPairCallback;
+
+	bool m_ownsPairCache;
+
+	int m_invalidPair;
+
+	///additional dynamic aabb structure, used to accelerate ray cast queries.
+	///can be disabled using a optional argument in the constructor
+	btDbvtBroadphase* m_raycastAccelerator;
+	btOverlappingPairCache* m_nullPairCache;
+
+	// allocation/deallocation
+	BP_FP_INT_TYPE allocHandle();
+	void freeHandle(BP_FP_INT_TYPE handle);
+
+	bool testOverlap2D(const Handle* pHandleA, const Handle* pHandleB, int axis0, int axis1);
+
+#ifdef DEBUG_BROADPHASE
+	void debugPrintAxis(int axis, bool checkCardinality = true);
+#endif  //DEBUG_BROADPHASE
+
+	//Overlap* AddOverlap(BP_FP_INT_TYPE handleA, BP_FP_INT_TYPE handleB);
+	//void RemoveOverlap(BP_FP_INT_TYPE handleA, BP_FP_INT_TYPE handleB);
+
+	void sortMinDown(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps);
+	void sortMinUp(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps);
+	void sortMaxDown(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps);
+	void sortMaxUp(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps);
+
+public:
+	btAxisSweep3Internal(const btVector3& worldAabbMin, const btVector3& worldAabbMax, BP_FP_INT_TYPE handleMask, BP_FP_INT_TYPE handleSentinel, BP_FP_INT_TYPE maxHandles = 16384, btOverlappingPairCache* pairCache = 0, bool disableRaycastAccelerator = false);
+
+	virtual ~btAxisSweep3Internal();
+
+	BP_FP_INT_TYPE getNumHandles() const
+	{
+		return m_numHandles;
+	}
+
+	virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
+
+	BP_FP_INT_TYPE addHandle(const btVector3& aabbMin, const btVector3& aabbMax, void* pOwner, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
+	void removeHandle(BP_FP_INT_TYPE handle, btDispatcher* dispatcher);
+	void updateHandle(BP_FP_INT_TYPE handle, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher);
+	SIMD_FORCE_INLINE Handle* getHandle(BP_FP_INT_TYPE index) const { return m_pHandles + index; }
+
+	virtual void resetPool(btDispatcher* dispatcher);
+
+	void processAllOverlappingPairs(btOverlapCallback* callback);
+
+	//Broadphase Interface
+	virtual btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
+	virtual void destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
+	virtual void setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher);
+	virtual void getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const;
+
+	virtual void rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin = btVector3(0, 0, 0), const btVector3& aabbMax = btVector3(0, 0, 0));
+	virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
+
+	void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const;
+	///unQuantize should be conservative: aabbMin/aabbMax should be larger then 'getAabb' result
+	void unQuantize(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const;
+
+	bool testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1);
+
+	btOverlappingPairCache* getOverlappingPairCache()
+	{
+		return m_pairCache;
+	}
+	const btOverlappingPairCache* getOverlappingPairCache() const
+	{
+		return m_pairCache;
+	}
+
+	void setOverlappingPairUserCallback(btOverlappingPairCallback* pairCallback)
+	{
+		m_userPairCallback = pairCallback;
+	}
+	const btOverlappingPairCallback* getOverlappingPairUserCallback() const
+	{
+		return m_userPairCallback;
+	}
+
+	///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
+	///will add some transform later
+	virtual void getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const
+	{
+		aabbMin = m_worldAabbMin;
+		aabbMax = m_worldAabbMax;
+	}
+
+	virtual void printStats()
+	{
+		/*		printf("btAxisSweep3.h\n");
+		printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
+		printf("aabbMin=%f,%f,%f,aabbMax=%f,%f,%f\n",m_worldAabbMin.getX(),m_worldAabbMin.getY(),m_worldAabbMin.getZ(),
+			m_worldAabbMax.getX(),m_worldAabbMax.getY(),m_worldAabbMax.getZ());
+			*/
+	}
+};
+
+////////////////////////////////////////////////////////////////////
+
+#ifdef DEBUG_BROADPHASE
+#include <stdio.h>
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3<BP_FP_INT_TYPE>::debugPrintAxis(int axis, bool checkCardinality)
+{
+	int numEdges = m_pHandles[0].m_maxEdges[axis];
+	printf("SAP Axis %d, numEdges=%d\n", axis, numEdges);
+
+	int i;
+	for (i = 0; i < numEdges + 1; i++)
+	{
+		Edge* pEdge = m_pEdges[axis] + i;
+		Handle* pHandlePrev = getHandle(pEdge->m_handle);
+		int handleIndex = pEdge->IsMax() ? pHandlePrev->m_maxEdges[axis] : pHandlePrev->m_minEdges[axis];
+		char beginOrEnd;
+		beginOrEnd = pEdge->IsMax() ? 'E' : 'B';
+		printf("	[%c,h=%d,p=%x,i=%d]\n", beginOrEnd, pEdge->m_handle, pEdge->m_pos, handleIndex);
+	}
+
+	if (checkCardinality)
+		btAssert(numEdges == m_numHandles * 2 + 1);
+}
+#endif  //DEBUG_BROADPHASE
+
+template <typename BP_FP_INT_TYPE>
+btBroadphaseProxy* btAxisSweep3Internal<BP_FP_INT_TYPE>::createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher)
+{
+	(void)shapeType;
+	BP_FP_INT_TYPE handleId = addHandle(aabbMin, aabbMax, userPtr, collisionFilterGroup, collisionFilterMask, dispatcher);
+
+	Handle* handle = getHandle(handleId);
+
+	if (m_raycastAccelerator)
+	{
+		btBroadphaseProxy* rayProxy = m_raycastAccelerator->createProxy(aabbMin, aabbMax, shapeType, userPtr, collisionFilterGroup, collisionFilterMask, dispatcher);
+		handle->m_dbvtProxy = rayProxy;
+	}
+	return handle;
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher)
+{
+	Handle* handle = static_cast<Handle*>(proxy);
+	if (m_raycastAccelerator)
+		m_raycastAccelerator->destroyProxy(handle->m_dbvtProxy, dispatcher);
+	removeHandle(static_cast<BP_FP_INT_TYPE>(handle->m_uniqueId), dispatcher);
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher)
+{
+	Handle* handle = static_cast<Handle*>(proxy);
+	handle->m_aabbMin = aabbMin;
+	handle->m_aabbMax = aabbMax;
+	updateHandle(static_cast<BP_FP_INT_TYPE>(handle->m_uniqueId), aabbMin, aabbMax, dispatcher);
+	if (m_raycastAccelerator)
+		m_raycastAccelerator->setAabb(handle->m_dbvtProxy, aabbMin, aabbMax, dispatcher);
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin, const btVector3& aabbMax)
+{
+	if (m_raycastAccelerator)
+	{
+		m_raycastAccelerator->rayTest(rayFrom, rayTo, rayCallback, aabbMin, aabbMax);
+	}
+	else
+	{
+		//choose axis?
+		BP_FP_INT_TYPE axis = 0;
+		//for each proxy
+		for (BP_FP_INT_TYPE i = 1; i < m_numHandles * 2 + 1; i++)
+		{
+			if (m_pEdges[axis][i].IsMax())
+			{
+				rayCallback.process(getHandle(m_pEdges[axis][i].m_handle));
+			}
+		}
+	}
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
+{
+	if (m_raycastAccelerator)
+	{
+		m_raycastAccelerator->aabbTest(aabbMin, aabbMax, callback);
+	}
+	else
+	{
+		//choose axis?
+		BP_FP_INT_TYPE axis = 0;
+		//for each proxy
+		for (BP_FP_INT_TYPE i = 1; i < m_numHandles * 2 + 1; i++)
+		{
+			if (m_pEdges[axis][i].IsMax())
+			{
+				Handle* handle = getHandle(m_pEdges[axis][i].m_handle);
+				if (TestAabbAgainstAabb2(aabbMin, aabbMax, handle->m_aabbMin, handle->m_aabbMax))
+				{
+					callback.process(handle);
+				}
+			}
+		}
+	}
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const
+{
+	Handle* pHandle = static_cast<Handle*>(proxy);
+	aabbMin = pHandle->m_aabbMin;
+	aabbMax = pHandle->m_aabbMax;
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::unQuantize(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const
+{
+	Handle* pHandle = static_cast<Handle*>(proxy);
+
+	unsigned short vecInMin[3];
+	unsigned short vecInMax[3];
+
+	vecInMin[0] = m_pEdges[0][pHandle->m_minEdges[0]].m_pos;
+	vecInMax[0] = m_pEdges[0][pHandle->m_maxEdges[0]].m_pos + 1;
+	vecInMin[1] = m_pEdges[1][pHandle->m_minEdges[1]].m_pos;
+	vecInMax[1] = m_pEdges[1][pHandle->m_maxEdges[1]].m_pos + 1;
+	vecInMin[2] = m_pEdges[2][pHandle->m_minEdges[2]].m_pos;
+	vecInMax[2] = m_pEdges[2][pHandle->m_maxEdges[2]].m_pos + 1;
+
+	aabbMin.setValue((btScalar)(vecInMin[0]) / (m_quantize.getX()), (btScalar)(vecInMin[1]) / (m_quantize.getY()), (btScalar)(vecInMin[2]) / (m_quantize.getZ()));
+	aabbMin += m_worldAabbMin;
+
+	aabbMax.setValue((btScalar)(vecInMax[0]) / (m_quantize.getX()), (btScalar)(vecInMax[1]) / (m_quantize.getY()), (btScalar)(vecInMax[2]) / (m_quantize.getZ()));
+	aabbMax += m_worldAabbMin;
+}
+
+template <typename BP_FP_INT_TYPE>
+btAxisSweep3Internal<BP_FP_INT_TYPE>::btAxisSweep3Internal(const btVector3& worldAabbMin, const btVector3& worldAabbMax, BP_FP_INT_TYPE handleMask, BP_FP_INT_TYPE handleSentinel, BP_FP_INT_TYPE userMaxHandles, btOverlappingPairCache* pairCache, bool disableRaycastAccelerator)
+	: m_bpHandleMask(handleMask),
+	  m_handleSentinel(handleSentinel),
+	  m_pairCache(pairCache),
+	  m_userPairCallback(0),
+	  m_ownsPairCache(false),
+	  m_invalidPair(0),
+	  m_raycastAccelerator(0)
+{
+	BP_FP_INT_TYPE maxHandles = static_cast<BP_FP_INT_TYPE>(userMaxHandles + 1);  //need to add one sentinel handle
+
+	if (!m_pairCache)
+	{
+		void* ptr = btAlignedAlloc(sizeof(btHashedOverlappingPairCache), 16);
+		m_pairCache = new (ptr) btHashedOverlappingPairCache();
+		m_ownsPairCache = true;
+	}
+
+	if (!disableRaycastAccelerator)
+	{
+		m_nullPairCache = new (btAlignedAlloc(sizeof(btNullPairCache), 16)) btNullPairCache();
+		m_raycastAccelerator = new (btAlignedAlloc(sizeof(btDbvtBroadphase), 16)) btDbvtBroadphase(m_nullPairCache);  //m_pairCache);
+		m_raycastAccelerator->m_deferedcollide = true;                                                                //don't add/remove pairs
+	}
+
+	//btAssert(bounds.HasVolume());
+
+	// init bounds
+	m_worldAabbMin = worldAabbMin;
+	m_worldAabbMax = worldAabbMax;
+
+	btVector3 aabbSize = m_worldAabbMax - m_worldAabbMin;
+
+	BP_FP_INT_TYPE maxInt = m_handleSentinel;
+
+	m_quantize = btVector3(btScalar(maxInt), btScalar(maxInt), btScalar(maxInt)) / aabbSize;
+
+	// allocate handles buffer, using btAlignedAlloc, and put all handles on free list
+	m_pHandles = new Handle[maxHandles];
+
+	m_maxHandles = maxHandles;
+	m_numHandles = 0;
+
+	// handle 0 is reserved as the null index, and is also used as the sentinel
+	m_firstFreeHandle = 1;
+	{
+		for (BP_FP_INT_TYPE i = m_firstFreeHandle; i < maxHandles; i++)
+			m_pHandles[i].SetNextFree(static_cast<BP_FP_INT_TYPE>(i + 1));
+		m_pHandles[maxHandles - 1].SetNextFree(0);
+	}
+
+	{
+		// allocate edge buffers
+		for (int i = 0; i < 3; i++)
+		{
+			m_pEdgesRawPtr[i] = btAlignedAlloc(sizeof(Edge) * maxHandles * 2, 16);
+			m_pEdges[i] = new (m_pEdgesRawPtr[i]) Edge[maxHandles * 2];
+		}
+	}
+	//removed overlap management
+
+	// make boundary sentinels
+
+	m_pHandles[0].m_clientObject = 0;
+
+	for (int axis = 0; axis < 3; axis++)
+	{
+		m_pHandles[0].m_minEdges[axis] = 0;
+		m_pHandles[0].m_maxEdges[axis] = 1;
+
+		m_pEdges[axis][0].m_pos = 0;
+		m_pEdges[axis][0].m_handle = 0;
+		m_pEdges[axis][1].m_pos = m_handleSentinel;
+		m_pEdges[axis][1].m_handle = 0;
+#ifdef DEBUG_BROADPHASE
+		debugPrintAxis(axis);
+#endif  //DEBUG_BROADPHASE
+	}
+}
+
+template <typename BP_FP_INT_TYPE>
+btAxisSweep3Internal<BP_FP_INT_TYPE>::~btAxisSweep3Internal()
+{
+	if (m_raycastAccelerator)
+	{
+		m_nullPairCache->~btOverlappingPairCache();
+		btAlignedFree(m_nullPairCache);
+		m_raycastAccelerator->~btDbvtBroadphase();
+		btAlignedFree(m_raycastAccelerator);
+	}
+
+	for (int i = 2; i >= 0; i--)
+	{
+		btAlignedFree(m_pEdgesRawPtr[i]);
+	}
+	delete[] m_pHandles;
+
+	if (m_ownsPairCache)
+	{
+		m_pairCache->~btOverlappingPairCache();
+		btAlignedFree(m_pairCache);
+	}
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const
+{
+#ifdef OLD_CLAMPING_METHOD
+	///problem with this clamping method is that the floating point during quantization might still go outside the range [(0|isMax) .. (m_handleSentinel&m_bpHandleMask]|isMax]
+	///see http://code.google.com/p/bullet/issues/detail?id=87
+	btVector3 clampedPoint(point);
+	clampedPoint.setMax(m_worldAabbMin);
+	clampedPoint.setMin(m_worldAabbMax);
+	btVector3 v = (clampedPoint - m_worldAabbMin) * m_quantize;
+	out[0] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getX() & m_bpHandleMask) | isMax);
+	out[1] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getY() & m_bpHandleMask) | isMax);
+	out[2] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getZ() & m_bpHandleMask) | isMax);
+#else
+	btVector3 v = (point - m_worldAabbMin) * m_quantize;
+	out[0] = (v[0] <= 0) ? (BP_FP_INT_TYPE)isMax : (v[0] >= m_handleSentinel) ? (BP_FP_INT_TYPE)((m_handleSentinel & m_bpHandleMask) | isMax) : (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v[0] & m_bpHandleMask) | isMax);
+	out[1] = (v[1] <= 0) ? (BP_FP_INT_TYPE)isMax : (v[1] >= m_handleSentinel) ? (BP_FP_INT_TYPE)((m_handleSentinel & m_bpHandleMask) | isMax) : (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v[1] & m_bpHandleMask) | isMax);
+	out[2] = (v[2] <= 0) ? (BP_FP_INT_TYPE)isMax : (v[2] >= m_handleSentinel) ? (BP_FP_INT_TYPE)((m_handleSentinel & m_bpHandleMask) | isMax) : (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v[2] & m_bpHandleMask) | isMax);
+#endif  //OLD_CLAMPING_METHOD
+}
+
+template <typename BP_FP_INT_TYPE>
+BP_FP_INT_TYPE btAxisSweep3Internal<BP_FP_INT_TYPE>::allocHandle()
+{
+	btAssert(m_firstFreeHandle);
+
+	BP_FP_INT_TYPE handle = m_firstFreeHandle;
+	m_firstFreeHandle = getHandle(handle)->GetNextFree();
+	m_numHandles++;
+
+	return handle;
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::freeHandle(BP_FP_INT_TYPE handle)
+{
+	btAssert(handle > 0 && handle < m_maxHandles);
+
+	getHandle(handle)->SetNextFree(m_firstFreeHandle);
+	m_firstFreeHandle = handle;
+
+	m_numHandles--;
+}
+
+template <typename BP_FP_INT_TYPE>
+BP_FP_INT_TYPE btAxisSweep3Internal<BP_FP_INT_TYPE>::addHandle(const btVector3& aabbMin, const btVector3& aabbMax, void* pOwner, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher)
+{
+	// quantize the bounds
+	BP_FP_INT_TYPE min[3], max[3];
+	quantize(min, aabbMin, 0);
+	quantize(max, aabbMax, 1);
+
+	// allocate a handle
+	BP_FP_INT_TYPE handle = allocHandle();
+
+	Handle* pHandle = getHandle(handle);
+
+	pHandle->m_uniqueId = static_cast<int>(handle);
+	//pHandle->m_pOverlaps = 0;
+	pHandle->m_clientObject = pOwner;
+	pHandle->m_collisionFilterGroup = collisionFilterGroup;
+	pHandle->m_collisionFilterMask = collisionFilterMask;
+
+	// compute current limit of edge arrays
+	BP_FP_INT_TYPE limit = static_cast<BP_FP_INT_TYPE>(m_numHandles * 2);
+
+	// insert new edges just inside the max boundary edge
+	for (BP_FP_INT_TYPE axis = 0; axis < 3; axis++)
+	{
+		m_pHandles[0].m_maxEdges[axis] += 2;
+
+		m_pEdges[axis][limit + 1] = m_pEdges[axis][limit - 1];
+
+		m_pEdges[axis][limit - 1].m_pos = min[axis];
+		m_pEdges[axis][limit - 1].m_handle = handle;
+
+		m_pEdges[axis][limit].m_pos = max[axis];
+		m_pEdges[axis][limit].m_handle = handle;
+
+		pHandle->m_minEdges[axis] = static_cast<BP_FP_INT_TYPE>(limit - 1);
+		pHandle->m_maxEdges[axis] = limit;
+	}
+
+	// now sort the new edges to their correct position
+	sortMinDown(0, pHandle->m_minEdges[0], dispatcher, false);
+	sortMaxDown(0, pHandle->m_maxEdges[0], dispatcher, false);
+	sortMinDown(1, pHandle->m_minEdges[1], dispatcher, false);
+	sortMaxDown(1, pHandle->m_maxEdges[1], dispatcher, false);
+	sortMinDown(2, pHandle->m_minEdges[2], dispatcher, true);
+	sortMaxDown(2, pHandle->m_maxEdges[2], dispatcher, true);
+
+	return handle;
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::removeHandle(BP_FP_INT_TYPE handle, btDispatcher* dispatcher)
+{
+	Handle* pHandle = getHandle(handle);
+
+	//explicitly remove the pairs containing the proxy
+	//we could do it also in the sortMinUp (passing true)
+	///@todo: compare performance
+	if (!m_pairCache->hasDeferredRemoval())
+	{
+		m_pairCache->removeOverlappingPairsContainingProxy(pHandle, dispatcher);
+	}
+
+	// compute current limit of edge arrays
+	int limit = static_cast<int>(m_numHandles * 2);
+
+	int axis;
+
+	for (axis = 0; axis < 3; axis++)
+	{
+		m_pHandles[0].m_maxEdges[axis] -= 2;
+	}
+
+	// remove the edges by sorting them up to the end of the list
+	for (axis = 0; axis < 3; axis++)
+	{
+		Edge* pEdges = m_pEdges[axis];
+		BP_FP_INT_TYPE max = pHandle->m_maxEdges[axis];
+		pEdges[max].m_pos = m_handleSentinel;
+
+		sortMaxUp(axis, max, dispatcher, false);
+
+		BP_FP_INT_TYPE i = pHandle->m_minEdges[axis];
+		pEdges[i].m_pos = m_handleSentinel;
+
+		sortMinUp(axis, i, dispatcher, false);
+
+		pEdges[limit - 1].m_handle = 0;
+		pEdges[limit - 1].m_pos = m_handleSentinel;
+
+#ifdef DEBUG_BROADPHASE
+		debugPrintAxis(axis, false);
+#endif  //DEBUG_BROADPHASE
+	}
+
+	// free the handle
+	freeHandle(handle);
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool(btDispatcher* /*dispatcher*/)
+{
+	if (m_numHandles == 0)
+	{
+		m_firstFreeHandle = 1;
+		{
+			for (BP_FP_INT_TYPE i = m_firstFreeHandle; i < m_maxHandles; i++)
+				m_pHandles[i].SetNextFree(static_cast<BP_FP_INT_TYPE>(i + 1));
+			m_pHandles[m_maxHandles - 1].SetNextFree(0);
+		}
+	}
+}
+
+//#include <stdio.h>
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::calculateOverlappingPairs(btDispatcher* dispatcher)
+{
+	if (m_pairCache->hasDeferredRemoval())
+	{
+		btBroadphasePairArray& overlappingPairArray = m_pairCache->getOverlappingPairArray();
+
+		//perform a sort, to find duplicates and to sort 'invalid' pairs to the end
+		overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
+
+		overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
+		m_invalidPair = 0;
+
+		int i;
+
+		btBroadphasePair previousPair;
+		previousPair.m_pProxy0 = 0;
+		previousPair.m_pProxy1 = 0;
+		previousPair.m_algorithm = 0;
+
+		for (i = 0; i < overlappingPairArray.size(); i++)
+		{
+			btBroadphasePair& pair = overlappingPairArray[i];
+
+			bool isDuplicate = (pair == previousPair);
+
+			previousPair = pair;
+
+			bool needsRemoval = false;
+
+			if (!isDuplicate)
+			{
+				///important to use an AABB test that is consistent with the broadphase
+				bool hasOverlap = testAabbOverlap(pair.m_pProxy0, pair.m_pProxy1);
+
+				if (hasOverlap)
+				{
+					needsRemoval = false;  //callback->processOverlap(pair);
+				}
+				else
+				{
+					needsRemoval = true;
+				}
+			}
+			else
+			{
+				//remove duplicate
+				needsRemoval = true;
+				//should have no algorithm
+				btAssert(!pair.m_algorithm);
+			}
+
+			if (needsRemoval)
+			{
+				m_pairCache->cleanOverlappingPair(pair, dispatcher);
+
+				//		m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
+				//		m_overlappingPairArray.pop_back();
+				pair.m_pProxy0 = 0;
+				pair.m_pProxy1 = 0;
+				m_invalidPair++;
+			}
+		}
+
+///if you don't like to skip the invalid pairs in the array, execute following code:
+#define CLEAN_INVALID_PAIRS 1
+#ifdef CLEAN_INVALID_PAIRS
+
+		//perform a sort, to sort 'invalid' pairs to the end
+		overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
+
+		overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
+		m_invalidPair = 0;
+#endif  //CLEAN_INVALID_PAIRS
+
+		//printf("overlappingPairArray.size()=%d\n",overlappingPairArray.size());
+	}
+}
+
+template <typename BP_FP_INT_TYPE>
+bool btAxisSweep3Internal<BP_FP_INT_TYPE>::testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
+{
+	const Handle* pHandleA = static_cast<Handle*>(proxy0);
+	const Handle* pHandleB = static_cast<Handle*>(proxy1);
+
+	//optimization 1: check the array index (memory address), instead of the m_pos
+
+	for (int axis = 0; axis < 3; axis++)
+	{
+		if (pHandleA->m_maxEdges[axis] < pHandleB->m_minEdges[axis] ||
+			pHandleB->m_maxEdges[axis] < pHandleA->m_minEdges[axis])
+		{
+			return false;
+		}
+	}
+	return true;
+}
+
+template <typename BP_FP_INT_TYPE>
+bool btAxisSweep3Internal<BP_FP_INT_TYPE>::testOverlap2D(const Handle* pHandleA, const Handle* pHandleB, int axis0, int axis1)
+{
+	//optimization 1: check the array index (memory address), instead of the m_pos
+
+	if (pHandleA->m_maxEdges[axis0] < pHandleB->m_minEdges[axis0] ||
+		pHandleB->m_maxEdges[axis0] < pHandleA->m_minEdges[axis0] ||
+		pHandleA->m_maxEdges[axis1] < pHandleB->m_minEdges[axis1] ||
+		pHandleB->m_maxEdges[axis1] < pHandleA->m_minEdges[axis1])
+	{
+		return false;
+	}
+	return true;
+}
+
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::updateHandle(BP_FP_INT_TYPE handle, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher)
+{
+	//	btAssert(bounds.IsFinite());
+	//btAssert(bounds.HasVolume());
+
+	Handle* pHandle = getHandle(handle);
+
+	// quantize the new bounds
+	BP_FP_INT_TYPE min[3], max[3];
+	quantize(min, aabbMin, 0);
+	quantize(max, aabbMax, 1);
+
+	// update changed edges
+	for (int axis = 0; axis < 3; axis++)
+	{
+		BP_FP_INT_TYPE emin = pHandle->m_minEdges[axis];
+		BP_FP_INT_TYPE emax = pHandle->m_maxEdges[axis];
+
+		int dmin = (int)min[axis] - (int)m_pEdges[axis][emin].m_pos;
+		int dmax = (int)max[axis] - (int)m_pEdges[axis][emax].m_pos;
+
+		m_pEdges[axis][emin].m_pos = min[axis];
+		m_pEdges[axis][emax].m_pos = max[axis];
+
+		// expand (only adds overlaps)
+		if (dmin < 0)
+			sortMinDown(axis, emin, dispatcher, true);
+
+		if (dmax > 0)
+			sortMaxUp(axis, emax, dispatcher, true);
+
+		// shrink (only removes overlaps)
+		if (dmin > 0)
+			sortMinUp(axis, emin, dispatcher, true);
+
+		if (dmax < 0)
+			sortMaxDown(axis, emax, dispatcher, true);
+
+#ifdef DEBUG_BROADPHASE
+		debugPrintAxis(axis);
+#endif  //DEBUG_BROADPHASE
+	}
+}
+
+// sorting a min edge downwards can only ever *add* overlaps
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMinDown(int axis, BP_FP_INT_TYPE edge, btDispatcher* /* dispatcher */, bool updateOverlaps)
+{
+	Edge* pEdge = m_pEdges[axis] + edge;
+	Edge* pPrev = pEdge - 1;
+	Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+	while (pEdge->m_pos < pPrev->m_pos)
+	{
+		Handle* pHandlePrev = getHandle(pPrev->m_handle);
+
+		if (pPrev->IsMax())
+		{
+			// if previous edge is a maximum check the bounds and add an overlap if necessary
+			const int axis1 = (1 << axis) & 3;
+			const int axis2 = (1 << axis1) & 3;
+			if (updateOverlaps && testOverlap2D(pHandleEdge, pHandlePrev, axis1, axis2))
+			{
+				m_pairCache->addOverlappingPair(pHandleEdge, pHandlePrev);
+				if (m_userPairCallback)
+					m_userPairCallback->addOverlappingPair(pHandleEdge, pHandlePrev);
+
+				//AddOverlap(pEdge->m_handle, pPrev->m_handle);
+			}
+
+			// update edge reference in other handle
+			pHandlePrev->m_maxEdges[axis]++;
+		}
+		else
+			pHandlePrev->m_minEdges[axis]++;
+
+		pHandleEdge->m_minEdges[axis]--;
+
+		// swap the edges
+		Edge swap = *pEdge;
+		*pEdge = *pPrev;
+		*pPrev = swap;
+
+		// decrement
+		pEdge--;
+		pPrev--;
+	}
+
+#ifdef DEBUG_BROADPHASE
+	debugPrintAxis(axis);
+#endif  //DEBUG_BROADPHASE
+}
+
+// sorting a min edge upwards can only ever *remove* overlaps
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMinUp(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps)
+{
+	Edge* pEdge = m_pEdges[axis] + edge;
+	Edge* pNext = pEdge + 1;
+	Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+	while (pNext->m_handle && (pEdge->m_pos >= pNext->m_pos))
+	{
+		Handle* pHandleNext = getHandle(pNext->m_handle);
+
+		if (pNext->IsMax())
+		{
+			Handle* handle0 = getHandle(pEdge->m_handle);
+			Handle* handle1 = getHandle(pNext->m_handle);
+			const int axis1 = (1 << axis) & 3;
+			const int axis2 = (1 << axis1) & 3;
+
+			// if next edge is maximum remove any overlap between the two handles
+			if (updateOverlaps
+#ifdef USE_OVERLAP_TEST_ON_REMOVES
+				&& testOverlap2D(handle0, handle1, axis1, axis2)
+#endif  //USE_OVERLAP_TEST_ON_REMOVES
+			)
+			{
+				m_pairCache->removeOverlappingPair(handle0, handle1, dispatcher);
+				if (m_userPairCallback)
+					m_userPairCallback->removeOverlappingPair(handle0, handle1, dispatcher);
+			}
+
+			// update edge reference in other handle
+			pHandleNext->m_maxEdges[axis]--;
+		}
+		else
+			pHandleNext->m_minEdges[axis]--;
+
+		pHandleEdge->m_minEdges[axis]++;
+
+		// swap the edges
+		Edge swap = *pEdge;
+		*pEdge = *pNext;
+		*pNext = swap;
+
+		// increment
+		pEdge++;
+		pNext++;
+	}
+}
+
+// sorting a max edge downwards can only ever *remove* overlaps
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMaxDown(int axis, BP_FP_INT_TYPE edge, btDispatcher* dispatcher, bool updateOverlaps)
+{
+	Edge* pEdge = m_pEdges[axis] + edge;
+	Edge* pPrev = pEdge - 1;
+	Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+	while (pEdge->m_pos < pPrev->m_pos)
+	{
+		Handle* pHandlePrev = getHandle(pPrev->m_handle);
+
+		if (!pPrev->IsMax())
+		{
+			// if previous edge was a minimum remove any overlap between the two handles
+			Handle* handle0 = getHandle(pEdge->m_handle);
+			Handle* handle1 = getHandle(pPrev->m_handle);
+			const int axis1 = (1 << axis) & 3;
+			const int axis2 = (1 << axis1) & 3;
+
+			if (updateOverlaps
+#ifdef USE_OVERLAP_TEST_ON_REMOVES
+				&& testOverlap2D(handle0, handle1, axis1, axis2)
+#endif  //USE_OVERLAP_TEST_ON_REMOVES
+			)
+			{
+				//this is done during the overlappingpairarray iteration/narrowphase collision
+
+				m_pairCache->removeOverlappingPair(handle0, handle1, dispatcher);
+				if (m_userPairCallback)
+					m_userPairCallback->removeOverlappingPair(handle0, handle1, dispatcher);
+			}
+
+			// update edge reference in other handle
+			pHandlePrev->m_minEdges[axis]++;
+			;
+		}
+		else
+			pHandlePrev->m_maxEdges[axis]++;
+
+		pHandleEdge->m_maxEdges[axis]--;
+
+		// swap the edges
+		Edge swap = *pEdge;
+		*pEdge = *pPrev;
+		*pPrev = swap;
+
+		// decrement
+		pEdge--;
+		pPrev--;
+	}
+
+#ifdef DEBUG_BROADPHASE
+	debugPrintAxis(axis);
+#endif  //DEBUG_BROADPHASE
+}
+
+// sorting a max edge upwards can only ever *add* overlaps
+template <typename BP_FP_INT_TYPE>
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::sortMaxUp(int axis, BP_FP_INT_TYPE edge, btDispatcher* /* dispatcher */, bool updateOverlaps)
+{
+	Edge* pEdge = m_pEdges[axis] + edge;
+	Edge* pNext = pEdge + 1;
+	Handle* pHandleEdge = getHandle(pEdge->m_handle);
+
+	while (pNext->m_handle && (pEdge->m_pos >= pNext->m_pos))
+	{
+		Handle* pHandleNext = getHandle(pNext->m_handle);
+
+		const int axis1 = (1 << axis) & 3;
+		const int axis2 = (1 << axis1) & 3;
+
+		if (!pNext->IsMax())
+		{
+			// if next edge is a minimum check the bounds and add an overlap if necessary
+			if (updateOverlaps && testOverlap2D(pHandleEdge, pHandleNext, axis1, axis2))
+			{
+				Handle* handle0 = getHandle(pEdge->m_handle);
+				Handle* handle1 = getHandle(pNext->m_handle);
+				m_pairCache->addOverlappingPair(handle0, handle1);
+				if (m_userPairCallback)
+					m_userPairCallback->addOverlappingPair(handle0, handle1);
+			}
+
+			// update edge reference in other handle
+			pHandleNext->m_minEdges[axis]--;
+		}
+		else
+			pHandleNext->m_maxEdges[axis]--;
+
+		pHandleEdge->m_maxEdges[axis]++;
+
+		// swap the edges
+		Edge swap = *pEdge;
+		*pEdge = *pNext;
+		*pNext = swap;
+
+		// increment
+		pEdge++;
+		pNext++;
+	}
+}
+
+#endif

+ 24 - 27
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h

@@ -13,10 +13,8 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-#ifndef		BT_BROADPHASE_INTERFACE_H
-#define 	BT_BROADPHASE_INTERFACE_H
-
-
+#ifndef BT_BROADPHASE_INTERFACE_H
+#define BT_BROADPHASE_INTERFACE_H
 
 
 struct btDispatcherInfo;
 struct btDispatcherInfo;
 class btDispatcher;
 class btDispatcher;
@@ -24,23 +22,23 @@ class btDispatcher;
 
 
 class btOverlappingPairCache;
 class btOverlappingPairCache;
 
 
-
-
-struct	btBroadphaseAabbCallback
+struct btBroadphaseAabbCallback
 {
 {
 	virtual ~btBroadphaseAabbCallback() {}
 	virtual ~btBroadphaseAabbCallback() {}
-	virtual bool	process(const btBroadphaseProxy* proxy) = 0;
+	virtual bool process(const btBroadphaseProxy* proxy) = 0;
 };
 };
 
 
-
-struct	btBroadphaseRayCallback : public btBroadphaseAabbCallback
+struct btBroadphaseRayCallback : public btBroadphaseAabbCallback
 {
 {
 	///added some cached data to accelerate ray-AABB tests
 	///added some cached data to accelerate ray-AABB tests
-	btVector3		m_rayDirectionInverse;
-	unsigned int	m_signs[3];
-	btScalar		m_lambda_max;
+	btVector3 m_rayDirectionInverse;
+	unsigned int m_signs[3];
+	btScalar m_lambda_max;
 
 
 	virtual ~btBroadphaseRayCallback() {}
 	virtual ~btBroadphaseRayCallback() {}
+
+protected:
+	btBroadphaseRayCallback() {}
 };
 };
 
 
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
@@ -53,30 +51,29 @@ class btBroadphaseInterface
 public:
 public:
 	virtual ~btBroadphaseInterface() {}
 	virtual ~btBroadphaseInterface() {}
 
 
-	virtual btBroadphaseProxy*	createProxy(  const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr,  int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher) =0;
-	virtual void	destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher)=0;
-	virtual void	setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher)=0;
-	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const =0;
+	virtual btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher) = 0;
+	virtual void destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher) = 0;
+	virtual void setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher) = 0;
+	virtual void getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const = 0;
 
 
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0;
+	virtual void rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin = btVector3(0, 0, 0), const btVector3& aabbMax = btVector3(0, 0, 0)) = 0;
 
 
-	virtual void	aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) = 0;
+	virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) = 0;
 
 
 	///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
 	///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb
-	virtual void	calculateOverlappingPairs(btDispatcher* dispatcher)=0;
+	virtual void calculateOverlappingPairs(btDispatcher* dispatcher) = 0;
 
 
-	virtual	btOverlappingPairCache*	getOverlappingPairCache()=0;
-	virtual	const btOverlappingPairCache*	getOverlappingPairCache() const =0;
+	virtual btOverlappingPairCache* getOverlappingPairCache() = 0;
+	virtual const btOverlappingPairCache* getOverlappingPairCache() const = 0;
 
 
 	///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
 	///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
 	///will add some transform later
 	///will add some transform later
-	virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const =0;
+	virtual void getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const = 0;
 
 
 	///reset broadphase internal structures, to ensure determinism/reproducability
 	///reset broadphase internal structures, to ensure determinism/reproducability
-	virtual void resetPool(btDispatcher* dispatcher) { (void) dispatcher; };
-
-	virtual void	printStats() = 0;
+	virtual void resetPool(btDispatcher* dispatcher) { (void)dispatcher; };
 
 
+	virtual void printStats() = 0;
 };
 };
 
 
-#endif //BT_BROADPHASE_INTERFACE_H
+#endif  //BT_BROADPHASE_INTERFACE_H

+ 1 - 0
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.cpp

@@ -15,3 +15,4 @@ subject to the following restrictions:
 
 
 #include "btBroadphaseProxy.h"
 #include "btBroadphaseProxy.h"
 
 
+BT_NOT_EMPTY_FILE  // fix warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library

+ 85 - 106
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h

@@ -16,11 +16,10 @@ subject to the following restrictions:
 #ifndef BT_BROADPHASE_PROXY_H
 #ifndef BT_BROADPHASE_PROXY_H
 #define BT_BROADPHASE_PROXY_H
 #define BT_BROADPHASE_PROXY_H
 
 
-#include "LinearMath/btScalar.h" //for SIMD_FORCE_INLINE
+#include "LinearMath/btScalar.h"  //for SIMD_FORCE_INLINE
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
 
 
-
 /// btDispatcher uses these types
 /// btDispatcher uses these types
 /// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
 /// IMPORTANT NOTE:The types are ordered polyhedral, implicit convex and concave
 /// to facilitate type checking
 /// to facilitate type checking
@@ -35,8 +34,8 @@ enum BroadphaseNativeTypes
 	CONVEX_HULL_SHAPE_PROXYTYPE,
 	CONVEX_HULL_SHAPE_PROXYTYPE,
 	CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE,
 	CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE,
 	CUSTOM_POLYHEDRAL_SHAPE_TYPE,
 	CUSTOM_POLYHEDRAL_SHAPE_TYPE,
-//implicit convex shapes
-IMPLICIT_CONVEX_SHAPES_START_HERE,
+	//implicit convex shapes
+	IMPLICIT_CONVEX_SHAPES_START_HERE,
 	SPHERE_SHAPE_PROXYTYPE,
 	SPHERE_SHAPE_PROXYTYPE,
 	MULTI_SPHERE_SHAPE_PROXYTYPE,
 	MULTI_SPHERE_SHAPE_PROXYTYPE,
 	CAPSULE_SHAPE_PROXYTYPE,
 	CAPSULE_SHAPE_PROXYTYPE,
@@ -49,8 +48,8 @@ IMPLICIT_CONVEX_SHAPES_START_HERE,
 	BOX_2D_SHAPE_PROXYTYPE,
 	BOX_2D_SHAPE_PROXYTYPE,
 	CONVEX_2D_SHAPE_PROXYTYPE,
 	CONVEX_2D_SHAPE_PROXYTYPE,
 	CUSTOM_CONVEX_SHAPE_TYPE,
 	CUSTOM_CONVEX_SHAPE_TYPE,
-//concave shapes
-CONCAVE_SHAPES_START_HERE,
+	//concave shapes
+	CONCAVE_SHAPES_START_HERE,
 	//keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
 	//keep all the convex shapetype below here, for the check IsConvexShape in broadphase proxy!
 	TRIANGLE_MESH_SHAPE_PROXYTYPE,
 	TRIANGLE_MESH_SHAPE_PROXYTYPE,
 	SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
 	SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE,
@@ -58,15 +57,16 @@ CONCAVE_SHAPES_START_HERE,
 	FAST_CONCAVE_MESH_PROXYTYPE,
 	FAST_CONCAVE_MESH_PROXYTYPE,
 	//terrain
 	//terrain
 	TERRAIN_SHAPE_PROXYTYPE,
 	TERRAIN_SHAPE_PROXYTYPE,
-///Used for GIMPACT Trimesh integration
+	///Used for GIMPACT Trimesh integration
 	GIMPACT_SHAPE_PROXYTYPE,
 	GIMPACT_SHAPE_PROXYTYPE,
-///Multimaterial mesh
-    MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
-	
+	///Multimaterial mesh
+	MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE,
+
 	EMPTY_SHAPE_PROXYTYPE,
 	EMPTY_SHAPE_PROXYTYPE,
 	STATIC_PLANE_PROXYTYPE,
 	STATIC_PLANE_PROXYTYPE,
 	CUSTOM_CONCAVE_SHAPE_TYPE,
 	CUSTOM_CONCAVE_SHAPE_TYPE,
-CONCAVE_SHAPES_END_HERE,
+	SDF_SHAPE_PROXYTYPE = CUSTOM_CONCAVE_SHAPE_TYPE,
+	CONCAVE_SHAPES_END_HERE,
 
 
 	COMPOUND_SHAPE_PROXYTYPE,
 	COMPOUND_SHAPE_PROXYTYPE,
 
 
@@ -76,38 +76,37 @@ CONCAVE_SHAPES_END_HERE,
 	INVALID_SHAPE_PROXYTYPE,
 	INVALID_SHAPE_PROXYTYPE,
 
 
 	MAX_BROADPHASE_COLLISION_TYPES
 	MAX_BROADPHASE_COLLISION_TYPES
-	
-};
 
 
+};
 
 
-///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases. 
+///The btBroadphaseProxy is the main class that can be used with the Bullet broadphases.
 ///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody.
 ///It stores collision shape type information, collision filter information and a client object, typically a btCollisionObject or btRigidBody.
-ATTRIBUTE_ALIGNED16(struct) btBroadphaseProxy
+ATTRIBUTE_ALIGNED16(struct)
+btBroadphaseProxy
 {
 {
+	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
-BT_DECLARE_ALIGNED_ALLOCATOR();
-	
 	///optional filtering to cull potential collisions
 	///optional filtering to cull potential collisions
 	enum CollisionFilterGroups
 	enum CollisionFilterGroups
 	{
 	{
-	        DefaultFilter = 1,
-	        StaticFilter = 2,
-	        KinematicFilter = 4,
-	        DebrisFilter = 8,
-			SensorTrigger = 16,
-			CharacterFilter = 32,
-	        AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
+		DefaultFilter = 1,
+		StaticFilter = 2,
+		KinematicFilter = 4,
+		DebrisFilter = 8,
+		SensorTrigger = 16,
+		CharacterFilter = 32,
+		AllFilter = -1  //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger
 	};
 	};
 
 
 	//Usually the client btCollisionObject or Rigidbody class
 	//Usually the client btCollisionObject or Rigidbody class
-	void*	m_clientObject;
-	int		m_collisionFilterGroup;
-	int		m_collisionFilterMask;
+	void* m_clientObject;
+	int m_collisionFilterGroup;
+	int m_collisionFilterMask;
 
 
-	int		m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
+	int m_uniqueId;  //m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
 
 
-	btVector3	m_aabbMin;
-	btVector3	m_aabbMax;
+	btVector3 m_aabbMin;
+	btVector3 m_aabbMax;
 
 
 	SIMD_FORCE_INLINE int getUid() const
 	SIMD_FORCE_INLINE int getUid() const
 	{
 	{
@@ -115,47 +114,45 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
 	}
 	}
 
 
 	//used for memory pools
 	//used for memory pools
-	btBroadphaseProxy() :m_clientObject(0)
+	btBroadphaseProxy() : m_clientObject(0)
 	{
 	{
 	}
 	}
 
 
-	btBroadphaseProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr, int collisionFilterGroup,  int collisionFilterMask)
-		:m_clientObject(userPtr),
-		m_collisionFilterGroup(collisionFilterGroup),
-		m_collisionFilterMask(collisionFilterMask),
-		m_aabbMin(aabbMin),
-		m_aabbMax(aabbMax)
+	btBroadphaseProxy(const btVector3& aabbMin, const btVector3& aabbMax, void* userPtr, int collisionFilterGroup, int collisionFilterMask)
+		: m_clientObject(userPtr),
+		  m_collisionFilterGroup(collisionFilterGroup),
+		  m_collisionFilterMask(collisionFilterMask),
+		  m_aabbMin(aabbMin),
+		  m_aabbMax(aabbMax)
 	{
 	{
 	}
 	}
 
 
-	
-
 	static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
 	static SIMD_FORCE_INLINE bool isPolyhedral(int proxyType)
 	{
 	{
-		return (proxyType  < IMPLICIT_CONVEX_SHAPES_START_HERE);
+		return (proxyType < IMPLICIT_CONVEX_SHAPES_START_HERE);
 	}
 	}
 
 
-	static SIMD_FORCE_INLINE bool	isConvex(int proxyType)
+	static SIMD_FORCE_INLINE bool isConvex(int proxyType)
 	{
 	{
 		return (proxyType < CONCAVE_SHAPES_START_HERE);
 		return (proxyType < CONCAVE_SHAPES_START_HERE);
 	}
 	}
 
 
-	static SIMD_FORCE_INLINE bool	isNonMoving(int proxyType)
+	static SIMD_FORCE_INLINE bool isNonMoving(int proxyType)
 	{
 	{
-		return (isConcave(proxyType) && !(proxyType==GIMPACT_SHAPE_PROXYTYPE));
+		return (isConcave(proxyType) && !(proxyType == GIMPACT_SHAPE_PROXYTYPE));
 	}
 	}
 
 
-	static SIMD_FORCE_INLINE bool	isConcave(int proxyType)
+	static SIMD_FORCE_INLINE bool isConcave(int proxyType)
 	{
 	{
 		return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
 		return ((proxyType > CONCAVE_SHAPES_START_HERE) &&
-			(proxyType < CONCAVE_SHAPES_END_HERE));
+				(proxyType < CONCAVE_SHAPES_END_HERE));
 	}
 	}
-	static SIMD_FORCE_INLINE bool	isCompound(int proxyType)
+	static SIMD_FORCE_INLINE bool isCompound(int proxyType)
 	{
 	{
 		return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
 		return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
 	}
 	}
 
 
-	static SIMD_FORCE_INLINE bool	isSoftBody(int proxyType)
+	static SIMD_FORCE_INLINE bool isSoftBody(int proxyType)
 	{
 	{
 		return (proxyType == SOFTBODY_SHAPE_PROXYTYPE);
 		return (proxyType == SOFTBODY_SHAPE_PROXYTYPE);
 	}
 	}
@@ -167,67 +164,55 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	static SIMD_FORCE_INLINE bool isConvex2d(int proxyType)
 	static SIMD_FORCE_INLINE bool isConvex2d(int proxyType)
 	{
 	{
-		return (proxyType == BOX_2D_SHAPE_PROXYTYPE) ||	(proxyType == CONVEX_2D_SHAPE_PROXYTYPE);
+		return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE);
 	}
 	}
-
-	
-}
-;
+};
 
 
 class btCollisionAlgorithm;
 class btCollisionAlgorithm;
 
 
 struct btBroadphaseProxy;
 struct btBroadphaseProxy;
 
 
-
-
 ///The btBroadphasePair class contains a pair of aabb-overlapping objects.
 ///The btBroadphasePair class contains a pair of aabb-overlapping objects.
 ///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes.
 ///A btDispatcher can search a btCollisionAlgorithm that performs exact/narrowphase collision detection on the actual collision shapes.
-ATTRIBUTE_ALIGNED16(struct) btBroadphasePair
+ATTRIBUTE_ALIGNED16(struct)
+btBroadphasePair
 {
 {
-	btBroadphasePair ()
-		:
-	m_pProxy0(0),
-		m_pProxy1(0),
-		m_algorithm(0),
-		m_internalInfo1(0)
+	btBroadphasePair()
+		: m_pProxy0(0),
+		  m_pProxy1(0),
+		  m_algorithm(0),
+		  m_internalInfo1(0)
 	{
 	{
 	}
 	}
 
 
-BT_DECLARE_ALIGNED_ALLOCATOR();
+	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
-	btBroadphasePair(const btBroadphasePair& other)
-		:		m_pProxy0(other.m_pProxy0),
-				m_pProxy1(other.m_pProxy1),
-				m_algorithm(other.m_algorithm),
-				m_internalInfo1(other.m_internalInfo1)
-	{
-	}
-	btBroadphasePair(btBroadphaseProxy& proxy0,btBroadphaseProxy& proxy1)
+	btBroadphasePair(btBroadphaseProxy & proxy0, btBroadphaseProxy & proxy1)
 	{
 	{
-
 		//keep them sorted, so the std::set operations work
 		//keep them sorted, so the std::set operations work
 		if (proxy0.m_uniqueId < proxy1.m_uniqueId)
 		if (proxy0.m_uniqueId < proxy1.m_uniqueId)
-        { 
-            m_pProxy0 = &proxy0; 
-            m_pProxy1 = &proxy1; 
-        }
-        else 
-        { 
-			m_pProxy0 = &proxy1; 
-            m_pProxy1 = &proxy0; 
-        }
+		{
+			m_pProxy0 = &proxy0;
+			m_pProxy1 = &proxy1;
+		}
+		else
+		{
+			m_pProxy0 = &proxy1;
+			m_pProxy1 = &proxy0;
+		}
 
 
 		m_algorithm = 0;
 		m_algorithm = 0;
 		m_internalInfo1 = 0;
 		m_internalInfo1 = 0;
-
 	}
 	}
-	
+
 	btBroadphaseProxy* m_pProxy0;
 	btBroadphaseProxy* m_pProxy0;
 	btBroadphaseProxy* m_pProxy1;
 	btBroadphaseProxy* m_pProxy1;
-	
-	mutable btCollisionAlgorithm* m_algorithm;
-	union { void* m_internalInfo1; int m_internalTmpValue;};//don't use this data, it will be removed in future version.
 
 
+	mutable btCollisionAlgorithm* m_algorithm;
+	union {
+		void* m_internalInfo1;
+		int m_internalTmpValue;
+	};  //don't use this data, it will be removed in future version.
 };
 };
 
 
 /*
 /*
@@ -239,31 +224,25 @@ SIMD_FORCE_INLINE bool operator<(const btBroadphasePair& a, const btBroadphasePa
 }
 }
 */
 */
 
 
-
-
 class btBroadphasePairSortPredicate
 class btBroadphasePairSortPredicate
 {
 {
-	public:
-
-		bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) const
-		{
-			const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
-			const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
-			const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1;
-			const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1;
-
-			 return uidA0 > uidB0 || 
-				(a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) ||
-				(a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm); 
-		}
+public:
+	bool operator()(const btBroadphasePair& a, const btBroadphasePair& b) const
+	{
+		const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
+		const int uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
+		const int uidA1 = a.m_pProxy1 ? a.m_pProxy1->m_uniqueId : -1;
+		const int uidB1 = b.m_pProxy1 ? b.m_pProxy1->m_uniqueId : -1;
+
+		return uidA0 > uidB0 ||
+			   (a.m_pProxy0 == b.m_pProxy0 && uidA1 > uidB1) ||
+			   (a.m_pProxy0 == b.m_pProxy0 && a.m_pProxy1 == b.m_pProxy1 && a.m_algorithm > b.m_algorithm);
+	}
 };
 };
 
 
-
-SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b) 
+SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphasePair& b)
 {
 {
-	 return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
+	return (a.m_pProxy0 == b.m_pProxy0) && (a.m_pProxy1 == b.m_pProxy1);
 }
 }
 
 
-
-#endif //BT_BROADPHASE_PROXY_H
-
+#endif  //BT_BROADPHASE_PROXY_H

+ 0 - 1
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.cpp

@@ -20,4 +20,3 @@ btCollisionAlgorithm::btCollisionAlgorithm(const btCollisionAlgorithmConstructio
 {
 {
 	m_dispatcher = ci.m_dispatcher1;
 	m_dispatcher = ci.m_dispatcher1;
 }
 }
-

+ 18 - 24
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h

@@ -25,57 +25,51 @@ class btManifoldResult;
 class btCollisionObject;
 class btCollisionObject;
 struct btCollisionObjectWrapper;
 struct btCollisionObjectWrapper;
 struct btDispatcherInfo;
 struct btDispatcherInfo;
-class	btPersistentManifold;
+class btPersistentManifold;
 
 
-typedef btAlignedObjectArray<btPersistentManifold*>	btManifoldArray;
+typedef btAlignedObjectArray<btPersistentManifold*> btManifoldArray;
 
 
 struct btCollisionAlgorithmConstructionInfo
 struct btCollisionAlgorithmConstructionInfo
 {
 {
 	btCollisionAlgorithmConstructionInfo()
 	btCollisionAlgorithmConstructionInfo()
-		:m_dispatcher1(0),
-		m_manifold(0)
+		: m_dispatcher1(0),
+		  m_manifold(0)
 	{
 	{
 	}
 	}
-	btCollisionAlgorithmConstructionInfo(btDispatcher* dispatcher,int temp)
-		:m_dispatcher1(dispatcher)
+	btCollisionAlgorithmConstructionInfo(btDispatcher* dispatcher, int temp)
+		: m_dispatcher1(dispatcher)
 	{
 	{
 		(void)temp;
 		(void)temp;
 	}
 	}
 
 
-	btDispatcher*	m_dispatcher1;
-	btPersistentManifold*	m_manifold;
-
-//	int	getDispatcherId();
+	btDispatcher* m_dispatcher1;
+	btPersistentManifold* m_manifold;
 
 
+	//	int	getDispatcherId();
 };
 };
 
 
-
 ///btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatcher.
 ///btCollisionAlgorithm is an collision interface that is compatible with the Broadphase and btDispatcher.
 ///It is persistent over frames
 ///It is persistent over frames
 class btCollisionAlgorithm
 class btCollisionAlgorithm
 {
 {
-
 protected:
 protected:
-
-	btDispatcher*	m_dispatcher;
+	btDispatcher* m_dispatcher;
 
 
 protected:
 protected:
-//	int	getDispatcherId();
-	
-public:
+	//	int	getDispatcherId();
 
 
-	btCollisionAlgorithm() {};
+public:
+	btCollisionAlgorithm(){};
 
 
 	btCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 	btCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 
 
-	virtual ~btCollisionAlgorithm() {};
+	virtual ~btCollisionAlgorithm(){};
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut) = 0;
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut) = 0;
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut) = 0;
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray) = 0;
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray) = 0;
 };
 };
 
 
-
-#endif //BT_COLLISION_ALGORITHM_H
+#endif  //BT_COLLISION_ALGORITHM_H

File diff suppressed because it is too large
+ 393 - 338
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvt.cpp


File diff suppressed because it is too large
+ 424 - 346
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvt.h


+ 438 - 430
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp

@@ -17,33 +17,32 @@ subject to the following restrictions:
 
 
 #include "btDbvtBroadphase.h"
 #include "btDbvtBroadphase.h"
 #include "LinearMath/btThreads.h"
 #include "LinearMath/btThreads.h"
-
+btScalar gDbvtMargin = btScalar(0.05);
 //
 //
 // Profiling
 // Profiling
 //
 //
 
 
-#if DBVT_BP_PROFILE||DBVT_BP_ENABLE_BENCHMARK
+#if DBVT_BP_PROFILE || DBVT_BP_ENABLE_BENCHMARK
 #include <stdio.h>
 #include <stdio.h>
 #endif
 #endif
 
 
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
-struct	ProfileScope
+struct ProfileScope
 {
 {
-	__forceinline ProfileScope(btClock& clock,unsigned long& value) :
-	m_clock(&clock),m_value(&value),m_base(clock.getTimeMicroseconds())
+	__forceinline ProfileScope(btClock& clock, unsigned long& value) : m_clock(&clock), m_value(&value), m_base(clock.getTimeMicroseconds())
 	{
 	{
 	}
 	}
 	__forceinline ~ProfileScope()
 	__forceinline ~ProfileScope()
 	{
 	{
-		(*m_value)+=m_clock->getTimeMicroseconds()-m_base;
+		(*m_value) += m_clock->getTimeMicroseconds() - m_base;
 	}
 	}
-	btClock*		m_clock;
-	unsigned long*	m_value;
-	unsigned long	m_base;
+	btClock* m_clock;
+	unsigned long* m_value;
+	unsigned long m_base;
 };
 };
-#define	SPC(_value_)	ProfileScope	spc_scope(m_clock,_value_)
+#define SPC(_value_) ProfileScope spc_scope(m_clock, _value_)
 #else
 #else
-#define	SPC(_value_)
+#define SPC(_value_)
 #endif
 #endif
 
 
 //
 //
@@ -52,66 +51,75 @@ struct	ProfileScope
 
 
 //
 //
 template <typename T>
 template <typename T>
-static inline void	listappend(T* item,T*& list)
+static inline void listappend(T* item, T*& list)
 {
 {
-	item->links[0]=0;
-	item->links[1]=list;
-	if(list) list->links[0]=item;
-	list=item;
+	item->links[0] = 0;
+	item->links[1] = list;
+	if (list) list->links[0] = item;
+	list = item;
 }
 }
 
 
 //
 //
 template <typename T>
 template <typename T>
-static inline void	listremove(T* item,T*& list)
+static inline void listremove(T* item, T*& list)
 {
 {
-	if(item->links[0]) item->links[0]->links[1]=item->links[1]; else list=item->links[1];
-	if(item->links[1]) item->links[1]->links[0]=item->links[0];
+	if (item->links[0])
+		item->links[0]->links[1] = item->links[1];
+	else
+		list = item->links[1];
+	if (item->links[1]) item->links[1]->links[0] = item->links[0];
 }
 }
 
 
 //
 //
 template <typename T>
 template <typename T>
-static inline int	listcount(T* root)
+static inline int listcount(T* root)
 {
 {
-	int	n=0;
-	while(root) { ++n;root=root->links[1]; }
-	return(n);
+	int n = 0;
+	while (root)
+	{
+		++n;
+		root = root->links[1];
+	}
+	return (n);
 }
 }
 
 
 //
 //
 template <typename T>
 template <typename T>
-static inline void	clear(T& value)
+static inline void clear(T& value)
 {
 {
-	static const struct ZeroDummy : T {} zerodummy;
-	value=zerodummy;
+	static const struct ZeroDummy : T
+	{
+	} zerodummy;
+	value = zerodummy;
 }
 }
 
 
 //
 //
 // Colliders
 // Colliders
 //
 //
 
 
-/* Tree collider	*/ 
-struct	btDbvtTreeCollider : btDbvt::ICollide
+/* Tree collider	*/
+struct btDbvtTreeCollider : btDbvt::ICollide
 {
 {
-	btDbvtBroadphase*	pbp;
-	btDbvtProxy*		proxy;
+	btDbvtBroadphase* pbp;
+	btDbvtProxy* proxy;
 	btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
 	btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {}
-	void	Process(const btDbvtNode* na,const btDbvtNode* nb)
+	void Process(const btDbvtNode* na, const btDbvtNode* nb)
 	{
 	{
-		if(na!=nb)
+		if (na != nb)
 		{
 		{
-			btDbvtProxy*	pa=(btDbvtProxy*)na->data;
-			btDbvtProxy*	pb=(btDbvtProxy*)nb->data;
+			btDbvtProxy* pa = (btDbvtProxy*)na->data;
+			btDbvtProxy* pb = (btDbvtProxy*)nb->data;
 #if DBVT_BP_SORTPAIRS
 #if DBVT_BP_SORTPAIRS
-			if(pa->m_uniqueId>pb->m_uniqueId) 
-				btSwap(pa,pb);
+			if (pa->m_uniqueId > pb->m_uniqueId)
+				btSwap(pa, pb);
 #endif
 #endif
-			pbp->m_paircache->addOverlappingPair(pa,pb);
+			pbp->m_paircache->addOverlappingPair(pa, pb);
 			++pbp->m_newpairs;
 			++pbp->m_newpairs;
 		}
 		}
 	}
 	}
-	void	Process(const btDbvtNode* n)
+	void Process(const btDbvtNode* n)
 	{
 	{
-		Process(n,proxy->leaf);
+		Process(n, proxy->leaf);
 	}
 	}
 };
 };
 
 
@@ -122,31 +130,31 @@ struct	btDbvtTreeCollider : btDbvt::ICollide
 //
 //
 btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
 btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
 {
 {
-	m_deferedcollide	=	false;
-	m_needcleanup		=	true;
-	m_releasepaircache	=	(paircache!=0)?false:true;
-	m_prediction		=	0;
-	m_stageCurrent		=	0;
-	m_fixedleft			=	0;
-	m_fupdates			=	1;
-	m_dupdates			=	0;
-	m_cupdates			=	10;
-	m_newpairs			=	1;
-	m_updates_call		=	0;
-	m_updates_done		=	0;
-	m_updates_ratio		=	0;
-	m_paircache			=	paircache? paircache	: new(btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache();
-	m_gid				=	0;
-	m_pid				=	0;
-	m_cid				=	0;
-	for(int i=0;i<=STAGECOUNT;++i)
+	m_deferedcollide = false;
+	m_needcleanup = true;
+	m_releasepaircache = (paircache != 0) ? false : true;
+	m_prediction = 0;
+	m_stageCurrent = 0;
+	m_fixedleft = 0;
+	m_fupdates = 1;
+	m_dupdates = 0;
+	m_cupdates = 10;
+	m_newpairs = 1;
+	m_updates_call = 0;
+	m_updates_done = 0;
+	m_updates_ratio = 0;
+	m_paircache = paircache ? paircache : new (btAlignedAlloc(sizeof(btHashedOverlappingPairCache), 16)) btHashedOverlappingPairCache();
+	m_gid = 0;
+	m_pid = 0;
+	m_cid = 0;
+	for (int i = 0; i <= STAGECOUNT; ++i)
 	{
 	{
-		m_stageRoots[i]=0;
+		m_stageRoots[i] = 0;
 	}
 	}
 #if BT_THREADSAFE
 #if BT_THREADSAFE
-    m_rayTestStacks.resize(BT_MAX_THREAD_COUNT);
+	m_rayTestStacks.resize(BT_MAX_THREAD_COUNT);
 #else
 #else
-    m_rayTestStacks.resize(1);
+	m_rayTestStacks.resize(1);
 #endif
 #endif
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
 	clear(m_profiling);
 	clear(m_profiling);
@@ -156,7 +164,7 @@ btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
 //
 //
 btDbvtBroadphase::~btDbvtBroadphase()
 btDbvtBroadphase::~btDbvtBroadphase()
 {
 {
-	if(m_releasepaircache) 
+	if (m_releasepaircache)
 	{
 	{
 		m_paircache->~btOverlappingPairCache();
 		m_paircache->~btOverlappingPairCache();
 		btAlignedFree(m_paircache);
 		btAlignedFree(m_paircache);
@@ -164,305 +172,294 @@ btDbvtBroadphase::~btDbvtBroadphase()
 }
 }
 
 
 //
 //
-btBroadphaseProxy*				btDbvtBroadphase::createProxy(	const btVector3& aabbMin,
-															  const btVector3& aabbMax,
-															  int /*shapeType*/,
-															  void* userPtr,
-															  int collisionFilterGroup,
-															  int collisionFilterMask,
-															  btDispatcher* /*dispatcher*/)
+btBroadphaseProxy* btDbvtBroadphase::createProxy(const btVector3& aabbMin,
+												 const btVector3& aabbMax,
+												 int /*shapeType*/,
+												 void* userPtr,
+												 int collisionFilterGroup,
+												 int collisionFilterMask,
+												 btDispatcher* /*dispatcher*/)
 {
 {
-	btDbvtProxy*		proxy=new(btAlignedAlloc(sizeof(btDbvtProxy),16)) btDbvtProxy(	aabbMin,aabbMax,userPtr,
-		collisionFilterGroup,
-		collisionFilterMask);
+	btDbvtProxy* proxy = new (btAlignedAlloc(sizeof(btDbvtProxy), 16)) btDbvtProxy(aabbMin, aabbMax, userPtr,
+																				   collisionFilterGroup,
+																				   collisionFilterMask);
 
 
-	btDbvtAabbMm aabb = btDbvtVolume::FromMM(aabbMin,aabbMax);
+	btDbvtAabbMm aabb = btDbvtVolume::FromMM(aabbMin, aabbMax);
 
 
 	//bproxy->aabb			=	btDbvtVolume::FromMM(aabbMin,aabbMax);
 	//bproxy->aabb			=	btDbvtVolume::FromMM(aabbMin,aabbMax);
-	proxy->stage		=	m_stageCurrent;
-	proxy->m_uniqueId	=	++m_gid;
-	proxy->leaf			=	m_sets[0].insert(aabb,proxy);
-	listappend(proxy,m_stageRoots[m_stageCurrent]);
-	if(!m_deferedcollide)
+	proxy->stage = m_stageCurrent;
+	proxy->m_uniqueId = ++m_gid;
+	proxy->leaf = m_sets[0].insert(aabb, proxy);
+	listappend(proxy, m_stageRoots[m_stageCurrent]);
+	if (!m_deferedcollide)
 	{
 	{
-		btDbvtTreeCollider	collider(this);
-		collider.proxy=proxy;
-		m_sets[0].collideTV(m_sets[0].m_root,aabb,collider);
-		m_sets[1].collideTV(m_sets[1].m_root,aabb,collider);
+		btDbvtTreeCollider collider(this);
+		collider.proxy = proxy;
+		m_sets[0].collideTV(m_sets[0].m_root, aabb, collider);
+		m_sets[1].collideTV(m_sets[1].m_root, aabb, collider);
 	}
 	}
-	return(proxy);
+	return (proxy);
 }
 }
 
 
 //
 //
-void							btDbvtBroadphase::destroyProxy(	btBroadphaseProxy* absproxy,
-															   btDispatcher* dispatcher)
+void btDbvtBroadphase::destroyProxy(btBroadphaseProxy* absproxy,
+									btDispatcher* dispatcher)
 {
 {
-	btDbvtProxy*	proxy=(btDbvtProxy*)absproxy;
-	if(proxy->stage==STAGECOUNT)
+	btDbvtProxy* proxy = (btDbvtProxy*)absproxy;
+	if (proxy->stage == STAGECOUNT)
 		m_sets[1].remove(proxy->leaf);
 		m_sets[1].remove(proxy->leaf);
 	else
 	else
 		m_sets[0].remove(proxy->leaf);
 		m_sets[0].remove(proxy->leaf);
-	listremove(proxy,m_stageRoots[proxy->stage]);
-	m_paircache->removeOverlappingPairsContainingProxy(proxy,dispatcher);
+	listremove(proxy, m_stageRoots[proxy->stage]);
+	m_paircache->removeOverlappingPairsContainingProxy(proxy, dispatcher);
 	btAlignedFree(proxy);
 	btAlignedFree(proxy);
-	m_needcleanup=true;
+	m_needcleanup = true;
 }
 }
 
 
-void	btDbvtBroadphase::getAabb(btBroadphaseProxy* absproxy,btVector3& aabbMin, btVector3& aabbMax ) const
+void btDbvtBroadphase::getAabb(btBroadphaseProxy* absproxy, btVector3& aabbMin, btVector3& aabbMax) const
 {
 {
-	btDbvtProxy*						proxy=(btDbvtProxy*)absproxy;
+	btDbvtProxy* proxy = (btDbvtProxy*)absproxy;
 	aabbMin = proxy->m_aabbMin;
 	aabbMin = proxy->m_aabbMin;
 	aabbMax = proxy->m_aabbMax;
 	aabbMax = proxy->m_aabbMax;
 }
 }
 
 
-struct	BroadphaseRayTester : btDbvt::ICollide
+struct BroadphaseRayTester : btDbvt::ICollide
 {
 {
 	btBroadphaseRayCallback& m_rayCallback;
 	btBroadphaseRayCallback& m_rayCallback;
 	BroadphaseRayTester(btBroadphaseRayCallback& orgCallback)
 	BroadphaseRayTester(btBroadphaseRayCallback& orgCallback)
-		:m_rayCallback(orgCallback)
+		: m_rayCallback(orgCallback)
 	{
 	{
 	}
 	}
-	void					Process(const btDbvtNode* leaf)
+	void Process(const btDbvtNode* leaf)
 	{
 	{
-		btDbvtProxy*	proxy=(btDbvtProxy*)leaf->data;
+		btDbvtProxy* proxy = (btDbvtProxy*)leaf->data;
 		m_rayCallback.process(proxy);
 		m_rayCallback.process(proxy);
 	}
 	}
-};	
+};
 
 
-void	btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback,const btVector3& aabbMin,const btVector3& aabbMax)
+void btDbvtBroadphase::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin, const btVector3& aabbMax)
 {
 {
 	BroadphaseRayTester callback(rayCallback);
 	BroadphaseRayTester callback(rayCallback);
-    btAlignedObjectArray<const btDbvtNode*>* stack = &m_rayTestStacks[0];
+	btAlignedObjectArray<const btDbvtNode*>* stack = &m_rayTestStacks[0];
 #if BT_THREADSAFE
 #if BT_THREADSAFE
-    // for this function to be threadsafe, each thread must have a separate copy
-    // of this stack.  This could be thread-local static to avoid dynamic allocations,
-    // instead of just a local.
-    int threadIndex = btGetCurrentThreadIndex();
-    btAlignedObjectArray<const btDbvtNode*> localStack;
-    if (threadIndex < m_rayTestStacks.size())
-    {
-        // use per-thread preallocated stack if possible to avoid dynamic allocations
-        stack = &m_rayTestStacks[threadIndex];
-    }
-    else
-    {
-        stack = &localStack;
-    }
+	// for this function to be threadsafe, each thread must have a separate copy
+	// of this stack.  This could be thread-local static to avoid dynamic allocations,
+	// instead of just a local.
+	int threadIndex = btGetCurrentThreadIndex();
+	btAlignedObjectArray<const btDbvtNode*> localStack;
+	//todo(erwincoumans, "why do we get tsan issue here?")
+	if (0)//threadIndex < m_rayTestStacks.size())
+	//if (threadIndex < m_rayTestStacks.size())
+	{
+		// use per-thread preallocated stack if possible to avoid dynamic allocations
+		stack = &m_rayTestStacks[threadIndex];
+	}
+	else
+	{
+		stack = &localStack;
+	}
 #endif
 #endif
 
 
-	m_sets[0].rayTestInternal(	m_sets[0].m_root,
-		rayFrom,
-		rayTo,
-		rayCallback.m_rayDirectionInverse,
-		rayCallback.m_signs,
-		rayCallback.m_lambda_max,
-		aabbMin,
-		aabbMax,
-        *stack,
-		callback);
-
-	m_sets[1].rayTestInternal(	m_sets[1].m_root,
-		rayFrom,
-		rayTo,
-		rayCallback.m_rayDirectionInverse,
-		rayCallback.m_signs,
-		rayCallback.m_lambda_max,
-		aabbMin,
-		aabbMax,
-        *stack,
-		callback);
-
+	m_sets[0].rayTestInternal(m_sets[0].m_root,
+							  rayFrom,
+							  rayTo,
+							  rayCallback.m_rayDirectionInverse,
+							  rayCallback.m_signs,
+							  rayCallback.m_lambda_max,
+							  aabbMin,
+							  aabbMax,
+							  *stack,
+							  callback);
+
+	m_sets[1].rayTestInternal(m_sets[1].m_root,
+							  rayFrom,
+							  rayTo,
+							  rayCallback.m_rayDirectionInverse,
+							  rayCallback.m_signs,
+							  rayCallback.m_lambda_max,
+							  aabbMin,
+							  aabbMax,
+							  *stack,
+							  callback);
 }
 }
 
 
-
-struct	BroadphaseAabbTester : btDbvt::ICollide
+struct BroadphaseAabbTester : btDbvt::ICollide
 {
 {
 	btBroadphaseAabbCallback& m_aabbCallback;
 	btBroadphaseAabbCallback& m_aabbCallback;
 	BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback)
 	BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback)
-		:m_aabbCallback(orgCallback)
+		: m_aabbCallback(orgCallback)
 	{
 	{
 	}
 	}
-	void					Process(const btDbvtNode* leaf)
+	void Process(const btDbvtNode* leaf)
 	{
 	{
-		btDbvtProxy*	proxy=(btDbvtProxy*)leaf->data;
+		btDbvtProxy* proxy = (btDbvtProxy*)leaf->data;
 		m_aabbCallback.process(proxy);
 		m_aabbCallback.process(proxy);
 	}
 	}
-};	
+};
 
 
-void	btDbvtBroadphase::aabbTest(const btVector3& aabbMin,const btVector3& aabbMax,btBroadphaseAabbCallback& aabbCallback)
+void btDbvtBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& aabbCallback)
 {
 {
 	BroadphaseAabbTester callback(aabbCallback);
 	BroadphaseAabbTester callback(aabbCallback);
 
 
-	const ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds=btDbvtVolume::FromMM(aabbMin,aabbMax);
-		//process all children, that overlap with  the given AABB bounds
-	m_sets[0].collideTV(m_sets[0].m_root,bounds,callback);
-	m_sets[1].collideTV(m_sets[1].m_root,bounds,callback);
-
+	const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(aabbMin, aabbMax);
+	//process all children, that overlap with  the given AABB bounds
+	m_sets[0].collideTV(m_sets[0].m_root, bounds, callback);
+	m_sets[1].collideTV(m_sets[1].m_root, bounds, callback);
 }
 }
 
 
-
-
 //
 //
-void							btDbvtBroadphase::setAabb(		btBroadphaseProxy* absproxy,
-														  const btVector3& aabbMin,
-														  const btVector3& aabbMax,
-														  btDispatcher* /*dispatcher*/)
+void btDbvtBroadphase::setAabb(btBroadphaseProxy* absproxy,
+							   const btVector3& aabbMin,
+							   const btVector3& aabbMax,
+							   btDispatcher* /*dispatcher*/)
 {
 {
-	btDbvtProxy*						proxy=(btDbvtProxy*)absproxy;
-	ATTRIBUTE_ALIGNED16(btDbvtVolume)	aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
+	btDbvtProxy* proxy = (btDbvtProxy*)absproxy;
+	ATTRIBUTE_ALIGNED16(btDbvtVolume)
+	aabb = btDbvtVolume::FromMM(aabbMin, aabbMax);
 #if DBVT_BP_PREVENTFALSEUPDATE
 #if DBVT_BP_PREVENTFALSEUPDATE
-	if(NotEqual(aabb,proxy->leaf->volume))
+	if (NotEqual(aabb, proxy->leaf->volume))
 #endif
 #endif
 	{
 	{
-		bool	docollide=false;
-		if(proxy->stage==STAGECOUNT)
-		{/* fixed -> dynamic set	*/ 
+		bool docollide = false;
+		if (proxy->stage == STAGECOUNT)
+		{ /* fixed -> dynamic set	*/
 			m_sets[1].remove(proxy->leaf);
 			m_sets[1].remove(proxy->leaf);
-			proxy->leaf=m_sets[0].insert(aabb,proxy);
-			docollide=true;
+			proxy->leaf = m_sets[0].insert(aabb, proxy);
+			docollide = true;
 		}
 		}
 		else
 		else
-		{/* dynamic set				*/ 
+		{ /* dynamic set				*/
 			++m_updates_call;
 			++m_updates_call;
-			if(Intersect(proxy->leaf->volume,aabb))
-			{/* Moving				*/ 
-
-				const btVector3	delta=aabbMin-proxy->m_aabbMin;
-				btVector3		velocity(((proxy->m_aabbMax-proxy->m_aabbMin)/2)*m_prediction);
-				if(delta[0]<0) velocity[0]=-velocity[0];
-				if(delta[1]<0) velocity[1]=-velocity[1];
-				if(delta[2]<0) velocity[2]=-velocity[2];
-				if	(
-#ifdef DBVT_BP_MARGIN				
-					m_sets[0].update(proxy->leaf,aabb,velocity,DBVT_BP_MARGIN)
-#else
-					m_sets[0].update(proxy->leaf,aabb,velocity)
-#endif
-					)
+			if (Intersect(proxy->leaf->volume, aabb))
+			{ /* Moving				*/
+
+				const btVector3 delta = aabbMin - proxy->m_aabbMin;
+				btVector3 velocity(((proxy->m_aabbMax - proxy->m_aabbMin) / 2) * m_prediction);
+				if (delta[0] < 0) velocity[0] = -velocity[0];
+				if (delta[1] < 0) velocity[1] = -velocity[1];
+				if (delta[2] < 0) velocity[2] = -velocity[2];
+				if (
+					m_sets[0].update(proxy->leaf, aabb, velocity, gDbvtMargin)
+
+				)
 				{
 				{
 					++m_updates_done;
 					++m_updates_done;
-					docollide=true;
+					docollide = true;
 				}
 				}
 			}
 			}
 			else
 			else
-			{/* Teleporting			*/ 
-				m_sets[0].update(proxy->leaf,aabb);
+			{ /* Teleporting			*/
+				m_sets[0].update(proxy->leaf, aabb);
 				++m_updates_done;
 				++m_updates_done;
-				docollide=true;
-			}	
+				docollide = true;
+			}
 		}
 		}
-		listremove(proxy,m_stageRoots[proxy->stage]);
+		listremove(proxy, m_stageRoots[proxy->stage]);
 		proxy->m_aabbMin = aabbMin;
 		proxy->m_aabbMin = aabbMin;
 		proxy->m_aabbMax = aabbMax;
 		proxy->m_aabbMax = aabbMax;
-		proxy->stage	=	m_stageCurrent;
-		listappend(proxy,m_stageRoots[m_stageCurrent]);
-		if(docollide)
+		proxy->stage = m_stageCurrent;
+		listappend(proxy, m_stageRoots[m_stageCurrent]);
+		if (docollide)
 		{
 		{
-			m_needcleanup=true;
-			if(!m_deferedcollide)
+			m_needcleanup = true;
+			if (!m_deferedcollide)
 			{
 			{
-				btDbvtTreeCollider	collider(this);
-				m_sets[1].collideTTpersistentStack(m_sets[1].m_root,proxy->leaf,collider);
-				m_sets[0].collideTTpersistentStack(m_sets[0].m_root,proxy->leaf,collider);
+				btDbvtTreeCollider collider(this);
+				m_sets[1].collideTTpersistentStack(m_sets[1].m_root, proxy->leaf, collider);
+				m_sets[0].collideTTpersistentStack(m_sets[0].m_root, proxy->leaf, collider);
 			}
 			}
-		}	
+		}
 	}
 	}
 }
 }
 
 
-
 //
 //
-void							btDbvtBroadphase::setAabbForceUpdate(		btBroadphaseProxy* absproxy,
-														  const btVector3& aabbMin,
-														  const btVector3& aabbMax,
-														  btDispatcher* /*dispatcher*/)
+void btDbvtBroadphase::setAabbForceUpdate(btBroadphaseProxy* absproxy,
+										  const btVector3& aabbMin,
+										  const btVector3& aabbMax,
+										  btDispatcher* /*dispatcher*/)
 {
 {
-	btDbvtProxy*						proxy=(btDbvtProxy*)absproxy;
-	ATTRIBUTE_ALIGNED16(btDbvtVolume)	aabb=btDbvtVolume::FromMM(aabbMin,aabbMax);
-	bool	docollide=false;
-	if(proxy->stage==STAGECOUNT)
-	{/* fixed -> dynamic set	*/ 
+	btDbvtProxy* proxy = (btDbvtProxy*)absproxy;
+	ATTRIBUTE_ALIGNED16(btDbvtVolume)
+	aabb = btDbvtVolume::FromMM(aabbMin, aabbMax);
+	bool docollide = false;
+	if (proxy->stage == STAGECOUNT)
+	{ /* fixed -> dynamic set	*/
 		m_sets[1].remove(proxy->leaf);
 		m_sets[1].remove(proxy->leaf);
-		proxy->leaf=m_sets[0].insert(aabb,proxy);
-		docollide=true;
+		proxy->leaf = m_sets[0].insert(aabb, proxy);
+		docollide = true;
 	}
 	}
 	else
 	else
-	{/* dynamic set				*/ 
+	{ /* dynamic set				*/
 		++m_updates_call;
 		++m_updates_call;
-		/* Teleporting			*/ 
-		m_sets[0].update(proxy->leaf,aabb);
+		/* Teleporting			*/
+		m_sets[0].update(proxy->leaf, aabb);
 		++m_updates_done;
 		++m_updates_done;
-		docollide=true;
+		docollide = true;
 	}
 	}
-	listremove(proxy,m_stageRoots[proxy->stage]);
+	listremove(proxy, m_stageRoots[proxy->stage]);
 	proxy->m_aabbMin = aabbMin;
 	proxy->m_aabbMin = aabbMin;
 	proxy->m_aabbMax = aabbMax;
 	proxy->m_aabbMax = aabbMax;
-	proxy->stage	=	m_stageCurrent;
-	listappend(proxy,m_stageRoots[m_stageCurrent]);
-	if(docollide)
+	proxy->stage = m_stageCurrent;
+	listappend(proxy, m_stageRoots[m_stageCurrent]);
+	if (docollide)
 	{
 	{
-		m_needcleanup=true;
-		if(!m_deferedcollide)
+		m_needcleanup = true;
+		if (!m_deferedcollide)
 		{
 		{
-			btDbvtTreeCollider	collider(this);
-			m_sets[1].collideTTpersistentStack(m_sets[1].m_root,proxy->leaf,collider);
-			m_sets[0].collideTTpersistentStack(m_sets[0].m_root,proxy->leaf,collider);
+			btDbvtTreeCollider collider(this);
+			m_sets[1].collideTTpersistentStack(m_sets[1].m_root, proxy->leaf, collider);
+			m_sets[0].collideTTpersistentStack(m_sets[0].m_root, proxy->leaf, collider);
 		}
 		}
-	}	
+	}
 }
 }
 
 
 //
 //
-void							btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
+void btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 {
 {
 	collide(dispatcher);
 	collide(dispatcher);
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
-	if(0==(m_pid%DBVT_BP_PROFILING_RATE))
-	{	
-		printf("fixed(%u) dynamics(%u) pairs(%u)\r\n",m_sets[1].m_leaves,m_sets[0].m_leaves,m_paircache->getNumOverlappingPairs());
-		unsigned int	total=m_profiling.m_total;
-		if(total<=0) total=1;
-		printf("ddcollide: %u%% (%uus)\r\n",(50+m_profiling.m_ddcollide*100)/total,m_profiling.m_ddcollide/DBVT_BP_PROFILING_RATE);
-		printf("fdcollide: %u%% (%uus)\r\n",(50+m_profiling.m_fdcollide*100)/total,m_profiling.m_fdcollide/DBVT_BP_PROFILING_RATE);
-		printf("cleanup:   %u%% (%uus)\r\n",(50+m_profiling.m_cleanup*100)/total,m_profiling.m_cleanup/DBVT_BP_PROFILING_RATE);
-		printf("total:     %uus\r\n",total/DBVT_BP_PROFILING_RATE);
-		const unsigned long	sum=m_profiling.m_ddcollide+
-			m_profiling.m_fdcollide+
-			m_profiling.m_cleanup;
-		printf("leaked: %u%% (%uus)\r\n",100-((50+sum*100)/total),(total-sum)/DBVT_BP_PROFILING_RATE);
-		printf("job counts: %u%%\r\n",(m_profiling.m_jobcount*100)/((m_sets[0].m_leaves+m_sets[1].m_leaves)*DBVT_BP_PROFILING_RATE));
+	if (0 == (m_pid % DBVT_BP_PROFILING_RATE))
+	{
+		printf("fixed(%u) dynamics(%u) pairs(%u)\r\n", m_sets[1].m_leaves, m_sets[0].m_leaves, m_paircache->getNumOverlappingPairs());
+		unsigned int total = m_profiling.m_total;
+		if (total <= 0) total = 1;
+		printf("ddcollide: %u%% (%uus)\r\n", (50 + m_profiling.m_ddcollide * 100) / total, m_profiling.m_ddcollide / DBVT_BP_PROFILING_RATE);
+		printf("fdcollide: %u%% (%uus)\r\n", (50 + m_profiling.m_fdcollide * 100) / total, m_profiling.m_fdcollide / DBVT_BP_PROFILING_RATE);
+		printf("cleanup:   %u%% (%uus)\r\n", (50 + m_profiling.m_cleanup * 100) / total, m_profiling.m_cleanup / DBVT_BP_PROFILING_RATE);
+		printf("total:     %uus\r\n", total / DBVT_BP_PROFILING_RATE);
+		const unsigned long sum = m_profiling.m_ddcollide +
+								  m_profiling.m_fdcollide +
+								  m_profiling.m_cleanup;
+		printf("leaked: %u%% (%uus)\r\n", 100 - ((50 + sum * 100) / total), (total - sum) / DBVT_BP_PROFILING_RATE);
+		printf("job counts: %u%%\r\n", (m_profiling.m_jobcount * 100) / ((m_sets[0].m_leaves + m_sets[1].m_leaves) * DBVT_BP_PROFILING_RATE));
 		clear(m_profiling);
 		clear(m_profiling);
 		m_clock.reset();
 		m_clock.reset();
 	}
 	}
 #endif
 #endif
 
 
 	performDeferredRemoval(dispatcher);
 	performDeferredRemoval(dispatcher);
-
 }
 }
 
 
 void btDbvtBroadphase::performDeferredRemoval(btDispatcher* dispatcher)
 void btDbvtBroadphase::performDeferredRemoval(btDispatcher* dispatcher)
 {
 {
-
 	if (m_paircache->hasDeferredRemoval())
 	if (m_paircache->hasDeferredRemoval())
 	{
 	{
-
-		btBroadphasePairArray&	overlappingPairArray = m_paircache->getOverlappingPairArray();
+		btBroadphasePairArray& overlappingPairArray = m_paircache->getOverlappingPairArray();
 
 
 		//perform a sort, to find duplicates and to sort 'invalid' pairs to the end
 		//perform a sort, to find duplicates and to sort 'invalid' pairs to the end
 		overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
 		overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
 
 
 		int invalidPair = 0;
 		int invalidPair = 0;
 
 
-		
 		int i;
 		int i;
 
 
 		btBroadphasePair previousPair;
 		btBroadphasePair previousPair;
 		previousPair.m_pProxy0 = 0;
 		previousPair.m_pProxy0 = 0;
 		previousPair.m_pProxy1 = 0;
 		previousPair.m_pProxy1 = 0;
 		previousPair.m_algorithm = 0;
 		previousPair.m_algorithm = 0;
-		
-		
-		for (i=0;i<overlappingPairArray.size();i++)
+
+		for (i = 0; i < overlappingPairArray.size(); i++)
 		{
 		{
-		
 			btBroadphasePair& pair = overlappingPairArray[i];
 			btBroadphasePair& pair = overlappingPairArray[i];
 
 
 			bool isDuplicate = (pair == previousPair);
 			bool isDuplicate = (pair == previousPair);
@@ -474,34 +471,35 @@ void btDbvtBroadphase::performDeferredRemoval(btDispatcher* dispatcher)
 			if (!isDuplicate)
 			if (!isDuplicate)
 			{
 			{
 				//important to perform AABB check that is consistent with the broadphase
 				//important to perform AABB check that is consistent with the broadphase
-				btDbvtProxy*		pa=(btDbvtProxy*)pair.m_pProxy0;
-				btDbvtProxy*		pb=(btDbvtProxy*)pair.m_pProxy1;
-				bool hasOverlap = Intersect(pa->leaf->volume,pb->leaf->volume);
+				btDbvtProxy* pa = (btDbvtProxy*)pair.m_pProxy0;
+				btDbvtProxy* pb = (btDbvtProxy*)pair.m_pProxy1;
+				bool hasOverlap = Intersect(pa->leaf->volume, pb->leaf->volume);
 
 
 				if (hasOverlap)
 				if (hasOverlap)
 				{
 				{
 					needsRemoval = false;
 					needsRemoval = false;
-				} else
+				}
+				else
 				{
 				{
 					needsRemoval = true;
 					needsRemoval = true;
 				}
 				}
-			} else
+			}
+			else
 			{
 			{
 				//remove duplicate
 				//remove duplicate
 				needsRemoval = true;
 				needsRemoval = true;
 				//should have no algorithm
 				//should have no algorithm
 				btAssert(!pair.m_algorithm);
 				btAssert(!pair.m_algorithm);
 			}
 			}
-			
+
 			if (needsRemoval)
 			if (needsRemoval)
 			{
 			{
-				m_paircache->cleanOverlappingPair(pair,dispatcher);
+				m_paircache->cleanOverlappingPair(pair, dispatcher);
 
 
 				pair.m_pProxy0 = 0;
 				pair.m_pProxy0 = 0;
 				pair.m_pProxy1 = 0;
 				pair.m_pProxy1 = 0;
 				invalidPair++;
 				invalidPair++;
-			} 
-			
+			}
 		}
 		}
 
 
 		//perform a sort, to sort 'invalid' pairs to the end
 		//perform a sort, to sort 'invalid' pairs to the end
@@ -511,7 +509,7 @@ void btDbvtBroadphase::performDeferredRemoval(btDispatcher* dispatcher)
 }
 }
 
 
 //
 //
-void							btDbvtBroadphase::collide(btDispatcher* dispatcher)
+void btDbvtBroadphase::collide(btDispatcher* dispatcher)
 {
 {
 	/*printf("---------------------------------------------------------\n");
 	/*printf("---------------------------------------------------------\n");
 	printf("m_sets[0].m_leaves=%d\n",m_sets[0].m_leaves);
 	printf("m_sets[0].m_leaves=%d\n",m_sets[0].m_leaves);
@@ -528,293 +526,303 @@ void							btDbvtBroadphase::collide(btDispatcher* dispatcher)
 	}
 	}
 */
 */
 
 
-
-
 	SPC(m_profiling.m_total);
 	SPC(m_profiling.m_total);
-	/* optimize				*/ 
-	m_sets[0].optimizeIncremental(1+(m_sets[0].m_leaves*m_dupdates)/100);
-	if(m_fixedleft)
+	/* optimize				*/
+	m_sets[0].optimizeIncremental(1 + (m_sets[0].m_leaves * m_dupdates) / 100);
+	if (m_fixedleft)
 	{
 	{
-		const int count=1+(m_sets[1].m_leaves*m_fupdates)/100;
-		m_sets[1].optimizeIncremental(1+(m_sets[1].m_leaves*m_fupdates)/100);
-		m_fixedleft=btMax<int>(0,m_fixedleft-count);
+		const int count = 1 + (m_sets[1].m_leaves * m_fupdates) / 100;
+		m_sets[1].optimizeIncremental(1 + (m_sets[1].m_leaves * m_fupdates) / 100);
+		m_fixedleft = btMax<int>(0, m_fixedleft - count);
 	}
 	}
-	/* dynamic -> fixed set	*/ 
-	m_stageCurrent=(m_stageCurrent+1)%STAGECOUNT;
-	btDbvtProxy*	current=m_stageRoots[m_stageCurrent];
-	if(current)
+	/* dynamic -> fixed set	*/
+	m_stageCurrent = (m_stageCurrent + 1) % STAGECOUNT;
+	btDbvtProxy* current = m_stageRoots[m_stageCurrent];
+	if (current)
 	{
 	{
-		btDbvtTreeCollider	collider(this);
-		do	{
-			btDbvtProxy*	next=current->links[1];
-			listremove(current,m_stageRoots[current->stage]);
-			listappend(current,m_stageRoots[STAGECOUNT]);
 #if DBVT_BP_ACCURATESLEEPING
 #if DBVT_BP_ACCURATESLEEPING
-			m_paircache->removeOverlappingPairsContainingProxy(current,dispatcher);
-			collider.proxy=current;
-			btDbvt::collideTV(m_sets[0].m_root,current->aabb,collider);
-			btDbvt::collideTV(m_sets[1].m_root,current->aabb,collider);
+		btDbvtTreeCollider collider(this);
+#endif
+		do
+		{
+			btDbvtProxy* next = current->links[1];
+			listremove(current, m_stageRoots[current->stage]);
+			listappend(current, m_stageRoots[STAGECOUNT]);
+#if DBVT_BP_ACCURATESLEEPING
+			m_paircache->removeOverlappingPairsContainingProxy(current, dispatcher);
+			collider.proxy = current;
+			btDbvt::collideTV(m_sets[0].m_root, current->aabb, collider);
+			btDbvt::collideTV(m_sets[1].m_root, current->aabb, collider);
 #endif
 #endif
 			m_sets[0].remove(current->leaf);
 			m_sets[0].remove(current->leaf);
-			ATTRIBUTE_ALIGNED16(btDbvtVolume)	curAabb=btDbvtVolume::FromMM(current->m_aabbMin,current->m_aabbMax);
-			current->leaf	=	m_sets[1].insert(curAabb,current);
-			current->stage	=	STAGECOUNT;	
-			current			=	next;
-		} while(current);
-		m_fixedleft=m_sets[1].m_leaves;
-		m_needcleanup=true;
+			ATTRIBUTE_ALIGNED16(btDbvtVolume)
+			curAabb = btDbvtVolume::FromMM(current->m_aabbMin, current->m_aabbMax);
+			current->leaf = m_sets[1].insert(curAabb, current);
+			current->stage = STAGECOUNT;
+			current = next;
+		} while (current);
+		m_fixedleft = m_sets[1].m_leaves;
+		m_needcleanup = true;
 	}
 	}
-	/* collide dynamics		*/ 
+	/* collide dynamics		*/
 	{
 	{
-		btDbvtTreeCollider	collider(this);
-		if(m_deferedcollide)
+		btDbvtTreeCollider collider(this);
+		if (m_deferedcollide)
 		{
 		{
 			SPC(m_profiling.m_fdcollide);
 			SPC(m_profiling.m_fdcollide);
-			m_sets[0].collideTTpersistentStack(m_sets[0].m_root,m_sets[1].m_root,collider);
+			m_sets[0].collideTTpersistentStack(m_sets[0].m_root, m_sets[1].m_root, collider);
 		}
 		}
-		if(m_deferedcollide)
+		if (m_deferedcollide)
 		{
 		{
 			SPC(m_profiling.m_ddcollide);
 			SPC(m_profiling.m_ddcollide);
-			m_sets[0].collideTTpersistentStack(m_sets[0].m_root,m_sets[0].m_root,collider);
+			m_sets[0].collideTTpersistentStack(m_sets[0].m_root, m_sets[0].m_root, collider);
 		}
 		}
 	}
 	}
-	/* clean up				*/ 
-	if(m_needcleanup)
+	/* clean up				*/
+	if (m_needcleanup)
 	{
 	{
 		SPC(m_profiling.m_cleanup);
 		SPC(m_profiling.m_cleanup);
-		btBroadphasePairArray&	pairs=m_paircache->getOverlappingPairArray();
-		if(pairs.size()>0)
+		btBroadphasePairArray& pairs = m_paircache->getOverlappingPairArray();
+		if (pairs.size() > 0)
 		{
 		{
-
-			int			ni=btMin(pairs.size(),btMax<int>(m_newpairs,(pairs.size()*m_cupdates)/100));
-			for(int i=0;i<ni;++i)
+			int ni = btMin(pairs.size(), btMax<int>(m_newpairs, (pairs.size() * m_cupdates) / 100));
+			for (int i = 0; i < ni; ++i)
 			{
 			{
-				btBroadphasePair&	p=pairs[(m_cid+i)%pairs.size()];
-				btDbvtProxy*		pa=(btDbvtProxy*)p.m_pProxy0;
-				btDbvtProxy*		pb=(btDbvtProxy*)p.m_pProxy1;
-				if(!Intersect(pa->leaf->volume,pb->leaf->volume))
+				btBroadphasePair& p = pairs[(m_cid + i) % pairs.size()];
+				btDbvtProxy* pa = (btDbvtProxy*)p.m_pProxy0;
+				btDbvtProxy* pb = (btDbvtProxy*)p.m_pProxy1;
+				if (!Intersect(pa->leaf->volume, pb->leaf->volume))
 				{
 				{
 #if DBVT_BP_SORTPAIRS
 #if DBVT_BP_SORTPAIRS
-					if(pa->m_uniqueId>pb->m_uniqueId) 
-						btSwap(pa,pb);
+					if (pa->m_uniqueId > pb->m_uniqueId)
+						btSwap(pa, pb);
 #endif
 #endif
-					m_paircache->removeOverlappingPair(pa,pb,dispatcher);
-					--ni;--i;
+					m_paircache->removeOverlappingPair(pa, pb, dispatcher);
+					--ni;
+					--i;
 				}
 				}
 			}
 			}
-			if(pairs.size()>0) m_cid=(m_cid+ni)%pairs.size(); else m_cid=0;
+			if (pairs.size() > 0)
+				m_cid = (m_cid + ni) % pairs.size();
+			else
+				m_cid = 0;
 		}
 		}
 	}
 	}
 	++m_pid;
 	++m_pid;
-	m_newpairs=1;
-	m_needcleanup=false;
-	if(m_updates_call>0)
-	{ m_updates_ratio=m_updates_done/(btScalar)m_updates_call; }
+	m_newpairs = 1;
+	m_needcleanup = false;
+	if (m_updates_call > 0)
+	{
+		m_updates_ratio = m_updates_done / (btScalar)m_updates_call;
+	}
 	else
 	else
-	{ m_updates_ratio=0; }
-	m_updates_done/=2;
-	m_updates_call/=2;
+	{
+		m_updates_ratio = 0;
+	}
+	m_updates_done /= 2;
+	m_updates_call /= 2;
 }
 }
 
 
 //
 //
-void							btDbvtBroadphase::optimize()
+void btDbvtBroadphase::optimize()
 {
 {
 	m_sets[0].optimizeTopDown();
 	m_sets[0].optimizeTopDown();
 	m_sets[1].optimizeTopDown();
 	m_sets[1].optimizeTopDown();
 }
 }
 
 
 //
 //
-btOverlappingPairCache*			btDbvtBroadphase::getOverlappingPairCache()
+btOverlappingPairCache* btDbvtBroadphase::getOverlappingPairCache()
 {
 {
-	return(m_paircache);
+	return (m_paircache);
 }
 }
 
 
 //
 //
-const btOverlappingPairCache*	btDbvtBroadphase::getOverlappingPairCache() const
+const btOverlappingPairCache* btDbvtBroadphase::getOverlappingPairCache() const
 {
 {
-	return(m_paircache);
+	return (m_paircache);
 }
 }
 
 
 //
 //
-void							btDbvtBroadphase::getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
+void btDbvtBroadphase::getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const
 {
 {
+	ATTRIBUTE_ALIGNED16(btDbvtVolume)
+	bounds;
 
 
-	ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds;
-
-	if(!m_sets[0].empty())
-		if(!m_sets[1].empty())	Merge(	m_sets[0].m_root->volume,
-			m_sets[1].m_root->volume,bounds);
+	if (!m_sets[0].empty())
+		if (!m_sets[1].empty())
+			Merge(m_sets[0].m_root->volume,
+				  m_sets[1].m_root->volume, bounds);
 		else
 		else
-			bounds=m_sets[0].m_root->volume;
-	else if(!m_sets[1].empty())	bounds=m_sets[1].m_root->volume;
+			bounds = m_sets[0].m_root->volume;
+	else if (!m_sets[1].empty())
+		bounds = m_sets[1].m_root->volume;
 	else
 	else
-		bounds=btDbvtVolume::FromCR(btVector3(0,0,0),0);
-	aabbMin=bounds.Mins();
-	aabbMax=bounds.Maxs();
+		bounds = btDbvtVolume::FromCR(btVector3(0, 0, 0), 0);
+	aabbMin = bounds.Mins();
+	aabbMax = bounds.Maxs();
 }
 }
 
 
 void btDbvtBroadphase::resetPool(btDispatcher* dispatcher)
 void btDbvtBroadphase::resetPool(btDispatcher* dispatcher)
 {
 {
-	
 	int totalObjects = m_sets[0].m_leaves + m_sets[1].m_leaves;
 	int totalObjects = m_sets[0].m_leaves + m_sets[1].m_leaves;
 	if (!totalObjects)
 	if (!totalObjects)
 	{
 	{
 		//reset internal dynamic tree data structures
 		//reset internal dynamic tree data structures
 		m_sets[0].clear();
 		m_sets[0].clear();
 		m_sets[1].clear();
 		m_sets[1].clear();
-		
-		m_deferedcollide	=	false;
-		m_needcleanup		=	true;
-		m_stageCurrent		=	0;
-		m_fixedleft			=	0;
-		m_fupdates			=	1;
-		m_dupdates			=	0;
-		m_cupdates			=	10;
-		m_newpairs			=	1;
-		m_updates_call		=	0;
-		m_updates_done		=	0;
-		m_updates_ratio		=	0;
-		
-		m_gid				=	0;
-		m_pid				=	0;
-		m_cid				=	0;
-		for(int i=0;i<=STAGECOUNT;++i)
+
+		m_deferedcollide = false;
+		m_needcleanup = true;
+		m_stageCurrent = 0;
+		m_fixedleft = 0;
+		m_fupdates = 1;
+		m_dupdates = 0;
+		m_cupdates = 10;
+		m_newpairs = 1;
+		m_updates_call = 0;
+		m_updates_done = 0;
+		m_updates_ratio = 0;
+
+		m_gid = 0;
+		m_pid = 0;
+		m_cid = 0;
+		for (int i = 0; i <= STAGECOUNT; ++i)
 		{
 		{
-			m_stageRoots[i]=0;
+			m_stageRoots[i] = 0;
 		}
 		}
 	}
 	}
 }
 }
 
 
 //
 //
-void							btDbvtBroadphase::printStats()
-{}
+void btDbvtBroadphase::printStats()
+{
+}
 
 
 //
 //
 #if DBVT_BP_ENABLE_BENCHMARK
 #if DBVT_BP_ENABLE_BENCHMARK
 
 
-struct	btBroadphaseBenchmark
+struct btBroadphaseBenchmark
 {
 {
-	struct	Experiment
+	struct Experiment
 	{
 	{
-		const char*			name;
-		int					object_count;
-		int					update_count;
-		int					spawn_count;
-		int					iterations;
-		btScalar			speed;
-		btScalar			amplitude;
+		const char* name;
+		int object_count;
+		int update_count;
+		int spawn_count;
+		int iterations;
+		btScalar speed;
+		btScalar amplitude;
 	};
 	};
-	struct	Object
+	struct Object
 	{
 	{
-		btVector3			center;
-		btVector3			extents;
-		btBroadphaseProxy*	proxy;
-		btScalar			time;
-		void				update(btScalar speed,btScalar amplitude,btBroadphaseInterface* pbi)
+		btVector3 center;
+		btVector3 extents;
+		btBroadphaseProxy* proxy;
+		btScalar time;
+		void update(btScalar speed, btScalar amplitude, btBroadphaseInterface* pbi)
 		{
 		{
-			time		+=	speed;
-			center[0]	=	btCos(time*(btScalar)2.17)*amplitude+
-				btSin(time)*amplitude/2;
-			center[1]	=	btCos(time*(btScalar)1.38)*amplitude+
-				btSin(time)*amplitude;
-			center[2]	=	btSin(time*(btScalar)0.777)*amplitude;
-			pbi->setAabb(proxy,center-extents,center+extents,0);
+			time += speed;
+			center[0] = btCos(time * (btScalar)2.17) * amplitude +
+						btSin(time) * amplitude / 2;
+			center[1] = btCos(time * (btScalar)1.38) * amplitude +
+						btSin(time) * amplitude;
+			center[2] = btSin(time * (btScalar)0.777) * amplitude;
+			pbi->setAabb(proxy, center - extents, center + extents, 0);
 		}
 		}
 	};
 	};
-	static int		UnsignedRand(int range=RAND_MAX-1)	{ return(rand()%(range+1)); }
-	static btScalar	UnitRand()							{ return(UnsignedRand(16384)/(btScalar)16384); }
-	static void		OutputTime(const char* name,btClock& c,unsigned count=0)
+	static int UnsignedRand(int range = RAND_MAX - 1) { return (rand() % (range + 1)); }
+	static btScalar UnitRand() { return (UnsignedRand(16384) / (btScalar)16384); }
+	static void OutputTime(const char* name, btClock& c, unsigned count = 0)
 	{
 	{
-		const unsigned long	us=c.getTimeMicroseconds();
-		const unsigned long	ms=(us+500)/1000;
-		const btScalar		sec=us/(btScalar)(1000*1000);
-		if(count>0)
-			printf("%s : %u us (%u ms), %.2f/s\r\n",name,us,ms,count/sec);
+		const unsigned long us = c.getTimeMicroseconds();
+		const unsigned long ms = (us + 500) / 1000;
+		const btScalar sec = us / (btScalar)(1000 * 1000);
+		if (count > 0)
+			printf("%s : %u us (%u ms), %.2f/s\r\n", name, us, ms, count / sec);
 		else
 		else
-			printf("%s : %u us (%u ms)\r\n",name,us,ms);
+			printf("%s : %u us (%u ms)\r\n", name, us, ms);
 	}
 	}
 };
 };
 
 
-void							btDbvtBroadphase::benchmark(btBroadphaseInterface* pbi)
+void btDbvtBroadphase::benchmark(btBroadphaseInterface* pbi)
 {
 {
-	static const btBroadphaseBenchmark::Experiment		experiments[]=
-	{
-		{"1024o.10%",1024,10,0,8192,(btScalar)0.005,(btScalar)100},
-		/*{"4096o.10%",4096,10,0,8192,(btScalar)0.005,(btScalar)100},
+	static const btBroadphaseBenchmark::Experiment experiments[] =
+		{
+			{"1024o.10%", 1024, 10, 0, 8192, (btScalar)0.005, (btScalar)100},
+			/*{"4096o.10%",4096,10,0,8192,(btScalar)0.005,(btScalar)100},
 		{"8192o.10%",8192,10,0,8192,(btScalar)0.005,(btScalar)100},*/
 		{"8192o.10%",8192,10,0,8192,(btScalar)0.005,(btScalar)100},*/
-	};
-	static const int										nexperiments=sizeof(experiments)/sizeof(experiments[0]);
-	btAlignedObjectArray<btBroadphaseBenchmark::Object*>	objects;
-	btClock													wallclock;
-	/* Begin			*/ 
-	for(int iexp=0;iexp<nexperiments;++iexp)
+		};
+	static const int nexperiments = sizeof(experiments) / sizeof(experiments[0]);
+	btAlignedObjectArray<btBroadphaseBenchmark::Object*> objects;
+	btClock wallclock;
+	/* Begin			*/
+	for (int iexp = 0; iexp < nexperiments; ++iexp)
 	{
 	{
-		const btBroadphaseBenchmark::Experiment&	experiment=experiments[iexp];
-		const int									object_count=experiment.object_count;
-		const int									update_count=(object_count*experiment.update_count)/100;
-		const int									spawn_count=(object_count*experiment.spawn_count)/100;
-		const btScalar								speed=experiment.speed;	
-		const btScalar								amplitude=experiment.amplitude;
-		printf("Experiment #%u '%s':\r\n",iexp,experiment.name);
-		printf("\tObjects: %u\r\n",object_count);
-		printf("\tUpdate: %u\r\n",update_count);
-		printf("\tSpawn: %u\r\n",spawn_count);
-		printf("\tSpeed: %f\r\n",speed);
-		printf("\tAmplitude: %f\r\n",amplitude);
+		const btBroadphaseBenchmark::Experiment& experiment = experiments[iexp];
+		const int object_count = experiment.object_count;
+		const int update_count = (object_count * experiment.update_count) / 100;
+		const int spawn_count = (object_count * experiment.spawn_count) / 100;
+		const btScalar speed = experiment.speed;
+		const btScalar amplitude = experiment.amplitude;
+		printf("Experiment #%u '%s':\r\n", iexp, experiment.name);
+		printf("\tObjects: %u\r\n", object_count);
+		printf("\tUpdate: %u\r\n", update_count);
+		printf("\tSpawn: %u\r\n", spawn_count);
+		printf("\tSpeed: %f\r\n", speed);
+		printf("\tAmplitude: %f\r\n", amplitude);
 		srand(180673);
 		srand(180673);
-		/* Create objects	*/ 
+		/* Create objects	*/
 		wallclock.reset();
 		wallclock.reset();
 		objects.reserve(object_count);
 		objects.reserve(object_count);
-		for(int i=0;i<object_count;++i)
+		for (int i = 0; i < object_count; ++i)
 		{
 		{
-			btBroadphaseBenchmark::Object*	po=new btBroadphaseBenchmark::Object();
-			po->center[0]=btBroadphaseBenchmark::UnitRand()*50;
-			po->center[1]=btBroadphaseBenchmark::UnitRand()*50;
-			po->center[2]=btBroadphaseBenchmark::UnitRand()*50;
-			po->extents[0]=btBroadphaseBenchmark::UnitRand()*2+2;
-			po->extents[1]=btBroadphaseBenchmark::UnitRand()*2+2;
-			po->extents[2]=btBroadphaseBenchmark::UnitRand()*2+2;
-			po->time=btBroadphaseBenchmark::UnitRand()*2000;
-			po->proxy=pbi->createProxy(po->center-po->extents,po->center+po->extents,0,po,1,1,0,0);
+			btBroadphaseBenchmark::Object* po = new btBroadphaseBenchmark::Object();
+			po->center[0] = btBroadphaseBenchmark::UnitRand() * 50;
+			po->center[1] = btBroadphaseBenchmark::UnitRand() * 50;
+			po->center[2] = btBroadphaseBenchmark::UnitRand() * 50;
+			po->extents[0] = btBroadphaseBenchmark::UnitRand() * 2 + 2;
+			po->extents[1] = btBroadphaseBenchmark::UnitRand() * 2 + 2;
+			po->extents[2] = btBroadphaseBenchmark::UnitRand() * 2 + 2;
+			po->time = btBroadphaseBenchmark::UnitRand() * 2000;
+			po->proxy = pbi->createProxy(po->center - po->extents, po->center + po->extents, 0, po, 1, 1, 0, 0);
 			objects.push_back(po);
 			objects.push_back(po);
 		}
 		}
-		btBroadphaseBenchmark::OutputTime("\tInitialization",wallclock);
-		/* First update		*/ 
+		btBroadphaseBenchmark::OutputTime("\tInitialization", wallclock);
+		/* First update		*/
 		wallclock.reset();
 		wallclock.reset();
-		for(int i=0;i<objects.size();++i)
+		for (int i = 0; i < objects.size(); ++i)
 		{
 		{
-			objects[i]->update(speed,amplitude,pbi);
+			objects[i]->update(speed, amplitude, pbi);
 		}
 		}
-		btBroadphaseBenchmark::OutputTime("\tFirst update",wallclock);
-		/* Updates			*/ 
+		btBroadphaseBenchmark::OutputTime("\tFirst update", wallclock);
+		/* Updates			*/
 		wallclock.reset();
 		wallclock.reset();
-		for(int i=0;i<experiment.iterations;++i)
+		for (int i = 0; i < experiment.iterations; ++i)
 		{
 		{
-			for(int j=0;j<update_count;++j)
-			{				
-				objects[j]->update(speed,amplitude,pbi);
+			for (int j = 0; j < update_count; ++j)
+			{
+				objects[j]->update(speed, amplitude, pbi);
 			}
 			}
 			pbi->calculateOverlappingPairs(0);
 			pbi->calculateOverlappingPairs(0);
 		}
 		}
-		btBroadphaseBenchmark::OutputTime("\tUpdate",wallclock,experiment.iterations);
-		/* Clean up			*/ 
+		btBroadphaseBenchmark::OutputTime("\tUpdate", wallclock, experiment.iterations);
+		/* Clean up			*/
 		wallclock.reset();
 		wallclock.reset();
-		for(int i=0;i<objects.size();++i)
+		for (int i = 0; i < objects.size(); ++i)
 		{
 		{
-			pbi->destroyProxy(objects[i]->proxy,0);
+			pbi->destroyProxy(objects[i]->proxy, 0);
 			delete objects[i];
 			delete objects[i];
 		}
 		}
 		objects.resize(0);
 		objects.resize(0);
-		btBroadphaseBenchmark::OutputTime("\tRelease",wallclock);
+		btBroadphaseBenchmark::OutputTime("\tRelease", wallclock);
 	}
 	}
-
 }
 }
 #else
 #else
-void							btDbvtBroadphase::benchmark(btBroadphaseInterface*)
-{}
+void btDbvtBroadphase::benchmark(btBroadphaseInterface*)
+{
+}
 #endif
 #endif
 
 
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
-#undef	SPC
+#undef SPC
 #endif
 #endif
-

+ 75 - 76
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h

@@ -24,15 +24,16 @@ subject to the following restrictions:
 // Compile time config
 // Compile time config
 //
 //
 
 
-#define	DBVT_BP_PROFILE					0
+#define DBVT_BP_PROFILE 0
 //#define DBVT_BP_SORTPAIRS				1
 //#define DBVT_BP_SORTPAIRS				1
-#define DBVT_BP_PREVENTFALSEUPDATE		0
-#define DBVT_BP_ACCURATESLEEPING		0
-#define DBVT_BP_ENABLE_BENCHMARK		0
-#define DBVT_BP_MARGIN					(btScalar)0.05
+#define DBVT_BP_PREVENTFALSEUPDATE 0
+#define DBVT_BP_ACCURATESLEEPING 0
+#define DBVT_BP_ENABLE_BENCHMARK 0
+//#define DBVT_BP_MARGIN					(btScalar)0.05
+extern btScalar gDbvtMargin;
 
 
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
-#define	DBVT_BP_PROFILING_RATE	256
+#define DBVT_BP_PROFILING_RATE 256
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btQuickprof.h"
 #endif
 #endif
 
 
@@ -41,90 +42,90 @@ subject to the following restrictions:
 //
 //
 struct btDbvtProxy : btBroadphaseProxy
 struct btDbvtProxy : btBroadphaseProxy
 {
 {
-	/* Fields		*/ 
+	/* Fields		*/
 	//btDbvtAabbMm	aabb;
 	//btDbvtAabbMm	aabb;
-	btDbvtNode*		leaf;
-	btDbvtProxy*	links[2];
-	int				stage;
-	/* ctor			*/ 
-	btDbvtProxy(const btVector3& aabbMin,const btVector3& aabbMax,void* userPtr, int collisionFilterGroup,  int collisionFilterMask) :
-	btBroadphaseProxy(aabbMin,aabbMax,userPtr,collisionFilterGroup,collisionFilterMask)
+	btDbvtNode* leaf;
+	btDbvtProxy* links[2];
+	int stage;
+	/* ctor			*/
+	btDbvtProxy(const btVector3& aabbMin, const btVector3& aabbMax, void* userPtr, int collisionFilterGroup, int collisionFilterMask) : btBroadphaseProxy(aabbMin, aabbMax, userPtr, collisionFilterGroup, collisionFilterMask)
 	{
 	{
-		links[0]=links[1]=0;
+		links[0] = links[1] = 0;
 	}
 	}
 };
 };
 
 
-typedef btAlignedObjectArray<btDbvtProxy*>	btDbvtProxyArray;
+typedef btAlignedObjectArray<btDbvtProxy*> btDbvtProxyArray;
 
 
 ///The btDbvtBroadphase implements a broadphase using two dynamic AABB bounding volume hierarchies/trees (see btDbvt).
 ///The btDbvtBroadphase implements a broadphase using two dynamic AABB bounding volume hierarchies/trees (see btDbvt).
 ///One tree is used for static/non-moving objects, and another tree is used for dynamic objects. Objects can move from one tree to the other.
 ///One tree is used for static/non-moving objects, and another tree is used for dynamic objects. Objects can move from one tree to the other.
 ///This is a very fast broadphase, especially for very dynamic worlds where many objects are moving. Its insert/add and remove of objects is generally faster than the sweep and prune broadphases btAxisSweep3 and bt32BitAxisSweep3.
 ///This is a very fast broadphase, especially for very dynamic worlds where many objects are moving. Its insert/add and remove of objects is generally faster than the sweep and prune broadphases btAxisSweep3 and bt32BitAxisSweep3.
-struct	btDbvtBroadphase : btBroadphaseInterface
+struct btDbvtBroadphase : btBroadphaseInterface
 {
 {
-	/* Config		*/ 
-	enum	{
-		DYNAMIC_SET			=	0,	/* Dynamic set index	*/ 
-		FIXED_SET			=	1,	/* Fixed set index		*/ 
-		STAGECOUNT			=	2	/* Number of stages		*/ 
+	/* Config		*/
+	enum
+	{
+		DYNAMIC_SET = 0, /* Dynamic set index	*/
+		FIXED_SET = 1,   /* Fixed set index		*/
+		STAGECOUNT = 2   /* Number of stages		*/
 	};
 	};
-	/* Fields		*/ 
-	btDbvt					m_sets[2];					// Dbvt sets
-	btDbvtProxy*			m_stageRoots[STAGECOUNT+1];	// Stages list
-	btOverlappingPairCache*	m_paircache;				// Pair cache
-	btScalar				m_prediction;				// Velocity prediction
-	int						m_stageCurrent;				// Current stage
-	int						m_fupdates;					// % of fixed updates per frame
-	int						m_dupdates;					// % of dynamic updates per frame
-	int						m_cupdates;					// % of cleanup updates per frame
-	int						m_newpairs;					// Number of pairs created
-	int						m_fixedleft;				// Fixed optimization left
-	unsigned				m_updates_call;				// Number of updates call
-	unsigned				m_updates_done;				// Number of updates done
-	btScalar				m_updates_ratio;			// m_updates_done/m_updates_call
-	int						m_pid;						// Parse id
-	int						m_cid;						// Cleanup index
-	int						m_gid;						// Gen id
-	bool					m_releasepaircache;			// Release pair cache on delete
-	bool					m_deferedcollide;			// Defere dynamic/static collision to collide call
-	bool					m_needcleanup;				// Need to run cleanup?
-    btAlignedObjectArray< btAlignedObjectArray<const btDbvtNode*> > m_rayTestStacks;
+	/* Fields		*/
+	btDbvt m_sets[2];                           // Dbvt sets
+	btDbvtProxy* m_stageRoots[STAGECOUNT + 1];  // Stages list
+	btOverlappingPairCache* m_paircache;        // Pair cache
+	btScalar m_prediction;                      // Velocity prediction
+	int m_stageCurrent;                         // Current stage
+	int m_fupdates;                             // % of fixed updates per frame
+	int m_dupdates;                             // % of dynamic updates per frame
+	int m_cupdates;                             // % of cleanup updates per frame
+	int m_newpairs;                             // Number of pairs created
+	int m_fixedleft;                            // Fixed optimization left
+	unsigned m_updates_call;                    // Number of updates call
+	unsigned m_updates_done;                    // Number of updates done
+	btScalar m_updates_ratio;                   // m_updates_done/m_updates_call
+	int m_pid;                                  // Parse id
+	int m_cid;                                  // Cleanup index
+	int m_gid;                                  // Gen id
+	bool m_releasepaircache;                    // Release pair cache on delete
+	bool m_deferedcollide;                      // Defere dynamic/static collision to collide call
+	bool m_needcleanup;                         // Need to run cleanup?
+	btAlignedObjectArray<btAlignedObjectArray<const btDbvtNode*> > m_rayTestStacks;
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
-	btClock					m_clock;
-	struct	{
-		unsigned long		m_total;
-		unsigned long		m_ddcollide;
-		unsigned long		m_fdcollide;
-		unsigned long		m_cleanup;
-		unsigned long		m_jobcount;
-	}				m_profiling;
+	btClock m_clock;
+	struct
+	{
+		unsigned long m_total;
+		unsigned long m_ddcollide;
+		unsigned long m_fdcollide;
+		unsigned long m_cleanup;
+		unsigned long m_jobcount;
+	} m_profiling;
 #endif
 #endif
-	/* Methods		*/ 
-	btDbvtBroadphase(btOverlappingPairCache* paircache=0);
+	/* Methods		*/
+	btDbvtBroadphase(btOverlappingPairCache* paircache = 0);
 	~btDbvtBroadphase();
 	~btDbvtBroadphase();
-	void							collide(btDispatcher* dispatcher);
-	void							optimize();
-	
-	/* btBroadphaseInterface Implementation	*/
-	btBroadphaseProxy*				createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr, int collisionFilterGroup, int collisionFilterMask,btDispatcher* dispatcher);
-	virtual void					destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
-	virtual void					setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher);
-	virtual void					rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0));
-	virtual void					aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
-
-	virtual void					getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
-	virtual	void					calculateOverlappingPairs(btDispatcher* dispatcher);
-	virtual	btOverlappingPairCache*	getOverlappingPairCache();
-	virtual	const btOverlappingPairCache*	getOverlappingPairCache() const;
-	virtual	void					getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
-	virtual	void					printStats();
+	void collide(btDispatcher* dispatcher);
+	void optimize();
 
 
+	/* btBroadphaseInterface Implementation	*/
+	btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
+	virtual void destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
+	virtual void setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher);
+	virtual void rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin = btVector3(0, 0, 0), const btVector3& aabbMax = btVector3(0, 0, 0));
+	virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
+
+	virtual void getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const;
+	virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
+	virtual btOverlappingPairCache* getOverlappingPairCache();
+	virtual const btOverlappingPairCache* getOverlappingPairCache() const;
+	virtual void getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const;
+	virtual void printStats();
 
 
 	///reset broadphase internal structures, to ensure determinism/reproducability
 	///reset broadphase internal structures, to ensure determinism/reproducability
 	virtual void resetPool(btDispatcher* dispatcher);
 	virtual void resetPool(btDispatcher* dispatcher);
 
 
-	void	performDeferredRemoval(btDispatcher* dispatcher);
-	
-	void	setVelocityPrediction(btScalar prediction)
+	void performDeferredRemoval(btDispatcher* dispatcher);
+
+	void setVelocityPrediction(btScalar prediction)
 	{
 	{
 		m_prediction = prediction;
 		m_prediction = prediction;
 	}
 	}
@@ -133,15 +134,13 @@ struct	btDbvtBroadphase : btBroadphaseInterface
 		return m_prediction;
 		return m_prediction;
 	}
 	}
 
 
-	///this setAabbForceUpdate is similar to setAabb but always forces the aabb update. 
+	///this setAabbForceUpdate is similar to setAabb but always forces the aabb update.
 	///it is not part of the btBroadphaseInterface but specific to btDbvtBroadphase.
 	///it is not part of the btBroadphaseInterface but specific to btDbvtBroadphase.
 	///it bypasses certain optimizations that prevent aabb updates (when the aabb shrinks), see
 	///it bypasses certain optimizations that prevent aabb updates (when the aabb shrinks), see
 	///http://code.google.com/p/bullet/issues/detail?id=223
 	///http://code.google.com/p/bullet/issues/detail?id=223
-	void							setAabbForceUpdate(		btBroadphaseProxy* absproxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* /*dispatcher*/);
-
-	static void						benchmark(btBroadphaseInterface*);
-
+	void setAabbForceUpdate(btBroadphaseProxy* absproxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* /*dispatcher*/);
 
 
+	static void benchmark(btBroadphaseInterface*);
 };
 };
 
 
 #endif
 #endif

+ 0 - 2
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.cpp

@@ -17,6 +17,4 @@ subject to the following restrictions:
 
 
 btDispatcher::~btDispatcher()
 btDispatcher::~btDispatcher()
 {
 {
-
 }
 }
-

+ 41 - 44
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.h

@@ -20,7 +20,7 @@ subject to the following restrictions:
 class btCollisionAlgorithm;
 class btCollisionAlgorithm;
 struct btBroadphaseProxy;
 struct btBroadphaseProxy;
 class btRigidBody;
 class btRigidBody;
-class	btCollisionObject;
+class btCollisionObject;
 class btOverlappingPairCache;
 class btOverlappingPairCache;
 struct btCollisionObjectWrapper;
 struct btCollisionObjectWrapper;
 
 
@@ -35,33 +35,34 @@ struct btDispatcherInfo
 		DISPATCH_CONTINUOUS
 		DISPATCH_CONTINUOUS
 	};
 	};
 	btDispatcherInfo()
 	btDispatcherInfo()
-		:m_timeStep(btScalar(0.)),
-		m_stepCount(0),
-		m_dispatchFunc(DISPATCH_DISCRETE),
-		m_timeOfImpact(btScalar(1.)),
-		m_useContinuous(true),
-		m_debugDraw(0),
-		m_enableSatConvex(false),
-		m_enableSPU(true),
-		m_useEpa(true),
-		m_allowedCcdPenetration(btScalar(0.04)),
-		m_useConvexConservativeDistanceUtil(false),
-		m_convexConservativeDistanceThreshold(0.0f)
+		: m_timeStep(btScalar(0.)),
+		  m_stepCount(0),
+		  m_dispatchFunc(DISPATCH_DISCRETE),
+		  m_timeOfImpact(btScalar(1.)),
+		  m_useContinuous(true),
+		  m_debugDraw(0),
+		  m_enableSatConvex(false),
+		  m_enableSPU(true),
+		  m_useEpa(true),
+		  m_allowedCcdPenetration(btScalar(0.04)),
+		  m_useConvexConservativeDistanceUtil(false),
+		  m_convexConservativeDistanceThreshold(0.0f),
+		  m_deterministicOverlappingPairs(false)
 	{
 	{
-
 	}
 	}
-	btScalar	m_timeStep;
-	int			m_stepCount;
-	int			m_dispatchFunc;
-	mutable btScalar	m_timeOfImpact;
-	bool		m_useContinuous;
-	class btIDebugDraw*	m_debugDraw;
-	bool		m_enableSatConvex;
-	bool		m_enableSPU;
-	bool		m_useEpa;
-	btScalar	m_allowedCcdPenetration;
-	bool		m_useConvexConservativeDistanceUtil;
-	btScalar	m_convexConservativeDistanceThreshold;
+	btScalar m_timeStep;
+	int m_stepCount;
+	int m_dispatchFunc;
+	mutable btScalar m_timeOfImpact;
+	bool m_useContinuous;
+	class btIDebugDraw* m_debugDraw;
+	bool m_enableSatConvex;
+	bool m_enableSPU;
+	bool m_useEpa;
+	btScalar m_allowedCcdPenetration;
+	bool m_useConvexConservativeDistanceUtil;
+	btScalar m_convexConservativeDistanceThreshold;
+	bool m_deterministicOverlappingPairs;
 };
 };
 
 
 enum ebtDispatcherQueryType
 enum ebtDispatcherQueryType
@@ -74,40 +75,36 @@ enum ebtDispatcherQueryType
 ///For example for pairwise collision detection, calculating contact points stored in btPersistentManifold or user callbacks (game logic).
 ///For example for pairwise collision detection, calculating contact points stored in btPersistentManifold or user callbacks (game logic).
 class btDispatcher
 class btDispatcher
 {
 {
-
-
 public:
 public:
-	virtual ~btDispatcher() ;
+	virtual ~btDispatcher();
 
 
-	virtual btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType) = 0;
+	virtual btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType) = 0;
 
 
-	virtual btPersistentManifold*	getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1)=0;
+	virtual btPersistentManifold* getNewManifold(const btCollisionObject* b0, const btCollisionObject* b1) = 0;
 
 
-	virtual void releaseManifold(btPersistentManifold* manifold)=0;
+	virtual void releaseManifold(btPersistentManifold* manifold) = 0;
 
 
-	virtual void clearManifold(btPersistentManifold* manifold)=0;
+	virtual void clearManifold(btPersistentManifold* manifold) = 0;
 
 
-	virtual bool	needsCollision(const btCollisionObject* body0,const btCollisionObject* body1) = 0;
+	virtual bool needsCollision(const btCollisionObject* body0, const btCollisionObject* body1) = 0;
 
 
-	virtual bool	needsResponse(const btCollisionObject* body0,const btCollisionObject* body1)=0;
+	virtual bool needsResponse(const btCollisionObject* body0, const btCollisionObject* body1) = 0;
 
 
-	virtual void	dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher)  =0;
+	virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& dispatchInfo, btDispatcher* dispatcher) = 0;
 
 
 	virtual int getNumManifolds() const = 0;
 	virtual int getNumManifolds() const = 0;
 
 
 	virtual btPersistentManifold* getManifoldByIndexInternal(int index) = 0;
 	virtual btPersistentManifold* getManifoldByIndexInternal(int index) = 0;
 
 
-	virtual	btPersistentManifold**	getInternalManifoldPointer() = 0;
+	virtual btPersistentManifold** getInternalManifoldPointer() = 0;
 
 
-	virtual	btPoolAllocator*	getInternalManifoldPool() = 0;
+	virtual btPoolAllocator* getInternalManifoldPool() = 0;
 
 
-	virtual	const btPoolAllocator*	getInternalManifoldPool() const = 0;
+	virtual const btPoolAllocator* getInternalManifoldPool() const = 0;
 
 
-	virtual	void* allocateCollisionAlgorithm(int size)  = 0;
-
-	virtual	void freeCollisionAlgorithm(void* ptr) = 0;
+	virtual void* allocateCollisionAlgorithm(int size) = 0;
 
 
+	virtual void freeCollisionAlgorithm(void* ptr) = 0;
 };
 };
 
 
-
-#endif //BT_DISPATCHER_H
+#endif  //BT_DISPATCHER_H

+ 171 - 192
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp

@@ -13,8 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
-
 #include "btOverlappingPairCache.h"
 #include "btOverlappingPairCache.h"
 
 
 #include "btDispatcher.h"
 #include "btDispatcher.h"
@@ -23,127 +21,95 @@ subject to the following restrictions:
 
 
 #include <stdio.h>
 #include <stdio.h>
 
 
-int	gOverlappingPairs = 0;
-
-int gRemovePairs =0;
-int gAddedPairs =0;
-int gFindPairs =0;
-
-
-
-
-btHashedOverlappingPairCache::btHashedOverlappingPairCache():
-	m_overlapFilterCallback(0),
-	m_ghostPairCallback(0)
+btHashedOverlappingPairCache::btHashedOverlappingPairCache() : m_overlapFilterCallback(0),
+															   m_ghostPairCallback(0)
 {
 {
-	int initialAllocatedSize= 2;
+	int initialAllocatedSize = 2;
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	growTables();
 	growTables();
 }
 }
 
 
-
-
-
 btHashedOverlappingPairCache::~btHashedOverlappingPairCache()
 btHashedOverlappingPairCache::~btHashedOverlappingPairCache()
 {
 {
 }
 }
 
 
-
-
-void	btHashedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher)
+void btHashedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair, btDispatcher* dispatcher)
 {
 {
 	if (pair.m_algorithm && dispatcher)
 	if (pair.m_algorithm && dispatcher)
 	{
 	{
 		{
 		{
 			pair.m_algorithm->~btCollisionAlgorithm();
 			pair.m_algorithm->~btCollisionAlgorithm();
 			dispatcher->freeCollisionAlgorithm(pair.m_algorithm);
 			dispatcher->freeCollisionAlgorithm(pair.m_algorithm);
-			pair.m_algorithm=0;
+			pair.m_algorithm = 0;
 		}
 		}
 	}
 	}
 }
 }
 
 
-
-
-
-void	btHashedOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy,btDispatcher* dispatcher)
+void btHashedOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy, btDispatcher* dispatcher)
 {
 {
-
-	class	CleanPairCallback : public btOverlapCallback
+	class CleanPairCallback : public btOverlapCallback
 	{
 	{
 		btBroadphaseProxy* m_cleanProxy;
 		btBroadphaseProxy* m_cleanProxy;
-		btOverlappingPairCache*	m_pairCache;
+		btOverlappingPairCache* m_pairCache;
 		btDispatcher* m_dispatcher;
 		btDispatcher* m_dispatcher;
 
 
 	public:
 	public:
-		CleanPairCallback(btBroadphaseProxy* cleanProxy,btOverlappingPairCache* pairCache,btDispatcher* dispatcher)
-			:m_cleanProxy(cleanProxy),
-			m_pairCache(pairCache),
-			m_dispatcher(dispatcher)
+		CleanPairCallback(btBroadphaseProxy* cleanProxy, btOverlappingPairCache* pairCache, btDispatcher* dispatcher)
+			: m_cleanProxy(cleanProxy),
+			  m_pairCache(pairCache),
+			  m_dispatcher(dispatcher)
 		{
 		{
 		}
 		}
-		virtual	bool	processOverlap(btBroadphasePair& pair)
+		virtual bool processOverlap(btBroadphasePair& pair)
 		{
 		{
 			if ((pair.m_pProxy0 == m_cleanProxy) ||
 			if ((pair.m_pProxy0 == m_cleanProxy) ||
 				(pair.m_pProxy1 == m_cleanProxy))
 				(pair.m_pProxy1 == m_cleanProxy))
 			{
 			{
-				m_pairCache->cleanOverlappingPair(pair,m_dispatcher);
+				m_pairCache->cleanOverlappingPair(pair, m_dispatcher);
 			}
 			}
 			return false;
 			return false;
 		}
 		}
-		
 	};
 	};
 
 
-	CleanPairCallback cleanPairs(proxy,this,dispatcher);
-
-	processAllOverlappingPairs(&cleanPairs,dispatcher);
+	CleanPairCallback cleanPairs(proxy, this, dispatcher);
 
 
+	processAllOverlappingPairs(&cleanPairs, dispatcher);
 }
 }
 
 
-
-
-
-void	btHashedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher)
+void btHashedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher)
 {
 {
-
-	class	RemovePairCallback : public btOverlapCallback
+	class RemovePairCallback : public btOverlapCallback
 	{
 	{
 		btBroadphaseProxy* m_obsoleteProxy;
 		btBroadphaseProxy* m_obsoleteProxy;
 
 
 	public:
 	public:
 		RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
 		RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
-			:m_obsoleteProxy(obsoleteProxy)
+			: m_obsoleteProxy(obsoleteProxy)
 		{
 		{
 		}
 		}
-		virtual	bool	processOverlap(btBroadphasePair& pair)
+		virtual bool processOverlap(btBroadphasePair& pair)
 		{
 		{
 			return ((pair.m_pProxy0 == m_obsoleteProxy) ||
 			return ((pair.m_pProxy0 == m_obsoleteProxy) ||
-				(pair.m_pProxy1 == m_obsoleteProxy));
+					(pair.m_pProxy1 == m_obsoleteProxy));
 		}
 		}
-		
 	};
 	};
 
 
-
 	RemovePairCallback removeCallback(proxy);
 	RemovePairCallback removeCallback(proxy);
 
 
-	processAllOverlappingPairs(&removeCallback,dispatcher);
+	processAllOverlappingPairs(&removeCallback, dispatcher);
 }
 }
 
 
-
-
-
-
 btBroadphasePair* btHashedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 btBroadphasePair* btHashedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 {
 {
-	gFindPairs++;
-	if(proxy0->m_uniqueId>proxy1->m_uniqueId) 
-		btSwap(proxy0,proxy1);
+	if (proxy0->m_uniqueId > proxy1->m_uniqueId)
+		btSwap(proxy0, proxy1);
 	int proxyId1 = proxy0->getUid();
 	int proxyId1 = proxy0->getUid();
 	int proxyId2 = proxy1->getUid();
 	int proxyId2 = proxy1->getUid();
 
 
-	/*if (proxyId1 > proxyId2) 
+	/*if (proxyId1 > proxyId2)
 		btSwap(proxyId1, proxyId2);*/
 		btSwap(proxyId1, proxyId2);*/
 
 
-	int hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1), static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity()-1));
+	int hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1), static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
 
 
 	if (hash >= m_hashTable.size())
 	if (hash >= m_hashTable.size())
 	{
 	{
@@ -168,9 +134,8 @@ btBroadphasePair* btHashedOverlappingPairCache::findPair(btBroadphaseProxy* prox
 
 
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-void	btHashedOverlappingPairCache::growTables()
+void btHashedOverlappingPairCache::growTables()
 {
 {
-
 	int newCapacity = m_overlappingPairArray.capacity();
 	int newCapacity = m_overlappingPairArray.capacity();
 
 
 	if (m_hashTable.size() < newCapacity)
 	if (m_hashTable.size() < newCapacity)
@@ -181,10 +146,9 @@ void	btHashedOverlappingPairCache::growTables()
 		m_hashTable.resize(newCapacity);
 		m_hashTable.resize(newCapacity);
 		m_next.resize(newCapacity);
 		m_next.resize(newCapacity);
 
 
-
 		int i;
 		int i;
 
 
-		for (i= 0; i < newCapacity; ++i)
+		for (i = 0; i < newCapacity; ++i)
 		{
 		{
 			m_hashTable[i] = BT_NULL_PAIR;
 			m_hashTable[i] = BT_NULL_PAIR;
 		}
 		}
@@ -193,35 +157,31 @@ void	btHashedOverlappingPairCache::growTables()
 			m_next[i] = BT_NULL_PAIR;
 			m_next[i] = BT_NULL_PAIR;
 		}
 		}
 
 
-		for(i=0;i<curHashtableSize;i++)
+		for (i = 0; i < curHashtableSize; i++)
 		{
 		{
-	
 			const btBroadphasePair& pair = m_overlappingPairArray[i];
 			const btBroadphasePair& pair = m_overlappingPairArray[i];
 			int proxyId1 = pair.m_pProxy0->getUid();
 			int proxyId1 = pair.m_pProxy0->getUid();
 			int proxyId2 = pair.m_pProxy1->getUid();
 			int proxyId2 = pair.m_pProxy1->getUid();
 			/*if (proxyId1 > proxyId2) 
 			/*if (proxyId1 > proxyId2) 
 				btSwap(proxyId1, proxyId2);*/
 				btSwap(proxyId1, proxyId2);*/
-			int	hashValue = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1),static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity()-1));	// New hash value with new mask
+			int hashValue = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1), static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));  // New hash value with new mask
 			m_next[i] = m_hashTable[hashValue];
 			m_next[i] = m_hashTable[hashValue];
 			m_hashTable[hashValue] = i;
 			m_hashTable[hashValue] = i;
 		}
 		}
-
-
 	}
 	}
 }
 }
 
 
 btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 {
 {
-	if(proxy0->m_uniqueId>proxy1->m_uniqueId) 
-		btSwap(proxy0,proxy1);
+	if (proxy0->m_uniqueId > proxy1->m_uniqueId)
+		btSwap(proxy0, proxy1);
 	int proxyId1 = proxy0->getUid();
 	int proxyId1 = proxy0->getUid();
 	int proxyId2 = proxy1->getUid();
 	int proxyId2 = proxy1->getUid();
 
 
 	/*if (proxyId1 > proxyId2) 
 	/*if (proxyId1 > proxyId2) 
 		btSwap(proxyId1, proxyId2);*/
 		btSwap(proxyId1, proxyId2);*/
 
 
-	int	hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1),static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity()-1));	// New hash value with new mask
-
+	int hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1), static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));  // New hash value with new mask
 
 
 	btBroadphasePair* pair = internalFindPair(proxy0, proxy1, hash);
 	btBroadphasePair* pair = internalFindPair(proxy0, proxy1, hash);
 	if (pair != NULL)
 	if (pair != NULL)
@@ -243,7 +203,7 @@ btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProx
 
 
 	//this is where we add an actual pair, so also call the 'ghost'
 	//this is where we add an actual pair, so also call the 'ghost'
 	if (m_ghostPairCallback)
 	if (m_ghostPairCallback)
-		m_ghostPairCallback->addOverlappingPair(proxy0,proxy1);
+		m_ghostPairCallback->addOverlappingPair(proxy0, proxy1);
 
 
 	int newCapacity = m_overlappingPairArray.capacity();
 	int newCapacity = m_overlappingPairArray.capacity();
 
 
@@ -251,15 +211,14 @@ btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProx
 	{
 	{
 		growTables();
 		growTables();
 		//hash with new capacity
 		//hash with new capacity
-		hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1),static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity()-1));
+		hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1), static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
 	}
 	}
-	
-	pair = new (mem) btBroadphasePair(*proxy0,*proxy1);
-//	pair->m_pProxy0 = proxy0;
-//	pair->m_pProxy1 = proxy1;
+
+	pair = new (mem) btBroadphasePair(*proxy0, *proxy1);
+	//	pair->m_pProxy0 = proxy0;
+	//	pair->m_pProxy1 = proxy1;
 	pair->m_algorithm = 0;
 	pair->m_algorithm = 0;
 	pair->m_internalTmpValue = 0;
 	pair->m_internalTmpValue = 0;
-	
 
 
 	m_next[count] = m_hashTable[hash];
 	m_next[count] = m_hashTable[hash];
 	m_hashTable[hash] = count;
 	m_hashTable[hash] = count;
@@ -267,20 +226,17 @@ btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProx
 	return pair;
 	return pair;
 }
 }
 
 
-
-
-void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1,btDispatcher* dispatcher)
+void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1, btDispatcher* dispatcher)
 {
 {
-	gRemovePairs++;
-	if(proxy0->m_uniqueId>proxy1->m_uniqueId) 
-		btSwap(proxy0,proxy1);
+	if (proxy0->m_uniqueId > proxy1->m_uniqueId)
+		btSwap(proxy0, proxy1);
 	int proxyId1 = proxy0->getUid();
 	int proxyId1 = proxy0->getUid();
 	int proxyId2 = proxy1->getUid();
 	int proxyId2 = proxy1->getUid();
 
 
-	/*if (proxyId1 > proxyId2) 
+	/*if (proxyId1 > proxyId2)
 		btSwap(proxyId1, proxyId2);*/
 		btSwap(proxyId1, proxyId2);*/
 
 
-	int	hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1),static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity()-1));
+	int hash = static_cast<int>(getHash(static_cast<unsigned int>(proxyId1), static_cast<unsigned int>(proxyId2)) & (m_overlappingPairArray.capacity() - 1));
 
 
 	btBroadphasePair* pair = internalFindPair(proxy0, proxy1, hash);
 	btBroadphasePair* pair = internalFindPair(proxy0, proxy1, hash);
 	if (pair == NULL)
 	if (pair == NULL)
@@ -288,7 +244,7 @@ void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 		return 0;
 		return 0;
 	}
 	}
 
 
-	cleanOverlappingPair(*pair,dispatcher);
+	cleanOverlappingPair(*pair, dispatcher);
 
 
 	void* userData = pair->m_internalInfo1;
 	void* userData = pair->m_internalInfo1;
 
 
@@ -326,7 +282,7 @@ void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 	int lastPairIndex = m_overlappingPairArray.size() - 1;
 	int lastPairIndex = m_overlappingPairArray.size() - 1;
 
 
 	if (m_ghostPairCallback)
 	if (m_ghostPairCallback)
-		m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1,dispatcher);
+		m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1, dispatcher);
 
 
 	// If the removed pair is the last pair, we are done.
 	// If the removed pair is the last pair, we are done.
 	if (lastPairIndex == pairIndex)
 	if (lastPairIndex == pairIndex)
@@ -337,8 +293,8 @@ void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 
 
 	// Remove the last pair from the hash table.
 	// Remove the last pair from the hash table.
 	const btBroadphasePair* last = &m_overlappingPairArray[lastPairIndex];
 	const btBroadphasePair* last = &m_overlappingPairArray[lastPairIndex];
-		/* missing swap here too, Nat. */ 
-	int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_pProxy0->getUid()), static_cast<unsigned int>(last->m_pProxy1->getUid())) & (m_overlappingPairArray.capacity()-1));
+	/* missing swap here too, Nat. */
+	int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_pProxy0->getUid()), static_cast<unsigned int>(last->m_pProxy1->getUid())) & (m_overlappingPairArray.capacity() - 1));
 
 
 	index = m_hashTable[lastHash];
 	index = m_hashTable[lastHash];
 	btAssert(index != BT_NULL_PAIR);
 	btAssert(index != BT_NULL_PAIR);
@@ -373,43 +329,105 @@ void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 }
 }
 //#include <stdio.h>
 //#include <stdio.h>
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btQuickprof.h"
-void	btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback,btDispatcher* dispatcher)
+void btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback, btDispatcher* dispatcher)
 {
 {
 	BT_PROFILE("btHashedOverlappingPairCache::processAllOverlappingPairs");
 	BT_PROFILE("btHashedOverlappingPairCache::processAllOverlappingPairs");
 	int i;
 	int i;
 
 
-//	printf("m_overlappingPairArray.size()=%d\n",m_overlappingPairArray.size());
-	for (i=0;i<m_overlappingPairArray.size();)
+	//	printf("m_overlappingPairArray.size()=%d\n",m_overlappingPairArray.size());
+	for (i = 0; i < m_overlappingPairArray.size();)
 	{
 	{
-	
 		btBroadphasePair* pair = &m_overlappingPairArray[i];
 		btBroadphasePair* pair = &m_overlappingPairArray[i];
 		if (callback->processOverlap(*pair))
 		if (callback->processOverlap(*pair))
 		{
 		{
-			removeOverlappingPair(pair->m_pProxy0,pair->m_pProxy1,dispatcher);
-
-			gOverlappingPairs--;
-		} else
+			removeOverlappingPair(pair->m_pProxy0, pair->m_pProxy1, dispatcher);
+		}
+		else
 		{
 		{
 			i++;
 			i++;
 		}
 		}
 	}
 	}
 }
 }
 
 
-void	btHashedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher)
+struct MyPairIndex
+{
+	int m_orgIndex;
+	int m_uidA0;
+	int m_uidA1;
+};
+
+class MyPairIndeSortPredicate
+{
+public:
+	bool operator()(const MyPairIndex& a, const MyPairIndex& b) const
+	{
+		const int uidA0 = a.m_uidA0;
+		const int uidB0 = b.m_uidA0;
+		const int uidA1 = a.m_uidA1;
+		const int uidB1 = b.m_uidA1;
+		return uidA0 > uidB0 || (uidA0 == uidB0 && uidA1 > uidB1);
+	}
+};
+
+void btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback, btDispatcher* dispatcher, const struct btDispatcherInfo& dispatchInfo)
+{
+	if (dispatchInfo.m_deterministicOverlappingPairs)
+	{
+		btBroadphasePairArray& pa = getOverlappingPairArray();
+		btAlignedObjectArray<MyPairIndex> indices;
+		{
+			BT_PROFILE("sortOverlappingPairs");
+			indices.resize(pa.size());
+			for (int i = 0; i < indices.size(); i++)
+			{
+				const btBroadphasePair& p = pa[i];
+				const int uidA0 = p.m_pProxy0 ? p.m_pProxy0->m_uniqueId : -1;
+				const int uidA1 = p.m_pProxy1 ? p.m_pProxy1->m_uniqueId : -1;
+
+				indices[i].m_uidA0 = uidA0;
+				indices[i].m_uidA1 = uidA1;
+				indices[i].m_orgIndex = i;
+			}
+			indices.quickSort(MyPairIndeSortPredicate());
+		}
+		{
+			BT_PROFILE("btHashedOverlappingPairCache::processAllOverlappingPairs");
+			int i;
+			for (i = 0; i < indices.size();)
+			{
+				btBroadphasePair* pair = &pa[indices[i].m_orgIndex];
+				if (callback->processOverlap(*pair))
+				{
+					removeOverlappingPair(pair->m_pProxy0, pair->m_pProxy1, dispatcher);
+				}
+				else
+				{
+					i++;
+				}
+			}
+		}
+	}
+	else
+	{
+		processAllOverlappingPairs(callback, dispatcher);
+	}
+}
+
+void btHashedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher)
 {
 {
 	///need to keep hashmap in sync with pair address, so rebuild all
 	///need to keep hashmap in sync with pair address, so rebuild all
 	btBroadphasePairArray tmpPairs;
 	btBroadphasePairArray tmpPairs;
 	int i;
 	int i;
-	for (i=0;i<m_overlappingPairArray.size();i++)
+	for (i = 0; i < m_overlappingPairArray.size(); i++)
 	{
 	{
 		tmpPairs.push_back(m_overlappingPairArray[i]);
 		tmpPairs.push_back(m_overlappingPairArray[i]);
 	}
 	}
 
 
-	for (i=0;i<tmpPairs.size();i++)
+	for (i = 0; i < tmpPairs.size(); i++)
 	{
 	{
-		removeOverlappingPair(tmpPairs[i].m_pProxy0,tmpPairs[i].m_pProxy1,dispatcher);
+		removeOverlappingPair(tmpPairs[i].m_pProxy0, tmpPairs[i].m_pProxy1, dispatcher);
 	}
 	}
-	
+
 	for (i = 0; i < m_next.size(); i++)
 	for (i = 0; i < m_next.size(); i++)
 	{
 	{
 		m_next[i] = BT_NULL_PAIR;
 		m_next[i] = BT_NULL_PAIR;
@@ -417,32 +435,28 @@ void	btHashedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher
 
 
 	tmpPairs.quickSort(btBroadphasePairSortPredicate());
 	tmpPairs.quickSort(btBroadphasePairSortPredicate());
 
 
-	for (i=0;i<tmpPairs.size();i++)
+	for (i = 0; i < tmpPairs.size(); i++)
 	{
 	{
-		addOverlappingPair(tmpPairs[i].m_pProxy0,tmpPairs[i].m_pProxy1);
+		addOverlappingPair(tmpPairs[i].m_pProxy0, tmpPairs[i].m_pProxy1);
 	}
 	}
-
-	
 }
 }
 
 
-
-void*	btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1, btDispatcher* dispatcher )
+void* btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1, btDispatcher* dispatcher)
 {
 {
 	if (!hasDeferredRemoval())
 	if (!hasDeferredRemoval())
 	{
 	{
-		btBroadphasePair findPair(*proxy0,*proxy1);
+		btBroadphasePair findPair(*proxy0, *proxy1);
 
 
 		int findIndex = m_overlappingPairArray.findLinearSearch(findPair);
 		int findIndex = m_overlappingPairArray.findLinearSearch(findPair);
 		if (findIndex < m_overlappingPairArray.size())
 		if (findIndex < m_overlappingPairArray.size())
 		{
 		{
-			gOverlappingPairs--;
 			btBroadphasePair& pair = m_overlappingPairArray[findIndex];
 			btBroadphasePair& pair = m_overlappingPairArray[findIndex];
 			void* userData = pair.m_internalInfo1;
 			void* userData = pair.m_internalInfo1;
-			cleanOverlappingPair(pair,dispatcher);
+			cleanOverlappingPair(pair, dispatcher);
 			if (m_ghostPairCallback)
 			if (m_ghostPairCallback)
-				m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1,dispatcher);
-			
-			m_overlappingPairArray.swap(findIndex,m_overlappingPairArray.capacity()-1);
+				m_ghostPairCallback->removeOverlappingPair(proxy0, proxy1, dispatcher);
+
+			m_overlappingPairArray.swap(findIndex, m_overlappingPairArray.capacity() - 1);
 			m_overlappingPairArray.pop_back();
 			m_overlappingPairArray.pop_back();
 			return userData;
 			return userData;
 		}
 		}
@@ -451,99 +465,73 @@ void*	btSortedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 	return 0;
 	return 0;
 }
 }
 
 
-
-
-
-
-
-
-
-btBroadphasePair*	btSortedOverlappingPairCache::addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+btBroadphasePair* btSortedOverlappingPairCache::addOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 {
 {
 	//don't add overlap with own
 	//don't add overlap with own
 	btAssert(proxy0 != proxy1);
 	btAssert(proxy0 != proxy1);
 
 
-	if (!needsBroadphaseCollision(proxy0,proxy1))
+	if (!needsBroadphaseCollision(proxy0, proxy1))
 		return 0;
 		return 0;
-	
+
 	void* mem = &m_overlappingPairArray.expandNonInitializing();
 	void* mem = &m_overlappingPairArray.expandNonInitializing();
-	btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1);
-	
-	gOverlappingPairs++;
-	gAddedPairs++;
-	
+	btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0, *proxy1);
+
 	if (m_ghostPairCallback)
 	if (m_ghostPairCallback)
 		m_ghostPairCallback->addOverlappingPair(proxy0, proxy1);
 		m_ghostPairCallback->addOverlappingPair(proxy0, proxy1);
 	return pair;
 	return pair;
-	
 }
 }
 
 
 ///this findPair becomes really slow. Either sort the list to speedup the query, or
 ///this findPair becomes really slow. Either sort the list to speedup the query, or
 ///use a different solution. It is mainly used for Removing overlapping pairs. Removal could be delayed.
 ///use a different solution. It is mainly used for Removing overlapping pairs. Removal could be delayed.
 ///we could keep a linked list in each proxy, and store pair in one of the proxies (with lowest memory address)
 ///we could keep a linked list in each proxy, and store pair in one of the proxies (with lowest memory address)
 ///Also we can use a 2D bitmap, which can be useful for a future GPU implementation
 ///Also we can use a 2D bitmap, which can be useful for a future GPU implementation
- btBroadphasePair*	btSortedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+btBroadphasePair* btSortedOverlappingPairCache::findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 {
 {
-	if (!needsBroadphaseCollision(proxy0,proxy1))
+	if (!needsBroadphaseCollision(proxy0, proxy1))
 		return 0;
 		return 0;
 
 
-	btBroadphasePair tmpPair(*proxy0,*proxy1);
+	btBroadphasePair tmpPair(*proxy0, *proxy1);
 	int findIndex = m_overlappingPairArray.findLinearSearch(tmpPair);
 	int findIndex = m_overlappingPairArray.findLinearSearch(tmpPair);
 
 
 	if (findIndex < m_overlappingPairArray.size())
 	if (findIndex < m_overlappingPairArray.size())
 	{
 	{
 		//btAssert(it != m_overlappingPairSet.end());
 		//btAssert(it != m_overlappingPairSet.end());
-		 btBroadphasePair* pair = &m_overlappingPairArray[findIndex];
+		btBroadphasePair* pair = &m_overlappingPairArray[findIndex];
 		return pair;
 		return pair;
 	}
 	}
 	return 0;
 	return 0;
 }
 }
 
 
-
-
-
-
-
-
-
-
-
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-void	btSortedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback,btDispatcher* dispatcher)
+void btSortedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback, btDispatcher* dispatcher)
 {
 {
-
 	int i;
 	int i;
 
 
-	for (i=0;i<m_overlappingPairArray.size();)
+	for (i = 0; i < m_overlappingPairArray.size();)
 	{
 	{
-	
 		btBroadphasePair* pair = &m_overlappingPairArray[i];
 		btBroadphasePair* pair = &m_overlappingPairArray[i];
 		if (callback->processOverlap(*pair))
 		if (callback->processOverlap(*pair))
 		{
 		{
-			cleanOverlappingPair(*pair,dispatcher);
+			cleanOverlappingPair(*pair, dispatcher);
 			pair->m_pProxy0 = 0;
 			pair->m_pProxy0 = 0;
 			pair->m_pProxy1 = 0;
 			pair->m_pProxy1 = 0;
-			m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
+			m_overlappingPairArray.swap(i, m_overlappingPairArray.size() - 1);
 			m_overlappingPairArray.pop_back();
 			m_overlappingPairArray.pop_back();
-			gOverlappingPairs--;
-		} else
+		}
+		else
 		{
 		{
 			i++;
 			i++;
 		}
 		}
 	}
 	}
 }
 }
 
 
-
-
-
-btSortedOverlappingPairCache::btSortedOverlappingPairCache():
-	m_blockedForChanges(false),
-	m_hasDeferredRemoval(true),
-	m_overlapFilterCallback(0),
-	m_ghostPairCallback(0)
+btSortedOverlappingPairCache::btSortedOverlappingPairCache() : m_blockedForChanges(false),
+															   m_hasDeferredRemoval(true),
+															   m_overlapFilterCallback(0),
+															   m_ghostPairCallback(0)
 {
 {
-	int initialAllocatedSize= 2;
+	int initialAllocatedSize = 2;
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 }
 }
 
 
@@ -551,82 +539,73 @@ btSortedOverlappingPairCache::~btSortedOverlappingPairCache()
 {
 {
 }
 }
 
 
-void	btSortedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher)
+void btSortedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair, btDispatcher* dispatcher)
 {
 {
 	if (pair.m_algorithm)
 	if (pair.m_algorithm)
 	{
 	{
 		{
 		{
 			pair.m_algorithm->~btCollisionAlgorithm();
 			pair.m_algorithm->~btCollisionAlgorithm();
 			dispatcher->freeCollisionAlgorithm(pair.m_algorithm);
 			dispatcher->freeCollisionAlgorithm(pair.m_algorithm);
-			pair.m_algorithm=0;
-			gRemovePairs--;
+			pair.m_algorithm = 0;
 		}
 		}
 	}
 	}
 }
 }
 
 
-
-void	btSortedOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy,btDispatcher* dispatcher)
+void btSortedOverlappingPairCache::cleanProxyFromPairs(btBroadphaseProxy* proxy, btDispatcher* dispatcher)
 {
 {
-
-	class	CleanPairCallback : public btOverlapCallback
+	class CleanPairCallback : public btOverlapCallback
 	{
 	{
 		btBroadphaseProxy* m_cleanProxy;
 		btBroadphaseProxy* m_cleanProxy;
-		btOverlappingPairCache*	m_pairCache;
+		btOverlappingPairCache* m_pairCache;
 		btDispatcher* m_dispatcher;
 		btDispatcher* m_dispatcher;
 
 
 	public:
 	public:
-		CleanPairCallback(btBroadphaseProxy* cleanProxy,btOverlappingPairCache* pairCache,btDispatcher* dispatcher)
-			:m_cleanProxy(cleanProxy),
-			m_pairCache(pairCache),
-			m_dispatcher(dispatcher)
+		CleanPairCallback(btBroadphaseProxy* cleanProxy, btOverlappingPairCache* pairCache, btDispatcher* dispatcher)
+			: m_cleanProxy(cleanProxy),
+			  m_pairCache(pairCache),
+			  m_dispatcher(dispatcher)
 		{
 		{
 		}
 		}
-		virtual	bool	processOverlap(btBroadphasePair& pair)
+		virtual bool processOverlap(btBroadphasePair& pair)
 		{
 		{
 			if ((pair.m_pProxy0 == m_cleanProxy) ||
 			if ((pair.m_pProxy0 == m_cleanProxy) ||
 				(pair.m_pProxy1 == m_cleanProxy))
 				(pair.m_pProxy1 == m_cleanProxy))
 			{
 			{
-				m_pairCache->cleanOverlappingPair(pair,m_dispatcher);
+				m_pairCache->cleanOverlappingPair(pair, m_dispatcher);
 			}
 			}
 			return false;
 			return false;
 		}
 		}
-		
 	};
 	};
 
 
-	CleanPairCallback cleanPairs(proxy,this,dispatcher);
-
-	processAllOverlappingPairs(&cleanPairs,dispatcher);
+	CleanPairCallback cleanPairs(proxy, this, dispatcher);
 
 
+	processAllOverlappingPairs(&cleanPairs, dispatcher);
 }
 }
 
 
-
-void	btSortedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher)
+void btSortedOverlappingPairCache::removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher)
 {
 {
-
-	class	RemovePairCallback : public btOverlapCallback
+	class RemovePairCallback : public btOverlapCallback
 	{
 	{
 		btBroadphaseProxy* m_obsoleteProxy;
 		btBroadphaseProxy* m_obsoleteProxy;
 
 
 	public:
 	public:
 		RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
 		RemovePairCallback(btBroadphaseProxy* obsoleteProxy)
-			:m_obsoleteProxy(obsoleteProxy)
+			: m_obsoleteProxy(obsoleteProxy)
 		{
 		{
 		}
 		}
-		virtual	bool	processOverlap(btBroadphasePair& pair)
+		virtual bool processOverlap(btBroadphasePair& pair)
 		{
 		{
 			return ((pair.m_pProxy0 == m_obsoleteProxy) ||
 			return ((pair.m_pProxy0 == m_obsoleteProxy) ||
-				(pair.m_pProxy1 == m_obsoleteProxy));
+					(pair.m_pProxy1 == m_obsoleteProxy));
 		}
 		}
-		
 	};
 	};
 
 
 	RemovePairCallback removeCallback(proxy);
 	RemovePairCallback removeCallback(proxy);
 
 
-	processAllOverlappingPairs(&removeCallback,dispatcher);
+	processAllOverlappingPairs(&removeCallback, dispatcher);
 }
 }
 
 
-void	btSortedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher)
+void btSortedOverlappingPairCache::sortOverlappingPairs(btDispatcher* dispatcher)
 {
 {
 	//should already be sorted
 	//should already be sorted
 }
 }
-

+ 168 - 206
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h

@@ -16,7 +16,6 @@ subject to the following restrictions:
 #ifndef BT_OVERLAPPING_PAIR_CACHE_H
 #ifndef BT_OVERLAPPING_PAIR_CACHE_H
 #define BT_OVERLAPPING_PAIR_CACHE_H
 #define BT_OVERLAPPING_PAIR_CACHE_H
 
 
-
 #include "btBroadphaseInterface.h"
 #include "btBroadphaseInterface.h"
 #include "btBroadphaseProxy.h"
 #include "btBroadphaseProxy.h"
 #include "btOverlappingPairCallback.h"
 #include "btOverlappingPairCallback.h"
@@ -24,177 +23,164 @@ subject to the following restrictions:
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
 class btDispatcher;
 class btDispatcher;
 
 
-typedef btAlignedObjectArray<btBroadphasePair>	btBroadphasePairArray;
+typedef btAlignedObjectArray<btBroadphasePair> btBroadphasePairArray;
 
 
-struct	btOverlapCallback
+struct btOverlapCallback
 {
 {
 	virtual ~btOverlapCallback()
 	virtual ~btOverlapCallback()
-	{}
+	{
+	}
 	//return true for deletion of the pair
 	//return true for deletion of the pair
-	virtual bool	processOverlap(btBroadphasePair& pair) = 0;
-
+	virtual bool processOverlap(btBroadphasePair& pair) = 0;
 };
 };
 
 
 struct btOverlapFilterCallback
 struct btOverlapFilterCallback
 {
 {
 	virtual ~btOverlapFilterCallback()
 	virtual ~btOverlapFilterCallback()
-	{}
+	{
+	}
 	// return true when pairs need collision
 	// return true when pairs need collision
-	virtual bool	needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const = 0;
+	virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) const = 0;
 };
 };
 
 
-
-
-
-
-
-
-extern int gRemovePairs;
-extern int gAddedPairs;
-extern int gFindPairs;
-
-const int BT_NULL_PAIR=0xffffffff;
+const int BT_NULL_PAIR = 0xffffffff;
 
 
 ///The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases.
 ///The btOverlappingPairCache provides an interface for overlapping pair management (add, remove, storage), used by the btBroadphaseInterface broadphases.
 ///The btHashedOverlappingPairCache and btSortedOverlappingPairCache classes are two implementations.
 ///The btHashedOverlappingPairCache and btSortedOverlappingPairCache classes are two implementations.
 class btOverlappingPairCache : public btOverlappingPairCallback
 class btOverlappingPairCache : public btOverlappingPairCallback
 {
 {
 public:
 public:
-	virtual ~btOverlappingPairCache() {} // this is needed so we can get to the derived class destructor
+	virtual ~btOverlappingPairCache() {}  // this is needed so we can get to the derived class destructor
 
 
-	virtual btBroadphasePair*	getOverlappingPairArrayPtr() = 0;
-	
-	virtual const btBroadphasePair*	getOverlappingPairArrayPtr() const = 0;
+	virtual btBroadphasePair* getOverlappingPairArrayPtr() = 0;
 
 
-	virtual btBroadphasePairArray&	getOverlappingPairArray() = 0;
+	virtual const btBroadphasePair* getOverlappingPairArrayPtr() const = 0;
 
 
-	virtual	void	cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher) = 0;
+	virtual btBroadphasePairArray& getOverlappingPairArray() = 0;
 
 
-	virtual int getNumOverlappingPairs() const = 0;
+	virtual void cleanOverlappingPair(btBroadphasePair& pair, btDispatcher* dispatcher) = 0;
 
 
-	virtual void	cleanProxyFromPairs(btBroadphaseProxy* proxy,btDispatcher* dispatcher) = 0;
+	virtual int getNumOverlappingPairs() const = 0;
+	virtual bool needsBroadphaseCollision(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1) const = 0;
+	virtual btOverlapFilterCallback* getOverlapFilterCallback() = 0;
+	virtual void cleanProxyFromPairs(btBroadphaseProxy* proxy, btDispatcher* dispatcher) = 0;
 
 
-	virtual	void setOverlapFilterCallback(btOverlapFilterCallback* callback) = 0;
+	virtual void setOverlapFilterCallback(btOverlapFilterCallback* callback) = 0;
 
 
-	virtual void	processAllOverlappingPairs(btOverlapCallback*,btDispatcher* dispatcher) = 0;
+	virtual void processAllOverlappingPairs(btOverlapCallback*, btDispatcher* dispatcher) = 0;
 
 
+	virtual void processAllOverlappingPairs(btOverlapCallback* callback, btDispatcher* dispatcher, const struct btDispatcherInfo& /*dispatchInfo*/)
+	{
+		processAllOverlappingPairs(callback, dispatcher);
+	}
 	virtual btBroadphasePair* findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) = 0;
 	virtual btBroadphasePair* findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) = 0;
 
 
-	virtual bool	hasDeferredRemoval() = 0;
-
-	virtual	void	setInternalGhostPairCallback(btOverlappingPairCallback* ghostPairCallback)=0;
-
-	virtual void	sortOverlappingPairs(btDispatcher* dispatcher) = 0;
+	virtual bool hasDeferredRemoval() = 0;
 
 
+	virtual void setInternalGhostPairCallback(btOverlappingPairCallback* ghostPairCallback) = 0;
 
 
+	virtual void sortOverlappingPairs(btDispatcher* dispatcher) = 0;
 };
 };
 
 
 /// Hash-space based Pair Cache, thanks to Erin Catto, Box2D, http://www.box2d.org, and Pierre Terdiman, Codercorner, http://codercorner.com
 /// Hash-space based Pair Cache, thanks to Erin Catto, Box2D, http://www.box2d.org, and Pierre Terdiman, Codercorner, http://codercorner.com
 
 
-ATTRIBUTE_ALIGNED16(class) btHashedOverlappingPairCache : public btOverlappingPairCache
+ATTRIBUTE_ALIGNED16(class)
+btHashedOverlappingPairCache : public btOverlappingPairCache
 {
 {
-	btBroadphasePairArray	m_overlappingPairArray;
+	btBroadphasePairArray m_overlappingPairArray;
 	btOverlapFilterCallback* m_overlapFilterCallback;
 	btOverlapFilterCallback* m_overlapFilterCallback;
 
 
 protected:
 protected:
-	
-	btAlignedObjectArray<int>	m_hashTable;
-	btAlignedObjectArray<int>	m_next;
-	btOverlappingPairCallback*	m_ghostPairCallback;
-
+	btAlignedObjectArray<int> m_hashTable;
+	btAlignedObjectArray<int> m_next;
+	btOverlappingPairCallback* m_ghostPairCallback;
 
 
 public:
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
-	
+
 	btHashedOverlappingPairCache();
 	btHashedOverlappingPairCache();
 	virtual ~btHashedOverlappingPairCache();
 	virtual ~btHashedOverlappingPairCache();
 
 
-	
-	void	removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
+	void removeOverlappingPairsContainingProxy(btBroadphaseProxy * proxy, btDispatcher * dispatcher);
 
 
-	virtual void*	removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher);
-	
-	SIMD_FORCE_INLINE bool needsBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
+	virtual void* removeOverlappingPair(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1, btDispatcher * dispatcher);
+
+	SIMD_FORCE_INLINE bool needsBroadphaseCollision(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1) const
 	{
 	{
 		if (m_overlapFilterCallback)
 		if (m_overlapFilterCallback)
-			return m_overlapFilterCallback->needBroadphaseCollision(proxy0,proxy1);
+			return m_overlapFilterCallback->needBroadphaseCollision(proxy0, proxy1);
 
 
 		bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
 		bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
 		collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
 		collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
-		
+
 		return collides;
 		return collides;
 	}
 	}
 
 
 	// Add a pair and return the new pair. If the pair already exists,
 	// Add a pair and return the new pair. If the pair already exists,
 	// no new pair is created and the old one is returned.
 	// no new pair is created and the old one is returned.
-	virtual btBroadphasePair* 	addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+	virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1)
 	{
 	{
-		gAddedPairs++;
-
-		if (!needsBroadphaseCollision(proxy0,proxy1))
+		if (!needsBroadphaseCollision(proxy0, proxy1))
 			return 0;
 			return 0;
 
 
-		return internalAddPair(proxy0,proxy1);
+		return internalAddPair(proxy0, proxy1);
 	}
 	}
 
 
-	
+	void cleanProxyFromPairs(btBroadphaseProxy * proxy, btDispatcher * dispatcher);
 
 
-	void	cleanProxyFromPairs(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
+	virtual void processAllOverlappingPairs(btOverlapCallback*, btDispatcher * dispatcher);
 
 
-	
-	virtual void	processAllOverlappingPairs(btOverlapCallback*,btDispatcher* dispatcher);
+	virtual void processAllOverlappingPairs(btOverlapCallback * callback, btDispatcher * dispatcher, const struct btDispatcherInfo& dispatchInfo);
 
 
-	virtual btBroadphasePair*	getOverlappingPairArrayPtr()
+	virtual btBroadphasePair* getOverlappingPairArrayPtr()
 	{
 	{
 		return &m_overlappingPairArray[0];
 		return &m_overlappingPairArray[0];
 	}
 	}
 
 
-	const btBroadphasePair*	getOverlappingPairArrayPtr() const
+	const btBroadphasePair* getOverlappingPairArrayPtr() const
 	{
 	{
 		return &m_overlappingPairArray[0];
 		return &m_overlappingPairArray[0];
 	}
 	}
 
 
-	btBroadphasePairArray&	getOverlappingPairArray()
+	btBroadphasePairArray& getOverlappingPairArray()
 	{
 	{
 		return m_overlappingPairArray;
 		return m_overlappingPairArray;
 	}
 	}
 
 
-	const btBroadphasePairArray&	getOverlappingPairArray() const
+	const btBroadphasePairArray& getOverlappingPairArray() const
 	{
 	{
 		return m_overlappingPairArray;
 		return m_overlappingPairArray;
 	}
 	}
 
 
-	void	cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher);
-
+	void cleanOverlappingPair(btBroadphasePair & pair, btDispatcher * dispatcher);
 
 
-
-	btBroadphasePair* findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1);
+	btBroadphasePair* findPair(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1);
 
 
 	int GetCount() const { return m_overlappingPairArray.size(); }
 	int GetCount() const { return m_overlappingPairArray.size(); }
-//	btBroadphasePair* GetPairs() { return m_pairs; }
+	//	btBroadphasePair* GetPairs() { return m_pairs; }
 
 
 	btOverlapFilterCallback* getOverlapFilterCallback()
 	btOverlapFilterCallback* getOverlapFilterCallback()
 	{
 	{
 		return m_overlapFilterCallback;
 		return m_overlapFilterCallback;
 	}
 	}
 
 
-	void setOverlapFilterCallback(btOverlapFilterCallback* callback)
+	void setOverlapFilterCallback(btOverlapFilterCallback * callback)
 	{
 	{
 		m_overlapFilterCallback = callback;
 		m_overlapFilterCallback = callback;
 	}
 	}
 
 
-	int	getNumOverlappingPairs() const
+	int getNumOverlappingPairs() const
 	{
 	{
 		return m_overlappingPairArray.size();
 		return m_overlappingPairArray.size();
 	}
 	}
+
 private:
 private:
-	
-	btBroadphasePair* 	internalAddPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
+	btBroadphasePair* internalAddPair(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1);
 
 
-	void	growTables();
+	void growTables();
 
 
 	SIMD_FORCE_INLINE bool equalsPair(const btBroadphasePair& pair, int proxyId1, int proxyId2)
 	SIMD_FORCE_INLINE bool equalsPair(const btBroadphasePair& pair, int proxyId1, int proxyId2)
-	{	
+	{
 		return pair.m_pProxy0->getUid() == proxyId1 && pair.m_pProxy1->getUid() == proxyId2;
 		return pair.m_pProxy0->getUid() == proxyId1 && pair.m_pProxy1->getUid() == proxyId2;
 	}
 	}
 
 
@@ -214,43 +200,37 @@ private:
 	}
 	}
 	*/
 	*/
 
 
-
-	
-	SIMD_FORCE_INLINE	unsigned int getHash(unsigned int proxyId1, unsigned int proxyId2)
+	SIMD_FORCE_INLINE unsigned int getHash(unsigned int proxyId1, unsigned int proxyId2)
 	{
 	{
-		int key = static_cast<int>(((unsigned int)proxyId1) | (((unsigned int)proxyId2) <<16));
+		unsigned int key = proxyId1 | (proxyId2 << 16);
 		// Thomas Wang's hash
 		// Thomas Wang's hash
 
 
 		key += ~(key << 15);
 		key += ~(key << 15);
-		key ^=  (key >> 10);
-		key +=  (key << 3);
-		key ^=  (key >> 6);
+		key ^= (key >> 10);
+		key += (key << 3);
+		key ^= (key >> 6);
 		key += ~(key << 11);
 		key += ~(key << 11);
-		key ^=  (key >> 16);
-		return static_cast<unsigned int>(key);
+		key ^= (key >> 16);
+		return key;
 	}
 	}
-	
-
-
 
 
-
-	SIMD_FORCE_INLINE btBroadphasePair* internalFindPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1, int hash)
+	SIMD_FORCE_INLINE btBroadphasePair* internalFindPair(btBroadphaseProxy * proxy0, btBroadphaseProxy * proxy1, int hash)
 	{
 	{
 		int proxyId1 = proxy0->getUid();
 		int proxyId1 = proxy0->getUid();
 		int proxyId2 = proxy1->getUid();
 		int proxyId2 = proxy1->getUid();
-		#if 0 // wrong, 'equalsPair' use unsorted uids, copy-past devil striked again. Nat.
+#if 0  // wrong, 'equalsPair' use unsorted uids, copy-past devil striked again. Nat.
 		if (proxyId1 > proxyId2) 
 		if (proxyId1 > proxyId2) 
 			btSwap(proxyId1, proxyId2);
 			btSwap(proxyId1, proxyId2);
-		#endif
+#endif
 
 
 		int index = m_hashTable[hash];
 		int index = m_hashTable[hash];
-		
-		while( index != BT_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyId1, proxyId2) == false)
+
+		while (index != BT_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyId1, proxyId2) == false)
 		{
 		{
 			index = m_next[index];
 			index = m_next[index];
 		}
 		}
 
 
-		if ( index == BT_NULL_PAIR )
+		if (index == BT_NULL_PAIR)
 		{
 		{
 			return NULL;
 			return NULL;
 		}
 		}
@@ -260,155 +240,136 @@ private:
 		return &m_overlappingPairArray[index];
 		return &m_overlappingPairArray[index];
 	}
 	}
 
 
-	virtual bool	hasDeferredRemoval()
+	virtual bool hasDeferredRemoval()
 	{
 	{
 		return false;
 		return false;
 	}
 	}
 
 
-	virtual	void	setInternalGhostPairCallback(btOverlappingPairCallback* ghostPairCallback)
+	virtual void setInternalGhostPairCallback(btOverlappingPairCallback * ghostPairCallback)
 	{
 	{
 		m_ghostPairCallback = ghostPairCallback;
 		m_ghostPairCallback = ghostPairCallback;
 	}
 	}
 
 
-	virtual void	sortOverlappingPairs(btDispatcher* dispatcher);
-	
-
-	
+	virtual void sortOverlappingPairs(btDispatcher * dispatcher);
 };
 };
 
 
-
-
-
 ///btSortedOverlappingPairCache maintains the objects with overlapping AABB
 ///btSortedOverlappingPairCache maintains the objects with overlapping AABB
 ///Typically managed by the Broadphase, Axis3Sweep or btSimpleBroadphase
 ///Typically managed by the Broadphase, Axis3Sweep or btSimpleBroadphase
-class	btSortedOverlappingPairCache : public btOverlappingPairCache
+class btSortedOverlappingPairCache : public btOverlappingPairCache
 {
 {
-	protected:
-		//avoid brute-force finding all the time
-		btBroadphasePairArray	m_overlappingPairArray;
+protected:
+	//avoid brute-force finding all the time
+	btBroadphasePairArray m_overlappingPairArray;
 
 
-		//during the dispatch, check that user doesn't destroy/create proxy
-		bool		m_blockedForChanges;
+	//during the dispatch, check that user doesn't destroy/create proxy
+	bool m_blockedForChanges;
 
 
-		///by default, do the removal during the pair traversal
-		bool		m_hasDeferredRemoval;
-		
-		//if set, use the callback instead of the built in filter in needBroadphaseCollision
-		btOverlapFilterCallback* m_overlapFilterCallback;
+	///by default, do the removal during the pair traversal
+	bool m_hasDeferredRemoval;
 
 
-		btOverlappingPairCallback*	m_ghostPairCallback;
+	//if set, use the callback instead of the built in filter in needBroadphaseCollision
+	btOverlapFilterCallback* m_overlapFilterCallback;
 
 
-	public:
-			
-		btSortedOverlappingPairCache();	
-		virtual ~btSortedOverlappingPairCache();
+	btOverlappingPairCallback* m_ghostPairCallback;
 
 
-		virtual void	processAllOverlappingPairs(btOverlapCallback*,btDispatcher* dispatcher);
+public:
+	btSortedOverlappingPairCache();
+	virtual ~btSortedOverlappingPairCache();
 
 
-		void*	removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher);
+	virtual void processAllOverlappingPairs(btOverlapCallback*, btDispatcher* dispatcher);
 
 
-		void	cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher);
-		
-		btBroadphasePair*	addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
+	void* removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1, btDispatcher* dispatcher);
 
 
-		btBroadphasePair*	findPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
-			
-		
-		void	cleanProxyFromPairs(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
+	void cleanOverlappingPair(btBroadphasePair& pair, btDispatcher* dispatcher);
 
 
-		void	removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
+	btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1);
 
 
+	btBroadphasePair* findPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1);
 
 
-		inline bool needsBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
-		{
-			if (m_overlapFilterCallback)
-				return m_overlapFilterCallback->needBroadphaseCollision(proxy0,proxy1);
+	void cleanProxyFromPairs(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
 
 
-			bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
-			collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
-			
-			return collides;
-		}
-		
-		btBroadphasePairArray&	getOverlappingPairArray()
-		{
-			return m_overlappingPairArray;
-		}
+	void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
 
 
-		const btBroadphasePairArray&	getOverlappingPairArray() const
-		{
-			return m_overlappingPairArray;
-		}
+	inline bool needsBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) const
+	{
+		if (m_overlapFilterCallback)
+			return m_overlapFilterCallback->needBroadphaseCollision(proxy0, proxy1);
 
 
-		
+		bool collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
+		collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
 
 
+		return collides;
+	}
 
 
-		btBroadphasePair*	getOverlappingPairArrayPtr()
-		{
-			return &m_overlappingPairArray[0];
-		}
+	btBroadphasePairArray& getOverlappingPairArray()
+	{
+		return m_overlappingPairArray;
+	}
 
 
-		const btBroadphasePair*	getOverlappingPairArrayPtr() const
-		{
-			return &m_overlappingPairArray[0];
-		}
+	const btBroadphasePairArray& getOverlappingPairArray() const
+	{
+		return m_overlappingPairArray;
+	}
 
 
-		int	getNumOverlappingPairs() const
-		{
-			return m_overlappingPairArray.size();
-		}
-		
-		btOverlapFilterCallback* getOverlapFilterCallback()
-		{
-			return m_overlapFilterCallback;
-		}
+	btBroadphasePair* getOverlappingPairArrayPtr()
+	{
+		return &m_overlappingPairArray[0];
+	}
 
 
-		void setOverlapFilterCallback(btOverlapFilterCallback* callback)
-		{
-			m_overlapFilterCallback = callback;
-		}
+	const btBroadphasePair* getOverlappingPairArrayPtr() const
+	{
+		return &m_overlappingPairArray[0];
+	}
 
 
-		virtual bool	hasDeferredRemoval()
-		{
-			return m_hasDeferredRemoval;
-		}
+	int getNumOverlappingPairs() const
+	{
+		return m_overlappingPairArray.size();
+	}
 
 
-		virtual	void	setInternalGhostPairCallback(btOverlappingPairCallback* ghostPairCallback)
-		{
-			m_ghostPairCallback = ghostPairCallback;
-		}
+	btOverlapFilterCallback* getOverlapFilterCallback()
+	{
+		return m_overlapFilterCallback;
+	}
 
 
-		virtual void	sortOverlappingPairs(btDispatcher* dispatcher);
-		
+	void setOverlapFilterCallback(btOverlapFilterCallback* callback)
+	{
+		m_overlapFilterCallback = callback;
+	}
 
 
-};
+	virtual bool hasDeferredRemoval()
+	{
+		return m_hasDeferredRemoval;
+	}
 
 
+	virtual void setInternalGhostPairCallback(btOverlappingPairCallback* ghostPairCallback)
+	{
+		m_ghostPairCallback = ghostPairCallback;
+	}
 
 
+	virtual void sortOverlappingPairs(btDispatcher* dispatcher);
+};
 
 
 ///btNullPairCache skips add/removal of overlapping pairs. Userful for benchmarking and unit testing.
 ///btNullPairCache skips add/removal of overlapping pairs. Userful for benchmarking and unit testing.
 class btNullPairCache : public btOverlappingPairCache
 class btNullPairCache : public btOverlappingPairCache
 {
 {
-
-	btBroadphasePairArray	m_overlappingPairArray;
+	btBroadphasePairArray m_overlappingPairArray;
 
 
 public:
 public:
-
-	virtual btBroadphasePair*	getOverlappingPairArrayPtr()
+	virtual btBroadphasePair* getOverlappingPairArrayPtr()
 	{
 	{
 		return &m_overlappingPairArray[0];
 		return &m_overlappingPairArray[0];
 	}
 	}
-	const btBroadphasePair*	getOverlappingPairArrayPtr() const
+	const btBroadphasePair* getOverlappingPairArrayPtr() const
 	{
 	{
 		return &m_overlappingPairArray[0];
 		return &m_overlappingPairArray[0];
 	}
 	}
-	btBroadphasePairArray&	getOverlappingPairArray()
+	btBroadphasePairArray& getOverlappingPairArray()
 	{
 	{
 		return m_overlappingPairArray;
 		return m_overlappingPairArray;
 	}
 	}
-	
-	virtual	void	cleanOverlappingPair(btBroadphasePair& /*pair*/,btDispatcher* /*dispatcher*/)
-	{
 
 
+	virtual void cleanOverlappingPair(btBroadphasePair& /*pair*/, btDispatcher* /*dispatcher*/)
+	{
 	}
 	}
 
 
 	virtual int getNumOverlappingPairs() const
 	virtual int getNumOverlappingPairs() const
@@ -416,16 +377,23 @@ public:
 		return 0;
 		return 0;
 	}
 	}
 
 
-	virtual void	cleanProxyFromPairs(btBroadphaseProxy* /*proxy*/,btDispatcher* /*dispatcher*/)
+	virtual void cleanProxyFromPairs(btBroadphaseProxy* /*proxy*/, btDispatcher* /*dispatcher*/)
 	{
 	{
-
 	}
 	}
 
 
-	virtual	void setOverlapFilterCallback(btOverlapFilterCallback* /*callback*/)
+	bool needsBroadphaseCollision(btBroadphaseProxy*, btBroadphaseProxy*) const
+	{
+		return true;
+	}
+	btOverlapFilterCallback* getOverlapFilterCallback()
+	{
+		return 0;
+	}
+	virtual void setOverlapFilterCallback(btOverlapFilterCallback* /*callback*/)
 	{
 	{
 	}
 	}
 
 
-	virtual void	processAllOverlappingPairs(btOverlapCallback*,btDispatcher* /*dispatcher*/)
+	virtual void processAllOverlappingPairs(btOverlapCallback*, btDispatcher* /*dispatcher*/)
 	{
 	{
 	}
 	}
 
 
@@ -434,39 +402,33 @@ public:
 		return 0;
 		return 0;
 	}
 	}
 
 
-	virtual bool	hasDeferredRemoval()
+	virtual bool hasDeferredRemoval()
 	{
 	{
 		return true;
 		return true;
 	}
 	}
 
 
-	virtual	void	setInternalGhostPairCallback(btOverlappingPairCallback* /* ghostPairCallback */)
+	virtual void setInternalGhostPairCallback(btOverlappingPairCallback* /* ghostPairCallback */)
 	{
 	{
-
 	}
 	}
 
 
-	virtual btBroadphasePair*	addOverlappingPair(btBroadphaseProxy* /*proxy0*/,btBroadphaseProxy* /*proxy1*/)
+	virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* /*proxy0*/, btBroadphaseProxy* /*proxy1*/)
 	{
 	{
 		return 0;
 		return 0;
 	}
 	}
 
 
-	virtual void*	removeOverlappingPair(btBroadphaseProxy* /*proxy0*/,btBroadphaseProxy* /*proxy1*/,btDispatcher* /*dispatcher*/)
+	virtual void* removeOverlappingPair(btBroadphaseProxy* /*proxy0*/, btBroadphaseProxy* /*proxy1*/, btDispatcher* /*dispatcher*/)
 	{
 	{
 		return 0;
 		return 0;
 	}
 	}
 
 
-	virtual void	removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/)
+	virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/, btDispatcher* /*dispatcher*/)
 	{
 	{
 	}
 	}
-	
-	virtual void	sortOverlappingPairs(btDispatcher* dispatcher)
+
+	virtual void sortOverlappingPairs(btDispatcher* dispatcher)
 	{
 	{
-        (void) dispatcher;
+		(void)dispatcher;
 	}
 	}
-
-
 };
 };
 
 
-
-#endif //BT_OVERLAPPING_PAIR_CACHE_H
-
-
+#endif  //BT_OVERLAPPING_PAIR_CACHE_H

+ 8 - 7
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h

@@ -18,23 +18,24 @@ subject to the following restrictions:
 #define OVERLAPPING_PAIR_CALLBACK_H
 #define OVERLAPPING_PAIR_CALLBACK_H
 
 
 class btDispatcher;
 class btDispatcher;
-struct  btBroadphasePair;
+struct btBroadphasePair;
 
 
 ///The btOverlappingPairCallback class is an additional optional broadphase user callback for adding/removing overlapping pairs, similar interface to btOverlappingPairCache.
 ///The btOverlappingPairCallback class is an additional optional broadphase user callback for adding/removing overlapping pairs, similar interface to btOverlappingPairCache.
 class btOverlappingPairCallback
 class btOverlappingPairCallback
 {
 {
+protected:
+	btOverlappingPairCallback() {}
+
 public:
 public:
 	virtual ~btOverlappingPairCallback()
 	virtual ~btOverlappingPairCallback()
 	{
 	{
-
 	}
 	}
-	
-	virtual btBroadphasePair*	addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) = 0;
 
 
-	virtual void*	removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher) = 0;
+	virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) = 0;
 
 
-	virtual void	removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0,btDispatcher* dispatcher) = 0;
+	virtual void* removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1, btDispatcher* dispatcher) = 0;
 
 
+	virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0, btDispatcher* dispatcher) = 0;
 };
 };
 
 
-#endif //OVERLAPPING_PAIR_CALLBACK_H
+#endif  //OVERLAPPING_PAIR_CALLBACK_H

File diff suppressed because it is too large
+ 228 - 270
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp


+ 149 - 187
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h

@@ -22,11 +22,11 @@ class btSerializer;
 #ifdef DEBUG_CHECK_DEQUANTIZATION
 #ifdef DEBUG_CHECK_DEQUANTIZATION
 #ifdef __SPU__
 #ifdef __SPU__
 #define printf spu_printf
 #define printf spu_printf
-#endif //__SPU__
+#endif  //__SPU__
 
 
 #include <stdio.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdlib.h>
-#endif //DEBUG_CHECK_DEQUANTIZATION
+#endif  //DEBUG_CHECK_DEQUANTIZATION
 
 
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
@@ -41,13 +41,10 @@ class btSerializer;
 #define btQuantizedBvhDataName "btQuantizedBvhFloatData"
 #define btQuantizedBvhDataName "btQuantizedBvhFloatData"
 #endif
 #endif
 
 
-
-
 //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vclrf__m128.asp
 //http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/vclrf__m128.asp
 
 
-
 //Note: currently we have 16 bytes per quantized node
 //Note: currently we have 16 bytes per quantized node
-#define MAX_SUBTREE_SIZE_IN_BYTES  2048
+#define MAX_SUBTREE_SIZE_IN_BYTES 2048
 
 
 // 10 gives the potential for 1024 parts, with at most 2^21 (2097152) (minus one
 // 10 gives the potential for 1024 parts, with at most 2^21 (2097152) (minus one
 // actually) triangles each (since the sign bit is reserved
 // actually) triangles each (since the sign bit is reserved
@@ -55,15 +52,16 @@ class btSerializer;
 
 
 ///btQuantizedBvhNode is a compressed aabb node, 16 bytes.
 ///btQuantizedBvhNode is a compressed aabb node, 16 bytes.
 ///Node can be used for leafnode or internal node. Leafnodes can point to 32-bit triangle index (non-negative range).
 ///Node can be used for leafnode or internal node. Leafnodes can point to 32-bit triangle index (non-negative range).
-ATTRIBUTE_ALIGNED16	(struct) btQuantizedBvhNode
+ATTRIBUTE_ALIGNED16(struct)
+btQuantizedBvhNode
 {
 {
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	//12 bytes
 	//12 bytes
-	unsigned short int	m_quantizedAabbMin[3];
-	unsigned short int	m_quantizedAabbMax[3];
+	unsigned short int m_quantizedAabbMin[3];
+	unsigned short int m_quantizedAabbMax[3];
 	//4 bytes
 	//4 bytes
-	int	m_escapeIndexOrTriangleIndex;
+	int m_escapeIndexOrTriangleIndex;
 
 
 	bool isLeafNode() const
 	bool isLeafNode() const
 	{
 	{
@@ -75,68 +73,67 @@ ATTRIBUTE_ALIGNED16	(struct) btQuantizedBvhNode
 		btAssert(!isLeafNode());
 		btAssert(!isLeafNode());
 		return -m_escapeIndexOrTriangleIndex;
 		return -m_escapeIndexOrTriangleIndex;
 	}
 	}
-	int	getTriangleIndex() const
+	int getTriangleIndex() const
 	{
 	{
 		btAssert(isLeafNode());
 		btAssert(isLeafNode());
-		unsigned int x=0;
-		unsigned int y = (~(x&0))<<(31-MAX_NUM_PARTS_IN_BITS);
+		unsigned int x = 0;
+		unsigned int y = (~(x & 0)) << (31 - MAX_NUM_PARTS_IN_BITS);
 		// Get only the lower bits where the triangle index is stored
 		// Get only the lower bits where the triangle index is stored
-		return (m_escapeIndexOrTriangleIndex&~(y));
+		return (m_escapeIndexOrTriangleIndex & ~(y));
 	}
 	}
-	int	getPartId() const
+	int getPartId() const
 	{
 	{
 		btAssert(isLeafNode());
 		btAssert(isLeafNode());
 		// Get only the highest bits where the part index is stored
 		// Get only the highest bits where the part index is stored
-		return (m_escapeIndexOrTriangleIndex>>(31-MAX_NUM_PARTS_IN_BITS));
+		return (m_escapeIndexOrTriangleIndex >> (31 - MAX_NUM_PARTS_IN_BITS));
 	}
 	}
-}
-;
+};
 
 
 /// btOptimizedBvhNode contains both internal and leaf node information.
 /// btOptimizedBvhNode contains both internal and leaf node information.
 /// Total node size is 44 bytes / node. You can use the compressed version of 16 bytes.
 /// Total node size is 44 bytes / node. You can use the compressed version of 16 bytes.
-ATTRIBUTE_ALIGNED16 (struct) btOptimizedBvhNode
+ATTRIBUTE_ALIGNED16(struct)
+btOptimizedBvhNode
 {
 {
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	//32 bytes
 	//32 bytes
-	btVector3	m_aabbMinOrg;
-	btVector3	m_aabbMaxOrg;
+	btVector3 m_aabbMinOrg;
+	btVector3 m_aabbMaxOrg;
 
 
 	//4
 	//4
-	int	m_escapeIndex;
+	int m_escapeIndex;
 
 
 	//8
 	//8
 	//for child nodes
 	//for child nodes
-	int	m_subPart;
-	int	m_triangleIndex;
+	int m_subPart;
+	int m_triangleIndex;
 
 
-//pad the size to 64 bytes
-	char	m_padding[20];
+	//pad the size to 64 bytes
+	char m_padding[20];
 };
 };
 
 
-
 ///btBvhSubtreeInfo provides info to gather a subtree of limited size
 ///btBvhSubtreeInfo provides info to gather a subtree of limited size
-ATTRIBUTE_ALIGNED16(class) btBvhSubtreeInfo
+ATTRIBUTE_ALIGNED16(class)
+btBvhSubtreeInfo
 {
 {
 public:
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	//12 bytes
 	//12 bytes
-	unsigned short int	m_quantizedAabbMin[3];
-	unsigned short int	m_quantizedAabbMax[3];
+	unsigned short int m_quantizedAabbMin[3];
+	unsigned short int m_quantizedAabbMax[3];
 	//4 bytes, points to the root of the subtree
 	//4 bytes, points to the root of the subtree
-	int			m_rootNodeIndex;
+	int m_rootNodeIndex;
 	//4 bytes
 	//4 bytes
-	int			m_subtreeSize;
-	int			m_padding[3];
+	int m_subtreeSize;
+	int m_padding[3];
 
 
 	btBvhSubtreeInfo()
 	btBvhSubtreeInfo()
 	{
 	{
 		//memset(&m_padding[0], 0, sizeof(m_padding));
 		//memset(&m_padding[0], 0, sizeof(m_padding));
 	}
 	}
 
 
-
-	void	setAabbFromQuantizeNode(const btQuantizedBvhNode& quantizedNode)
+	void setAabbFromQuantizeNode(const btQuantizedBvhNode& quantizedNode)
 	{
 	{
 		m_quantizedAabbMin[0] = quantizedNode.m_quantizedAabbMin[0];
 		m_quantizedAabbMin[0] = quantizedNode.m_quantizedAabbMin[0];
 		m_quantizedAabbMin[1] = quantizedNode.m_quantizedAabbMin[1];
 		m_quantizedAabbMin[1] = quantizedNode.m_quantizedAabbMin[1];
@@ -145,14 +142,12 @@ public:
 		m_quantizedAabbMax[1] = quantizedNode.m_quantizedAabbMax[1];
 		m_quantizedAabbMax[1] = quantizedNode.m_quantizedAabbMax[1];
 		m_quantizedAabbMax[2] = quantizedNode.m_quantizedAabbMax[2];
 		m_quantizedAabbMax[2] = quantizedNode.m_quantizedAabbMax[2];
 	}
 	}
-}
-;
-
+};
 
 
 class btNodeOverlapCallback
 class btNodeOverlapCallback
 {
 {
 public:
 public:
-	virtual ~btNodeOverlapCallback() {};
+	virtual ~btNodeOverlapCallback(){};
 
 
 	virtual void processNode(int subPart, int triangleIndex) = 0;
 	virtual void processNode(int subPart, int triangleIndex) = 0;
 };
 };
@@ -160,18 +155,16 @@ public:
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
 
 
-
-
 ///for code readability:
 ///for code readability:
-typedef btAlignedObjectArray<btOptimizedBvhNode>	NodeArray;
-typedef btAlignedObjectArray<btQuantizedBvhNode>	QuantizedNodeArray;
-typedef btAlignedObjectArray<btBvhSubtreeInfo>		BvhSubtreeInfoArray;
-
+typedef btAlignedObjectArray<btOptimizedBvhNode> NodeArray;
+typedef btAlignedObjectArray<btQuantizedBvhNode> QuantizedNodeArray;
+typedef btAlignedObjectArray<btBvhSubtreeInfo> BvhSubtreeInfoArray;
 
 
 ///The btQuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU.
 ///The btQuantizedBvh class stores an AABB tree that can be quickly traversed on CPU and Cell SPU.
 ///It is used by the btBvhTriangleMeshShape as midphase.
 ///It is used by the btBvhTriangleMeshShape as midphase.
 ///It is recommended to use quantization for better performance and lower memory requirements.
 ///It is recommended to use quantization for better performance and lower memory requirements.
-ATTRIBUTE_ALIGNED16(class) btQuantizedBvh
+ATTRIBUTE_ALIGNED16(class)
+btQuantizedBvh
 {
 {
 public:
 public:
 	enum btTraversalMode
 	enum btTraversalMode
@@ -182,54 +175,47 @@ public:
 	};
 	};
 
 
 protected:
 protected:
+	btVector3 m_bvhAabbMin;
+	btVector3 m_bvhAabbMax;
+	btVector3 m_bvhQuantization;
 
 
+	int m_bulletVersion;  //for serialization versioning. It could also be used to detect endianess.
 
 
-	btVector3			m_bvhAabbMin;
-	btVector3			m_bvhAabbMax;
-	btVector3			m_bvhQuantization;
-
-	int					m_bulletVersion;	//for serialization versioning. It could also be used to detect endianess.
-
-	int					m_curNodeIndex;
+	int m_curNodeIndex;
 	//quantization data
 	//quantization data
-	bool				m_useQuantization;
+	bool m_useQuantization;
 
 
+	NodeArray m_leafNodes;
+	NodeArray m_contiguousNodes;
+	QuantizedNodeArray m_quantizedLeafNodes;
+	QuantizedNodeArray m_quantizedContiguousNodes;
 
 
-
-	NodeArray			m_leafNodes;
-	NodeArray			m_contiguousNodes;
-	QuantizedNodeArray	m_quantizedLeafNodes;
-	QuantizedNodeArray	m_quantizedContiguousNodes;
-	
-	btTraversalMode	m_traversalMode;
-	BvhSubtreeInfoArray		m_SubtreeHeaders;
+	btTraversalMode m_traversalMode;
+	BvhSubtreeInfoArray m_SubtreeHeaders;
 
 
 	//This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray
 	//This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray
 	mutable int m_subtreeHeaderCount;
 	mutable int m_subtreeHeaderCount;
 
 
-	
-
-
-
 	///two versions, one for quantized and normal nodes. This allows code-reuse while maintaining readability (no template/macro!)
 	///two versions, one for quantized and normal nodes. This allows code-reuse while maintaining readability (no template/macro!)
 	///this might be refactored into a virtual, it is usually not calculated at run-time
 	///this might be refactored into a virtual, it is usually not calculated at run-time
-	void	setInternalNodeAabbMin(int nodeIndex, const btVector3& aabbMin)
+	void setInternalNodeAabbMin(int nodeIndex, const btVector3& aabbMin)
 	{
 	{
 		if (m_useQuantization)
 		if (m_useQuantization)
 		{
 		{
-			quantize(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0] ,aabbMin,0);
-		} else
+			quantize(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[0], aabbMin, 0);
+		}
+		else
 		{
 		{
 			m_contiguousNodes[nodeIndex].m_aabbMinOrg = aabbMin;
 			m_contiguousNodes[nodeIndex].m_aabbMinOrg = aabbMin;
-
 		}
 		}
 	}
 	}
-	void	setInternalNodeAabbMax(int nodeIndex,const btVector3& aabbMax)
+	void setInternalNodeAabbMax(int nodeIndex, const btVector3& aabbMax)
 	{
 	{
 		if (m_useQuantization)
 		if (m_useQuantization)
 		{
 		{
-			quantize(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0],aabbMax,1);
-		} else
+			quantize(&m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[0], aabbMax, 1);
+		}
+		else
 		{
 		{
 			m_contiguousNodes[nodeIndex].m_aabbMaxOrg = aabbMax;
 			m_contiguousNodes[nodeIndex].m_aabbMaxOrg = aabbMax;
 		}
 		}
@@ -243,115 +229,102 @@ protected:
 		}
 		}
 		//non-quantized
 		//non-quantized
 		return m_leafNodes[nodeIndex].m_aabbMinOrg;
 		return m_leafNodes[nodeIndex].m_aabbMinOrg;
-
 	}
 	}
 	btVector3 getAabbMax(int nodeIndex) const
 	btVector3 getAabbMax(int nodeIndex) const
 	{
 	{
 		if (m_useQuantization)
 		if (m_useQuantization)
 		{
 		{
 			return unQuantize(&m_quantizedLeafNodes[nodeIndex].m_quantizedAabbMax[0]);
 			return unQuantize(&m_quantizedLeafNodes[nodeIndex].m_quantizedAabbMax[0]);
-		} 
+		}
 		//non-quantized
 		//non-quantized
 		return m_leafNodes[nodeIndex].m_aabbMaxOrg;
 		return m_leafNodes[nodeIndex].m_aabbMaxOrg;
-		
 	}
 	}
 
 
-	
-	void	setInternalNodeEscapeIndex(int nodeIndex, int escapeIndex)
+	void setInternalNodeEscapeIndex(int nodeIndex, int escapeIndex)
 	{
 	{
 		if (m_useQuantization)
 		if (m_useQuantization)
 		{
 		{
 			m_quantizedContiguousNodes[nodeIndex].m_escapeIndexOrTriangleIndex = -escapeIndex;
 			m_quantizedContiguousNodes[nodeIndex].m_escapeIndexOrTriangleIndex = -escapeIndex;
-		} 
+		}
 		else
 		else
 		{
 		{
 			m_contiguousNodes[nodeIndex].m_escapeIndex = escapeIndex;
 			m_contiguousNodes[nodeIndex].m_escapeIndex = escapeIndex;
 		}
 		}
-
 	}
 	}
 
 
-	void mergeInternalNodeAabb(int nodeIndex,const btVector3& newAabbMin,const btVector3& newAabbMax) 
+	void mergeInternalNodeAabb(int nodeIndex, const btVector3& newAabbMin, const btVector3& newAabbMax)
 	{
 	{
 		if (m_useQuantization)
 		if (m_useQuantization)
 		{
 		{
 			unsigned short int quantizedAabbMin[3];
 			unsigned short int quantizedAabbMin[3];
 			unsigned short int quantizedAabbMax[3];
 			unsigned short int quantizedAabbMax[3];
-			quantize(quantizedAabbMin,newAabbMin,0);
-			quantize(quantizedAabbMax,newAabbMax,1);
-			for (int i=0;i<3;i++)
+			quantize(quantizedAabbMin, newAabbMin, 0);
+			quantize(quantizedAabbMax, newAabbMax, 1);
+			for (int i = 0; i < 3; i++)
 			{
 			{
 				if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] > quantizedAabbMin[i])
 				if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] > quantizedAabbMin[i])
 					m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] = quantizedAabbMin[i];
 					m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMin[i] = quantizedAabbMin[i];
 
 
 				if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[i] < quantizedAabbMax[i])
 				if (m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[i] < quantizedAabbMax[i])
 					m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[i] = quantizedAabbMax[i];
 					m_quantizedContiguousNodes[nodeIndex].m_quantizedAabbMax[i] = quantizedAabbMax[i];
-
 			}
 			}
-		} else
+		}
+		else
 		{
 		{
 			//non-quantized
 			//non-quantized
 			m_contiguousNodes[nodeIndex].m_aabbMinOrg.setMin(newAabbMin);
 			m_contiguousNodes[nodeIndex].m_aabbMinOrg.setMin(newAabbMin);
-			m_contiguousNodes[nodeIndex].m_aabbMaxOrg.setMax(newAabbMax);		
+			m_contiguousNodes[nodeIndex].m_aabbMaxOrg.setMax(newAabbMax);
 		}
 		}
 	}
 	}
 
 
-	void	swapLeafNodes(int firstIndex,int secondIndex);
+	void swapLeafNodes(int firstIndex, int secondIndex);
 
 
-	void	assignInternalNodeFromLeafNode(int internalNode,int leafNodeIndex);
+	void assignInternalNodeFromLeafNode(int internalNode, int leafNodeIndex);
 
 
 protected:
 protected:
+	void buildTree(int startIndex, int endIndex);
 
 
-	
+	int calcSplittingAxis(int startIndex, int endIndex);
 
 
-	void	buildTree	(int startIndex,int endIndex);
+	int sortAndCalcSplittingIndex(int startIndex, int endIndex, int splitAxis);
 
 
-	int	calcSplittingAxis(int startIndex,int endIndex);
+	void walkStacklessTree(btNodeOverlapCallback * nodeCallback, const btVector3& aabbMin, const btVector3& aabbMax) const;
 
 
-	int	sortAndCalcSplittingIndex(int startIndex,int endIndex,int splitAxis);
-	
-	void	walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
-
-	void	walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
-	void	walkStacklessQuantizedTree(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax,int startNodeIndex,int endNodeIndex) const;
-	void	walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const;
+	void walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback * nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex, int endNodeIndex) const;
+	void walkStacklessQuantizedTree(btNodeOverlapCallback * nodeCallback, unsigned short int* quantizedQueryAabbMin, unsigned short int* quantizedQueryAabbMax, int startNodeIndex, int endNodeIndex) const;
+	void walkStacklessTreeAgainstRay(btNodeOverlapCallback * nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex, int endNodeIndex) const;
 
 
 	///tree traversal designed for small-memory processors like PS3 SPU
 	///tree traversal designed for small-memory processors like PS3 SPU
-	void	walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
+	void walkStacklessQuantizedTreeCacheFriendly(btNodeOverlapCallback * nodeCallback, unsigned short int* quantizedQueryAabbMin, unsigned short int* quantizedQueryAabbMax) const;
 
 
 	///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
 	///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
-	void	walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantizedBvhNode* currentNode,btNodeOverlapCallback* nodeCallback,unsigned short int* quantizedQueryAabbMin,unsigned short int* quantizedQueryAabbMax) const;
+	void walkRecursiveQuantizedTreeAgainstQueryAabb(const btQuantizedBvhNode* currentNode, btNodeOverlapCallback* nodeCallback, unsigned short int* quantizedQueryAabbMin, unsigned short int* quantizedQueryAabbMax) const;
 
 
 	///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
 	///use the 16-byte stackless 'skipindex' node tree to do a recursive traversal
-	void	walkRecursiveQuantizedTreeAgainstQuantizedTree(const btQuantizedBvhNode* treeNodeA,const btQuantizedBvhNode* treeNodeB,btNodeOverlapCallback* nodeCallback) const;
-	
+	void walkRecursiveQuantizedTreeAgainstQuantizedTree(const btQuantizedBvhNode* treeNodeA, const btQuantizedBvhNode* treeNodeB, btNodeOverlapCallback* nodeCallback) const;
 
 
-
-
-	void	updateSubtreeHeaders(int leftChildNodexIndex,int rightChildNodexIndex);
+	void updateSubtreeHeaders(int leftChildNodexIndex, int rightChildNodexIndex);
 
 
 public:
 public:
-	
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	btQuantizedBvh();
 	btQuantizedBvh();
 
 
 	virtual ~btQuantizedBvh();
 	virtual ~btQuantizedBvh();
 
 
-	
 	///***************************************** expert/internal use only *************************
 	///***************************************** expert/internal use only *************************
-	void	setQuantizationValues(const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,btScalar quantizationMargin=btScalar(1.0));
-	QuantizedNodeArray&	getLeafNodeArray() {			return	m_quantizedLeafNodes;	}
+	void setQuantizationValues(const btVector3& bvhAabbMin, const btVector3& bvhAabbMax, btScalar quantizationMargin = btScalar(1.0));
+	QuantizedNodeArray& getLeafNodeArray() { return m_quantizedLeafNodes; }
 	///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized
 	///buildInternal is expert use only: assumes that setQuantizationValues and LeafNodeArray are initialized
-	void	buildInternal();
+	void buildInternal();
 	///***************************************** expert/internal use only *************************
 	///***************************************** expert/internal use only *************************
 
 
-	void	reportAabbOverlappingNodex(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const;
-	void	reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const;
-	void	reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const;
+	void reportAabbOverlappingNodex(btNodeOverlapCallback * nodeCallback, const btVector3& aabbMin, const btVector3& aabbMax) const;
+	void reportRayOverlappingNodex(btNodeOverlapCallback * nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const;
+	void reportBoxCastOverlappingNodex(btNodeOverlapCallback * nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax) const;
 
 
-		SIMD_FORCE_INLINE void quantize(unsigned short* out, const btVector3& point,int isMax) const
+	SIMD_FORCE_INLINE void quantize(unsigned short* out, const btVector3& point, int isMax) const
 	{
 	{
-
 		btAssert(m_useQuantization);
 		btAssert(m_useQuantization);
 
 
 		btAssert(point.getX() <= m_bvhAabbMax.getX());
 		btAssert(point.getX() <= m_bvhAabbMax.getX());
@@ -368,122 +341,114 @@ public:
 		///@todo: double-check this
 		///@todo: double-check this
 		if (isMax)
 		if (isMax)
 		{
 		{
-			out[0] = (unsigned short) (((unsigned short)(v.getX()+btScalar(1.)) | 1));
-			out[1] = (unsigned short) (((unsigned short)(v.getY()+btScalar(1.)) | 1));
-			out[2] = (unsigned short) (((unsigned short)(v.getZ()+btScalar(1.)) | 1));
-		} else
+			out[0] = (unsigned short)(((unsigned short)(v.getX() + btScalar(1.)) | 1));
+			out[1] = (unsigned short)(((unsigned short)(v.getY() + btScalar(1.)) | 1));
+			out[2] = (unsigned short)(((unsigned short)(v.getZ() + btScalar(1.)) | 1));
+		}
+		else
 		{
 		{
-			out[0] = (unsigned short) (((unsigned short)(v.getX()) & 0xfffe));
-			out[1] = (unsigned short) (((unsigned short)(v.getY()) & 0xfffe));
-			out[2] = (unsigned short) (((unsigned short)(v.getZ()) & 0xfffe));
+			out[0] = (unsigned short)(((unsigned short)(v.getX()) & 0xfffe));
+			out[1] = (unsigned short)(((unsigned short)(v.getY()) & 0xfffe));
+			out[2] = (unsigned short)(((unsigned short)(v.getZ()) & 0xfffe));
 		}
 		}
 
 
-
 #ifdef DEBUG_CHECK_DEQUANTIZATION
 #ifdef DEBUG_CHECK_DEQUANTIZATION
 		btVector3 newPoint = unQuantize(out);
 		btVector3 newPoint = unQuantize(out);
 		if (isMax)
 		if (isMax)
 		{
 		{
 			if (newPoint.getX() < point.getX())
 			if (newPoint.getX() < point.getX())
 			{
 			{
-				printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n",newPoint.getX()-point.getX(), newPoint.getX(),point.getX());
+				printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n", newPoint.getX() - point.getX(), newPoint.getX(), point.getX());
 			}
 			}
 			if (newPoint.getY() < point.getY())
 			if (newPoint.getY() < point.getY())
 			{
 			{
-				printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n",newPoint.getY()-point.getY(), newPoint.getY(),point.getY());
+				printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n", newPoint.getY() - point.getY(), newPoint.getY(), point.getY());
 			}
 			}
 			if (newPoint.getZ() < point.getZ())
 			if (newPoint.getZ() < point.getZ())
 			{
 			{
-
-				printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n",newPoint.getZ()-point.getZ(), newPoint.getZ(),point.getZ());
+				printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n", newPoint.getZ() - point.getZ(), newPoint.getZ(), point.getZ());
 			}
 			}
-		} else
+		}
+		else
 		{
 		{
 			if (newPoint.getX() > point.getX())
 			if (newPoint.getX() > point.getX())
 			{
 			{
-				printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n",newPoint.getX()-point.getX(), newPoint.getX(),point.getX());
+				printf("unconservative X, diffX = %f, oldX=%f,newX=%f\n", newPoint.getX() - point.getX(), newPoint.getX(), point.getX());
 			}
 			}
 			if (newPoint.getY() > point.getY())
 			if (newPoint.getY() > point.getY())
 			{
 			{
-				printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n",newPoint.getY()-point.getY(), newPoint.getY(),point.getY());
+				printf("unconservative Y, diffY = %f, oldY=%f,newY=%f\n", newPoint.getY() - point.getY(), newPoint.getY(), point.getY());
 			}
 			}
 			if (newPoint.getZ() > point.getZ())
 			if (newPoint.getZ() > point.getZ())
 			{
 			{
-				printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n",newPoint.getZ()-point.getZ(), newPoint.getZ(),point.getZ());
+				printf("unconservative Z, diffZ = %f, oldZ=%f,newZ=%f\n", newPoint.getZ() - point.getZ(), newPoint.getZ(), point.getZ());
 			}
 			}
 		}
 		}
-#endif //DEBUG_CHECK_DEQUANTIZATION
-
+#endif  //DEBUG_CHECK_DEQUANTIZATION
 	}
 	}
 
 
-
-	SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point2,int isMax) const
+	SIMD_FORCE_INLINE void quantizeWithClamp(unsigned short* out, const btVector3& point2, int isMax) const
 	{
 	{
-
 		btAssert(m_useQuantization);
 		btAssert(m_useQuantization);
 
 
 		btVector3 clampedPoint(point2);
 		btVector3 clampedPoint(point2);
 		clampedPoint.setMax(m_bvhAabbMin);
 		clampedPoint.setMax(m_bvhAabbMin);
 		clampedPoint.setMin(m_bvhAabbMax);
 		clampedPoint.setMin(m_bvhAabbMax);
 
 
-		quantize(out,clampedPoint,isMax);
-
+		quantize(out, clampedPoint, isMax);
 	}
 	}
-	
-	SIMD_FORCE_INLINE btVector3	unQuantize(const unsigned short* vecIn) const
+
+	SIMD_FORCE_INLINE btVector3 unQuantize(const unsigned short* vecIn) const
 	{
 	{
-			btVector3	vecOut;
-			vecOut.setValue(
+		btVector3 vecOut;
+		vecOut.setValue(
 			(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
 			(btScalar)(vecIn[0]) / (m_bvhQuantization.getX()),
 			(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
 			(btScalar)(vecIn[1]) / (m_bvhQuantization.getY()),
 			(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
 			(btScalar)(vecIn[2]) / (m_bvhQuantization.getZ()));
-			vecOut += m_bvhAabbMin;
-			return vecOut;
+		vecOut += m_bvhAabbMin;
+		return vecOut;
 	}
 	}
 
 
 	///setTraversalMode let's you choose between stackless, recursive or stackless cache friendly tree traversal. Note this is only implemented for quantized trees.
 	///setTraversalMode let's you choose between stackless, recursive or stackless cache friendly tree traversal. Note this is only implemented for quantized trees.
-	void	setTraversalMode(btTraversalMode	traversalMode)
+	void setTraversalMode(btTraversalMode traversalMode)
 	{
 	{
 		m_traversalMode = traversalMode;
 		m_traversalMode = traversalMode;
 	}
 	}
 
 
-
-	SIMD_FORCE_INLINE QuantizedNodeArray&	getQuantizedNodeArray()
-	{	
-		return	m_quantizedContiguousNodes;
+	SIMD_FORCE_INLINE QuantizedNodeArray& getQuantizedNodeArray()
+	{
+		return m_quantizedContiguousNodes;
 	}
 	}
 
 
-
-	SIMD_FORCE_INLINE BvhSubtreeInfoArray&	getSubtreeInfoArray()
+	SIMD_FORCE_INLINE BvhSubtreeInfoArray& getSubtreeInfoArray()
 	{
 	{
 		return m_SubtreeHeaders;
 		return m_SubtreeHeaders;
 	}
 	}
 
 
-////////////////////////////////////////////////////////////////////
+	////////////////////////////////////////////////////////////////////
 
 
 	/////Calculate space needed to store BVH for serialization
 	/////Calculate space needed to store BVH for serialization
 	unsigned calculateSerializeBufferSize() const;
 	unsigned calculateSerializeBufferSize() const;
 
 
 	/// Data buffer MUST be 16 byte aligned
 	/// Data buffer MUST be 16 byte aligned
-	virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const;
+	virtual bool serialize(void* o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const;
 
 
 	///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place'
 	///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place'
-	static btQuantizedBvh *deSerializeInPlace(void *i_alignedDataBuffer, unsigned int i_dataBufferSize, bool i_swapEndian);
+	static btQuantizedBvh* deSerializeInPlace(void* i_alignedDataBuffer, unsigned int i_dataBufferSize, bool i_swapEndian);
 
 
 	static unsigned int getAlignmentSerializationPadding();
 	static unsigned int getAlignmentSerializationPadding();
-//////////////////////////////////////////////////////////////////////
+	//////////////////////////////////////////////////////////////////////
 
 
-	
-	virtual	int	calculateSerializeBufferSizeNew() const;
+	virtual int calculateSerializeBufferSizeNew() const;
 
 
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
-	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
-
-	virtual	void deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData);
+	virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
 
 
-	virtual	void deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData);
+	virtual void deSerializeFloat(struct btQuantizedBvhFloatData & quantizedBvhFloatData);
 
 
+	virtual void deSerializeDouble(struct btQuantizedBvhDoubleData & quantizedBvhDoubleData);
 
 
-////////////////////////////////////////////////////////////////////
+	////////////////////////////////////////////////////////////////////
 
 
 	SIMD_FORCE_INLINE bool isQuantized()
 	SIMD_FORCE_INLINE bool isQuantized()
 	{
 	{
@@ -494,38 +459,37 @@ private:
 	// Special "copy" constructor that allows for in-place deserialization
 	// Special "copy" constructor that allows for in-place deserialization
 	// Prevents btVector3's default constructor from being called, but doesn't inialize much else
 	// Prevents btVector3's default constructor from being called, but doesn't inialize much else
 	// ownsMemory should most likely be false if deserializing, and if you are not, don't call this (it also changes the function signature, which we need)
 	// ownsMemory should most likely be false if deserializing, and if you are not, don't call this (it also changes the function signature, which we need)
-	btQuantizedBvh(btQuantizedBvh &other, bool ownsMemory);
-
-}
-;
-
+	btQuantizedBvh(btQuantizedBvh & other, bool ownsMemory);
+};
 
 
-struct	btBvhSubtreeInfoData
+// clang-format off
+// parser needs * with the name
+struct btBvhSubtreeInfoData
 {
 {
-	int			m_rootNodeIndex;
-	int			m_subtreeSize;
+	int m_rootNodeIndex;
+	int m_subtreeSize;
 	unsigned short m_quantizedAabbMin[3];
 	unsigned short m_quantizedAabbMin[3];
 	unsigned short m_quantizedAabbMax[3];
 	unsigned short m_quantizedAabbMax[3];
 };
 };
 
 
 struct btOptimizedBvhNodeFloatData
 struct btOptimizedBvhNodeFloatData
 {
 {
-	btVector3FloatData	m_aabbMinOrg;
-	btVector3FloatData	m_aabbMaxOrg;
-	int	m_escapeIndex;
-	int	m_subPart;
-	int	m_triangleIndex;
+	btVector3FloatData m_aabbMinOrg;
+	btVector3FloatData m_aabbMaxOrg;
+	int m_escapeIndex;
+	int m_subPart;
+	int m_triangleIndex;
 	char m_pad[4];
 	char m_pad[4];
 };
 };
 
 
 struct btOptimizedBvhNodeDoubleData
 struct btOptimizedBvhNodeDoubleData
 {
 {
-	btVector3DoubleData	m_aabbMinOrg;
-	btVector3DoubleData	m_aabbMaxOrg;
-	int	m_escapeIndex;
-	int	m_subPart;
-	int	m_triangleIndex;
-	char	m_pad[4];
+	btVector3DoubleData m_aabbMinOrg;
+	btVector3DoubleData m_aabbMaxOrg;
+	int m_escapeIndex;
+	int m_subPart;
+	int m_triangleIndex;
+	char m_pad[4];
 };
 };
 
 
 
 
@@ -569,13 +533,11 @@ struct	btQuantizedBvhDoubleData
 	int							m_numSubtreeHeaders;
 	int							m_numSubtreeHeaders;
 	btBvhSubtreeInfoData		*m_subTreeInfoPtr;
 	btBvhSubtreeInfoData		*m_subTreeInfoPtr;
 };
 };
+// clang-format on
 
 
-
-SIMD_FORCE_INLINE	int	btQuantizedBvh::calculateSerializeBufferSizeNew() const
+SIMD_FORCE_INLINE int btQuantizedBvh::calculateSerializeBufferSizeNew() const
 {
 {
 	return sizeof(btQuantizedBvhData);
 	return sizeof(btQuantizedBvhData);
 }
 }
 
 
-
-
-#endif //BT_QUANTIZED_BVH_H
+#endif  //BT_QUANTIZED_BVH_H

+ 64 - 88
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp

@@ -24,52 +24,45 @@ subject to the following restrictions:
 
 
 #include <new>
 #include <new>
 
 
-extern int gOverlappingPairs;
-
-void	btSimpleBroadphase::validate()
+void btSimpleBroadphase::validate()
 {
 {
-	for (int i=0;i<m_numHandles;i++)
+	for (int i = 0; i < m_numHandles; i++)
 	{
 	{
-		for (int j=i+1;j<m_numHandles;j++)
+		for (int j = i + 1; j < m_numHandles; j++)
 		{
 		{
 			btAssert(&m_pHandles[i] != &m_pHandles[j]);
 			btAssert(&m_pHandles[i] != &m_pHandles[j]);
 		}
 		}
 	}
 	}
-	
 }
 }
 
 
 btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* overlappingPairCache)
 btSimpleBroadphase::btSimpleBroadphase(int maxProxies, btOverlappingPairCache* overlappingPairCache)
-	:m_pairCache(overlappingPairCache),
-	m_ownsPairCache(false),
-	m_invalidPair(0)
+	: m_pairCache(overlappingPairCache),
+	  m_ownsPairCache(false),
+	  m_invalidPair(0)
 {
 {
-
 	if (!overlappingPairCache)
 	if (!overlappingPairCache)
 	{
 	{
-		void* mem = btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16);
-		m_pairCache = new (mem)btHashedOverlappingPairCache();
+		void* mem = btAlignedAlloc(sizeof(btHashedOverlappingPairCache), 16);
+		m_pairCache = new (mem) btHashedOverlappingPairCache();
 		m_ownsPairCache = true;
 		m_ownsPairCache = true;
 	}
 	}
 
 
 	// allocate handles buffer and put all handles on free list
 	// allocate handles buffer and put all handles on free list
-	m_pHandlesRawPtr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy)*maxProxies,16);
-	m_pHandles = new(m_pHandlesRawPtr) btSimpleBroadphaseProxy[maxProxies];
+	m_pHandlesRawPtr = btAlignedAlloc(sizeof(btSimpleBroadphaseProxy) * maxProxies, 16);
+	m_pHandles = new (m_pHandlesRawPtr) btSimpleBroadphaseProxy[maxProxies];
 	m_maxHandles = maxProxies;
 	m_maxHandles = maxProxies;
 	m_numHandles = 0;
 	m_numHandles = 0;
 	m_firstFreeHandle = 0;
 	m_firstFreeHandle = 0;
 	m_LastHandleIndex = -1;
 	m_LastHandleIndex = -1;
-	
 
 
 	{
 	{
 		for (int i = m_firstFreeHandle; i < maxProxies; i++)
 		for (int i = m_firstFreeHandle; i < maxProxies; i++)
 		{
 		{
 			m_pHandles[i].SetNextFree(i + 1);
 			m_pHandles[i].SetNextFree(i + 1);
-			m_pHandles[i].m_uniqueId = i+2;//any UID will do, we just avoid too trivial values (0,1) for debugging purposes
+			m_pHandles[i].m_uniqueId = i + 2;  //any UID will do, we just avoid too trivial values (0,1) for debugging purposes
 		}
 		}
 		m_pHandles[maxProxies - 1].SetNextFree(0);
 		m_pHandles[maxProxies - 1].SetNextFree(0);
-	
 	}
 	}
-
 }
 }
 
 
 btSimpleBroadphase::~btSimpleBroadphase()
 btSimpleBroadphase::~btSimpleBroadphase()
@@ -83,26 +76,25 @@ btSimpleBroadphase::~btSimpleBroadphase()
 	}
 	}
 }
 }
 
 
-
-btBroadphaseProxy*	btSimpleBroadphase::createProxy(  const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr , int collisionFilterGroup, int collisionFilterMask, btDispatcher* /*dispatcher*/)
+btBroadphaseProxy* btSimpleBroadphase::createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* /*dispatcher*/)
 {
 {
 	if (m_numHandles >= m_maxHandles)
 	if (m_numHandles >= m_maxHandles)
 	{
 	{
 		btAssert(0);
 		btAssert(0);
-		return 0; //should never happen, but don't let the game crash ;-)
+		return 0;  //should never happen, but don't let the game crash ;-)
 	}
 	}
-	btAssert(aabbMin[0]<= aabbMax[0] && aabbMin[1]<= aabbMax[1] && aabbMin[2]<= aabbMax[2]);
+	btAssert(aabbMin[0] <= aabbMax[0] && aabbMin[1] <= aabbMax[1] && aabbMin[2] <= aabbMax[2]);
 
 
 	int newHandleIndex = allocHandle();
 	int newHandleIndex = allocHandle();
-	btSimpleBroadphaseProxy* proxy = new (&m_pHandles[newHandleIndex])btSimpleBroadphaseProxy(aabbMin,aabbMax,shapeType,userPtr,collisionFilterGroup,collisionFilterMask);
+	btSimpleBroadphaseProxy* proxy = new (&m_pHandles[newHandleIndex]) btSimpleBroadphaseProxy(aabbMin, aabbMax, shapeType, userPtr, collisionFilterGroup, collisionFilterMask);
 
 
 	return proxy;
 	return proxy;
 }
 }
 
 
-class	RemovingOverlapCallback : public btOverlapCallback
+class RemovingOverlapCallback : public btOverlapCallback
 {
 {
 protected:
 protected:
-	virtual bool	processOverlap(btBroadphasePair& pair)
+	virtual bool processOverlap(btBroadphasePair& pair)
 	{
 	{
 		(void)pair;
 		(void)pair;
 		btAssert(0);
 		btAssert(0);
@@ -112,12 +104,13 @@ protected:
 
 
 class RemovePairContainingProxy
 class RemovePairContainingProxy
 {
 {
+	btBroadphaseProxy* m_targetProxy;
 
 
-	btBroadphaseProxy*	m_targetProxy;
-	public:
+public:
 	virtual ~RemovePairContainingProxy()
 	virtual ~RemovePairContainingProxy()
 	{
 	{
 	}
 	}
+
 protected:
 protected:
 	virtual bool processOverlap(btBroadphasePair& pair)
 	virtual bool processOverlap(btBroadphasePair& pair)
 	{
 	{
@@ -128,38 +121,36 @@ protected:
 	};
 	};
 };
 };
 
 
-void	btSimpleBroadphase::destroyProxy(btBroadphaseProxy* proxyOrg,btDispatcher* dispatcher)
+void btSimpleBroadphase::destroyProxy(btBroadphaseProxy* proxyOrg, btDispatcher* dispatcher)
 {
 {
-		
-		btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxyOrg);
-		freeHandle(proxy0);
+	m_pairCache->removeOverlappingPairsContainingProxy(proxyOrg, dispatcher);
 
 
-		m_pairCache->removeOverlappingPairsContainingProxy(proxyOrg,dispatcher);
+	btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxyOrg);
+	freeHandle(proxy0);
 
 
-		//validate();
-		
+	//validate();
 }
 }
 
 
-void	btSimpleBroadphase::getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const
+void btSimpleBroadphase::getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const
 {
 {
 	const btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
 	const btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
 	aabbMin = sbp->m_aabbMin;
 	aabbMin = sbp->m_aabbMin;
 	aabbMax = sbp->m_aabbMax;
 	aabbMax = sbp->m_aabbMax;
 }
 }
 
 
-void	btSimpleBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* /*dispatcher*/)
+void btSimpleBroadphase::setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* /*dispatcher*/)
 {
 {
 	btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
 	btSimpleBroadphaseProxy* sbp = getSimpleProxyFromProxy(proxy);
 	sbp->m_aabbMin = aabbMin;
 	sbp->m_aabbMin = aabbMin;
 	sbp->m_aabbMax = aabbMax;
 	sbp->m_aabbMax = aabbMax;
 }
 }
 
 
-void	btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin,const btVector3& aabbMax)
+void btSimpleBroadphase::rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin, const btVector3& aabbMax)
 {
 {
-	for (int i=0; i <= m_LastHandleIndex; i++)
+	for (int i = 0; i <= m_LastHandleIndex; i++)
 	{
 	{
 		btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
 		btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
-		if(!proxy->m_clientObject)
+		if (!proxy->m_clientObject)
 		{
 		{
 			continue;
 			continue;
 		}
 		}
@@ -167,69 +158,59 @@ void	btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo
 	}
 	}
 }
 }
 
 
-
-void	btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
+void btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
 {
 {
-	for (int i=0; i <= m_LastHandleIndex; i++)
+	for (int i = 0; i <= m_LastHandleIndex; i++)
 	{
 	{
 		btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
 		btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
-		if(!proxy->m_clientObject)
+		if (!proxy->m_clientObject)
 		{
 		{
 			continue;
 			continue;
 		}
 		}
-		if (TestAabbAgainstAabb2(aabbMin,aabbMax,proxy->m_aabbMin,proxy->m_aabbMax))
+		if (TestAabbAgainstAabb2(aabbMin, aabbMax, proxy->m_aabbMin, proxy->m_aabbMax))
 		{
 		{
 			callback.process(proxy);
 			callback.process(proxy);
 		}
 		}
 	}
 	}
 }
 }
 
 
-
-
-	
-
-
-
-bool	btSimpleBroadphase::aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1)
+bool btSimpleBroadphase::aabbOverlap(btSimpleBroadphaseProxy* proxy0, btSimpleBroadphaseProxy* proxy1)
 {
 {
-	return proxy0->m_aabbMin[0] <= proxy1->m_aabbMax[0] && proxy1->m_aabbMin[0] <= proxy0->m_aabbMax[0] && 
+	return proxy0->m_aabbMin[0] <= proxy1->m_aabbMax[0] && proxy1->m_aabbMin[0] <= proxy0->m_aabbMax[0] &&
 		   proxy0->m_aabbMin[1] <= proxy1->m_aabbMax[1] && proxy1->m_aabbMin[1] <= proxy0->m_aabbMax[1] &&
 		   proxy0->m_aabbMin[1] <= proxy1->m_aabbMax[1] && proxy1->m_aabbMin[1] <= proxy0->m_aabbMax[1] &&
 		   proxy0->m_aabbMin[2] <= proxy1->m_aabbMax[2] && proxy1->m_aabbMin[2] <= proxy0->m_aabbMax[2];
 		   proxy0->m_aabbMin[2] <= proxy1->m_aabbMax[2] && proxy1->m_aabbMin[2] <= proxy0->m_aabbMax[2];
-
 }
 }
 
 
-
-
 //then remove non-overlapping ones
 //then remove non-overlapping ones
 class CheckOverlapCallback : public btOverlapCallback
 class CheckOverlapCallback : public btOverlapCallback
 {
 {
 public:
 public:
 	virtual bool processOverlap(btBroadphasePair& pair)
 	virtual bool processOverlap(btBroadphasePair& pair)
 	{
 	{
-		return (!btSimpleBroadphase::aabbOverlap(static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy0),static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy1)));
+		return (!btSimpleBroadphase::aabbOverlap(static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy0), static_cast<btSimpleBroadphaseProxy*>(pair.m_pProxy1)));
 	}
 	}
 };
 };
 
 
-void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
+void btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 {
 {
 	//first check for new overlapping pairs
 	//first check for new overlapping pairs
-	int i,j;
+	int i, j;
 	if (m_numHandles >= 0)
 	if (m_numHandles >= 0)
 	{
 	{
 		int new_largest_index = -1;
 		int new_largest_index = -1;
-		for (i=0; i <= m_LastHandleIndex; i++)
+		for (i = 0; i <= m_LastHandleIndex; i++)
 		{
 		{
 			btSimpleBroadphaseProxy* proxy0 = &m_pHandles[i];
 			btSimpleBroadphaseProxy* proxy0 = &m_pHandles[i];
-			if(!proxy0->m_clientObject)
+			if (!proxy0->m_clientObject)
 			{
 			{
 				continue;
 				continue;
 			}
 			}
 			new_largest_index = i;
 			new_largest_index = i;
-			for (j=i+1; j <= m_LastHandleIndex; j++)
+			for (j = i + 1; j <= m_LastHandleIndex; j++)
 			{
 			{
 				btSimpleBroadphaseProxy* proxy1 = &m_pHandles[j];
 				btSimpleBroadphaseProxy* proxy1 = &m_pHandles[j];
 				btAssert(proxy0 != proxy1);
 				btAssert(proxy0 != proxy1);
-				if(!proxy1->m_clientObject)
+				if (!proxy1->m_clientObject)
 				{
 				{
 					continue;
 					continue;
 				}
 				}
@@ -237,19 +218,20 @@ void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 				btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
 				btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
 				btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
 				btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
 
 
-				if (aabbOverlap(p0,p1))
+				if (aabbOverlap(p0, p1))
 				{
 				{
-					if ( !m_pairCache->findPair(proxy0,proxy1))
+					if (!m_pairCache->findPair(proxy0, proxy1))
 					{
 					{
-						m_pairCache->addOverlappingPair(proxy0,proxy1);
+						m_pairCache->addOverlappingPair(proxy0, proxy1);
 					}
 					}
-				} else
+				}
+				else
 				{
 				{
 					if (!m_pairCache->hasDeferredRemoval())
 					if (!m_pairCache->hasDeferredRemoval())
 					{
 					{
-						if ( m_pairCache->findPair(proxy0,proxy1))
+						if (m_pairCache->findPair(proxy0, proxy1))
 						{
 						{
-							m_pairCache->removeOverlappingPair(proxy0,proxy1,dispatcher);
+							m_pairCache->removeOverlappingPair(proxy0, proxy1, dispatcher);
 						}
 						}
 					}
 					}
 				}
 				}
@@ -260,8 +242,7 @@ void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 
 
 		if (m_ownsPairCache && m_pairCache->hasDeferredRemoval())
 		if (m_ownsPairCache && m_pairCache->hasDeferredRemoval())
 		{
 		{
-
-			btBroadphasePairArray&	overlappingPairArray = m_pairCache->getOverlappingPairArray();
+			btBroadphasePairArray& overlappingPairArray = m_pairCache->getOverlappingPairArray();
 
 
 			//perform a sort, to find duplicates and to sort 'invalid' pairs to the end
 			//perform a sort, to find duplicates and to sort 'invalid' pairs to the end
 			overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
 			overlappingPairArray.quickSort(btBroadphasePairSortPredicate());
@@ -269,16 +250,13 @@ void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 			overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
 			overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
 			m_invalidPair = 0;
 			m_invalidPair = 0;
 
 
-
 			btBroadphasePair previousPair;
 			btBroadphasePair previousPair;
 			previousPair.m_pProxy0 = 0;
 			previousPair.m_pProxy0 = 0;
 			previousPair.m_pProxy1 = 0;
 			previousPair.m_pProxy1 = 0;
 			previousPair.m_algorithm = 0;
 			previousPair.m_algorithm = 0;
 
 
-
-			for (i=0;i<overlappingPairArray.size();i++)
+			for (i = 0; i < overlappingPairArray.size(); i++)
 			{
 			{
-
 				btBroadphasePair& pair = overlappingPairArray[i];
 				btBroadphasePair& pair = overlappingPairArray[i];
 
 
 				bool isDuplicate = (pair == previousPair);
 				bool isDuplicate = (pair == previousPair);
@@ -289,16 +267,18 @@ void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 
 
 				if (!isDuplicate)
 				if (!isDuplicate)
 				{
 				{
-					bool hasOverlap = testAabbOverlap(pair.m_pProxy0,pair.m_pProxy1);
+					bool hasOverlap = testAabbOverlap(pair.m_pProxy0, pair.m_pProxy1);
 
 
 					if (hasOverlap)
 					if (hasOverlap)
 					{
 					{
-						needsRemoval = false;//callback->processOverlap(pair);
-					} else
+						needsRemoval = false;  //callback->processOverlap(pair);
+					}
+					else
 					{
 					{
 						needsRemoval = true;
 						needsRemoval = true;
 					}
 					}
-				} else
+				}
+				else
 				{
 				{
 					//remove duplicate
 					//remove duplicate
 					needsRemoval = true;
 					needsRemoval = true;
@@ -308,16 +288,14 @@ void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 
 
 				if (needsRemoval)
 				if (needsRemoval)
 				{
 				{
-					m_pairCache->cleanOverlappingPair(pair,dispatcher);
+					m_pairCache->cleanOverlappingPair(pair, dispatcher);
 
 
 					//		m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
 					//		m_overlappingPairArray.swap(i,m_overlappingPairArray.size()-1);
 					//		m_overlappingPairArray.pop_back();
 					//		m_overlappingPairArray.pop_back();
 					pair.m_pProxy0 = 0;
 					pair.m_pProxy0 = 0;
 					pair.m_pProxy1 = 0;
 					pair.m_pProxy1 = 0;
 					m_invalidPair++;
 					m_invalidPair++;
-					gOverlappingPairs--;
-				} 
-
+				}
 			}
 			}
 
 
 			///if you don't like to skip the invalid pairs in the array, execute following code:
 			///if you don't like to skip the invalid pairs in the array, execute following code:
@@ -329,21 +307,19 @@ void	btSimpleBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 
 
 			overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
 			overlappingPairArray.resize(overlappingPairArray.size() - m_invalidPair);
 			m_invalidPair = 0;
 			m_invalidPair = 0;
-#endif//CLEAN_INVALID_PAIRS
-
+#endif  //CLEAN_INVALID_PAIRS
 		}
 		}
 	}
 	}
 }
 }
 
 
-
-bool btSimpleBroadphase::testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+bool btSimpleBroadphase::testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 {
 {
 	btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
 	btSimpleBroadphaseProxy* p0 = getSimpleProxyFromProxy(proxy0);
 	btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
 	btSimpleBroadphaseProxy* p1 = getSimpleProxyFromProxy(proxy1);
-	return aabbOverlap(p0,p1);
+	return aabbOverlap(p0, p1);
 }
 }
 
 
-void	btSimpleBroadphase::resetPool(btDispatcher* dispatcher)
+void btSimpleBroadphase::resetPool(btDispatcher* dispatcher)
 {
 {
 	//not yet
 	//not yet
 }
 }

+ 42 - 65
Source/ThirdParty/Bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h

@@ -16,57 +16,47 @@ subject to the following restrictions:
 #ifndef BT_SIMPLE_BROADPHASE_H
 #ifndef BT_SIMPLE_BROADPHASE_H
 #define BT_SIMPLE_BROADPHASE_H
 #define BT_SIMPLE_BROADPHASE_H
 
 
-
 #include "btOverlappingPairCache.h"
 #include "btOverlappingPairCache.h"
 
 
-
 struct btSimpleBroadphaseProxy : public btBroadphaseProxy
 struct btSimpleBroadphaseProxy : public btBroadphaseProxy
 {
 {
-	int			m_nextFree;
-	
-//	int			m_handleId;
+	int m_nextFree;
 
 
-	
-	btSimpleBroadphaseProxy() {};
+	//	int			m_handleId;
 
 
-	btSimpleBroadphaseProxy(const btVector3& minpt,const btVector3& maxpt,int shapeType,void* userPtr, int collisionFilterGroup, int collisionFilterMask)
-	:btBroadphaseProxy(minpt,maxpt,userPtr,collisionFilterGroup,collisionFilterMask)
+	btSimpleBroadphaseProxy(){};
+
+	btSimpleBroadphaseProxy(const btVector3& minpt, const btVector3& maxpt, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask)
+		: btBroadphaseProxy(minpt, maxpt, userPtr, collisionFilterGroup, collisionFilterMask)
 	{
 	{
 		(void)shapeType;
 		(void)shapeType;
 	}
 	}
-	
-	
-	SIMD_FORCE_INLINE void SetNextFree(int next) {m_nextFree = next;}
-	SIMD_FORCE_INLINE int GetNextFree() const {return m_nextFree;}
-
-	
-
 
 
+	SIMD_FORCE_INLINE void SetNextFree(int next) { m_nextFree = next; }
+	SIMD_FORCE_INLINE int GetNextFree() const { return m_nextFree; }
 };
 };
 
 
 ///The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead.
 ///The SimpleBroadphase is just a unit-test for btAxisSweep3, bt32BitAxisSweep3, or btDbvtBroadphase, so use those classes instead.
 ///It is a brute force aabb culling broadphase based on O(n^2) aabb checks
 ///It is a brute force aabb culling broadphase based on O(n^2) aabb checks
 class btSimpleBroadphase : public btBroadphaseInterface
 class btSimpleBroadphase : public btBroadphaseInterface
 {
 {
-
 protected:
 protected:
+	int m_numHandles;  // number of active handles
+	int m_maxHandles;  // max number of handles
+	int m_LastHandleIndex;
 
 
-	int		m_numHandles;						// number of active handles
-	int		m_maxHandles;						// max number of handles
-	int		m_LastHandleIndex;							
-	
-	btSimpleBroadphaseProxy* m_pHandles;						// handles pool
+	btSimpleBroadphaseProxy* m_pHandles;  // handles pool
 
 
 	void* m_pHandlesRawPtr;
 	void* m_pHandlesRawPtr;
-	int		m_firstFreeHandle;		// free handles list
-	
+	int m_firstFreeHandle;  // free handles list
+
 	int allocHandle()
 	int allocHandle()
 	{
 	{
 		btAssert(m_numHandles < m_maxHandles);
 		btAssert(m_numHandles < m_maxHandles);
 		int freeHandle = m_firstFreeHandle;
 		int freeHandle = m_firstFreeHandle;
 		m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
 		m_firstFreeHandle = m_pHandles[freeHandle].GetNextFree();
 		m_numHandles++;
 		m_numHandles++;
-		if(freeHandle > m_LastHandleIndex)
+		if (freeHandle > m_LastHandleIndex)
 		{
 		{
 			m_LastHandleIndex = freeHandle;
 			m_LastHandleIndex = freeHandle;
 		}
 		}
@@ -75,9 +65,9 @@ protected:
 
 
 	void freeHandle(btSimpleBroadphaseProxy* proxy)
 	void freeHandle(btSimpleBroadphaseProxy* proxy)
 	{
 	{
-		int handle = int(proxy-m_pHandles);
+		int handle = int(proxy - m_pHandles);
 		btAssert(handle >= 0 && handle < m_maxHandles);
 		btAssert(handle >= 0 && handle < m_maxHandles);
-		if(handle == m_LastHandleIndex)
+		if (handle == m_LastHandleIndex)
 		{
 		{
 			m_LastHandleIndex--;
 			m_LastHandleIndex--;
 		}
 		}
@@ -89,20 +79,18 @@ protected:
 		m_numHandles--;
 		m_numHandles--;
 	}
 	}
 
 
-	btOverlappingPairCache*	m_pairCache;
-	bool	m_ownsPairCache;
+	btOverlappingPairCache* m_pairCache;
+	bool m_ownsPairCache;
 
 
-	int	m_invalidPair;
+	int m_invalidPair;
 
 
-	
-	
-	inline btSimpleBroadphaseProxy*	getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
+	inline btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy)
 	{
 	{
 		btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
 		btSimpleBroadphaseProxy* proxy0 = static_cast<btSimpleBroadphaseProxy*>(proxy);
 		return proxy0;
 		return proxy0;
 	}
 	}
 
 
-	inline const btSimpleBroadphaseProxy*	getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
+	inline const btSimpleBroadphaseProxy* getSimpleProxyFromProxy(btBroadphaseProxy* proxy) const
 	{
 	{
 		const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
 		const btSimpleBroadphaseProxy* proxy0 = static_cast<const btSimpleBroadphaseProxy*>(proxy);
 		return proxy0;
 		return proxy0;
@@ -111,61 +99,50 @@ protected:
 	///reset broadphase internal structures, to ensure determinism/reproducability
 	///reset broadphase internal structures, to ensure determinism/reproducability
 	virtual void resetPool(btDispatcher* dispatcher);
 	virtual void resetPool(btDispatcher* dispatcher);
 
 
-
-	void	validate();
+	void validate();
 
 
 protected:
 protected:
-
-
-	
-
 public:
 public:
-	btSimpleBroadphase(int maxProxies=16384,btOverlappingPairCache* overlappingPairCache=0);
+	btSimpleBroadphase(int maxProxies = 16384, btOverlappingPairCache* overlappingPairCache = 0);
 	virtual ~btSimpleBroadphase();
 	virtual ~btSimpleBroadphase();
 
 
+	static bool aabbOverlap(btSimpleBroadphaseProxy* proxy0, btSimpleBroadphaseProxy* proxy1);
 
 
-		static bool	aabbOverlap(btSimpleBroadphaseProxy* proxy0,btSimpleBroadphaseProxy* proxy1);
-
+	virtual btBroadphaseProxy* createProxy(const btVector3& aabbMin, const btVector3& aabbMax, int shapeType, void* userPtr, int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
 
 
-	virtual btBroadphaseProxy*	createProxy(  const btVector3& aabbMin,  const btVector3& aabbMax,int shapeType,void* userPtr , int collisionFilterGroup, int collisionFilterMask, btDispatcher* dispatcher);
+	virtual void calculateOverlappingPairs(btDispatcher* dispatcher);
 
 
-	virtual void	calculateOverlappingPairs(btDispatcher* dispatcher);
+	virtual void destroyProxy(btBroadphaseProxy* proxy, btDispatcher* dispatcher);
+	virtual void setAabb(btBroadphaseProxy* proxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* dispatcher);
+	virtual void getAabb(btBroadphaseProxy* proxy, btVector3& aabbMin, btVector3& aabbMax) const;
 
 
-	virtual void	destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
-	virtual void	setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher);
-	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
+	virtual void rayTest(const btVector3& rayFrom, const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin = btVector3(0, 0, 0), const btVector3& aabbMax = btVector3(0, 0, 0));
+	virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
 
 
-	virtual void	rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0));
-	virtual void	aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback);
-		
-	btOverlappingPairCache*	getOverlappingPairCache()
+	btOverlappingPairCache* getOverlappingPairCache()
 	{
 	{
 		return m_pairCache;
 		return m_pairCache;
 	}
 	}
-	const btOverlappingPairCache*	getOverlappingPairCache() const
+	const btOverlappingPairCache* getOverlappingPairCache() const
 	{
 	{
 		return m_pairCache;
 		return m_pairCache;
 	}
 	}
 
 
-	bool	testAabbOverlap(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1);
-
+	bool testAabbOverlap(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1);
 
 
 	///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
 	///getAabb returns the axis aligned bounding box in the 'global' coordinate frame
 	///will add some transform later
 	///will add some transform later
-	virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const
+	virtual void getBroadphaseAabb(btVector3& aabbMin, btVector3& aabbMax) const
 	{
 	{
-		aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT);
-		aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT);
+		aabbMin.setValue(-BT_LARGE_FLOAT, -BT_LARGE_FLOAT, -BT_LARGE_FLOAT);
+		aabbMax.setValue(BT_LARGE_FLOAT, BT_LARGE_FLOAT, BT_LARGE_FLOAT);
 	}
 	}
 
 
-	virtual void	printStats()
+	virtual void printStats()
 	{
 	{
-//		printf("btSimpleBroadphase.h\n");
-//		printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
+		//		printf("btSimpleBroadphase.h\n");
+		//		printf("numHandles = %d, maxHandles = %d\n",m_numHandles,m_maxHandles);
 	}
 	}
 };
 };
 
 
-
-
-#endif //BT_SIMPLE_BROADPHASE_H
-
+#endif  //BT_SIMPLE_BROADPHASE_H

+ 79 - 73
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp

@@ -18,94 +18,95 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 
 
-
-SphereTriangleDetector::SphereTriangleDetector(btSphereShape* sphere,btTriangleShape* triangle,btScalar contactBreakingThreshold)
-:m_sphere(sphere),
-m_triangle(triangle),
-m_contactBreakingThreshold(contactBreakingThreshold)
+SphereTriangleDetector::SphereTriangleDetector(btSphereShape* sphere, btTriangleShape* triangle, btScalar contactBreakingThreshold)
+	: m_sphere(sphere),
+	  m_triangle(triangle),
+	  m_contactBreakingThreshold(contactBreakingThreshold)
 {
 {
-
 }
 }
 
 
-void	SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults)
+void SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input, Result& output, class btIDebugDraw* debugDraw, bool swapResults)
 {
 {
-
 	(void)debugDraw;
 	(void)debugDraw;
 	const btTransform& transformA = input.m_transformA;
 	const btTransform& transformA = input.m_transformA;
 	const btTransform& transformB = input.m_transformB;
 	const btTransform& transformB = input.m_transformB;
 
 
-	btVector3 point,normal;
+	btVector3 point, normal;
 	btScalar timeOfImpact = btScalar(1.);
 	btScalar timeOfImpact = btScalar(1.);
 	btScalar depth = btScalar(0.);
 	btScalar depth = btScalar(0.);
-//	output.m_distance = btScalar(BT_LARGE_FLOAT);
+	//	output.m_distance = btScalar(BT_LARGE_FLOAT);
 	//move sphere into triangle space
 	//move sphere into triangle space
-	btTransform	sphereInTr = transformB.inverseTimes(transformA);
+	btTransform sphereInTr = transformB.inverseTimes(transformA);
 
 
-	if (collide(sphereInTr.getOrigin(),point,normal,depth,timeOfImpact,m_contactBreakingThreshold))
+	if (collide(sphereInTr.getOrigin(), point, normal, depth, timeOfImpact, m_contactBreakingThreshold))
 	{
 	{
 		if (swapResults)
 		if (swapResults)
 		{
 		{
-			btVector3 normalOnB = transformB.getBasis()*normal;
+			btVector3 normalOnB = transformB.getBasis() * normal;
 			btVector3 normalOnA = -normalOnB;
 			btVector3 normalOnA = -normalOnB;
-			btVector3 pointOnA = transformB*point+normalOnB*depth;
-			output.addContactPoint(normalOnA,pointOnA,depth);
-		} else
+			btVector3 pointOnA = transformB * point + normalOnB * depth;
+			output.addContactPoint(normalOnA, pointOnA, depth);
+		}
+		else
 		{
 		{
-			output.addContactPoint(transformB.getBasis()*normal,transformB*point,depth);
+			output.addContactPoint(transformB.getBasis() * normal, transformB * point, depth);
 		}
 		}
 	}
 	}
-
 }
 }
 
 
-
-
 // See also geometrictools.com
 // See also geometrictools.com
 // Basic idea: D = |p - (lo + t0*lv)| where t0 = lv . (p - lo) / lv . lv
 // Basic idea: D = |p - (lo + t0*lv)| where t0 = lv . (p - lo) / lv . lv
-btScalar SegmentSqrDistance(const btVector3& from, const btVector3& to,const btVector3 &p, btVector3 &nearest);
+btScalar SegmentSqrDistance(const btVector3& from, const btVector3& to, const btVector3& p, btVector3& nearest);
 
 
-btScalar SegmentSqrDistance(const btVector3& from, const btVector3& to,const btVector3 &p, btVector3 &nearest) {
+btScalar SegmentSqrDistance(const btVector3& from, const btVector3& to, const btVector3& p, btVector3& nearest)
+{
 	btVector3 diff = p - from;
 	btVector3 diff = p - from;
 	btVector3 v = to - from;
 	btVector3 v = to - from;
 	btScalar t = v.dot(diff);
 	btScalar t = v.dot(diff);
-	
-	if (t > 0) {
+
+	if (t > 0)
+	{
 		btScalar dotVV = v.dot(v);
 		btScalar dotVV = v.dot(v);
-		if (t < dotVV) {
+		if (t < dotVV)
+		{
 			t /= dotVV;
 			t /= dotVV;
-			diff -= t*v;
-		} else {
+			diff -= t * v;
+		}
+		else
+		{
 			t = 1;
 			t = 1;
 			diff -= v;
 			diff -= v;
 		}
 		}
-	} else
+	}
+	else
 		t = 0;
 		t = 0;
 
 
-	nearest = from + t*v;
-	return diff.dot(diff);	
+	nearest = from + t * v;
+	return diff.dot(diff);
 }
 }
 
 
-bool SphereTriangleDetector::facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal)  {
+bool SphereTriangleDetector::facecontains(const btVector3& p, const btVector3* vertices, btVector3& normal)
+{
 	btVector3 lp(p);
 	btVector3 lp(p);
 	btVector3 lnormal(normal);
 	btVector3 lnormal(normal);
-	
+
 	return pointInTriangle(vertices, lnormal, &lp);
 	return pointInTriangle(vertices, lnormal, &lp);
 }
 }
 
 
-bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold)
+bool SphereTriangleDetector::collide(const btVector3& sphereCenter, btVector3& point, btVector3& resultNormal, btScalar& depth, btScalar& timeOfImpact, btScalar contactBreakingThreshold)
 {
 {
-
 	const btVector3* vertices = &m_triangle->getVertexPtr(0);
 	const btVector3* vertices = &m_triangle->getVertexPtr(0);
-	
+
 	btScalar radius = m_sphere->getRadius();
 	btScalar radius = m_sphere->getRadius();
 	btScalar radiusWithThreshold = radius + contactBreakingThreshold;
 	btScalar radiusWithThreshold = radius + contactBreakingThreshold;
 
 
-	btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
+	btVector3 normal = (vertices[1] - vertices[0]).cross(vertices[2] - vertices[0]);
 
 
 	btScalar l2 = normal.length2();
 	btScalar l2 = normal.length2();
 	bool hasContact = false;
 	bool hasContact = false;
 	btVector3 contactPoint;
 	btVector3 contactPoint;
 
 
-	if (l2 >= SIMD_EPSILON*SIMD_EPSILON)
+	if (l2 >= SIMD_EPSILON * SIMD_EPSILON)
 	{
 	{
 		normal /= btSqrt(l2);
 		normal /= btSqrt(l2);
 
 
@@ -120,52 +121,59 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
 		}
 		}
 
 
 		bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
 		bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
-	
+
 		// Check for contact / intersection
 		// Check for contact / intersection
-	
-		if (isInsideContactPlane) {
-			if (facecontains(sphereCenter, vertices, normal)) {
+
+		if (isInsideContactPlane)
+		{
+			if (facecontains(sphereCenter, vertices, normal))
+			{
 				// Inside the contact wedge - touches a point on the shell plane
 				// Inside the contact wedge - touches a point on the shell plane
 				hasContact = true;
 				hasContact = true;
-				contactPoint = sphereCenter - normal*distanceFromPlane;
+				contactPoint = sphereCenter - normal * distanceFromPlane;
 			}
 			}
-			else {
+			else
+			{
 				// Could be inside one of the contact capsules
 				// Could be inside one of the contact capsules
-				btScalar contactCapsuleRadiusSqr = radiusWithThreshold*radiusWithThreshold;
+				btScalar contactCapsuleRadiusSqr = radiusWithThreshold * radiusWithThreshold;
+				btScalar minDistSqr = contactCapsuleRadiusSqr;
 				btVector3 nearestOnEdge;
 				btVector3 nearestOnEdge;
-				for (int i = 0; i < m_triangle->getNumEdges(); i++) {
-
+				for (int i = 0; i < m_triangle->getNumEdges(); i++)
+				{
 					btVector3 pa;
 					btVector3 pa;
 					btVector3 pb;
 					btVector3 pb;
 
 
 					m_triangle->getEdge(i, pa, pb);
 					m_triangle->getEdge(i, pa, pb);
 
 
 					btScalar distanceSqr = SegmentSqrDistance(pa, pb, sphereCenter, nearestOnEdge);
 					btScalar distanceSqr = SegmentSqrDistance(pa, pb, sphereCenter, nearestOnEdge);
-					if (distanceSqr < contactCapsuleRadiusSqr) {
-						// Yep, we're inside a capsule
+					if (distanceSqr < minDistSqr)
+					{
+						// Yep, we're inside a capsule, and record the capsule with smallest distance
+						minDistSqr = distanceSqr;
 						hasContact = true;
 						hasContact = true;
 						contactPoint = nearestOnEdge;
 						contactPoint = nearestOnEdge;
 					}
 					}
-
 				}
 				}
 			}
 			}
 		}
 		}
 	}
 	}
 
 
-	if (hasContact) {
+	if (hasContact)
+	{
 		btVector3 contactToCentre = sphereCenter - contactPoint;
 		btVector3 contactToCentre = sphereCenter - contactPoint;
 		btScalar distanceSqr = contactToCentre.length2();
 		btScalar distanceSqr = contactToCentre.length2();
 
 
-		if (distanceSqr < radiusWithThreshold*radiusWithThreshold)
+		if (distanceSqr < radiusWithThreshold * radiusWithThreshold)
 		{
 		{
-			if (distanceSqr>SIMD_EPSILON)
+			if (distanceSqr > SIMD_EPSILON)
 			{
 			{
 				btScalar distance = btSqrt(distanceSqr);
 				btScalar distance = btSqrt(distanceSqr);
 				resultNormal = contactToCentre;
 				resultNormal = contactToCentre;
 				resultNormal.normalize();
 				resultNormal.normalize();
 				point = contactPoint;
 				point = contactPoint;
-				depth = -(radius-distance);
-			} else
+				depth = -(radius - distance);
+			}
+			else
 			{
 			{
 				resultNormal = normal;
 				resultNormal = normal;
 				point = contactPoint;
 				point = contactPoint;
@@ -174,36 +182,34 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
 			return true;
 			return true;
 		}
 		}
 	}
 	}
-	
+
 	return false;
 	return false;
 }
 }
 
 
-
-bool SphereTriangleDetector::pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p )
+bool SphereTriangleDetector::pointInTriangle(const btVector3 vertices[], const btVector3& normal, btVector3* p)
 {
 {
 	const btVector3* p1 = &vertices[0];
 	const btVector3* p1 = &vertices[0];
 	const btVector3* p2 = &vertices[1];
 	const btVector3* p2 = &vertices[1];
 	const btVector3* p3 = &vertices[2];
 	const btVector3* p3 = &vertices[2];
 
 
-	btVector3 edge1( *p2 - *p1 );
-	btVector3 edge2( *p3 - *p2 );
-	btVector3 edge3( *p1 - *p3 );
+	btVector3 edge1(*p2 - *p1);
+	btVector3 edge2(*p3 - *p2);
+	btVector3 edge3(*p1 - *p3);
+
+	btVector3 p1_to_p(*p - *p1);
+	btVector3 p2_to_p(*p - *p2);
+	btVector3 p3_to_p(*p - *p3);
 
 
-	btVector3 p1_to_p( *p - *p1 );
-	btVector3 p2_to_p( *p - *p2 );
-	btVector3 p3_to_p( *p - *p3 );
+	btVector3 edge1_normal(edge1.cross(normal));
+	btVector3 edge2_normal(edge2.cross(normal));
+	btVector3 edge3_normal(edge3.cross(normal));
 
 
-	btVector3 edge1_normal( edge1.cross(normal));
-	btVector3 edge2_normal( edge2.cross(normal));
-	btVector3 edge3_normal( edge3.cross(normal));
-	
 	btScalar r1, r2, r3;
 	btScalar r1, r2, r3;
-	r1 = edge1_normal.dot( p1_to_p );
-	r2 = edge2_normal.dot( p2_to_p );
-	r3 = edge3_normal.dot( p3_to_p );
-	if ( ( r1 > 0 && r2 > 0 && r3 > 0 ) ||
-	     ( r1 <= 0 && r2 <= 0 && r3 <= 0 ) )
+	r1 = edge1_normal.dot(p1_to_p);
+	r2 = edge2_normal.dot(p2_to_p);
+	r3 = edge3_normal.dot(p3_to_p);
+	if ((r1 > 0 && r2 > 0 && r3 > 0) ||
+		(r1 <= 0 && r2 <= 0 && r3 <= 0))
 		return true;
 		return true;
 	return false;
 	return false;
-
 }
 }

+ 8 - 16
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h

@@ -18,34 +18,26 @@ subject to the following restrictions:
 
 
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 
 
-
-
 class btSphereShape;
 class btSphereShape;
 class btTriangleShape;
 class btTriangleShape;
 
 
-
-
 /// sphere-triangle to match the btDiscreteCollisionDetectorInterface
 /// sphere-triangle to match the btDiscreteCollisionDetectorInterface
 struct SphereTriangleDetector : public btDiscreteCollisionDetectorInterface
 struct SphereTriangleDetector : public btDiscreteCollisionDetectorInterface
 {
 {
-	virtual void	getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults=false);
+	virtual void getClosestPoints(const ClosestPointInput& input, Result& output, class btIDebugDraw* debugDraw, bool swapResults = false);
 
 
-	SphereTriangleDetector(btSphereShape* sphere,btTriangleShape* triangle, btScalar contactBreakingThreshold);
+	SphereTriangleDetector(btSphereShape* sphere, btTriangleShape* triangle, btScalar contactBreakingThreshold);
 
 
-	virtual ~SphereTriangleDetector() {};
+	virtual ~SphereTriangleDetector(){};
 
 
-	bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar	contactBreakingThreshold);
+	bool collide(const btVector3& sphereCenter, btVector3& point, btVector3& resultNormal, btScalar& depth, btScalar& timeOfImpact, btScalar contactBreakingThreshold);
 
 
 private:
 private:
-
-	
-	bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p );
-	bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal);
+	bool pointInTriangle(const btVector3 vertices[], const btVector3& normal, btVector3* p);
+	bool facecontains(const btVector3& p, const btVector3* vertices, btVector3& normal);
 
 
 	btSphereShape* m_sphere;
 	btSphereShape* m_sphere;
 	btTriangleShape* m_triangle;
 	btTriangleShape* m_triangle;
-	btScalar	m_contactBreakingThreshold;
-	
+	btScalar m_contactBreakingThreshold;
 };
 };
-#endif //BT_SPHERE_TRIANGLE_DETECTOR_H
-
+#endif  //BT_SPHERE_TRIANGLE_DETECTOR_H

+ 14 - 14
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp

@@ -17,31 +17,31 @@ subject to the following restrictions:
 #include "btCollisionDispatcher.h"
 #include "btCollisionDispatcher.h"
 #include "btCollisionObject.h"
 #include "btCollisionObject.h"
 
 
-btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci)
-:btCollisionAlgorithm(ci)
+btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
+	: btCollisionAlgorithm(ci)
 //,
 //,
 //m_colObj0(0),
 //m_colObj0(0),
 //m_colObj1(0)
 //m_colObj1(0)
 {
 {
 }
 }
-btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* )
-:btCollisionAlgorithm(ci)
+btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper*, const btCollisionObjectWrapper*)
+	: btCollisionAlgorithm(ci)
 //,
 //,
 //m_colObj0(0),
 //m_colObj0(0),
 //m_colObj1(0)
 //m_colObj1(0)
 {
 {
-//	if (ci.m_dispatcher1->needsCollision(colObj0,colObj1))
-//	{
-//		m_colObj0 = colObj0;
-//		m_colObj1 = colObj1;
-//		
-//		m_colObj0->activate();
-//		m_colObj1->activate();
-//	}
+	//	if (ci.m_dispatcher1->needsCollision(colObj0,colObj1))
+	//	{
+	//		m_colObj0 = colObj0;
+	//		m_colObj1 = colObj1;
+	//
+	//		m_colObj0->activate();
+	//		m_colObj1->activate();
+	//	}
 }
 }
 
 
 btActivatingCollisionAlgorithm::~btActivatingCollisionAlgorithm()
 btActivatingCollisionAlgorithm::~btActivatingCollisionAlgorithm()
 {
 {
-//		m_colObj0->activate();
-//		m_colObj1->activate();
+	//		m_colObj0->activate();
+	//		m_colObj1->activate();
 }
 }

+ 7 - 8
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h

@@ -21,16 +21,15 @@ subject to the following restrictions:
 ///This class is not enabled yet (work-in-progress) to more aggressively activate objects.
 ///This class is not enabled yet (work-in-progress) to more aggressively activate objects.
 class btActivatingCollisionAlgorithm : public btCollisionAlgorithm
 class btActivatingCollisionAlgorithm : public btCollisionAlgorithm
 {
 {
-//	btCollisionObject* m_colObj0;
-//	btCollisionObject* m_colObj1;
+	//	btCollisionObject* m_colObj0;
+	//	btCollisionObject* m_colObj1;
 
 
-public:
-
-	btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci);
+protected:
+	btActivatingCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 
 
-	btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
+	btActivatingCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
 
 
+public:
 	virtual ~btActivatingCollisionAlgorithm();
 	virtual ~btActivatingCollisionAlgorithm();
-
 };
 };
-#endif //__BT_ACTIVATING_COLLISION_ALGORITHM_H
+#endif  //__BT_ACTIVATING_COLLISION_ALGORITHM_H

+ 48 - 58
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp

@@ -26,61 +26,55 @@ subject to the following restrictions:
 
 
 #define USE_PERSISTENT_CONTACTS 1
 #define USE_PERSISTENT_CONTACTS 1
 
 
-btBox2dBox2dCollisionAlgorithm::btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* obj0Wrap,const btCollisionObjectWrapper* obj1Wrap)
-: btActivatingCollisionAlgorithm(ci,obj0Wrap,obj1Wrap),
-m_ownManifold(false),
-m_manifoldPtr(mf)
+btBox2dBox2dCollisionAlgorithm::btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* obj0Wrap, const btCollisionObjectWrapper* obj1Wrap)
+	: btActivatingCollisionAlgorithm(ci, obj0Wrap, obj1Wrap),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf)
 {
 {
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0Wrap->getCollisionObject(),obj1Wrap->getCollisionObject()))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0Wrap->getCollisionObject(), obj1Wrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(obj0Wrap->getCollisionObject(),obj1Wrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(obj0Wrap->getCollisionObject(), obj1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
 
 
 btBox2dBox2dCollisionAlgorithm::~btBox2dBox2dCollisionAlgorithm()
 btBox2dBox2dCollisionAlgorithm::~btBox2dBox2dCollisionAlgorithm()
 {
 {
-	
 	if (m_ownManifold)
 	if (m_ownManifold)
 	{
 	{
 		if (m_manifoldPtr)
 		if (m_manifoldPtr)
 			m_dispatcher->releaseManifold(m_manifoldPtr);
 			m_dispatcher->releaseManifold(m_manifoldPtr);
 	}
 	}
-	
 }
 }
 
 
-
-void b2CollidePolygons(btManifoldResult* manifold,  const btBox2dShape* polyA, const btTransform& xfA, const btBox2dShape* polyB, const btTransform& xfB);
+void b2CollidePolygons(btManifoldResult* manifold, const btBox2dShape* polyA, const btTransform& xfA, const btBox2dShape* polyB, const btTransform& xfB);
 
 
 //#include <stdio.h>
 //#include <stdio.h>
-void btBox2dBox2dCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btBox2dBox2dCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 		return;
 		return;
 
 
-	
 	const btBox2dShape* box0 = (const btBox2dShape*)body0Wrap->getCollisionShape();
 	const btBox2dShape* box0 = (const btBox2dShape*)body0Wrap->getCollisionShape();
 	const btBox2dShape* box1 = (const btBox2dShape*)body1Wrap->getCollisionShape();
 	const btBox2dShape* box1 = (const btBox2dShape*)body1Wrap->getCollisionShape();
 
 
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
 
 
-	b2CollidePolygons(resultOut,box0,body0Wrap->getWorldTransform(),box1,body1Wrap->getWorldTransform());
+	b2CollidePolygons(resultOut, box0, body0Wrap->getWorldTransform(), box1, body1Wrap->getWorldTransform());
 
 
 	//  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
 	//  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
 	if (m_ownManifold)
 	if (m_ownManifold)
 	{
 	{
 		resultOut->refreshContactPoints();
 		resultOut->refreshContactPoints();
 	}
 	}
-
 }
 }
 
 
-btScalar btBox2dBox2dCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/,btCollisionObject* /*body1*/,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/)
+btScalar btBox2dBox2dCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/, btCollisionObject* /*body1*/, const btDispatcherInfo& /*dispatchInfo*/, btManifoldResult* /*resultOut*/)
 {
 {
 	//not yet
 	//not yet
 	return 1.f;
 	return 1.f;
 }
 }
 
 
-
 struct ClipVertex
 struct ClipVertex
 {
 {
 	btVector3 v;
 	btVector3 v;
@@ -89,16 +83,16 @@ struct ClipVertex
 	//b2ContactID id;
 	//b2ContactID id;
 };
 };
 
 
-#define b2Dot(a,b) (a).dot(b)
-#define b2Mul(a,b) (a)*(b)
-#define b2MulT(a,b) (a).transpose()*(b)
-#define b2Cross(a,b) (a).cross(b)
-#define btCrossS(a,s) btVector3(s * a.getY(), -s * a.getX(),0.f)
+#define b2Dot(a, b) (a).dot(b)
+#define b2Mul(a, b) (a) * (b)
+#define b2MulT(a, b) (a).transpose() * (b)
+#define b2Cross(a, b) (a).cross(b)
+#define btCrossS(a, s) btVector3(s* a.getY(), -s* a.getX(), 0.f)
 
 
-int b2_maxManifoldPoints =2;
+int b2_maxManifoldPoints = 2;
 
 
 static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
 static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
-					  const btVector3& normal, btScalar offset)
+							 const btVector3& normal, btScalar offset)
 {
 {
 	// Start with no output points
 	// Start with no output points
 	int numOut = 0;
 	int numOut = 0;
@@ -133,7 +127,7 @@ static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
 
 
 // Find the separation between poly1 and poly2 for a give edge normal on poly1.
 // Find the separation between poly1 and poly2 for a give edge normal on poly1.
 static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1, int edge1,
 static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1, int edge1,
-							  const btBox2dShape* poly2, const btTransform& xf2)
+							   const btBox2dShape* poly2, const btTransform& xf2)
 {
 {
 	const btVector3* vertices1 = poly1->getVertices();
 	const btVector3* vertices1 = poly1->getVertices();
 	const btVector3* normals1 = poly1->getNormals();
 	const btVector3* normals1 = poly1->getNormals();
@@ -151,8 +145,8 @@ static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1
 	int index = 0;
 	int index = 0;
 	btScalar minDot = BT_LARGE_FLOAT;
 	btScalar minDot = BT_LARGE_FLOAT;
 
 
-    if( count2 > 0 )
-        index = (int) normal1.minDot( vertices2, count2, minDot);
+	if (count2 > 0)
+		index = (int)normal1.minDot(vertices2, count2, minDot);
 
 
 	btVector3 v1 = b2Mul(xf1, vertices1[edge1]);
 	btVector3 v1 = b2Mul(xf1, vertices1[edge1]);
 	btVector3 v2 = b2Mul(xf2, vertices2[index]);
 	btVector3 v2 = b2Mul(xf2, vertices2[index]);
@@ -162,8 +156,8 @@ static btScalar EdgeSeparation(const btBox2dShape* poly1, const btTransform& xf1
 
 
 // Find the max separation between poly1 and poly2 using edge normals from poly1.
 // Find the max separation between poly1 and poly2 using edge normals from poly1.
 static btScalar FindMaxSeparation(int* edgeIndex,
 static btScalar FindMaxSeparation(int* edgeIndex,
-								 const btBox2dShape* poly1, const btTransform& xf1,
-								 const btBox2dShape* poly2, const btTransform& xf2)
+								  const btBox2dShape* poly1, const btTransform& xf1,
+								  const btBox2dShape* poly2, const btTransform& xf2)
 {
 {
 	int count1 = poly1->getVertexCount();
 	int count1 = poly1->getVertexCount();
 	const btVector3* normals1 = poly1->getNormals();
 	const btVector3* normals1 = poly1->getNormals();
@@ -174,9 +168,9 @@ static btScalar FindMaxSeparation(int* edgeIndex,
 
 
 	// Find edge normal on poly1 that has the largest projection onto d.
 	// Find edge normal on poly1 that has the largest projection onto d.
 	int edge = 0;
 	int edge = 0;
-    btScalar maxDot;
-    if( count1 > 0 )
-        edge = (int) dLocal1.maxDot( normals1, count1, maxDot);
+	btScalar maxDot;
+	if (count1 > 0)
+		edge = (int)dLocal1.maxDot(normals1, count1, maxDot);
 
 
 	// Get the separation for the edge normal.
 	// Get the separation for the edge normal.
 	btScalar s = EdgeSeparation(poly1, xf1, edge, poly2, xf2);
 	btScalar s = EdgeSeparation(poly1, xf1, edge, poly2, xf2);
@@ -224,7 +218,7 @@ static btScalar FindMaxSeparation(int* edgeIndex,
 	}
 	}
 
 
 	// Perform a local search for the best edge normal.
 	// Perform a local search for the best edge normal.
-	for ( ; ; )
+	for (;;)
 	{
 	{
 		if (increment == -1)
 		if (increment == -1)
 			edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
 			edge = bestEdge - 1 >= 0 ? bestEdge - 1 : count1 - 1;
@@ -285,14 +279,14 @@ static void FindIncidentEdge(ClipVertex c[2],
 	int i2 = i1 + 1 < count2 ? i1 + 1 : 0;
 	int i2 = i1 + 1 < count2 ? i1 + 1 : 0;
 
 
 	c[0].v = b2Mul(xf2, vertices2[i1]);
 	c[0].v = b2Mul(xf2, vertices2[i1]);
-//	c[0].id.features.referenceEdge = (unsigned char)edge1;
-//	c[0].id.features.incidentEdge = (unsigned char)i1;
-//	c[0].id.features.incidentVertex = 0;
+	//	c[0].id.features.referenceEdge = (unsigned char)edge1;
+	//	c[0].id.features.incidentEdge = (unsigned char)i1;
+	//	c[0].id.features.incidentVertex = 0;
 
 
 	c[1].v = b2Mul(xf2, vertices2[i2]);
 	c[1].v = b2Mul(xf2, vertices2[i2]);
-//	c[1].id.features.referenceEdge = (unsigned char)edge1;
-//	c[1].id.features.incidentEdge = (unsigned char)i2;
-//	c[1].id.features.incidentVertex = 1;
+	//	c[1].id.features.referenceEdge = (unsigned char)edge1;
+	//	c[1].id.features.incidentEdge = (unsigned char)i2;
+	//	c[1].id.features.incidentVertex = 1;
 }
 }
 
 
 // Find edge normal of max separation on A - return if separating axis is found
 // Find edge normal of max separation on A - return if separating axis is found
@@ -303,10 +297,9 @@ static void FindIncidentEdge(ClipVertex c[2],
 
 
 // The normal points from 1 to 2
 // The normal points from 1 to 2
 void b2CollidePolygons(btManifoldResult* manifold,
 void b2CollidePolygons(btManifoldResult* manifold,
-					  const btBox2dShape* polyA, const btTransform& xfA,
-					  const btBox2dShape* polyB, const btTransform& xfB)
+					   const btBox2dShape* polyA, const btTransform& xfA,
+					   const btBox2dShape* polyB, const btTransform& xfB)
 {
 {
-
 	int edgeA = 0;
 	int edgeA = 0;
 	btScalar separationA = FindMaxSeparation(&edgeA, polyA, xfA, polyB, xfB);
 	btScalar separationA = FindMaxSeparation(&edgeA, polyA, xfA, polyB, xfB);
 	if (separationA > 0.0f)
 	if (separationA > 0.0f)
@@ -317,10 +310,10 @@ void b2CollidePolygons(btManifoldResult* manifold,
 	if (separationB > 0.0f)
 	if (separationB > 0.0f)
 		return;
 		return;
 
 
-	const btBox2dShape* poly1;	// reference poly
-	const btBox2dShape* poly2;	// incident poly
+	const btBox2dShape* poly1;  // reference poly
+	const btBox2dShape* poly2;  // incident poly
 	btTransform xf1, xf2;
 	btTransform xf1, xf2;
-	int edge1;		// reference edge
+	int edge1;  // reference edge
 	unsigned char flip;
 	unsigned char flip;
 	const btScalar k_relativeTol = 0.98f;
 	const btScalar k_relativeTol = 0.98f;
 	const btScalar k_absoluteTol = 0.001f;
 	const btScalar k_absoluteTol = 0.001f;
@@ -352,14 +345,13 @@ void b2CollidePolygons(btManifoldResult* manifold,
 	const btVector3* vertices1 = poly1->getVertices();
 	const btVector3* vertices1 = poly1->getVertices();
 
 
 	btVector3 v11 = vertices1[edge1];
 	btVector3 v11 = vertices1[edge1];
-	btVector3 v12 = edge1 + 1 < count1 ? vertices1[edge1+1] : vertices1[0];
+	btVector3 v12 = edge1 + 1 < count1 ? vertices1[edge1 + 1] : vertices1[0];
 
 
 	//btVector3 dv = v12 - v11;
 	//btVector3 dv = v12 - v11;
 	btVector3 sideNormal = b2Mul(xf1.getBasis(), v12 - v11);
 	btVector3 sideNormal = b2Mul(xf1.getBasis(), v12 - v11);
 	sideNormal.normalize();
 	sideNormal.normalize();
 	btVector3 frontNormal = btCrossS(sideNormal, 1.0f);
 	btVector3 frontNormal = btCrossS(sideNormal, 1.0f);
-	
-	
+
 	v11 = b2Mul(xf1, v11);
 	v11 = b2Mul(xf1, v11);
 	v12 = b2Mul(xf1, v12);
 	v12 = b2Mul(xf1, v12);
 
 
@@ -369,13 +361,12 @@ void b2CollidePolygons(btManifoldResult* manifold,
 
 
 	// Clip incident edge against extruded edge1 side edges.
 	// Clip incident edge against extruded edge1 side edges.
 	ClipVertex clipPoints1[2];
 	ClipVertex clipPoints1[2];
-	clipPoints1[0].v.setValue(0,0,0);
-	clipPoints1[1].v.setValue(0,0,0);
+	clipPoints1[0].v.setValue(0, 0, 0);
+	clipPoints1[1].v.setValue(0, 0, 0);
 
 
 	ClipVertex clipPoints2[2];
 	ClipVertex clipPoints2[2];
-	clipPoints2[0].v.setValue(0,0,0);
-	clipPoints2[1].v.setValue(0,0,0);
-
+	clipPoints2[0].v.setValue(0, 0, 0);
+	clipPoints2[1].v.setValue(0, 0, 0);
 
 
 	int np;
 	int np;
 
 
@@ -386,7 +377,7 @@ void b2CollidePolygons(btManifoldResult* manifold,
 		return;
 		return;
 
 
 	// Clip to negative box side 1
 	// Clip to negative box side 1
-	np = ClipSegmentToLine(clipPoints2, clipPoints1,  sideNormal, sideOffset2);
+	np = ClipSegmentToLine(clipPoints2, clipPoints1, sideNormal, sideOffset2);
 
 
 	if (np < 2)
 	if (np < 2)
 	{
 	{
@@ -403,19 +394,18 @@ void b2CollidePolygons(btManifoldResult* manifold,
 
 
 		if (separation <= 0.0f)
 		if (separation <= 0.0f)
 		{
 		{
-			
 			//b2ManifoldPoint* cp = manifold->points + pointCount;
 			//b2ManifoldPoint* cp = manifold->points + pointCount;
 			//btScalar separation = separation;
 			//btScalar separation = separation;
 			//cp->localPoint1 = b2MulT(xfA, clipPoints2[i].v);
 			//cp->localPoint1 = b2MulT(xfA, clipPoints2[i].v);
 			//cp->localPoint2 = b2MulT(xfB, clipPoints2[i].v);
 			//cp->localPoint2 = b2MulT(xfB, clipPoints2[i].v);
 
 
-			manifold->addContactPoint(-manifoldNormal,clipPoints2[i].v,separation);
+			manifold->addContactPoint(-manifoldNormal, clipPoints2[i].v, separation);
 
 
-//			cp->id = clipPoints2[i].id;
-//			cp->id.features.flip = flip;
+			//			cp->id = clipPoints2[i].id;
+			//			cp->id.features.flip = flip;
 			++pointCount;
 			++pointCount;
 		}
 		}
 	}
 	}
 
 
-//	manifold->pointCount = pointCount;}
+	//	manifold->pointCount = pointCount;}
 }
 }

+ 11 - 14
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h

@@ -26,22 +26,22 @@ class btPersistentManifold;
 ///box-box collision detection
 ///box-box collision detection
 class btBox2dBox2dCollisionAlgorithm : public btActivatingCollisionAlgorithm
 class btBox2dBox2dCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+
 public:
 public:
 	btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 		: btActivatingCollisionAlgorithm(ci) {}
 		: btActivatingCollisionAlgorithm(ci) {}
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
+	btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
 
 
 	virtual ~btBox2dBox2dCollisionAlgorithm();
 	virtual ~btBox2dBox2dCollisionAlgorithm();
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 		{
 		{
@@ -49,18 +49,15 @@ public:
 		}
 		}
 	}
 	}
 
 
-
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			int bbsize = sizeof(btBox2dBox2dCollisionAlgorithm);
 			int bbsize = sizeof(btBox2dBox2dCollisionAlgorithm);
 			void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
 			void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
-			return new(ptr) btBox2dBox2dCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
+			return new (ptr) btBox2dBox2dCollisionAlgorithm(0, ci, body0Wrap, body1Wrap);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
-
+#endif  //BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H

+ 13 - 17
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp

@@ -21,14 +21,14 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #define USE_PERSISTENT_CONTACTS 1
 #define USE_PERSISTENT_CONTACTS 1
 
 
-btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
-: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_ownManifold(false),
-m_manifoldPtr(mf)
+btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
+	: btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf)
 {
 {
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject()))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(body0Wrap->getCollisionObject(), body1Wrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(), body1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -42,30 +42,27 @@ btBoxBoxCollisionAlgorithm::~btBoxBoxCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btBoxBoxCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btBoxBoxCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 		return;
 		return;
 
 
-	
 	const btBoxShape* box0 = (btBoxShape*)body0Wrap->getCollisionShape();
 	const btBoxShape* box0 = (btBoxShape*)body0Wrap->getCollisionShape();
 	const btBoxShape* box1 = (btBoxShape*)body1Wrap->getCollisionShape();
 	const btBoxShape* box1 = (btBoxShape*)body1Wrap->getCollisionShape();
 
 
-
-
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
-#ifndef USE_PERSISTENT_CONTACTS	
+#ifndef USE_PERSISTENT_CONTACTS
 	m_manifoldPtr->clearManifold();
 	m_manifoldPtr->clearManifold();
-#endif //USE_PERSISTENT_CONTACTS
+#endif  //USE_PERSISTENT_CONTACTS
 
 
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
 	input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
 	input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
 	input.m_transformA = body0Wrap->getWorldTransform();
 	input.m_transformA = body0Wrap->getWorldTransform();
 	input.m_transformB = body1Wrap->getWorldTransform();
 	input.m_transformB = body1Wrap->getWorldTransform();
 
 
-	btBoxBoxDetector detector(box0,box1);
-	detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+	btBoxBoxDetector detector(box0, box1);
+	detector.getClosestPoints(input, *resultOut, dispatchInfo.m_debugDraw);
 
 
 #ifdef USE_PERSISTENT_CONTACTS
 #ifdef USE_PERSISTENT_CONTACTS
 	//  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
 	//  refreshContactPoints is only necessary when using persistent contact points. otherwise all points are newly added
@@ -73,11 +70,10 @@ void btBoxBoxCollisionAlgorithm::processCollision (const btCollisionObjectWrappe
 	{
 	{
 		resultOut->refreshContactPoints();
 		resultOut->refreshContactPoints();
 	}
 	}
-#endif //USE_PERSISTENT_CONTACTS
-
+#endif  //USE_PERSISTENT_CONTACTS
 }
 }
 
 
-btScalar btBoxBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/,btCollisionObject* /*body1*/,const btDispatcherInfo& /*dispatchInfo*/,btManifoldResult* /*resultOut*/)
+btScalar btBoxBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* /*body0*/, btCollisionObject* /*body1*/, const btDispatcherInfo& /*dispatchInfo*/, btManifoldResult* /*resultOut*/)
 {
 {
 	//not yet
 	//not yet
 	return 1.f;
 	return 1.f;

+ 11 - 14
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h

@@ -26,22 +26,22 @@ class btPersistentManifold;
 ///box-box collision detection
 ///box-box collision detection
 class btBoxBoxCollisionAlgorithm : public btActivatingCollisionAlgorithm
 class btBoxBoxCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+
 public:
 public:
 	btBoxBoxCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	btBoxBoxCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 		: btActivatingCollisionAlgorithm(ci) {}
 		: btActivatingCollisionAlgorithm(ci) {}
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
+	btBoxBoxCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
 
 
 	virtual ~btBoxBoxCollisionAlgorithm();
 	virtual ~btBoxBoxCollisionAlgorithm();
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 		{
 		{
@@ -49,18 +49,15 @@ public:
 		}
 		}
 	}
 	}
 
 
-
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			int bbsize = sizeof(btBoxBoxCollisionAlgorithm);
 			int bbsize = sizeof(btBoxBoxCollisionAlgorithm);
 			void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
 			void* ptr = ci.m_dispatcher1->allocateCollisionAlgorithm(bbsize);
-			return new(ptr) btBoxBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
+			return new (ptr) btBoxBoxCollisionAlgorithm(0, ci, body0Wrap, body1Wrap);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_BOX_BOX__COLLISION_ALGORITHM_H
-
+#endif  //BT_BOX_BOX__COLLISION_ALGORITHM_H

+ 637 - 588
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp

@@ -24,14 +24,12 @@ subject to the following restrictions:
 #include <float.h>
 #include <float.h>
 #include <string.h>
 #include <string.h>
 
 
-btBoxBoxDetector::btBoxBoxDetector(const btBoxShape* box1,const btBoxShape* box2)
-: m_box1(box1),
-m_box2(box2)
+btBoxBoxDetector::btBoxBoxDetector(const btBoxShape* box1, const btBoxShape* box2)
+	: m_box1(box1),
+	  m_box2(box2)
 {
 {
-
 }
 }
 
 
-
 // given two boxes (p1,R1,side1) and (p2,R2,side2), collide them together and
 // given two boxes (p1,R1,side1) and (p2,R2,side2), collide them together and
 // generate contact points. this returns 0 if there is no contact otherwise
 // generate contact points. this returns 0 if there is no contact otherwise
 // it returns the number of contacts generated.
 // it returns the number of contacts generated.
@@ -48,67 +46,66 @@ m_box2(box2)
 // collision functions. this function only fills in the position and depth
 // collision functions. this function only fills in the position and depth
 // fields.
 // fields.
 struct dContactGeom;
 struct dContactGeom;
-#define dDOTpq(a,b,p,q) ((a)[0]*(b)[0] + (a)[p]*(b)[q] + (a)[2*(p)]*(b)[2*(q)])
+#define dDOTpq(a, b, p, q) ((a)[0] * (b)[0] + (a)[p] * (b)[q] + (a)[2 * (p)] * (b)[2 * (q)])
 #define dInfinity FLT_MAX
 #define dInfinity FLT_MAX
 
 
-
 /*PURE_INLINE btScalar dDOT   (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,1,1); }
 /*PURE_INLINE btScalar dDOT   (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,1,1); }
 PURE_INLINE btScalar dDOT13 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,1,3); }
 PURE_INLINE btScalar dDOT13 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,1,3); }
 PURE_INLINE btScalar dDOT31 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,3,1); }
 PURE_INLINE btScalar dDOT31 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,3,1); }
 PURE_INLINE btScalar dDOT33 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,3,3); }
 PURE_INLINE btScalar dDOT33 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,3,3); }
 */
 */
-static btScalar dDOT   (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,1,1); }
-static btScalar dDOT44 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,4,4); }
-static btScalar dDOT41 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,4,1); }
-static btScalar dDOT14 (const btScalar *a, const btScalar *b) { return dDOTpq(a,b,1,4); }
-#define dMULTIPLYOP1_331(A,op,B,C) \
-{\
-  (A)[0] op dDOT41((B),(C)); \
-  (A)[1] op dDOT41((B+1),(C)); \
-  (A)[2] op dDOT41((B+2),(C)); \
-}
+static btScalar dDOT(const btScalar* a, const btScalar* b) { return dDOTpq(a, b, 1, 1); }
+static btScalar dDOT44(const btScalar* a, const btScalar* b) { return dDOTpq(a, b, 4, 4); }
+static btScalar dDOT41(const btScalar* a, const btScalar* b) { return dDOTpq(a, b, 4, 1); }
+static btScalar dDOT14(const btScalar* a, const btScalar* b) { return dDOTpq(a, b, 1, 4); }
+#define dMULTIPLYOP1_331(A, op, B, C)   \
+	{                                   \
+		(A)[0] op dDOT41((B), (C));     \
+		(A)[1] op dDOT41((B + 1), (C)); \
+		(A)[2] op dDOT41((B + 2), (C)); \
+	}
 
 
-#define dMULTIPLYOP0_331(A,op,B,C) \
-{ \
-  (A)[0] op dDOT((B),(C)); \
-  (A)[1] op dDOT((B+4),(C)); \
-  (A)[2] op dDOT((B+8),(C)); \
-} 
+#define dMULTIPLYOP0_331(A, op, B, C) \
+	{                                 \
+		(A)[0] op dDOT((B), (C));     \
+		(A)[1] op dDOT((B + 4), (C)); \
+		(A)[2] op dDOT((B + 8), (C)); \
+	}
 
 
-#define dMULTIPLY1_331(A,B,C) dMULTIPLYOP1_331(A,=,B,C)
-#define dMULTIPLY0_331(A,B,C) dMULTIPLYOP0_331(A,=,B,C)
+#define dMULTIPLY1_331(A, B, C) dMULTIPLYOP1_331(A, =, B, C)
+#define dMULTIPLY0_331(A, B, C) dMULTIPLYOP0_331(A, =, B, C)
 
 
-typedef btScalar dMatrix3[4*3];
+typedef btScalar dMatrix3[4 * 3];
 
 
-void dLineClosestApproach (const btVector3& pa, const btVector3& ua,
-			   const btVector3& pb, const btVector3& ub,
-			   btScalar *alpha, btScalar *beta);
-void dLineClosestApproach (const btVector3& pa, const btVector3& ua,
-			   const btVector3& pb, const btVector3& ub,
-			   btScalar *alpha, btScalar *beta)
+void dLineClosestApproach(const btVector3& pa, const btVector3& ua,
+						  const btVector3& pb, const btVector3& ub,
+						  btScalar* alpha, btScalar* beta);
+void dLineClosestApproach(const btVector3& pa, const btVector3& ua,
+						  const btVector3& pb, const btVector3& ub,
+						  btScalar* alpha, btScalar* beta)
 {
 {
-  btVector3 p;
-  p[0] = pb[0] - pa[0];
-  p[1] = pb[1] - pa[1];
-  p[2] = pb[2] - pa[2];
-  btScalar uaub = dDOT(ua,ub);
-  btScalar q1 =  dDOT(ua,p);
-  btScalar q2 = -dDOT(ub,p);
-  btScalar d = 1-uaub*uaub;
-  if (d <= btScalar(0.0001f)) {
-    // @@@ this needs to be made more robust
-    *alpha = 0;
-    *beta  = 0;
-  }
-  else {
-    d = 1.f/d;
-    *alpha = (q1 + uaub*q2)*d;
-    *beta  = (uaub*q1 + q2)*d;
-  }
+	btVector3 p;
+	p[0] = pb[0] - pa[0];
+	p[1] = pb[1] - pa[1];
+	p[2] = pb[2] - pa[2];
+	btScalar uaub = dDOT(ua, ub);
+	btScalar q1 = dDOT(ua, p);
+	btScalar q2 = -dDOT(ub, p);
+	btScalar d = 1 - uaub * uaub;
+	if (d <= btScalar(0.0001f))
+	{
+		// @@@ this needs to be made more robust
+		*alpha = 0;
+		*beta = 0;
+	}
+	else
+	{
+		d = 1.f / d;
+		*alpha = (q1 + uaub * q2) * d;
+		*beta = (uaub * q1 + q2) * d;
+	}
 }
 }
 
 
-
-
 // find all the intersection points between the 2D rectangle with vertices
 // find all the intersection points between the 2D rectangle with vertices
 // at (+/-h[0],+/-h[1]) and the 2D quadrilateral with vertices (p[0],p[1]),
 // at (+/-h[0],+/-h[1]) and the 2D quadrilateral with vertices (p[0],p[1]),
 // (p[2],p[3]),(p[4],p[5]),(p[6],p[7]).
 // (p[2],p[3]),(p[4],p[5]),(p[6],p[7]).
@@ -117,60 +114,66 @@ void dLineClosestApproach (const btVector3& pa, const btVector3& ua,
 // the number of intersection points is returned by the function (this will
 // the number of intersection points is returned by the function (this will
 // be in the range 0 to 8).
 // be in the range 0 to 8).
 
 
-static int intersectRectQuad2 (btScalar h[2], btScalar p[8], btScalar ret[16])
+static int intersectRectQuad2(btScalar h[2], btScalar p[8], btScalar ret[16])
 {
 {
-  // q (and r) contain nq (and nr) coordinate points for the current (and
-  // chopped) polygons
-  int nq=4,nr=0;
-  btScalar buffer[16];
-  btScalar *q = p;
-  btScalar *r = ret;
-  for (int dir=0; dir <= 1; dir++) {
-    // direction notation: xy[0] = x axis, xy[1] = y axis
-    for (int sign=-1; sign <= 1; sign += 2) {
-      // chop q along the line xy[dir] = sign*h[dir]
-      btScalar *pq = q;
-      btScalar *pr = r;
-      nr = 0;
-      for (int i=nq; i > 0; i--) {
-	// go through all points in q and all lines between adjacent points
-	if (sign*pq[dir] < h[dir]) {
-	  // this point is inside the chopping line
-	  pr[0] = pq[0];
-	  pr[1] = pq[1];
-	  pr += 2;
-	  nr++;
-	  if (nr & 8) {
-	    q = r;
-	    goto done;
-	  }
-	}
-	btScalar *nextq = (i > 1) ? pq+2 : q;
-	if ((sign*pq[dir] < h[dir]) ^ (sign*nextq[dir] < h[dir])) {
-	  // this line crosses the chopping line
-	  pr[1-dir] = pq[1-dir] + (nextq[1-dir]-pq[1-dir]) /
-	    (nextq[dir]-pq[dir]) * (sign*h[dir]-pq[dir]);
-	  pr[dir] = sign*h[dir];
-	  pr += 2;
-	  nr++;
-	  if (nr & 8) {
-	    q = r;
-	    goto done;
-	  }
+	// q (and r) contain nq (and nr) coordinate points for the current (and
+	// chopped) polygons
+	int nq = 4, nr = 0;
+	btScalar buffer[16];
+	btScalar* q = p;
+	btScalar* r = ret;
+	for (int dir = 0; dir <= 1; dir++)
+	{
+		// direction notation: xy[0] = x axis, xy[1] = y axis
+		for (int sign = -1; sign <= 1; sign += 2)
+		{
+			// chop q along the line xy[dir] = sign*h[dir]
+			btScalar* pq = q;
+			btScalar* pr = r;
+			nr = 0;
+			for (int i = nq; i > 0; i--)
+			{
+				// go through all points in q and all lines between adjacent points
+				if (sign * pq[dir] < h[dir])
+				{
+					// this point is inside the chopping line
+					pr[0] = pq[0];
+					pr[1] = pq[1];
+					pr += 2;
+					nr++;
+					if (nr & 8)
+					{
+						q = r;
+						goto done;
+					}
+				}
+				btScalar* nextq = (i > 1) ? pq + 2 : q;
+				if ((sign * pq[dir] < h[dir]) ^ (sign * nextq[dir] < h[dir]))
+				{
+					// this line crosses the chopping line
+					pr[1 - dir] = pq[1 - dir] + (nextq[1 - dir] - pq[1 - dir]) /
+													(nextq[dir] - pq[dir]) * (sign * h[dir] - pq[dir]);
+					pr[dir] = sign * h[dir];
+					pr += 2;
+					nr++;
+					if (nr & 8)
+					{
+						q = r;
+						goto done;
+					}
+				}
+				pq += 2;
+			}
+			q = r;
+			r = (q == ret) ? buffer : ret;
+			nq = nr;
+		}
 	}
 	}
-	pq += 2;
-      }
-      q = r;
-      r = (q==ret) ? buffer : ret;
-      nq = nr;
-    }
-  }
- done:
-  if (q != ret) memcpy (ret,q,nr*2*sizeof(btScalar));
-  return nr;
+done:
+	if (q != ret) memcpy(ret, q, nr * 2 * sizeof(btScalar));
+	return nr;
 }
 }
 
 
-
 #define M__PI 3.14159265f
 #define M__PI 3.14159265f
 
 
 // given n points in the plane (array p, of size 2*n), generate m points that
 // given n points in the plane (array p, of size 2*n), generate m points that
@@ -181,538 +184,584 @@ static int intersectRectQuad2 (btScalar h[2], btScalar p[8], btScalar ret[16])
 // n must be in the range [1..8]. m must be in the range [1..n]. i0 must be
 // n must be in the range [1..8]. m must be in the range [1..n]. i0 must be
 // in the range [0..n-1].
 // in the range [0..n-1].
 
 
-void cullPoints2 (int n, btScalar p[], int m, int i0, int iret[]);
-void cullPoints2 (int n, btScalar p[], int m, int i0, int iret[])
+void cullPoints2(int n, btScalar p[], int m, int i0, int iret[]);
+void cullPoints2(int n, btScalar p[], int m, int i0, int iret[])
 {
 {
-  // compute the centroid of the polygon in cx,cy
-  int i,j;
-  btScalar a,cx,cy,q;
-  if (n==1) {
-    cx = p[0];
-    cy = p[1];
-  }
-  else if (n==2) {
-    cx = btScalar(0.5)*(p[0] + p[2]);
-    cy = btScalar(0.5)*(p[1] + p[3]);
-  }
-  else {
-    a = 0;
-    cx = 0;
-    cy = 0;
-    for (i=0; i<(n-1); i++) {
-      q = p[i*2]*p[i*2+3] - p[i*2+2]*p[i*2+1];
-      a += q;
-      cx += q*(p[i*2]+p[i*2+2]);
-      cy += q*(p[i*2+1]+p[i*2+3]);
-    }
-    q = p[n*2-2]*p[1] - p[0]*p[n*2-1];
-	if (btFabs(a+q) > SIMD_EPSILON)
+	// compute the centroid of the polygon in cx,cy
+	int i, j;
+	btScalar a, cx, cy, q;
+	if (n == 1)
 	{
 	{
-		a = 1.f/(btScalar(3.0)*(a+q));
-	} else
+		cx = p[0];
+		cy = p[1];
+	}
+	else if (n == 2)
 	{
 	{
-		a=BT_LARGE_FLOAT;
+		cx = btScalar(0.5) * (p[0] + p[2]);
+		cy = btScalar(0.5) * (p[1] + p[3]);
 	}
 	}
-    cx = a*(cx + q*(p[n*2-2]+p[0]));
-    cy = a*(cy + q*(p[n*2-1]+p[1]));
-  }
-
-  // compute the angle of each point w.r.t. the centroid
-  btScalar A[8];
-  for (i=0; i<n; i++) A[i] = btAtan2(p[i*2+1]-cy,p[i*2]-cx);
-
-  // search for points that have angles closest to A[i0] + i*(2*pi/m).
-  int avail[8];
-  for (i=0; i<n; i++) avail[i] = 1;
-  avail[i0] = 0;
-  iret[0] = i0;
-  iret++;
-  for (j=1; j<m; j++) {
-    a = btScalar(j)*(2*M__PI/m) + A[i0];
-    if (a > M__PI) a -= 2*M__PI;
-    btScalar maxdiff=1e9,diff;
-
-    *iret = i0;			// iret is not allowed to keep this value, but it sometimes does, when diff=#QNAN0
-
-    for (i=0; i<n; i++) {
-      if (avail[i]) {
-	diff = btFabs (A[i]-a);
-	if (diff > M__PI) diff = 2*M__PI - diff;
-	if (diff < maxdiff) {
-	  maxdiff = diff;
-	  *iret = i;
+	else
+	{
+		a = 0;
+		cx = 0;
+		cy = 0;
+		for (i = 0; i < (n - 1); i++)
+		{
+			q = p[i * 2] * p[i * 2 + 3] - p[i * 2 + 2] * p[i * 2 + 1];
+			a += q;
+			cx += q * (p[i * 2] + p[i * 2 + 2]);
+			cy += q * (p[i * 2 + 1] + p[i * 2 + 3]);
+		}
+		q = p[n * 2 - 2] * p[1] - p[0] * p[n * 2 - 1];
+		if (btFabs(a + q) > SIMD_EPSILON)
+		{
+			a = 1.f / (btScalar(3.0) * (a + q));
+		}
+		else
+		{
+			a = BT_LARGE_FLOAT;
+		}
+		cx = a * (cx + q * (p[n * 2 - 2] + p[0]));
+		cy = a * (cy + q * (p[n * 2 - 1] + p[1]));
 	}
 	}
-      }
-    }
-#if defined(DEBUG) || defined (_DEBUG)
-    btAssert (*iret != i0);	// ensure iret got set
+
+	// compute the angle of each point w.r.t. the centroid
+	btScalar A[8];
+	for (i = 0; i < n; i++) A[i] = btAtan2(p[i * 2 + 1] - cy, p[i * 2] - cx);
+
+	// search for points that have angles closest to A[i0] + i*(2*pi/m).
+	int avail[8];
+	for (i = 0; i < n; i++) avail[i] = 1;
+	avail[i0] = 0;
+	iret[0] = i0;
+	iret++;
+	for (j = 1; j < m; j++)
+	{
+		a = btScalar(j) * (2 * M__PI / m) + A[i0];
+		if (a > M__PI) a -= 2 * M__PI;
+		btScalar maxdiff = 1e9, diff;
+
+		*iret = i0;  // iret is not allowed to keep this value, but it sometimes does, when diff=#QNAN0
+
+		for (i = 0; i < n; i++)
+		{
+			if (avail[i])
+			{
+				diff = btFabs(A[i] - a);
+				if (diff > M__PI) diff = 2 * M__PI - diff;
+				if (diff < maxdiff)
+				{
+					maxdiff = diff;
+					*iret = i;
+				}
+			}
+		}
+#if defined(DEBUG) || defined(_DEBUG)
+		btAssert(*iret != i0);  // ensure iret got set
 #endif
 #endif
-    avail[*iret] = 0;
-    iret++;
-  }
+		avail[*iret] = 0;
+		iret++;
+	}
 }
 }
 
 
+int dBoxBox2(const btVector3& p1, const dMatrix3 R1,
+			 const btVector3& side1, const btVector3& p2,
+			 const dMatrix3 R2, const btVector3& side2,
+			 btVector3& normal, btScalar* depth, int* return_code,
+			 int maxc, dContactGeom* /*contact*/, int /*skip*/, btDiscreteCollisionDetectorInterface::Result& output);
+int dBoxBox2(const btVector3& p1, const dMatrix3 R1,
+			 const btVector3& side1, const btVector3& p2,
+			 const dMatrix3 R2, const btVector3& side2,
+			 btVector3& normal, btScalar* depth, int* return_code,
+			 int maxc, dContactGeom* /*contact*/, int /*skip*/, btDiscreteCollisionDetectorInterface::Result& output)
+{
+	const btScalar fudge_factor = btScalar(1.05);
+	btVector3 p, pp, normalC(0.f, 0.f, 0.f);
+	const btScalar* normalR = 0;
+	btScalar A[3], B[3], R11, R12, R13, R21, R22, R23, R31, R32, R33,
+		Q11, Q12, Q13, Q21, Q22, Q23, Q31, Q32, Q33, s, s2, l;
+	int i, j, invert_normal, code;
+
+	// get vector from centers of box 1 to box 2, relative to box 1
+	p = p2 - p1;
+	dMULTIPLY1_331(pp, R1, p);  // get pp = p relative to body 1
+
+	// get side lengths / 2
+	A[0] = side1[0] * btScalar(0.5);
+	A[1] = side1[1] * btScalar(0.5);
+	A[2] = side1[2] * btScalar(0.5);
+	B[0] = side2[0] * btScalar(0.5);
+	B[1] = side2[1] * btScalar(0.5);
+	B[2] = side2[2] * btScalar(0.5);
+
+	// Rij is R1'*R2, i.e. the relative rotation between R1 and R2
+	R11 = dDOT44(R1 + 0, R2 + 0);
+	R12 = dDOT44(R1 + 0, R2 + 1);
+	R13 = dDOT44(R1 + 0, R2 + 2);
+	R21 = dDOT44(R1 + 1, R2 + 0);
+	R22 = dDOT44(R1 + 1, R2 + 1);
+	R23 = dDOT44(R1 + 1, R2 + 2);
+	R31 = dDOT44(R1 + 2, R2 + 0);
+	R32 = dDOT44(R1 + 2, R2 + 1);
+	R33 = dDOT44(R1 + 2, R2 + 2);
+
+	Q11 = btFabs(R11);
+	Q12 = btFabs(R12);
+	Q13 = btFabs(R13);
+	Q21 = btFabs(R21);
+	Q22 = btFabs(R22);
+	Q23 = btFabs(R23);
+	Q31 = btFabs(R31);
+	Q32 = btFabs(R32);
+	Q33 = btFabs(R33);
+
+	// for all 15 possible separating axes:
+	//   * see if the axis separates the boxes. if so, return 0.
+	//   * find the depth of the penetration along the separating axis (s2)
+	//   * if this is the largest depth so far, record it.
+	// the normal vector will be set to the separating axis with the smallest
+	// depth. note: normalR is set to point to a column of R1 or R2 if that is
+	// the smallest depth normal so far. otherwise normalR is 0 and normalC is
+	// set to a vector relative to body 1. invert_normal is 1 if the sign of
+	// the normal should be flipped.
+
+#define TST(expr1, expr2, norm, cc)    \
+	s2 = btFabs(expr1) - (expr2);      \
+	if (s2 > 0) return 0;              \
+	if (s2 > s)                        \
+	{                                  \
+		s = s2;                        \
+		normalR = norm;                \
+		invert_normal = ((expr1) < 0); \
+		code = (cc);                   \
+	}
 
 
+	s = -dInfinity;
+	invert_normal = 0;
+	code = 0;
 
 
-int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
-	     const btVector3& side1, const btVector3& p2,
-	     const dMatrix3 R2, const btVector3& side2,
-	     btVector3& normal, btScalar *depth, int *return_code,
-		 int maxc, dContactGeom * /*contact*/, int /*skip*/,btDiscreteCollisionDetectorInterface::Result& output);
-int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
-	     const btVector3& side1, const btVector3& p2,
-	     const dMatrix3 R2, const btVector3& side2,
-	     btVector3& normal, btScalar *depth, int *return_code,
-		 int maxc, dContactGeom * /*contact*/, int /*skip*/,btDiscreteCollisionDetectorInterface::Result& output)
-{
-  const btScalar fudge_factor = btScalar(1.05);
-  btVector3 p,pp,normalC(0.f,0.f,0.f);
-  const btScalar *normalR = 0;
-  btScalar A[3],B[3],R11,R12,R13,R21,R22,R23,R31,R32,R33,
-    Q11,Q12,Q13,Q21,Q22,Q23,Q31,Q32,Q33,s,s2,l;
-  int i,j,invert_normal,code;
-
-  // get vector from centers of box 1 to box 2, relative to box 1
-  p = p2 - p1;
-  dMULTIPLY1_331 (pp,R1,p);		// get pp = p relative to body 1
-
-  // get side lengths / 2
-  A[0] = side1[0]*btScalar(0.5);
-  A[1] = side1[1]*btScalar(0.5);
-  A[2] = side1[2]*btScalar(0.5);
-  B[0] = side2[0]*btScalar(0.5);
-  B[1] = side2[1]*btScalar(0.5);
-  B[2] = side2[2]*btScalar(0.5);
-
-  // Rij is R1'*R2, i.e. the relative rotation between R1 and R2
-  R11 = dDOT44(R1+0,R2+0); R12 = dDOT44(R1+0,R2+1); R13 = dDOT44(R1+0,R2+2);
-  R21 = dDOT44(R1+1,R2+0); R22 = dDOT44(R1+1,R2+1); R23 = dDOT44(R1+1,R2+2);
-  R31 = dDOT44(R1+2,R2+0); R32 = dDOT44(R1+2,R2+1); R33 = dDOT44(R1+2,R2+2);
-
-  Q11 = btFabs(R11); Q12 = btFabs(R12); Q13 = btFabs(R13);
-  Q21 = btFabs(R21); Q22 = btFabs(R22); Q23 = btFabs(R23);
-  Q31 = btFabs(R31); Q32 = btFabs(R32); Q33 = btFabs(R33);
-
-  // for all 15 possible separating axes:
-  //   * see if the axis separates the boxes. if so, return 0.
-  //   * find the depth of the penetration along the separating axis (s2)
-  //   * if this is the largest depth so far, record it.
-  // the normal vector will be set to the separating axis with the smallest
-  // depth. note: normalR is set to point to a column of R1 or R2 if that is
-  // the smallest depth normal so far. otherwise normalR is 0 and normalC is
-  // set to a vector relative to body 1. invert_normal is 1 if the sign of
-  // the normal should be flipped.
-
-#define TST(expr1,expr2,norm,cc) \
-  s2 = btFabs(expr1) - (expr2); \
-  if (s2 > 0) return 0; \
-  if (s2 > s) { \
-    s = s2; \
-    normalR = norm; \
-    invert_normal = ((expr1) < 0); \
-    code = (cc); \
-  }
-
-  s = -dInfinity;
-  invert_normal = 0;
-  code = 0;
-
-  // separating axis = u1,u2,u3
-  TST (pp[0],(A[0] + B[0]*Q11 + B[1]*Q12 + B[2]*Q13),R1+0,1);
-  TST (pp[1],(A[1] + B[0]*Q21 + B[1]*Q22 + B[2]*Q23),R1+1,2);
-  TST (pp[2],(A[2] + B[0]*Q31 + B[1]*Q32 + B[2]*Q33),R1+2,3);
-
-  // separating axis = v1,v2,v3
-  TST (dDOT41(R2+0,p),(A[0]*Q11 + A[1]*Q21 + A[2]*Q31 + B[0]),R2+0,4);
-  TST (dDOT41(R2+1,p),(A[0]*Q12 + A[1]*Q22 + A[2]*Q32 + B[1]),R2+1,5);
-  TST (dDOT41(R2+2,p),(A[0]*Q13 + A[1]*Q23 + A[2]*Q33 + B[2]),R2+2,6);
-
-  // note: cross product axes need to be scaled when s is computed.
-  // normal (n1,n2,n3) is relative to box 1.
+	// separating axis = u1,u2,u3
+	TST(pp[0], (A[0] + B[0] * Q11 + B[1] * Q12 + B[2] * Q13), R1 + 0, 1);
+	TST(pp[1], (A[1] + B[0] * Q21 + B[1] * Q22 + B[2] * Q23), R1 + 1, 2);
+	TST(pp[2], (A[2] + B[0] * Q31 + B[1] * Q32 + B[2] * Q33), R1 + 2, 3);
+
+	// separating axis = v1,v2,v3
+	TST(dDOT41(R2 + 0, p), (A[0] * Q11 + A[1] * Q21 + A[2] * Q31 + B[0]), R2 + 0, 4);
+	TST(dDOT41(R2 + 1, p), (A[0] * Q12 + A[1] * Q22 + A[2] * Q32 + B[1]), R2 + 1, 5);
+	TST(dDOT41(R2 + 2, p), (A[0] * Q13 + A[1] * Q23 + A[2] * Q33 + B[2]), R2 + 2, 6);
+
+	// note: cross product axes need to be scaled when s is computed.
+	// normal (n1,n2,n3) is relative to box 1.
 #undef TST
 #undef TST
-#define TST(expr1,expr2,n1,n2,n3,cc) \
-  s2 = btFabs(expr1) - (expr2); \
-  if (s2 > SIMD_EPSILON) return 0; \
-  l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \
-  if (l > SIMD_EPSILON) { \
-    s2 /= l; \
-    if (s2*fudge_factor > s) { \
-      s = s2; \
-      normalR = 0; \
-      normalC[0] = (n1)/l; normalC[1] = (n2)/l; normalC[2] = (n3)/l; \
-      invert_normal = ((expr1) < 0); \
-      code = (cc); \
-    } \
-  }
-
-  btScalar fudge2 (1.0e-5f);
-
-  Q11 += fudge2;
-  Q12 += fudge2;
-  Q13 += fudge2;
-
-  Q21 += fudge2;
-  Q22 += fudge2;
-  Q23 += fudge2;
-
-  Q31 += fudge2;
-  Q32 += fudge2;
-  Q33 += fudge2;
-
-  // separating axis = u1 x (v1,v2,v3)
-  TST(pp[2]*R21-pp[1]*R31,(A[1]*Q31+A[2]*Q21+B[1]*Q13+B[2]*Q12),0,-R31,R21,7);
-  TST(pp[2]*R22-pp[1]*R32,(A[1]*Q32+A[2]*Q22+B[0]*Q13+B[2]*Q11),0,-R32,R22,8);
-  TST(pp[2]*R23-pp[1]*R33,(A[1]*Q33+A[2]*Q23+B[0]*Q12+B[1]*Q11),0,-R33,R23,9);
-
-  // separating axis = u2 x (v1,v2,v3)
-  TST(pp[0]*R31-pp[2]*R11,(A[0]*Q31+A[2]*Q11+B[1]*Q23+B[2]*Q22),R31,0,-R11,10);
-  TST(pp[0]*R32-pp[2]*R12,(A[0]*Q32+A[2]*Q12+B[0]*Q23+B[2]*Q21),R32,0,-R12,11);
-  TST(pp[0]*R33-pp[2]*R13,(A[0]*Q33+A[2]*Q13+B[0]*Q22+B[1]*Q21),R33,0,-R13,12);
-
-  // separating axis = u3 x (v1,v2,v3)
-  TST(pp[1]*R11-pp[0]*R21,(A[0]*Q21+A[1]*Q11+B[1]*Q33+B[2]*Q32),-R21,R11,0,13);
-  TST(pp[1]*R12-pp[0]*R22,(A[0]*Q22+A[1]*Q12+B[0]*Q33+B[2]*Q31),-R22,R12,0,14);
-  TST(pp[1]*R13-pp[0]*R23,(A[0]*Q23+A[1]*Q13+B[0]*Q32+B[1]*Q31),-R23,R13,0,15);
+#define TST(expr1, expr2, n1, n2, n3, cc)                \
+	s2 = btFabs(expr1) - (expr2);                        \
+	if (s2 > SIMD_EPSILON) return 0;                     \
+	l = btSqrt((n1) * (n1) + (n2) * (n2) + (n3) * (n3)); \
+	if (l > SIMD_EPSILON)                                \
+	{                                                    \
+		s2 /= l;                                         \
+		if (s2 * fudge_factor > s)                       \
+		{                                                \
+			s = s2;                                      \
+			normalR = 0;                                 \
+			normalC[0] = (n1) / l;                       \
+			normalC[1] = (n2) / l;                       \
+			normalC[2] = (n3) / l;                       \
+			invert_normal = ((expr1) < 0);               \
+			code = (cc);                                 \
+		}                                                \
+	}
+
+	btScalar fudge2(1.0e-5f);
+
+	Q11 += fudge2;
+	Q12 += fudge2;
+	Q13 += fudge2;
+
+	Q21 += fudge2;
+	Q22 += fudge2;
+	Q23 += fudge2;
+
+	Q31 += fudge2;
+	Q32 += fudge2;
+	Q33 += fudge2;
+
+	// separating axis = u1 x (v1,v2,v3)
+	TST(pp[2] * R21 - pp[1] * R31, (A[1] * Q31 + A[2] * Q21 + B[1] * Q13 + B[2] * Q12), 0, -R31, R21, 7);
+	TST(pp[2] * R22 - pp[1] * R32, (A[1] * Q32 + A[2] * Q22 + B[0] * Q13 + B[2] * Q11), 0, -R32, R22, 8);
+	TST(pp[2] * R23 - pp[1] * R33, (A[1] * Q33 + A[2] * Q23 + B[0] * Q12 + B[1] * Q11), 0, -R33, R23, 9);
+
+	// separating axis = u2 x (v1,v2,v3)
+	TST(pp[0] * R31 - pp[2] * R11, (A[0] * Q31 + A[2] * Q11 + B[1] * Q23 + B[2] * Q22), R31, 0, -R11, 10);
+	TST(pp[0] * R32 - pp[2] * R12, (A[0] * Q32 + A[2] * Q12 + B[0] * Q23 + B[2] * Q21), R32, 0, -R12, 11);
+	TST(pp[0] * R33 - pp[2] * R13, (A[0] * Q33 + A[2] * Q13 + B[0] * Q22 + B[1] * Q21), R33, 0, -R13, 12);
+
+	// separating axis = u3 x (v1,v2,v3)
+	TST(pp[1] * R11 - pp[0] * R21, (A[0] * Q21 + A[1] * Q11 + B[1] * Q33 + B[2] * Q32), -R21, R11, 0, 13);
+	TST(pp[1] * R12 - pp[0] * R22, (A[0] * Q22 + A[1] * Q12 + B[0] * Q33 + B[2] * Q31), -R22, R12, 0, 14);
+	TST(pp[1] * R13 - pp[0] * R23, (A[0] * Q23 + A[1] * Q13 + B[0] * Q32 + B[1] * Q31), -R23, R13, 0, 15);
 
 
 #undef TST
 #undef TST
 
 
-  if (!code) return 0;
-
-  // if we get to this point, the boxes interpenetrate. compute the normal
-  // in global coordinates.
-  if (normalR) {
-    normal[0] = normalR[0];
-    normal[1] = normalR[4];
-    normal[2] = normalR[8];
-  }
-  else {
-    dMULTIPLY0_331 (normal,R1,normalC);
-  }
-  if (invert_normal) {
-    normal[0] = -normal[0];
-    normal[1] = -normal[1];
-    normal[2] = -normal[2];
-  }
-  *depth = -s;
-
-  // compute contact point(s)
-
-  if (code > 6) {
-    // an edge from box 1 touches an edge from box 2.
-    // find a point pa on the intersecting edge of box 1
-    btVector3 pa;
-    btScalar sign;
-    for (i=0; i<3; i++) pa[i] = p1[i];
-    for (j=0; j<3; j++) {
-      sign = (dDOT14(normal,R1+j) > 0) ? btScalar(1.0) : btScalar(-1.0);
-      for (i=0; i<3; i++) pa[i] += sign * A[j] * R1[i*4+j];
-    }
-
-    // find a point pb on the intersecting edge of box 2
-    btVector3 pb;
-    for (i=0; i<3; i++) pb[i] = p2[i];
-    for (j=0; j<3; j++) {
-      sign = (dDOT14(normal,R2+j) > 0) ? btScalar(-1.0) : btScalar(1.0);
-      for (i=0; i<3; i++) pb[i] += sign * B[j] * R2[i*4+j];
-    }
-
-    btScalar alpha,beta;
-    btVector3 ua,ub;
-    for (i=0; i<3; i++) ua[i] = R1[((code)-7)/3 + i*4];
-    for (i=0; i<3; i++) ub[i] = R2[((code)-7)%3 + i*4];
-
-    dLineClosestApproach (pa,ua,pb,ub,&alpha,&beta);
-    for (i=0; i<3; i++) pa[i] += ua[i]*alpha;
-    for (i=0; i<3; i++) pb[i] += ub[i]*beta;
+	if (!code) return 0;
 
 
+	// if we get to this point, the boxes interpenetrate. compute the normal
+	// in global coordinates.
+	if (normalR)
+	{
+		normal[0] = normalR[0];
+		normal[1] = normalR[4];
+		normal[2] = normalR[8];
+	}
+	else
 	{
 	{
-		
-		//contact[0].pos[i] = btScalar(0.5)*(pa[i]+pb[i]);
-		//contact[0].depth = *depth;
-		btVector3 pointInWorld;
+		dMULTIPLY0_331(normal, R1, normalC);
+	}
+	if (invert_normal)
+	{
+		normal[0] = -normal[0];
+		normal[1] = -normal[1];
+		normal[2] = -normal[2];
+	}
+	*depth = -s;
+
+	// compute contact point(s)
+
+	if (code > 6)
+	{
+		// an edge from box 1 touches an edge from box 2.
+		// find a point pa on the intersecting edge of box 1
+		btVector3 pa;
+		btScalar sign;
+		for (i = 0; i < 3; i++) pa[i] = p1[i];
+		for (j = 0; j < 3; j++)
+		{
+			sign = (dDOT14(normal, R1 + j) > 0) ? btScalar(1.0) : btScalar(-1.0);
+			for (i = 0; i < 3; i++) pa[i] += sign * A[j] * R1[i * 4 + j];
+		}
+
+		// find a point pb on the intersecting edge of box 2
+		btVector3 pb;
+		for (i = 0; i < 3; i++) pb[i] = p2[i];
+		for (j = 0; j < 3; j++)
+		{
+			sign = (dDOT14(normal, R2 + j) > 0) ? btScalar(-1.0) : btScalar(1.0);
+			for (i = 0; i < 3; i++) pb[i] += sign * B[j] * R2[i * 4 + j];
+		}
+
+		btScalar alpha, beta;
+		btVector3 ua, ub;
+		for (i = 0; i < 3; i++) ua[i] = R1[((code)-7) / 3 + i * 4];
+		for (i = 0; i < 3; i++) ub[i] = R2[((code)-7) % 3 + i * 4];
+
+		dLineClosestApproach(pa, ua, pb, ub, &alpha, &beta);
+		for (i = 0; i < 3; i++) pa[i] += ua[i] * alpha;
+		for (i = 0; i < 3; i++) pb[i] += ub[i] * beta;
+
+		{
+			//contact[0].pos[i] = btScalar(0.5)*(pa[i]+pb[i]);
+			//contact[0].depth = *depth;
+			btVector3 pointInWorld;
 
 
 #ifdef USE_CENTER_POINT
 #ifdef USE_CENTER_POINT
-	    for (i=0; i<3; i++) 
-			pointInWorld[i] = (pa[i]+pb[i])*btScalar(0.5);
-		output.addContactPoint(-normal,pointInWorld,-*depth);
+			for (i = 0; i < 3; i++)
+				pointInWorld[i] = (pa[i] + pb[i]) * btScalar(0.5);
+			output.addContactPoint(-normal, pointInWorld, -*depth);
 #else
 #else
-		output.addContactPoint(-normal,pb,-*depth);
+			output.addContactPoint(-normal, pb, -*depth);
 
 
-#endif //
-		*return_code = code;
+#endif  //
+			*return_code = code;
+		}
+		return 1;
+	}
+
+	// okay, we have a face-something intersection (because the separating
+	// axis is perpendicular to a face). define face 'a' to be the reference
+	// face (i.e. the normal vector is perpendicular to this) and face 'b' to be
+	// the incident face (the closest face of the other box).
+
+	const btScalar *Ra, *Rb, *pa, *pb, *Sa, *Sb;
+	if (code <= 3)
+	{
+		Ra = R1;
+		Rb = R2;
+		pa = p1;
+		pb = p2;
+		Sa = A;
+		Sb = B;
+	}
+	else
+	{
+		Ra = R2;
+		Rb = R1;
+		pa = p2;
+		pb = p1;
+		Sa = B;
+		Sb = A;
+	}
+
+	// nr = normal vector of reference face dotted with axes of incident box.
+	// anr = absolute values of nr.
+	btVector3 normal2, nr, anr;
+	if (code <= 3)
+	{
+		normal2[0] = normal[0];
+		normal2[1] = normal[1];
+		normal2[2] = normal[2];
+	}
+	else
+	{
+		normal2[0] = -normal[0];
+		normal2[1] = -normal[1];
+		normal2[2] = -normal[2];
 	}
 	}
-    return 1;
-  }
-
-  // okay, we have a face-something intersection (because the separating
-  // axis is perpendicular to a face). define face 'a' to be the reference
-  // face (i.e. the normal vector is perpendicular to this) and face 'b' to be
-  // the incident face (the closest face of the other box).
-
-  const btScalar *Ra,*Rb,*pa,*pb,*Sa,*Sb;
-  if (code <= 3) {
-    Ra = R1;
-    Rb = R2;
-    pa = p1;
-    pb = p2;
-    Sa = A;
-    Sb = B;
-  }
-  else {
-    Ra = R2;
-    Rb = R1;
-    pa = p2;
-    pb = p1;
-    Sa = B;
-    Sb = A;
-  }
-
-  // nr = normal vector of reference face dotted with axes of incident box.
-  // anr = absolute values of nr.
-  btVector3 normal2,nr,anr;
-  if (code <= 3) {
-    normal2[0] = normal[0];
-    normal2[1] = normal[1];
-    normal2[2] = normal[2];
-  }
-  else {
-    normal2[0] = -normal[0];
-    normal2[1] = -normal[1];
-    normal2[2] = -normal[2];
-  }
-  dMULTIPLY1_331 (nr,Rb,normal2);
-  anr[0] = btFabs (nr[0]);
-  anr[1] = btFabs (nr[1]);
-  anr[2] = btFabs (nr[2]);
-
-  // find the largest compontent of anr: this corresponds to the normal
-  // for the indident face. the other axis numbers of the indicent face
-  // are stored in a1,a2.
-  int lanr,a1,a2;
-  if (anr[1] > anr[0]) {
-    if (anr[1] > anr[2]) {
-      a1 = 0;
-      lanr = 1;
-      a2 = 2;
-    }
-    else {
-      a1 = 0;
-      a2 = 1;
-      lanr = 2;
-    }
-  }
-  else {
-    if (anr[0] > anr[2]) {
-      lanr = 0;
-      a1 = 1;
-      a2 = 2;
-    }
-    else {
-      a1 = 0;
-      a2 = 1;
-      lanr = 2;
-    }
-  }
-
-  // compute center point of incident face, in reference-face coordinates
-  btVector3 center;
-  if (nr[lanr] < 0) {
-    for (i=0; i<3; i++) center[i] = pb[i] - pa[i] + Sb[lanr] * Rb[i*4+lanr];
-  }
-  else {
-    for (i=0; i<3; i++) center[i] = pb[i] - pa[i] - Sb[lanr] * Rb[i*4+lanr];
-  }
-
-  // find the normal and non-normal axis numbers of the reference box
-  int codeN,code1,code2;
-  if (code <= 3) codeN = code-1; else codeN = code-4;
-  if (codeN==0) {
-    code1 = 1;
-    code2 = 2;
-  }
-  else if (codeN==1) {
-    code1 = 0;
-    code2 = 2;
-  }
-  else {
-    code1 = 0;
-    code2 = 1;
-  }
-
-  // find the four corners of the incident face, in reference-face coordinates
-  btScalar quad[8];	// 2D coordinate of incident face (x,y pairs)
-  btScalar c1,c2,m11,m12,m21,m22;
-  c1 = dDOT14 (center,Ra+code1);
-  c2 = dDOT14 (center,Ra+code2);
-  // optimize this? - we have already computed this data above, but it is not
-  // stored in an easy-to-index format. for now it's quicker just to recompute
-  // the four dot products.
-  m11 = dDOT44 (Ra+code1,Rb+a1);
-  m12 = dDOT44 (Ra+code1,Rb+a2);
-  m21 = dDOT44 (Ra+code2,Rb+a1);
-  m22 = dDOT44 (Ra+code2,Rb+a2);
-  {
-    btScalar k1 = m11*Sb[a1];
-    btScalar k2 = m21*Sb[a1];
-    btScalar k3 = m12*Sb[a2];
-    btScalar k4 = m22*Sb[a2];
-    quad[0] = c1 - k1 - k3;
-    quad[1] = c2 - k2 - k4;
-    quad[2] = c1 - k1 + k3;
-    quad[3] = c2 - k2 + k4;
-    quad[4] = c1 + k1 + k3;
-    quad[5] = c2 + k2 + k4;
-    quad[6] = c1 + k1 - k3;
-    quad[7] = c2 + k2 - k4;
-  }
-
-  // find the size of the reference face
-  btScalar rect[2];
-  rect[0] = Sa[code1];
-  rect[1] = Sa[code2];
-
-  // intersect the incident and reference faces
-  btScalar ret[16];
-  int n = intersectRectQuad2 (rect,quad,ret);
-  if (n < 1) return 0;		// this should never happen
-
-  // convert the intersection points into reference-face coordinates,
-  // and compute the contact position and depth for each point. only keep
-  // those points that have a positive (penetrating) depth. delete points in
-  // the 'ret' array as necessary so that 'point' and 'ret' correspond.
-  btScalar point[3*8];		// penetrating contact points
-  btScalar dep[8];			// depths for those points
-  btScalar det1 = 1.f/(m11*m22 - m12*m21);
-  m11 *= det1;
-  m12 *= det1;
-  m21 *= det1;
-  m22 *= det1;
-  int cnum = 0;			// number of penetrating contact points found
-  for (j=0; j < n; j++) {
-    btScalar k1 =  m22*(ret[j*2]-c1) - m12*(ret[j*2+1]-c2);
-    btScalar k2 = -m21*(ret[j*2]-c1) + m11*(ret[j*2+1]-c2);
-    for (i=0; i<3; i++) point[cnum*3+i] =
-			  center[i] + k1*Rb[i*4+a1] + k2*Rb[i*4+a2];
-    dep[cnum] = Sa[codeN] - dDOT(normal2,point+cnum*3);
-    if (dep[cnum] >= 0) {
-      ret[cnum*2] = ret[j*2];
-      ret[cnum*2+1] = ret[j*2+1];
-      cnum++;
-    }
-  }
-  if (cnum < 1) return 0;	// this should never happen
-
-  // we can't generate more contacts than we actually have
-  if (maxc > cnum) maxc = cnum;
-  if (maxc < 1) maxc = 1;
-
-  if (cnum <= maxc) {
-
-	  if (code<4) 
-	  {
-    // we have less contacts than we need, so we use them all
-    for (j=0; j < cnum; j++) 
+	dMULTIPLY1_331(nr, Rb, normal2);
+	anr[0] = btFabs(nr[0]);
+	anr[1] = btFabs(nr[1]);
+	anr[2] = btFabs(nr[2]);
+
+	// find the largest compontent of anr: this corresponds to the normal
+	// for the indident face. the other axis numbers of the indicent face
+	// are stored in a1,a2.
+	int lanr, a1, a2;
+	if (anr[1] > anr[0])
 	{
 	{
-		btVector3 pointInWorld;
-		for (i=0; i<3; i++) 
-			pointInWorld[i] = point[j*3+i] + pa[i];
-		output.addContactPoint(-normal,pointInWorld,-dep[j]);
-
-    }
-	  } else
-	  {
-		  // we have less contacts than we need, so we use them all
-		for (j=0; j < cnum; j++) 
+		if (anr[1] > anr[2])
 		{
 		{
-			btVector3 pointInWorld;
-			for (i=0; i<3; i++) 
-				pointInWorld[i] = point[j*3+i] + pa[i]-normal[i]*dep[j];
+			a1 = 0;
+			lanr = 1;
+			a2 = 2;
+		}
+		else
+		{
+			a1 = 0;
+			a2 = 1;
+			lanr = 2;
+		}
+	}
+	else
+	{
+		if (anr[0] > anr[2])
+		{
+			lanr = 0;
+			a1 = 1;
+			a2 = 2;
+		}
+		else
+		{
+			a1 = 0;
+			a2 = 1;
+			lanr = 2;
+		}
+	}
+
+	// compute center point of incident face, in reference-face coordinates
+	btVector3 center;
+	if (nr[lanr] < 0)
+	{
+		for (i = 0; i < 3; i++) center[i] = pb[i] - pa[i] + Sb[lanr] * Rb[i * 4 + lanr];
+	}
+	else
+	{
+		for (i = 0; i < 3; i++) center[i] = pb[i] - pa[i] - Sb[lanr] * Rb[i * 4 + lanr];
+	}
+
+	// find the normal and non-normal axis numbers of the reference box
+	int codeN, code1, code2;
+	if (code <= 3)
+		codeN = code - 1;
+	else
+		codeN = code - 4;
+	if (codeN == 0)
+	{
+		code1 = 1;
+		code2 = 2;
+	}
+	else if (codeN == 1)
+	{
+		code1 = 0;
+		code2 = 2;
+	}
+	else
+	{
+		code1 = 0;
+		code2 = 1;
+	}
+
+	// find the four corners of the incident face, in reference-face coordinates
+	btScalar quad[8];  // 2D coordinate of incident face (x,y pairs)
+	btScalar c1, c2, m11, m12, m21, m22;
+	c1 = dDOT14(center, Ra + code1);
+	c2 = dDOT14(center, Ra + code2);
+	// optimize this? - we have already computed this data above, but it is not
+	// stored in an easy-to-index format. for now it's quicker just to recompute
+	// the four dot products.
+	m11 = dDOT44(Ra + code1, Rb + a1);
+	m12 = dDOT44(Ra + code1, Rb + a2);
+	m21 = dDOT44(Ra + code2, Rb + a1);
+	m22 = dDOT44(Ra + code2, Rb + a2);
+	{
+		btScalar k1 = m11 * Sb[a1];
+		btScalar k2 = m21 * Sb[a1];
+		btScalar k3 = m12 * Sb[a2];
+		btScalar k4 = m22 * Sb[a2];
+		quad[0] = c1 - k1 - k3;
+		quad[1] = c2 - k2 - k4;
+		quad[2] = c1 - k1 + k3;
+		quad[3] = c2 - k2 + k4;
+		quad[4] = c1 + k1 + k3;
+		quad[5] = c2 + k2 + k4;
+		quad[6] = c1 + k1 - k3;
+		quad[7] = c2 + k2 - k4;
+	}
+
+	// find the size of the reference face
+	btScalar rect[2];
+	rect[0] = Sa[code1];
+	rect[1] = Sa[code2];
+
+	// intersect the incident and reference faces
+	btScalar ret[16];
+	int n = intersectRectQuad2(rect, quad, ret);
+	if (n < 1) return 0;  // this should never happen
+
+	// convert the intersection points into reference-face coordinates,
+	// and compute the contact position and depth for each point. only keep
+	// those points that have a positive (penetrating) depth. delete points in
+	// the 'ret' array as necessary so that 'point' and 'ret' correspond.
+	btScalar point[3 * 8];  // penetrating contact points
+	btScalar dep[8];        // depths for those points
+	btScalar det1 = 1.f / (m11 * m22 - m12 * m21);
+	m11 *= det1;
+	m12 *= det1;
+	m21 *= det1;
+	m22 *= det1;
+	int cnum = 0;  // number of penetrating contact points found
+	for (j = 0; j < n; j++)
+	{
+		btScalar k1 = m22 * (ret[j * 2] - c1) - m12 * (ret[j * 2 + 1] - c2);
+		btScalar k2 = -m21 * (ret[j * 2] - c1) + m11 * (ret[j * 2 + 1] - c2);
+		for (i = 0; i < 3; i++) point[cnum * 3 + i] =
+									center[i] + k1 * Rb[i * 4 + a1] + k2 * Rb[i * 4 + a2];
+		dep[cnum] = Sa[codeN] - dDOT(normal2, point + cnum * 3);
+		if (dep[cnum] >= 0)
+		{
+			ret[cnum * 2] = ret[j * 2];
+			ret[cnum * 2 + 1] = ret[j * 2 + 1];
+			cnum++;
+		}
+	}
+	if (cnum < 1) return 0;  // this should never happen
+
+	// we can't generate more contacts than we actually have
+	if (maxc > cnum) maxc = cnum;
+	if (maxc < 1) maxc = 1;
+
+	if (cnum <= maxc)
+	{
+		if (code < 4)
+		{
+			// we have less contacts than we need, so we use them all
+			for (j = 0; j < cnum; j++)
+			{
+				btVector3 pointInWorld;
+				for (i = 0; i < 3; i++)
+					pointInWorld[i] = point[j * 3 + i] + pa[i];
+				output.addContactPoint(-normal, pointInWorld, -dep[j]);
+			}
+		}
+		else
+		{
+			// we have less contacts than we need, so we use them all
+			for (j = 0; j < cnum; j++)
+			{
+				btVector3 pointInWorld;
+				for (i = 0; i < 3; i++)
+					pointInWorld[i] = point[j * 3 + i] + pa[i] - normal[i] * dep[j];
 				//pointInWorld[i] = point[j*3+i] + pa[i];
 				//pointInWorld[i] = point[j*3+i] + pa[i];
-			output.addContactPoint(-normal,pointInWorld,-dep[j]);
+				output.addContactPoint(-normal, pointInWorld, -dep[j]);
+			}
 		}
 		}
-	  }
-  }
-  else {
-    // we have more contacts than are wanted, some of them must be culled.
-    // find the deepest point, it is always the first contact.
-    int i1 = 0;
-    btScalar maxdepth = dep[0];
-    for (i=1; i<cnum; i++) {
-      if (dep[i] > maxdepth) {
-	maxdepth = dep[i];
-	i1 = i;
-      }
-    }
-
-    int iret[8];
-    cullPoints2 (cnum,ret,maxc,i1,iret);
-
-    for (j=0; j < maxc; j++) {
-//      dContactGeom *con = CONTACT(contact,skip*j);
-  //    for (i=0; i<3; i++) con->pos[i] = point[iret[j]*3+i] + pa[i];
-    //  con->depth = dep[iret[j]];
-
-		btVector3 posInWorld;
-		for (i=0; i<3; i++) 
-			posInWorld[i] = point[iret[j]*3+i] + pa[i];
-		if (code<4) 
-	   {
-			output.addContactPoint(-normal,posInWorld,-dep[iret[j]]);
-		} else
+	}
+	else
+	{
+		// we have more contacts than are wanted, some of them must be culled.
+		// find the deepest point, it is always the first contact.
+		int i1 = 0;
+		btScalar maxdepth = dep[0];
+		for (i = 1; i < cnum; i++)
 		{
 		{
-			output.addContactPoint(-normal,posInWorld-normal*dep[iret[j]],-dep[iret[j]]);
+			if (dep[i] > maxdepth)
+			{
+				maxdepth = dep[i];
+				i1 = i;
+			}
 		}
 		}
-    }
-    cnum = maxc;
-  }
 
 
-  *return_code = code;
-  return cnum;
+		int iret[8];
+		cullPoints2(cnum, ret, maxc, i1, iret);
+
+		for (j = 0; j < maxc; j++)
+		{
+			//      dContactGeom *con = CONTACT(contact,skip*j);
+			//    for (i=0; i<3; i++) con->pos[i] = point[iret[j]*3+i] + pa[i];
+			//  con->depth = dep[iret[j]];
+
+			btVector3 posInWorld;
+			for (i = 0; i < 3; i++)
+				posInWorld[i] = point[iret[j] * 3 + i] + pa[i];
+			if (code < 4)
+			{
+				output.addContactPoint(-normal, posInWorld, -dep[iret[j]]);
+			}
+			else
+			{
+				output.addContactPoint(-normal, posInWorld - normal * dep[iret[j]], -dep[iret[j]]);
+			}
+		}
+		cnum = maxc;
+	}
+
+	*return_code = code;
+	return cnum;
 }
 }
 
 
-void	btBoxBoxDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* /*debugDraw*/,bool /*swapResults*/)
+void btBoxBoxDetector::getClosestPoints(const ClosestPointInput& input, Result& output, class btIDebugDraw* /*debugDraw*/, bool /*swapResults*/)
 {
 {
-	
 	const btTransform& transformA = input.m_transformA;
 	const btTransform& transformA = input.m_transformA;
 	const btTransform& transformB = input.m_transformB;
 	const btTransform& transformB = input.m_transformB;
-	
+
 	int skip = 0;
 	int skip = 0;
-	dContactGeom *contact = 0;
+	dContactGeom* contact = 0;
 
 
 	dMatrix3 R1;
 	dMatrix3 R1;
 	dMatrix3 R2;
 	dMatrix3 R2;
 
 
-	for (int j=0;j<3;j++)
+	for (int j = 0; j < 3; j++)
 	{
 	{
-		R1[0+4*j] = transformA.getBasis()[j].x();
-		R2[0+4*j] = transformB.getBasis()[j].x();
-
-		R1[1+4*j] = transformA.getBasis()[j].y();
-		R2[1+4*j] = transformB.getBasis()[j].y();
-
+		R1[0 + 4 * j] = transformA.getBasis()[j].x();
+		R2[0 + 4 * j] = transformB.getBasis()[j].x();
 
 
-		R1[2+4*j] = transformA.getBasis()[j].z();
-		R2[2+4*j] = transformB.getBasis()[j].z();
+		R1[1 + 4 * j] = transformA.getBasis()[j].y();
+		R2[1 + 4 * j] = transformB.getBasis()[j].y();
 
 
+		R1[2 + 4 * j] = transformA.getBasis()[j].z();
+		R2[2 + 4 * j] = transformB.getBasis()[j].z();
 	}
 	}
 
 
-	
-
 	btVector3 normal;
 	btVector3 normal;
 	btScalar depth;
 	btScalar depth;
 	int return_code;
 	int return_code;
 	int maxc = 4;
 	int maxc = 4;
 
 
-
-	dBoxBox2 (transformA.getOrigin(), 
-	R1,
-	2.f*m_box1->getHalfExtentsWithMargin(),
-	transformB.getOrigin(),
-	R2, 
-	2.f*m_box2->getHalfExtentsWithMargin(),
-	normal, &depth, &return_code,
-	maxc, contact, skip,
-	output
-	);
-
+	dBoxBox2(transformA.getOrigin(),
+			 R1,
+			 2.f * m_box1->getHalfExtentsWithMargin(),
+			 transformB.getOrigin(),
+			 R2,
+			 2.f * m_box2->getHalfExtentsWithMargin(),
+			 normal, &depth, &return_code,
+			 maxc, contact, skip,
+			 output);
 }
 }

+ 4 - 8
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h

@@ -19,11 +19,9 @@ subject to the following restrictions:
 #ifndef BT_BOX_BOX_DETECTOR_H
 #ifndef BT_BOX_BOX_DETECTOR_H
 #define BT_BOX_BOX_DETECTOR_H
 #define BT_BOX_BOX_DETECTOR_H
 
 
-
 class btBoxShape;
 class btBoxShape;
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 
 
-
 /// btBoxBoxDetector wraps the ODE box-box collision detector
 /// btBoxBoxDetector wraps the ODE box-box collision detector
 /// re-distributed under the Zlib license with permission from Russell L. Smith
 /// re-distributed under the Zlib license with permission from Russell L. Smith
 struct btBoxBoxDetector : public btDiscreteCollisionDetectorInterface
 struct btBoxBoxDetector : public btDiscreteCollisionDetectorInterface
@@ -32,13 +30,11 @@ struct btBoxBoxDetector : public btDiscreteCollisionDetectorInterface
 	const btBoxShape* m_box2;
 	const btBoxShape* m_box2;
 
 
 public:
 public:
+	btBoxBoxDetector(const btBoxShape* box1, const btBoxShape* box2);
 
 
-	btBoxBoxDetector(const btBoxShape* box1,const btBoxShape* box2);
-
-	virtual ~btBoxBoxDetector() {};
-
-	virtual void	getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults=false);
+	virtual ~btBoxBoxDetector(){};
 
 
+	virtual void getClosestPoints(const ClosestPointInput& input, Result& output, class btIDebugDraw* debugDraw, bool swapResults = false);
 };
 };
 
 
-#endif //BT_BOX_BOX_DETECTOR_H
+#endif  //BT_BOX_BOX_DETECTOR_H

+ 3 - 9
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h

@@ -23,11 +23,9 @@ class btPoolAllocator;
 ///btCollisionConfiguration allows to configure Bullet collision detection
 ///btCollisionConfiguration allows to configure Bullet collision detection
 ///stack allocator size, default collision algorithms and persistent manifold pool size
 ///stack allocator size, default collision algorithms and persistent manifold pool size
 ///@todo: describe the meaning
 ///@todo: describe the meaning
-class	btCollisionConfiguration
+class btCollisionConfiguration
 {
 {
-
 public:
 public:
-
 	virtual ~btCollisionConfiguration()
 	virtual ~btCollisionConfiguration()
 	{
 	{
 	}
 	}
@@ -37,13 +35,9 @@ public:
 
 
 	virtual btPoolAllocator* getCollisionAlgorithmPool() = 0;
 	virtual btPoolAllocator* getCollisionAlgorithmPool() = 0;
 
 
-
-	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1) =0;
+	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1) = 0;
 
 
 	virtual btCollisionAlgorithmCreateFunc* getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) = 0;
 	virtual btCollisionAlgorithmCreateFunc* getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) = 0;
-
-
 };
 };
 
 
-#endif //BT_COLLISION_CONFIGURATION
-
+#endif  //BT_COLLISION_CONFIGURATION

+ 4 - 6
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h

@@ -26,20 +26,18 @@ struct btCollisionAlgorithmConstructionInfo;
 struct btCollisionAlgorithmCreateFunc
 struct btCollisionAlgorithmCreateFunc
 {
 {
 	bool m_swapped;
 	bool m_swapped;
-	
+
 	btCollisionAlgorithmCreateFunc()
 	btCollisionAlgorithmCreateFunc()
-		:m_swapped(false)
+		: m_swapped(false)
 	{
 	{
 	}
 	}
 	virtual ~btCollisionAlgorithmCreateFunc(){};
 	virtual ~btCollisionAlgorithmCreateFunc(){};
 
 
-	virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& , const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+	virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo&, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 	{
 	{
-		
 		(void)body0Wrap;
 		(void)body0Wrap;
 		(void)body1Wrap;
 		(void)body1Wrap;
 		return 0;
 		return 0;
 	}
 	}
 };
 };
-#endif //BT_COLLISION_CREATE_FUNC
-
+#endif  //BT_COLLISION_CREATE_FUNC

+ 79 - 114
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp

@@ -13,8 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
-
 #include "btCollisionDispatcher.h"
 #include "btCollisionDispatcher.h"
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btQuickprof.h"
 
 
@@ -27,46 +25,38 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
-int gNumManifold = 0;
-
 #ifdef BT_DEBUG
 #ifdef BT_DEBUG
 #include <stdio.h>
 #include <stdio.h>
 #endif
 #endif
 
 
-
-btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): 
-m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD),
-	m_collisionConfiguration(collisionConfiguration)
+btCollisionDispatcher::btCollisionDispatcher(btCollisionConfiguration* collisionConfiguration) : m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD),
+																								 m_collisionConfiguration(collisionConfiguration)
 {
 {
 	int i;
 	int i;
 
 
 	setNearCallback(defaultNearCallback);
 	setNearCallback(defaultNearCallback);
-	
+
 	m_collisionAlgorithmPoolAllocator = collisionConfiguration->getCollisionAlgorithmPool();
 	m_collisionAlgorithmPoolAllocator = collisionConfiguration->getCollisionAlgorithmPool();
 
 
 	m_persistentManifoldPoolAllocator = collisionConfiguration->getPersistentManifoldPool();
 	m_persistentManifoldPoolAllocator = collisionConfiguration->getPersistentManifoldPool();
 
 
-	for (i=0;i<MAX_BROADPHASE_COLLISION_TYPES;i++)
+	for (i = 0; i < MAX_BROADPHASE_COLLISION_TYPES; i++)
 	{
 	{
-		for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
+		for (int j = 0; j < MAX_BROADPHASE_COLLISION_TYPES; j++)
 		{
 		{
-			m_doubleDispatchContactPoints[i][j] = m_collisionConfiguration->getCollisionAlgorithmCreateFunc(i,j);
+			m_doubleDispatchContactPoints[i][j] = m_collisionConfiguration->getCollisionAlgorithmCreateFunc(i, j);
 			btAssert(m_doubleDispatchContactPoints[i][j]);
 			btAssert(m_doubleDispatchContactPoints[i][j]);
 			m_doubleDispatchClosestPoints[i][j] = m_collisionConfiguration->getClosestPointsAlgorithmCreateFunc(i, j);
 			m_doubleDispatchClosestPoints[i][j] = m_collisionConfiguration->getClosestPointsAlgorithmCreateFunc(i, j);
-
 		}
 		}
 	}
 	}
-	
-	
 }
 }
 
 
-
-void btCollisionDispatcher::registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
+void btCollisionDispatcher::registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc* createFunc)
 {
 {
 	m_doubleDispatchContactPoints[proxyType0][proxyType1] = createFunc;
 	m_doubleDispatchContactPoints[proxyType0][proxyType1] = createFunc;
 }
 }
 
 
-void btCollisionDispatcher::registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
+void btCollisionDispatcher::registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc* createFunc)
 {
 {
 	m_doubleDispatchClosestPoints[proxyType0][proxyType1] = createFunc;
 	m_doubleDispatchClosestPoints[proxyType0][proxyType1] = createFunc;
 }
 }
@@ -75,37 +65,33 @@ btCollisionDispatcher::~btCollisionDispatcher()
 {
 {
 }
 }
 
 
-btPersistentManifold*	btCollisionDispatcher::getNewManifold(const btCollisionObject* body0,const btCollisionObject* body1) 
-{ 
-	gNumManifold++;
-	
+btPersistentManifold* btCollisionDispatcher::getNewManifold(const btCollisionObject* body0, const btCollisionObject* body1)
+{
 	//btAssert(gNumManifold < 65535);
 	//btAssert(gNumManifold < 65535);
-	
-
 
 
 	//optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
 	//optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
-	
-	btScalar contactBreakingThreshold =  (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ? 
-		btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold))
-		: gContactBreakingThreshold ;
-
-	btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold());
-		
- 	void* mem = m_persistentManifoldPoolAllocator->allocate( sizeof( btPersistentManifold ) );
-    if (NULL == mem)
+
+	btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ? btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold), body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold))
+																																: gContactBreakingThreshold;
+
+	btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(), body1->getContactProcessingThreshold());
+
+	void* mem = m_persistentManifoldPoolAllocator->allocate(sizeof(btPersistentManifold));
+	if (NULL == mem)
 	{
 	{
-        //we got a pool memory overflow, by default we fallback to dynamically allocate memory. If we require a contiguous contact pool then assert.
-		if ((m_dispatcherFlags&CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION)==0)
+		//we got a pool memory overflow, by default we fallback to dynamically allocate memory. If we require a contiguous contact pool then assert.
+		if ((m_dispatcherFlags & CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION) == 0)
 		{
 		{
-			mem = btAlignedAlloc(sizeof(btPersistentManifold),16);
-		} else
+			mem = btAlignedAlloc(sizeof(btPersistentManifold), 16);
+		}
+		else
 		{
 		{
 			btAssert(0);
 			btAssert(0);
 			//make sure to increase the m_defaultMaxPersistentManifoldPoolSize in the btDefaultCollisionConstructionInfo/btDefaultCollisionConfiguration
 			//make sure to increase the m_defaultMaxPersistentManifoldPoolSize in the btDefaultCollisionConstructionInfo/btDefaultCollisionConfiguration
 			return 0;
 			return 0;
 		}
 		}
 	}
 	}
-	btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0,contactBreakingThreshold,contactProcessingThreshold);
+	btPersistentManifold* manifold = new (mem) btPersistentManifold(body0, body1, 0, contactBreakingThreshold, contactProcessingThreshold);
 	manifold->m_index1a = m_manifoldsPtr.size();
 	manifold->m_index1a = m_manifoldsPtr.size();
 	m_manifoldsPtr.push_back(manifold);
 	m_manifoldsPtr.push_back(manifold);
 
 
@@ -117,18 +103,14 @@ void btCollisionDispatcher::clearManifold(btPersistentManifold* manifold)
 	manifold->clearManifold();
 	manifold->clearManifold();
 }
 }
 
 
-	
 void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 {
 {
-	
-	gNumManifold--;
-
 	//printf("releaseManifold: gNumManifold %d\n",gNumManifold);
 	//printf("releaseManifold: gNumManifold %d\n",gNumManifold);
 	clearManifold(manifold);
 	clearManifold(manifold);
 
 
 	int findIndex = manifold->m_index1a;
 	int findIndex = manifold->m_index1a;
 	btAssert(findIndex < m_manifoldsPtr.size());
 	btAssert(findIndex < m_manifoldsPtr.size());
-	m_manifoldsPtr.swap(findIndex,m_manifoldsPtr.size()-1);
+	m_manifoldsPtr.swap(findIndex, m_manifoldsPtr.size() - 1);
 	m_manifoldsPtr[findIndex]->m_index1a = findIndex;
 	m_manifoldsPtr[findIndex]->m_index1a = findIndex;
 	m_manifoldsPtr.pop_back();
 	m_manifoldsPtr.pop_back();
 
 
@@ -136,19 +118,15 @@ void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 	if (m_persistentManifoldPoolAllocator->validPtr(manifold))
 	if (m_persistentManifoldPoolAllocator->validPtr(manifold))
 	{
 	{
 		m_persistentManifoldPoolAllocator->freeMemory(manifold);
 		m_persistentManifoldPoolAllocator->freeMemory(manifold);
-	} else
+	}
+	else
 	{
 	{
 		btAlignedFree(manifold);
 		btAlignedFree(manifold);
 	}
 	}
-	
 }
 }
 
 
-	
-
-
-btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType algoType)
+btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btPersistentManifold* sharedManifold, ebtDispatcherQueryType algoType)
 {
 {
-	
 	btCollisionAlgorithmConstructionInfo ci;
 	btCollisionAlgorithmConstructionInfo ci;
 
 
 	ci.m_dispatcher1 = this;
 	ci.m_dispatcher1 = this;
@@ -166,21 +144,18 @@ btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(const btCollisionObje
 	return algo;
 	return algo;
 }
 }
 
 
-
-
-
-bool	btCollisionDispatcher::needsResponse(const btCollisionObject* body0,const btCollisionObject* body1)
+bool btCollisionDispatcher::needsResponse(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
 	//here you can do filtering
 	//here you can do filtering
-	bool hasResponse = 
+	bool hasResponse =
 		(body0->hasContactResponse() && body1->hasContactResponse());
 		(body0->hasContactResponse() && body1->hasContactResponse());
 	//no response between two static/kinematic bodies:
 	//no response between two static/kinematic bodies:
 	hasResponse = hasResponse &&
 	hasResponse = hasResponse &&
-		((!body0->isStaticOrKinematicObject()) ||(! body1->isStaticOrKinematicObject()));
+				  ((!body0->isStaticOrKinematicObject()) || (!body1->isStaticOrKinematicObject()));
 	return hasResponse;
 	return hasResponse;
 }
 }
 
 
-bool	btCollisionDispatcher::needsCollision(const btCollisionObject* body0,const btCollisionObject* body1)
+bool btCollisionDispatcher::needsCollision(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
 	btAssert(body0);
 	btAssert(body0);
 	btAssert(body1);
 	btAssert(body1);
@@ -197,31 +172,27 @@ bool	btCollisionDispatcher::needsCollision(const btCollisionObject* body0,const
 			printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
 			printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
 		}
 		}
 	}
 	}
-#endif //BT_DEBUG
+#endif  //BT_DEBUG
 
 
 	if ((!body0->isActive()) && (!body1->isActive()))
 	if ((!body0->isActive()) && (!body1->isActive()))
 		needsCollision = false;
 		needsCollision = false;
 	else if ((!body0->checkCollideWith(body1)) || (!body1->checkCollideWith(body0)))
 	else if ((!body0->checkCollideWith(body1)) || (!body1->checkCollideWith(body0)))
 		needsCollision = false;
 		needsCollision = false;
-	
-	return needsCollision ;
 
 
+	return needsCollision;
 }
 }
 
 
-
-
 ///interface for iterating all overlapping collision pairs, no matter how those pairs are stored (array, set, map etc)
 ///interface for iterating all overlapping collision pairs, no matter how those pairs are stored (array, set, map etc)
 ///this is useful for the collision dispatcher.
 ///this is useful for the collision dispatcher.
 class btCollisionPairCallback : public btOverlapCallback
 class btCollisionPairCallback : public btOverlapCallback
 {
 {
 	const btDispatcherInfo& m_dispatchInfo;
 	const btDispatcherInfo& m_dispatchInfo;
-	btCollisionDispatcher*	m_dispatcher;
+	btCollisionDispatcher* m_dispatcher;
 
 
 public:
 public:
-
-	btCollisionPairCallback(const btDispatcherInfo& dispatchInfo,btCollisionDispatcher*	dispatcher)
-	:m_dispatchInfo(dispatchInfo),
-	m_dispatcher(dispatcher)
+	btCollisionPairCallback(const btDispatcherInfo& dispatchInfo, btCollisionDispatcher* dispatcher)
+		: m_dispatchInfo(dispatchInfo),
+		  m_dispatcher(dispatcher)
 	{
 	{
 	}
 	}
 
 
@@ -233,83 +204,76 @@ public:
 	}
 	}
 	*/
 	*/
 
 
-
 	virtual ~btCollisionPairCallback() {}
 	virtual ~btCollisionPairCallback() {}
 
 
-
-	virtual bool	processOverlap(btBroadphasePair& pair)
+	virtual bool processOverlap(btBroadphasePair& pair)
 	{
 	{
-		(*m_dispatcher->getNearCallback())(pair,*m_dispatcher,m_dispatchInfo);
+		(*m_dispatcher->getNearCallback())(pair, *m_dispatcher, m_dispatchInfo);
 		return false;
 		return false;
 	}
 	}
 };
 };
 
 
-
-
-void	btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) 
+void btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& dispatchInfo, btDispatcher* dispatcher)
 {
 {
 	//m_blockedForChanges = true;
 	//m_blockedForChanges = true;
 
 
-	btCollisionPairCallback	collisionCallback(dispatchInfo,this);
+	btCollisionPairCallback collisionCallback(dispatchInfo, this);
 
 
-	pairCache->processAllOverlappingPairs(&collisionCallback,dispatcher);
+	{
+		BT_PROFILE("processAllOverlappingPairs");
+		pairCache->processAllOverlappingPairs(&collisionCallback, dispatcher, dispatchInfo);
+	}
 
 
 	//m_blockedForChanges = false;
 	//m_blockedForChanges = false;
-
 }
 }
 
 
-
-
 //by default, Bullet will use this near callback
 //by default, Bullet will use this near callback
 void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
 void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
 {
 {
-		btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
-		btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
+	btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
+	btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
+
+	if (dispatcher.needsCollision(colObj0, colObj1))
+	{
+		btCollisionObjectWrapper obj0Wrap(0, colObj0->getCollisionShape(), colObj0, colObj0->getWorldTransform(), -1, -1);
+		btCollisionObjectWrapper obj1Wrap(0, colObj1->getCollisionShape(), colObj1, colObj1->getWorldTransform(), -1, -1);
 
 
-		if (dispatcher.needsCollision(colObj0,colObj1))
+		//dispatcher will keep algorithms persistent in the collision pair
+		if (!collisionPair.m_algorithm)
 		{
 		{
-			btCollisionObjectWrapper obj0Wrap(0,colObj0->getCollisionShape(),colObj0,colObj0->getWorldTransform(),-1,-1);
-			btCollisionObjectWrapper obj1Wrap(0,colObj1->getCollisionShape(),colObj1,colObj1->getWorldTransform(),-1,-1);
+			collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap, &obj1Wrap, 0, BT_CONTACT_POINT_ALGORITHMS);
+		}
 
 
+		if (collisionPair.m_algorithm)
+		{
+			btManifoldResult contactPointResult(&obj0Wrap, &obj1Wrap);
 
 
-			//dispatcher will keep algorithms persistent in the collision pair
-			if (!collisionPair.m_algorithm)
+			if (dispatchInfo.m_dispatchFunc == btDispatcherInfo::DISPATCH_DISCRETE)
 			{
 			{
-				collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap,0, BT_CONTACT_POINT_ALGORITHMS);
-			}
+				//discrete collision detection query
 
 
-			if (collisionPair.m_algorithm)
+				collisionPair.m_algorithm->processCollision(&obj0Wrap, &obj1Wrap, dispatchInfo, &contactPointResult);
+			}
+			else
 			{
 			{
-				btManifoldResult contactPointResult(&obj0Wrap,&obj1Wrap);
-				
-				if (dispatchInfo.m_dispatchFunc == 		btDispatcherInfo::DISPATCH_DISCRETE)
-				{
-					//discrete collision detection query
-					
-					collisionPair.m_algorithm->processCollision(&obj0Wrap,&obj1Wrap,dispatchInfo,&contactPointResult);
-				} else
-				{
-					//continuous collision detection query, time of impact (toi)
-					btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0,colObj1,dispatchInfo,&contactPointResult);
-					if (dispatchInfo.m_timeOfImpact > toi)
-						dispatchInfo.m_timeOfImpact = toi;
-
-				}
+				//continuous collision detection query, time of impact (toi)
+				btScalar toi = collisionPair.m_algorithm->calculateTimeOfImpact(colObj0, colObj1, dispatchInfo, &contactPointResult);
+				if (dispatchInfo.m_timeOfImpact > toi)
+					dispatchInfo.m_timeOfImpact = toi;
 			}
 			}
 		}
 		}
-
+	}
 }
 }
 
 
-
 void* btCollisionDispatcher::allocateCollisionAlgorithm(int size)
 void* btCollisionDispatcher::allocateCollisionAlgorithm(int size)
 {
 {
-    void* mem = m_collisionAlgorithmPoolAllocator->allocate( size );
-    if (NULL == mem)
-    {
-	    //warn user for overflow?
-	    return btAlignedAlloc(static_cast<size_t>(size), 16);
-    }
-    return mem;
+	void* mem = m_collisionAlgorithmPoolAllocator->allocate(size);
+	if (NULL == mem)
+	{
+		//warn user for overflow?
+		return btAlignedAlloc(static_cast<size_t>(size), 16);
+	}
+	return mem;
 }
 }
 
 
 void btCollisionDispatcher::freeCollisionAlgorithm(void* ptr)
 void btCollisionDispatcher::freeCollisionAlgorithm(void* ptr)
@@ -317,7 +281,8 @@ void btCollisionDispatcher::freeCollisionAlgorithm(void* ptr)
 	if (m_collisionAlgorithmPoolAllocator->validPtr(ptr))
 	if (m_collisionAlgorithmPoolAllocator->validPtr(ptr))
 	{
 	{
 		m_collisionAlgorithmPoolAllocator->freeMemory(ptr);
 		m_collisionAlgorithmPoolAllocator->freeMemory(ptr);
-	} else
+	}
+	else
 	{
 	{
 		btAlignedFree(ptr);
 		btAlignedFree(ptr);
 	}
 	}

+ 43 - 49
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h

@@ -37,35 +37,28 @@ class btCollisionDispatcher;
 ///user can override this nearcallback for collision filtering and more finegrained control over collision detection
 ///user can override this nearcallback for collision filtering and more finegrained control over collision detection
 typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
 typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
 
 
-
 ///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
 ///btCollisionDispatcher supports algorithms that handle ConvexConvex and ConvexConcave collision pairs.
 ///Time of Impact, Closest Points and Penetration Depth.
 ///Time of Impact, Closest Points and Penetration Depth.
 class btCollisionDispatcher : public btDispatcher
 class btCollisionDispatcher : public btDispatcher
 {
 {
-
 protected:
 protected:
+	int m_dispatcherFlags;
 
 
-	int		m_dispatcherFlags;
+	btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr;
 
 
-	btAlignedObjectArray<btPersistentManifold*>	m_manifoldsPtr;
+	btNearCallback m_nearCallback;
 
 
-	btManifoldResult	m_defaultManifoldResult;
+	btPoolAllocator* m_collisionAlgorithmPoolAllocator;
 
 
-	btNearCallback		m_nearCallback;
-	
-	btPoolAllocator*	m_collisionAlgorithmPoolAllocator;
-
-	btPoolAllocator*	m_persistentManifoldPoolAllocator;
+	btPoolAllocator* m_persistentManifoldPoolAllocator;
 
 
 	btCollisionAlgorithmCreateFunc* m_doubleDispatchContactPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
 	btCollisionAlgorithmCreateFunc* m_doubleDispatchContactPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
 
 
 	btCollisionAlgorithmCreateFunc* m_doubleDispatchClosestPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
 	btCollisionAlgorithmCreateFunc* m_doubleDispatchClosestPoints[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES];
 
 
-	btCollisionConfiguration*	m_collisionConfiguration;
-
+	btCollisionConfiguration* m_collisionConfiguration;
 
 
 public:
 public:
-
 	enum DispatcherFlags
 	enum DispatcherFlags
 	{
 	{
 		CD_STATIC_STATIC_REPORTED = 1,
 		CD_STATIC_STATIC_REPORTED = 1,
@@ -73,103 +66,104 @@ public:
 		CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4
 		CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4
 	};
 	};
 
 
-	int	getDispatcherFlags() const
+	int getDispatcherFlags() const
 	{
 	{
 		return m_dispatcherFlags;
 		return m_dispatcherFlags;
 	}
 	}
 
 
-	void	setDispatcherFlags(int flags)
+	void setDispatcherFlags(int flags)
 	{
 	{
 		m_dispatcherFlags = flags;
 		m_dispatcherFlags = flags;
 	}
 	}
 
 
 	///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
 	///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
-	void	registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
+	void registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
 
 
-	void	registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc);
+	void registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
 
 
-	int	getNumManifolds() const
-	{ 
-		return int( m_manifoldsPtr.size());
+	int getNumManifolds() const
+	{
+		return int(m_manifoldsPtr.size());
 	}
 	}
 
 
-	btPersistentManifold**	getInternalManifoldPointer()
+	btPersistentManifold** getInternalManifoldPointer()
 	{
 	{
-		return m_manifoldsPtr.size()? &m_manifoldsPtr[0] : 0;
+		return m_manifoldsPtr.size() ? &m_manifoldsPtr[0] : 0;
 	}
 	}
 
 
-	 btPersistentManifold* getManifoldByIndexInternal(int index)
+	btPersistentManifold* getManifoldByIndexInternal(int index)
 	{
 	{
+		btAssert(index>=0);
+		btAssert(index<m_manifoldsPtr.size());
 		return m_manifoldsPtr[index];
 		return m_manifoldsPtr[index];
 	}
 	}
 
 
-	 const btPersistentManifold* getManifoldByIndexInternal(int index) const
+	const btPersistentManifold* getManifoldByIndexInternal(int index) const
 	{
 	{
+		btAssert(index>=0);
+		btAssert(index<m_manifoldsPtr.size());
 		return m_manifoldsPtr[index];
 		return m_manifoldsPtr[index];
 	}
 	}
 
 
-	btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration);
+	btCollisionDispatcher(btCollisionConfiguration* collisionConfiguration);
 
 
 	virtual ~btCollisionDispatcher();
 	virtual ~btCollisionDispatcher();
 
 
-	virtual btPersistentManifold*	getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1);
-	
-	virtual void releaseManifold(btPersistentManifold* manifold);
+	virtual btPersistentManifold* getNewManifold(const btCollisionObject* b0, const btCollisionObject* b1);
 
 
+	virtual void releaseManifold(btPersistentManifold* manifold);
 
 
 	virtual void clearManifold(btPersistentManifold* manifold);
 	virtual void clearManifold(btPersistentManifold* manifold);
 
 
-	btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType);
-		
-	virtual bool	needsCollision(const btCollisionObject* body0,const btCollisionObject* body1);
-	
-	virtual bool	needsResponse(const btCollisionObject* body0,const btCollisionObject* body1);
-	
-	virtual void	dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) ;
+	btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType);
+
+	virtual bool needsCollision(const btCollisionObject* body0, const btCollisionObject* body1);
+
+	virtual bool needsResponse(const btCollisionObject* body0, const btCollisionObject* body1);
 
 
-	void	setNearCallback(btNearCallback	nearCallback)
+	virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& dispatchInfo, btDispatcher* dispatcher);
+
+	void setNearCallback(btNearCallback nearCallback)
 	{
 	{
-		m_nearCallback = nearCallback; 
+		m_nearCallback = nearCallback;
 	}
 	}
 
 
-	btNearCallback	getNearCallback() const
+	btNearCallback getNearCallback() const
 	{
 	{
 		return m_nearCallback;
 		return m_nearCallback;
 	}
 	}
 
 
 	//by default, Bullet will use this near callback
 	//by default, Bullet will use this near callback
-	static void  defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
+	static void defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
 
 
-	virtual	void* allocateCollisionAlgorithm(int size);
+	virtual void* allocateCollisionAlgorithm(int size);
 
 
-	virtual	void freeCollisionAlgorithm(void* ptr);
+	virtual void freeCollisionAlgorithm(void* ptr);
 
 
-	btCollisionConfiguration*	getCollisionConfiguration()
+	btCollisionConfiguration* getCollisionConfiguration()
 	{
 	{
 		return m_collisionConfiguration;
 		return m_collisionConfiguration;
 	}
 	}
 
 
-	const btCollisionConfiguration*	getCollisionConfiguration() const
+	const btCollisionConfiguration* getCollisionConfiguration() const
 	{
 	{
 		return m_collisionConfiguration;
 		return m_collisionConfiguration;
 	}
 	}
 
 
-	void	setCollisionConfiguration(btCollisionConfiguration* config)
+	void setCollisionConfiguration(btCollisionConfiguration* config)
 	{
 	{
 		m_collisionConfiguration = config;
 		m_collisionConfiguration = config;
 	}
 	}
 
 
-	virtual	btPoolAllocator*	getInternalManifoldPool()
+	virtual btPoolAllocator* getInternalManifoldPool()
 	{
 	{
 		return m_persistentManifoldPoolAllocator;
 		return m_persistentManifoldPoolAllocator;
 	}
 	}
 
 
-	virtual	const btPoolAllocator*	getInternalManifoldPool() const
+	virtual const btPoolAllocator* getInternalManifoldPool() const
 	{
 	{
 		return m_persistentManifoldPoolAllocator;
 		return m_persistentManifoldPoolAllocator;
 	}
 	}
-
 };
 };
 
 
-#endif //BT_COLLISION__DISPATCHER_H
-
+#endif  //BT_COLLISION__DISPATCHER_H

+ 162 - 0
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcherMt.cpp

@@ -0,0 +1,162 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose, 
+including commercial applications, and to alter it and redistribute it freely, 
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#include "btCollisionDispatcherMt.h"
+#include "LinearMath/btQuickprof.h"
+
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
+
+#include "BulletCollision/CollisionShapes/btCollisionShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
+#include "LinearMath/btPoolAllocator.h"
+#include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+
+btCollisionDispatcherMt::btCollisionDispatcherMt(btCollisionConfiguration* config, int grainSize)
+	: btCollisionDispatcher(config)
+{
+	m_batchManifoldsPtr.resize(btGetTaskScheduler()->getNumThreads());
+	m_batchUpdating = false;
+	m_grainSize = grainSize;  // iterations per task
+}
+
+btPersistentManifold* btCollisionDispatcherMt::getNewManifold(const btCollisionObject* body0, const btCollisionObject* body1)
+{
+	//optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance)
+
+	btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ? btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold), body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold))
+																																: gContactBreakingThreshold;
+
+	btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(), body1->getContactProcessingThreshold());
+
+	void* mem = m_persistentManifoldPoolAllocator->allocate(sizeof(btPersistentManifold));
+	if (NULL == mem)
+	{
+		//we got a pool memory overflow, by default we fallback to dynamically allocate memory. If we require a contiguous contact pool then assert.
+		if ((m_dispatcherFlags & CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION) == 0)
+		{
+			mem = btAlignedAlloc(sizeof(btPersistentManifold), 16);
+		}
+		else
+		{
+			btAssert(0);
+			//make sure to increase the m_defaultMaxPersistentManifoldPoolSize in the btDefaultCollisionConstructionInfo/btDefaultCollisionConfiguration
+			return 0;
+		}
+	}
+	btPersistentManifold* manifold = new (mem) btPersistentManifold(body0, body1, 0, contactBreakingThreshold, contactProcessingThreshold);
+	if (!m_batchUpdating)
+	{
+		// batch updater will update manifold pointers array after finishing, so
+		// only need to update array when not batch-updating
+		//btAssert( !btThreadsAreRunning() );
+		manifold->m_index1a = m_manifoldsPtr.size();
+		m_manifoldsPtr.push_back(manifold);
+	}
+	else
+	{
+		m_batchManifoldsPtr[btGetCurrentThreadIndex()].push_back(manifold);
+	}
+
+	return manifold;
+}
+
+void btCollisionDispatcherMt::releaseManifold(btPersistentManifold* manifold)
+{
+	clearManifold(manifold);
+	//btAssert( !btThreadsAreRunning() );
+	if (!m_batchUpdating)
+	{
+		// batch updater will update manifold pointers array after finishing, so
+		// only need to update array when not batch-updating
+		int findIndex = manifold->m_index1a;
+		btAssert(findIndex < m_manifoldsPtr.size());
+		m_manifoldsPtr.swap(findIndex, m_manifoldsPtr.size() - 1);
+		m_manifoldsPtr[findIndex]->m_index1a = findIndex;
+		m_manifoldsPtr.pop_back();
+	}
+
+	manifold->~btPersistentManifold();
+	if (m_persistentManifoldPoolAllocator->validPtr(manifold))
+	{
+		m_persistentManifoldPoolAllocator->freeMemory(manifold);
+	}
+	else
+	{
+		btAlignedFree(manifold);
+	}
+}
+
+struct CollisionDispatcherUpdater : public btIParallelForBody
+{
+	btBroadphasePair* mPairArray;
+	btNearCallback mCallback;
+	btCollisionDispatcher* mDispatcher;
+	const btDispatcherInfo* mInfo;
+
+	CollisionDispatcherUpdater()
+	{
+		mPairArray = NULL;
+		mCallback = NULL;
+		mDispatcher = NULL;
+		mInfo = NULL;
+	}
+	void forLoop(int iBegin, int iEnd) const
+	{
+		for (int i = iBegin; i < iEnd; ++i)
+		{
+			btBroadphasePair* pair = &mPairArray[i];
+			mCallback(*pair, *mDispatcher, *mInfo);
+		}
+	}
+};
+
+void btCollisionDispatcherMt::dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& info, btDispatcher* dispatcher)
+{
+	const int pairCount = pairCache->getNumOverlappingPairs();
+	if (pairCount == 0)
+	{
+		return;
+	}
+	CollisionDispatcherUpdater updater;
+	updater.mCallback = getNearCallback();
+	updater.mPairArray = pairCache->getOverlappingPairArrayPtr();
+	updater.mDispatcher = this;
+	updater.mInfo = &info;
+
+	m_batchUpdating = true;
+	btParallelFor(0, pairCount, m_grainSize, updater);
+	m_batchUpdating = false;
+
+	// merge new manifolds, if any
+	for (int i = 0; i < m_batchManifoldsPtr.size(); ++i)
+	{
+		btAlignedObjectArray<btPersistentManifold*>& batchManifoldsPtr = m_batchManifoldsPtr[i];
+
+		for (int j = 0; j < batchManifoldsPtr.size(); ++j)
+		{
+			m_manifoldsPtr.push_back(batchManifoldsPtr[j]);
+		}
+
+		batchManifoldsPtr.resizeNoInitialize(0);
+	}
+
+	// update the indices (used when releasing manifolds)
+	for (int i = 0; i < m_manifoldsPtr.size(); ++i)
+	{
+		m_manifoldsPtr[i]->m_index1a = i;
+	}
+}

+ 38 - 0
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcherMt.h

@@ -0,0 +1,38 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
+
+This software is provided 'as-is', without any express or implied warranty.
+In no event will the authors be held liable for any damages arising from the use of this software.
+Permission is granted to anyone to use this software for any purpose, 
+including commercial applications, and to alter it and redistribute it freely, 
+subject to the following restrictions:
+
+1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+3. This notice may not be removed or altered from any source distribution.
+*/
+
+#ifndef BT_COLLISION_DISPATCHER_MT_H
+#define BT_COLLISION_DISPATCHER_MT_H
+
+#include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
+#include "LinearMath/btThreads.h"
+
+class btCollisionDispatcherMt : public btCollisionDispatcher
+{
+public:
+	btCollisionDispatcherMt(btCollisionConfiguration* config, int grainSize = 40);
+
+	virtual btPersistentManifold* getNewManifold(const btCollisionObject* body0, const btCollisionObject* body1) BT_OVERRIDE;
+	virtual void releaseManifold(btPersistentManifold* manifold) BT_OVERRIDE;
+
+	virtual void dispatchAllCollisionPairs(btOverlappingPairCache* pairCache, const btDispatcherInfo& info, btDispatcher* dispatcher) BT_OVERRIDE;
+
+protected:
+	btAlignedObjectArray<btAlignedObjectArray<btPersistentManifold*> > m_batchManifoldsPtr;
+	bool m_batchUpdating;
+	int m_grainSize;
+};
+
+#endif  //BT_COLLISION_DISPATCHER_MT_H

+ 53 - 40
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp

@@ -13,41 +13,45 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "btCollisionObject.h"
 #include "btCollisionObject.h"
 #include "LinearMath/btSerializer.h"
 #include "LinearMath/btSerializer.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 
 
 btCollisionObject::btCollisionObject()
 btCollisionObject::btCollisionObject()
-	:	m_anisotropicFriction(1.f,1.f,1.f),
-	m_hasAnisotropicFriction(false),
-	m_contactProcessingThreshold(BT_LARGE_FLOAT),
-		m_broadphaseHandle(0),
-		m_collisionShape(0),
-		m_extensionPointer(0),
-		m_rootCollisionShape(0),
-		m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
-		m_islandTag1(-1),
-		m_companionId(-1),
-        m_worldArrayIndex(-1),
-		m_activationState1(1),
-		m_deactivationTime(btScalar(0.)),
-		m_friction(btScalar(0.5)),
-		m_restitution(btScalar(0.)),
-		m_rollingFriction(0.0f),
-        m_spinningFriction(0.f),
-		m_contactDamping(.1),
-		m_contactStiffness(1e4),
-		m_internalType(CO_COLLISION_OBJECT),
-		m_userObjectPointer(0),
-		m_userIndex2(-1),
-		m_userIndex(-1),
-		m_hitFraction(btScalar(1.)),
-		m_ccdSweptSphereRadius(btScalar(0.)),
-		m_ccdMotionThreshold(btScalar(0.)),
-		m_checkCollideWith(false),
-		m_updateRevision(0)
+	: m_interpolationLinearVelocity(0.f, 0.f, 0.f),
+	  m_interpolationAngularVelocity(0.f, 0.f, 0.f),
+	  m_anisotropicFriction(1.f, 1.f, 1.f),
+	  m_hasAnisotropicFriction(false),
+	  m_contactProcessingThreshold(BT_LARGE_FLOAT),
+	  m_broadphaseHandle(0),
+	  m_collisionShape(0),
+	  m_extensionPointer(0),
+	  m_rootCollisionShape(0),
+	  m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
+	  m_islandTag1(-1),
+	  m_companionId(-1),
+	  m_worldArrayIndex(-1),
+	  m_activationState1(1),
+	  m_deactivationTime(btScalar(0.)),
+	  m_friction(btScalar(0.5)),
+	  m_restitution(btScalar(0.)),
+	  m_rollingFriction(0.0f),
+	  m_spinningFriction(0.f),
+	  m_contactDamping(.1),
+	  m_contactStiffness(BT_LARGE_FLOAT),
+	  m_internalType(CO_COLLISION_OBJECT),
+	  m_userObjectPointer(0),
+	  m_userIndex2(-1),
+	  m_userIndex(-1),
+	  m_userIndex3(-1),
+	  m_hitFraction(btScalar(1.)),
+	  m_ccdSweptSphereRadius(btScalar(0.)),
+	  m_ccdMotionThreshold(btScalar(0.)),
+	  m_checkCollideWith(false),
+	  m_updateRevision(0)
 {
 {
 	m_worldTransform.setIdentity();
 	m_worldTransform.setIdentity();
+	m_interpolationWorldTransform.setIdentity();
 }
 }
 
 
 btCollisionObject::~btCollisionObject()
 btCollisionObject::~btCollisionObject()
@@ -55,8 +59,8 @@ btCollisionObject::~btCollisionObject()
 }
 }
 
 
 void btCollisionObject::setActivationState(int newState) const
 void btCollisionObject::setActivationState(int newState) const
-{ 
-	if ( (m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
+{
+	if ((m_activationState1 != DISABLE_DEACTIVATION) && (m_activationState1 != DISABLE_SIMULATION))
 		m_activationState1 = newState;
 		m_activationState1 = newState;
 }
 }
 
 
@@ -67,7 +71,7 @@ void btCollisionObject::forceActivationState(int newState) const
 
 
 void btCollisionObject::activate(bool forceActivation) const
 void btCollisionObject::activate(bool forceActivation) const
 {
 {
-	if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT|CF_KINEMATIC_OBJECT)))
+	if (forceActivation || !(m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT)))
 	{
 	{
 		setActivationState(ACTIVE_TAG);
 		setActivationState(ACTIVE_TAG);
 		m_deactivationTime = btScalar(0.);
 		m_deactivationTime = btScalar(0.);
@@ -76,7 +80,6 @@ void btCollisionObject::activate(bool forceActivation) const
 
 
 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
 {
 {
-
 	btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
 	btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
 
 
 	m_worldTransform.serialize(dataOut->m_worldTransform);
 	m_worldTransform.serialize(dataOut->m_worldTransform);
@@ -88,7 +91,7 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali
 	dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
 	dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
 	dataOut->m_broadphaseHandle = 0;
 	dataOut->m_broadphaseHandle = 0;
 	dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
 	dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
-	dataOut->m_rootCollisionShape = 0;//@todo
+	dataOut->m_rootCollisionShape = 0;  //@todo
 	dataOut->m_collisionFlags = m_collisionFlags;
 	dataOut->m_collisionFlags = m_collisionFlags;
 	dataOut->m_islandTag1 = m_islandTag1;
 	dataOut->m_islandTag1 = m_islandTag1;
 	dataOut->m_companionId = m_companionId;
 	dataOut->m_companionId = m_companionId;
@@ -100,8 +103,8 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali
 	dataOut->m_contactStiffness = m_contactStiffness;
 	dataOut->m_contactStiffness = m_contactStiffness;
 	dataOut->m_restitution = m_restitution;
 	dataOut->m_restitution = m_restitution;
 	dataOut->m_internalType = m_internalType;
 	dataOut->m_internalType = m_internalType;
-	
-	char* name = (char*) serializer->findNameForPointer(this);
+
+	char* name = (char*)serializer->findNameForPointer(this);
 	dataOut->m_name = (char*)serializer->getUniquePointer(name);
 	dataOut->m_name = (char*)serializer->getUniquePointer(name);
 	if (dataOut->m_name)
 	if (dataOut->m_name)
 	{
 	{
@@ -111,15 +114,25 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali
 	dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
 	dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
 	dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
 	dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
 	dataOut->m_checkCollideWith = m_checkCollideWith;
 	dataOut->m_checkCollideWith = m_checkCollideWith;
-
+	if (m_broadphaseHandle)
+	{
+		dataOut->m_collisionFilterGroup = m_broadphaseHandle->m_collisionFilterGroup;
+		dataOut->m_collisionFilterMask = m_broadphaseHandle->m_collisionFilterMask;
+		dataOut->m_uniqueId = m_broadphaseHandle->m_uniqueId;
+	}
+	else
+	{
+		dataOut->m_collisionFilterGroup = 0;
+		dataOut->m_collisionFilterMask = 0;
+		dataOut->m_uniqueId = -1;
+	}
 	return btCollisionObjectDataName;
 	return btCollisionObjectDataName;
 }
 }
 
 
-
 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const
 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const
 {
 {
 	int len = calculateSerializeBufferSize();
 	int len = calculateSerializeBufferSize();
-	btChunk* chunk = serializer->allocate(len,1);
+	btChunk* chunk = serializer->allocate(len, 1);
 	const char* structType = serialize(chunk->m_oldPtr, serializer);
 	const char* structType = serialize(chunk->m_oldPtr, serializer);
-	serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this);
+	serializer->finalizeChunk(chunk, structType, BT_COLLISIONOBJECT_CODE, (void*)this);
 }
 }

+ 210 - 199
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.h

@@ -25,8 +25,8 @@ subject to the following restrictions:
 #define DISABLE_DEACTIVATION 4
 #define DISABLE_DEACTIVATION 4
 #define DISABLE_SIMULATION 5
 #define DISABLE_SIMULATION 5
 
 
-struct	btBroadphaseProxy;
-class	btCollisionShape;
+struct btBroadphaseProxy;
+class btCollisionShape;
 struct btCollisionShapeData;
 struct btCollisionShapeData;
 #include "LinearMath/btMotionState.h"
 #include "LinearMath/btMotionState.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
@@ -42,121 +42,120 @@ typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
 #define btCollisionObjectDataName "btCollisionObjectFloatData"
 #define btCollisionObjectDataName "btCollisionObjectFloatData"
 #endif
 #endif
 
 
-
-/// btCollisionObject can be used to manage collision detection objects. 
+/// btCollisionObject can be used to manage collision detection objects.
 /// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy.
 /// btCollisionObject maintains all information that is needed for a collision detection: Shape, Transform and AABB proxy.
 /// They can be added to the btCollisionWorld.
 /// They can be added to the btCollisionWorld.
-ATTRIBUTE_ALIGNED16(class)	btCollisionObject
+ATTRIBUTE_ALIGNED16(class)
+btCollisionObject
 {
 {
-
 protected:
 protected:
-
-	btTransform	m_worldTransform;
+	btTransform m_worldTransform;
 
 
 	///m_interpolationWorldTransform is used for CCD and interpolation
 	///m_interpolationWorldTransform is used for CCD and interpolation
 	///it can be either previous or future (predicted) transform
 	///it can be either previous or future (predicted) transform
-	btTransform	m_interpolationWorldTransform;
-	//those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities) 
+	btTransform m_interpolationWorldTransform;
+	//those two are experimental: just added for bullet time effect, so you can still apply impulses (directly modifying velocities)
 	//without destroying the continuous interpolated motion (which uses this interpolation velocities)
 	//without destroying the continuous interpolated motion (which uses this interpolation velocities)
-	btVector3	m_interpolationLinearVelocity;
-	btVector3	m_interpolationAngularVelocity;
-	
-	btVector3	m_anisotropicFriction;
-	int			m_hasAnisotropicFriction;
-	btScalar	m_contactProcessingThreshold;	
-
-	btBroadphaseProxy*		m_broadphaseHandle;
-	btCollisionShape*		m_collisionShape;
+	btVector3 m_interpolationLinearVelocity;
+	btVector3 m_interpolationAngularVelocity;
+
+	btVector3 m_anisotropicFriction;
+	int m_hasAnisotropicFriction;
+	btScalar m_contactProcessingThreshold;
+
+	btBroadphaseProxy* m_broadphaseHandle;
+	btCollisionShape* m_collisionShape;
 	///m_extensionPointer is used by some internal low-level Bullet extensions.
 	///m_extensionPointer is used by some internal low-level Bullet extensions.
-	void*					m_extensionPointer;
-	
+	void* m_extensionPointer;
+
 	///m_rootCollisionShape is temporarily used to store the original collision shape
 	///m_rootCollisionShape is temporarily used to store the original collision shape
 	///The m_collisionShape might be temporarily replaced by a child collision shape during collision detection purposes
 	///The m_collisionShape might be temporarily replaced by a child collision shape during collision detection purposes
 	///If it is NULL, the m_collisionShape is not temporarily replaced.
 	///If it is NULL, the m_collisionShape is not temporarily replaced.
-	btCollisionShape*		m_rootCollisionShape;
+	btCollisionShape* m_rootCollisionShape;
 
 
-	int				m_collisionFlags;
+	int m_collisionFlags;
 
 
-	int				m_islandTag1;
-	int				m_companionId;
-    int             m_worldArrayIndex;  // index of object in world's collisionObjects array
+	int m_islandTag1;
+	int m_companionId;
+	int m_worldArrayIndex;  // index of object in world's collisionObjects array
 
 
-	mutable int				m_activationState1;
-	mutable btScalar			m_deactivationTime;
+	mutable int m_activationState1;
+	mutable btScalar m_deactivationTime;
 
 
-	btScalar		m_friction;
-	btScalar		m_restitution;
-	btScalar		m_rollingFriction;//torsional friction orthogonal to contact normal (useful to stop spheres rolling forever)
-    btScalar        m_spinningFriction; // torsional friction around the contact normal (useful for grasping)
-	btScalar		m_contactDamping;
-	btScalar		m_contactStiffness;
-	
-	
+	btScalar m_friction;
+	btScalar m_restitution;
+	btScalar m_rollingFriction;   //torsional friction orthogonal to contact normal (useful to stop spheres rolling forever)
+	btScalar m_spinningFriction;  // torsional friction around the contact normal (useful for grasping)
+	btScalar m_contactDamping;
+	btScalar m_contactStiffness;
 
 
 	///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
 	///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc.
 	///do not assign your own m_internalType unless you write a new dynamics object class.
 	///do not assign your own m_internalType unless you write a new dynamics object class.
-	int				m_internalType;
+	int m_internalType;
 
 
 	///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
 	///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
 
 
-	void*			m_userObjectPointer;
+	void* m_userObjectPointer;
+
+	int m_userIndex2;
+
+	int m_userIndex;
 
 
-	int				m_userIndex2;
-	
-    int	m_userIndex;
+	int m_userIndex3;
 
 
 	///time of impact calculation
 	///time of impact calculation
-	btScalar		m_hitFraction; 
-	
+	btScalar m_hitFraction;
+
 	///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
 	///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
-	btScalar		m_ccdSweptSphereRadius;
+	btScalar m_ccdSweptSphereRadius;
 
 
 	/// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
 	/// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
-	btScalar		m_ccdMotionThreshold;
-	
+	btScalar m_ccdMotionThreshold;
+
 	/// If some object should have elaborate collision filtering by sub-classes
 	/// If some object should have elaborate collision filtering by sub-classes
-	int			m_checkCollideWith;
+	int m_checkCollideWith;
 
 
 	btAlignedObjectArray<const btCollisionObject*> m_objectsWithoutCollisionCheck;
 	btAlignedObjectArray<const btCollisionObject*> m_objectsWithoutCollisionCheck;
 
 
 	///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation.
 	///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation.
-	int			m_updateRevision;
+	int m_updateRevision;
 
 
-	btVector3	m_customDebugColorRGB;
+	btVector3 m_customDebugColorRGB;
 
 
 public:
 public:
-
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	enum CollisionFlags
 	enum CollisionFlags
 	{
 	{
-		CF_STATIC_OBJECT= 1,
-		CF_KINEMATIC_OBJECT= 2,
+		CF_STATIC_OBJECT = 1,
+		CF_KINEMATIC_OBJECT = 2,
 		CF_NO_CONTACT_RESPONSE = 4,
 		CF_NO_CONTACT_RESPONSE = 4,
-		CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
+		CF_CUSTOM_MATERIAL_CALLBACK = 8,  //this allows per-triangle material (friction/restitution)
 		CF_CHARACTER_OBJECT = 16,
 		CF_CHARACTER_OBJECT = 16,
-		CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
-		CF_DISABLE_SPU_COLLISION_PROCESSING = 64,//disable parallel/SPU processing
+		CF_DISABLE_VISUALIZE_OBJECT = 32,          //disable debug drawing
+		CF_DISABLE_SPU_COLLISION_PROCESSING = 64,  //disable parallel/SPU processing
 		CF_HAS_CONTACT_STIFFNESS_DAMPING = 128,
 		CF_HAS_CONTACT_STIFFNESS_DAMPING = 128,
 		CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR = 256,
 		CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR = 256,
+		CF_HAS_FRICTION_ANCHOR = 512,
+		CF_HAS_COLLISION_SOUND_TRIGGER = 1024
 	};
 	};
 
 
-	enum	CollisionObjectTypes
+	enum CollisionObjectTypes
 	{
 	{
-		CO_COLLISION_OBJECT =1,
-		CO_RIGID_BODY=2,
+		CO_COLLISION_OBJECT = 1,
+		CO_RIGID_BODY = 2,
 		///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter
 		///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter
 		///It is useful for collision sensors, explosion objects, character controller etc.
 		///It is useful for collision sensors, explosion objects, character controller etc.
-		CO_GHOST_OBJECT=4,
-		CO_SOFT_BODY=8,
-		CO_HF_FLUID=16,
-		CO_USER_TYPE=32,
-		CO_FEATHERSTONE_LINK=64
+		CO_GHOST_OBJECT = 4,
+		CO_SOFT_BODY = 8,
+		CO_HF_FLUID = 16,
+		CO_USER_TYPE = 32,
+		CO_FEATHERSTONE_LINK = 64
 	};
 	};
 
 
 	enum AnisotropicFrictionFlags
 	enum AnisotropicFrictionFlags
 	{
 	{
-		CF_ANISOTROPIC_FRICTION_DISABLED=0,
+		CF_ANISOTROPIC_FRICTION_DISABLED = 0,
 		CF_ANISOTROPIC_FRICTION = 1,
 		CF_ANISOTROPIC_FRICTION = 1,
 		CF_ANISOTROPIC_ROLLING_FRICTION = 2
 		CF_ANISOTROPIC_ROLLING_FRICTION = 2
 	};
 	};
@@ -164,76 +163,77 @@ public:
 	SIMD_FORCE_INLINE bool mergesSimulationIslands() const
 	SIMD_FORCE_INLINE bool mergesSimulationIslands() const
 	{
 	{
 		///static objects, kinematic and object without contact response don't merge islands
 		///static objects, kinematic and object without contact response don't merge islands
-		return  ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE) )==0);
+		return ((m_collisionFlags & (CF_STATIC_OBJECT | CF_KINEMATIC_OBJECT | CF_NO_CONTACT_RESPONSE)) == 0);
 	}
 	}
 
 
 	const btVector3& getAnisotropicFriction() const
 	const btVector3& getAnisotropicFriction() const
 	{
 	{
 		return m_anisotropicFriction;
 		return m_anisotropicFriction;
 	}
 	}
-	void	setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
+	void setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
 	{
 	{
 		m_anisotropicFriction = anisotropicFriction;
 		m_anisotropicFriction = anisotropicFriction;
-		bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
-		m_hasAnisotropicFriction = isUnity?frictionMode : 0;
+		bool isUnity = (anisotropicFriction[0] != 1.f) || (anisotropicFriction[1] != 1.f) || (anisotropicFriction[2] != 1.f);
+		m_hasAnisotropicFriction = isUnity ? frictionMode : 0;
 	}
 	}
-	bool	hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
+	bool hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
 	{
 	{
-		return (m_hasAnisotropicFriction&frictionMode)!=0;
+		return (m_hasAnisotropicFriction & frictionMode) != 0;
 	}
 	}
 
 
 	///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default.
 	///the constraint solver can discard solving contacts, if the distance is above this threshold. 0 by default.
 	///Note that using contacts with positive distance can improve stability. It increases, however, the chance of colliding with degerate contacts, such as 'interior' triangle edges
 	///Note that using contacts with positive distance can improve stability. It increases, however, the chance of colliding with degerate contacts, such as 'interior' triangle edges
-	void	setContactProcessingThreshold( btScalar contactProcessingThreshold)
+	void setContactProcessingThreshold(btScalar contactProcessingThreshold)
 	{
 	{
 		m_contactProcessingThreshold = contactProcessingThreshold;
 		m_contactProcessingThreshold = contactProcessingThreshold;
 	}
 	}
-	btScalar	getContactProcessingThreshold() const
+	btScalar getContactProcessingThreshold() const
 	{
 	{
 		return m_contactProcessingThreshold;
 		return m_contactProcessingThreshold;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool		isStaticObject() const {
+	SIMD_FORCE_INLINE bool isStaticObject() const
+	{
 		return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
 		return (m_collisionFlags & CF_STATIC_OBJECT) != 0;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool		isKinematicObject() const
+	SIMD_FORCE_INLINE bool isKinematicObject() const
 	{
 	{
 		return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
 		return (m_collisionFlags & CF_KINEMATIC_OBJECT) != 0;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool		isStaticOrKinematicObject() const
+	SIMD_FORCE_INLINE bool isStaticOrKinematicObject() const
 	{
 	{
-		return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0 ;
+		return (m_collisionFlags & (CF_KINEMATIC_OBJECT | CF_STATIC_OBJECT)) != 0;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool		hasContactResponse() const {
-		return (m_collisionFlags & CF_NO_CONTACT_RESPONSE)==0;
+	SIMD_FORCE_INLINE bool hasContactResponse() const
+	{
+		return (m_collisionFlags & CF_NO_CONTACT_RESPONSE) == 0;
 	}
 	}
 
 
-	
 	btCollisionObject();
 	btCollisionObject();
 
 
 	virtual ~btCollisionObject();
 	virtual ~btCollisionObject();
 
 
-	virtual void	setCollisionShape(btCollisionShape* collisionShape)
+	virtual void setCollisionShape(btCollisionShape * collisionShape)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_collisionShape = collisionShape;
 		m_collisionShape = collisionShape;
 		m_rootCollisionShape = collisionShape;
 		m_rootCollisionShape = collisionShape;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE const btCollisionShape*	getCollisionShape() const
+	SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const
 	{
 	{
 		return m_collisionShape;
 		return m_collisionShape;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE btCollisionShape*	getCollisionShape()
+	SIMD_FORCE_INLINE btCollisionShape* getCollisionShape()
 	{
 	{
 		return m_collisionShape;
 		return m_collisionShape;
 	}
 	}
 
 
-	void	setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
+	void setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
 	{
 	{
 		if (ignoreCollisionCheck)
 		if (ignoreCollisionCheck)
 		{
 		{
@@ -251,7 +251,17 @@ public:
 		m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
 		m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
 	}
 	}
 
 
-	virtual bool	checkCollideWithOverride(const btCollisionObject*  co) const
+        int getNumObjectsWithoutCollision() const
+	{
+		return m_objectsWithoutCollisionCheck.size();
+	}
+
+	const btCollisionObject* getObjectWithoutCollision(int index)
+	{
+		return m_objectsWithoutCollisionCheck[index];
+	}
+
+	virtual bool checkCollideWithOverride(const btCollisionObject* co) const
 	{
 	{
 		int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
 		int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
 		if (index < m_objectsWithoutCollisionCheck.size())
 		if (index < m_objectsWithoutCollisionCheck.size())
@@ -261,317 +271,319 @@ public:
 		return true;
 		return true;
 	}
 	}
 
 
-
-	
-
-	///Avoid using this internal API call, the extension pointer is used by some Bullet extensions. 
+	///Avoid using this internal API call, the extension pointer is used by some Bullet extensions.
 	///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
 	///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
-	void*		internalGetExtensionPointer() const
+	void* internalGetExtensionPointer() const
 	{
 	{
 		return m_extensionPointer;
 		return m_extensionPointer;
 	}
 	}
 	///Avoid using this internal API call, the extension pointer is used by some Bullet extensions
 	///Avoid using this internal API call, the extension pointer is used by some Bullet extensions
 	///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
 	///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead.
-	void	internalSetExtensionPointer(void* pointer)
+	void internalSetExtensionPointer(void* pointer)
 	{
 	{
 		m_extensionPointer = pointer;
 		m_extensionPointer = pointer;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE	int	getActivationState() const { return m_activationState1;}
-	
+	SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1; }
+
 	void setActivationState(int newState) const;
 	void setActivationState(int newState) const;
 
 
-	void	setDeactivationTime(btScalar time)
+	void setDeactivationTime(btScalar time)
 	{
 	{
 		m_deactivationTime = time;
 		m_deactivationTime = time;
 	}
 	}
-	btScalar	getDeactivationTime() const
+	btScalar getDeactivationTime() const
 	{
 	{
 		return m_deactivationTime;
 		return m_deactivationTime;
 	}
 	}
 
 
 	void forceActivationState(int newState) const;
 	void forceActivationState(int newState) const;
 
 
-	void	activate(bool forceActivation = false) const;
+	void activate(bool forceActivation = false) const;
 
 
 	SIMD_FORCE_INLINE bool isActive() const
 	SIMD_FORCE_INLINE bool isActive() const
 	{
 	{
 		return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
 		return ((getActivationState() != ISLAND_SLEEPING) && (getActivationState() != DISABLE_SIMULATION));
 	}
 	}
 
 
-	void	setRestitution(btScalar rest)
+	void setRestitution(btScalar rest)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_restitution = rest;
 		m_restitution = rest;
 	}
 	}
-	btScalar	getRestitution() const
+	btScalar getRestitution() const
 	{
 	{
 		return m_restitution;
 		return m_restitution;
 	}
 	}
-	void	setFriction(btScalar frict)
+	void setFriction(btScalar frict)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_friction = frict;
 		m_friction = frict;
 	}
 	}
-	btScalar	getFriction() const
+	btScalar getFriction() const
 	{
 	{
 		return m_friction;
 		return m_friction;
 	}
 	}
 
 
-	void	setRollingFriction(btScalar frict)
+	void setRollingFriction(btScalar frict)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_rollingFriction = frict;
 		m_rollingFriction = frict;
 	}
 	}
-	btScalar	getRollingFriction() const
+	btScalar getRollingFriction() const
 	{
 	{
 		return m_rollingFriction;
 		return m_rollingFriction;
 	}
 	}
-    void	setSpinningFriction(btScalar frict)
-    {
-        m_updateRevision++;
-        m_spinningFriction = frict;
-    }
-    btScalar	getSpinningFriction() const
-    {
-        return m_spinningFriction;
-    }
-    void	setContactStiffnessAndDamping(btScalar stiffness, btScalar damping)
+	void setSpinningFriction(btScalar frict)
+	{
+		m_updateRevision++;
+		m_spinningFriction = frict;
+	}
+	btScalar getSpinningFriction() const
+	{
+		return m_spinningFriction;
+	}
+	void setContactStiffnessAndDamping(btScalar stiffness, btScalar damping)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_contactStiffness = stiffness;
 		m_contactStiffness = stiffness;
 		m_contactDamping = damping;
 		m_contactDamping = damping;
-		
-		m_collisionFlags |=CF_HAS_CONTACT_STIFFNESS_DAMPING;
-		
-        //avoid divisions by zero...
-		if (m_contactStiffness< SIMD_EPSILON)
-        {
-            m_contactStiffness = SIMD_EPSILON;
-        }
-	}
-	
-	btScalar	getContactStiffness() const
+
+		m_collisionFlags |= CF_HAS_CONTACT_STIFFNESS_DAMPING;
+
+		//avoid divisions by zero...
+		if (m_contactStiffness < SIMD_EPSILON)
+		{
+			m_contactStiffness = SIMD_EPSILON;
+		}
+	}
+
+	btScalar getContactStiffness() const
 	{
 	{
 		return m_contactStiffness;
 		return m_contactStiffness;
 	}
 	}
-	
-	btScalar	getContactDamping() const
+
+	btScalar getContactDamping() const
 	{
 	{
 		return m_contactDamping;
 		return m_contactDamping;
 	}
 	}
-    
+
 	///reserved for Bullet internal usage
 	///reserved for Bullet internal usage
-	int	getInternalType() const
+	int getInternalType() const
 	{
 	{
 		return m_internalType;
 		return m_internalType;
 	}
 	}
 
 
-	btTransform&	getWorldTransform()
+	btTransform& getWorldTransform()
 	{
 	{
 		return m_worldTransform;
 		return m_worldTransform;
 	}
 	}
 
 
-	const btTransform&	getWorldTransform() const
+	const btTransform& getWorldTransform() const
 	{
 	{
 		return m_worldTransform;
 		return m_worldTransform;
 	}
 	}
 
 
-	void	setWorldTransform(const btTransform& worldTrans)
+	void setWorldTransform(const btTransform& worldTrans)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_worldTransform = worldTrans;
 		m_worldTransform = worldTrans;
 	}
 	}
 
 
-
-	SIMD_FORCE_INLINE btBroadphaseProxy*	getBroadphaseHandle()
+	SIMD_FORCE_INLINE btBroadphaseProxy* getBroadphaseHandle()
 	{
 	{
 		return m_broadphaseHandle;
 		return m_broadphaseHandle;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE const btBroadphaseProxy*	getBroadphaseHandle() const
+	SIMD_FORCE_INLINE const btBroadphaseProxy* getBroadphaseHandle() const
 	{
 	{
 		return m_broadphaseHandle;
 		return m_broadphaseHandle;
 	}
 	}
 
 
-	void	setBroadphaseHandle(btBroadphaseProxy* handle)
+	void setBroadphaseHandle(btBroadphaseProxy * handle)
 	{
 	{
 		m_broadphaseHandle = handle;
 		m_broadphaseHandle = handle;
 	}
 	}
 
 
-
-	const btTransform&	getInterpolationWorldTransform() const
+	const btTransform& getInterpolationWorldTransform() const
 	{
 	{
 		return m_interpolationWorldTransform;
 		return m_interpolationWorldTransform;
 	}
 	}
 
 
-	btTransform&	getInterpolationWorldTransform()
+	btTransform& getInterpolationWorldTransform()
 	{
 	{
 		return m_interpolationWorldTransform;
 		return m_interpolationWorldTransform;
 	}
 	}
 
 
-	void	setInterpolationWorldTransform(const btTransform&	trans)
+	void setInterpolationWorldTransform(const btTransform& trans)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_interpolationWorldTransform = trans;
 		m_interpolationWorldTransform = trans;
 	}
 	}
 
 
-	void	setInterpolationLinearVelocity(const btVector3& linvel)
+	void setInterpolationLinearVelocity(const btVector3& linvel)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_interpolationLinearVelocity = linvel;
 		m_interpolationLinearVelocity = linvel;
 	}
 	}
 
 
-	void	setInterpolationAngularVelocity(const btVector3& angvel)
+	void setInterpolationAngularVelocity(const btVector3& angvel)
 	{
 	{
 		m_updateRevision++;
 		m_updateRevision++;
 		m_interpolationAngularVelocity = angvel;
 		m_interpolationAngularVelocity = angvel;
 	}
 	}
 
 
-	const btVector3&	getInterpolationLinearVelocity() const
+	const btVector3& getInterpolationLinearVelocity() const
 	{
 	{
 		return m_interpolationLinearVelocity;
 		return m_interpolationLinearVelocity;
 	}
 	}
 
 
-	const btVector3&	getInterpolationAngularVelocity() const
+	const btVector3& getInterpolationAngularVelocity() const
 	{
 	{
 		return m_interpolationAngularVelocity;
 		return m_interpolationAngularVelocity;
 	}
 	}
 
 
 	SIMD_FORCE_INLINE int getIslandTag() const
 	SIMD_FORCE_INLINE int getIslandTag() const
 	{
 	{
-		return	m_islandTag1;
+		return m_islandTag1;
 	}
 	}
 
 
-	void	setIslandTag(int tag)
+	void setIslandTag(int tag)
 	{
 	{
 		m_islandTag1 = tag;
 		m_islandTag1 = tag;
 	}
 	}
 
 
 	SIMD_FORCE_INLINE int getCompanionId() const
 	SIMD_FORCE_INLINE int getCompanionId() const
 	{
 	{
-		return	m_companionId;
+		return m_companionId;
 	}
 	}
 
 
-	void	setCompanionId(int id)
+	void setCompanionId(int id)
 	{
 	{
 		m_companionId = id;
 		m_companionId = id;
 	}
 	}
 
 
-    SIMD_FORCE_INLINE int getWorldArrayIndex() const
-    {
-        return	m_worldArrayIndex;
-    }
+	SIMD_FORCE_INLINE int getWorldArrayIndex() const
+	{
+		return m_worldArrayIndex;
+	}
 
 
-    // only should be called by CollisionWorld
-    void setWorldArrayIndex(int ix)
-    {
-        m_worldArrayIndex = ix;
-    }
+	// only should be called by CollisionWorld
+	void setWorldArrayIndex(int ix)
+	{
+		m_worldArrayIndex = ix;
+	}
 
 
-    SIMD_FORCE_INLINE btScalar			getHitFraction() const
+	SIMD_FORCE_INLINE btScalar getHitFraction() const
 	{
 	{
-		return m_hitFraction; 
+		return m_hitFraction;
 	}
 	}
 
 
-	void	setHitFraction(btScalar hitFraction)
+	void setHitFraction(btScalar hitFraction)
 	{
 	{
 		m_hitFraction = hitFraction;
 		m_hitFraction = hitFraction;
 	}
 	}
 
 
-	
-	SIMD_FORCE_INLINE int	getCollisionFlags() const
+	SIMD_FORCE_INLINE int getCollisionFlags() const
 	{
 	{
 		return m_collisionFlags;
 		return m_collisionFlags;
 	}
 	}
 
 
-	void	setCollisionFlags(int flags)
+	void setCollisionFlags(int flags)
 	{
 	{
 		m_collisionFlags = flags;
 		m_collisionFlags = flags;
 	}
 	}
-	
+
 	///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
 	///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
-	btScalar			getCcdSweptSphereRadius() const
+	btScalar getCcdSweptSphereRadius() const
 	{
 	{
 		return m_ccdSweptSphereRadius;
 		return m_ccdSweptSphereRadius;
 	}
 	}
 
 
 	///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
 	///Swept sphere radius (0.0 by default), see btConvexConvexAlgorithm::
-	void	setCcdSweptSphereRadius(btScalar radius)
+	void setCcdSweptSphereRadius(btScalar radius)
 	{
 	{
 		m_ccdSweptSphereRadius = radius;
 		m_ccdSweptSphereRadius = radius;
 	}
 	}
 
 
-	btScalar 	getCcdMotionThreshold() const
+	btScalar getCcdMotionThreshold() const
 	{
 	{
 		return m_ccdMotionThreshold;
 		return m_ccdMotionThreshold;
 	}
 	}
 
 
-	btScalar 	getCcdSquareMotionThreshold() const
+	btScalar getCcdSquareMotionThreshold() const
 	{
 	{
-		return m_ccdMotionThreshold*m_ccdMotionThreshold;
+		return m_ccdMotionThreshold * m_ccdMotionThreshold;
 	}
 	}
 
 
-
-
 	/// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
 	/// Don't do continuous collision detection if the motion (in one step) is less then m_ccdMotionThreshold
-	void	setCcdMotionThreshold(btScalar ccdMotionThreshold)
+	void setCcdMotionThreshold(btScalar ccdMotionThreshold)
 	{
 	{
 		m_ccdMotionThreshold = ccdMotionThreshold;
 		m_ccdMotionThreshold = ccdMotionThreshold;
 	}
 	}
 
 
 	///users can point to their objects, userPointer is not used by Bullet
 	///users can point to their objects, userPointer is not used by Bullet
-	void*	getUserPointer() const
+	void* getUserPointer() const
 	{
 	{
 		return m_userObjectPointer;
 		return m_userObjectPointer;
 	}
 	}
 
 
-	int	getUserIndex() const
+	int getUserIndex() const
 	{
 	{
 		return m_userIndex;
 		return m_userIndex;
 	}
 	}
-	
-	int	getUserIndex2() const
+
+	int getUserIndex2() const
 	{
 	{
 		return m_userIndex2;
 		return m_userIndex2;
 	}
 	}
-	
+
+	int getUserIndex3() const
+	{
+		return m_userIndex3;
+	}
+
 	///users can point to their objects, userPointer is not used by Bullet
 	///users can point to their objects, userPointer is not used by Bullet
-	void	setUserPointer(void* userPointer)
+	void setUserPointer(void* userPointer)
 	{
 	{
 		m_userObjectPointer = userPointer;
 		m_userObjectPointer = userPointer;
 	}
 	}
 
 
 	///users can point to their objects, userPointer is not used by Bullet
 	///users can point to their objects, userPointer is not used by Bullet
-	void	setUserIndex(int index)
+	void setUserIndex(int index)
 	{
 	{
 		m_userIndex = index;
 		m_userIndex = index;
 	}
 	}
-	
-	void	setUserIndex2(int index)
+
+	void setUserIndex2(int index)
 	{
 	{
 		m_userIndex2 = index;
 		m_userIndex2 = index;
 	}
 	}
 
 
-	int	getUpdateRevisionInternal() const
+	void setUserIndex3(int index)
+	{
+		m_userIndex3 = index;
+	}
+
+	int getUpdateRevisionInternal() const
 	{
 	{
 		return m_updateRevision;
 		return m_updateRevision;
 	}
 	}
 
 
-	void	setCustomDebugColor(const btVector3& colorRGB)
+	void setCustomDebugColor(const btVector3& colorRGB)
 	{
 	{
 		m_customDebugColorRGB = colorRGB;
 		m_customDebugColorRGB = colorRGB;
 		m_collisionFlags |= CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
 		m_collisionFlags |= CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
 	}
 	}
 
 
-	void	removeCustomDebugColor()
+	void removeCustomDebugColor()
 	{
 	{
 		m_collisionFlags &= ~CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
 		m_collisionFlags &= ~CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
 	}
 	}
 
 
-	bool getCustomDebugColor(btVector3& colorRGB) const
+	bool getCustomDebugColor(btVector3 & colorRGB) const
 	{
 	{
-		bool hasCustomColor = (0!=(m_collisionFlags&CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR));
+		bool hasCustomColor = (0 != (m_collisionFlags & CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR));
 		if (hasCustomColor)
 		if (hasCustomColor)
 		{
 		{
 			colorRGB = m_customDebugColorRGB;
 			colorRGB = m_customDebugColorRGB;
@@ -587,15 +599,16 @@ public:
 		return true;
 		return true;
 	}
 	}
 
 
-	virtual	int	calculateSerializeBufferSize()	const;
+	virtual int calculateSerializeBufferSize() const;
 
 
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
-	virtual	const char*	serialize(void* dataBuffer, class btSerializer* serializer) const;
-
-	virtual void serializeSingleObject(class btSerializer* serializer) const;
+	virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const;
 
 
+	virtual void serializeSingleObject(class btSerializer * serializer) const;
 };
 };
 
 
+// clang-format off
+
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 struct	btCollisionObjectDoubleData
 struct	btCollisionObjectDoubleData
 {
 {
@@ -619,7 +632,6 @@ struct	btCollisionObjectDoubleData
 	double					m_hitFraction; 
 	double					m_hitFraction; 
 	double					m_ccdSweptSphereRadius;
 	double					m_ccdSweptSphereRadius;
 	double					m_ccdMotionThreshold;
 	double					m_ccdMotionThreshold;
-
 	int						m_hasAnisotropicFriction;
 	int						m_hasAnisotropicFriction;
 	int						m_collisionFlags;
 	int						m_collisionFlags;
 	int						m_islandTag1;
 	int						m_islandTag1;
@@ -627,8 +639,9 @@ struct	btCollisionObjectDoubleData
 	int						m_activationState1;
 	int						m_activationState1;
 	int						m_internalType;
 	int						m_internalType;
 	int						m_checkCollideWith;
 	int						m_checkCollideWith;
-
-	char	m_padding[4];
+	int						m_collisionFilterGroup;
+	int						m_collisionFilterMask;
+	int						m_uniqueId;//m_uniqueId is introduced for paircache. could get rid of this, by calculating the address offset etc.
 };
 };
 
 
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
@@ -648,13 +661,12 @@ struct	btCollisionObjectFloatData
 	float					m_deactivationTime;
 	float					m_deactivationTime;
 	float					m_friction;
 	float					m_friction;
 	float					m_rollingFriction;
 	float					m_rollingFriction;
-    float                   m_contactDamping;
+	float                   m_contactDamping;
     float                   m_contactStiffness;
     float                   m_contactStiffness;
 	float					m_restitution;
 	float					m_restitution;
 	float					m_hitFraction; 
 	float					m_hitFraction; 
 	float					m_ccdSweptSphereRadius;
 	float					m_ccdSweptSphereRadius;
 	float					m_ccdMotionThreshold;
 	float					m_ccdMotionThreshold;
-
 	int						m_hasAnisotropicFriction;
 	int						m_hasAnisotropicFriction;
 	int						m_collisionFlags;
 	int						m_collisionFlags;
 	int						m_islandTag1;
 	int						m_islandTag1;
@@ -662,16 +674,15 @@ struct	btCollisionObjectFloatData
 	int						m_activationState1;
 	int						m_activationState1;
 	int						m_internalType;
 	int						m_internalType;
 	int						m_checkCollideWith;
 	int						m_checkCollideWith;
-	char					m_padding[4];
+	int						m_collisionFilterGroup;
+	int						m_collisionFilterMask;
+	int						m_uniqueId;
 };
 };
+// clang-format on
 
 
-
-
-SIMD_FORCE_INLINE	int	btCollisionObject::calculateSerializeBufferSize() const
+SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const
 {
 {
 	return sizeof(btCollisionObjectData);
 	return sizeof(btCollisionObjectData);
 }
 }
 
 
-
-
-#endif //BT_COLLISION_OBJECT_H
+#endif  //BT_COLLISION_OBJECT_H

+ 19 - 13
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h

@@ -1,25 +1,25 @@
 #ifndef BT_COLLISION_OBJECT_WRAPPER_H
 #ifndef BT_COLLISION_OBJECT_WRAPPER_H
 #define BT_COLLISION_OBJECT_WRAPPER_H
 #define BT_COLLISION_OBJECT_WRAPPER_H
 
 
-///btCollisionObjectWrapperis an internal data structure. 
+///btCollisionObjectWrapperis an internal data structure.
 ///Most users can ignore this and use btCollisionObject and btCollisionShape instead
 ///Most users can ignore this and use btCollisionObject and btCollisionShape instead
 class btCollisionShape;
 class btCollisionShape;
 class btCollisionObject;
 class btCollisionObject;
 class btTransform;
 class btTransform;
-#include "LinearMath/btScalar.h" // for SIMD_FORCE_INLINE definition
+#include "LinearMath/btScalar.h"  // for SIMD_FORCE_INLINE definition
 
 
 #define BT_DECLARE_STACK_ONLY_OBJECT \
 #define BT_DECLARE_STACK_ONLY_OBJECT \
-	private: \
-		void* operator new(size_t size); \
-		void operator delete(void*);
+private:                             \
+	void* operator new(size_t size); \
+	void operator delete(void*);
 
 
 struct btCollisionObjectWrapper;
 struct btCollisionObjectWrapper;
 struct btCollisionObjectWrapper
 struct btCollisionObjectWrapper
 {
 {
-BT_DECLARE_STACK_ONLY_OBJECT
+	BT_DECLARE_STACK_ONLY_OBJECT
 
 
 private:
 private:
-	btCollisionObjectWrapper(const btCollisionObjectWrapper&); // not implemented. Not allowed.
+	btCollisionObjectWrapper(const btCollisionObjectWrapper&);  // not implemented. Not allowed.
 	btCollisionObjectWrapper* operator=(const btCollisionObjectWrapper&);
 	btCollisionObjectWrapper* operator=(const btCollisionObjectWrapper&);
 
 
 public:
 public:
@@ -27,17 +27,23 @@ public:
 	const btCollisionShape* m_shape;
 	const btCollisionShape* m_shape;
 	const btCollisionObject* m_collisionObject;
 	const btCollisionObject* m_collisionObject;
 	const btTransform& m_worldTransform;
 	const btTransform& m_worldTransform;
-	int		m_partId;
-	int		m_index;
+    const btTransform* m_preTransform;
+	int m_partId;
+	int m_index;
 
 
 	btCollisionObjectWrapper(const btCollisionObjectWrapper* parent, const btCollisionShape* shape, const btCollisionObject* collisionObject, const btTransform& worldTransform, int partId, int index)
 	btCollisionObjectWrapper(const btCollisionObjectWrapper* parent, const btCollisionShape* shape, const btCollisionObject* collisionObject, const btTransform& worldTransform, int partId, int index)
-	: m_parent(parent), m_shape(shape), m_collisionObject(collisionObject), m_worldTransform(worldTransform),
-	m_partId(partId), m_index(index)
-	{}
+		: m_parent(parent), m_shape(shape), m_collisionObject(collisionObject), m_worldTransform(worldTransform), m_preTransform(NULL), m_partId(partId), m_index(index)
+	{
+	}
+    
+    btCollisionObjectWrapper(const btCollisionObjectWrapper* parent, const btCollisionShape* shape, const btCollisionObject* collisionObject, const btTransform& worldTransform, const btTransform& preTransform, int partId, int index)
+    : m_parent(parent), m_shape(shape), m_collisionObject(collisionObject), m_worldTransform(worldTransform), m_preTransform(&preTransform), m_partId(partId), m_index(index)
+    {
+    }
 
 
 	SIMD_FORCE_INLINE const btTransform& getWorldTransform() const { return m_worldTransform; }
 	SIMD_FORCE_INLINE const btTransform& getWorldTransform() const { return m_worldTransform; }
 	SIMD_FORCE_INLINE const btCollisionObject* getCollisionObject() const { return m_collisionObject; }
 	SIMD_FORCE_INLINE const btCollisionObject* getCollisionObject() const { return m_collisionObject; }
 	SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const { return m_shape; }
 	SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const { return m_shape; }
 };
 };
 
 
-#endif //BT_COLLISION_OBJECT_WRAPPER_H
+#endif  //BT_COLLISION_OBJECT_WRAPPER_H

File diff suppressed because it is too large
+ 315 - 316
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp


+ 165 - 180
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.h

@@ -13,7 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 /**
 /**
  * @mainpage Bullet Documentation
  * @mainpage Bullet Documentation
  *
  *
@@ -66,8 +65,6 @@ subject to the following restrictions:
  * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf
  * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf
  * 
  * 
  */
  */
- 
- 
 
 
 #ifndef BT_COLLISION_WORLD_H
 #ifndef BT_COLLISION_WORLD_H
 #define BT_COLLISION_WORLD_H
 #define BT_COLLISION_WORLD_H
@@ -87,144 +84,138 @@ class btSerializer;
 ///CollisionWorld is interface and container for the collision detection
 ///CollisionWorld is interface and container for the collision detection
 class btCollisionWorld
 class btCollisionWorld
 {
 {
-
-	
 protected:
 protected:
+	btAlignedObjectArray<btCollisionObject*> m_collisionObjects;
 
 
-	btAlignedObjectArray<btCollisionObject*>	m_collisionObjects;
-	
-	btDispatcher*	m_dispatcher1;
+	btDispatcher* m_dispatcher1;
 
 
-	btDispatcherInfo	m_dispatchInfo;
+	btDispatcherInfo m_dispatchInfo;
 
 
-	btBroadphaseInterface*	m_broadphasePairCache;
+	btBroadphaseInterface* m_broadphasePairCache;
 
 
-	btIDebugDraw*	m_debugDrawer;
+	btIDebugDraw* m_debugDrawer;
 
 
 	///m_forceUpdateAllAabbs can be set to false as an optimization to only update active object AABBs
 	///m_forceUpdateAllAabbs can be set to false as an optimization to only update active object AABBs
 	///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB)
 	///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB)
 	bool m_forceUpdateAllAabbs;
 	bool m_forceUpdateAllAabbs;
 
 
-	void	serializeCollisionObjects(btSerializer* serializer);
+	void serializeCollisionObjects(btSerializer* serializer);
 
 
-public:
+	void serializeContactManifolds(btSerializer* serializer);
 
 
+public:
 	//this constructor doesn't own the dispatcher and paircache/broadphase
 	//this constructor doesn't own the dispatcher and paircache/broadphase
-	btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* broadphasePairCache, btCollisionConfiguration* collisionConfiguration);
+	btCollisionWorld(btDispatcher* dispatcher, btBroadphaseInterface* broadphasePairCache, btCollisionConfiguration* collisionConfiguration);
 
 
 	virtual ~btCollisionWorld();
 	virtual ~btCollisionWorld();
 
 
-	void	setBroadphase(btBroadphaseInterface*	pairCache)
+	void setBroadphase(btBroadphaseInterface* pairCache)
 	{
 	{
 		m_broadphasePairCache = pairCache;
 		m_broadphasePairCache = pairCache;
 	}
 	}
 
 
-	const btBroadphaseInterface*	getBroadphase() const
+	const btBroadphaseInterface* getBroadphase() const
 	{
 	{
 		return m_broadphasePairCache;
 		return m_broadphasePairCache;
 	}
 	}
 
 
-	btBroadphaseInterface*	getBroadphase()
+	btBroadphaseInterface* getBroadphase()
 	{
 	{
 		return m_broadphasePairCache;
 		return m_broadphasePairCache;
 	}
 	}
 
 
-	btOverlappingPairCache*	getPairCache()
+	btOverlappingPairCache* getPairCache()
 	{
 	{
 		return m_broadphasePairCache->getOverlappingPairCache();
 		return m_broadphasePairCache->getOverlappingPairCache();
 	}
 	}
 
 
-
-	btDispatcher*	getDispatcher()
+	btDispatcher* getDispatcher()
 	{
 	{
 		return m_dispatcher1;
 		return m_dispatcher1;
 	}
 	}
 
 
-	const btDispatcher*	getDispatcher() const
+	const btDispatcher* getDispatcher() const
 	{
 	{
 		return m_dispatcher1;
 		return m_dispatcher1;
 	}
 	}
 
 
-	void	updateSingleAabb(btCollisionObject* colObj);
+	void updateSingleAabb(btCollisionObject* colObj);
 
 
-	virtual void	updateAabbs();
+	virtual void updateAabbs();
 
 
 	///the computeOverlappingPairs is usually already called by performDiscreteCollisionDetection (or stepSimulation)
 	///the computeOverlappingPairs is usually already called by performDiscreteCollisionDetection (or stepSimulation)
 	///it can be useful to use if you perform ray tests without collision detection/simulation
 	///it can be useful to use if you perform ray tests without collision detection/simulation
-	virtual void	computeOverlappingPairs();
+	virtual void computeOverlappingPairs();
 
 
-	
-	virtual void	setDebugDrawer(btIDebugDraw*	debugDrawer)
+	virtual void setDebugDrawer(btIDebugDraw* debugDrawer)
 	{
 	{
-			m_debugDrawer = debugDrawer;
+		m_debugDrawer = debugDrawer;
 	}
 	}
 
 
-	virtual btIDebugDraw*	getDebugDrawer()
+	virtual btIDebugDraw* getDebugDrawer()
 	{
 	{
 		return m_debugDrawer;
 		return m_debugDrawer;
 	}
 	}
 
 
-	virtual void	debugDrawWorld();
+	virtual void debugDrawWorld();
 
 
 	virtual void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
 	virtual void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color);
 
 
-
 	///LocalShapeInfo gives extra information for complex shapes
 	///LocalShapeInfo gives extra information for complex shapes
 	///Currently, only btTriangleMeshShape is available, so it just contains triangleIndex and subpart
 	///Currently, only btTriangleMeshShape is available, so it just contains triangleIndex and subpart
-	struct	LocalShapeInfo
+	struct LocalShapeInfo
 	{
 	{
-		int	m_shapePart;
-		int	m_triangleIndex;
-		
+		int m_shapePart;
+		int m_triangleIndex;
+
 		//const btCollisionShape*	m_shapeTemp;
 		//const btCollisionShape*	m_shapeTemp;
 		//const btTransform*	m_shapeLocalTransform;
 		//const btTransform*	m_shapeLocalTransform;
 	};
 	};
 
 
-	struct	LocalRayResult
+	struct LocalRayResult
 	{
 	{
-		LocalRayResult(const btCollisionObject*	collisionObject, 
-			LocalShapeInfo*	localShapeInfo,
-			const btVector3&		hitNormalLocal,
-			btScalar hitFraction)
-		:m_collisionObject(collisionObject),
-		m_localShapeInfo(localShapeInfo),
-		m_hitNormalLocal(hitNormalLocal),
-		m_hitFraction(hitFraction)
+		LocalRayResult(const btCollisionObject* collisionObject,
+					   LocalShapeInfo* localShapeInfo,
+					   const btVector3& hitNormalLocal,
+					   btScalar hitFraction)
+			: m_collisionObject(collisionObject),
+			  m_localShapeInfo(localShapeInfo),
+			  m_hitNormalLocal(hitNormalLocal),
+			  m_hitFraction(hitFraction)
 		{
 		{
 		}
 		}
 
 
-		const btCollisionObject*		m_collisionObject;
-		LocalShapeInfo*			m_localShapeInfo;
-		btVector3				m_hitNormalLocal;
-		btScalar				m_hitFraction;
-
+		const btCollisionObject* m_collisionObject;
+		LocalShapeInfo* m_localShapeInfo;
+		btVector3 m_hitNormalLocal;
+		btScalar m_hitFraction;
 	};
 	};
 
 
 	///RayResultCallback is used to report new raycast results
 	///RayResultCallback is used to report new raycast results
-	struct	RayResultCallback
+	struct RayResultCallback
 	{
 	{
-		btScalar	m_closestHitFraction;
-		const btCollisionObject*		m_collisionObject;
-		int	m_collisionFilterGroup;
-		int	m_collisionFilterMask;
+		btScalar m_closestHitFraction;
+		const btCollisionObject* m_collisionObject;
+		int m_collisionFilterGroup;
+		int m_collisionFilterMask;
 		//@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback.h. Apply any of the EFlags defined there on m_flags here to invoke.
 		//@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback.h. Apply any of the EFlags defined there on m_flags here to invoke.
 		unsigned int m_flags;
 		unsigned int m_flags;
 
 
 		virtual ~RayResultCallback()
 		virtual ~RayResultCallback()
 		{
 		{
 		}
 		}
-		bool	hasHit() const
+		bool hasHit() const
 		{
 		{
 			return (m_collisionObject != 0);
 			return (m_collisionObject != 0);
 		}
 		}
 
 
 		RayResultCallback()
 		RayResultCallback()
-			:m_closestHitFraction(btScalar(1.)),
-			m_collisionObject(0),
-			m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
-			m_collisionFilterMask(btBroadphaseProxy::AllFilter),
-			//@BP Mod
-			m_flags(0)
+			: m_closestHitFraction(btScalar(1.)),
+			  m_collisionObject(0),
+			  m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
+			  m_collisionFilterMask(btBroadphaseProxy::AllFilter),
+			  //@BP Mod
+			  m_flags(0)
 		{
 		{
 		}
 		}
 
 
@@ -235,62 +226,62 @@ public:
 			return collides;
 			return collides;
 		}
 		}
 
 
-
-		virtual	btScalar	addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) = 0;
+		virtual btScalar addSingleResult(LocalRayResult& rayResult, bool normalInWorldSpace) = 0;
 	};
 	};
 
 
-	struct	ClosestRayResultCallback : public RayResultCallback
+	struct ClosestRayResultCallback : public RayResultCallback
 	{
 	{
-		ClosestRayResultCallback(const btVector3&	rayFromWorld,const btVector3&	rayToWorld)
-		:m_rayFromWorld(rayFromWorld),
-		m_rayToWorld(rayToWorld)
+		ClosestRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld)
+			: m_rayFromWorld(rayFromWorld),
+			  m_rayToWorld(rayToWorld)
 		{
 		{
 		}
 		}
 
 
-		btVector3	m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
-		btVector3	m_rayToWorld;
+		btVector3 m_rayFromWorld;  //used to calculate hitPointWorld from hitFraction
+		btVector3 m_rayToWorld;
+
+		btVector3 m_hitNormalWorld;
+		btVector3 m_hitPointWorld;
 
 
-		btVector3	m_hitNormalWorld;
-		btVector3	m_hitPointWorld;
-			
-		virtual	btScalar	addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace)
+		virtual btScalar addSingleResult(LocalRayResult& rayResult, bool normalInWorldSpace)
 		{
 		{
 			//caller already does the filter on the m_closestHitFraction
 			//caller already does the filter on the m_closestHitFraction
 			btAssert(rayResult.m_hitFraction <= m_closestHitFraction);
 			btAssert(rayResult.m_hitFraction <= m_closestHitFraction);
-			
+
 			m_closestHitFraction = rayResult.m_hitFraction;
 			m_closestHitFraction = rayResult.m_hitFraction;
 			m_collisionObject = rayResult.m_collisionObject;
 			m_collisionObject = rayResult.m_collisionObject;
 			if (normalInWorldSpace)
 			if (normalInWorldSpace)
 			{
 			{
 				m_hitNormalWorld = rayResult.m_hitNormalLocal;
 				m_hitNormalWorld = rayResult.m_hitNormalLocal;
-			} else
+			}
+			else
 			{
 			{
 				///need to transform normal into worldspace
 				///need to transform normal into worldspace
-				m_hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;
+				m_hitNormalWorld = m_collisionObject->getWorldTransform().getBasis() * rayResult.m_hitNormalLocal;
 			}
 			}
-			m_hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);
+			m_hitPointWorld.setInterpolate3(m_rayFromWorld, m_rayToWorld, rayResult.m_hitFraction);
 			return rayResult.m_hitFraction;
 			return rayResult.m_hitFraction;
 		}
 		}
 	};
 	};
 
 
-	struct	AllHitsRayResultCallback : public RayResultCallback
+	struct AllHitsRayResultCallback : public RayResultCallback
 	{
 	{
-		AllHitsRayResultCallback(const btVector3&	rayFromWorld,const btVector3&	rayToWorld)
-		:m_rayFromWorld(rayFromWorld),
-		m_rayToWorld(rayToWorld)
+		AllHitsRayResultCallback(const btVector3& rayFromWorld, const btVector3& rayToWorld)
+			: m_rayFromWorld(rayFromWorld),
+			  m_rayToWorld(rayToWorld)
 		{
 		{
 		}
 		}
 
 
-		btAlignedObjectArray<const btCollisionObject*>		m_collisionObjects;
+		btAlignedObjectArray<const btCollisionObject*> m_collisionObjects;
 
 
-		btVector3	m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
-		btVector3	m_rayToWorld;
+		btVector3 m_rayFromWorld;  //used to calculate hitPointWorld from hitFraction
+		btVector3 m_rayToWorld;
 
 
-		btAlignedObjectArray<btVector3>	m_hitNormalWorld;
-		btAlignedObjectArray<btVector3>	m_hitPointWorld;
+		btAlignedObjectArray<btVector3> m_hitNormalWorld;
+		btAlignedObjectArray<btVector3> m_hitPointWorld;
 		btAlignedObjectArray<btScalar> m_hitFractions;
 		btAlignedObjectArray<btScalar> m_hitFractions;
-			
-		virtual	btScalar	addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace)
+
+		virtual btScalar addSingleResult(LocalRayResult& rayResult, bool normalInWorldSpace)
 		{
 		{
 			m_collisionObject = rayResult.m_collisionObject;
 			m_collisionObject = rayResult.m_collisionObject;
 			m_collisionObjects.push_back(rayResult.m_collisionObject);
 			m_collisionObjects.push_back(rayResult.m_collisionObject);
@@ -298,69 +289,66 @@ public:
 			if (normalInWorldSpace)
 			if (normalInWorldSpace)
 			{
 			{
 				hitNormalWorld = rayResult.m_hitNormalLocal;
 				hitNormalWorld = rayResult.m_hitNormalLocal;
-			} else
+			}
+			else
 			{
 			{
 				///need to transform normal into worldspace
 				///need to transform normal into worldspace
-				hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;
+				hitNormalWorld = m_collisionObject->getWorldTransform().getBasis() * rayResult.m_hitNormalLocal;
 			}
 			}
 			m_hitNormalWorld.push_back(hitNormalWorld);
 			m_hitNormalWorld.push_back(hitNormalWorld);
 			btVector3 hitPointWorld;
 			btVector3 hitPointWorld;
-			hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);
+			hitPointWorld.setInterpolate3(m_rayFromWorld, m_rayToWorld, rayResult.m_hitFraction);
 			m_hitPointWorld.push_back(hitPointWorld);
 			m_hitPointWorld.push_back(hitPointWorld);
 			m_hitFractions.push_back(rayResult.m_hitFraction);
 			m_hitFractions.push_back(rayResult.m_hitFraction);
 			return m_closestHitFraction;
 			return m_closestHitFraction;
 		}
 		}
 	};
 	};
 
 
-
 	struct LocalConvexResult
 	struct LocalConvexResult
 	{
 	{
-		LocalConvexResult(const btCollisionObject*	hitCollisionObject, 
-			LocalShapeInfo*	localShapeInfo,
-			const btVector3&		hitNormalLocal,
-			const btVector3&		hitPointLocal,
-			btScalar hitFraction
-			)
-		:m_hitCollisionObject(hitCollisionObject),
-		m_localShapeInfo(localShapeInfo),
-		m_hitNormalLocal(hitNormalLocal),
-		m_hitPointLocal(hitPointLocal),
-		m_hitFraction(hitFraction)
+		LocalConvexResult(const btCollisionObject* hitCollisionObject,
+						  LocalShapeInfo* localShapeInfo,
+						  const btVector3& hitNormalLocal,
+						  const btVector3& hitPointLocal,
+						  btScalar hitFraction)
+			: m_hitCollisionObject(hitCollisionObject),
+			  m_localShapeInfo(localShapeInfo),
+			  m_hitNormalLocal(hitNormalLocal),
+			  m_hitPointLocal(hitPointLocal),
+			  m_hitFraction(hitFraction)
 		{
 		{
 		}
 		}
 
 
-		const btCollisionObject*		m_hitCollisionObject;
-		LocalShapeInfo*			m_localShapeInfo;
-		btVector3				m_hitNormalLocal;
-		btVector3				m_hitPointLocal;
-		btScalar				m_hitFraction;
+		const btCollisionObject* m_hitCollisionObject;
+		LocalShapeInfo* m_localShapeInfo;
+		btVector3 m_hitNormalLocal;
+		btVector3 m_hitPointLocal;
+		btScalar m_hitFraction;
 	};
 	};
 
 
 	///RayResultCallback is used to report new raycast results
 	///RayResultCallback is used to report new raycast results
-	struct	ConvexResultCallback
+	struct ConvexResultCallback
 	{
 	{
-		btScalar	m_closestHitFraction;
-		int	m_collisionFilterGroup;
-		int	m_collisionFilterMask;
-		
+		btScalar m_closestHitFraction;
+		int m_collisionFilterGroup;
+		int m_collisionFilterMask;
+
 		ConvexResultCallback()
 		ConvexResultCallback()
-			:m_closestHitFraction(btScalar(1.)),
-			m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
-			m_collisionFilterMask(btBroadphaseProxy::AllFilter)
+			: m_closestHitFraction(btScalar(1.)),
+			  m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
+			  m_collisionFilterMask(btBroadphaseProxy::AllFilter)
 		{
 		{
 		}
 		}
 
 
 		virtual ~ConvexResultCallback()
 		virtual ~ConvexResultCallback()
 		{
 		{
 		}
 		}
-		
-		bool	hasHit() const
+
+		bool hasHit() const
 		{
 		{
 			return (m_closestHitFraction < btScalar(1.));
 			return (m_closestHitFraction < btScalar(1.));
 		}
 		}
 
 
-		
-
 		virtual bool needsCollision(btBroadphaseProxy* proxy0) const
 		virtual bool needsCollision(btBroadphaseProxy* proxy0) const
 		{
 		{
 			bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
 			bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
@@ -368,39 +356,40 @@ public:
 			return collides;
 			return collides;
 		}
 		}
 
 
-		virtual	btScalar	addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace) = 0;
+		virtual btScalar addSingleResult(LocalConvexResult& convexResult, bool normalInWorldSpace) = 0;
 	};
 	};
 
 
-	struct	ClosestConvexResultCallback : public ConvexResultCallback
+	struct ClosestConvexResultCallback : public ConvexResultCallback
 	{
 	{
-		ClosestConvexResultCallback(const btVector3&	convexFromWorld,const btVector3&	convexToWorld)
-		:m_convexFromWorld(convexFromWorld),
-		m_convexToWorld(convexToWorld),
-		m_hitCollisionObject(0)
+		ClosestConvexResultCallback(const btVector3& convexFromWorld, const btVector3& convexToWorld)
+			: m_convexFromWorld(convexFromWorld),
+			  m_convexToWorld(convexToWorld),
+			  m_hitCollisionObject(0)
 		{
 		{
 		}
 		}
 
 
-		btVector3	m_convexFromWorld;//used to calculate hitPointWorld from hitFraction
-		btVector3	m_convexToWorld;
+		btVector3 m_convexFromWorld;  //used to calculate hitPointWorld from hitFraction
+		btVector3 m_convexToWorld;
 
 
-		btVector3	m_hitNormalWorld;
-		btVector3	m_hitPointWorld;
-		const btCollisionObject*	m_hitCollisionObject;
-		
-		virtual	btScalar	addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace)
+		btVector3 m_hitNormalWorld;
+		btVector3 m_hitPointWorld;
+		const btCollisionObject* m_hitCollisionObject;
+
+		virtual btScalar addSingleResult(LocalConvexResult& convexResult, bool normalInWorldSpace)
 		{
 		{
-//caller already does the filter on the m_closestHitFraction
+			//caller already does the filter on the m_closestHitFraction
 			btAssert(convexResult.m_hitFraction <= m_closestHitFraction);
 			btAssert(convexResult.m_hitFraction <= m_closestHitFraction);
-						
+
 			m_closestHitFraction = convexResult.m_hitFraction;
 			m_closestHitFraction = convexResult.m_hitFraction;
 			m_hitCollisionObject = convexResult.m_hitCollisionObject;
 			m_hitCollisionObject = convexResult.m_hitCollisionObject;
 			if (normalInWorldSpace)
 			if (normalInWorldSpace)
 			{
 			{
 				m_hitNormalWorld = convexResult.m_hitNormalLocal;
 				m_hitNormalWorld = convexResult.m_hitNormalLocal;
-			} else
+			}
+			else
 			{
 			{
 				///need to transform normal into worldspace
 				///need to transform normal into worldspace
-				m_hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal;
+				m_hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis() * convexResult.m_hitNormalLocal;
 			}
 			}
 			m_hitPointWorld = convexResult.m_hitPointLocal;
 			m_hitPointWorld = convexResult.m_hitPointLocal;
 			return convexResult.m_hitFraction;
 			return convexResult.m_hitFraction;
@@ -408,23 +397,23 @@ public:
 	};
 	};
 
 
 	///ContactResultCallback is used to report contact points
 	///ContactResultCallback is used to report contact points
-	struct	ContactResultCallback
+	struct ContactResultCallback
 	{
 	{
-		int	m_collisionFilterGroup;
-		int	m_collisionFilterMask;
-		btScalar	m_closestDistanceThreshold;
+		int m_collisionFilterGroup;
+		int m_collisionFilterMask;
+		btScalar m_closestDistanceThreshold;
 
 
 		ContactResultCallback()
 		ContactResultCallback()
-			:m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
-			m_collisionFilterMask(btBroadphaseProxy::AllFilter),
-			m_closestDistanceThreshold(0)
+			: m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
+			  m_collisionFilterMask(btBroadphaseProxy::AllFilter),
+			  m_closestDistanceThreshold(0)
 		{
 		{
 		}
 		}
 
 
 		virtual ~ContactResultCallback()
 		virtual ~ContactResultCallback()
 		{
 		{
 		}
 		}
-		
+
 		virtual bool needsCollision(btBroadphaseProxy* proxy0) const
 		virtual bool needsCollision(btBroadphaseProxy* proxy0) const
 		{
 		{
 			bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
 			bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
@@ -432,58 +421,57 @@ public:
 			return collides;
 			return collides;
 		}
 		}
 
 
-		virtual	btScalar	addSingleResult(btManifoldPoint& cp,	const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1) = 0;
+		virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper* colObj1Wrap, int partId1, int index1) = 0;
 	};
 	};
 
 
-
-
-	int	getNumCollisionObjects() const
+	int getNumCollisionObjects() const
 	{
 	{
 		return int(m_collisionObjects.size());
 		return int(m_collisionObjects.size());
 	}
 	}
 
 
 	/// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback
 	/// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback
 	/// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
 	/// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback.
-	virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const; 
+	virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;
 
 
 	/// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback
 	/// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback
 	/// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
 	/// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
-	void    convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback,  btScalar allowedCcdPenetration = btScalar(0.)) const;
+	void convexSweepTest(const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = btScalar(0.)) const;
 
 
 	///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback.
 	///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback.
 	///it reports one or more contact points for every overlapping object (including the one with deepest penetration)
 	///it reports one or more contact points for every overlapping object (including the one with deepest penetration)
-	void	contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback);
+	void contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback);
 
 
 	///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected.
 	///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected.
 	///it reports one or more contact points (including the one with deepest penetration)
 	///it reports one or more contact points (including the one with deepest penetration)
-	void	contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback);
-
+	void contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback);
 
 
 	/// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
 	/// rayTestSingle performs a raycast call and calls the resultCallback. It is used internally by rayTest.
 	/// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.
 	/// In a future implementation, we consider moving the ray test as a virtual method in btCollisionShape.
 	/// This allows more customization.
 	/// This allows more customization.
-	static void	rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
-					  btCollisionObject* collisionObject,
-					  const btCollisionShape* collisionShape,
-					  const btTransform& colObjWorldTransform,
-					  RayResultCallback& resultCallback);
+	static void rayTestSingle(const btTransform& rayFromTrans, const btTransform& rayToTrans,
+							  btCollisionObject* collisionObject,
+							  const btCollisionShape* collisionShape,
+							  const btTransform& colObjWorldTransform,
+							  RayResultCallback& resultCallback);
 
 
-	static void	rayTestSingleInternal(const btTransform& rayFromTrans,const btTransform& rayToTrans,
-					  const btCollisionObjectWrapper* collisionObjectWrap,
-					  RayResultCallback& resultCallback);
+	static void rayTestSingleInternal(const btTransform& rayFromTrans, const btTransform& rayToTrans,
+									  const btCollisionObjectWrapper* collisionObjectWrap,
+									  RayResultCallback& resultCallback);
 
 
 	/// objectQuerySingle performs a collision detection query and calls the resultCallback. It is used internally by rayTest.
 	/// objectQuerySingle performs a collision detection query and calls the resultCallback. It is used internally by rayTest.
-	static void	objectQuerySingle(const btConvexShape* castShape, const btTransform& rayFromTrans,const btTransform& rayToTrans,
-					  btCollisionObject* collisionObject,
-					  const btCollisionShape* collisionShape,
-					  const btTransform& colObjWorldTransform,
-					  ConvexResultCallback& resultCallback, btScalar	allowedPenetration);
+	static void objectQuerySingle(const btConvexShape* castShape, const btTransform& rayFromTrans, const btTransform& rayToTrans,
+								  btCollisionObject* collisionObject,
+								  const btCollisionShape* collisionShape,
+								  const btTransform& colObjWorldTransform,
+								  ConvexResultCallback& resultCallback, btScalar allowedPenetration);
 
 
-	static void	objectQuerySingleInternal(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
-											const btCollisionObjectWrapper* colObjWrap,
-											ConvexResultCallback& resultCallback, btScalar allowedPenetration);
+	static void objectQuerySingleInternal(const btConvexShape* castShape, const btTransform& convexFromTrans, const btTransform& convexToTrans,
+										  const btCollisionObjectWrapper* colObjWrap,
+										  ConvexResultCallback& resultCallback, btScalar allowedPenetration);
 
 
-	virtual void	addCollisionObject(btCollisionObject* collisionObject, int collisionFilterGroup=btBroadphaseProxy::DefaultFilter, int collisionFilterMask=btBroadphaseProxy::AllFilter);
+	virtual void addCollisionObject(btCollisionObject* collisionObject, int collisionFilterGroup = btBroadphaseProxy::DefaultFilter, int collisionFilterMask = btBroadphaseProxy::AllFilter);
+
+	virtual void refreshBroadphaseProxy(btCollisionObject* collisionObject);
 
 
 	btCollisionObjectArray& getCollisionObjectArray()
 	btCollisionObjectArray& getCollisionObjectArray()
 	{
 	{
@@ -495,10 +483,9 @@ public:
 		return m_collisionObjects;
 		return m_collisionObjects;
 	}
 	}
 
 
+	virtual void removeCollisionObject(btCollisionObject* collisionObject);
 
 
-	virtual void	removeCollisionObject(btCollisionObject* collisionObject);
-
-	virtual void	performDiscreteCollisionDetection();
+	virtual void performDiscreteCollisionDetection();
 
 
 	btDispatcherInfo& getDispatchInfo()
 	btDispatcherInfo& getDispatchInfo()
 	{
 	{
@@ -509,20 +496,18 @@ public:
 	{
 	{
 		return m_dispatchInfo;
 		return m_dispatchInfo;
 	}
 	}
-	
-	bool	getForceUpdateAllAabbs() const
+
+	bool getForceUpdateAllAabbs() const
 	{
 	{
 		return m_forceUpdateAllAabbs;
 		return m_forceUpdateAllAabbs;
 	}
 	}
-	void setForceUpdateAllAabbs( bool forceUpdateAllAabbs)
+	void setForceUpdateAllAabbs(bool forceUpdateAllAabbs)
 	{
 	{
 		m_forceUpdateAllAabbs = forceUpdateAllAabbs;
 		m_forceUpdateAllAabbs = forceUpdateAllAabbs;
 	}
 	}
 
 
 	///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo)
 	///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo)
-	virtual	void	serialize(btSerializer* serializer);
-
+	virtual void serialize(btSerializer* serializer);
 };
 };
 
 
-
-#endif //BT_COLLISION_WORLD_H
+#endif  //BT_COLLISION_WORLD_H

File diff suppressed because it is too large
+ 312 - 354
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp


+ 39 - 60
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.h

@@ -13,7 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #ifndef BT_COLLISION_WORLD_IMPORTER_H
 #ifndef BT_COLLISION_WORLD_IMPORTER_H
 #define BT_COLLISION_WORLD_IMPORTER_H
 #define BT_COLLISION_WORLD_IMPORTER_H
 
 
@@ -26,7 +25,6 @@ class btCollisionShape;
 class btCollisionObject;
 class btCollisionObject;
 struct btBulletSerializedArrays;
 struct btBulletSerializedArrays;
 
 
-
 struct ConstraintInput;
 struct ConstraintInput;
 class btCollisionWorld;
 class btCollisionWorld;
 struct btCollisionShapeData;
 struct btCollisionShapeData;
@@ -46,9 +44,6 @@ class btSliderConstraint;
 class btGearConstraint;
 class btGearConstraint;
 struct btContactSolverInfo;
 struct btContactSolverInfo;
 
 
-
-
-
 class btCollisionWorldImporter
 class btCollisionWorldImporter
 {
 {
 protected:
 protected:
@@ -56,60 +51,53 @@ protected:
 
 
 	int m_verboseMode;
 	int m_verboseMode;
 
 
-	btAlignedObjectArray<btCollisionShape*>  m_allocatedCollisionShapes;
+	btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
 	btAlignedObjectArray<btCollisionObject*> m_allocatedRigidBodies;
 	btAlignedObjectArray<btCollisionObject*> m_allocatedRigidBodies;
 
 
-	btAlignedObjectArray<btOptimizedBvh*>	 m_allocatedBvhs;
+	btAlignedObjectArray<btOptimizedBvh*> m_allocatedBvhs;
 	btAlignedObjectArray<btTriangleInfoMap*> m_allocatedTriangleInfoMaps;
 	btAlignedObjectArray<btTriangleInfoMap*> m_allocatedTriangleInfoMaps;
 	btAlignedObjectArray<btTriangleIndexVertexArray*> m_allocatedTriangleIndexArrays;
 	btAlignedObjectArray<btTriangleIndexVertexArray*> m_allocatedTriangleIndexArrays;
 	btAlignedObjectArray<btStridingMeshInterfaceData*> m_allocatedbtStridingMeshInterfaceDatas;
 	btAlignedObjectArray<btStridingMeshInterfaceData*> m_allocatedbtStridingMeshInterfaceDatas;
 	btAlignedObjectArray<btCollisionObject*> m_allocatedCollisionObjects;
 	btAlignedObjectArray<btCollisionObject*> m_allocatedCollisionObjects;
 
 
+	btAlignedObjectArray<char*> m_allocatedNames;
 
 
-	btAlignedObjectArray<char*>				m_allocatedNames;
+	btAlignedObjectArray<int*> m_indexArrays;
+	btAlignedObjectArray<short int*> m_shortIndexArrays;
+	btAlignedObjectArray<unsigned char*> m_charIndexArrays;
 
 
-	btAlignedObjectArray<int*>				m_indexArrays;
-	btAlignedObjectArray<short int*>		m_shortIndexArrays;
-	btAlignedObjectArray<unsigned char*>	m_charIndexArrays;
+	btAlignedObjectArray<btVector3FloatData*> m_floatVertexArrays;
+	btAlignedObjectArray<btVector3DoubleData*> m_doubleVertexArrays;
 
 
-	btAlignedObjectArray<btVector3FloatData*>	m_floatVertexArrays;
-	btAlignedObjectArray<btVector3DoubleData*>	m_doubleVertexArrays;
+	btHashMap<btHashPtr, btOptimizedBvh*> m_bvhMap;
+	btHashMap<btHashPtr, btTriangleInfoMap*> m_timMap;
 
 
+	btHashMap<btHashString, btCollisionShape*> m_nameShapeMap;
+	btHashMap<btHashString, btCollisionObject*> m_nameColObjMap;
 
 
-	btHashMap<btHashPtr,btOptimizedBvh*>	m_bvhMap;
-	btHashMap<btHashPtr,btTriangleInfoMap*>	m_timMap;
-
-	btHashMap<btHashString,btCollisionShape*>	m_nameShapeMap;
-	btHashMap<btHashString,btCollisionObject*>	m_nameColObjMap;
-
-	btHashMap<btHashPtr,const char*>	m_objectNameMap;
-
-	btHashMap<btHashPtr,btCollisionShape*>	m_shapeMap;
-	btHashMap<btHashPtr,btCollisionObject*>	m_bodyMap;
+	btHashMap<btHashPtr, const char*> m_objectNameMap;
 
 
+	btHashMap<btHashPtr, btCollisionShape*> m_shapeMap;
+	btHashMap<btHashPtr, btCollisionObject*> m_bodyMap;
 
 
 	//methods
 	//methods
 
 
+	char* duplicateName(const char* name);
 
 
-
-	char*	duplicateName(const char* name);
-
-	btCollisionShape* convertCollisionShape(  btCollisionShapeData* shapeData  );
-
+	btCollisionShape* convertCollisionShape(btCollisionShapeData* shapeData);
 
 
 public:
 public:
-
 	btCollisionWorldImporter(btCollisionWorld* world);
 	btCollisionWorldImporter(btCollisionWorld* world);
 
 
 	virtual ~btCollisionWorldImporter();
 	virtual ~btCollisionWorldImporter();
 
 
-    bool	convertAllObjects( btBulletSerializedArrays* arrays);
+	bool convertAllObjects(btBulletSerializedArrays* arrays);
 
 
-		///delete all memory collision shapes, rigid bodies, constraints etc. allocated during the load.
+	///delete all memory collision shapes, rigid bodies, constraints etc. allocated during the load.
 	///make sure you don't use the dynamics world containing objects after you call this method
 	///make sure you don't use the dynamics world containing objects after you call this method
 	virtual void deleteAllData();
 	virtual void deleteAllData();
 
 
-	void	setVerboseMode(int verboseMode)
+	void setVerboseMode(int verboseMode)
 	{
 	{
 		m_verboseMode = verboseMode;
 		m_verboseMode = verboseMode;
 	}
 	}
@@ -119,15 +107,14 @@ public:
 		return m_verboseMode;
 		return m_verboseMode;
 	}
 	}
 
 
-		// query for data
-	int	getNumCollisionShapes() const;
+	// query for data
+	int getNumCollisionShapes() const;
 	btCollisionShape* getCollisionShapeByIndex(int index);
 	btCollisionShape* getCollisionShapeByIndex(int index);
 	int getNumRigidBodies() const;
 	int getNumRigidBodies() const;
 	btCollisionObject* getRigidBodyByIndex(int index) const;
 	btCollisionObject* getRigidBodyByIndex(int index) const;
-	int getNumConstraints() const;
 
 
 	int getNumBvhs() const;
 	int getNumBvhs() const;
-	btOptimizedBvh*  getBvhByIndex(int index) const;
+	btOptimizedBvh* getBvhByIndex(int index) const;
 	int getNumTriangleInfoMaps() const;
 	int getNumTriangleInfoMaps() const;
 	btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const;
 	btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const;
 
 
@@ -135,56 +122,48 @@ public:
 	btCollisionShape* getCollisionShapeByName(const char* name);
 	btCollisionShape* getCollisionShapeByName(const char* name);
 	btCollisionObject* getCollisionObjectByName(const char* name);
 	btCollisionObject* getCollisionObjectByName(const char* name);
 
 
-
-	const char*	getNameForPointer(const void* ptr) const;
+	const char* getNameForPointer(const void* ptr) const;
 
 
 	///those virtuals are called by load and can be overridden by the user
 	///those virtuals are called by load and can be overridden by the user
 
 
-
-
 	//bodies
 	//bodies
 
 
-	virtual btCollisionObject*  createCollisionObject(	const btTransform& startTransform,	btCollisionShape* shape,const char* bodyName);
+	virtual btCollisionObject* createCollisionObject(const btTransform& startTransform, btCollisionShape* shape, const char* bodyName);
 
 
 	///shapes
 	///shapes
 
 
-	virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
+	virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal, btScalar planeConstant);
 	virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
 	virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
 	virtual btCollisionShape* createSphereShape(btScalar radius);
 	virtual btCollisionShape* createSphereShape(btScalar radius);
 	virtual btCollisionShape* createCapsuleShapeX(btScalar radius, btScalar height);
 	virtual btCollisionShape* createCapsuleShapeX(btScalar radius, btScalar height);
 	virtual btCollisionShape* createCapsuleShapeY(btScalar radius, btScalar height);
 	virtual btCollisionShape* createCapsuleShapeY(btScalar radius, btScalar height);
 	virtual btCollisionShape* createCapsuleShapeZ(btScalar radius, btScalar height);
 	virtual btCollisionShape* createCapsuleShapeZ(btScalar radius, btScalar height);
 
 
-	virtual btCollisionShape* createCylinderShapeX(btScalar radius,btScalar height);
-	virtual btCollisionShape* createCylinderShapeY(btScalar radius,btScalar height);
-	virtual btCollisionShape* createCylinderShapeZ(btScalar radius,btScalar height);
-	virtual btCollisionShape* createConeShapeX(btScalar radius,btScalar height);
-	virtual btCollisionShape* createConeShapeY(btScalar radius,btScalar height);
-	virtual btCollisionShape* createConeShapeZ(btScalar radius,btScalar height);
-	virtual class btTriangleIndexVertexArray*	createTriangleMeshContainer();
-	virtual	btBvhTriangleMeshShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh);
+	virtual btCollisionShape* createCylinderShapeX(btScalar radius, btScalar height);
+	virtual btCollisionShape* createCylinderShapeY(btScalar radius, btScalar height);
+	virtual btCollisionShape* createCylinderShapeZ(btScalar radius, btScalar height);
+	virtual btCollisionShape* createConeShapeX(btScalar radius, btScalar height);
+	virtual btCollisionShape* createConeShapeY(btScalar radius, btScalar height);
+	virtual btCollisionShape* createConeShapeZ(btScalar radius, btScalar height);
+	virtual class btTriangleIndexVertexArray* createTriangleMeshContainer();
+	virtual btBvhTriangleMeshShape* createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh);
 	virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh);
 	virtual btCollisionShape* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh);
 #ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
 #ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
 	virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh);
 	virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh);
-#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
+#endif  //SUPPORT_GIMPACT_SHAPE_IMPORT
 	virtual btStridingMeshInterfaceData* createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData);
 	virtual btStridingMeshInterfaceData* createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData);
 
 
 	virtual class btConvexHullShape* createConvexHullShape();
 	virtual class btConvexHullShape* createConvexHullShape();
 	virtual class btCompoundShape* createCompoundShape();
 	virtual class btCompoundShape* createCompoundShape();
-	virtual class btScaledBvhTriangleMeshShape* createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScalingbtBvhTriangleMeshShape);
+	virtual class btScaledBvhTriangleMeshShape* createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape, const btVector3& localScalingbtBvhTriangleMeshShape);
 
 
-	virtual class btMultiSphereShape* createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres);
+	virtual class btMultiSphereShape* createMultiSphereShape(const btVector3* positions, const btScalar* radi, int numSpheres);
 
 
 	virtual btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
 	virtual btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
 
 
 	///acceleration and connectivity structures
 	///acceleration and connectivity structures
-	virtual btOptimizedBvh*	createOptimizedBvh();
+	virtual btOptimizedBvh* createOptimizedBvh();
 	virtual btTriangleInfoMap* createTriangleInfoMap();
 	virtual btTriangleInfoMap* createTriangleInfoMap();
-
-
-
-
 };
 };
 
 
-
-#endif //BT_WORLD_IMPORTER_H
+#endif  //BT_WORLD_IMPORTER_H

+ 119 - 131
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

@@ -27,62 +27,58 @@ subject to the following restrictions:
 
 
 btShapePairCallback gCompoundChildShapePairCallback = 0;
 btShapePairCallback gCompoundChildShapePairCallback = 0;
 
 
-btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
-:btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_isSwapped(isSwapped),
-m_sharedManifold(ci.m_manifold)
+btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped)
+	: btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
+	  m_isSwapped(isSwapped),
+	  m_sharedManifold(ci.m_manifold)
 {
 {
 	m_ownsManifold = false;
 	m_ownsManifold = false;
 
 
-	const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
-	btAssert (colObjWrap->getCollisionShape()->isCompound());
-	
+	const btCollisionObjectWrapper* colObjWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	btAssert(colObjWrap->getCollisionShape()->isCompound());
+
 	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 	m_compoundShapeRevision = compoundShape->getUpdateRevision();
 	m_compoundShapeRevision = compoundShape->getUpdateRevision();
-	
-	
-	preallocateChildAlgorithms(body0Wrap,body1Wrap);
+
+	preallocateChildAlgorithms(body0Wrap, body1Wrap);
 }
 }
 
 
-void	btCompoundCollisionAlgorithm::preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+void btCompoundCollisionAlgorithm::preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 {
 {
-	const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
-	const btCollisionObjectWrapper* otherObjWrap = m_isSwapped? body0Wrap : body1Wrap;
-	btAssert (colObjWrap->getCollisionShape()->isCompound());
-	
+	const btCollisionObjectWrapper* colObjWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* otherObjWrap = m_isSwapped ? body0Wrap : body1Wrap;
+	btAssert(colObjWrap->getCollisionShape()->isCompound());
+
 	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 
 
 	int numChildren = compoundShape->getNumChildShapes();
 	int numChildren = compoundShape->getNumChildShapes();
 	int i;
 	int i;
-	
+
 	m_childCollisionAlgorithms.resize(numChildren);
 	m_childCollisionAlgorithms.resize(numChildren);
-	for (i=0;i<numChildren;i++)
+	for (i = 0; i < numChildren; i++)
 	{
 	{
 		if (compoundShape->getDynamicAabbTree())
 		if (compoundShape->getDynamicAabbTree())
 		{
 		{
 			m_childCollisionAlgorithms[i] = 0;
 			m_childCollisionAlgorithms[i] = 0;
-		} else
+		}
+		else
 		{
 		{
-			
 			const btCollisionShape* childShape = compoundShape->getChildShape(i);
 			const btCollisionShape* childShape = compoundShape->getChildShape(i);
 
 
-			btCollisionObjectWrapper childWrap(colObjWrap,childShape,colObjWrap->getCollisionObject(),colObjWrap->getWorldTransform(),-1,i);//wrong child trans, but unused (hopefully)
-			m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(&childWrap,otherObjWrap,m_sharedManifold, BT_CONTACT_POINT_ALGORITHMS);
-
+			btCollisionObjectWrapper childWrap(colObjWrap, childShape, colObjWrap->getCollisionObject(), colObjWrap->getWorldTransform(), -1, i);  //wrong child trans, but unused (hopefully)
+			m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(&childWrap, otherObjWrap, m_sharedManifold, BT_CONTACT_POINT_ALGORITHMS);
 
 
 			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsContact;
 			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsContact;
 			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsClosestPoints;
 			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsClosestPoints;
-
-
 		}
 		}
 	}
 	}
 }
 }
 
 
-void	btCompoundCollisionAlgorithm::removeChildAlgorithms()
+void btCompoundCollisionAlgorithm::removeChildAlgorithms()
 {
 {
 	int numChildren = m_childCollisionAlgorithms.size();
 	int numChildren = m_childCollisionAlgorithms.size();
 	int i;
 	int i;
-	for (i=0;i<numChildren;i++)
+	for (i = 0; i < numChildren; i++)
 	{
 	{
 		if (m_childCollisionAlgorithms[i])
 		if (m_childCollisionAlgorithms[i])
 		{
 		{
@@ -97,71 +93,68 @@ btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
 	removeChildAlgorithms();
 	removeChildAlgorithms();
 }
 }
 
 
-
-
-
-struct	btCompoundLeafCallback : btDbvt::ICollide
+struct btCompoundLeafCallback : btDbvt::ICollide
 {
 {
-
 public:
 public:
-
 	const btCollisionObjectWrapper* m_compoundColObjWrap;
 	const btCollisionObjectWrapper* m_compoundColObjWrap;
 	const btCollisionObjectWrapper* m_otherObjWrap;
 	const btCollisionObjectWrapper* m_otherObjWrap;
 	btDispatcher* m_dispatcher;
 	btDispatcher* m_dispatcher;
 	const btDispatcherInfo& m_dispatchInfo;
 	const btDispatcherInfo& m_dispatchInfo;
-	btManifoldResult*	m_resultOut;
-	btCollisionAlgorithm**	m_childCollisionAlgorithms;
-	btPersistentManifold*	m_sharedManifold;
-	
-	btCompoundLeafCallback (const btCollisionObjectWrapper* compoundObjWrap,const btCollisionObjectWrapper* otherObjWrap,btDispatcher* dispatcher,const btDispatcherInfo& dispatchInfo,btManifoldResult*	resultOut,btCollisionAlgorithm**	childCollisionAlgorithms,btPersistentManifold*	sharedManifold)
-		:m_compoundColObjWrap(compoundObjWrap),m_otherObjWrap(otherObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
-		m_childCollisionAlgorithms(childCollisionAlgorithms),
-		m_sharedManifold(sharedManifold)
-	{
+	btManifoldResult* m_resultOut;
+	btCollisionAlgorithm** m_childCollisionAlgorithms;
+	btPersistentManifold* m_sharedManifold;
 
 
+	btCompoundLeafCallback(const btCollisionObjectWrapper* compoundObjWrap, const btCollisionObjectWrapper* otherObjWrap, btDispatcher* dispatcher, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut, btCollisionAlgorithm** childCollisionAlgorithms, btPersistentManifold* sharedManifold)
+		: m_compoundColObjWrap(compoundObjWrap), m_otherObjWrap(otherObjWrap), m_dispatcher(dispatcher), m_dispatchInfo(dispatchInfo), m_resultOut(resultOut), m_childCollisionAlgorithms(childCollisionAlgorithms), m_sharedManifold(sharedManifold)
+	{
 	}
 	}
 
 
-
-	void	ProcessChildShape(const btCollisionShape* childShape,int index)
+	void ProcessChildShape(const btCollisionShape* childShape, int index)
 	{
 	{
-		btAssert(index>=0);
+		btAssert(index >= 0);
 		const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
 		const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
-		btAssert(index<compoundShape->getNumChildShapes());
+		btAssert(index < compoundShape->getNumChildShapes());
 
 
+		if (gCompoundChildShapePairCallback)
+		{
+			if (!gCompoundChildShapePairCallback(m_otherObjWrap->getCollisionShape(), childShape))
+				return;
+		}
 
 
 		//backup
 		//backup
-		btTransform	orgTrans = m_compoundColObjWrap->getWorldTransform();
-		
+		btTransform orgTrans = m_compoundColObjWrap->getWorldTransform();
+
 		const btTransform& childTrans = compoundShape->getChildTransform(index);
 		const btTransform& childTrans = compoundShape->getChildTransform(index);
-		btTransform	newChildWorldTrans = orgTrans*childTrans ;
+		btTransform newChildWorldTrans = orgTrans * childTrans;
 
 
 		//perform an AABB check first
 		//perform an AABB check first
-		btVector3 aabbMin0,aabbMax0;
-		childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
+		btVector3 aabbMin0, aabbMax0;
+		childShape->getAabb(newChildWorldTrans, aabbMin0, aabbMax0);
 
 
 		btVector3 extendAabb(m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold);
 		btVector3 extendAabb(m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold);
 		aabbMin0 -= extendAabb;
 		aabbMin0 -= extendAabb;
 		aabbMax0 += extendAabb;
 		aabbMax0 += extendAabb;
 
 
 		btVector3 aabbMin1, aabbMax1;
 		btVector3 aabbMin1, aabbMax1;
-		m_otherObjWrap->getCollisionShape()->getAabb(m_otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
+		m_otherObjWrap->getCollisionShape()->getAabb(m_otherObjWrap->getWorldTransform(), aabbMin1, aabbMax1);
 
 
-		if (gCompoundChildShapePairCallback)
-		{
-			if (!gCompoundChildShapePairCallback(m_otherObjWrap->getCollisionShape(), childShape))
-				return;
-		}
 
 
-		if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+		if (TestAabbAgainstAabb2(aabbMin0, aabbMax0, aabbMin1, aabbMax1))
 		{
 		{
+			btTransform preTransform = childTrans;
+			if (this->m_compoundColObjWrap->m_preTransform)
+			{
+				preTransform = preTransform *(*(this->m_compoundColObjWrap->m_preTransform));
+			}
+			btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap, childShape, m_compoundColObjWrap->getCollisionObject(), newChildWorldTrans, preTransform, -1, index);
 
 
-			btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap,childShape,m_compoundColObjWrap->getCollisionObject(),newChildWorldTrans,-1,index);
-			
 			btCollisionAlgorithm* algo = 0;
 			btCollisionAlgorithm* algo = 0;
+			bool allocatedAlgorithm = false;
 
 
 			if (m_resultOut->m_closestPointDistanceThreshold > 0)
 			if (m_resultOut->m_closestPointDistanceThreshold > 0)
 			{
 			{
 				algo = m_dispatcher->findAlgorithm(&compoundWrap, m_otherObjWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
 				algo = m_dispatcher->findAlgorithm(&compoundWrap, m_otherObjWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
+				allocatedAlgorithm = true;
 			}
 			}
 			else
 			else
 			{
 			{
@@ -172,7 +165,7 @@ public:
 				}
 				}
 				algo = m_childCollisionAlgorithms[index];
 				algo = m_childCollisionAlgorithms[index];
 			}
 			}
-			
+
 			const btCollisionObjectWrapper* tmpWrap = 0;
 			const btCollisionObjectWrapper* tmpWrap = 0;
 
 
 			///detect swapping case
 			///detect swapping case
@@ -180,15 +173,16 @@ public:
 			{
 			{
 				tmpWrap = m_resultOut->getBody0Wrap();
 				tmpWrap = m_resultOut->getBody0Wrap();
 				m_resultOut->setBody0Wrap(&compoundWrap);
 				m_resultOut->setBody0Wrap(&compoundWrap);
-				m_resultOut->setShapeIdentifiersA(-1,index);
-			} else
+				m_resultOut->setShapeIdentifiersA(-1, index);
+			}
+			else
 			{
 			{
 				tmpWrap = m_resultOut->getBody1Wrap();
 				tmpWrap = m_resultOut->getBody1Wrap();
 				m_resultOut->setBody1Wrap(&compoundWrap);
 				m_resultOut->setBody1Wrap(&compoundWrap);
-				m_resultOut->setShapeIdentifiersB(-1,index);
+				m_resultOut->setShapeIdentifiersB(-1, index);
 			}
 			}
 
 
-			algo->processCollision(&compoundWrap,m_otherObjWrap,m_dispatchInfo,m_resultOut);
+			algo->processCollision(&compoundWrap, m_otherObjWrap, m_dispatchInfo, m_resultOut);
 
 
 #if 0
 #if 0
 			if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
 			if (m_dispatchInfo.m_debugDraw && (m_dispatchInfo.m_debugDraw->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
@@ -202,14 +196,19 @@ public:
 			if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
 			if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
 			{
 			{
 				m_resultOut->setBody0Wrap(tmpWrap);
 				m_resultOut->setBody0Wrap(tmpWrap);
-			} else
+			}
+			else
 			{
 			{
 				m_resultOut->setBody1Wrap(tmpWrap);
 				m_resultOut->setBody1Wrap(tmpWrap);
 			}
 			}
-			
+			if (allocatedAlgorithm)
+			{
+				algo->~btCollisionAlgorithm();
+				m_dispatcher->freeCollisionAlgorithm(algo);
+			}
 		}
 		}
 	}
 	}
-	void		Process(const btDbvtNode* leaf)
+	void Process(const btDbvtNode* leaf)
 	{
 	{
 		int index = leaf->dataAsInt;
 		int index = leaf->dataAsInt;
 
 
@@ -226,27 +225,21 @@ public:
 		}
 		}
 #endif
 #endif
 
 
-		ProcessChildShape(childShape,index);
-
+		ProcessChildShape(childShape, index);
 	}
 	}
 };
 };
 
 
-
-
-
-
-
-void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btCompoundCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
-	const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
-	const btCollisionObjectWrapper* otherObjWrap = m_isSwapped? body0Wrap : body1Wrap;
+	const btCollisionObjectWrapper* colObjWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* otherObjWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
 
-	btAssert (colObjWrap->getCollisionShape()->isCompound());
+	btAssert(colObjWrap->getCollisionShape()->isCompound());
 	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 
 
-    // Urho3D: do not go further if compound does not have child shapes, to prevent assert
-    if (!compoundShape->getNumChildShapes())
-        return;
+	// Urho3D: do not go further if compound does not have child shapes, to prevent assert
+	if (!compoundShape->getNumChildShapes())
+		return;
 
 
 	///btCompoundShape might have changed:
 	///btCompoundShape might have changed:
 	////make sure the internal child collision algorithm caches are still valid
 	////make sure the internal child collision algorithm caches are still valid
@@ -254,17 +247,17 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 	{
 	{
 		///clear and update all
 		///clear and update all
 		removeChildAlgorithms();
 		removeChildAlgorithms();
-		
-		preallocateChildAlgorithms(body0Wrap,body1Wrap);
+
+		preallocateChildAlgorithms(body0Wrap, body1Wrap);
 		m_compoundShapeRevision = compoundShape->getUpdateRevision();
 		m_compoundShapeRevision = compoundShape->getUpdateRevision();
 	}
 	}
 
 
-    if (m_childCollisionAlgorithms.size()==0)
-        return;
-    
+	if (m_childCollisionAlgorithms.size() == 0)
+		return;
+
 	const btDbvt* tree = compoundShape->getDynamicAabbTree();
 	const btDbvt* tree = compoundShape->getDynamicAabbTree();
 	//use a dynamic aabb tree to cull potential child-overlaps
 	//use a dynamic aabb tree to cull potential child-overlaps
-	btCompoundLeafCallback  callback(colObjWrap,otherObjWrap,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
+	btCompoundLeafCallback callback(colObjWrap, otherObjWrap, m_dispatcher, dispatchInfo, resultOut, &m_childCollisionAlgorithms[0], m_sharedManifold);
 
 
 	///we need to refresh all contact manifolds
 	///we need to refresh all contact manifolds
 	///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
 	///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
@@ -272,18 +265,18 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 	{
 	{
 		int i;
 		int i;
 		manifoldArray.resize(0);
 		manifoldArray.resize(0);
-		for (i=0;i<m_childCollisionAlgorithms.size();i++)
+		for (i = 0; i < m_childCollisionAlgorithms.size(); i++)
 		{
 		{
 			if (m_childCollisionAlgorithms[i])
 			if (m_childCollisionAlgorithms[i])
 			{
 			{
 				m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
 				m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
-				for (int m=0;m<manifoldArray.size();m++)
+				for (int m = 0; m < manifoldArray.size(); m++)
 				{
 				{
 					if (manifoldArray[m]->getNumContacts())
 					if (manifoldArray[m]->getNumContacts())
 					{
 					{
 						resultOut->setPersistentManifold(manifoldArray[m]);
 						resultOut->setPersistentManifold(manifoldArray[m]);
 						resultOut->refreshContactPoints();
 						resultOut->refreshContactPoints();
-						resultOut->setPersistentManifold(0);//??necessary?
+						resultOut->setPersistentManifold(0);  //??necessary?
 					}
 					}
 				}
 				}
 				manifoldArray.resize(0);
 				manifoldArray.resize(0);
@@ -293,57 +286,56 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 
 
 	if (tree)
 	if (tree)
 	{
 	{
-
-		btVector3 localAabbMin,localAabbMax;
+		btVector3 localAabbMin, localAabbMax;
 		btTransform otherInCompoundSpace;
 		btTransform otherInCompoundSpace;
 		otherInCompoundSpace = colObjWrap->getWorldTransform().inverse() * otherObjWrap->getWorldTransform();
 		otherInCompoundSpace = colObjWrap->getWorldTransform().inverse() * otherObjWrap->getWorldTransform();
-		otherObjWrap->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);
+		otherObjWrap->getCollisionShape()->getAabb(otherInCompoundSpace, localAabbMin, localAabbMax);
 		btVector3 extraExtends(resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold);
 		btVector3 extraExtends(resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold);
 		localAabbMin -= extraExtends;
 		localAabbMin -= extraExtends;
 		localAabbMax += extraExtends;
 		localAabbMax += extraExtends;
 
 
-		const ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
+		const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(localAabbMin, localAabbMax);
 		//process all children, that overlap with  the given AABB bounds
 		//process all children, that overlap with  the given AABB bounds
-		tree->collideTVNoStackAlloc(tree->m_root,bounds,stack2,callback);
-
-	} else
+		tree->collideTVNoStackAlloc(tree->m_root, bounds, stack2, callback);
+	}
+	else
 	{
 	{
 		//iterate over all children, perform an AABB check inside ProcessChildShape
 		//iterate over all children, perform an AABB check inside ProcessChildShape
 		int numChildren = m_childCollisionAlgorithms.size();
 		int numChildren = m_childCollisionAlgorithms.size();
 		int i;
 		int i;
-		for (i=0;i<numChildren;i++)
+		for (i = 0; i < numChildren; i++)
 		{
 		{
-			callback.ProcessChildShape(compoundShape->getChildShape(i),i);
+			callback.ProcessChildShape(compoundShape->getChildShape(i), i);
 		}
 		}
 	}
 	}
 
 
 	{
 	{
-				//iterate over all children, perform an AABB check inside ProcessChildShape
+		//iterate over all children, perform an AABB check inside ProcessChildShape
 		int numChildren = m_childCollisionAlgorithms.size();
 		int numChildren = m_childCollisionAlgorithms.size();
 		int i;
 		int i;
 		manifoldArray.resize(0);
 		manifoldArray.resize(0);
-        const btCollisionShape* childShape = 0;
-        btTransform	orgTrans;
-        
-        btTransform	newChildWorldTrans;
-        btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;        
-        
-		for (i=0;i<numChildren;i++)
+		const btCollisionShape* childShape = 0;
+		btTransform orgTrans;
+
+		btTransform newChildWorldTrans;
+		btVector3 aabbMin0, aabbMax0, aabbMin1, aabbMax1;
+
+		for (i = 0; i < numChildren; i++)
 		{
 		{
 			if (m_childCollisionAlgorithms[i])
 			if (m_childCollisionAlgorithms[i])
 			{
 			{
 				childShape = compoundShape->getChildShape(i);
 				childShape = compoundShape->getChildShape(i);
-			//if not longer overlapping, remove the algorithm
+				//if not longer overlapping, remove the algorithm
 				orgTrans = colObjWrap->getWorldTransform();
 				orgTrans = colObjWrap->getWorldTransform();
-                
+
 				const btTransform& childTrans = compoundShape->getChildTransform(i);
 				const btTransform& childTrans = compoundShape->getChildTransform(i);
-                newChildWorldTrans = orgTrans*childTrans ;
+				newChildWorldTrans = orgTrans * childTrans;
 
 
 				//perform an AABB check first
 				//perform an AABB check first
-				childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
-				otherObjWrap->getCollisionShape()->getAabb(otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
+				childShape->getAabb(newChildWorldTrans, aabbMin0, aabbMax0);
+				otherObjWrap->getCollisionShape()->getAabb(otherObjWrap->getWorldTransform(), aabbMin1, aabbMax1);
 
 
-				if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+				if (!TestAabbAgainstAabb2(aabbMin0, aabbMax0, aabbMin1, aabbMax1))
 				{
 				{
 					m_childCollisionAlgorithms[i]->~btCollisionAlgorithm();
 					m_childCollisionAlgorithms[i]->~btCollisionAlgorithm();
 					m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
 					m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
@@ -354,15 +346,15 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 	}
 	}
 }
 }
 
 
-btScalar	btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	btAssert(0);
 	btAssert(0);
 	//needs to be fixed, using btCollisionObjectWrapper and NOT modifying internal data structures
 	//needs to be fixed, using btCollisionObjectWrapper and NOT modifying internal data structures
-	btCollisionObject* colObj = m_isSwapped? body1 : body0;
-	btCollisionObject* otherObj = m_isSwapped? body0 : body1;
+	btCollisionObject* colObj = m_isSwapped ? body1 : body0;
+	btCollisionObject* otherObj = m_isSwapped ? body0 : body1;
+
+	btAssert(colObj->getCollisionShape()->isCompound());
 
 
-	btAssert (colObj->getCollisionShape()->isCompound());
-	
 	btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
 	btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
 
 
 	//We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
 	//We will use the OptimizedBVH, AABB tree to cull potential child-overlaps
@@ -376,33 +368,29 @@ btScalar	btCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
 
 
 	int numChildren = m_childCollisionAlgorithms.size();
 	int numChildren = m_childCollisionAlgorithms.size();
 	int i;
 	int i;
-    btTransform	orgTrans;
-    btScalar frac;
-	for (i=0;i<numChildren;i++)
+	btTransform orgTrans;
+	btScalar frac;
+	for (i = 0; i < numChildren; i++)
 	{
 	{
 		//btCollisionShape* childShape = compoundShape->getChildShape(i);
 		//btCollisionShape* childShape = compoundShape->getChildShape(i);
 
 
 		//backup
 		//backup
-        orgTrans = colObj->getWorldTransform();
-	
+		orgTrans = colObj->getWorldTransform();
+
 		const btTransform& childTrans = compoundShape->getChildTransform(i);
 		const btTransform& childTrans = compoundShape->getChildTransform(i);
 		//btTransform	newChildWorldTrans = orgTrans*childTrans ;
 		//btTransform	newChildWorldTrans = orgTrans*childTrans ;
-		colObj->setWorldTransform( orgTrans*childTrans );
+		colObj->setWorldTransform(orgTrans * childTrans);
 
 
 		//btCollisionShape* tmpShape = colObj->getCollisionShape();
 		//btCollisionShape* tmpShape = colObj->getCollisionShape();
 		//colObj->internalSetTemporaryCollisionShape( childShape );
 		//colObj->internalSetTemporaryCollisionShape( childShape );
-        frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
-		if (frac<hitFraction)
+		frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj, otherObj, dispatchInfo, resultOut);
+		if (frac < hitFraction)
 		{
 		{
 			hitFraction = frac;
 			hitFraction = frac;
 		}
 		}
 		//revert back
 		//revert back
 		//colObj->internalSetTemporaryCollisionShape( tmpShape);
 		//colObj->internalSetTemporaryCollisionShape( tmpShape);
-		colObj->setWorldTransform( orgTrans);
+		colObj->setWorldTransform(orgTrans);
 	}
 	}
 	return hitFraction;
 	return hitFraction;
-
 }
 }
-
-
-

+ 20 - 25
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h

@@ -35,7 +35,7 @@ typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCol
 extern btShapePairCallback gCompoundChildShapePairCallback;
 extern btShapePairCallback gCompoundChildShapePairCallback;
 
 
 /// btCompoundCollisionAlgorithm  supports collision between CompoundCollisionShapes and other collision shapes
 /// btCompoundCollisionAlgorithm  supports collision between CompoundCollisionShapes and other collision shapes
-class btCompoundCollisionAlgorithm  : public btActivatingCollisionAlgorithm
+class btCompoundCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
 	btNodeStack stack2;
 	btNodeStack stack2;
 	btManifoldArray manifoldArray;
 	btManifoldArray manifoldArray;
@@ -44,61 +44,56 @@ protected:
 	btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
 	btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
 	bool m_isSwapped;
 	bool m_isSwapped;
 
 
-	class btPersistentManifold*	m_sharedManifold;
-	bool					m_ownsManifold;
+	class btPersistentManifold* m_sharedManifold;
+	bool m_ownsManifold;
 
 
+	int m_compoundShapeRevision;  //to keep track of changes, so that childAlgorithm array can be updated
 
 
-	int	m_compoundShapeRevision;//to keep track of changes, so that childAlgorithm array can be updated
-	
-	void	removeChildAlgorithms();
-	
-	void	preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
+	void removeChildAlgorithms();
 
 
-public:
+	void preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
 
 
-	btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
+public:
+	btCompoundCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
 
 	virtual ~btCompoundCollisionAlgorithm();
 	virtual ~btCompoundCollisionAlgorithm();
 
 
-	btCollisionAlgorithm* getChildAlgorithm (int n) const
+	btCollisionAlgorithm* getChildAlgorithm(int n) const
 	{
 	{
 		return m_childCollisionAlgorithms[n];
 		return m_childCollisionAlgorithms[n];
 	}
 	}
 
 
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	btScalar	calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
-
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		int i;
 		int i;
-		for (i=0;i<m_childCollisionAlgorithms.size();i++)
+		for (i = 0; i < m_childCollisionAlgorithms.size(); i++)
 		{
 		{
 			if (m_childCollisionAlgorithms[i])
 			if (m_childCollisionAlgorithms[i])
 				m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
 				m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
 		}
 		}
 	}
 	}
 
 
-	
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
-			return new(mem) btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
+			return new (mem) btCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, false);
 		}
 		}
 	};
 	};
 
 
-	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCollisionAlgorithm));
-			return new(mem) btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
+			return new (mem) btCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, true);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_COMPOUND_COLLISION_ALGORITHM_H
+#endif  //BT_COMPOUND_COLLISION_ALGORITHM_H

+ 139 - 182
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp

@@ -29,29 +29,25 @@ subject to the following restrictions:
 
 
 btShapePairCallback gCompoundCompoundChildShapePairCallback = 0;
 btShapePairCallback gCompoundCompoundChildShapePairCallback = 0;
 
 
-btCompoundCompoundCollisionAlgorithm::btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
-:btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,isSwapped)
+btCompoundCompoundCollisionAlgorithm::btCompoundCompoundCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped)
+	: btCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, isSwapped)
 {
 {
-
-	void* ptr = btAlignedAlloc(sizeof(btHashedSimplePairCache),16);
-	m_childCollisionAlgorithmCache= new(ptr) btHashedSimplePairCache();
+	void* ptr = btAlignedAlloc(sizeof(btHashedSimplePairCache), 16);
+	m_childCollisionAlgorithmCache = new (ptr) btHashedSimplePairCache();
 
 
 	const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
 	const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
-	btAssert (col0ObjWrap->getCollisionShape()->isCompound());
+	btAssert(col0ObjWrap->getCollisionShape()->isCompound());
 
 
 	const btCollisionObjectWrapper* col1ObjWrap = body1Wrap;
 	const btCollisionObjectWrapper* col1ObjWrap = body1Wrap;
-	btAssert (col1ObjWrap->getCollisionShape()->isCompound());
-	
+	btAssert(col1ObjWrap->getCollisionShape()->isCompound());
+
 	const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
 	m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
 	m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
 
 
 	const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
 	m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
 	m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
-	
-	
 }
 }
 
 
-
 btCompoundCompoundCollisionAlgorithm::~btCompoundCompoundCollisionAlgorithm()
 btCompoundCompoundCollisionAlgorithm::~btCompoundCompoundCollisionAlgorithm()
 {
 {
 	removeChildAlgorithms();
 	removeChildAlgorithms();
@@ -59,32 +55,30 @@ btCompoundCompoundCollisionAlgorithm::~btCompoundCompoundCollisionAlgorithm()
 	btAlignedFree(m_childCollisionAlgorithmCache);
 	btAlignedFree(m_childCollisionAlgorithmCache);
 }
 }
 
 
-void	btCompoundCompoundCollisionAlgorithm::getAllContactManifolds(btManifoldArray&	manifoldArray)
+void btCompoundCompoundCollisionAlgorithm::getAllContactManifolds(btManifoldArray& manifoldArray)
 {
 {
 	int i;
 	int i;
 	btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
 	btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
-	for (i=0;i<pairs.size();i++)
+	for (i = 0; i < pairs.size(); i++)
 	{
 	{
 		if (pairs[i].m_userPointer)
 		if (pairs[i].m_userPointer)
 		{
 		{
-			
 			((btCollisionAlgorithm*)pairs[i].m_userPointer)->getAllContactManifolds(manifoldArray);
 			((btCollisionAlgorithm*)pairs[i].m_userPointer)->getAllContactManifolds(manifoldArray);
 		}
 		}
 	}
 	}
 }
 }
 
 
-
-void	btCompoundCompoundCollisionAlgorithm::removeChildAlgorithms()
+void btCompoundCompoundCollisionAlgorithm::removeChildAlgorithms()
 {
 {
 	btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
 	btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
 
 
 	int numChildren = pairs.size();
 	int numChildren = pairs.size();
 	int i;
 	int i;
-	for (i=0;i<numChildren;i++)
+	for (i = 0; i < numChildren; i++)
 	{
 	{
 		if (pairs[i].m_userPointer)
 		if (pairs[i].m_userPointer)
 		{
 		{
-			btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
+			btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
 			algo->~btCollisionAlgorithm();
 			algo->~btCollisionAlgorithm();
 			m_dispatcher->freeCollisionAlgorithm(algo);
 			m_dispatcher->freeCollisionAlgorithm(algo);
 		}
 		}
@@ -92,77 +86,65 @@ void	btCompoundCompoundCollisionAlgorithm::removeChildAlgorithms()
 	m_childCollisionAlgorithmCache->removeAllPairs();
 	m_childCollisionAlgorithmCache->removeAllPairs();
 }
 }
 
 
-struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
+struct btCompoundCompoundLeafCallback : btDbvt::ICollide
 {
 {
 	int m_numOverlapPairs;
 	int m_numOverlapPairs;
 
 
-
 	const btCollisionObjectWrapper* m_compound0ColObjWrap;
 	const btCollisionObjectWrapper* m_compound0ColObjWrap;
 	const btCollisionObjectWrapper* m_compound1ColObjWrap;
 	const btCollisionObjectWrapper* m_compound1ColObjWrap;
 	btDispatcher* m_dispatcher;
 	btDispatcher* m_dispatcher;
 	const btDispatcherInfo& m_dispatchInfo;
 	const btDispatcherInfo& m_dispatchInfo;
-	btManifoldResult*	m_resultOut;
-	
-	
-	class btHashedSimplePairCache*	m_childCollisionAlgorithmCache;
-	
-	btPersistentManifold*	m_sharedManifold;
-	
-	btCompoundCompoundLeafCallback (const btCollisionObjectWrapper* compound1ObjWrap,
-									const btCollisionObjectWrapper* compound0ObjWrap,
-									btDispatcher* dispatcher,
-									const btDispatcherInfo& dispatchInfo,
-									btManifoldResult*	resultOut,
-									btHashedSimplePairCache* childAlgorithmsCache,
-									btPersistentManifold*	sharedManifold)
-		:m_numOverlapPairs(0),m_compound0ColObjWrap(compound1ObjWrap),m_compound1ColObjWrap(compound0ObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
-		m_childCollisionAlgorithmCache(childAlgorithmsCache),
-		m_sharedManifold(sharedManifold)
-	{
+	btManifoldResult* m_resultOut;
 
 
-	}
+	class btHashedSimplePairCache* m_childCollisionAlgorithmCache;
 
 
+	btPersistentManifold* m_sharedManifold;
 
 
+	btCompoundCompoundLeafCallback(const btCollisionObjectWrapper* compound1ObjWrap,
+								   const btCollisionObjectWrapper* compound0ObjWrap,
+								   btDispatcher* dispatcher,
+								   const btDispatcherInfo& dispatchInfo,
+								   btManifoldResult* resultOut,
+								   btHashedSimplePairCache* childAlgorithmsCache,
+								   btPersistentManifold* sharedManifold)
+		: m_numOverlapPairs(0), m_compound0ColObjWrap(compound1ObjWrap), m_compound1ColObjWrap(compound0ObjWrap), m_dispatcher(dispatcher), m_dispatchInfo(dispatchInfo), m_resultOut(resultOut), m_childCollisionAlgorithmCache(childAlgorithmsCache), m_sharedManifold(sharedManifold)
+	{
+	}
 
 
-	
-	void		Process(const btDbvtNode* leaf0,const btDbvtNode* leaf1)
+	void Process(const btDbvtNode* leaf0, const btDbvtNode* leaf1)
 	{
 	{
 		BT_PROFILE("btCompoundCompoundLeafCallback::Process");
 		BT_PROFILE("btCompoundCompoundLeafCallback::Process");
 		m_numOverlapPairs++;
 		m_numOverlapPairs++;
 
 
-
 		int childIndex0 = leaf0->dataAsInt;
 		int childIndex0 = leaf0->dataAsInt;
 		int childIndex1 = leaf1->dataAsInt;
 		int childIndex1 = leaf1->dataAsInt;
-		
-
-		btAssert(childIndex0>=0);
-		btAssert(childIndex1>=0);
 
 
+		btAssert(childIndex0 >= 0);
+		btAssert(childIndex1 >= 0);
 
 
 		const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(m_compound0ColObjWrap->getCollisionShape());
 		const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(m_compound0ColObjWrap->getCollisionShape());
-		btAssert(childIndex0<compoundShape0->getNumChildShapes());
+		btAssert(childIndex0 < compoundShape0->getNumChildShapes());
 
 
 		const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(m_compound1ColObjWrap->getCollisionShape());
 		const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(m_compound1ColObjWrap->getCollisionShape());
-		btAssert(childIndex1<compoundShape1->getNumChildShapes());
+		btAssert(childIndex1 < compoundShape1->getNumChildShapes());
 
 
 		const btCollisionShape* childShape0 = compoundShape0->getChildShape(childIndex0);
 		const btCollisionShape* childShape0 = compoundShape0->getChildShape(childIndex0);
 		const btCollisionShape* childShape1 = compoundShape1->getChildShape(childIndex1);
 		const btCollisionShape* childShape1 = compoundShape1->getChildShape(childIndex1);
 
 
 		//backup
 		//backup
-		btTransform	orgTrans0 = m_compound0ColObjWrap->getWorldTransform();
+		btTransform orgTrans0 = m_compound0ColObjWrap->getWorldTransform();
 		const btTransform& childTrans0 = compoundShape0->getChildTransform(childIndex0);
 		const btTransform& childTrans0 = compoundShape0->getChildTransform(childIndex0);
-		btTransform	newChildWorldTrans0 = orgTrans0*childTrans0 ;
-		
-		btTransform	orgTrans1 = m_compound1ColObjWrap->getWorldTransform();
+		btTransform newChildWorldTrans0 = orgTrans0 * childTrans0;
+
+		btTransform orgTrans1 = m_compound1ColObjWrap->getWorldTransform();
 		const btTransform& childTrans1 = compoundShape1->getChildTransform(childIndex1);
 		const btTransform& childTrans1 = compoundShape1->getChildTransform(childIndex1);
-		btTransform	newChildWorldTrans1 = orgTrans1*childTrans1 ;
-		
+		btTransform newChildWorldTrans1 = orgTrans1 * childTrans1;
 
 
 		//perform an AABB check first
 		//perform an AABB check first
-		btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
-		childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
-		childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
-		
+		btVector3 aabbMin0, aabbMax0, aabbMin1, aabbMax1;
+		childShape0->getAabb(newChildWorldTrans0, aabbMin0, aabbMax0);
+		childShape1->getAabb(newChildWorldTrans1, aabbMin1, aabbMax1);
+
 		btVector3 thresholdVec(m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold);
 		btVector3 thresholdVec(m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold);
 
 
 		aabbMin0 -= thresholdVec;
 		aabbMin0 -= thresholdVec;
@@ -170,29 +152,28 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 
 
 		if (gCompoundCompoundChildShapePairCallback)
 		if (gCompoundCompoundChildShapePairCallback)
 		{
 		{
-			if (!gCompoundCompoundChildShapePairCallback(childShape0,childShape1))
+			if (!gCompoundCompoundChildShapePairCallback(childShape0, childShape1))
 				return;
 				return;
 		}
 		}
 
 
-		if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+		if (TestAabbAgainstAabb2(aabbMin0, aabbMax0, aabbMin1, aabbMax1))
 		{
 		{
-			btCollisionObjectWrapper compoundWrap0(this->m_compound0ColObjWrap,childShape0, m_compound0ColObjWrap->getCollisionObject(),newChildWorldTrans0,-1,childIndex0);
-			btCollisionObjectWrapper compoundWrap1(this->m_compound1ColObjWrap,childShape1,m_compound1ColObjWrap->getCollisionObject(),newChildWorldTrans1,-1,childIndex1);
-			
-
-			btSimplePair* pair = m_childCollisionAlgorithmCache->findPair(childIndex0,childIndex1);
+			btCollisionObjectWrapper compoundWrap0(this->m_compound0ColObjWrap, childShape0, m_compound0ColObjWrap->getCollisionObject(), newChildWorldTrans0, -1, childIndex0);
+			btCollisionObjectWrapper compoundWrap1(this->m_compound1ColObjWrap, childShape1, m_compound1ColObjWrap->getCollisionObject(), newChildWorldTrans1, -1, childIndex1);
 
 
+			btSimplePair* pair = m_childCollisionAlgorithmCache->findPair(childIndex0, childIndex1);
+			bool removePair = false;
 			btCollisionAlgorithm* colAlgo = 0;
 			btCollisionAlgorithm* colAlgo = 0;
 			if (m_resultOut->m_closestPointDistanceThreshold > 0)
 			if (m_resultOut->m_closestPointDistanceThreshold > 0)
 			{
 			{
 				colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0, &compoundWrap1, 0, BT_CLOSEST_POINT_ALGORITHMS);
 				colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0, &compoundWrap1, 0, BT_CLOSEST_POINT_ALGORITHMS);
+				removePair = true;
 			}
 			}
 			else
 			else
 			{
 			{
 				if (pair)
 				if (pair)
 				{
 				{
 					colAlgo = (btCollisionAlgorithm*)pair->m_userPointer;
 					colAlgo = (btCollisionAlgorithm*)pair->m_userPointer;
-
 				}
 				}
 				else
 				else
 				{
 				{
@@ -204,7 +185,7 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 			}
 			}
 
 
 			btAssert(colAlgo);
 			btAssert(colAlgo);
-						
+
 			const btCollisionObjectWrapper* tmpWrap0 = 0;
 			const btCollisionObjectWrapper* tmpWrap0 = 0;
 			const btCollisionObjectWrapper* tmpWrap1 = 0;
 			const btCollisionObjectWrapper* tmpWrap1 = 0;
 
 
@@ -214,101 +195,100 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 			m_resultOut->setBody0Wrap(&compoundWrap0);
 			m_resultOut->setBody0Wrap(&compoundWrap0);
 			m_resultOut->setBody1Wrap(&compoundWrap1);
 			m_resultOut->setBody1Wrap(&compoundWrap1);
 
 
-			m_resultOut->setShapeIdentifiersA(-1,childIndex0);
-			m_resultOut->setShapeIdentifiersB(-1,childIndex1);
+			m_resultOut->setShapeIdentifiersA(-1, childIndex0);
+			m_resultOut->setShapeIdentifiersB(-1, childIndex1);
 
 
+			colAlgo->processCollision(&compoundWrap0, &compoundWrap1, m_dispatchInfo, m_resultOut);
 
 
-			colAlgo->processCollision(&compoundWrap0,&compoundWrap1,m_dispatchInfo,m_resultOut);
-			
 			m_resultOut->setBody0Wrap(tmpWrap0);
 			m_resultOut->setBody0Wrap(tmpWrap0);
 			m_resultOut->setBody1Wrap(tmpWrap1);
 			m_resultOut->setBody1Wrap(tmpWrap1);
-			
-
 
 
+			if (removePair)
+			{
+				colAlgo->~btCollisionAlgorithm();
+				m_dispatcher->freeCollisionAlgorithm(colAlgo);
+			}
 		}
 		}
 	}
 	}
 };
 };
 
 
-
-static DBVT_INLINE bool		MyIntersect(	const btDbvtAabbMm& a,
-								  const btDbvtAabbMm& b, const btTransform& xform, btScalar distanceThreshold)
+static DBVT_INLINE bool MyIntersect(const btDbvtAabbMm& a,
+									const btDbvtAabbMm& b, const btTransform& xform, btScalar distanceThreshold)
 {
 {
-	btVector3 newmin,newmax;
-	btTransformAabb(b.Mins(),b.Maxs(),0.f,xform,newmin,newmax);
+	btVector3 newmin, newmax;
+	btTransformAabb(b.Mins(), b.Maxs(), 0.f, xform, newmin, newmax);
 	newmin -= btVector3(distanceThreshold, distanceThreshold, distanceThreshold);
 	newmin -= btVector3(distanceThreshold, distanceThreshold, distanceThreshold);
 	newmax += btVector3(distanceThreshold, distanceThreshold, distanceThreshold);
 	newmax += btVector3(distanceThreshold, distanceThreshold, distanceThreshold);
-	btDbvtAabbMm newb = btDbvtAabbMm::FromMM(newmin,newmax);
-	return Intersect(a,newb);
+	btDbvtAabbMm newb = btDbvtAabbMm::FromMM(newmin, newmax);
+	return Intersect(a, newb);
 }
 }
 
 
-
-static inline void		MycollideTT(	const btDbvtNode* root0,
-								  const btDbvtNode* root1,
-								  const btTransform& xform,
-								  btCompoundCompoundLeafCallback* callback, btScalar distanceThreshold)
+static inline void MycollideTT(const btDbvtNode* root0,
+							   const btDbvtNode* root1,
+							   const btTransform& xform,
+							   btCompoundCompoundLeafCallback* callback, btScalar distanceThreshold)
 {
 {
-
-		if(root0&&root1)
-		{
-			int								depth=1;
-			int								treshold=btDbvt::DOUBLE_STACKSIZE-4;
-			btAlignedObjectArray<btDbvt::sStkNN>	stkStack;
+	if (root0 && root1)
+	{
+		int depth = 1;
+		int treshold = btDbvt::DOUBLE_STACKSIZE - 4;
+		btAlignedObjectArray<btDbvt::sStkNN> stkStack;
 #ifdef USE_LOCAL_STACK
 #ifdef USE_LOCAL_STACK
-			ATTRIBUTE_ALIGNED16(btDbvt::sStkNN localStack[btDbvt::DOUBLE_STACKSIZE]);
-			stkStack.initializeFromBuffer(&localStack,btDbvt::DOUBLE_STACKSIZE,btDbvt::DOUBLE_STACKSIZE);
+		ATTRIBUTE_ALIGNED16(btDbvt::sStkNN localStack[btDbvt::DOUBLE_STACKSIZE]);
+		stkStack.initializeFromBuffer(&localStack, btDbvt::DOUBLE_STACKSIZE, btDbvt::DOUBLE_STACKSIZE);
 #else
 #else
-			stkStack.resize(btDbvt::DOUBLE_STACKSIZE);
+		stkStack.resize(btDbvt::DOUBLE_STACKSIZE);
 #endif
 #endif
-			stkStack[0]=btDbvt::sStkNN(root0,root1);
-			do	{
-				btDbvt::sStkNN	p=stkStack[--depth];
-				if(MyIntersect(p.a->volume,p.b->volume,xform, distanceThreshold))
+		stkStack[0] = btDbvt::sStkNN(root0, root1);
+		do
+		{
+			btDbvt::sStkNN p = stkStack[--depth];
+			if (MyIntersect(p.a->volume, p.b->volume, xform, distanceThreshold))
+			{
+				if (depth > treshold)
 				{
 				{
-					if(depth>treshold)
+					stkStack.resize(stkStack.size() * 2);
+					treshold = stkStack.size() - 4;
+				}
+				if (p.a->isinternal())
+				{
+					if (p.b->isinternal())
 					{
 					{
-						stkStack.resize(stkStack.size()*2);
-						treshold=stkStack.size()-4;
+						stkStack[depth++] = btDbvt::sStkNN(p.a->childs[0], p.b->childs[0]);
+						stkStack[depth++] = btDbvt::sStkNN(p.a->childs[1], p.b->childs[0]);
+						stkStack[depth++] = btDbvt::sStkNN(p.a->childs[0], p.b->childs[1]);
+						stkStack[depth++] = btDbvt::sStkNN(p.a->childs[1], p.b->childs[1]);
 					}
 					}
-					if(p.a->isinternal())
+					else
 					{
 					{
-						if(p.b->isinternal())
-						{					
-							stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b->childs[0]);
-							stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b->childs[0]);
-							stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b->childs[1]);
-							stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b->childs[1]);
-						}
-						else
-						{
-							stkStack[depth++]=btDbvt::sStkNN(p.a->childs[0],p.b);
-							stkStack[depth++]=btDbvt::sStkNN(p.a->childs[1],p.b);
-						}
+						stkStack[depth++] = btDbvt::sStkNN(p.a->childs[0], p.b);
+						stkStack[depth++] = btDbvt::sStkNN(p.a->childs[1], p.b);
+					}
+				}
+				else
+				{
+					if (p.b->isinternal())
+					{
+						stkStack[depth++] = btDbvt::sStkNN(p.a, p.b->childs[0]);
+						stkStack[depth++] = btDbvt::sStkNN(p.a, p.b->childs[1]);
 					}
 					}
 					else
 					else
 					{
 					{
-						if(p.b->isinternal())
-						{
-							stkStack[depth++]=btDbvt::sStkNN(p.a,p.b->childs[0]);
-							stkStack[depth++]=btDbvt::sStkNN(p.a,p.b->childs[1]);
-						}
-						else
-						{
-							callback->Process(p.a,p.b);
-						}
+						callback->Process(p.a, p.b);
 					}
 					}
 				}
 				}
-			} while(depth);
-		}
+			}
+		} while (depth);
+	}
 }
 }
 
 
-void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btCompoundCompoundCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
-
 	const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
 	const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
-	const btCollisionObjectWrapper* col1ObjWrap= body1Wrap;
+	const btCollisionObjectWrapper* col1ObjWrap = body1Wrap;
 
 
-	btAssert (col0ObjWrap->getCollisionShape()->isCompound());
-	btAssert (col1ObjWrap->getCollisionShape()->isCompound());
+	btAssert(col0ObjWrap->getCollisionShape()->isCompound());
+	btAssert(col1ObjWrap->getCollisionShape()->isCompound());
 	const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
 	const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
 
 
@@ -316,7 +296,7 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 	const btDbvt* tree1 = compoundShape1->getDynamicAabbTree();
 	const btDbvt* tree1 = compoundShape1->getDynamicAabbTree();
 	if (!tree0 || !tree1)
 	if (!tree0 || !tree1)
 	{
 	{
-		return btCompoundCollisionAlgorithm::processCollision(body0Wrap,body1Wrap,dispatchInfo,resultOut);
+		return btCompoundCollisionAlgorithm::processCollision(body0Wrap, body1Wrap, dispatchInfo, resultOut);
 	}
 	}
 	///btCompoundShape might have changed:
 	///btCompoundShape might have changed:
 	////make sure the internal child collision algorithm caches are still valid
 	////make sure the internal child collision algorithm caches are still valid
@@ -326,28 +306,26 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 		removeChildAlgorithms();
 		removeChildAlgorithms();
 		m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
 		m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
 		m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
 		m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
-
 	}
 	}
 
 
-
 	///we need to refresh all contact manifolds
 	///we need to refresh all contact manifolds
 	///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
 	///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
 	///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
 	///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
 	{
 	{
 		int i;
 		int i;
 		btManifoldArray manifoldArray;
 		btManifoldArray manifoldArray;
-#ifdef USE_LOCAL_STACK 
+#ifdef USE_LOCAL_STACK
 		btPersistentManifold localManifolds[4];
 		btPersistentManifold localManifolds[4];
-		manifoldArray.initializeFromBuffer(&localManifolds,0,4);
+		manifoldArray.initializeFromBuffer(&localManifolds, 0, 4);
 #endif
 #endif
 		btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
 		btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
-		for (i=0;i<pairs.size();i++)
+		for (i = 0; i < pairs.size(); i++)
 		{
 		{
 			if (pairs[i].m_userPointer)
 			if (pairs[i].m_userPointer)
 			{
 			{
-				btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
+				btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
 				algo->getAllContactManifolds(manifoldArray);
 				algo->getAllContactManifolds(manifoldArray);
-				for (int m=0;m<manifoldArray.size();m++)
+				for (int m = 0; m < manifoldArray.size(); m++)
 				{
 				{
 					if (manifoldArray[m]->getNumContacts())
 					if (manifoldArray[m]->getNumContacts())
 					{
 					{
@@ -361,96 +339,75 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 		}
 		}
 	}
 	}
 
 
+	btCompoundCompoundLeafCallback callback(col0ObjWrap, col1ObjWrap, this->m_dispatcher, dispatchInfo, resultOut, this->m_childCollisionAlgorithmCache, m_sharedManifold);
 
 
-	
-
-	btCompoundCompoundLeafCallback callback(col0ObjWrap,col1ObjWrap,this->m_dispatcher,dispatchInfo,resultOut,this->m_childCollisionAlgorithmCache,m_sharedManifold);
-
-
-	const btTransform	xform=col0ObjWrap->getWorldTransform().inverse()*col1ObjWrap->getWorldTransform();
-	MycollideTT(tree0->m_root,tree1->m_root,xform,&callback, resultOut->m_closestPointDistanceThreshold);
+	const btTransform xform = col0ObjWrap->getWorldTransform().inverse() * col1ObjWrap->getWorldTransform();
+	MycollideTT(tree0->m_root, tree1->m_root, xform, &callback, resultOut->m_closestPointDistanceThreshold);
 
 
 	//printf("#compound-compound child/leaf overlap =%d                      \r",callback.m_numOverlapPairs);
 	//printf("#compound-compound child/leaf overlap =%d                      \r",callback.m_numOverlapPairs);
 
 
 	//remove non-overlapping child pairs
 	//remove non-overlapping child pairs
 
 
 	{
 	{
-		btAssert(m_removePairs.size()==0);
+		btAssert(m_removePairs.size() == 0);
 
 
 		//iterate over all children, perform an AABB check inside ProcessChildShape
 		//iterate over all children, perform an AABB check inside ProcessChildShape
 		btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
 		btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
-		
+
 		int i;
 		int i;
-		btManifoldArray	manifoldArray;
-        
-		
-
-        
-        
-        btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;        
-        
-		for (i=0;i<pairs.size();i++)
+		btManifoldArray manifoldArray;
+
+		btVector3 aabbMin0, aabbMax0, aabbMin1, aabbMax1;
+
+		for (i = 0; i < pairs.size(); i++)
 		{
 		{
 			if (pairs[i].m_userPointer)
 			if (pairs[i].m_userPointer)
 			{
 			{
 				btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
 				btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
 
 
 				{
 				{
-					btTransform	orgTrans0;
 					const btCollisionShape* childShape0 = 0;
 					const btCollisionShape* childShape0 = 0;
-					
-					btTransform	newChildWorldTrans0;
-					btTransform	orgInterpolationTrans0;
+
+					btTransform newChildWorldTrans0;
 					childShape0 = compoundShape0->getChildShape(pairs[i].m_indexA);
 					childShape0 = compoundShape0->getChildShape(pairs[i].m_indexA);
-					orgTrans0 = col0ObjWrap->getWorldTransform();
-					orgInterpolationTrans0 = col0ObjWrap->getWorldTransform();
 					const btTransform& childTrans0 = compoundShape0->getChildTransform(pairs[i].m_indexA);
 					const btTransform& childTrans0 = compoundShape0->getChildTransform(pairs[i].m_indexA);
-					newChildWorldTrans0 = orgTrans0*childTrans0 ;
-					childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
+					newChildWorldTrans0 = col0ObjWrap->getWorldTransform() * childTrans0;
+					childShape0->getAabb(newChildWorldTrans0, aabbMin0, aabbMax0);
 				}
 				}
 				btVector3 thresholdVec(resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold);
 				btVector3 thresholdVec(resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold);
 				aabbMin0 -= thresholdVec;
 				aabbMin0 -= thresholdVec;
 				aabbMax0 += thresholdVec;
 				aabbMax0 += thresholdVec;
 				{
 				{
-					btTransform	orgInterpolationTrans1;
 					const btCollisionShape* childShape1 = 0;
 					const btCollisionShape* childShape1 = 0;
-					btTransform	orgTrans1;
-					btTransform	newChildWorldTrans1;
+					btTransform newChildWorldTrans1;
 
 
 					childShape1 = compoundShape1->getChildShape(pairs[i].m_indexB);
 					childShape1 = compoundShape1->getChildShape(pairs[i].m_indexB);
-					orgTrans1 = col1ObjWrap->getWorldTransform();
-					orgInterpolationTrans1 = col1ObjWrap->getWorldTransform();
 					const btTransform& childTrans1 = compoundShape1->getChildTransform(pairs[i].m_indexB);
 					const btTransform& childTrans1 = compoundShape1->getChildTransform(pairs[i].m_indexB);
-					newChildWorldTrans1 = orgTrans1*childTrans1 ;
-					childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
+					newChildWorldTrans1 = col1ObjWrap->getWorldTransform() * childTrans1;
+					childShape1->getAabb(newChildWorldTrans1, aabbMin1, aabbMax1);
 				}
 				}
-				
+
 				aabbMin1 -= thresholdVec;
 				aabbMin1 -= thresholdVec;
 				aabbMax1 += thresholdVec;
 				aabbMax1 += thresholdVec;
 
 
-				if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+				if (!TestAabbAgainstAabb2(aabbMin0, aabbMax0, aabbMin1, aabbMax1))
 				{
 				{
 					algo->~btCollisionAlgorithm();
 					algo->~btCollisionAlgorithm();
 					m_dispatcher->freeCollisionAlgorithm(algo);
 					m_dispatcher->freeCollisionAlgorithm(algo);
-					m_removePairs.push_back(btSimplePair(pairs[i].m_indexA,pairs[i].m_indexB));
+					m_removePairs.push_back(btSimplePair(pairs[i].m_indexA, pairs[i].m_indexB));
 				}
 				}
 			}
 			}
 		}
 		}
-		for (int i=0;i<m_removePairs.size();i++)
+		for (int i = 0; i < m_removePairs.size(); i++)
 		{
 		{
-			m_childCollisionAlgorithmCache->removeOverlappingPair(m_removePairs[i].m_indexA,m_removePairs[i].m_indexB);
+			m_childCollisionAlgorithmCache->removeOverlappingPair(m_removePairs[i].m_indexA, m_removePairs[i].m_indexB);
 		}
 		}
 		m_removePairs.clear();
 		m_removePairs.clear();
 	}
 	}
-
 }
 }
 
 
-btScalar	btCompoundCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btCompoundCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	btAssert(0);
 	btAssert(0);
 	return 0.f;
 	return 0.f;
-
 }
 }
-
-
-

+ 19 - 26
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h

@@ -33,57 +33,50 @@ class btDispatcher;
 class btCollisionObject;
 class btCollisionObject;
 
 
 class btCollisionShape;
 class btCollisionShape;
-typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
+
 extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
 extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
 
 
 /// btCompoundCompoundCollisionAlgorithm  supports collision between two btCompoundCollisionShape shapes
 /// btCompoundCompoundCollisionAlgorithm  supports collision between two btCompoundCollisionShape shapes
-class btCompoundCompoundCollisionAlgorithm  : public btCompoundCollisionAlgorithm
+class btCompoundCompoundCollisionAlgorithm : public btCompoundCollisionAlgorithm
 {
 {
-
-	class btHashedSimplePairCache*	m_childCollisionAlgorithmCache;
+	class btHashedSimplePairCache* m_childCollisionAlgorithmCache;
 	btSimplePairArray m_removePairs;
 	btSimplePairArray m_removePairs;
 
 
+	int m_compoundShapeRevision0;  //to keep track of changes, so that childAlgorithm array can be updated
+	int m_compoundShapeRevision1;
 
 
-	int	m_compoundShapeRevision0;//to keep track of changes, so that childAlgorithm array can be updated
-	int	m_compoundShapeRevision1;
-	
-	void	removeChildAlgorithms();
-	
-//	void	preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
+	void removeChildAlgorithms();
 
 
-public:
+	//	void	preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 
-	btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
+public:
+	btCompoundCompoundCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
 
 	virtual ~btCompoundCompoundCollisionAlgorithm();
 	virtual ~btCompoundCompoundCollisionAlgorithm();
 
 
-	
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	btScalar	calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray);
-	
-	
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
-			return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
+			return new (mem) btCompoundCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, false);
 		}
 		}
 	};
 	};
 
 
-	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
-			return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
+			return new (mem) btCompoundCompoundCollisionAlgorithm(ci, body0Wrap, body1Wrap, true);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
+#endif  //BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H

+ 34 - 65
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp

@@ -22,7 +22,6 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
 
 
-
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
@@ -34,8 +33,6 @@ subject to the following restrictions:
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h"
 
 
-
-
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 
 
@@ -45,31 +42,28 @@ subject to the following restrictions:
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
-btConvex2dConvex2dAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
+btConvex2dConvex2dAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
 {
 {
 	m_simplexSolver = simplexSolver;
 	m_simplexSolver = simplexSolver;
 	m_pdSolver = pdSolver;
 	m_pdSolver = pdSolver;
 }
 }
 
 
-btConvex2dConvex2dAlgorithm::CreateFunc::~CreateFunc() 
-{ 
+btConvex2dConvex2dAlgorithm::CreateFunc::~CreateFunc()
+{
 }
 }
 
 
-btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int /* numPerturbationIterations */, int /* minimumPointsPerturbationThreshold */)
-: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_simplexSolver(simplexSolver),
-m_pdSolver(pdSolver),
-m_ownManifold (false),
-m_manifoldPtr(mf),
-m_lowLevelOfDetail(false)
+btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int /* numPerturbationIterations */, int /* minimumPointsPerturbationThreshold */)
+	: btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
+	  m_simplexSolver(simplexSolver),
+	  m_pdSolver(pdSolver),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf),
+	  m_lowLevelOfDetail(false)
 {
 {
 	(void)body0Wrap;
 	(void)body0Wrap;
 	(void)body1Wrap;
 	(void)body1Wrap;
 }
 }
 
 
-
-
-
 btConvex2dConvex2dAlgorithm::~btConvex2dConvex2dAlgorithm()
 btConvex2dConvex2dAlgorithm::~btConvex2dConvex2dAlgorithm()
 {
 {
 	if (m_ownManifold)
 	if (m_ownManifold)
@@ -79,26 +73,22 @@ btConvex2dConvex2dAlgorithm::~btConvex2dConvex2dAlgorithm()
 	}
 	}
 }
 }
 
 
-void	btConvex2dConvex2dAlgorithm ::setLowLevelOfDetail(bool useLowLevel)
+void btConvex2dConvex2dAlgorithm ::setLowLevelOfDetail(bool useLowLevel)
 {
 {
 	m_lowLevelOfDetail = useLowLevel;
 	m_lowLevelOfDetail = useLowLevel;
 }
 }
 
 
-
-
 extern btScalar gContactBreakingThreshold;
 extern btScalar gContactBreakingThreshold;
 
 
-
 //
 //
 // Convex-Convex collision algorithm
 // Convex-Convex collision algorithm
 //
 //
-void btConvex2dConvex2dAlgorithm ::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvex2dConvex2dAlgorithm ::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
-
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 	{
 	{
 		//swapped?
 		//swapped?
-		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(), body1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
@@ -106,49 +96,41 @@ void btConvex2dConvex2dAlgorithm ::processCollision (const btCollisionObjectWrap
 	//comment-out next line to test multi-contact generation
 	//comment-out next line to test multi-contact generation
 	//resultOut->getPersistentManifold()->clearManifold();
 	//resultOut->getPersistentManifold()->clearManifold();
 
 
-
 	const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
 	const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
 	const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
 	const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
 
 
-	btVector3  normalOnB;
-	btVector3  pointOnBWorld;
+	btVector3 normalOnB;
+	btVector3 pointOnBWorld;
 
 
 	{
 	{
-
-
 		btGjkPairDetector::ClosestPointInput input;
 		btGjkPairDetector::ClosestPointInput input;
 
 
-		btGjkPairDetector	gjkPairDetector(min0,min1,m_simplexSolver,m_pdSolver);
+		btGjkPairDetector gjkPairDetector(min0, min1, m_simplexSolver, m_pdSolver);
 		//TODO: if (dispatchInfo.m_useContinuous)
 		//TODO: if (dispatchInfo.m_useContinuous)
 		gjkPairDetector.setMinkowskiA(min0);
 		gjkPairDetector.setMinkowskiA(min0);
 		gjkPairDetector.setMinkowskiB(min1);
 		gjkPairDetector.setMinkowskiB(min1);
 
 
 		{
 		{
 			input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
 			input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
-			input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
+			input.m_maximumDistanceSquared *= input.m_maximumDistanceSquared;
 		}
 		}
 
 
 		input.m_transformA = body0Wrap->getWorldTransform();
 		input.m_transformA = body0Wrap->getWorldTransform();
 		input.m_transformB = body1Wrap->getWorldTransform();
 		input.m_transformB = body1Wrap->getWorldTransform();
 
 
-		gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+		gjkPairDetector.getClosestPoints(input, *resultOut, dispatchInfo.m_debugDraw);
 
 
-		btVector3 v0,v1;
+		btVector3 v0, v1;
 		btVector3 sepNormalWorldSpace;
 		btVector3 sepNormalWorldSpace;
-
 	}
 	}
 
 
 	if (m_ownManifold)
 	if (m_ownManifold)
 	{
 	{
 		resultOut->refreshContactPoints();
 		resultOut->refreshContactPoints();
 	}
 	}
-
 }
 }
 
 
-
-
-
-btScalar	btConvex2dConvex2dAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btConvex2dConvex2dAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, btCollisionObject* col1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)resultOut;
 	(void)resultOut;
 	(void)dispatchInfo;
 	(void)dispatchInfo;
@@ -158,7 +140,6 @@ btScalar	btConvex2dConvex2dAlgorithm::calculateTimeOfImpact(btCollisionObject* c
 	///col0->m_worldTransform,
 	///col0->m_worldTransform,
 	btScalar resultFraction = btScalar(1.);
 	btScalar resultFraction = btScalar(1.);
 
 
-
 	btScalar squareMot0 = (col0->getInterpolationWorldTransform().getOrigin() - col0->getWorldTransform().getOrigin()).length2();
 	btScalar squareMot0 = (col0->getInterpolationWorldTransform().getOrigin() - col0->getWorldTransform().getOrigin()).length2();
 	btScalar squareMot1 = (col1->getInterpolationWorldTransform().getOrigin() - col1->getWorldTransform().getOrigin()).length2();
 	btScalar squareMot1 = (col1->getInterpolationWorldTransform().getOrigin() - col1->getWorldTransform().getOrigin()).length2();
 
 
@@ -166,77 +147,65 @@ btScalar	btConvex2dConvex2dAlgorithm::calculateTimeOfImpact(btCollisionObject* c
 		squareMot1 < col1->getCcdSquareMotionThreshold())
 		squareMot1 < col1->getCcdSquareMotionThreshold())
 		return resultFraction;
 		return resultFraction;
 
 
-
 	//An adhoc way of testing the Continuous Collision Detection algorithms
 	//An adhoc way of testing the Continuous Collision Detection algorithms
 	//One object is approximated as a sphere, to simplify things
 	//One object is approximated as a sphere, to simplify things
 	//Starting in penetration should report no time of impact
 	//Starting in penetration should report no time of impact
 	//For proper CCD, better accuracy and handling of 'allowed' penetration should be added
 	//For proper CCD, better accuracy and handling of 'allowed' penetration should be added
 	//also the mainloop of the physics should have a kind of toi queue (something like Brian Mirtich's application of Timewarp for Rigidbodies)
 	//also the mainloop of the physics should have a kind of toi queue (something like Brian Mirtich's application of Timewarp for Rigidbodies)
 
 
-
 	/// Convex0 against sphere for Convex1
 	/// Convex0 against sphere for Convex1
 	{
 	{
 		btConvexShape* convex0 = static_cast<btConvexShape*>(col0->getCollisionShape());
 		btConvexShape* convex0 = static_cast<btConvexShape*>(col0->getCollisionShape());
 
 
-		btSphereShape	sphere1(col1->getCcdSweptSphereRadius()); //todo: allow non-zero sphere sizes, for better approximation
+		btSphereShape sphere1(col1->getCcdSweptSphereRadius());  //todo: allow non-zero sphere sizes, for better approximation
 		btConvexCast::CastResult result;
 		btConvexCast::CastResult result;
 		btVoronoiSimplexSolver voronoiSimplex;
 		btVoronoiSimplexSolver voronoiSimplex;
 		//SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
 		//SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
 		///Simplification, one object is simplified as a sphere
 		///Simplification, one object is simplified as a sphere
-		btGjkConvexCast ccd1( convex0 ,&sphere1,&voronoiSimplex);
+		btGjkConvexCast ccd1(convex0, &sphere1, &voronoiSimplex);
 		//ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
 		//ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
-		if (ccd1.calcTimeOfImpact(col0->getWorldTransform(),col0->getInterpolationWorldTransform(),
-			col1->getWorldTransform(),col1->getInterpolationWorldTransform(),result))
+		if (ccd1.calcTimeOfImpact(col0->getWorldTransform(), col0->getInterpolationWorldTransform(),
+								  col1->getWorldTransform(), col1->getInterpolationWorldTransform(), result))
 		{
 		{
-
 			//store result.m_fraction in both bodies
 			//store result.m_fraction in both bodies
 
 
-			if (col0->getHitFraction()> result.m_fraction)
-				col0->setHitFraction( result.m_fraction );
+			if (col0->getHitFraction() > result.m_fraction)
+				col0->setHitFraction(result.m_fraction);
 
 
 			if (col1->getHitFraction() > result.m_fraction)
 			if (col1->getHitFraction() > result.m_fraction)
-				col1->setHitFraction( result.m_fraction);
+				col1->setHitFraction(result.m_fraction);
 
 
 			if (resultFraction > result.m_fraction)
 			if (resultFraction > result.m_fraction)
 				resultFraction = result.m_fraction;
 				resultFraction = result.m_fraction;
-
 		}
 		}
-
-
-
-
 	}
 	}
 
 
 	/// Sphere (for convex0) against Convex1
 	/// Sphere (for convex0) against Convex1
 	{
 	{
 		btConvexShape* convex1 = static_cast<btConvexShape*>(col1->getCollisionShape());
 		btConvexShape* convex1 = static_cast<btConvexShape*>(col1->getCollisionShape());
 
 
-		btSphereShape	sphere0(col0->getCcdSweptSphereRadius()); //todo: allow non-zero sphere sizes, for better approximation
+		btSphereShape sphere0(col0->getCcdSweptSphereRadius());  //todo: allow non-zero sphere sizes, for better approximation
 		btConvexCast::CastResult result;
 		btConvexCast::CastResult result;
 		btVoronoiSimplexSolver voronoiSimplex;
 		btVoronoiSimplexSolver voronoiSimplex;
 		//SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
 		//SubsimplexConvexCast ccd0(&sphere,min0,&voronoiSimplex);
 		///Simplification, one object is simplified as a sphere
 		///Simplification, one object is simplified as a sphere
-		btGjkConvexCast ccd1(&sphere0,convex1,&voronoiSimplex);
+		btGjkConvexCast ccd1(&sphere0, convex1, &voronoiSimplex);
 		//ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
 		//ContinuousConvexCollision ccd(min0,min1,&voronoiSimplex,0);
-		if (ccd1.calcTimeOfImpact(col0->getWorldTransform(),col0->getInterpolationWorldTransform(),
-			col1->getWorldTransform(),col1->getInterpolationWorldTransform(),result))
+		if (ccd1.calcTimeOfImpact(col0->getWorldTransform(), col0->getInterpolationWorldTransform(),
+								  col1->getWorldTransform(), col1->getInterpolationWorldTransform(), result))
 		{
 		{
-
 			//store result.m_fraction in both bodies
 			//store result.m_fraction in both bodies
 
 
-			if (col0->getHitFraction()	> result.m_fraction)
-				col0->setHitFraction( result.m_fraction);
+			if (col0->getHitFraction() > result.m_fraction)
+				col0->setHitFraction(result.m_fraction);
 
 
 			if (col1->getHitFraction() > result.m_fraction)
 			if (col1->getHitFraction() > result.m_fraction)
-				col1->setHitFraction( result.m_fraction);
+				col1->setHitFraction(result.m_fraction);
 
 
 			if (resultFraction > result.m_fraction)
 			if (resultFraction > result.m_fraction)
 				resultFraction = result.m_fraction;
 				resultFraction = result.m_fraction;
-
 		}
 		}
 	}
 	}
 
 
 	return resultFraction;
 	return resultFraction;
-
 }
 }
-

+ 20 - 29
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h

@@ -23,70 +23,61 @@ subject to the following restrictions:
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
 #include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
-#include "LinearMath/btTransformUtil.h" //for btConvexSeparatingDistanceUtil
+#include "LinearMath/btTransformUtil.h"  //for btConvexSeparatingDistanceUtil
 
 
 class btConvexPenetrationDepthSolver;
 class btConvexPenetrationDepthSolver;
 
 
-
 ///The convex2dConvex2dAlgorithm collision algorithm support 2d collision detection for btConvex2dShape
 ///The convex2dConvex2dAlgorithm collision algorithm support 2d collision detection for btConvex2dShape
 ///Currently it requires the btMinkowskiPenetrationDepthSolver, it has support for 2d penetration depth computation
 ///Currently it requires the btMinkowskiPenetrationDepthSolver, it has support for 2d penetration depth computation
 class btConvex2dConvex2dAlgorithm : public btActivatingCollisionAlgorithm
 class btConvex2dConvex2dAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-	btSimplexSolverInterface*		m_simplexSolver;
+	btSimplexSolverInterface* m_simplexSolver;
 	btConvexPenetrationDepthSolver* m_pdSolver;
 	btConvexPenetrationDepthSolver* m_pdSolver;
 
 
-	
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	bool			m_lowLevelOfDetail;
-	
-public:
-
-	btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+	bool m_lowLevelOfDetail;
 
 
+public:
+	btConvex2dConvex2dAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
 
 
 	virtual ~btConvex2dConvex2dAlgorithm();
 	virtual ~btConvex2dConvex2dAlgorithm();
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		///should we use m_ownManifold to avoid adding duplicates?
 		///should we use m_ownManifold to avoid adding duplicates?
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 			manifoldArray.push_back(m_manifoldPtr);
 			manifoldArray.push_back(m_manifoldPtr);
 	}
 	}
 
 
+	void setLowLevelOfDetail(bool useLowLevel);
 
 
-	void	setLowLevelOfDetail(bool useLowLevel);
-
-
-	const btPersistentManifold*	getManifold()
+	const btPersistentManifold* getManifold()
 	{
 	{
 		return m_manifoldPtr;
 		return m_manifoldPtr;
 	}
 	}
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-
-		btConvexPenetrationDepthSolver*		m_pdSolver;
-		btSimplexSolverInterface*			m_simplexSolver;
+		btConvexPenetrationDepthSolver* m_pdSolver;
+		btSimplexSolverInterface* m_simplexSolver;
 		int m_numPerturbationIterations;
 		int m_numPerturbationIterations;
 		int m_minimumPointsPerturbationThreshold;
 		int m_minimumPointsPerturbationThreshold;
 
 
-		CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
-		
+		CreateFunc(btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
+
 		virtual ~CreateFunc();
 		virtual ~CreateFunc();
 
 
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvex2dConvex2dAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvex2dConvex2dAlgorithm));
-			return new(mem) btConvex2dConvex2dAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+			return new (mem) btConvex2dConvex2dAlgorithm(ci.m_manifold, ci, body0Wrap, body1Wrap, m_simplexSolver, m_pdSolver, m_numPerturbationIterations, m_minimumPointsPerturbationThreshold);
 		}
 		}
 	};
 	};
-
-
 };
 };
 
 
-#endif //BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#endif  //BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H

+ 141 - 113
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp

@@ -13,7 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "btConvexConcaveCollisionAlgorithm.h"
 #include "btConvexConcaveCollisionAlgorithm.h"
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btQuickprof.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
@@ -27,11 +26,12 @@ subject to the following restrictions:
 #include "LinearMath/btIDebugDraw.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+#include "BulletCollision/CollisionShapes/btSdfCollisionShape.h"
 
 
-btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
-: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_btConvexTriangleCallback(ci.m_dispatcher1,body0Wrap,body1Wrap,isSwapped),
-m_isSwapped(isSwapped)
+btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped)
+	: btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
+	  m_btConvexTriangleCallback(ci.m_dispatcher1, body0Wrap, body1Wrap, isSwapped),
+	  m_isSwapped(isSwapped)
 {
 {
 }
 }
 
 
@@ -39,7 +39,7 @@ btConvexConcaveCollisionAlgorithm::~btConvexConcaveCollisionAlgorithm()
 {
 {
 }
 }
 
 
-void	btConvexConcaveCollisionAlgorithm::getAllContactManifolds(btManifoldArray&	manifoldArray)
+void btConvexConcaveCollisionAlgorithm::getAllContactManifolds(btManifoldArray& manifoldArray)
 {
 {
 	if (m_btConvexTriangleCallback.m_manifoldPtr)
 	if (m_btConvexTriangleCallback.m_manifoldPtr)
 	{
 	{
@@ -47,38 +47,32 @@ void	btConvexConcaveCollisionAlgorithm::getAllContactManifolds(btManifoldArray&
 	}
 	}
 }
 }
 
 
-
-btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher*  dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped):
-	  m_dispatcher(dispatcher),
-	m_dispatchInfoPtr(0)
+btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher* dispatcher, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped) : m_dispatcher(dispatcher),
+																																													 m_dispatchInfoPtr(0)
 {
 {
-	m_convexBodyWrap = isSwapped? body1Wrap:body0Wrap;
-	m_triBodyWrap = isSwapped? body0Wrap:body1Wrap;
-	
-	  //
-	  // create the manifold from the dispatcher 'manifold pool'
-	  //
-	  m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBodyWrap->getCollisionObject(),m_triBodyWrap->getCollisionObject());
+	m_convexBodyWrap = isSwapped ? body1Wrap : body0Wrap;
+	m_triBodyWrap = isSwapped ? body0Wrap : body1Wrap;
+
+	//
+	// create the manifold from the dispatcher 'manifold pool'
+	//
+	m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBodyWrap->getCollisionObject(), m_triBodyWrap->getCollisionObject());
 
 
-  	  clearCache();
+	clearCache();
 }
 }
 
 
 btConvexTriangleCallback::~btConvexTriangleCallback()
 btConvexTriangleCallback::~btConvexTriangleCallback()
 {
 {
 	clearCache();
 	clearCache();
-	m_dispatcher->releaseManifold( m_manifoldPtr );
-  
+	m_dispatcher->releaseManifold(m_manifoldPtr);
 }
 }
-  
 
 
-void	btConvexTriangleCallback::clearCache()
+void btConvexTriangleCallback::clearCache()
 {
 {
 	m_dispatcher->clearManifold(m_manifoldPtr);
 	m_dispatcher->clearManifold(m_manifoldPtr);
 }
 }
 
 
-
-void btConvexTriangleCallback::processTriangle(btVector3* triangle,int
-partId, int triangleIndex)
+void btConvexTriangleCallback::processTriangle(btVector3* triangle, int partId, int triangleIndex)
 {
 {
 	BT_PROFILE("btConvexTriangleCallback::processTriangle");
 	BT_PROFILE("btConvexTriangleCallback::processTriangle");
 
 
@@ -87,16 +81,12 @@ partId, int triangleIndex)
 		return;
 		return;
 	}
 	}
 
 
-        //just for debugging purposes
-        //printf("triangle %d",m_triangleCount++);
-
-
+	//just for debugging purposes
+	//printf("triangle %d",m_triangleCount++);
 
 
 	btCollisionAlgorithmConstructionInfo ci;
 	btCollisionAlgorithmConstructionInfo ci;
 	ci.m_dispatcher1 = m_dispatcher;
 	ci.m_dispatcher1 = m_dispatcher;
 
 
-
-
 #if 0	
 #if 0	
 	
 	
 	///debug drawing of the overlapping triangles
 	///debug drawing of the overlapping triangles
@@ -110,16 +100,15 @@ partId, int triangleIndex)
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
 	}
 	}
 #endif
 #endif
-	
+
 	if (m_convexBodyWrap->getCollisionShape()->isConvex())
 	if (m_convexBodyWrap->getCollisionShape()->isConvex())
 	{
 	{
-		btTriangleShape tm(triangle[0],triangle[1],triangle[2]);	
+		btTriangleShape tm(triangle[0], triangle[1], triangle[2]);
 		tm.setMargin(m_collisionMarginTriangle);
 		tm.setMargin(m_collisionMarginTriangle);
-		
-		
-		btCollisionObjectWrapper triObWrap(m_triBodyWrap,&tm,m_triBodyWrap->getCollisionObject(),m_triBodyWrap->getWorldTransform(),partId,triangleIndex);//correct transform?
+
+		btCollisionObjectWrapper triObWrap(m_triBodyWrap, &tm, m_triBodyWrap->getCollisionObject(), m_triBodyWrap->getWorldTransform(), partId, triangleIndex);  //correct transform?
 		btCollisionAlgorithm* colAlgo = 0;
 		btCollisionAlgorithm* colAlgo = 0;
-		
+
 		if (m_resultOut->m_closestPointDistanceThreshold > 0)
 		if (m_resultOut->m_closestPointDistanceThreshold > 0)
 		{
 		{
 			colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap, &triObWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
 			colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap, &triObWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
@@ -134,36 +123,32 @@ partId, int triangleIndex)
 		{
 		{
 			tmpWrap = m_resultOut->getBody0Wrap();
 			tmpWrap = m_resultOut->getBody0Wrap();
 			m_resultOut->setBody0Wrap(&triObWrap);
 			m_resultOut->setBody0Wrap(&triObWrap);
-			m_resultOut->setShapeIdentifiersA(partId,triangleIndex);
+			m_resultOut->setShapeIdentifiersA(partId, triangleIndex);
 		}
 		}
 		else
 		else
 		{
 		{
 			tmpWrap = m_resultOut->getBody1Wrap();
 			tmpWrap = m_resultOut->getBody1Wrap();
 			m_resultOut->setBody1Wrap(&triObWrap);
 			m_resultOut->setBody1Wrap(&triObWrap);
-			m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
+			m_resultOut->setShapeIdentifiersB(partId, triangleIndex);
 		}
 		}
-	
-		colAlgo->processCollision(m_convexBodyWrap,&triObWrap,*m_dispatchInfoPtr,m_resultOut);
+
+		colAlgo->processCollision(m_convexBodyWrap, &triObWrap, *m_dispatchInfoPtr, m_resultOut);
 
 
 		if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
 		if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
 		{
 		{
 			m_resultOut->setBody0Wrap(tmpWrap);
 			m_resultOut->setBody0Wrap(tmpWrap);
-		} else
+		}
+		else
 		{
 		{
 			m_resultOut->setBody1Wrap(tmpWrap);
 			m_resultOut->setBody1Wrap(tmpWrap);
 		}
 		}
-		
-
 
 
 		colAlgo->~btCollisionAlgorithm();
 		colAlgo->~btCollisionAlgorithm();
 		ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
 		ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
 	}
 	}
-
 }
 }
 
 
-
-
-void	btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut)
+void btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle, const btDispatcherInfo& dispatchInfo, const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut)
 {
 {
 	m_convexBodyWrap = convexBodyWrap;
 	m_convexBodyWrap = convexBodyWrap;
 	m_triBodyWrap = triBodyWrap;
 	m_triBodyWrap = triBodyWrap;
@@ -177,66 +162,120 @@ void	btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTr
 	convexInTriangleSpace = m_triBodyWrap->getWorldTransform().inverse() * m_convexBodyWrap->getWorldTransform();
 	convexInTriangleSpace = m_triBodyWrap->getWorldTransform().inverse() * m_convexBodyWrap->getWorldTransform();
 	const btCollisionShape* convexShape = static_cast<const btCollisionShape*>(m_convexBodyWrap->getCollisionShape());
 	const btCollisionShape* convexShape = static_cast<const btCollisionShape*>(m_convexBodyWrap->getCollisionShape());
 	//CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
 	//CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
-	convexShape->getAabb(convexInTriangleSpace,m_aabbMin,m_aabbMax);
-	btScalar extraMargin = collisionMarginTriangle+ resultOut->m_closestPointDistanceThreshold;
-	
-	btVector3 extra(extraMargin,extraMargin,extraMargin);
+	convexShape->getAabb(convexInTriangleSpace, m_aabbMin, m_aabbMax);
+	btScalar extraMargin = collisionMarginTriangle + resultOut->m_closestPointDistanceThreshold;
+
+	btVector3 extra(extraMargin, extraMargin, extraMargin);
 
 
 	m_aabbMax += extra;
 	m_aabbMax += extra;
 	m_aabbMin -= extra;
 	m_aabbMin -= extra;
-	
 }
 }
 
 
 void btConvexConcaveCollisionAlgorithm::clearCache()
 void btConvexConcaveCollisionAlgorithm::clearCache()
 {
 {
 	m_btConvexTriangleCallback.clearCache();
 	m_btConvexTriangleCallback.clearCache();
-
 }
 }
 
 
-void btConvexConcaveCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexConcaveCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	BT_PROFILE("btConvexConcaveCollisionAlgorithm::processCollision");
 	BT_PROFILE("btConvexConcaveCollisionAlgorithm::processCollision");
-	
+
 	const btCollisionObjectWrapper* convexBodyWrap = m_isSwapped ? body1Wrap : body0Wrap;
 	const btCollisionObjectWrapper* convexBodyWrap = m_isSwapped ? body1Wrap : body0Wrap;
 	const btCollisionObjectWrapper* triBodyWrap = m_isSwapped ? body0Wrap : body1Wrap;
 	const btCollisionObjectWrapper* triBodyWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
 
 	if (triBodyWrap->getCollisionShape()->isConcave())
 	if (triBodyWrap->getCollisionShape()->isConcave())
 	{
 	{
+		if (triBodyWrap->getCollisionShape()->getShapeType() == SDF_SHAPE_PROXYTYPE)
+		{
+			btSdfCollisionShape* sdfShape = (btSdfCollisionShape*)triBodyWrap->getCollisionShape();
+			if (convexBodyWrap->getCollisionShape()->isConvex())
+			{
+				btConvexShape* convex = (btConvexShape*)convexBodyWrap->getCollisionShape();
+				btAlignedObjectArray<btVector3> queryVertices;
+
+				if (convex->isPolyhedral())
+				{
+					btPolyhedralConvexShape* poly = (btPolyhedralConvexShape*)convex;
+					for (int v = 0; v < poly->getNumVertices(); v++)
+					{
+						btVector3 vtx;
+						poly->getVertex(v, vtx);
+						queryVertices.push_back(vtx);
+					}
+				}
+				btScalar maxDist = SIMD_EPSILON;
+
+				if (convex->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
+				{
+					queryVertices.push_back(btVector3(0, 0, 0));
+					btSphereShape* sphere = (btSphereShape*)convex;
+					maxDist = sphere->getRadius() + SIMD_EPSILON;
+				}
+				if (queryVertices.size())
+				{
+					resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
+					//m_btConvexTriangleCallback.m_manifoldPtr->clearManifold();
+
+					btPolyhedralConvexShape* poly = (btPolyhedralConvexShape*)convex;
+					for (int v = 0; v < queryVertices.size(); v++)
+					{
+						const btVector3& vtx = queryVertices[v];
+						btVector3 vtxWorldSpace = convexBodyWrap->getWorldTransform() * vtx;
+						btVector3 vtxInSdf = triBodyWrap->getWorldTransform().invXform(vtxWorldSpace);
+
+						btVector3 normalLocal;
+						btScalar dist;
+						if (sdfShape->queryPoint(vtxInSdf, dist, normalLocal))
+						{
+							if (dist <= maxDist)
+							{
+								normalLocal.safeNormalize();
+								btVector3 normal = triBodyWrap->getWorldTransform().getBasis() * normalLocal;
+
+								if (convex->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
+								{
+									btSphereShape* sphere = (btSphereShape*)convex;
+									dist -= sphere->getRadius();
+									vtxWorldSpace -= sphere->getRadius() * normal;
+								}
+								resultOut->addContactPoint(normal, vtxWorldSpace - normal * dist, dist);
+							}
+						}
+					}
+					resultOut->refreshContactPoints();
+				}
+			}
+		}
+		else
+		{
+			const btConcaveShape* concaveShape = static_cast<const btConcaveShape*>(triBodyWrap->getCollisionShape());
+
+			if (convexBodyWrap->getCollisionShape()->isConvex())
+			{
+				btScalar collisionMarginTriangle = concaveShape->getMargin();
 
 
+				resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
+				m_btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle, dispatchInfo, convexBodyWrap, triBodyWrap, resultOut);
 
 
-		
-		const btConcaveShape* concaveShape = static_cast<const btConcaveShape*>( triBodyWrap->getCollisionShape());
-		
-		if (convexBodyWrap->getCollisionShape()->isConvex())
-		{
-			btScalar collisionMarginTriangle = concaveShape->getMargin();
-					
-			resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
-			m_btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,convexBodyWrap,triBodyWrap,resultOut);
+				m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBodyWrap->getCollisionObject(), triBodyWrap->getCollisionObject());
 
 
-			m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBodyWrap->getCollisionObject(),triBodyWrap->getCollisionObject());
+				concaveShape->processAllTriangles(&m_btConvexTriangleCallback, m_btConvexTriangleCallback.getAabbMin(), m_btConvexTriangleCallback.getAabbMax());
 
 
-			concaveShape->processAllTriangles( &m_btConvexTriangleCallback,m_btConvexTriangleCallback.getAabbMin(),m_btConvexTriangleCallback.getAabbMax());
-			
-			resultOut->refreshContactPoints();
+				resultOut->refreshContactPoints();
 
 
-			m_btConvexTriangleCallback.clearWrapperData();
-	
+				m_btConvexTriangleCallback.clearWrapperData();
+			}
 		}
 		}
-	
 	}
 	}
-
 }
 }
 
 
-
-btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)resultOut;
 	(void)resultOut;
 	(void)dispatchInfo;
 	(void)dispatchInfo;
 	btCollisionObject* convexbody = m_isSwapped ? body1 : body0;
 	btCollisionObject* convexbody = m_isSwapped ? body1 : body0;
 	btCollisionObject* triBody = m_isSwapped ? body0 : body1;
 	btCollisionObject* triBody = m_isSwapped ? body0 : body1;
 
 
-
 	//quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)
 	//quick approximation using raycast, todo: hook up to the continuous collision detection (one of the btConvexCast)
 
 
 	//only perform CCD above a certain threshold, this prevents blocking on the long run
 	//only perform CCD above a certain threshold, this prevents blocking on the long run
@@ -255,25 +294,23 @@ btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObj
 	btTransform convexFromLocal = triInv * convexbody->getWorldTransform();
 	btTransform convexFromLocal = triInv * convexbody->getWorldTransform();
 	btTransform convexToLocal = triInv * convexbody->getInterpolationWorldTransform();
 	btTransform convexToLocal = triInv * convexbody->getInterpolationWorldTransform();
 
 
-	struct LocalTriangleSphereCastCallback	: public btTriangleCallback
+	struct LocalTriangleSphereCastCallback : public btTriangleCallback
 	{
 	{
 		btTransform m_ccdSphereFromTrans;
 		btTransform m_ccdSphereFromTrans;
 		btTransform m_ccdSphereToTrans;
 		btTransform m_ccdSphereToTrans;
-		btTransform	m_meshTransform;
+		btTransform m_meshTransform;
 
 
-		btScalar	m_ccdSphereRadius;
-		btScalar	m_hitFraction;
-	
+		btScalar m_ccdSphereRadius;
+		btScalar m_hitFraction;
 
 
-		LocalTriangleSphereCastCallback(const btTransform& from,const btTransform& to,btScalar ccdSphereRadius,btScalar hitFraction)
-			:m_ccdSphereFromTrans(from),
-			m_ccdSphereToTrans(to),
-			m_ccdSphereRadius(ccdSphereRadius),
-			m_hitFraction(hitFraction)
-		{			
+		LocalTriangleSphereCastCallback(const btTransform& from, const btTransform& to, btScalar ccdSphereRadius, btScalar hitFraction)
+			: m_ccdSphereFromTrans(from),
+			  m_ccdSphereToTrans(to),
+			  m_ccdSphereRadius(ccdSphereRadius),
+			  m_hitFraction(hitFraction)
+		{
 		}
 		}
-		
-		
+
 		virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 		virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 		{
 		{
 			BT_PROFILE("processTriangle");
 			BT_PROFILE("processTriangle");
@@ -284,29 +321,23 @@ btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObj
 			ident.setIdentity();
 			ident.setIdentity();
 			btConvexCast::CastResult castResult;
 			btConvexCast::CastResult castResult;
 			castResult.m_fraction = m_hitFraction;
 			castResult.m_fraction = m_hitFraction;
-			btSphereShape	pointShape(m_ccdSphereRadius);
-			btTriangleShape	triShape(triangle[0],triangle[1],triangle[2]);
-			btVoronoiSimplexSolver	simplexSolver;
-			btSubsimplexConvexCast convexCaster(&pointShape,&triShape,&simplexSolver);
+			btSphereShape pointShape(m_ccdSphereRadius);
+			btTriangleShape triShape(triangle[0], triangle[1], triangle[2]);
+			btVoronoiSimplexSolver simplexSolver;
+			btSubsimplexConvexCast convexCaster(&pointShape, &triShape, &simplexSolver);
 			//GjkConvexCast	convexCaster(&pointShape,convexShape,&simplexSolver);
 			//GjkConvexCast	convexCaster(&pointShape,convexShape,&simplexSolver);
 			//ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
 			//ContinuousConvexCollision convexCaster(&pointShape,convexShape,&simplexSolver,0);
 			//local space?
 			//local space?
 
 
-			if (convexCaster.calcTimeOfImpact(m_ccdSphereFromTrans,m_ccdSphereToTrans,
-				ident,ident,castResult))
+			if (convexCaster.calcTimeOfImpact(m_ccdSphereFromTrans, m_ccdSphereToTrans,
+											  ident, ident, castResult))
 			{
 			{
 				if (m_hitFraction > castResult.m_fraction)
 				if (m_hitFraction > castResult.m_fraction)
 					m_hitFraction = castResult.m_fraction;
 					m_hitFraction = castResult.m_fraction;
 			}
 			}
-
 		}
 		}
-
 	};
 	};
 
 
-
-	
-
-	
 	if (triBody->getCollisionShape()->isConcave())
 	if (triBody->getCollisionShape()->isConcave())
 	{
 	{
 		btVector3 rayAabbMin = convexFromLocal.getOrigin();
 		btVector3 rayAabbMin = convexFromLocal.getOrigin();
@@ -314,33 +345,30 @@ btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObj
 		btVector3 rayAabbMax = convexFromLocal.getOrigin();
 		btVector3 rayAabbMax = convexFromLocal.getOrigin();
 		rayAabbMax.setMax(convexToLocal.getOrigin());
 		rayAabbMax.setMax(convexToLocal.getOrigin());
 		btScalar ccdRadius0 = convexbody->getCcdSweptSphereRadius();
 		btScalar ccdRadius0 = convexbody->getCcdSweptSphereRadius();
-		rayAabbMin -= btVector3(ccdRadius0,ccdRadius0,ccdRadius0);
-		rayAabbMax += btVector3(ccdRadius0,ccdRadius0,ccdRadius0);
+		rayAabbMin -= btVector3(ccdRadius0, ccdRadius0, ccdRadius0);
+		rayAabbMax += btVector3(ccdRadius0, ccdRadius0, ccdRadius0);
 
 
-		btScalar curHitFraction = btScalar(1.); //is this available?
-		LocalTriangleSphereCastCallback raycastCallback(convexFromLocal,convexToLocal,
-			convexbody->getCcdSweptSphereRadius(),curHitFraction);
+		btScalar curHitFraction = btScalar(1.);  //is this available?
+		LocalTriangleSphereCastCallback raycastCallback(convexFromLocal, convexToLocal,
+														convexbody->getCcdSweptSphereRadius(), curHitFraction);
 
 
 		raycastCallback.m_hitFraction = convexbody->getHitFraction();
 		raycastCallback.m_hitFraction = convexbody->getHitFraction();
 
 
 		btCollisionObject* concavebody = triBody;
 		btCollisionObject* concavebody = triBody;
 
 
-		btConcaveShape* triangleMesh = (btConcaveShape*) concavebody->getCollisionShape();
-		
+		btConcaveShape* triangleMesh = (btConcaveShape*)concavebody->getCollisionShape();
+
 		if (triangleMesh)
 		if (triangleMesh)
 		{
 		{
-			triangleMesh->processAllTriangles(&raycastCallback,rayAabbMin,rayAabbMax);
+			triangleMesh->processAllTriangles(&raycastCallback, rayAabbMin, rayAabbMax);
 		}
 		}
-	
-
 
 
 		if (raycastCallback.m_hitFraction < convexbody->getHitFraction())
 		if (raycastCallback.m_hitFraction < convexbody->getHitFraction())
 		{
 		{
-			convexbody->setHitFraction( raycastCallback.m_hitFraction);
+			convexbody->setHitFraction(raycastCallback.m_hitFraction);
 			return raycastCallback.m_hitFraction;
 			return raycastCallback.m_hitFraction;
 		}
 		}
 	}
 	}
 
 
 	return btScalar(1.);
 	return btScalar(1.);
-
 }
 }

+ 32 - 42
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h

@@ -26,42 +26,40 @@ class btDispatcher;
 #include "btCollisionCreateFunc.h"
 #include "btCollisionCreateFunc.h"
 
 
 ///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), processTriangle is called.
 ///For each triangle in the concave mesh that overlaps with the AABB of a convex (m_convexProxy), processTriangle is called.
-ATTRIBUTE_ALIGNED16(class)  btConvexTriangleCallback : public btTriangleCallback
+ATTRIBUTE_ALIGNED16(class)
+btConvexTriangleCallback : public btTriangleCallback
 {
 {
-
-	btVector3	m_aabbMin;
-	btVector3	m_aabbMax ;
+	btVector3 m_aabbMin;
+	btVector3 m_aabbMax;
 
 
 	const btCollisionObjectWrapper* m_convexBodyWrap;
 	const btCollisionObjectWrapper* m_convexBodyWrap;
 	const btCollisionObjectWrapper* m_triBodyWrap;
 	const btCollisionObjectWrapper* m_triBodyWrap;
 
 
-
-
 	btManifoldResult* m_resultOut;
 	btManifoldResult* m_resultOut;
-	btDispatcher*	m_dispatcher;
+	btDispatcher* m_dispatcher;
 	const btDispatcherInfo* m_dispatchInfoPtr;
 	const btDispatcherInfo* m_dispatchInfoPtr;
 	btScalar m_collisionMarginTriangle;
 	btScalar m_collisionMarginTriangle;
-	
+
 public:
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
-	
-int	m_triangleCount;
-	
-	btPersistentManifold*	m_manifoldPtr;
 
 
-	btConvexTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
+	int m_triangleCount;
+
+	btPersistentManifold* m_manifoldPtr;
 
 
-	void	setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut);
+	btConvexTriangleCallback(btDispatcher * dispatcher, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
 
-	void	clearWrapperData()
+	void setTimeStepAndCounters(btScalar collisionMarginTriangle, const btDispatcherInfo& dispatchInfo, const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut);
+
+	void clearWrapperData()
 	{
 	{
 		m_convexBodyWrap = 0;
 		m_convexBodyWrap = 0;
 		m_triBodyWrap = 0;
 		m_triBodyWrap = 0;
 	}
 	}
 	virtual ~btConvexTriangleCallback();
 	virtual ~btConvexTriangleCallback();
 
 
-	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex);
-	
+	virtual void processTriangle(btVector3 * triangle, int partId, int triangleIndex);
+
 	void clearCache();
 	void clearCache();
 
 
 	SIMD_FORCE_INLINE const btVector3& getAabbMin() const
 	SIMD_FORCE_INLINE const btVector3& getAabbMin() const
@@ -72,56 +70,48 @@ int	m_triangleCount;
 	{
 	{
 		return m_aabbMax;
 		return m_aabbMax;
 	}
 	}
-
 };
 };
 
 
-
-
-
 /// btConvexConcaveCollisionAlgorithm  supports collision between convex shapes and (concave) trianges meshes.
 /// btConvexConcaveCollisionAlgorithm  supports collision between convex shapes and (concave) trianges meshes.
-ATTRIBUTE_ALIGNED16(class)  btConvexConcaveCollisionAlgorithm  : public btActivatingCollisionAlgorithm
+ATTRIBUTE_ALIGNED16(class)
+btConvexConcaveCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-
 	btConvexTriangleCallback m_btConvexTriangleCallback;
 	btConvexTriangleCallback m_btConvexTriangleCallback;
 
 
-	bool	m_isSwapped;
-
-
+	bool m_isSwapped;
 
 
 public:
 public:
-
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
-	
-	btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
+
+	btConvexConcaveCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
 
 	virtual ~btConvexConcaveCollisionAlgorithm();
 	virtual ~btConvexConcaveCollisionAlgorithm();
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
+
+	btScalar calculateTimeOfImpact(btCollisionObject * body0, btCollisionObject * body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	btScalar	calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void getAllContactManifolds(btManifoldArray & manifoldArray);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray);
-	
-	void	clearCache();
+	void clearCache();
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
-			return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
+			return new (mem) btConvexConcaveCollisionAlgorithm(ci, body0Wrap, body1Wrap, false);
 		}
 		}
 	};
 	};
 
 
-	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct SwappedCreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConcaveCollisionAlgorithm));
-			return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
+			return new (mem) btConvexConcaveCollisionAlgorithm(ci, body0Wrap, body1Wrap, true);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#endif  //BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H

File diff suppressed because it is too large
+ 464 - 407
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp


+ 19 - 27
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h

@@ -23,7 +23,7 @@ subject to the following restrictions:
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "btCollisionCreateFunc.h"
 #include "btCollisionCreateFunc.h"
 #include "btCollisionDispatcher.h"
 #include "btCollisionDispatcher.h"
-#include "LinearMath/btTransformUtil.h" //for btConvexSeparatingDistanceUtil
+#include "LinearMath/btTransformUtil.h"  //for btConvexSeparatingDistanceUtil
 #include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h"
 #include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h"
 
 
 class btConvexPenetrationDepthSolver;
 class btConvexPenetrationDepthSolver;
@@ -41,69 +41,61 @@ class btConvexPenetrationDepthSolver;
 class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
 #ifdef USE_SEPDISTANCE_UTIL2
 #ifdef USE_SEPDISTANCE_UTIL2
-	btConvexSeparatingDistanceUtil	m_sepDistance;
+	btConvexSeparatingDistanceUtil m_sepDistance;
 #endif
 #endif
 	btConvexPenetrationDepthSolver* m_pdSolver;
 	btConvexPenetrationDepthSolver* m_pdSolver;
 
 
 	btVertexArray worldVertsB1;
 	btVertexArray worldVertsB1;
 	btVertexArray worldVertsB2;
 	btVertexArray worldVertsB2;
-	
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	bool			m_lowLevelOfDetail;
-	
+
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+	bool m_lowLevelOfDetail;
+
 	int m_numPerturbationIterations;
 	int m_numPerturbationIterations;
 	int m_minimumPointsPerturbationThreshold;
 	int m_minimumPointsPerturbationThreshold;
 
 
-
 	///cache separating vector to speedup collision detection
 	///cache separating vector to speedup collision detection
-	
 
 
 public:
 public:
-
-	btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
+	btConvexConvexAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
 
 
 	virtual ~btConvexConvexAlgorithm();
 	virtual ~btConvexConvexAlgorithm();
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		///should we use m_ownManifold to avoid adding duplicates?
 		///should we use m_ownManifold to avoid adding duplicates?
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 			manifoldArray.push_back(m_manifoldPtr);
 			manifoldArray.push_back(m_manifoldPtr);
 	}
 	}
 
 
+	void setLowLevelOfDetail(bool useLowLevel);
 
 
-	void	setLowLevelOfDetail(bool useLowLevel);
-
-
-	const btPersistentManifold*	getManifold()
+	const btPersistentManifold* getManifold()
 	{
 	{
 		return m_manifoldPtr;
 		return m_manifoldPtr;
 	}
 	}
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-
-		btConvexPenetrationDepthSolver*		m_pdSolver;
+		btConvexPenetrationDepthSolver* m_pdSolver;
 		int m_numPerturbationIterations;
 		int m_numPerturbationIterations;
 		int m_minimumPointsPerturbationThreshold;
 		int m_minimumPointsPerturbationThreshold;
 
 
 		CreateFunc(btConvexPenetrationDepthSolver* pdSolver);
 		CreateFunc(btConvexPenetrationDepthSolver* pdSolver);
-		
+
 		virtual ~CreateFunc();
 		virtual ~CreateFunc();
 
 
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConvexAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConvexAlgorithm));
-			return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+			return new (mem) btConvexConvexAlgorithm(ci.m_manifold, ci, body0Wrap, body1Wrap, m_pdSolver, m_numPerturbationIterations, m_minimumPointsPerturbationThreshold);
 		}
 		}
 	};
 	};
-
-
 };
 };
 
 
-#endif //BT_CONVEX_CONVEX_ALGORITHM_H
+#endif  //BT_CONVEX_CONVEX_ALGORITHM_H

+ 47 - 49
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp

@@ -23,25 +23,24 @@ subject to the following restrictions:
 
 
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
-: btCollisionAlgorithm(ci),
-m_ownManifold(false),
-m_manifoldPtr(mf),
-m_isSwapped(isSwapped),
-m_numPerturbationIterations(numPerturbationIterations),
-m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
+btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap, bool isSwapped, int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+	: btCollisionAlgorithm(ci),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf),
+	  m_isSwapped(isSwapped),
+	  m_numPerturbationIterations(numPerturbationIterations),
+	  m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 {
 {
-	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? col1Wrap : col0Wrap;
-	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? col0Wrap : col1Wrap;
+	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped ? col1Wrap : col0Wrap;
+	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped ? col0Wrap : col1Wrap;
 
 
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObjWrap->getCollisionObject(),planeObjWrap->getCollisionObject()))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObjWrap->getCollisionObject(), planeObjWrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(convexObjWrap->getCollisionObject(),planeObjWrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(convexObjWrap->getCollisionObject(), planeObjWrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
 
 
-
 btConvexPlaneCollisionAlgorithm::~btConvexPlaneCollisionAlgorithm()
 btConvexPlaneCollisionAlgorithm::~btConvexPlaneCollisionAlgorithm()
 {
 {
 	if (m_ownManifold)
 	if (m_ownManifold)
@@ -51,32 +50,32 @@ btConvexPlaneCollisionAlgorithm::~btConvexPlaneCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexPlaneCollisionAlgorithm::collideSingleContact(const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
-    const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? body1Wrap : body0Wrap;
-	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? body0Wrap: body1Wrap;
+	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
 
-	btConvexShape* convexShape = (btConvexShape*) convexObjWrap->getCollisionShape();
-	btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObjWrap->getCollisionShape();
+	btConvexShape* convexShape = (btConvexShape*)convexObjWrap->getCollisionShape();
+	btStaticPlaneShape* planeShape = (btStaticPlaneShape*)planeObjWrap->getCollisionShape();
 
 
-    bool hasCollision = false;
+	bool hasCollision = false;
 	const btVector3& planeNormal = planeShape->getPlaneNormal();
 	const btVector3& planeNormal = planeShape->getPlaneNormal();
 	const btScalar& planeConstant = planeShape->getPlaneConstant();
 	const btScalar& planeConstant = planeShape->getPlaneConstant();
-	
+
 	btTransform convexWorldTransform = convexObjWrap->getWorldTransform();
 	btTransform convexWorldTransform = convexObjWrap->getWorldTransform();
 	btTransform convexInPlaneTrans;
 	btTransform convexInPlaneTrans;
-	convexInPlaneTrans= planeObjWrap->getWorldTransform().inverse() * convexWorldTransform;
+	convexInPlaneTrans = planeObjWrap->getWorldTransform().inverse() * convexWorldTransform;
 	//now perturbe the convex-world transform
 	//now perturbe the convex-world transform
-	convexWorldTransform.getBasis()*=btMatrix3x3(perturbeRot);
+	convexWorldTransform.getBasis() *= btMatrix3x3(perturbeRot);
 	btTransform planeInConvex;
 	btTransform planeInConvex;
-	planeInConvex= convexWorldTransform.inverse() * planeObjWrap->getWorldTransform();
-	
-	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
+	planeInConvex = convexWorldTransform.inverse() * planeObjWrap->getWorldTransform();
+
+	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis() * -planeNormal);
 
 
 	btVector3 vtxInPlane = convexInPlaneTrans(vtx);
 	btVector3 vtxInPlane = convexInPlaneTrans(vtx);
 	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 
 
-	btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
+	btVector3 vtxInPlaneProjected = vtxInPlane - distance * planeNormal;
 	btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 	btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 
 
 	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
 	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
@@ -86,70 +85,69 @@ void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion&
 		/// report a contact. internally this will be kept persistent, and contact reduction is done
 		/// report a contact. internally this will be kept persistent, and contact reduction is done
 		btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
 		btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
 		btVector3 pOnB = vtxInPlaneWorld;
 		btVector3 pOnB = vtxInPlaneWorld;
-		resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
+		resultOut->addContactPoint(normalOnSurfaceB, pOnB, distance);
 	}
 	}
 }
 }
 
 
-
-void btConvexPlaneCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexPlaneCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)dispatchInfo;
 	(void)dispatchInfo;
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 		return;
 		return;
 
 
-	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? body1Wrap : body0Wrap;
-	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? body0Wrap: body1Wrap;
+	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
 
-	btConvexShape* convexShape = (btConvexShape*) convexObjWrap->getCollisionShape();
-	btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObjWrap->getCollisionShape();
+	btConvexShape* convexShape = (btConvexShape*)convexObjWrap->getCollisionShape();
+	btStaticPlaneShape* planeShape = (btStaticPlaneShape*)planeObjWrap->getCollisionShape();
 
 
 	bool hasCollision = false;
 	bool hasCollision = false;
 	const btVector3& planeNormal = planeShape->getPlaneNormal();
 	const btVector3& planeNormal = planeShape->getPlaneNormal();
 	const btScalar& planeConstant = planeShape->getPlaneConstant();
 	const btScalar& planeConstant = planeShape->getPlaneConstant();
 	btTransform planeInConvex;
 	btTransform planeInConvex;
-	planeInConvex= convexObjWrap->getWorldTransform().inverse() * planeObjWrap->getWorldTransform();
+	planeInConvex = convexObjWrap->getWorldTransform().inverse() * planeObjWrap->getWorldTransform();
 	btTransform convexInPlaneTrans;
 	btTransform convexInPlaneTrans;
-	convexInPlaneTrans= planeObjWrap->getWorldTransform().inverse() * convexObjWrap->getWorldTransform();
+	convexInPlaneTrans = planeObjWrap->getWorldTransform().inverse() * convexObjWrap->getWorldTransform();
 
 
-	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
+	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis() * -planeNormal);
 	btVector3 vtxInPlane = convexInPlaneTrans(vtx);
 	btVector3 vtxInPlane = convexInPlaneTrans(vtx);
 	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 
 
-	btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
+	btVector3 vtxInPlaneProjected = vtxInPlane - distance * planeNormal;
 	btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 	btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 
 
-	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
+	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold()+ resultOut->m_closestPointDistanceThreshold;
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	if (hasCollision)
 	if (hasCollision)
 	{
 	{
 		/// report a contact. internally this will be kept persistent, and contact reduction is done
 		/// report a contact. internally this will be kept persistent, and contact reduction is done
 		btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
 		btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
 		btVector3 pOnB = vtxInPlaneWorld;
 		btVector3 pOnB = vtxInPlaneWorld;
-		resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
+		resultOut->addContactPoint(normalOnSurfaceB, pOnB, distance);
 	}
 	}
 
 
 	//the perturbation algorithm doesn't work well with implicit surfaces such as spheres, cylinder and cones:
 	//the perturbation algorithm doesn't work well with implicit surfaces such as spheres, cylinder and cones:
 	//they keep on rolling forever because of the additional off-center contact points
 	//they keep on rolling forever because of the additional off-center contact points
 	//so only enable the feature for polyhedral shapes (btBoxShape, btConvexHullShape etc)
 	//so only enable the feature for polyhedral shapes (btBoxShape, btConvexHullShape etc)
-	if (convexShape->isPolyhedral() && resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold)
+	if (convexShape->isPolyhedral() && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)
 	{
 	{
-		btVector3 v0,v1;
-		btPlaneSpace1(planeNormal,v0,v1);
+		btVector3 v0, v1;
+		btPlaneSpace1(planeNormal, v0, v1);
 		//now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
 		//now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
 
 
 		const btScalar angleLimit = 0.125f * SIMD_PI;
 		const btScalar angleLimit = 0.125f * SIMD_PI;
 		btScalar perturbeAngle;
 		btScalar perturbeAngle;
 		btScalar radius = convexShape->getAngularMotionDisc();
 		btScalar radius = convexShape->getAngularMotionDisc();
 		perturbeAngle = gContactBreakingThreshold / radius;
 		perturbeAngle = gContactBreakingThreshold / radius;
-		if ( perturbeAngle > angleLimit ) 
-				perturbeAngle = angleLimit;
+		if (perturbeAngle > angleLimit)
+			perturbeAngle = angleLimit;
 
 
-		btQuaternion perturbeRot(v0,perturbeAngle);
-		for (int i=0;i<m_numPerturbationIterations;i++)
+		btQuaternion perturbeRot(v0, perturbeAngle);
+		for (int i = 0; i < m_numPerturbationIterations; i++)
 		{
 		{
-			btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
-			btQuaternion rotq(planeNormal,iterationAngle);
-			collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0Wrap,body1Wrap,dispatchInfo,resultOut);
+			btScalar iterationAngle = i * (SIMD_2_PI / btScalar(m_numPerturbationIterations));
+			btQuaternion rotq(planeNormal, iterationAngle);
+			collideSingleContact(rotq.inverse() * perturbeRot * rotq, body0Wrap, body1Wrap, dispatchInfo, resultOut);
 		}
 		}
 	}
 	}
 
 
@@ -162,7 +160,7 @@ void btConvexPlaneCollisionAlgorithm::processCollision (const btCollisionObjectW
 	}
 	}
 }
 }
 
 
-btScalar btConvexPlaneCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btConvexPlaneCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, btCollisionObject* col1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)resultOut;
 	(void)resultOut;
 	(void)dispatchInfo;
 	(void)dispatchInfo;

+ 22 - 24
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h

@@ -28,25 +28,24 @@ class btPersistentManifold;
 /// Other features are frame-coherency (persistent data) and collision response.
 /// Other features are frame-coherency (persistent data) and collision response.
 class btConvexPlaneCollisionAlgorithm : public btCollisionAlgorithm
 class btConvexPlaneCollisionAlgorithm : public btCollisionAlgorithm
 {
 {
-	bool		m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	bool		m_isSwapped;
-	int			m_numPerturbationIterations;
-	int			m_minimumPointsPerturbationThreshold;
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+	bool m_isSwapped;
+	int m_numPerturbationIterations;
+	int m_minimumPointsPerturbationThreshold;
 
 
 public:
 public:
-
-	btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold);
+	btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
 
 
 	virtual ~btConvexPlaneCollisionAlgorithm();
 	virtual ~btConvexPlaneCollisionAlgorithm();
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	void collideSingleContact (const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	void collideSingleContact(const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 		{
 		{
@@ -54,31 +53,30 @@ public:
 		}
 		}
 	}
 	}
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		int	m_numPerturbationIterations;
+		int m_numPerturbationIterations;
 		int m_minimumPointsPerturbationThreshold;
 		int m_minimumPointsPerturbationThreshold;
-			
-		CreateFunc() 
+
+		CreateFunc()
 			: m_numPerturbationIterations(1),
 			: m_numPerturbationIterations(1),
-			m_minimumPointsPerturbationThreshold(0)
+			  m_minimumPointsPerturbationThreshold(0)
 		{
 		{
 		}
 		}
-		
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexPlaneCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexPlaneCollisionAlgorithm));
 			if (!m_swapped)
 			if (!m_swapped)
 			{
 			{
-				return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
-			} else
+				return new (mem) btConvexPlaneCollisionAlgorithm(0, ci, body0Wrap, body1Wrap, false, m_numPerturbationIterations, m_minimumPointsPerturbationThreshold);
+			}
+			else
 			{
 			{
-				return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+				return new (mem) btConvexPlaneCollisionAlgorithm(0, ci, body0Wrap, body1Wrap, true, m_numPerturbationIterations, m_minimumPointsPerturbationThreshold);
 			}
 			}
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
-
+#endif  //BT_CONVEX_PLANE_COLLISION_ALGORITHM_H

+ 99 - 120
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp

@@ -26,114 +26,108 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 #include "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h"
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
+#endif  //USE_BUGGY_SPHERE_BOX_ALGORITHM
 #include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
 
 
-
-
 #include "LinearMath/btPoolAllocator.h"
 #include "LinearMath/btPoolAllocator.h"
 
 
-
-
-
-
 btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
 btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo)
 //btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc*	stackAlloc,btPoolAllocator*	persistentManifoldPool,btPoolAllocator*	collisionAlgorithmPool)
 //btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc*	stackAlloc,btPoolAllocator*	persistentManifoldPool,btPoolAllocator*	collisionAlgorithmPool)
 {
 {
-
-    void* mem = NULL;
+	void* mem = NULL;
 	if (constructionInfo.m_useEpaPenetrationAlgorithm)
 	if (constructionInfo.m_useEpaPenetrationAlgorithm)
 	{
 	{
-		mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
-		m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;
-	}else
+		mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver), 16);
+		m_pdSolver = new (mem) btGjkEpaPenetrationDepthSolver;
+	}
+	else
 	{
 	{
-		mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);
-		m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;
+		mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver), 16);
+		m_pdSolver = new (mem) btMinkowskiPenetrationDepthSolver;
 	}
 	}
-	
+
 	//default CreationFunctions, filling the m_doubleDispatch table
 	//default CreationFunctions, filling the m_doubleDispatch table
-	mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16);
-	m_convexConvexCreateFunc = new(mem) btConvexConvexAlgorithm::CreateFunc(m_pdSolver);
-	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
-	m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc;
-	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
-	m_swappedConvexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
-	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc),16);
-	m_compoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::CreateFunc;
-
-	mem = btAlignedAlloc(sizeof(btCompoundCompoundCollisionAlgorithm::CreateFunc),16);
-	m_compoundCompoundCreateFunc = new (mem)btCompoundCompoundCollisionAlgorithm::CreateFunc;
-
-	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc),16);
-	m_swappedCompoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::SwappedCreateFunc;
-	mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc),16);
-	m_emptyCreateFunc = new(mem) btEmptyAlgorithm::CreateFunc;
-	
-	mem = btAlignedAlloc(sizeof(btSphereSphereCollisionAlgorithm::CreateFunc),16);
-	m_sphereSphereCF = new(mem) btSphereSphereCollisionAlgorithm::CreateFunc;
+	mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc), 16);
+	m_convexConvexCreateFunc = new (mem) btConvexConvexAlgorithm::CreateFunc(m_pdSolver);
+	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc), 16);
+	m_convexConcaveCreateFunc = new (mem) btConvexConcaveCollisionAlgorithm::CreateFunc;
+	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc), 16);
+	m_swappedConvexConcaveCreateFunc = new (mem) btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
+	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc), 16);
+	m_compoundCreateFunc = new (mem) btCompoundCollisionAlgorithm::CreateFunc;
+
+	mem = btAlignedAlloc(sizeof(btCompoundCompoundCollisionAlgorithm::CreateFunc), 16);
+	m_compoundCompoundCreateFunc = new (mem) btCompoundCompoundCollisionAlgorithm::CreateFunc;
+
+	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc), 16);
+	m_swappedCompoundCreateFunc = new (mem) btCompoundCollisionAlgorithm::SwappedCreateFunc;
+	mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc), 16);
+	m_emptyCreateFunc = new (mem) btEmptyAlgorithm::CreateFunc;
+
+	mem = btAlignedAlloc(sizeof(btSphereSphereCollisionAlgorithm::CreateFunc), 16);
+	m_sphereSphereCF = new (mem) btSphereSphereCollisionAlgorithm::CreateFunc;
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
-	mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16);
-	m_sphereBoxCF = new(mem) btSphereBoxCollisionAlgorithm::CreateFunc;
-	mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc),16);
-	m_boxSphereCF = new (mem)btSphereBoxCollisionAlgorithm::CreateFunc;
+	mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc), 16);
+	m_sphereBoxCF = new (mem) btSphereBoxCollisionAlgorithm::CreateFunc;
+	mem = btAlignedAlloc(sizeof(btSphereBoxCollisionAlgorithm::CreateFunc), 16);
+	m_boxSphereCF = new (mem) btSphereBoxCollisionAlgorithm::CreateFunc;
 	m_boxSphereCF->m_swapped = true;
 	m_boxSphereCF->m_swapped = true;
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
+#endif  //USE_BUGGY_SPHERE_BOX_ALGORITHM
 
 
-	mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16);
-	m_sphereTriangleCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc;
-	mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc),16);
-	m_triangleSphereCF = new (mem)btSphereTriangleCollisionAlgorithm::CreateFunc;
+	mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc), 16);
+	m_sphereTriangleCF = new (mem) btSphereTriangleCollisionAlgorithm::CreateFunc;
+	mem = btAlignedAlloc(sizeof(btSphereTriangleCollisionAlgorithm::CreateFunc), 16);
+	m_triangleSphereCF = new (mem) btSphereTriangleCollisionAlgorithm::CreateFunc;
 	m_triangleSphereCF->m_swapped = true;
 	m_triangleSphereCF->m_swapped = true;
-	
-	mem = btAlignedAlloc(sizeof(btBoxBoxCollisionAlgorithm::CreateFunc),16);
-	m_boxBoxCF = new(mem)btBoxBoxCollisionAlgorithm::CreateFunc;
+
+	mem = btAlignedAlloc(sizeof(btBoxBoxCollisionAlgorithm::CreateFunc), 16);
+	m_boxBoxCF = new (mem) btBoxBoxCollisionAlgorithm::CreateFunc;
 
 
 	//convex versus plane
 	//convex versus plane
-	mem = btAlignedAlloc (sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc),16);
+	mem = btAlignedAlloc(sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc), 16);
 	m_convexPlaneCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc;
 	m_convexPlaneCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc;
-	mem = btAlignedAlloc (sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc),16);
+	mem = btAlignedAlloc(sizeof(btConvexPlaneCollisionAlgorithm::CreateFunc), 16);
 	m_planeConvexCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc;
 	m_planeConvexCF = new (mem) btConvexPlaneCollisionAlgorithm::CreateFunc;
 	m_planeConvexCF->m_swapped = true;
 	m_planeConvexCF->m_swapped = true;
-	
+
 	///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
 	///calculate maximum element size, big enough to fit any collision algorithm in the memory pool
 	int maxSize = sizeof(btConvexConvexAlgorithm);
 	int maxSize = sizeof(btConvexConvexAlgorithm);
 	int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
 	int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
 	int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
 	int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
 	int maxSize4 = sizeof(btCompoundCompoundCollisionAlgorithm);
 	int maxSize4 = sizeof(btCompoundCompoundCollisionAlgorithm);
 
 
-	int	collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
-	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
-	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
-	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize4);
-		
+	int collisionAlgorithmMaxElementSize = btMax(maxSize, constructionInfo.m_customCollisionAlgorithmMaxElementSize);
+	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize2);
+	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize3);
+	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize, maxSize4);
+
 	if (constructionInfo.m_persistentManifoldPool)
 	if (constructionInfo.m_persistentManifoldPool)
 	{
 	{
 		m_ownsPersistentManifoldPool = false;
 		m_ownsPersistentManifoldPool = false;
 		m_persistentManifoldPool = constructionInfo.m_persistentManifoldPool;
 		m_persistentManifoldPool = constructionInfo.m_persistentManifoldPool;
-	} else
+	}
+	else
 	{
 	{
 		m_ownsPersistentManifoldPool = true;
 		m_ownsPersistentManifoldPool = true;
-		void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
-		m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
+		void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
+		m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold), constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
 	}
 	}
-	
-	collisionAlgorithmMaxElementSize = (collisionAlgorithmMaxElementSize+16)&0xffffffffffff0;
+
+	collisionAlgorithmMaxElementSize = (collisionAlgorithmMaxElementSize + 16) & 0xffffffffffff0;
 	if (constructionInfo.m_collisionAlgorithmPool)
 	if (constructionInfo.m_collisionAlgorithmPool)
 	{
 	{
 		m_ownsCollisionAlgorithmPool = false;
 		m_ownsCollisionAlgorithmPool = false;
 		m_collisionAlgorithmPool = constructionInfo.m_collisionAlgorithmPool;
 		m_collisionAlgorithmPool = constructionInfo.m_collisionAlgorithmPool;
-	} else
+	}
+	else
 	{
 	{
 		m_ownsCollisionAlgorithmPool = true;
 		m_ownsCollisionAlgorithmPool = true;
-		void* mem = btAlignedAlloc(sizeof(btPoolAllocator),16);
-		m_collisionAlgorithmPool = new(mem) btPoolAllocator(collisionAlgorithmMaxElementSize,constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
+		void* mem = btAlignedAlloc(sizeof(btPoolAllocator), 16);
+		m_collisionAlgorithmPool = new (mem) btPoolAllocator(collisionAlgorithmMaxElementSize, constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize);
 	}
 	}
-
-
 }
 }
 
 
 btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
@@ -150,83 +144,78 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 	}
 	}
 
 
 	m_convexConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_convexConvexCreateFunc->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree(	m_convexConvexCreateFunc);
+	btAlignedFree(m_convexConvexCreateFunc);
 
 
 	m_convexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_convexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_convexConcaveCreateFunc);
+	btAlignedFree(m_convexConcaveCreateFunc);
 	m_swappedConvexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_swappedConvexConcaveCreateFunc->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_swappedConvexConcaveCreateFunc);
+	btAlignedFree(m_swappedConvexConcaveCreateFunc);
 
 
 	m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_compoundCreateFunc);
+	btAlignedFree(m_compoundCreateFunc);
 
 
 	m_compoundCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_compoundCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	btAlignedFree(m_compoundCompoundCreateFunc);
 	btAlignedFree(m_compoundCompoundCreateFunc);
 
 
 	m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_swappedCompoundCreateFunc);
+	btAlignedFree(m_swappedCompoundCreateFunc);
 
 
 	m_emptyCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_emptyCreateFunc->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_emptyCreateFunc);
+	btAlignedFree(m_emptyCreateFunc);
 
 
 	m_sphereSphereCF->~btCollisionAlgorithmCreateFunc();
 	m_sphereSphereCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_sphereSphereCF);
+	btAlignedFree(m_sphereSphereCF);
 
 
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 	m_sphereBoxCF->~btCollisionAlgorithmCreateFunc();
 	m_sphereBoxCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_sphereBoxCF);
+	btAlignedFree(m_sphereBoxCF);
 	m_boxSphereCF->~btCollisionAlgorithmCreateFunc();
 	m_boxSphereCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_boxSphereCF);
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
+	btAlignedFree(m_boxSphereCF);
+#endif  //USE_BUGGY_SPHERE_BOX_ALGORITHM
 
 
 	m_sphereTriangleCF->~btCollisionAlgorithmCreateFunc();
 	m_sphereTriangleCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_sphereTriangleCF);
+	btAlignedFree(m_sphereTriangleCF);
 	m_triangleSphereCF->~btCollisionAlgorithmCreateFunc();
 	m_triangleSphereCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_triangleSphereCF);
+	btAlignedFree(m_triangleSphereCF);
 	m_boxBoxCF->~btCollisionAlgorithmCreateFunc();
 	m_boxBoxCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_boxBoxCF);
+	btAlignedFree(m_boxBoxCF);
 
 
 	m_convexPlaneCF->~btCollisionAlgorithmCreateFunc();
 	m_convexPlaneCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_convexPlaneCF);
+	btAlignedFree(m_convexPlaneCF);
 	m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
 	m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
-	btAlignedFree( m_planeConvexCF);
+	btAlignedFree(m_planeConvexCF);
 
 
 	m_pdSolver->~btConvexPenetrationDepthSolver();
 	m_pdSolver->~btConvexPenetrationDepthSolver();
-	
-	btAlignedFree(m_pdSolver);
-
 
 
+	btAlignedFree(m_pdSolver);
 }
 }
 
 
 btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1)
 btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1)
 {
 {
-
-
 	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_sphereSphereCF;
+		return m_sphereSphereCF;
 	}
 	}
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
 	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_sphereBoxCF;
+		return m_sphereBoxCF;
 	}
 	}
 
 
 	if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_boxSphereCF;
+		return m_boxSphereCF;
 	}
 	}
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
-
+#endif  //USE_BUGGY_SPHERE_BOX_ALGORITHM
 
 
 	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_SHAPE_PROXYTYPE))
 	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_sphereTriangleCF;
+		return m_sphereTriangleCF;
 	}
 	}
 
 
 	if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_triangleSphereCF;
+		return m_triangleSphereCF;
 	}
 	}
 
 
 	if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
 	if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
@@ -239,8 +228,6 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getClosestPoint
 		return m_planeConvexCF;
 		return m_planeConvexCF;
 	}
 	}
 
 
-
-
 	if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
 	if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
 	{
 	{
 		return m_convexConvexCreateFunc;
 		return m_convexConvexCreateFunc;
@@ -256,7 +243,6 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getClosestPoint
 		return m_swappedConvexConcaveCreateFunc;
 		return m_swappedConvexConcaveCreateFunc;
 	}
 	}
 
 
-
 	if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
 	if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
 	{
 	{
 		return m_compoundCompoundCreateFunc;
 		return m_compoundCompoundCreateFunc;
@@ -276,46 +262,41 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getClosestPoint
 
 
 	//failed to find an algorithm
 	//failed to find an algorithm
 	return m_emptyCreateFunc;
 	return m_emptyCreateFunc;
-
 }
 }
 
 
-btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
+btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1)
 {
 {
-
-
-
-	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
+	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_sphereSphereCF;
+		return m_sphereSphereCF;
 	}
 	}
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 #ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
-	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1==BOX_SHAPE_PROXYTYPE))
+	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_sphereBoxCF;
+		return m_sphereBoxCF;
 	}
 	}
 
 
-	if ((proxyType0 == BOX_SHAPE_PROXYTYPE ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
+	if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_boxSphereCF;
+		return m_boxSphereCF;
 	}
 	}
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
-
+#endif  //USE_BUGGY_SPHERE_BOX_ALGORITHM
 
 
-	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE ) && (proxyType1==TRIANGLE_SHAPE_PROXYTYPE))
+	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_sphereTriangleCF;
+		return m_sphereTriangleCF;
 	}
 	}
 
 
-	if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE  ) && (proxyType1==SPHERE_SHAPE_PROXYTYPE))
+	if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
 	{
 	{
-		return	m_triangleSphereCF;
-	} 
+		return m_triangleSphereCF;
+	}
 
 
 	if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
 	if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
 	{
 	{
 		return m_boxBoxCF;
 		return m_boxBoxCF;
 	}
 	}
-	
+
 	if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
 	if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
 	{
 	{
 		return m_convexPlaneCF;
 		return m_convexPlaneCF;
@@ -325,8 +306,6 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlg
 	{
 	{
 		return m_planeConvexCF;
 		return m_planeConvexCF;
 	}
 	}
-	
-
 
 
 	if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
 	if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
 	{
 	{
@@ -343,7 +322,6 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlg
 		return m_swappedConvexConcaveCreateFunc;
 		return m_swappedConvexConcaveCreateFunc;
 	}
 	}
 
 
-
 	if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
 	if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
 	{
 	{
 		return m_compoundCompoundCreateFunc;
 		return m_compoundCompoundCreateFunc;
@@ -352,7 +330,8 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlg
 	if (btBroadphaseProxy::isCompound(proxyType0))
 	if (btBroadphaseProxy::isCompound(proxyType0))
 	{
 	{
 		return m_compoundCreateFunc;
 		return m_compoundCreateFunc;
-	} else
+	}
+	else
 	{
 	{
 		if (btBroadphaseProxy::isCompound(proxyType1))
 		if (btBroadphaseProxy::isCompound(proxyType1))
 		{
 		{
@@ -366,17 +345,17 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlg
 
 
 void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
 void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
 {
 {
-	btConvexConvexAlgorithm::CreateFunc* convexConvex = (btConvexConvexAlgorithm::CreateFunc*) m_convexConvexCreateFunc;
+	btConvexConvexAlgorithm::CreateFunc* convexConvex = (btConvexConvexAlgorithm::CreateFunc*)m_convexConvexCreateFunc;
 	convexConvex->m_numPerturbationIterations = numPerturbationIterations;
 	convexConvex->m_numPerturbationIterations = numPerturbationIterations;
 	convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
 	convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
 }
 }
 
 
-void	btDefaultCollisionConfiguration::setPlaneConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+void btDefaultCollisionConfiguration::setPlaneConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
 {
 {
 	btConvexPlaneCollisionAlgorithm::CreateFunc* cpCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_convexPlaneCF;
 	btConvexPlaneCollisionAlgorithm::CreateFunc* cpCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_convexPlaneCF;
 	cpCF->m_numPerturbationIterations = numPerturbationIterations;
 	cpCF->m_numPerturbationIterations = numPerturbationIterations;
 	cpCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
 	cpCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
-	
+
 	btConvexPlaneCollisionAlgorithm::CreateFunc* pcCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_planeConvexCF;
 	btConvexPlaneCollisionAlgorithm::CreateFunc* pcCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_planeConvexCF;
 	pcCF->m_numPerturbationIterations = numPerturbationIterations;
 	pcCF->m_numPerturbationIterations = numPerturbationIterations;
 	pcCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
 	pcCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;

+ 38 - 49
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h

@@ -20,76 +20,68 @@ subject to the following restrictions:
 class btVoronoiSimplexSolver;
 class btVoronoiSimplexSolver;
 class btConvexPenetrationDepthSolver;
 class btConvexPenetrationDepthSolver;
 
 
-struct	btDefaultCollisionConstructionInfo
+struct btDefaultCollisionConstructionInfo
 {
 {
-	btPoolAllocator*	m_persistentManifoldPool;
-	btPoolAllocator*	m_collisionAlgorithmPool;
-	int					m_defaultMaxPersistentManifoldPoolSize;
-	int					m_defaultMaxCollisionAlgorithmPoolSize;
-	int					m_customCollisionAlgorithmMaxElementSize;
-	int					m_useEpaPenetrationAlgorithm;
+	btPoolAllocator* m_persistentManifoldPool;
+	btPoolAllocator* m_collisionAlgorithmPool;
+	int m_defaultMaxPersistentManifoldPoolSize;
+	int m_defaultMaxCollisionAlgorithmPoolSize;
+	int m_customCollisionAlgorithmMaxElementSize;
+	int m_useEpaPenetrationAlgorithm;
 
 
 	btDefaultCollisionConstructionInfo()
 	btDefaultCollisionConstructionInfo()
-		:m_persistentManifoldPool(0),
-		m_collisionAlgorithmPool(0),
-		m_defaultMaxPersistentManifoldPoolSize(4096),
-		m_defaultMaxCollisionAlgorithmPoolSize(4096),
-		m_customCollisionAlgorithmMaxElementSize(0),
-		m_useEpaPenetrationAlgorithm(true)
+		: m_persistentManifoldPool(0),
+		  m_collisionAlgorithmPool(0),
+		  m_defaultMaxPersistentManifoldPoolSize(4096),
+		  m_defaultMaxCollisionAlgorithmPoolSize(4096),
+		  m_customCollisionAlgorithmMaxElementSize(0),
+		  m_useEpaPenetrationAlgorithm(true)
 	{
 	{
 	}
 	}
 };
 };
 
 
-
-
 ///btCollisionConfiguration allows to configure Bullet collision detection
 ///btCollisionConfiguration allows to configure Bullet collision detection
 ///stack allocator, pool memory allocators
 ///stack allocator, pool memory allocators
 ///@todo: describe the meaning
 ///@todo: describe the meaning
-class	btDefaultCollisionConfiguration : public btCollisionConfiguration
+class btDefaultCollisionConfiguration : public btCollisionConfiguration
 {
 {
-
 protected:
 protected:
+	int m_persistentManifoldPoolSize;
 
 
-	int	m_persistentManifoldPoolSize;
-	
-
-	btPoolAllocator*	m_persistentManifoldPool;
-	bool	m_ownsPersistentManifoldPool;
+	btPoolAllocator* m_persistentManifoldPool;
+	bool m_ownsPersistentManifoldPool;
 
 
-
-	btPoolAllocator*	m_collisionAlgorithmPool;
-	bool	m_ownsCollisionAlgorithmPool;
+	btPoolAllocator* m_collisionAlgorithmPool;
+	bool m_ownsCollisionAlgorithmPool;
 
 
 	//default penetration depth solver
 	//default penetration depth solver
-	btConvexPenetrationDepthSolver*	m_pdSolver;
-	
+	btConvexPenetrationDepthSolver* m_pdSolver;
+
 	//default CreationFunctions, filling the m_doubleDispatch table
 	//default CreationFunctions, filling the m_doubleDispatch table
-	btCollisionAlgorithmCreateFunc*	m_convexConvexCreateFunc;
-	btCollisionAlgorithmCreateFunc*	m_convexConcaveCreateFunc;
-	btCollisionAlgorithmCreateFunc*	m_swappedConvexConcaveCreateFunc;
-	btCollisionAlgorithmCreateFunc*	m_compoundCreateFunc;
-	btCollisionAlgorithmCreateFunc*	m_compoundCompoundCreateFunc;
-	
-	btCollisionAlgorithmCreateFunc*	m_swappedCompoundCreateFunc;
+	btCollisionAlgorithmCreateFunc* m_convexConvexCreateFunc;
+	btCollisionAlgorithmCreateFunc* m_convexConcaveCreateFunc;
+	btCollisionAlgorithmCreateFunc* m_swappedConvexConcaveCreateFunc;
+	btCollisionAlgorithmCreateFunc* m_compoundCreateFunc;
+	btCollisionAlgorithmCreateFunc* m_compoundCompoundCreateFunc;
+
+	btCollisionAlgorithmCreateFunc* m_swappedCompoundCreateFunc;
 	btCollisionAlgorithmCreateFunc* m_emptyCreateFunc;
 	btCollisionAlgorithmCreateFunc* m_emptyCreateFunc;
 	btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
 	btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
 	btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
 	btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
 	btCollisionAlgorithmCreateFunc* m_boxSphereCF;
 	btCollisionAlgorithmCreateFunc* m_boxSphereCF;
 
 
 	btCollisionAlgorithmCreateFunc* m_boxBoxCF;
 	btCollisionAlgorithmCreateFunc* m_boxBoxCF;
-	btCollisionAlgorithmCreateFunc*	m_sphereTriangleCF;
-	btCollisionAlgorithmCreateFunc*	m_triangleSphereCF;
-	btCollisionAlgorithmCreateFunc*	m_planeConvexCF;
-	btCollisionAlgorithmCreateFunc*	m_convexPlaneCF;
-	
-public:
-
+	btCollisionAlgorithmCreateFunc* m_sphereTriangleCF;
+	btCollisionAlgorithmCreateFunc* m_triangleSphereCF;
+	btCollisionAlgorithmCreateFunc* m_planeConvexCF;
+	btCollisionAlgorithmCreateFunc* m_convexPlaneCF;
 
 
+public:
 	btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo = btDefaultCollisionConstructionInfo());
 	btDefaultCollisionConfiguration(const btDefaultCollisionConstructionInfo& constructionInfo = btDefaultCollisionConstructionInfo());
 
 
 	virtual ~btDefaultCollisionConfiguration();
 	virtual ~btDefaultCollisionConfiguration();
 
 
-		///memory pools
+	///memory pools
 	virtual btPoolAllocator* getPersistentManifoldPool()
 	virtual btPoolAllocator* getPersistentManifoldPool()
 	{
 	{
 		return m_persistentManifoldPool;
 		return m_persistentManifoldPool;
@@ -100,8 +92,7 @@ public:
 		return m_collisionAlgorithmPool;
 		return m_collisionAlgorithmPool;
 	}
 	}
 
 
-
-	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1);
+	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0, int proxyType1);
 
 
 	virtual btCollisionAlgorithmCreateFunc* getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1);
 	virtual btCollisionAlgorithmCreateFunc* getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1);
 
 
@@ -112,11 +103,9 @@ public:
 	///3 is a good value for both params, if you want to enable the feature. This is because the default contact cache contains a maximum of 4 points, and one collision query at the unperturbed orientation is performed first.
 	///3 is a good value for both params, if you want to enable the feature. This is because the default contact cache contains a maximum of 4 points, and one collision query at the unperturbed orientation is performed first.
 	///See Bullet/Demos/CollisionDemo for an example how this feature gathers multiple points.
 	///See Bullet/Demos/CollisionDemo for an example how this feature gathers multiple points.
 	///@todo we could add a per-object setting of those parameters, for level-of-detail collision detection.
 	///@todo we could add a per-object setting of those parameters, for level-of-detail collision detection.
-	void	setConvexConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold = 3);
-
-	void	setPlaneConvexMultipointIterations(int numPerturbationIterations=3, int minimumPointsPerturbationThreshold = 3);
+	void setConvexConvexMultipointIterations(int numPerturbationIterations = 3, int minimumPointsPerturbationThreshold = 3);
 
 
+	void setPlaneConvexMultipointIterations(int numPerturbationIterations = 3, int minimumPointsPerturbationThreshold = 3);
 };
 };
 
 
-#endif //BT_DEFAULT_COLLISION_CONFIGURATION
-
+#endif  //BT_DEFAULT_COLLISION_CONFIGURATION

+ 2 - 6
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp

@@ -15,20 +15,16 @@ subject to the following restrictions:
 
 
 #include "btEmptyCollisionAlgorithm.h"
 #include "btEmptyCollisionAlgorithm.h"
 
 
-
-
 btEmptyAlgorithm::btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 btEmptyAlgorithm::btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	: btCollisionAlgorithm(ci)
 	: btCollisionAlgorithm(ci)
 {
 {
 }
 }
 
 
-void btEmptyAlgorithm::processCollision (const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* ,const btDispatcherInfo& ,btManifoldResult* )
+void btEmptyAlgorithm::processCollision(const btCollisionObjectWrapper*, const btCollisionObjectWrapper*, const btDispatcherInfo&, btManifoldResult*)
 {
 {
 }
 }
 
 
-btScalar btEmptyAlgorithm::calculateTimeOfImpact(btCollisionObject* ,btCollisionObject* ,const btDispatcherInfo& ,btManifoldResult* )
+btScalar btEmptyAlgorithm::calculateTimeOfImpact(btCollisionObject*, btCollisionObject*, const btDispatcherInfo&, btManifoldResult*)
 {
 {
 	return btScalar(1.);
 	return btScalar(1.);
 }
 }
-
-

+ 8 - 10
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h

@@ -25,30 +25,28 @@ subject to the following restrictions:
 ///The dispatcher can dispatch a persistent btEmptyAlgorithm to avoid a search every frame.
 ///The dispatcher can dispatch a persistent btEmptyAlgorithm to avoid a search every frame.
 class btEmptyAlgorithm : public btCollisionAlgorithm
 class btEmptyAlgorithm : public btCollisionAlgorithm
 {
 {
-
 public:
 public:
-	
 	btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 	btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 	}
 	}
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-        virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
-        {
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
+		{
 			(void)body0Wrap;
 			(void)body0Wrap;
 			(void)body1Wrap;
 			(void)body1Wrap;
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btEmptyAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btEmptyAlgorithm));
-			return new(mem) btEmptyAlgorithm(ci);
+			return new (mem) btEmptyAlgorithm(ci);
 		}
 		}
 	};
 	};
 
 
 } ATTRIBUTE_ALIGNED(16);
 } ATTRIBUTE_ALIGNED(16);
 
 
-#endif //BT_EMPTY_ALGORITH
+#endif  //BT_EMPTY_ALGORITH

+ 46 - 51
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btGhostObject.cpp

@@ -29,60 +29,58 @@ btGhostObject::~btGhostObject()
 	btAssert(!m_overlappingObjects.size());
 	btAssert(!m_overlappingObjects.size());
 }
 }
 
 
-
-void btGhostObject::addOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btBroadphaseProxy* thisProxy)
+void btGhostObject::addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy)
 {
 {
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btAssert(otherObject);
 	btAssert(otherObject);
 	///if this linearSearch becomes too slow (too many overlapping objects) we should add a more appropriate data structure
 	///if this linearSearch becomes too slow (too many overlapping objects) we should add a more appropriate data structure
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
-	if (index==m_overlappingObjects.size())
+	if (index == m_overlappingObjects.size())
 	{
 	{
 		//not found
 		//not found
 		m_overlappingObjects.push_back(otherObject);
 		m_overlappingObjects.push_back(otherObject);
 	}
 	}
 }
 }
 
 
-void btGhostObject::removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy)
+void btGhostObject::removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btDispatcher* dispatcher, btBroadphaseProxy* thisProxy)
 {
 {
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btAssert(otherObject);
 	btAssert(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
-	if (index<m_overlappingObjects.size())
+	if (index < m_overlappingObjects.size())
 	{
 	{
-		m_overlappingObjects[index] = m_overlappingObjects[m_overlappingObjects.size()-1];
+		m_overlappingObjects[index] = m_overlappingObjects[m_overlappingObjects.size() - 1];
 		m_overlappingObjects.pop_back();
 		m_overlappingObjects.pop_back();
 	}
 	}
 }
 }
 
 
-
 btPairCachingGhostObject::btPairCachingGhostObject()
 btPairCachingGhostObject::btPairCachingGhostObject()
 {
 {
-	m_hashPairCache = new (btAlignedAlloc(sizeof(btHashedOverlappingPairCache),16)) btHashedOverlappingPairCache();
+	m_hashPairCache = new (btAlignedAlloc(sizeof(btHashedOverlappingPairCache), 16)) btHashedOverlappingPairCache();
 }
 }
 
 
 btPairCachingGhostObject::~btPairCachingGhostObject()
 btPairCachingGhostObject::~btPairCachingGhostObject()
 {
 {
 	m_hashPairCache->~btHashedOverlappingPairCache();
 	m_hashPairCache->~btHashedOverlappingPairCache();
-	btAlignedFree( m_hashPairCache );
+	btAlignedFree(m_hashPairCache);
 }
 }
 
 
-void btPairCachingGhostObject::addOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btBroadphaseProxy* thisProxy)
+void btPairCachingGhostObject::addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy)
 {
 {
-	btBroadphaseProxy*actualThisProxy = thisProxy ? thisProxy : getBroadphaseHandle();
+	btBroadphaseProxy* actualThisProxy = thisProxy ? thisProxy : getBroadphaseHandle();
 	btAssert(actualThisProxy);
 	btAssert(actualThisProxy);
 
 
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btAssert(otherObject);
 	btAssert(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
-	if (index==m_overlappingObjects.size())
+	if (index == m_overlappingObjects.size())
 	{
 	{
 		m_overlappingObjects.push_back(otherObject);
 		m_overlappingObjects.push_back(otherObject);
-		m_hashPairCache->addOverlappingPair(actualThisProxy,otherProxy);
+		m_hashPairCache->addOverlappingPair(actualThisProxy, otherProxy);
 	}
 	}
 }
 }
 
 
-void btPairCachingGhostObject::removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy1)
+void btPairCachingGhostObject::removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btDispatcher* dispatcher, btBroadphaseProxy* thisProxy1)
 {
 {
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btCollisionObject* otherObject = (btCollisionObject*)otherProxy->m_clientObject;
 	btBroadphaseProxy* actualThisProxy = thisProxy1 ? thisProxy1 : getBroadphaseHandle();
 	btBroadphaseProxy* actualThisProxy = thisProxy1 ? thisProxy1 : getBroadphaseHandle();
@@ -90,82 +88,79 @@ void btPairCachingGhostObject::removeOverlappingObjectInternal(btBroadphaseProxy
 
 
 	btAssert(otherObject);
 	btAssert(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
 	int index = m_overlappingObjects.findLinearSearch(otherObject);
-	if (index<m_overlappingObjects.size())
+	if (index < m_overlappingObjects.size())
 	{
 	{
-		m_overlappingObjects[index] = m_overlappingObjects[m_overlappingObjects.size()-1];
+		m_overlappingObjects[index] = m_overlappingObjects[m_overlappingObjects.size() - 1];
 		m_overlappingObjects.pop_back();
 		m_overlappingObjects.pop_back();
-		m_hashPairCache->removeOverlappingPair(actualThisProxy,otherProxy,dispatcher);
+		m_hashPairCache->removeOverlappingPair(actualThisProxy, otherProxy, dispatcher);
 	}
 	}
 }
 }
 
 
-
-void	btGhostObject::convexSweepTest(const btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, btCollisionWorld::ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration) const
+void btGhostObject::convexSweepTest(const btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, btCollisionWorld::ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration) const
 {
 {
-	btTransform	convexFromTrans,convexToTrans;
+	btTransform convexFromTrans, convexToTrans;
 	convexFromTrans = convexFromWorld;
 	convexFromTrans = convexFromWorld;
 	convexToTrans = convexToWorld;
 	convexToTrans = convexToWorld;
 	btVector3 castShapeAabbMin, castShapeAabbMax;
 	btVector3 castShapeAabbMin, castShapeAabbMax;
 	/* Compute AABB that encompasses angular movement */
 	/* Compute AABB that encompasses angular movement */
 	{
 	{
 		btVector3 linVel, angVel;
 		btVector3 linVel, angVel;
-		btTransformUtil::calculateVelocity (convexFromTrans, convexToTrans, 1.0, linVel, angVel);
+		btTransformUtil::calculateVelocity(convexFromTrans, convexToTrans, 1.0, linVel, angVel);
 		btTransform R;
 		btTransform R;
-		R.setIdentity ();
-		R.setRotation (convexFromTrans.getRotation());
-		castShape->calculateTemporalAabb (R, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
+		R.setIdentity();
+		R.setRotation(convexFromTrans.getRotation());
+		castShape->calculateTemporalAabb(R, linVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
 	}
 	}
 
 
 	/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
 	/// go over all objects, and if the ray intersects their aabb + cast shape aabb,
 	// do a ray-shape query using convexCaster (CCD)
 	// do a ray-shape query using convexCaster (CCD)
 	int i;
 	int i;
-	for (i=0;i<m_overlappingObjects.size();i++)
+	for (i = 0; i < m_overlappingObjects.size(); i++)
 	{
 	{
-		btCollisionObject*	collisionObject= m_overlappingObjects[i];
+		btCollisionObject* collisionObject = m_overlappingObjects[i];
 		//only perform raycast if filterMask matches
 		//only perform raycast if filterMask matches
-		if(resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) {
+		if (resultCallback.needsCollision(collisionObject->getBroadphaseHandle()))
+		{
 			//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
 			//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
-			btVector3 collisionObjectAabbMin,collisionObjectAabbMax;
-			collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(),collisionObjectAabbMin,collisionObjectAabbMax);
-			AabbExpand (collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
-			btScalar hitLambda = btScalar(1.); //could use resultCallback.m_closestHitFraction, but needs testing
+			btVector3 collisionObjectAabbMin, collisionObjectAabbMax;
+			collisionObject->getCollisionShape()->getAabb(collisionObject->getWorldTransform(), collisionObjectAabbMin, collisionObjectAabbMax);
+			AabbExpand(collisionObjectAabbMin, collisionObjectAabbMax, castShapeAabbMin, castShapeAabbMax);
+			btScalar hitLambda = btScalar(1.);  //could use resultCallback.m_closestHitFraction, but needs testing
 			btVector3 hitNormal;
 			btVector3 hitNormal;
-			if (btRayAabb(convexFromWorld.getOrigin(),convexToWorld.getOrigin(),collisionObjectAabbMin,collisionObjectAabbMax,hitLambda,hitNormal))
+			if (btRayAabb(convexFromWorld.getOrigin(), convexToWorld.getOrigin(), collisionObjectAabbMin, collisionObjectAabbMax, hitLambda, hitNormal))
 			{
 			{
-				btCollisionWorld::objectQuerySingle(castShape, convexFromTrans,convexToTrans,
-					collisionObject,
-						collisionObject->getCollisionShape(),
-						collisionObject->getWorldTransform(),
-						resultCallback,
-						allowedCcdPenetration);
+				btCollisionWorld::objectQuerySingle(castShape, convexFromTrans, convexToTrans,
+													collisionObject,
+													collisionObject->getCollisionShape(),
+													collisionObject->getWorldTransform(),
+													resultCallback,
+													allowedCcdPenetration);
 			}
 			}
 		}
 		}
 	}
 	}
-
 }
 }
 
 
-void	btGhostObject::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const
+void btGhostObject::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const
 {
 {
 	btTransform rayFromTrans;
 	btTransform rayFromTrans;
 	rayFromTrans.setIdentity();
 	rayFromTrans.setIdentity();
 	rayFromTrans.setOrigin(rayFromWorld);
 	rayFromTrans.setOrigin(rayFromWorld);
-	btTransform  rayToTrans;
+	btTransform rayToTrans;
 	rayToTrans.setIdentity();
 	rayToTrans.setIdentity();
 	rayToTrans.setOrigin(rayToWorld);
 	rayToTrans.setOrigin(rayToWorld);
 
 
-
 	int i;
 	int i;
-	for (i=0;i<m_overlappingObjects.size();i++)
+	for (i = 0; i < m_overlappingObjects.size(); i++)
 	{
 	{
-		btCollisionObject*	collisionObject= m_overlappingObjects[i];
+		btCollisionObject* collisionObject = m_overlappingObjects[i];
 		//only perform raycast if filterMask matches
 		//only perform raycast if filterMask matches
-		if(resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 
+		if (resultCallback.needsCollision(collisionObject->getBroadphaseHandle()))
 		{
 		{
-			btCollisionWorld::rayTestSingle(rayFromTrans,rayToTrans,
-							collisionObject,
-								collisionObject->getCollisionShape(),
-								collisionObject->getWorldTransform(),
-								resultCallback);
+			btCollisionWorld::rayTestSingle(rayFromTrans, rayToTrans,
+											collisionObject,
+											collisionObject->getCollisionShape(),
+											collisionObject->getWorldTransform(),
+											resultCallback);
 		}
 		}
 	}
 	}
 }
 }
-

+ 33 - 46
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btGhostObject.h

@@ -16,7 +16,6 @@ subject to the following restrictions:
 #ifndef BT_GHOST_OBJECT_H
 #ifndef BT_GHOST_OBJECT_H
 #define BT_GHOST_OBJECT_H
 #define BT_GHOST_OBJECT_H
 
 
-
 #include "btCollisionObject.h"
 #include "btCollisionObject.h"
 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h"
 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCallback.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
@@ -31,48 +30,47 @@ class btDispatcher;
 ///By default, this overlap is based on the AABB
 ///By default, this overlap is based on the AABB
 ///This is useful for creating a character controller, collision sensors/triggers, explosions etc.
 ///This is useful for creating a character controller, collision sensors/triggers, explosions etc.
 ///We plan on adding rayTest and other queries for the btGhostObject
 ///We plan on adding rayTest and other queries for the btGhostObject
-ATTRIBUTE_ALIGNED16(class) btGhostObject : public btCollisionObject
+ATTRIBUTE_ALIGNED16(class)
+btGhostObject : public btCollisionObject
 {
 {
 protected:
 protected:
-
 	btAlignedObjectArray<btCollisionObject*> m_overlappingObjects;
 	btAlignedObjectArray<btCollisionObject*> m_overlappingObjects;
 
 
 public:
 public:
-
 	btGhostObject();
 	btGhostObject();
 
 
 	virtual ~btGhostObject();
 	virtual ~btGhostObject();
 
 
-	void	convexSweepTest(const class btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, btCollisionWorld::ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = 0.f) const;
+	void convexSweepTest(const class btConvexShape* castShape, const btTransform& convexFromWorld, const btTransform& convexToWorld, btCollisionWorld::ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = 0.f) const;
 
 
-	void	rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const; 
+	void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, btCollisionWorld::RayResultCallback& resultCallback) const;
 
 
 	///this method is mainly for expert/internal use only.
 	///this method is mainly for expert/internal use only.
-	virtual void	addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy=0);
+	virtual void addOverlappingObjectInternal(btBroadphaseProxy * otherProxy, btBroadphaseProxy* thisProxy = 0);
 	///this method is mainly for expert/internal use only.
 	///this method is mainly for expert/internal use only.
-	virtual void	removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy=0);
+	virtual void removeOverlappingObjectInternal(btBroadphaseProxy * otherProxy, btDispatcher * dispatcher, btBroadphaseProxy* thisProxy = 0);
 
 
-	int	getNumOverlappingObjects() const
+	int getNumOverlappingObjects() const
 	{
 	{
 		return m_overlappingObjects.size();
 		return m_overlappingObjects.size();
 	}
 	}
 
 
-	btCollisionObject*	getOverlappingObject(int index)
+	btCollisionObject* getOverlappingObject(int index)
 	{
 	{
 		return m_overlappingObjects[index];
 		return m_overlappingObjects[index];
 	}
 	}
 
 
-	const btCollisionObject*	getOverlappingObject(int index) const
+	const btCollisionObject* getOverlappingObject(int index) const
 	{
 	{
 		return m_overlappingObjects[index];
 		return m_overlappingObjects[index];
 	}
 	}
 
 
-	btAlignedObjectArray<btCollisionObject*>&	getOverlappingPairs()
+	btAlignedObjectArray<btCollisionObject*>& getOverlappingPairs()
 	{
 	{
 		return m_overlappingObjects;
 		return m_overlappingObjects;
 	}
 	}
 
 
-	const btAlignedObjectArray<btCollisionObject*>	getOverlappingPairs() const
+	const btAlignedObjectArray<btCollisionObject*> getOverlappingPairs() const
 	{
 	{
 		return m_overlappingObjects;
 		return m_overlappingObjects;
 	}
 	}
@@ -81,49 +79,43 @@ public:
 	// internal cast
 	// internal cast
 	//
 	//
 
 
-	static const btGhostObject*	upcast(const btCollisionObject* colObj)
+	static const btGhostObject* upcast(const btCollisionObject* colObj)
 	{
 	{
-		if (colObj->getInternalType()==CO_GHOST_OBJECT)
+		if (colObj->getInternalType() == CO_GHOST_OBJECT)
 			return (const btGhostObject*)colObj;
 			return (const btGhostObject*)colObj;
 		return 0;
 		return 0;
 	}
 	}
-	static btGhostObject*			upcast(btCollisionObject* colObj)
+	static btGhostObject* upcast(btCollisionObject * colObj)
 	{
 	{
-		if (colObj->getInternalType()==CO_GHOST_OBJECT)
+		if (colObj->getInternalType() == CO_GHOST_OBJECT)
 			return (btGhostObject*)colObj;
 			return (btGhostObject*)colObj;
 		return 0;
 		return 0;
 	}
 	}
-
 };
 };
 
 
-class	btPairCachingGhostObject : public btGhostObject
+class btPairCachingGhostObject : public btGhostObject
 {
 {
-	btHashedOverlappingPairCache*	m_hashPairCache;
+	btHashedOverlappingPairCache* m_hashPairCache;
 
 
 public:
 public:
-
 	btPairCachingGhostObject();
 	btPairCachingGhostObject();
 
 
 	virtual ~btPairCachingGhostObject();
 	virtual ~btPairCachingGhostObject();
 
 
 	///this method is mainly for expert/internal use only.
 	///this method is mainly for expert/internal use only.
-	virtual void	addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy=0);
+	virtual void addOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btBroadphaseProxy* thisProxy = 0);
 
 
-	virtual void	removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy,btDispatcher* dispatcher,btBroadphaseProxy* thisProxy=0);
+	virtual void removeOverlappingObjectInternal(btBroadphaseProxy* otherProxy, btDispatcher* dispatcher, btBroadphaseProxy* thisProxy = 0);
 
 
-	btHashedOverlappingPairCache*	getOverlappingPairCache()
+	btHashedOverlappingPairCache* getOverlappingPairCache()
 	{
 	{
 		return m_hashPairCache;
 		return m_hashPairCache;
 	}
 	}
-
 };
 };
 
 
-
-
 ///The btGhostPairCallback interfaces and forwards adding and removal of overlapping pairs from the btBroadphaseInterface to btGhostObject.
 ///The btGhostPairCallback interfaces and forwards adding and removal of overlapping pairs from the btBroadphaseInterface to btGhostObject.
 class btGhostPairCallback : public btOverlappingPairCallback
 class btGhostPairCallback : public btOverlappingPairCallback
 {
 {
-	
 public:
 public:
 	btGhostPairCallback()
 	btGhostPairCallback()
 	{
 	{
@@ -131,15 +123,14 @@ public:
 
 
 	virtual ~btGhostPairCallback()
 	virtual ~btGhostPairCallback()
 	{
 	{
-		
 	}
 	}
 
 
-	virtual btBroadphasePair*	addOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1)
+	virtual btBroadphasePair* addOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1)
 	{
 	{
-		btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
-		btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
-		btGhostObject* ghost0 = 		btGhostObject::upcast(colObj0);
-		btGhostObject* ghost1 = 		btGhostObject::upcast(colObj1);
+		btCollisionObject* colObj0 = (btCollisionObject*)proxy0->m_clientObject;
+		btCollisionObject* colObj1 = (btCollisionObject*)proxy1->m_clientObject;
+		btGhostObject* ghost0 = btGhostObject::upcast(colObj0);
+		btGhostObject* ghost1 = btGhostObject::upcast(colObj1);
 		if (ghost0)
 		if (ghost0)
 			ghost0->addOverlappingObjectInternal(proxy1, proxy0);
 			ghost0->addOverlappingObjectInternal(proxy1, proxy0);
 		if (ghost1)
 		if (ghost1)
@@ -147,29 +138,25 @@ public:
 		return 0;
 		return 0;
 	}
 	}
 
 
-	virtual void*	removeOverlappingPair(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1,btDispatcher* dispatcher)
+	virtual void* removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1, btDispatcher* dispatcher)
 	{
 	{
-		btCollisionObject* colObj0 = (btCollisionObject*) proxy0->m_clientObject;
-		btCollisionObject* colObj1 = (btCollisionObject*) proxy1->m_clientObject;
-		btGhostObject* ghost0 = 		btGhostObject::upcast(colObj0);
-		btGhostObject* ghost1 = 		btGhostObject::upcast(colObj1);
+		btCollisionObject* colObj0 = (btCollisionObject*)proxy0->m_clientObject;
+		btCollisionObject* colObj1 = (btCollisionObject*)proxy1->m_clientObject;
+		btGhostObject* ghost0 = btGhostObject::upcast(colObj0);
+		btGhostObject* ghost1 = btGhostObject::upcast(colObj1);
 		if (ghost0)
 		if (ghost0)
-			ghost0->removeOverlappingObjectInternal(proxy1,dispatcher,proxy0);
+			ghost0->removeOverlappingObjectInternal(proxy1, dispatcher, proxy0);
 		if (ghost1)
 		if (ghost1)
-			ghost1->removeOverlappingObjectInternal(proxy0,dispatcher,proxy1);
+			ghost1->removeOverlappingObjectInternal(proxy0, dispatcher, proxy1);
 		return 0;
 		return 0;
 	}
 	}
 
 
-	virtual void	removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/)
+	virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/, btDispatcher* /*dispatcher*/)
 	{
 	{
 		btAssert(0);
 		btAssert(0);
 		//need to keep track of all ghost objects and call them here
 		//need to keep track of all ghost objects and call them here
 		//m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher);
 		//m_hashPairCache->removeOverlappingPairsContainingProxy(proxy0,dispatcher);
 	}
 	}
-
-	
-
 };
 };
 
 
 #endif
 #endif
-

+ 29 - 61
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp

@@ -13,61 +13,49 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
-
 #include "btHashedSimplePairCache.h"
 #include "btHashedSimplePairCache.h"
 
 
-
 #include <stdio.h>
 #include <stdio.h>
 
 
-int	gOverlappingSimplePairs = 0;
-int gRemoveSimplePairs =0;
-int gAddedSimplePairs =0;
-int gFindSimplePairs =0;
-
-
-
+#ifdef BT_DEBUG_COLLISION_PAIRS
+int gOverlappingSimplePairs = 0;
+int gRemoveSimplePairs = 0;
+int gAddedSimplePairs = 0;
+int gFindSimplePairs = 0;
+#endif  //BT_DEBUG_COLLISION_PAIRS
 
 
-btHashedSimplePairCache::btHashedSimplePairCache() {
-	int initialAllocatedSize= 2;
+btHashedSimplePairCache::btHashedSimplePairCache()
+{
+	int initialAllocatedSize = 2;
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	growTables();
 	growTables();
 }
 }
 
 
-
-
-
 btHashedSimplePairCache::~btHashedSimplePairCache()
 btHashedSimplePairCache::~btHashedSimplePairCache()
 {
 {
 }
 }
 
 
-
-
-
-
-
 void btHashedSimplePairCache::removeAllPairs()
 void btHashedSimplePairCache::removeAllPairs()
 {
 {
 	m_overlappingPairArray.clear();
 	m_overlappingPairArray.clear();
 	m_hashTable.clear();
 	m_hashTable.clear();
 	m_next.clear();
 	m_next.clear();
 
 
-	int initialAllocatedSize= 2;
+	int initialAllocatedSize = 2;
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	growTables();
 	growTables();
 }
 }
 
 
-
-
 btSimplePair* btHashedSimplePairCache::findPair(int indexA, int indexB)
 btSimplePair* btHashedSimplePairCache::findPair(int indexA, int indexB)
 {
 {
+#ifdef BT_DEBUG_COLLISION_PAIRS
 	gFindSimplePairs++;
 	gFindSimplePairs++;
-	
-	
+#endif
+
 	/*if (indexA > indexB) 
 	/*if (indexA > indexB) 
 		btSwap(indexA, indexB);*/
 		btSwap(indexA, indexB);*/
 
 
-	int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
+	int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity() - 1));
 
 
 	if (hash >= m_hashTable.size())
 	if (hash >= m_hashTable.size())
 	{
 	{
@@ -92,9 +80,8 @@ btSimplePair* btHashedSimplePairCache::findPair(int indexA, int indexB)
 
 
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-void	btHashedSimplePairCache::growTables()
+void btHashedSimplePairCache::growTables()
 {
 {
-
 	int newCapacity = m_overlappingPairArray.capacity();
 	int newCapacity = m_overlappingPairArray.capacity();
 
 
 	if (m_hashTable.size() < newCapacity)
 	if (m_hashTable.size() < newCapacity)
@@ -105,10 +92,9 @@ void	btHashedSimplePairCache::growTables()
 		m_hashTable.resize(newCapacity);
 		m_hashTable.resize(newCapacity);
 		m_next.resize(newCapacity);
 		m_next.resize(newCapacity);
 
 
-
 		int i;
 		int i;
 
 
-		for (i= 0; i < newCapacity; ++i)
+		for (i = 0; i < newCapacity; ++i)
 		{
 		{
 			m_hashTable[i] = BT_SIMPLE_NULL_PAIR;
 			m_hashTable[i] = BT_SIMPLE_NULL_PAIR;
 		}
 		}
@@ -117,27 +103,22 @@ void	btHashedSimplePairCache::growTables()
 			m_next[i] = BT_SIMPLE_NULL_PAIR;
 			m_next[i] = BT_SIMPLE_NULL_PAIR;
 		}
 		}
 
 
-		for(i=0;i<curHashtableSize;i++)
+		for (i = 0; i < curHashtableSize; i++)
 		{
 		{
-	
 			const btSimplePair& pair = m_overlappingPairArray[i];
 			const btSimplePair& pair = m_overlappingPairArray[i];
 			int indexA = pair.m_indexA;
 			int indexA = pair.m_indexA;
 			int indexB = pair.m_indexB;
 			int indexB = pair.m_indexB;
-			
-			int	hashValue = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));	// New hash value with new mask
+
+			int hashValue = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity() - 1));  // New hash value with new mask
 			m_next[i] = m_hashTable[hashValue];
 			m_next[i] = m_hashTable[hashValue];
 			m_hashTable[hashValue] = i;
 			m_hashTable[hashValue] = i;
 		}
 		}
-
-
 	}
 	}
 }
 }
 
 
 btSimplePair* btHashedSimplePairCache::internalAddPair(int indexA, int indexB)
 btSimplePair* btHashedSimplePairCache::internalAddPair(int indexA, int indexB)
 {
 {
-
-	int	hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));	// New hash value with new mask
-
+	int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity() - 1));  // New hash value with new mask
 
 
 	btSimplePair* pair = internalFindPair(indexA, indexB, hash);
 	btSimplePair* pair = internalFindPair(indexA, indexB, hash);
 	if (pair != NULL)
 	if (pair != NULL)
@@ -155,30 +136,29 @@ btSimplePair* btHashedSimplePairCache::internalAddPair(int indexA, int indexB)
 	{
 	{
 		growTables();
 		growTables();
 		//hash with new capacity
 		//hash with new capacity
-		hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
+		hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity() - 1));
 	}
 	}
-	
-	pair = new (mem) btSimplePair(indexA,indexB);
+
+	pair = new (mem) btSimplePair(indexA, indexB);
 
 
 	pair->m_userPointer = 0;
 	pair->m_userPointer = 0;
-	
+
 	m_next[count] = m_hashTable[hash];
 	m_next[count] = m_hashTable[hash];
 	m_hashTable[hash] = count;
 	m_hashTable[hash] = count;
 
 
 	return pair;
 	return pair;
 }
 }
 
 
-
-
 void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
 void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
 {
 {
+#ifdef BT_DEBUG_COLLISION_PAIRS
 	gRemoveSimplePairs++;
 	gRemoveSimplePairs++;
-	
+#endif
 
 
 	/*if (indexA > indexB) 
 	/*if (indexA > indexB) 
 		btSwap(indexA, indexB);*/
 		btSwap(indexA, indexB);*/
 
 
-	int	hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA),static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity()-1));
+	int hash = static_cast<int>(getHash(static_cast<unsigned int>(indexA), static_cast<unsigned int>(indexB)) & (m_overlappingPairArray.capacity() - 1));
 
 
 	btSimplePair* pair = internalFindPair(indexA, indexB, hash);
 	btSimplePair* pair = internalFindPair(indexA, indexB, hash);
 	if (pair == NULL)
 	if (pair == NULL)
@@ -186,10 +166,8 @@ void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
 		return 0;
 		return 0;
 	}
 	}
 
 
-	
 	void* userData = pair->m_userPointer;
 	void* userData = pair->m_userPointer;
 
 
-
 	int pairIndex = int(pair - &m_overlappingPairArray[0]);
 	int pairIndex = int(pair - &m_overlappingPairArray[0]);
 	btAssert(pairIndex < m_overlappingPairArray.size());
 	btAssert(pairIndex < m_overlappingPairArray.size());
 
 
@@ -229,8 +207,8 @@ void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
 
 
 	// Remove the last pair from the hash table.
 	// Remove the last pair from the hash table.
 	const btSimplePair* last = &m_overlappingPairArray[lastPairIndex];
 	const btSimplePair* last = &m_overlappingPairArray[lastPairIndex];
-		/* missing swap here too, Nat. */ 
-	int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_indexA), static_cast<unsigned int>(last->m_indexB)) & (m_overlappingPairArray.capacity()-1));
+	/* missing swap here too, Nat. */
+	int lastHash = static_cast<int>(getHash(static_cast<unsigned int>(last->m_indexA), static_cast<unsigned int>(last->m_indexB)) & (m_overlappingPairArray.capacity() - 1));
 
 
 	index = m_hashTable[lastHash];
 	index = m_hashTable[lastHash];
 	btAssert(index != BT_SIMPLE_NULL_PAIR);
 	btAssert(index != BT_SIMPLE_NULL_PAIR);
@@ -264,13 +242,3 @@ void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
 	return userData;
 	return userData;
 }
 }
 //#include <stdio.h>
 //#include <stdio.h>
-
-
-
-
-
-
-
-
-
-

+ 43 - 66
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.h

@@ -16,142 +16,126 @@ subject to the following restrictions:
 #ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
 #ifndef BT_HASHED_SIMPLE_PAIR_CACHE_H
 #define BT_HASHED_SIMPLE_PAIR_CACHE_H
 #define BT_HASHED_SIMPLE_PAIR_CACHE_H
 
 
-
-
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
 
 
-const int BT_SIMPLE_NULL_PAIR=0xffffffff;
+const int BT_SIMPLE_NULL_PAIR = 0xffffffff;
 
 
 struct btSimplePair
 struct btSimplePair
 {
 {
-	btSimplePair(int indexA,int indexB)
-		:m_indexA(indexA),
-		m_indexB(indexB),
-		m_userPointer(0)
+	btSimplePair(int indexA, int indexB)
+		: m_indexA(indexA),
+		  m_indexB(indexB),
+		  m_userPointer(0)
 	{
 	{
 	}
 	}
 
 
 	int m_indexA;
 	int m_indexA;
 	int m_indexB;
 	int m_indexB;
-	union
-	{
-		void*	m_userPointer;
-		int		m_userValue;
+	union {
+		void* m_userPointer;
+		int m_userValue;
 	};
 	};
 };
 };
 
 
-typedef btAlignedObjectArray<btSimplePair>	btSimplePairArray;
-
-
+typedef btAlignedObjectArray<btSimplePair> btSimplePairArray;
 
 
+#ifdef BT_DEBUG_COLLISION_PAIRS
 extern int gOverlappingSimplePairs;
 extern int gOverlappingSimplePairs;
 extern int gRemoveSimplePairs;
 extern int gRemoveSimplePairs;
 extern int gAddedSimplePairs;
 extern int gAddedSimplePairs;
 extern int gFindSimplePairs;
 extern int gFindSimplePairs;
-
-
-
+#endif  //BT_DEBUG_COLLISION_PAIRS
 
 
 class btHashedSimplePairCache
 class btHashedSimplePairCache
 {
 {
-	btSimplePairArray	m_overlappingPairArray;
-		
+	btSimplePairArray m_overlappingPairArray;
 
 
 protected:
 protected:
-	
-	btAlignedObjectArray<int>	m_hashTable;
-	btAlignedObjectArray<int>	m_next;
-	
+	btAlignedObjectArray<int> m_hashTable;
+	btAlignedObjectArray<int> m_next;
 
 
 public:
 public:
 	btHashedSimplePairCache();
 	btHashedSimplePairCache();
 	virtual ~btHashedSimplePairCache();
 	virtual ~btHashedSimplePairCache();
-	
+
 	void removeAllPairs();
 	void removeAllPairs();
 
 
-	virtual void*	removeOverlappingPair(int indexA,int indexB);
-	
+	virtual void* removeOverlappingPair(int indexA, int indexB);
+
 	// Add a pair and return the new pair. If the pair already exists,
 	// Add a pair and return the new pair. If the pair already exists,
 	// no new pair is created and the old one is returned.
 	// no new pair is created and the old one is returned.
-	virtual btSimplePair* 	addOverlappingPair(int indexA,int indexB)
+	virtual btSimplePair* addOverlappingPair(int indexA, int indexB)
 	{
 	{
+#ifdef BT_DEBUG_COLLISION_PAIRS
 		gAddedSimplePairs++;
 		gAddedSimplePairs++;
+#endif
 
 
-		return internalAddPair(indexA,indexB);
+		return internalAddPair(indexA, indexB);
 	}
 	}
 
 
-	
-	virtual btSimplePair*	getOverlappingPairArrayPtr()
+	virtual btSimplePair* getOverlappingPairArrayPtr()
 	{
 	{
 		return &m_overlappingPairArray[0];
 		return &m_overlappingPairArray[0];
 	}
 	}
 
 
-	const btSimplePair*	getOverlappingPairArrayPtr() const
+	const btSimplePair* getOverlappingPairArrayPtr() const
 	{
 	{
 		return &m_overlappingPairArray[0];
 		return &m_overlappingPairArray[0];
 	}
 	}
 
 
-	btSimplePairArray&	getOverlappingPairArray()
+	btSimplePairArray& getOverlappingPairArray()
 	{
 	{
 		return m_overlappingPairArray;
 		return m_overlappingPairArray;
 	}
 	}
 
 
-	const btSimplePairArray&	getOverlappingPairArray() const
+	const btSimplePairArray& getOverlappingPairArray() const
 	{
 	{
 		return m_overlappingPairArray;
 		return m_overlappingPairArray;
 	}
 	}
 
 
-	
-	btSimplePair* findPair(int indexA,int indexB);
+	btSimplePair* findPair(int indexA, int indexB);
 
 
 	int GetCount() const { return m_overlappingPairArray.size(); }
 	int GetCount() const { return m_overlappingPairArray.size(); }
 
 
-	int	getNumOverlappingPairs() const
+	int getNumOverlappingPairs() const
 	{
 	{
 		return m_overlappingPairArray.size();
 		return m_overlappingPairArray.size();
 	}
 	}
+
 private:
 private:
-	
-	btSimplePair* 	internalAddPair(int indexA, int indexB);
+	btSimplePair* internalAddPair(int indexA, int indexB);
 
 
-	void	growTables();
+	void growTables();
 
 
 	SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
 	SIMD_FORCE_INLINE bool equalsPair(const btSimplePair& pair, int indexA, int indexB)
-	{	
+	{
 		return pair.m_indexA == indexA && pair.m_indexB == indexB;
 		return pair.m_indexA == indexA && pair.m_indexB == indexB;
 	}
 	}
 
 
-	
-	
-	SIMD_FORCE_INLINE	unsigned int getHash(unsigned int indexA, unsigned int indexB)
+	SIMD_FORCE_INLINE unsigned int getHash(unsigned int indexA, unsigned int indexB)
 	{
 	{
-		int key = static_cast<int>(((unsigned int)indexA) | (((unsigned int)indexB) <<16));
+		unsigned int key = indexA | (indexB << 16);
 		// Thomas Wang's hash
 		// Thomas Wang's hash
 
 
 		key += ~(key << 15);
 		key += ~(key << 15);
-		key ^=  (key >> 10);
-		key +=  (key << 3);
-		key ^=  (key >> 6);
+		key ^= (key >> 10);
+		key += (key << 3);
+		key ^= (key >> 6);
 		key += ~(key << 11);
 		key += ~(key << 11);
-		key ^=  (key >> 16);
-		return static_cast<unsigned int>(key);
+		key ^= (key >> 16);
+		return key;
 	}
 	}
-	
-
-
 
 
-
-	SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA , int proxyIdB, int hash)
+	SIMD_FORCE_INLINE btSimplePair* internalFindPair(int proxyIdA, int proxyIdB, int hash)
 	{
 	{
-		
 		int index = m_hashTable[hash];
 		int index = m_hashTable[hash];
-		
-		while( index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
+
+		while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], proxyIdA, proxyIdB) == false)
 		{
 		{
 			index = m_next[index];
 			index = m_next[index];
 		}
 		}
 
 
-		if ( index == BT_SIMPLE_NULL_PAIR )
+		if (index == BT_SIMPLE_NULL_PAIR)
 		{
 		{
 			return NULL;
 			return NULL;
 		}
 		}
@@ -160,13 +144,6 @@ private:
 
 
 		return &m_overlappingPairArray[index];
 		return &m_overlappingPairArray[index];
 	}
 	}
-
-	
 };
 };
 
 
-
-
-
-#endif //BT_HASHED_SIMPLE_PAIR_CACHE_H
-
-
+#endif  //BT_HASHED_SIMPLE_PAIR_CACHE_H

+ 454 - 392
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp

@@ -1,6 +1,8 @@
 #include "btInternalEdgeUtility.h"
 #include "btInternalEdgeUtility.h"
 
 
 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h"
+
 #include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
 #include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
 #include "BulletCollision/CollisionShapes/btTriangleShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
@@ -12,50 +14,44 @@
 
 
 #ifdef DEBUG_INTERNAL_EDGE
 #ifdef DEBUG_INTERNAL_EDGE
 #include <stdio.h>
 #include <stdio.h>
-#endif //DEBUG_INTERNAL_EDGE
-
+#endif  //DEBUG_INTERNAL_EDGE
 
 
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 static btIDebugDraw* gDebugDrawer = 0;
 static btIDebugDraw* gDebugDrawer = 0;
 
 
-void	btSetDebugDrawer(btIDebugDraw* debugDrawer)
+void btSetDebugDrawer(btIDebugDraw* debugDrawer)
 {
 {
 	gDebugDrawer = debugDrawer;
 	gDebugDrawer = debugDrawer;
 }
 }
 
 
-static void    btDebugDrawLine(const btVector3& from,const btVector3& to, const btVector3& color)
+static void btDebugDrawLine(const btVector3& from, const btVector3& to, const btVector3& color)
 {
 {
 	if (gDebugDrawer)
 	if (gDebugDrawer)
-		gDebugDrawer->drawLine(from,to,color);
+		gDebugDrawer->drawLine(from, to, color);
 }
 }
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
-static int	btGetHash(int partId, int triangleIndex)
+static int btGetHash(int partId, int triangleIndex)
 {
 {
-	int hash = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
+	int hash = (partId << (31 - MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
 	return hash;
 	return hash;
 }
 }
 
 
-
-
-static btScalar btGetAngle(const btVector3& edgeA, const btVector3& normalA,const btVector3& normalB)
+static btScalar btGetAngle(const btVector3& edgeA, const btVector3& normalA, const btVector3& normalB)
 {
 {
-	const btVector3 refAxis0  = edgeA;
-	const btVector3 refAxis1  = normalA;
+	const btVector3 refAxis0 = edgeA;
+	const btVector3 refAxis1 = normalA;
 	const btVector3 swingAxis = normalB;
 	const btVector3 swingAxis = normalB;
 	btScalar angle = btAtan2(swingAxis.dot(refAxis0), swingAxis.dot(refAxis1));
 	btScalar angle = btAtan2(swingAxis.dot(refAxis0), swingAxis.dot(refAxis1));
-	return  angle;
+	return angle;
 }
 }
 
 
-
 struct btConnectivityProcessor : public btTriangleCallback
 struct btConnectivityProcessor : public btTriangleCallback
 {
 {
-	int				m_partIdA;
-	int				m_triangleIndexA;
-	btVector3*		m_triangleVerticesA;
-	btTriangleInfoMap*	m_triangleInfoMap;
-
+	int m_partIdA;
+	int m_triangleIndexA;
+	btVector3* m_triangleVerticesA;
+	btTriangleInfoMap* m_triangleInfoMap;
 
 
 	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 	{
 	{
@@ -69,18 +65,17 @@ struct btConnectivityProcessor : public btTriangleCallback
 
 
 		//search for shared vertices and edges
 		//search for shared vertices and edges
 		int numshared = 0;
 		int numshared = 0;
-		int sharedVertsA[3]={-1,-1,-1};
-		int sharedVertsB[3]={-1,-1,-1};
+		int sharedVertsA[3] = {-1, -1, -1};
+		int sharedVertsB[3] = {-1, -1, -1};
 
 
 		///skip degenerate triangles
 		///skip degenerate triangles
-		btScalar crossBSqr = ((triangle[1]-triangle[0]).cross(triangle[2]-triangle[0])).length2();
+		btScalar crossBSqr = ((triangle[1] - triangle[0]).cross(triangle[2] - triangle[0])).length2();
 		if (crossBSqr < m_triangleInfoMap->m_equalVertexThreshold)
 		if (crossBSqr < m_triangleInfoMap->m_equalVertexThreshold)
 			return;
 			return;
 
 
-
-		btScalar crossASqr = ((m_triangleVerticesA[1]-m_triangleVerticesA[0]).cross(m_triangleVerticesA[2]-m_triangleVerticesA[0])).length2();
+		btScalar crossASqr = ((m_triangleVerticesA[1] - m_triangleVerticesA[0]).cross(m_triangleVerticesA[2] - m_triangleVerticesA[0])).length2();
 		///skip degenerate triangles
 		///skip degenerate triangles
-		if (crossASqr< m_triangleInfoMap->m_equalVertexThreshold)
+		if (crossASqr < m_triangleInfoMap->m_equalVertexThreshold)
 			return;
 			return;
 
 
 #if 0
 #if 0
@@ -96,36 +91,36 @@ struct btConnectivityProcessor : public btTriangleCallback
 			triangle[2].getX(),triangle[2].getY(),triangle[2].getZ());
 			triangle[2].getX(),triangle[2].getY(),triangle[2].getZ());
 #endif
 #endif
 
 
-		for (int i=0;i<3;i++)
+		for (int i = 0; i < 3; i++)
 		{
 		{
-			for (int j=0;j<3;j++)
+			for (int j = 0; j < 3; j++)
 			{
 			{
-				if ( (m_triangleVerticesA[i]-triangle[j]).length2() < m_triangleInfoMap->m_equalVertexThreshold)
+				if ((m_triangleVerticesA[i] - triangle[j]).length2() < m_triangleInfoMap->m_equalVertexThreshold)
 				{
 				{
 					sharedVertsA[numshared] = i;
 					sharedVertsA[numshared] = i;
 					sharedVertsB[numshared] = j;
 					sharedVertsB[numshared] = j;
 					numshared++;
 					numshared++;
 					///degenerate case
 					///degenerate case
-					if(numshared >= 3)
+					if (numshared >= 3)
 						return;
 						return;
 				}
 				}
 			}
 			}
 			///degenerate case
 			///degenerate case
-			if(numshared >= 3)
+			if (numshared >= 3)
 				return;
 				return;
 		}
 		}
 		switch (numshared)
 		switch (numshared)
 		{
 		{
-		case 0:
+			case 0:
 			{
 			{
 				break;
 				break;
 			}
 			}
-		case 1:
+			case 1:
 			{
 			{
 				//shared vertex
 				//shared vertex
 				break;
 				break;
 			}
 			}
-		case 2:
+			case 2:
 			{
 			{
 				//shared edge
 				//shared edge
 				//we need to make sure the edge is in the order V2V0 and not V0V2 so that the signs are correct
 				//we need to make sure the edge is in the order V2V0 and not V0V2 so that the signs are correct
@@ -138,26 +133,25 @@ struct btConnectivityProcessor : public btTriangleCallback
 					sharedVertsB[0] = tmp;
 					sharedVertsB[0] = tmp;
 				}
 				}
 
 
-				int hash = btGetHash(m_partIdA,m_triangleIndexA);
+				int hash = btGetHash(m_partIdA, m_triangleIndexA);
 
 
 				btTriangleInfo* info = m_triangleInfoMap->find(hash);
 				btTriangleInfo* info = m_triangleInfoMap->find(hash);
 				if (!info)
 				if (!info)
 				{
 				{
 					btTriangleInfo tmp;
 					btTriangleInfo tmp;
-					m_triangleInfoMap->insert(hash,tmp);
+					m_triangleInfoMap->insert(hash, tmp);
 					info = m_triangleInfoMap->find(hash);
 					info = m_triangleInfoMap->find(hash);
 				}
 				}
 
 
-				int sumvertsA = sharedVertsA[0]+sharedVertsA[1];
-				int otherIndexA = 3-sumvertsA;
+				int sumvertsA = sharedVertsA[0] + sharedVertsA[1];
+				int otherIndexA = 3 - sumvertsA;
 
 
-				
-				btVector3 edge(m_triangleVerticesA[sharedVertsA[1]]-m_triangleVerticesA[sharedVertsA[0]]);
+				btVector3 edge(m_triangleVerticesA[sharedVertsA[1]] - m_triangleVerticesA[sharedVertsA[0]]);
 
 
-				btTriangleShape tA(m_triangleVerticesA[0],m_triangleVerticesA[1],m_triangleVerticesA[2]);
-				int otherIndexB = 3-(sharedVertsB[0]+sharedVertsB[1]);
+				btTriangleShape tA(m_triangleVerticesA[0], m_triangleVerticesA[1], m_triangleVerticesA[2]);
+				int otherIndexB = 3 - (sharedVertsB[0] + sharedVertsB[1]);
 
 
-				btTriangleShape tB(triangle[sharedVertsB[1]],triangle[sharedVertsB[0]],triangle[otherIndexB]);
+				btTriangleShape tB(triangle[sharedVertsB[1]], triangle[sharedVertsB[0]], triangle[otherIndexB]);
 				//btTriangleShape tB(triangle[0],triangle[1],triangle[2]);
 				//btTriangleShape tB(triangle[0],triangle[1],triangle[2]);
 
 
 				btVector3 normalA;
 				btVector3 normalA;
@@ -168,26 +162,25 @@ struct btConnectivityProcessor : public btTriangleCallback
 				btVector3 edgeCrossA = edge.cross(normalA).normalize();
 				btVector3 edgeCrossA = edge.cross(normalA).normalize();
 
 
 				{
 				{
-					btVector3 tmp = m_triangleVerticesA[otherIndexA]-m_triangleVerticesA[sharedVertsA[0]];
+					btVector3 tmp = m_triangleVerticesA[otherIndexA] - m_triangleVerticesA[sharedVertsA[0]];
 					if (edgeCrossA.dot(tmp) < 0)
 					if (edgeCrossA.dot(tmp) < 0)
 					{
 					{
-						edgeCrossA*=-1;
+						edgeCrossA *= -1;
 					}
 					}
 				}
 				}
 
 
 				btVector3 edgeCrossB = edge.cross(normalB).normalize();
 				btVector3 edgeCrossB = edge.cross(normalB).normalize();
 
 
 				{
 				{
-					btVector3 tmp = triangle[otherIndexB]-triangle[sharedVertsB[0]];
+					btVector3 tmp = triangle[otherIndexB] - triangle[sharedVertsB[0]];
 					if (edgeCrossB.dot(tmp) < 0)
 					if (edgeCrossB.dot(tmp) < 0)
 					{
 					{
-						edgeCrossB*=-1;
+						edgeCrossB *= -1;
 					}
 					}
 				}
 				}
 
 
-				btScalar	angle2 = 0;
-				btScalar	ang4 = 0.f;
-
+				btScalar angle2 = 0;
+				btScalar ang4 = 0.f;
 
 
 				btVector3 calculatedEdge = edgeCrossA.cross(edgeCrossB);
 				btVector3 calculatedEdge = edgeCrossA.cross(edgeCrossB);
 				btScalar len2 = calculatedEdge.length2();
 				btScalar len2 = calculatedEdge.length2();
@@ -196,52 +189,47 @@ struct btConnectivityProcessor : public btTriangleCallback
 				//btVector3 calculatedNormalB = normalA;
 				//btVector3 calculatedNormalB = normalA;
 				bool isConvex = false;
 				bool isConvex = false;
 
 
-				if (len2<m_triangleInfoMap->m_planarEpsilon)
+				if (len2 < m_triangleInfoMap->m_planarEpsilon)
 				{
 				{
 					angle2 = 0.f;
 					angle2 = 0.f;
 					ang4 = 0.f;
 					ang4 = 0.f;
-				} else
+				}
+				else
 				{
 				{
-
 					calculatedEdge.normalize();
 					calculatedEdge.normalize();
 					btVector3 calculatedNormalA = calculatedEdge.cross(edgeCrossA);
 					btVector3 calculatedNormalA = calculatedEdge.cross(edgeCrossA);
 					calculatedNormalA.normalize();
 					calculatedNormalA.normalize();
-					angle2 = btGetAngle(calculatedNormalA,edgeCrossA,edgeCrossB);
-					ang4 = SIMD_PI-angle2;
+					angle2 = btGetAngle(calculatedNormalA, edgeCrossA, edgeCrossB);
+					ang4 = SIMD_PI - angle2;
 					btScalar dotA = normalA.dot(edgeCrossB);
 					btScalar dotA = normalA.dot(edgeCrossB);
 					///@todo: check if we need some epsilon, due to floating point imprecision
 					///@todo: check if we need some epsilon, due to floating point imprecision
-					isConvex = (dotA<0.);
+					isConvex = (dotA < 0.);
 
 
 					correctedAngle = isConvex ? ang4 : -ang4;
 					correctedAngle = isConvex ? ang4 : -ang4;
 				}
 				}
 
 
-				
-
-				
-							
-				//alternatively use 
+				//alternatively use
 				//btVector3 calculatedNormalB2 = quatRotate(orn,normalA);
 				//btVector3 calculatedNormalB2 = quatRotate(orn,normalA);
 
 
-
 				switch (sumvertsA)
 				switch (sumvertsA)
 				{
 				{
-				case 1:
+					case 1:
 					{
 					{
-						btVector3 edge = m_triangleVerticesA[0]-m_triangleVerticesA[1];
-						btQuaternion orn(edge,-correctedAngle);
-						btVector3 computedNormalB = quatRotate(orn,normalA);
+						btVector3 edge = m_triangleVerticesA[0] - m_triangleVerticesA[1];
+						btQuaternion orn(edge, -correctedAngle);
+						btVector3 computedNormalB = quatRotate(orn, normalA);
 						btScalar bla = computedNormalB.dot(normalB);
 						btScalar bla = computedNormalB.dot(normalB);
-						if (bla<0)
+						if (bla < 0)
 						{
 						{
-							computedNormalB*=-1;
+							computedNormalB *= -1;
 							info->m_flags |= TRI_INFO_V0V1_SWAP_NORMALB;
 							info->m_flags |= TRI_INFO_V0V1_SWAP_NORMALB;
 						}
 						}
 #ifdef DEBUG_INTERNAL_EDGE
 #ifdef DEBUG_INTERNAL_EDGE
-						if ((computedNormalB-normalB).length()>0.0001)
+						if ((computedNormalB - normalB).length() > 0.0001)
 						{
 						{
 							printf("warning: normals not identical\n");
 							printf("warning: normals not identical\n");
 						}
 						}
-#endif//DEBUG_INTERNAL_EDGE
+#endif  //DEBUG_INTERNAL_EDGE
 
 
 						info->m_edgeV0V1Angle = -correctedAngle;
 						info->m_edgeV0V1Angle = -correctedAngle;
 
 
@@ -249,44 +237,44 @@ struct btConnectivityProcessor : public btTriangleCallback
 							info->m_flags |= TRI_INFO_V0V1_CONVEX;
 							info->m_flags |= TRI_INFO_V0V1_CONVEX;
 						break;
 						break;
 					}
 					}
-				case 2:
+					case 2:
 					{
 					{
-						btVector3 edge = m_triangleVerticesA[2]-m_triangleVerticesA[0];
-						btQuaternion orn(edge,-correctedAngle);
-						btVector3 computedNormalB = quatRotate(orn,normalA);
-						if (computedNormalB.dot(normalB)<0)
+						btVector3 edge = m_triangleVerticesA[2] - m_triangleVerticesA[0];
+						btQuaternion orn(edge, -correctedAngle);
+						btVector3 computedNormalB = quatRotate(orn, normalA);
+						if (computedNormalB.dot(normalB) < 0)
 						{
 						{
-							computedNormalB*=-1;
+							computedNormalB *= -1;
 							info->m_flags |= TRI_INFO_V2V0_SWAP_NORMALB;
 							info->m_flags |= TRI_INFO_V2V0_SWAP_NORMALB;
 						}
 						}
 
 
 #ifdef DEBUG_INTERNAL_EDGE
 #ifdef DEBUG_INTERNAL_EDGE
-						if ((computedNormalB-normalB).length()>0.0001)
+						if ((computedNormalB - normalB).length() > 0.0001)
 						{
 						{
 							printf("warning: normals not identical\n");
 							printf("warning: normals not identical\n");
 						}
 						}
-#endif //DEBUG_INTERNAL_EDGE
+#endif  //DEBUG_INTERNAL_EDGE
 						info->m_edgeV2V0Angle = -correctedAngle;
 						info->m_edgeV2V0Angle = -correctedAngle;
 						if (isConvex)
 						if (isConvex)
 							info->m_flags |= TRI_INFO_V2V0_CONVEX;
 							info->m_flags |= TRI_INFO_V2V0_CONVEX;
-						break;	
+						break;
 					}
 					}
-				case 3:
+					case 3:
 					{
 					{
-						btVector3 edge = m_triangleVerticesA[1]-m_triangleVerticesA[2];
-						btQuaternion orn(edge,-correctedAngle);
-						btVector3 computedNormalB = quatRotate(orn,normalA);
-						if (computedNormalB.dot(normalB)<0)
+						btVector3 edge = m_triangleVerticesA[1] - m_triangleVerticesA[2];
+						btQuaternion orn(edge, -correctedAngle);
+						btVector3 computedNormalB = quatRotate(orn, normalA);
+						if (computedNormalB.dot(normalB) < 0)
 						{
 						{
 							info->m_flags |= TRI_INFO_V1V2_SWAP_NORMALB;
 							info->m_flags |= TRI_INFO_V1V2_SWAP_NORMALB;
-							computedNormalB*=-1;
+							computedNormalB *= -1;
 						}
 						}
 #ifdef DEBUG_INTERNAL_EDGE
 #ifdef DEBUG_INTERNAL_EDGE
-						if ((computedNormalB-normalB).length()>0.0001)
+						if ((computedNormalB - normalB).length() > 0.0001)
 						{
 						{
 							printf("warning: normals not identical\n");
 							printf("warning: normals not identical\n");
 						}
 						}
-#endif //DEBUG_INTERNAL_EDGE
+#endif  //DEBUG_INTERNAL_EDGE
 						info->m_edgeV1V2Angle = -correctedAngle;
 						info->m_edgeV1V2Angle = -correctedAngle;
 
 
 						if (isConvex)
 						if (isConvex)
@@ -297,18 +285,50 @@ struct btConnectivityProcessor : public btTriangleCallback
 
 
 				break;
 				break;
 			}
 			}
-		default:
+			default:
 			{
 			{
 				//				printf("warning: duplicate triangle\n");
 				//				printf("warning: duplicate triangle\n");
 			}
 			}
-
 		}
 		}
 	}
 	}
 };
 };
+
+
+struct b3ProcessAllTrianglesHeightfield: public btTriangleCallback
+{
+	btHeightfieldTerrainShape* m_heightfieldShape;
+	btTriangleInfoMap* m_triangleInfoMap;
+	
+
+	b3ProcessAllTrianglesHeightfield(btHeightfieldTerrainShape* heightFieldShape, btTriangleInfoMap* triangleInfoMap)
+		:m_heightfieldShape(heightFieldShape),
+		m_triangleInfoMap(triangleInfoMap)
+	{
+	}
+	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
+	{
+		btConnectivityProcessor connectivityProcessor;
+		connectivityProcessor.m_partIdA = partId;
+		connectivityProcessor.m_triangleIndexA = triangleIndex;
+		connectivityProcessor.m_triangleVerticesA = triangle;
+		connectivityProcessor.m_triangleInfoMap = m_triangleInfoMap;
+		btVector3 aabbMin, aabbMax;
+		aabbMin.setValue(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT));
+		aabbMax.setValue(btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT));
+		aabbMin.setMin(triangle[0]);
+		aabbMax.setMax(triangle[0]);
+		aabbMin.setMin(triangle[1]);
+		aabbMax.setMax(triangle[1]);
+		aabbMin.setMin(triangle[2]);
+		aabbMax.setMax(triangle[2]);
+
+		m_heightfieldShape->processAllTriangles(&connectivityProcessor, aabbMin, aabbMax);
+	}
+};
 /////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////
 
 
-void btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangleInfoMap* triangleInfoMap)
+void btGenerateInternalEdgeInfo(btBvhTriangleMeshShape* trimeshShape, btTriangleInfoMap* triangleInfoMap)
 {
 {
 	//the user pointer shouldn't already be used for other purposes, we intend to store connectivity info there!
 	//the user pointer shouldn't already be used for other purposes, we intend to store connectivity info there!
 	if (trimeshShape->getTriangleInfoMap())
 	if (trimeshShape->getTriangleInfoMap())
@@ -319,46 +339,51 @@ void btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangle
 	btStridingMeshInterface* meshInterface = trimeshShape->getMeshInterface();
 	btStridingMeshInterface* meshInterface = trimeshShape->getMeshInterface();
 	const btVector3& meshScaling = meshInterface->getScaling();
 	const btVector3& meshScaling = meshInterface->getScaling();
 
 
-	for (int partId = 0; partId< meshInterface->getNumSubParts();partId++)
+	for (int partId = 0; partId < meshInterface->getNumSubParts(); partId++)
 	{
 	{
-		const unsigned char *vertexbase = 0;
+		const unsigned char* vertexbase = 0;
 		int numverts = 0;
 		int numverts = 0;
 		PHY_ScalarType type = PHY_INTEGER;
 		PHY_ScalarType type = PHY_INTEGER;
 		int stride = 0;
 		int stride = 0;
-		const unsigned char *indexbase = 0;
+		const unsigned char* indexbase = 0;
 		int indexstride = 0;
 		int indexstride = 0;
 		int numfaces = 0;
 		int numfaces = 0;
 		PHY_ScalarType indicestype = PHY_INTEGER;
 		PHY_ScalarType indicestype = PHY_INTEGER;
 		//PHY_ScalarType indexType=0;
 		//PHY_ScalarType indexType=0;
 
 
 		btVector3 triangleVerts[3];
 		btVector3 triangleVerts[3];
-		meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,	type,stride,&indexbase,indexstride,numfaces,indicestype,partId);
-		btVector3 aabbMin,aabbMax;
+		meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase, numverts, type, stride, &indexbase, indexstride, numfaces, indicestype, partId);
+		btVector3 aabbMin, aabbMax;
 
 
-		for (int triangleIndex = 0 ; triangleIndex < numfaces;triangleIndex++)
+		for (int triangleIndex = 0; triangleIndex < numfaces; triangleIndex++)
 		{
 		{
-			unsigned int* gfxbase = (unsigned int*)(indexbase+triangleIndex*indexstride);
+			unsigned int* gfxbase = (unsigned int*)(indexbase + triangleIndex * indexstride);
 
 
-			for (int j=2;j>=0;j--)
+			for (int j = 2; j >= 0; j--)
 			{
 			{
-
-				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
+				int graphicsindex;
+                                switch (indicestype) {
+                                        case PHY_INTEGER: graphicsindex = gfxbase[j]; break;
+                                        case PHY_SHORT: graphicsindex = ((unsigned short*)gfxbase)[j]; break;
+                                        case PHY_UCHAR: graphicsindex = ((unsigned char*)gfxbase)[j]; break;
+                                        default: btAssert(0);
+                                }
 				if (type == PHY_FLOAT)
 				if (type == PHY_FLOAT)
 				{
 				{
-					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+					float* graphicsbase = (float*)(vertexbase + graphicsindex * stride);
 					triangleVerts[j] = btVector3(
 					triangleVerts[j] = btVector3(
-						graphicsbase[0]*meshScaling.getX(),
-						graphicsbase[1]*meshScaling.getY(),
-						graphicsbase[2]*meshScaling.getZ());
+						graphicsbase[0] * meshScaling.getX(),
+						graphicsbase[1] * meshScaling.getY(),
+						graphicsbase[2] * meshScaling.getZ());
 				}
 				}
 				else
 				else
 				{
 				{
-					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
-					triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*meshScaling.getX()), btScalar(graphicsbase[1]*meshScaling.getY()), btScalar(graphicsbase[2]*meshScaling.getZ()));
+					double* graphicsbase = (double*)(vertexbase + graphicsindex * stride);
+					triangleVerts[j] = btVector3(btScalar(graphicsbase[0] * meshScaling.getX()), btScalar(graphicsbase[1] * meshScaling.getY()), btScalar(graphicsbase[2] * meshScaling.getZ()));
 				}
 				}
 			}
 			}
-			aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
-			aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 
+			aabbMin.setValue(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT));
+			aabbMax.setValue(btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT));
 			aabbMin.setMin(triangleVerts[0]);
 			aabbMin.setMin(triangleVerts[0]);
 			aabbMax.setMax(triangleVerts[0]);
 			aabbMax.setMax(triangleVerts[0]);
 			aabbMin.setMin(triangleVerts[1]);
 			aabbMin.setMin(triangleVerts[1]);
@@ -370,131 +395,177 @@ void btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangle
 			connectivityProcessor.m_partIdA = partId;
 			connectivityProcessor.m_partIdA = partId;
 			connectivityProcessor.m_triangleIndexA = triangleIndex;
 			connectivityProcessor.m_triangleIndexA = triangleIndex;
 			connectivityProcessor.m_triangleVerticesA = &triangleVerts[0];
 			connectivityProcessor.m_triangleVerticesA = &triangleVerts[0];
-			connectivityProcessor.m_triangleInfoMap  = triangleInfoMap;
+			connectivityProcessor.m_triangleInfoMap = triangleInfoMap;
 
 
-			trimeshShape->processAllTriangles(&connectivityProcessor,aabbMin,aabbMax);
+			trimeshShape->processAllTriangles(&connectivityProcessor, aabbMin, aabbMax);
 		}
 		}
-
 	}
 	}
-
 }
 }
 
 
 
 
+void btGenerateInternalEdgeInfo(btHeightfieldTerrainShape* heightfieldShape, btTriangleInfoMap* triangleInfoMap)
+{
+
+	//the user pointer shouldn't already be used for other purposes, we intend to store connectivity info there!
+	if (heightfieldShape->getTriangleInfoMap())
+		return;
+
+	heightfieldShape->setTriangleInfoMap(triangleInfoMap);
+
+	//get all the triangles of the heightfield
 
 
+	btVector3 aabbMin, aabbMax;
+
+	aabbMax.setValue(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT));
+	aabbMin.setValue(btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT));
+
+	b3ProcessAllTrianglesHeightfield processHeightfield(heightfieldShape, triangleInfoMap);
+	heightfieldShape->processAllTriangles(&processHeightfield, aabbMin, aabbMax);
+
+}
 
 
 // Given a point and a line segment (defined by two points), compute the closest point
 // Given a point and a line segment (defined by two points), compute the closest point
 // in the line.  Cap the point at the endpoints of the line segment.
 // in the line.  Cap the point at the endpoints of the line segment.
-void btNearestPointInLineSegment(const btVector3 &point, const btVector3& line0, const btVector3& line1, btVector3& nearestPoint)
+void btNearestPointInLineSegment(const btVector3& point, const btVector3& line0, const btVector3& line1, btVector3& nearestPoint)
 {
 {
-	btVector3 lineDelta     = line1 - line0;
+	btVector3 lineDelta = line1 - line0;
 
 
 	// Handle degenerate lines
 	// Handle degenerate lines
-	if ( lineDelta.fuzzyZero())
+	if (lineDelta.fuzzyZero())
 	{
 	{
 		nearestPoint = line0;
 		nearestPoint = line0;
 	}
 	}
 	else
 	else
 	{
 	{
-		btScalar delta = (point-line0).dot(lineDelta) / (lineDelta).dot(lineDelta);
+		btScalar delta = (point - line0).dot(lineDelta) / (lineDelta).dot(lineDelta);
 
 
 		// Clamp the point to conform to the segment's endpoints
 		// Clamp the point to conform to the segment's endpoints
-		if ( delta < 0 )
+		if (delta < 0)
 			delta = 0;
 			delta = 0;
-		else if ( delta > 1 )
+		else if (delta > 1)
 			delta = 1;
 			delta = 1;
 
 
-		nearestPoint = line0 + lineDelta*delta;
+		nearestPoint = line0 + lineDelta * delta;
 	}
 	}
 }
 }
 
 
-
-
-
-bool	btClampNormal(const btVector3& edge,const btVector3& tri_normal_org,const btVector3& localContactNormalOnB, btScalar correctedEdgeAngle, btVector3 & clampedLocalNormal)
+bool btClampNormal(const btVector3& edge, const btVector3& tri_normal_org, const btVector3& localContactNormalOnB, btScalar correctedEdgeAngle, btVector3& clampedLocalNormal)
 {
 {
 	btVector3 tri_normal = tri_normal_org;
 	btVector3 tri_normal = tri_normal_org;
 	//we only have a local triangle normal, not a local contact normal -> only normal in world space...
 	//we only have a local triangle normal, not a local contact normal -> only normal in world space...
 	//either compute the current angle all in local space, or all in world space
 	//either compute the current angle all in local space, or all in world space
 
 
 	btVector3 edgeCross = edge.cross(tri_normal).normalize();
 	btVector3 edgeCross = edge.cross(tri_normal).normalize();
-	btScalar curAngle = btGetAngle(edgeCross,tri_normal,localContactNormalOnB);
+	btScalar curAngle = btGetAngle(edgeCross, tri_normal, localContactNormalOnB);
 
 
-	if (correctedEdgeAngle<0)
+	if (correctedEdgeAngle < 0)
 	{
 	{
 		if (curAngle < correctedEdgeAngle)
 		if (curAngle < correctedEdgeAngle)
 		{
 		{
-			btScalar diffAngle = correctedEdgeAngle-curAngle;
-			btQuaternion rotation(edge,diffAngle );
-			clampedLocalNormal = btMatrix3x3(rotation)*localContactNormalOnB;
+			btScalar diffAngle = correctedEdgeAngle - curAngle;
+			btQuaternion rotation(edge, diffAngle);
+			clampedLocalNormal = btMatrix3x3(rotation) * localContactNormalOnB;
 			return true;
 			return true;
 		}
 		}
 	}
 	}
 
 
-	if (correctedEdgeAngle>=0)
+	if (correctedEdgeAngle >= 0)
 	{
 	{
 		if (curAngle > correctedEdgeAngle)
 		if (curAngle > correctedEdgeAngle)
 		{
 		{
-			btScalar diffAngle = correctedEdgeAngle-curAngle;
-			btQuaternion rotation(edge,diffAngle );
-			clampedLocalNormal = btMatrix3x3(rotation)*localContactNormalOnB;
+			btScalar diffAngle = correctedEdgeAngle - curAngle;
+			btQuaternion rotation(edge, diffAngle);
+			clampedLocalNormal = btMatrix3x3(rotation) * localContactNormalOnB;
 			return true;
 			return true;
 		}
 		}
 	}
 	}
 	return false;
 	return false;
 }
 }
 
 
-
-
 /// Changes a btManifoldPoint collision normal to the normal from the mesh.
 /// Changes a btManifoldPoint collision normal to the normal from the mesh.
-void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap,const btCollisionObjectWrapper* colObj1Wrap, int partId0, int index0, int normalAdjustFlags)
+void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, const btCollisionObjectWrapper* colObj1Wrap, int partId0, int index0, int normalAdjustFlags)
 {
 {
 	//btAssert(colObj0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE);
 	//btAssert(colObj0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE);
 	if (colObj0Wrap->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
 	if (colObj0Wrap->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
 		return;
 		return;
 
 
+	
+	btTriangleInfoMap* triangleInfoMapPtr = 0;
+
+	if (colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType() == TERRAIN_SHAPE_PROXYTYPE)
+	{
+		btHeightfieldTerrainShape* heightfield = (btHeightfieldTerrainShape*)colObj0Wrap->getCollisionObject()->getCollisionShape();
+		triangleInfoMapPtr = heightfield->getTriangleInfoMap();
+
+//#define USE_HEIGHTFIELD_TRIANGLES
+#ifdef USE_HEIGHTFIELD_TRIANGLES
+		btVector3 newNormal = btVector3(0, 0, 1);
+
+		const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0Wrap->getCollisionShape());
+		btVector3 tri_normal;
+		tri_shape->calcNormal(tri_normal);
+		newNormal = tri_normal;
+		//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
+		cp.m_normalWorldOnB = newNormal;
+		// Reproject collision point along normal. (what about cp.m_distance1?)
+		cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
+		cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
+		return;
+#endif
+	}
+
+
 	btBvhTriangleMeshShape* trimesh = 0;
 	btBvhTriangleMeshShape* trimesh = 0;
+
+	if (colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE)
+	{
+		trimesh = ((btScaledBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape())->getChildShape();
+	}
+	else
+	{
+		if (colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
+		{
+			trimesh = (btBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape();
+		}
+	}
+	if (trimesh)
+	{
+		triangleInfoMapPtr = (btTriangleInfoMap*)trimesh->getTriangleInfoMap();
+	}
+	
 	
 	
-	if( colObj0Wrap->getCollisionObject()->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE )
-	   trimesh = ((btScaledBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape())->getChildShape();
-   else	   
-	   trimesh = (btBvhTriangleMeshShape*)colObj0Wrap->getCollisionObject()->getCollisionShape();
-	   
-   	btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap();
 	if (!triangleInfoMapPtr)
 	if (!triangleInfoMapPtr)
 		return;
 		return;
 
 
-	int hash = btGetHash(partId0,index0);
-
+	int hash = btGetHash(partId0, index0);
 
 
 	btTriangleInfo* info = triangleInfoMapPtr->find(hash);
 	btTriangleInfo* info = triangleInfoMapPtr->find(hash);
 	if (!info)
 	if (!info)
 		return;
 		return;
 
 
-	btScalar frontFacing = (normalAdjustFlags & BT_TRIANGLE_CONVEX_BACKFACE_MODE)==0? 1.f : -1.f;
-	
+	btScalar frontFacing = (normalAdjustFlags & BT_TRIANGLE_CONVEX_BACKFACE_MODE) == 0 ? 1.f : -1.f;
+
 	const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0Wrap->getCollisionShape());
 	const btTriangleShape* tri_shape = static_cast<const btTriangleShape*>(colObj0Wrap->getCollisionShape());
-	btVector3 v0,v1,v2;
-	tri_shape->getVertex(0,v0);
-	tri_shape->getVertex(1,v1);
-	tri_shape->getVertex(2,v2);
+	btVector3 v0, v1, v2;
+	tri_shape->getVertex(0, v0);
+	tri_shape->getVertex(1, v1);
+	tri_shape->getVertex(2, v2);
 
 
 	//btVector3 center = (v0+v1+v2)*btScalar(1./3.);
 	//btVector3 center = (v0+v1+v2)*btScalar(1./3.);
 
 
-	btVector3 red(1,0,0), green(0,1,0),blue(0,0,1),white(1,1,1),black(0,0,0);
+	btVector3 red(1, 0, 0), green(0, 1, 0), blue(0, 0, 1), white(1, 1, 1), black(0, 0, 0);
 	btVector3 tri_normal;
 	btVector3 tri_normal;
 	tri_shape->calcNormal(tri_normal);
 	tri_shape->calcNormal(tri_normal);
 
 
 	//btScalar dot = tri_normal.dot(cp.m_normalWorldOnB);
 	//btScalar dot = tri_normal.dot(cp.m_normalWorldOnB);
 	btVector3 nearest;
 	btVector3 nearest;
-	btNearestPointInLineSegment(cp.m_localPointB,v0,v1,nearest);
+	btNearestPointInLineSegment(cp.m_localPointB, v0, v1, nearest);
 
 
 	btVector3 contact = cp.m_localPointB;
 	btVector3 contact = cp.m_localPointB;
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 	const btTransform& tr = colObj0->getWorldTransform();
 	const btTransform& tr = colObj0->getWorldTransform();
-	btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,red);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-
+	btDebugDrawLine(tr * nearest, tr * cp.m_localPointB, red);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
 	bool isNearEdge = false;
 	bool isNearEdge = false;
 
 
@@ -502,334 +573,325 @@ void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWr
 	int numConvexEdgeHits = 0;
 	int numConvexEdgeHits = 0;
 
 
 	btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
 	btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
-	localContactNormalOnB.normalize();//is this necessary?
-	
+	localContactNormalOnB.normalize();  //is this necessary?
+
 	// Get closest edge
 	// Get closest edge
-	int      bestedge=-1;
-	btScalar    disttobestedge=BT_LARGE_FLOAT;
+	int bestedge = -1;
+	btScalar disttobestedge = BT_LARGE_FLOAT;
 	//
 	//
 	// Edge 0 -> 1
 	// Edge 0 -> 1
-	if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
-	{	
-	   btVector3 nearest;
-	   btNearestPointInLineSegment( cp.m_localPointB, v0, v1, nearest );
-	   btScalar     len=(contact-nearest).length();
-	   //
-	   if( len < disttobestedge )
-	   {
-	      bestedge=0;
-	      disttobestedge=len;
-      }	      
-   }	   
+	if (btFabs(info->m_edgeV0V1Angle) < triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	{
+		btVector3 nearest;
+		btNearestPointInLineSegment(cp.m_localPointB, v0, v1, nearest);
+		btScalar len = (contact - nearest).length();
+		//
+		if (len < disttobestedge)
+		{
+			bestedge = 0;
+			disttobestedge = len;
+		}
+	}
 	// Edge 1 -> 2
 	// Edge 1 -> 2
-	if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
-	{	
-	   btVector3 nearest;
-	   btNearestPointInLineSegment( cp.m_localPointB, v1, v2, nearest );
-	   btScalar     len=(contact-nearest).length();
-	   //
-	   if( len < disttobestedge )
-	   {
-	      bestedge=1;
-	      disttobestedge=len;
-      }	      
-   }	   
+	if (btFabs(info->m_edgeV1V2Angle) < triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	{
+		btVector3 nearest;
+		btNearestPointInLineSegment(cp.m_localPointB, v1, v2, nearest);
+		btScalar len = (contact - nearest).length();
+		//
+		if (len < disttobestedge)
+		{
+			bestedge = 1;
+			disttobestedge = len;
+		}
+	}
 	// Edge 2 -> 0
 	// Edge 2 -> 0
-	if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
-	{	
-	   btVector3 nearest;
-	   btNearestPointInLineSegment( cp.m_localPointB, v2, v0, nearest );
-	   btScalar     len=(contact-nearest).length();
-	   //
-	   if( len < disttobestedge )
-	   {
-	      bestedge=2;
-	      disttobestedge=len;
-      }	      
-   }   	      	
-	
+	if (btFabs(info->m_edgeV2V0Angle) < triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	{
+		btVector3 nearest;
+		btNearestPointInLineSegment(cp.m_localPointB, v2, v0, nearest);
+		btScalar len = (contact - nearest).length();
+		//
+		if (len < disttobestedge)
+		{
+			bestedge = 2;
+			disttobestedge = len;
+		}
+	}
+
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-   btVector3 upfix=tri_normal * btVector3(0.1f,0.1f,0.1f);
-   btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red );
-#endif   
-	if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	btVector3 upfix = tri_normal * btVector3(0.1f, 0.1f, 0.1f);
+	btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red);
+#endif
+	if (btFabs(info->m_edgeV0V1Angle) < triangleInfoMapPtr->m_maxEdgeAngleThreshold)
 	{
 	{
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-		btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
+		btDebugDrawLine(tr * contact, tr * (contact + cp.m_normalWorldOnB * 10), black);
 #endif
 #endif
-		btScalar len = (contact-nearest).length();
-		if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
-		if( bestedge==0 )
-		{
-			btVector3 edge(v0-v1);
-			isNearEdge = true;
-
-			if (info->m_edgeV0V1Angle==btScalar(0))
-			{
-				numConcaveEdgeHits++;
-			} else
+		btScalar len = (contact - nearest).length();
+		if (len < triangleInfoMapPtr->m_edgeDistanceThreshold)
+			if (bestedge == 0)
 			{
 			{
+				btVector3 edge(v0 - v1);
+				isNearEdge = true;
 
 
-				bool isEdgeConvex = (info->m_flags & TRI_INFO_V0V1_CONVEX);
-				btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
-	#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-				btDebugDrawLine(tr*nearest,tr*(nearest+swapFactor*tri_normal*10),white);
-	#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
+				if (info->m_edgeV0V1Angle == btScalar(0))
+				{
+					numConcaveEdgeHits++;
+				}
+				else
+				{
+					bool isEdgeConvex = (info->m_flags & TRI_INFO_V0V1_CONVEX);
+					btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+					btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
-				btVector3 nA = swapFactor * tri_normal;
+					btVector3 nA = swapFactor * tri_normal;
 
 
-				btQuaternion orn(edge,info->m_edgeV0V1Angle);
-				btVector3 computedNormalB = quatRotate(orn,tri_normal);
-				if (info->m_flags & TRI_INFO_V0V1_SWAP_NORMALB)
-					computedNormalB*=-1;
-				btVector3 nB = swapFactor*computedNormalB;
+					btQuaternion orn(edge, info->m_edgeV0V1Angle);
+					btVector3 computedNormalB = quatRotate(orn, tri_normal);
+					if (info->m_flags & TRI_INFO_V0V1_SWAP_NORMALB)
+						computedNormalB *= -1;
+					btVector3 nB = swapFactor * computedNormalB;
 
 
-				btScalar	NdotA = localContactNormalOnB.dot(nA);
-				btScalar	NdotB = localContactNormalOnB.dot(nB);
-				bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);
+					btScalar NdotA = localContactNormalOnB.dot(nA);
+					btScalar NdotB = localContactNormalOnB.dot(nB);
+					bool backFacingNormal = (NdotA < triangleInfoMapPtr->m_convexEpsilon) && (NdotB < triangleInfoMapPtr->m_convexEpsilon);
 
 
 #ifdef DEBUG_INTERNAL_EDGE
 #ifdef DEBUG_INTERNAL_EDGE
-				{
-					
-					btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+tr.getBasis()*(nB*20),red);
-				}
-#endif //DEBUG_INTERNAL_EDGE
-
+					{
+						btDebugDrawLine(cp.getPositionWorldOnB(), cp.getPositionWorldOnB() + tr.getBasis() * (nB * 20), red);
+					}
+#endif  //DEBUG_INTERNAL_EDGE
 
 
-				if (backFacingNormal)
-				{
-					numConcaveEdgeHits++;
-				}
-				else
-				{
-					numConvexEdgeHits++;
-					btVector3 clampedLocalNormal;
-					bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB, info->m_edgeV0V1Angle,clampedLocalNormal);
-					if (isClamped)
+					if (backFacingNormal)
 					{
 					{
-						if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
+						numConcaveEdgeHits++;
+					}
+					else
+					{
+						numConvexEdgeHits++;
+						btVector3 clampedLocalNormal;
+						bool isClamped = btClampNormal(edge, swapFactor * tri_normal, localContactNormalOnB, info->m_edgeV0V1Angle, clampedLocalNormal);
+						if (isClamped)
 						{
 						{
-							btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
-							//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
-							cp.m_normalWorldOnB = newNormal;
-							// Reproject collision point along normal. (what about cp.m_distance1?)
-							cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-							cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
-							
+							if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED) != 0) || (clampedLocalNormal.dot(frontFacing * tri_normal) > 0))
+							{
+								btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
+								//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
+								cp.m_normalWorldOnB = newNormal;
+								// Reproject collision point along normal. (what about cp.m_distance1?)
+								cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
+								cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
+							}
 						}
 						}
 					}
 					}
 				}
 				}
 			}
 			}
-		}
 	}
 	}
 
 
-	btNearestPointInLineSegment(contact,v1,v2,nearest);
+	btNearestPointInLineSegment(contact, v1, v2, nearest);
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-	btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,green);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
+	btDebugDrawLine(tr * nearest, tr * cp.m_localPointB, green);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-   btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix , green );
-#endif   
+	btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix, green);
+#endif
 
 
-	if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	if (btFabs(info->m_edgeV1V2Angle) < triangleInfoMapPtr->m_maxEdgeAngleThreshold)
 	{
 	{
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-		btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-
-
-		btScalar len = (contact-nearest).length();
-		if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
-		if( bestedge==1 )
-		{
-			isNearEdge = true;
-#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-			btDebugDrawLine(tr*nearest,tr*(nearest+tri_normal*10),white);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-			btVector3 edge(v1-v2);
-
-			isNearEdge = true;
+		btDebugDrawLine(tr * contact, tr * (contact + cp.m_normalWorldOnB * 10), black);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
-			if (info->m_edgeV1V2Angle == btScalar(0))
+		btScalar len = (contact - nearest).length();
+		if (len < triangleInfoMapPtr->m_edgeDistanceThreshold)
+			if (bestedge == 1)
 			{
 			{
-				numConcaveEdgeHits++;
-			} else
-			{
-				bool isEdgeConvex = (info->m_flags & TRI_INFO_V1V2_CONVEX)!=0;
-				btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
-	#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-				btDebugDrawLine(tr*nearest,tr*(nearest+swapFactor*tri_normal*10),white);
-	#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-				btVector3 nA = swapFactor * tri_normal;
-				
-				btQuaternion orn(edge,info->m_edgeV1V2Angle);
-				btVector3 computedNormalB = quatRotate(orn,tri_normal);
-				if (info->m_flags & TRI_INFO_V1V2_SWAP_NORMALB)
-					computedNormalB*=-1;
-				btVector3 nB = swapFactor*computedNormalB;
-
-#ifdef DEBUG_INTERNAL_EDGE
-				{
-					btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+tr.getBasis()*(nB*20),red);
-				}
-#endif //DEBUG_INTERNAL_EDGE
+				isNearEdge = true;
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+				btDebugDrawLine(tr * nearest, tr * (nearest + tri_normal * 10), white);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
+				btVector3 edge(v1 - v2);
 
 
-				btScalar	NdotA = localContactNormalOnB.dot(nA);
-				btScalar	NdotB = localContactNormalOnB.dot(nB);
-				bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);
+				isNearEdge = true;
 
 
-				if (backFacingNormal)
+				if (info->m_edgeV1V2Angle == btScalar(0))
 				{
 				{
 					numConcaveEdgeHits++;
 					numConcaveEdgeHits++;
 				}
 				}
 				else
 				else
 				{
 				{
-					numConvexEdgeHits++;
-					btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
-					btVector3 clampedLocalNormal;
-					bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB, info->m_edgeV1V2Angle,clampedLocalNormal);
-					if (isClamped)
+					bool isEdgeConvex = (info->m_flags & TRI_INFO_V1V2_CONVEX) != 0;
+					btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+					btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
+
+					btVector3 nA = swapFactor * tri_normal;
+
+					btQuaternion orn(edge, info->m_edgeV1V2Angle);
+					btVector3 computedNormalB = quatRotate(orn, tri_normal);
+					if (info->m_flags & TRI_INFO_V1V2_SWAP_NORMALB)
+						computedNormalB *= -1;
+					btVector3 nB = swapFactor * computedNormalB;
+
+#ifdef DEBUG_INTERNAL_EDGE
+					{
+						btDebugDrawLine(cp.getPositionWorldOnB(), cp.getPositionWorldOnB() + tr.getBasis() * (nB * 20), red);
+					}
+#endif  //DEBUG_INTERNAL_EDGE
+
+					btScalar NdotA = localContactNormalOnB.dot(nA);
+					btScalar NdotB = localContactNormalOnB.dot(nB);
+					bool backFacingNormal = (NdotA < triangleInfoMapPtr->m_convexEpsilon) && (NdotB < triangleInfoMapPtr->m_convexEpsilon);
+
+					if (backFacingNormal)
+					{
+						numConcaveEdgeHits++;
+					}
+					else
 					{
 					{
-						if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
+						numConvexEdgeHits++;
+						btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
+						btVector3 clampedLocalNormal;
+						bool isClamped = btClampNormal(edge, swapFactor * tri_normal, localContactNormalOnB, info->m_edgeV1V2Angle, clampedLocalNormal);
+						if (isClamped)
 						{
 						{
-							btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
-							//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
-							cp.m_normalWorldOnB = newNormal;
-							// Reproject collision point along normal.
-							cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-							cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
+							if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED) != 0) || (clampedLocalNormal.dot(frontFacing * tri_normal) > 0))
+							{
+								btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
+								//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
+								cp.m_normalWorldOnB = newNormal;
+								// Reproject collision point along normal.
+								cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
+								cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
+							}
 						}
 						}
 					}
 					}
 				}
 				}
 			}
 			}
-		}
 	}
 	}
 
 
-	btNearestPointInLineSegment(contact,v2,v0,nearest);
+	btNearestPointInLineSegment(contact, v2, v0, nearest);
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-	btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,blue);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
+	btDebugDrawLine(tr * nearest, tr * cp.m_localPointB, blue);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-   btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix , blue );
-#endif   
+	btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix, blue);
+#endif
 
 
-	if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold)
+	if (btFabs(info->m_edgeV2V0Angle) < triangleInfoMapPtr->m_maxEdgeAngleThreshold)
 	{
 	{
-
-#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-		btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-		btScalar len = (contact-nearest).length();
-		if(len<triangleInfoMapPtr->m_edgeDistanceThreshold)
-		if( bestedge==2 )
-		{
-			isNearEdge = true;
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-			btDebugDrawLine(tr*nearest,tr*(nearest+tri_normal*10),white);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-			btVector3 edge(v2-v0);
+		btDebugDrawLine(tr * contact, tr * (contact + cp.m_normalWorldOnB * 10), black);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
-			if (info->m_edgeV2V0Angle==btScalar(0))
-			{
-				numConcaveEdgeHits++;
-			} else
+		btScalar len = (contact - nearest).length();
+		if (len < triangleInfoMapPtr->m_edgeDistanceThreshold)
+			if (bestedge == 2)
 			{
 			{
+				isNearEdge = true;
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+				btDebugDrawLine(tr * nearest, tr * (nearest + tri_normal * 10), white);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
-				bool isEdgeConvex = (info->m_flags & TRI_INFO_V2V0_CONVEX)!=0;
-				btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
-	#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-				btDebugDrawLine(tr*nearest,tr*(nearest+swapFactor*tri_normal*10),white);
-	#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-				btVector3 nA = swapFactor * tri_normal;
-				btQuaternion orn(edge,info->m_edgeV2V0Angle);
-				btVector3 computedNormalB = quatRotate(orn,tri_normal);
-				if (info->m_flags & TRI_INFO_V2V0_SWAP_NORMALB)
-					computedNormalB*=-1;
-				btVector3 nB = swapFactor*computedNormalB;
-
-#ifdef DEBUG_INTERNAL_EDGE
-				{
-					btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+tr.getBasis()*(nB*20),red);
-				}
-#endif //DEBUG_INTERNAL_EDGE
-
-				btScalar	NdotA = localContactNormalOnB.dot(nA);
-				btScalar	NdotB = localContactNormalOnB.dot(nB);
-				bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);
+				btVector3 edge(v2 - v0);
 
 
-				if (backFacingNormal)
+				if (info->m_edgeV2V0Angle == btScalar(0))
 				{
 				{
 					numConcaveEdgeHits++;
 					numConcaveEdgeHits++;
 				}
 				}
 				else
 				else
 				{
 				{
-					numConvexEdgeHits++;
-					//				printf("hitting convex edge\n");
+					bool isEdgeConvex = (info->m_flags & TRI_INFO_V2V0_CONVEX) != 0;
+					btScalar swapFactor = isEdgeConvex ? btScalar(1) : btScalar(-1);
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+					btDebugDrawLine(tr * nearest, tr * (nearest + swapFactor * tri_normal * 10), white);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
+
+					btVector3 nA = swapFactor * tri_normal;
+					btQuaternion orn(edge, info->m_edgeV2V0Angle);
+					btVector3 computedNormalB = quatRotate(orn, tri_normal);
+					if (info->m_flags & TRI_INFO_V2V0_SWAP_NORMALB)
+						computedNormalB *= -1;
+					btVector3 nB = swapFactor * computedNormalB;
+
+#ifdef DEBUG_INTERNAL_EDGE
+					{
+						btDebugDrawLine(cp.getPositionWorldOnB(), cp.getPositionWorldOnB() + tr.getBasis() * (nB * 20), red);
+					}
+#endif  //DEBUG_INTERNAL_EDGE
 
 
+					btScalar NdotA = localContactNormalOnB.dot(nA);
+					btScalar NdotB = localContactNormalOnB.dot(nB);
+					bool backFacingNormal = (NdotA < triangleInfoMapPtr->m_convexEpsilon) && (NdotB < triangleInfoMapPtr->m_convexEpsilon);
 
 
-					btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
-					btVector3 clampedLocalNormal;
-					bool isClamped = btClampNormal(edge,swapFactor*tri_normal,localContactNormalOnB,info->m_edgeV2V0Angle,clampedLocalNormal);
-					if (isClamped)
+					if (backFacingNormal)
+					{
+						numConcaveEdgeHits++;
+					}
+					else
 					{
 					{
-						if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED)!=0) || (clampedLocalNormal.dot(frontFacing*tri_normal)>0))
+						numConvexEdgeHits++;
+						//				printf("hitting convex edge\n");
+
+						btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
+						btVector3 clampedLocalNormal;
+						bool isClamped = btClampNormal(edge, swapFactor * tri_normal, localContactNormalOnB, info->m_edgeV2V0Angle, clampedLocalNormal);
+						if (isClamped)
 						{
 						{
-							btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
-							//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
-							cp.m_normalWorldOnB = newNormal;
-							// Reproject collision point along normal.
-							cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
-							cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
+							if (((normalAdjustFlags & BT_TRIANGLE_CONVEX_DOUBLE_SIDED) != 0) || (clampedLocalNormal.dot(frontFacing * tri_normal) > 0))
+							{
+								btVector3 newNormal = colObj0Wrap->getWorldTransform().getBasis() * clampedLocalNormal;
+								//					cp.m_distance1 = cp.m_distance1 * newNormal.dot(cp.m_normalWorldOnB);
+								cp.m_normalWorldOnB = newNormal;
+								// Reproject collision point along normal.
+								cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
+								cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
+							}
 						}
 						}
 					}
 					}
-				} 
+				}
 			}
 			}
-			
-
-		}
 	}
 	}
 
 
 #ifdef DEBUG_INTERNAL_EDGE
 #ifdef DEBUG_INTERNAL_EDGE
 	{
 	{
-		btVector3 color(0,1,1);
-		btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+cp.m_normalWorldOnB*10,color);
+		btVector3 color(0, 1, 1);
+		btDebugDrawLine(cp.getPositionWorldOnB(), cp.getPositionWorldOnB() + cp.m_normalWorldOnB * 10, color);
 	}
 	}
-#endif //DEBUG_INTERNAL_EDGE
+#endif  //DEBUG_INTERNAL_EDGE
 
 
 	if (isNearEdge)
 	if (isNearEdge)
 	{
 	{
-
-		if (numConcaveEdgeHits>0)
+		if (numConcaveEdgeHits > 0)
 		{
 		{
-			if ((normalAdjustFlags & BT_TRIANGLE_CONCAVE_DOUBLE_SIDED)!=0)
+			if ((normalAdjustFlags & BT_TRIANGLE_CONCAVE_DOUBLE_SIDED) != 0)
 			{
 			{
 				//fix tri_normal so it pointing the same direction as the current local contact normal
 				//fix tri_normal so it pointing the same direction as the current local contact normal
 				if (tri_normal.dot(localContactNormalOnB) < 0)
 				if (tri_normal.dot(localContactNormalOnB) < 0)
 				{
 				{
 					tri_normal *= -1;
 					tri_normal *= -1;
 				}
 				}
-				cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis()*tri_normal;
-			} else
+				cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() * tri_normal;
+			}
+			else
 			{
 			{
-				btVector3 newNormal = tri_normal *frontFacing;
+				btVector3 newNormal = tri_normal * frontFacing;
 				//if the tri_normal is pointing opposite direction as the current local contact normal, skip it
 				//if the tri_normal is pointing opposite direction as the current local contact normal, skip it
-				btScalar d = newNormal.dot(localContactNormalOnB) ;
-				if (d< 0)
+				btScalar d = newNormal.dot(localContactNormalOnB);
+				if (d < 0)
 				{
 				{
 					return;
 					return;
 				}
 				}
 				//modify the normal to be the triangle normal (or backfacing normal)
 				//modify the normal to be the triangle normal (or backfacing normal)
-				cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() *newNormal;
+				cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() * newNormal;
 			}
 			}
-						
+
 			// Reproject collision point along normal.
 			// Reproject collision point along normal.
 			cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
 			cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
 			cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);
 			cp.m_localPointB = colObj0Wrap->getWorldTransform().invXform(cp.m_positionWorldOnB);

+ 8 - 11
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h

@@ -15,33 +15,30 @@ class btCollisionObject;
 struct btCollisionObjectWrapper;
 struct btCollisionObjectWrapper;
 class btManifoldPoint;
 class btManifoldPoint;
 class btIDebugDraw;
 class btIDebugDraw;
-
-
+class btHeightfieldTerrainShape;
 
 
 enum btInternalEdgeAdjustFlags
 enum btInternalEdgeAdjustFlags
 {
 {
 	BT_TRIANGLE_CONVEX_BACKFACE_MODE = 1,
 	BT_TRIANGLE_CONVEX_BACKFACE_MODE = 1,
-	BT_TRIANGLE_CONCAVE_DOUBLE_SIDED = 2, //double sided options are experimental, single sided is recommended
+	BT_TRIANGLE_CONCAVE_DOUBLE_SIDED = 2,  //double sided options are experimental, single sided is recommended
 	BT_TRIANGLE_CONVEX_DOUBLE_SIDED = 4
 	BT_TRIANGLE_CONVEX_DOUBLE_SIDED = 4
 };
 };
 
 
-
 ///Call btGenerateInternalEdgeInfo to create triangle info, store in the shape 'userInfo'
 ///Call btGenerateInternalEdgeInfo to create triangle info, store in the shape 'userInfo'
-void	btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangleInfoMap* triangleInfoMap);
+void btGenerateInternalEdgeInfo(btBvhTriangleMeshShape* trimeshShape, btTriangleInfoMap* triangleInfoMap);
 
 
+void btGenerateInternalEdgeInfo(btHeightfieldTerrainShape* trimeshShape, btTriangleInfoMap* triangleInfoMap);
 
 
 ///Call the btFixMeshNormal to adjust the collision normal, using the triangle info map (generated using btGenerateInternalEdgeInfo)
 ///Call the btFixMeshNormal to adjust the collision normal, using the triangle info map (generated using btGenerateInternalEdgeInfo)
 ///If this info map is missing, or the triangle is not store in this map, nothing will be done
 ///If this info map is missing, or the triangle is not store in this map, nothing will be done
-void	btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* trimeshColObj0Wrap,const btCollisionObjectWrapper* otherColObj1Wrap, int partId0, int index0, int normalAdjustFlags = 0);
+void btAdjustInternalEdgeContacts(btManifoldPoint& cp, const btCollisionObjectWrapper* trimeshColObj0Wrap, const btCollisionObjectWrapper* otherColObj1Wrap, int partId0, int index0, int normalAdjustFlags = 0);
 
 
 ///Enable the BT_INTERNAL_EDGE_DEBUG_DRAW define and call btSetDebugDrawer, to get visual info to see if the internal edge utility works properly.
 ///Enable the BT_INTERNAL_EDGE_DEBUG_DRAW define and call btSetDebugDrawer, to get visual info to see if the internal edge utility works properly.
 ///If the utility doesn't work properly, you might have to adjust the threshold values in btTriangleInfoMap
 ///If the utility doesn't work properly, you might have to adjust the threshold values in btTriangleInfoMap
 //#define BT_INTERNAL_EDGE_DEBUG_DRAW
 //#define BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
-void	btSetDebugDrawer(btIDebugDraw* debugDrawer);
-#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
-
-
-#endif //BT_INTERNAL_EDGE_UTILITY_H
+void btSetDebugDrawer(btIDebugDraw* debugDrawer);
+#endif  //BT_INTERNAL_EDGE_DEBUG_DRAW
 
 
+#endif  //BT_INTERNAL_EDGE_UTILITY_H

+ 94 - 82
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp

@@ -13,179 +13,191 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "btManifoldResult.h"
 #include "btManifoldResult.h"
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
 ///This is to allow MaterialCombiner/Custom Friction/Restitution values
 ///This is to allow MaterialCombiner/Custom Friction/Restitution values
-ContactAddedCallback		gContactAddedCallback=0;
-
+ContactAddedCallback gContactAddedCallback = 0;
 
 
+CalculateCombinedCallback gCalculateCombinedRestitutionCallback = &btManifoldResult::calculateCombinedRestitution;
+CalculateCombinedCallback gCalculateCombinedFrictionCallback = &btManifoldResult::calculateCombinedFriction;
+CalculateCombinedCallback gCalculateCombinedRollingFrictionCallback = &btManifoldResult::calculateCombinedRollingFriction;
+CalculateCombinedCallback gCalculateCombinedSpinningFrictionCallback = &btManifoldResult::calculateCombinedSpinningFriction;
+CalculateCombinedCallback gCalculateCombinedContactDampingCallback = &btManifoldResult::calculateCombinedContactDamping;
+CalculateCombinedCallback gCalculateCombinedContactStiffnessCallback = &btManifoldResult::calculateCombinedContactStiffness;
 
 
-btScalar	btManifoldResult::calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar btManifoldResult::calculateCombinedRollingFriction(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
 	btScalar friction = body0->getRollingFriction() * body1->getFriction() + body1->getRollingFriction() * body0->getFriction();
 	btScalar friction = body0->getRollingFriction() * body1->getFriction() + body1->getRollingFriction() * body0->getFriction();
 
 
-	const btScalar MAX_FRICTION  = btScalar(10.);
+	const btScalar MAX_FRICTION = btScalar(10.);
 	if (friction < -MAX_FRICTION)
 	if (friction < -MAX_FRICTION)
 		friction = -MAX_FRICTION;
 		friction = -MAX_FRICTION;
 	if (friction > MAX_FRICTION)
 	if (friction > MAX_FRICTION)
 		friction = MAX_FRICTION;
 		friction = MAX_FRICTION;
 	return friction;
 	return friction;
-
 }
 }
 
 
-btScalar	btManifoldResult::calculateCombinedSpinningFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar btManifoldResult::calculateCombinedSpinningFriction(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
-    btScalar friction = body0->getSpinningFriction() * body1->getFriction() + body1->getSpinningFriction() * body0->getFriction();
-    
-    const btScalar MAX_FRICTION  = btScalar(10.);
-    if (friction < -MAX_FRICTION)
-        friction = -MAX_FRICTION;
-    if (friction > MAX_FRICTION)
-        friction = MAX_FRICTION;
-    return friction;
+	btScalar friction = body0->getSpinningFriction() * body1->getFriction() + body1->getSpinningFriction() * body0->getFriction();
+
+	const btScalar MAX_FRICTION = btScalar(10.);
+	if (friction < -MAX_FRICTION)
+		friction = -MAX_FRICTION;
+	if (friction > MAX_FRICTION)
+		friction = MAX_FRICTION;
+	return friction;
 }
 }
 
 
 ///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
 ///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
-btScalar	btManifoldResult::calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar btManifoldResult::calculateCombinedFriction(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
 	btScalar friction = body0->getFriction() * body1->getFriction();
 	btScalar friction = body0->getFriction() * body1->getFriction();
 
 
-	const btScalar MAX_FRICTION  = btScalar(10.);
+	const btScalar MAX_FRICTION = btScalar(10.);
 	if (friction < -MAX_FRICTION)
 	if (friction < -MAX_FRICTION)
 		friction = -MAX_FRICTION;
 		friction = -MAX_FRICTION;
 	if (friction > MAX_FRICTION)
 	if (friction > MAX_FRICTION)
 		friction = MAX_FRICTION;
 		friction = MAX_FRICTION;
 	return friction;
 	return friction;
-
 }
 }
 
 
-btScalar	btManifoldResult::calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar btManifoldResult::calculateCombinedRestitution(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
 	return body0->getRestitution() * body1->getRestitution();
 	return body0->getRestitution() * body1->getRestitution();
 }
 }
 
 
-btScalar	btManifoldResult::calculateCombinedContactDamping(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar btManifoldResult::calculateCombinedContactDamping(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
-    return body0->getContactDamping() + body1->getContactDamping();
+	return body0->getContactDamping() + body1->getContactDamping();
 }
 }
 
 
-btScalar	btManifoldResult::calculateCombinedContactStiffness(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar btManifoldResult::calculateCombinedContactStiffness(const btCollisionObject* body0, const btCollisionObject* body1)
 {
 {
-    
-    btScalar s0 = body0->getContactStiffness();
-    btScalar s1 = body1->getContactStiffness();
-    
-    btScalar tmp0 = btScalar(1)/s0;
-    btScalar tmp1 = btScalar(1)/s1;
-    btScalar combinedStiffness = btScalar(1) / (tmp0+tmp1);
-    return combinedStiffness;
-}
+	btScalar s0 = body0->getContactStiffness();
+	btScalar s1 = body1->getContactStiffness();
 
 
+	btScalar tmp0 = btScalar(1) / s0;
+	btScalar tmp1 = btScalar(1) / s1;
+	btScalar combinedStiffness = btScalar(1) / (tmp0 + tmp1);
+	return combinedStiffness;
+}
 
 
-btManifoldResult::btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
-		:m_manifoldPtr(0),
-		m_body0Wrap(body0Wrap),
-		m_body1Wrap(body1Wrap)
+btManifoldResult::btManifoldResult(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
+	: m_manifoldPtr(0),
+	  m_body0Wrap(body0Wrap),
+	  m_body1Wrap(body1Wrap)
 #ifdef DEBUG_PART_INDEX
 #ifdef DEBUG_PART_INDEX
-		,m_partId0(-1),
-	m_partId1(-1),
-	m_index0(-1),
-	m_index1(-1)
-#endif //DEBUG_PART_INDEX
-	, m_closestPointDistanceThreshold(0)
+	  ,
+	  m_partId0(-1),
+	  m_partId1(-1),
+	  m_index0(-1),
+	  m_index1(-1)
+#endif  //DEBUG_PART_INDEX
+	  ,
+	  m_closestPointDistanceThreshold(0)
 {
 {
 }
 }
 
 
-
-void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
+void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld, const btVector3& pointInWorld, btScalar depth)
 {
 {
 	btAssert(m_manifoldPtr);
 	btAssert(m_manifoldPtr);
 	//order in manifold needs to match
 	//order in manifold needs to match
 
 
 	if (depth > m_manifoldPtr->getContactBreakingThreshold())
 	if (depth > m_manifoldPtr->getContactBreakingThreshold())
-//	if (depth > m_manifoldPtr->getContactProcessingThreshold())
+		//	if (depth > m_manifoldPtr->getContactProcessingThreshold())
 		return;
 		return;
 
 
 	bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
 	bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
+	bool isNewCollision = m_manifoldPtr->getNumContacts() == 0;
 
 
 	btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
 	btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
 
 
 	btVector3 localA;
 	btVector3 localA;
 	btVector3 localB;
 	btVector3 localB;
-	
+
 	if (isSwapped)
 	if (isSwapped)
 	{
 	{
-		localA = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+		localA = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointA);
 		localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
 		localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
-	} else
+	}
+	else
 	{
 	{
-		localA = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+		localA = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointA);
 		localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
 		localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
 	}
 	}
 
 
-	btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
+	btManifoldPoint newPt(localA, localB, normalOnBInWorld, depth);
 	newPt.m_positionWorldOnA = pointA;
 	newPt.m_positionWorldOnA = pointA;
 	newPt.m_positionWorldOnB = pointInWorld;
 	newPt.m_positionWorldOnB = pointInWorld;
-	
+
 	int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
 	int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
 
 
-	newPt.m_combinedFriction = calculateCombinedFriction(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
-	newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
-	newPt.m_combinedRollingFriction = calculateCombinedRollingFriction(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
-    newPt.m_combinedSpinningFriction = calculateCombinedSpinningFriction(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
-	
-	if (    (m_body0Wrap->getCollisionObject()->getCollisionFlags()& btCollisionObject::CF_HAS_CONTACT_STIFFNESS_DAMPING) ||
-            (m_body1Wrap->getCollisionObject()->getCollisionFlags()& btCollisionObject::CF_HAS_CONTACT_STIFFNESS_DAMPING))
-    {
-        newPt.m_combinedContactDamping1 = calculateCombinedContactDamping(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
-        newPt.m_combinedContactStiffness1 = calculateCombinedContactStiffness(m_body0Wrap->getCollisionObject(),m_body1Wrap->getCollisionObject());
-        newPt.m_contactPointFlags |= BT_CONTACT_FLAG_CONTACT_STIFFNESS_DAMPING;
-    }
-	
-	btPlaneSpace1(newPt.m_normalWorldOnB,newPt.m_lateralFrictionDir1,newPt.m_lateralFrictionDir2);
-	
-
-	
-   //BP mod, store contact triangles.
+	newPt.m_combinedFriction = gCalculateCombinedFrictionCallback(m_body0Wrap->getCollisionObject(), m_body1Wrap->getCollisionObject());
+	newPt.m_combinedRestitution = gCalculateCombinedRestitutionCallback(m_body0Wrap->getCollisionObject(), m_body1Wrap->getCollisionObject());
+	newPt.m_combinedRollingFriction = gCalculateCombinedRollingFrictionCallback(m_body0Wrap->getCollisionObject(), m_body1Wrap->getCollisionObject());
+	newPt.m_combinedSpinningFriction = gCalculateCombinedSpinningFrictionCallback(m_body0Wrap->getCollisionObject(), m_body1Wrap->getCollisionObject());
+
+	if ((m_body0Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_HAS_CONTACT_STIFFNESS_DAMPING) ||
+		(m_body1Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_HAS_CONTACT_STIFFNESS_DAMPING))
+	{
+		newPt.m_combinedContactDamping1 = gCalculateCombinedContactDampingCallback(m_body0Wrap->getCollisionObject(), m_body1Wrap->getCollisionObject());
+		newPt.m_combinedContactStiffness1 = gCalculateCombinedContactStiffnessCallback(m_body0Wrap->getCollisionObject(), m_body1Wrap->getCollisionObject());
+		newPt.m_contactPointFlags |= BT_CONTACT_FLAG_CONTACT_STIFFNESS_DAMPING;
+	}
+
+	if ((m_body0Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_HAS_FRICTION_ANCHOR) ||
+		(m_body1Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_HAS_FRICTION_ANCHOR))
+	{
+		newPt.m_contactPointFlags |= BT_CONTACT_FLAG_FRICTION_ANCHOR;
+	}
+
+	btPlaneSpace1(newPt.m_normalWorldOnB, newPt.m_lateralFrictionDir1, newPt.m_lateralFrictionDir2);
+
+	//BP mod, store contact triangles.
 	if (isSwapped)
 	if (isSwapped)
 	{
 	{
 		newPt.m_partId0 = m_partId1;
 		newPt.m_partId0 = m_partId1;
 		newPt.m_partId1 = m_partId0;
 		newPt.m_partId1 = m_partId0;
-		newPt.m_index0  = m_index1;
-		newPt.m_index1  = m_index0;
-	} else
+		newPt.m_index0 = m_index1;
+		newPt.m_index1 = m_index0;
+	}
+	else
 	{
 	{
 		newPt.m_partId0 = m_partId0;
 		newPt.m_partId0 = m_partId0;
 		newPt.m_partId1 = m_partId1;
 		newPt.m_partId1 = m_partId1;
-		newPt.m_index0  = m_index0;
-		newPt.m_index1  = m_index1;
+		newPt.m_index0 = m_index0;
+		newPt.m_index1 = m_index1;
 	}
 	}
 	//printf("depth=%f\n",depth);
 	//printf("depth=%f\n",depth);
 	///@todo, check this for any side effects
 	///@todo, check this for any side effects
 	if (insertIndex >= 0)
 	if (insertIndex >= 0)
 	{
 	{
 		//const btManifoldPoint& oldPoint = m_manifoldPtr->getContactPoint(insertIndex);
 		//const btManifoldPoint& oldPoint = m_manifoldPtr->getContactPoint(insertIndex);
-		m_manifoldPtr->replaceContactPoint(newPt,insertIndex);
-	} else
+		m_manifoldPtr->replaceContactPoint(newPt, insertIndex);
+	}
+	else
 	{
 	{
 		insertIndex = m_manifoldPtr->addManifoldPoint(newPt);
 		insertIndex = m_manifoldPtr->addManifoldPoint(newPt);
 	}
 	}
-	
+
 	//User can override friction and/or restitution
 	//User can override friction and/or restitution
 	if (gContactAddedCallback &&
 	if (gContactAddedCallback &&
 		//and if either of the two bodies requires custom material
 		//and if either of the two bodies requires custom material
-		 ((m_body0Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
-		   (m_body1Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
+		((m_body0Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
+		 (m_body1Wrap->getCollisionObject()->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK)))
 	{
 	{
 		//experimental feature info, for per-triangle material etc.
 		//experimental feature info, for per-triangle material etc.
-		const btCollisionObjectWrapper* obj0Wrap = isSwapped? m_body1Wrap : m_body0Wrap;
-		const btCollisionObjectWrapper* obj1Wrap = isSwapped? m_body0Wrap : m_body1Wrap;
-		(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0Wrap,newPt.m_partId0,newPt.m_index0,obj1Wrap,newPt.m_partId1,newPt.m_index1);
+		const btCollisionObjectWrapper* obj0Wrap = isSwapped ? m_body1Wrap : m_body0Wrap;
+		const btCollisionObjectWrapper* obj1Wrap = isSwapped ? m_body0Wrap : m_body1Wrap;
+		(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex), obj0Wrap, newPt.m_partId0, newPt.m_index0, obj1Wrap, newPt.m_partId1, newPt.m_index1);
 	}
 	}
 
 
+	if (gContactStartedCallback && isNewCollision)
+	{
+		gContactStartedCallback(m_manifoldPtr);
+	}
 }
 }
-

+ 45 - 40
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.h

@@ -13,7 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #ifndef BT_MANIFOLD_RESULT_H
 #ifndef BT_MANIFOLD_RESULT_H
 #define BT_MANIFOLD_RESULT_H
 #define BT_MANIFOLD_RESULT_H
 
 
@@ -29,76 +28,81 @@ class btManifoldPoint;
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 
 
-typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,	const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1);
-extern ContactAddedCallback		gContactAddedCallback;
+typedef bool (*ContactAddedCallback)(btManifoldPoint& cp, const btCollisionObjectWrapper* colObj0Wrap, int partId0, int index0, const btCollisionObjectWrapper* colObj1Wrap, int partId1, int index1);
+extern ContactAddedCallback gContactAddedCallback;
 
 
 //#define DEBUG_PART_INDEX 1
 //#define DEBUG_PART_INDEX 1
 
 
+/// These callbacks are used to customize the algorith that combine restitution, friction, damping, Stiffness
+typedef btScalar (*CalculateCombinedCallback)(const btCollisionObject* body0, const btCollisionObject* body1);
+
+extern CalculateCombinedCallback gCalculateCombinedRestitutionCallback;
+extern CalculateCombinedCallback gCalculateCombinedFrictionCallback;
+extern CalculateCombinedCallback gCalculateCombinedRollingFrictionCallback;
+extern CalculateCombinedCallback gCalculateCombinedSpinningFrictionCallback;
+extern CalculateCombinedCallback gCalculateCombinedContactDampingCallback;
+extern CalculateCombinedCallback gCalculateCombinedContactStiffnessCallback;
 
 
 ///btManifoldResult is a helper class to manage  contact results.
 ///btManifoldResult is a helper class to manage  contact results.
 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result
 {
 {
 protected:
 protected:
-
 	btPersistentManifold* m_manifoldPtr;
 	btPersistentManifold* m_manifoldPtr;
 
 
 	const btCollisionObjectWrapper* m_body0Wrap;
 	const btCollisionObjectWrapper* m_body0Wrap;
 	const btCollisionObjectWrapper* m_body1Wrap;
 	const btCollisionObjectWrapper* m_body1Wrap;
-	int	m_partId0;
+	int m_partId0;
 	int m_partId1;
 	int m_partId1;
 	int m_index0;
 	int m_index0;
 	int m_index1;
 	int m_index1;
-	
-	
-public:
 
 
+public:
 	btManifoldResult()
 	btManifoldResult()
 		:
 		:
 #ifdef DEBUG_PART_INDEX
 #ifdef DEBUG_PART_INDEX
-		
-	m_partId0(-1),
-	m_partId1(-1),
-	m_index0(-1),
-	m_index1(-1)
-#endif //DEBUG_PART_INDEX
-		m_closestPointDistanceThreshold(0)
+
+		  m_partId0(-1),
+		  m_partId1(-1),
+		  m_index0(-1),
+		  m_index1(-1)
+#endif  //DEBUG_PART_INDEX
+			  m_closestPointDistanceThreshold(0)
 	{
 	{
 	}
 	}
 
 
-	btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
+	btManifoldResult(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap);
 
 
-	virtual ~btManifoldResult() {};
+	virtual ~btManifoldResult(){};
 
 
-	void	setPersistentManifold(btPersistentManifold* manifoldPtr)
+	void setPersistentManifold(btPersistentManifold* manifoldPtr)
 	{
 	{
 		m_manifoldPtr = manifoldPtr;
 		m_manifoldPtr = manifoldPtr;
 	}
 	}
 
 
-	const btPersistentManifold*	getPersistentManifold() const
+	const btPersistentManifold* getPersistentManifold() const
 	{
 	{
 		return m_manifoldPtr;
 		return m_manifoldPtr;
 	}
 	}
-	btPersistentManifold*	getPersistentManifold()
+	btPersistentManifold* getPersistentManifold()
 	{
 	{
 		return m_manifoldPtr;
 		return m_manifoldPtr;
 	}
 	}
 
 
-	virtual void setShapeIdentifiersA(int partId0,int index0)
+	virtual void setShapeIdentifiersA(int partId0, int index0)
 	{
 	{
-		m_partId0=partId0;
-		m_index0=index0;
+		m_partId0 = partId0;
+		m_index0 = index0;
 	}
 	}
 
 
-	virtual void setShapeIdentifiersB(	int partId1,int index1)
+	virtual void setShapeIdentifiersB(int partId1, int index1)
 	{
 	{
-		m_partId1=partId1;
-		m_index1=index1;
+		m_partId1 = partId1;
+		m_index1 = index1;
 	}
 	}
 
 
+	virtual void addContactPoint(const btVector3& normalOnBInWorld, const btVector3& pointInWorld, btScalar depth);
 
 
-	virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth);
-
-	SIMD_FORCE_INLINE	void refreshContactPoints()
+	SIMD_FORCE_INLINE void refreshContactPoints()
 	{
 	{
 		btAssert(m_manifoldPtr);
 		btAssert(m_manifoldPtr);
 		if (!m_manifoldPtr->getNumContacts())
 		if (!m_manifoldPtr->getNumContacts())
@@ -108,10 +112,11 @@ public:
 
 
 		if (isSwapped)
 		if (isSwapped)
 		{
 		{
-			m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(),m_body0Wrap->getCollisionObject()->getWorldTransform());
-		} else
+			m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(), m_body0Wrap->getCollisionObject()->getWorldTransform());
+		}
+		else
 		{
 		{
-			m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(),m_body1Wrap->getCollisionObject()->getWorldTransform());
+			m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(), m_body1Wrap->getCollisionObject()->getWorldTransform());
 		}
 		}
 	}
 	}
 
 
@@ -144,15 +149,15 @@ public:
 		return m_body1Wrap->getCollisionObject();
 		return m_body1Wrap->getCollisionObject();
 	}
 	}
 
 
-	btScalar	m_closestPointDistanceThreshold;
+	btScalar m_closestPointDistanceThreshold;
 
 
 	/// in the future we can let the user override the methods to combine restitution and friction
 	/// in the future we can let the user override the methods to combine restitution and friction
-	static btScalar	calculateCombinedRestitution(const btCollisionObject* body0,const btCollisionObject* body1);
-	static btScalar	calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1);
-	static btScalar calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1);
-    static btScalar calculateCombinedSpinningFriction(const btCollisionObject* body0,const btCollisionObject* body1);
-    static btScalar calculateCombinedContactDamping(const btCollisionObject* body0,const btCollisionObject* body1);
-	static btScalar calculateCombinedContactStiffness(const btCollisionObject* body0,const btCollisionObject* body1);
+	static btScalar calculateCombinedRestitution(const btCollisionObject* body0, const btCollisionObject* body1);
+	static btScalar calculateCombinedFriction(const btCollisionObject* body0, const btCollisionObject* body1);
+	static btScalar calculateCombinedRollingFriction(const btCollisionObject* body0, const btCollisionObject* body1);
+	static btScalar calculateCombinedSpinningFriction(const btCollisionObject* body0, const btCollisionObject* body1);
+	static btScalar calculateCombinedContactDamping(const btCollisionObject* body0, const btCollisionObject* body1);
+	static btScalar calculateCombinedContactStiffness(const btCollisionObject* body0, const btCollisionObject* body1);
 };
 };
 
 
-#endif //BT_MANIFOLD_RESULT_H
+#endif  //BT_MANIFOLD_RESULT_H

+ 142 - 147
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp

@@ -14,7 +14,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "LinearMath/btScalar.h"
 #include "LinearMath/btScalar.h"
 #include "btSimulationIslandManager.h"
 #include "btSimulationIslandManager.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
@@ -25,8 +24,7 @@ subject to the following restrictions:
 //#include <stdio.h>
 //#include <stdio.h>
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btQuickprof.h"
 
 
-btSimulationIslandManager::btSimulationIslandManager():
-m_splitIslands(true)
+btSimulationIslandManager::btSimulationIslandManager() : m_splitIslands(true)
 {
 {
 }
 }
 
 
@@ -34,53 +32,47 @@ btSimulationIslandManager::~btSimulationIslandManager()
 {
 {
 }
 }
 
 
-
 void btSimulationIslandManager::initUnionFind(int n)
 void btSimulationIslandManager::initUnionFind(int n)
 {
 {
-		m_unionFind.reset(n);
+	m_unionFind.reset(n);
 }
 }
-		
 
 
-void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */,btCollisionWorld* colWorld)
+void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */, btCollisionWorld* colWorld)
 {
 {
-	
 	{
 	{
 		btOverlappingPairCache* pairCachePtr = colWorld->getPairCache();
 		btOverlappingPairCache* pairCachePtr = colWorld->getPairCache();
 		const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs();
 		const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs();
 		if (numOverlappingPairs)
 		if (numOverlappingPairs)
 		{
 		{
-		btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr();
-		
-		for (int i=0;i<numOverlappingPairs;i++)
-		{
-			const btBroadphasePair& collisionPair = pairPtr[i];
-			btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
-			btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
+			btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr();
 
 
-			if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
-				((colObj1) && ((colObj1)->mergesSimulationIslands())))
+			for (int i = 0; i < numOverlappingPairs; i++)
 			{
 			{
+				const btBroadphasePair& collisionPair = pairPtr[i];
+				btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
+				btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
 
 
-				m_unionFind.unite((colObj0)->getIslandTag(),
-					(colObj1)->getIslandTag());
+				if (((colObj0) && ((colObj0)->mergesSimulationIslands())) &&
+					((colObj1) && ((colObj1)->mergesSimulationIslands())))
+				{
+					m_unionFind.unite((colObj0)->getIslandTag(),
+									  (colObj1)->getIslandTag());
+				}
 			}
 			}
 		}
 		}
-		}
 	}
 	}
 }
 }
 
 
 #ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION
 #ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION
-void   btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
+void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld, btDispatcher* dispatcher)
 {
 {
-
-	// put the index into m_controllers into m_tag   
+	// put the index into m_controllers into m_tag
 	int index = 0;
 	int index = 0;
 	{
 	{
-
 		int i;
 		int i;
-		for (i=0;i<colWorld->getCollisionObjectArray().size(); i++)
+		for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
 		{
 		{
-			btCollisionObject*   collisionObject= colWorld->getCollisionObjectArray()[i];
+			btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
 			//Adding filtering here
 			//Adding filtering here
 			if (!collisionObject->isStaticOrKinematicObject())
 			if (!collisionObject->isStaticOrKinematicObject())
 			{
 			{
@@ -92,28 +84,29 @@ void   btSimulationIslandManager::updateActivationState(btCollisionWorld* colWor
 	}
 	}
 	// do the union find
 	// do the union find
 
 
-	initUnionFind( index );
+	initUnionFind(index);
 
 
-	findUnions(dispatcher,colWorld);
+	findUnions(dispatcher, colWorld);
 }
 }
 
 
-void   btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
+void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
 {
 {
-	// put the islandId ('find' value) into m_tag   
+	// put the islandId ('find' value) into m_tag
 	{
 	{
 		int index = 0;
 		int index = 0;
 		int i;
 		int i;
-		for (i=0;i<colWorld->getCollisionObjectArray().size();i++)
+		for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
 		{
 		{
-			btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i];
+			btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
 			if (!collisionObject->isStaticOrKinematicObject())
 			if (!collisionObject->isStaticOrKinematicObject())
 			{
 			{
-				collisionObject->setIslandTag( m_unionFind.find(index) );
+				collisionObject->setIslandTag(m_unionFind.find(index));
 				//Set the correct object offset in Collision Object Array
 				//Set the correct object offset in Collision Object Array
 				m_unionFind.getElement(index).m_sz = i;
 				m_unionFind.getElement(index).m_sz = i;
 				collisionObject->setCompanionId(-1);
 				collisionObject->setCompanionId(-1);
 				index++;
 				index++;
-			} else
+			}
+			else
 			{
 			{
 				collisionObject->setIslandTag(-1);
 				collisionObject->setIslandTag(-1);
 				collisionObject->setCompanionId(-2);
 				collisionObject->setCompanionId(-2);
@@ -122,49 +115,44 @@ void   btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* c
 	}
 	}
 }
 }
 
 
-
-#else //STATIC_SIMULATION_ISLAND_OPTIMIZATION
-void	btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
+#else  //STATIC_SIMULATION_ISLAND_OPTIMIZATION
+void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld, btDispatcher* dispatcher)
 {
 {
+	initUnionFind(int(colWorld->getCollisionObjectArray().size()));
 
 
-	initUnionFind( int (colWorld->getCollisionObjectArray().size()));
-
-	// put the index into m_controllers into m_tag	
+	// put the index into m_controllers into m_tag
 	{
 	{
-
 		int index = 0;
 		int index = 0;
 		int i;
 		int i;
-		for (i=0;i<colWorld->getCollisionObjectArray().size(); i++)
+		for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
 		{
 		{
-			btCollisionObject*	collisionObject= colWorld->getCollisionObjectArray()[i];
+			btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
 			collisionObject->setIslandTag(index);
 			collisionObject->setIslandTag(index);
 			collisionObject->setCompanionId(-1);
 			collisionObject->setCompanionId(-1);
 			collisionObject->setHitFraction(btScalar(1.));
 			collisionObject->setHitFraction(btScalar(1.));
 			index++;
 			index++;
-
 		}
 		}
 	}
 	}
 	// do the union find
 	// do the union find
 
 
-	findUnions(dispatcher,colWorld);
+	findUnions(dispatcher, colWorld);
 }
 }
 
 
-void	btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
+void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
 {
 {
-	// put the islandId ('find' value) into m_tag	
+	// put the islandId ('find' value) into m_tag
 	{
 	{
-
-
 		int index = 0;
 		int index = 0;
 		int i;
 		int i;
-		for (i=0;i<colWorld->getCollisionObjectArray().size();i++)
+		for (i = 0; i < colWorld->getCollisionObjectArray().size(); i++)
 		{
 		{
-			btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i];
+			btCollisionObject* collisionObject = colWorld->getCollisionObjectArray()[i];
 			if (!collisionObject->isStaticOrKinematicObject())
 			if (!collisionObject->isStaticOrKinematicObject())
 			{
 			{
-				collisionObject->setIslandTag( m_unionFind.find(index) );
+				collisionObject->setIslandTag(m_unionFind.find(index));
 				collisionObject->setCompanionId(-1);
 				collisionObject->setCompanionId(-1);
-			} else
+			}
+			else
 			{
 			{
 				collisionObject->setIslandTag(-1);
 				collisionObject->setIslandTag(-1);
 				collisionObject->setCompanionId(-2);
 				collisionObject->setCompanionId(-2);
@@ -174,56 +162,59 @@ void	btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* col
 	}
 	}
 }
 }
 
 
-#endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION
+#endif  //STATIC_SIMULATION_ISLAND_OPTIMIZATION
 
 
-inline	int	getIslandId(const btPersistentManifold* lhs)
+inline int getIslandId(const btPersistentManifold* lhs)
 {
 {
 	int islandId;
 	int islandId;
 	const btCollisionObject* rcolObj0 = static_cast<const btCollisionObject*>(lhs->getBody0());
 	const btCollisionObject* rcolObj0 = static_cast<const btCollisionObject*>(lhs->getBody0());
 	const btCollisionObject* rcolObj1 = static_cast<const btCollisionObject*>(lhs->getBody1());
 	const btCollisionObject* rcolObj1 = static_cast<const btCollisionObject*>(lhs->getBody1());
-	islandId= rcolObj0->getIslandTag()>=0?rcolObj0->getIslandTag():rcolObj1->getIslandTag();
+	islandId = rcolObj0->getIslandTag() >= 0 ? rcolObj0->getIslandTag() : rcolObj1->getIslandTag();
 	return islandId;
 	return islandId;
-
 }
 }
 
 
-
-
 /// function object that routes calls to operator<
 /// function object that routes calls to operator<
 class btPersistentManifoldSortPredicate
 class btPersistentManifoldSortPredicate
 {
 {
-	public:
-
-		SIMD_FORCE_INLINE bool operator() ( const btPersistentManifold* lhs, const btPersistentManifold* rhs ) const
-		{
-			return getIslandId(lhs) < getIslandId(rhs);
-		}
+public:
+	SIMD_FORCE_INLINE bool operator()(const btPersistentManifold* lhs, const btPersistentManifold* rhs) const
+	{
+		return getIslandId(lhs) < getIslandId(rhs);
+	}
 };
 };
 
 
-
-void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisionWorld* collisionWorld)
+class btPersistentManifoldSortPredicateDeterministic
 {
 {
+public:
+	SIMD_FORCE_INLINE bool operator()(const btPersistentManifold* lhs, const btPersistentManifold* rhs) const
+	{
+		return (
+			(getIslandId(lhs) < getIslandId(rhs)) || ((getIslandId(lhs) == getIslandId(rhs)) && lhs->getBody0()->getBroadphaseHandle()->m_uniqueId < rhs->getBody0()->getBroadphaseHandle()->m_uniqueId) || ((getIslandId(lhs) == getIslandId(rhs)) && (lhs->getBody0()->getBroadphaseHandle()->m_uniqueId == rhs->getBody0()->getBroadphaseHandle()->m_uniqueId) && (lhs->getBody1()->getBroadphaseHandle()->m_uniqueId < rhs->getBody1()->getBroadphaseHandle()->m_uniqueId)));
+	}
+};
 
 
+void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld)
+{
 	BT_PROFILE("islandUnionFindAndQuickSort");
 	BT_PROFILE("islandUnionFindAndQuickSort");
-	
+
 	btCollisionObjectArray& collisionObjects = collisionWorld->getCollisionObjectArray();
 	btCollisionObjectArray& collisionObjects = collisionWorld->getCollisionObjectArray();
 
 
 	m_islandmanifold.resize(0);
 	m_islandmanifold.resize(0);
 
 
 	//we are going to sort the unionfind array, and store the element id in the size
 	//we are going to sort the unionfind array, and store the element id in the size
 	//afterwards, we clean unionfind, to make sure no-one uses it anymore
 	//afterwards, we clean unionfind, to make sure no-one uses it anymore
-	
+
 	getUnionFind().sortIslands();
 	getUnionFind().sortIslands();
 	int numElem = getUnionFind().getNumElements();
 	int numElem = getUnionFind().getNumElements();
 
 
-	int endIslandIndex=1;
+	int endIslandIndex = 1;
 	int startIslandIndex;
 	int startIslandIndex;
 
 
-
 	//update the sleeping state for bodies, if all are sleeping
 	//update the sleeping state for bodies, if all are sleeping
-	for ( startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex)
+	for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex)
 	{
 	{
 		int islandId = getUnionFind().getElement(startIslandIndex).m_id;
 		int islandId = getUnionFind().getElement(startIslandIndex).m_id;
-		for (endIslandIndex = startIslandIndex+1;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++)
+		for (endIslandIndex = startIslandIndex + 1; (endIslandIndex < numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId); endIslandIndex++)
 		{
 		{
 		}
 		}
 
 
@@ -232,71 +223,69 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
 		bool allSleeping = true;
 		bool allSleeping = true;
 
 
 		int idx;
 		int idx;
-		for (idx=startIslandIndex;idx<endIslandIndex;idx++)
+		for (idx = startIslandIndex; idx < endIslandIndex; idx++)
 		{
 		{
 			int i = getUnionFind().getElement(idx).m_sz;
 			int i = getUnionFind().getElement(idx).m_sz;
 
 
 			btCollisionObject* colObj0 = collisionObjects[i];
 			btCollisionObject* colObj0 = collisionObjects[i];
 			if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
 			if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
 			{
 			{
-//				printf("error in island management\n");
+				//				printf("error in island management\n");
 			}
 			}
 
 
-			btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
+            btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
 			if (colObj0->getIslandTag() == islandId)
 			if (colObj0->getIslandTag() == islandId)
 			{
 			{
-				if (colObj0->getActivationState()== ACTIVE_TAG)
-				{
-					allSleeping = false;
-				}
-				if (colObj0->getActivationState()== DISABLE_DEACTIVATION)
+				if (colObj0->getActivationState() == ACTIVE_TAG ||
+					colObj0->getActivationState() == DISABLE_DEACTIVATION)
 				{
 				{
 					allSleeping = false;
 					allSleeping = false;
+					break;
 				}
 				}
 			}
 			}
 		}
 		}
-			
 
 
 		if (allSleeping)
 		if (allSleeping)
 		{
 		{
 			int idx;
 			int idx;
-			for (idx=startIslandIndex;idx<endIslandIndex;idx++)
+			for (idx = startIslandIndex; idx < endIslandIndex; idx++)
 			{
 			{
 				int i = getUnionFind().getElement(idx).m_sz;
 				int i = getUnionFind().getElement(idx).m_sz;
 				btCollisionObject* colObj0 = collisionObjects[i];
 				btCollisionObject* colObj0 = collisionObjects[i];
 				if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
 				if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
 				{
 				{
-//					printf("error in island management\n");
+					//					printf("error in island management\n");
 				}
 				}
 
 
-				btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
+                btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
 
 
 				if (colObj0->getIslandTag() == islandId)
 				if (colObj0->getIslandTag() == islandId)
 				{
 				{
-					colObj0->setActivationState( ISLAND_SLEEPING );
+					colObj0->setActivationState(ISLAND_SLEEPING);
 				}
 				}
 			}
 			}
-		} else
+		}
+		else
 		{
 		{
-
 			int idx;
 			int idx;
-			for (idx=startIslandIndex;idx<endIslandIndex;idx++)
+			for (idx = startIslandIndex; idx < endIslandIndex; idx++)
 			{
 			{
 				int i = getUnionFind().getElement(idx).m_sz;
 				int i = getUnionFind().getElement(idx).m_sz;
 
 
 				btCollisionObject* colObj0 = collisionObjects[i];
 				btCollisionObject* colObj0 = collisionObjects[i];
 				if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
 				if ((colObj0->getIslandTag() != islandId) && (colObj0->getIslandTag() != -1))
 				{
 				{
-//					printf("error in island management\n");
+					//					printf("error in island management\n");
 				}
 				}
 
 
-				btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
+                 btAssert((colObj0->getIslandTag() == islandId) || (colObj0->getIslandTag() == -1));
+
 
 
 				if (colObj0->getIslandTag() == islandId)
 				if (colObj0->getIslandTag() == islandId)
 				{
 				{
-					if ( colObj0->getActivationState() == ISLAND_SLEEPING)
+					if (colObj0->getActivationState() == ISLAND_SLEEPING)
 					{
 					{
-						colObj0->setActivationState( WANTS_DEACTIVATION);
+						colObj0->setActivationState(WANTS_DEACTIVATION);
 						colObj0->setDeactivationTime(0.f);
 						colObj0->setDeactivationTime(0.f);
 					}
 					}
 				}
 				}
@@ -304,29 +293,30 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
 		}
 		}
 	}
 	}
 
 
-	
 	int i;
 	int i;
 	int maxNumManifolds = dispatcher->getNumManifolds();
 	int maxNumManifolds = dispatcher->getNumManifolds();
 
 
-//#define SPLIT_ISLANDS 1
-//#ifdef SPLIT_ISLANDS
+	//#define SPLIT_ISLANDS 1
+	//#ifdef SPLIT_ISLANDS
 
 
-	
-//#endif //SPLIT_ISLANDS
+	//#endif //SPLIT_ISLANDS
 
 
-	
-	for (i=0;i<maxNumManifolds ;i++)
+	for (i = 0; i < maxNumManifolds; i++)
 	{
 	{
-		 btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
-		 
-		 const btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
-		 const btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
-		
-		 ///@todo: check sleeping conditions!
-		 if (((colObj0) && colObj0->getActivationState() != ISLAND_SLEEPING) ||
+		btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
+		if (collisionWorld->getDispatchInfo().m_deterministicOverlappingPairs)
+		{
+			if (manifold->getNumContacts() == 0)
+				continue;
+		}
+
+		const btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
+		const btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
+
+		///@todo: check sleeping conditions!
+		if (((colObj0) && colObj0->getActivationState() != ISLAND_SLEEPING) ||
 			((colObj1) && colObj1->getActivationState() != ISLAND_SLEEPING))
 			((colObj1) && colObj1->getActivationState() != ISLAND_SLEEPING))
 		{
 		{
-		
 			//kinematic objects don't merge islands, but wake up all connected objects
 			//kinematic objects don't merge islands, but wake up all connected objects
 			if (colObj0->isKinematicObject() && colObj0->getActivationState() != ISLAND_SLEEPING)
 			if (colObj0->isKinematicObject() && colObj0->getActivationState() != ISLAND_SLEEPING)
 			{
 			{
@@ -338,10 +328,10 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
 				if (colObj1->hasContactResponse())
 				if (colObj1->hasContactResponse())
 					colObj0->activate();
 					colObj0->activate();
 			}
 			}
-			if(m_splitIslands)
-			{ 
+			if (m_splitIslands)
+			{
 				//filtering for response
 				//filtering for response
-				if (dispatcher->needsResponse(colObj0,colObj1))
+				if (dispatcher->needsResponse(colObj0, colObj1))
 					m_islandmanifold.push_back(manifold);
 					m_islandmanifold.push_back(manifold);
 			}
 			}
 		}
 		}
@@ -349,25 +339,27 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
 }
 }
 
 
 
 
-
 ///@todo: this is random access, it can be walked 'cache friendly'!
 ///@todo: this is random access, it can be walked 'cache friendly'!
-void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,btCollisionWorld* collisionWorld, IslandCallback* callback)
+void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld, IslandCallback* callback)
 {
 {
-	btCollisionObjectArray& collisionObjects = collisionWorld->getCollisionObjectArray();
-
-	buildIslands(dispatcher,collisionWorld);
+	buildIslands(dispatcher, collisionWorld);
+    processIslands(dispatcher, collisionWorld, callback);
+}
 
 
-	int endIslandIndex=1;
+void btSimulationIslandManager::processIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld, IslandCallback* callback)
+{
+    btCollisionObjectArray& collisionObjects = collisionWorld->getCollisionObjectArray();
+	int endIslandIndex = 1;
 	int startIslandIndex;
 	int startIslandIndex;
 	int numElem = getUnionFind().getNumElements();
 	int numElem = getUnionFind().getNumElements();
 
 
 	BT_PROFILE("processIslands");
 	BT_PROFILE("processIslands");
 
 
-	if(!m_splitIslands)
+	if (!m_splitIslands)
 	{
 	{
 		btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer();
 		btPersistentManifold** manifold = dispatcher->getInternalManifoldPointer();
 		int maxNumManifolds = dispatcher->getNumManifolds();
 		int maxNumManifolds = dispatcher->getNumManifolds();
-		callback->processIsland(&collisionObjects[0],collisionObjects.size(),manifold,maxNumManifolds, -1);
+		callback->processIsland(&collisionObjects[0], collisionObjects.size(), manifold, maxNumManifolds, -1);
 	}
 	}
 	else
 	else
 	{
 	{
@@ -375,11 +367,21 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 		// Sort the vector using predicate and std::sort
 		// Sort the vector using predicate and std::sort
 		//std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
 		//std::sort(islandmanifold.begin(), islandmanifold.end(), btPersistentManifoldSortPredicate);
 
 
-		int numManifolds = int (m_islandmanifold.size());
+		int numManifolds = int(m_islandmanifold.size());
 
 
 		//tried a radix sort, but quicksort/heapsort seems still faster
 		//tried a radix sort, but quicksort/heapsort seems still faster
 		//@todo rewrite island management
 		//@todo rewrite island management
-		m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
+		//btPersistentManifoldSortPredicateDeterministic sorts contact manifolds based on islandid,
+		//but also based on object0 unique id and object1 unique id
+		if (collisionWorld->getDispatchInfo().m_deterministicOverlappingPairs)
+		{
+			m_islandmanifold.quickSort(btPersistentManifoldSortPredicateDeterministic());
+		}
+		else
+		{
+			m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
+		}
+
 		//m_islandmanifold.heapSort(btPersistentManifoldSortPredicate());
 		//m_islandmanifold.heapSort(btPersistentManifoldSortPredicate());
 
 
 		//now process all active islands (sets of manifolds for now)
 		//now process all active islands (sets of manifolds for now)
@@ -389,55 +391,49 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 
 
 		//int islandId;
 		//int islandId;
 
 
-		
-
-	//	printf("Start Islands\n");
+		//	printf("Start Islands\n");
 
 
 		//traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated
 		//traverse the simulation islands, and call the solver, unless all objects are sleeping/deactivated
-		for ( startIslandIndex=0;startIslandIndex<numElem;startIslandIndex = endIslandIndex)
+		for (startIslandIndex = 0; startIslandIndex < numElem; startIslandIndex = endIslandIndex)
 		{
 		{
 			int islandId = getUnionFind().getElement(startIslandIndex).m_id;
 			int islandId = getUnionFind().getElement(startIslandIndex).m_id;
 
 
+			bool islandSleeping = true;
 
 
-			   bool islandSleeping = true;
-	                
-					for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++)
-					{
-							int i = getUnionFind().getElement(endIslandIndex).m_sz;
-							btCollisionObject* colObj0 = collisionObjects[i];
-							m_islandBodies.push_back(colObj0);
-							if (colObj0->isActive())
-									islandSleeping = false;
-					}
-	                
+			for (endIslandIndex = startIslandIndex; (endIslandIndex < numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId); endIslandIndex++)
+			{
+				int i = getUnionFind().getElement(endIslandIndex).m_sz;
+				btCollisionObject* colObj0 = collisionObjects[i];
+				m_islandBodies.push_back(colObj0);
+				if (colObj0->isActive())
+					islandSleeping = false;
+			}
 
 
 			//find the accompanying contact manifold for this islandId
 			//find the accompanying contact manifold for this islandId
 			int numIslandManifolds = 0;
 			int numIslandManifolds = 0;
 			btPersistentManifold** startManifold = 0;
 			btPersistentManifold** startManifold = 0;
 
 
-			if (startManifoldIndex<numManifolds)
+			if (startManifoldIndex < numManifolds)
 			{
 			{
 				int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]);
 				int curIslandId = getIslandId(m_islandmanifold[startManifoldIndex]);
 				if (curIslandId == islandId)
 				if (curIslandId == islandId)
 				{
 				{
 					startManifold = &m_islandmanifold[startManifoldIndex];
 					startManifold = &m_islandmanifold[startManifoldIndex];
-				
-					for (endManifoldIndex = startManifoldIndex+1;(endManifoldIndex<numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex]));endManifoldIndex++)
-					{
 
 
+					for (endManifoldIndex = startManifoldIndex + 1; (endManifoldIndex < numManifolds) && (islandId == getIslandId(m_islandmanifold[endManifoldIndex])); endManifoldIndex++)
+					{
 					}
 					}
 					/// Process the actual simulation, only if not sleeping/deactivated
 					/// Process the actual simulation, only if not sleeping/deactivated
-					numIslandManifolds = endManifoldIndex-startManifoldIndex;
+					numIslandManifolds = endManifoldIndex - startManifoldIndex;
 				}
 				}
-
 			}
 			}
 
 
 			if (!islandSleeping)
 			if (!islandSleeping)
 			{
 			{
-				callback->processIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId);
-	//			printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
+				callback->processIsland(&m_islandBodies[0], m_islandBodies.size(), startManifold, numIslandManifolds, islandId);
+				//			printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
 			}
 			}
-			
+
 			if (numIslandManifolds)
 			if (numIslandManifolds)
 			{
 			{
 				startManifoldIndex = endManifoldIndex;
 				startManifoldIndex = endManifoldIndex;
@@ -445,6 +441,5 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 
 
 			m_islandBodies.resize(0);
 			m_islandBodies.resize(0);
 		}
 		}
-	} // else if(!splitIslands) 
-
+	}  // else if(!splitIslands)
 }
 }

+ 18 - 24
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h

@@ -26,46 +26,42 @@ class btCollisionWorld;
 class btDispatcher;
 class btDispatcher;
 class btPersistentManifold;
 class btPersistentManifold;
 
 
-
 ///SimulationIslandManager creates and handles simulation islands, using btUnionFind
 ///SimulationIslandManager creates and handles simulation islands, using btUnionFind
 class btSimulationIslandManager
 class btSimulationIslandManager
 {
 {
 	btUnionFind m_unionFind;
 	btUnionFind m_unionFind;
 
 
-	btAlignedObjectArray<btPersistentManifold*>  m_islandmanifold;
-	btAlignedObjectArray<btCollisionObject* >  m_islandBodies;
-	
+	btAlignedObjectArray<btPersistentManifold*> m_islandmanifold;
+	btAlignedObjectArray<btCollisionObject*> m_islandBodies;
+
 	bool m_splitIslands;
 	bool m_splitIslands;
-	
+
 public:
 public:
 	btSimulationIslandManager();
 	btSimulationIslandManager();
 	virtual ~btSimulationIslandManager();
 	virtual ~btSimulationIslandManager();
 
 
+	void initUnionFind(int n);
 
 
-	void initUnionFind(int n);	
-	
-		
-	btUnionFind& getUnionFind() { return m_unionFind;}
-
-	virtual	void	updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher);
-	virtual	void	storeIslandActivationState(btCollisionWorld* world);
+	btUnionFind& getUnionFind() { return m_unionFind; }
 
 
+	virtual void updateActivationState(btCollisionWorld* colWorld, btDispatcher* dispatcher);
+	virtual void storeIslandActivationState(btCollisionWorld* world);
 
 
-	void	findUnions(btDispatcher* dispatcher,btCollisionWorld* colWorld);
+	void findUnions(btDispatcher* dispatcher, btCollisionWorld* colWorld);
 
 
-	
-
-	struct	IslandCallback
+	struct IslandCallback
 	{
 	{
-		virtual ~IslandCallback() {};
+		virtual ~IslandCallback(){};
 
 
-		virtual	void	processIsland(btCollisionObject** bodies,int numBodies,class btPersistentManifold**	manifolds,int numManifolds, int islandId) = 0;
+		virtual void processIsland(btCollisionObject** bodies, int numBodies, class btPersistentManifold** manifolds, int numManifolds, int islandId) = 0;
 	};
 	};
 
 
-	void	buildAndProcessIslands(btDispatcher* dispatcher,btCollisionWorld* collisionWorld, IslandCallback* callback);
-
-	void buildIslands(btDispatcher* dispatcher,btCollisionWorld* colWorld);
+	void buildAndProcessIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld, IslandCallback* callback);
+    
+	void buildIslands(btDispatcher* dispatcher, btCollisionWorld* colWorld);
 
 
+    void processIslands(btDispatcher* dispatcher, btCollisionWorld* collisionWorld, IslandCallback* callback);
+    
 	bool getSplitIslands()
 	bool getSplitIslands()
 	{
 	{
 		return m_splitIslands;
 		return m_splitIslands;
@@ -74,8 +70,6 @@ public:
 	{
 	{
 		m_splitIslands = doSplitIslands;
 		m_splitIslands = doSplitIslands;
 	}
 	}
-
 };
 };
 
 
-#endif //BT_SIMULATION_ISLAND_MANAGER_H
-
+#endif  //BT_SIMULATION_ISLAND_MANAGER_H

+ 42 - 47
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp

@@ -21,23 +21,22 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped)
-: btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
-m_ownManifold(false),
-m_manifoldPtr(mf),
-m_isSwapped(isSwapped)
+btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap, bool isSwapped)
+	: btActivatingCollisionAlgorithm(ci, col0Wrap, col1Wrap),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf),
+	  m_isSwapped(isSwapped)
 {
 {
-	const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped? col1Wrap : col0Wrap;
-	const btCollisionObjectWrapper* boxObjWrap = m_isSwapped? col0Wrap : col1Wrap;
-	
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObjWrap->getCollisionObject(),boxObjWrap->getCollisionObject()))
+	const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped ? col1Wrap : col0Wrap;
+	const btCollisionObjectWrapper* boxObjWrap = m_isSwapped ? col0Wrap : col1Wrap;
+
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObjWrap->getCollisionObject(), boxObjWrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(sphereObjWrap->getCollisionObject(),boxObjWrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(sphereObjWrap->getCollisionObject(), boxObjWrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
 
 
-
 btSphereBoxCollisionAlgorithm::~btSphereBoxCollisionAlgorithm()
 btSphereBoxCollisionAlgorithm::~btSphereBoxCollisionAlgorithm()
 {
 {
 	if (m_ownManifold)
 	if (m_ownManifold)
@@ -47,17 +46,15 @@ btSphereBoxCollisionAlgorithm::~btSphereBoxCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-
-
-void btSphereBoxCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
+void btSphereBoxCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)dispatchInfo;
 	(void)dispatchInfo;
 	(void)resultOut;
 	(void)resultOut;
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 		return;
 		return;
 
 
-	const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped? body1Wrap : body0Wrap;
-	const btCollisionObjectWrapper* boxObjWrap = m_isSwapped? body0Wrap : body1Wrap;
+	const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* boxObjWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
 
 	btVector3 pOnBox;
 	btVector3 pOnBox;
 
 
@@ -83,10 +80,9 @@ void btSphereBoxCollisionAlgorithm::processCollision (const btCollisionObjectWra
 			resultOut->refreshContactPoints();
 			resultOut->refreshContactPoints();
 		}
 		}
 	}
 	}
-
 }
 }
 
 
-btScalar btSphereBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btSphereBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, btCollisionObject* col1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)resultOut;
 	(void)resultOut;
 	(void)dispatchInfo;
 	(void)dispatchInfo;
@@ -97,27 +93,26 @@ btScalar btSphereBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
 	return btScalar(1.);
 	return btScalar(1.);
 }
 }
 
 
-
-bool btSphereBoxCollisionAlgorithm::getSphereDistance(const btCollisionObjectWrapper* boxObjWrap, btVector3& pointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& sphereCenter, btScalar fRadius, btScalar maxContactDistance ) 
+bool btSphereBoxCollisionAlgorithm::getSphereDistance(const btCollisionObjectWrapper* boxObjWrap, btVector3& pointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& sphereCenter, btScalar fRadius, btScalar maxContactDistance)
 {
 {
-	const btBoxShape* boxShape= (const btBoxShape*)boxObjWrap->getCollisionShape();
-	btVector3 const &boxHalfExtent = boxShape->getHalfExtentsWithoutMargin();
+	const btBoxShape* boxShape = (const btBoxShape*)boxObjWrap->getCollisionShape();
+	btVector3 const& boxHalfExtent = boxShape->getHalfExtentsWithoutMargin();
 	btScalar boxMargin = boxShape->getMargin();
 	btScalar boxMargin = boxShape->getMargin();
 	penetrationDepth = 1.0f;
 	penetrationDepth = 1.0f;
 
 
 	// convert the sphere position to the box's local space
 	// convert the sphere position to the box's local space
-	btTransform const &m44T = boxObjWrap->getWorldTransform();
+	btTransform const& m44T = boxObjWrap->getWorldTransform();
 	btVector3 sphereRelPos = m44T.invXform(sphereCenter);
 	btVector3 sphereRelPos = m44T.invXform(sphereCenter);
 
 
 	// Determine the closest point to the sphere center in the box
 	// Determine the closest point to the sphere center in the box
 	btVector3 closestPoint = sphereRelPos;
 	btVector3 closestPoint = sphereRelPos;
-	closestPoint.setX( btMin(boxHalfExtent.getX(), closestPoint.getX()) );
-	closestPoint.setX( btMax(-boxHalfExtent.getX(), closestPoint.getX()) );
-	closestPoint.setY( btMin(boxHalfExtent.getY(), closestPoint.getY()) );
-	closestPoint.setY( btMax(-boxHalfExtent.getY(), closestPoint.getY()) );
-	closestPoint.setZ( btMin(boxHalfExtent.getZ(), closestPoint.getZ()) );
-	closestPoint.setZ( btMax(-boxHalfExtent.getZ(), closestPoint.getZ()) );
-	
+	closestPoint.setX(btMin(boxHalfExtent.getX(), closestPoint.getX()));
+	closestPoint.setX(btMax(-boxHalfExtent.getX(), closestPoint.getX()));
+	closestPoint.setY(btMin(boxHalfExtent.getY(), closestPoint.getY()));
+	closestPoint.setY(btMax(-boxHalfExtent.getY(), closestPoint.getY()));
+	closestPoint.setZ(btMin(boxHalfExtent.getZ(), closestPoint.getZ()));
+	closestPoint.setZ(btMax(-boxHalfExtent.getZ(), closestPoint.getZ()));
+
 	btScalar intersectionDist = fRadius + boxMargin;
 	btScalar intersectionDist = fRadius + boxMargin;
 	btScalar contactDist = intersectionDist + maxContactDistance;
 	btScalar contactDist = intersectionDist + maxContactDistance;
 	normal = sphereRelPos - closestPoint;
 	normal = sphereRelPos - closestPoint;
@@ -136,42 +131,42 @@ bool btSphereBoxCollisionAlgorithm::getSphereDistance(const btCollisionObjectWra
 	{
 	{
 		distance = -getSpherePenetration(boxHalfExtent, sphereRelPos, closestPoint, normal);
 		distance = -getSpherePenetration(boxHalfExtent, sphereRelPos, closestPoint, normal);
 	}
 	}
-	else //compute the penetration details
+	else  //compute the penetration details
 	{
 	{
 		distance = normal.length();
 		distance = normal.length();
 		normal /= distance;
 		normal /= distance;
 	}
 	}
 
 
 	pointOnBox = closestPoint + normal * boxMargin;
 	pointOnBox = closestPoint + normal * boxMargin;
-//	v3PointOnSphere = sphereRelPos - (normal * fRadius);	
+	//	v3PointOnSphere = sphereRelPos - (normal * fRadius);
 	penetrationDepth = distance - intersectionDist;
 	penetrationDepth = distance - intersectionDist;
 
 
 	// transform back in world space
 	// transform back in world space
 	btVector3 tmp = m44T(pointOnBox);
 	btVector3 tmp = m44T(pointOnBox);
 	pointOnBox = tmp;
 	pointOnBox = tmp;
-//	tmp = m44T(v3PointOnSphere);
-//	v3PointOnSphere = tmp;
+	//	tmp = m44T(v3PointOnSphere);
+	//	v3PointOnSphere = tmp;
 	tmp = m44T.getBasis() * normal;
 	tmp = m44T.getBasis() * normal;
 	normal = tmp;
 	normal = tmp;
 
 
 	return true;
 	return true;
 }
 }
 
 
-btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btVector3 const &boxHalfExtent, btVector3 const &sphereRelPos, btVector3 &closestPoint, btVector3& normal ) 
+btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration(btVector3 const& boxHalfExtent, btVector3 const& sphereRelPos, btVector3& closestPoint, btVector3& normal)
 {
 {
 	//project the center of the sphere on the closest face of the box
 	//project the center of the sphere on the closest face of the box
 	btScalar faceDist = boxHalfExtent.getX() - sphereRelPos.getX();
 	btScalar faceDist = boxHalfExtent.getX() - sphereRelPos.getX();
 	btScalar minDist = faceDist;
 	btScalar minDist = faceDist;
-	closestPoint.setX( boxHalfExtent.getX() );
-	normal.setValue(btScalar(1.0f),  btScalar(0.0f),  btScalar(0.0f));
+	closestPoint.setX(boxHalfExtent.getX());
+	normal.setValue(btScalar(1.0f), btScalar(0.0f), btScalar(0.0f));
 
 
 	faceDist = boxHalfExtent.getX() + sphereRelPos.getX();
 	faceDist = boxHalfExtent.getX() + sphereRelPos.getX();
 	if (faceDist < minDist)
 	if (faceDist < minDist)
 	{
 	{
 		minDist = faceDist;
 		minDist = faceDist;
 		closestPoint = sphereRelPos;
 		closestPoint = sphereRelPos;
-		closestPoint.setX( -boxHalfExtent.getX() );
-		normal.setValue(btScalar(-1.0f),  btScalar(0.0f),  btScalar(0.0f));
+		closestPoint.setX(-boxHalfExtent.getX());
+		normal.setValue(btScalar(-1.0f), btScalar(0.0f), btScalar(0.0f));
 	}
 	}
 
 
 	faceDist = boxHalfExtent.getY() - sphereRelPos.getY();
 	faceDist = boxHalfExtent.getY() - sphereRelPos.getY();
@@ -179,8 +174,8 @@ btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btVector3 const &b
 	{
 	{
 		minDist = faceDist;
 		minDist = faceDist;
 		closestPoint = sphereRelPos;
 		closestPoint = sphereRelPos;
-		closestPoint.setY( boxHalfExtent.getY() );
-		normal.setValue(btScalar(0.0f),  btScalar(1.0f),  btScalar(0.0f));
+		closestPoint.setY(boxHalfExtent.getY());
+		normal.setValue(btScalar(0.0f), btScalar(1.0f), btScalar(0.0f));
 	}
 	}
 
 
 	faceDist = boxHalfExtent.getY() + sphereRelPos.getY();
 	faceDist = boxHalfExtent.getY() + sphereRelPos.getY();
@@ -188,8 +183,8 @@ btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btVector3 const &b
 	{
 	{
 		minDist = faceDist;
 		minDist = faceDist;
 		closestPoint = sphereRelPos;
 		closestPoint = sphereRelPos;
-		closestPoint.setY( -boxHalfExtent.getY() );
-		normal.setValue(btScalar(0.0f),  btScalar(-1.0f),  btScalar(0.0f));
+		closestPoint.setY(-boxHalfExtent.getY());
+		normal.setValue(btScalar(0.0f), btScalar(-1.0f), btScalar(0.0f));
 	}
 	}
 
 
 	faceDist = boxHalfExtent.getZ() - sphereRelPos.getZ();
 	faceDist = boxHalfExtent.getZ() - sphereRelPos.getZ();
@@ -197,8 +192,8 @@ btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btVector3 const &b
 	{
 	{
 		minDist = faceDist;
 		minDist = faceDist;
 		closestPoint = sphereRelPos;
 		closestPoint = sphereRelPos;
-		closestPoint.setZ( boxHalfExtent.getZ() );
-		normal.setValue(btScalar(0.0f),  btScalar(0.0f),  btScalar(1.0f));
+		closestPoint.setZ(boxHalfExtent.getZ());
+		normal.setValue(btScalar(0.0f), btScalar(0.0f), btScalar(1.0f));
 	}
 	}
 
 
 	faceDist = boxHalfExtent.getZ() + sphereRelPos.getZ();
 	faceDist = boxHalfExtent.getZ() + sphereRelPos.getZ();
@@ -206,8 +201,8 @@ btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btVector3 const &b
 	{
 	{
 		minDist = faceDist;
 		minDist = faceDist;
 		closestPoint = sphereRelPos;
 		closestPoint = sphereRelPos;
-		closestPoint.setZ( -boxHalfExtent.getZ() );
-		normal.setValue(btScalar(0.0f),  btScalar(0.0f),  btScalar(-1.0f));
+		closestPoint.setZ(-boxHalfExtent.getZ());
+		normal.setValue(btScalar(0.0f), btScalar(0.0f), btScalar(-1.0f));
 	}
 	}
 
 
 	return minDist;
 	return minDist;

+ 18 - 20
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h

@@ -28,21 +28,20 @@ class btPersistentManifold;
 /// Other features are frame-coherency (persistent data) and collision response.
 /// Other features are frame-coherency (persistent data) and collision response.
 class btSphereBoxCollisionAlgorithm : public btActivatingCollisionAlgorithm
 class btSphereBoxCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	bool	m_isSwapped;
-	
-public:
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+	bool m_isSwapped;
 
 
-	btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
+public:
+	btSphereBoxCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
 
 	virtual ~btSphereBoxCollisionAlgorithm();
 	virtual ~btSphereBoxCollisionAlgorithm();
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 		{
 		{
@@ -50,26 +49,25 @@ public:
 		}
 		}
 	}
 	}
 
 
-	bool getSphereDistance( const btCollisionObjectWrapper* boxObjWrap, btVector3& v3PointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& v3SphereCenter, btScalar fRadius, btScalar maxContactDistance );
+	bool getSphereDistance(const btCollisionObjectWrapper* boxObjWrap, btVector3& v3PointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& v3SphereCenter, btScalar fRadius, btScalar maxContactDistance);
+
+	btScalar getSpherePenetration(btVector3 const& boxHalfExtent, btVector3 const& sphereRelPos, btVector3& closestPoint, btVector3& normal);
 
 
-	btScalar getSpherePenetration( btVector3 const &boxHalfExtent, btVector3 const &sphereRelPos, btVector3 &closestPoint, btVector3& normal );
-	
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereBoxCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereBoxCollisionAlgorithm));
 			if (!m_swapped)
 			if (!m_swapped)
 			{
 			{
-				return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false);
-			} else
+				return new (mem) btSphereBoxCollisionAlgorithm(0, ci, body0Wrap, body1Wrap, false);
+			}
+			else
 			{
 			{
-				return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true);
+				return new (mem) btSphereBoxCollisionAlgorithm(0, ci, body0Wrap, body1Wrap, true);
 			}
 			}
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_SPHERE_BOX_COLLISION_ALGORITHM_H
-
+#endif  //BT_SPHERE_BOX_COLLISION_ALGORITHM_H

+ 17 - 19
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp

@@ -20,14 +20,14 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
-btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap)
-: btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
-m_ownManifold(false),
-m_manifoldPtr(mf)
+btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap)
+	: btActivatingCollisionAlgorithm(ci, col0Wrap, col1Wrap),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf)
 {
 {
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(col0Wrap->getCollisionObject(),col1Wrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(col0Wrap->getCollisionObject(), col1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -41,7 +41,7 @@ btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btSphereSphereCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)dispatchInfo;
 	(void)dispatchInfo;
 
 
@@ -53,27 +53,27 @@ void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObject
 	btSphereShape* sphere0 = (btSphereShape*)col0Wrap->getCollisionShape();
 	btSphereShape* sphere0 = (btSphereShape*)col0Wrap->getCollisionShape();
 	btSphereShape* sphere1 = (btSphereShape*)col1Wrap->getCollisionShape();
 	btSphereShape* sphere1 = (btSphereShape*)col1Wrap->getCollisionShape();
 
 
-	btVector3 diff = col0Wrap->getWorldTransform().getOrigin()-  col1Wrap->getWorldTransform().getOrigin();
+	btVector3 diff = col0Wrap->getWorldTransform().getOrigin() - col1Wrap->getWorldTransform().getOrigin();
 	btScalar len = diff.length();
 	btScalar len = diff.length();
 	btScalar radius0 = sphere0->getRadius();
 	btScalar radius0 = sphere0->getRadius();
 	btScalar radius1 = sphere1->getRadius();
 	btScalar radius1 = sphere1->getRadius();
 
 
 #ifdef CLEAR_MANIFOLD
 #ifdef CLEAR_MANIFOLD
-	m_manifoldPtr->clearManifold(); //don't do this, it disables warmstarting
+	m_manifoldPtr->clearManifold();  //don't do this, it disables warmstarting
 #endif
 #endif
 
 
 	///iff distance positive, don't generate a new contact
 	///iff distance positive, don't generate a new contact
-	if ( len > (radius0+radius1+resultOut->m_closestPointDistanceThreshold))
+	if (len > (radius0 + radius1 + resultOut->m_closestPointDistanceThreshold))
 	{
 	{
 #ifndef CLEAR_MANIFOLD
 #ifndef CLEAR_MANIFOLD
 		resultOut->refreshContactPoints();
 		resultOut->refreshContactPoints();
-#endif //CLEAR_MANIFOLD
+#endif  //CLEAR_MANIFOLD
 		return;
 		return;
 	}
 	}
 	///distance (negative means penetration)
 	///distance (negative means penetration)
-	btScalar dist = len - (radius0+radius1);
+	btScalar dist = len - (radius0 + radius1);
 
 
-	btVector3 normalOnSurfaceB(1,0,0);
+	btVector3 normalOnSurfaceB(1, 0, 0);
 	if (len > SIMD_EPSILON)
 	if (len > SIMD_EPSILON)
 	{
 	{
 		normalOnSurfaceB = diff / len;
 		normalOnSurfaceB = diff / len;
@@ -82,20 +82,18 @@ void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObject
 	///point on A (worldspace)
 	///point on A (worldspace)
 	///btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;
 	///btVector3 pos0 = col0->getWorldTransform().getOrigin() - radius0 * normalOnSurfaceB;
 	///point on B (worldspace)
 	///point on B (worldspace)
-	btVector3 pos1 = col1Wrap->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
+	btVector3 pos1 = col1Wrap->getWorldTransform().getOrigin() + radius1 * normalOnSurfaceB;
 
 
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
-	
-	
-	resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
+
+	resultOut->addContactPoint(normalOnSurfaceB, pos1, dist);
 
 
 #ifndef CLEAR_MANIFOLD
 #ifndef CLEAR_MANIFOLD
 	resultOut->refreshContactPoints();
 	resultOut->refreshContactPoints();
-#endif //CLEAR_MANIFOLD
-
+#endif  //CLEAR_MANIFOLD
 }
 }
 
 
-btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, btCollisionObject* col1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)col0;
 	(void)col0;
 	(void)col1;
 	(void)col1;

+ 12 - 14
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h

@@ -28,39 +28,37 @@ class btPersistentManifold;
 /// Also provides the most basic sample for custom/user btCollisionAlgorithm
 /// Also provides the most basic sample for custom/user btCollisionAlgorithm
 class btSphereSphereCollisionAlgorithm : public btActivatingCollisionAlgorithm
 class btSphereSphereCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+
 public:
 public:
-	btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap);
+	btSphereSphereCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap);
 
 
 	btSphereSphereCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	btSphereSphereCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 		: btActivatingCollisionAlgorithm(ci) {}
 		: btActivatingCollisionAlgorithm(ci) {}
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 		{
 		{
 			manifoldArray.push_back(m_manifoldPtr);
 			manifoldArray.push_back(m_manifoldPtr);
 		}
 		}
 	}
 	}
-	
+
 	virtual ~btSphereSphereCollisionAlgorithm();
 	virtual ~btSphereSphereCollisionAlgorithm();
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap)
 		{
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereSphereCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereSphereCollisionAlgorithm));
-			return new(mem) btSphereSphereCollisionAlgorithm(0,ci,col0Wrap,col1Wrap);
+			return new (mem) btSphereSphereCollisionAlgorithm(0, ci, col0Wrap, col1Wrap);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
-
+#endif  //BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H

+ 15 - 17
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp

@@ -13,7 +13,6 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "btSphereTriangleCollisionAlgorithm.h"
 #include "btSphereTriangleCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
@@ -21,15 +20,15 @@ subject to the following restrictions:
 #include "SphereTriangleDetector.h"
 #include "SphereTriangleDetector.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
-btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool swapped)
-: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_ownManifold(false),
-m_manifoldPtr(mf),
-m_swapped(swapped)
+btSphereTriangleCollisionAlgorithm::btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool swapped)
+	: btActivatingCollisionAlgorithm(ci, body0Wrap, body1Wrap),
+	  m_ownManifold(false),
+	  m_manifoldPtr(mf),
+	  m_swapped(swapped)
 {
 {
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
+		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(), body1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -43,36 +42,35 @@ btSphereTriangleCollisionAlgorithm::~btSphereTriangleCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btSphereTriangleCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btSphereTriangleCollisionAlgorithm::processCollision(const btCollisionObjectWrapper* col0Wrap, const btCollisionObjectWrapper* col1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 		return;
 		return;
 
 
-	const btCollisionObjectWrapper* sphereObjWrap = m_swapped? col1Wrap : col0Wrap;
-	const btCollisionObjectWrapper* triObjWrap = m_swapped? col0Wrap : col1Wrap;
+	const btCollisionObjectWrapper* sphereObjWrap = m_swapped ? col1Wrap : col0Wrap;
+	const btCollisionObjectWrapper* triObjWrap = m_swapped ? col0Wrap : col1Wrap;
 
 
 	btSphereShape* sphere = (btSphereShape*)sphereObjWrap->getCollisionShape();
 	btSphereShape* sphere = (btSphereShape*)sphereObjWrap->getCollisionShape();
 	btTriangleShape* triangle = (btTriangleShape*)triObjWrap->getCollisionShape();
 	btTriangleShape* triangle = (btTriangleShape*)triObjWrap->getCollisionShape();
-	
+
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
-	SphereTriangleDetector detector(sphere,triangle, m_manifoldPtr->getContactBreakingThreshold()+ resultOut->m_closestPointDistanceThreshold);
-	
+	SphereTriangleDetector detector(sphere, triangle, m_manifoldPtr->getContactBreakingThreshold() + resultOut->m_closestPointDistanceThreshold);
+
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
-	input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds
+	input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);  ///@todo: tighter bounds
 	input.m_transformA = sphereObjWrap->getWorldTransform();
 	input.m_transformA = sphereObjWrap->getWorldTransform();
 	input.m_transformB = triObjWrap->getWorldTransform();
 	input.m_transformB = triObjWrap->getWorldTransform();
 
 
 	bool swapResults = m_swapped;
 	bool swapResults = m_swapped;
 
 
-	detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw,swapResults);
+	detector.getClosestPoints(input, *resultOut, dispatchInfo.m_debugDraw, swapResults);
 
 
 	if (m_ownManifold)
 	if (m_ownManifold)
 		resultOut->refreshContactPoints();
 		resultOut->refreshContactPoints();
-	
 }
 }
 
 
-btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0, btCollisionObject* col1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut)
 {
 {
 	(void)resultOut;
 	(void)resultOut;
 	(void)dispatchInfo;
 	(void)dispatchInfo;

+ 13 - 17
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h

@@ -27,43 +27,39 @@ class btPersistentManifold;
 /// Also provides the most basic sample for custom/user btCollisionAlgorithm
 /// Also provides the most basic sample for custom/user btCollisionAlgorithm
 class btSphereTriangleCollisionAlgorithm : public btActivatingCollisionAlgorithm
 class btSphereTriangleCollisionAlgorithm : public btActivatingCollisionAlgorithm
 {
 {
-	bool	m_ownManifold;
-	btPersistentManifold*	m_manifoldPtr;
-	bool	m_swapped;
-	
+	bool m_ownManifold;
+	btPersistentManifold* m_manifoldPtr;
+	bool m_swapped;
+
 public:
 public:
-	btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool swapped);
+	btSphereTriangleCollisionAlgorithm(btPersistentManifold* mf, const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, bool swapped);
 
 
 	btSphereTriangleCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	btSphereTriangleCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 		: btActivatingCollisionAlgorithm(ci) {}
 		: btActivatingCollisionAlgorithm(ci) {}
 
 
-	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision(const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual btScalar calculateTimeOfImpact(btCollisionObject* body0, btCollisionObject* body1, const btDispatcherInfo& dispatchInfo, btManifoldResult* resultOut);
 
 
-	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray)
+	virtual void getAllContactManifolds(btManifoldArray& manifoldArray)
 	{
 	{
 		if (m_manifoldPtr && m_ownManifold)
 		if (m_manifoldPtr && m_ownManifold)
 		{
 		{
 			manifoldArray.push_back(m_manifoldPtr);
 			manifoldArray.push_back(m_manifoldPtr);
 		}
 		}
 	}
 	}
-	
+
 	virtual ~btSphereTriangleCollisionAlgorithm();
 	virtual ~btSphereTriangleCollisionAlgorithm();
 
 
-	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	struct CreateFunc : public btCollisionAlgorithmCreateFunc
 	{
 	{
-		
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap, const btCollisionObjectWrapper* body1Wrap)
 		{
 		{
-			
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereTriangleCollisionAlgorithm));
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btSphereTriangleCollisionAlgorithm));
 
 
-			return new(mem) btSphereTriangleCollisionAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_swapped);
+			return new (mem) btSphereTriangleCollisionAlgorithm(ci.m_manifold, ci, body0Wrap, body1Wrap, m_swapped);
 		}
 		}
 	};
 	};
-
 };
 };
 
 
-#endif //BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H
-
+#endif  //BT_SPHERE_TRIANGLE_COLLISION_ALGORITHM_H

+ 21 - 29
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btUnionFind.cpp

@@ -15,68 +15,60 @@ subject to the following restrictions:
 
 
 #include "btUnionFind.h"
 #include "btUnionFind.h"
 
 
-
-
 btUnionFind::~btUnionFind()
 btUnionFind::~btUnionFind()
 {
 {
 	Free();
 	Free();
-
 }
 }
 
 
 btUnionFind::btUnionFind()
 btUnionFind::btUnionFind()
-{ 
-
+{
 }
 }
 
 
-void	btUnionFind::allocate(int N)
+void btUnionFind::allocate(int N)
 {
 {
 	m_elements.resize(N);
 	m_elements.resize(N);
 }
 }
-void	btUnionFind::Free()
+void btUnionFind::Free()
 {
 {
 	m_elements.clear();
 	m_elements.clear();
 }
 }
 
 
-
-void	btUnionFind::reset(int N)
+void btUnionFind::reset(int N)
 {
 {
 	allocate(N);
 	allocate(N);
 
 
-	for (int i = 0; i < N; i++) 
-	{ 
-		m_elements[i].m_id = i; m_elements[i].m_sz = 1; 
-	} 
+	for (int i = 0; i < N; i++)
+	{
+		m_elements[i].m_id = i;
+		m_elements[i].m_sz = 1;
+	}
 }
 }
 
 
-
 class btUnionFindElementSortPredicate
 class btUnionFindElementSortPredicate
 {
 {
-	public:
-
-		bool operator() ( const btElement& lhs, const btElement& rhs ) const
-		{
-			return lhs.m_id < rhs.m_id;
-		}
+public:
+	bool operator()(const btElement& lhs, const btElement& rhs) const
+	{
+		return lhs.m_id < rhs.m_id;
+	}
 };
 };
 
 
 ///this is a special operation, destroying the content of btUnionFind.
 ///this is a special operation, destroying the content of btUnionFind.
 ///it sorts the elements, based on island id, in order to make it easy to iterate over islands
 ///it sorts the elements, based on island id, in order to make it easy to iterate over islands
-void	btUnionFind::sortIslands()
+void btUnionFind::sortIslands()
 {
 {
-
 	//first store the original body index, and islandId
 	//first store the original body index, and islandId
 	int numElements = m_elements.size();
 	int numElements = m_elements.size();
-	
-	for (int i=0;i<numElements;i++)
+
+	for (int i = 0; i < numElements; i++)
 	{
 	{
 		m_elements[i].m_id = find(i);
 		m_elements[i].m_id = find(i);
 #ifndef STATIC_SIMULATION_ISLAND_OPTIMIZATION
 #ifndef STATIC_SIMULATION_ISLAND_OPTIMIZATION
 		m_elements[i].m_sz = i;
 		m_elements[i].m_sz = i;
-#endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION
+#endif  //STATIC_SIMULATION_ISLAND_OPTIMIZATION
 	}
 	}
-	
-	 // Sort the vector using predicate and std::sort
-	  //std::sort(m_elements.begin(), m_elements.end(), btUnionFindElementSortPredicate);
-	  m_elements.quickSort(btUnionFindElementSortPredicate());
 
 
+	// Sort the vector using predicate and std::sort
+	//std::sort(m_elements.begin(), m_elements.end(), btUnionFindElementSortPredicate);
+	m_elements.quickSort(btUnionFindElementSortPredicate());
 }
 }

+ 83 - 89
Source/ThirdParty/Bullet/src/BulletCollision/CollisionDispatch/btUnionFind.h

@@ -23,107 +23,101 @@ subject to the following restrictions:
 ///see for discussion of static island optimizations by Vroonsh here: http://code.google.com/p/bullet/issues/detail?id=406
 ///see for discussion of static island optimizations by Vroonsh here: http://code.google.com/p/bullet/issues/detail?id=406
 #define STATIC_SIMULATION_ISLAND_OPTIMIZATION 1
 #define STATIC_SIMULATION_ISLAND_OPTIMIZATION 1
 
 
-struct	btElement
+struct btElement
 {
 {
-	int	m_id;
-	int	m_sz;
+	int m_id;
+	int m_sz;
 };
 };
 
 
 ///UnionFind calculates connected subsets
 ///UnionFind calculates connected subsets
 // Implements weighted Quick Union with path compression
 // Implements weighted Quick Union with path compression
 // optimization: could use short ints instead of ints (halving memory, would limit the number of rigid bodies to 64k, sounds reasonable)
 // optimization: could use short ints instead of ints (halving memory, would limit the number of rigid bodies to 64k, sounds reasonable)
 class btUnionFind
 class btUnionFind
-  {
-    private:
-		btAlignedObjectArray<btElement>	m_elements;
-
-    public:
-	  
-		btUnionFind();
-		~btUnionFind();
-
-	
-		//this is a special operation, destroying the content of btUnionFind.
-		//it sorts the elements, based on island id, in order to make it easy to iterate over islands
-		void	sortIslands();
-
-	  void	reset(int N);
-
-	  SIMD_FORCE_INLINE int	getNumElements() const
-	  {
-		  return int(m_elements.size());
-	  }
-	  SIMD_FORCE_INLINE bool  isRoot(int x) const
-	  {
-		  return (x == m_elements[x].m_id);
-	  }
-
-	  btElement&	getElement(int index)
-	  {
-		  return m_elements[index];
-	  }
-	  const btElement& getElement(int index) const
-	  {
-		  return m_elements[index];
-	  }
-   
-	  void	allocate(int N);
-	  void	Free();
-
-
-
-
-	  int find(int p, int q)
-		{ 
-			return (find(p) == find(q)); 
-		}
-
-		void unite(int p, int q)
-		{
-			int i = find(p), j = find(q);
-			if (i == j) 
-				return;
+{
+private:
+	btAlignedObjectArray<btElement> m_elements;
+
+public:
+	btUnionFind();
+	~btUnionFind();
+
+	//this is a special operation, destroying the content of btUnionFind.
+	//it sorts the elements, based on island id, in order to make it easy to iterate over islands
+	void sortIslands();
+
+	void reset(int N);
+
+	SIMD_FORCE_INLINE int getNumElements() const
+	{
+		return int(m_elements.size());
+	}
+	SIMD_FORCE_INLINE bool isRoot(int x) const
+	{
+		return (x == m_elements[x].m_id);
+	}
+
+	btElement& getElement(int index)
+	{
+		return m_elements[index];
+	}
+	const btElement& getElement(int index) const
+	{
+		return m_elements[index];
+	}
+
+	void allocate(int N);
+	void Free();
+
+	int find(int p, int q)
+	{
+		return (find(p) == find(q));
+	}
+
+	void unite(int p, int q)
+	{
+		int i = find(p), j = find(q);
+		if (i == j)
+			return;
 
 
 #ifndef USE_PATH_COMPRESSION
 #ifndef USE_PATH_COMPRESSION
-			//weighted quick union, this keeps the 'trees' balanced, and keeps performance of unite O( log(n) )
-			if (m_elements[i].m_sz < m_elements[j].m_sz)
-			{ 
-				m_elements[i].m_id = j; m_elements[j].m_sz += m_elements[i].m_sz; 
-			}
-			else 
-			{ 
-				m_elements[j].m_id = i; m_elements[i].m_sz += m_elements[j].m_sz; 
-			}
-#else
-			m_elements[i].m_id = j; m_elements[j].m_sz += m_elements[i].m_sz; 
-#endif //USE_PATH_COMPRESSION
+		//weighted quick union, this keeps the 'trees' balanced, and keeps performance of unite O( log(n) )
+		if (m_elements[i].m_sz < m_elements[j].m_sz)
+		{
+			m_elements[i].m_id = j;
+			m_elements[j].m_sz += m_elements[i].m_sz;
+		}
+		else
+		{
+			m_elements[j].m_id = i;
+			m_elements[i].m_sz += m_elements[j].m_sz;
 		}
 		}
+#else
+		m_elements[i].m_id = j;
+		m_elements[j].m_sz += m_elements[i].m_sz;
+#endif  //USE_PATH_COMPRESSION
+	}
+
+	int find(int x)
+	{
+		//btAssert(x < m_N);
+		//btAssert(x >= 0);
 
 
-		int find(int x)
-		{ 
+		while (x != m_elements[x].m_id)
+		{
+			//not really a reason not to use path compression, and it flattens the trees/improves find performance dramatically
+
+#ifdef USE_PATH_COMPRESSION
+			const btElement* elementPtr = &m_elements[m_elements[x].m_id];
+			m_elements[x].m_id = elementPtr->m_id;
+			x = elementPtr->m_id;
+#else  //
+			x = m_elements[x].m_id;
+#endif
 			//btAssert(x < m_N);
 			//btAssert(x < m_N);
 			//btAssert(x >= 0);
 			//btAssert(x >= 0);
-
-			while (x != m_elements[x].m_id) 
-			{
-		//not really a reason not to use path compression, and it flattens the trees/improves find performance dramatically
-	
-		#ifdef USE_PATH_COMPRESSION
-				const btElement* elementPtr = &m_elements[m_elements[x].m_id];
-				m_elements[x].m_id = elementPtr->m_id;
-				x = elementPtr->m_id;			
-		#else//
-				x = m_elements[x].m_id;
-		#endif		
-				//btAssert(x < m_N);
-				//btAssert(x >= 0);
-
-			}
-			return x; 
 		}
 		}
+		return x;
+	}
+};
 
 
-
-  };
-
-
-#endif //BT_UNION_FIND_H
+#endif  //BT_UNION_FIND_H

+ 10 - 15
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBox2dShape.cpp

@@ -15,28 +15,23 @@ subject to the following restrictions:
 
 
 #include "btBox2dShape.h"
 #include "btBox2dShape.h"
 
 
+//{
 
 
-//{ 
-
-
-void btBox2dShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+void btBox2dShape::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
 {
 {
-	btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax);
+	btTransformAabb(getHalfExtentsWithoutMargin(), getMargin(), t, aabbMin, aabbMax);
 }
 }
 
 
-
-void	btBox2dShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
+void btBox2dShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
 {
 {
 	//btScalar margin = btScalar(0.);
 	//btScalar margin = btScalar(0.);
 	btVector3 halfExtents = getHalfExtentsWithMargin();
 	btVector3 halfExtents = getHalfExtentsWithMargin();
 
 
-	btScalar lx=btScalar(2.)*(halfExtents.x());
-	btScalar ly=btScalar(2.)*(halfExtents.y());
-	btScalar lz=btScalar(2.)*(halfExtents.z());
-
-	inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
-					mass/(btScalar(12.0)) * (lx*lx + lz*lz),
-					mass/(btScalar(12.0)) * (lx*lx + ly*ly));
+	btScalar lx = btScalar(2.) * (halfExtents.x());
+	btScalar ly = btScalar(2.) * (halfExtents.y());
+	btScalar lz = btScalar(2.) * (halfExtents.z());
 
 
+	inertia.setValue(mass / (btScalar(12.0)) * (ly * ly + lz * lz),
+					 mass / (btScalar(12.0)) * (lx * lx + lz * lz),
+					 mass / (btScalar(12.0)) * (lx * lx + ly * ly));
 }
 }
-

+ 160 - 192
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBox2dShape.h

@@ -23,9 +23,9 @@ subject to the following restrictions:
 #include "LinearMath/btMinMax.h"
 #include "LinearMath/btMinMax.h"
 
 
 ///The btBox2dShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
 ///The btBox2dShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
-ATTRIBUTE_ALIGNED16(class) btBox2dShape: public btPolyhedralConvexShape
+ATTRIBUTE_ALIGNED16(class)
+btBox2dShape : public btPolyhedralConvexShape
 {
 {
-
 	//btVector3	m_boxHalfExtents1; //use m_implicitShapeDimensions instead
 	//btVector3	m_boxHalfExtents1; //use m_implicitShapeDimensions instead
 
 
 	btVector3 m_centroid;
 	btVector3 m_centroid;
@@ -33,122 +33,111 @@ ATTRIBUTE_ALIGNED16(class) btBox2dShape: public btPolyhedralConvexShape
 	btVector3 m_normals[4];
 	btVector3 m_normals[4];
 
 
 public:
 public:
-
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	btVector3 getHalfExtentsWithMargin() const
 	btVector3 getHalfExtentsWithMargin() const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
-		btVector3 margin(getMargin(),getMargin(),getMargin());
+		btVector3 margin(getMargin(), getMargin(), getMargin());
 		halfExtents += margin;
 		halfExtents += margin;
 		return halfExtents;
 		return halfExtents;
 	}
 	}
-	
+
 	const btVector3& getHalfExtentsWithoutMargin() const
 	const btVector3& getHalfExtentsWithoutMargin() const
 	{
 	{
-		return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included
+		return m_implicitShapeDimensions;  //changed in Bullet 2.63: assume the scaling and margin are included
 	}
 	}
-	
 
 
-	virtual btVector3	localGetSupportingVertex(const btVector3& vec) const
+	virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
-		btVector3 margin(getMargin(),getMargin(),getMargin());
+		btVector3 margin(getMargin(), getMargin(), getMargin());
 		halfExtents += margin;
 		halfExtents += margin;
-		
+
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
-			btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
-			btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
+						 btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+						 btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
 	}
 	}
 
 
-	SIMD_FORCE_INLINE  btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+	SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const
 	{
 	{
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
-		
+
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
-			btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
-			btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
+						 btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+						 btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
 	}
 	}
 
 
-	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+	virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
 	{
 	{
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
-	
-		for (int i=0;i<numVectors;i++)
+
+		for (int i = 0; i < numVectors; i++)
 		{
 		{
 			const btVector3& vec = vectors[i];
 			const btVector3& vec = vectors[i];
 			supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
 			supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
-				btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
-				btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); 
+										   btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+										   btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
 		}
 		}
-
 	}
 	}
 
 
-
 	///a btBox2dShape is a flat 2D box in the X-Y plane (Z extents are zero)
 	///a btBox2dShape is a flat 2D box in the X-Y plane (Z extents are zero)
-	btBox2dShape( const btVector3& boxHalfExtents) 
+	btBox2dShape(const btVector3& boxHalfExtents)
 		: btPolyhedralConvexShape(),
 		: btPolyhedralConvexShape(),
-		m_centroid(0,0,0)
+		  m_centroid(0, 0, 0)
 	{
 	{
-		m_vertices[0].setValue(-boxHalfExtents.getX(),-boxHalfExtents.getY(),0);
-		m_vertices[1].setValue(boxHalfExtents.getX(),-boxHalfExtents.getY(),0);
-		m_vertices[2].setValue(boxHalfExtents.getX(),boxHalfExtents.getY(),0);
-		m_vertices[3].setValue(-boxHalfExtents.getX(),boxHalfExtents.getY(),0);
+		m_vertices[0].setValue(-boxHalfExtents.getX(), -boxHalfExtents.getY(), 0);
+		m_vertices[1].setValue(boxHalfExtents.getX(), -boxHalfExtents.getY(), 0);
+		m_vertices[2].setValue(boxHalfExtents.getX(), boxHalfExtents.getY(), 0);
+		m_vertices[3].setValue(-boxHalfExtents.getX(), boxHalfExtents.getY(), 0);
 
 
-		m_normals[0].setValue(0,-1,0);
-		m_normals[1].setValue(1,0,0);
-		m_normals[2].setValue(0,1,0);
-		m_normals[3].setValue(-1,0,0);
+		m_normals[0].setValue(0, -1, 0);
+		m_normals[1].setValue(1, 0, 0);
+		m_normals[2].setValue(0, 1, 0);
+		m_normals[3].setValue(-1, 0, 0);
 
 
 		btScalar minDimension = boxHalfExtents.getX();
 		btScalar minDimension = boxHalfExtents.getX();
-		if (minDimension>boxHalfExtents.getY())
+		if (minDimension > boxHalfExtents.getY())
 			minDimension = boxHalfExtents.getY();
 			minDimension = boxHalfExtents.getY();
-		setSafeMargin(minDimension);
 
 
 		m_shapeType = BOX_2D_SHAPE_PROXYTYPE;
 		m_shapeType = BOX_2D_SHAPE_PROXYTYPE;
-		btVector3 margin(getMargin(),getMargin(),getMargin());
+		btVector3 margin(getMargin(), getMargin(), getMargin());
 		m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
 		m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
+
+		setSafeMargin(minDimension);
 	};
 	};
 
 
 	virtual void setMargin(btScalar collisionMargin)
 	virtual void setMargin(btScalar collisionMargin)
 	{
 	{
 		//correct the m_implicitShapeDimensions for the margin
 		//correct the m_implicitShapeDimensions for the margin
-		btVector3 oldMargin(getMargin(),getMargin(),getMargin());
-		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
-		
+		btVector3 oldMargin(getMargin(), getMargin(), getMargin());
+		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin;
+
 		btConvexInternalShape::setMargin(collisionMargin);
 		btConvexInternalShape::setMargin(collisionMargin);
-		btVector3 newMargin(getMargin(),getMargin(),getMargin());
+		btVector3 newMargin(getMargin(), getMargin(), getMargin());
 		m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
 		m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
-
 	}
 	}
-	virtual void	setLocalScaling(const btVector3& scaling)
+	virtual void setLocalScaling(const btVector3& scaling)
 	{
 	{
-		btVector3 oldMargin(getMargin(),getMargin(),getMargin());
-		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
+		btVector3 oldMargin(getMargin(), getMargin(), getMargin());
+		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin;
 		btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
 		btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
 
 
 		btConvexInternalShape::setLocalScaling(scaling);
 		btConvexInternalShape::setLocalScaling(scaling);
 
 
 		m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
 		m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
-
 	}
 	}
 
 
-	virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
-
-	
-
-	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
+	virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
 
 
+	virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
 
 
-
-
-
-	int	getVertexCount() const
+	int getVertexCount() const
 	{
 	{
 		return 4;
 		return 4;
 	}
 	}
 
 
-	virtual int getNumVertices()const
+	virtual int getNumVertices() const
 	{
 	{
 		return 4;
 		return 4;
 	}
 	}
@@ -163,82 +152,70 @@ public:
 		return &m_normals[0];
 		return &m_normals[0];
 	}
 	}
 
 
-
-
-
-
-
-
-	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const
+	virtual void getPlane(btVector3 & planeNormal, btVector3 & planeSupport, int i) const
 	{
 	{
 		//this plane might not be aligned...
 		//this plane might not be aligned...
-		btVector4 plane ;
-		getPlaneEquation(plane,i);
-		planeNormal = btVector3(plane.getX(),plane.getY(),plane.getZ());
+		btVector4 plane;
+		getPlaneEquation(plane, i);
+		planeNormal = btVector3(plane.getX(), plane.getY(), plane.getZ());
 		planeSupport = localGetSupportingVertex(-planeNormal);
 		planeSupport = localGetSupportingVertex(-planeNormal);
 	}
 	}
 
 
-
 	const btVector3& getCentroid() const
 	const btVector3& getCentroid() const
 	{
 	{
 		return m_centroid;
 		return m_centroid;
 	}
 	}
-	
+
 	virtual int getNumPlanes() const
 	virtual int getNumPlanes() const
 	{
 	{
 		return 6;
 		return 6;
-	}	
-	
-	
+	}
 
 
 	virtual int getNumEdges() const
 	virtual int getNumEdges() const
 	{
 	{
 		return 12;
 		return 12;
 	}
 	}
 
 
-
-	virtual void getVertex(int i,btVector3& vtx) const
+	virtual void getVertex(int i, btVector3& vtx) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 
 
 		vtx = btVector3(
 		vtx = btVector3(
-				halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1),
-				halfExtents.y() * (1-((i&2)>>1)) - halfExtents.y() * ((i&2)>>1),
-				halfExtents.z() * (1-((i&4)>>2)) - halfExtents.z() * ((i&4)>>2));
+			halfExtents.x() * (1 - (i & 1)) - halfExtents.x() * (i & 1),
+			halfExtents.y() * (1 - ((i & 2) >> 1)) - halfExtents.y() * ((i & 2) >> 1),
+			halfExtents.z() * (1 - ((i & 4) >> 2)) - halfExtents.z() * ((i & 4) >> 2));
 	}
 	}
-	
 
 
-	virtual void	getPlaneEquation(btVector4& plane,int i) const
+	virtual void getPlaneEquation(btVector4 & plane, int i) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 
 
 		switch (i)
 		switch (i)
 		{
 		{
-		case 0:
-			plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.),-halfExtents.x());
-			break;
-		case 1:
-			plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.),-halfExtents.x());
-			break;
-		case 2:
-			plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.),-halfExtents.y());
-			break;
-		case 3:
-			plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.),-halfExtents.y());
-			break;
-		case 4:
-			plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.),-halfExtents.z());
-			break;
-		case 5:
-			plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.),-halfExtents.z());
-			break;
-		default:
-			btAssert(0);
+			case 0:
+				plane.setValue(btScalar(1.), btScalar(0.), btScalar(0.), -halfExtents.x());
+				break;
+			case 1:
+				plane.setValue(btScalar(-1.), btScalar(0.), btScalar(0.), -halfExtents.x());
+				break;
+			case 2:
+				plane.setValue(btScalar(0.), btScalar(1.), btScalar(0.), -halfExtents.y());
+				break;
+			case 3:
+				plane.setValue(btScalar(0.), btScalar(-1.), btScalar(0.), -halfExtents.y());
+				break;
+			case 4:
+				plane.setValue(btScalar(0.), btScalar(0.), btScalar(1.), -halfExtents.z());
+				break;
+			case 5:
+				plane.setValue(btScalar(0.), btScalar(0.), btScalar(-1.), -halfExtents.z());
+				break;
+			default:
+				btAssert(0);
 		}
 		}
 	}
 	}
 
 
-	
-	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
+	virtual void getEdge(int i, btVector3& pa, btVector3& pb) const
 	//virtual void getEdge(int i,Edge& edge) const
 	//virtual void getEdge(int i,Edge& edge) const
 	{
 	{
 		int edgeVert0 = 0;
 		int edgeVert0 = 0;
@@ -246,126 +223,117 @@ public:
 
 
 		switch (i)
 		switch (i)
 		{
 		{
-		case 0:
+			case 0:
 				edgeVert0 = 0;
 				edgeVert0 = 0;
 				edgeVert1 = 1;
 				edgeVert1 = 1;
-			break;
-		case 1:
+				break;
+			case 1:
 				edgeVert0 = 0;
 				edgeVert0 = 0;
 				edgeVert1 = 2;
 				edgeVert1 = 2;
-			break;
-		case 2:
-			edgeVert0 = 1;
-			edgeVert1 = 3;
-
-			break;
-		case 3:
-			edgeVert0 = 2;
-			edgeVert1 = 3;
-			break;
-		case 4:
-			edgeVert0 = 0;
-			edgeVert1 = 4;
-			break;
-		case 5:
-			edgeVert0 = 1;
-			edgeVert1 = 5;
-
-			break;
-		case 6:
-			edgeVert0 = 2;
-			edgeVert1 = 6;
-			break;
-		case 7:
-			edgeVert0 = 3;
-			edgeVert1 = 7;
-			break;
-		case 8:
-			edgeVert0 = 4;
-			edgeVert1 = 5;
-			break;
-		case 9:
-			edgeVert0 = 4;
-			edgeVert1 = 6;
-			break;
-		case 10:
-			edgeVert0 = 5;
-			edgeVert1 = 7;
-			break;
-		case 11:
-			edgeVert0 = 6;
-			edgeVert1 = 7;
-			break;
-		default:
-			btAssert(0);
-
+				break;
+			case 2:
+				edgeVert0 = 1;
+				edgeVert1 = 3;
+
+				break;
+			case 3:
+				edgeVert0 = 2;
+				edgeVert1 = 3;
+				break;
+			case 4:
+				edgeVert0 = 0;
+				edgeVert1 = 4;
+				break;
+			case 5:
+				edgeVert0 = 1;
+				edgeVert1 = 5;
+
+				break;
+			case 6:
+				edgeVert0 = 2;
+				edgeVert1 = 6;
+				break;
+			case 7:
+				edgeVert0 = 3;
+				edgeVert1 = 7;
+				break;
+			case 8:
+				edgeVert0 = 4;
+				edgeVert1 = 5;
+				break;
+			case 9:
+				edgeVert0 = 4;
+				edgeVert1 = 6;
+				break;
+			case 10:
+				edgeVert0 = 5;
+				edgeVert1 = 7;
+				break;
+			case 11:
+				edgeVert0 = 6;
+				edgeVert1 = 7;
+				break;
+			default:
+				btAssert(0);
 		}
 		}
 
 
-		getVertex(edgeVert0,pa );
-		getVertex(edgeVert1,pb );
+		getVertex(edgeVert0, pa);
+		getVertex(edgeVert1, pb);
 	}
 	}
 
 
-
-
-
-	
-	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const
+	virtual bool isInside(const btVector3& pt, btScalar tolerance) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 
 
 		//btScalar minDist = 2*tolerance;
 		//btScalar minDist = 2*tolerance;
-		
-		bool result =	(pt.x() <= (halfExtents.x()+tolerance)) &&
-						(pt.x() >= (-halfExtents.x()-tolerance)) &&
-						(pt.y() <= (halfExtents.y()+tolerance)) &&
-						(pt.y() >= (-halfExtents.y()-tolerance)) &&
-						(pt.z() <= (halfExtents.z()+tolerance)) &&
-						(pt.z() >= (-halfExtents.z()-tolerance));
-		
+
+		bool result = (pt.x() <= (halfExtents.x() + tolerance)) &&
+					  (pt.x() >= (-halfExtents.x() - tolerance)) &&
+					  (pt.y() <= (halfExtents.y() + tolerance)) &&
+					  (pt.y() >= (-halfExtents.y() - tolerance)) &&
+					  (pt.z() <= (halfExtents.z() + tolerance)) &&
+					  (pt.z() >= (-halfExtents.z() - tolerance));
+
 		return result;
 		return result;
 	}
 	}
 
 
-
 	//debugging
 	//debugging
-	virtual const char*	getName()const
+	virtual const char* getName() const
 	{
 	{
 		return "Box2d";
 		return "Box2d";
 	}
 	}
 
 
-	virtual int		getNumPreferredPenetrationDirections() const
+	virtual int getNumPreferredPenetrationDirections() const
 	{
 	{
 		return 6;
 		return 6;
 	}
 	}
-	
-	virtual void	getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
+
+	virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
 	{
 	{
 		switch (index)
 		switch (index)
 		{
 		{
-		case 0:
-			penetrationVector.setValue(btScalar(1.),btScalar(0.),btScalar(0.));
-			break;
-		case 1:
-			penetrationVector.setValue(btScalar(-1.),btScalar(0.),btScalar(0.));
-			break;
-		case 2:
-			penetrationVector.setValue(btScalar(0.),btScalar(1.),btScalar(0.));
-			break;
-		case 3:
-			penetrationVector.setValue(btScalar(0.),btScalar(-1.),btScalar(0.));
-			break;
-		case 4:
-			penetrationVector.setValue(btScalar(0.),btScalar(0.),btScalar(1.));
-			break;
-		case 5:
-			penetrationVector.setValue(btScalar(0.),btScalar(0.),btScalar(-1.));
-			break;
-		default:
-			btAssert(0);
+			case 0:
+				penetrationVector.setValue(btScalar(1.), btScalar(0.), btScalar(0.));
+				break;
+			case 1:
+				penetrationVector.setValue(btScalar(-1.), btScalar(0.), btScalar(0.));
+				break;
+			case 2:
+				penetrationVector.setValue(btScalar(0.), btScalar(1.), btScalar(0.));
+				break;
+			case 3:
+				penetrationVector.setValue(btScalar(0.), btScalar(-1.), btScalar(0.));
+				break;
+			case 4:
+				penetrationVector.setValue(btScalar(0.), btScalar(0.), btScalar(1.));
+				break;
+			case 5:
+				penetrationVector.setValue(btScalar(0.), btScalar(0.), btScalar(-1.));
+				break;
+			default:
+				btAssert(0);
 		}
 		}
 	}
 	}
-
 };
 };
 
 
-#endif //BT_OBB_BOX_2D_SHAPE_H
-
-
+#endif  //BT_OBB_BOX_2D_SHAPE_H

+ 14 - 20
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBoxShape.cpp

@@ -14,38 +14,32 @@ subject to the following restrictions:
 */
 */
 #include "btBoxShape.h"
 #include "btBoxShape.h"
 
 
-btBoxShape::btBoxShape( const btVector3& boxHalfExtents) 
-: btPolyhedralConvexShape()
+btBoxShape::btBoxShape(const btVector3& boxHalfExtents)
+	: btPolyhedralConvexShape()
 {
 {
 	m_shapeType = BOX_SHAPE_PROXYTYPE;
 	m_shapeType = BOX_SHAPE_PROXYTYPE;
 
 
-	setSafeMargin(boxHalfExtents);
-
-	btVector3 margin(getMargin(),getMargin(),getMargin());
+	btVector3 margin(getMargin(), getMargin(), getMargin());
 	m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
 	m_implicitShapeDimensions = (boxHalfExtents * m_localScaling) - margin;
-};
-
-
 
 
+	setSafeMargin(boxHalfExtents);
+};
 
 
-void btBoxShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
+void btBoxShape::getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
 {
 {
-	btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax);
+	btTransformAabb(getHalfExtentsWithoutMargin(), getMargin(), t, aabbMin, aabbMax);
 }
 }
 
 
-
-void	btBoxShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
+void btBoxShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
 {
 {
 	//btScalar margin = btScalar(0.);
 	//btScalar margin = btScalar(0.);
 	btVector3 halfExtents = getHalfExtentsWithMargin();
 	btVector3 halfExtents = getHalfExtentsWithMargin();
 
 
-	btScalar lx=btScalar(2.)*(halfExtents.x());
-	btScalar ly=btScalar(2.)*(halfExtents.y());
-	btScalar lz=btScalar(2.)*(halfExtents.z());
-
-	inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
-					mass/(btScalar(12.0)) * (lx*lx + lz*lz),
-					mass/(btScalar(12.0)) * (lx*lx + ly*ly));
+	btScalar lx = btScalar(2.) * (halfExtents.x());
+	btScalar ly = btScalar(2.) * (halfExtents.y());
+	btScalar lz = btScalar(2.) * (halfExtents.z());
 
 
+	inertia.setValue(mass / (btScalar(12.0)) * (ly * ly + lz * lz),
+					 mass / (btScalar(12.0)) * (lx * lx + lz * lz),
+					 mass / (btScalar(12.0)) * (lx * lx + ly * ly));
 }
 }
-

+ 147 - 170
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBoxShape.h

@@ -23,112 +23,102 @@ subject to the following restrictions:
 #include "LinearMath/btMinMax.h"
 #include "LinearMath/btMinMax.h"
 
 
 ///The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
 ///The btBoxShape is a box primitive around the origin, its sides axis aligned with length specified by half extents, in local shape coordinates. When used as part of a btCollisionObject or btRigidBody it will be an oriented box in world space.
-ATTRIBUTE_ALIGNED16(class) btBoxShape: public btPolyhedralConvexShape
+ATTRIBUTE_ALIGNED16(class)
+btBoxShape : public btPolyhedralConvexShape
 {
 {
-
 	//btVector3	m_boxHalfExtents1; //use m_implicitShapeDimensions instead
 	//btVector3	m_boxHalfExtents1; //use m_implicitShapeDimensions instead
 
 
-
 public:
 public:
-
-BT_DECLARE_ALIGNED_ALLOCATOR();
+	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 	btVector3 getHalfExtentsWithMargin() const
 	btVector3 getHalfExtentsWithMargin() const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
-		btVector3 margin(getMargin(),getMargin(),getMargin());
+		btVector3 margin(getMargin(), getMargin(), getMargin());
 		halfExtents += margin;
 		halfExtents += margin;
 		return halfExtents;
 		return halfExtents;
 	}
 	}
-	
+
 	const btVector3& getHalfExtentsWithoutMargin() const
 	const btVector3& getHalfExtentsWithoutMargin() const
 	{
 	{
-		return m_implicitShapeDimensions;//scaling is included, margin is not
+		return m_implicitShapeDimensions;  //scaling is included, margin is not
 	}
 	}
-	
 
 
-	virtual btVector3	localGetSupportingVertex(const btVector3& vec) const
+	virtual btVector3 localGetSupportingVertex(const btVector3& vec) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
-		btVector3 margin(getMargin(),getMargin(),getMargin());
+		btVector3 margin(getMargin(), getMargin(), getMargin());
 		halfExtents += margin;
 		halfExtents += margin;
-		
+
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
-			btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
-			btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
+						 btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+						 btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
 	}
 	}
 
 
-	SIMD_FORCE_INLINE  btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const
+	SIMD_FORCE_INLINE btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const
 	{
 	{
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
-		
+
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
 		return btVector3(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
-			btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
-			btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
+						 btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+						 btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
 	}
 	}
 
 
-	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+	virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
 	{
 	{
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
 		const btVector3& halfExtents = getHalfExtentsWithoutMargin();
-	
-		for (int i=0;i<numVectors;i++)
+
+		for (int i = 0; i < numVectors; i++)
 		{
 		{
 			const btVector3& vec = vectors[i];
 			const btVector3& vec = vectors[i];
 			supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
 			supportVerticesOut[i].setValue(btFsels(vec.x(), halfExtents.x(), -halfExtents.x()),
-				btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
-				btFsels(vec.z(), halfExtents.z(), -halfExtents.z())); 
+										   btFsels(vec.y(), halfExtents.y(), -halfExtents.y()),
+										   btFsels(vec.z(), halfExtents.z(), -halfExtents.z()));
 		}
 		}
-
 	}
 	}
 
 
-
-	btBoxShape( const btVector3& boxHalfExtents);
+	btBoxShape(const btVector3& boxHalfExtents);
 
 
 	virtual void setMargin(btScalar collisionMargin)
 	virtual void setMargin(btScalar collisionMargin)
 	{
 	{
 		//correct the m_implicitShapeDimensions for the margin
 		//correct the m_implicitShapeDimensions for the margin
-		btVector3 oldMargin(getMargin(),getMargin(),getMargin());
-		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
-		
+		btVector3 oldMargin(getMargin(), getMargin(), getMargin());
+		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin;
+
 		btConvexInternalShape::setMargin(collisionMargin);
 		btConvexInternalShape::setMargin(collisionMargin);
-		btVector3 newMargin(getMargin(),getMargin(),getMargin());
+		btVector3 newMargin(getMargin(), getMargin(), getMargin());
 		m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
 		m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin;
-
 	}
 	}
-	virtual void	setLocalScaling(const btVector3& scaling)
+	virtual void setLocalScaling(const btVector3& scaling)
 	{
 	{
-		btVector3 oldMargin(getMargin(),getMargin(),getMargin());
-		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin;
+		btVector3 oldMargin(getMargin(), getMargin(), getMargin());
+		btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions + oldMargin;
 		btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
 		btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling;
 
 
 		btConvexInternalShape::setLocalScaling(scaling);
 		btConvexInternalShape::setLocalScaling(scaling);
 
 
 		m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
 		m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin;
-
 	}
 	}
 
 
-	virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+	virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
 
 
-	
+	virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
 
 
-	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
-
-	virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const
+	virtual void getPlane(btVector3 & planeNormal, btVector3 & planeSupport, int i) const
 	{
 	{
 		//this plane might not be aligned...
 		//this plane might not be aligned...
-		btVector4 plane ;
-		getPlaneEquation(plane,i);
-		planeNormal = btVector3(plane.getX(),plane.getY(),plane.getZ());
+		btVector4 plane;
+		getPlaneEquation(plane, i);
+		planeNormal = btVector3(plane.getX(), plane.getY(), plane.getZ());
 		planeSupport = localGetSupportingVertex(-planeNormal);
 		planeSupport = localGetSupportingVertex(-planeNormal);
 	}
 	}
 
 
-	
 	virtual int getNumPlanes() const
 	virtual int getNumPlanes() const
 	{
 	{
 		return 6;
 		return 6;
-	}	
-	
-	virtual int	getNumVertices() const 
+	}
+
+	virtual int getNumVertices() const
 	{
 	{
 		return 8;
 		return 8;
 	}
 	}
@@ -138,49 +128,46 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
 		return 12;
 		return 12;
 	}
 	}
 
 
-
-	virtual void getVertex(int i,btVector3& vtx) const
+	virtual void getVertex(int i, btVector3& vtx) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithMargin();
 		btVector3 halfExtents = getHalfExtentsWithMargin();
 
 
 		vtx = btVector3(
 		vtx = btVector3(
-				halfExtents.x() * (1-(i&1)) - halfExtents.x() * (i&1),
-				halfExtents.y() * (1-((i&2)>>1)) - halfExtents.y() * ((i&2)>>1),
-				halfExtents.z() * (1-((i&4)>>2)) - halfExtents.z() * ((i&4)>>2));
+			halfExtents.x() * (1 - (i & 1)) - halfExtents.x() * (i & 1),
+			halfExtents.y() * (1 - ((i & 2) >> 1)) - halfExtents.y() * ((i & 2) >> 1),
+			halfExtents.z() * (1 - ((i & 4) >> 2)) - halfExtents.z() * ((i & 4) >> 2));
 	}
 	}
-	
 
 
-	virtual void	getPlaneEquation(btVector4& plane,int i) const
+	virtual void getPlaneEquation(btVector4 & plane, int i) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 
 
 		switch (i)
 		switch (i)
 		{
 		{
-		case 0:
-			plane.setValue(btScalar(1.),btScalar(0.),btScalar(0.),-halfExtents.x());
-			break;
-		case 1:
-			plane.setValue(btScalar(-1.),btScalar(0.),btScalar(0.),-halfExtents.x());
-			break;
-		case 2:
-			plane.setValue(btScalar(0.),btScalar(1.),btScalar(0.),-halfExtents.y());
-			break;
-		case 3:
-			plane.setValue(btScalar(0.),btScalar(-1.),btScalar(0.),-halfExtents.y());
-			break;
-		case 4:
-			plane.setValue(btScalar(0.),btScalar(0.),btScalar(1.),-halfExtents.z());
-			break;
-		case 5:
-			plane.setValue(btScalar(0.),btScalar(0.),btScalar(-1.),-halfExtents.z());
-			break;
-		default:
-			btAssert(0);
+			case 0:
+				plane.setValue(btScalar(1.), btScalar(0.), btScalar(0.), -halfExtents.x());
+				break;
+			case 1:
+				plane.setValue(btScalar(-1.), btScalar(0.), btScalar(0.), -halfExtents.x());
+				break;
+			case 2:
+				plane.setValue(btScalar(0.), btScalar(1.), btScalar(0.), -halfExtents.y());
+				break;
+			case 3:
+				plane.setValue(btScalar(0.), btScalar(-1.), btScalar(0.), -halfExtents.y());
+				break;
+			case 4:
+				plane.setValue(btScalar(0.), btScalar(0.), btScalar(1.), -halfExtents.z());
+				break;
+			case 5:
+				plane.setValue(btScalar(0.), btScalar(0.), btScalar(-1.), -halfExtents.z());
+				break;
+			default:
+				btAssert(0);
 		}
 		}
 	}
 	}
 
 
-	
-	virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
+	virtual void getEdge(int i, btVector3& pa, btVector3& pb) const
 	//virtual void getEdge(int i,Edge& edge) const
 	//virtual void getEdge(int i,Edge& edge) const
 	{
 	{
 		int edgeVert0 = 0;
 		int edgeVert0 = 0;
@@ -188,127 +175,117 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
 		switch (i)
 		switch (i)
 		{
 		{
-		case 0:
+			case 0:
 				edgeVert0 = 0;
 				edgeVert0 = 0;
 				edgeVert1 = 1;
 				edgeVert1 = 1;
-			break;
-		case 1:
+				break;
+			case 1:
 				edgeVert0 = 0;
 				edgeVert0 = 0;
 				edgeVert1 = 2;
 				edgeVert1 = 2;
-			break;
-		case 2:
-			edgeVert0 = 1;
-			edgeVert1 = 3;
-
-			break;
-		case 3:
-			edgeVert0 = 2;
-			edgeVert1 = 3;
-			break;
-		case 4:
-			edgeVert0 = 0;
-			edgeVert1 = 4;
-			break;
-		case 5:
-			edgeVert0 = 1;
-			edgeVert1 = 5;
-
-			break;
-		case 6:
-			edgeVert0 = 2;
-			edgeVert1 = 6;
-			break;
-		case 7:
-			edgeVert0 = 3;
-			edgeVert1 = 7;
-			break;
-		case 8:
-			edgeVert0 = 4;
-			edgeVert1 = 5;
-			break;
-		case 9:
-			edgeVert0 = 4;
-			edgeVert1 = 6;
-			break;
-		case 10:
-			edgeVert0 = 5;
-			edgeVert1 = 7;
-			break;
-		case 11:
-			edgeVert0 = 6;
-			edgeVert1 = 7;
-			break;
-		default:
-			btAssert(0);
-
+				break;
+			case 2:
+				edgeVert0 = 1;
+				edgeVert1 = 3;
+
+				break;
+			case 3:
+				edgeVert0 = 2;
+				edgeVert1 = 3;
+				break;
+			case 4:
+				edgeVert0 = 0;
+				edgeVert1 = 4;
+				break;
+			case 5:
+				edgeVert0 = 1;
+				edgeVert1 = 5;
+
+				break;
+			case 6:
+				edgeVert0 = 2;
+				edgeVert1 = 6;
+				break;
+			case 7:
+				edgeVert0 = 3;
+				edgeVert1 = 7;
+				break;
+			case 8:
+				edgeVert0 = 4;
+				edgeVert1 = 5;
+				break;
+			case 9:
+				edgeVert0 = 4;
+				edgeVert1 = 6;
+				break;
+			case 10:
+				edgeVert0 = 5;
+				edgeVert1 = 7;
+				break;
+			case 11:
+				edgeVert0 = 6;
+				edgeVert1 = 7;
+				break;
+			default:
+				btAssert(0);
 		}
 		}
 
 
-		getVertex(edgeVert0,pa );
-		getVertex(edgeVert1,pb );
+		getVertex(edgeVert0, pa);
+		getVertex(edgeVert1, pb);
 	}
 	}
 
 
-
-
-
-	
-	virtual	bool isInside(const btVector3& pt,btScalar tolerance) const
+	virtual bool isInside(const btVector3& pt, btScalar tolerance) const
 	{
 	{
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 		btVector3 halfExtents = getHalfExtentsWithoutMargin();
 
 
 		//btScalar minDist = 2*tolerance;
 		//btScalar minDist = 2*tolerance;
-		
-		bool result =	(pt.x() <= (halfExtents.x()+tolerance)) &&
-						(pt.x() >= (-halfExtents.x()-tolerance)) &&
-						(pt.y() <= (halfExtents.y()+tolerance)) &&
-						(pt.y() >= (-halfExtents.y()-tolerance)) &&
-						(pt.z() <= (halfExtents.z()+tolerance)) &&
-						(pt.z() >= (-halfExtents.z()-tolerance));
-		
+
+		bool result = (pt.x() <= (halfExtents.x() + tolerance)) &&
+					  (pt.x() >= (-halfExtents.x() - tolerance)) &&
+					  (pt.y() <= (halfExtents.y() + tolerance)) &&
+					  (pt.y() >= (-halfExtents.y() - tolerance)) &&
+					  (pt.z() <= (halfExtents.z() + tolerance)) &&
+					  (pt.z() >= (-halfExtents.z() - tolerance));
+
 		return result;
 		return result;
 	}
 	}
 
 
-
 	//debugging
 	//debugging
-	virtual const char*	getName()const
+	virtual const char* getName() const
 	{
 	{
 		return "Box";
 		return "Box";
 	}
 	}
 
 
-	virtual int		getNumPreferredPenetrationDirections() const
+	virtual int getNumPreferredPenetrationDirections() const
 	{
 	{
 		return 6;
 		return 6;
 	}
 	}
-	
-	virtual void	getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
+
+	virtual void getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const
 	{
 	{
 		switch (index)
 		switch (index)
 		{
 		{
-		case 0:
-			penetrationVector.setValue(btScalar(1.),btScalar(0.),btScalar(0.));
-			break;
-		case 1:
-			penetrationVector.setValue(btScalar(-1.),btScalar(0.),btScalar(0.));
-			break;
-		case 2:
-			penetrationVector.setValue(btScalar(0.),btScalar(1.),btScalar(0.));
-			break;
-		case 3:
-			penetrationVector.setValue(btScalar(0.),btScalar(-1.),btScalar(0.));
-			break;
-		case 4:
-			penetrationVector.setValue(btScalar(0.),btScalar(0.),btScalar(1.));
-			break;
-		case 5:
-			penetrationVector.setValue(btScalar(0.),btScalar(0.),btScalar(-1.));
-			break;
-		default:
-			btAssert(0);
+			case 0:
+				penetrationVector.setValue(btScalar(1.), btScalar(0.), btScalar(0.));
+				break;
+			case 1:
+				penetrationVector.setValue(btScalar(-1.), btScalar(0.), btScalar(0.));
+				break;
+			case 2:
+				penetrationVector.setValue(btScalar(0.), btScalar(1.), btScalar(0.));
+				break;
+			case 3:
+				penetrationVector.setValue(btScalar(0.), btScalar(-1.), btScalar(0.));
+				break;
+			case 4:
+				penetrationVector.setValue(btScalar(0.), btScalar(0.), btScalar(1.));
+				break;
+			case 5:
+				penetrationVector.setValue(btScalar(0.), btScalar(0.), btScalar(-1.));
+				break;
+			default:
+				btAssert(0);
 		}
 		}
 	}
 	}
-
 };
 };
 
 
-
-#endif //BT_OBB_BOX_MINKOWSKI_H
-
-
+#endif  //BT_OBB_BOX_MINKOWSKI_H

+ 168 - 173
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp

@@ -22,11 +22,11 @@ subject to the following restrictions:
 ///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
 ///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization.
 ///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
 ///Uses an interface to access the triangles to allow for sharing graphics/physics triangles.
 btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh)
 btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh)
-:btTriangleMeshShape(meshInterface),
-m_bvh(0),
-m_triangleInfoMap(0),
-m_useQuantizedAabbCompression(useQuantizedAabbCompression),
-m_ownsBvh(false)
+	: btTriangleMeshShape(meshInterface),
+	  m_bvh(0),
+	  m_triangleInfoMap(0),
+	  m_useQuantizedAabbCompression(useQuantizedAabbCompression),
+	  m_ownsBvh(false)
 {
 {
 	m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
 	m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
 	//construct bvh from meshInterface
 	//construct bvh from meshInterface
@@ -37,16 +37,15 @@ m_ownsBvh(false)
 		buildOptimizedBvh();
 		buildOptimizedBvh();
 	}
 	}
 
 
-#endif //DISABLE_BVH
-
+#endif  //DISABLE_BVH
 }
 }
 
 
-btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax,bool buildBvh)
-:btTriangleMeshShape(meshInterface),
-m_bvh(0),
-m_triangleInfoMap(0),
-m_useQuantizedAabbCompression(useQuantizedAabbCompression),
-m_ownsBvh(false)
+btBvhTriangleMeshShape::btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax, bool buildBvh)
+	: btTriangleMeshShape(meshInterface),
+	  m_bvh(0),
+	  m_triangleInfoMap(0),
+	  m_useQuantizedAabbCompression(useQuantizedAabbCompression),
+	  m_ownsBvh(false)
 {
 {
 	m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
 	m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
 	//construct bvh from meshInterface
 	//construct bvh from meshInterface
@@ -54,30 +53,28 @@ m_ownsBvh(false)
 
 
 	if (buildBvh)
 	if (buildBvh)
 	{
 	{
-		void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
+		void* mem = btAlignedAlloc(sizeof(btOptimizedBvh), 16);
 		m_bvh = new (mem) btOptimizedBvh();
 		m_bvh = new (mem) btOptimizedBvh();
-		
-		m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax);
+
+		m_bvh->build(meshInterface, m_useQuantizedAabbCompression, bvhAabbMin, bvhAabbMax);
 		m_ownsBvh = true;
 		m_ownsBvh = true;
 	}
 	}
 
 
-#endif //DISABLE_BVH
-
+#endif  //DISABLE_BVH
 }
 }
 
 
-void	btBvhTriangleMeshShape::partialRefitTree(const btVector3& aabbMin,const btVector3& aabbMax)
+void btBvhTriangleMeshShape::partialRefitTree(const btVector3& aabbMin, const btVector3& aabbMax)
 {
 {
-	m_bvh->refitPartial( m_meshInterface,aabbMin,aabbMax );
-	
+	m_bvh->refitPartial(m_meshInterface, aabbMin, aabbMax);
+
 	m_localAabbMin.setMin(aabbMin);
 	m_localAabbMin.setMin(aabbMin);
 	m_localAabbMax.setMax(aabbMax);
 	m_localAabbMax.setMax(aabbMax);
 }
 }
 
 
-
-void	btBvhTriangleMeshShape::refitTree(const btVector3& aabbMin,const btVector3& aabbMax)
+void btBvhTriangleMeshShape::refitTree(const btVector3& aabbMin, const btVector3& aabbMax)
 {
 {
-	m_bvh->refit( m_meshInterface, aabbMin,aabbMax );
-	
+	m_bvh->refit(m_meshInterface, aabbMin, aabbMax);
+
 	recalcLocalAabb();
 	recalcLocalAabb();
 }
 }
 
 
@@ -90,27 +87,27 @@ btBvhTriangleMeshShape::~btBvhTriangleMeshShape()
 	}
 	}
 }
 }
 
 
-void	btBvhTriangleMeshShape::performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget)
+void btBvhTriangleMeshShape::performRaycast(btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget)
 {
 {
-	struct	MyNodeOverlapCallback : public btNodeOverlapCallback
+	struct MyNodeOverlapCallback : public btNodeOverlapCallback
 	{
 	{
-		btStridingMeshInterface*	m_meshInterface;
+		btStridingMeshInterface* m_meshInterface;
 		btTriangleCallback* m_callback;
 		btTriangleCallback* m_callback;
 
 
-		MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
-			:m_meshInterface(meshInterface),
-			m_callback(callback)
+		MyNodeOverlapCallback(btTriangleCallback* callback, btStridingMeshInterface* meshInterface)
+			: m_meshInterface(meshInterface),
+			  m_callback(callback)
 		{
 		{
 		}
 		}
-				
+
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		{
 		{
 			btVector3 m_triangle[3];
 			btVector3 m_triangle[3];
-			const unsigned char *vertexbase;
+			const unsigned char* vertexbase;
 			int numverts;
 			int numverts;
 			PHY_ScalarType type;
 			PHY_ScalarType type;
 			int stride;
 			int stride;
-			const unsigned char *indexbase;
+			const unsigned char* indexbase;
 			int indexstride;
 			int indexstride;
 			int numfaces;
 			int numfaces;
 			PHY_ScalarType indicestype;
 			PHY_ScalarType indicestype;
@@ -126,60 +123,65 @@ void	btBvhTriangleMeshShape::performRaycast (btTriangleCallback* callback, const
 				indicestype,
 				indicestype,
 				nodeSubPart);
 				nodeSubPart);
 
 
-			unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
-			btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
-	
+			unsigned int* gfxbase = (unsigned int*)(indexbase + nodeTriangleIndex * indexstride);
+
 			const btVector3& meshScaling = m_meshInterface->getScaling();
 			const btVector3& meshScaling = m_meshInterface->getScaling();
-			for (int j=2;j>=0;j--)
+			for (int j = 2; j >= 0; j--)
 			{
 			{
-				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
-				
+				int graphicsindex;
+                                switch (indicestype) {
+                                        case PHY_INTEGER: graphicsindex = gfxbase[j]; break;
+                                        case PHY_SHORT: graphicsindex = ((unsigned short*)gfxbase)[j]; break;
+                                        case PHY_UCHAR: graphicsindex = ((unsigned char*)gfxbase)[j]; break;
+                                        default: btAssert(0);
+                                }
+
 				if (type == PHY_FLOAT)
 				if (type == PHY_FLOAT)
 				{
 				{
-					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
-					
-					m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());		
+					float* graphicsbase = (float*)(vertexbase + graphicsindex * stride);
+
+					m_triangle[j] = btVector3(graphicsbase[0] * meshScaling.getX(), graphicsbase[1] * meshScaling.getY(), graphicsbase[2] * meshScaling.getZ());
 				}
 				}
 				else
 				else
 				{
 				{
-					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
-					
-					m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ());		
+					double* graphicsbase = (double*)(vertexbase + graphicsindex * stride);
+
+					m_triangle[j] = btVector3(btScalar(graphicsbase[0]) * meshScaling.getX(), btScalar(graphicsbase[1]) * meshScaling.getY(), btScalar(graphicsbase[2]) * meshScaling.getZ());
 				}
 				}
 			}
 			}
 
 
 			/* Perform ray vs. triangle collision here */
 			/* Perform ray vs. triangle collision here */
-			m_callback->processTriangle(m_triangle,nodeSubPart,nodeTriangleIndex);
+			m_callback->processTriangle(m_triangle, nodeSubPart, nodeTriangleIndex);
 			m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
 			m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
 		}
 		}
 	};
 	};
 
 
-	MyNodeOverlapCallback	myNodeCallback(callback,m_meshInterface);
+	MyNodeOverlapCallback myNodeCallback(callback, m_meshInterface);
 
 
-	m_bvh->reportRayOverlappingNodex(&myNodeCallback,raySource,rayTarget);
+	m_bvh->reportRayOverlappingNodex(&myNodeCallback, raySource, rayTarget);
 }
 }
 
 
-void	btBvhTriangleMeshShape::performConvexcast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax)
+void btBvhTriangleMeshShape::performConvexcast(btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax)
 {
 {
-	struct	MyNodeOverlapCallback : public btNodeOverlapCallback
+	struct MyNodeOverlapCallback : public btNodeOverlapCallback
 	{
 	{
-		btStridingMeshInterface*	m_meshInterface;
+		btStridingMeshInterface* m_meshInterface;
 		btTriangleCallback* m_callback;
 		btTriangleCallback* m_callback;
 
 
-		MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
-			:m_meshInterface(meshInterface),
-			m_callback(callback)
+		MyNodeOverlapCallback(btTriangleCallback* callback, btStridingMeshInterface* meshInterface)
+			: m_meshInterface(meshInterface),
+			  m_callback(callback)
 		{
 		{
 		}
 		}
-				
+
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		{
 		{
 			btVector3 m_triangle[3];
 			btVector3 m_triangle[3];
-			const unsigned char *vertexbase;
+			const unsigned char* vertexbase;
 			int numverts;
 			int numverts;
 			PHY_ScalarType type;
 			PHY_ScalarType type;
 			int stride;
 			int stride;
-			const unsigned char *indexbase;
+			const unsigned char* indexbase;
 			int indexstride;
 			int indexstride;
 			int numfaces;
 			int numfaces;
 			PHY_ScalarType indicestype;
 			PHY_ScalarType indicestype;
@@ -195,77 +197,79 @@ void	btBvhTriangleMeshShape::performConvexcast (btTriangleCallback* callback, co
 				indicestype,
 				indicestype,
 				nodeSubPart);
 				nodeSubPart);
 
 
-			unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
-			btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT);
-	
+			unsigned int* gfxbase = (unsigned int*)(indexbase + nodeTriangleIndex * indexstride);
+
 			const btVector3& meshScaling = m_meshInterface->getScaling();
 			const btVector3& meshScaling = m_meshInterface->getScaling();
-			for (int j=2;j>=0;j--)
+			for (int j = 2; j >= 0; j--)
 			{
 			{
-				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
+				int graphicsindex;
+                                switch (indicestype) {
+                                        case PHY_INTEGER: graphicsindex = gfxbase[j]; break;
+                                        case PHY_SHORT: graphicsindex = ((unsigned short*)gfxbase)[j]; break;
+                                        case PHY_UCHAR: graphicsindex = ((unsigned char*)gfxbase)[j]; break;
+                                        default: btAssert(0);
+                                }
 
 
 				if (type == PHY_FLOAT)
 				if (type == PHY_FLOAT)
 				{
 				{
-					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+					float* graphicsbase = (float*)(vertexbase + graphicsindex * stride);
 
 
-					m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());		
+					m_triangle[j] = btVector3(graphicsbase[0] * meshScaling.getX(), graphicsbase[1] * meshScaling.getY(), graphicsbase[2] * meshScaling.getZ());
 				}
 				}
 				else
 				else
 				{
 				{
-					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
-					
-					m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ());		
+					double* graphicsbase = (double*)(vertexbase + graphicsindex * stride);
+
+					m_triangle[j] = btVector3(btScalar(graphicsbase[0]) * meshScaling.getX(), btScalar(graphicsbase[1]) * meshScaling.getY(), btScalar(graphicsbase[2]) * meshScaling.getZ());
 				}
 				}
 			}
 			}
 
 
 			/* Perform ray vs. triangle collision here */
 			/* Perform ray vs. triangle collision here */
-			m_callback->processTriangle(m_triangle,nodeSubPart,nodeTriangleIndex);
+			m_callback->processTriangle(m_triangle, nodeSubPart, nodeTriangleIndex);
 			m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
 			m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
 		}
 		}
 	};
 	};
 
 
-	MyNodeOverlapCallback	myNodeCallback(callback,m_meshInterface);
+	MyNodeOverlapCallback myNodeCallback(callback, m_meshInterface);
 
 
-	m_bvh->reportBoxCastOverlappingNodex (&myNodeCallback, raySource, rayTarget, aabbMin, aabbMax);
+	m_bvh->reportBoxCastOverlappingNodex(&myNodeCallback, raySource, rayTarget, aabbMin, aabbMax);
 }
 }
 
 
 //perform bvh tree traversal and report overlapping triangles to 'callback'
 //perform bvh tree traversal and report overlapping triangles to 'callback'
-void	btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
+void btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback, const btVector3& aabbMin, const btVector3& aabbMax) const
 {
 {
-
 #ifdef DISABLE_BVH
 #ifdef DISABLE_BVH
 	//brute force traverse all triangles
 	//brute force traverse all triangles
-	btTriangleMeshShape::processAllTriangles(callback,aabbMin,aabbMax);
+	btTriangleMeshShape::processAllTriangles(callback, aabbMin, aabbMax);
 #else
 #else
 
 
 	//first get all the nodes
 	//first get all the nodes
 
 
-	
-	struct	MyNodeOverlapCallback : public btNodeOverlapCallback
+	struct MyNodeOverlapCallback : public btNodeOverlapCallback
 	{
 	{
-		btStridingMeshInterface*	m_meshInterface;
-		btTriangleCallback*		m_callback;
-		btVector3				m_triangle[3];
+		btStridingMeshInterface* m_meshInterface;
+		btTriangleCallback* m_callback;
+		btVector3 m_triangle[3];
 		int m_numOverlap;
 		int m_numOverlap;
 
 
-		MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
-			:m_meshInterface(meshInterface),
-			m_callback(callback),
-			m_numOverlap(0)
+		MyNodeOverlapCallback(btTriangleCallback* callback, btStridingMeshInterface* meshInterface)
+			: m_meshInterface(meshInterface),
+			  m_callback(callback),
+			  m_numOverlap(0)
 		{
 		{
 		}
 		}
-				
+
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		{
 		{
 			m_numOverlap++;
 			m_numOverlap++;
-			const unsigned char *vertexbase;
+			const unsigned char* vertexbase;
 			int numverts;
 			int numverts;
 			PHY_ScalarType type;
 			PHY_ScalarType type;
 			int stride;
 			int stride;
-			const unsigned char *indexbase;
+			const unsigned char* indexbase;
 			int indexstride;
 			int indexstride;
 			int numfaces;
 			int numfaces;
 			PHY_ScalarType indicestype;
 			PHY_ScalarType indicestype;
-			
 
 
 			m_meshInterface->getLockedReadOnlyVertexIndexBase(
 			m_meshInterface->getLockedReadOnlyVertexIndexBase(
 				&vertexbase,
 				&vertexbase,
@@ -278,67 +282,62 @@ void	btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
 				indicestype,
 				indicestype,
 				nodeSubPart);
 				nodeSubPart);
 
 
-			unsigned int* gfxbase = (unsigned int*)(indexbase+nodeTriangleIndex*indexstride);
-			btAssert(indicestype==PHY_INTEGER||indicestype==PHY_SHORT||indicestype==PHY_UCHAR);
-	
+			unsigned int* gfxbase = (unsigned int*)(indexbase + nodeTriangleIndex * indexstride);
+			btAssert(indicestype == PHY_INTEGER || indicestype == PHY_SHORT || indicestype == PHY_UCHAR);
+
 			const btVector3& meshScaling = m_meshInterface->getScaling();
 			const btVector3& meshScaling = m_meshInterface->getScaling();
-			for (int j=2;j>=0;j--)
+			for (int j = 2; j >= 0; j--)
 			{
 			{
-				
-				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:indicestype==PHY_INTEGER?gfxbase[j]:((unsigned char*)gfxbase)[j];
-
+				int graphicsindex = indicestype == PHY_SHORT ? ((unsigned short*)gfxbase)[j] : indicestype == PHY_INTEGER ? gfxbase[j] : ((unsigned char*)gfxbase)[j];
 
 
 #ifdef DEBUG_TRIANGLE_MESH
 #ifdef DEBUG_TRIANGLE_MESH
-				printf("%d ,",graphicsindex);
-#endif //DEBUG_TRIANGLE_MESH
+				printf("%d ,", graphicsindex);
+#endif  //DEBUG_TRIANGLE_MESH
 				if (type == PHY_FLOAT)
 				if (type == PHY_FLOAT)
 				{
 				{
-					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
-					
+					float* graphicsbase = (float*)(vertexbase + graphicsindex * stride);
+
 					m_triangle[j] = btVector3(
 					m_triangle[j] = btVector3(
-																		graphicsbase[0]*meshScaling.getX(),
-																		graphicsbase[1]*meshScaling.getY(),
-																		graphicsbase[2]*meshScaling.getZ());
+						graphicsbase[0] * meshScaling.getX(),
+						graphicsbase[1] * meshScaling.getY(),
+						graphicsbase[2] * meshScaling.getZ());
 				}
 				}
 				else
 				else
 				{
 				{
-					double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
+					double* graphicsbase = (double*)(vertexbase + graphicsindex * stride);
 
 
 					m_triangle[j] = btVector3(
 					m_triangle[j] = btVector3(
-						btScalar(graphicsbase[0])*meshScaling.getX(),
-						btScalar(graphicsbase[1])*meshScaling.getY(),
-						btScalar(graphicsbase[2])*meshScaling.getZ());
+						btScalar(graphicsbase[0]) * meshScaling.getX(),
+						btScalar(graphicsbase[1]) * meshScaling.getY(),
+						btScalar(graphicsbase[2]) * meshScaling.getZ());
 				}
 				}
 #ifdef DEBUG_TRIANGLE_MESH
 #ifdef DEBUG_TRIANGLE_MESH
-				printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
-#endif //DEBUG_TRIANGLE_MESH
+				printf("triangle vertices:%f,%f,%f\n", triangle[j].x(), triangle[j].y(), triangle[j].z());
+#endif  //DEBUG_TRIANGLE_MESH
 			}
 			}
 
 
-			m_callback->processTriangle(m_triangle,nodeSubPart,nodeTriangleIndex);
+			m_callback->processTriangle(m_triangle, nodeSubPart, nodeTriangleIndex);
 			m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
 			m_meshInterface->unLockReadOnlyVertexBase(nodeSubPart);
 		}
 		}
-
 	};
 	};
 
 
-	MyNodeOverlapCallback	myNodeCallback(callback,m_meshInterface);
-
-	m_bvh->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
-	
-#endif//DISABLE_BVH
+	MyNodeOverlapCallback myNodeCallback(callback, m_meshInterface);
 
 
+	m_bvh->reportAabbOverlappingNodex(&myNodeCallback, aabbMin, aabbMax);
 
 
+#endif  //DISABLE_BVH
 }
 }
 
 
-void   btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
+void btBvhTriangleMeshShape::setLocalScaling(const btVector3& scaling)
 {
 {
-   if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
-   {
-      btTriangleMeshShape::setLocalScaling(scaling);
-	  buildOptimizedBvh();
-   }
+	if ((getLocalScaling() - scaling).length2() > SIMD_EPSILON)
+	{
+		btTriangleMeshShape::setLocalScaling(scaling);
+		buildOptimizedBvh();
+	}
 }
 }
 
 
-void   btBvhTriangleMeshShape::buildOptimizedBvh()
+void btBvhTriangleMeshShape::buildOptimizedBvh()
 {
 {
 	if (m_ownsBvh)
 	if (m_ownsBvh)
 	{
 	{
@@ -346,43 +345,39 @@ void   btBvhTriangleMeshShape::buildOptimizedBvh()
 		btAlignedFree(m_bvh);
 		btAlignedFree(m_bvh);
 	}
 	}
 	///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
 	///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work
-	void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16);
-	m_bvh = new(mem) btOptimizedBvh();
+	void* mem = btAlignedAlloc(sizeof(btOptimizedBvh), 16);
+	m_bvh = new (mem) btOptimizedBvh();
 	//rebuild the bvh...
 	//rebuild the bvh...
-	m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax);
+	m_bvh->build(m_meshInterface, m_useQuantizedAabbCompression, m_localAabbMin, m_localAabbMax);
 	m_ownsBvh = true;
 	m_ownsBvh = true;
 }
 }
 
 
-void   btBvhTriangleMeshShape::setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& scaling)
+void btBvhTriangleMeshShape::setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& scaling)
 {
 {
-   btAssert(!m_bvh);
-   btAssert(!m_ownsBvh);
-
-   m_bvh = bvh;
-   m_ownsBvh = false;
-   // update the scaling without rebuilding the bvh
-   if ((getLocalScaling() -scaling).length2() > SIMD_EPSILON)
-   {
-      btTriangleMeshShape::setLocalScaling(scaling);
-   }
-}
-
+	btAssert(!m_bvh);
+	btAssert(!m_ownsBvh);
 
 
+	m_bvh = bvh;
+	m_ownsBvh = false;
+	// update the scaling without rebuilding the bvh
+	if ((getLocalScaling() - scaling).length2() > SIMD_EPSILON)
+	{
+		btTriangleMeshShape::setLocalScaling(scaling);
+	}
+}
 
 
 ///fills the dataBuffer and returns the struct name (and 0 on failure)
 ///fills the dataBuffer and returns the struct name (and 0 on failure)
-const char*	btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const
+const char* btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const
 {
 {
-	btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer;
+	btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*)dataBuffer;
 
 
-	btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer);
+	btCollisionShape::serialize(&trimeshData->m_collisionShapeData, serializer);
 
 
 	m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer);
 	m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer);
 
 
 	trimeshData->m_collisionMargin = float(m_collisionMargin);
 	trimeshData->m_collisionMargin = float(m_collisionMargin);
 
 
-	
-
-	if (m_bvh && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_BVH))
+	if (m_bvh && !(serializer->getSerializationFlags() & BT_SERIALIZE_NO_BVH))
 	{
 	{
 		void* chunk = serializer->findPointer(m_bvh);
 		void* chunk = serializer->findPointer(m_bvh);
 		if (chunk)
 		if (chunk)
@@ -391,77 +386,77 @@ const char*	btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* se
 			trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk;
 			trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk;
 			trimeshData->m_quantizedFloatBvh = 0;
 			trimeshData->m_quantizedFloatBvh = 0;
 #else
 #else
-			trimeshData->m_quantizedFloatBvh  = (btQuantizedBvhData*)chunk;
-			trimeshData->m_quantizedDoubleBvh= 0;
-#endif //BT_USE_DOUBLE_PRECISION
-		} else
+			trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)chunk;
+			trimeshData->m_quantizedDoubleBvh = 0;
+#endif  //BT_USE_DOUBLE_PRECISION
+		}
+		else
 		{
 		{
-
 #ifdef BT_USE_DOUBLE_PRECISION
 #ifdef BT_USE_DOUBLE_PRECISION
 			trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh);
 			trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh);
 			trimeshData->m_quantizedFloatBvh = 0;
 			trimeshData->m_quantizedFloatBvh = 0;
 #else
 #else
-			trimeshData->m_quantizedFloatBvh  = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh);
-			trimeshData->m_quantizedDoubleBvh= 0;
-#endif //BT_USE_DOUBLE_PRECISION
-	
+			trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh);
+			trimeshData->m_quantizedDoubleBvh = 0;
+#endif  //BT_USE_DOUBLE_PRECISION
+
 			int sz = m_bvh->calculateSerializeBufferSizeNew();
 			int sz = m_bvh->calculateSerializeBufferSizeNew();
-			btChunk* chunk = serializer->allocate(sz,1);
+			btChunk* chunk = serializer->allocate(sz, 1);
 			const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
 			const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
-			serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,m_bvh);
+			serializer->finalizeChunk(chunk, structType, BT_QUANTIZED_BVH_CODE, m_bvh);
 		}
 		}
-	} else
+	}
+	else
 	{
 	{
 		trimeshData->m_quantizedFloatBvh = 0;
 		trimeshData->m_quantizedFloatBvh = 0;
 		trimeshData->m_quantizedDoubleBvh = 0;
 		trimeshData->m_quantizedDoubleBvh = 0;
 	}
 	}
 
 
-	
-
-	if (m_triangleInfoMap && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_TRIANGLEINFOMAP))
+	if (m_triangleInfoMap && !(serializer->getSerializationFlags() & BT_SERIALIZE_NO_TRIANGLEINFOMAP))
 	{
 	{
 		void* chunk = serializer->findPointer(m_triangleInfoMap);
 		void* chunk = serializer->findPointer(m_triangleInfoMap);
 		if (chunk)
 		if (chunk)
 		{
 		{
 			trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)chunk;
 			trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)chunk;
-		} else
+		}
+		else
 		{
 		{
 			trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)serializer->getUniquePointer(m_triangleInfoMap);
 			trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)serializer->getUniquePointer(m_triangleInfoMap);
 			int sz = m_triangleInfoMap->calculateSerializeBufferSize();
 			int sz = m_triangleInfoMap->calculateSerializeBufferSize();
-			btChunk* chunk = serializer->allocate(sz,1);
+			btChunk* chunk = serializer->allocate(sz, 1);
 			const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer);
 			const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer);
-			serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,m_triangleInfoMap);
+			serializer->finalizeChunk(chunk, structType, BT_TRIANLGE_INFO_MAP, m_triangleInfoMap);
 		}
 		}
-	} else
+	}
+	else
 	{
 	{
 		trimeshData->m_triangleInfoMap = 0;
 		trimeshData->m_triangleInfoMap = 0;
 	}
 	}
 
 
+	// Fill padding with zeros to appease msan.
+	memset(trimeshData->m_pad3, 0, sizeof(trimeshData->m_pad3));
+
 	return "btTriangleMeshShapeData";
 	return "btTriangleMeshShapeData";
 }
 }
 
 
-void	btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const
+void btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const
 {
 {
 	if (m_bvh)
 	if (m_bvh)
 	{
 	{
-		int len = m_bvh->calculateSerializeBufferSizeNew(); //make sure not to use calculateSerializeBufferSize because it is used for in-place
-		btChunk* chunk = serializer->allocate(len,1);
+		int len = m_bvh->calculateSerializeBufferSizeNew();  //make sure not to use calculateSerializeBufferSize because it is used for in-place
+		btChunk* chunk = serializer->allocate(len, 1);
 		const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
 		const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer);
-		serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,(void*)m_bvh);
+		serializer->finalizeChunk(chunk, structType, BT_QUANTIZED_BVH_CODE, (void*)m_bvh);
 	}
 	}
 }
 }
 
 
-void	btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const
+void btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const
 {
 {
 	if (m_triangleInfoMap)
 	if (m_triangleInfoMap)
 	{
 	{
 		int len = m_triangleInfoMap->calculateSerializeBufferSize();
 		int len = m_triangleInfoMap->calculateSerializeBufferSize();
-		btChunk* chunk = serializer->allocate(len,1);
+		btChunk* chunk = serializer->allocate(len, 1);
 		const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer);
 		const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer);
-		serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,(void*)m_triangleInfoMap);
+		serializer->finalizeChunk(chunk, structType, BT_TRIANLGE_INFO_MAP, (void*)m_triangleInfoMap);
 	}
 	}
 }
 }
-
-
-
-

+ 38 - 43
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h

@@ -23,103 +23,99 @@ subject to the following restrictions:
 
 
 ///The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving objects.
 ///The btBvhTriangleMeshShape is a static-triangle mesh shape, it can only be used for fixed/non-moving objects.
 ///If you required moving concave triangle meshes, it is recommended to perform convex decomposition
 ///If you required moving concave triangle meshes, it is recommended to perform convex decomposition
-///using HACD, see Bullet/Demos/ConvexDecompositionDemo. 
+///using HACD, see Bullet/Demos/ConvexDecompositionDemo.
 ///Alternatively, you can use btGimpactMeshShape for moving concave triangle meshes.
 ///Alternatively, you can use btGimpactMeshShape for moving concave triangle meshes.
-///btBvhTriangleMeshShape has several optimizations, such as bounding volume hierarchy and 
-///cache friendly traversal for PlayStation 3 Cell SPU. 
+///btBvhTriangleMeshShape has several optimizations, such as bounding volume hierarchy and
+///cache friendly traversal for PlayStation 3 Cell SPU.
 ///It is recommended to enable useQuantizedAabbCompression for better memory usage.
 ///It is recommended to enable useQuantizedAabbCompression for better memory usage.
 ///It takes a triangle mesh as input, for example a btTriangleMesh or btTriangleIndexVertexArray. The btBvhTriangleMeshShape class allows for triangle mesh deformations by a refit or partialRefit method.
 ///It takes a triangle mesh as input, for example a btTriangleMesh or btTriangleIndexVertexArray. The btBvhTriangleMeshShape class allows for triangle mesh deformations by a refit or partialRefit method.
 ///Instead of building the bounding volume hierarchy acceleration structure, it is also possible to serialize (save) and deserialize (load) the structure from disk.
 ///Instead of building the bounding volume hierarchy acceleration structure, it is also possible to serialize (save) and deserialize (load) the structure from disk.
 ///See Demos\ConcaveDemo\ConcavePhysicsDemo.cpp for an example.
 ///See Demos\ConcaveDemo\ConcavePhysicsDemo.cpp for an example.
-ATTRIBUTE_ALIGNED16(class) btBvhTriangleMeshShape : public btTriangleMeshShape
+ATTRIBUTE_ALIGNED16(class)
+btBvhTriangleMeshShape : public btTriangleMeshShape
 {
 {
-
-	btOptimizedBvh*	m_bvh;
-	btTriangleInfoMap*	m_triangleInfoMap;
+	btOptimizedBvh* m_bvh;
+	btTriangleInfoMap* m_triangleInfoMap;
 
 
 	bool m_useQuantizedAabbCompression;
 	bool m_useQuantizedAabbCompression;
 	bool m_ownsBvh;
 	bool m_ownsBvh;
 #ifdef __clang__
 #ifdef __clang__
-	bool m_pad[11] __attribute__((unused));////need padding due to alignment
+	bool m_pad[11] __attribute__((unused));  ////need padding due to alignment
 #else
 #else
-	bool m_pad[11];////need padding due to alignment
+	bool m_pad[11];  ////need padding due to alignment
 #endif
 #endif
 
 
 public:
 public:
-
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
-	
-	btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
+	btBvhTriangleMeshShape(btStridingMeshInterface * meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true);
 
 
 	///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
 	///optionally pass in a larger bvh aabb, used for quantization. This allows for deformations within this aabb
-	btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression,const btVector3& bvhAabbMin,const btVector3& bvhAabbMax, bool buildBvh = true);
-	
+	btBvhTriangleMeshShape(btStridingMeshInterface * meshInterface, bool useQuantizedAabbCompression, const btVector3& bvhAabbMin, const btVector3& bvhAabbMax, bool buildBvh = true);
+
 	virtual ~btBvhTriangleMeshShape();
 	virtual ~btBvhTriangleMeshShape();
 
 
-	bool getOwnsBvh () const
+	bool getOwnsBvh() const
 	{
 	{
 		return m_ownsBvh;
 		return m_ownsBvh;
 	}
 	}
 
 
+	void performRaycast(btTriangleCallback * callback, const btVector3& raySource, const btVector3& rayTarget);
+	void performConvexcast(btTriangleCallback * callback, const btVector3& boxSource, const btVector3& boxTarget, const btVector3& boxMin, const btVector3& boxMax);
 
 
-	
-	void performRaycast (btTriangleCallback* callback, const btVector3& raySource, const btVector3& rayTarget);
-	void performConvexcast (btTriangleCallback* callback, const btVector3& boxSource, const btVector3& boxTarget, const btVector3& boxMin, const btVector3& boxMax);
-
-	virtual void	processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
+	virtual void processAllTriangles(btTriangleCallback * callback, const btVector3& aabbMin, const btVector3& aabbMax) const;
 
 
-	void	refitTree(const btVector3& aabbMin,const btVector3& aabbMax);
+	void refitTree(const btVector3& aabbMin, const btVector3& aabbMax);
 
 
 	///for a fast incremental refit of parts of the tree. Note: the entire AABB of the tree will become more conservative, it never shrinks
 	///for a fast incremental refit of parts of the tree. Note: the entire AABB of the tree will become more conservative, it never shrinks
-	void	partialRefitTree(const btVector3& aabbMin,const btVector3& aabbMax);
+	void partialRefitTree(const btVector3& aabbMin, const btVector3& aabbMax);
 
 
 	//debugging
 	//debugging
-	virtual const char*	getName()const {return "BVHTRIANGLEMESH";}
+	virtual const char* getName() const { return "BVHTRIANGLEMESH"; }
 
 
+	virtual void setLocalScaling(const btVector3& scaling);
 
 
-	virtual void	setLocalScaling(const btVector3& scaling);
-	
-	btOptimizedBvh*	getOptimizedBvh()
+	btOptimizedBvh* getOptimizedBvh()
 	{
 	{
 		return m_bvh;
 		return m_bvh;
 	}
 	}
 
 
-	void	setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));
+	void setOptimizedBvh(btOptimizedBvh * bvh, const btVector3& localScaling = btVector3(1, 1, 1));
 
 
-	void    buildOptimizedBvh();
+	void buildOptimizedBvh();
 
 
-	bool	usesQuantizedAabbCompression() const
+	bool usesQuantizedAabbCompression() const
 	{
 	{
-		return	m_useQuantizedAabbCompression;
+		return m_useQuantizedAabbCompression;
 	}
 	}
 
 
-	void	setTriangleInfoMap(btTriangleInfoMap* triangleInfoMap)
+	void setTriangleInfoMap(btTriangleInfoMap * triangleInfoMap)
 	{
 	{
 		m_triangleInfoMap = triangleInfoMap;
 		m_triangleInfoMap = triangleInfoMap;
 	}
 	}
 
 
-	const btTriangleInfoMap*	getTriangleInfoMap() const
+	const btTriangleInfoMap* getTriangleInfoMap() const
 	{
 	{
 		return m_triangleInfoMap;
 		return m_triangleInfoMap;
 	}
 	}
-	
-	btTriangleInfoMap*	getTriangleInfoMap()
+
+	btTriangleInfoMap* getTriangleInfoMap()
 	{
 	{
 		return m_triangleInfoMap;
 		return m_triangleInfoMap;
 	}
 	}
 
 
-	virtual	int	calculateSerializeBufferSize() const;
+	virtual int calculateSerializeBufferSize() const;
 
 
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
-	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
-
-	virtual void	serializeSingleBvh(btSerializer* serializer) const;
+	virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
 
 
-	virtual void	serializeSingleTriangleInfoMap(btSerializer* serializer) const;
+	virtual void serializeSingleBvh(btSerializer * serializer) const;
 
 
+	virtual void serializeSingleTriangleInfoMap(btSerializer * serializer) const;
 };
 };
 
 
+// clang-format off
+
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 struct	btTriangleMeshShapeData
 struct	btTriangleMeshShapeData
 {
 {
@@ -138,12 +134,11 @@ struct	btTriangleMeshShapeData
 	
 	
 };
 };
 
 
+// clang-format on
 
 
-SIMD_FORCE_INLINE	int	btBvhTriangleMeshShape::calculateSerializeBufferSize() const
+SIMD_FORCE_INLINE int btBvhTriangleMeshShape::calculateSerializeBufferSize() const
 {
 {
 	return sizeof(btTriangleMeshShapeData);
 	return sizeof(btTriangleMeshShapeData);
 }
 }
 
 
-
-
-#endif //BT_BVH_TRIANGLE_MESH_SHAPE_H
+#endif  //BT_BVH_TRIANGLE_MESH_SHAPE_H

+ 30 - 51
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCapsuleShape.cpp

@@ -13,24 +13,21 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "btCapsuleShape.h"
 #include "btCapsuleShape.h"
 
 
 #include "LinearMath/btQuaternion.h"
 #include "LinearMath/btQuaternion.h"
 
 
-btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape ()
+btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInternalShape()
 {
 {
 	m_collisionMargin = radius;
 	m_collisionMargin = radius;
 	m_shapeType = CAPSULE_SHAPE_PROXYTYPE;
 	m_shapeType = CAPSULE_SHAPE_PROXYTYPE;
 	m_upAxis = 1;
 	m_upAxis = 1;
-	m_implicitShapeDimensions.setValue(radius,0.5f*height,radius);
+	m_implicitShapeDimensions.setValue(radius, 0.5f * height, radius);
 }
 }
 
 
- 
- btVector3	btCapsuleShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
+btVector3 btCapsuleShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0) const
 {
 {
-
-	btVector3 supVec(0,0,0);
+	btVector3 supVec(0, 0, 0);
 
 
 	btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
 	btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
 
 
@@ -38,20 +35,19 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter
 	btScalar lenSqr = vec.length2();
 	btScalar lenSqr = vec.length2();
 	if (lenSqr < btScalar(0.0001))
 	if (lenSqr < btScalar(0.0001))
 	{
 	{
-		vec.setValue(1,0,0);
-	} else
+		vec.setValue(1, 0, 0);
+	}
+	else
 	{
 	{
-		btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
+		btScalar rlen = btScalar(1.) / btSqrt(lenSqr);
 		vec *= rlen;
 		vec *= rlen;
 	}
 	}
 
 
 	btVector3 vtx;
 	btVector3 vtx;
 	btScalar newDot;
 	btScalar newDot;
-	
-	
 
 
 	{
 	{
-		btVector3 pos(0,0,0);
+		btVector3 pos(0, 0, 0);
 		pos[getUpAxis()] = getHalfHeight();
 		pos[getUpAxis()] = getHalfHeight();
 
 
 		vtx = pos;
 		vtx = pos;
@@ -63,7 +59,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter
 		}
 		}
 	}
 	}
 	{
 	{
-		btVector3 pos(0,0,0);
+		btVector3 pos(0, 0, 0);
 		pos[getUpAxis()] = -getHalfHeight();
 		pos[getUpAxis()] = -getHalfHeight();
 
 
 		vtx = pos;
 		vtx = pos;
@@ -76,15 +72,11 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter
 	}
 	}
 
 
 	return supVec;
 	return supVec;
-
 }
 }
 
 
- void	btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+void btCapsuleShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
 {
 {
-
-	
-	
-	for (int j=0;j<numVectors;j++)
+	for (int j = 0; j < numVectors; j++)
 	{
 	{
 		btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
 		btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
 		const btVector3& vec = vectors[j];
 		const btVector3& vec = vectors[j];
@@ -92,7 +84,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter
 		btVector3 vtx;
 		btVector3 vtx;
 		btScalar newDot;
 		btScalar newDot;
 		{
 		{
-			btVector3 pos(0,0,0);
+			btVector3 pos(0, 0, 0);
 			pos[getUpAxis()] = getHalfHeight();
 			pos[getUpAxis()] = getHalfHeight();
 			vtx = pos;
 			vtx = pos;
 			newDot = vec.dot(vtx);
 			newDot = vec.dot(vtx);
@@ -103,7 +95,7 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter
 			}
 			}
 		}
 		}
 		{
 		{
-			btVector3 pos(0,0,0);
+			btVector3 pos(0, 0, 0);
 			pos[getUpAxis()] = -getHalfHeight();
 			pos[getUpAxis()] = -getHalfHeight();
 			vtx = pos;
 			vtx = pos;
 			newDot = vec.dot(vtx);
 			newDot = vec.dot(vtx);
@@ -113,57 +105,44 @@ btCapsuleShape::btCapsuleShape(btScalar radius, btScalar height) : btConvexInter
 				supportVerticesOut[j] = vtx;
 				supportVerticesOut[j] = vtx;
 			}
 			}
 		}
 		}
-		
 	}
 	}
 }
 }
 
 
-
-void	btCapsuleShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
+void btCapsuleShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
 {
 {
 	//as an approximation, take the inertia of the box that bounds the spheres
 	//as an approximation, take the inertia of the box that bounds the spheres
 
 
 	btTransform ident;
 	btTransform ident;
 	ident.setIdentity();
 	ident.setIdentity();
 
 
-	
 	btScalar radius = getRadius();
 	btScalar radius = getRadius();
 
 
-	btVector3 halfExtents(radius,radius,radius);
-	halfExtents[getUpAxis()]+=getHalfHeight();
+	btVector3 halfExtents(radius, radius, radius);
+	halfExtents[getUpAxis()] += getHalfHeight();
 
 
-	btScalar lx=btScalar(2.)*(halfExtents[0]);
-	btScalar ly=btScalar(2.)*(halfExtents[1]);
-	btScalar lz=btScalar(2.)*(halfExtents[2]);
-	const btScalar x2 = lx*lx;
-	const btScalar y2 = ly*ly;
-	const btScalar z2 = lz*lz;
+	btScalar lx = btScalar(2.) * (halfExtents[0]);
+	btScalar ly = btScalar(2.) * (halfExtents[1]);
+	btScalar lz = btScalar(2.) * (halfExtents[2]);
+	const btScalar x2 = lx * lx;
+	const btScalar y2 = ly * ly;
+	const btScalar z2 = lz * lz;
 	const btScalar scaledmass = mass * btScalar(.08333333);
 	const btScalar scaledmass = mass * btScalar(.08333333);
 
 
-	inertia[0] = scaledmass * (y2+z2);
-	inertia[1] = scaledmass * (x2+z2);
-	inertia[2] = scaledmass * (x2+y2);
-
+	inertia[0] = scaledmass * (y2 + z2);
+	inertia[1] = scaledmass * (x2 + z2);
+	inertia[2] = scaledmass * (x2 + y2);
 }
 }
 
 
-btCapsuleShapeX::btCapsuleShapeX(btScalar radius,btScalar height)
+btCapsuleShapeX::btCapsuleShapeX(btScalar radius, btScalar height)
 {
 {
 	m_collisionMargin = radius;
 	m_collisionMargin = radius;
 	m_upAxis = 0;
 	m_upAxis = 0;
-	m_implicitShapeDimensions.setValue(0.5f*height, radius,radius);
+	m_implicitShapeDimensions.setValue(0.5f * height, radius, radius);
 }
 }
 
 
-
-
-
-
-
-btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius,btScalar height)
+btCapsuleShapeZ::btCapsuleShapeZ(btScalar radius, btScalar height)
 {
 {
 	m_collisionMargin = radius;
 	m_collisionMargin = radius;
 	m_upAxis = 2;
 	m_upAxis = 2;
-	m_implicitShapeDimensions.setValue(radius,radius,0.5f*height);
+	m_implicitShapeDimensions.setValue(radius, radius, 0.5f * height);
 }
 }
-
-
-
-

+ 59 - 61
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCapsuleShape.h

@@ -17,98 +17,96 @@ subject to the following restrictions:
 #define BT_CAPSULE_SHAPE_H
 #define BT_CAPSULE_SHAPE_H
 
 
 #include "btConvexInternalShape.h"
 #include "btConvexInternalShape.h"
-#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
-
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"  // for the types
 
 
 ///The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned around the X axis and btCapsuleShapeZ around the Z axis.
 ///The btCapsuleShape represents a capsule around the Y axis, there is also the btCapsuleShapeX aligned around the X axis and btCapsuleShapeZ around the Z axis.
 ///The total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
 ///The total height is height+2*radius, so the height is just the height between the center of each 'sphere' of the capsule caps.
 ///The btCapsuleShape is a convex hull of two spheres. The btMultiSphereShape is a more general collision shape that takes the convex hull of multiple sphere, so it can also represent a capsule when just using two spheres.
 ///The btCapsuleShape is a convex hull of two spheres. The btMultiSphereShape is a more general collision shape that takes the convex hull of multiple sphere, so it can also represent a capsule when just using two spheres.
-ATTRIBUTE_ALIGNED16(class) btCapsuleShape : public btConvexInternalShape
+ATTRIBUTE_ALIGNED16(class)
+btCapsuleShape : public btConvexInternalShape
 {
 {
 protected:
 protected:
-	int	m_upAxis;
+	int m_upAxis;
 
 
 protected:
 protected:
 	///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
 	///only used for btCapsuleShapeZ and btCapsuleShapeX subclasses.
-	btCapsuleShape() : btConvexInternalShape() {m_shapeType = CAPSULE_SHAPE_PROXYTYPE;};
+	btCapsuleShape() : btConvexInternalShape() { m_shapeType = CAPSULE_SHAPE_PROXYTYPE; };
 
 
 public:
 public:
-	
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
-	
-	btCapsuleShape(btScalar radius,btScalar height);
+
+	btCapsuleShape(btScalar radius, btScalar height);
 
 
 	///CollisionShape Interface
 	///CollisionShape Interface
-	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
+	virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
 
 
 	/// btConvexShape Interface
 	/// btConvexShape Interface
-	virtual btVector3	localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
+	virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec) const;
+
+	virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const;
 
 
-	virtual void	batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
-	
 	virtual void setMargin(btScalar collisionMargin)
 	virtual void setMargin(btScalar collisionMargin)
 	{
 	{
 		//don't override the margin for capsules, their entire radius == margin
 		//don't override the margin for capsules, their entire radius == margin
+		(void)collisionMargin;
 	}
 	}
 
 
-	virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
+	virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
 	{
 	{
-			btVector3 halfExtents(getRadius(),getRadius(),getRadius());
-			halfExtents[m_upAxis] = getRadius() + getHalfHeight();
-			btMatrix3x3 abs_b = t.getBasis().absolute();  
-			btVector3 center = t.getOrigin();
-            btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
-        
-			aabbMin = center - extent;
-			aabbMax = center + extent;
+		btVector3 halfExtents(getRadius(), getRadius(), getRadius());
+		halfExtents[m_upAxis] = getRadius() + getHalfHeight();
+		btMatrix3x3 abs_b = t.getBasis().absolute();
+		btVector3 center = t.getOrigin();
+		btVector3 extent = halfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
+
+		aabbMin = center - extent;
+		aabbMax = center + extent;
 	}
 	}
 
 
-	virtual const char*	getName()const 
+	virtual const char* getName() const
 	{
 	{
 		return "CapsuleShape";
 		return "CapsuleShape";
 	}
 	}
 
 
-	int	getUpAxis() const
+	int getUpAxis() const
 	{
 	{
 		return m_upAxis;
 		return m_upAxis;
 	}
 	}
 
 
-	btScalar	getRadius() const
+	btScalar getRadius() const
 	{
 	{
-		int radiusAxis = (m_upAxis+2)%3;
+		int radiusAxis = (m_upAxis + 2) % 3;
 		return m_implicitShapeDimensions[radiusAxis];
 		return m_implicitShapeDimensions[radiusAxis];
 	}
 	}
 
 
-	btScalar	getHalfHeight() const
+	btScalar getHalfHeight() const
 	{
 	{
 		return m_implicitShapeDimensions[m_upAxis];
 		return m_implicitShapeDimensions[m_upAxis];
 	}
 	}
 
 
-	virtual void	setLocalScaling(const btVector3& scaling)
+	virtual void setLocalScaling(const btVector3& scaling)
 	{
 	{
 		btVector3 unScaledImplicitShapeDimensions = m_implicitShapeDimensions / m_localScaling;
 		btVector3 unScaledImplicitShapeDimensions = m_implicitShapeDimensions / m_localScaling;
-                btConvexInternalShape::setLocalScaling(scaling);
+		btConvexInternalShape::setLocalScaling(scaling);
 		m_implicitShapeDimensions = (unScaledImplicitShapeDimensions * scaling);
 		m_implicitShapeDimensions = (unScaledImplicitShapeDimensions * scaling);
 		//update m_collisionMargin, since entire radius==margin
 		//update m_collisionMargin, since entire radius==margin
-		int radiusAxis = (m_upAxis+2)%3;
+		int radiusAxis = (m_upAxis + 2) % 3;
 		m_collisionMargin = m_implicitShapeDimensions[radiusAxis];
 		m_collisionMargin = m_implicitShapeDimensions[radiusAxis];
 	}
 	}
 
 
-	virtual btVector3	getAnisotropicRollingFrictionDirection() const
+	virtual btVector3 getAnisotropicRollingFrictionDirection() const
 	{
 	{
-		btVector3 aniDir(0,0,0);
-		aniDir[getUpAxis()]=1;
+		btVector3 aniDir(0, 0, 0);
+		aniDir[getUpAxis()] = 1;
 		return aniDir;
 		return aniDir;
 	}
 	}
 
 
-
-	virtual	int	calculateSerializeBufferSize() const;
+	virtual int calculateSerializeBufferSize() const;
 
 
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
-	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
-
-	SIMD_FORCE_INLINE	void	deSerializeFloat(struct btCapsuleShapeData* dataBuffer);
+	virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
 
 
+	SIMD_FORCE_INLINE void deSerializeFloat(struct btCapsuleShapeData * dataBuffer);
 };
 };
 
 
 ///btCapsuleShapeX represents a capsule around the Z axis
 ///btCapsuleShapeX represents a capsule around the Z axis
@@ -116,17 +114,13 @@ public:
 class btCapsuleShapeX : public btCapsuleShape
 class btCapsuleShapeX : public btCapsuleShape
 {
 {
 public:
 public:
+	btCapsuleShapeX(btScalar radius, btScalar height);
 
 
-	btCapsuleShapeX(btScalar radius,btScalar height);
-		
 	//debugging
 	//debugging
-	virtual const char*	getName()const
+	virtual const char* getName() const
 	{
 	{
 		return "CapsuleX";
 		return "CapsuleX";
 	}
 	}
-
-	
-
 };
 };
 
 
 ///btCapsuleShapeZ represents a capsule around the Z axis
 ///btCapsuleShapeZ represents a capsule around the Z axis
@@ -134,45 +128,49 @@ public:
 class btCapsuleShapeZ : public btCapsuleShape
 class btCapsuleShapeZ : public btCapsuleShape
 {
 {
 public:
 public:
-	btCapsuleShapeZ(btScalar radius,btScalar height);
+	btCapsuleShapeZ(btScalar radius, btScalar height);
 
 
-		//debugging
-	virtual const char*	getName()const
+	//debugging
+	virtual const char* getName() const
 	{
 	{
 		return "CapsuleZ";
 		return "CapsuleZ";
 	}
 	}
-
-	
 };
 };
 
 
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
-struct	btCapsuleShapeData
+struct btCapsuleShapeData
 {
 {
-	btConvexInternalShapeData	m_convexInternalShapeData;
+	btConvexInternalShapeData m_convexInternalShapeData;
 
 
-	int	m_upAxis;
+	int m_upAxis;
 
 
-	char	m_padding[4];
+	char m_padding[4];
 };
 };
 
 
-SIMD_FORCE_INLINE	int	btCapsuleShape::calculateSerializeBufferSize() const
+SIMD_FORCE_INLINE int btCapsuleShape::calculateSerializeBufferSize() const
 {
 {
 	return sizeof(btCapsuleShapeData);
 	return sizeof(btCapsuleShapeData);
 }
 }
 
 
-	///fills the dataBuffer and returns the struct name (and 0 on failure)
-SIMD_FORCE_INLINE	const char*	btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const
+///fills the dataBuffer and returns the struct name (and 0 on failure)
+SIMD_FORCE_INLINE const char* btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const
 {
 {
-	btCapsuleShapeData* shapeData = (btCapsuleShapeData*) dataBuffer;
-	
-	btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer);
+	btCapsuleShapeData* shapeData = (btCapsuleShapeData*)dataBuffer;
+
+	btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
 
 
 	shapeData->m_upAxis = m_upAxis;
 	shapeData->m_upAxis = m_upAxis;
-	
+
+	// Fill padding with zeros to appease msan.
+	shapeData->m_padding[0] = 0;
+	shapeData->m_padding[1] = 0;
+	shapeData->m_padding[2] = 0;
+	shapeData->m_padding[3] = 0;
+
 	return "btCapsuleShapeData";
 	return "btCapsuleShapeData";
 }
 }
 
 
-SIMD_FORCE_INLINE	void	btCapsuleShape::deSerializeFloat(btCapsuleShapeData* dataBuffer)
+SIMD_FORCE_INLINE void btCapsuleShape::deSerializeFloat(btCapsuleShapeData* dataBuffer)
 {
 {
 	m_implicitShapeDimensions.deSerializeFloat(dataBuffer->m_convexInternalShapeData.m_implicitShapeDimensions);
 	m_implicitShapeDimensions.deSerializeFloat(dataBuffer->m_convexInternalShapeData.m_implicitShapeDimensions);
 	m_collisionMargin = dataBuffer->m_convexInternalShapeData.m_collisionMargin;
 	m_collisionMargin = dataBuffer->m_convexInternalShapeData.m_collisionMargin;
@@ -181,4 +179,4 @@ SIMD_FORCE_INLINE	void	btCapsuleShape::deSerializeFloat(btCapsuleShapeData* data
 	m_upAxis = dataBuffer->m_upAxis;
 	m_upAxis = dataBuffer->m_upAxis;
 }
 }
 
 
-#endif //BT_CAPSULE_SHAPE_H
+#endif  //BT_CAPSULE_SHAPE_H

+ 2 - 5
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCollisionMargin.h

@@ -19,9 +19,6 @@ subject to the following restrictions:
 ///The CONVEX_DISTANCE_MARGIN is a default collision margin for convex collision shapes derived from btConvexInternalShape.
 ///The CONVEX_DISTANCE_MARGIN is a default collision margin for convex collision shapes derived from btConvexInternalShape.
 ///This collision margin is used by Gjk and some other algorithms
 ///This collision margin is used by Gjk and some other algorithms
 ///Note that when creating small objects, you need to make sure to set a smaller collision margin, using the 'setMargin' API
 ///Note that when creating small objects, you need to make sure to set a smaller collision margin, using the 'setMargin' API
-#define CONVEX_DISTANCE_MARGIN btScalar(0.04)// btScalar(0.1)//;//btScalar(0.01)
-
-
-
-#endif //BT_COLLISION_MARGIN_H
+#define CONVEX_DISTANCE_MARGIN btScalar(0.04)  // btScalar(0.1)//;//btScalar(0.01)
 
 
+#endif  //BT_COLLISION_MARGIN_H

+ 31 - 31
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCollisionShape.cpp

@@ -20,47 +20,44 @@ subject to the following restrictions:
   can be used by probes that are checking whether the
   can be used by probes that are checking whether the
   library is actually installed.
   library is actually installed.
 */
 */
-extern "C" 
+extern "C"
 {
 {
-void btBulletCollisionProbe ();
+	void btBulletCollisionProbe();
 
 
-void btBulletCollisionProbe () {}
+	void btBulletCollisionProbe() {}
 }
 }
 
 
-
-
-void	btCollisionShape::getBoundingSphere(btVector3& center,btScalar& radius) const
+void btCollisionShape::getBoundingSphere(btVector3& center, btScalar& radius) const
 {
 {
 	btTransform tr;
 	btTransform tr;
 	tr.setIdentity();
 	tr.setIdentity();
-	btVector3 aabbMin,aabbMax;
+	btVector3 aabbMin, aabbMax;
 
 
-	getAabb(tr,aabbMin,aabbMax);
+	getAabb(tr, aabbMin, aabbMax);
 
 
-	radius = (aabbMax-aabbMin).length()*btScalar(0.5);
-	center = (aabbMin+aabbMax)*btScalar(0.5);
+	radius = (aabbMax - aabbMin).length() * btScalar(0.5);
+	center = (aabbMin + aabbMax) * btScalar(0.5);
 }
 }
 
 
-
-btScalar	btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const
+btScalar btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const
 {
 {
 	return getAngularMotionDisc() * defaultContactThreshold;
 	return getAngularMotionDisc() * defaultContactThreshold;
 }
 }
 
 
-btScalar	btCollisionShape::getAngularMotionDisc() const
+btScalar btCollisionShape::getAngularMotionDisc() const
 {
 {
 	///@todo cache this value, to improve performance
 	///@todo cache this value, to improve performance
-	btVector3	center;
+	btVector3 center;
 	btScalar disc;
 	btScalar disc;
-	getBoundingSphere(center,disc);
+	getBoundingSphere(center, disc);
 	disc += (center).length();
 	disc += (center).length();
 	return disc;
 	return disc;
 }
 }
 
 
-void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const
+void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans, const btVector3& linvel, const btVector3& angvel, btScalar timeStep, btVector3& temporalAabbMin, btVector3& temporalAabbMax) const
 {
 {
 	//start with static aabb
 	//start with static aabb
-	getAabb(curTrans,temporalAabbMin,temporalAabbMax);
+	getAabb(curTrans, temporalAabbMin, temporalAabbMax);
 
 
 	btScalar temporalAabbMaxx = temporalAabbMax.getX();
 	btScalar temporalAabbMaxx = temporalAabbMax.getX();
 	btScalar temporalAabbMaxy = temporalAabbMax.getY();
 	btScalar temporalAabbMaxy = temporalAabbMax.getY();
@@ -70,50 +67,53 @@ void btCollisionShape::calculateTemporalAabb(const btTransform& curTrans,const b
 	btScalar temporalAabbMinz = temporalAabbMin.getZ();
 	btScalar temporalAabbMinz = temporalAabbMin.getZ();
 
 
 	// add linear motion
 	// add linear motion
-	btVector3 linMotion = linvel*timeStep;
+	btVector3 linMotion = linvel * timeStep;
 	///@todo: simd would have a vector max/min operation, instead of per-element access
 	///@todo: simd would have a vector max/min operation, instead of per-element access
 	if (linMotion.x() > btScalar(0.))
 	if (linMotion.x() > btScalar(0.))
-		temporalAabbMaxx += linMotion.x(); 
+		temporalAabbMaxx += linMotion.x();
 	else
 	else
 		temporalAabbMinx += linMotion.x();
 		temporalAabbMinx += linMotion.x();
 	if (linMotion.y() > btScalar(0.))
 	if (linMotion.y() > btScalar(0.))
-		temporalAabbMaxy += linMotion.y(); 
+		temporalAabbMaxy += linMotion.y();
 	else
 	else
 		temporalAabbMiny += linMotion.y();
 		temporalAabbMiny += linMotion.y();
 	if (linMotion.z() > btScalar(0.))
 	if (linMotion.z() > btScalar(0.))
-		temporalAabbMaxz += linMotion.z(); 
+		temporalAabbMaxz += linMotion.z();
 	else
 	else
 		temporalAabbMinz += linMotion.z();
 		temporalAabbMinz += linMotion.z();
 
 
 	//add conservative angular motion
 	//add conservative angular motion
 	btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
 	btScalar angularMotion = angvel.length() * getAngularMotionDisc() * timeStep;
-	btVector3 angularMotion3d(angularMotion,angularMotion,angularMotion);
-	temporalAabbMin = btVector3(temporalAabbMinx,temporalAabbMiny,temporalAabbMinz);
-	temporalAabbMax = btVector3(temporalAabbMaxx,temporalAabbMaxy,temporalAabbMaxz);
+	btVector3 angularMotion3d(angularMotion, angularMotion, angularMotion);
+	temporalAabbMin = btVector3(temporalAabbMinx, temporalAabbMiny, temporalAabbMinz);
+	temporalAabbMax = btVector3(temporalAabbMaxx, temporalAabbMaxy, temporalAabbMaxz);
 
 
 	temporalAabbMin -= angularMotion3d;
 	temporalAabbMin -= angularMotion3d;
 	temporalAabbMax += angularMotion3d;
 	temporalAabbMax += angularMotion3d;
 }
 }
 
 
 ///fills the dataBuffer and returns the struct name (and 0 on failure)
 ///fills the dataBuffer and returns the struct name (and 0 on failure)
-const char*	btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const
+const char* btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const
 {
 {
-	btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer;
-	char* name = (char*) serializer->findNameForPointer(this);
+	btCollisionShapeData* shapeData = (btCollisionShapeData*)dataBuffer;
+	char* name = (char*)serializer->findNameForPointer(this);
 	shapeData->m_name = (char*)serializer->getUniquePointer(name);
 	shapeData->m_name = (char*)serializer->getUniquePointer(name);
 	if (shapeData->m_name)
 	if (shapeData->m_name)
 	{
 	{
 		serializer->serializeName(name);
 		serializer->serializeName(name);
 	}
 	}
 	shapeData->m_shapeType = m_shapeType;
 	shapeData->m_shapeType = m_shapeType;
-	//shapeData->m_padding//??
+
+	// Fill padding with zeros to appease msan.
+	memset(shapeData->m_padding, 0, sizeof(shapeData->m_padding));
+
 	return "btCollisionShapeData";
 	return "btCollisionShapeData";
 }
 }
 
 
-void	btCollisionShape::serializeSingleShape(btSerializer* serializer) const
+void btCollisionShape::serializeSingleShape(btSerializer* serializer) const
 {
 {
 	int len = calculateSerializeBufferSize();
 	int len = calculateSerializeBufferSize();
-	btChunk* chunk = serializer->allocate(len,1);
+	btChunk* chunk = serializer->allocate(len, 1);
 	const char* structType = serialize(chunk->m_oldPtr, serializer);
 	const char* structType = serialize(chunk->m_oldPtr, serializer);
-	serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this);
+	serializer->finalizeChunk(chunk, structType, BT_SHAPE_CODE, (void*)this);
 }
 }

+ 51 - 47
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCollisionShape.h

@@ -19,23 +19,23 @@ subject to the following restrictions:
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btMatrix3x3.h"
 #include "LinearMath/btMatrix3x3.h"
-#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"  //for the shape types
 class btSerializer;
 class btSerializer;
 
 
-
 ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
 ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects.
-ATTRIBUTE_ALIGNED16(class) btCollisionShape
+ATTRIBUTE_ALIGNED16(class)
+btCollisionShape
 {
 {
 protected:
 protected:
 	int m_shapeType;
 	int m_shapeType;
 	void* m_userPointer;
 	void* m_userPointer;
 	int m_userIndex;
 	int m_userIndex;
+	int m_userIndex2;
 
 
 public:
 public:
-
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
-	btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1)
+	btCollisionShape() : m_shapeType(INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1), m_userIndex2(-1)
 	{
 	{
 	}
 	}
 
 
@@ -44,50 +44,47 @@ public:
 	}
 	}
 
 
 	///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
 	///getAabb returns the axis aligned bounding box in the coordinate frame of the given transform t.
-	virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const =0;
+	virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const = 0;
 
 
-	virtual void	getBoundingSphere(btVector3& center,btScalar& radius) const;
+	virtual void getBoundingSphere(btVector3 & center, btScalar & radius) const;
 
 
 	///getAngularMotionDisc returns the maximum radius needed for Conservative Advancement to handle time-of-impact with rotations.
 	///getAngularMotionDisc returns the maximum radius needed for Conservative Advancement to handle time-of-impact with rotations.
-	virtual btScalar	getAngularMotionDisc() const;
-
-	virtual btScalar	getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
+	virtual btScalar getAngularMotionDisc() const;
 
 
+	virtual btScalar getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
 
 
 	///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
 	///calculateTemporalAabb calculates the enclosing aabb for the moving object over interval [0..timeStep)
 	///result is conservative
 	///result is conservative
-	void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const;
-
-
+	void calculateTemporalAabb(const btTransform& curTrans, const btVector3& linvel, const btVector3& angvel, btScalar timeStep, btVector3& temporalAabbMin, btVector3& temporalAabbMax) const;
 
 
-	SIMD_FORCE_INLINE bool	isPolyhedral() const
+	SIMD_FORCE_INLINE bool isPolyhedral() const
 	{
 	{
 		return btBroadphaseProxy::isPolyhedral(getShapeType());
 		return btBroadphaseProxy::isPolyhedral(getShapeType());
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool	isConvex2d() const
+	SIMD_FORCE_INLINE bool isConvex2d() const
 	{
 	{
 		return btBroadphaseProxy::isConvex2d(getShapeType());
 		return btBroadphaseProxy::isConvex2d(getShapeType());
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool	isConvex() const
+	SIMD_FORCE_INLINE bool isConvex() const
 	{
 	{
 		return btBroadphaseProxy::isConvex(getShapeType());
 		return btBroadphaseProxy::isConvex(getShapeType());
 	}
 	}
-	SIMD_FORCE_INLINE bool	isNonMoving() const
+	SIMD_FORCE_INLINE bool isNonMoving() const
 	{
 	{
 		return btBroadphaseProxy::isNonMoving(getShapeType());
 		return btBroadphaseProxy::isNonMoving(getShapeType());
 	}
 	}
-	SIMD_FORCE_INLINE bool	isConcave() const
+	SIMD_FORCE_INLINE bool isConcave() const
 	{
 	{
 		return btBroadphaseProxy::isConcave(getShapeType());
 		return btBroadphaseProxy::isConcave(getShapeType());
 	}
 	}
-	SIMD_FORCE_INLINE bool	isCompound() const
+	SIMD_FORCE_INLINE bool isCompound() const
 	{
 	{
 		return btBroadphaseProxy::isCompound(getShapeType());
 		return btBroadphaseProxy::isCompound(getShapeType());
 	}
 	}
 
 
-	SIMD_FORCE_INLINE bool	isSoftBody() const
+	SIMD_FORCE_INLINE bool isSoftBody() const
 	{
 	{
 		return btBroadphaseProxy::isSoftBody(getShapeType());
 		return btBroadphaseProxy::isSoftBody(getShapeType());
 	}
 	}
@@ -99,35 +96,35 @@ public:
 	}
 	}
 
 
 #ifndef __SPU__
 #ifndef __SPU__
-	virtual void	setLocalScaling(const btVector3& scaling) =0;
-	virtual const btVector3& getLocalScaling() const =0;
-	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const = 0;
+	virtual void setLocalScaling(const btVector3& scaling) = 0;
+	virtual const btVector3& getLocalScaling() const = 0;
+	virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const = 0;
 
 
+	//debugging support
+	virtual const char* getName() const = 0;
+#endif  //__SPU__
 
 
-//debugging support
-	virtual const char*	getName()const =0 ;
-#endif //__SPU__
-
-	
-	int		getShapeType() const { return m_shapeType; }
+	int getShapeType() const
+	{
+		return m_shapeType;
+	}
 
 
 	///the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction
 	///the getAnisotropicRollingFrictionDirection can be used in combination with setAnisotropicFriction
 	///See Bullet/Demos/RollingFrictionDemo for an example
 	///See Bullet/Demos/RollingFrictionDemo for an example
-	virtual btVector3	getAnisotropicRollingFrictionDirection() const
+	virtual btVector3 getAnisotropicRollingFrictionDirection() const
 	{
 	{
-		return btVector3(1,1,1);
+		return btVector3(1, 1, 1);
 	}
 	}
-	virtual void	setMargin(btScalar margin) = 0;
-	virtual btScalar	getMargin() const = 0;
+	virtual void setMargin(btScalar margin) = 0;
+	virtual btScalar getMargin() const = 0;
 
 
-	
 	///optional user data pointer
 	///optional user data pointer
-	void	setUserPointer(void*  userPtr)
+	void setUserPointer(void* userPtr)
 	{
 	{
 		m_userPointer = userPtr;
 		m_userPointer = userPtr;
 	}
 	}
 
 
-	void*	getUserPointer() const
+	void* getUserPointer() const
 	{
 	{
 		return m_userPointer;
 		return m_userPointer;
 	}
 	}
@@ -141,16 +138,26 @@ public:
 		return m_userIndex;
 		return m_userIndex;
 	}
 	}
 
 
+	void setUserIndex2(int index)
+	{
+		m_userIndex2 = index;
+	}
 
 
-	virtual	int	calculateSerializeBufferSize() const;
+	int getUserIndex2() const
+	{
+		return m_userIndex2;
+	}
 
 
-	///fills the dataBuffer and returns the struct name (and 0 on failure)
-	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
+	virtual int calculateSerializeBufferSize() const;
 
 
-	virtual void	serializeSingleShape(btSerializer* serializer) const;
+	///fills the dataBuffer and returns the struct name (and 0 on failure)
+	virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
 
 
-};	
+	virtual void serializeSingleShape(btSerializer * serializer) const;
+};
 
 
+// clang-format off
+// parser needs * with the name
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 struct	btCollisionShapeData
 struct	btCollisionShapeData
 {
 {
@@ -158,13 +165,10 @@ struct	btCollisionShapeData
 	int		m_shapeType;
 	int		m_shapeType;
 	char	m_padding[4];
 	char	m_padding[4];
 };
 };
-
-SIMD_FORCE_INLINE	int	btCollisionShape::calculateSerializeBufferSize() const
+// clang-format on
+SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() const
 {
 {
 	return sizeof(btCollisionShapeData);
 	return sizeof(btCollisionShapeData);
 }
 }
 
 
-
-
-#endif //BT_COLLISION_SHAPE_H
-
+#endif  //BT_COLLISION_SHAPE_H

+ 85 - 109
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCompoundShape.cpp

@@ -19,26 +19,25 @@ subject to the following restrictions:
 #include "LinearMath/btSerializer.h"
 #include "LinearMath/btSerializer.h"
 
 
 btCompoundShape::btCompoundShape(bool enableDynamicAabbTree, const int initialChildCapacity)
 btCompoundShape::btCompoundShape(bool enableDynamicAabbTree, const int initialChildCapacity)
-: m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)),
-m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)),
-m_dynamicAabbTree(0),
-m_updateRevision(1),
-m_collisionMargin(btScalar(0.)),
-m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
+	: m_localAabbMin(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT)),
+	  m_localAabbMax(btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT)),
+	  m_dynamicAabbTree(0),
+	  m_updateRevision(1),
+	  m_collisionMargin(btScalar(0.)),
+	  m_localScaling(btScalar(1.), btScalar(1.), btScalar(1.))
 {
 {
 	m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
 	m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
 
 
 	if (enableDynamicAabbTree)
 	if (enableDynamicAabbTree)
 	{
 	{
-		void* mem = btAlignedAlloc(sizeof(btDbvt),16);
-		m_dynamicAabbTree = new(mem) btDbvt();
-		btAssert(mem==m_dynamicAabbTree);
+		void* mem = btAlignedAlloc(sizeof(btDbvt), 16);
+		m_dynamicAabbTree = new (mem) btDbvt();
+		btAssert(mem == m_dynamicAabbTree);
 	}
 	}
 
 
 	m_children.reserve(initialChildCapacity);
 	m_children.reserve(initialChildCapacity);
 }
 }
 
 
-
 btCompoundShape::~btCompoundShape()
 btCompoundShape::~btCompoundShape()
 {
 {
 	if (m_dynamicAabbTree)
 	if (m_dynamicAabbTree)
@@ -48,7 +47,7 @@ btCompoundShape::~btCompoundShape()
 	}
 	}
 }
 }
 
 
-void	btCompoundShape::addChildShape(const btTransform& localTransform,btCollisionShape* shape)
+void btCompoundShape::addChildShape(const btTransform& localTransform, btCollisionShape* shape)
 {
 {
 	m_updateRevision++;
 	m_updateRevision++;
 	//m_childTransforms.push_back(localTransform);
 	//m_childTransforms.push_back(localTransform);
@@ -60,11 +59,10 @@ void	btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio
 	child.m_childShapeType = shape->getShapeType();
 	child.m_childShapeType = shape->getShapeType();
 	child.m_childMargin = shape->getMargin();
 	child.m_childMargin = shape->getMargin();
 
 
-	
 	//extend the local aabbMin/aabbMax
 	//extend the local aabbMin/aabbMax
-	btVector3 localAabbMin,localAabbMax;
-	shape->getAabb(localTransform,localAabbMin,localAabbMax);
-	for (int i=0;i<3;i++)
+	btVector3 localAabbMin, localAabbMax;
+	shape->getAabb(localTransform, localAabbMin, localAabbMax);
+	for (int i = 0; i < 3; i++)
 	{
 	{
 		if (m_localAabbMin[i] > localAabbMin[i])
 		if (m_localAabbMin[i] > localAabbMin[i])
 		{
 		{
@@ -74,31 +72,30 @@ void	btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio
 		{
 		{
 			m_localAabbMax[i] = localAabbMax[i];
 			m_localAabbMax[i] = localAabbMax[i];
 		}
 		}
-
 	}
 	}
 	if (m_dynamicAabbTree)
 	if (m_dynamicAabbTree)
 	{
 	{
-		const btDbvtVolume	bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
+		const btDbvtVolume bounds = btDbvtVolume::FromMM(localAabbMin, localAabbMax);
 		size_t index = m_children.size();
 		size_t index = m_children.size();
-		child.m_node = m_dynamicAabbTree->insert(bounds,reinterpret_cast<void*>(index) );
+		child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index));
 	}
 	}
 
 
 	m_children.push_back(child);
 	m_children.push_back(child);
-
 }
 }
 
 
-void	btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform,bool shouldRecalculateLocalAabb)
+void btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb)
 {
 {
 	m_children[childIndex].m_transform = newChildTransform;
 	m_children[childIndex].m_transform = newChildTransform;
 
 
 	if (m_dynamicAabbTree)
 	if (m_dynamicAabbTree)
 	{
 	{
 		///update the dynamic aabb tree
 		///update the dynamic aabb tree
-		btVector3 localAabbMin,localAabbMax;
-		m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax);
-		ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
+		btVector3 localAabbMin, localAabbMax;
+		m_children[childIndex].m_childShape->getAabb(newChildTransform, localAabbMin, localAabbMax);
+		ATTRIBUTE_ALIGNED16(btDbvtVolume)
+		bounds = btDbvtVolume::FromMM(localAabbMin, localAabbMax);
 		//int index = m_children.size()-1;
 		//int index = m_children.size()-1;
-		m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds);
+		m_dynamicAabbTree->update(m_children[childIndex].m_node, bounds);
 	}
 	}
 
 
 	if (shouldRecalculateLocalAabb)
 	if (shouldRecalculateLocalAabb)
@@ -110,35 +107,30 @@ void	btCompoundShape::updateChildTransform(int childIndex, const btTransform& ne
 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
 void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
 {
 {
 	m_updateRevision++;
 	m_updateRevision++;
-	btAssert(childShapeIndex >=0 && childShapeIndex < m_children.size());
+	btAssert(childShapeIndex >= 0 && childShapeIndex < m_children.size());
 	if (m_dynamicAabbTree)
 	if (m_dynamicAabbTree)
 	{
 	{
 		m_dynamicAabbTree->remove(m_children[childShapeIndex].m_node);
 		m_dynamicAabbTree->remove(m_children[childShapeIndex].m_node);
 	}
 	}
-	m_children.swap(childShapeIndex,m_children.size()-1);
-    if (m_dynamicAabbTree) 
+	m_children.swap(childShapeIndex, m_children.size() - 1);
+	if (m_dynamicAabbTree)
 		m_children[childShapeIndex].m_node->dataAsInt = childShapeIndex;
 		m_children[childShapeIndex].m_node->dataAsInt = childShapeIndex;
 	m_children.pop_back();
 	m_children.pop_back();
-
 }
 }
 
 
-
-
 void btCompoundShape::removeChildShape(btCollisionShape* shape)
 void btCompoundShape::removeChildShape(btCollisionShape* shape)
 {
 {
 	m_updateRevision++;
 	m_updateRevision++;
 	// Find the children containing the shape specified, and remove those children.
 	// Find the children containing the shape specified, and remove those children.
 	//note: there might be multiple children using the same shape!
 	//note: there might be multiple children using the same shape!
-	for(int i = m_children.size()-1; i >= 0 ; i--)
+	for (int i = m_children.size() - 1; i >= 0; i--)
 	{
 	{
-		if(m_children[i].m_childShape == shape)
+		if (m_children[i].m_childShape == shape)
 		{
 		{
 			removeChildShapeByIndex(i);
 			removeChildShapeByIndex(i);
 		}
 		}
 	}
 	}
 
 
-
-
 	recalculateLocalAabb();
 	recalculateLocalAabb();
 }
 }
 
 
@@ -147,15 +139,15 @@ void btCompoundShape::recalculateLocalAabb()
 	// Recalculate the local aabb
 	// Recalculate the local aabb
 	// Brute force, it iterates over all the shapes left.
 	// Brute force, it iterates over all the shapes left.
 
 
-	m_localAabbMin = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
-	m_localAabbMax = btVector3(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
+	m_localAabbMin = btVector3(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT));
+	m_localAabbMax = btVector3(btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT), btScalar(-BT_LARGE_FLOAT));
 
 
 	//extend the local aabbMin/aabbMax
 	//extend the local aabbMin/aabbMax
 	for (int j = 0; j < m_children.size(); j++)
 	for (int j = 0; j < m_children.size(); j++)
 	{
 	{
-		btVector3 localAabbMin,localAabbMax;
+		btVector3 localAabbMin, localAabbMax;
 		m_children[j].m_childShape->getAabb(m_children[j].m_transform, localAabbMin, localAabbMax);
 		m_children[j].m_childShape->getAabb(m_children[j].m_transform, localAabbMin, localAabbMax);
-		for (int i=0;i<3;i++)
+		for (int i = 0; i < 3; i++)
 		{
 		{
 			if (m_localAabbMin[i] > localAabbMin[i])
 			if (m_localAabbMin[i] > localAabbMin[i])
 				m_localAabbMin[i] = localAabbMin[i];
 				m_localAabbMin[i] = localAabbMin[i];
@@ -166,54 +158,48 @@ void btCompoundShape::recalculateLocalAabb()
 }
 }
 
 
 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
-void btCompoundShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
+void btCompoundShape::getAabb(const btTransform& trans, btVector3& aabbMin, btVector3& aabbMax) const
 {
 {
-	btVector3 localHalfExtents = btScalar(0.5)*(m_localAabbMax-m_localAabbMin);
-	btVector3 localCenter = btScalar(0.5)*(m_localAabbMax+m_localAabbMin);
-	
+	btVector3 localHalfExtents = btScalar(0.5) * (m_localAabbMax - m_localAabbMin);
+	btVector3 localCenter = btScalar(0.5) * (m_localAabbMax + m_localAabbMin);
+
 	//avoid an illegal AABB when there are no children
 	//avoid an illegal AABB when there are no children
 	if (!m_children.size())
 	if (!m_children.size())
 	{
 	{
-		localHalfExtents.setValue(0,0,0);
-		localCenter.setValue(0,0,0);
+		localHalfExtents.setValue(0, 0, 0);
+		localCenter.setValue(0, 0, 0);
 	}
 	}
-	localHalfExtents += btVector3(getMargin(),getMargin(),getMargin());
-		
+	localHalfExtents += btVector3(getMargin(), getMargin(), getMargin());
 
 
-	btMatrix3x3 abs_b = trans.getBasis().absolute();  
+	btMatrix3x3 abs_b = trans.getBasis().absolute();
 
 
 	btVector3 center = trans(localCenter);
 	btVector3 center = trans(localCenter);
 
 
-    btVector3 extent = localHalfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
-	aabbMin = center-extent;
-	aabbMax = center+extent;
-	
+	btVector3 extent = localHalfExtents.dot3(abs_b[0], abs_b[1], abs_b[2]);
+	aabbMin = center - extent;
+	aabbMax = center + extent;
 }
 }
 
 
-void	btCompoundShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const
+void btCompoundShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
 {
 {
 	//approximation: take the inertia from the aabb for now
 	//approximation: take the inertia from the aabb for now
 	btTransform ident;
 	btTransform ident;
 	ident.setIdentity();
 	ident.setIdentity();
-	btVector3 aabbMin,aabbMax;
-	getAabb(ident,aabbMin,aabbMax);
+	btVector3 aabbMin, aabbMax;
+	getAabb(ident, aabbMin, aabbMax);
 
 
-	btVector3 halfExtents = (aabbMax-aabbMin)*btScalar(0.5);
+	btVector3 halfExtents = (aabbMax - aabbMin) * btScalar(0.5);
 
 
-	btScalar lx=btScalar(2.)*(halfExtents.x());
-	btScalar ly=btScalar(2.)*(halfExtents.y());
-	btScalar lz=btScalar(2.)*(halfExtents.z());
-
-	inertia[0] = mass/(btScalar(12.0)) * (ly*ly + lz*lz);
-	inertia[1] = mass/(btScalar(12.0)) * (lx*lx + lz*lz);
-	inertia[2] = mass/(btScalar(12.0)) * (lx*lx + ly*ly);
+	btScalar lx = btScalar(2.) * (halfExtents.x());
+	btScalar ly = btScalar(2.) * (halfExtents.y());
+	btScalar lz = btScalar(2.) * (halfExtents.z());
 
 
+	inertia[0] = mass / (btScalar(12.0)) * (ly * ly + lz * lz);
+	inertia[1] = mass / (btScalar(12.0)) * (lx * lx + lz * lz);
+	inertia[2] = mass / (btScalar(12.0)) * (lx * lx + ly * ly);
 }
 }
 
 
-
-
-
-void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const
+void btCompoundShape::calculatePrincipalAxisTransform(const btScalar* masses, btTransform& principal, btVector3& inertia) const
 {
 {
 	int n = m_children.size();
 	int n = m_children.size();
 
 
@@ -223,18 +209,18 @@ void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransf
 
 
 	for (k = 0; k < n; k++)
 	for (k = 0; k < n; k++)
 	{
 	{
-		btAssert(masses[k]>0);
+		btAssert(masses[k] > 0);
 		center += m_children[k].m_transform.getOrigin() * masses[k];
 		center += m_children[k].m_transform.getOrigin() * masses[k];
 		totalMass += masses[k];
 		totalMass += masses[k];
 	}
 	}
 
 
-	btAssert(totalMass>0);
+	btAssert(totalMass > 0);
 
 
 	center /= totalMass;
 	center /= totalMass;
 	principal.setOrigin(center);
 	principal.setOrigin(center);
 
 
 	btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
 	btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
-	for ( k = 0; k < n; k++)
+	for (k = 0; k < n; k++)
 	{
 	{
 		btVector3 i;
 		btVector3 i;
 		m_children[k].m_childShape->calculateLocalInertia(masses[k], i);
 		m_children[k].m_childShape->calculateLocalInertia(masses[k], i);
@@ -259,8 +245,8 @@ void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransf
 		j[0].setValue(o2, 0, 0);
 		j[0].setValue(o2, 0, 0);
 		j[1].setValue(0, o2, 0);
 		j[1].setValue(0, o2, 0);
 		j[2].setValue(0, 0, o2);
 		j[2].setValue(0, 0, o2);
-		j[0] += o * -o.x(); 
-		j[1] += o * -o.y(); 
+		j[0] += o * -o.x();
+		j[1] += o * -o.y();
 		j[2] += o * -o.z();
 		j[2] += o * -o.z();
 
 
 		//add inertia tensor of pointmass
 		//add inertia tensor of pointmass
@@ -273,59 +259,50 @@ void btCompoundShape::calculatePrincipalAxisTransform(btScalar* masses, btTransf
 	inertia.setValue(tensor[0][0], tensor[1][1], tensor[2][2]);
 	inertia.setValue(tensor[0][0], tensor[1][1], tensor[2][2]);
 }
 }
 
 
-
-
-
-
 void btCompoundShape::setLocalScaling(const btVector3& scaling)
 void btCompoundShape::setLocalScaling(const btVector3& scaling)
 {
 {
-
-	for(int i = 0; i < m_children.size(); i++)
+	for (int i = 0; i < m_children.size(); i++)
 	{
 	{
 		btTransform childTrans = getChildTransform(i);
 		btTransform childTrans = getChildTransform(i);
 		btVector3 childScale = m_children[i].m_childShape->getLocalScaling();
 		btVector3 childScale = m_children[i].m_childShape->getLocalScaling();
-//		childScale = childScale * (childTrans.getBasis() * scaling);
+		//		childScale = childScale * (childTrans.getBasis() * scaling);
 		childScale = childScale * scaling / m_localScaling;
 		childScale = childScale * scaling / m_localScaling;
 		m_children[i].m_childShape->setLocalScaling(childScale);
 		m_children[i].m_childShape->setLocalScaling(childScale);
 		childTrans.setOrigin((childTrans.getOrigin()) * scaling / m_localScaling);
 		childTrans.setOrigin((childTrans.getOrigin()) * scaling / m_localScaling);
-		updateChildTransform(i, childTrans,false);
+		updateChildTransform(i, childTrans, false);
 	}
 	}
-	
+
 	m_localScaling = scaling;
 	m_localScaling = scaling;
 	recalculateLocalAabb();
 	recalculateLocalAabb();
-
 }
 }
 
 
-
 void btCompoundShape::createAabbTreeFromChildren()
 void btCompoundShape::createAabbTreeFromChildren()
 {
 {
-    if ( !m_dynamicAabbTree )
-    {
-        void* mem = btAlignedAlloc(sizeof(btDbvt),16);
-        m_dynamicAabbTree = new(mem) btDbvt();
-        btAssert(mem==m_dynamicAabbTree);
+	if (!m_dynamicAabbTree)
+	{
+		void* mem = btAlignedAlloc(sizeof(btDbvt), 16);
+		m_dynamicAabbTree = new (mem) btDbvt();
+		btAssert(mem == m_dynamicAabbTree);
 
 
-        for ( int index = 0; index < m_children.size(); index++ )
-        {
-            btCompoundShapeChild &child = m_children[index];
+		for (int index = 0; index < m_children.size(); index++)
+		{
+			btCompoundShapeChild& child = m_children[index];
 
 
-            //extend the local aabbMin/aabbMax
-            btVector3 localAabbMin,localAabbMax;
-            child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax);
+			//extend the local aabbMin/aabbMax
+			btVector3 localAabbMin, localAabbMax;
+			child.m_childShape->getAabb(child.m_transform, localAabbMin, localAabbMax);
 
 
-            const btDbvtVolume  bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
+			const btDbvtVolume bounds = btDbvtVolume::FromMM(localAabbMin, localAabbMax);
 			size_t index2 = index;
 			size_t index2 = index;
-            child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index2) );
-        }
-    }
+			child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index2));
+		}
+	}
 }
 }
 
 
-
 ///fills the dataBuffer and returns the struct name (and 0 on failure)
 ///fills the dataBuffer and returns the struct name (and 0 on failure)
-const char*	btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const
+const char* btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const
 {
 {
-
-	btCompoundShapeData* shapeData = (btCompoundShapeData*) dataBuffer;
+	btCompoundShapeData* shapeData = (btCompoundShapeData*)dataBuffer;
 	btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer);
 	btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer);
 
 
 	shapeData->m_collisionMargin = float(m_collisionMargin);
 	shapeData->m_collisionMargin = float(m_collisionMargin);
@@ -333,27 +310,26 @@ const char*	btCompoundShape::serialize(void* dataBuffer, btSerializer* serialize
 	shapeData->m_childShapePtr = 0;
 	shapeData->m_childShapePtr = 0;
 	if (shapeData->m_numChildShapes)
 	if (shapeData->m_numChildShapes)
 	{
 	{
-		btChunk* chunk = serializer->allocate(sizeof(btCompoundShapeChildData),shapeData->m_numChildShapes);
+		btChunk* chunk = serializer->allocate(sizeof(btCompoundShapeChildData), shapeData->m_numChildShapes);
 		btCompoundShapeChildData* memPtr = (btCompoundShapeChildData*)chunk->m_oldPtr;
 		btCompoundShapeChildData* memPtr = (btCompoundShapeChildData*)chunk->m_oldPtr;
 		shapeData->m_childShapePtr = (btCompoundShapeChildData*)serializer->getUniquePointer(memPtr);
 		shapeData->m_childShapePtr = (btCompoundShapeChildData*)serializer->getUniquePointer(memPtr);
 
 
-		for (int i=0;i<shapeData->m_numChildShapes;i++,memPtr++)
+		for (int i = 0; i < shapeData->m_numChildShapes; i++, memPtr++)
 		{
 		{
 			memPtr->m_childMargin = float(m_children[i].m_childMargin);
 			memPtr->m_childMargin = float(m_children[i].m_childMargin);
 			memPtr->m_childShape = (btCollisionShapeData*)serializer->getUniquePointer(m_children[i].m_childShape);
 			memPtr->m_childShape = (btCollisionShapeData*)serializer->getUniquePointer(m_children[i].m_childShape);
 			//don't serialize shapes that already have been serialized
 			//don't serialize shapes that already have been serialized
 			if (!serializer->findPointer(m_children[i].m_childShape))
 			if (!serializer->findPointer(m_children[i].m_childShape))
 			{
 			{
-				btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(),1);
-				const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr,serializer);
-				serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,m_children[i].m_childShape);
-			} 
+				btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(), 1);
+				const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr, serializer);
+				serializer->finalizeChunk(chunk, structType, BT_SHAPE_CODE, m_children[i].m_childShape);
+			}
 
 
 			memPtr->m_childShapeType = m_children[i].m_childShapeType;
 			memPtr->m_childShapeType = m_children[i].m_childShapeType;
 			m_children[i].m_transform.serializeFloat(memPtr->m_transform);
 			m_children[i].m_transform.serializeFloat(memPtr->m_transform);
 		}
 		}
-		serializer->finalizeChunk(chunk,"btCompoundShapeChildData",BT_ARRAY_CODE,chunk->m_oldPtr);
+		serializer->finalizeChunk(chunk, "btCompoundShapeChildData", BT_ARRAY_CODE, chunk->m_oldPtr);
 	}
 	}
 	return "btCompoundShapeData";
 	return "btCompoundShapeData";
 }
 }
-

+ 47 - 52
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btCompoundShape.h

@@ -27,45 +27,47 @@ subject to the following restrictions:
 //class btOptimizedBvh;
 //class btOptimizedBvh;
 struct btDbvt;
 struct btDbvt;
 
 
-ATTRIBUTE_ALIGNED16(struct) btCompoundShapeChild
+ATTRIBUTE_ALIGNED16(struct)
+btCompoundShapeChild
 {
 {
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
 
-	btTransform			m_transform;
-	btCollisionShape*	m_childShape;
-	int					m_childShapeType;
-	btScalar			m_childMargin;
-	struct btDbvtNode*	m_node;
+	btTransform m_transform;
+	btCollisionShape* m_childShape;
+	int m_childShapeType;
+	btScalar m_childMargin;
+	struct btDbvtNode* m_node;
 };
 };
 
 
 SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
 SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompoundShapeChild& c2)
 {
 {
-	return  ( c1.m_transform      == c2.m_transform &&
-		c1.m_childShape     == c2.m_childShape &&
-		c1.m_childShapeType == c2.m_childShapeType &&
-		c1.m_childMargin    == c2.m_childMargin );
+	return (c1.m_transform == c2.m_transform &&
+			c1.m_childShape == c2.m_childShape &&
+			c1.m_childShapeType == c2.m_childShapeType &&
+			c1.m_childMargin == c2.m_childMargin);
 }
 }
 
 
 /// The btCompoundShape allows to store multiple other btCollisionShapes
 /// The btCompoundShape allows to store multiple other btCollisionShapes
 /// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
 /// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
-/// It has an (optional) dynamic aabb tree to accelerate early rejection tests. 
+/// It has an (optional) dynamic aabb tree to accelerate early rejection tests.
 /// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25
 /// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25
 /// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
 /// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
-ATTRIBUTE_ALIGNED16(class) btCompoundShape	: public btCollisionShape
+ATTRIBUTE_ALIGNED16(class)
+btCompoundShape : public btCollisionShape
 {
 {
 protected:
 protected:
 	btAlignedObjectArray<btCompoundShapeChild> m_children;
 	btAlignedObjectArray<btCompoundShapeChild> m_children;
-	btVector3						m_localAabbMin;
-	btVector3						m_localAabbMax;
+	btVector3 m_localAabbMin;
+	btVector3 m_localAabbMax;
 
 
-	btDbvt*							m_dynamicAabbTree;
+	btDbvt* m_dynamicAabbTree;
 
 
 	///increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be updated
 	///increment m_updateRevision when adding/removing/replacing child shapes, so that some caches can be updated
-	int								m_updateRevision;
+	int m_updateRevision;
 
 
-	btScalar	m_collisionMargin;
+	btScalar m_collisionMargin;
 
 
-	btVector3	m_localScaling;
+	btVector3 m_localScaling;
 
 
 public:
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
@@ -74,17 +76,16 @@ public:
 
 
 	virtual ~btCompoundShape();
 	virtual ~btCompoundShape();
 
 
-	void	addChildShape(const btTransform& localTransform,btCollisionShape* shape);
+	void addChildShape(const btTransform& localTransform, btCollisionShape* shape);
 
 
 	/// Remove all children shapes that contain the specified shape
 	/// Remove all children shapes that contain the specified shape
-	virtual void removeChildShape(btCollisionShape* shape);
+	virtual void removeChildShape(btCollisionShape * shape);
 
 
 	void removeChildShapeByIndex(int childShapeindex);
 	void removeChildShapeByIndex(int childShapeindex);
 
 
-
-	int		getNumChildShapes() const
+	int getNumChildShapes() const
 	{
 	{
-		return int (m_children.size());
+		return int(m_children.size());
 	}
 	}
 
 
 	btCollisionShape* getChildShape(int index)
 	btCollisionShape* getChildShape(int index)
@@ -96,18 +97,17 @@ public:
 		return m_children[index].m_childShape;
 		return m_children[index].m_childShape;
 	}
 	}
 
 
-	btTransform&	getChildTransform(int index)
+	btTransform& getChildTransform(int index)
 	{
 	{
 		return m_children[index].m_transform;
 		return m_children[index].m_transform;
 	}
 	}
-	const btTransform&	getChildTransform(int index) const
+	const btTransform& getChildTransform(int index) const
 	{
 	{
 		return m_children[index].m_transform;
 		return m_children[index].m_transform;
 	}
 	}
 
 
 	///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
 	///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
-	void	updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true);
-
+	void updateChildTransform(int childIndex, const btTransform& newChildTransform, bool shouldRecalculateLocalAabb = true);
 
 
 	btCompoundShapeChild* getChildList()
 	btCompoundShapeChild* getChildList()
 	{
 	{
@@ -115,40 +115,40 @@ public:
 	}
 	}
 
 
 	///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
 	///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
-	virtual	void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
+	virtual void getAabb(const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
 
 
 	/** Re-calculate the local Aabb. Is called at the end of removeChildShapes. 
 	/** Re-calculate the local Aabb. Is called at the end of removeChildShapes. 
 	Use this yourself if you modify the children or their transforms. */
 	Use this yourself if you modify the children or their transforms. */
-	virtual void recalculateLocalAabb(); 
+	virtual void recalculateLocalAabb();
 
 
-	virtual void	setLocalScaling(const btVector3& scaling);
+	virtual void setLocalScaling(const btVector3& scaling);
 
 
-	virtual const btVector3& getLocalScaling() const 
+	virtual const btVector3& getLocalScaling() const
 	{
 	{
 		return m_localScaling;
 		return m_localScaling;
 	}
 	}
 
 
-	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const;
+	virtual void calculateLocalInertia(btScalar mass, btVector3 & inertia) const;
 
 
-	virtual void	setMargin(btScalar margin)
+	virtual void setMargin(btScalar margin)
 	{
 	{
 		m_collisionMargin = margin;
 		m_collisionMargin = margin;
 	}
 	}
-	virtual btScalar	getMargin() const
+	virtual btScalar getMargin() const
 	{
 	{
 		return m_collisionMargin;
 		return m_collisionMargin;
 	}
 	}
-	virtual const char*	getName()const
+	virtual const char* getName() const
 	{
 	{
 		return "Compound";
 		return "Compound";
 	}
 	}
 
 
-	const btDbvt*	getDynamicAabbTree() const
+	const btDbvt* getDynamicAabbTree() const
 	{
 	{
 		return m_dynamicAabbTree;
 		return m_dynamicAabbTree;
 	}
 	}
-	
-	btDbvt*	getDynamicAabbTree()
+
+	btDbvt* getDynamicAabbTree()
 	{
 	{
 		return m_dynamicAabbTree;
 		return m_dynamicAabbTree;
 	}
 	}
@@ -160,21 +160,21 @@ public:
 	///"principal" has to be applied inversely to all children transforms in order for the local coordinate system of the compound
 	///"principal" has to be applied inversely to all children transforms in order for the local coordinate system of the compound
 	///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
 	///shape to be centered at the center of mass and to coincide with the principal axes. This also necessitates a correction of the world transform
 	///of the collision object by the principal transform.
 	///of the collision object by the principal transform.
-	void calculatePrincipalAxisTransform(btScalar* masses, btTransform& principal, btVector3& inertia) const;
+	void calculatePrincipalAxisTransform(const btScalar* masses, btTransform& principal, btVector3& inertia) const;
 
 
-	int	getUpdateRevision() const
+	int getUpdateRevision() const
 	{
 	{
 		return m_updateRevision;
 		return m_updateRevision;
 	}
 	}
 
 
-	virtual	int	calculateSerializeBufferSize() const;
+	virtual int calculateSerializeBufferSize() const;
 
 
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
-	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
-
-
+	virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const;
 };
 };
 
 
+// clang-format off
+
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
 struct btCompoundShapeChildData
 struct btCompoundShapeChildData
 {
 {
@@ -197,16 +197,11 @@ struct	btCompoundShapeData
 
 
 };
 };
 
 
+// clang-format on
 
 
-SIMD_FORCE_INLINE	int	btCompoundShape::calculateSerializeBufferSize() const
+SIMD_FORCE_INLINE int btCompoundShape::calculateSerializeBufferSize() const
 {
 {
 	return sizeof(btCompoundShapeData);
 	return sizeof(btCompoundShapeData);
 }
 }
 
 
-
-
-
-
-
-
-#endif //BT_COMPOUND_SHAPE_H
+#endif  //BT_COMPOUND_SHAPE_H

+ 0 - 3
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btConcaveShape.cpp

@@ -13,15 +13,12 @@ subject to the following restrictions:
 3. This notice may not be removed or altered from any source distribution.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
 
 
-
 #include "btConcaveShape.h"
 #include "btConcaveShape.h"
 
 
 btConcaveShape::btConcaveShape() : m_collisionMargin(btScalar(0.))
 btConcaveShape::btConcaveShape() : m_collisionMargin(btScalar(0.))
 {
 {
-
 }
 }
 
 
 btConcaveShape::~btConcaveShape()
 btConcaveShape::~btConcaveShape()
 {
 {
-
 }
 }

+ 10 - 10
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btConcaveShape.h

@@ -17,12 +17,13 @@ subject to the following restrictions:
 #define BT_CONCAVE_SHAPE_H
 #define BT_CONCAVE_SHAPE_H
 
 
 #include "btCollisionShape.h"
 #include "btCollisionShape.h"
-#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"  // for the types
 #include "btTriangleCallback.h"
 #include "btTriangleCallback.h"
 
 
 /// PHY_ScalarType enumerates possible scalar types.
 /// PHY_ScalarType enumerates possible scalar types.
 /// See the btStridingMeshInterface or btHeightfieldTerrainShape for its use
 /// See the btStridingMeshInterface or btHeightfieldTerrainShape for its use
-typedef enum PHY_ScalarType {
+typedef enum PHY_ScalarType
+{
 	PHY_FLOAT,
 	PHY_FLOAT,
 	PHY_DOUBLE,
 	PHY_DOUBLE,
 	PHY_INTEGER,
 	PHY_INTEGER,
@@ -33,30 +34,29 @@ typedef enum PHY_ScalarType {
 
 
 ///The btConcaveShape class provides an interface for non-moving (static) concave shapes.
 ///The btConcaveShape class provides an interface for non-moving (static) concave shapes.
 ///It has been implemented by the btStaticPlaneShape, btBvhTriangleMeshShape and btHeightfieldTerrainShape.
 ///It has been implemented by the btStaticPlaneShape, btBvhTriangleMeshShape and btHeightfieldTerrainShape.
-ATTRIBUTE_ALIGNED16(class) btConcaveShape : public btCollisionShape
+ATTRIBUTE_ALIGNED16(class)
+btConcaveShape : public btCollisionShape
 {
 {
 protected:
 protected:
 	btScalar m_collisionMargin;
 	btScalar m_collisionMargin;
 
 
 public:
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 	BT_DECLARE_ALIGNED_ALLOCATOR();
-	
+
 	btConcaveShape();
 	btConcaveShape();
 
 
 	virtual ~btConcaveShape();
 	virtual ~btConcaveShape();
 
 
-	virtual void	processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const = 0;
+	virtual void processAllTriangles(btTriangleCallback * callback, const btVector3& aabbMin, const btVector3& aabbMax) const = 0;
 
 
-	virtual btScalar getMargin() const {
+	virtual btScalar getMargin() const
+	{
 		return m_collisionMargin;
 		return m_collisionMargin;
 	}
 	}
 	virtual void setMargin(btScalar collisionMargin)
 	virtual void setMargin(btScalar collisionMargin)
 	{
 	{
 		m_collisionMargin = collisionMargin;
 		m_collisionMargin = collisionMargin;
 	}
 	}
-
-
-
 };
 };
 
 
-#endif //BT_CONCAVE_SHAPE_H
+#endif  //BT_CONCAVE_SHAPE_H

+ 51 - 56
Source/ThirdParty/Bullet/src/BulletCollision/CollisionShapes/btConeShape.cpp

@@ -15,11 +15,9 @@ subject to the following restrictions:
 
 
 #include "btConeShape.h"
 #include "btConeShape.h"
 
 
-
-
-btConeShape::btConeShape (btScalar radius,btScalar height): btConvexInternalShape (),
-m_radius (radius),
-m_height(height)
+btConeShape::btConeShape(btScalar radius, btScalar height) : btConvexInternalShape(),
+															 m_radius(radius),
+															 m_height(height)
 {
 {
 	m_shapeType = CONE_SHAPE_PROXYTYPE;
 	m_shapeType = CONE_SHAPE_PROXYTYPE;
 	setConeUpIndex(1);
 	setConeUpIndex(1);
@@ -27,42 +25,40 @@ m_height(height)
 	m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
 	m_sinAngle = (m_radius / btSqrt(m_radius * m_radius + m_height * m_height));
 }
 }
 
 
-btConeShapeZ::btConeShapeZ (btScalar radius,btScalar height):
-btConeShape(radius,height)
+btConeShapeZ::btConeShapeZ(btScalar radius, btScalar height) : btConeShape(radius, height)
 {
 {
 	setConeUpIndex(2);
 	setConeUpIndex(2);
 }
 }
 
 
-btConeShapeX::btConeShapeX (btScalar radius,btScalar height):
-btConeShape(radius,height)
+btConeShapeX::btConeShapeX(btScalar radius, btScalar height) : btConeShape(radius, height)
 {
 {
 	setConeUpIndex(0);
 	setConeUpIndex(0);
 }
 }
 
 
 ///choose upAxis index
 ///choose upAxis index
-void	btConeShape::setConeUpIndex(int upIndex)
+void btConeShape::setConeUpIndex(int upIndex)
 {
 {
 	switch (upIndex)
 	switch (upIndex)
 	{
 	{
-	case 0:
+		case 0:
 			m_coneIndices[0] = 1;
 			m_coneIndices[0] = 1;
 			m_coneIndices[1] = 0;
 			m_coneIndices[1] = 0;
 			m_coneIndices[2] = 2;
 			m_coneIndices[2] = 2;
-		break;
-	case 1:
+			break;
+		case 1:
 			m_coneIndices[0] = 0;
 			m_coneIndices[0] = 0;
 			m_coneIndices[1] = 1;
 			m_coneIndices[1] = 1;
 			m_coneIndices[2] = 2;
 			m_coneIndices[2] = 2;
-		break;
-	case 2:
+			break;
+		case 2:
 			m_coneIndices[0] = 0;
 			m_coneIndices[0] = 0;
 			m_coneIndices[1] = 2;
 			m_coneIndices[1] = 2;
 			m_coneIndices[2] = 1;
 			m_coneIndices[2] = 1;
-		break;
-	default:
-		btAssert(0);
+			break;
+		default:
+			btAssert(0);
 	};
 	};
-	
+
 	m_implicitShapeDimensions[m_coneIndices[0]] = m_radius;
 	m_implicitShapeDimensions[m_coneIndices[0]] = m_radius;
 	m_implicitShapeDimensions[m_coneIndices[1]] = m_height;
 	m_implicitShapeDimensions[m_coneIndices[1]] = m_height;
 	m_implicitShapeDimensions[m_coneIndices[2]] = m_radius;
 	m_implicitShapeDimensions[m_coneIndices[2]] = m_radius;
@@ -70,72 +66,71 @@ void	btConeShape::setConeUpIndex(int upIndex)
 
 
 btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
 btVector3 btConeShape::coneLocalSupport(const btVector3& v) const
 {
 {
-	
 	btScalar halfHeight = m_height * btScalar(0.5);
 	btScalar halfHeight = m_height * btScalar(0.5);
 
 
- if (v[m_coneIndices[1]] > v.length() * m_sinAngle)
- {
-	btVector3 tmp;
-
-	tmp[m_coneIndices[0]] = btScalar(0.);
-	tmp[m_coneIndices[1]] = halfHeight;
-	tmp[m_coneIndices[2]] = btScalar(0.);
-	return tmp;
- }
-  else {
-    btScalar s = btSqrt(v[m_coneIndices[0]] * v[m_coneIndices[0]] + v[m_coneIndices[2]] * v[m_coneIndices[2]]);
-    if (s > SIMD_EPSILON) {
-      btScalar d = m_radius / s;
-	  btVector3 tmp;
-	  tmp[m_coneIndices[0]] = v[m_coneIndices[0]] * d;
-	  tmp[m_coneIndices[1]] = -halfHeight;
-	  tmp[m_coneIndices[2]] = v[m_coneIndices[2]] * d;
-	  return tmp;
-    }
-    else  {
+	if (v[m_coneIndices[1]] > v.length() * m_sinAngle)
+	{
 		btVector3 tmp;
 		btVector3 tmp;
+
 		tmp[m_coneIndices[0]] = btScalar(0.);
 		tmp[m_coneIndices[0]] = btScalar(0.);
-		tmp[m_coneIndices[1]] = -halfHeight;
+		tmp[m_coneIndices[1]] = halfHeight;
 		tmp[m_coneIndices[2]] = btScalar(0.);
 		tmp[m_coneIndices[2]] = btScalar(0.);
 		return tmp;
 		return tmp;
 	}
 	}
-  }
-
+	else
+	{
+		btScalar s = btSqrt(v[m_coneIndices[0]] * v[m_coneIndices[0]] + v[m_coneIndices[2]] * v[m_coneIndices[2]]);
+		if (s > SIMD_EPSILON)
+		{
+			btScalar d = m_radius / s;
+			btVector3 tmp;
+			tmp[m_coneIndices[0]] = v[m_coneIndices[0]] * d;
+			tmp[m_coneIndices[1]] = -halfHeight;
+			tmp[m_coneIndices[2]] = v[m_coneIndices[2]] * d;
+			return tmp;
+		}
+		else
+		{
+			btVector3 tmp;
+			tmp[m_coneIndices[0]] = btScalar(0.);
+			tmp[m_coneIndices[1]] = -halfHeight;
+			tmp[m_coneIndices[2]] = btScalar(0.);
+			return tmp;
+		}
+	}
 }
 }
 
 
-btVector3	btConeShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
+btVector3 btConeShape::localGetSupportingVertexWithoutMargin(const btVector3& vec) const
 {
 {
-		return coneLocalSupport(vec);
+	return coneLocalSupport(vec);
 }
 }
 
 
-void	btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
+void btConeShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors, btVector3* supportVerticesOut, int numVectors) const
 {
 {
-	for (int i=0;i<numVectors;i++)
+	for (int i = 0; i < numVectors; i++)
 	{
 	{
 		const btVector3& vec = vectors[i];
 		const btVector3& vec = vectors[i];
 		supportVerticesOut[i] = coneLocalSupport(vec);
 		supportVerticesOut[i] = coneLocalSupport(vec);
 	}
 	}
 }
 }
 
 
-
-btVector3	btConeShape::localGetSupportingVertex(const btVector3& vec)  const
+btVector3 btConeShape::localGetSupportingVertex(const btVector3& vec) const
 {
 {
 	btVector3 supVertex = coneLocalSupport(vec);
 	btVector3 supVertex = coneLocalSupport(vec);
-	if ( getMargin()!=btScalar(0.) )
+	if (getMargin() != btScalar(0.))
 	{
 	{
 		btVector3 vecnorm = vec;
 		btVector3 vecnorm = vec;
-		if (vecnorm .length2() < (SIMD_EPSILON*SIMD_EPSILON))
+		if (vecnorm.length2() < (SIMD_EPSILON * SIMD_EPSILON))
 		{
 		{
-			vecnorm.setValue(btScalar(-1.),btScalar(-1.),btScalar(-1.));
-		} 
+			vecnorm.setValue(btScalar(-1.), btScalar(-1.), btScalar(-1.));
+		}
 		vecnorm.normalize();
 		vecnorm.normalize();
-		supVertex+= getMargin() * vecnorm;
+		supVertex += getMargin() * vecnorm;
 	}
 	}
 	return supVertex;
 	return supVertex;
 }
 }
 
 
-
-void	btConeShape::setLocalScaling(const btVector3& scaling)
+void btConeShape::setLocalScaling(const btVector3& scaling)
 {
 {
 	int axis = m_coneIndices[1];
 	int axis = m_coneIndices[1];
 	int r1 = m_coneIndices[0];
 	int r1 = m_coneIndices[0];

Some files were not shown because too many files changed in this diff