Browse Source

Merge pull request #2 from GarageGames/development

Jumping into the future
Thomas Dickerson 8 years ago
parent
commit
3f73bb99b9
100 changed files with 7605 additions and 5928 deletions
  1. 13 0
      .gitattributes
  2. 10 0
      .gitignore
  3. 13 0
      CMakeLists.txt
  4. 58 0
      CONTRIBUTING.md
  5. 27 0
      Engine/lib/bullet/.travis.yml
  6. 0 22
      Engine/lib/bullet/AUTHORS
  7. 40 0
      Engine/lib/bullet/AUTHORS.txt
  8. 25 0
      Engine/lib/bullet/BulletConfig.cmake.in
  9. 0 17
      Engine/lib/bullet/BulletLicense.txt
  10. BIN
      Engine/lib/bullet/Bullet_Faq.pdf
  11. 318 38
      Engine/lib/bullet/CMakeLists.txt
  12. 0 745
      Engine/lib/bullet/ChangeLog
  13. 22 5
      Engine/lib/bullet/Doxyfile
  14. 0 100
      Engine/lib/bullet/INSTALL
  15. 0 66
      Engine/lib/bullet/Jamfile.in
  16. 0 21
      Engine/lib/bullet/Jamrules
  17. 0 19
      Engine/lib/bullet/LICENSE
  18. 15 0
      Engine/lib/bullet/LICENSE.txt
  19. 0 7
      Engine/lib/bullet/Makefile.am
  20. 0 4
      Engine/lib/bullet/NEWS
  21. 0 7
      Engine/lib/bullet/README
  22. 107 0
      Engine/lib/bullet/README.md
  23. 0 34
      Engine/lib/bullet/RELEASING.TXT
  24. 10 0
      Engine/lib/bullet/UseBullet.cmake
  25. 1 1
      Engine/lib/bullet/VERSION
  26. 0 3056
      Engine/lib/bullet/acinclude.m4
  27. 19 0
      Engine/lib/bullet/appveyor.yml
  28. 0 61
      Engine/lib/bullet/autogen.sh
  29. 6 0
      Engine/lib/bullet/bullet.pc.cmake
  30. 0 11
      Engine/lib/bullet/bullet.pc.in
  31. 0 108
      Engine/lib/bullet/config.h.in
  32. 0 192
      Engine/lib/bullet/configure.ac
  33. 0 176
      Engine/lib/bullet/src/Bullet-C-Api.h
  34. 30 3
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h
  35. 14 6
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
  36. 15 4
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
  37. 7 6
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h
  38. 6 4
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.cpp
  39. 113 36
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.h
  40. 93 0
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
  41. 28 16
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
  42. 21 14
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.h
  43. 1 1
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp
  44. 5 6
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
  45. 10 9
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
  46. 257 10
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
  47. 117 9
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
  48. 19 0
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
  49. 4 3
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
  50. 43 22
      Engine/lib/bullet/src/BulletCollision/CMakeLists.txt
  51. 27 36
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
  52. 6 4
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
  53. 1 1
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp
  54. 1 1
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h
  55. 18 34
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp
  56. 7 7
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h
  57. 11 12
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
  58. 7 7
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h
  59. 42 13
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
  60. 5 5
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h
  61. 4 2
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h
  62. 7 7
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h
  63. 65 41
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
  64. 45 17
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
  65. 64 7
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
  66. 296 40
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.h
  67. 43 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h
  68. 1006 204
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
  69. 139 33
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
  70. 1147 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp
  71. 190 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.h
  72. 136 85
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
  73. 28 10
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
  74. 445 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp
  75. 89 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h
  76. 12 17
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp
  77. 7 10
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h
  78. 82 53
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
  79. 28 17
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
  80. 291 72
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
  81. 12 12
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
  82. 46 27
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
  83. 10 10
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
  84. 112 27
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
  85. 8 16
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
  86. 1 1
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp
  87. 8 8
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h
  88. 3 2
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btGhostObject.h
  89. 276 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp
  90. 172 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.h
  91. 838 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
  92. 47 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h
  93. 78 21
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp
  94. 51 19
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.h
  95. 86 26
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
  96. 4 4
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h
  97. 109 155
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
  98. 10 10
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h
  99. 11 9
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
  100. 7 7
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h

+ 13 - 0
.gitattributes

@@ -3,3 +3,16 @@
 
 
 # Set to always use Windows line endings
 # Set to always use Windows line endings
 *.cs text eol=crlf
 *.cs text eol=crlf
+
+# Explicitly declare text files we want to always be normalized and converted 
+# to native line endings on checkout.
+*.c text
+*.h text
+*.cpp text
+*.hpp text
+*.ppm text
+*.nsh text
+*.nlf text
+*.command
+*.txt
+*.ini

+ 10 - 0
.gitignore

@@ -40,6 +40,11 @@ local.properties
 *.suo
 *.suo
 *.user
 *.user
 *.sln.docstates
 *.sln.docstates
+*.sln
+*.vcxproj
+*.vcxproj.filters
+*.vcproj
+
 
 
 # Build results
 # Build results
 [Dd]ebug/
 [Dd]ebug/
@@ -62,6 +67,11 @@ local.properties
 *.vspscc
 *.vspscc
 .builds
 .builds
 *.dotCover
 *.dotCover
+*.dll
+*.lib
+*.exp
+*.exe
+
 
 
 ## TODO: If you have NuGet Package Restore enabled, uncomment this
 ## TODO: If you have NuGet Package Restore enabled, uncomment this
 #packages/
 #packages/

+ 13 - 0
CMakeLists.txt

@@ -0,0 +1,13 @@
+cmake_minimum_required (VERSION 2.8.12)
+
+set(TORQUE_APP_NAME "" CACHE STRING "the app name")
+
+set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/temp" CACHE PATH "default install path" FORCE )
+
+if("${TORQUE_APP_NAME}" STREQUAL "")
+	message(FATAL_ERROR "Please set TORQUE_APP_NAME first")
+endif()
+
+project(${TORQUE_APP_NAME})
+
+add_subdirectory(Tools/CMake)

+ 58 - 0
CONTRIBUTING.md

@@ -0,0 +1,58 @@
+# Torque 3D contribution guidelines
+
+So you want to help Torque out by contributing to the repo? That's awesome!
+We just ask that you'd give this document a quick read to get yourself familiar with the process.
+Do you want to [request a feature](#request-a-feature)?
+Create a [pull-request](#create-a-pull-request) to contribute your own code to the engine?
+[Report an issue](#report-an-issue) you've discovered?
+
+## Report an issue
+
+Before you report an issue with the engine, please [search](https://github.com/GarageGames/Torque3D/issues) and quickly make sure someone else hasn't obviously reported it.
+If you're not sure if it's the same issue, go ahead and comment on it!
+Once you're certain you've found a new issue, hit the [big green button](https://github.com/GarageGames/Torque3D/issues/new) and please include the following information:
+
+ * Your platform and compiler, if you're not using a precompiled binary
+ * Steps to reproduce the issue, if _at all_ possible
+ * If it's related to graphics, your GFX card and driver details.
+
+## Create a pull-request
+
+We ask that potential contributors read our [pull-request guidelines](http://torque3d.org/contribute/#pull-request-guide) before opening a PR.
+We also have some [code style guidelines](https://github.com/GarageGames/Torque3D/wiki/Code-Style-Guidelines).
+Here's a quick guide to the branches in this repo that you might think of targeting a PR at:
+
+### The master branch
+
+The repository's `master` branch is where we make releases.
+It's supposed to be stable at all times - or as stable as we can make it - and only gets updated when a new version comes out.
+Any pull-requests to the master branch will have to be rejected - sorry :(.
+
+### The development branch
+
+The `development` branch is where most development happens.
+It is the target for the next 'middle' version of the engine (the 6 in 3.6.1, for example).
+This means we will add new features, and refactor code if it doesn't break existing games made with the engine _too_ much*.
+Most pull requests to `development` can be accepted if we like your code - unless they would potentially break users' games.
+
+*How much is _too_ much is for the Steering Committee to decide.
+
+### The development-3.6 branch
+
+The `development-3.6` branch is where we will make bugfixes and small patches to the previous stable 'middle' version.
+This branch is where the 'small' versions will be created - 3.6.2, 3.6.3, etcetera.
+So if you have a bugfix or tiny enhancement that doesn't require anyone to change their game, it'd be best appreciated in this branch.
+
+### TLDR
+
+Don't make any PRs to `master`.
+PR new features and large fixes/refactorings to `development`.
+PR bugfixes to `development-3.6`.
+
+## Request a feature
+
+We ask that all feature requests be discussed in the [GarageGames forums](http://www.garagegames.com/community/forums), our [IRC channel](http://torque3d.wikidot.com/community:chat), or on our [UserVoice feature request voting page](https://garagegames.uservoice.com/forums/178972-torque-3d-mit/filters/top) before making an issue here.
+If your idea is popular, we'll hear of it and probably make an issue ourselves, if we agree.
+
+Even better - don't request a feature, start working on it!
+This engine isn't going to improve itself ;).

+ 27 - 0
Engine/lib/bullet/.travis.yml

@@ -0,0 +1,27 @@
+language: cpp
+os:
+  - linux
+  - osx
+compiler:
+  - gcc
+  - clang
+addons:
+  apt:
+    packages:
+      - python3
+
+script:
+  - echo "CXX="$CXX
+  - echo "CC="$CC
+  - cmake . -DBUILD_PYBULLET=ON -G"Unix Makefiles" #-DCMAKE_CXX_FLAGS=-Werror
+  - make -j8
+  - ctest -j8 --output-on-failure
+  # Build again with double precision
+  - cmake . -G "Unix Makefiles" -DUSE_DOUBLE_PRECISION=ON #-DCMAKE_CXX_FLAGS=-Werror
+  - make -j8
+  - ctest -j8 --output-on-failure
+  # Build again with shared libraries
+  - cmake . -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON
+  - make -j8
+  - ctest -j8 --output-on-failure
+  - sudo make install

+ 0 - 22
Engine/lib/bullet/AUTHORS

@@ -1,22 +0,0 @@
-
-Bullet Physics Library is an open source project with help from the community at the Physics Forum
-See the forum at http://bulletphysics.com
-
-The project was started by Erwin Coumans
-
-Following people contributed to Bullet
-(random order, please let us know on the forum if your name should be in this list)
-
-Gino van den Bergen: LinearMath classes
-Christer Ericson: parts of the voronoi simplex solver
-Simon Hobbs: 3d axis sweep and prune, Extras/SATCollision, separating axis theorem + SIMD code
-Dirk Gregorius: generic D6 constraint
-Erin Catto: accumulated impulse in sequential impulse
-Nathanael Presson: EPA penetration depth calculation
-Francisco Leon: GIMPACT Concave Concave collision
-Joerg Henrichs: make buildsystem (work in progress)
-Eric Sunshine: jam + msvcgen buildsystem
-Steve Baker: GPU physics and general implementation improvements
-Jay Lee: Double precision support
-KleMiX, aka Vsevolod Klementjev, managed version, rewritten in C# for XNA
-Erwin Coumans: most other source code

+ 40 - 0
Engine/lib/bullet/AUTHORS.txt

@@ -0,0 +1,40 @@
+Bullet Physics is created by Erwin Coumans with contributions from the following authors / copyright holders:
+
+AMD
+Apple
+Steve Baker
+Gino van den Bergen
+Nicola Candussi
+Erin Catto
+Lawrence Chai
+Erwin Coumans
+Christer Ericson
+Disney Animation
+Google
+Dirk Gregorius
+Marcus Hennix
+MBSim Development Team
+Takahiro Harada
+Simon Hobbs
+John Hsu
+Ole Kniemeyer
+Jay Lee
+Francisco Leon
+Vsevolod Klementjev
+Phil Knight
+John McCutchan
+Steven Peters
+Roman Ponomarev
+Nathanael Presson
+Gabor PUHR
+Arthur Shek
+Russel Smith
+Sony
+Jakub Stephien
+Marten Svanfeldt
+Pierre Terdiman
+Steven Thompson
+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

+ 25 - 0
Engine/lib/bullet/BulletConfig.cmake.in

@@ -0,0 +1,25 @@
+#                                               -*- cmake -*-
+#
+#  BulletConfig.cmake(.in)
+#
+
+# Use the following variables to compile and link against Bullet:
+#  BULLET_FOUND              - True if Bullet was found on your system
+#  BULLET_USE_FILE           - The file making Bullet usable
+#  BULLET_DEFINITIONS        - Definitions needed to build with Bullet
+#  BULLET_INCLUDE_DIR        - Directory where Bullet-C-Api.h can be found
+#  BULLET_INCLUDE_DIRS       - List of directories of Bullet and it's dependencies
+#  BULLET_LIBRARIES          - List of libraries to link against Bullet library
+#  BULLET_LIBRARY_DIRS       - List of directories containing Bullet' libraries
+#  BULLET_ROOT_DIR           - The base directory of Bullet
+#  BULLET_VERSION_STRING     - A human-readable string containing the version
+
+set ( BULLET_FOUND 1 )
+set ( BULLET_USE_FILE     "@BULLET_USE_FILE@" )
+set ( BULLET_DEFINITIONS  "@BULLET_DEFINITIONS@" )
+set ( BULLET_INCLUDE_DIR  "@INCLUDE_INSTALL_DIR@" )
+set ( BULLET_INCLUDE_DIRS "@INCLUDE_INSTALL_DIR@" )
+set ( BULLET_LIBRARIES    "@BULLET_LIBRARIES@" )
+set ( BULLET_LIBRARY_DIRS "@LIB_DESTINATION@" )
+set ( BULLET_ROOT_DIR     "@CMAKE_INSTALL_PREFIX@" )
+set ( BULLET_VERSION_STRING "@BULLET_VERSION@" )

+ 0 - 17
Engine/lib/bullet/BulletLicense.txt

@@ -1,17 +0,0 @@
-/*
-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.
-*/
-
-
-Free for commercial use, but please mail [email protected] to report projects, and join the forum at
-www.continuousphysics.com/Bullet/phpBB2

BIN
Engine/lib/bullet/Bullet_Faq.pdf


+ 318 - 38
Engine/lib/bullet/CMakeLists.txt

@@ -1,72 +1,352 @@
-cmake_minimum_required(VERSION 2.4)
+cmake_minimum_required(VERSION 2.4.3)
+set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
+
+#this line has to appear before 'PROJECT' in order to be able to disable incremental linking
+SET(MSVC_INCREMENTAL_DEFAULT ON)
 
 
 PROJECT(BULLET_PHYSICS)
 PROJECT(BULLET_PHYSICS)
-SET(BULLET_VERSION 2.75)
+SET(BULLET_VERSION 2.85)
+
+IF(COMMAND cmake_policy)
+   cmake_policy(SET CMP0003 NEW)
+   if(POLICY CMP0042)
+      # Enable MACOSX_RPATH by default.
+      cmake_policy(SET CMP0042 NEW)
+   endif(POLICY CMP0042)
+ENDIF(COMMAND cmake_policy)
+
 
 
 IF (NOT CMAKE_BUILD_TYPE)
 IF (NOT CMAKE_BUILD_TYPE)
 # SET(CMAKE_BUILD_TYPE "Debug")
 # SET(CMAKE_BUILD_TYPE "Debug")
  SET(CMAKE_BUILD_TYPE "Release")
  SET(CMAKE_BUILD_TYPE "Release")
-ENDIF (NOT CMAKE_BUILD_TYPE) 
+ENDIF (NOT CMAKE_BUILD_TYPE)
+
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
+#MESSAGE("CMAKE_CXX_FLAGS_DEBUG="+${CMAKE_CXX_FLAGS_DEBUG})
+
+OPTION(USE_DOUBLE_PRECISION "Use double precision"	OFF)
+OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
+OPTION(BUILD_SHARED_LIBS "Use shared libraries" OFF)
+OPTION(USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD "Use btSoftMultiBodyDynamicsWorld" OFF)	
+OPTION(BULLET2_USE_THREAD_LOCKS "Build Bullet 2 libraries with mutex locking around certain operations" OFF)
+
+OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
+OPTION(USE_CUSTOM_VECTOR_MATH "Use custom vectormath library" OFF)
+
+#statically linking VC++ isn't supported for WindowsPhone/WindowsStore
+IF (CMAKE_SYSTEM_NAME STREQUAL WindowsPhone OR CMAKE_SYSTEM_NAME STREQUAL WindowsStore)
+	OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" ON)
+ELSE ()
+	OPTION(USE_MSVC_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" OFF)
+ENDIF (CMAKE_SYSTEM_NAME STREQUAL WindowsPhone OR CMAKE_SYSTEM_NAME STREQUAL WindowsStore)
+
+#SET(CMAKE_EXE_LINKER_FLAGS_INIT    "/STACK:10000000 /INCREMENTAL:NO")
+#SET(CMAKE_EXE_LINKER_FLAGS    "/STACK:10000000 /INCREMENTAL:NO")
+
+#MESSAGE("MSVC_INCREMENTAL_YES_FLAG"+${MSVC_INCREMENTAL_YES_FLAG})
+
+
+IF(MSVC)
+	IF (NOT USE_MSVC_INCREMENTAL_LINKING)
+		#MESSAGE("MSVC_INCREMENTAL_DEFAULT"+${MSVC_INCREMENTAL_DEFAULT})
+		SET( MSVC_INCREMENTAL_YES_FLAG "/INCREMENTAL:NO")
+
+		STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags ${CMAKE_EXE_LINKER_FLAGS_DEBUG})
+		SET(CMAKE_EXE_LINKER_FLAGS_DEBUG "/INCREMENTAL:NO ${replacementFlags}" )
+		MESSAGE("CMAKE_EXE_LINKER_FLAGS_DEBUG=${CMAKE_EXE_LINKER_FLAGS_DEBUG}")
+
+		STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags2 ${CMAKE_EXE_LINKER_FLAGS})
+
+		SET(CMAKE_EXE_LINKER_FLAGS ${replacementFlag2})
+		STRING(REPLACE "INCREMENTAL:YES" "" replacementFlags3 "${CMAKE_EXTRA_LINK_FLAGS}")
+
+		SET(CMAKE_EXTRA_LINK_FLAGS ${replacementFlag3})
+
+
+		STRING(REPLACE "INCREMENTAL:YES" "INCREMENTAL:NO" replacementFlags3 "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")
+		SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO ${replacementFlags3})
+		SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/INCREMENTAL:NO ${replacementFlags3}" )
+
+	ENDIF (NOT USE_MSVC_INCREMENTAL_LINKING)
+
+	IF (NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
+		#We statically link to reduce dependancies
+		FOREACH(flag_var CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO )
+			IF(${flag_var} MATCHES "/MD")
+				STRING(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
+			ENDIF(${flag_var} MATCHES "/MD")
+			IF(${flag_var} MATCHES "/MDd")
+				STRING(REGEX REPLACE "/MDd" "/MTd" ${flag_var} "${${flag_var}}")
+			ENDIF(${flag_var} MATCHES "/MDd")
+		ENDFOREACH(flag_var)
+	ENDIF (NOT USE_MSVC_RUNTIME_LIBRARY_DLL)
+
+	IF (CMAKE_CL_64)
+	  ADD_DEFINITIONS(-D_WIN64)
+	ELSE()
+	  OPTION(USE_MSVC_SSE "Use MSVC /arch:sse option"	ON)
+	  IF (USE_MSVC_SSE)
+		  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE")
+	  ENDIF()
+	ENDIF()
+	OPTION(USE_MSVC_FAST_FLOATINGPOINT "Use MSVC /fp:fast option"	ON)
+	IF (USE_MSVC_FAST_FLOATINGPOINT)
+		  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
+  ENDIF()
+
+	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267")
+ENDIF(MSVC)
+
+
+
+IF (WIN32)
+OPTION(INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES "Create MSVC projectfiles that can be distributed" OFF)
+
+IF (INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
+	SET (LIBRARY_OUTPUT_PATH ${BULLET_PHYSICS_SOURCE_DIR}/lib CACHE PATH "Single output directory for building all libraries.")
+	SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR})
+	SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${BULLET_PHYSICS_SOURCE_DIR})
+	SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${BULLET_PHYSICS_SOURCE_DIR})
+	SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${BULLET_PHYSICS_SOURCE_DIR})
+	SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${BULLET_PHYSICS_SOURCE_DIR})
+ELSE()
+	SET (LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib CACHE PATH "Single output directory for building all libraries.")
+ENDIF()
+
+
+
+OPTION(INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES "Create MSVC projectfiles with relative paths" OFF)
+OPTION(INTERNAL_ADD_POSTFIX_EXECUTABLE_NAMES "Add MSVC postfix for executable names (_Debug)" OFF)
+
+SET(CMAKE_DEBUG_POSTFIX "_Debug" CACHE STRING "Adds a postfix for debug-built libraries.")
+SET(CMAKE_MINSIZEREL_POSTFIX "_MinsizeRel" CACHE STRING "Adds a postfix for MinsizeRelease-built libraries.")
+SET(CMAKE_RELWITHDEBINFO_POSTFIX "_RelWithDebugInfo" CACHE STRING "Adds a postfix for ReleaseWithDebug-built libraries.")
+
+
+
+
+
+IF (INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES)
+SET(CMAKE_SUPPRESS_REGENERATION  1)
+SET(CMAKE_USE_RELATIVE_PATHS 1)
+ENDIF(INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES)
+
+ENDIF (WIN32)
+
+
+OPTION(BUILD_CPU_DEMOS "Build original Bullet CPU examples" ON)
+
+
+
+OPTION(INTERNAL_UPDATE_SERIALIZATION_STRUCTURES "Internal update serialization structures" OFF)
+IF (INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
+ADD_DEFINITIONS( -DBT_INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
+ENDIF (INTERNAL_UPDATE_SERIALIZATION_STRUCTURES)
+
+IF (USE_DOUBLE_PRECISION)
+ADD_DEFINITIONS( -DBT_USE_DOUBLE_PRECISION)
+SET( BULLET_DOUBLE_DEF "-DBT_USE_DOUBLE_PRECISION")
+ENDIF (USE_DOUBLE_PRECISION)
+
+IF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD)
+ADD_DEFINITIONS(-DUSE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD)
+ENDIF (USE_SOFT_BODY_MULTI_BODY_DYNAMICS_WORLD)
+
+IF(USE_GRAPHICAL_BENCHMARK)
+ADD_DEFINITIONS( -DUSE_GRAPHICAL_BENCHMARK)
+ENDIF (USE_GRAPHICAL_BENCHMARK)
+
+IF(BULLET2_USE_THREAD_LOCKS)
+	ADD_DEFINITIONS( -DBT_THREADSAFE=1 )
+	IF (NOT MSVC)
+		SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
+	ENDIF (NOT MSVC)
+ENDIF (BULLET2_USE_THREAD_LOCKS)
+
+IF (WIN32)
+OPTION(USE_GLUT "Use Glut"	ON)
+ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
+ADD_DEFINITIONS( -D_CRT_SECURE_NO_DEPRECATE )
+ADD_DEFINITIONS( -D_SCL_SECURE_NO_WARNINGS )
+
+IF (USE_GLUT AND MSVC)
+	string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+	remove_definitions(-D_WINDOWS )
+ENDIF()
+
+
+
+ELSE(WIN32)
+OPTION(USE_GLUT "Use Glut"	ON)
+ENDIF(WIN32)
+
 
 
-# string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
-remove_definitions(-D_WINDOWS )
-   
 IF(COMMAND cmake_policy)
 IF(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
    cmake_policy(SET CMP0003 NEW)
 ENDIF(COMMAND cmake_policy)
 ENDIF(COMMAND cmake_policy)
-   
+
 
 
 # This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system
 # This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system
 # This should be the case.
 # This should be the case.
 
 
 FIND_PACKAGE(OpenGL)
 FIND_PACKAGE(OpenGL)
 IF (OPENGL_FOUND)
 IF (OPENGL_FOUND)
-MESSAGE("OPENGL FOUND")
-MESSAGE(${OPENGL_LIBRARIES})
+	MESSAGE("OPENGL FOUND")
+	MESSAGE(${OPENGL_LIBRARIES})
 ELSE (OPENGL_FOUND)
 ELSE (OPENGL_FOUND)
-MESSAGE("OPENGL NOT FOUND")
-SET(OPENGL_gl_LIBRARY opengl32)
-SET(OPENGL_glu_LIBRARY glu32)
+	MESSAGE("OPENGL NOT FOUND")
+	SET(OPENGL_gl_LIBRARY opengl32)
+	SET(OPENGL_glu_LIBRARY glu32)
 ENDIF (OPENGL_FOUND)
 ENDIF (OPENGL_FOUND)
 
 
-# ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
 
 
-FIND_PACKAGE(GLU)
+#FIND_PACKAGE(GLU)
 
 
-FIND_PACKAGE(GLUT)
-IF (GLUT_FOUND)
-MESSAGE("GLUT FOUND")
-MESSAGE(${GLUT_glut_LIBRARY})
-ELSE (GLUT_FOUND)
 
 
-IF (MINGW)
-MESSAGE ("GLUT NOT FOUND not found, trying to use MINGW glut32")
-SET(GLUT_glut_LIBRARY glut32)
-ENDIF (MINGW)
+IF (APPLE)
+  FIND_LIBRARY(COCOA_LIBRARY Cocoa)
+ENDIF()
 
 
-IF (MSVC)
-MESSAGE ("GLUT NOT FOUND, trying to use Bullet/Glut/glut32.lib for MSVC")
-SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib)
-ENDIF (MSVC)
-ENDIF (GLUT_FOUND)
+OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON)
 
 
+OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF)
 
 
-IF (WIN32)
-  INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/Glut)
-ELSE (WIN32)
-  # This is the lines for linux.  This should always work if everything is installed and working fine.
-  INCLUDE_DIRECTORIES(/usr/include /usr/local/include ${GLUT_INCLUDE_DIR}) 
-ENDIF (WIN32)
+
+IF(BUILD_PYBULLET)
+
+	FIND_PACKAGE(PythonLibs)
+
+	OPTION(BUILD_PYBULLET_NUMPY "Set when you want to build pybullet with NumPy support" OFF)
+	OPTION(BUILD_PYBULLET_ENET "Set when you want to build pybullet with enet UDP networking support" ON)
+	
+	IF(BUILD_PYBULLET_NUMPY)	
+		set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/build3/cmake)
+		#include(FindNumPy)
+		FIND_PACKAGE(NumPy)
+		if (PYTHON_NUMPY_FOUND)
+			message("NumPy found")
+			add_definitions(-DPYBULLET_USE_NUMPY)
+		else()
+			message("NumPy not found")
+		endif()
+	ENDIF()
+	OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF)
+
+	IF(WIN32)
+		SET(BUILD_SHARED_LIBS OFF CACHE BOOL "Shared Libs" FORCE)
+	ELSE(WIN32)
+		SET(BUILD_SHARED_LIBS ON CACHE BOOL "Shared Libs" FORCE)
+	ENDIF(WIN32)
+ENDIF(BUILD_PYBULLET)
+
+IF(BUILD_BULLET3)
+	 IF(APPLE)
+		MESSAGE("Mac OSX Version is ${_CURRENT_OSX_VERSION}")
+		IF(_CURRENT_OSX_VERSION  VERSION_LESS 10.9)
+			MESSAGE("Mac OSX below 10.9 has no OpenGL 3 support so please disable the BUILD_OPENGL3_DEMOS option")
+			#unset(BUILD_OPENGL3_DEMOS CACHE)
+
+			OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" OFF)
+		ELSE()
+			OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build the OpenGL3+ demos" ON)
+		ENDIF()
+	ELSE()
+		OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build Bullet 3 OpenGL3+ demos" ON)
+	ENDIF()
+ELSE(BUILD_BULLET3)
+	unset(BUILD_OPENGL3_DEMOS CACHE)
+	OPTION(BUILD_OPENGL3_DEMOS "Set when you want to build Bullet 3 OpenGL3+ demos" OFF)
+ENDIF(BUILD_BULLET3)
+IF(BUILD_OPENGL3_DEMOS)
+	IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos3)
+		SUBDIRS(Demos3)
+	ENDIF()
+ELSE()
+	ADD_DEFINITIONS(-DNO_OPENGL3)
+ENDIF(BUILD_OPENGL3_DEMOS)
+
+OPTION(BUILD_BULLET2_DEMOS "Set when you want to build the Bullet 2 demos" ON)
+IF(BUILD_BULLET2_DEMOS)
+
+	IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/examples AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/examples)
+		SUBDIRS(examples)
+	ENDIF()
+
+        IF (BULLET2_USE_THREAD_LOCKS)
+            OPTION(BULLET2_MULTITHREADED_OPEN_MP_DEMO "Build Bullet 2 MultithreadedDemo using OpenMP (requires a compiler with OpenMP support)" OFF)
+            OPTION(BULLET2_MULTITHREADED_TBB_DEMO "Build Bullet 2 MultithreadedDemo using Intel Threading Building Blocks (requires the TBB library to be already installed)" OFF)
+            IF (MSVC)
+                OPTION(BULLET2_MULTITHREADED_PPL_DEMO "Build Bullet 2 MultithreadedDemo using Microsoft Parallel Patterns Library (requires MSVC compiler)" OFF)
+            ENDIF (MSVC)
+        ENDIF (BULLET2_USE_THREAD_LOCKS)
+
+ENDIF(BUILD_BULLET2_DEMOS)
 
 
 
 
-OPTION(BUILD_DEMOS "Set when you want to build the demos" ON)
-IF(BUILD_DEMOS)
-  SUBDIRS(Demos)
-ENDIF(BUILD_DEMOS)
 
 
 OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
 OPTION(BUILD_EXTRAS "Set when you want to build the extras" ON)
 IF(BUILD_EXTRAS)
 IF(BUILD_EXTRAS)
   SUBDIRS(Extras)
   SUBDIRS(Extras)
 ENDIF(BUILD_EXTRAS)
 ENDIF(BUILD_EXTRAS)
 
 
+
+#Maya Dynamica plugin is moved to http://dynamica.googlecode.com
+
 SUBDIRS(src)
 SUBDIRS(src)
+
+IF("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles")
+	OPTION(INSTALL_LIBS "Set when you want to install libraries" ON)
+ELSE()
+	IF(APPLE AND FRAMEWORK)
+		OPTION(INSTALL_LIBS "Set when you want to install libraries" ON)
+	ELSE()
+#by default, don't enable the 'INSTALL' option for Xcode and MSVC projectfiles
+		OPTION(INSTALL_LIBS "Set when you want to install libraries" OFF)
+	ENDIF()
+ENDIF()
+
+IF(INSTALL_LIBS)
+	SET (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
+	SET (LIB_DESTINATION "lib${LIB_SUFFIX}" CACHE STRING "Library directory name")
+	## the following are directories where stuff will be installed to
+	SET(INCLUDE_INSTALL_DIR "include/bullet/" CACHE PATH "The subdirectory to the header prefix")
+	SET(PKGCONFIG_INSTALL_PREFIX "lib${LIB_SUFFIX}/pkgconfig/" CACHE STRING "Base directory for pkgconfig files")
+	IF(NOT MSVC)
+	  CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/bullet.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/bullet.pc @ONLY)
+  	INSTALL(
+		FILES
+		${CMAKE_CURRENT_BINARY_DIR}/bullet.pc
+		DESTINATION
+		${PKGCONFIG_INSTALL_PREFIX})
+	ENDIF(NOT MSVC)
+ENDIF(INSTALL_LIBS)
+
+#INSTALL of other files requires CMake 2.6
+IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
+	OPTION(INSTALL_EXTRA_LIBS "Set when you want extra libraries installed" OFF)
+ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
+
+OPTION(BUILD_UNIT_TESTS "Build Unit Tests"	ON)
+
+IF (BUILD_UNIT_TESTS)
+	ENABLE_TESTING()
+	SUBDIRS(test)
+ENDIF()
+
+set (BULLET_CONFIG_CMAKE_PATH lib${LIB_SUFFIX}/cmake/bullet )
+list (APPEND BULLET_LIBRARIES LinearMath)
+IF(BUILD_BULLET3)
+    list (APPEND BULLET_LIBRARIES BulletInverseDynamics)
+ENDIF(BUILD_BULLET3)
+list (APPEND BULLET_LIBRARIES BulletCollision)
+list (APPEND BULLET_LIBRARIES BulletDynamics)
+list (APPEND BULLET_LIBRARIES BulletSoftBody)
+set (BULLET_USE_FILE ${BULLET_CONFIG_CMAKE_PATH}/UseBullet.cmake)
+configure_file 	( ${CMAKE_CURRENT_SOURCE_DIR}/BulletConfig.cmake.in
+					${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake
+					@ONLY ESCAPE_QUOTES
+				)
+install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/UseBullet.cmake
+		${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake
+		DESTINATION ${BULLET_CONFIG_CMAKE_PATH}
+	)

+ 0 - 745
Engine/lib/bullet/ChangeLog

@@ -1,745 +0,0 @@
-Bullet Continuous Collision Detection and Physics Library
-Primary author and maintainer: Erwin Coumans
-
-Please see http://code.google.com/p/bullet/source/list for more complete log in Subversion
-
-2009 September 17
-	- Minor update to Bullet 2.75 release, revision 1770
-	- Support for btConvex2dShape, check out Bullet/Demos/Box2dDemo
-	- Minor fix in btGjkPairDetector
-	- Initialize world transform for btCollisionShape in constructor
-
-
-2009 September 6
-	- Bullet 2.75 release
-	- Added SPH fluid simulation in Extras, not integrated with rigid body / soft body yet
-	Thanks to Rama Hoetzlein to make this contribution available under the ZLib license
-	- add special capsule-capsule collider code in btConvexConvexCollisionAlgorithm, to speed up capsule-ragdolls
-	- soft body improvement: faster building of bending constraints
-	- soft body improvement: allow to disable/enable cluster self-collision
-	- soft body fix: 'exploding' soft bodies when using cluster collision
-	- fix some degenerate cases in continuous convex cast, could impact ray cast/convex cast
-	Thanks to Jacob Langford for the report and reproduction cases, see http://code.google.com/p/bullet/issues/detail?id=250&can=1&start=200
-	- re-enabled split impulse
-	- added btHinge2Constraint, btUniversalConstraint, btGeneric6DofSpringConstraint
-	- demonstrate 2D physics with 2D/3D object interaction
-	
-
-2008 December 2
-	- Fix contact refresh issues with btCompoundShape, introduced with btDbvt acceleration structure in btCompoundCollisionAlgorithm
-	- Made btSequentialImpulseConstraintSolver 100% compatible with ODE quickstep
-	constraints can use 'solveConstraint' method or 'getInfo/getInfo2'
-
-2008 November 30
-	- Add highly optimized SIMD branchless PGS/SI solver innerloop 
-
-2008 November 12
-	- Add compound shape export to BulletColladaConverter
-	Thanks to JamesH for the report: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=12&t=2840
-	- Fix compiler build for Visual Studio 6
-	Thanks to JoF for the report: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2841
-
-2008 November 11
-	- Add CProfileManager::dumpAll() to dump performance statistics to console using printf.
-	- Add support for interaction between btSoftBody and btCollisionObject/btGhostObject
-
-2008 November 8
-	- Fix PosixThreadSupport
-	- Add improved btHeightfieldTerrainShape support and new Demos/TerrainDemo
-	Thanks to tomva, http://code.google.com/p/bullet/issues/detail?id=63&can=1
-	- Moved kinematic character controller from Demos/CharacterDemo into src/BulletDynamics/Character/btKinematicCharacterController.cpp
-
-2008 November 6
-	- reduced default memory pool allocation from 40Mb to 3Mb. This should be more suitable for all platforms, including iPhone
-	- improved CUDA broadphase
-	- IBM Cell SDK 3.x support, fix ibmsdk Makefiles
-	- improved CMake support with 'install' and 'framework option
-	
-2008 November 4
-	- add btAxisSweep::resetPool to avoid non-determinism due to shuffled linked list
-	Thanks to Ole for the contribution, 
-
-2008 October 30
-	- disabled btTriangleMesh duplicate search by default, it is extremely slow
-	- added Extras/IFF binary chunk serialization library as preparation for in-game native platform serialization (planned COLLADA DOM -> IFF converter)
-
-2008 October 20
-	- added SCE Physics Effects box-box collision detection for SPU/BulletMultiThreaded version
-	See Bullet/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/boxBoxDistance.cpp
-	Thanks to Sony Computer Entertainment Japan, SCEI for the contribution
-
-2008 October 17
-	- Added btGhostObject support, this helps character controller, explosions, triggers and other local spatial queries
-
-2008 October 10
-	- Moved aabb to btBroadphaseProxy, improves rayTest dramatically. Further raytest improvements using the broadphase acceleration structures are planned
-	- Moved BulletMultiThreaded from Extras to /src/BulletMultiThreaded for better integration
-
-
-2008 October 3
-	- Add support for autoconf automake
-	./autogen.sh and ./configure will create both Makefile and Jamfile. CMake and autogenerated Visual Studio projectfiles remain supported too.
-	- Improved ColladaConverter: plane shape export, and callback for shape construction to allow deletion of memory
-	
-2008 Sept 30
-	- Improved Soft Body support, fixed issues related to soft body colliding against concave triangle meshes
-	- Shared more code between regular version and SPU/BulletMultiThreaded, in particular GJK/EPA
-
-2008 Sept 28
-	- Fixed rotation issues in Dynamic Maya Plugin
-
-2008 Sept 11
-	- Enable CCD motion clamping for btDiscreteDynamicsWorld, to avoid tunneling. A more advanced solution will be implemented in btContinuousDynamicsWorld.
-
-2008 Sept 7
-	- Add btScaledBvhTriangleMeshShape, to allow re-use of btBvhTriangleMeshShape of different sizes, without copying of the BVH data.
-
-2008 Sept 5
-	- Enabled Demos/ForkLiftDemo
-	Thanks Roman Ponomarev.
-
-2008 Sept 4
-	- Added btCudaBroadphase in Extras/CUDA: some research into accelerating Bullet using CUDA.
-	Thanks to the particle demo from the NVidia CUDA SDK.
-	
-2008 Sept 3
-	- Several bug fixes and contributions related to inertia tensor, memory leaks etc.
-	Thanks to Ole K.
-
-2008 Sept 1
-	- Updated CDTestFramework, with latest version of OPCODE Array SAP. See Extras/CDTestFramework
-	Thanks to Pierre Terdiman for the update
-
-2008 August 25
-	- Walt Disney Studios contributes their in-house Maya Plugin for simulating Bullet physics, with options for other engines such as PhysBam or PhysX.
-	Thanks to Nicola Candussi and Arthur Shek
-	
-2008 August 14
-	- Improved performance for btDbvtBroadphase, based on dual dynamic AABB trees (one for static, one for dynamic objects, where objects can move from one to the other tree)
-	Thanks to Nathanael Presson again, for all his work.
-	
-2008 July 31
-	- Added Havok .hkx to COLLADA Physics .dae converter patch+information
-	- Fix btSubsimplexConvexCast
-	Thanks to Nacho, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2422)
-	- Fix in rendering, GL_STENCIL
-	- btTriangleIndexVertexArray indices should be unsigned int/unsigned short int,
-	- Made InternalProcessAllTriangles virtual, thanks to
-	Both thank to Fullmetalcoder, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2401
-	- clamp impulse for btPoint2PointConstraint
-	Thanks to Martijn Reuvers, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2418
-	- Free memory of bvh, pass in scaling factor (optional)
-	Thanks to Roy Eltham, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=2375
-
-2008 July 27
-
-btDbvtBroadphase:
-	- Fixed a performance issues reported by 'reltham'
-	- Added btDbvtBroadphase::optimize() for people who want good performances right
-away or don't do dynamics.
-	- fixed compilation issues when DBVT_BP_PROFILE was set.
-btSoftBody:
-	- Fixed singular matrix issues related to polar decomposition (flat meshes).
-DemoApplication:
-	- Shadows (enable/disable through 'g' or DemoApplication::setShadows(bool)).
-	- Texture can be enable/disable through 'u'
-CDFramework:
-	- fixed compilation issues.
-	All thanks to Nathanael Presson
-
-2008 July 10
-	- Added btMultimaterialTriangleMeshShape and MultiMaterialDemo
-	Thanks to Alex Silverman for the contribution
-
-2008 June 30
-	- Added initial support for kinematic character controller
-	Thanks to John McCutchan
-
-2008 April 14
-	- Added ray cast support for Soft Bodies
-	Thanks to Nathanael Presson for the contribution
-	
-2008 April 9
-	- Cleanup of Stan Melax ConvexHull, removed Extras/ConvexHull, moved sources into LinearMath/BulletCollision
-
-2008 April 4
-	- Added btSliderConstraint and demo
-	Thanks Roman Ponomarev
-	
-2008 April 3
-	- Fixed btMinkowskiSumShape, and added hitpoint to btSubsimplexConvexCast
-
-2008 April 2
-	- Added Extras/CdTestFrameWork
-	Thanks Pierre Terdiman
-
-2008 April 1
-	- Added posix thread (pthread) support
-	Thanks Enrico
-
-2008 March 30
-	- Added Soft Body, cloth, rope and deformable volumes, including demos and interaction
-	Thanks Nathanael Presson for this great contribution
-	
-	2008 March 17
-	- Improved BulletColladaConverter
-	Thanks John McCutchan
-
-2008 March 15
-	- btMultiSapBroadphase in a working state. Needs more optimizations to be fully useable.
-	- Allow btOptimizedBvh to be used for arbitrary objects, not just triangles
-	- added quicksort to btAlignedObjectArray
-	- removed btTypedUserInfo, added btHashMap
-
-2008 March 30
-	- Moved quickstep solver and boxbox into Bullet/src folder
-	Thanks Russell L. Smith for permission to redistribute Open Dynamics Engine quickstep and box-box under the ZLib license	
-
-2008 Feb 27
-	- Added initial version for Character Control Demo
-	- Applied fixes to IBM Cell SDK 3.0 build makefiles
-	Thanks Jochen and mojo for reporting/providing patch: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1922
-
-2008 Feb 8
-	- Bugfixes in ConvexCast support against the world.
-	Thanks to Isgmasa for reporting/providing fix: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1823
-
-2008 Feb 6
-	- Added btCapsuleShapeX and btCapsuleShapeZ for capsules around X and Z axis (default capsule is around Y)
-	
-2008 Feb 3
-	- Added btTypedUserInfo, useful for serialization
-
-2008 Jan 31
-	- Add support for 16 and 32-bit indices for SPU / BulletMultiThreaded version.
-
-2008 Jan 29
-	- Added COLLADA Physics export/serialization/snapshot from any Bullet btDynamicsWorld. Saving the physics world into a text .xml file is useful for debugging etc.
-
-2008 Jan 23
-	- Added Stan Melax Convex Hull utility library in Extras/ConvexHull. This is useful to render non-polyhedral convex objects, and to simplify convex polyhedra.
-	
-2008 Jan 14
-	- Add support for batch raycasting on SPU / BulletMultiThreaded
-	
-2007 Dec 16
-	- Added btRigidBodyConstructionInfo, to make it easier to set individual setting (and leave other untouched) during rigid body construction.
-	Thanks Vangelis Kokkevis for pointing this out.
-	- Fixed memoryleak in the ConstraintDemo and Raytracer demo.
-	- Fixed issue with clearing forces/gravity at the end of the stepSimulation, instead of during internalSingleStepSimulation.
-	Thanks chunky for pointing this out: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1780
-	- Disabled additional damping in rigid body by default, but enable it in most demos. Set btRigidBodyConstructionInfo m_additionalDamping to true to enable this.
-	- Removed obsolete QUICKPROF BEGIN/END_PROFILE, and enabled BT_PROFILE. Profiling is enabled by default (see Bullet/Demos/OpenGL/DemoApplication.cpp how to use this).
-	User can switch off profiling by enabling define BT_NO_PROFILE in Bullet/src/btQuickprof.h.
-
-2007 Dec 14
-	- Added Hello World and BulletMultiThreaded demos
-	- Add portable version of BulletMultiThreaded, through SequentialThreadSupport (non-parallel but sharing the same code-path)
-	- Add Cmake support for AllBulletDemos
-	
-
-2007 Dec 11
-	- Moved the 'btRigidBody::clearForce' to the end of the stepSimulation, instead of in each substep.
-	See discussion http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1601
-	- Added btConvexPlaneCollisionAlgorithm, makes planes perform better, and prevents tunneling
-	Thanks Andy O'Neil for reporting the performance/functionality issue
-	- Fixes for IBM Cell SDK 3.0
-	Thanks to Jochen Roth for the patch.
-
-2007 Dec 10
-	- Fixes in btHeightfieldTerrainShape
-	Thanks to Jay Lee for the patch.
-
-2007	Dec 9
-	- Only update aabb of active objects
-	Thanks Peter Tchernev for reporting (http://bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1764 )
-	- Added workaround to compile libxml under Visual Studio 2008 Beta 2
-	- Make glui compile under MSVC 9.0 beta (vsnprintf is already defined)
-
-2007 Dec 6
-	- Added DynamicControlDemo, showing dynamic control through constraint motors
-		Thanks to Eddy Boxerman
-	- Add support for generic concave shapes for convex cast.
-	- Added convex cast query to collision world.
-	- Added workaround for OpenGL bug in Mac OS X 10.5.0 (Leopard)
-	- Added concave raycast demo
-		All above thanks to John McCutchan (JMC)
-	- Fixed issues that prevent Linux version to compile. 
-	Thanks to Enrico for reporting and patch, see
-	- Fixed misleading name 'numTriangleIndices' into 'numTriangles'
-	Thanks Sean Tasker for reporting:
-
-2007 Nov 28:
-	- Added raycast against trianglemesh. Will be extended to object cast soon.
-	Thanks John McCutchan (JMC)
-	- make getNumPoints const correct, add const getPoints(). 
-	Thanks Dirk Gregorius
-	- Bugfix: allow btCollisionObjects (non-btRigidBody) to interact properly with btRigidBody for cache-friendly btSequentialImpulseConstraintSolver.
-	Thanks Andy O'Neil for pointing this out.
-	- Bugfix: don't fail if spheres have identical center, use arbitrary separating normal (1,0,0)
-	Thanks Sean Tasker for reporting! http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1681
-
-
-2007, November 20
-	- Added hierarchical profiling
-	- Fixed memory leak in btMultiSapBroadphase,
-	- Fixed hash function (typo, should use 2 proxies)
-	Thanks to Stephen (shatcher) for reporting and fixes! http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1696
-
-2007 Nov 11
-	- Fixed parallel solver (BulletMultiThreaded) friction issue
-	- Terminate Win32 Threads when closing the CcdPhysicsDemo (when USE_PARALLEL_SOLVER/USE_PARALLEL_DISPATCHER is defined)
-
-2007 Nov 6
-	- Added support for 16-bit indices for triangle meshes
-	- Added support for multiple mesh parts using btBvhTriangleMeshShape.
-	Thanks to Tim Johansson
-	
-2007 Oct 22
-	- All memory allocations go through btAlignedAlloc/btAlignedFree. User can override this to verify memory leaks
-	- added a few more demos to AllBulletDemos
-	- fix for one of the constructors of btHingeConstraint
-	Thanks Marcus Hennix
-	
-2007 Oct 20
-	- included glui, a GLUT/OpenGL based toolkit for some graphical user elements
-	Removed dynamic_cast from glui, to allow linkage without rtti
-	- added Box2D framework using glui, allowing all demos to run within one executable
-	Thanks Erin Catto for the FrameWork skeleton (http://www.box2d.org)
-
-2007 Ocy 17
-	- Allow user to pass in their own memory (stack and pool) allocators, through collisionConfiguration. See demos how to use this
-
-2007 Oct 14
-	- Included working version of Cell SPU parallel optimized version for Libspe2 SPU task scheduler.
-	This version compiles and runs on Playstation 3 Linux and IBM CellBlade, see BulletSpuOptimized.pdf for build instructions
-	(Official Playstation 3 developers can request a SPURS version through Sony PS3 Devnet.)
-	Thanks to IBM 'Extreme Blue' project for the contribution
-	http://www-913.ibm.com/employment/us/extremeblue/ 
-	Thanks Minh Cuong Tran, Benjamin Hoeferlin, Frederick Roth and Martina Huellmann
-	for various contributions to get this initial Libspe2 parallel version up and running.
-
-2007 Oct 13
-	- made 'btCollisionShape::calculateLocalInertia' const
-	Thanks to cgripeos, see http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1514
-	- applied a large patch to remove warnings
-	Thanks to Enrico, see http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1568
-	- removed SSE includes, added #incude <string.h> for memset in Extras/quickstep, thanks Eternl Knight
-
-2007 Oct 11
-	- added Hashed Overlapping Pair Cache, recommended by Pierre Terdiman. It works like a charm, thanks Pierre and Erin Catto (code from Box2D)
-	- modified some margins inside btBoxShape, btCylinderShape and btSphereShape
-	- added cone debug rendering (for cones with x, y and z up-axis)
-	- added improvements for optional Extra/quickstep, thanks to Remotion
-	- some performance improvements for Bullet constraint solver
-
-2007 Sept 28
-	- upgraded GIMPACT to version 0.3
-	Thanks to Francisco Leon
-
-2007 Sept 27
-	- added contribution from IBM Extreme Blue project for Libspe2 support. This allow to execute BulletMultiThreaded on Cell SPU under PS3 Linux and Cell Blade. See http://www-913.ibm.com/employment/us/extremeblue
-	Thanks to Minh Cuong Tran, Frederick Roth, Martina Heullmann and Benjamin Hoeferlin.
-
-2007 Sept 13
-	- Improved btGenericD6Constraint. It can be used to create ragdolls (similar to the new btConeTwistConstraint). See GenericJointDemo
-	- Added support for Bullet constraints in the optional Extras/quickstep ODE solver. See CcdPhysicsDemo, enable #COMPARE_WITH_QUICKSTEP and add libquickstep to the dependencies.
-	For both patches/improvements thanks Francisco Leon/projectileman
-		
-2007 Sept 10
-	- removed union from btQuadWordStorage, it caused issues under certain version of gcc/Linux
-
-2007 Sept 10
-	- Reverted constraint solver, due to some issues. Need to review the recent memory allocation changes.
-	- Fixed issue with kinematic objects rotating at low speed: quaternion was de-normalized, passing value > 1 into acosf returns #IND00 invalid values
-	- 16 byte memory alignment for BVH serialization
-	- memory cleanup for btPoolAllocator
-
-2007 Sept 9
-	- Added serialization for BVH/btBvhTriangleMeshShape, including endian swapping. See ConcaveDemo for an example.
-	Thanks to Phil Knight for the contribution.
-	- Fixed issues related to stack allocator/compound collision algorithm
-	Thanks Proctoid, http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=18&t=1460
-	- Increase some default memory pool settings, and added a fallback for the constraints solver to use heap memory
-	- Removed accidential testing code in btScalar.h related to operator new.	
-	- Enable btAxis3Sweep and bt32BitAxis3Sweep to be linked in at the same time, using template
-	
-2007 Sept 7
-	- Replaced several dynamic memory allocations by stack allocation and pool allocations
-	- Added branch-free quantized aabb bounding box overlap check, works better on Playstation 3 and XBox 360
-	Thanks to Phil Knight. Also see www.cellperformance.com for related articles
-	- Collision algorithms and settings for the memory/stack allocator can be done using btDefaultCollisionConfiguration
-	This is an API change. See demos how to modify existing implementations with a one-liner.
-	- Register several collision algorithms by default (sphere-sphere, sphere-box, sphere-triangle)
-	- Use other traveral method for BVH by default, this improves triangle mesh collision performance.
-	
-2007 Aug 31
-	- fixed MSVC 6 build
-	Thanks Proctoid, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1375
-	- fixed double precision build issues
-	Thanks Alex Silverman, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1434
-
-2007 Aug 24
-	- fixed bug in btMatrix3x3::transposeTimes(const btMatrix3x3& m) const. Luckily it wasn't used in core parts of the library (yet).
-	Thanks to Jay Lee
-	
-2007 Aug 15
-	- fixed bug in Extras/GIMPACT 0.2 related to moving triangle meshes
-	Thanks Thomas, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1368
-
-2007 Aug 14
-	- added parallel constraint solver. Works on Playstation 3 Cell SPU and multi core (Win Threads on PC and XBox 360).
-	  See Extras/BulletMultiThreaded for SpuSolverTask subfolder and SpuParallelSolver.cpp
-	  Thanks Marten Svanfeldt (Starbreeze Studios)	
-	- fixed some bugs related to parallel collision detection (Extras/BulletMultiThreaded)
-	  Thanks Marten Svanfeldt (Starbreeze Studios)	
-	
-2007 Aug 2
-	- added compound and concave-convex (swapped) case for BulletMultiThreaded collision detection, thanks to Marten Svanfeldt
-	- refactored broadphase and overlapping pair cache. This allows performance improvement by combining multiple broadphases. This helps add/remove of large batches of objects and large worlds. See also Pierre Terdiman forum topic:
-	http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1329
-
-
-2007 July 27
-	- added Ragdoll Demo
-		Thanks to Marten Svanfeldt (Starbreeze Studios)
-
-	- added Vector Math library for SIMD 3D graphics linear algebra (vector, matrix, quaternion)
-		See Bullet/Extras/vectormathlibrary
-		Supports SIMD SSE, PowerPC PPU and Cell SPU (including PS3 Linux and CellBlade), as well as generic portable scalar version
-		Will be used to improve BulletMultiThreaded performance
-		Open Sourced by Sony Computer Entertainment Inc. under the new BSD license
-	- added SIMD math library
-		4-way SIMD for common math functions like atan2f4, cosf4, floorf4, fabsf4, rsqrtf4 etc. Used by Vector Math library under PPU and SPU.
-		Supports PowerPC (PPU) and Cell SPU, including PS3 Linux and CellBlade.
-		See Bullet/Extras/simdmathlibrary
-		Open sourced by Sony Computer Entertainment Inc. under the new BSD license
-
-	
-2007 July 25
-	- added several patches: per-rigidbody sleeping threshold. added Assert to prevent deletion of rigidbody while constraints are still pointing at it
-		Thanks to Marten Svanfeldt (Starbreeze Studios)
-	
-2007 July 13
-	- fixed relative #include paths again. We can't use "../" relative paths: some compilers choke on it (it causes extreme long paths)
-		Within the libraries, we always need to start with "BulletCollision/" or "BulletDynamics/ or "LinearMath/"
-
-2007 July 10
-	- Updated Bullet User Manual
-
-2007 July 5
-	- added btConeTwistConstraint, especially useful for ragdolls. See Demos/RagdollDemo
-		Thanks to Marten Svanfeldt (Starbreeze Studios)
-
-2007 June 29
-	- btHeightfieldTerrainShape: Added heightfield support, with customizations
-	- Upgraded to GIMPACT 0.2, see Extras/GIMPACT and MovingConcaveDemo
-	- Several patches from Marten Svanfeldt (Starbreeze Studios)
-		Improved collision filtering (in broadphase and rigidbody)
-		Improved debug rendering
-		Allow to set collision filter group/mask in addRigidBody
-		
-		
-2007 June 15
-	- Changed btAlignedObjectArray to call copy constructor/replacement new for duplication, rather then assignment operator (operator=).
-
-2007 June 11
-	- Added multi-threading. Originally for Playstation 3 Cell SPU, but the same code can run using Win32 Threads using fake DMA transfers (memcpy)
-		Libspe2 support for Cell Blade / PS3 Linux is upcoming
-		See Extras/BulletMultiThreaded. Usage: replace btCollisionDispatcher by btSpuGatheringCollisionDispatcher
-
-	- Added managed Bullet library, entirely rewritten in C# for Windows and XBox 360 XNA
-		See Extras/BulletX
-		Thanks to KleMiX, aka Vsevolod Klementjev
-
-2007 May 31
-	- sign-bit went wrong in case of 32-bit broadphase, causing quantization problems. 
-		Thanks DevO for reporting.
-
-2007 May 23
-	- Fixed quantization problem for planar triangle meshes in btOptimizedBvh
-		Thanks Phil Knight for reporting and helping to fix this bug.
-		
-2007 May 20
-	- btAxisSweep3: Fixed a bug in btAxisSweep3 (sweep and prune) related to object removal. Only showed up when at least one btStaticPlaneShape was inserted.
-		Thanks tbp for more details on reproducing case.
-	- btAxisSweep3: Fixed issue with full 32bit precision btAxisSweep3 (define BP_USE_FIXEDPOINT_INT_32), it used only 0xffff/65536 for quantization instead of full integer space (0xffffffff)
-	- btRaycastVehicle: Added 'getForwardVector' and getCurrentSpeedKmHour utility functions
-	- Fixed local scaling issues (btConvexTriangleMeshShape, btBvhTriangleMeshShape, removed scaling from btMatrix3x3). 
-		Thanks Volker for reporting!
-	- Added second filename search, so that starting BspDemo and ConvexDecompositionDemo from within Visual Studio (without setting the starting path) still works
-
-2007 April 22
-	- Added braking functionality to btRaycastVehicle
-	- Removed tons of warnings, under MSVC 2005 compilation in -W4
-	
-2007 March 21
-	- Fixed issues: comma at end of enum causes errors for some compilers
-	- Fixed initialization bug in LocalRayResult (	m_localShapeInfo(localShapeInfo) )
-	
-2007 March 20
-	- Added refit tree to quantized stackless tree, and updated ConcaveDemo as example.
-	
-2007 March 17
-	- Added constraint solver optimizations, avoiding cross products during iterations, and gather rigidbody/constraint info in contiguous memory (btSolverBody/btSolverConstraint)
-	- These optimizations don't give large benefit yet, but it has good potential. Turned on by default. Can be switched off using solver->setSolverMode(SOLVER_RANDMIZE_ORDER).
-	- Enabled anti-jitter for rigid bodies. This is experimental, and can be switched off by setting a global (it is experimental so no proper interface) gJitterVelocityDampingFactor = 1.0;
-	- Fixed bug in islandmanifold.heapSort(btPersistentManifoldSortPredicate()); , thanks Noehrgel for reporting this (affected Sun Solaris)
-	
-2007 March 12
-	- Added compile-time toggle between on 16-bit and 32-bit fixed-point SAP broadphase. 
-		This allows the number of bodies to exceed 32767
-	- Enable useQuantizedAabbCompression on btTriangleMesh, see ColladaDemo
-	
-2007 March 8
-	- Fixed bug in constraint/island sorting (caused by replacing STL by dedicated btAlignedObjectArray with heapSort)
-		Thanks Clemens Unterkofler for pointing this out!
-
-2007 March 6
-	- removed STL from the Bullet library: replace std::vector by btAlignedObjectArray. Also removed the std::set for overlapping pair set, and turned it into an overlapping pair array. The SAP only adds objects, never removed. Removal is postponed for during traversal of overlapping pairs (duplicates and non-overlapping pairs are removed during that traversal).
-	- added heap sort and binary search/linear search to btAlignedObjectArray
-	- fixed wrong cast, thanks Hamstray, http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=1015
-
-
-2007 Feb 25
-	- Improved performance of convex collision shapes, cache local AABB instead of recomputation. This fixes issue with very slow performance in larger .bsp levels
-	
-2007 Feb 24
-	- Added compressed/quantized AABB tree, 16 bytes per node, while supporting 32-bit (triangle) indices. 
-	  Should be faster and smaller then original version (quantized aabb check is done in integer space)
-		Original aabb tree nodes are still supported. They are 44 bytes, with full floating point precision and additional subPart index.
-	- added meter-unit scaling support in ColladaConverter.cpp
-
-2007 Feb 21
-	- Build system: updated bullet.pc.in library names
-	- Updated EPA comparison integration (missing parameter)
-	
-2007 Jan 04
-	- fixed optimized AABB tree building: in some cases the tree building fails due to unbalanced trees, which generated stack overflow
-	
-2006 Dec 15
-	- added contribution to allow double precision collision detection/dynamics. Define BT_USE_DOUBLE_PRECISION in your project and libraries that include Bullet
-
-2006 Dec 14
-	- merged contact and non-contact constraint solving into one loop, will improve stability of jointed bodies during collisions
-	- added first draft for hingeConstraint motor
-	
-2006 Dec 8, Erwin Coumans
-	- preparation for SIMD: added btAlignedAllocator and btAlignedObjectArray, to replace stl std::vector, same interface, but compatible with 16 byte alignment
-	- cleaned up dependencies in autogenerated msvc projectfiles
-	- aligned btVector3 on 16 bytes boundary, under win32. see if developers will come up with problems
-
-2006 Dec 04, Erwin Coumans
-	Added btNearCallback. This is similar to Open Dynamics Engine (ODE) dNearCallback, but important differences:
-	- contact points are persistent (lifetime more then one frame, for warmstarting/incremental contact point management)
-	- continuous collision detection, time of impact
-	Added btRigidBody::isInWorld(), returns true if btRigidBody is inside a btCollisionWorld/btDynamicsWorld derived class
-	Added angularFactor to btRigidbody, this helps some character control (no angular impulse applied)
-
-
-2006 Nov 28
-	Moved StackAlloc from EPA into LinearMath/btStackAlloc
-	renamed internal class ConcaveShape into btConcaveShape
-	added btHeightfieldTerrainShape (not completed yet)
-		
-2006 Nov 15 Nathanael Presson
-	Added EPA penetration depth algorithm, Expanding Polytope Algorithm
-	Added Pierre Terdiman penetration depth comparison/test DEMO
-	Fixed Bullet's Minkowski sampling penetration depth solver
-	Contributed by Nathanael Presson
-	
-2006 Nov 11 Francisco León Nájera
-	Added GIMPACT trimesh collision detection: concave versus concave,
-	Contributed by Francisco León Nájera
-
-2006 Nov 2
-	Minor refactoring: btCollisionObject changes from struct into class, added accessor methods
-	Force use of btMotionState to synchronize graphics transform, disabled old btRigidBody constructor that accepts btTransform
-	Renamed treshold into threshold throughout the code
-	
-2006 Oct 30
-	Enable decoupling of physics and graphics framerate using interpolation and internal fixed timestep, based on btMotionState
-	Enabled raycast vehicle demo (still needs tuning)
-	Refresh contact points, even when they are already persistent.
-	Fixed debugDraw colors (thanks pc0de for reporting)
-	Use Dispatcher in ConcaveConvexCollisionAlgorithm (so it uses the registered collision algorithm, not hardcoded convexconcave)
-	Improved performance of constraint solver by precalculating the cross product/impulse arm
-	Added collision comparison code: ODE box-box, also sphere-triangle
-	Added safety check into GJK, and an assert for AABB's that are very large
-	Fixed kinematic support (deriving velocities for animated objects)
-	Updated comparison/optional quickstep solver in Extras
-	UserCollisionAlgorithm demonstrates btTriangleMesh usage (easier trimesh compared to index array version)
-	Removed scaling from btTransform (we only want to deal with rigid transforms)
-	
-2006 Oct 4
-	Fixed minor leak in btOptimizeBVH
-	Cleanup of btRigidBody construction
-	added getW() in btQuaternion
-	assert when setLinearVelocity is called on btRigidBody
-	renamed projectfile library from collada-dom to colladadom (to make VC6 happy)
-	
-2006 Sept 27
-	Big Refactoring: renamed and moved files, create a replacement for CcdPhysicsEnvironment/CcdPhysicsController.
-	All Bullet classes in LinearMath, BulletCollision and BulletDynamics start with bt, and methods start with lowercase.
-	Moved classes into src folder, which is the only include folder needed.
-	Added 2 headerfiles in src: btBulletCollisionCommon.h and btBulletDynamicsCommon.h
-
-2006 Sept 23
-	Fixed 2 bugs, causing crashes when removing objects. Should do better unit-testing. UnionFind and 3D SAP were involved.
-	
-2006 Sept 19
-	Allow programmable friction and contact solver model. User can register their own functions for several interaction types.
-	Improved performance, and removed hardcoded maximum overlaps (switched from C-array to stl::set)
-	
-2006 Sept 16
-	Added Bullet 2.0  User Manual
-	Allow registration of custom user collision algorithms
-
-2006 Sept 10
-	Started cleaning up demos
-	
-2006 Sept 4
-	Fixed concave collision bug (caused instability/missing collisions in meshes/compounds)
-	Fixed memoryleak in OptimizedBvh, added RayTestSingle to CollisionWorld
-	Prepared for VehicleDemo
-	Increased Performance (island generation for sleeping objects took too much time)
-	Better COLLADA 1.4.1 physics conformance in ColladaDemo
-
-2006 August 11
-	Added Quake BspDemo
-	Improved CCD for compound and non-convex objects
-
-2006 August 10
-	Added per-triangle material (friction/restitution) support for non-convex meshes. See ConcaveDemo for usage.
-
-2006 August 9
-	Added CMake support (see http://cmake.org)
-	This can autogenerate makefiles, projectfiles cross platform (including MacOS X Xcode )
-	Just run cmake . in the root folder and it will autogenerate build files
-	
-2006 July 26 Erwin Coumans
-	Upgraded to COLLADA-DOM 1.4.1, latest SVN version
-	ColladaDemo can export snapshots to .dae
-	
-2006 July 24 Erwin Coumans
-	Added Compound CollisionShape support
-	(this is still low performance -> requires stackless tree-versus-tree traversal for better performance)
-
-2006 July 15 Erwin Coumans
-	Added initial support for Parallel execution (collision detection, constraint solving)
-	See ParallelPhysicsEnvironment in Extras\PhysicsInterface\CcdPhysics
-	
-2006 July 10 Erwin Coumans
-	Added MacOS X support (some build issues mainly)
-		
-2006 July 5 Erwin Coumans
-	Improved COLLADA 1.4 physics import, both COLLADA-DOM and FCollada
-
-2006 June 29 Erwin Coumans
-	Refactoring of the broadphase
-	Moved some optional files to Extras: Algebraic ccd and EPA, quickstep
-	Moved the limits on bodies/overlap to 32k and 65k
-	
-2006 June 25 Erwin Coumans
-	Added basic Collision Filtering, during broadphase
-	Allow adding meshes to the TriangleIndexVertexArray,
-	(input for TriangleMeshShape) 
-	Preparation for CompoundShape
-
-2006 June 19 Erwin Coumans
-	Added support for COLLADA Physics Import.
-	Both jam and Visual Studio can compile ColladaDemo
-
-2006 June 18 Dirk Gregorius <[email protected]>
-	Started implementing Generic6DOF joint and setup basic interface
-
-
-2006 June 17 Frank Richter <[email protected]>
-	Bumped version in configure.ac to 1.5.6 (assuming that "1.5f" is
-	  the next version released).
-	Updated files in mk/autoconf and mk/jam with copies from CS; fixes a 
-	  GLU detection issue on MinGW.
-	Set msvc/bullet_ico.ico as the default application icon.
-	Disabled exceptions for gcc builds.
-	Applied a patch from Michael D. Adams to fix a warning with gcc.
-2006 jUNE 16 Erwin Coumans
-	Constraints now merge simulation islands.
-
-2006 May 24
-	Improved GJK accuracy, fixed GjkConvexCast issue, thanks to ~MyXa~ for reporting
-	
-2006 May 19
-	Added restitution support
-	Moved out Friction and Dynamics info from ManifoldPoint (removed logical dependency)
-	Added a void* m_userPersistentData in ManifoldPoint.
-	Added a ContactDestroyedCallback, to allow user to handle destruction of m_userPersistentData
-
-2006 May 13
-	Fixed some bugs in friction / jacobian calculations. Reported by Dirk Gregorius. Thanks!
-
-2006 May 9
-	Fixed raycasting filtering
-	Moved repository to SVN at https://svn.sourceforge.net/svnroot/bullet
-		
-2006 April 27
-	Moved raycasting to CollisionWorld, to make it more generic
-	Added basic CCD option in the CcdCollisionDemo
-	Fixed 'noResponse' mode, for triggering rigidbodies (useful for Artificial Intelligence queries)
-	Improved Bullet/ODE sample (in Extras)
-		
-2006 April 10
-	Separating Axis Test (SAT) convex hull collision detector, contribution by Simon Hobbs
-	Added SIMD SSE Math classes (for above SAT)
-	Added Mouse picking in CcdPhysicsDemo
-	Improved penetration depth estimation in MinkowskiPenetrationDepthSolver, both accuracy and performance
-	Added Hinge constraint
-	Added quickprof profiling (see http://sourceforge.net/projects/quickprof )
-		
-2006 March 21 Frank Richter <[email protected]>
-	Removed VC manifest files.
-	Removed superfluous "grpplugins" projects.
-
-2006 March 20 Erwin Coumans
-	Clamped the acculumated impulse rather then intermediate impulse (within the iteration)
-	Use the persistent contacts for reusing the impulse
-	Separated friction and normal solving for better stability
-	Decreased the default number of iterations of the constraint solver from 10 to 4
-
-2006 March 19 Frank Richter <[email protected]>
-	Removed a couple of CSisms from the VC projects.
-	Fixed VC include & lib paths to go to the Addtional* options
-	  instead the command line arguments.
-	Added pkgconfig support.
-
-2006 March 14 Frank Richter <[email protected]>
-	Added support for shipped GLUT on MinGW.
-	Fixed GLUT support on MinGW.
-
-2006 March 13 Frank Richter <[email protected]>
-	Bolted on Jam-based build system.
-	Generated VC project files.
-	Fixed GCC warnings.
-	Fixed Linux build issues.
-
-2006 March 13
-Added 3D Sweep and Prune Broadphase Collision Detection, Contribution from Simon Hobbs.
-
-2006 March 2
-	Minor change in license to ZLib/LibPNG
-	This makes it legally a bit easier to deploy on Playstation 3
-	Prepared for more generic constraints, added ConstraintsDemo
-
-2006 Feb 23
-	Rearranged files and dependencies to allow for easier standalone Collision Detection without Bullet Dynamics.
-	See Demos/CollisionInterfaceDemo and Extras/ode/ode/test/test_BulletGjk.cpp for examples how to use.
-
-2005 August 6
-	Bullet 0.2 release with demos, sources, doxygen, draft manual
-
-2005 June 1
-	First public release of Bullet
-	
-
-... todo: add history
-
-2003 Initial version (continuous collision detection)

+ 22 - 5
Engine/lib/bullet/Doxyfile

@@ -13,6 +13,9 @@
 # General configuration options
 # General configuration options
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
 
 
+
+
+
 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
 # The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
 # by quotes) that should identify the project. 
 # by quotes) that should identify the project. 
 PROJECT_NAME           = "Bullet Collision Detection & Physics Library"
 PROJECT_NAME           = "Bullet Collision Detection & Physics Library"
@@ -267,7 +270,7 @@ WARN_LOGFILE           =
 # directories like "/usr/src/myproject". Separate the files or directories 
 # directories like "/usr/src/myproject". Separate the files or directories 
 # with spaces. 
 # with spaces. 
 
 
-INPUT                  = src
+INPUT                  = src/LinearMath src/BulletCollision src/BulletDynamics src/BulletSoftBody src/btBulletCollisionCommon.h src/btBulletDynamicsCommon.h  Extras/Serialize/BulletWorldImporter Extras/Serialize/BulletFileLoader
 
 
 
 
 # If the value of the INPUT tag contains directories, you can use the 
 # If the value of the INPUT tag contains directories, you can use the 
@@ -399,7 +402,9 @@ HTML_ALIGN_MEMBERS     = YES
 
 
 GENERATE_HTMLHELP      = YES
 GENERATE_HTMLHELP      = YES
 
 
-HHC_LOCATION = "C:\Program Files\HTML Help Workshop\hhc.exe"
+# HHC_LOCATION = "C:\Program Files\HTML Help Workshop\hhc.exe"
+HHC_LOCATION = "C:\Program Files (x86)\HTML Help Workshop\hhc.exe"
+
 
 
 HTML_FILE_EXTENSION = .html
 HTML_FILE_EXTENSION = .html
 HTML_HEADER = 
 HTML_HEADER = 
@@ -589,7 +594,7 @@ MACRO_EXPANSION        = YES
 # then the macro expansion is limited to the macros specified with the 
 # then the macro expansion is limited to the macros specified with the 
 # PREDEFINED and EXPAND_AS_PREDEFINED tags. 
 # PREDEFINED and EXPAND_AS_PREDEFINED tags. 
 
 
-EXPAND_ONLY_PREDEF     = NO
+EXPAND_ONLY_PREDEF     = YES
 
 
 # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 
 # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files 
 # in the INCLUDE_PATH (see below) will be search if a #include is found. 
 # in the INCLUDE_PATH (see below) will be search if a #include is found. 
@@ -600,7 +605,7 @@ SEARCH_INCLUDES        = YES
 # contain include files that are not input files but should be processed by 
 # contain include files that are not input files but should be processed by 
 # the preprocessor. 
 # the preprocessor. 
 
 
-INCLUDE_PATH           = src
+INCLUDE_PATH           = 
 
 
 # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
 # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard 
 # patterns (like *.h and *.hpp) to filter out the header-files in the 
 # patterns (like *.h and *.hpp) to filter out the header-files in the 
@@ -615,7 +620,14 @@ INCLUDE_FILE_PATTERNS  =
 # or name=definition (no spaces). If the definition and the = are 
 # or name=definition (no spaces). If the definition and the = are 
 # omitted =1 is assumed. 
 # omitted =1 is assumed. 
 
 
-PREDEFINED             = 
+PREDEFINED		=	"ATTRIBUTE_ALIGNED128(x)=x" \
+					"ATTRIBUTE_ALIGNED16(x)=x" \
+					"SIMD_FORCE_INLINE=inline" \
+					"VECTORMATH_FORCE_INLINE=inline" \
+					"USE_WIN32_THREADING=1"\
+					"USE_PTHREADS=1"\
+					"_WIN32=1"
+					
 
 
 # If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY tags are set to YES then 
 # If the MACRO_EXPANSION and EXPAND_PREDEF_ONLY tags are set to YES then 
 # this tag can be used to specify a list of macro names that should be expanded. 
 # this tag can be used to specify a list of macro names that should be expanded. 
@@ -718,6 +730,11 @@ MAX_DOT_GRAPH_HEIGHT   = 1024
 
 
 GENERATE_LEGEND        = YES
 GENERATE_LEGEND        = YES
 
 
+
+# delete intermediate dot files?
+
+DOT_CLEANUP = YES
+
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------
 # Configuration::addtions related to the search engine   
 # Configuration::addtions related to the search engine   
 #---------------------------------------------------------------------------
 #---------------------------------------------------------------------------

+ 0 - 100
Engine/lib/bullet/INSTALL

@@ -1,100 +0,0 @@
-Bullet Collision Detection and Physics Library
-
-** Windows Compilation **
-
-Under Windows, projectfiles for Visual Studio version 6,7,7.1 and 8 are 
-available in msvc/<version>.  For example, for Visual Studio 2005, open 
-msvc/8/wksbullet.sln
-
-The ColladaDemo and ConvexDecomposition demo needs to be able to locate the 
-data files (jenga.dae and file.obj) in the current directory. Make sure Visual 
-Studio points to the right folder (..\..).
-
-Alternatively use CMake to autogenerate a build system for Windows:
-	
-	- Download/install CMake from www.cmake.org or package manager
-	- List available build systems by running 'cmake' in the Bullet root folder
-	- Create a build system using the -G option for example:
-	
-	cmake . -G "Visual Studio 9 2008" or
-	cmake . -G "Visual Studio 9 2008 Win64"
-		 
-
-** Linux Compilation **
-
-  - Download/install CMake from www.cmake.org or package manager
-    CMake is like autoconf in that it will create build scripts which are then 
-    used for the actual compilation
-
-  - There are some options for cmake builds:
-      BUILD_SHARED_LIBS: default 'OFF', set to 'ON' to build .so libraries
-      BUILD_EXTRAS: default 'ON', compiles additional libraries in 'Extras'
-      BUILD_DEMOS: default 'ON', compiles applications found in 'Demos'
-      CMAKE_INSTALL_PREFIX: default '/usr/local', the installation path.
-      CMAKE_INSTALL_RPATH: if you install outside a standard ld search path,
-        then you should set this to the installation lib path.
-    Other options may be discovered by 'cmake --help-variable-list' and
-    'cmake --help-variable OPTION'
-
-  - Run 'cmake' with desired options of the form -DOPTION=VALUE
-    By default this will create the usual Makefile build system, but CMake can 
-    also produce Eclipse or KDevelop project files.  See 'cmake --help' to see 
-    what "generators" are available in your environment, selected via '-G'.
-        For example:
-        cmake -DBUILD_SHARED_LIBS=ON
-
-  - Assuming using the default Makefile output from cmake, run 'make' to 
-    build, and then 'make install' if you wish to install.
-
-
-** Mac OS X Compilation **
-
-  - Download/install CMake from www.cmake.org or package manager
-    CMake is like autoconf in that it will create build scripts which are then 
-    used for the actual compilation
-
-  - There are some options for cmake builds:
-      BUILD_SHARED_LIBS: default 'OFF', set to 'ON' to build .dylib libraries
-      BUILD_EXTRAS: default 'ON', compiles additional libraries in 'Extras'
-      BUILD_DEMOS: default 'ON', compiles applications found in 'Demos'
-      CMAKE_INSTALL_PREFIX: default '/usr/local', the installation path.
-      CMAKE_INSTALL_NAME_DIR: if you install outside a standard ld search 
-        path, then you should set this to the installation lib/framework path. 
-
-    To build framework bundles:
-      FRAMEWORK: default 'OFF', also requires 'BUILD_SHARED_LIBS' set ON
-        If both FRAMEWORK and BUILD_SHARED_LIBS are set, will create
-        OS X style Framework Bundles which can be placed in 
-        linked via the -framework gcc argument or drag into Xcode projects.
-    (If not framework, then UNIX style 'include' and 'lib' will be produced)
-      
-    Other options may be discovered by 'cmake --help-variable-list' and
-    'cmake --help-variable OPTION'
-
-  - Run 'cmake' with desired options of the form -DOPTION=VALUE
-    By default this will create the usual Makefile build system, but CMake can 
-    also produce Eclipse or KDevelop project files.  See 'cmake --help' to see 
-    what "generators" are available in your environment, selected via '-G'.
-        For example:
-        cmake -DBUILD_SHARED_LIBS=ON -DFRAMEWORK=ON \
-              -DCMAKE_INSTALL_PREFIX=/Library/Frameworks \
-              -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks
-
-  - Assuming using the default Makefile output from cmake, run 'make' to build 
-    and then 'make install'.
-
-
-** Alternative Mac OS X and Linux via 'jam' or autoconf/make **
-  - at the command line:
-    ./autogen.sh
-    ./configure
-  - 'jam' or 'make' depending on preference
-  - If jam is not available for your system, you can compile it, jam sources 
-    are included with the Bullet sources in jam-2.5
-      - compiling jam:
-        cd jam-2.5
-        make
-        sudo make install
-
-
-** For more help, visit http://www.bulletphysics.com **

+ 0 - 66
Engine/lib/bullet/Jamfile.in

@@ -1,66 +0,0 @@
-TOP ?= "@top_srcdir@" ;
-BUILDTOP ?= "@top_builddir@" ;
-
-SubDir TOP ;
-
-IncludeDir ;
-IncludeDir src ;
-
-IncludeDir $(BUILDTOP) : : literal transient ;
-
-CleanDir clean :
-    out ;
-Clean distclean :
-    aclocal.m4
-    config.h
-    config.h.in~
-    config.log
-    config.status
-    config.status.lineno
-    config.cache
-    configure.lineno
-    Jamconfig
-    Jamfile ;
-CleanDir distclean :
-    autom4te.cache ;
-Depends distclean : clean ;
-
-Clean maintainerclean :
-  config.h.in
-  configure ;
-Depends maintainerclean : distclean ;
-
-Help distclean : "Remove built targets and configuration" ;
-Help maintainerclean :
-    "Remove built targets, configuration, and generated files." ;
-
-ApplicationIconDefault win32 : all : bullet_ico.ico : $(TOP) msvc ;
-
-MsvcGenSubDir TOP msvc : common ;
-MsvcGenSubDir TOP msvc 6 : 6 ;
-MsvcGenSubDir TOP msvc 7 : 7 ;
-MsvcGenSubDir TOP msvc 71 : 71 ;
-MsvcGenSubDir TOP msvc sn71 : sn71 ;
-MsvcGenSubDir TOP msvc 8 : 8 ;
-MsvcGenSubDir TOP msvc xenon8 : xenon8 ;
-MsvcGenTemplateDir TOP mk msvcgen ;
-MsvcGenWorkspace bullet : : "grp.+_(?!bullet$)" ;
-MsvcGenWorkspace bullet_corelib : libbulletcollision libbulletdynamics libbulletmath libbulletmultithreaded : "grp.+_(?!bullet_corelib$)" ;
-
-# Set project-specific compiler and linker options for msvcgen.
-MsvcGenConfig GL.AVAILABLE : yes ;
-MsvcGenConfig GL.LFLAGS :  ;
-MsvcGenConfig GL.LIBS : opengl32.lib ;
-MsvcGenConfig GLUT.AVAILABLE : yes ;
-MsvcGenConfig GLUT.CFLAGS : ;
-MsvcGenConfig GLUT.LFLAGS : ;
-MsvcGenConfig GLUT.INCDIRS : "../../Glut" ;
-MsvcGenConfig GLUT.LIBDIRS : "../../Glut" ;
-MsvcGenConfig GLUT.LIBS : glut32.lib ;
-MsvcGenConfig GLEW.LIBS : glew32.lib ;
-
-SubInclude TOP src ;
-SubInclude TOP Extras ;
-SubInclude TOP Demos ;
-
-Depends install_config : [ DoInstall bullet.pc : $(libdir)/pkgconfig ] ;

+ 0 - 21
Engine/lib/bullet/Jamrules

@@ -1,21 +0,0 @@
-if ! $(BUILDTOP)
-{
-BUILDTOP = . ;
-}
-
-# Include configuration.
-JAMCONFIG ?= $(BUILDTOP)/Jamconfig ;
-include $(JAMCONFIG) ;
-
-# Set up compiler flags.
-# Unfortunately, we can not use FDefines here since Boost Jam does not have it,
-# and we have not yet included mk/jam/build.jam which provides an emulation
-# layer for Boost.  We can not include build.jam earlier because these flags
-# need to be defined before build.jam is included.  :-(
-COMPILER.CFLAGS += -Wall -Wno-unknown-pragmas ;
-COMPILER.CFLAGS.optimize += -O3 -fomit-frame-pointer -ffast-math ;
-COMPILER.CFLAGS.debug += -g3 ;
-COMPILER.CFLAGS.profile += -gp -O3 ;
-
-# Include CS build rules
-include $(TOP)/mk/jam/build.jam ;

+ 0 - 19
Engine/lib/bullet/LICENSE

@@ -1,19 +0,0 @@
-/*
-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.
-*/
-
-All files in the Bullet/src folder are under this Zlib license.
-Optional Extras/GIMPACT and Extras/GIMPACTBullet is also under ZLib license. Other optional external libraries in  Extras/Demos have own license,see respective files.
-
-This means Bullet can freely be used in any software, including commercial and console software. A Playstation 3 optimized version is available through Sony.

+ 15 - 0
Engine/lib/bullet/LICENSE.txt

@@ -0,0 +1,15 @@
+
+The files in this repository are licensed under the zlib license, except for the files under 'Extras' and examples/ThirdPartyLibs.
+
+Bullet Continuous Collision Detection and Physics Library
+http://bulletphysics.org
+
+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.

+ 0 - 7
Engine/lib/bullet/Makefile.am

@@ -1,7 +0,0 @@
-if CONDITIONAL_BUILD_DEMOS
-SUBDIRS=src Extras Demos
-else
-SUBDIRS=src Extras
-endif
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = bullet.pc

+ 0 - 4
Engine/lib/bullet/NEWS

@@ -1,4 +0,0 @@
-
-For news, visit the Bullet Physics Forum at
-http://www.continuousphysics.com/Bullet/phpBB2/viewforum.php?f=9
-

+ 0 - 7
Engine/lib/bullet/README

@@ -1,7 +0,0 @@
-
-Bullet is a 3D Collision Detection and Rigid Body Dynamics Library for games and animation.
-Free for commercial use, including Playstation 3, open source under the ZLib License.
-Discrete and continuous collision detection, integrated into Blender 3D, and COLLADA 1.4 Physics import. 
-
-See the Bullet_User_Manual.pdf for more info and visit the Bullet Physics Forum at
-http://bulletphysics.com

+ 107 - 0
Engine/lib/bullet/README.md

@@ -0,0 +1,107 @@
+
+[![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.

+ 0 - 34
Engine/lib/bullet/RELEASING.TXT

@@ -1,34 +0,0 @@
-This document details the steps necessary to package a release of Bullet.
-
-1) Preparing for release:
-
-update VERSION in several places
-update ChangeLog 
-regenerate MSVC project files
-
-2) Generating the release .zip:
-Do an SVN export on a Windows machine into the directory: bullet-X.YY
-prepare a zip file containing the directory
-
-3) Generating the release .tar.gz:
-Do an SVN export on a Unix machine into the directory: bullet-X.YY
-prepare a .tar.gz file containing the directory
-
-4) Uploading release to google code:
-
-Google Code Bullet downloads URL: http://code.google.com/p/bullet/downloads/list
-
-Title of release should follow this guide line: Bullet <VERSION> Physics SDK <Release Type> (revision)
-
-It is better to upload the .tar.gz before the .zip so that the .zip appears first in the list
-
-If the release is an Alpha/Beta or RC the tags should be: Type-Source, OpSys-ALL
-If the release is a final release the tags should be: Type-Source, OpSys-ALL, Featured
-
-5) Obsoleting old releases
-
-Edit the tags on old releases and add the 'Deprecated' tag
-
-6) Announcing final releases:
-
-Final release announcements are done here: http://bulletphysics.com/Bullet/phpBB3/viewforum.php?f=18

+ 10 - 0
Engine/lib/bullet/UseBullet.cmake

@@ -0,0 +1,10 @@
+#                                               -*- cmake -*-
+#
+#  UseBullet.cmake
+#
+
+
+add_definitions     ( ${BULLET_DEFINITIONS} )
+include_directories ( ${BULLET_INCLUDE_DIRS} )
+link_directories    ( ${BULLET_LIBRARY_DIRS} )
+

+ 1 - 1
Engine/lib/bullet/VERSION

@@ -1 +1 @@
-2.75
+2.85

+ 0 - 3056
Engine/lib/bullet/acinclude.m4

@@ -1,3056 +0,0 @@
-# checkbuild.m4                                                -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_SPLIT_TUPLE(TUPLE, OUTPUT-VARIABLES)
-#	Split a build-tuple into its component parts.  A build tuple is
-#	constructed by CS_CREATE_TUPLE() and is comprised of compiler flags,
-#	linker flags, and library references.  OUTPUT-VARIABLES is a
-#	comma-delimited list of shell variables which should receive the
-#	extracted compiler flags, linker flags, and library references,
-#	respectively.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_SPLIT_TUPLE],
-    [CS_SPLIT([$1], [cs_dummy,$2], [@])
-    m4_map([_CS_SPLIT_TUPLE], [$2])])
-
-AC_DEFUN([_CS_SPLIT_TUPLE],
-    [$1=`echo $$1 | sed 'y%@%:@% %'`
-    ])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CREATE_TUPLE([CFLAGS], [LFLAGS], [LIBS])
-#	Construct a build-tuple which is comprised of compiler flags, linker
-#	flags, and library references.  Build tuples are encoded so as to
-#	preserve whitespace in each component.  This makes it possible for
-#	macros (such as CS_BUILD_IFELSE) which employ build tuples to accept
-#	whitespace-delimited lists of tuples, and for shell "for" statements to
-#	iterate over tuple lists without compromising whitespace embedded
-#	within individual flags or library references.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CREATE_TUPLE], [`echo @$1@$2@$3 | sed 'y% %@%:@%'`])
-
-
-
-#------------------------------------------------------------------------------
-# CS_LANG_CFLAGS
-#	Return the literal string CFLAGS if the current language is C.  Return
-#	the literal string CXXFLAGS if the current language is C++.  Generic
-#	compiler test macros which need to modify or save the compiler flags
-#	can invoke this macro to get the name of the compiler flags environment
-#	variable (either CFLAGS or CXXFLAGS) depending upon the current
-#	language.  For example:
-#		CS_LANG_CFLAGS="$CS_LANG_CFLAGS -Wall"
-#	With C, this expands to:
-#		CFLAGS="$CFLAGS -Wall"
-#	With C++, it expands to:
-#		CXXFLAGS="$CXXFLAGS -Wall"
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_LANG_CFLAGS], [AC_LANG_CASE([C], [CFLAGS], [C++], [CXXFLAGS])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_BUILD_IFELSE([PROGRAM], [FLAGS], [LANGUAGE], [ACTION-IF-BUILT],
-#                 [ACTION-IF-NOT-BUILT], [OTHER-CFLAGS], [OTHER-LFLAGS],
-#                 [OTHER-LIBS], [INHIBIT-OTHER-FLAGS], [ERROR-REGEX])
-#	Try building a program using the supplied compiler flags, linker flags,
-#	and library references.  PROGRAM is typically a program composed via
-#	AC_LANG_PROGRAM().  PROGRAM may be omitted if you are interested only
-#	in learning if the compiler or linker respects certain flags.  LANGUAGE
-#	is typically either C or C++ and specifies which compiler to use for
-#	the test.  If LANGUAGE is omitted, C is used.  FLAGS is a whitespace
-#	delimited list of build tuples.  Tuples are created with
-#	CS_CREATE_TUPLE() and are composed of up to three elements each.  The
-#	first element represents compiler flags, the second linker flags, and
-#	the third libraries used when linking the program.  Each tuple from
-#	FLAGS is attempted in order.  If you want a build attempted with no
-#	special flags prior to builds with specialized flags, create an empty
-#	tuple with CS_CREATE_TUPLE() at the start of the FLAGS list.  If the
-#	build is successful, then the shell variables cs_build_ok is set to
-#	"yes", cs_build_cflags, cs_build_lflags, and cs_build_libs are set to
-#	the tuple elements which resulted in the successful build, and
-#	ACTION-IF-BUILT is invoked.  Upon successful build, no further tuples
-#	are consulted.  If no tuple results in a successful build, then
-#	cs_build_ok is set to "no" and ACTION-IF-NOT-BUILT is invoked.
-#	OTHER-CFLAGS, OTHER-LFLAGS, and OTHER-LIBS specify additional compiler
-#	flags, linker flags, and libraries which should be used with each tuple
-#	build attempt.  Upon successful build, these additional flags are also
-#	reflected in the variables cs_build_cflags, cs_build_lflags, and
-#	cs_build_libs unless INHIBIT-OTHER-FLAGS is a non-empty string.  The
-#	optional ERROR-REGEX places an additional constraint upon the build
-#	check.  If specified, ERROR-REGEX, which is a standard `grep' regular
-#	expression, is applied to output captured from the compiler and linker.
-#	If ERROR-REGEX matches, then the build is deemed a failure, and
-#	cs_build_ok is set to "no".  This facility is useful for broken build
-#	tools which emit an error message yet still return success as a result.
-#	In such cases, it should be possible to detect the failure by scanning
-#	the tools' output.
-#
-# IMPLEMENTATION NOTES
-#
-#	In Autoconf 2.57 and earlier, AC_LINK_IFELSE() invokes AC_TRY_EVAL(),
-#	which does not provide access to the captured output.  To work around
-#	this limitation, we temporarily re-define AC_TRY_EVAL() as
-#	_AC_EVAL_STDERR(), which leaves the captured output in conftest.err
-#	(which we must also delete).  In Autoconf 2.58, however,
-#	AC_LINK_IFELSE() instead already invokes _AC_EVAL_STDERR() on our
-#	behalf, however we must be careful to apply ERROR-REGEX within the
-#	invocation AC_LINK_IFELSE(), since AC_LINK_IFELSE() deletes
-#	conftest.err before it returns.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_BUILD_IFELSE],
-    [AC_LANG_PUSH(m4_default([$3],[C]))
-    cs_cflags_save="$CS_LANG_CFLAGS"
-    cs_lflags_save="$LDFLAGS"
-    cs_libs_save="$LIBS"
-    cs_build_ok=no
-    m4_ifval([$10], [m4_pushdef([AC_TRY_EVAL], [_AC_EVAL_STDERR]($$[1]))])
-
-    for cs_build_item in m4_default([$2],[CS_CREATE_TUPLE()])
-    do
-	CS_SPLIT_TUPLE(
-	    [$cs_build_item],[cs_cflags_test,cs_lflags_test,cs_libs_test])
-	CS_LANG_CFLAGS="$cs_cflags_test $6 $cs_cflags_save"
-	LDFLAGS="$cs_lflags_test $7 $cs_lflags_save"
-	LIBS="$cs_libs_test $8 $cs_libs_save"
-	AC_LINK_IFELSE(m4_default([$1], [AC_LANG_PROGRAM([],[])]),
-	    [m4_ifval([$10],
-		[AS_IF([AC_TRY_COMMAND(
-		    [grep "AS_ESCAPE([$10])" conftest.err >/dev/null 2>&1])],
-		    [cs_build_ok=no], [cs_build_ok=yes])],
-		[cs_build_ok=yes])])
-	AS_IF([test $cs_build_ok = yes], [break])
-    done
-
-    m4_ifval([$10], [m4_popdef([AC_TRY_EVAL]) rm -f conftest.err])
-    CS_LANG_CFLAGS=$cs_cflags_save
-    LDFLAGS=$cs_lflags_save
-    LIBS=$cs_libs_save
-    AC_LANG_POP(m4_default([$3],[C]))
-
-    AS_IF([test $cs_build_ok = yes],
-	[cs_build_cflags=CS_TRIM([$cs_cflags_test[]m4_ifval([$9],[],[ $6])])
-	cs_build_lflags=CS_TRIM([$cs_lflags_test[]m4_ifval([$9],[],[ $7])])
-	cs_build_libs=CS_TRIM([$cs_libs_test[]m4_ifval([$9],[],[ $8])])
-	$4],
-	[$5])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_BUILD(MESSAGE, CACHE-VAR, [PROGRAM], [FLAGS], [LANGUAGE],
-#                [ACTION-IF-BUILT], [ACTION-IF-NOT-BUILT], [IGNORE-CACHE],
-#                [OTHER-CFLAGS], [OTHER-LFLAGS], [OTHER-LIBS],
-#                [INHIBIT-OTHER-FLAGS], [ERROR-REGEX])
-#	Like CS_BUILD_IFELSE() but also prints "checking" and result messages,
-#	and optionally respects the cache.  Sets CACHE-VAR to "yes" upon
-#	success, else "no" upon failure.  Additionally, sets CACHE-VAR_cflags,
-#	CACHE-VAR_lflags, and CACHE-VAR_libs to the values which resulted in a
-#	successful build.  If IGNORE-CACHE is "yes", then the cache variables
-#	are ignored upon entry to this macro, however they are still set to
-#	appropriate values upon exit.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_BUILD],
-    [AS_IF([test "$8" != yes],
-	[AC_CACHE_CHECK([$1], [$2],
-	    [CS_BUILD_IFELSE([$3], [$4], [$5],
-		[$2=yes
-		$2_cflags=$cs_build_cflags
-		$2_lflags=$cs_build_lflags
-		$2_libs=$cs_build_libs],
-		[$2=no], [$9], [$10], [$11], [$12], [$13])])],
-	[AC_MSG_CHECKING([$1])
-	    CS_BUILD_IFELSE([$3], [$4], [$5],
-		[$2=yes
-		$2_cflags=$cs_build_cflags
-		$2_lflags=$cs_build_lflags
-		$2_libs=$cs_build_libs],
-		[$2=no], [$9], [$10], [$11], [$12], [$13])
-	    AC_MSG_RESULT([$$2])])
-    AS_IF([test $$2 = yes], [$6],
-	[$2_cflags=''
-	$2_lflags=''
-	$2_libs=''
-	$7])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_BUILD_FLAGS(MESSAGE, CACHE-VAR, FLAGS, [LANGUAGE],
-#                     [ACTION-IF-RECOGNIZED], [ACTION-IF-NOT-RECOGNIZED],
-#                     [OTHER-CFLAGS], [OTHER-LFLAGS], [OTHER-LIBS],
-#                     [ERROR-REGEX])
-#	Like CS_CHECK_BUILD(), but checks only if the compiler or linker
-#	recognizes a command-line option or options.  MESSAGE is the "checking"
-#	message.  CACHE-VAR is the shell cache variable which receives the flag
-#	or flags recognized by the compiler or linker.  FLAGS is a
-#	whitespace-delimited list of build tuples created with
-#	CS_CREATE_TUPLE().  Each tuple from FLAGS is attempted in order until
-#	one is found which is recognized by the compiler.  After that, no
-#	further flags are checked.  LANGUAGE is typically either C or C++ and
-#	specifies which compiler to use for the test.  If LANGUAGE is omitted,
-#	C is used.  If a command-line option is recognized, then CACHE-VAR is
-#	set to the composite value of $cs_build_cflags, $cs_build_lflags, and
-#	$cs_build_libs of the FLAGS element which succeeded (not including the
-#	"other" flags) and ACTION-IF-RECOGNIZED is invoked.  If no options are
-#	recognized, then CACHE-VAR is set to the empty string, and
-#	ACTION-IF-NOT-RECOGNIZED is invoked. As a convenience, in case
-#	comparing CACHE-VAR against the empty string to test for failure is
-#	undesirable, a second variable named CACHE-VAR_ok is set to the literal
-#	"no" upon failure, and to the same value as CACHE-VAR upon success.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_BUILD_FLAGS],
-    [AC_CACHE_CHECK([$1], [$2_ok],
-	[CS_BUILD_IFELSE([], [$3], [$4],
-	    [$2=CS_TRIM([$cs_build_cflags $cs_build_lflags $cs_build_libs])
-	    $2_ok="$$2"],
-	    [$2=''
-	    $2_ok=no], [$7], [$8], [$9], [Y], [$10])])
-    AS_IF([test "$$2_ok" != no], [$5], [$6])])
-#==============================================================================
-# Copyright (C)2003-2006 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_COMMON_TOOLS_LINK
-#	Checks for common tools related to linking.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_COMMON_TOOLS_LINK],
-    [
-    # The default RANLIB in Jambase is wrong on some platforms, and is also
-    # unsuitable during cross-compilation, so we set the value unconditionally
-    # (sixth argument of CS_EMIT_BUILD_PROPERTY).
-    AC_PROG_RANLIB
-    CS_EMIT_BUILD_PROPERTY([RANLIB], [$RANLIB], [], [], [], [Y])
-    
-    CS_CHECK_TOOLS([DLLTOOL], [dlltool])
-    CS_EMIT_BUILD_PROPERTY([CMD.DLLTOOL], [$DLLTOOL])
-    
-    CS_CHECK_TOOLS([DLLWRAP], [dllwrap])
-    CS_EMIT_BUILD_PROPERTY([CMD.DLLWRAP], [$DLLWRAP])
-    
-    CS_CHECK_TOOLS([WINDRES], [windres])
-    CS_EMIT_BUILD_PROPERTY([CMD.WINDRES], [$WINDRES])
-    
-    CS_CHECK_TOOLS([STRINGS], [strings])
-    CS_EMIT_BUILD_PROPERTY([CMD.STRINGS], [$STRINGS])
-
-    CS_CHECK_TOOLS([OBJCOPY], [objcopy])
-    CS_EMIT_BUILD_PROPERTY([CMD.OBJCOPY], [$OBJCOPY])
-    
-    CS_CHECK_LIBTOOL
-    CS_EMIT_BUILD_PROPERTY([LIBTOOL], [$LIBTOOL])
-    CS_EMIT_BUILD_PROPERTY([APPLE_LIBTOOL], [$APPLE_LIBTOOL])
-    ])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_COMMON_TOOLS_BASIC
-#	Checks for basic tools for building things.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_COMMON_TOOLS_BASIC],
-    [CS_CHECK_MKDIR
-    CS_EMIT_BUILD_PROPERTY([CMD.MKDIR], [$MKDIR])
-    CS_EMIT_BUILD_PROPERTY([CMD.MKDIRS], [$MKDIRS])
-
-    CS_CHECK_PROGS([INSTALL], [install])
-    CS_EMIT_BUILD_PROPERTY([INSTALL], [$INSTALL])])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_COMMON_TOOLS_DOC_TEXINFO
-#	Checks for tools to generate documentation from texinfo files.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_COMMON_TOOLS_DOC_TEXINFO],
-    [CS_CHECK_PROGS([TEXI2DVI], [texi2dvi])
-    CS_EMIT_BUILD_PROPERTY([CMD.TEXI2DVI], [$TEXI2DVI])
-
-    CS_CHECK_PROGS([TEXI2PDF], [texi2pdf])
-    CS_EMIT_BUILD_PROPERTY([CMD.TEXI2PDF], [$TEXI2PDF])
-
-    CS_CHECK_PROGS([DVIPS], [dvips])
-    CS_EMIT_BUILD_PROPERTY([CMD.DVIPS], [$DVIPS])
-
-    CS_CHECK_PROGS([DVIPDF], [dvipdf])
-    CS_EMIT_BUILD_PROPERTY([CMD.DVIPDF], [$DVIPDF])
-
-    CS_CHECK_PROGS([MAKEINFO], [makeinfo])
-    CS_EMIT_BUILD_PROPERTY([CMD.MAKEINFO], [$MAKEINFO])])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_COMMON_TOOLS_DOC_DOXYGEN
-#	Checks for tools to generate source documentation via doxygen.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_COMMON_TOOLS_DOC_DOXYGEN],
-    [CS_CHECK_PROGS([DOXYGEN], [doxygen])
-    CS_EMIT_BUILD_PROPERTY([CMD.DOXYGEN], [$DOXYGEN])
-
-    CS_CHECK_TOOLS([DOT], [dot])
-    CS_EMIT_BUILD_PROPERTY([CMD.DOT], [$DOT])])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_COMMON_LIBS
-#       Check for typical required libraries (libm, libmx, libdl, libnsl).
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_COMMON_LIBS],
-    [AC_LANG_PUSH([C])
-    AC_CHECK_LIB([m], [pow], [cs_cv_libm_libs=-lm], [cs_cv_libm_libs=])
-    AC_CHECK_LIB([m], [cosf], [cs_cv_libm_libs=-lm])
-    AC_CHECK_LIB([mx], [cosf])
-    AC_CHECK_LIB([dl], [dlopen], [cs_cv_libdl_libs=-ldl], [cs_cv_libdl_libs=])
-    AC_CHECK_LIB([nsl], [gethostbyname])
-    AC_LANG_POP([C])])
-# checkcppunit.m4                                              -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_CPPUNIT([EMITTER])
-#	Check if CppUnit (http://cppunit.sourceforge.net/), the unit-testing
-#	framework is available. The shell variable cs_cv_libcppunit is set to
-#	"yes" if CppUnit is discovered, else "no".  If available, then the
-#	variables cs_cv_libcppunit_cflags, cs_cv_libcppunit_lflags, and
-#	cs_cv_libcppunit_libs are set. If EMITTER is provided, then
-#	CS_EMIT_BUILD_RESULT() is invoked with EMITTER in order to record the
-#	results in an output file. As a convenience, if EMITTER is the literal
-#	value "emit" or "yes", then CS_EMIT_BUILD_RESULT()'s default emitter
-#	will be used.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_CPPUNIT],
-    [CS_CHECK_LIB_WITH([cppunit],
-	[AC_LANG_PROGRAM([[#include <cppunit/ui/text/TestRunner.h>]],
-	    [CppUnit::TextUi::TestRunner r; r.run();])],
-	[], [C++])
-	
-    AS_IF([test $cs_cv_libcppunit = yes],
-	[CS_CHECK_BUILD([if cppunit is sufficiently recent],
-	    [cs_cv_libcppunit_recent],
-	    [AC_LANG_PROGRAM(
-		[[#include <cppunit/BriefTestProgressListener.h>]], 
-		[CppUnit::BriefTestProgressListener b; b.startTest(0);])],
-	    [], [C++],
-	    [CS_EMIT_BUILD_RESULT([cs_cv_libcppunit], [CPPUNIT],
-		CS_EMITTER_OPTIONAL([$1]))], [], [],
-	    [$cs_cv_libcppunit_cflags],
-	    [$cs_cv_libcppunit_lflags],
-	    [$cs_cv_libcppunit_libs])])])
-# checklib.m4                                                  -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003-2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# cs_lib_paths_default
-#	Whitespace delimited list of directory tuples in which to search, by
-#	default, for external libraries.  Each list item can specify an
-#	include|library directory tuple (for example, "/usr/include|/usr/lib"),
-#	or a single directory (for example, "/usr").  If the second form is
-#	used, then "include" and "lib" subdirectories of the directory are
-#	searched.  If the library resources are not found, then the directory
-#	itself is searched.  Thus, "/proj" is shorthand for
-#	"/proj/include|/proj/lib /proj|/proj".
-#
-# Present Cases:
-#	/usr/local -- Not all compilers search here by default, so we specify
-#		it manually.
-#	/sw -- Fink, the MacOS/X manager of Unix packages, installs here by
-#		default.
-#	/opt/local -- DarwinPorts installs here by default.
-#------------------------------------------------------------------------------
-m4_define([cs_lib_paths_default],
-    [/usr/local/include|/usr/local/lib \
-    /sw/include|/sw/lib \
-    /opt/local/include|/opt/local/lib \
-    /opt/include|/opt/lib])
-
-
-
-#------------------------------------------------------------------------------
-# cs_pkg_paths_default
-#	Comma delimited list of additional directories in which the
-#	`pkg-config' command should search for its `.pc' files.
-#
-# Present Cases:
-#	/usr/local/lib/pkgconfig -- Although a common location for .pc files
-#		installed by "make install", many `pkg-config' commands neglect
-#		to search here automatically.
-#	/sw/lib/pkgconfig -- Fink, the MacOS/X manager of Unix packages,
-#		installs .pc files here by default.
-#	/opt/local/lib/pkgconfig -- DarwinPorts installs .pc files here by
-#		default.
-#------------------------------------------------------------------------------
-m4_define([cs_pkg_paths_default],
-    [/usr/local/lib/pkgconfig,
-    /sw/lib/pkgconfig,
-    /opt/local/lib/pkgconfig,
-    /opt/lib/pkgconfig])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_LIB_WITH(LIBRARY, PROGRAM, [SEARCH-LIST], [LANGUAGE],
-#                   [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND], [OTHER-CFLAGS],
-#                   [OTHER-LFLAGS], [OTHER-LIBS], [ALIASES])
-#	Very roughly similar in concept to AC_CHECK_LIB(), but allows caller to
-#	to provide list of directories in which to search for LIBRARY; allows
-#	user to override library location via --with-LIBRARY=dir; and consults
-#	`pkg-config' (if present) and `LIBRARY-config' (if present, i.e.
-#	`sdl-config') in order to obtain compiler and linker flags.  LIBRARY is
-#	the name of the library or MacOS/X framework which is to be located
-#	(for example, "readline" for `libreadline.a' or `readline.framework').
-#	PROGRAM, which is typically composed with AC_LANG_PROGRAM(), is a
-#	program which references at least one function or symbol in LIBRARY.
-#	SEARCH-LIST is a whitespace-delimited list of paths in which to search
-#	for the library and its header files, in addition to those searched by
-#	the compiler and linker by default, and those referenced by the
-#	cs_lib_paths_default macro.  Each list item can specify an
-#	`include|library' directory tuple (for example,
-#	"/usr/include|/usr/lib"), or a single directory (for example, "/usr").
-#	If the second form is used, then "include" and "lib" subdirectories of
-#	the directory are searched.  If the library resources are not found,
-#	then the directory itself is searched.  Thus, "/proj" is shorthand for
-#	"/proj/include|/proj/lib /proj|/proj".  Items in the search list can
-#	include wildcards.  SEARCH-LIST can be overridden by the user with the
-#	--with-LIBRARY=dir option, in which case only "dir/include|dir/lib" and
-#	"dir|dir" are searched.  If SEARCH-LIST is omitted and the user did not
-#	override the search list via --with-LIBRARY=dir, then only the
-#	directories normally searched by the compiler and the directories
-#	mentioned via cs_lib_paths_default are searched.  LANGUAGE is typically
-#	either C or C++ and specifies which compiler to use for the test.  If
-#	LANGUAGE is omitted, C is used.  OTHER-CFLAGS, OTHER-LFLAGS, and
-#	OTHER-LIBS can specify additional compiler flags, linker flags, and
-#	libraries needed to successfully link with LIBRARY.  The optional
-#	ALIASES is a comma-delimited list of library names for which to search
-#	in case LIBRARY is not located (for example "[sdl1.2, sdl12]" for
-#	libsdl1.2.a, sdl1.2.framework, libsdl12.a, and sdl12.framework).  If
-#	the library or one of its aliases is found and can be successfully
-#	linked into a program, then the shell cache variable cs_cv_libLIBRARY
-#	is set to "yes"; cs_cv_libLIBRARY_cflags, cs_cv_libLIBRARY_lflags, and
-#	cs_cv_libLIBRARY_libs are set, respectively, to the compiler flags
-#	(including OTHER-CFLAGS), linker flags (including OTHER-LFLAGS), and
-#	library references (including OTHER-LIBS) which resulted in a
-#	successful build; and ACTION-IF-FOUND is invoked.  If the library was
-#	not found or was unlinkable, or if the user disabled the library via
-#	--without-LIBRARY, then cs_cv_libLIBRARY is set to "no" and
-#	ACTION-IF-NOT-FOUND is invoked.  Note that the exported shell variable
-#	names are always composed from LIBRARY regardless of whether the test
-#	succeeded because the primary library was discovered or one of the
-#	aliases.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_LIB_WITH],
-    [AC_ARG_WITH([$1], [AC_HELP_STRING([--with-$1=dir],
-	[specify location of lib$1 if not detected automatically; searches
-	dir/include, dir/lib, and dir])])
-
-    # Backward compatibility: Recognize --with-lib$1 as alias for --with-$1.
-    AS_IF([test -n "$with_lib$1" && test -z "$with_$1"],
-	[with_$1="$with_lib$1"])
-
-    AS_IF([test -z "$with_$1"], [with_$1=yes])
-    AS_IF([test "$with_$1" != no],
-	[# If --with-$1 value is same as cached value, then assume other
-	 # cached values are also valid; otherwise, ignore all cached values.
-	AS_IF([test "$with_$1" != "$cs_cv_with_$1"],
-	    [cs_ignore_cache=yes], [cs_ignore_cache=no])
-
-	cs_check_lib_flags=''
-	AS_IF([test $with_$1 = yes],
-	    [m4_foreach([cs_check_lib_alias], [$1, $10],
-		[_CS_CHECK_LIB_PKG_CONFIG_FLAGS([cs_check_lib_flags],
-		    cs_check_lib_alias)
-		_CS_CHECK_LIB_CONFIG_FLAGS([cs_check_lib_flags],
-		    cs_check_lib_alias)
-		])])
-
-	AS_IF([test $with_$1 != yes],
-	    [cs_check_lib_paths=$with_$1],
-	    [cs_check_lib_paths="| cs_lib_paths_default $3"])
-	m4_foreach([cs_check_lib_alias], [$1, $10],
-	    [_CS_CHECK_LIB_CREATE_FLAGS([cs_check_lib_flags],
-		cs_check_lib_alias, [$cs_check_lib_paths])
-	    ])
-
-	CS_CHECK_BUILD([for lib$1], [cs_cv_lib$1], [$2], [$cs_check_lib_flags],
-	    [$4], [], [], [$cs_ignore_cache], [$7], [$8], [$9])],
-	[cs_cv_lib$1=no])
-
-    cs_cv_with_$1="$with_$1"
-    AS_IF([test "$cs_cv_lib$1" = yes], [$5], [$6])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_PKG_CONFIG
-#	Check if the `pkg-config' command is available and reasonably recent.
-#	This program acts as a central repository of build flags for various
-#	packages.  For example, to determine the compiler flags for FreeType2
-#	use, "pkg-config --cflags freetype2"; and "pkg-config --libs freetype2"
-#	to determine the linker flags. If `pkg-config' is found and is
-#	sufficiently recent, PKG_CONFIG is set and AC_SUBST() invoked.
-#------------------------------------------------------------------------------
-m4_define([CS_PKG_CONFIG_MIN], [0.9.0])
-AC_DEFUN([CS_CHECK_PKG_CONFIG],
-    [AS_IF([test "$cs_prog_pkg_config_checked" != yes],
-	[CS_CHECK_TOOLS([PKG_CONFIG], [pkg-config])
-	_CS_CHECK_PKG_CONFIG_PREPARE_PATH
-	cs_prog_pkg_config_checked=yes])
-    AS_IF([test -z "$cs_cv_prog_pkg_config_ok"],
-	[AS_IF([test -n "$PKG_CONFIG"],
-	    [AS_IF([$PKG_CONFIG --atleast-pkgconfig-version=CS_PKG_CONFIG_MIN],
-		[cs_cv_prog_pkg_config_ok=yes],
-		[cs_cv_prog_pkg_config_ok=no])],
-	    [cs_cv_prog_pkg_config_ok=no])])])
-
-AC_DEFUN([_CS_CHECK_PKG_CONFIG_PREPARE_PATH],
-    [PKG_CONFIG_PATH="m4_foreach([cs_pkg_path], [cs_pkg_paths_default],
-	[cs_pkg_path$PATH_SEPARATOR])$PKG_CONFIG_PATH"
-    export PKG_CONFIG_PATH])
-
-
-
-#------------------------------------------------------------------------------
-# _CS_CHECK_LIB_PKG_CONFIG_FLAGS(VARIABLE, LIBRARY)
-#	Helper macro for CS_CHECK_LIB_WITH().  Checks if `pkg-config' knows
-#	about LIBRARY and, if so, appends a build tuple consisting of the
-#	compiler and linker flags reported by `pkg-config' to the list of
-#	tuples stored in the shell variable VARIABLE.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_CHECK_LIB_PKG_CONFIG_FLAGS],
-    [CS_CHECK_PKG_CONFIG
-    AS_IF([test $cs_cv_prog_pkg_config_ok = yes],
-	[AC_CACHE_CHECK([if $PKG_CONFIG recognizes $2], [_CS_CLPCF_CVAR([$2])],
-	    [AS_IF([$PKG_CONFIG --exists $2],
-		[_CS_CLPCF_CVAR([$2])=yes], [_CS_CLPCF_CVAR([$2])=no])])
-	AS_IF([test $_CS_CLPCF_CVAR([$2]) = yes],
-	    [_CS_CHECK_LIB_CONFIG_PROG_FLAGS([$1], [pkg_config_$2],
-		[$PKG_CONFIG], [$2])])])])
-
-AC_DEFUN([_CS_CLPCF_CVAR], [AS_TR_SH([cs_cv_prog_pkg_config_$1])])
-
-
-
-#------------------------------------------------------------------------------
-# _CS_CHECK_LIB_CONFIG_FLAGS(VARIABLE, LIBRARY)
-#	Helper macro for CS_CHECK_LIB_WITH().  Checks if `LIBRARY-config'
-#	(i.e. `sdl-config') exists and, if so, appends a build tuple consisting
-#	of the compiler and linker flags reported by `LIBRARY-config' to the
-#	list of tuples stored in the shell variable VARIABLE.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_CHECK_LIB_CONFIG_FLAGS],
-    [CS_CHECK_TOOLS(_CS_CLCF_SHVAR([$2]), [$2-config])
-    AS_IF([test -n "$_CS_CLCF_SHVAR([$2])"],
-	[AS_IF([test -z "$_CS_CLCF_CVAR([$2])"],
-	    [AS_IF([$_CS_CLCF_SHVAR([$2]) --cflags --libs >/dev/null 2>&1],
-		[_CS_CLCF_CVAR([$2])=yes], [_CS_CLCF_CVAR([$2])=no])])
-	AS_IF([test $_CS_CLCF_CVAR([$2]) = yes],
-	    [_CS_CHECK_LIB_CONFIG_PROG_FLAGS([$1], [config_$2],
-		[$_CS_CLCF_SHVAR([$2])])])])])
-
-AC_DEFUN([_CS_CLCF_CVAR], [AS_TR_SH([cs_cv_prog_config_$1_ok])])
-AC_DEFUN([_CS_CLCF_SHVAR], [m4_toupper(AS_TR_SH([CONFIG_$1]))])
-
-
-
-#------------------------------------------------------------------------------
-# _CS_CHECK_LIB_CONFIG_PROG_FLAGS(VARIABLE, TAG, CONFIG-PROGRAM, [ARGS])
-#	Helper macro for _CS_CHECK_LIB_PKG_CONFIG_FLAGS() and
-#	_CS_CHECK_LIB_CONFIG_FLAGS(). CONFIG-PROGRAM is a command which
-#	responds to the --cflags and --libs options and returns suitable
-#	compiler and linker flags for some package. ARGS, if supplied, is
-#	passed to CONFIG-PROGRAM after the --cflags or --libs argument. The
-#	results of the --cflags and --libs options are packed into a build
-#	tuple and appended to the list of tuples stored in the shell variable
-#	VARIABLE. TAG is used to compose the name of the cache variable. A good
-#	choice for TAG is some unique combination of the library name and
-#	configuration program.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_CHECK_LIB_CONFIG_PROG_FLAGS],
-    [AS_IF([test -z "$_CS_CLCPF_CVAR([$2])"],
-	[cs_check_lib_cflag=CS_RUN_PATH_NORMALIZE([$3 --cflags $4])
-	cs_check_lib_lflag=''
-	cs_check_lib_libs=CS_RUN_PATH_NORMALIZE([$3 --libs $4])
-	_CS_CLCPF_CVAR([$2])=CS_CREATE_TUPLE(
-	    [$cs_check_lib_cflag],
-	    [$cs_check_lib_lflag],
-	    [$cs_check_lib_libs])])
-    $1="$$1 $_CS_CLCPF_CVAR([$2])"])
-
-AC_DEFUN([_CS_CLCPF_CVAR], [AS_TR_SH([cs_cv_prog_$1_flags])])
-
-
-
-#------------------------------------------------------------------------------
-# _CS_CHECK_LIB_CREATE_FLAGS(VARIABLE, LIBRARY, PATHS)
-#	Helper macro for CS_CHECK_LIB_WITH().  Constructs a list of build
-#	tuples suitable for CS_CHECK_BUILD() and appends the tuple list to the
-#	shell variable VARIABLE.  LIBRARY and PATHS have the same meanings as
-#	the like-named arguments of CS_CHECK_LIB_WITH().
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_CHECK_LIB_CREATE_FLAGS],
-    [for cs_lib_item in $3
-    do
-	case $cs_lib_item in
-	    *\|*) CS_SPLIT(
-		    [$cs_lib_item], [cs_check_incdir,cs_check_libdir], [|])
-		_CS_CHECK_LIB_CREATE_FLAG([$1],
-		    [$cs_check_incdir], [$cs_check_libdir], [$2])
-		;;
-	    *)  _CS_CHECK_LIB_CREATE_FLAG([$1],
-		    [$cs_lib_item/include], [$cs_lib_item/lib], [$2])
-		_CS_CHECK_LIB_CREATE_FLAG(
-		    [$1], [$cs_lib_item], [$cs_lib_item], [$2])
-		;;
-	esac
-    done])
-
-
-
-#------------------------------------------------------------------------------
-# _CS_CHECK_LIB_CREATE_FLAG(VARIABLE, HEADER-DIR, LIBRARY-DIR, LIBRARY)
-#	Helper macro for _CS_CHECK_LIB_CREATE_FLAGS().  Constructs build tuples
-#	suitable for CS_CHECK_BUILD() for given header and library directories,
-#	and appends the tuples to the shell variable VARIABLE. Synthesizes
-#	tuples which check for LIBRARY as a MacOS/X framework, and a standard
-#	link library.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_CHECK_LIB_CREATE_FLAG],
-   [AS_IF([test -n "$2"], [cs_check_lib_cflag="-I$2"], [cs_check_lib_cflag=''])
-    AS_IF([test -n "$3"], [cs_check_lib_lflag="-L$3"], [cs_check_lib_lflag=''])
-    AS_IF([test -n "$4"],
-	[cs_check_lib_libs="-l$4"
-	cs_check_lib_framework="-framework $4"],
-	[cs_check_lib_libs=''
-	cs_check_lib_framework=''])
-    $1="$$1
-	CS_CREATE_TUPLE(
-	    [$cs_check_lib_cflag],
-	    [$cs_check_lib_lflag],
-	    [$cs_check_lib_framework])
-	CS_CREATE_TUPLE(
-	    [$cs_check_lib_cflag],
-	    [$cs_check_lib_lflag],
-	    [$cs_check_lib_libs])"])
-# checklibtool.m4                                              -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2004 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_LIBTOOL
-#	Find and identify the various implementations of libtool.  In
-#	particular, this macro is aware of GNU libtool and Apple's libtool
-#	(which serves a completely different purpose).  On MacOS/X, GNU libtool
-#	is typically named glibtool, however a user might also use Fink to
-#	install the unadorned libtool; and the Fink-installed version might
-#	shadow Apple's own libtool if it appears in the PATH before the Apple
-#	tool. This macro jumps through the necessary hoops to distinguish and
-#	locate the various implementations. Sets the shell variable LIBTOOL to
-#	the located GNU libtool (if any), and APPLE_LIBTOOL to the located
-#	Apple libtool. Invokes AC_SUBST() for LIBTOOL and APPLE_LIBTOOL.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_LIBTOOL],
-[# GNU: Search for libtool before glibtool since Fink version is likely newer.
-m4_define([cs_lt_path_gnu],
-    [/sw/bin$PATH_SEPARATOR/usr/local/bin$PATH_SEPARATOR$PATH])
-AS_IF([test -z "$LIBTOOL"],
-    [CS_CHECK_TOOLS([LIBTOOL_TEST], [libtool glibtool gnulibtool], [],
-	[cs_lt_path_gnu])
-    AS_IF([test -n "$LIBTOOL_TEST"],
-	[CS_PATH_PROG([LIBTOOL_PATH], [$LIBTOOL_TEST], [], [cs_lt_path_gnu])
-	CS_LIBTOOL_CLASSIFY([$LIBTOOL_PATH],
-	    [LIBTOOL="$LIBTOOL_PATH"],
-	    [AS_IF([test -z "$APPLE_LIBTOOL"], [APPLE_LIBTOOL="$LIBTOOL_PATH"])
-	    CS_CHECK_TOOLS([LIBTOOL], [glibtool gnulibtool])])])])
-AC_SUBST([LIBTOOL])
-
-# Apple: Ensure that Apple libtool will be found before GNU libtool from Fink.
-m4_define([cs_lt_path_apple],[/bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH])
-AS_IF([test -z "$APPLE_LIBTOOL"],
-    [CS_PATH_PROG([CS_LT_APPLE], [libtool], [], [cs_lt_path_apple])
-    CS_LIBTOOL_CLASSIFY([$CS_LT_APPLE], [],
-	[APPLE_LIBTOOL="$CS_LT_APPLE"])])
-AC_SUBST([APPLE_LIBTOOL])])
-
-AC_DEFUN([CS_LIBTOOL_CLASSIFY],
-    [AS_IF([test -n "$1"],
-	[AC_MSG_CHECKING([classification of $1])
-	CS_LIBTOOL_GNU_IFELSE([$1],
-	    [AC_MSG_RESULT([gnu])
-	    $2],
-	    [AC_MSG_RESULT([apple])
-	    $3])])])
-
-AC_DEFUN([CS_LIBTOOL_GNU_IFELSE],
-    [AS_IF([AC_RUN_LOG([$1 --version 1>&2])], [$2], [$3])])
-#==============================================================================
-# Copyright (C)2003-2006 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_OPENGL
-#	Check for OpenGL.
-#
-# IMPLEMENTATION NOTES
-#
-# Some Mesa installations require pthread, so pthread flags are employed if
-# available.
-#
-# The check for opengl32 needs to precede other checks because Cygwin users
-# often have Mesa installed, and Mesa's OpenGL library is compiled without the
-# __stdcall flags which results in link errors, whereas Microsoft's native
-# opengl32 works fine.  Conversely, some Unix implementations have Wine
-# installed (Windows emulation layer) which includes an opengl32.so library.
-# We need to avoid detection of this library on Unix since it would cause an
-# undesirable dependence upon Wine.
-#
-# Many OpenGL libraries on Unix already contain GLX, so there is no separate
-# GLX library, thus we first check for GLX using the discovered OpenGL library
-# before attempting to locate a separate GLX-specific library.  
-#
-# On MacOS/X, some users have XFree86 installed which creates a link from
-# /usr/include/GL to /usr/X11R6/include/GL.  We want to ignore this directory
-# and instead check for Apple's OpenGL.framework, if we are not cross-building
-# for Darwin.  We accomplish this by placing the OpenGL.framework test ahead of
-# the other tests.
-#
-# At least one user (Jorrit) has a strange installation in which inclusion of
-# <windows.h> fails if an int32 is not present, thus we must take this into
-# account.
-#------------------------------------------------------------------------------
-m4_define([cs_define_int32],
-    [[#if !HAVE_TYPE_INT32
-    typedef long int32;
-    #endif
-    ]])
-
-# CS_GL_INCLUDE(CPP-MACRO,FALLBACK,HEADER)
-AC_DEFUN([CS_GL_INCLUDE],
-    [[#if HAVE_WINDOWS_H
-    #if !HAVE_TYPE_INT32
-    typedef long int32;
-    #endif
-    #include <windows.h>
-    #endif
-    #ifndef CS_HEADER_GLOBAL
-    #define CS_HEADER_GLOBAL(X,Y) CS_HEADER_GLOBAL_COMPOSE(X,Y)
-    #define CS_HEADER_GLOBAL_COMPOSE(X,Y) <X/Y>
-    #endif
-    #ifdef $1
-    #include CS_HEADER_GLOBAL($1,$3)
-    #else
-    #include <$2/$3>
-    #endif]])
-
-AC_DEFUN([CS_CHECK_OPENGL],
-    [AC_REQUIRE([CS_CHECK_HOST])
-    AC_REQUIRE([CS_CHECK_COMMON_LIBS])
-    AC_REQUIRE([CS_CHECK_PTHREAD])
-    AC_REQUIRE([AC_PATH_X])
-    AC_REQUIRE([AC_PATH_XTRA])
-    AC_CHECK_TYPE([int32], [AC_DEFINE([HAVE_TYPE_INT32], [], 
-	[Whether the int32 type is available])], [])
-    AC_CHECK_HEADERS([windows.h], [], [], [cs_define_int32])
-    
-    # Apply plaform-specific flags if necessary.
-    cs_gl_plat_cflags=''
-    cs_gl_plat_lflags=''
-    cs_gl_plat_libs=''
-    AS_IF([test -n "$cs_cv_libm_cflags$cs_cv_libm_lflags$cs_cv_libm_libs"],
-	[cs_gl_plat_cflags="$cs_cv_libm_cflags $cs_gl_plat_cflags"
-	cs_gl_plat_lflags="$cs_cv_libm_lflags $cs_gl_plat_lflags"
-	cs_gl_plat_libs="$cs_cv_libm_libs $cs_gl_plat_libs"])
-    AS_IF([test $cs_cv_sys_pthread = yes],
-	[cs_gl_plat_cflags="$cs_cv_sys_pthread_cflags $cs_gl_plat_cflags"
-	cs_gl_plat_lflags="$cs_cv_sys_pthread_lflags $cs_gl_plat_lflags"
-	cs_gl_plat_libs="$cs_cv_sys_pthread_libs $cs_gl_plat_libs"])
-    AS_IF([test "$no_x" != yes],
-	[cs_gl_plat_cflags="$X_CFLAGS $cs_gl_plat_cflags"
-	cs_gl_plat_lflags="$cs_gl_plat_lflags"
-	cs_gl_plat_libs="
-	    $X_PRE_LIBS $X_LIBS -lX11 -lXext $X_EXTRA_LIBS $cs_gl_plat_libs"])
-
-    # Mesa requested?
-    AC_ARG_WITH([mesa], [AC_HELP_STRING([--with-mesa],
-	    [use Mesa OpenGL library if available (default YES)])],
-	    [], [with_mesa=yes])
-    
-    AS_IF([test $with_mesa != no],
-	[cs_mesa_gl=CS_CREATE_TUPLE([],[],[-lMesaGL])])
-    
-    # MacOS/X or Darwin?
-    AS_IF([test "x$cs_host_macosx" = "xyes"],
-	[cs_osx_gl=CS_CREATE_TUPLE([-DCS_OPENGL_PATH=OpenGL],[],[-framework OpenGL])])
-    AS_IF([test "x$cs_host_macosx" = "xyes"],
-          [cs_gl_plat_lflags="$cs_plat_lflags -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib"])
-
-    # Windows?
-    AS_IF([test $cs_host_family = windows],
-	[cs_win32_gl=CS_CREATE_TUPLE([],[],[-lopengl32])])
-    
-    # Check for OpenGL.
-    CS_CHECK_BUILD([for OpenGL], [cs_cv_libgl],
-	[AC_LANG_PROGRAM([CS_GL_INCLUDE([CS_OPENGL_PATH],[GL],[gl.h])],[glEnd()])],
-	[$cs_win32_gl \
-	$cs_osx_gl \
-	CS_CREATE_TUPLE([],[],[-lGL]) \
-	CS_CREATE_TUPLE([],[],[-lgl]) \
-	$cs_mesa_gl], [],
-	[CS_EMIT_BUILD_RESULT([cs_cv_libgl], [GL])], [], [],
-	[$cs_gl_plat_cflags], [$cs_gl_plat_lflags], [$cs_gl_plat_libs])])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_GLU
-#	Check for GLU.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_GLU],
-    [AC_REQUIRE([CS_CHECK_OPENGL])
-    AS_IF([test $cs_cv_libgl = yes],
-        [AS_IF([test $with_mesa != no],
-	    [cs_mesa_glu=CS_CREATE_TUPLE([],[],[-lMesaGLU])])
-	
-	# MacOS/X or Darwin?
-	AS_IF([test "x$cs_host_macosx" = "xyes"],
-	    [cs_osx_glu=CS_CREATE_TUPLE([-DCS_GLU_PATH=OpenGL],[],[-framework OpenGL])])
-	
-	# Windows?
-	AS_IF([test $cs_host_family = windows],
-	    [cs_win32_glu=CS_CREATE_TUPLE([],[],[-lglu32])])
-    
-	# Check for GLU.
-	CS_CHECK_BUILD([for GLU], [cs_cv_libglu],
-	    [AC_LANG_PROGRAM(
-		[CS_GL_INCLUDE([CS_GLU_PATH],[GL],[glu.h])], [gluNewQuadric()])],
-	    [$cs_osx_glu \
-	    CS_CREATE_TUPLE() \
-	    $cs_win32_glu \
-	    CS_CREATE_TUPLE([],[],[-lGLU]) \
-	    CS_CREATE_TUPLE([],[],[-lglu]) \
-	    $cs_mesa_glu], [],
-	    [CS_EMIT_BUILD_RESULT([cs_cv_libglu], [GLU])], [], [],
-	    [$cs_cv_libgl_cflags], [$cs_cv_libgl_lflags], [$cs_cv_libgl_libs])])])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_GLX
-#	Check for GLX.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_GLX],
-    [AC_REQUIRE([CS_CHECK_OPENGL])
-    AS_IF([test $cs_cv_libgl = yes],
-        [AS_IF([test $with_mesa != no],
-            [cs_mesa_glx=CS_CREATE_TUPLE([],[],[-lMesaGLX])])
-	
-        # Check for GLX.
-	AS_IF([test "$no_x" != yes],
-	    [CS_CHECK_BUILD([for GLX], [cs_cv_libglx],
-		[AC_LANG_PROGRAM([[#include <GL/glx.h>]], [glXWaitGL()])],
-		[CS_CREATE_TUPLE() \
-		CS_CREATE_TUPLE([],[],[-lGLX]) \
-		CS_CREATE_TUPLE([],[],[-lglx]) \
-		$cs_mesa_glx], [],
-		[CS_EMIT_BUILD_RESULT([cs_cv_libglx], [GLX])], [], [],
-		[$cs_cv_libgl_cflags], [$cs_cv_libgl_lflags], [$cs_cv_libgl_libs])])])])
-    
-
-#------------------------------------------------------------------------------
-# CS_CHECK_GLXEXT([ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
-#	Check for GLX extensions.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_GLXEXT],
-    [AC_REQUIRE([CS_CHECK_GLX])
-    AS_IF([test x$cs_cv_libglx = "xyes"],
-	[# Check for GLX extensions.
-	CS_CHECK_BUILD([for GLX extensions], [cs_cv_libglx_extensions],
-	    [AC_LANG_PROGRAM(
-		[[#define GLX_GLXEXT_PROTOTYPES
-		#include <GL/glx.h>]],
-		[glXGetProcAddressARB(0)])],
-	    [CS_CREATE_TUPLE(
-		[$cs_cv_libglx_cflags],
-		[$cs_cv_libglx_lflags],
-		[$cs_cv_libglx_libs])],
-	    [], [$1], [$2])])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_GLUT
-#	Check for GLUT.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_GLUT],
-    [AC_REQUIRE([CS_CHECK_GLU])
-    AS_IF([test x$cs_cv_libglu = "xyes"],
-        [# MacOS/X or Darwin?
-	AS_IF([test "x$cs_host_macosx" = "xyes"],
-	    [cs_osx_glut=CS_CREATE_TUPLE([-DCS_GLUT_PATH=GLUT],[],[-framework GLUT])])
-	
-	# Windows?
-	AS_IF([test $cs_host_family = windows],
-	    [cs_win32_glut=CS_CREATE_TUPLE([],[],[-lglut32])])
-    
-	# Check for GLUT.
-	CS_CHECK_BUILD([for GLUT], [cs_cv_libglut],
-	    [AC_LANG_PROGRAM(
-		[CS_GL_INCLUDE([CS_GLUT_PATH],[GL],[glut.h])], [glutSwapBuffers()])],
-	    [$cs_osx_glut \
-	    CS_CREATE_TUPLE() \
-	    $cs_win32_glut \
-	    CS_CREATE_TUPLE([],[],[-lGLUT]) \
-	    CS_CREATE_TUPLE([],[],[-lglut])], [],
-	    [CS_EMIT_BUILD_RESULT([cs_cv_libglut], [GLUT])], [], [],
-	    [$cs_cv_libgl_cflags $cs_cv_libglu_cflags], 
-	    [$cs_cv_libgl_lflags $cs_cv_libglu_lflags], 
-	    [$cs_cv_libgl_libs   $cs_cv_libglu_libs])])])
-
-# checkpic.m4                                                  -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_PIC([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                 [ACTION-IF-NOT-FOUND])
-#	Check if compiler can be instructed to produce
-#	position-independent-code (PIC).  This feature is required by some
-#	platforms when building plugin modules and shared libraries.  If
-#	LANGUAGE is not provided, then `C' is assumed (other options include
-#	`C++').  If CACHE-VAR is not provided, then it defaults to the name
-#	"cs_cv_prog_compiler_pic".  If a PIC-enabling option (such as `-fPIC')
-#	is discovered, then it is assigned to CACHE-VAR and ACTION-IF-FOUND is
-#	invoked; otherwise the empty string is assigned to CACHE-VAR and
-#	ACTION-IF-NOT-FOUND is invoked.
-#
-# IMPLEMENTATION NOTES
-#
-#	On some platforms (such as Windows), the -fPIC option is superfluous
-#	and emits a warning "-fPIC ignored for target (all code is position
-#	independent)", despite the fact that the compiler accepts the option
-#	and returns a success code. We want to re-interpret the warning as a
-#	failure in order to avoid unnecessary compiler diagnostics in case the
-#	client inserts the result of this check into CFLAGS, for instance. We
-#	do so by attempting to promote warnings to errors using the result of
-#	CS_COMPILER_ERRORS(). As an extra safe-guard, we also scan the compiler
-#	output for an appropriate diagnostic because some gcc warnings fail to
-#	promote to error status despite use of -Werror.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_PIC],
-    [CS_COMPILER_ERRORS([$1],
-	[m4_default([$2_werror],[cs_cv_prog_compiler_pic_werror])])
-    CS_CHECK_BUILD_FLAGS(
-	[how to enable m4_default([$1],[C]) PIC generation],
-	[m4_default([$2],[cs_cv_prog_compiler_pic])],
-	[CS_CREATE_TUPLE([-fPIC])], [$1], [$3], [$4],
-	[m4_default([$$2_werror],[$cs_cv_prog_compiler_pic_werror])], [], [],
-	[fPIC])])
-
-# Backward-compatiblity alias.
-AC_DEFUN([CS_CHECK_COMPILER_PIC], [CS_COMPILER_PIC([$1],[$2],[$3],[$4])])
-# checkprog.m4                                                 -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2004 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# cs_bin_paths_default
-#	Comma delimited list of additional directories in which tools and
-#	commands might be found.
-#
-# Present Cases:
-#	/usr/local/bin -- Although a common location for executables, it is
-#		now-and-then absent from the default PATH setting.
-#	/sw/bin -- Fink, the MacOS/X manager of Unix packages, installs
-#		executables here.
-#------------------------------------------------------------------------------
-m4_define([cs_bin_paths_default], [/usr/local/bin, /sw/bin])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_PROG(VARIABLE, PROGRAM, VALUE-IF-FOUND, [VALUE-IF-NOT-FOUND],
-#		[PATH], [REJECT])
-#	Simple wrapper for AC_CHECK_PROG() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_PROG],
-    [_CS_PROG_PATH_PREPARE
-    AC_CHECK_PROG([$1], [$2], [$3], [$4],
-	m4_ifval([$5], [_CS_PROG_CLIENT_PATH([$5])]), [$6])])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_PROGS(VARIABLE, PROGRAMS, [VALUE-IF-NOT-FOUND], [PATH])
-#	Simple wrapper for AC_CHECK_PROGS() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_PROGS],
-    [_CS_PROG_PATH_PREPARE
-    AC_CHECK_PROGS([$1], [$2], [$3],
-	m4_ifval([$4], [_CS_PROG_CLIENT_PATH([$4])]))])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_TOOL(VARIABLE, TOOL, [VALUE-IF-NOT-FOUND], [PATH])
-#	Simple wrapper for AC_CHECK_TOOL() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_TOOL],
-    [_CS_PROG_PATH_PREPARE
-    AC_CHECK_TOOL([$1], [$2], [$3],
-	m4_ifval([$4], [_CS_PROG_CLIENT_PATH([$4])]))])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_TOOLS(VARIABLE, TOOLS, [VALUE-IF-NOT-FOUND], [PATH])
-#	Simple wrapper for AC_CHECK_TOOLS() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_TOOLS],
-    [_CS_PROG_PATH_PREPARE
-    AC_CHECK_TOOLS([$1], [$2], [$3],
-	m4_ifval([$4], [_CS_PROG_CLIENT_PATH([$4])]))])
-
-
-#------------------------------------------------------------------------------
-# CS_PATH_PROG(VARIABLE, PROGRAM, [VALUE-IF-NOT-FOUND], [PATH])
-#	Simple wrapper for AC_PATH_PROG() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_PATH_PROG],
-    [_CS_PROG_PATH_PREPARE
-    AC_PATH_PROG([$1], [$2], [$3],
-	m4_ifval([$4], [_CS_PROG_CLIENT_PATH([$4])]))])
-
-
-#------------------------------------------------------------------------------
-# CS_PATH_PROGS(VARIABLE, PROGRAMS, [VALUE-IF-NOT-FOUND], [PATH])
-#	Simple wrapper for AC_PATH_PROGS() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_PATH_PROGS],
-    [_CS_PROG_PATH_PREPARE
-    AC_PATH_PROGS([$1], [$2], [$3],
-	m4_ifval([$4], [_CS_PROG_CLIENT_PATH([$4])]))])
-
-
-#------------------------------------------------------------------------------
-# CS_PATH_TOOL(VARIABLE, TOOL, [VALUE-IF-NOT-FOUND], [PATH])
-#	Simple wrapper for AC_PATH_TOOL() which ensures that the search path
-#	is augmented by the directories mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_PATH_TOOL],
-    [_CS_PROG_PATH_PREPARE
-    AC_PATH_TOOL([$1], [$2], [$3],
-	m4_ifval([$4], [_CS_PROG_CLIENT_PATH([$4])]))])
-
-
-#------------------------------------------------------------------------------
-# _CS_PROG_PATH_PREPARE
-#	Ensure that the PATH environment variable mentions the set of
-#	directories listed in cs_bin_paths_default. These directories may not
-#	appear by default in the typical PATH, yet they might be common
-#	locations for tools and commands.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_PROG_PATH_PREPARE],
-    [AS_REQUIRE([_AS_PATH_SEPARATOR_PREPARE])
-    AS_IF([test "$cs_prog_path_prepared" != yes],
-	[cs_prog_path_prepared=yes
-	PATH="$PATH[]m4_foreach([cs_bin_path], [cs_bin_paths_default],
-	[$PATH_SEPARATOR[]cs_bin_path])"
-	export PATH])])
-
-
-#------------------------------------------------------------------------------
-# _CS_PROG_CLIENT_PATH(CLIENT-PATH)
-#	Given a client-supplied replacement for PATH, augment the list by
-#	appending the locations mentioned in cs_bin_paths_default.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_PROG_CLIENT_PATH],
-    [AS_REQUIRE([_AS_PATH_SEPARATOR_PREPARE])dnl
-    $1[]m4_foreach([cs_bin_path], [cs_bin_paths_default],
-	[$PATH_SEPARATOR[]cs_bin_path])])
-# checkpthread.m4                                              -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003-2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_PTHREAD([REJECT-MASK])
-#	Check for pthread.  Also check if the pthread implementation supports
-#	the recursive and timed mutex extensions. (Timed mutexes are needed for
-#	the NPTL: New Posix Thread Library on GNU/Linux if the mutex is going
-#	to be used with any of the timed condition-wait functions.) The shell
-#	variable cs_cv_sys_pthread is set to "yes" if pthread is available,
-#	else "no". If available, then the variables cs_cv_sys_pthread_cflags,
-#	cs_cv_sys_pthread_lflags, and cs_cv_sys_pthread_libs are set. (As a
-#	convenience, these variables can be emitted to an output file with
-#	CS_EMIT_BUILD_RESULT() by passing "cs_cv_sys_pthread" as its CACHE-VAR
-#	argument.)  If the recursive mutex extension is supported, then
-#	cs_cv_sys_pthread_mutex_recursive will be set with the literal name of
-#	the constant which must be passed to pthread_mutexattr_settype() to
-#	enable this feature. The constant name will be typically
-#	PTHREAD_MUTEX_RECURSIVE or PTHREAD_MUTEX_RECURSIVE_NP. If the recursive
-#	mutex extension is not available, then
-#	cs_cv_sys_pthread_mutex_recursive will be set to "no".  If the timed
-#	mutex extension is supported, then cs_cv_sys_pthread_mutex_timed will
-#	be set with the literal name of the constant which must be passed to
-#	pthread_mutexattr_settype() to enable this feature. The constant name
-#	will be typically PTHREAD_MUTEX_TIMED or PTHREAD_MUTEX_TIMED_NP. If the
-#	timed mutex extension is not available, then
-#	cs_cv_sys_pthread_mutex_timed will be set to "no".  REJECT-MASK can be
-#	used to limit the platforms on which the pthread test is performed. It
-#	is compared against $host_os; matches are rejected. If omitted, then
-#	the test is performed on all platforms. Examples: To avoid testing on
-#	Cygwin, use "cygwin*"; to avoid testing on Cygwin and AIX, use
-#	"cygwin*|aix*".
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_PTHREAD],
-    [AC_REQUIRE([AC_CANONICAL_HOST])
-    case $host_os in
-	m4_ifval([$1],
-	[$1)
-	    cs_cv_sys_pthread=no
-	    ;;
-	])
-	*)
-	    CS_CHECK_BUILD([for pthread], [cs_cv_sys_pthread],
-		[AC_LANG_PROGRAM(
-		    [[#include <pthread.h>
-		    #include <semaphore.h>
-		    void* worker(void* p) { (void)p; return p; }]],
-		    [pthread_t tid;
-		    sem_t sem;
-		    pthread_create(&tid, 0, worker, 0);
-		    sem_init(&sem, 0, 0);
-		    sem_destroy(&sem);])],
-		[cs_pthread_flags])
-	    ;;
-    esac
-    _CS_CHECK_MUTEX_FEATURE([PTHREAD_MUTEX_RECURSIVE],
-	[cs_cv_sys_pthread_mutex_recursive], [for pthread recursive mutexes])])
-
-# _CS_CHECK_MUTEX_FEATURE(FEATURE, CACHE-VAR, MESSAGE)
-AC_DEFUN([_CS_CHECK_MUTEX_FEATURE],
-    [AS_IF([test $cs_cv_sys_pthread = yes],
-	[AC_CACHE_CHECK([$3], [$2],
-	    [CS_BUILD_IFELSE(
-		[AC_LANG_PROGRAM(
-		    [[#include <pthread.h>]],
-		    [pthread_mutexattr_t attr;
-		    pthread_mutexattr_settype(&attr, CS_MUTEX_FEATURE);])],
-		[CS_CREATE_TUPLE([-DCS_MUTEX_FEATURE=$1]) \
-		CS_CREATE_TUPLE([-DCS_MUTEX_FEATURE=$1_NP])],
-		[],
-		[$2=`echo $cs_build_cflags | sed 's/.*\($1_*N*P*\).*/\1/'`],
-		[$2=no],
-		[$cs_cv_sys_pthread_cflags -D_GNU_SOURCE],
-		[$cs_cv_sys_pthread_lflags],
-		[$cs_cv_sys_pthread_libs])])],
-	[$2=no])])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_PTHREAD_ATFORK(CACHE-VAR)
-#     Checks whether the pthread library contains pthread_atfork(). Sets
-#     CACHE-VAR to "yes" or "no", according to the test result.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_PTHREAD_ATFORK],
-    [AS_IF([test $cs_cv_sys_pthread = yes],
-	[AC_CACHE_CHECK([for pthread_atfork support], [$1],
-	    [CS_BUILD_IFELSE(
-		[AC_LANG_PROGRAM(
-		    [[#include <pthread.h>]],
-		    [pthread_atfork (0, 0, 0);])],
-		[], [],
-		[$1=yes], [$1=no],
-		[$cs_cv_sys_pthread_cflags -D_GNU_SOURCE],
-		[$cs_cv_sys_pthread_lflags],
-		[$cs_cv_sys_pthread_libs])])],
-	[$1=no])])
-
-m4_define([cs_pthread_flags],
-    [CS_CREATE_TUPLE() \
-    CS_CREATE_TUPLE([], [], [-lpthread]) \
-    CS_CREATE_TUPLE([], [], [-lpthread -lrt]) \
-    CS_CREATE_TUPLE([-pthread], [-pthread], []) \
-    CS_CREATE_TUPLE([-pthread], [-pthread], [-lpthread]) \
-    CS_CREATE_TUPLE([-pthread], [-pthread], [-lc_r])])
-# checktt2.m4                                                  -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2004,2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_TEMPLATE_TOOLKIT2([EMITTER])
-#	Check if Template Toolkit 2 (http://www.tt2.org/) is available. The
-#	shell variable cs_cv_perl_tt2 is set to "yes" if the package is
-#	discovered, else "no". Also sets the shell variable TTREE to the name
-#	path of the 'ttree' utility program and invokes AC_SUBST().  If EMITTER
-#	is provided and the package was discovered, then
-#	CS_EMIT_BUILD_PROPERTY() is invoked with EMITTER in order to record the
-#	value of the TTREE variable in an output file. As a convenience, if
-#	EMITTER is the literal value "emit" or "yes", then
-#	CS_EMIT_BUILD_RESULT()'s default emitter will be used.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_TEMPLATE_TOOLKIT2],
-    [CS_CHECK_PROGS([PERL], [perl5 perl])
-    AS_IF([test -n "$PERL"],
-	[AC_CACHE_CHECK([for TemplateToolkit], [cs_cv_perl_tt2],
-	    [AS_IF([AC_RUN_LOG(
-		[$PERL -M'Template 2.11' -MTemplate::Plugin -e 0 1>&2])],
-		[cs_cv_perl_tt2=yes],
-		[cs_cv_perl_tt2=no])])
-	CS_PATH_PROGS([TTREE], [ttree])
-	AS_IF([test $cs_cv_perl_tt2 = yes && test -n "$TTREE"],
-	    [CS_EMIT_BUILD_PROPERTY([TTREE], [$TTREE], [], [],
-		CS_EMITTER_OPTIONAL([$1]))])])])
-# compiler.m4                                                  -*- Autoconf -*-
-#=============================================================================
-# Copyright (C)2003 by Matze Braun <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#=============================================================================
-
-#-----------------------------------------------------------------------------
-# Detection of C and C++ compilers and setting flags
-#
-# CS_PROG_CC
-#       Detects the C compiler.  Also takes care of the CFLAGS, CPPFLAGS and CC
-#       environment variables.  This will filter out all -g and -O from the
-#       CFLAGS variable because Autoconf's -g and -O defaults are not always
-#       desired.  This will also set the CMD.CC and COMPILER.CFLAGS variables
-#       in Jamconfig
-# CS_PROG_CXX
-#       Detects the C++ compiler.  Also takes care of the CXXFLAGS, CPPFLAGS
-#       and CXX environment variables.  This will filter out all -g and -O from
-#       the CXXFLAGS variable because Autoconf's -g and -O defaults are not
-#       always desired.  This will also set the CMD.C++ and COMPILER.C++FLAGS
-#       variables in Jamconfig
-# CS_PROG_LINK
-#	Tries to determine a linker.  This is done by checking if a C++ or
-#       Objecctive-C++ compiler is available in which case it is used for
-#       linking; otherwise the C or Objective-C compiler is used.  This also
-#       sets the CMD.LINK and COMPILER.LFLAGS variables in Jamconfig and
-#       respects the LDFLAGS environment variable.  Finally, checks if linker
-#	recognizes -shared and sets PLUGIN.LFLAGS; and checks if linker
-#	recognizes -soname and sets PLUGIN.LFLAGS.USE_SONAME to "yes".
-#-----------------------------------------------------------------------------
-AC_DEFUN([CS_PROG_CC],[
-    CFLAGS="$CFLAGS" # Filter undesired flags
-    AC_PROG_CC
-    AS_IF([test -n "$CC"],[
-	CS_EMIT_BUILD_PROPERTY([CMD.CC], [$CC])
-	CS_EMIT_BUILD_PROPERTY([COMPILER.CFLAGS], [$CPPFLAGS $CFLAGS], [+])
-	
-	# Check if compiler recognizes -pipe directive.
-	CS_EMIT_BUILD_FLAGS([if $CC accepts -pipe], [cs_cv_prog_cc_pipe],
-	  [CS_CREATE_TUPLE([-pipe])], [C], [COMPILER.CFLAGS], [+])
-    ])
-])
-
-AC_DEFUN([CS_PROG_CXX],[
-    CXXFLAGS="$CXXFLAGS" # Filter undesired flags
-    AC_PROG_CXX
-    AS_IF([test -n "$CXX"],[
-	CS_EMIT_BUILD_PROPERTY([CMD.C++], [$CXX])
-
-	CS_EMIT_BUILD_PROPERTY([COMPILER.C++FLAGS], [$CPPFLAGS $CXXFLAGS], [+])
-
-        # Check if compiler can be instructed to produce position-independent-code
-        # (PIC).  This feature is required by some platforms when building plugin
-        # modules and shared libraries.
-	CS_COMPILER_PIC([C++], [cs_cv_prog_cxx_pic],
-	    [CS_EMIT_BUILD_PROPERTY([COMPILER.C++FLAGS.PIC],
-		[$cs_cv_prog_cxx_pic])])
-    ])
-])
-
-AC_DEFUN([CS_PROG_LINK],[
-    AC_REQUIRE([CS_PROG_CXX])
-    AS_IF([test -n "$CXX"],
-	[CS_EMIT_BUILD_PROPERTY([CMD.LINK], [AS_ESCAPE([$(CMD.C++)])])],
-	[CS_EMIT_BUILD_PROPERTY([CMD.LINK], [AS_ESCAPE([$(CMD.CC)])])])
-
-    CS_EMIT_BUILD_PROPERTY([COMPILER.LFLAGS], [$LDFLAGS], [+])
-
-    # Check if compiler/linker recognizes -shared directive which is needed for
-    # linking plugin modules.  Unfortunately, the Apple compiler (and possibly
-    # others) requires extra effort.  Even though the compiler does not recognize
-    # the -shared option, it nevertheless returns a "success" result after emitting
-    # the warning "unrecognized option `-shared'".  Worse, even -Werror fails to
-    # promote the warning to an error, so we must instead scan the compiler's
-    # output for an appropriate diagnostic.
-    CS_CHECK_BUILD_FLAGS([if -shared is accepted], [cs_cv_prog_link_shared],
-	[CS_CREATE_TUPLE([-shared $cs_cv_prog_cxx_pic])], [C++],
-	[CS_EMIT_BUILD_PROPERTY([PLUGIN.LFLAGS], [-shared], [+])], [],
-	[], [], [], [shared])
-
-    # Check if linker recognizes -soname which is used to assign a name internally
-    # to plugin modules.
-    CS_CHECK_BUILD([if -soname is accepted], [cs_cv_prog_link_soname], [],
-	[CS_CREATE_TUPLE([-Wl,-soname,foobar])], [C++],
-	[CS_EMIT_BUILD_PROPERTY([PLUGIN.LFLAGS.USE_SONAME], [yes])])
-])
-#------------------------------------------------------------------------------
-# Determine host platform.  Recognized families: Unix, Windows, MacOS/X.
-# Orginial Macros Copyright (C)2003 Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#------------------------------------------------------------------------------
-
-#------------------------------------------------------------------------------
-# Determine host CPU.
-#
-# CS_CHECK_HOST_CPU
-#       Set the shell variable cs_host_cpu to a normalized form of the CPU name
-#       returned by config.guess/config.sub.  Typically, Crystal Space's
-#       conception of CPU name is the same as that returned by
-#       config.guess/config.sub, but there may be exceptions as seen in the
-#       `case' statement.  Also takes the normalized name, uppercases it to
-#       form a name suitable for the C preprocessor.  Additionally sets the
-#       TARGET.PROCESSOR Jamconfig property.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_HOST_CPU],
-    [AC_REQUIRE([AC_CANONICAL_HOST])
-    case $host_cpu in
-        [[Ii][3-9]86*|[Xx]86*]) cs_host_cpu=x86 ;;
-        *) cs_host_cpu=$host_cpu ;;
-    esac
-    cs_host_cpu_normalized="AS_TR_CPP([$cs_host_cpu])"
-    CS_JAMCONFIG_PROPERTY([TARGET.PROCESSOR], [$cs_host_cpu_normalized])
-    ])
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_HOST
-#       Sets the shell variables cs_host_target cs_host_family,
-#       cs_host_os_normalized, and cs_host_os_normalized_uc.  Emits appropriate
-#       CS_PLATFORM_UNIX, CS_PLATFORM_WIN32, CS_PLATFORM_MACOSX via
-#       AC_DEFINE(), and TARGET.OS and TARGET.OS.NORMALIZED to Jamconfig.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_HOST],
-    [AC_REQUIRE([AC_CANONICAL_HOST])
-    CS_CHECK_HOST_CPU
-    cs_host_os_normalized=''
-    case $host_os in
-        mingw*|cygwin*)
-            cs_host_target=win32gcc
-            cs_host_family=windows
-            ;;
-        darwin*)
-            _CS_CHECK_HOST_DARWIN
-            ;;
-        *)
-            # Everything else is assumed to be Unix or Unix-like.
-            cs_host_target=unix
-            cs_host_family=unix
-	    ;;
-    esac
-
-    case $cs_host_family in
-	windows)
-            AC_DEFINE([CS_PLATFORM_WIN32], [],
-		[Define when compiling for Win32])
-	    AS_IF([test -z "$cs_host_os_normalized"],
-		[cs_host_os_normalized='Win32'])
-	    ;;
-	unix)
-            AC_DEFINE([CS_PLATFORM_UNIX], [],
-		[Define when compiling for Unix and Unix-like (i.e. MacOS/X)])
-	    AS_IF([test -z "$cs_host_os_normalized"],
-		[cs_host_os_normalized='Unix'])
-	    ;;
-    esac
-
-    cs_host_os_normalized_uc="AS_TR_CPP([$cs_host_os_normalized])"
-    CS_JAMCONFIG_PROPERTY([TARGET.OS], [$cs_host_os_normalized_uc])
-    CS_JAMCONFIG_PROPERTY([TARGET.OS.NORMALIZED], [$cs_host_os_normalized])
-])
-
-AC_DEFUN([_CS_CHECK_HOST_DARWIN],
-    [AC_REQUIRE([CS_PROG_CC])
-    AC_REQUIRE([CS_PROG_CXX])
-
-    # Both MacOS/X and Darwin are identified via $host_os as "darwin".  We need
-    # a way to distinguish between the two.  If Carbon.h is present, then
-    # assume MacOX/S; if not, assume Darwin.  If --with-x=yes was invoked, and
-    # Carbon.h is present, then assume that user wants to cross-build for
-    # Darwin even though build host is MacOS/X.
-    # IMPLEMENTATION NOTE *1*
-    # The QuickTime 7.0 installer removes <CarbonSound/CarbonSound.h>, which
-    # causes #include <Carbon/Carbon.h> to fail unconditionally. Re-installing
-    # the QuickTime SDK should restore the header, however not all developers
-    # know to do this, so we work around the problem of the missing
-    # CarbonSound.h by #defining __CARBONSOUND__ in the test in order to
-    # prevent Carbon.h from attempting to #include the missing header.
-    # IMPLEMENTATION NOTE *2*
-    # At least one MacOS/X user switches between gcc 2.95 and gcc 3.3 with a
-    # script which toggles the values of CC, CXX, and CPP.  Unfortunately, CPP
-    # was being set to run the preprocessor directly ("cpp", for instance)
-    # rather than running it via the compiler ("gcc -E", for instance).  The
-    # problem with running the preprocessor directly is that __APPLE__ and
-    # __GNUC__ are not defined, which causes the Carbon.h check to fail.  We
-    # avoid this problem by supplying a non-empty fourth argument to
-    # AC_CHECK_HEADER(), which causes it to test compile the header only (which
-    # is a more robust test), rather than also testing it via the preprocessor.
-
-    AC_DEFINE([__CARBONSOUND__], [],
-	[Avoid problem caused by missing <Carbon/CarbonSound.h>])
-    AC_CHECK_HEADER([Carbon/Carbon.h],
-	[cs_host_macosx=yes], [cs_host_macosx=no], [/* force compile */])
-
-    AS_IF([test $cs_host_macosx = yes],
-	[AC_MSG_CHECKING([for --with-x])
-	AS_IF([test "${with_x+set}" = set && test "$with_x" = "yes"],
-	    [AC_MSG_RESULT([yes (assume Darwin)])
-	    cs_host_macosx=no],
-	    [AC_MSG_RESULT([no])])])
-
-    AS_IF([test $cs_host_macosx = yes],
-	[cs_host_target=macosx
-	cs_host_family=unix
-	cs_host_os_normalized='MacOS/X'
-        AC_DEFINE([CS_PLATFORM_MACOSX], [],
-	    [Define when compiling for MacOS/X])
-
-	AC_CACHE_CHECK([for Objective-C compiler], [cs_cv_prog_objc],
-	    [cs_cv_prog_objc="$CC"])
-	CS_JAMCONFIG_PROPERTY([CMD.OBJC], [$cs_cv_prog_objc])
-	AC_CACHE_CHECK([for Objective-C++ compiler], [cs_cv_prog_objcxx],
-	    [cs_cv_prog_objcxx="$CXX"])
-	CS_JAMCONFIG_PROPERTY([CMD.OBJC++], [$cs_cv_prog_objcxx])],
-
-	[cs_host_target=unix
-	cs_host_family=unix])])
-# diagnose.m4                                                  -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_MSG_ERROR(ERROR-DESCRIPTION, [EXIT-STATUS])
-#	A convenience wrapper for AC_MSG_ERROR() which invokes AC_CACHE_SAVE()
-#	before aborting the script.  Saving the cache should make subsequent
-#	re-invocations of the configure script faster once the user has
-#	corrected the problem(s) which caused the failure.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_MSG_ERROR],
-    [AC_CACHE_SAVE
-    AC_MSG_ERROR([$1], [$2])])
-# embed.m4                                                     -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003,2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_META_INFO_EMBED([EMITTER], [GPL-OKAY])
-#	Determine if plugin meta-information should be embedded or if it should
-#	exist in a stand-alone .csplugin file, and check if necessary tools and
-#	libraries are present.  Sets the shell variable
-#	enable_meta_info_embedding to "yes" if the user requested embedding or
-#	if it was enabled by default; otherwise sets it to "no".
-#
-#	If EMITTER is provided, then a subset of the following variables
-#	(depending upon platform and availability) are recorded by invoking
-#	CS_EMIT_BUILD_PROPERTY() with EMITTER.  As a convenience, if EMITTER is
-#	the literal value "emit" or "yes", then CS_EMIT_BUILD_RESULT()'s
-#	default emitter will be used.
-#
-#	EMBED_META := yes or no
-#	EMBED_META.CFLAGS := compiler flags
-#	EMBED_META.LFLAGS := linker flags
-#	CMD.WINDRES := windres.exe
-#	OBJCOPY.AVAILABLE := yes or no
-#	CMD.OBJCOPY := objcopy.exe
-#	LIBBFD.AVAILABLE := yes or no
-#	LIBBFD.CFLAGS := libbfd compiler flags
-#	LIBBFD.LFLAGS := libbfd linker flags
-#	ELF.AVAILABLE := yes or no
-#
-#	In general, clients need only concern themselves with the various
-#	EMBED_META-related variables. For building plugin modules, utilize
-#	EMBED_META.CFLAGS when compiling, and EMBED_META.LFLAGS when linking.
-#
-#	On Unix, when CS' own ELF metadata reader can't be used (because the
-#	necessary header file elf.h was not found) embedding is accomplished
-#	via libbfd, which carries a GPL license. Projects which carry licenses
-#	not compatible with GPL should consider carefully before enabling
-#	embedding on Unix. If your project is GPL-compatible, then set GPL-OKAY
-#	to "yes". This will indicate that it is safe to use libbfd if the ELF
-#	reader can not be used.  If your project is not GPL-compatible, then
-#	set it to "no" in order to disable embedding on Unix if the ELF reader
-#	is not usable. (The user can still manually override the setting via
-#	the --enable-meta-info-embedding option.)
-#
-# IMPLEMENTATION NOTES
-#
-#	Recent versions of Mingw supply libbfd and libiberty.  Since Crystal
-#	Space uses native Win32 API for meta-information embedding on Windows,
-#	we do not require these libraries on Windows.  More importantly, users
-#	do not want to see these GPL-licensed libraries appear in the link
-#	statement for plugin modules, thus we explicitly disable the libbfd
-#	test on Windows.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_META_INFO_EMBED],
-    [AC_REQUIRE([AC_CANONICAL_HOST])
-    _CS_META_INFO_EMBED_ENABLE([$1], [$2])
-    AS_IF([test $enable_meta_info_embedding = yes],
-        [_CS_META_INFO_EMBED_TOOLS([$1])
-        AS_IF([test $cs_header_elf_h = yes],
-	    [CS_EMIT_BUILD_PROPERTY([ELF.AVAILABLE], [yes], [], [],
-		CS_EMITTER_OPTIONAL([$1]))],
-            [case $host_os in
-	        mingw*|cygwin*) ;;
-		*)
-		    CS_CHECK_LIBBFD([$1],
-			[CS_EMIT_BUILD_PROPERTY([EMBED_META.CFLAGS],
-			    [$cs_cv_libbfd_ok_cflags], [+], [],
-			    CS_EMITTER_OPTIONAL([$1]))
-			CS_EMIT_BUILD_PROPERTY([EMBED_META.LFLAGS],
-			    [$cs_cv_libbfd_ok_lflags $cs_cv_libbfd_ok_libs],
-			    [+], [], CS_EMITTER_OPTIONAL([$1]))])
-		    ;;
-	    esac])])])
-
-
-#------------------------------------------------------------------------------
-# _CS_META_INFO_EMBED_ENABLE([EMITTER], [GPL-OKAY])
-#	Helper for CS_META_INFO_EMBED which adds an
-#	--enable-meta-info-embedding option to the configure script allowing
-#	the user to control embedding.  Sets the shell variable
-#	enable_meta_info_embedding to yes or no.
-#
-# IMPLEMENTATION NOTES
-#
-#	On Unix, embedding is enabled by default if elf.h is found and disabled
-#	by default unless overridden via GPL-OKAY because libbfd carries a GPL
-#	license which may be incompatible with a project's own license (such as
-#	LGPL).
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_META_INFO_EMBED_ENABLE],
-    [AC_REQUIRE([CS_CHECK_HOST])
-    AC_CHECK_HEADERS([elf.h], [cs_header_elf_h=yes], [cs_header_elf_h=no])
-    AC_MSG_CHECKING([whether to embed plugin meta-information])
-    case $cs_host_target in
-	unix) AS_IF([test $cs_header_elf_h = yes],
-              [cs_embed_meta_info_default=yes],
-              [cs_embed_meta_info_default=m4_ifval([$2],[$2],[no])]) ;;
-	*) cs_embed_meta_info_default=yes ;;
-    esac
-    AC_ARG_ENABLE([meta-info-embedding],
-	[AC_HELP_STRING([--enable-meta-info-embedding],
-	    [store plugin meta-information directly inside plugin modules if
-	    supported by platform; if disabled, meta-information is stored in
-	    stand-alone .csplugin files; this option is enabled by default for
-	    non-Unix platforms and on Unix platforms with ELF-format object
-	    files; it is disabled by default on Unix platforms if ELF is not
-	    available and the project uses a non-GPL-compatible license (such
-	    as LGPL) since the non-ELF Unix embedding technology requires the
-	    GPL-licensed libbfd library; if ELF is not available, enable this
-	    option on Unix only if you are certain you want a GPL-licensed
-	    library infecting your project])],
-	[], [enable_meta_info_embedding=$cs_embed_meta_info_default])
-    AC_MSG_RESULT([$enable_meta_info_embedding])
-    CS_EMIT_BUILD_PROPERTY([EMBED_META], [$enable_meta_info_embedding],
-	[], [], CS_EMITTER_OPTIONAL([$1]))])
-
-
-
-#------------------------------------------------------------------------------
-# _CS_META_INFO_EMBED_TOOLS([EMITTER])
-#	Helper for CS_META_INFO_EMBED() which searches for tools required for
-#	plugin meta-info embedding.
-#------------------------------------------------------------------------------
-AC_DEFUN([_CS_META_INFO_EMBED_TOOLS],
-    [CS_CHECK_TOOLS([WINDRES], [windres])
-    CS_EMIT_BUILD_PROPERTY([CMD.WINDRES], [$WINDRES], [], [],
-	CS_EMITTER_OPTIONAL([$1]))
-
-    CS_CHECK_TOOLS([OBJCOPY], [objcopy])
-    AS_IF([test -n "$OBJCOPY"],
-        [CS_EMIT_BUILD_PROPERTY([OBJCOPY.AVAILABLE], [yes], [], [],
-	    CS_EMITTER_OPTIONAL([$1]))
-        CS_EMIT_BUILD_PROPERTY([CMD.OBJCOPY], [$OBJCOPY], [], [],
-	    CS_EMITTER_OPTIONAL([$1]))])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_CHECK_LIBBFD([EMITTER], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
-#	Exhaustive check for a usable GPL-licensed libbfd, the Binary File
-#	Descriptor library, a component of binutils, which allows low-level
-#	manipulation of executable and object files.  If EMITTER is provided,
-#	then the following variables are recorded by invoking
-#	CS_EMIT_BUILD_PROPERTY() with EMITTER.  As a convenience, if EMITTER is
-#	the literal value "emit" or "yes", then CS_EMIT_BUILD_RESULT()'s
-#	default emitter will be used.
-#
-#	LIBBFD.AVAILABLE := yes or no
-#	LIBBFD.CFLAGS := libbfd compiler flags
-#	LIBBFD.LFLAGS := libbfd linker flags
-#
-#	The shell variable cs_cv_libbfd_ok is set to yes if a usable libbfd was
-#	discovered, else no. If found, the additional shell variables
-#	cs_cv_libbfd_ok_cflags, cs_cv_libbfd_ok_lflags, and
-#	cs_cv_libbfd_ok_libs are also set.
-#
-# WARNING
-#
-#	libbfd carries a GPL license which is incompatible with the LGPL
-#	license of Crystal Space. Do not use this library with projects under
-#	less restrictive licenses, such as LGPL.
-#
-# IMPLEMENTATION NOTES
-#
-#	It seems that some platforms have two version of libiberty installed:
-#	one from binutils and one from gcc.  The binutils version resides in
-#	/usr/lib, whereas the gcc version resides in the gcc installation
-#	directory.  The gcc version, by default, takes precedence at link time
-#	over the binutils version.  Unfortunately, in broken cases, the gcc
-#	version of libiberty is missing htab_create_alloc() which is required
-#	by some libbfd functions.  The extensive secondary check of libbfd
-#	catches this anomalous case of broken gcc libiberty.  It turns out that
-#	it is possible to make the linker prefer the binutils version by
-#	specifying -L/usr/lib, thus the extensive test attempts to do so in an
-#	effort to resolve this unfortunate issue.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_LIBBFD],
-    [CS_CHECK_LIB_WITH([bfd],
-	[AC_LANG_PROGRAM([[#include <bfd.h>]], [bfd_init();])],
-	[], [], [], [], [], [], [-liberty])
-
-    AS_IF([test $cs_cv_libbfd = yes],
-	[CS_CHECK_BUILD([if libbfd is usable], [cs_cv_libbfd_ok],
-	    [AC_LANG_PROGRAM([[#include <bfd.h>]],
-		[bfd* p;
-		asection* s;
-		bfd_init();
-		p = bfd_openr(0,0);
-		bfd_check_format(p,bfd_object);
-		bfd_get_section_by_name(p,0);
-		bfd_section_size(p,s);
-		bfd_get_section_contents(p,s,0,0,0);
-		bfd_close(p);])],
-	    [CS_CREATE_TUPLE() CS_CREATE_TUPLE([],[-L/usr/lib],[])],
-	    [], [], [], [],
-	    [$cs_cv_libbfd_cflags],
-	    [$cs_cv_libbfd_lflags],
-	    [$cs_cv_libbfd_libs])],
-	[cs_cv_libbfd_ok=no])
-
-    AS_IF([test $cs_cv_libbfd_ok = yes],
-	[CS_EMIT_BUILD_RESULT([cs_cv_libbfd_ok], [LIBBFD],
-	    CS_EMITTER_OPTIONAL([$1]))
-	$2],
-	[$3])])
-# emit.m4                                                      -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003-2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_EMIT_BUILD_PROPERTY(KEY, VALUE, [APPEND], [EMPTY-OKAY], [EMITTER],
-#                        [UNCONDITIONAL])
-#	A utility function which invokes an emitter to record the KEY/VALUE
-#	tuple if VALUE is not the empty string (after leading and trailing
-#	whitespace is stripped). If EMPTY-OKAY is not an empty string, then the
-#	property is emitted even if VALUE is empty; that is, it is emitted
-#	unconditionally.  If APPEND is the empty string, then the emitter sets
-#	the key's value directly (though it may be overridden by the
-#	environment), otherwise the emitter appends VALUE to the existing value
-#	of the key.  EMITTER is a macro name, such as CS_JAMCONFIG_PROPERTY or
-#	CS_MAKEFILE_PROPERTY, which performs the actual task of emitting the
-#	KEY/VALUE tuple; it should also accept APPEND as an optional third
-#	argument. If EMITTER is omitted, CS_JAMCONFIG_PROPERTY is used.  Some
-#	emitters accept an optional fourth argument, UNCONDITIONAL, which
-#	instructs it to set KEY's value unconditionally, even if KEY already
-#	had been assigned a value via some other mechanism (such as imported
-#	from the environment, or from Jambase, in the case of
-#	CS_JAMCONFIG_PROPERTY).
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_EMIT_BUILD_PROPERTY],
-    [cs_build_prop_val="$2"
-    cs_build_prop_val=CS_TRIM([$cs_build_prop_val])
-    m4_ifval([$4],
-	[CS_JAMCONFIG_PROPERTY([$1], [$cs_build_prop_val], [$3])],
-	AS_IF([test -n "$cs_build_prop_val"],
-	    [m4_default([$5],[CS_JAMCONFIG_PROPERTY])(
-		[$1], [$cs_build_prop_val], [$3], [$6])]))])
-
-
-
-#------------------------------------------------------------------------------
-# CS_EMIT_BUILD_RESULT(CACHE-VAR, PREFIX, [EMITTER])
-#	Record the results of CS_CHECK_BUILD() or CS_CHECK_LIB_WITH() via some
-#	emitter.  If CACHE-VAR indicates that the build succeeded, then the
-#	following properties are emitted:
-#
-#	PREFIX.AVAILABLE = yes
-#	PREFIX.CFLAGS = $CACHE-VAR_cflags
-#	PREFIX.LFLAGS = $CACHE-VAR_lflags $CACHE-VAR_libs
-#
-#	EMITTER is a macro name, such as CS_JAMCONFIG_PROPERTY or
-#	CS_MAKEFILE_PROPERTY, which performs the actual task of emitting the
-#	KEY/VALUE tuple. If EMITTER is omitted, CS_JAMCONFIG_PROPERTY is used.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_EMIT_BUILD_RESULT],
-    [AS_IF([test "$$1" = yes],
-	[CS_EMIT_BUILD_PROPERTY([$2.AVAILABLE], [yes], [], [], [$3])
-	CS_EMIT_BUILD_PROPERTY([$2.CFLAGS], [$$1_cflags], [], [], [$3])
-	CS_EMIT_BUILD_PROPERTY([$2.LFLAGS], [$$1_lflags $$1_libs],
-	    [], [], [$3])])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_EMIT_BUILD_FLAGS(MESSAGE, CACHE-VAR, FLAGS, [LANGUAGE], EMITTER-KEY,
-#                     [APPEND], [ACTION-IF-RECOGNIZED],
-#                     [ACTION-IF-NOT-RECOGNIZED], [EMITTER])
-#	A convenience wrapper for CS_CHECK_BUILD_FLAGS() which also records the
-#	results via CS_EMIT_BUILD_PROPERTY().  Checks if the compiler or linker
-#	recognizes a command-line option.  MESSAGE is the "checking" message.
-#	CACHE-VAR is the shell cache variable which receives the flag
-#	recognized by the compiler or linker, or "no" if the flag was not
-#	recognized.  FLAGS is a whitespace- delimited list of build tuples
-#	created with CS_CREATE_TUPLE().  Each tuple from FLAGS is attempted in
-#	order until one is found which is recognized by the compiler.  After
-#	that, no further flags are checked.  LANGUAGE is typically either C or
-#	C++ and specifies which compiler to use for the test.  If LANGUAGE is
-#	omitted, C is used.  EMITTER-KEY is the name to pass as the emitter's
-#	"key" argument if a usable flag is encountered.  If APPEND is not the
-#	empty string, then the discovered flag is appended to the existing
-#	value of the EMITTER-KEY.  If the command-line option was recognized,
-#	then ACTION-IF-RECOGNIZED is invoked, otherwise
-#	ACTION-IF-NOT-RECOGNIZED is invoked.  EMITTER is a macro name, such as
-#	CS_JAMCONFIG_PROPERTY or CS_MAKEFILE_PROPERTY, which performs the
-#	actual task of emitting the KEY/VALUE tuple; it should also accept
-#	APPEND as an optional third argument. If EMITTER is omitted,
-#	CS_JAMCONFIG_PROPERTY is used.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_EMIT_BUILD_FLAGS],
-    [CS_CHECK_BUILD_FLAGS([$1], [$2], [$3], [$4],
-	[CS_EMIT_BUILD_PROPERTY([$5], [$$2], [$6], [], [$9])
-	    $7],
-	[$8])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_EMITTER_OPTIONAL([EMITTER])
-#	The CS_EMIT_FOO() macros optionally accept an emitter. If no emitter is
-#	supplied to those macros, then a default emitter is chosen.  Other
-#	macros, however, which perform testing and optionally emit the results
-#	may wish to interpret an omitted EMITTER as a request not to emit the
-#	results. CS_EMITTER_OPTIONAL() is a convenience macro to help in these
-#	cases. It should be passed to one of the CS_EMIT_FOO() macros in place
-#	of the literal EMITTER argument. It functions by re-interpretating
-#	EMITTER as follows:
-#
-#	- If EMITTER is omitted, then CS_NULL_EMITTER is returned, effectively
-#	  disabling output by the CS_EMIT_FOO() macro.
-#	- If EMITTER is the literal string "emit" or "yes", then it returns an
-#	  empty string, which signals to the CS_EMIT_FOO() macro that is should
-#	  use its default emitter.
-#	- Any other value for EMITTER is passed along as-is to the
-#	  CS_EMIT_FOO() macro.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_EMITTER_OPTIONAL],
-    [m4_case([$1],
-	[], [[CS_NULL_EMITTER]],
-	[emit], [],
-	[yes], [],
-	[[$1]])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_NULL_EMITTER(KEY, VALUE, [APPEND])
-#	A do-nothing emitter suitable for use as the EMITTER argument of one of
-#	the CS_EMIT_FOO() macros.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_NULL_EMITTER], [:
-])
-
-
-
-#------------------------------------------------------------------------------
-# CS_SUBST_EMITTER(KEY, VALUE, [APPEND])
-#	An emitter wrapped around AC_SUBST(). Invokes
-#	AC_SUBST(AS_TR_SH(KEY),VALUE).  The APPEND argument is ignored.
-#	Suitable for use as the EMITTER argument of one of the CS_EMIT_FOO()
-#	macros.  The call to AS_TR_SH() ensures that KEY is transformed into a
-#	valid shell variable. For instance, if a macro attempts to emit
-#	MYLIB.CFLAGS and MYLIB.LFLAGS via CS_SUBST_EMITTER(), then the names
-#	will be transformed to MYLIB_CFLAGS and MYLIB_LFLAGS, respectively, for
-#	the invocation of AC_SUBST().
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_SUBST_EMITTER], [AC_SUBST(AS_TR_SH([$1]),[$2])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_DEFINE_EMITTER(KEY, VALUE, [APPEND])
-#	An emitter wrapped around AC_DEFINE_UNQUOTED(). Invokes
-#	AC_DEFINE_UNQUOTED(AS_TR_CPP(KEY),VALUE).  The APPEND argument is
-#	ignored.  Suitable for use as the EMITTER argument of one of the
-#	CS_EMIT_FOO() macros. The call to AS_TR_CPP() ensures that KEY is a
-#	well-formed token for the C-preprocessor.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_DEFINE_EMITTER],
-    [AC_DEFINE_UNQUOTED(AS_TR_CPP([$1]),[$2],
-	[Define when feature is available])])
-# headercache.m4                                               -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# Text cache facility for C-style #define properties.  The cache is stored in
-# the shell variable cs_header_text.
-#
-# CS_HEADER_APPEND(TEXT)
-#	Append text to the C header text cache.  This is a cover for
-#	CS_TEXT_CACHE_APPEND().
-#
-# CS_HEADER_PREPEND(TEXT)
-#	Prepend text to the C header text cache.  This is a cover for
-#	CS_TEXT_CACHE_PREPEND().
-#
-# CS_HEADER_PROPERTY(KEY, [VALUE])
-#	Append a line of the form "#define KEY VALUE" to the C header text
-#	cache.  If the VALUE argument is omitted, then the appended line has
-#	the simplified form "#define KEY".
-#
-# CS_HEADER_OUTPUT(FILENAME)
-#	Instruct config.status to write the C header text cache to the given
-#	filename.  This is a cover for CS_TEXT_CACHE_OUTPUT().
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_HEADER_APPEND], [CS_TEXT_CACHE_APPEND([cs_header_text], [$1])])
-AC_DEFUN([CS_HEADER_PREPEND], [CS_TEXT_CACHE_PREPEND([cs_header_text], [$1])])
-AC_DEFUN([CS_HEADER_PROPERTY],
-[CS_HEADER_APPEND([@%:@define $1[]m4_ifval([$2], [ $2], [])
-])])
-AC_DEFUN([CS_HEADER_OUTPUT], [CS_TEXT_CACHE_OUTPUT([cs_header_text], [$1])])
-#-----------------------------------------------------------------------------
-# installdirs.m4 (c) Matze Braun <[email protected]>
-# Macro for emitting the installation paths gathered by Autoconf.
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#-----------------------------------------------------------------------------
-
-#-----------------------------------------------------------------------------
-# CS_OUTPUT_INSTALLDIRS([EMITTER], [RAW-BACKSLASHES])
-#   Emit installation directories collected by Autoconf.  EMITTER is a macro
-#   name, such as CS_JAMCONFIG_PROPERTY or CS_MAKEFILE_PROPERTY, which performs
-#   the actual task of emitting the KEY/VALUE tuple.  If EMITTER is omitted,
-#   CS_JAMCONFIG_PROPERTY is used.  If RAW-BACKSLASHES is not provided, then
-#   backslashes in emitted values are each escaped with an additional
-#   backslash. If RAW-BACKSLASHES is not the null value, then backslashes are
-#   emitted raw.  The following properties are emitted:
-#
-#       prefix
-#       exec_prefix
-#       bindir
-#       sbindir
-#       libexecdir
-#       datadir
-#       sysconfdir
-#       sharedstatedir
-#       localstatedir
-#       libdir
-#       includedir
-#       oldincludedir
-#       infodir
-#       mandir
-#-----------------------------------------------------------------------------
-AC_DEFUN([CS_OUTPUT_INSTALLDIRS],[
-# Handle the case when no prefix is given, and the special case when a path
-# contains more than 2 slashes, these paths seem to be correct but Jam fails
-# on them.
-AS_IF([test $prefix = NONE],
-    [cs_install_prefix="$ac_default_prefix"],
-    [cs_install_prefix=`echo "$prefix" | sed -e 's:///*:/:g'`])
-AS_IF([test $exec_prefix = NONE],
-    [cs_install_exec_prefix="AS_ESCAPE([$(prefix)])"],
-    [cs_install_exec_prefix=`echo "$exec_prefix" | sed -e 's:///*:/:g'`])
-
-_CS_OUTPUT_INSTALL_DIRS([$1], [prefix],
-    [CS_PREPARE_INSTALLPATH([$cs_install_prefix], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [exec_prefix],
-    [CS_PREPARE_INSTALLPATH([$cs_install_exec_prefix], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [bindir],
-    [CS_PREPARE_INSTALLPATH([$bindir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [sbindir],
-    [CS_PREPARE_INSTALLPATH([$sbindir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [libexecdir],
-    [CS_PREPARE_INSTALLPATH([$libexecdir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [datadir],
-    [CS_PREPARE_INSTALLPATH([$datadir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [sysconfdir], 
-    [CS_PREPARE_INSTALLPATH([$sysconfdir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [sharedstatedir], 
-    [CS_PREPARE_INSTALLPATH([$sharedstatedir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [localstatedir], 
-    [CS_PREPARE_INSTALLPATH([$localstatedir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [libdir],
-    [CS_PREPARE_INSTALLPATH([$libdir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [includedir], 
-    [CS_PREPARE_INSTALLPATH([$includedir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [oldincludedir], 
-    [CS_PREPARE_INSTALLPATH([$oldincludedir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [infodir],
-    [CS_PREPARE_INSTALLPATH([$infodir], [$2])])
-_CS_OUTPUT_INSTALL_DIRS([$1], [mandir],
-    [CS_PREPARE_INSTALLPATH([$mandir], [$2])])
-])
-
-AC_DEFUN([_CS_OUTPUT_INSTALL_DIRS],
-    [m4_default([$1], [CS_JAMCONFIG_PROPERTY])([$2], [$3])])
-
-
-#-----------------------------------------------------------------------------
-# CS_PREPARE_INSTALLPATH(VALUE, [RAW-BACKSLASHES])
-#   Transform variable references of the form ${bla} to $(bla) in VALUE and
-#   correctly quotes backslashes.  This is needed if you need to emit some of
-#   the paths from Autoconf. RAW-BACKSLASHES has the same meaning as in
-#   CS_OUTPUT_INSTALLDIRS.
-#-----------------------------------------------------------------------------
-AC_DEFUN([CS_PREPARE_INSTALLPATH],
-[`echo "$1" | sed 's/\${\([[a-zA-Z_][a-zA-Z_]]*\)}/$(\1)/g;m4_ifval([$2],
-    [s/\\/\\\\/g], [s/\\\\/\\\\\\\\/g])'`])
-# jamcache.m4                                                  -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# Text cache facility for Jam-style properties.  The cache is stored in
-# the shell variable cs_jamfile_text.
-#
-# CS_JAMCONFIG_APPEND(TEXT)
-#	Append text to the Jam text cache.  This is a cover for
-#	CS_TEXT_CACHE_APPEND().
-#
-# CS_JAMCONFIG_PREPEND(TEXT)
-#	Prepend text to the Jam text cache.  This is a cover for
-#	CS_TEXT_CACHE_PREPEND().
-#
-# CS_JAMCONFIG_PROPERTY(KEY, VALUE, [APPEND], [UNCONDITIONAL])
-#	Append a line of the form "KEY ?= VALUE" to the Jam text cache.  If the
-#	APPEND argument is not the empty string, then VALUE is appended to the
-#	existing value of KEY using the form "KEY += VALUE".  If the
-#	UNCONDITIONAL argument is not empty, then the value of KEY is set
-#	unconditionally "KEY = VALUE", rather than via "KEY ?= VALUE".  APPEND
-#	takes precedence over UNCONDITIONAL.  Note that if VALUE references
-#	other Jam variables, for example $(OBJS), then be sure to protect the
-#	value with AS_ESCAPE().  For example:
-#	CS_JAMCONFIG_PROPERTY([ALLOBJS], [AS_ESCAPE([$(OBJS) $(LIBOBJS)])])
-#
-# CS_JAMCONFIG_OUTPUT(FILENAME)
-#	Instruct config.status to write the Jam text cache to the given
-#	filename.  This is a cover for CS_TEXT_CACHE_OUTPUT().
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_JAMCONFIG_APPEND],
-    [CS_TEXT_CACHE_APPEND([cs_jamconfig_text], [$1])])
-AC_DEFUN([CS_JAMCONFIG_PREPEND],
-    [CS_TEXT_CACHE_PREPEND([cs_jamconfig_text], [$1])])
-AC_DEFUN([CS_JAMCONFIG_PROPERTY],
-    [CS_JAMCONFIG_APPEND(
-	[$1 m4_ifval([$3], [+=], m4_ifval([$4], [=], [?=])) \"$2\" ;
-])])
-AC_DEFUN([CS_JAMCONFIG_OUTPUT],
-    [CS_TEXT_CACHE_OUTPUT([cs_jamconfig_text], [$1])])
-# makecache.m4                                                 -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# Text cache facility for makefile-style properties.  The cache is stored in
-# the shell variable cs_makefile_text.
-#
-# CS_MAKEFILE_APPEND(TEXT)
-#	Append text to the makefile text cache.  This is a cover for
-#	CS_TEXT_CACHE_APPEND().
-#
-# CS_MAKEFILE_PREPEND(TEXT)
-#	Prepend text to the makefile text cache.  This is a cover for
-#	CS_TEXT_CACHE_PREPEND().
-#
-# CS_MAKEFILE_PROPERTY(KEY, VALUE, [APPEND])
-#	Append a line of the form "KEY = VALUE" to the makefile text cache.  If
-#	the APPEND argument is not the empty string, then VALUE is appended to
-#	the existing value of KEY using the form "KEY += VALUE".  Note that if
-#	VALUE references other makefile variables, for example $(OBJS), then be
-#	sure to protect the value with AS_ESCAPE().  For example:
-#	CS_MAKEFILE_PROPERTY([ALLOBJS], [AS_ESCAPE([$(OBJS) $(LIBOBJS)])])
-#
-# CS_MAKEFILE_OUTPUT(FILENAME)
-#	Instruct config.status to write the makefile text cache to the given
-#	filename.  This is a cover for CS_TEXT_CACHE_OUTPUT().
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_MAKEFILE_APPEND],
-    [CS_TEXT_CACHE_APPEND([cs_makefile_text], [$1])])
-AC_DEFUN([CS_MAKEFILE_PREPEND],
-    [CS_TEXT_CACHE_PREPEND([cs_makefile_text], [$1])])
-AC_DEFUN([CS_MAKEFILE_PROPERTY],
-    [CS_MAKEFILE_APPEND([$1 m4_ifval([$3], [+=], [=]) $2
-])])
-AC_DEFUN([CS_MAKEFILE_OUTPUT],[CS_TEXT_CACHE_OUTPUT([cs_makefile_text], [$1])])
-# mkdir.m4                                                     -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_CHECK_MKDIR
-#	Determine how to create a directory and a directory tree. Sets the
-#	shell variable MKDIR to the command which creates a directory, and
-#	MKDIRS to the command which creates a directory tree. Invokes
-#	AC_SUBST() for MKDIR and MKDIRS.
-#
-# IMPLEMENTATION NOTES
-#	We need to know the exact commands, so that we can emit them, thus the
-#	AS_MKDIR_P function is not what we want to use here since it does not
-#	provide access to the commands (and might not even discover suitable
-#	commands).  First try "mkdir -p", then try the older "mkdirs".
-#	Finally, if the mkdir command failed to recognize -p, then it might
-#	have created a directory named "-p", so clean up that bogus directory.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_CHECK_MKDIR],
-    [AC_CACHE_CHECK([how to create a directory], [cs_cv_shell_mkdir],
-	[cs_cv_shell_mkdir='mkdir'])
-    AC_SUBST([MKDIR], [$cs_cv_shell_mkdir])
-
-    AC_CACHE_CHECK([how to create a directory tree], [cs_cv_shell_mkdir_p],
-	[if $cs_cv_shell_mkdir -p . 2>/dev/null; then
-	    cs_cv_shell_mkdir_p='mkdir -p'
-	elif mkdirs . 2>/dev/null; then
-	    cs_cv_shell_mkdir_p='mkdirs'
-	fi
-	test -d ./-p && rmdir ./-p])
-    AS_VAR_SET_IF([cs_cv_shell_mkdir_p],
-	[AC_SUBST([MKDIRS], [$cs_cv_shell_mkdir_p])],
-	[CS_MSG_ERROR([do not know how to create a directory tree])])])
-
-
-
-#------------------------------------------------------------------------------
-# Replacement for AS_MKDIR_P() from m4sugar/m4sh.m4 which fixes two problems
-# which are present in Autoconf 2.57 and probably all earlier 2.5x versions.
-# This bug, along with a patch, was submitted to the Autoconf GNATS database by
-# Eric Sunshine as #227 on 17-Dec-2002.  The bogus "-p" directory bug was fixed
-# for Autoconf 2.58 on 26-Sep-2003.  The "mkdirs" optimization was not accepted
-# (since it is unnecessary; it's only an optimization).
-#
-# 1) Removes bogus "-p" directory which the stock AS_MKDIR_P() leaves laying
-#    around in the working directory if the mkdir command does not recognize
-#    the -p option.
-# 2) Takes advantage of the older "mkdirs" program if it exists and if "mkdir
-#    -p" does not work.
-#------------------------------------------------------------------------------
-m4_defun([_AS_MKDIR_P_PREPARE],
-[if mkdir -p . 2>/dev/null; then
-  as_mkdir_p='mkdir -p'
-elif mkdirs . 2>/dev/null; then
-  as_mkdir_p='mkdirs'
-else
-  as_mkdir_p=''
-fi
-test -d ./-p && rmdir ./-p
-])# _AS_MKDIR_P_PREPARE
-
-m4_define([AS_MKDIR_P],
-[AS_REQUIRE([_$0_PREPARE])dnl
-{ if test -n "$as_mkdir_p"; then
-    $as_mkdir_p $1
-  else
-    as_dir=$1
-    as_dirs=
-    while test ! -d "$as_dir"; do
-      as_dirs="$as_dir $as_dirs"
-      as_dir=`AS_DIRNAME("$as_dir")`
-    done
-    test ! -n "$as_dirs" || mkdir $as_dirs
-  fi || AS_ERROR([cannot create directory $1]); }
-])# AS_MKDIR_P
-#==============================================================================
-# packageinfo.m4
-#    Macros for setting general info on the package, such as name and version
-#    numbers and propagate them to the generated make and Jam property files.
-#
-# Copyright (C)2003 by Matthias Braun <[email protected]>
-# Copyright (C)2003,2004 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-
-#------------------------------------------------------------------------------
-# CS_PACKAGEINFO([LONGNAME], [COPYRIGHT, [HOMEPAGE])
-#	Set additional information for the package.  Note that the version
-#	number of your application should only contain numbers, because on
-#	Windows you can only set numerical values in some of the file
-#	properties (such as versioninfo .rc files).
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_PACKAGEINFO],
-    [PACKAGE_LONGNAME="[$1]"
-    PACKAGE_COPYRIGHT="[$2]"
-    PACKAGE_HOMEPAGE="[$3]"
-])
-
-
-#------------------------------------------------------------------------------
-# CS_EMIT_PACKAGEINFO([EMITTER])
-#	Emit extended package information using the provided EMITTER.  EMITTER
-#	is a macro name, such as CS_JAMCONFIG_PROPERTY or CS_MAKEFILE_PROPERTY,
-#	which performs the actual task of emitting the KEY/VALUE tuple.  If
-#	EMITTER is omitted, CS_JAMCONFIG_PROPERTY is used.  For backward
-#	compatibility, if EMITTER is the literal value "jam", then
-#	CS_JAMCONFIG_PROPERTY is used; if it is "make", then
-#	CS_MAKEFILE_PROPERTY is used; however use of these literal names is
-#	highly discouraged.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_EMIT_PACKAGEINFO],
-    [_CS_EMIT_PACKAGEINFO([$1], [PACKAGE_NAME], [$PACKAGE_NAME])
-    _CS_EMIT_PACKAGEINFO([$1], [PACKAGE_VERSION], [$PACKAGE_VERSION])
-    _CS_EMIT_PACKAGEINFO([$1], [PACKAGE_STRING], [$PACKAGE_STRING])
-    _CS_EMIT_PACKAGEINFO([$1], [PACKAGE_BUGREPORT], [$PACKAGE_BUGREPORT])
-    _CS_EMIT_PACKAGEINFO([$1], [PACKAGE_LONGNAME], [$PACKAGE_LONGNAME])
-    _CS_EMIT_PACKAGEINFO([$1], [PACKAGE_HOMEPAGE], [$PACKAGE_HOMEPAGE])
-    _CS_EMIT_PACKAGEINFO([$1], [PACKAGE_COPYRIGHT], [$PACKAGE_COPYRIGHT])
-    for cs_veritem in m4_translit(AC_PACKAGE_VERSION, [.], [ ]); do
-	_CS_EMIT_PACKAGEINFO([$1], [PACKAGE_VERSION_LIST], [$cs_veritem], [+])
-    done
-    ])
-
-AC_DEFUN([_CS_EMIT_PACKAGEINFO],
-    [m4_case([$1],
-	[make], [CS_MAKEFILE_PROPERTY([$2], [$3], [$4])],
-	[jam], [CS_JAMCONFIG_PROPERTY([$2], [$3], [$4])],
-	[], [CS_JAMCONFIG_PROPERTY([$2], [$3], [$4])],
-	[$1([$2], [$3], [$4])])])
-# path.m4                                                      -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2004 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_PATH_NORMALIZE(STRING)
-#	Normalize a pathname at run-time by transliterating Windows/DOS
-#	backslashes to forward slashes.  Also collapses whitespace.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_PATH_NORMALIZE],
-[`echo "x$1" | tr '\\\\' '/' | sed 's/^x//;s/   */ /g;s/^ //;s/ $//'`])
-
-
-#------------------------------------------------------------------------------
-# CS_RUN_PATH_NORMALIZE(COMMAND)
-#	Normalize the pathname emitted by COMMAND by transliterating
-#	Windows/DOS backslashes to forward slashes.  Also collapses whitespace.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_RUN_PATH_NORMALIZE],
-[`AC_RUN_LOG([$1]) | tr '\\\\' '/' | sed 's/^x//;s/   */ /g;s/^ //;s/ $//'`])
-###############################################################################
-# progver.m4
-# Written by Norman Kramer <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-###############################################################################
-#
-# From the input pattern we create regular expressions we send through sed
-# to extract the version information from the standard input to sed.
-# Then we extract from the resulting version string subparts.
-# The same happens with the supplied version string. It too is split into its
-# subparts according to the pattern.
-# Then the subparts from the gathered version string and the supplied one are
-# compared.
-#
-# How does the pattern look like ?
-# It is a sequence of 9s and _s and separators.
-# 9 denotes a non empty sequence of digits.
-# _ denotes a non empty sequence of characters from the class [a-zA-Z].
-# | everything behind is optional
-# Everything else is treated as a separator.
-# Consecutive 9s and _s are compressed to contain only one of each type.
-# For instance "99_.9.__abc9_" will become "9_.9._abc9_".
-#
-# How we find the parts we compare ?
-# From this transformed string we yield the parts we will later compare.
-# We break up the string as follows:
-# Any sequence of separators represent one breakup. Additional breakups are
-# placed behind every 9 and _ .
-# So the example from above will give:
-#
-# "99_.9.__abc9_"  ===compress==> "9_.9._abc9_" ===breakup==> "9" "_" "9" "_" "9" "_"
-#
-# How we create the regular expressions ?
-# We take the compressed pattern and quote every separator.
-# The we replace the 9s with [0-9][0-9]*
-# and the _s with [a-zA-Z][a-zA-Z]* .
-# The above example will become:
-#
-# "99_.9.__abc9_"  ===compress==> "9_.9._abc9_" ===rexify==>
-# [0-9][0-9]*[a-zA-Z][a-zA-Z]*\.[0-9][0-9]*\.[a-zA-Z][a-zA-Z]*\a\b\c[0-9][0-9]*[a-zA-Z][a-zA-Z]*
-#
-# Voila.
-#
-# To yield the subparts from the string we additionally enclose the
-# 9s and _s with \( and \).
-#
-###############################################################################
-
-# ****************************************************************
-# **                      helper definitions                    **
-# ****************************************************************
-m4_define([CS_VCHK_RUNTH], [m4_pushdef([i], [$1])m4_if($1,0,,[CS_VCHK_RUNTH(m4_decr($1), [$2])][$2])m4_popdef([i])])
-m4_define([CS_VCHK_PREFIX], [])
-m4_define([CS_VCHK_SUFFIX], [])
-m4_define([CS_VCHK_GROUPPREFIX], [\(])
-m4_define([CS_VCHK_GROUPSUFFIX], [\)])
-m4_define([CS_VCHK_CHAR], [[[[a-zA-Z]]]])
-m4_define([CS_VCHK_DIGIT], [[[0-9]]])
-m4_define([CS_VCHK_SEQUENCE], [CS_VCHK_PREFIX[]CS_VCHK_SINGLE[]CS_VCHK_SINGLE[]*CS_VCHK_SUFFIX[]])
-m4_define([CS_VCHK_OPTSEQUENCE], [CS_VCHK_PREFIX[]CS_VCHK_SINGLE[]*CS_VCHK_SUFFIX[]])
-m4_define([CS_VCHK_REXSEQ], [m4_bpatsubst($1, [$2], [[]CS_VCHK_SEQUENCE[]])])
-m4_define([CS_VCHK_GROUPINGON], [m4_pushdef([CS_VCHK_PREFIX], [CS_VCHK_GROUPPREFIX])m4_pushdef([CS_VCHK_SUFFIX], [CS_VCHK_GROUPSUFFIX])])
-m4_define([CS_VCHK_GROUPINGOFF], [m4_popdef([CS_VCHK_SUFFIX])m4_popdef([CS_VCHK_PREFIX])])
-m4_define([CS_VCHK_OPTON], [m4_pushdef([CS_VCHK_SEQUENCE], [CS_VCHK_OPTSEQUENCE])])
-m4_define([CS_VCHK_OPTOFF], [m4_popdef([CS_VCHK_SEQUENCE])])
-m4_define([CS_VCHK_RMOPT], [CS_VCHK_RMCHAR([$1], m4_index([$1], [|]))])
-m4_define([CS_VCHK_RMCHAR], [m4_if($2,-1,[$1],m4_substr([$1], 0, $2)[]m4_substr([$1], m4_incr($2)))])
-m4_define([CS_VCHK_RMALL], [m4_translit([$1], [|], [])])
-m4_define([CS_VCHK_CUTOFF], [m4_if(m4_index($1,[|]),-1, [$1], [m4_substr($1, 0, m4_index($1,[|]))])])
-m4_define([CS_VCHK_CYCLEOPT], [
-m4_if($2,-1,, [m4_pushdef([i], CS_VCHK_CUTOFF([$1])) m4_pushdef([j], CS_VCHK_DUMMY_TAIL([$1])) CS_VCHK_CYCLEOPT( CS_VCHK_RMOPT([$1]), m4_index($1, [|]), [$3])$3 m4_popdef([i]) m4_popdef([j])])
-])
-m4_define([CS_VCHK_TAIL], [m4_if(m4_index($1,[|]),-1, [], [m4_substr($1, m4_incr(m4_index($1,[|])))])])
-m4_define([CS_VCHK_DUMMY_COMPRESS], [m4_bpatsubst(m4_bpatsubst([$1], [__*], [A]), [99*], [0])])
-m4_define([CS_VCHK_DUMMY_TAIL], [CS_VCHK_DUMMY_COMPRESS(m4_translit(CS_VCHK_TAIL([$1]), [|], []))])
-
-# ****************************************************************
-# **                      FlagsOn / FlagsOff                    **
-# ****************************************************************
-m4_define([CS_VCHK_FLAGSON],
-[m4_if($#, 0, [],
-       $1, [], [],
-       [$1], [group], [CS_VCHK_GROUPINGON[]],
-       [$1], [opt], [CS_VCHK_OPTON[]])dnl
-m4_if($#, 0, [], $1, [], [], [CS_VCHK_FLAGSON(m4_shift($@))])])
-
-m4_define([CS_VCHK_FLAGSOFF],
-[m4_if($#, 0, [],
-       $1, [], [],
-       $1, [group], [CS_VCHK_GROUPINGOFF[]],
-       [$1], [opt], [CS_VCHK_OPTOFF[]])dnl
-m4_if($#, 0, [], $1, [], [], [CS_VCHK_FLAGSOFF(m4_shift($@))])])
-
-# ****************************************************************
-# **                      rexify / sedify                       **
-# ****************************************************************
-m4_define([CS_VCHK_REXIFY],
-[m4_pushdef([CS_VCHK_SINGLE], [$1])dnl
-CS_VCHK_FLAGSON(m4_shift(m4_shift(m4_shift($@))))dnl
-CS_VCHK_REXSEQ([$3], [$2])dnl
-CS_VCHK_FLAGSOFF(m4_shift(m4_shift(m4_shift($@))))dnl
-m4_popdef([CS_VCHK_SINGLE])])
-
-m4_define([CS_VCHK_QUOTESEP], [m4_bpatsubst($1, [[^9_]], [\\\&])])
-
-m4_define([CS_VCHK_REXCHAR], [CS_VCHK_REXIFY([CS_VCHK_CHAR], [__*], $@)])
-m4_define([CS_VCHK_REXDIGIT],  [CS_VCHK_REXIFY([CS_VCHK_DIGIT], [99*], $@)])
-m4_define([CS_VCHK_SEDIFY], [CS_VCHK_REXDIGIT([CS_VCHK_REXCHAR([CS_VCHK_QUOTESEP([$1])], m4_shift($@))], m4_shift($@))])
-m4_define([CS_VCHK_SEDEXPRALL], [/CS_VCHK_SEDIFY([$1])/!d;s/.*\(CS_VCHK_SEDIFY([$1])\).*/\1/;q])
-m4_define([CS_VCHK_SEDEXPRNTH], [/CS_VCHK_SEDIFY([$1])/!d;s/.*CS_VCHK_SEDIFY([$1],[group]).*/\$2/])
-
-# ****************************************************************
-# **                      Pattern splitting                     **
-# ****************************************************************
-m4_define([CS_VCHK_SPLITSEP], [CS_VCHK_REXIFY([s], [[^9_][^9_]*], $@)])
-m4_define([CS_VCHK_SPLITDIGIT], [CS_VCHK_REXIFY([d], [99*], $@)])
-m4_define([CS_VCHK_SPLITCHAR], [CS_VCHK_REXIFY([c], [__*], $@)])
-
-# ****************************************************************
-# ** return a list of 's' 'd' 'c' 'e' chars denoting the kind   **
-# ** pattern parts: separator, digit, char, end                 **
-# ****************************************************************
-m4_define([CS_VCHK_PATTERNLIST], [m4_pushdef([CS_VCHK_SEQUENCE], [CS_VCHK_SINGLE ])dnl
-m4_translit(CS_VCHK_SPLITDIGIT([CS_VCHK_SPLITCHAR([CS_VCHK_SPLITSEP([$1])])]), [ ], m4_if([$2],[],[ ],[$2]))e[]dnl
-m4_popdef([CS_VCHK_SEQUENCE])])
-
-# ****************************************************************
-# ** Build the shell commands we emit to the configure script.  **
-# ****************************************************************
-m4_define([CS_VCHK_PATCOUNT], [m4_len(m4_bpatsubst(CS_VCHK_PATTERNLIST([$1]), [[^dc]]))])
-
-# ****************************************************************************************
-# ** CS_VCHK_EXTRACTVERSION(EXTRACT_CALL, MIN_VERSION, PATTERN, PRGPREFIX, COMPARISION) **
-# ****************************************************************************************
-m4_define([CS_VCHK_EXTRACTVERSION],
-[cs_prog_$4_is_version=
-cs_prog_$4_min_version=
-cs_prog_$4_is_suffix=
-cs_prog_$4_min_suffix=
-cs_prog_$4_is_suffix_done=
-cs_prog_$4_min_suffix_done=
-CS_VCHK_CYCLEOPT([$3], [], 
-[test -z $cs_prog_$4_is_version && cs_prog_$4_is_version=`$1 | sed 'CS_VCHK_SEDEXPRALL([i])'`
-test -n "$cs_prog_$4_is_version" && test -z $cs_prog_$4_is_suffix_done  && { cs_prog_$4_is_suffix_done=yes ; cs_prog_$4_is_suffix=j ; }
-])
-CS_VCHK_CYCLEOPT([$3], , 
-[test -z $cs_prog_$4_min_version && cs_prog_$4_min_version=`echo $2 | sed 'CS_VCHK_SEDEXPRALL([i])'`
-test -n "$cs_prog_$4_min_version" && test -z $cs_prog_$4_min_suffix_done  && { cs_prog_$4_min_suffix_done=yes ; cs_prog_$4_min_suffix=j ; }
-])
-CS_VCHK_RUNTH([CS_VCHK_PATCOUNT([$3])],
-    [cs_prog_$4_is_ver_[]i=`echo ${cs_prog_$4_is_version}${cs_prog_$4_is_suffix} | sed 'CS_VCHK_SEDEXPRNTH([CS_VCHK_RMALL([$3])], [i])'`
-])
-CS_VCHK_RUNTH([CS_VCHK_PATCOUNT([$3])],
-    [cs_prog_$4_min_ver_[]i=`echo $cs_prog_$4_min_version${cs_prog_$4_min_suffix} | sed 'CS_VCHK_SEDEXPRNTH([CS_VCHK_RMALL([$3])], [i])'`
-])
-cs_cv_prog_$4_version_ok=''
-CS_VCHK_RUNTH([CS_VCHK_PATCOUNT([$3])],
-[test -z "$cs_cv_prog_$4_version_ok" && { expr "$cs_prog_$4_is_ver_[]i" "$5" "$cs_prog_$4_min_ver_[]i" >/dev/null || cs_cv_prog_$4_version_ok=no ; }
-test -z "$cs_cv_prog_$4_version_ok" && { expr "$cs_prog_$4_min_ver_[]i" "$5" "$cs_prog_$4_is_ver_[]i" >/dev/null || cs_cv_prog_$4_version_ok=yes ; }
-])
-AS_IF([test -z "$cs_cv_prog_$4_version_ok"], [cs_cv_prog_$4_version_ok=yes])
-cs_cv_prog_$4_version_ok_annotated="$cs_cv_prog_$4_version_ok"
-AS_IF([test -n "$cs_prog_$4_is_version"],
-    [cs_cv_prog_$4_version_ok_annotated="$cs_cv_prog_$4_version_ok_annotated (version $cs_prog_$4_is_version)"])
-])
-
-##############################################################################
-# CS_CHECK_PROG_VERSION(PROG, EXTRACT_CALL, VERSION, PATTERN,
-#                       [ACTION-IF-OKAY], [ACTION-IF-NOT-OKAY], [CMP])
-# Check the version of a program PROG.
-# Version information is emitted by EXTRACT_CALL (for instance "bison -V").
-# The discovered program version is compared against VERSION.
-# The pattern of the version string matches PATTERN
-# The extracted version and the supplied version are compared with the CMP
-# operator. i.e. EXTRACTED_VERSION CMP SUPPLIED_VERSION
-# CMP defaults to >= if not specified.
-# ACTION-IF-OKAY is invoked if comparision yields true, otherwise
-# ACTION-IF-NOT-OKAY is invoked.
-#
-# PATTERN literals: 9 .. marks a non empty sequence of digits
-#                   _ .. marks a non empty sequence of characters from [a-zA-Z]
-#                   | .. everything behind is optional
-#                     .. everything else is taken as separator - it is better
-#                        to not try stuff like space, slash or comma.
-#
-# The test results in cs_cv_prog_PROG_version_ok being either yes or no.
-##############################################################################
-AC_DEFUN([CS_CHECK_PROG_VERSION],
-[AC_CACHE_CHECK([if $1 version m4_default([$7],[>=]) $3],
-    [AS_TR_SH([cs_cv_prog_$1_version_ok_annotated])],
-    [CS_VCHK_EXTRACTVERSION([$2], [$3], [$4], AS_TR_SH([$1]),
-	m4_default([$7],[>=]))])
-AS_IF([test "$AS_TR_SH([cs_cv_prog_$1_version_ok])" = yes], [$5], [$6])])
-# qualify.m4                                                   -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_SYMBOL_QUALIFIER(MESSAGE, CACHE-VAR, QUALIFIERS, [SYMBOL], [LANG],
-#		      [ACTION-IF-ACCEPTED], [ACTION-IF-NOT-ACCEPTED])
-#	Test if a symbol can be qualified by one of the elements of the
-#	comma-separated list of QUALIFIERS.  Examples of qualifiers include
-#	__attribute__((deprecated)), __declspec(dllimport), etc. MESSAGE is the
-#	"checking" message. CACHE-VAR is the variable which receives the
-#	qualifier which succeeded, or the the literal "no" if none were
-#	accepted. SYMBOL is the symbol to which the qualifier should be
-#	applied. If omitted, then SYMBOL defaults to "void f();". LANG is the
-#	language of the test, typically "C" or "C++". It defaults to "C" if
-#	omitted. ACTION-IF-ACCEPTED is invoked after CACHE-VAR is set if one of
-#	the qualifiers is accepted, else ACTION-IF-NOT-ACCEPTED is invoked.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_SYMBOL_QUALIFIER],
-    [AC_CACHE_CHECK([$1], [$2],
-	[$2='no'
-	m4_foreach([cs_symbol_qualifier], [$3],
-	    [AS_IF([test "$$2" = no],
-		[CS_BUILD_IFELSE(
-		    [AC_LANG_PROGRAM(
-			[cs_symbol_qualifier m4_default([$4],[void f()]);],
-			[])],
-		    [], [$5], [$2='cs_symbol_qualifier'], [$2='no'])])])])
-    AS_IF([test $$2 != no], [$6], [$7])])
-# split.m4                                                     -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_SPLIT(LINE, [OUTPUT-VARIABLES], [DELIMITER], [FILLER])
-#	Split LINE into individual tokens.  Tokens are delimited by DELIMITER,
-#	which is the space character if omitted.  OUTPUT-VARIABLES is a
-#	comma-delimited list of shell variables which should receive the
-#	extracted tokens.  If there are too few tokens to fill the output
-#	variables, then the excess variables will be assigned the empty string.
-#	If there are too few output variables, then the excess tokens will be
-#	ignored.  If OUTPUT-VARIABLES is omitted, then the split tokens will be
-#	assigned to the shell meta-variables $1, $2, $3, etc.  When
-#	OUTPUT-VARIABLES is omitted, FILLER is assigned to meta-variables in
-#	cases where DELIMITER delimits a zero-length token.  FILLER defaults
-#	to "filler".  For example, if DELIMITER is "+" and OUTPUT-VARIABLES is
-#	omitted, given the line "one++three", $1 will be "one", $2 will be
-#	"filler", and $3 will be "three".
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_SPLIT],
-    [m4_define([cs_split_filler], m4_default([$4],[filler]))
-    set cs_split_filler `echo "$1" | awk 'BEGIN { FS="m4_default([$3],[ ])" }
-	{ for (i=1; i <= NF; ++i)
-	    { if ($i == "") print "cs_split_filler"; else print $i } }'`
-    shift
-    m4_map([_CS_SPLIT], [$2])])
-
-AC_DEFUN([_CS_SPLIT],
-    [AS_IF([test $[@%:@] -eq 0], [$1=''],
-	[AS_IF([test "$[1]" = cs_split_filler], [$1=''], [$1=$[1]])
-	shift])])
-# textcache.m4                                                 -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# Text cache facility.  These macros provide a way to incrementally store
-# arbitrary text in a shell variable, and to write the saved text to a file.
-#
-# CS_TEXT_CACHE_APPEND(VARIABLE, TEXT)
-#	Append text to the contents of the named shell variable.  If the text
-#	contains references to shell variables (such as $foo), then those
-#	references will be expanded.  If expansion is not desired, then protect
-#	the text with AS_ESCAPE().
-#
-# CS_TEXT_CACHE_PREPEND(VARIABLE, TEXT)
-#	Prepend text to the contents of the named shell variable.  If the text
-#	contains references to shell variables (such as $foo), then those
-#	references will be expanded.  If expansion is not desired, then protect
-#	the text with AS_ESCAPE().
-#
-# CS_TEXT_CACHE_OUTPUT(VARIABLE, FILENAME)
-#	Instruct config.status to write the contents of the named shell
-#	variable to the given filename.  If the file resides in a directory,
-#	the directory will be created, if necessary.  If the output file
-#	already exists, and if the cached text is identical to the contents of
-#	the existing file, then the existing file is left alone, thus its time
-#	stamp remains unmolested.  This heuristic may help to minimize rebuilds
-#	when the file is listed as a dependency in a makefile.
-#
-# *NOTE*
-#	There is a bug in Autoconf 2.57 and probably all earlier 2.5x versions
-#	which results in errors if AC_CONFIG_COMMANDS is invoked for a `tag'
-#	which represents a file in a directory which does not yet exist.
-#	Unfortunately, even invoking AS_MKDIR_P in the `cmd' portion of
-#	AC_CONFIG_COMMANDS does not solve the problem because the generated
-#	configure script attempts to access information about the directory
-#	before AS_MKDIR_P has a chance to create it.  This forces us to invoke
-#	AS_MKDIR_P in the third argument to AC_CONFIG_COMMANDS (the
-#	`init-cmds') rather than the second (the `cmds').  This is undesirable
-#	because it means that the directory will be created anytime
-#	config.status is invoked (even for a simple --help), rather than being
-#	created only when requested to output the text cache.  This bug was
-#	submitted to the Autoconf GNATS database by Eric Sunshine as #228 on
-#	27-Dec-2002.  It was fixed for Autoconf 2.58 on 26-Sep-2003.  The
-#	official fix makes the assumption that `tag' always represents a file
-#	(as opposed to some generic target), and creates the file's directory
-#	is not present.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_TEXT_CACHE_APPEND], [$1="${$1}$2"])
-AC_DEFUN([CS_TEXT_CACHE_PREPEND], [$1="$2${$1}"])
-AC_DEFUN([CS_TEXT_CACHE_OUTPUT],
-    [AC_CONFIG_COMMANDS([$2],
-	[echo $ECHO_N "$$1$ECHO_C" > $tmp/tcache
-	AS_IF([diff $2 $tmp/tcache >/dev/null 2>&1],
-	    [AC_MSG_NOTICE([$2 is unchanged])],
-	    [rm -f $2
-	    cp $tmp/tcache $2])
-	rm -f $tmp/tcache],
-	[$1='$$1'
-	cs_dir=`AS_DIRNAME([$2])`
-	AS_ESCAPE(AS_MKDIR_P([$cs_dir]), [$`\])])])
-# trim.m4                                                      -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2003 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_TRIM(STRING)
-#	Strip leading and trailing spaces from STRING and collapse internal
-#	runs of multiple spaces to a single space.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_TRIM], [`echo x$1 | sed 's/^x//;s/   */ /g;s/^ //;s/ $//'`])
-# warnings.m4                                                  -*- Autoconf -*-
-#==============================================================================
-# Copyright (C)2005 by Eric Sunshine <[email protected]>
-#
-#    This library is free software; you can redistribute it and/or modify it
-#    under the terms of the GNU Library General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or (at your
-#    option) any later version.
-#
-#    This library is distributed in the hope that it will be useful, but
-#    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-#    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
-#    License for more details.
-#
-#    You should have received a copy of the GNU Library General Public License
-#    along with this library; if not, write to the Free Software Foundation,
-#    Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-#
-#==============================================================================
-AC_PREREQ([2.56])
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_WARNINGS([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                      [ACTION-IF-NOT-FOUND])
-#	Check how to enable compilation warnings. If LANGUAGE is not provided,
-#	then `C' is assumed (other options include `C++').  If CACHE-VAR is not
-#	provided, then it defaults to the name
-#	"cs_cv_prog_compiler_enable_warnings".  If an option for enabling
-#	warnings (such as `-Wall') is discovered, then it is assigned to
-#	CACHE-VAR and ACTION-IF-FOUND is invoked; otherwise the empty string is
-#	assigned to CACHE-VAR and ACTION-IF-NOT-FOUND is invoked.
-#
-# IMPLEMENTATION NOTES
-#
-#	On some platforms, it is more appropriate to use -Wmost rather than
-#	-Wall even if the compiler understands both, thus we attempt -Wmost
-#	before -Wall.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_WARNINGS],
-    [CS_CHECK_BUILD_FLAGS(
-	[how to enable m4_default([$1],[C]) compilation warnings],
-	[m4_default([$2],[cs_cv_prog_compiler_enable_warnings])],
-	[CS_CREATE_TUPLE([-Wmost]) CS_CREATE_TUPLE([-Wall])],
-	[$1], [$3], [$4])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_ERRORS([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                    [ACTION-IF-NOT-FOUND])
-#	Check how to promote compilation diganostics from warning to error
-#	status. If LANGUAGE is not provided, then `C' is assumed (other options
-#	include `C++').  If CACHE-VAR is not provided, then it defaults to the
-#	name "cs_cv_prog_compiler_enable_errors".  If an option for performing
-#	this promotion (such as `-Werror') is discovered, then it is assigned
-#	to CACHE-VAR and ACTION-IF-FOUND is invoked; otherwise the empty string
-#	is assigned to CACHE-VAR and ACTION-IF-NOT-FOUND is invoked.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_ERRORS],
-    [CS_CHECK_BUILD_FLAGS(
-	[how to treat m4_default([$1],[C]) warnings as errors],
-	[m4_default([$2],[cs_cv_prog_compiler_enable_errors])],
-	[CS_CREATE_TUPLE([-Werror])], [$1], [$3], [$4])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_IGNORE_UNUSED([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                           [ACTION-IF-NOT-FOUND])
-#	Check how to instruct compiler to ignore unused variables and
-#	arguments.  This option may be useful for code generated by tools, such
-#	as Swig, Bison, and Flex, over which the client has no control, yet
-#	wishes to compile without excessive diagnostic spew.  If LANGUAGE is
-#	not provided, then `C' is assumed (other options include `C++').  If
-#	CACHE-VAR is not provided, then it defaults to the name
-#	"cs_cv_prog_compiler_ignore_unused".  If an option (such as
-#	`-Wno-unused') is discovered, then it is assigned to CACHE-VAR and
-#	ACTION-IF-FOUND is invoked; otherwise the empty string is assigned to
-#	CACHE-VAR and ACTION-IF-NOT-FOUND is invoked.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_IGNORE_UNUSED],
-    [CS_CHECK_BUILD_FLAGS(
-	[how to suppress m4_default([$1],[C]) unused variable warnings],
-	[m4_default([$2],[cs_cv_prog_compiler_ignore_unused])],
-	[CS_CREATE_TUPLE([-Wno-unused])], [$1], [$3], [$4])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_IGNORE_UNINITIALIZED([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                                  [ACTION-IF-NOT-FOUND])
-#	Check how to instruct compiler to ignore uninitialized variables.  This
-#	option may be useful for code generated by tools, such as Swig, Bison,
-#	and Flex, over which the client has no control, yet wishes to compile
-#	without excessive diagnostic spew.  If LANGUAGE is not provided, then
-#	`C' is assumed (other options include `C++').  If CACHE-VAR is not
-#	provided, then it defaults to the name
-#	"cs_cv_prog_compiler_ignore_uninitialized".  If an option (such as
-#	`-Wno-uninitialized') is discovered, then it is assigned to CACHE-VAR
-#	and ACTION-IF-FOUND is invoked; otherwise the empty string is assigned
-#	to CACHE-VAR and ACTION-IF-NOT-FOUND is invoked.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_IGNORE_UNINITIALIZED],
-    [CS_CHECK_BUILD_FLAGS(
-	[how to suppress m4_default([$1],[C]) uninitialized warnings],
-	[m4_default([$2],
-	    [cs_cv_prog_compiler_ignore_uninitialized_variables])],
-	[CS_CREATE_TUPLE([-Wno-uninitialized])], [$1], [$3], [$4])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_IGNORE_PRAGMAS([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                            [ACTION-IF-NOT-FOUND])
-#	Check how to instruct compiler to ignore unrecognized #pragma
-#	directives.  This option may be useful for code which contains
-#	unprotected #pragmas which are not understood by all compilers.  If
-#	LANGUAGE is not provided, then `C' is assumed (other options include
-#	`C++').  If CACHE-VAR is not provided, then it defaults to the name
-#	"cs_cv_prog_compiler_ignore_unknown_pragmas".  If an option (such as
-#	`-Wno-unknown-pragmas') is discovered, then it is assigned to CACHE-VAR
-#	and ACTION-IF-FOUND is invoked; otherwise the empty string is assigned
-#	to CACHE-VAR and ACTION-IF-NOT-FOUND is invoked.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_IGNORE_PRAGMAS],
-    [CS_CHECK_BUILD_FLAGS(
-	[how to suppress m4_default([$1],[C]) unknown [#pragma] warnings],
-	[m4_default([$2],[cs_cv_prog_compiler_ignore_unknown_pragmas])],
-	[CS_CREATE_TUPLE([-Wno-unknown-pragmas])], [$1], [$3], [$4])])
-
-
-
-#------------------------------------------------------------------------------
-# CS_COMPILER_IGNORE_LONG_DOUBLE([LANGUAGE], [CACHE-VAR], [ACTION-IF-FOUND],
-#                                [ACTION-IF-NOT-FOUND])
-#	Check how to instruct compiler to suppress warnings about `long double'
-#	usage.  This option may be useful for code generated by tools, such as
-#	Swig, Bison, and Flex, over which the client has no control, yet wishes
-#	to compile without excessive diagnostic spew.  If LANGUAGE is not
-#	provided, then `C' is assumed (other options include `C++').  If
-#	CACHE-VAR is not provided, then it defaults to the name
-#	"cs_cv_prog_compiler_ignore_long_double".  If an option (such as
-#	`-Wno-long-double') is discovered, then it is assigned to CACHE-VAR and
-#	ACTION-IF-FOUND is invoked; otherwise the empty string is assigned to
-#	CACHE-VAR and ACTION-IF-NOT-FOUND is invoked.
-#------------------------------------------------------------------------------
-AC_DEFUN([CS_COMPILER_IGNORE_LONG_DOUBLE],
-    [CS_CHECK_BUILD_FLAGS(
-	[how to suppress m4_default([$1],[C]) `long double' warnings],
-	[m4_default([$2],[cs_cv_prog_compiler_ignore_long_double])],
-	[CS_CREATE_TUPLE([-Wno-long-double])], [$1], [$3], [$4])])

+ 19 - 0
Engine/lib/bullet/appveyor.yml

@@ -0,0 +1,19 @@
+build:
+  project: build3/vs2010/0_Bullet3Solution.sln
+
+build_script:
+  - mkdir cm
+  - cd cm
+  - cmake .. -G"Visual Studio 14 2015 Win64"
+  - cmake --build . --target ALL_BUILD --config Release -- /maxcpucount:4 /verbosity:quiet
+
+test_script:
+  - ctest --parallel 4 --build-config Release --output-on-failure
+
+before_build:
+  - echo %CD%
+  - ps: cd build3
+  - echo %CD%
+  - premake4  vs2010
+  - ps: cd ..
+

+ 0 - 61
Engine/lib/bullet/autogen.sh

@@ -1,61 +0,0 @@
-#! /bin/sh
-
-if [ "$USER" = "root" ]; then
-	echo "*** You cannot do this as "$USER" please use a normal user account."
-	exit 1
-fi
-if test ! -f configure.ac ; then
-	echo "*** Please invoke this script from directory containing configure.ac."
-	exit 1
-fi
-
-echo "running aclocal"
-aclocal
-rc=$?
-
-if test $rc -eq 0; then
-	echo "running libtool"
-	libtoolize --force --automake --copy
-	rc=$?
-else
-	echo "An error occured, autogen.sh stopping."
-	exit $rc
-fi
-
-if test $rc -eq 0; then
-	echo "libtool worked."
-else
-	echo "libtool not found. trying glibtool."
-	glibtoolize --force --automake --copy
-	rc=$?
-fi
-
-if test $rc -eq 0; then
-	echo "running automake"
-	automake --add-missing --copy
-	rc=$?
-else
-	echo "An error occured, autogen.sh stopping."
-	exit $rc
-fi
-
-if test $rc -eq 0; then
-	echo "running autoheader"
-	autoheader
-	rc=$?
-else
-	echo "An error occured, autogen.sh stopping."
-	exit $rc
-fi
-
-if test $rc -eq 0; then
-	echo "running autoconf"
-	autoconf
-	rc=$?
-else
-	echo "An error occured, autogen.sh stopping."
-	exit $rc
-fi
-
-echo "autogen.sh complete"
-exit $rc

+ 6 - 0
Engine/lib/bullet/bullet.pc.cmake

@@ -0,0 +1,6 @@
+Name: bullet
+Description: Bullet Continuous Collision Detection and Physics Library
+Requires:
+Version: @BULLET_VERSION@
+Libs: -L@CMAKE_INSTALL_PREFIX@/@LIB_DESTINATION@ -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath
+Cflags: @BULLET_DOUBLE_DEF@ -I@CMAKE_INSTALL_PREFIX@/@INCLUDE_INSTALL_DIR@ -I@CMAKE_INSTALL_PREFIX@/include

+ 0 - 11
Engine/lib/bullet/bullet.pc.in

@@ -1,11 +0,0 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-
-Name: bullet
-Description: Bullet Continuous Collision Detection and Physics Library
-Requires:
-Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -lbulletdynamics -lbulletcollision -lbulletmath
-Cflags: -I${includedir}/bullet

+ 0 - 108
Engine/lib/bullet/config.h.in

@@ -1,108 +0,0 @@
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Architecture is PowerPC */
-#undef ARCH_PPC
-
-/* Architecture is x86 */
-#undef ARCH_X86
-
-/* Architecture is x86-64 */
-#undef ARCH_X86_64
-
-/* Define when compiling for MacOS/X */
-#undef CS_PLATFORM_MACOSX
-
-/* Define when compiling for Unix and Unix-like (i.e. MacOS/X) */
-#undef CS_PLATFORM_UNIX
-
-/* Define when compiling for Win32 */
-#undef CS_PLATFORM_WIN32
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the `mx' library (-lmx). */
-#undef HAVE_LIBMX
-
-/* Define to 1 if you have the `nsl' library (-lnsl). */
-#undef HAVE_LIBNSL
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Whether the int32 type is available */
-#undef HAVE_TYPE_INT32
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Define to 1 if you have the <windows.h> header file. */
-#undef HAVE_WINDOWS_H
-
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
-   */
-#undef LT_OBJDIR
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Platform is Apple */
-#undef PLATFORM_APPLE
-
-/* Platform is Linux */
-#undef PLATFORM_LINUX
-
-/* Platform is Win32 */
-#undef PLATFORM_WIN32
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Version number of package */
-#undef VERSION
-
-/* Define to 1 if your processor stores words with the most significant byte
-   first (like Motorola and SPARC, unlike Intel and VAX). */
-#undef WORDS_BIGENDIAN
-
-/* Define to 1 if the X Window System is missing or not being used. */
-#undef X_DISPLAY_MISSING
-
-/* Avoid problem caused by missing <Carbon/CarbonSound.h> */
-#undef __CARBONSOUND__

+ 0 - 192
Engine/lib/bullet/configure.ac

@@ -1,192 +0,0 @@
-#----------------------------------------------------------------------------
-# Autoconf input script. Invoke the ./autogen.sh script to generate a
-# configure script from this file.
-#----------------------------------------------------------------------------
-AC_PREREQ([2.54])
-
-#----------------------------------------------------------------------------
-# Initialize Autoconf.
-#----------------------------------------------------------------------------
-AC_INIT(
-    [bullet],
-    [2.75],
-    [[email protected]])
-AC_CANONICAL_HOST
-CS_PACKAGEINFO(
-    [Bullet Continuous Collision Detection and Physics Library],
-    [Copyright (c) 2005-2008  Erwin Coumans],
-    [http://www.bulletphysics.com])
-AC_CONFIG_SRCDIR([configure.ac])
-AM_INIT_AUTOMAKE
-AC_PROG_CC
-AC_PROG_CXX
-AC_PROG_LIBTOOL
-
-case "$host" in
-        *-*-mingw*|*-*-cygwin*)
-                AC_DEFINE(PLATFORM_WIN32, 1, [Platform is Win32])
-                opengl_LIBS="-lunsupported_platform"
-                PLATFORM_STRING="Win32"
-                ;;
-        *-*-linux*)
-                AC_DEFINE(PLATFORM_LINUX, 1, [Platform is Linux])
-                opengl_LIBS="-lGL -lGLU -lglut"
-                PLATFORM_STRING="Linux"
-                ;;
-        *-*-darwin*)
-                AC_DEFINE(PLATFORM_APPLE, 1, [Platform is Apple])
-                opengl_LIBS="-framework AGL -framework OpenGL -framework GLUT"
-                PLATFORM_STRING="Apple"
-                ;;
-        *)
-                AC_MSG_WARN([*** Please add $host to configure.ac checks!])
-                ;;
-esac
-AC_SUBST(opengl_LIBS)
-
-case "$host" in
-        i?86-* | k?-* | athlon-* | pentium*-)
-                AC_DEFINE(ARCH_X86, 1, [Architecture is x86])
-                ARCH_SPECIFIC_CFLAGS=""
-                ARCH_STRING="X86"
-                ;;
-        x86_64-*)
-                AC_DEFINE(ARCH_X86_64, 1, [Architecture is x86-64])
-                ARCH_SPECIFIC_CFLAGS="-DUSE_ADDR64"
-                ARCH_STRING="X86-64"
-                ;;
-        ppc-* | powerpc-*)
-                AC_DEFINE(ARCH_PPC, 1, [Architecture is PowerPC])
-                ARCH_SPECIFIC_CFLAGS=""
-                ARCH_STRING="PowerPC"
-                ;;
-        *)
-                AC_MSG_ERROR([Unknown Architecture])
-                ;;
-esac
-AC_C_BIGENDIAN
-
-
-#----------------------------------------------------------------------------
-# Setup for the configuration header.
-#----------------------------------------------------------------------------
-AC_CONFIG_HEADERS([config.h])
-
-#----------------------------------------------------------------------------
-# Check for tools.
-#----------------------------------------------------------------------------
-CS_PROG_CC
-AS_IF([test -z "$CC"],
-    [AC_MSG_ERROR([Could not find a usable C compiler.])])
-CS_PROG_CXX
-AS_IF([test -z "$CXX"],
-    [AC_MSG_ERROR([Could not find a usable C++ compiler.])])
-CS_PROG_LINK
-
-CS_CHECK_COMMON_TOOLS_LINK
-CS_CHECK_COMMON_TOOLS_BASIC
-CS_CHECK_COMMON_TOOLS_DOC_DOXYGEN
-
-CS_CHECK_PROGS([PERL], [perl5 perl])
-CS_EMIT_BUILD_PROPERTY([PERL], [$PERL])
-
-CS_CHECK_TEMPLATE_TOOLKIT2([emit])
-
-#----------------------------------------------------------------------------
-# Check if C++ exceptions can be disabled.
-#----------------------------------------------------------------------------
-CS_EMIT_BUILD_FLAGS([how to disable C++ exceptions],
-    [cs_cv_prog_cxx_disable_exceptions], [CS_CREATE_TUPLE([-fno-exceptions])],
-    [C++], [COMPILER.C++FLAGS.EXCEPTIONS.DISABLE], [],
-    [CS_EMIT_BUILD_PROPERTY([COMPILER.C++FLAGS],
-	[$cs_cv_prog_cxx_disable_exceptions], [+])])
-
-
-#----------------------------------------------------------------------------
-# Determine system type
-#----------------------------------------------------------------------------
-CS_CHECK_HOST
-
-#----------------------------------------------------------------------------
-# Check for syntax problems / header files
-#----------------------------------------------------------------------------
-# Nothing yet.
-
-#----------------------------------------------------------------------------
-# Check for GLUT.
-#----------------------------------------------------------------------------
-AS_IF([test $cs_host_family = windows],
-    [# Tack the GLUT that comes with bullet onto compiler & linker flags.
-    _AC_SRCDIRS(["."])
-    glut_cflags="-I$ac_top_srcdir/Glut"
-    glut_lflags="-L$ac_top_srcdir/Glut"
-    CFLAGS="$CFLAGS $glut_cflags"
-    LDFLAGS="$LDFLAGS $glut_lflags"
-    CS_EMIT_BUILD_PROPERTY([COMPILER.CFLAGS], [$glut_cflags], [+])
-    CS_EMIT_BUILD_PROPERTY([COMPILER.LFLAGS], [$glut_lflags], [+])
-    ])
-CS_CHECK_GLUT
-
-
-#----------------------------------------------------------------------------
-# Package configuration switches.
-#----------------------------------------------------------------------------
-AC_ARG_ENABLE([multithreaded],
-	[AC_HELP_STRING([--enable-multithreaded],
-		[build BulletMultiThreaded (default NO)])],
-	[disable_multithreaded=no], [disable_multithreaded=yes])
-AC_MSG_CHECKING([BulletMultiThreaded])
-AS_IF([test "$disable_multithreaded" = yes], [build_multithreaded=no], [build_multithreaded=yes])
-AC_MSG_RESULT([$build_multithreaded])
-AM_CONDITIONAL([CONDITIONAL_BUILD_MULTITHREADED], [test "$build_multithreaded" = yes])
-
-AC_ARG_ENABLE([demos],
-    [AS_HELP_STRING([--disable-demos],
-	    [disable Bullet demos])],
-    [],
-    [enable_demos=yes])
-AM_CONDITIONAL([CONDITIONAL_BUILD_DEMOS], [false])
-if test "x$enable_demos" != xno; then
-    AC_MSG_NOTICE([Building Bullet demos])
-    AM_CONDITIONAL([CONDITIONAL_BUILD_DEMOS],[true])
-fi
-
-
-
-AC_ARG_ENABLE([debug],
-    [AC_HELP_STRING([--enable-debug],
-	[build with debugging information (default NO)])],
-    [], [enable_debug=no])
-
-AC_MSG_CHECKING([build mode])
-AS_IF([test $enable_debug = yes], [build_mode=debug], [build_mode=optimize])
-AC_MSG_RESULT([$build_mode])
-
-CS_EMIT_BUILD_PROPERTY([MODE], [$build_mode])
-
-#-----------------------------------------------------------------------------
-# Emit install paths and package information.
-#-----------------------------------------------------------------------------
-CS_OUTPUT_INSTALLDIRS
-CS_EMIT_PACKAGEINFO
-
-
-CFLAGS="$ARCH_SPECIFIC_CFLAGS $CFLAGS"
-CXXFLAGS="$ARCH_SPECIFIC_CFLAGS $CXXFLAGS $CFLAGS"
-#----------------------------------------------------------------------------
-# Emit generated files.
-#----------------------------------------------------------------------------
-CS_JAMCONFIG_OUTPUT([Jamconfig])
-AC_CONFIG_FILES([bullet.pc Jamfile Makefile Demos/Makefile Demos/SoftDemo/Makefile Demos/AllBulletDemos/Makefile Demos/MultiThreadedDemo/Makefile Demos/ColladaDemo/Makefile Demos/OpenGL/Makefile Demos/BasicDemo/Makefile Demos/CcdPhysicsDemo/Makefile Demos/VehicleDemo/Makefile Demos/TerrainDemo/Makefile src/Makefile Extras/Makefile])
-AC_OUTPUT
-
-AC_MSG_NOTICE([
-You can type 'make' or 'jam' to build Bullet.
-Alternatively, you can use cmake or use the wksbullet.sln visual studio x solutions in the msvc/x folder.
-
-CMake home:http://cmake.org
-Jam home: http://www.perforce.com/jam/jam.html
-Jam source: ftp://ftp.perforce.com/jam/
-
-Please type 'make' to build Bullet
-])

+ 0 - 176
Engine/lib/bullet/src/Bullet-C-Api.h

@@ -1,176 +0,0 @@
-/*
-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.
-*/
-
-/*
-	Draft high-level generic physics C-API. For low-level access, use the physics SDK native API's.
-	Work in progress, functionality will be added on demand.
-
-	If possible, use the richer Bullet C++ API, by including "btBulletDynamicsCommon.h"
-*/
-
-#ifndef BULLET_C_API_H
-#define BULLET_C_API_H
-
-#define PL_DECLARE_HANDLE(name) typedef struct name##__ { int unused; } *name
-
-#ifdef BT_USE_DOUBLE_PRECISION
-typedef double	plReal;
-#else
-typedef float	plReal;
-#endif
-
-typedef plReal	plVector3[3];
-typedef plReal	plQuaternion[4];
-
-#ifdef __cplusplus
-extern "C" { 
-#endif
-
-/**	Particular physics SDK (C-API) */
-	PL_DECLARE_HANDLE(plPhysicsSdkHandle);
-
-/** 	Dynamics world, belonging to some physics SDK (C-API)*/
-	PL_DECLARE_HANDLE(plDynamicsWorldHandle);
-
-/** Rigid Body that can be part of a Dynamics World (C-API)*/	
-	PL_DECLARE_HANDLE(plRigidBodyHandle);
-
-/** 	Collision Shape/Geometry, property of a Rigid Body (C-API)*/
-	PL_DECLARE_HANDLE(plCollisionShapeHandle);
-
-/** Constraint for Rigid Bodies (C-API)*/
-	PL_DECLARE_HANDLE(plConstraintHandle);
-
-/** Triangle Mesh interface (C-API)*/
-	PL_DECLARE_HANDLE(plMeshInterfaceHandle);
-
-/** Broadphase Scene/Proxy Handles (C-API)*/
-	PL_DECLARE_HANDLE(plCollisionBroadphaseHandle);
-	PL_DECLARE_HANDLE(plBroadphaseProxyHandle);
-	PL_DECLARE_HANDLE(plCollisionWorldHandle);
-
-/**
-	Create and Delete a Physics SDK	
-*/
-
-	extern	plPhysicsSdkHandle	plNewBulletSdk(); //this could be also another sdk, like ODE, PhysX etc.
-	extern	void		plDeletePhysicsSdk(plPhysicsSdkHandle	physicsSdk);
-
-/** Collision World, not strictly necessary, you can also just create a Dynamics World with Rigid Bodies which internally manages the Collision World with Collision Objects */
-
-	typedef void(*btBroadphaseCallback)(void* clientData, void* object1,void* object2);
-
-	extern plCollisionBroadphaseHandle	plCreateSapBroadphase(btBroadphaseCallback beginCallback,btBroadphaseCallback endCallback);
-
-	extern void	plDestroyBroadphase(plCollisionBroadphaseHandle bp);
-
-	extern 	plBroadphaseProxyHandle plCreateProxy(plCollisionBroadphaseHandle bp, void* clientData, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ);
-
-	extern void plDestroyProxy(plCollisionBroadphaseHandle bp, plBroadphaseProxyHandle proxyHandle);
-
-	extern void plSetBoundingBox(plBroadphaseProxyHandle proxyHandle, plReal minX,plReal minY,plReal minZ, plReal maxX,plReal maxY, plReal maxZ);
-
-/* todo: add pair cache support with queries like add/remove/find pair */
-	
-	extern plCollisionWorldHandle plCreateCollisionWorld(plPhysicsSdkHandle physicsSdk);
-
-/* todo: add/remove objects */
-	
-
-/* Dynamics World */
-
-	extern  plDynamicsWorldHandle plCreateDynamicsWorld(plPhysicsSdkHandle physicsSdk);
-
-	extern  void           plDeleteDynamicsWorld(plDynamicsWorldHandle world);
-
-	extern	void	plStepSimulation(plDynamicsWorldHandle,	plReal	timeStep);
-
-	extern  void plAddRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
-
-	extern  void plRemoveRigidBody(plDynamicsWorldHandle world, plRigidBodyHandle object);
-
-
-/* Rigid Body  */
-
-	extern  plRigidBodyHandle plCreateRigidBody(	void* user_data,  float mass, plCollisionShapeHandle cshape );
-
-	extern  void plDeleteRigidBody(plRigidBodyHandle body);
-
-
-/* Collision Shape definition */
-
-	extern  plCollisionShapeHandle plNewSphereShape(plReal radius);
-	extern  plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z);
-	extern  plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height);	
-	extern  plCollisionShapeHandle plNewConeShape(plReal radius, plReal height);
-	extern  plCollisionShapeHandle plNewCylinderShape(plReal radius, plReal height);
-	extern	plCollisionShapeHandle plNewCompoundShape();
-	extern	void	plAddChildShape(plCollisionShapeHandle compoundShape,plCollisionShapeHandle childShape, plVector3 childPos,plQuaternion childOrn);
-
-	extern  void plDeleteShape(plCollisionShapeHandle shape);
-
-	/* Convex Meshes */
-	extern  plCollisionShapeHandle plNewConvexHullShape();
-	extern  void		plAddVertex(plCollisionShapeHandle convexHull, plReal x,plReal y,plReal z);
-/* Concave static triangle meshes */
-	extern  plMeshInterfaceHandle		   plNewMeshInterface();
-	extern  void		plAddTriangle(plMeshInterfaceHandle meshHandle, plVector3 v0,plVector3 v1,plVector3 v2);
-	extern  plCollisionShapeHandle plNewStaticTriangleMeshShape(plMeshInterfaceHandle);
-
-	extern  void plSetScaling(plCollisionShapeHandle shape, plVector3 scaling);
-
-/* SOLID has Response Callback/Table/Management */
-/* PhysX has Triggers, User Callbacks and filtering */
-/* ODE has the typedef void dNearCallback (void *data, dGeomID o1, dGeomID o2); */
-
-/*	typedef void plUpdatedPositionCallback(void* userData, plRigidBodyHandle	rbHandle, plVector3 pos); */
-/*	typedef void plUpdatedOrientationCallback(void* userData, plRigidBodyHandle	rbHandle, plQuaternion orientation); */
-
-	/* get world transform */
-	extern void	plGetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix);
-	extern void	plGetPosition(plRigidBodyHandle object,plVector3 position);
-	extern void plGetOrientation(plRigidBodyHandle object,plQuaternion orientation);
-
-	/* set world transform (position/orientation) */
-	extern  void plSetPosition(plRigidBodyHandle object, const plVector3 position);
-	extern  void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation);
-	extern	void plSetEuler(plReal yaw,plReal pitch,plReal roll, plQuaternion orient);
-	extern	void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix);
-
-	typedef struct plRayCastResult {
-		plRigidBodyHandle		m_body;  
-		plCollisionShapeHandle	m_shape; 		
-		plVector3				m_positionWorld; 		
-		plVector3				m_normalWorld;
-	} plRayCastResult;
-
-	extern  int plRayCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plRayCastResult res);
-
-	/* Sweep API */
-
-	/* extern  plRigidBodyHandle plObjectCast(plDynamicsWorldHandle world, const plVector3 rayStart, const plVector3 rayEnd, plVector3 hitpoint, plVector3 normal); */
-
-	/* Continuous Collision Detection API */
-	
-	// needed for source/blender/blenkernel/intern/collision.c
-	double plNearestPoints(float p1[3], float p2[3], float p3[3], float q1[3], float q2[3], float q3[3], float *pa, float *pb, float normal[3]);
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif //BULLET_C_API_H
-

+ 30 - 3
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btAxisSweep3.h

@@ -16,8 +16,8 @@
 //
 //
 // 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 AXIS_SWEEP_3_H
-#define AXIS_SWEEP_3_H
+#ifndef BT_AXIS_SWEEP_3_H
+#define BT_AXIS_SWEEP_3_H
 
 
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "btOverlappingPairCache.h"
 #include "btOverlappingPairCache.h"
@@ -150,6 +150,8 @@ public:
 	virtual void  getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
 	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	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;
 	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
 	///unQuantize should be conservative: aabbMin/aabbMax should be larger then 'getAabb' result
@@ -285,6 +287,31 @@ void	btAxisSweep3Internal<BP_FP_INT_TYPE>::rayTest(const btVector3& rayFrom,cons
 	}
 	}
 }
 }
 
 
+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>
 template <typename BP_FP_INT_TYPE>
@@ -588,7 +615,7 @@ void btAxisSweep3Internal<BP_FP_INT_TYPE>::removeHandle(BP_FP_INT_TYPE handle,bt
 }
 }
 
 
 template <typename BP_FP_INT_TYPE>
 template <typename BP_FP_INT_TYPE>
-void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool(btDispatcher* dispatcher)
+void btAxisSweep3Internal<BP_FP_INT_TYPE>::resetPool(btDispatcher* /*dispatcher*/)
 {
 {
 	if (m_numHandles == 0)
 	if (m_numHandles == 0)
 	{
 	{

+ 14 - 6
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h

@@ -13,8 +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		BROADPHASE_INTERFACE_H
-#define 	BROADPHASE_INTERFACE_H
+#ifndef		BT_BROADPHASE_INTERFACE_H
+#define 	BT_BROADPHASE_INTERFACE_H
 
 
 
 
 
 
@@ -26,7 +26,14 @@ class btOverlappingPairCache;
 
 
 
 
 
 
-struct	btBroadphaseRayCallback
+struct	btBroadphaseAabbCallback
+{
+	virtual ~btBroadphaseAabbCallback() {}
+	virtual bool	process(const btBroadphaseProxy* proxy) = 0;
+};
+
+
+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;
 	btVector3		m_rayDirectionInverse;
@@ -34,7 +41,6 @@ struct	btBroadphaseRayCallback
 	btScalar		m_lambda_max;
 	btScalar		m_lambda_max;
 
 
 	virtual ~btBroadphaseRayCallback() {}
 	virtual ~btBroadphaseRayCallback() {}
-	virtual bool	process(const btBroadphaseProxy* proxy) = 0;
 };
 };
 
 
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
@@ -54,6 +60,8 @@ public:
 
 
 	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;
+
 	///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;
 
 
@@ -65,10 +73,10 @@ public:
 	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) {};
+	virtual void resetPool(btDispatcher* dispatcher) { (void) dispatcher; };
 
 
 	virtual void	printStats() = 0;
 	virtual void	printStats() = 0;
 
 
 };
 };
 
 
-#endif //BROADPHASE_INTERFACE_H
+#endif //BT_BROADPHASE_INTERFACE_H

+ 15 - 4
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h

@@ -13,8 +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 BROADPHASE_PROXY_H
-#define BROADPHASE_PROXY_H
+#ifndef 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"
@@ -141,6 +141,11 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
 		return (proxyType < CONCAVE_SHAPES_START_HERE);
 		return (proxyType < CONCAVE_SHAPES_START_HERE);
 	}
 	}
 
 
+	static SIMD_FORCE_INLINE bool	isNonMoving(int 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) &&
@@ -150,6 +155,12 @@ BT_DECLARE_ALIGNED_ALLOCATOR();
 	{
 	{
 		return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
 		return (proxyType == COMPOUND_SHAPE_PROXYTYPE);
 	}
 	}
+
+	static SIMD_FORCE_INLINE bool	isSoftBody(int proxyType)
+	{
+		return (proxyType == SOFTBODY_SHAPE_PROXYTYPE);
+	}
+
 	static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
 	static SIMD_FORCE_INLINE bool isInfinite(int proxyType)
 	{
 	{
 		return (proxyType == STATIC_PLANE_PROXYTYPE);
 		return (proxyType == STATIC_PLANE_PROXYTYPE);
@@ -235,7 +246,7 @@ class btBroadphasePairSortPredicate
 {
 {
 	public:
 	public:
 
 
-		bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b )
+		bool operator() ( const btBroadphasePair& a, const btBroadphasePair& b ) const
 		{
 		{
 			const int uidA0 = a.m_pProxy0 ? a.m_pProxy0->m_uniqueId : -1;
 			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 uidB0 = b.m_pProxy0 ? b.m_pProxy0->m_uniqueId : -1;
@@ -255,5 +266,5 @@ SIMD_FORCE_INLINE bool operator==(const btBroadphasePair& a, const btBroadphaseP
 }
 }
 
 
 
 
-#endif //BROADPHASE_PROXY_H
+#endif //BT_BROADPHASE_PROXY_H
 
 

+ 7 - 6
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h

@@ -13,8 +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 COLLISION_ALGORITHM_H
-#define COLLISION_ALGORITHM_H
+#ifndef BT_COLLISION_ALGORITHM_H
+#define BT_COLLISION_ALGORITHM_H
 
 
 #include "LinearMath/btScalar.h"
 #include "LinearMath/btScalar.h"
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
@@ -23,6 +23,7 @@ struct btBroadphaseProxy;
 class btDispatcher;
 class btDispatcher;
 class btManifoldResult;
 class btManifoldResult;
 class btCollisionObject;
 class btCollisionObject;
+struct btCollisionObjectWrapper;
 struct btDispatcherInfo;
 struct btDispatcherInfo;
 class	btPersistentManifold;
 class	btPersistentManifold;
 
 
@@ -44,7 +45,7 @@ struct btCollisionAlgorithmConstructionInfo
 	btDispatcher*	m_dispatcher1;
 	btDispatcher*	m_dispatcher1;
 	btPersistentManifold*	m_manifold;
 	btPersistentManifold*	m_manifold;
 
 
-	int	getDispatcherId();
+//	int	getDispatcherId();
 
 
 };
 };
 
 
@@ -59,7 +60,7 @@ protected:
 	btDispatcher*	m_dispatcher;
 	btDispatcher*	m_dispatcher;
 
 
 protected:
 protected:
-	int	getDispatcherId();
+//	int	getDispatcherId();
 	
 	
 public:
 public:
 
 
@@ -69,7 +70,7 @@ public:
 
 
 	virtual ~btCollisionAlgorithm() {};
 	virtual ~btCollisionAlgorithm() {};
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,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;
 
 
@@ -77,4 +78,4 @@ public:
 };
 };
 
 
 
 
-#endif //COLLISION_ALGORITHM_H
+#endif //BT_COLLISION_ALGORITHM_H

+ 6 - 4
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.cpp

@@ -38,8 +38,9 @@ static DBVT_INLINE btDbvtVolume	merge(	const btDbvtVolume& a,
 									  const btDbvtVolume& b)
 									  const btDbvtVolume& b)
 {
 {
 #if (DBVT_MERGE_IMPL==DBVT_IMPL_SSE)
 #if (DBVT_MERGE_IMPL==DBVT_IMPL_SSE)
-	ATTRIBUTE_ALIGNED16(char locals[sizeof(btDbvtAabbMm)]);
-	btDbvtVolume&	res=*(btDbvtVolume*)locals;
+	ATTRIBUTE_ALIGNED16( char locals[sizeof(btDbvtAabbMm)]);
+	btDbvtVolume* ptr = (btDbvtVolume*) locals;
+	btDbvtVolume&	res=*ptr;
 #else
 #else
 		btDbvtVolume	res;
 		btDbvtVolume	res;
 #endif
 #endif
@@ -61,7 +62,7 @@ static void						getmaxdepth(const btDbvtNode* node,int depth,int& maxdepth)
 	if(node->isinternal())
 	if(node->isinternal())
 	{
 	{
 		getmaxdepth(node->childs[0],depth+1,maxdepth);
 		getmaxdepth(node->childs[0],depth+1,maxdepth);
-		getmaxdepth(node->childs[0],depth+1,maxdepth);
+		getmaxdepth(node->childs[1],depth+1,maxdepth);
 	} else maxdepth=btMax(maxdepth,depth);
 	} else maxdepth=btMax(maxdepth,depth);
 }
 }
 
 
@@ -250,7 +251,8 @@ static btDbvtVolume				bounds(	const tNodeArray& leaves)
 {
 {
 #if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
 #if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
 	ATTRIBUTE_ALIGNED16(char	locals[sizeof(btDbvtVolume)]);
 	ATTRIBUTE_ALIGNED16(char	locals[sizeof(btDbvtVolume)]);
-	btDbvtVolume&	volume=*(btDbvtVolume*)locals;
+	btDbvtVolume* ptr = (btDbvtVolume*) locals;
+	btDbvtVolume&	volume=*ptr;
 	volume=leaves[0]->volume;
 	volume=leaves[0]->volume;
 #else
 #else
 	btDbvtVolume volume=leaves[0]->volume;
 	btDbvtVolume volume=leaves[0]->volume;

+ 113 - 36
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.h

@@ -32,7 +32,7 @@ subject to the following restrictions:
 #define DBVT_IMPL_SSE			1	// SSE
 #define DBVT_IMPL_SSE			1	// SSE
 
 
 // Template implementation of ICollide
 // Template implementation of ICollide
-#ifdef WIN32
+#ifdef _WIN32
 #if (defined (_MSC_VER) && _MSC_VER >= 1400)
 #if (defined (_MSC_VER) && _MSC_VER >= 1400)
 #define	DBVT_USE_TEMPLATE		1
 #define	DBVT_USE_TEMPLATE		1
 #else
 #else
@@ -57,7 +57,7 @@ subject to the following restrictions:
 // Specific methods implementation
 // Specific methods implementation
 
 
 //SSE gives errors on a MSVC 7.1
 //SSE gives errors on a MSVC 7.1
-#if defined (BT_USE_SSE) && defined (WIN32)
+#if defined (BT_USE_SSE) //&& defined (_WIN32)
 #define DBVT_SELECT_IMPL		DBVT_IMPL_SSE
 #define DBVT_SELECT_IMPL		DBVT_IMPL_SSE
 #define DBVT_MERGE_IMPL			DBVT_IMPL_SSE
 #define DBVT_MERGE_IMPL			DBVT_IMPL_SSE
 #define DBVT_INT0_IMPL			DBVT_IMPL_SSE
 #define DBVT_INT0_IMPL			DBVT_IMPL_SSE
@@ -92,7 +92,7 @@ subject to the following restrictions:
 #endif
 #endif
 
 
 #if DBVT_USE_MEMMOVE
 #if DBVT_USE_MEMMOVE
-#ifndef __CELLOS_LV2__
+#if !defined( __CELLOS_LV2__) && !defined(__MWERKS__)
 #include <memory.h>
 #include <memory.h>
 #endif
 #endif
 #include <string.h>
 #include <string.h>
@@ -122,6 +122,7 @@ subject to the following restrictions:
 #error "DBVT_INT0_IMPL undefined"
 #error "DBVT_INT0_IMPL undefined"
 #endif
 #endif
 
 
+
 //
 //
 // Defaults volumes
 // Defaults volumes
 //
 //
@@ -160,6 +161,10 @@ struct	btDbvtAabbMm
 		btDbvtAabbMm& r);
 		btDbvtAabbMm& r);
 	DBVT_INLINE friend bool			NotEqual(	const btDbvtAabbMm& a,
 	DBVT_INLINE friend bool			NotEqual(	const btDbvtAabbMm& a,
 		const btDbvtAabbMm& b);
 		const btDbvtAabbMm& b);
+    
+    DBVT_INLINE btVector3&	tMins()	{ return(mi); }
+	DBVT_INLINE btVector3&	tMaxs()	{ return(mx); }
+    
 private:
 private:
 	DBVT_INLINE void				AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
 	DBVT_INLINE void				AddSpan(const btVector3& d,btScalar& smi,btScalar& smx) const;
 private:
 private:
@@ -184,6 +189,9 @@ struct	btDbvtNode
 	};
 	};
 };
 };
 
 
+typedef btAlignedObjectArray<const btDbvtNode*> btNodeStack;
+
+
 ///The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes (aabb tree).
 ///The btDbvt class implements a fast dynamic bounding volume tree based on axis aligned bounding boxes (aabb tree).
 ///This btDbvt is used for soft body collision detection and for the btDbvtBroadphase. It has a fast insert, remove and update of nodes.
 ///This btDbvt is used for soft body collision detection and for the btDbvtBroadphase. It has a fast insert, remove and update of nodes.
 ///Unlike the btQuantizedBvh, nodes can be dynamically moved around, which allows for change in topology of the underlying data structure.
 ///Unlike the btQuantizedBvh, nodes can be dynamically moved around, which allows for change in topology of the underlying data structure.
@@ -319,7 +327,17 @@ struct	btDbvt
 	DBVT_PREFIX
 	DBVT_PREFIX
 		void		collideTV(	const btDbvtNode* root,
 		void		collideTV(	const btDbvtNode* root,
 		const btDbvtVolume& volume,
 		const btDbvtVolume& volume,
-		DBVT_IPOLICY);
+		DBVT_IPOLICY) const;
+	
+	DBVT_PREFIX
+	void		collideTVNoStackAlloc(	const btDbvtNode* root,
+						  const btDbvtVolume& volume,
+						  btNodeStack& stack,
+						  DBVT_IPOLICY) const;
+	
+	
+	
+	
 	///rayTest is a re-entrant ray test, and can be called in parallel as long as the btAlignedAlloc is thread-safe (uses locking etc)
 	///rayTest is a re-entrant ray test, and can be called in parallel as long as the btAlignedAlloc is thread-safe (uses locking etc)
 	///rayTest is slower than rayTestInternal, because it builds a local stack, using memory allocations, and it recomputes signs/rayDirectionInverses each time
 	///rayTest is slower than rayTestInternal, because it builds a local stack, using memory allocations, and it recomputes signs/rayDirectionInverses each time
 	DBVT_PREFIX
 	DBVT_PREFIX
@@ -338,6 +356,7 @@ struct	btDbvt
 								btScalar lambda_max,
 								btScalar lambda_max,
 								const btVector3& aabbMin,
 								const btVector3& aabbMin,
 								const btVector3& aabbMax,
 								const btVector3& aabbMax,
+                                btAlignedObjectArray<const btDbvtNode*>& stack,
 								DBVT_IPOLICY) const;
 								DBVT_IPOLICY) const;
 
 
 	DBVT_PREFIX
 	DBVT_PREFIX
@@ -518,7 +537,11 @@ DBVT_INLINE bool		Intersect(	const btDbvtAabbMm& a,
 #if	DBVT_INT0_IMPL == DBVT_IMPL_SSE
 #if	DBVT_INT0_IMPL == DBVT_IMPL_SSE
 	const __m128	rt(_mm_or_ps(	_mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
 	const __m128	rt(_mm_or_ps(	_mm_cmplt_ps(_mm_load_ps(b.mx),_mm_load_ps(a.mi)),
 		_mm_cmplt_ps(_mm_load_ps(a.mx),_mm_load_ps(b.mi))));
 		_mm_cmplt_ps(_mm_load_ps(a.mx),_mm_load_ps(b.mi))));
+#if defined (_WIN32)
 	const __int32*	pu((const __int32*)&rt);
 	const __int32*	pu((const __int32*)&rt);
+#else
+    const int*	pu((const int*)&rt);
+#endif
 	return((pu[0]|pu[1]|pu[2])==0);
 	return((pu[0]|pu[1]|pu[2])==0);
 #else
 #else
 	return(	(a.mi.x()<=b.mx.x())&&
 	return(	(a.mi.x()<=b.mx.x())&&
@@ -567,7 +590,12 @@ DBVT_INLINE int			Select(	const btDbvtAabbMm& o,
 							   const btDbvtAabbMm& b)
 							   const btDbvtAabbMm& b)
 {
 {
 #if	DBVT_SELECT_IMPL == DBVT_IMPL_SSE
 #if	DBVT_SELECT_IMPL == DBVT_IMPL_SSE
+    
+#if defined (_WIN32)
 	static ATTRIBUTE_ALIGNED16(const unsigned __int32)	mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
 	static ATTRIBUTE_ALIGNED16(const unsigned __int32)	mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x7fffffff};
+#else
+    static ATTRIBUTE_ALIGNED16(const unsigned int)	mask[]={0x7fffffff,0x7fffffff,0x7fffffff,0x00000000 /*0x7fffffff*/};
+#endif
 	///@todo: the intrinsic version is 11% slower
 	///@todo: the intrinsic version is 11% slower
 #if DBVT_USE_INTRINSIC_SSE
 #if DBVT_USE_INTRINSIC_SSE
 
 
@@ -903,39 +931,72 @@ inline void		btDbvt::collideTT(	const btDbvtNode* root0,
 }
 }
 #endif 
 #endif 
 
 
-//
 DBVT_PREFIX
 DBVT_PREFIX
 inline void		btDbvt::collideTV(	const btDbvtNode* root,
 inline void		btDbvt::collideTV(	const btDbvtNode* root,
 								  const btDbvtVolume& vol,
 								  const btDbvtVolume& vol,
-								  DBVT_IPOLICY)
+								  DBVT_IPOLICY) const
 {
 {
 	DBVT_CHECKTYPE
 	DBVT_CHECKTYPE
-		if(root)
-		{
-			ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume(vol);
-			btAlignedObjectArray<const btDbvtNode*>	stack;
-			stack.resize(0);
-			stack.reserve(SIMPLE_STACKSIZE);
-			stack.push_back(root);
-			do	{
-				const btDbvtNode*	n=stack[stack.size()-1];
-				stack.pop_back();
-				if(Intersect(n->volume,volume))
+	if(root)
+	{
+		ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume(vol);
+		btAlignedObjectArray<const btDbvtNode*>	stack;
+		stack.resize(0);
+		stack.reserve(SIMPLE_STACKSIZE);
+		stack.push_back(root);
+		do	{
+			const btDbvtNode*	n=stack[stack.size()-1];
+			stack.pop_back();
+			if(Intersect(n->volume,volume))
+			{
+				if(n->isinternal())
 				{
 				{
-					if(n->isinternal())
-					{
-						stack.push_back(n->childs[0]);
-						stack.push_back(n->childs[1]);
-					}
-					else
-					{
-						policy.Process(n);
-					}
+					stack.push_back(n->childs[0]);
+					stack.push_back(n->childs[1]);
 				}
 				}
-			} while(stack.size()>0);
-		}
+				else
+				{
+					policy.Process(n);
+				}
+			}
+		} while(stack.size()>0);
+	}
 }
 }
 
 
+//
+DBVT_PREFIX
+inline void		btDbvt::collideTVNoStackAlloc(	const btDbvtNode* root,
+											 const btDbvtVolume& vol,
+											 btNodeStack& stack,
+											 DBVT_IPOLICY) const
+{
+	DBVT_CHECKTYPE
+	if(root)
+	{
+		ATTRIBUTE_ALIGNED16(btDbvtVolume)		volume(vol);
+		stack.resize(0);
+		stack.reserve(SIMPLE_STACKSIZE);
+		stack.push_back(root);
+		do	{
+			const btDbvtNode*	n=stack[stack.size()-1];
+			stack.pop_back();
+			if(Intersect(n->volume,volume))
+			{
+				if(n->isinternal())
+				{
+					stack.push_back(n->childs[0]);
+					stack.push_back(n->childs[1]);
+				}
+				else
+				{
+					policy.Process(n);
+				}
+			}
+		} while(stack.size()>0);
+	}
+}
+
+
 DBVT_PREFIX
 DBVT_PREFIX
 inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 								const btVector3& rayFrom,
 								const btVector3& rayFrom,
@@ -945,8 +1006,10 @@ inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 								btScalar lambda_max,
 								btScalar lambda_max,
 								const btVector3& aabbMin,
 								const btVector3& aabbMin,
 								const btVector3& aabbMax,
 								const btVector3& aabbMax,
-								DBVT_IPOLICY) const
+                                btAlignedObjectArray<const btDbvtNode*>& stack,
+                                DBVT_IPOLICY ) const
 {
 {
+        (void) rayTo;
 	DBVT_CHECKTYPE
 	DBVT_CHECKTYPE
 	if(root)
 	if(root)
 	{
 	{
@@ -954,15 +1017,14 @@ inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 
 
 		int								depth=1;
 		int								depth=1;
 		int								treshold=DOUBLE_STACKSIZE-2;
 		int								treshold=DOUBLE_STACKSIZE-2;
-		btAlignedObjectArray<const btDbvtNode*>	stack;
 		stack.resize(DOUBLE_STACKSIZE);
 		stack.resize(DOUBLE_STACKSIZE);
 		stack[0]=root;
 		stack[0]=root;
 		btVector3 bounds[2];
 		btVector3 bounds[2];
 		do	
 		do	
 		{
 		{
 			const btDbvtNode*	node=stack[--depth];
 			const btDbvtNode*	node=stack[--depth];
-			bounds[0] = node->volume.Mins()+aabbMin;
-			bounds[1] = node->volume.Maxs()+aabbMax;
+			bounds[0] = node->volume.Mins()-aabbMax;
+			bounds[1] = node->volume.Maxs()-aabbMin;
 			btScalar tmin=1.f,lambda_min=0.f;
 			btScalar tmin=1.f,lambda_min=0.f;
 			unsigned int result1=false;
 			unsigned int result1=false;
 			result1 = btRayAabb2(rayFrom,rayDirectionInverse,signs,bounds,tmin,lambda_min,lambda_max);
 			result1 = btRayAabb2(rayFrom,rayDirectionInverse,signs,bounds,tmin,lambda_min,lambda_max);
@@ -1178,19 +1240,34 @@ inline void		btDbvt::collideOCL(	const btDbvtNode* root,
 							/* Insert 0	*/ 
 							/* Insert 0	*/ 
 							j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size());
 							j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size());
 							stack.push_back(0);
 							stack.push_back(0);
+							
+							//void * memmove ( void * destination, const void * source, size_t num );
+							
 #if DBVT_USE_MEMMOVE
 #if DBVT_USE_MEMMOVE
-							memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
+                     {
+                     int num_items_to_move = stack.size()-1-j;
+                     if(num_items_to_move > 0)
+                        memmove(&stack[j+1],&stack[j],sizeof(int)*num_items_to_move);
+                     }
 #else
 #else
-							for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
+                     for(int k=stack.size()-1;k>j;--k) {
+								stack[k]=stack[k-1];
+                     }
 #endif
 #endif
 							stack[j]=allocate(ifree,stock,nes[q]);
 							stack[j]=allocate(ifree,stock,nes[q]);
 							/* Insert 1	*/ 
 							/* Insert 1	*/ 
 							j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size());
 							j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size());
 							stack.push_back(0);
 							stack.push_back(0);
 #if DBVT_USE_MEMMOVE
 #if DBVT_USE_MEMMOVE
-							memmove(&stack[j+1],&stack[j],sizeof(int)*(stack.size()-j-1));
+                     {
+                     int num_items_to_move = stack.size()-1-j;
+                     if(num_items_to_move > 0)
+                        memmove(&stack[j+1],&stack[j],sizeof(int)*num_items_to_move);
+                     }
 #else
 #else
-							for(int k=stack.size()-1;k>j;--k) stack[k]=stack[k-1];
+                     for(int k=stack.size()-1;k>j;--k) {
+                        stack[k]=stack[k-1];
+                     }
 #endif
 #endif
 							stack[j]=allocate(ifree,stock,nes[1-q]);
 							stack[j]=allocate(ifree,stock,nes[1-q]);
 						}
 						}

+ 93 - 0
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp

@@ -16,6 +16,7 @@ subject to the following restrictions:
 ///btDbvtBroadphase implementation by Nathanael Presson
 ///btDbvtBroadphase implementation by Nathanael Presson
 
 
 #include "btDbvtBroadphase.h"
 #include "btDbvtBroadphase.h"
+#include "LinearMath/btThreads.h"
 
 
 //
 //
 // Profiling
 // Profiling
@@ -142,6 +143,11 @@ btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
 	{
 	{
 		m_stageRoots[i]=0;
 		m_stageRoots[i]=0;
 	}
 	}
+#if BT_THREADSAFE
+    m_rayTestStacks.resize(BT_MAX_THREAD_COUNT);
+#else
+    m_rayTestStacks.resize(1);
+#endif
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
 	clear(m_profiling);
 	clear(m_profiling);
 #endif
 #endif
@@ -227,6 +233,23 @@ struct	BroadphaseRayTester : btDbvt::ICollide
 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];
+#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;
+    }
+#endif
 
 
 	m_sets[0].rayTestInternal(	m_sets[0].m_root,
 	m_sets[0].rayTestInternal(	m_sets[0].m_root,
 		rayFrom,
 		rayFrom,
@@ -236,6 +259,7 @@ void	btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
 		rayCallback.m_lambda_max,
 		rayCallback.m_lambda_max,
 		aabbMin,
 		aabbMin,
 		aabbMax,
 		aabbMax,
+        *stack,
 		callback);
 		callback);
 
 
 	m_sets[1].rayTestInternal(	m_sets[1].m_root,
 	m_sets[1].rayTestInternal(	m_sets[1].m_root,
@@ -246,11 +270,39 @@ void	btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
 		rayCallback.m_lambda_max,
 		rayCallback.m_lambda_max,
 		aabbMin,
 		aabbMin,
 		aabbMax,
 		aabbMax,
+        *stack,
 		callback);
 		callback);
 
 
 }
 }
 
 
 
 
+struct	BroadphaseAabbTester : btDbvt::ICollide
+{
+	btBroadphaseAabbCallback& m_aabbCallback;
+	BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback)
+		:m_aabbCallback(orgCallback)
+	{
+	}
+	void					Process(const btDbvtNode* leaf)
+	{
+		btDbvtProxy*	proxy=(btDbvtProxy*)leaf->data;
+		m_aabbCallback.process(proxy);
+	}
+};	
+
+void	btDbvtBroadphase::aabbTest(const btVector3& aabbMin,const btVector3& aabbMax,btBroadphaseAabbCallback& 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);
+
+}
+
+
+
 //
 //
 void							btDbvtBroadphase::setAabb(		btBroadphaseProxy* absproxy,
 void							btDbvtBroadphase::setAabb(		btBroadphaseProxy* absproxy,
 														  const btVector3& aabbMin,
 														  const btVector3& aabbMin,
@@ -318,6 +370,47 @@ void							btDbvtBroadphase::setAabb(		btBroadphaseProxy* absproxy,
 	}
 	}
 }
 }
 
 
+
+//
+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	*/ 
+		m_sets[1].remove(proxy->leaf);
+		proxy->leaf=m_sets[0].insert(aabb,proxy);
+		docollide=true;
+	}
+	else
+	{/* dynamic set				*/ 
+		++m_updates_call;
+		/* Teleporting			*/ 
+		m_sets[0].update(proxy->leaf,aabb);
+		++m_updates_done;
+		docollide=true;
+	}
+	listremove(proxy,m_stageRoots[proxy->stage]);
+	proxy->m_aabbMin = aabbMin;
+	proxy->m_aabbMax = aabbMax;
+	proxy->stage	=	m_stageCurrent;
+	listappend(proxy,m_stageRoots[m_stageCurrent]);
+	if(docollide)
+	{
+		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);
+		}
+	}	
+}
+
 //
 //
 void							btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 void							btDbvtBroadphase::calculateOverlappingPairs(btDispatcher* dispatcher)
 {
 {

+ 28 - 16
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h

@@ -87,6 +87,7 @@ struct	btDbvtBroadphase : btBroadphaseInterface
 	bool					m_releasepaircache;			// Release pair cache on delete
 	bool					m_releasepaircache;			// Release pair cache on delete
 	bool					m_deferedcollide;			// Defere dynamic/static collision to collide call
 	bool					m_deferedcollide;			// Defere dynamic/static collision to collide call
 	bool					m_needcleanup;				// Need to run cleanup?
 	bool					m_needcleanup;				// Need to run cleanup?
+    btAlignedObjectArray< btAlignedObjectArray<const btDbvtNode*> > m_rayTestStacks;
 #if DBVT_BP_PROFILE
 #if DBVT_BP_PROFILE
 	btClock					m_clock;
 	btClock					m_clock;
 	struct	{
 	struct	{
@@ -102,20 +103,27 @@ struct	btDbvtBroadphase : btBroadphaseInterface
 	~btDbvtBroadphase();
 	~btDbvtBroadphase();
 	void							collide(btDispatcher* dispatcher);
 	void							collide(btDispatcher* dispatcher);
 	void							optimize();
 	void							optimize();
-	/* btBroadphaseInterface Implementation	*/ 
+	
+	/* btBroadphaseInterface Implementation	*/
 	btBroadphaseProxy*				createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
 	btBroadphaseProxy*				createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy);
-	void							destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher);
-	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	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
-	void							calculateOverlappingPairs(btDispatcher* dispatcher);
-	btOverlappingPairCache*			getOverlappingPairCache();
-	const btOverlappingPairCache*	getOverlappingPairCache() const;
-	void							getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const;
-	void							printStats();
-	static void						benchmark(btBroadphaseInterface*);
+	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
+	virtual void resetPool(btDispatcher* dispatcher);
+
+	void	performDeferredRemoval(btDispatcher* dispatcher);
+	
 	void	setVelocityPrediction(btScalar prediction)
 	void	setVelocityPrediction(btScalar prediction)
 	{
 	{
 		m_prediction = prediction;
 		m_prediction = prediction;
@@ -124,11 +132,15 @@ struct	btDbvtBroadphase : btBroadphaseInterface
 	{
 	{
 		return m_prediction;
 		return m_prediction;
 	}
 	}
-	
-	void	performDeferredRemoval(btDispatcher* dispatcher);
 
 
-	///reset broadphase internal structures, to ensure determinism/reproducability
-	virtual void resetPool(btDispatcher* dispatcher);
+	///this setAabbForceUpdate is similar to setAabb but always forces the aabb update. 
+	///it is not part of the btBroadphaseInterface but specific to btDbvtBroadphase.
+	///it bypasses certain optimizations that prevent aabb updates (when the aabb shrinks), see
+	///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*);
+
 
 
 };
 };
 
 

+ 21 - 14
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.h

@@ -13,9 +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 _DISPATCHER_H
-#define _DISPATCHER_H
-
+#ifndef BT_DISPATCHER_H
+#define BT_DISPATCHER_H
 #include "LinearMath/btScalar.h"
 #include "LinearMath/btScalar.h"
 
 
 class btCollisionAlgorithm;
 class btCollisionAlgorithm;
@@ -23,10 +22,10 @@ struct btBroadphaseProxy;
 class btRigidBody;
 class btRigidBody;
 class	btCollisionObject;
 class	btCollisionObject;
 class btOverlappingPairCache;
 class btOverlappingPairCache;
-
+struct btCollisionObjectWrapper;
 
 
 class btPersistentManifold;
 class btPersistentManifold;
-class btStackAlloc;
+class btPoolAllocator;
 
 
 struct btDispatcherInfo
 struct btDispatcherInfo
 {
 {
@@ -40,15 +39,14 @@ struct btDispatcherInfo
 		m_stepCount(0),
 		m_stepCount(0),
 		m_dispatchFunc(DISPATCH_DISCRETE),
 		m_dispatchFunc(DISPATCH_DISCRETE),
 		m_timeOfImpact(btScalar(1.)),
 		m_timeOfImpact(btScalar(1.)),
-		m_useContinuous(false),
+		m_useContinuous(true),
 		m_debugDraw(0),
 		m_debugDraw(0),
 		m_enableSatConvex(false),
 		m_enableSatConvex(false),
 		m_enableSPU(true),
 		m_enableSPU(true),
 		m_useEpa(true),
 		m_useEpa(true),
 		m_allowedCcdPenetration(btScalar(0.04)),
 		m_allowedCcdPenetration(btScalar(0.04)),
 		m_useConvexConservativeDistanceUtil(false),
 		m_useConvexConservativeDistanceUtil(false),
-		m_convexConservativeDistanceThreshold(0.0f),
-		m_stackAllocator(0)
+		m_convexConservativeDistanceThreshold(0.0f)
 	{
 	{
 
 
 	}
 	}
@@ -64,7 +62,12 @@ struct btDispatcherInfo
 	btScalar	m_allowedCcdPenetration;
 	btScalar	m_allowedCcdPenetration;
 	bool		m_useConvexConservativeDistanceUtil;
 	bool		m_useConvexConservativeDistanceUtil;
 	btScalar	m_convexConservativeDistanceThreshold;
 	btScalar	m_convexConservativeDistanceThreshold;
-	btStackAlloc*	m_stackAllocator;
+};
+
+enum ebtDispatcherQueryType
+{
+	BT_CONTACT_POINT_ALGORITHMS = 1,
+	BT_CLOSEST_POINT_ALGORITHMS = 2
 };
 };
 
 
 ///The btDispatcher interface class can be used in combination with broadphase to dispatch calculations for overlapping pairs.
 ///The btDispatcher interface class can be used in combination with broadphase to dispatch calculations for overlapping pairs.
@@ -76,17 +79,17 @@ class btDispatcher
 public:
 public:
 	virtual ~btDispatcher() ;
 	virtual ~btDispatcher() ;
 
 
-	virtual btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold=0) = 0;
+	virtual btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType) = 0;
 
 
-	virtual btPersistentManifold*	getNewManifold(void* body0,void* body1)=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(btCollisionObject* body0,btCollisionObject* body1) = 0;
+	virtual bool	needsCollision(const btCollisionObject* body0,const btCollisionObject* body1) = 0;
 
 
-	virtual bool	needsResponse(btCollisionObject* body0,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;
 
 
@@ -96,6 +99,10 @@ public:
 
 
 	virtual	btPersistentManifold**	getInternalManifoldPointer() = 0;
 	virtual	btPersistentManifold**	getInternalManifoldPointer() = 0;
 
 
+	virtual	btPoolAllocator*	getInternalManifoldPool() = 0;
+
+	virtual	const btPoolAllocator*	getInternalManifoldPool() const = 0;
+
 	virtual	void* allocateCollisionAlgorithm(int size)  = 0;
 	virtual	void* allocateCollisionAlgorithm(int size)  = 0;
 
 
 	virtual	void freeCollisionAlgorithm(void* ptr) = 0;
 	virtual	void freeCollisionAlgorithm(void* ptr) = 0;
@@ -103,4 +110,4 @@ public:
 };
 };
 
 
 
 
-#endif //_DISPATCHER_H
+#endif //BT_DISPATCHER_H

+ 1 - 1
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp

@@ -341,7 +341,7 @@ class btMultiSapBroadphasePairSortPredicate
 {
 {
 	public:
 	public:
 
 
-		bool operator() ( const btBroadphasePair& a1, const btBroadphasePair& b1 )
+		bool operator() ( const btBroadphasePair& a1, const btBroadphasePair& b1 ) const
 		{
 		{
 				btMultiSapBroadphase::btMultiSapProxy* aProxy0 = a1.m_pProxy0 ? (btMultiSapBroadphase::btMultiSapProxy*)a1.m_pProxy0->m_multiSapParentProxy : 0;
 				btMultiSapBroadphase::btMultiSapProxy* aProxy0 = a1.m_pProxy0 ? (btMultiSapBroadphase::btMultiSapProxy*)a1.m_pProxy0->m_multiSapParentProxy : 0;
 				btMultiSapBroadphase::btMultiSapProxy* aProxy1 = a1.m_pProxy1 ? (btMultiSapBroadphase::btMultiSapProxy*)a1.m_pProxy1->m_multiSapParentProxy : 0;
 				btMultiSapBroadphase::btMultiSapProxy* aProxy1 = a1.m_pProxy1 ? (btMultiSapBroadphase::btMultiSapProxy*)a1.m_pProxy1->m_multiSapParentProxy : 0;

+ 5 - 6
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp

@@ -34,7 +34,6 @@ int gFindPairs =0;
 
 
 btHashedOverlappingPairCache::btHashedOverlappingPairCache():
 btHashedOverlappingPairCache::btHashedOverlappingPairCache():
 	m_overlapFilterCallback(0),
 	m_overlapFilterCallback(0),
-	m_blockedForChanges(false),
 	m_ghostPairCallback(0)
 	m_ghostPairCallback(0)
 {
 {
 	int initialAllocatedSize= 2;
 	int initialAllocatedSize= 2;
@@ -53,7 +52,7 @@ btHashedOverlappingPairCache::~btHashedOverlappingPairCache()
 
 
 void	btHashedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher)
 void	btHashedOverlappingPairCache::cleanOverlappingPair(btBroadphasePair& pair,btDispatcher* dispatcher)
 {
 {
-	if (pair.m_algorithm)
+	if (pair.m_algorithm && dispatcher)
 	{
 	{
 		{
 		{
 			pair.m_algorithm->~btCollisionAlgorithm();
 			pair.m_algorithm->~btCollisionAlgorithm();
@@ -240,7 +239,7 @@ btBroadphasePair* btHashedOverlappingPairCache::internalAddPair(btBroadphaseProx
 		}*/
 		}*/
 	int count = m_overlappingPairArray.size();
 	int count = m_overlappingPairArray.size();
 	int oldCapacity = m_overlappingPairArray.capacity();
 	int oldCapacity = m_overlappingPairArray.capacity();
-	void* mem = &m_overlappingPairArray.expand();
+	void* mem = &m_overlappingPairArray.expandNonInitializing();
 
 
 	//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)
@@ -373,10 +372,10 @@ void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 	return userData;
 	return userData;
 }
 }
 //#include <stdio.h>
 //#include <stdio.h>
-
+#include "LinearMath/btQuickprof.h"
 void	btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback,btDispatcher* dispatcher)
 void	btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback,btDispatcher* dispatcher)
 {
 {
-
+	BT_PROFILE("btHashedOverlappingPairCache::processAllOverlappingPairs");
 	int i;
 	int i;
 
 
 //	printf("m_overlappingPairArray.size()=%d\n",m_overlappingPairArray.size());
 //	printf("m_overlappingPairArray.size()=%d\n",m_overlappingPairArray.size());
@@ -467,7 +466,7 @@ btBroadphasePair*	btSortedOverlappingPairCache::addOverlappingPair(btBroadphaseP
 	if (!needsBroadphaseCollision(proxy0,proxy1))
 	if (!needsBroadphaseCollision(proxy0,proxy1))
 		return 0;
 		return 0;
 	
 	
-	void* mem = &m_overlappingPairArray.expand();
+	void* mem = &m_overlappingPairArray.expandNonInitializing();
 	btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1);
 	btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1);
 	
 	
 	gOverlappingPairs++;
 	gOverlappingPairs++;

+ 10 - 9
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h

@@ -13,8 +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 OVERLAPPING_PAIR_CACHE_H
-#define OVERLAPPING_PAIR_CACHE_H
+#ifndef BT_OVERLAPPING_PAIR_CACHE_H
+#define BT_OVERLAPPING_PAIR_CACHE_H
 
 
 
 
 #include "btBroadphaseInterface.h"
 #include "btBroadphaseInterface.h"
@@ -94,7 +94,12 @@ class btHashedOverlappingPairCache : public btOverlappingPairCache
 {
 {
 	btBroadphasePairArray	m_overlappingPairArray;
 	btBroadphasePairArray	m_overlappingPairArray;
 	btOverlapFilterCallback* m_overlapFilterCallback;
 	btOverlapFilterCallback* m_overlapFilterCallback;
-	bool		m_blockedForChanges;
+
+protected:
+	
+	btAlignedObjectArray<int>	m_hashTable;
+	btAlignedObjectArray<int>	m_next;
+	btOverlappingPairCallback*	m_ghostPairCallback;
 
 
 
 
 public:
 public:
@@ -265,11 +270,6 @@ private:
 	virtual void	sortOverlappingPairs(btDispatcher* dispatcher);
 	virtual void	sortOverlappingPairs(btDispatcher* dispatcher);
 	
 	
 
 
-protected:
-	
-	btAlignedObjectArray<int>	m_hashTable;
-	btAlignedObjectArray<int>	m_next;
-	btOverlappingPairCallback*	m_ghostPairCallback;
 	
 	
 };
 };
 
 
@@ -457,12 +457,13 @@ public:
 	
 	
 	virtual void	sortOverlappingPairs(btDispatcher* dispatcher)
 	virtual void	sortOverlappingPairs(btDispatcher* dispatcher)
 	{
 	{
+        (void) dispatcher;
 	}
 	}
 
 
 
 
 };
 };
 
 
 
 
-#endif //OVERLAPPING_PAIR_CACHE_H
+#endif //BT_OVERLAPPING_PAIR_CACHE_H
 
 
 
 

+ 257 - 10
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp

@@ -17,6 +17,7 @@ subject to the following restrictions:
 
 
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "LinearMath/btIDebugDraw.h"
+#include "LinearMath/btSerializer.h"
 
 
 #define RAYAABB2
 #define RAYAABB2
 
 
@@ -78,10 +79,10 @@ void btQuantizedBvh::buildInternal()
 #ifdef DEBUG_PATCH_COLORS
 #ifdef DEBUG_PATCH_COLORS
 btVector3 color[4]=
 btVector3 color[4]=
 {
 {
-	btVector3(255,0,0),
-	btVector3(0,255,0),
-	btVector3(0,0,255),
-	btVector3(0,255,255)
+	btVector3(1,0,0),
+	btVector3(0,1,0),
+	btVector3(0,0,1),
+	btVector3(0,1,1)
 };
 };
 #endif //DEBUG_PATCH_COLORS
 #endif //DEBUG_PATCH_COLORS
 
 
@@ -95,7 +96,27 @@ void	btQuantizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btV
 	m_bvhAabbMax = bvhAabbMax + clampValue;
 	m_bvhAabbMax = bvhAabbMax + clampValue;
 	btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
 	btVector3 aabbSize = m_bvhAabbMax - m_bvhAabbMin;
 	m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
 	m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
+
 	m_useQuantization = true;
 	m_useQuantization = true;
+
+	{
+		unsigned short vecIn[3];
+		btVector3 v;
+		{
+			quantize(vecIn,m_bvhAabbMin,false);
+			v = unQuantize(vecIn);
+			m_bvhAabbMin.setMin(v-clampValue);
+		}
+        aabbSize = m_bvhAabbMax - m_bvhAabbMin;
+        m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
+		{
+			quantize(vecIn,m_bvhAabbMax,true);
+			v = unQuantize(vecIn);
+			m_bvhAabbMax.setMax(v+clampValue);
+		}
+		aabbSize = m_bvhAabbMax - m_bvhAabbMin;
+		m_bvhQuantization = btVector3(btScalar(65533.0),btScalar(65533.0),btScalar(65533.0)) / aabbSize;
+	}
 }
 }
 
 
 
 
@@ -493,8 +514,8 @@ void	btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCall
 		bounds[0] = rootNode->m_aabbMinOrg;
 		bounds[0] = rootNode->m_aabbMinOrg;
 		bounds[1] = rootNode->m_aabbMaxOrg;
 		bounds[1] = rootNode->m_aabbMaxOrg;
 		/* Add box cast extents */
 		/* Add box cast extents */
-		bounds[0] += aabbMin;
-		bounds[1] += aabbMax;
+		bounds[0] -= aabbMax;
+		bounds[1] -= aabbMin;
 
 
 		aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg);
 		aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg);
 		//perhaps profile if it is worth doing the aabbOverlap test first
 		//perhaps profile if it is worth doing the aabbOverlap test first
@@ -617,8 +638,8 @@ void	btQuantizedBvh::walkStacklessQuantizedTreeAgainstRay(btNodeOverlapCallback*
 			bounds[0] = unQuantize(rootNode->m_quantizedAabbMin);
 			bounds[0] = unQuantize(rootNode->m_quantizedAabbMin);
 			bounds[1] = unQuantize(rootNode->m_quantizedAabbMax);
 			bounds[1] = unQuantize(rootNode->m_quantizedAabbMax);
 			/* Add box cast extents */
 			/* Add box cast extents */
-			bounds[0] += aabbMin;
-			bounds[1] += aabbMax;
+			bounds[0] -= aabbMax;
+			bounds[1] -= aabbMin;
 			btVector3 normal;
 			btVector3 normal;
 #if 0
 #if 0
 			bool ra2 = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
 			bool ra2 = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0, lambda_max);
@@ -830,7 +851,7 @@ unsigned int btQuantizedBvh::getAlignmentSerializationPadding()
 	return 0;//BVH_ALIGNMENT_BLOCKS * BVH_ALIGNMENT;
 	return 0;//BVH_ALIGNMENT_BLOCKS * BVH_ALIGNMENT;
 }
 }
 
 
-unsigned btQuantizedBvh::calculateSerializeBufferSize()
+unsigned btQuantizedBvh::calculateSerializeBufferSize() const
 {
 {
 	unsigned baseSize = sizeof(btQuantizedBvh) + getAlignmentSerializationPadding();
 	unsigned baseSize = sizeof(btQuantizedBvh) + getAlignmentSerializationPadding();
 	baseSize += sizeof(btBvhSubtreeInfo) * m_subtreeHeaderCount;
 	baseSize += sizeof(btBvhSubtreeInfo) * m_subtreeHeaderCount;
@@ -841,7 +862,7 @@ unsigned btQuantizedBvh::calculateSerializeBufferSize()
 	return baseSize + m_curNodeIndex * sizeof(btOptimizedBvhNode);
 	return baseSize + m_curNodeIndex * sizeof(btOptimizedBvhNode);
 }
 }
 
 
-bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian)
+bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) const
 {
 {
 	btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
 	btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
 	m_subtreeHeaderCount = m_SubtreeHeaders.size();
 	m_subtreeHeaderCount = m_SubtreeHeaders.size();
@@ -1143,6 +1164,232 @@ m_bulletVersion(BT_BULLET_VERSION)
 
 
 }
 }
 
 
+void btQuantizedBvh::deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData)
+{
+	m_bvhAabbMax.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMax);
+	m_bvhAabbMin.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMin);
+	m_bvhQuantization.deSerializeFloat(quantizedBvhFloatData.m_bvhQuantization);
+
+	m_curNodeIndex = quantizedBvhFloatData.m_curNodeIndex;
+	m_useQuantization = quantizedBvhFloatData.m_useQuantization!=0;
+	
+	{
+		int numElem = quantizedBvhFloatData.m_numContiguousLeafNodes;
+		m_contiguousNodes.resize(numElem);
+
+		if (numElem)
+		{
+			btOptimizedBvhNodeFloatData* memPtr = quantizedBvhFloatData.m_contiguousNodesPtr;
+
+			for (int i=0;i<numElem;i++,memPtr++)
+			{
+				m_contiguousNodes[i].m_aabbMaxOrg.deSerializeFloat(memPtr->m_aabbMaxOrg);
+				m_contiguousNodes[i].m_aabbMinOrg.deSerializeFloat(memPtr->m_aabbMinOrg);
+				m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex;
+				m_contiguousNodes[i].m_subPart = memPtr->m_subPart;
+				m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex;
+			}
+		}
+	}
+
+	{
+		int numElem = quantizedBvhFloatData.m_numQuantizedContiguousNodes;
+		m_quantizedContiguousNodes.resize(numElem);
+		
+		if (numElem)
+		{
+			btQuantizedBvhNodeData* memPtr = quantizedBvhFloatData.m_quantizedContiguousNodesPtr;
+			for (int i=0;i<numElem;i++,memPtr++)
+			{
+				m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex;
+				m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
+			}
+		}
+	}
+
+	m_traversalMode = btTraversalMode(quantizedBvhFloatData.m_traversalMode);
+	
+	{
+		int numElem = quantizedBvhFloatData.m_numSubtreeHeaders;
+		m_SubtreeHeaders.resize(numElem);
+		if (numElem)
+		{
+			btBvhSubtreeInfoData* memPtr = quantizedBvhFloatData.m_subTreeInfoPtr;
+			for (int i=0;i<numElem;i++,memPtr++)
+			{
+				m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ;
+				m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
+				m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
+				m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
+				m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
+				m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
+				m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex;
+				m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize;
+			}
+		}
+	}
+}
+
+void btQuantizedBvh::deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData)
+{
+	m_bvhAabbMax.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMax);
+	m_bvhAabbMin.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMin);
+	m_bvhQuantization.deSerializeDouble(quantizedBvhDoubleData.m_bvhQuantization);
+
+	m_curNodeIndex = quantizedBvhDoubleData.m_curNodeIndex;
+	m_useQuantization = quantizedBvhDoubleData.m_useQuantization!=0;
+	
+	{
+		int numElem = quantizedBvhDoubleData.m_numContiguousLeafNodes;
+		m_contiguousNodes.resize(numElem);
+
+		if (numElem)
+		{
+			btOptimizedBvhNodeDoubleData* memPtr = quantizedBvhDoubleData.m_contiguousNodesPtr;
+
+			for (int i=0;i<numElem;i++,memPtr++)
+			{
+				m_contiguousNodes[i].m_aabbMaxOrg.deSerializeDouble(memPtr->m_aabbMaxOrg);
+				m_contiguousNodes[i].m_aabbMinOrg.deSerializeDouble(memPtr->m_aabbMinOrg);
+				m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex;
+				m_contiguousNodes[i].m_subPart = memPtr->m_subPart;
+				m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex;
+			}
+		}
+	}
+
+	{
+		int numElem = quantizedBvhDoubleData.m_numQuantizedContiguousNodes;
+		m_quantizedContiguousNodes.resize(numElem);
+		
+		if (numElem)
+		{
+			btQuantizedBvhNodeData* memPtr = quantizedBvhDoubleData.m_quantizedContiguousNodesPtr;
+			for (int i=0;i<numElem;i++,memPtr++)
+			{
+				m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex;
+				m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
+				m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
+			}
+		}
+	}
+
+	m_traversalMode = btTraversalMode(quantizedBvhDoubleData.m_traversalMode);
+	
+	{
+		int numElem = quantizedBvhDoubleData.m_numSubtreeHeaders;
+		m_SubtreeHeaders.resize(numElem);
+		if (numElem)
+		{
+			btBvhSubtreeInfoData* memPtr = quantizedBvhDoubleData.m_subTreeInfoPtr;
+			for (int i=0;i<numElem;i++,memPtr++)
+			{
+				m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ;
+				m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1];
+				m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2];
+				m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0];
+				m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1];
+				m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2];
+				m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex;
+				m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize;
+			}
+		}
+	}
+
+}
+
+
+
+///fills the dataBuffer and returns the struct name (and 0 on failure)
+const char*	btQuantizedBvh::serialize(void* dataBuffer, btSerializer* serializer) const
+{
+	btQuantizedBvhData* quantizedData = (btQuantizedBvhData*)dataBuffer;
+	
+	m_bvhAabbMax.serialize(quantizedData->m_bvhAabbMax);
+	m_bvhAabbMin.serialize(quantizedData->m_bvhAabbMin);
+	m_bvhQuantization.serialize(quantizedData->m_bvhQuantization);
+
+	quantizedData->m_curNodeIndex = m_curNodeIndex;
+	quantizedData->m_useQuantization = m_useQuantization;
+	
+	quantizedData->m_numContiguousLeafNodes = m_contiguousNodes.size();
+	quantizedData->m_contiguousNodesPtr = (btOptimizedBvhNodeData*) (m_contiguousNodes.size() ? serializer->getUniquePointer((void*)&m_contiguousNodes[0]) : 0);
+	if (quantizedData->m_contiguousNodesPtr)
+	{
+		int sz = sizeof(btOptimizedBvhNodeData);
+		int numElem = m_contiguousNodes.size();
+		btChunk* chunk = serializer->allocate(sz,numElem);
+		btOptimizedBvhNodeData* memPtr = (btOptimizedBvhNodeData*)chunk->m_oldPtr;
+		for (int i=0;i<numElem;i++,memPtr++)
+		{
+			m_contiguousNodes[i].m_aabbMaxOrg.serialize(memPtr->m_aabbMaxOrg);
+			m_contiguousNodes[i].m_aabbMinOrg.serialize(memPtr->m_aabbMinOrg);
+			memPtr->m_escapeIndex = m_contiguousNodes[i].m_escapeIndex;
+			memPtr->m_subPart = m_contiguousNodes[i].m_subPart;
+			memPtr->m_triangleIndex = m_contiguousNodes[i].m_triangleIndex;
+		}
+		serializer->finalizeChunk(chunk,"btOptimizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_contiguousNodes[0]);
+	}
+
+	quantizedData->m_numQuantizedContiguousNodes = m_quantizedContiguousNodes.size();
+//	printf("quantizedData->m_numQuantizedContiguousNodes=%d\n",quantizedData->m_numQuantizedContiguousNodes);
+	quantizedData->m_quantizedContiguousNodesPtr =(btQuantizedBvhNodeData*) (m_quantizedContiguousNodes.size() ? serializer->getUniquePointer((void*)&m_quantizedContiguousNodes[0]) : 0);
+	if (quantizedData->m_quantizedContiguousNodesPtr)
+	{
+		int sz = sizeof(btQuantizedBvhNodeData);
+		int numElem = m_quantizedContiguousNodes.size();
+		btChunk* chunk = serializer->allocate(sz,numElem);
+		btQuantizedBvhNodeData* memPtr = (btQuantizedBvhNodeData*)chunk->m_oldPtr;
+		for (int i=0;i<numElem;i++,memPtr++)
+		{
+			memPtr->m_escapeIndexOrTriangleIndex = m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex;
+			memPtr->m_quantizedAabbMax[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[0];
+			memPtr->m_quantizedAabbMax[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[1];
+			memPtr->m_quantizedAabbMax[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[2];
+			memPtr->m_quantizedAabbMin[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[0];
+			memPtr->m_quantizedAabbMin[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[1];
+			memPtr->m_quantizedAabbMin[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[2];
+		}
+		serializer->finalizeChunk(chunk,"btQuantizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_quantizedContiguousNodes[0]);
+	}
+
+	quantizedData->m_traversalMode = int(m_traversalMode);
+	quantizedData->m_numSubtreeHeaders = m_SubtreeHeaders.size();
+
+	quantizedData->m_subTreeInfoPtr = (btBvhSubtreeInfoData*) (m_SubtreeHeaders.size() ? serializer->getUniquePointer((void*)&m_SubtreeHeaders[0]) : 0);
+	if (quantizedData->m_subTreeInfoPtr)
+	{
+		int sz = sizeof(btBvhSubtreeInfoData);
+		int numElem = m_SubtreeHeaders.size();
+		btChunk* chunk = serializer->allocate(sz,numElem);
+		btBvhSubtreeInfoData* memPtr = (btBvhSubtreeInfoData*)chunk->m_oldPtr;
+		for (int i=0;i<numElem;i++,memPtr++)
+		{
+			memPtr->m_quantizedAabbMax[0] = m_SubtreeHeaders[i].m_quantizedAabbMax[0];
+			memPtr->m_quantizedAabbMax[1] = m_SubtreeHeaders[i].m_quantizedAabbMax[1];
+			memPtr->m_quantizedAabbMax[2] = m_SubtreeHeaders[i].m_quantizedAabbMax[2];
+			memPtr->m_quantizedAabbMin[0] = m_SubtreeHeaders[i].m_quantizedAabbMin[0];
+			memPtr->m_quantizedAabbMin[1] = m_SubtreeHeaders[i].m_quantizedAabbMin[1];
+			memPtr->m_quantizedAabbMin[2] = m_SubtreeHeaders[i].m_quantizedAabbMin[2];
+
+			memPtr->m_rootNodeIndex = m_SubtreeHeaders[i].m_rootNodeIndex;
+			memPtr->m_subtreeSize = m_SubtreeHeaders[i].m_subtreeSize;
+		}
+		serializer->finalizeChunk(chunk,"btBvhSubtreeInfoData",BT_ARRAY_CODE,(void*)&m_SubtreeHeaders[0]);
+	}
+	return btQuantizedBvhDataName;
+}
+
+
 
 
 
 
 
 

+ 117 - 9
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.h

@@ -13,8 +13,10 @@ 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 QUANTIZED_BVH_H
-#define QUANTIZED_BVH_H
+#ifndef BT_QUANTIZED_BVH_H
+#define BT_QUANTIZED_BVH_H
+
+class btSerializer;
 
 
 //#define DEBUG_CHECK_DEQUANTIZATION 1
 //#define DEBUG_CHECK_DEQUANTIZATION 1
 #ifdef DEBUG_CHECK_DEQUANTIZATION
 #ifdef DEBUG_CHECK_DEQUANTIZATION
@@ -29,6 +31,17 @@ subject to the following restrictions:
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
 
 
+#ifdef BT_USE_DOUBLE_PRECISION
+#define btQuantizedBvhData btQuantizedBvhDoubleData
+#define btOptimizedBvhNodeData btOptimizedBvhNodeDoubleData
+#define btQuantizedBvhDataName "btQuantizedBvhDoubleData"
+#else
+#define btQuantizedBvhData btQuantizedBvhFloatData
+#define btOptimizedBvhNodeData btOptimizedBvhNodeFloatData
+#define btQuantizedBvhDataName "btQuantizedBvhFloatData"
+#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
 
 
@@ -65,8 +78,10 @@ ATTRIBUTE_ALIGNED16	(struct) btQuantizedBvhNode
 	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);
 		// 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&~((~0)<<(31-MAX_NUM_PARTS_IN_BITS)));
+		return (m_escapeIndexOrTriangleIndex&~(y));
 	}
 	}
 	int	getPartId() const
 	int	getPartId() const
 	{
 	{
@@ -94,9 +109,9 @@ ATTRIBUTE_ALIGNED16 (struct) btOptimizedBvhNode
 	//for child nodes
 	//for child nodes
 	int	m_subPart;
 	int	m_subPart;
 	int	m_triangleIndex;
 	int	m_triangleIndex;
-	int	m_padding[5];//bad, due to alignment
-
 
 
+//pad the size to 64 bytes
+	char	m_padding[20];
 };
 };
 
 
 
 
@@ -190,7 +205,7 @@ protected:
 	BvhSubtreeInfoArray		m_SubtreeHeaders;
 	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
-	int m_subtreeHeaderCount;
+	mutable int m_subtreeHeaderCount;
 
 
 	
 	
 
 
@@ -443,17 +458,32 @@ public:
 		return m_SubtreeHeaders;
 		return m_SubtreeHeaders;
 	}
 	}
 
 
+////////////////////////////////////////////////////////////////////
 
 
 	/////Calculate space needed to store BVH for serialization
 	/////Calculate space needed to store BVH for serialization
-	unsigned calculateSerializeBufferSize();
+	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);
+	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;
+
+	///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	void deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData);
+
+
+////////////////////////////////////////////////////////////////////
 
 
 	SIMD_FORCE_INLINE bool isQuantized()
 	SIMD_FORCE_INLINE bool isQuantized()
 	{
 	{
@@ -470,4 +500,82 @@ private:
 ;
 ;
 
 
 
 
-#endif //QUANTIZED_BVH_H
+struct	btBvhSubtreeInfoData
+{
+	int			m_rootNodeIndex;
+	int			m_subtreeSize;
+	unsigned short m_quantizedAabbMin[3];
+	unsigned short m_quantizedAabbMax[3];
+};
+
+struct btOptimizedBvhNodeFloatData
+{
+	btVector3FloatData	m_aabbMinOrg;
+	btVector3FloatData	m_aabbMaxOrg;
+	int	m_escapeIndex;
+	int	m_subPart;
+	int	m_triangleIndex;
+	char m_pad[4];
+};
+
+struct btOptimizedBvhNodeDoubleData
+{
+	btVector3DoubleData	m_aabbMinOrg;
+	btVector3DoubleData	m_aabbMaxOrg;
+	int	m_escapeIndex;
+	int	m_subPart;
+	int	m_triangleIndex;
+	char	m_pad[4];
+};
+
+
+struct btQuantizedBvhNodeData
+{
+	unsigned short m_quantizedAabbMin[3];
+	unsigned short m_quantizedAabbMax[3];
+	int	m_escapeIndexOrTriangleIndex;
+};
+
+struct	btQuantizedBvhFloatData
+{
+	btVector3FloatData			m_bvhAabbMin;
+	btVector3FloatData			m_bvhAabbMax;
+	btVector3FloatData			m_bvhQuantization;
+	int					m_curNodeIndex;
+	int					m_useQuantization;
+	int					m_numContiguousLeafNodes;
+	int					m_numQuantizedContiguousNodes;
+	btOptimizedBvhNodeFloatData	*m_contiguousNodesPtr;
+	btQuantizedBvhNodeData		*m_quantizedContiguousNodesPtr;
+	btBvhSubtreeInfoData	*m_subTreeInfoPtr;
+	int					m_traversalMode;
+	int					m_numSubtreeHeaders;
+	
+};
+
+struct	btQuantizedBvhDoubleData
+{
+	btVector3DoubleData			m_bvhAabbMin;
+	btVector3DoubleData			m_bvhAabbMax;
+	btVector3DoubleData			m_bvhQuantization;
+	int							m_curNodeIndex;
+	int							m_useQuantization;
+	int							m_numContiguousLeafNodes;
+	int							m_numQuantizedContiguousNodes;
+	btOptimizedBvhNodeDoubleData	*m_contiguousNodesPtr;
+	btQuantizedBvhNodeData			*m_quantizedContiguousNodesPtr;
+
+	int							m_traversalMode;
+	int							m_numSubtreeHeaders;
+	btBvhSubtreeInfoData		*m_subTreeInfoPtr;
+};
+
+
+SIMD_FORCE_INLINE	int	btQuantizedBvh::calculateSerializeBufferSizeNew() const
+{
+	return sizeof(btQuantizedBvhData);
+}
+
+
+
+#endif //BT_QUANTIZED_BVH_H

+ 19 - 0
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp

@@ -20,6 +20,8 @@ subject to the following restrictions:
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btMatrix3x3.h"
 #include "LinearMath/btMatrix3x3.h"
+#include "LinearMath/btAabbUtil2.h"
+
 #include <new>
 #include <new>
 
 
 extern int gOverlappingPairs;
 extern int gOverlappingPairs;
@@ -166,6 +168,23 @@ void	btSimpleBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo
 }
 }
 
 
 
 
+void	btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback)
+{
+	for (int i=0; i <= m_LastHandleIndex; i++)
+	{
+		btSimpleBroadphaseProxy* proxy = &m_pHandles[i];
+		if(!proxy->m_clientObject)
+		{
+			continue;
+		}
+		if (TestAabbAgainstAabb2(aabbMin,aabbMax,proxy->m_aabbMin,proxy->m_aabbMax))
+		{
+			callback.process(proxy);
+		}
+	}
+}
+
+
 
 
 	
 	
 
 

+ 4 - 3
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h

@@ -13,8 +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 SIMPLE_BROADPHASE_H
-#define SIMPLE_BROADPHASE_H
+#ifndef BT_SIMPLE_BROADPHASE_H
+#define BT_SIMPLE_BROADPHASE_H
 
 
 
 
 #include "btOverlappingPairCache.h"
 #include "btOverlappingPairCache.h"
@@ -136,6 +136,7 @@ public:
 	virtual void	getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const;
 	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	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()
 	{
 	{
@@ -166,5 +167,5 @@ public:
 
 
 
 
 
 
-#endif //SIMPLE_BROADPHASE_H
+#endif //BT_SIMPLE_BROADPHASE_H
 
 

+ 43 - 22
Engine/lib/bullet/src/BulletCollision/CMakeLists.txt

@@ -1,4 +1,4 @@
-INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src } )
+INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src  )
 
 
 SET(BulletCollision_SRCS
 SET(BulletCollision_SRCS
 	BroadphaseCollision/btAxisSweep3.cpp
 	BroadphaseCollision/btAxisSweep3.cpp
@@ -18,7 +18,9 @@ SET(BulletCollision_SRCS
 	CollisionDispatch/btCollisionDispatcher.cpp
 	CollisionDispatch/btCollisionDispatcher.cpp
 	CollisionDispatch/btCollisionObject.cpp
 	CollisionDispatch/btCollisionObject.cpp
 	CollisionDispatch/btCollisionWorld.cpp
 	CollisionDispatch/btCollisionWorld.cpp
+	CollisionDispatch/btCollisionWorldImporter.cpp
 	CollisionDispatch/btCompoundCollisionAlgorithm.cpp
 	CollisionDispatch/btCompoundCollisionAlgorithm.cpp
+	CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp
 	CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
 	CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
 	CollisionDispatch/btConvexConvexAlgorithm.cpp
 	CollisionDispatch/btConvexConvexAlgorithm.cpp
 	CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
 	CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
@@ -26,6 +28,9 @@ SET(BulletCollision_SRCS
 	CollisionDispatch/btDefaultCollisionConfiguration.cpp
 	CollisionDispatch/btDefaultCollisionConfiguration.cpp
 	CollisionDispatch/btEmptyCollisionAlgorithm.cpp
 	CollisionDispatch/btEmptyCollisionAlgorithm.cpp
 	CollisionDispatch/btGhostObject.cpp
 	CollisionDispatch/btGhostObject.cpp
+	CollisionDispatch/btHashedSimplePairCache.cpp
+	CollisionDispatch/btInternalEdgeUtility.cpp
+	CollisionDispatch/btInternalEdgeUtility.h
 	CollisionDispatch/btManifoldResult.cpp
 	CollisionDispatch/btManifoldResult.cpp
 	CollisionDispatch/btSimulationIslandManager.cpp
 	CollisionDispatch/btSimulationIslandManager.cpp
 	CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
 	CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp
@@ -44,6 +49,7 @@ SET(BulletCollision_SRCS
 	CollisionShapes/btConvexHullShape.cpp
 	CollisionShapes/btConvexHullShape.cpp
 	CollisionShapes/btConvexInternalShape.cpp
 	CollisionShapes/btConvexInternalShape.cpp
 	CollisionShapes/btConvexPointCloudShape.cpp
 	CollisionShapes/btConvexPointCloudShape.cpp
+	CollisionShapes/btConvexPolyhedron.cpp
 	CollisionShapes/btConvexShape.cpp
 	CollisionShapes/btConvexShape.cpp
 	CollisionShapes/btConvex2dShape.cpp
 	CollisionShapes/btConvex2dShape.cpp
 	CollisionShapes/btConvexTriangleMeshShape.cpp
 	CollisionShapes/btConvexTriangleMeshShape.cpp
@@ -90,6 +96,7 @@ SET(BulletCollision_SRCS
 	NarrowPhaseCollision/btRaycastCallback.cpp
 	NarrowPhaseCollision/btRaycastCallback.cpp
 	NarrowPhaseCollision/btSubSimplexConvexCast.cpp
 	NarrowPhaseCollision/btSubSimplexConvexCast.cpp
 	NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
 	NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
+	NarrowPhaseCollision/btPolyhedralContactClipping.cpp
 )
 )
 
 
 SET(Root_HDRS
 SET(Root_HDRS
@@ -118,8 +125,11 @@ SET(CollisionDispatch_HDRS
 	CollisionDispatch/btCollisionCreateFunc.h
 	CollisionDispatch/btCollisionCreateFunc.h
 	CollisionDispatch/btCollisionDispatcher.h
 	CollisionDispatch/btCollisionDispatcher.h
 	CollisionDispatch/btCollisionObject.h
 	CollisionDispatch/btCollisionObject.h
+	CollisionDispatch/btCollisionObjectWrapper.h
 	CollisionDispatch/btCollisionWorld.h
 	CollisionDispatch/btCollisionWorld.h
+	CollisionDispatch/btCollisionWorldImporter.h
 	CollisionDispatch/btCompoundCollisionAlgorithm.h
 	CollisionDispatch/btCompoundCollisionAlgorithm.h
+	CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h
 	CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
 	CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
 	CollisionDispatch/btConvexConvexAlgorithm.h
 	CollisionDispatch/btConvexConvexAlgorithm.h
 	CollisionDispatch/btConvex2dConvex2dAlgorithm.h
 	CollisionDispatch/btConvex2dConvex2dAlgorithm.h
@@ -127,6 +137,7 @@ SET(CollisionDispatch_HDRS
 	CollisionDispatch/btDefaultCollisionConfiguration.h
 	CollisionDispatch/btDefaultCollisionConfiguration.h
 	CollisionDispatch/btEmptyCollisionAlgorithm.h
 	CollisionDispatch/btEmptyCollisionAlgorithm.h
 	CollisionDispatch/btGhostObject.h
 	CollisionDispatch/btGhostObject.h
+	CollisionDispatch/btHashedSimplePairCache.h
 	CollisionDispatch/btManifoldResult.h
 	CollisionDispatch/btManifoldResult.h
 	CollisionDispatch/btSimulationIslandManager.h
 	CollisionDispatch/btSimulationIslandManager.h
 	CollisionDispatch/btSphereBoxCollisionAlgorithm.h
 	CollisionDispatch/btSphereBoxCollisionAlgorithm.h
@@ -148,6 +159,7 @@ SET(CollisionShapes_HDRS
 	CollisionShapes/btConvexHullShape.h
 	CollisionShapes/btConvexHullShape.h
 	CollisionShapes/btConvexInternalShape.h
 	CollisionShapes/btConvexInternalShape.h
 	CollisionShapes/btConvexPointCloudShape.h
 	CollisionShapes/btConvexPointCloudShape.h
+	CollisionShapes/btConvexPolyhedron.h
 	CollisionShapes/btConvexShape.h
 	CollisionShapes/btConvexShape.h
 	CollisionShapes/btConvex2dShape.h
 	CollisionShapes/btConvex2dShape.h
 	CollisionShapes/btConvexTriangleMeshShape.h
 	CollisionShapes/btConvexTriangleMeshShape.h
@@ -170,6 +182,7 @@ SET(CollisionShapes_HDRS
 	CollisionShapes/btTriangleCallback.h
 	CollisionShapes/btTriangleCallback.h
 	CollisionShapes/btTriangleIndexVertexArray.h
 	CollisionShapes/btTriangleIndexVertexArray.h
 	CollisionShapes/btTriangleIndexVertexMaterialArray.h
 	CollisionShapes/btTriangleIndexVertexMaterialArray.h
+	CollisionShapes/btTriangleInfoMap.h
 	CollisionShapes/btTriangleMesh.h
 	CollisionShapes/btTriangleMesh.h
 	CollisionShapes/btTriangleMeshShape.h
 	CollisionShapes/btTriangleMeshShape.h
 	CollisionShapes/btTriangleShape.h
 	CollisionShapes/btTriangleShape.h
@@ -221,6 +234,7 @@ SET(NarrowPhaseCollision_HDRS
 	NarrowPhaseCollision/btSimplexSolverInterface.h
 	NarrowPhaseCollision/btSimplexSolverInterface.h
 	NarrowPhaseCollision/btSubSimplexConvexCast.h
 	NarrowPhaseCollision/btSubSimplexConvexCast.h
 	NarrowPhaseCollision/btVoronoiSimplexSolver.h
 	NarrowPhaseCollision/btVoronoiSimplexSolver.h
+	NarrowPhaseCollision/btPolyhedralContactClipping.h
 )
 )
 
 
 SET(BulletCollision_HDRS
 SET(BulletCollision_HDRS
@@ -241,27 +255,34 @@ IF (BUILD_SHARED_LIBS)
 ENDIF (BUILD_SHARED_LIBS)
 ENDIF (BUILD_SHARED_LIBS)
 
 
 
 
+IF (INSTALL_LIBS)
+	IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
+		#INSTALL of other files requires CMake 2.6
+		IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
+			IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
+				INSTALL(TARGETS BulletCollision DESTINATION .)
+			ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
+				INSTALL(TARGETS BulletCollision RUNTIME DESTINATION bin
+								LIBRARY DESTINATION lib${LIB_SUFFIX}
+								ARCHIVE DESTINATION lib${LIB_SUFFIX})
+				INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE PATTERN "CMakeFiles" EXCLUDE)
+				INSTALL(FILES ../btBulletCollisionCommon.h
+DESTINATION ${INCLUDE_INSTALL_DIR}/BulletCollision)
+			ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
+		ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
 
 
+		IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
+			SET_TARGET_PROPERTIES(BulletCollision PROPERTIES FRAMEWORK true)
 
 
-#INSTALL of other files requires CMake 2.6
-IF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
-	IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
-		INSTALL(TARGETS BulletCollision DESTINATION .)
-	ELSE (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
-	INSTALL(TARGETS BulletCollision DESTINATION lib)
-        INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.h")
-	ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
-ENDIF (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} GREATER 2.5)
+			SET_TARGET_PROPERTIES(BulletCollision PROPERTIES PUBLIC_HEADER "${Root_HDRS}")
+			# Have to list out sub-directories manually:
+			SET_PROPERTY(SOURCE ${BroadphaseCollision_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/BroadphaseCollision)
+			SET_PROPERTY(SOURCE ${CollisionDispatch_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/CollisionDispatch)
+			SET_PROPERTY(SOURCE ${CollisionShapes_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/CollisionShapes)
+			SET_PROPERTY(SOURCE ${Gimpact_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/Gimpact)
+			SET_PROPERTY(SOURCE ${NarrowPhaseCollision_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/NarrowPhaseCollision)
 
 
-IF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
-	SET_TARGET_PROPERTIES(BulletCollision PROPERTIES FRAMEWORK true)
-
-	SET_TARGET_PROPERTIES(BulletCollision PROPERTIES PUBLIC_HEADER "${Root_HDRS}")
-	# Have to list out sub-directories manually:
-	SET_PROPERTY(SOURCE ${BroadphaseCollision_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/BroadphaseCollision)
-	SET_PROPERTY(SOURCE ${CollisionDispatch_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/CollisionDispatch)
-	SET_PROPERTY(SOURCE ${CollisionShapes_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/CollisionShapes)
-	SET_PROPERTY(SOURCE ${Gimpact_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/Gimpact)
-	SET_PROPERTY(SOURCE ${NarrowPhaseCollision_HDRS} PROPERTY MACOSX_PACKAGE_LOCATION Headers/NarrowPhaseCollision)
-
-ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
+		ENDIF (APPLE AND BUILD_SHARED_LIBS AND FRAMEWORK)
+	ENDIF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
+ENDIF (INSTALL_LIBS)

+ 27 - 36
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp

@@ -57,8 +57,6 @@ void	SphereTriangleDetector::getClosestPoints(const ClosestPointInput& input,Res
 
 
 }
 }
 
 
-#define MAX_OVERLAP btScalar(0.)
-
 
 
 
 
 // See also geometrictools.com
 // See also geometrictools.com
@@ -93,48 +91,39 @@ bool SphereTriangleDetector::facecontains(const btVector3 &p,const btVector3* ve
 	return pointInTriangle(vertices, lnormal, &lp);
 	return pointInTriangle(vertices, lnormal, &lp);
 }
 }
 
 
-///combined discrete/continuous sphere-triangle
 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);
-	const btVector3& c = sphereCenter;
-	btScalar r = m_sphere->getRadius();
-
-	btVector3 delta (0,0,0);
+	
+	btScalar radius = m_sphere->getRadius();
+	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]);
-	normal.normalize();
-	btVector3 p1ToCentre = c - vertices[0];
+	normal.safeNormalize();
+	btVector3 p1ToCentre = sphereCenter - vertices[0];
 	btScalar distanceFromPlane = p1ToCentre.dot(normal);
 	btScalar distanceFromPlane = p1ToCentre.dot(normal);
 
 
 	if (distanceFromPlane < btScalar(0.))
 	if (distanceFromPlane < btScalar(0.))
 	{
 	{
 		//triangle facing the other way
 		//triangle facing the other way
-	
 		distanceFromPlane *= btScalar(-1.);
 		distanceFromPlane *= btScalar(-1.);
 		normal *= btScalar(-1.);
 		normal *= btScalar(-1.);
 	}
 	}
 
 
-	btScalar contactMargin = contactBreakingThreshold;
-	bool isInsideContactPlane = distanceFromPlane < r + contactMargin;
-	bool isInsideShellPlane = distanceFromPlane < r;
+	bool isInsideContactPlane = distanceFromPlane < radiusWithThreshold;
 	
 	
-	btScalar deltaDotNormal = delta.dot(normal);
-	if (!isInsideShellPlane && deltaDotNormal >= btScalar(0.0))
-		return false;
-
 	// Check for contact / intersection
 	// Check for contact / intersection
 	bool hasContact = false;
 	bool hasContact = false;
 	btVector3 contactPoint;
 	btVector3 contactPoint;
 	if (isInsideContactPlane) {
 	if (isInsideContactPlane) {
-		if (facecontains(c,vertices,normal)) {
+		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 = c - 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 = (r + contactMargin) * (r + contactMargin);
+			btScalar contactCapsuleRadiusSqr = radiusWithThreshold*radiusWithThreshold;
 			btVector3 nearestOnEdge;
 			btVector3 nearestOnEdge;
 			for (int i = 0; i < m_triangle->getNumEdges(); i++) {
 			for (int i = 0; i < m_triangle->getNumEdges(); i++) {
 				
 				
@@ -143,7 +132,7 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
 				
 				
 				m_triangle->getEdge(i,pa,pb);
 				m_triangle->getEdge(i,pa,pb);
 
 
-				btScalar distanceSqr = SegmentSqrDistance(pa,pb,c, nearestOnEdge);
+				btScalar distanceSqr = SegmentSqrDistance(pa,pb,sphereCenter, nearestOnEdge);
 				if (distanceSqr < contactCapsuleRadiusSqr) {
 				if (distanceSqr < contactCapsuleRadiusSqr) {
 					// Yep, we're inside a capsule
 					// Yep, we're inside a capsule
 					hasContact = true;
 					hasContact = true;
@@ -155,24 +144,26 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
 	}
 	}
 
 
 	if (hasContact) {
 	if (hasContact) {
-		btVector3 contactToCentre = c - contactPoint;
+		btVector3 contactToCentre = sphereCenter - contactPoint;
 		btScalar distanceSqr = contactToCentre.length2();
 		btScalar distanceSqr = contactToCentre.length2();
-		if (distanceSqr < (r - MAX_OVERLAP)*(r - MAX_OVERLAP)) {
-			btScalar distance = btSqrt(distanceSqr);
-			resultNormal = contactToCentre;
-			resultNormal.normalize();
-			point = contactPoint;
-			depth = -(r-distance);
+
+		if (distanceSqr < radiusWithThreshold*radiusWithThreshold)
+		{
+			if (distanceSqr>SIMD_EPSILON)
+			{
+				btScalar distance = btSqrt(distanceSqr);
+				resultNormal = contactToCentre;
+				resultNormal.normalize();
+				point = contactPoint;
+				depth = -(radius-distance);
+			} else
+			{
+				resultNormal = normal;
+				point = contactPoint;
+				depth = -radius;
+			}
 			return true;
 			return true;
 		}
 		}
-
-		if (delta.dot(contactToCentre) >= btScalar(0.0)) 
-			return false;
-		
-		// Moving towards the contact point -> collision
-		point = contactPoint;
-		timeOfImpact = btScalar(0.0);
-		return true;
 	}
 	}
 	
 	
 	return false;
 	return false;

+ 6 - 4
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.h

@@ -13,8 +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 SPHERE_TRIANGLE_DETECTOR_H
-#define SPHERE_TRIANGLE_DETECTOR_H
+#ifndef BT_SPHERE_TRIANGLE_DETECTOR_H
+#define BT_SPHERE_TRIANGLE_DETECTOR_H
 
 
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 
 
@@ -34,9 +34,11 @@ struct SphereTriangleDetector : public btDiscreteCollisionDetectorInterface
 
 
 	virtual ~SphereTriangleDetector() {};
 	virtual ~SphereTriangleDetector() {};
 
 
+	bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar	contactBreakingThreshold);
+
 private:
 private:
 
 
-	bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar	contactBreakingThreshold);
+	
 	bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p );
 	bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p );
 	bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal);
 	bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal);
 
 
@@ -45,5 +47,5 @@ private:
 	btScalar	m_contactBreakingThreshold;
 	btScalar	m_contactBreakingThreshold;
 	
 	
 };
 };
-#endif //SPHERE_TRIANGLE_DETECTOR_H
+#endif //BT_SPHERE_TRIANGLE_DETECTOR_H
 
 

+ 1 - 1
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.cpp

@@ -24,7 +24,7 @@ btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisio
 //m_colObj1(0)
 //m_colObj1(0)
 {
 {
 }
 }
-btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* colObj0,btCollisionObject* colObj1)
+btActivatingCollisionAlgorithm::btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* )
 :btCollisionAlgorithm(ci)
 :btCollisionAlgorithm(ci)
 //,
 //,
 //m_colObj0(0),
 //m_colObj0(0),

+ 1 - 1
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h

@@ -28,7 +28,7 @@ public:
 
 
 	btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci);
 	btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci);
 
 
-	btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* colObj0,btCollisionObject* colObj1);
+	btActivatingCollisionAlgorithm (const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 
 	virtual ~btActivatingCollisionAlgorithm();
 	virtual ~btActivatingCollisionAlgorithm();
 
 

+ 18 - 34
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp

@@ -22,17 +22,18 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btBoxBoxDetector.h"
 #include "BulletCollision/CollisionDispatch/btBoxBoxDetector.h"
 #include "BulletCollision/CollisionShapes/btBox2dShape.h"
 #include "BulletCollision/CollisionShapes/btBox2dShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
 #define USE_PERSISTENT_CONTACTS 1
 #define USE_PERSISTENT_CONTACTS 1
 
 
-btBox2dBox2dCollisionAlgorithm::btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* obj0,btCollisionObject* obj1)
-: btActivatingCollisionAlgorithm(ci,obj0,obj1),
+btBox2dBox2dCollisionAlgorithm::btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* obj0Wrap,const btCollisionObjectWrapper* obj1Wrap)
+: btActivatingCollisionAlgorithm(ci,obj0Wrap,obj1Wrap),
 m_ownManifold(false),
 m_ownManifold(false),
 m_manifoldPtr(mf)
 m_manifoldPtr(mf)
 {
 {
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0,obj1))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0Wrap->getCollisionObject(),obj1Wrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(obj0,obj1);
+		m_manifoldPtr = m_dispatcher->getNewManifold(obj0Wrap->getCollisionObject(),obj1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -52,19 +53,18 @@ btBox2dBox2dCollisionAlgorithm::~btBox2dBox2dCollisionAlgorithm()
 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 (btCollisionObject* body0,btCollisionObject* body1,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;
 
 
-	btCollisionObject*	col0 = body0;
-	btCollisionObject*	col1 = body1;
-	btBox2dShape* box0 = (btBox2dShape*)col0->getCollisionShape();
-	btBox2dShape* box1 = (btBox2dShape*)col1->getCollisionShape();
+	
+	const btBox2dShape* box0 = (const btBox2dShape*)body0Wrap->getCollisionShape();
+	const btBox2dShape* box1 = (const btBox2dShape*)body1Wrap->getCollisionShape();
 
 
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
 
 
-	b2CollidePolygons(resultOut,box0,col0->getWorldTransform(),box1,col1->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)
@@ -135,14 +135,13 @@ static int ClipSegmentToLine(ClipVertex vOut[2], ClipVertex vIn[2],
 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)
 {
 {
-	int count1 = poly1->getVertexCount();
 	const btVector3* vertices1 = poly1->getVertices();
 	const btVector3* vertices1 = poly1->getVertices();
 	const btVector3* normals1 = poly1->getNormals();
 	const btVector3* normals1 = poly1->getNormals();
 
 
 	int count2 = poly2->getVertexCount();
 	int count2 = poly2->getVertexCount();
 	const btVector3* vertices2 = poly2->getVertices();
 	const btVector3* vertices2 = poly2->getVertices();
 
 
-	btAssert(0 <= edge1 && edge1 < count1);
+	btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
 
 
 	// Convert normal from poly1's frame into poly2's frame.
 	// Convert normal from poly1's frame into poly2's frame.
 	btVector3 normal1World = b2Mul(xf1.getBasis(), normals1[edge1]);
 	btVector3 normal1World = b2Mul(xf1.getBasis(), normals1[edge1]);
@@ -152,15 +151,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;
 
 
-	for (int i = 0; i < count2; ++i)
-	{
-		btScalar dot = b2Dot(vertices2[i], normal1);
-		if (dot < minDot)
-		{
-			minDot = dot;
-			index = i;
-		}
-	}
+    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]);
@@ -182,16 +174,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 = -BT_LARGE_FLOAT;
-	for (int i = 0; i < count1; ++i)
-	{
-		btScalar dot = b2Dot(normals1[i], dLocal1);
-		if (dot > maxDot)
-		{
-			maxDot = dot;
-			edge = i;
-		}
-	}
+    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);
@@ -271,14 +256,13 @@ static void FindIncidentEdge(ClipVertex c[2],
 							 const btBox2dShape* poly1, const btTransform& xf1, int edge1,
 							 const btBox2dShape* poly1, const btTransform& xf1, int edge1,
 							 const btBox2dShape* poly2, const btTransform& xf2)
 							 const btBox2dShape* poly2, const btTransform& xf2)
 {
 {
-	int count1 = poly1->getVertexCount();
 	const btVector3* normals1 = poly1->getNormals();
 	const btVector3* normals1 = poly1->getNormals();
 
 
 	int count2 = poly2->getVertexCount();
 	int count2 = poly2->getVertexCount();
 	const btVector3* vertices2 = poly2->getVertices();
 	const btVector3* vertices2 = poly2->getVertices();
 	const btVector3* normals2 = poly2->getNormals();
 	const btVector3* normals2 = poly2->getNormals();
 
 
-	btAssert(0 <= edge1 && edge1 < count1);
+	btAssert(0 <= edge1 && edge1 < poly1->getVertexCount());
 
 
 	// Get the normal of the reference edge in poly2's frame.
 	// Get the normal of the reference edge in poly2's frame.
 	btVector3 normal1 = b2MulT(xf2.getBasis(), b2Mul(xf1.getBasis(), normals1[edge1]));
 	btVector3 normal1 = b2MulT(xf2.getBasis(), b2Mul(xf1.getBasis(), normals1[edge1]));
@@ -370,7 +354,7 @@ void b2CollidePolygons(btManifoldResult* manifold,
 	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);

+ 7 - 7
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h

@@ -13,8 +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 BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
-#define BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
+#ifndef BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
+#define BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
 
 
 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -33,11 +33,11 @@ public:
 	btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	btBox2dBox2dCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 		: btActivatingCollisionAlgorithm(ci) {}
 		: btActivatingCollisionAlgorithm(ci) {}
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,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,btCollisionObject* body0,btCollisionObject* body1);
+	btBox2dBox2dCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 
 	virtual ~btBox2dBox2dCollisionAlgorithm();
 	virtual ~btBox2dBox2dCollisionAlgorithm();
 
 
@@ -52,15 +52,15 @@ public:
 
 
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1);
+			return new(ptr) btBox2dBox2dCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
+#endif //BT_BOX_2D_BOX_2D__COLLISION_ALGORITHM_H
 
 

+ 11 - 12
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp

@@ -18,17 +18,17 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btBoxShape.h"
 #include "BulletCollision/CollisionShapes/btBoxShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "btBoxBoxDetector.h"
 #include "btBoxBoxDetector.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 #define USE_PERSISTENT_CONTACTS 1
 #define USE_PERSISTENT_CONTACTS 1
 
 
-btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* obj0,btCollisionObject* obj1)
-: btActivatingCollisionAlgorithm(ci,obj0,obj1),
+btBoxBoxCollisionAlgorithm::btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_ownManifold(false),
 m_ownManifold(false),
 m_manifoldPtr(mf)
 m_manifoldPtr(mf)
 {
 {
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(obj0,obj1))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(obj0,obj1);
+		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -42,15 +42,14 @@ btBoxBoxCollisionAlgorithm::~btBoxBoxCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btBoxBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,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;
 
 
-	btCollisionObject*	col0 = body0;
-	btCollisionObject*	col1 = body1;
-	btBoxShape* box0 = (btBoxShape*)col0->getCollisionShape();
-	btBoxShape* box1 = (btBoxShape*)col1->getCollisionShape();
+	
+	const btBoxShape* box0 = (btBoxShape*)body0Wrap->getCollisionShape();
+	const btBoxShape* box1 = (btBoxShape*)body1Wrap->getCollisionShape();
 
 
 
 
 
 
@@ -62,8 +61,8 @@ void btBoxBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCo
 
 
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
 	input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
 	input.m_maximumDistanceSquared = BT_LARGE_FLOAT;
-	input.m_transformA = body0->getWorldTransform();
-	input.m_transformB = body1->getWorldTransform();
+	input.m_transformA = body0Wrap->getWorldTransform();
+	input.m_transformB = body1Wrap->getWorldTransform();
 
 
 	btBoxBoxDetector detector(box0,box1);
 	btBoxBoxDetector detector(box0,box1);
 	detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 	detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);

+ 7 - 7
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h

@@ -13,8 +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 BOX_BOX__COLLISION_ALGORITHM_H
-#define BOX_BOX__COLLISION_ALGORITHM_H
+#ifndef BT_BOX_BOX__COLLISION_ALGORITHM_H
+#define BT_BOX_BOX__COLLISION_ALGORITHM_H
 
 
 #include "btActivatingCollisionAlgorithm.h"
 #include "btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -33,11 +33,11 @@ public:
 	btBoxBoxCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 	btBoxBoxCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci)
 		: btActivatingCollisionAlgorithm(ci) {}
 		: btActivatingCollisionAlgorithm(ci) {}
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,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,btCollisionObject* body0,btCollisionObject* body1);
+	btBoxBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 
 	virtual ~btBoxBoxCollisionAlgorithm();
 	virtual ~btBoxBoxCollisionAlgorithm();
 
 
@@ -52,15 +52,15 @@ public:
 
 
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1);
+			return new(ptr) btBoxBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap);
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //BOX_BOX__COLLISION_ALGORITHM_H
+#endif //BT_BOX_BOX__COLLISION_ALGORITHM_H
 
 

+ 42 - 13
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp

@@ -1,4 +1,3 @@
-
 /*
 /*
  * Box-Box collision detection re-distributed under the ZLib license with permission from Russell L. Smith
  * Box-Box collision detection re-distributed under the ZLib license with permission from Russell L. Smith
  * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.
  * Original version is from Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.
@@ -25,7 +24,7 @@ subject to the following restrictions:
 #include <float.h>
 #include <float.h>
 #include <string.h>
 #include <string.h>
 
 
-btBoxBoxDetector::btBoxBoxDetector(btBoxShape* box1,btBoxShape* box2)
+btBoxBoxDetector::btBoxBoxDetector(const btBoxShape* box1,const btBoxShape* box2)
 : m_box1(box1),
 : m_box1(box1),
 m_box2(box2)
 m_box2(box2)
 {
 {
@@ -333,9 +332,9 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
 #undef TST
 #undef TST
 #define TST(expr1,expr2,n1,n2,n3,cc) \
 #define TST(expr1,expr2,n1,n2,n3,cc) \
   s2 = btFabs(expr1) - (expr2); \
   s2 = btFabs(expr1) - (expr2); \
-  if (s2 > 0) return 0; \
+  if (s2 > SIMD_EPSILON) return 0; \
   l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \
   l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \
-  if (l > 0) { \
+  if (l > SIMD_EPSILON) { \
     s2 /= l; \
     s2 /= l; \
     if (s2*fudge_factor > s) { \
     if (s2*fudge_factor > s) { \
       s = s2; \
       s = s2; \
@@ -346,6 +345,20 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
     } \
     } \
   }
   }
 
 
+  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)
   // 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]*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]*R22-pp[1]*R32,(A[1]*Q32+A[2]*Q22+B[0]*Q13+B[2]*Q11),0,-R32,R22,8);
@@ -424,6 +437,7 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
 		output.addContactPoint(-normal,pointInWorld,-*depth);
 		output.addContactPoint(-normal,pointInWorld,-*depth);
 #else
 #else
 		output.addContactPoint(-normal,pb,-*depth);
 		output.addContactPoint(-normal,pb,-*depth);
+
 #endif //
 #endif //
 		*return_code = code;
 		*return_code = code;
 	}
 	}
@@ -593,21 +607,30 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
   if (maxc < 1) maxc = 1;
   if (maxc < 1) maxc = 1;
 
 
   if (cnum <= maxc) {
   if (cnum <= maxc) {
-    // we have less contacts than we need, so we use them all
-    for (j=0; j < cnum; j++) {
-
-		//AddContactPoint...
-
-		//dContactGeom *con = CONTACT(contact,skip*j);
-      //for (i=0; i<3; i++) con->pos[i] = point[j*3+i] + pa[i];
-      //con->depth = dep[j];
 
 
+	  if (code<4) 
+	  {
+    // we have less contacts than we need, so we use them all
+    for (j=0; j < cnum; j++) 
+	{
 		btVector3 pointInWorld;
 		btVector3 pointInWorld;
 		for (i=0; i<3; i++) 
 		for (i=0; i<3; i++) 
 			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 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];
+			output.addContactPoint(-normal,pointInWorld,-dep[j]);
+		}
+	  }
   }
   }
   else {
   else {
     // we have more contacts than are wanted, some of them must be culled.
     // we have more contacts than are wanted, some of them must be culled.
@@ -632,7 +655,13 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1,
 		btVector3 posInWorld;
 		btVector3 posInWorld;
 		for (i=0; i<3; i++) 
 		for (i=0; i<3; i++) 
 			posInWorld[i] = point[iret[j]*3+i] + pa[i];
 			posInWorld[i] = point[iret[j]*3+i] + pa[i];
-		output.addContactPoint(-normal,posInWorld,-dep[iret[j]]);
+		if (code<4) 
+	   {
+			output.addContactPoint(-normal,posInWorld,-dep[iret[j]]);
+		} else
+		{
+			output.addContactPoint(-normal,posInWorld-normal*dep[iret[j]],-dep[iret[j]]);
+		}
     }
     }
     cnum = maxc;
     cnum = maxc;
   }
   }

+ 5 - 5
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.h

@@ -16,8 +16,8 @@ subject to the following restrictions:
 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 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.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
-#ifndef BOX_BOX_DETECTOR_H
-#define BOX_BOX_DETECTOR_H
+#ifndef BT_BOX_BOX_DETECTOR_H
+#define BT_BOX_BOX_DETECTOR_H
 
 
 
 
 class btBoxShape;
 class btBoxShape;
@@ -28,12 +28,12 @@ class btBoxShape;
 /// 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
 {
 {
-	btBoxShape* m_box1;
-	btBoxShape* m_box2;
+	const btBoxShape* m_box1;
+	const btBoxShape* m_box2;
 
 
 public:
 public:
 
 
-	btBoxBoxDetector(btBoxShape* box1,btBoxShape* box2);
+	btBoxBoxDetector(const btBoxShape* box1,const btBoxShape* box2);
 
 
 	virtual ~btBoxBoxDetector() {};
 	virtual ~btBoxBoxDetector() {};
 
 

+ 4 - 2
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h

@@ -15,9 +15,9 @@ subject to the following restrictions:
 
 
 #ifndef BT_COLLISION_CONFIGURATION
 #ifndef BT_COLLISION_CONFIGURATION
 #define BT_COLLISION_CONFIGURATION
 #define BT_COLLISION_CONFIGURATION
+
 struct btCollisionAlgorithmCreateFunc;
 struct btCollisionAlgorithmCreateFunc;
 
 
-class btStackAlloc;
 class btPoolAllocator;
 class btPoolAllocator;
 
 
 ///btCollisionConfiguration allows to configure Bullet collision detection
 ///btCollisionConfiguration allows to configure Bullet collision detection
@@ -37,10 +37,12 @@ public:
 
 
 	virtual btPoolAllocator* getCollisionAlgorithmPool() = 0;
 	virtual btPoolAllocator* getCollisionAlgorithmPool() = 0;
 
 
-	virtual btStackAlloc*	getStackAllocator() = 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;
+
+
 };
 };
 
 
 #endif //BT_COLLISION_CONFIGURATION
 #endif //BT_COLLISION_CONFIGURATION

+ 7 - 7
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionCreateFunc.h

@@ -13,13 +13,13 @@ 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 COLLISION_CREATE_FUNC
-#define COLLISION_CREATE_FUNC
+#ifndef BT_COLLISION_CREATE_FUNC
+#define BT_COLLISION_CREATE_FUNC
 
 
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
 class btCollisionAlgorithm;
 class btCollisionAlgorithm;
 class btCollisionObject;
 class btCollisionObject;
-
+struct btCollisionObjectWrapper;
 struct btCollisionAlgorithmConstructionInfo;
 struct btCollisionAlgorithmConstructionInfo;
 
 
 ///Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm
 ///Used by the btCollisionDispatcher to register and create instances for btCollisionAlgorithm
@@ -33,13 +33,13 @@ struct btCollisionAlgorithmCreateFunc
 	}
 	}
 	virtual ~btCollisionAlgorithmCreateFunc(){};
 	virtual ~btCollisionAlgorithmCreateFunc(){};
 
 
-	virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& , btCollisionObject* body0,btCollisionObject* body1)
+	virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& , const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
 	{
 	{
 		
 		
-		(void)body0;
-		(void)body1;
+		(void)body0Wrap;
+		(void)body1Wrap;
 		return 0;
 		return 0;
 	}
 	}
 };
 };
-#endif //COLLISION_CREATE_FUNC
+#endif //BT_COLLISION_CREATE_FUNC
 
 

+ 65 - 41
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp

@@ -16,7 +16,7 @@ subject to the following restrictions:
 
 
 
 
 #include "btCollisionDispatcher.h"
 #include "btCollisionDispatcher.h"
-
+#include "LinearMath/btQuickprof.h"
 
 
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 
 
@@ -25,6 +25,7 @@ subject to the following restrictions:
 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
 #include "BulletCollision/BroadphaseCollision/btOverlappingPairCache.h"
 #include "LinearMath/btPoolAllocator.h"
 #include "LinearMath/btPoolAllocator.h"
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
 int gNumManifold = 0;
 int gNumManifold = 0;
 
 
@@ -34,9 +35,7 @@ int gNumManifold = 0;
 
 
 
 
 btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): 
 btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): 
-	m_count(0),
-	m_useIslands(true),
-	m_staticWarningReported(false),
+m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD),
 	m_collisionConfiguration(collisionConfiguration)
 	m_collisionConfiguration(collisionConfiguration)
 {
 {
 	int i;
 	int i;
@@ -51,8 +50,10 @@ btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisio
 	{
 	{
 		for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
 		for (int j=0;j<MAX_BROADPHASE_COLLISION_TYPES;j++)
 		{
 		{
-			m_doubleDispatch[i][j] = m_collisionConfiguration->getCollisionAlgorithmCreateFunc(i,j);
-			btAssert(m_doubleDispatch[i][j]);
+			m_doubleDispatchContactPoints[i][j] = m_collisionConfiguration->getCollisionAlgorithmCreateFunc(i,j);
+			btAssert(m_doubleDispatchContactPoints[i][j]);
+			m_doubleDispatchClosestPoints[i][j] = m_collisionConfiguration->getClosestPointsAlgorithmCreateFunc(i, j);
+
 		}
 		}
 	}
 	}
 	
 	
@@ -62,38 +63,47 @@ btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisio
 
 
 void btCollisionDispatcher::registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
 void btCollisionDispatcher::registerCollisionCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
 {
 {
-	m_doubleDispatch[proxyType0][proxyType1] = createFunc;
+	m_doubleDispatchContactPoints[proxyType0][proxyType1] = createFunc;
+}
+
+void btCollisionDispatcher::registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc)
+{
+	m_doubleDispatchClosestPoints[proxyType0][proxyType1] = createFunc;
 }
 }
 
 
 btCollisionDispatcher::~btCollisionDispatcher()
 btCollisionDispatcher::~btCollisionDispatcher()
 {
 {
 }
 }
 
 
-btPersistentManifold*	btCollisionDispatcher::getNewManifold(void* b0,void* b1) 
+btPersistentManifold*	btCollisionDispatcher::getNewManifold(const btCollisionObject* body0,const btCollisionObject* body1) 
 { 
 { 
 	gNumManifold++;
 	gNumManifold++;
 	
 	
 	//btAssert(gNumManifold < 65535);
 	//btAssert(gNumManifold < 65535);
 	
 	
 
 
-	btCollisionObject* body0 = (btCollisionObject*)b0;
-	btCollisionObject* body1 = (btCollisionObject*)b1;
 
 
-	//test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold'
-	//btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()));
-	btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold());
+	//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());
 	btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold());
 		
 		
-	void* mem = 0;
-	
-	if (m_persistentManifoldPoolAllocator->getFreeCount())
+ 	void* mem = m_persistentManifoldPoolAllocator->allocate( sizeof( btPersistentManifold ) );
+    if (NULL == mem)
 	{
 	{
-		mem = m_persistentManifoldPoolAllocator->allocate(sizeof(btPersistentManifold));
-	} else
-	{
-		mem = btAlignedAlloc(sizeof(btPersistentManifold),16);
-
+        //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);
 	btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0,contactBreakingThreshold,contactProcessingThreshold);
 	manifold->m_index1a = m_manifoldsPtr.size();
 	manifold->m_index1a = m_manifoldsPtr.size();
@@ -135,14 +145,23 @@ void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 
 
 	
 	
 
 
-btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold)
+
+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;
 	ci.m_manifold = sharedManifold;
 	ci.m_manifold = sharedManifold;
-	btCollisionAlgorithm* algo = m_doubleDispatch[body0->getCollisionShape()->getShapeType()][body1->getCollisionShape()->getShapeType()]->CreateCollisionAlgorithm(ci,body0,body1);
+	btCollisionAlgorithm* algo = 0;
+	if (algoType == BT_CONTACT_POINT_ALGORITHMS)
+	{
+		algo = m_doubleDispatchContactPoints[body0Wrap->getCollisionShape()->getShapeType()][body1Wrap->getCollisionShape()->getShapeType()]->CreateCollisionAlgorithm(ci, body0Wrap, body1Wrap);
+	}
+	else
+	{
+		algo = m_doubleDispatchClosestPoints[body0Wrap->getCollisionShape()->getShapeType()][body1Wrap->getCollisionShape()->getShapeType()]->CreateCollisionAlgorithm(ci, body0Wrap, body1Wrap);
+	}
 
 
 	return algo;
 	return algo;
 }
 }
@@ -150,7 +169,7 @@ btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(btCollisionObject* bo
 
 
 
 
 
 
-bool	btCollisionDispatcher::needsResponse(btCollisionObject* body0,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 = 
@@ -161,7 +180,7 @@ bool	btCollisionDispatcher::needsResponse(btCollisionObject* body0,btCollisionOb
 	return hasResponse;
 	return hasResponse;
 }
 }
 
 
-bool	btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionObject* body1)
+bool	btCollisionDispatcher::needsCollision(const btCollisionObject* body0,const btCollisionObject* body1)
 {
 {
 	btAssert(body0);
 	btAssert(body0);
 	btAssert(body1);
 	btAssert(body1);
@@ -169,13 +188,12 @@ bool	btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionO
 	bool needsCollision = true;
 	bool needsCollision = true;
 
 
 #ifdef BT_DEBUG
 #ifdef BT_DEBUG
-	if (!m_staticWarningReported)
+	if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED))
 	{
 	{
 		//broadphase filtering already deals with this
 		//broadphase filtering already deals with this
-		if ((body0->isStaticObject() || body0->isKinematicObject()) &&
-			(body1->isStaticObject() || body1->isKinematicObject()))
+		if (body0->isStaticOrKinematicObject() && body1->isStaticOrKinematicObject())
 		{
 		{
-			m_staticWarningReported = true;
+			m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED;
 			printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
 			printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n");
 		}
 		}
 	}
 	}
@@ -183,7 +201,7 @@ bool	btCollisionDispatcher::needsCollision(btCollisionObject* body0,btCollisionO
 
 
 	if ((!body0->isActive()) && (!body1->isActive()))
 	if ((!body0->isActive()) && (!body1->isActive()))
 		needsCollision = false;
 		needsCollision = false;
-	else if (!body0->checkCollideWith(body1))
+	else if ((!body0->checkCollideWith(body1)) || (!body1->checkCollideWith(body0)))
 		needsCollision = false;
 		needsCollision = false;
 	
 	
 	return needsCollision ;
 	return needsCollision ;
@@ -221,6 +239,8 @@ public:
 
 
 	virtual bool	processOverlap(btBroadphasePair& pair)
 	virtual bool	processOverlap(btBroadphasePair& pair)
 	{
 	{
+		BT_PROFILE("btCollisionDispatcher::processOverlap");
+
 		(*m_dispatcher->getNearCallback())(pair,*m_dispatcher,m_dispatchInfo);
 		(*m_dispatcher->getNearCallback())(pair,*m_dispatcher,m_dispatchInfo);
 
 
 		return false;
 		return false;
@@ -243,7 +263,6 @@ void	btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pa
 
 
 
 
 
 
-
 //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)
 {
 {
@@ -252,20 +271,25 @@ void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair,
 
 
 		if (dispatcher.needsCollision(colObj0,colObj1))
 		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);
+
+
 			//dispatcher will keep algorithms persistent in the collision pair
 			//dispatcher will keep algorithms persistent in the collision pair
 			if (!collisionPair.m_algorithm)
 			if (!collisionPair.m_algorithm)
 			{
 			{
-				collisionPair.m_algorithm = dispatcher.findAlgorithm(colObj0,colObj1);
+				collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap,0, BT_CONTACT_POINT_ALGORITHMS);
 			}
 			}
 
 
 			if (collisionPair.m_algorithm)
 			if (collisionPair.m_algorithm)
 			{
 			{
-				btManifoldResult contactPointResult(colObj0,colObj1);
+				btManifoldResult contactPointResult(&obj0Wrap,&obj1Wrap);
 				
 				
 				if (dispatchInfo.m_dispatchFunc == 		btDispatcherInfo::DISPATCH_DISCRETE)
 				if (dispatchInfo.m_dispatchFunc == 		btDispatcherInfo::DISPATCH_DISCRETE)
 				{
 				{
 					//discrete collision detection query
 					//discrete collision detection query
-					collisionPair.m_algorithm->processCollision(colObj0,colObj1,dispatchInfo,&contactPointResult);
+					
+					collisionPair.m_algorithm->processCollision(&obj0Wrap,&obj1Wrap,dispatchInfo,&contactPointResult);
 				} else
 				} else
 				{
 				{
 					//continuous collision detection query, time of impact (toi)
 					//continuous collision detection query, time of impact (toi)
@@ -282,13 +306,13 @@ void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair,
 
 
 void* btCollisionDispatcher::allocateCollisionAlgorithm(int size)
 void* btCollisionDispatcher::allocateCollisionAlgorithm(int size)
 {
 {
-	if (m_collisionAlgorithmPoolAllocator->getFreeCount())
-	{
-		return m_collisionAlgorithmPoolAllocator->allocate(size);
-	}
-	
-	//warn user for overflow?
-	return	btAlignedAlloc(static_cast<size_t>(size), 16);
+    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)

+ 45 - 17
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h

@@ -13,8 +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 COLLISION__DISPATCHER_H
-#define COLLISION__DISPATCHER_H
+#ifndef BT_COLLISION__DISPATCHER_H
+#define BT_COLLISION__DISPATCHER_H
 
 
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
@@ -42,14 +42,13 @@ typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispa
 ///Time of Impact, Closest Points and Penetration Depth.
 ///Time of Impact, Closest Points and Penetration Depth.
 class btCollisionDispatcher : public btDispatcher
 class btCollisionDispatcher : public btDispatcher
 {
 {
-	int m_count;
-	
-	btAlignedObjectArray<btPersistentManifold*>	m_manifoldsPtr;
 
 
-	bool m_useIslands;
+protected:
+
+	int		m_dispatcherFlags;
+
+	btAlignedObjectArray<btPersistentManifold*>	m_manifoldsPtr;
 
 
-	bool	m_staticWarningReported;
-	
 	btManifoldResult	m_defaultManifoldResult;
 	btManifoldResult	m_defaultManifoldResult;
 
 
 	btNearCallback		m_nearCallback;
 	btNearCallback		m_nearCallback;
@@ -58,17 +57,37 @@ class btCollisionDispatcher : public btDispatcher
 
 
 	btPoolAllocator*	m_persistentManifoldPoolAllocator;
 	btPoolAllocator*	m_persistentManifoldPoolAllocator;
 
 
-	btCollisionAlgorithmCreateFunc* m_doubleDispatch[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];
 
 
 	btCollisionConfiguration*	m_collisionConfiguration;
 	btCollisionConfiguration*	m_collisionConfiguration;
 
 
 
 
 public:
 public:
 
 
+	enum DispatcherFlags
+	{
+		CD_STATIC_STATIC_REPORTED = 1,
+		CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2,
+		CD_DISABLE_CONTACTPOOL_DYNAMIC_ALLOCATION = 4
+	};
+
+	int	getDispatcherFlags() const
+	{
+		return m_dispatcherFlags;
+	}
+
+	void	setDispatcherFlags(int 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);
+
 	int	getNumManifolds() const
 	int	getNumManifolds() const
 	{ 
 	{ 
 		return int( m_manifoldsPtr.size());
 		return int( m_manifoldsPtr.size());
@@ -76,7 +95,7 @@ public:
 
 
 	btPersistentManifold**	getInternalManifoldPointer()
 	btPersistentManifold**	getInternalManifoldPointer()
 	{
 	{
-		return &m_manifoldsPtr[0];
+		return m_manifoldsPtr.size()? &m_manifoldsPtr[0] : 0;
 	}
 	}
 
 
 	 btPersistentManifold* getManifoldByIndexInternal(int index)
 	 btPersistentManifold* getManifoldByIndexInternal(int index)
@@ -93,19 +112,18 @@ public:
 
 
 	virtual ~btCollisionDispatcher();
 	virtual ~btCollisionDispatcher();
 
 
-	virtual btPersistentManifold*	getNewManifold(void* b0,void* b1);
+	virtual btPersistentManifold*	getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1);
 	
 	
 	virtual void releaseManifold(btPersistentManifold* manifold);
 	virtual void releaseManifold(btPersistentManifold* manifold);
 
 
 
 
 	virtual void clearManifold(btPersistentManifold* manifold);
 	virtual void clearManifold(btPersistentManifold* manifold);
 
 
-			
-	btCollisionAlgorithm* findAlgorithm(btCollisionObject* body0,btCollisionObject* body1,btPersistentManifold* sharedManifold = 0);
+	btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType);
 		
 		
-	virtual bool	needsCollision(btCollisionObject* body0,btCollisionObject* body1);
+	virtual bool	needsCollision(const btCollisionObject* body0,const btCollisionObject* body1);
 	
 	
-	virtual bool	needsResponse(btCollisionObject* body0,btCollisionObject* body1);
+	virtual bool	needsResponse(const btCollisionObject* body0,const btCollisionObject* body1);
 	
 	
 	virtual void	dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) ;
 	virtual void	dispatchAllCollisionPairs(btOverlappingPairCache* pairCache,const btDispatcherInfo& dispatchInfo,btDispatcher* dispatcher) ;
 
 
@@ -141,7 +159,17 @@ public:
 		m_collisionConfiguration = config;
 		m_collisionConfiguration = config;
 	}
 	}
 
 
+	virtual	btPoolAllocator*	getInternalManifoldPool()
+	{
+		return m_persistentManifoldPoolAllocator;
+	}
+
+	virtual	const btPoolAllocator*	getInternalManifoldPool() const
+	{
+		return m_persistentManifoldPoolAllocator;
+	}
+
 };
 };
 
 
-#endif //COLLISION__DISPATCHER_H
+#endif //BT_COLLISION__DISPATCHER_H
 
 

+ 64 - 7
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp

@@ -4,8 +4,8 @@ Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
 
 
 This software is provided 'as-is', without any express or implied warranty.
 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.
 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, 
+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:
 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.
 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.
@@ -15,6 +15,7 @@ subject to the following restrictions:
 
 
 
 
 #include "btCollisionObject.h"
 #include "btCollisionObject.h"
+#include "LinearMath/btSerializer.h"
 
 
 btCollisionObject::btCollisionObject()
 btCollisionObject::btCollisionObject()
 	:	m_anisotropicFriction(1.f,1.f,1.f),
 	:	m_anisotropicFriction(1.f,1.f,1.f),
@@ -22,20 +23,29 @@ btCollisionObject::btCollisionObject()
 	m_contactProcessingThreshold(BT_LARGE_FLOAT),
 	m_contactProcessingThreshold(BT_LARGE_FLOAT),
 		m_broadphaseHandle(0),
 		m_broadphaseHandle(0),
 		m_collisionShape(0),
 		m_collisionShape(0),
+		m_extensionPointer(0),
 		m_rootCollisionShape(0),
 		m_rootCollisionShape(0),
 		m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
 		m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
 		m_islandTag1(-1),
 		m_islandTag1(-1),
 		m_companionId(-1),
 		m_companionId(-1),
+        m_worldArrayIndex(-1),
 		m_activationState1(1),
 		m_activationState1(1),
 		m_deactivationTime(btScalar(0.)),
 		m_deactivationTime(btScalar(0.)),
 		m_friction(btScalar(0.5)),
 		m_friction(btScalar(0.5)),
 		m_restitution(btScalar(0.)),
 		m_restitution(btScalar(0.)),
-		m_userObjectPointer(0),
+		m_rollingFriction(0.0f),
+        m_spinningFriction(0.f),
+		m_contactDamping(.1),
+		m_contactStiffness(1e4),
 		m_internalType(CO_COLLISION_OBJECT),
 		m_internalType(CO_COLLISION_OBJECT),
+		m_userObjectPointer(0),
+		m_userIndex2(-1),
+		m_userIndex(-1),
 		m_hitFraction(btScalar(1.)),
 		m_hitFraction(btScalar(1.)),
 		m_ccdSweptSphereRadius(btScalar(0.)),
 		m_ccdSweptSphereRadius(btScalar(0.)),
 		m_ccdMotionThreshold(btScalar(0.)),
 		m_ccdMotionThreshold(btScalar(0.)),
-		m_checkCollideWith(false)
+		m_checkCollideWith(false),
+		m_updateRevision(0)
 {
 {
 	m_worldTransform.setIdentity();
 	m_worldTransform.setIdentity();
 }
 }
@@ -44,18 +54,18 @@ btCollisionObject::~btCollisionObject()
 {
 {
 }
 }
 
 
-void btCollisionObject::setActivationState(int newState) 
+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;
 }
 }
 
 
-void btCollisionObject::forceActivationState(int newState)
+void btCollisionObject::forceActivationState(int newState) const
 {
 {
 	m_activationState1 = newState;
 	m_activationState1 = newState;
 }
 }
 
 
-void btCollisionObject::activate(bool forceActivation)
+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)))
 	{
 	{
@@ -64,5 +74,52 @@ void btCollisionObject::activate(bool forceActivation)
 	}
 	}
 }
 }
 
 
+const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const
+{
+
+	btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer;
 
 
+	m_worldTransform.serialize(dataOut->m_worldTransform);
+	m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform);
+	m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity);
+	m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity);
+	m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction);
+	dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction;
+	dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold;
+	dataOut->m_broadphaseHandle = 0;
+	dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape);
+	dataOut->m_rootCollisionShape = 0;//@todo
+	dataOut->m_collisionFlags = m_collisionFlags;
+	dataOut->m_islandTag1 = m_islandTag1;
+	dataOut->m_companionId = m_companionId;
+	dataOut->m_activationState1 = m_activationState1;
+	dataOut->m_deactivationTime = m_deactivationTime;
+	dataOut->m_friction = m_friction;
+	dataOut->m_rollingFriction = m_rollingFriction;
+	dataOut->m_contactDamping = m_contactDamping;
+	dataOut->m_contactStiffness = m_contactStiffness;
+	dataOut->m_restitution = m_restitution;
+	dataOut->m_internalType = m_internalType;
+	
+	char* name = (char*) serializer->findNameForPointer(this);
+	dataOut->m_name = (char*)serializer->getUniquePointer(name);
+	if (dataOut->m_name)
+	{
+		serializer->serializeName(name);
+	}
+	dataOut->m_hitFraction = m_hitFraction;
+	dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius;
+	dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold;
+	dataOut->m_checkCollideWith = m_checkCollideWith;
 
 
+	return btCollisionObjectDataName;
+}
+
+
+void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const
+{
+	int len = calculateSerializeBufferSize();
+	btChunk* chunk = serializer->allocate(len,1);
+	const char* structType = serialize(chunk->m_oldPtr, serializer);
+	serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this);
+}

+ 296 - 40
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.h

@@ -13,8 +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 COLLISION_OBJECT_H
-#define COLLISION_OBJECT_H
+#ifndef BT_COLLISION_OBJECT_H
+#define BT_COLLISION_OBJECT_H
 
 
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btTransform.h"
 
 
@@ -27,13 +27,21 @@ subject to the following restrictions:
 
 
 struct	btBroadphaseProxy;
 struct	btBroadphaseProxy;
 class	btCollisionShape;
 class	btCollisionShape;
+struct btCollisionShapeData;
 #include "LinearMath/btMotionState.h"
 #include "LinearMath/btMotionState.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedAllocator.h"
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
 
 
-
 typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
 typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray;
 
 
+#ifdef BT_USE_DOUBLE_PRECISION
+#define btCollisionObjectData btCollisionObjectDoubleData
+#define btCollisionObjectDataName "btCollisionObjectDoubleData"
+#else
+#define btCollisionObjectData btCollisionObjectFloatData
+#define btCollisionObjectDataName "btCollisionObjectFloatData"
+#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.
@@ -53,12 +61,14 @@ protected:
 	btVector3	m_interpolationLinearVelocity;
 	btVector3	m_interpolationLinearVelocity;
 	btVector3	m_interpolationAngularVelocity;
 	btVector3	m_interpolationAngularVelocity;
 	
 	
-	btVector3		m_anisotropicFriction;
-	bool				m_hasAnisotropicFriction;
-	btScalar		m_contactProcessingThreshold;	
+	btVector3	m_anisotropicFriction;
+	int			m_hasAnisotropicFriction;
+	btScalar	m_contactProcessingThreshold;	
 
 
 	btBroadphaseProxy*		m_broadphaseHandle;
 	btBroadphaseProxy*		m_broadphaseHandle;
 	btCollisionShape*		m_collisionShape;
 	btCollisionShape*		m_collisionShape;
+	///m_extensionPointer is used by some internal low-level Bullet extensions.
+	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
@@ -69,20 +79,32 @@ protected:
 
 
 	int				m_islandTag1;
 	int				m_islandTag1;
 	int				m_companionId;
 	int				m_companionId;
+    int             m_worldArrayIndex;  // index of object in world's collisionObjects array
 
 
-	int				m_activationState1;
-	btScalar			m_deactivationTime;
+	mutable int				m_activationState1;
+	mutable btScalar			m_deactivationTime;
 
 
 	btScalar		m_friction;
 	btScalar		m_friction;
 	btScalar		m_restitution;
 	btScalar		m_restitution;
-
-	///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
-	void*			m_userObjectPointer;
+	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
+
+	void*			m_userObjectPointer;
+
+	int				m_userIndex2;
+	
+    int	m_userIndex;
+
 	///time of impact calculation
 	///time of impact calculation
 	btScalar		m_hitFraction; 
 	btScalar		m_hitFraction; 
 	
 	
@@ -93,14 +115,14 @@ protected:
 	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
-	bool			m_checkCollideWith;
+	int			m_checkCollideWith;
 
 
-	char	m_pad[7];
+	btAlignedObjectArray<const btCollisionObject*> m_objectsWithoutCollisionCheck;
 
 
-	virtual bool	checkCollideWithOverride(btCollisionObject* /* co */)
-	{
-		return true;
-	}
+	///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation.
+	int			m_updateRevision;
+
+	btVector3	m_customDebugColorRGB;
 
 
 public:
 public:
 
 
@@ -112,18 +134,31 @@ public:
 		CF_KINEMATIC_OBJECT= 2,
 		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_HAS_CONTACT_STIFFNESS_DAMPING = 128,
+		CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR = 256,
 	};
 	};
 
 
 	enum	CollisionObjectTypes
 	enum	CollisionObjectTypes
 	{
 	{
 		CO_COLLISION_OBJECT =1,
 		CO_COLLISION_OBJECT =1,
-		CO_RIGID_BODY,
+		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,
-		CO_SOFT_BODY,
-		CO_HF_FLUID
+		CO_GHOST_OBJECT=4,
+		CO_SOFT_BODY=8,
+		CO_HF_FLUID=16,
+		CO_USER_TYPE=32,
+		CO_FEATHERSTONE_LINK=64
+	};
+
+	enum AnisotropicFrictionFlags
+	{
+		CF_ANISOTROPIC_FRICTION_DISABLED=0,
+		CF_ANISOTROPIC_FRICTION = 1,
+		CF_ANISOTROPIC_ROLLING_FRICTION = 2
 	};
 	};
 
 
 	SIMD_FORCE_INLINE bool mergesSimulationIslands() const
 	SIMD_FORCE_INLINE bool mergesSimulationIslands() const
@@ -136,14 +171,15 @@ public:
 	{
 	{
 		return m_anisotropicFriction;
 		return m_anisotropicFriction;
 	}
 	}
-	void	setAnisotropicFriction(const btVector3& anisotropicFriction)
+	void	setAnisotropicFriction(const btVector3& anisotropicFriction, int frictionMode = CF_ANISOTROPIC_FRICTION)
 	{
 	{
 		m_anisotropicFriction = anisotropicFriction;
 		m_anisotropicFriction = anisotropicFriction;
-		m_hasAnisotropicFriction = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
+		bool isUnity = (anisotropicFriction[0]!=1.f) || (anisotropicFriction[1]!=1.f) || (anisotropicFriction[2]!=1.f);
+		m_hasAnisotropicFriction = isUnity?frictionMode : 0;
 	}
 	}
-	bool	hasAnisotropicFriction() const
+	bool	hasAnisotropicFriction(int frictionMode = CF_ANISOTROPIC_FRICTION) const
 	{
 	{
-		return m_hasAnisotropicFriction;
+		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.
@@ -182,6 +218,7 @@ public:
 
 
 	virtual void	setCollisionShape(btCollisionShape* collisionShape)
 	virtual void	setCollisionShape(btCollisionShape* collisionShape)
 	{
 	{
+		m_updateRevision++;
 		m_collisionShape = collisionShape;
 		m_collisionShape = collisionShape;
 		m_rootCollisionShape = collisionShape;
 		m_rootCollisionShape = collisionShape;
 	}
 	}
@@ -196,26 +233,53 @@ public:
 		return m_collisionShape;
 		return m_collisionShape;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE const btCollisionShape*	getRootCollisionShape() const
+	void	setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
 	{
 	{
-		return m_rootCollisionShape;
+		if (ignoreCollisionCheck)
+		{
+			//We don't check for duplicates. Is it ok to leave that up to the user of this API?
+			//int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
+			//if (index == m_objectsWithoutCollisionCheck.size())
+			//{
+			m_objectsWithoutCollisionCheck.push_back(co);
+			//}
+		}
+		else
+		{
+			m_objectsWithoutCollisionCheck.remove(co);
+		}
+		m_checkCollideWith = m_objectsWithoutCollisionCheck.size() > 0;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE btCollisionShape*	getRootCollisionShape()
+	virtual bool	checkCollideWithOverride(const btCollisionObject*  co) const
 	{
 	{
-		return m_rootCollisionShape;
+		int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
+		if (index < m_objectsWithoutCollisionCheck.size())
+		{
+			return false;
+		}
+		return true;
 	}
 	}
 
 
-	///Avoid using this internal API call
-	///internalSetTemporaryCollisionShape is used to temporary replace the actual collision shape by a child collision shape.
-	void	internalSetTemporaryCollisionShape(btCollisionShape* collisionShape)
+
+	
+
+	///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.
+	void*		internalGetExtensionPointer() const
 	{
 	{
-		m_collisionShape = collisionShape;
+		return m_extensionPointer;
+	}
+	///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.
+	void	internalSetExtensionPointer(void* 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);
+	void setActivationState(int newState) const;
 
 
 	void	setDeactivationTime(btScalar time)
 	void	setDeactivationTime(btScalar time)
 	{
 	{
@@ -226,9 +290,9 @@ public:
 		return m_deactivationTime;
 		return m_deactivationTime;
 	}
 	}
 
 
-	void forceActivationState(int newState);
+	void forceActivationState(int newState) const;
 
 
-	void	activate(bool forceActivation = false);
+	void	activate(bool forceActivation = false) const;
 
 
 	SIMD_FORCE_INLINE bool isActive() const
 	SIMD_FORCE_INLINE bool isActive() const
 	{
 	{
@@ -237,6 +301,7 @@ public:
 
 
 	void	setRestitution(btScalar rest)
 	void	setRestitution(btScalar rest)
 	{
 	{
+		m_updateRevision++;
 		m_restitution = rest;
 		m_restitution = rest;
 	}
 	}
 	btScalar	getRestitution() const
 	btScalar	getRestitution() const
@@ -245,6 +310,7 @@ public:
 	}
 	}
 	void	setFriction(btScalar frict)
 	void	setFriction(btScalar frict)
 	{
 	{
+		m_updateRevision++;
 		m_friction = frict;
 		m_friction = frict;
 	}
 	}
 	btScalar	getFriction() const
 	btScalar	getFriction() const
@@ -252,6 +318,49 @@ public:
 		return m_friction;
 		return m_friction;
 	}
 	}
 
 
+	void	setRollingFriction(btScalar frict)
+	{
+		m_updateRevision++;
+		m_rollingFriction = frict;
+	}
+	btScalar	getRollingFriction() const
+	{
+		return m_rollingFriction;
+	}
+    void	setSpinningFriction(btScalar frict)
+    {
+        m_updateRevision++;
+        m_spinningFriction = frict;
+    }
+    btScalar	getSpinningFriction() const
+    {
+        return m_spinningFriction;
+    }
+    void	setContactStiffnessAndDamping(btScalar stiffness, btScalar damping)
+	{
+		m_updateRevision++;
+		m_contactStiffness = stiffness;
+		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
+	{
+		return m_contactStiffness;
+	}
+	
+	btScalar	getContactDamping() const
+	{
+		return m_contactDamping;
+	}
+    
 	///reserved for Bullet internal usage
 	///reserved for Bullet internal usage
 	int	getInternalType() const
 	int	getInternalType() const
 	{
 	{
@@ -270,6 +379,7 @@ public:
 
 
 	void	setWorldTransform(const btTransform& worldTrans)
 	void	setWorldTransform(const btTransform& worldTrans)
 	{
 	{
+		m_updateRevision++;
 		m_worldTransform = worldTrans;
 		m_worldTransform = worldTrans;
 	}
 	}
 
 
@@ -302,16 +412,19 @@ public:
 
 
 	void	setInterpolationWorldTransform(const btTransform&	trans)
 	void	setInterpolationWorldTransform(const btTransform&	trans)
 	{
 	{
+		m_updateRevision++;
 		m_interpolationWorldTransform = trans;
 		m_interpolationWorldTransform = trans;
 	}
 	}
 
 
 	void	setInterpolationLinearVelocity(const btVector3& linvel)
 	void	setInterpolationLinearVelocity(const btVector3& linvel)
 	{
 	{
+		m_updateRevision++;
 		m_interpolationLinearVelocity = linvel;
 		m_interpolationLinearVelocity = linvel;
 	}
 	}
 
 
 	void	setInterpolationAngularVelocity(const btVector3& angvel)
 	void	setInterpolationAngularVelocity(const btVector3& angvel)
 	{
 	{
+		m_updateRevision++;
 		m_interpolationAngularVelocity = angvel;
 		m_interpolationAngularVelocity = angvel;
 	}
 	}
 
 
@@ -345,7 +458,18 @@ public:
 		m_companionId = id;
 		m_companionId = id;
 	}
 	}
 
 
-	SIMD_FORCE_INLINE btScalar			getHitFraction() const
+    SIMD_FORCE_INLINE int getWorldArrayIndex() const
+    {
+        return	m_worldArrayIndex;
+    }
+
+    // only should be called by CollisionWorld
+    void setWorldArrayIndex(int ix)
+    {
+        m_worldArrayIndex = ix;
+    }
+
+    SIMD_FORCE_INLINE btScalar			getHitFraction() const
 	{
 	{
 		return m_hitFraction; 
 		return m_hitFraction; 
 	}
 	}
@@ -401,6 +525,16 @@ public:
 	{
 	{
 		return m_userObjectPointer;
 		return m_userObjectPointer;
 	}
 	}
+
+	int	getUserIndex() const
+	{
+		return m_userIndex;
+	}
+	
+	int	getUserIndex2() const
+	{
+		return m_userIndex2;
+	}
 	
 	
 	///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)
@@ -408,14 +542,136 @@ public:
 		m_userObjectPointer = userPointer;
 		m_userObjectPointer = userPointer;
 	}
 	}
 
 
+	///users can point to their objects, userPointer is not used by Bullet
+	void	setUserIndex(int index)
+	{
+		m_userIndex = index;
+	}
+	
+	void	setUserIndex2(int index)
+	{
+		m_userIndex2 = index;
+	}
+
+	int	getUpdateRevisionInternal() const
+	{
+		return m_updateRevision;
+	}
+
+	void	setCustomDebugColor(const btVector3& colorRGB)
+	{
+		m_customDebugColorRGB = colorRGB;
+		m_collisionFlags |= CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
+	}
+
+	void	removeCustomDebugColor()
+	{
+		m_collisionFlags &= ~CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR;
+	}
+
+	bool getCustomDebugColor(btVector3& colorRGB) const
+	{
+		bool hasCustomColor = (0!=(m_collisionFlags&CF_HAS_CUSTOM_DEBUG_RENDERING_COLOR));
+		if (hasCustomColor)
+		{
+			colorRGB = m_customDebugColorRGB;
+		}
+		return hasCustomColor;
+	}
 
 
-	inline bool checkCollideWith(btCollisionObject* co)
+	inline bool checkCollideWith(const btCollisionObject* co) const
 	{
 	{
 		if (m_checkCollideWith)
 		if (m_checkCollideWith)
 			return checkCollideWithOverride(co);
 			return checkCollideWithOverride(co);
 
 
 		return true;
 		return true;
 	}
 	}
+
+	virtual	int	calculateSerializeBufferSize()	const;
+
+	///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;
+
+};
+
+///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
+struct	btCollisionObjectDoubleData
+{
+	void					*m_broadphaseHandle;
+	void					*m_collisionShape;
+	btCollisionShapeData	*m_rootCollisionShape;
+	char					*m_name;
+
+	btTransformDoubleData	m_worldTransform;
+	btTransformDoubleData	m_interpolationWorldTransform;
+	btVector3DoubleData		m_interpolationLinearVelocity;
+	btVector3DoubleData		m_interpolationAngularVelocity;
+	btVector3DoubleData		m_anisotropicFriction;
+	double					m_contactProcessingThreshold;	
+	double					m_deactivationTime;
+	double					m_friction;
+	double					m_rollingFriction;
+	double                  m_contactDamping;
+	double                  m_contactStiffness;
+	double					m_restitution;
+	double					m_hitFraction; 
+	double					m_ccdSweptSphereRadius;
+	double					m_ccdMotionThreshold;
+
+	int						m_hasAnisotropicFriction;
+	int						m_collisionFlags;
+	int						m_islandTag1;
+	int						m_companionId;
+	int						m_activationState1;
+	int						m_internalType;
+	int						m_checkCollideWith;
+
+	char	m_padding[4];
 };
 };
 
 
-#endif //COLLISION_OBJECT_H
+///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64
+struct	btCollisionObjectFloatData
+{
+	void					*m_broadphaseHandle;
+	void					*m_collisionShape;
+	btCollisionShapeData	*m_rootCollisionShape;
+	char					*m_name;
+
+	btTransformFloatData	m_worldTransform;
+	btTransformFloatData	m_interpolationWorldTransform;
+	btVector3FloatData		m_interpolationLinearVelocity;
+	btVector3FloatData		m_interpolationAngularVelocity;
+	btVector3FloatData		m_anisotropicFriction;
+	float					m_contactProcessingThreshold;	
+	float					m_deactivationTime;
+	float					m_friction;
+	float					m_rollingFriction;
+    float                   m_contactDamping;
+    float                   m_contactStiffness;
+	float					m_restitution;
+	float					m_hitFraction; 
+	float					m_ccdSweptSphereRadius;
+	float					m_ccdMotionThreshold;
+
+	int						m_hasAnisotropicFriction;
+	int						m_collisionFlags;
+	int						m_islandTag1;
+	int						m_companionId;
+	int						m_activationState1;
+	int						m_internalType;
+	int						m_checkCollideWith;
+	char					m_padding[4];
+};
+
+
+
+SIMD_FORCE_INLINE	int	btCollisionObject::calculateSerializeBufferSize() const
+{
+	return sizeof(btCollisionObjectData);
+}
+
+
+
+#endif //BT_COLLISION_OBJECT_H

+ 43 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h

@@ -0,0 +1,43 @@
+#ifndef BT_COLLISION_OBJECT_WRAPPER_H
+#define BT_COLLISION_OBJECT_WRAPPER_H
+
+///btCollisionObjectWrapperis an internal data structure. 
+///Most users can ignore this and use btCollisionObject and btCollisionShape instead
+class btCollisionShape;
+class btCollisionObject;
+class btTransform;
+#include "LinearMath/btScalar.h" // for SIMD_FORCE_INLINE definition
+
+#define BT_DECLARE_STACK_ONLY_OBJECT \
+	private: \
+		void* operator new(size_t size); \
+		void operator delete(void*);
+
+struct btCollisionObjectWrapper;
+struct btCollisionObjectWrapper
+{
+BT_DECLARE_STACK_ONLY_OBJECT
+
+private:
+	btCollisionObjectWrapper(const btCollisionObjectWrapper&); // not implemented. Not allowed.
+	btCollisionObjectWrapper* operator=(const btCollisionObjectWrapper&);
+
+public:
+	const btCollisionObjectWrapper* m_parent;
+	const btCollisionShape* m_shape;
+	const btCollisionObject* m_collisionObject;
+	const btTransform& m_worldTransform;
+	int		m_partId;
+	int		m_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)
+	{}
+
+	SIMD_FORCE_INLINE const btTransform& getWorldTransform() const { return m_worldTransform; }
+	SIMD_FORCE_INLINE const btCollisionObject* getCollisionObject() const { return m_collisionObject; }
+	SIMD_FORCE_INLINE const btCollisionShape* getCollisionShape() const { return m_shape; }
+};
+
+#endif //BT_COLLISION_OBJECT_WRAPPER_H

+ 1006 - 204
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp

@@ -26,11 +26,17 @@ 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/btContinuousConvexCollision.h"
 #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h"
-
+#include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+#include "BulletCollision/BroadphaseCollision/btDbvt.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btQuickprof.h"
 #include "LinearMath/btQuickprof.h"
-#include "LinearMath/btStackAlloc.h"
+#include "LinearMath/btSerializer.h"
+#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+
+//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
+
 
 
 //#define USE_BRUTEFORCE_RAYBROADPHASE 1
 //#define USE_BRUTEFORCE_RAYBROADPHASE 1
 //RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation'  or 'updateAabbs' before using a rayTest
 //RECALCULATE_AABB is slower, but benefit is that you don't need to call 'stepSimulation'  or 'updateAabbs' before using a rayTest
@@ -42,14 +48,30 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
 #include "BulletCollision/CollisionDispatch/btCollisionConfiguration.h"
 
 
 
 
+///for debug drawing
+
+//for debug rendering
+#include "BulletCollision/CollisionShapes/btBoxShape.h"
+#include "BulletCollision/CollisionShapes/btCapsuleShape.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
+#include "BulletCollision/CollisionShapes/btConeShape.h"
+#include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btCylinderShape.h"
+#include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
+#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
+#include "BulletCollision/CollisionShapes/btSphereShape.h"
+#include "BulletCollision/CollisionShapes/btTriangleCallback.h"
+#include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
+
+
+
 btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration)
 btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration)
 :m_dispatcher1(dispatcher),
 :m_dispatcher1(dispatcher),
 m_broadphasePairCache(pairCache),
 m_broadphasePairCache(pairCache),
 m_debugDrawer(0),
 m_debugDrawer(0),
 m_forceUpdateAllAabbs(true)
 m_forceUpdateAllAabbs(true)
 {
 {
-	m_stackAlloc = collisionConfiguration->getStackAllocator();
-	m_dispatchInfo.m_stackAllocator = m_stackAlloc;
 }
 }
 
 
 
 
@@ -92,27 +114,29 @@ void	btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,sho
 	btAssert(collisionObject);
 	btAssert(collisionObject);
 
 
 	//check that the object isn't already added
 	//check that the object isn't already added
-		btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());
+	btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());
+    btAssert(collisionObject->getWorldArrayIndex() == -1);  // do not add the same object to more than one collision world
 
 
-		m_collisionObjects.push_back(collisionObject);
+    collisionObject->setWorldArrayIndex(m_collisionObjects.size());
+	m_collisionObjects.push_back(collisionObject);
 
 
-		//calculate new AABB
-		btTransform trans = collisionObject->getWorldTransform();
+	//calculate new AABB
+	btTransform trans = collisionObject->getWorldTransform();
 
 
-		btVector3	minAabb;
-		btVector3	maxAabb;
-		collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb);
+	btVector3	minAabb;
+	btVector3	maxAabb;
+	collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb);
 
 
-		int type = collisionObject->getCollisionShape()->getShapeType();
-		collisionObject->setBroadphaseHandle( getBroadphase()->createProxy(
-			minAabb,
-			maxAabb,
-			type,
-			collisionObject,
-			collisionFilterGroup,
-			collisionFilterMask,
-			m_dispatcher1,0
-			))	;
+	int type = collisionObject->getCollisionShape()->getShapeType();
+	collisionObject->setBroadphaseHandle( getBroadphase()->createProxy(
+		minAabb,
+		maxAabb,
+		type,
+		collisionObject,
+		collisionFilterGroup,
+		collisionFilterMask,
+		m_dispatcher1,0
+		))	;
 
 
 
 
 
 
@@ -131,6 +155,16 @@ void	btCollisionWorld::updateSingleAabb(btCollisionObject* colObj)
 	minAabb -= contactThreshold;
 	minAabb -= contactThreshold;
 	maxAabb += contactThreshold;
 	maxAabb += contactThreshold;
 
 
+	if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())
+	{
+		btVector3 minAabb2,maxAabb2;
+		colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
+		minAabb2 -= contactThreshold;
+		maxAabb2 += contactThreshold;
+		minAabb.setMin(minAabb2);
+		maxAabb.setMax(maxAabb2);
+	}
+
 	btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;
 	btBroadphaseInterface* bp = (btBroadphaseInterface*)m_broadphasePairCache;
 
 
 	//moving objects should be moderately sized, probably something wrong if not
 	//moving objects should be moderately sized, probably something wrong if not
@@ -163,6 +197,7 @@ void	btCollisionWorld::updateAabbs()
 	for ( int i=0;i<m_collisionObjects.size();i++)
 	for ( int i=0;i<m_collisionObjects.size();i++)
 	{
 	{
 		btCollisionObject* colObj = m_collisionObjects[i];
 		btCollisionObject* colObj = m_collisionObjects[i];
+        btAssert(colObj->getWorldArrayIndex() == i);
 
 
 		//only update aabb of active objects
 		//only update aabb of active objects
 		if (m_forceUpdateAllAabbs || colObj->isActive())
 		if (m_forceUpdateAllAabbs || colObj->isActive())
@@ -173,6 +208,11 @@ void	btCollisionWorld::updateAabbs()
 }
 }
 
 
 
 
+void	btCollisionWorld::computeOverlappingPairs()
+{
+	BT_PROFILE("calculateOverlappingPairs");
+	m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
+}
 
 
 void	btCollisionWorld::performDiscreteCollisionDetection()
 void	btCollisionWorld::performDiscreteCollisionDetection()
 {
 {
@@ -182,11 +222,7 @@ void	btCollisionWorld::performDiscreteCollisionDetection()
 
 
 	updateAabbs();
 	updateAabbs();
 
 
-	{
-		BT_PROFILE("calculateOverlappingPairs");
-		m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
-	}
-
+	computeOverlappingPairs();
 
 
 	btDispatcher* dispatcher = getDispatcher();
 	btDispatcher* dispatcher = getDispatcher();
 	{
 	{
@@ -220,38 +256,70 @@ void	btCollisionWorld::removeCollisionObject(btCollisionObject* collisionObject)
 	}
 	}
 
 
 
 
-	//swapremove
-	m_collisionObjects.remove(collisionObject);
-
+    int iObj = collisionObject->getWorldArrayIndex();
+    btAssert(iObj >= 0 && iObj < m_collisionObjects.size()); // trying to remove an object that was never added or already removed previously?
+    if (iObj >= 0 && iObj < m_collisionObjects.size())
+    {
+        btAssert(collisionObject == m_collisionObjects[iObj]);
+        m_collisionObjects.swap(iObj, m_collisionObjects.size()-1);
+        m_collisionObjects.pop_back();
+        if (iObj < m_collisionObjects.size())
+        {
+            m_collisionObjects[iObj]->setWorldArrayIndex(iObj);
+        }
+    }
+    else
+    {
+        // slow linear search
+        //swapremove
+        m_collisionObjects.remove(collisionObject);
+    }
+    collisionObject->setWorldArrayIndex(-1);
 }
 }
 
 
 
 
-
 void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
 void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans,
-					  btCollisionObject* collisionObject,
-					  const btCollisionShape* collisionShape,
-					  const btTransform& colObjWorldTransform,
-					  RayResultCallback& resultCallback)
+										btCollisionObject* collisionObject,
+										const btCollisionShape* collisionShape,
+										const btTransform& colObjWorldTransform,
+										RayResultCallback& resultCallback)
+{
+	btCollisionObjectWrapper colObWrap(0,collisionShape,collisionObject,colObjWorldTransform,-1,-1);
+	btCollisionWorld::rayTestSingleInternal(rayFromTrans,rayToTrans,&colObWrap,resultCallback);
+}
+
+void	btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,const btTransform& rayToTrans,
+										const btCollisionObjectWrapper* collisionObjectWrap,
+										RayResultCallback& resultCallback)
 {
 {
 	btSphereShape pointShape(btScalar(0.0));
 	btSphereShape pointShape(btScalar(0.0));
 	pointShape.setMargin(0.f);
 	pointShape.setMargin(0.f);
 	const btConvexShape* castShape = &pointShape;
 	const btConvexShape* castShape = &pointShape;
+	const btCollisionShape* collisionShape = collisionObjectWrap->getCollisionShape();
+	const btTransform& colObjWorldTransform = collisionObjectWrap->getWorldTransform();
 
 
 	if (collisionShape->isConvex())
 	if (collisionShape->isConvex())
 	{
 	{
-//		BT_PROFILE("rayTestConvex");
+		//		BT_PROFILE("rayTestConvex");
 		btConvexCast::CastResult castResult;
 		btConvexCast::CastResult castResult;
 		castResult.m_fraction = resultCallback.m_closestHitFraction;
 		castResult.m_fraction = resultCallback.m_closestHitFraction;
 
 
 		btConvexShape* convexShape = (btConvexShape*) collisionShape;
 		btConvexShape* convexShape = (btConvexShape*) collisionShape;
 		btVoronoiSimplexSolver	simplexSolver;
 		btVoronoiSimplexSolver	simplexSolver;
-#define USE_SUBSIMPLEX_CONVEX_CAST 1
-#ifdef USE_SUBSIMPLEX_CONVEX_CAST
-		btSubsimplexConvexCast convexCaster(castShape,convexShape,&simplexSolver);
-#else
-		//btGjkConvexCast	convexCaster(castShape,convexShape,&simplexSolver);
+		btSubsimplexConvexCast subSimplexConvexCaster(castShape,convexShape,&simplexSolver);
+		
+		btGjkConvexCast	gjkConvexCaster(castShape,convexShape,&simplexSolver);
+		
 		//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
 		//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
-#endif //#USE_SUBSIMPLEX_CONVEX_CAST
+
+		btConvexCast* convexCasterPtr = 0;
+		//use kF_UseSubSimplexConvexCastRaytest by default
+		if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseGjkConvexCastRaytest)
+			convexCasterPtr = &gjkConvexCaster;
+		else
+			convexCasterPtr = &subSimplexConvexCaster;
+		
+		btConvexCast& convexCaster = *convexCasterPtr;
 
 
 		if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
 		if (convexCaster.calcTimeOfImpact(rayFromTrans,rayToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
 		{
 		{
@@ -260,6 +328,7 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 			{
 			{
 				if (castResult.m_fraction < resultCallback.m_closestHitFraction)
 				if (castResult.m_fraction < resultCallback.m_closestHitFraction)
 				{
 				{
+					//todo: figure out what this is about. When is rayFromTest.getBasis() not identity?
 #ifdef USE_SUBSIMPLEX_CONVEX_CAST
 #ifdef USE_SUBSIMPLEX_CONVEX_CAST
 					//rotate normal into worldspace
 					//rotate normal into worldspace
 					castResult.m_normal = rayFromTrans.getBasis() * castResult.m_normal;
 					castResult.m_normal = rayFromTrans.getBasis() * castResult.m_normal;
@@ -268,10 +337,10 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 					castResult.m_normal.normalize();
 					castResult.m_normal.normalize();
 					btCollisionWorld::LocalRayResult localRayResult
 					btCollisionWorld::LocalRayResult localRayResult
 						(
 						(
-							collisionObject,
-							0,
-							castResult.m_normal,
-							castResult.m_fraction
+						collisionObjectWrap->getCollisionObject(),
+						0,
+						castResult.m_normal,
+						castResult.m_fraction
 						);
 						);
 
 
 					bool normalInWorldSpace = true;
 					bool normalInWorldSpace = true;
@@ -283,32 +352,24 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 	} else {
 	} else {
 		if (collisionShape->isConcave())
 		if (collisionShape->isConcave())
 		{
 		{
-//			BT_PROFILE("rayTestConcave");
-			if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
-			{
-				///optimized version for btBvhTriangleMeshShape
-				btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
-				btTransform worldTocollisionObject = colObjWorldTransform.inverse();
-				btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
-				btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();
 
 
-				//ConvexCast::CastResult
+			//ConvexCast::CastResult
 				struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
 				struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
 				{
 				{
 					btCollisionWorld::RayResultCallback* m_resultCallback;
 					btCollisionWorld::RayResultCallback* m_resultCallback;
-					btCollisionObject*	m_collisionObject;
-					btTriangleMeshShape*	m_triangleMesh;
+					const btCollisionObject*	m_collisionObject;
+					const btConcaveShape*	m_triangleMesh;
 
 
-               btTransform m_colObjWorldTransform;
+					btTransform m_colObjWorldTransform;
 
 
 					BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
 					BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
-						btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*	triangleMesh,const btTransform& colObjWorldTransform):
-                  //@BP Mod
+					btCollisionWorld::RayResultCallback* resultCallback, const btCollisionObject* collisionObject,const btConcaveShape*	triangleMesh,const btTransform& colObjWorldTransform):
+						//@BP Mod
 						btTriangleRaycastCallback(from,to, resultCallback->m_flags),
 						btTriangleRaycastCallback(from,to, resultCallback->m_flags),
 							m_resultCallback(resultCallback),
 							m_resultCallback(resultCallback),
 							m_collisionObject(collisionObject),
 							m_collisionObject(collisionObject),
 							m_triangleMesh(triangleMesh),
 							m_triangleMesh(triangleMesh),
-                     m_colObjWorldTransform(colObjWorldTransform)
+							m_colObjWorldTransform(colObjWorldTransform)
 						{
 						{
 						}
 						}
 
 
@@ -319,10 +380,10 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 						shapeInfo.m_shapePart = partId;
 						shapeInfo.m_shapePart = partId;
 						shapeInfo.m_triangleIndex = triangleIndex;
 						shapeInfo.m_triangleIndex = triangleIndex;
 
 
-                  btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal;
+						btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal;
 
 
 						btCollisionWorld::LocalRayResult rayResult
 						btCollisionWorld::LocalRayResult rayResult
-						(m_collisionObject,
+							(m_collisionObject,
 							&shapeInfo,
 							&shapeInfo,
 							hitNormalWorld,
 							hitNormalWorld,
 							hitFraction);
 							hitFraction);
@@ -333,10 +394,21 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 
 
 				};
 				};
 
 
-				BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh,colObjWorldTransform);
+			btTransform worldTocollisionObject = colObjWorldTransform.inverse();
+			btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
+			btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();
+
+			//			BT_PROFILE("rayTestConcave");
+			if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
+			{
+				///optimized version for btBvhTriangleMeshShape
+				btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
+				
+				BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),triangleMesh,colObjWorldTransform);
 				rcb.m_hitFraction = resultCallback.m_closestHitFraction;
 				rcb.m_hitFraction = resultCallback.m_closestHitFraction;
 				triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
 				triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
-			} else
+			}
+			else
 			{
 			{
 				//generic (slower) case
 				//generic (slower) case
 				btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
 				btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
@@ -351,21 +423,21 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 				struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
 				struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
 				{
 				{
 					btCollisionWorld::RayResultCallback* m_resultCallback;
 					btCollisionWorld::RayResultCallback* m_resultCallback;
-					btCollisionObject*	m_collisionObject;
+					const btCollisionObject*	m_collisionObject;
 					btConcaveShape*	m_triangleMesh;
 					btConcaveShape*	m_triangleMesh;
 
 
-               btTransform m_colObjWorldTransform;
+					btTransform m_colObjWorldTransform;
 
 
 					BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
 					BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
-						btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape*	triangleMesh, const btTransform& colObjWorldTransform):
-                  //@BP Mod
-                  btTriangleRaycastCallback(from,to, resultCallback->m_flags),
-							m_resultCallback(resultCallback),
-							m_collisionObject(collisionObject),
-							m_triangleMesh(triangleMesh),
-                     m_colObjWorldTransform(colObjWorldTransform)
-						{
-						}
+						btCollisionWorld::RayResultCallback* resultCallback, const btCollisionObject* collisionObject,btConcaveShape*	triangleMesh, const btTransform& colObjWorldTransform):
+					//@BP Mod
+					btTriangleRaycastCallback(from,to, resultCallback->m_flags),
+						m_resultCallback(resultCallback),
+						m_collisionObject(collisionObject),
+						m_triangleMesh(triangleMesh),
+						m_colObjWorldTransform(colObjWorldTransform)
+					{
+					}
 
 
 
 
 					virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex )
 					virtual btScalar reportHit(const btVector3& hitNormalLocal, btScalar hitFraction, int partId, int triangleIndex )
@@ -374,10 +446,10 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 						shapeInfo.m_shapePart = partId;
 						shapeInfo.m_shapePart = partId;
 						shapeInfo.m_triangleIndex = triangleIndex;
 						shapeInfo.m_triangleIndex = triangleIndex;
 
 
-                  btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal;
+						btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal;
 
 
 						btCollisionWorld::LocalRayResult rayResult
 						btCollisionWorld::LocalRayResult rayResult
-						(m_collisionObject,
+							(m_collisionObject,
 							&shapeInfo,
 							&shapeInfo,
 							hitNormalWorld,
 							hitNormalWorld,
 							hitFraction);
 							hitFraction);
@@ -389,7 +461,7 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 				};
 				};
 
 
 
 
-				BridgeTriangleRaycastCallback	rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
+				BridgeTriangleRaycastCallback	rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
 				rcb.m_hitFraction = resultCallback.m_closestHitFraction;
 				rcb.m_hitFraction = resultCallback.m_closestHitFraction;
 
 
 				btVector3 rayAabbMinLocal = rayFromLocal;
 				btVector3 rayAabbMinLocal = rayFromLocal;
@@ -400,27 +472,116 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 				concaveShape->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
 				concaveShape->processAllTriangles(&rcb,rayAabbMinLocal,rayAabbMaxLocal);
 			}
 			}
 		} else {
 		} else {
-//			BT_PROFILE("rayTestCompound");
-			///@todo: use AABB tree or other BVH acceleration structure, see btDbvt
+			//			BT_PROFILE("rayTestCompound");
 			if (collisionShape->isCompound())
 			if (collisionShape->isCompound())
 			{
 			{
+				struct LocalInfoAdder2 : public RayResultCallback
+				{
+					RayResultCallback* m_userCallback;
+					int m_i;
+					
+					LocalInfoAdder2 (int i, RayResultCallback *user)
+						: m_userCallback(user), m_i(i)
+					{ 
+						m_closestHitFraction = m_userCallback->m_closestHitFraction;
+						m_flags = m_userCallback->m_flags;
+					}
+					virtual bool needsCollision(btBroadphaseProxy* p) const
+					{
+						return m_userCallback->needsCollision(p);
+					}
+
+					virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b)
+					{
+						btCollisionWorld::LocalShapeInfo shapeInfo;
+						shapeInfo.m_shapePart = -1;
+						shapeInfo.m_triangleIndex = m_i;
+						if (r.m_localShapeInfo == NULL)
+							r.m_localShapeInfo = &shapeInfo;
+
+						const btScalar result = m_userCallback->addSingleResult(r, b);
+						m_closestHitFraction = m_userCallback->m_closestHitFraction;
+						return result;
+					}
+				};
+				
+				struct RayTester : btDbvt::ICollide
+				{
+					const btCollisionObject* m_collisionObject;
+					const btCompoundShape* m_compoundShape;
+					const btTransform& m_colObjWorldTransform;
+					const btTransform& m_rayFromTrans;
+					const btTransform& m_rayToTrans;
+					RayResultCallback& m_resultCallback;
+					
+					RayTester(const btCollisionObject* collisionObject,
+							const btCompoundShape* compoundShape,
+							const btTransform& colObjWorldTransform,
+							const btTransform& rayFromTrans,
+							const btTransform& rayToTrans,
+							RayResultCallback& resultCallback):
+						m_collisionObject(collisionObject),
+						m_compoundShape(compoundShape),
+						m_colObjWorldTransform(colObjWorldTransform),
+						m_rayFromTrans(rayFromTrans),
+						m_rayToTrans(rayToTrans),
+						m_resultCallback(resultCallback)
+					{
+						
+					}
+					
+					void ProcessLeaf(int i)
+					{
+						const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(i);
+						const btTransform& childTrans = m_compoundShape->getChildTransform(i);
+						btTransform childWorldTrans = m_colObjWorldTransform * childTrans;
+						
+						btCollisionObjectWrapper tmpOb(0,childCollisionShape,m_collisionObject,childWorldTrans,-1,i);
+						// replace collision shape so that callback can determine the triangle
+
+						
+
+						LocalInfoAdder2 my_cb(i, &m_resultCallback);
+
+						rayTestSingleInternal(
+							m_rayFromTrans,
+							m_rayToTrans,
+							&tmpOb,
+							my_cb);
+						
+					}
+				
+					void Process(const btDbvtNode* leaf)
+					{
+						ProcessLeaf(leaf->dataAsInt);
+					}
+				};
+				
 				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
 				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
-				int i=0;
-				for (i=0;i<compoundShape->getNumChildShapes();i++)
+				const btDbvt* dbvt = compoundShape->getDynamicAabbTree();
+
+
+				RayTester rayCB(
+					collisionObjectWrap->getCollisionObject(),
+					compoundShape,
+					colObjWorldTransform,
+					rayFromTrans,
+					rayToTrans,
+					resultCallback);
+#ifndef	DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
+				if (dbvt)
 				{
 				{
-					btTransform childTrans = compoundShape->getChildTransform(i);
-					const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
-					btTransform childWorldTrans = colObjWorldTransform * childTrans;
-					// replace collision shape so that callback can determine the triangle
-					btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape();
-					collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
-					rayTestSingle(rayFromTrans,rayToTrans,
-						collisionObject,
-						childCollisionShape,
-						childWorldTrans,
-						resultCallback);
-					// restore
-					collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
+					btVector3 localRayFrom = colObjWorldTransform.inverseTimes(rayFromTrans).getOrigin();
+					btVector3 localRayTo = colObjWorldTransform.inverseTimes(rayToTrans).getOrigin();
+					btDbvt::rayTest(dbvt->m_root, localRayFrom , localRayTo, rayCB);
+				}
+				else
+#endif //DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
+				{
+					for (int i = 0, n = compoundShape->getNumChildShapes(); i < n; ++i)
+					{
+						rayCB.ProcessLeaf(i);
+					}	
 				}
 				}
 			}
 			}
 		}
 		}
@@ -428,11 +589,22 @@ void	btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTra
 }
 }
 
 
 void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
 void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
-					  btCollisionObject* collisionObject,
-					  const btCollisionShape* collisionShape,
-					  const btTransform& colObjWorldTransform,
-					  ConvexResultCallback& resultCallback, btScalar allowedPenetration)
+											btCollisionObject* collisionObject,
+											const btCollisionShape* collisionShape,
+											const btTransform& colObjWorldTransform,
+											ConvexResultCallback& resultCallback, btScalar allowedPenetration)
 {
 {
+	btCollisionObjectWrapper tmpOb(0,collisionShape,collisionObject,colObjWorldTransform,-1,-1);
+	btCollisionWorld::objectQuerySingleInternal(castShape,convexFromTrans,convexToTrans,&tmpOb,resultCallback,allowedPenetration);
+}
+
+void	btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans,
+											const btCollisionObjectWrapper* colObjWrap,
+											ConvexResultCallback& resultCallback, btScalar allowedPenetration)
+{
+	const btCollisionShape* collisionShape = colObjWrap->getCollisionShape();
+	const btTransform& colObjWorldTransform = colObjWrap->getWorldTransform();
+
 	if (collisionShape->isConvex())
 	if (collisionShape->isConvex())
 	{
 	{
 		//BT_PROFILE("convexSweepConvex");
 		//BT_PROFILE("convexSweepConvex");
@@ -443,15 +615,15 @@ void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 		btConvexShape* convexShape = (btConvexShape*) collisionShape;
 		btConvexShape* convexShape = (btConvexShape*) collisionShape;
 		btVoronoiSimplexSolver	simplexSolver;
 		btVoronoiSimplexSolver	simplexSolver;
 		btGjkEpaPenetrationDepthSolver	gjkEpaPenetrationSolver;
 		btGjkEpaPenetrationDepthSolver	gjkEpaPenetrationSolver;
-		
+
 		btContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver);
 		btContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver);
 		//btGjkConvexCast convexCaster2(castShape,convexShape,&simplexSolver);
 		//btGjkConvexCast convexCaster2(castShape,convexShape,&simplexSolver);
 		//btSubsimplexConvexCast convexCaster3(castShape,convexShape,&simplexSolver);
 		//btSubsimplexConvexCast convexCaster3(castShape,convexShape,&simplexSolver);
 
 
 		btConvexCast* castPtr = &convexCaster1;
 		btConvexCast* castPtr = &convexCaster1;
-	
-	
-		
+
+
+
 		if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
 		if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
 		{
 		{
 			//add hit
 			//add hit
@@ -461,13 +633,13 @@ void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 				{
 				{
 					castResult.m_normal.normalize();
 					castResult.m_normal.normalize();
 					btCollisionWorld::LocalConvexResult localConvexResult
 					btCollisionWorld::LocalConvexResult localConvexResult
-								(
-									collisionObject,
-									0,
-									castResult.m_normal,
-									castResult.m_hitPoint,
-									castResult.m_fraction
-								);
+						(
+						colObjWrap->getCollisionObject(),
+						0,
+						castResult.m_normal,
+						castResult.m_hitPoint,
+						castResult.m_fraction
+						);
 
 
 					bool normalInWorldSpace = true;
 					bool normalInWorldSpace = true;
 					resultCallback.addSingleResult(localConvexResult, normalInWorldSpace);
 					resultCallback.addSingleResult(localConvexResult, normalInWorldSpace);
@@ -492,17 +664,17 @@ void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 				struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
 				struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
 				{
 				{
 					btCollisionWorld::ConvexResultCallback* m_resultCallback;
 					btCollisionWorld::ConvexResultCallback* m_resultCallback;
-					btCollisionObject*	m_collisionObject;
+					const btCollisionObject*	m_collisionObject;
 					btTriangleMeshShape*	m_triangleMesh;
 					btTriangleMeshShape*	m_triangleMesh;
 
 
 					BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
 					BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
-						btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape*	triangleMesh, const btTransform& triangleToWorld):
-						btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
-							m_resultCallback(resultCallback),
-							m_collisionObject(collisionObject),
-							m_triangleMesh(triangleMesh)
-						{
-						}
+						btCollisionWorld::ConvexResultCallback* resultCallback, const btCollisionObject* collisionObject,btTriangleMeshShape*	triangleMesh, const btTransform& triangleToWorld):
+					btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
+						m_resultCallback(resultCallback),
+						m_collisionObject(collisionObject),
+						m_triangleMesh(triangleMesh)
+					{
+					}
 
 
 
 
 					virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
 					virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
@@ -514,7 +686,7 @@ void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 						{
 						{
 
 
 							btCollisionWorld::LocalConvexResult convexResult
 							btCollisionWorld::LocalConvexResult convexResult
-							(m_collisionObject,
+								(m_collisionObject,
 								&shapeInfo,
 								&shapeInfo,
 								hitNormalLocal,
 								hitNormalLocal,
 								hitPointLocal,
 								hitPointLocal,
@@ -530,30 +702,65 @@ void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 
 
 				};
 				};
 
 
-				BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,triangleMesh, colObjWorldTransform);
+				BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,colObjWrap->getCollisionObject(),triangleMesh, colObjWorldTransform);
 				tccb.m_hitFraction = resultCallback.m_closestHitFraction;
 				tccb.m_hitFraction = resultCallback.m_closestHitFraction;
+				tccb.m_allowedPenetration = allowedPenetration;
 				btVector3 boxMinLocal, boxMaxLocal;
 				btVector3 boxMinLocal, boxMaxLocal;
 				castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
 				castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
 				triangleMesh->performConvexcast(&tccb,convexFromLocal,convexToLocal,boxMinLocal, boxMaxLocal);
 				triangleMesh->performConvexcast(&tccb,convexFromLocal,convexToLocal,boxMinLocal, boxMaxLocal);
 			} else
 			} else
 			{
 			{
-				//BT_PROFILE("convexSweepConcave");
-				btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
-				btTransform worldTocollisionObject = colObjWorldTransform.inverse();
-				btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
-				btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
-				// rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation
-				btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis());
+				if (collisionShape->getShapeType()==STATIC_PLANE_PROXYTYPE)
+				{
+					btConvexCast::CastResult castResult;
+					castResult.m_allowedPenetration = allowedPenetration;
+					castResult.m_fraction = resultCallback.m_closestHitFraction;
+					btStaticPlaneShape* planeShape = (btStaticPlaneShape*) collisionShape;
+					btContinuousConvexCollision convexCaster1(castShape,planeShape);
+					btConvexCast* castPtr = &convexCaster1;
+
+					if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult))
+					{
+						//add hit
+						if (castResult.m_normal.length2() > btScalar(0.0001))
+						{
+							if (castResult.m_fraction < resultCallback.m_closestHitFraction)
+							{
+								castResult.m_normal.normalize();
+								btCollisionWorld::LocalConvexResult localConvexResult
+									(
+									colObjWrap->getCollisionObject(),
+									0,
+									castResult.m_normal,
+									castResult.m_hitPoint,
+									castResult.m_fraction
+									);
 
 
-				//ConvexCast::CastResult
-				struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
+								bool normalInWorldSpace = true;
+								resultCallback.addSingleResult(localConvexResult, normalInWorldSpace);
+							}
+						}
+					}
+
+				} else
 				{
 				{
-					btCollisionWorld::ConvexResultCallback* m_resultCallback;
-					btCollisionObject*	m_collisionObject;
-					btConcaveShape*	m_triangleMesh;
+					//BT_PROFILE("convexSweepConcave");
+					btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
+					btTransform worldTocollisionObject = colObjWorldTransform.inverse();
+					btVector3 convexFromLocal = worldTocollisionObject * convexFromTrans.getOrigin();
+					btVector3 convexToLocal = worldTocollisionObject * convexToTrans.getOrigin();
+					// rotation of box in local mesh space = MeshRotation^-1 * ConvexToRotation
+					btTransform rotationXform = btTransform(worldTocollisionObject.getBasis() * convexToTrans.getBasis());
+
+					//ConvexCast::CastResult
+					struct BridgeTriangleConvexcastCallback : public btTriangleConvexcastCallback
+					{
+						btCollisionWorld::ConvexResultCallback* m_resultCallback;
+						const btCollisionObject*	m_collisionObject;
+						btConcaveShape*	m_triangleMesh;
 
 
-					BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
-						btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape*	triangleMesh, const btTransform& triangleToWorld):
+						BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to,
+							btCollisionWorld::ConvexResultCallback* resultCallback, const btCollisionObject* collisionObject,btConcaveShape*	triangleMesh, const btTransform& triangleToWorld):
 						btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
 						btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()),
 							m_resultCallback(resultCallback),
 							m_resultCallback(resultCallback),
 							m_collisionObject(collisionObject),
 							m_collisionObject(collisionObject),
@@ -562,65 +769,158 @@ void	btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const bt
 						}
 						}
 
 
 
 
-					virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
-					{
-						btCollisionWorld::LocalShapeInfo	shapeInfo;
-						shapeInfo.m_shapePart = partId;
-						shapeInfo.m_triangleIndex = triangleIndex;
-						if (hitFraction <= m_resultCallback->m_closestHitFraction)
+						virtual btScalar reportHit(const btVector3& hitNormalLocal, const btVector3& hitPointLocal, btScalar hitFraction, int partId, int triangleIndex )
 						{
 						{
+							btCollisionWorld::LocalShapeInfo	shapeInfo;
+							shapeInfo.m_shapePart = partId;
+							shapeInfo.m_triangleIndex = triangleIndex;
+							if (hitFraction <= m_resultCallback->m_closestHitFraction)
+							{
+
+								btCollisionWorld::LocalConvexResult convexResult
+									(m_collisionObject,
+									&shapeInfo,
+									hitNormalLocal,
+									hitPointLocal,
+									hitFraction);
+
+								bool	normalInWorldSpace = true;
+
+								return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace);
+							}
+							return hitFraction;
+						}
 
 
-							btCollisionWorld::LocalConvexResult convexResult
-							(m_collisionObject,
-								&shapeInfo,
-								hitNormalLocal,
-								hitPointLocal,
-								hitFraction);
+					};
+
+					BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,colObjWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
+					tccb.m_hitFraction = resultCallback.m_closestHitFraction;
+					tccb.m_allowedPenetration = allowedPenetration;
+					btVector3 boxMinLocal, boxMaxLocal;
+					castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
+
+					btVector3 rayAabbMinLocal = convexFromLocal;
+					rayAabbMinLocal.setMin(convexToLocal);
+					btVector3 rayAabbMaxLocal = convexFromLocal;
+					rayAabbMaxLocal.setMax(convexToLocal);
+					rayAabbMinLocal += boxMinLocal;
+					rayAabbMaxLocal += boxMaxLocal;
+					concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
+				}
+			}
+		} else {
+			if (collisionShape->isCompound())
+			{
+				struct	btCompoundLeafCallback : btDbvt::ICollide
+				{
+					btCompoundLeafCallback(
+										   const btCollisionObjectWrapper* colObjWrap,
+										   const btConvexShape* castShape,
+										   const btTransform& convexFromTrans,
+										   const btTransform& convexToTrans,
+										   btScalar allowedPenetration,
+										   const btCompoundShape* compoundShape,
+										   const btTransform& colObjWorldTransform,
+										   ConvexResultCallback& resultCallback)
+					: 
+					  m_colObjWrap(colObjWrap),
+						m_castShape(castShape),
+						m_convexFromTrans(convexFromTrans),
+						m_convexToTrans(convexToTrans),
+						m_allowedPenetration(allowedPenetration),
+						m_compoundShape(compoundShape),
+						m_colObjWorldTransform(colObjWorldTransform),
+						m_resultCallback(resultCallback) {
+					}
 
 
-							bool	normalInWorldSpace = false;
+				  const btCollisionObjectWrapper* m_colObjWrap;
+					const btConvexShape* m_castShape;
+					const btTransform& m_convexFromTrans;
+					const btTransform& m_convexToTrans;
+					btScalar m_allowedPenetration;
+					const btCompoundShape* m_compoundShape;
+					const btTransform& m_colObjWorldTransform;
+					ConvexResultCallback& m_resultCallback;
 
 
-							return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace);
-						}
-						return hitFraction;
+				public:
+
+					void		ProcessChild(int index, const btTransform& childTrans, const btCollisionShape* childCollisionShape)
+					{
+						btTransform childWorldTrans = m_colObjWorldTransform * childTrans;
+
+						struct	LocalInfoAdder : public ConvexResultCallback {
+							ConvexResultCallback* m_userCallback;
+							int m_i;
+
+							LocalInfoAdder(int i, ConvexResultCallback *user)
+								: m_userCallback(user), m_i(i)
+							{
+								m_closestHitFraction = m_userCallback->m_closestHitFraction;
+							}
+							virtual bool needsCollision(btBroadphaseProxy* p) const
+							{
+								return m_userCallback->needsCollision(p);
+							}
+							virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult&	r, bool b)
+							{
+								btCollisionWorld::LocalShapeInfo	shapeInfo;
+								shapeInfo.m_shapePart = -1;
+								shapeInfo.m_triangleIndex = m_i;
+								if (r.m_localShapeInfo == NULL)
+									r.m_localShapeInfo = &shapeInfo;
+								const btScalar result = m_userCallback->addSingleResult(r, b);
+								m_closestHitFraction = m_userCallback->m_closestHitFraction;
+								return result;
+
+							}
+						};
+
+						LocalInfoAdder my_cb(index, &m_resultCallback);
+
+						btCollisionObjectWrapper tmpObj(m_colObjWrap, childCollisionShape, m_colObjWrap->getCollisionObject(), childWorldTrans, -1, index);
+
+						objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, &tmpObj, my_cb, m_allowedPenetration);
 					}
 					}
 
 
-				};
+					void		Process(const btDbvtNode* leaf)
+					{
+						// Processing leaf node
+						int index = leaf->dataAsInt;
 
 
-				BridgeTriangleConvexcastCallback tccb(castShape, convexFromTrans,convexToTrans,&resultCallback,collisionObject,concaveShape, colObjWorldTransform);
-				tccb.m_hitFraction = resultCallback.m_closestHitFraction;
-				btVector3 boxMinLocal, boxMaxLocal;
-				castShape->getAabb(rotationXform, boxMinLocal, boxMaxLocal);
+						btTransform childTrans = m_compoundShape->getChildTransform(index);
+						const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index);
+
+						ProcessChild(index, childTrans, childCollisionShape);
+					}
+				};
 
 
-				btVector3 rayAabbMinLocal = convexFromLocal;
-				rayAabbMinLocal.setMin(convexToLocal);
-				btVector3 rayAabbMaxLocal = convexFromLocal;
-				rayAabbMaxLocal.setMax(convexToLocal);
-				rayAabbMinLocal += boxMinLocal;
-				rayAabbMaxLocal += boxMaxLocal;
-				concaveShape->processAllTriangles(&tccb,rayAabbMinLocal,rayAabbMaxLocal);
-			}
-		} else {
-			///@todo : use AABB tree or other BVH acceleration structure!
-			if (collisionShape->isCompound())
-			{
 				BT_PROFILE("convexSweepCompound");
 				BT_PROFILE("convexSweepCompound");
 				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
 				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
-				int i=0;
-				for (i=0;i<compoundShape->getNumChildShapes();i++)
-				{
-					btTransform childTrans = compoundShape->getChildTransform(i);
-					const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
-					btTransform childWorldTrans = colObjWorldTransform * childTrans;
-					// replace collision shape so that callback can determine the triangle
-					btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape();
-					collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape);
-					objectQuerySingle(castShape, convexFromTrans,convexToTrans,
-						collisionObject,
-						childCollisionShape,
-						childWorldTrans,
-						resultCallback, allowedPenetration);
-					// restore
-					collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape);
+
+				btVector3 fromLocalAabbMin, fromLocalAabbMax;
+				btVector3 toLocalAabbMin, toLocalAabbMax;
+
+				castShape->getAabb(colObjWorldTransform.inverse() * convexFromTrans, fromLocalAabbMin, fromLocalAabbMax);
+				castShape->getAabb(colObjWorldTransform.inverse() * convexToTrans, toLocalAabbMin, toLocalAabbMax);
+
+				fromLocalAabbMin.setMin(toLocalAabbMin);
+				fromLocalAabbMax.setMax(toLocalAabbMax);
+
+				btCompoundLeafCallback callback(colObjWrap, castShape, convexFromTrans, convexToTrans,
+					  allowedPenetration, compoundShape, colObjWorldTransform, resultCallback);
+
+				const btDbvt* tree = compoundShape->getDynamicAabbTree();
+				if (tree) {
+					const ATTRIBUTE_ALIGNED16(btDbvtVolume)	bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax);
+					tree->collideTV(tree->m_root, bounds, callback);
+				} else {
+					int i;
+					for (i=0;i<compoundShape->getNumChildShapes();i++)
+					{
+						const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
+						btTransform childTrans = compoundShape->getChildTransform(i);
+						callback.ProcessChild(i, childTrans, childCollisionShape);
+					}
 				}
 				}
 			}
 			}
 		}
 		}
@@ -641,10 +941,10 @@ struct btSingleRayCallback : public btBroadphaseRayCallback
 	btCollisionWorld::RayResultCallback&	m_resultCallback;
 	btCollisionWorld::RayResultCallback&	m_resultCallback;
 
 
 	btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback)
 	btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback)
-	:m_rayFromWorld(rayFromWorld),
-	m_rayToWorld(rayToWorld),
-	m_world(world),
-	m_resultCallback(resultCallback)
+		:m_rayFromWorld(rayFromWorld),
+		m_rayToWorld(rayToWorld),
+		m_world(world),
+		m_resultCallback(resultCallback)
 	{
 	{
 		m_rayFromTrans.setIdentity();
 		m_rayFromTrans.setIdentity();
 		m_rayFromTrans.setOrigin(m_rayFromWorld);
 		m_rayFromTrans.setOrigin(m_rayFromWorld);
@@ -666,7 +966,7 @@ struct btSingleRayCallback : public btBroadphaseRayCallback
 
 
 	}
 	}
 
 
-	
+
 
 
 	virtual bool	process(const btBroadphaseProxy* proxy)
 	virtual bool	process(const btBroadphaseProxy* proxy)
 	{
 	{
@@ -697,9 +997,9 @@ struct btSingleRayCallback : public btBroadphaseRayCallback
 			{
 			{
 				m_world->rayTestSingle(m_rayFromTrans,m_rayToTrans,
 				m_world->rayTestSingle(m_rayFromTrans,m_rayToTrans,
 					collisionObject,
 					collisionObject,
-						collisionObject->getCollisionShape(),
-						collisionObject->getWorldTransform(),
-						m_resultCallback);
+					collisionObject->getCollisionShape(),
+					collisionObject->getWorldTransform(),
+					m_resultCallback);
 			}
 			}
 		}
 		}
 		return true;
 		return true;
@@ -771,13 +1071,13 @@ struct btSingleSweepCallback : public btBroadphaseRayCallback
 		if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) {
 		if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) {
 			//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
 			//RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject();
 			m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans,
 			m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans,
-					collisionObject,
-						collisionObject->getCollisionShape(),
-						collisionObject->getWorldTransform(),
-						m_resultCallback,
-						m_allowedCcdPenetration);
+				collisionObject,
+				collisionObject->getCollisionShape(),
+				collisionObject->getWorldTransform(),
+				m_resultCallback,
+				m_allowedCcdPenetration);
 		}
 		}
-		
+
 		return true;
 		return true;
 	}
 	}
 };
 };
@@ -792,7 +1092,7 @@ void	btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btT
 	/// and for each object with ray-aabb overlap, perform an exact ray test
 	/// and for each object with ray-aabb overlap, perform an exact ray test
 	/// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical
 	/// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical
 
 
-	
+
 
 
 	btTransform	convexFromTrans,convexToTrans;
 	btTransform	convexFromTrans,convexToTrans;
 	convexFromTrans = convexFromWorld;
 	convexFromTrans = convexFromWorld;
@@ -801,13 +1101,13 @@ void	btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btT
 	/* 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.0f, linVel, angVel);
 		btVector3 zeroLinVel;
 		btVector3 zeroLinVel;
 		zeroLinVel.setValue(0,0,0);
 		zeroLinVel.setValue(0,0,0);
 		btTransform R;
 		btTransform R;
 		R.setIdentity ();
 		R.setIdentity ();
 		R.setRotation (convexFromTrans.getRotation());
 		R.setRotation (convexFromTrans.getRotation());
-		castShape->calculateTemporalAabb (R, zeroLinVel, angVel, 1.0, castShapeAabbMin, castShapeAabbMax);
+		castShape->calculateTemporalAabb (R, zeroLinVel, angVel, 1.0f, castShapeAabbMin, castShapeAabbMax);
 	}
 	}
 
 
 #ifndef USE_BRUTEFORCE_RAYBROADPHASE
 #ifndef USE_BRUTEFORCE_RAYBROADPHASE
@@ -835,12 +1135,514 @@ void	btCollisionWorld::convexSweepTest(const btConvexShape* castShape, const btT
 			{
 			{
 				objectQuerySingle(castShape, convexFromTrans,convexToTrans,
 				objectQuerySingle(castShape, convexFromTrans,convexToTrans,
 					collisionObject,
 					collisionObject,
-						collisionObject->getCollisionShape(),
-						collisionObject->getWorldTransform(),
-						resultCallback,
-						allowedCcdPenetration);
+					collisionObject->getCollisionShape(),
+					collisionObject->getWorldTransform(),
+					resultCallback,
+					allowedCcdPenetration);
 			}
 			}
 		}
 		}
 	}
 	}
 #endif //USE_BRUTEFORCE_RAYBROADPHASE
 #endif //USE_BRUTEFORCE_RAYBROADPHASE
 }
 }
+
+
+
+struct btBridgedManifoldResult : public btManifoldResult
+{
+
+	btCollisionWorld::ContactResultCallback&	m_resultCallback;
+
+	btBridgedManifoldResult( const btCollisionObjectWrapper* obj0Wrap,const btCollisionObjectWrapper* obj1Wrap,btCollisionWorld::ContactResultCallback& resultCallback )
+		:btManifoldResult(obj0Wrap,obj1Wrap),
+		m_resultCallback(resultCallback)
+	{
+	}
+
+	virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)
+	{
+		bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
+		btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
+		btVector3 localA;
+		btVector3 localB;
+		if (isSwapped)
+		{
+			localA = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+			localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
+		} else
+		{
+			localA = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+			localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
+		}
+		
+		btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
+		newPt.m_positionWorldOnA = pointA;
+		newPt.m_positionWorldOnB = pointInWorld;
+		
+	   //BP mod, store contact triangles.
+		if (isSwapped)
+		{
+			newPt.m_partId0 = m_partId1;
+			newPt.m_partId1 = m_partId0;
+			newPt.m_index0  = m_index1;
+			newPt.m_index1  = m_index0;
+		} else
+		{
+			newPt.m_partId0 = m_partId0;
+			newPt.m_partId1 = m_partId1;
+			newPt.m_index0  = m_index0;
+			newPt.m_index1  = m_index1;
+		}
+
+		//experimental feature info, for per-triangle material etc.
+		const btCollisionObjectWrapper* obj0Wrap = isSwapped? m_body1Wrap : m_body0Wrap;
+		const btCollisionObjectWrapper* obj1Wrap = isSwapped? m_body0Wrap : m_body1Wrap;
+		m_resultCallback.addSingleResult(newPt,obj0Wrap,newPt.m_partId0,newPt.m_index0,obj1Wrap,newPt.m_partId1,newPt.m_index1);
+
+	}
+	
+};
+
+
+
+struct btSingleContactCallback : public btBroadphaseAabbCallback
+{
+
+	btCollisionObject* m_collisionObject;
+	btCollisionWorld*	m_world;
+	btCollisionWorld::ContactResultCallback&	m_resultCallback;
+	
+	
+	btSingleContactCallback(btCollisionObject* collisionObject, btCollisionWorld* world,btCollisionWorld::ContactResultCallback& resultCallback)
+		:m_collisionObject(collisionObject),
+		m_world(world),
+		m_resultCallback(resultCallback)
+	{
+	}
+
+	virtual bool	process(const btBroadphaseProxy* proxy)
+	{
+		btCollisionObject*	collisionObject = (btCollisionObject*)proxy->m_clientObject;
+		if (collisionObject == m_collisionObject)
+			return true;
+
+		//only perform raycast if filterMask matches
+		if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 
+		{
+			btCollisionObjectWrapper ob0(0,m_collisionObject->getCollisionShape(),m_collisionObject,m_collisionObject->getWorldTransform(),-1,-1);
+			btCollisionObjectWrapper ob1(0,collisionObject->getCollisionShape(),collisionObject,collisionObject->getWorldTransform(),-1,-1);
+
+			btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(&ob0,&ob1,0, BT_CLOSEST_POINT_ALGORITHMS);
+			if (algorithm)
+			{
+				btBridgedManifoldResult contactPointResult(&ob0,&ob1, m_resultCallback);
+				//discrete collision detection query
+				
+				algorithm->processCollision(&ob0,&ob1, m_world->getDispatchInfo(),&contactPointResult);
+
+				algorithm->~btCollisionAlgorithm();
+				m_world->getDispatcher()->freeCollisionAlgorithm(algorithm);
+			}
+		}
+		return true;
+	}
+};
+
+
+///contactTest performs a discrete collision test 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)
+void	btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCallback& resultCallback)
+{
+	btVector3 aabbMin,aabbMax;
+	colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax);
+	btSingleContactCallback	contactCB(colObj,this,resultCallback);
+	
+	m_broadphasePairCache->aabbTest(aabbMin,aabbMax,contactCB);
+}
+
+
+///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)
+void	btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback)
+{
+	btCollisionObjectWrapper obA(0,colObjA->getCollisionShape(),colObjA,colObjA->getWorldTransform(),-1,-1);
+	btCollisionObjectWrapper obB(0,colObjB->getCollisionShape(),colObjB,colObjB->getWorldTransform(),-1,-1);
+
+	btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(&obA,&obB, 0, BT_CLOSEST_POINT_ALGORITHMS);
+	if (algorithm)
+	{
+		btBridgedManifoldResult contactPointResult(&obA,&obB, resultCallback);
+		contactPointResult.m_closestPointDistanceThreshold = resultCallback.m_closestDistanceThreshold;
+		//discrete collision detection query
+		algorithm->processCollision(&obA,&obB, getDispatchInfo(),&contactPointResult);
+
+		algorithm->~btCollisionAlgorithm();
+		getDispatcher()->freeCollisionAlgorithm(algorithm);
+	}
+
+}
+
+
+
+
+class DebugDrawcallback : public btTriangleCallback, public btInternalTriangleIndexCallback
+{
+	btIDebugDraw*	m_debugDrawer;
+	btVector3	m_color;
+	btTransform	m_worldTrans;
+
+public:
+
+	DebugDrawcallback(btIDebugDraw*	debugDrawer,const btTransform& worldTrans,const btVector3& color) :
+	  m_debugDrawer(debugDrawer),
+		  m_color(color),
+		  m_worldTrans(worldTrans)
+	  {
+	  }
+
+	  virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int  triangleIndex)
+	  {
+		  processTriangle(triangle,partId,triangleIndex);
+	  }
+
+	  virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)
+	  {
+		  (void)partId;
+		  (void)triangleIndex;
+
+		  btVector3 wv0,wv1,wv2;
+		  wv0 = m_worldTrans*triangle[0];
+		  wv1 = m_worldTrans*triangle[1];
+		  wv2 = m_worldTrans*triangle[2];
+		  btVector3 center = (wv0+wv1+wv2)*btScalar(1./3.);
+          
+          if (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawNormals )
+          {
+		    btVector3 normal = (wv1-wv0).cross(wv2-wv0);
+		    normal.normalize();
+		    btVector3 normalColor(1,1,0);
+		    m_debugDrawer->drawLine(center,center+normal,normalColor);
+          }
+		  m_debugDrawer->drawLine(wv0,wv1,m_color);
+		  m_debugDrawer->drawLine(wv1,wv2,m_color);
+		  m_debugDrawer->drawLine(wv2,wv0,m_color);
+	  }
+};
+
+
+void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
+{
+	// Draw a small simplex at the center of the object
+	if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawFrames)
+	{
+		getDebugDrawer()->drawTransform(worldTransform,1);
+	}
+
+	if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
+	{
+		const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);
+		for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--)
+		{
+			btTransform childTrans = compoundShape->getChildTransform(i);
+			const btCollisionShape* colShape = compoundShape->getChildShape(i);
+			debugDrawObject(worldTransform*childTrans,colShape,color);
+		}
+
+	} else
+	{
+
+        switch (shape->getShapeType())
+        {
+
+        case BOX_SHAPE_PROXYTYPE:
+            {
+                const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape);
+                btVector3 halfExtents = boxShape->getHalfExtentsWithMargin();
+                getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color);
+                break;
+            }
+
+        case SPHERE_SHAPE_PROXYTYPE:
+            {
+                const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);
+                btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin
+
+                getDebugDrawer()->drawSphere(radius, worldTransform, color);
+                break;
+            }
+        case MULTI_SPHERE_SHAPE_PROXYTYPE:
+            {
+                const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);
+
+                btTransform childTransform;
+                childTransform.setIdentity();
+
+                for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)
+                {
+                    childTransform.setOrigin(multiSphereShape->getSpherePosition(i));
+                    getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color);
+                }
+
+                break;
+            }
+        case CAPSULE_SHAPE_PROXYTYPE:
+            {
+                const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);
+
+                btScalar radius = capsuleShape->getRadius();
+                btScalar halfHeight = capsuleShape->getHalfHeight();
+
+                int upAxis = capsuleShape->getUpAxis();
+                getDebugDrawer()->drawCapsule(radius, halfHeight, upAxis, worldTransform, color);
+                break;
+            }
+        case CONE_SHAPE_PROXYTYPE:
+            {
+                const btConeShape* coneShape = static_cast<const btConeShape*>(shape);
+                btScalar radius = coneShape->getRadius();//+coneShape->getMargin();
+                btScalar height = coneShape->getHeight();//+coneShape->getMargin();
+
+                int upAxis= coneShape->getConeUpIndex();
+                getDebugDrawer()->drawCone(radius, height, upAxis, worldTransform, color);
+                break;
+
+            }
+        case CYLINDER_SHAPE_PROXYTYPE:
+            {
+                const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);
+                int upAxis = cylinder->getUpAxis();
+                btScalar radius = cylinder->getRadius();
+                btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];
+                getDebugDrawer()->drawCylinder(radius, halfHeight, upAxis, worldTransform, color);
+                break;
+            }
+
+        case STATIC_PLANE_PROXYTYPE:
+            {
+                const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);
+                btScalar planeConst = staticPlaneShape->getPlaneConstant();
+                const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();
+                getDebugDrawer()->drawPlane(planeNormal, planeConst,worldTransform, color);
+                break;
+
+            }
+        default:
+            {
+
+                /// for polyhedral shapes
+                if (shape->isPolyhedral())
+                {
+                    btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;
+                    
+                    int i;
+                    if (polyshape->getConvexPolyhedron())
+                    {
+                        const btConvexPolyhedron* poly = polyshape->getConvexPolyhedron();
+                        for (i=0;i<poly->m_faces.size();i++)
+                        {
+                            btVector3 centroid(0,0,0);
+                            int numVerts = poly->m_faces[i].m_indices.size();
+                            if (numVerts)
+                            {
+                                int lastV = poly->m_faces[i].m_indices[numVerts-1];
+                                for (int v=0;v<poly->m_faces[i].m_indices.size();v++)
+                                {
+                                    int curVert = poly->m_faces[i].m_indices[v];
+                                    centroid+=poly->m_vertices[curVert];
+                                    getDebugDrawer()->drawLine(worldTransform*poly->m_vertices[lastV],worldTransform*poly->m_vertices[curVert],color);
+                                    lastV = curVert;
+                                }
+                            }
+                            centroid*= btScalar(1.f)/btScalar(numVerts);
+                            if (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawNormals)
+                            {
+                                btVector3 normalColor(1,1,0);
+                                btVector3 faceNormal(poly->m_faces[i].m_plane[0],poly->m_faces[i].m_plane[1],poly->m_faces[i].m_plane[2]);
+                                getDebugDrawer()->drawLine(worldTransform*centroid,worldTransform*(centroid+faceNormal),normalColor);
+                            }
+                            
+                        }
+                        
+                        
+                    } else
+                    {
+                        for (i=0;i<polyshape->getNumEdges();i++)
+                        {
+                            btVector3 a,b;
+                            polyshape->getEdge(i,a,b);
+                            btVector3 wa = worldTransform * a;
+                            btVector3 wb = worldTransform * b;
+                            getDebugDrawer()->drawLine(wa,wb,color);
+                        }
+                    }
+                    
+                    
+                }
+                    
+                if (shape->isConcave())
+                {
+                    btConcaveShape* concaveMesh = (btConcaveShape*) shape;
+
+                    ///@todo pass camera, for some culling? no -> we are not a graphics lib
+                    btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
+                    btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
+
+                    DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
+                    concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);
+
+                }
+
+                if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)
+                {
+                    btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;
+                    //todo: pass camera for some culling			
+                    btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT));
+                    btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT));
+                    //DebugDrawcallback drawCallback;
+                    DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);
+                    convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);
+                }
+
+
+                
+            }
+       
+		}
+	}
+}
+
+
+void	btCollisionWorld::debugDrawWorld()
+{
+	if (getDebugDrawer())
+	{
+		btIDebugDraw::DefaultColors defaultColors = getDebugDrawer()->getDefaultColors();
+
+		if ( getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
+		{
+		
+
+			if (getDispatcher())
+			{
+				int numManifolds = getDispatcher()->getNumManifolds();
+			
+				for (int i=0;i<numManifolds;i++)
+				{
+					btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i);
+					//btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
+					//btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
+
+					int numContacts = contactManifold->getNumContacts();
+					for (int j=0;j<numContacts;j++)
+					{
+						btManifoldPoint& cp = contactManifold->getContactPoint(j);
+						getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),defaultColors.m_contactPoint);
+					}
+				}
+			}
+		}
+
+		if ((getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
+		{
+			int i;
+
+			for (  i=0;i<m_collisionObjects.size();i++)
+			{
+				btCollisionObject* colObj = m_collisionObjects[i];
+				if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
+				{
+					if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
+					{
+						btVector3 color(btScalar(0.4),btScalar(0.4),btScalar(0.4));
+
+						switch(colObj->getActivationState())
+						{
+						case  ACTIVE_TAG:
+							color = defaultColors.m_activeObject; break;
+						case ISLAND_SLEEPING:
+							color =  defaultColors.m_deactivatedObject;break;
+						case WANTS_DEACTIVATION:
+							color = defaultColors.m_wantsDeactivationObject;break;
+						case DISABLE_DEACTIVATION:
+							color = defaultColors.m_disabledDeactivationObject;break;
+						case DISABLE_SIMULATION:
+							color = defaultColors.m_disabledSimulationObject;break;
+						default:
+							{
+								color = btVector3(btScalar(.3),btScalar(0.3),btScalar(0.3));
+							}
+						};
+
+						colObj->getCustomDebugColor(color);
+
+						debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
+					}
+					if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
+					{
+						btVector3 minAabb,maxAabb;
+						btVector3 colorvec = defaultColors.m_aabb;
+						colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
+						btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
+						minAabb -= contactThreshold;
+						maxAabb += contactThreshold;
+
+						btVector3 minAabb2,maxAabb2;
+
+						if(getDispatchInfo().m_useContinuous && colObj->getInternalType()==btCollisionObject::CO_RIGID_BODY && !colObj->isStaticOrKinematicObject())
+						{
+							colObj->getCollisionShape()->getAabb(colObj->getInterpolationWorldTransform(),minAabb2,maxAabb2);
+							minAabb2 -= contactThreshold;
+							maxAabb2 += contactThreshold;
+							minAabb.setMin(minAabb2);
+							maxAabb.setMax(maxAabb2);
+						}
+
+						m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
+					}
+				}
+			}
+		}
+	}
+}
+
+
+void	btCollisionWorld::serializeCollisionObjects(btSerializer* serializer)
+{
+	int i;
+
+	///keep track of shapes already serialized
+	btHashMap<btHashPtr,btCollisionShape*>	serializedShapes;
+
+	for (i=0;i<m_collisionObjects.size();i++)
+	{
+		btCollisionObject* colObj = m_collisionObjects[i];
+		btCollisionShape* shape = colObj->getCollisionShape();
+
+		if (!serializedShapes.find(shape))
+		{
+			serializedShapes.insert(shape,shape);
+			shape->serializeSingleShape(serializer);
+		}
+	}
+
+	//serialize all collision objects
+	for (i=0;i<m_collisionObjects.size();i++)
+	{
+		btCollisionObject* colObj = m_collisionObjects[i];
+		if ((colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT) || (colObj->getInternalType() == btCollisionObject::CO_FEATHERSTONE_LINK))
+		{
+			colObj->serializeSingleObject(serializer);
+		}
+	}
+}
+
+
+void	btCollisionWorld::serialize(btSerializer* serializer)
+{
+
+	serializer->startSerialization();
+	
+	serializeCollisionObjects(serializer);
+	
+	serializer->finishSerialization();
+}
+

+ 139 - 33
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.h

@@ -1,6 +1,6 @@
 /*
 /*
 Bullet Continuous Collision Detection and Physics Library
 Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans  http://bulletphysics.com/Bullet/
+Copyright (c) 2003-2013 Erwin Coumans  http://bulletphysics.org
 
 
 This software is provided 'as-is', without any express or implied warranty.
 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.
 In no event will the authors be held liable for any damages arising from the use of this software.
@@ -18,25 +18,35 @@ subject to the following restrictions:
  * @mainpage Bullet Documentation
  * @mainpage Bullet Documentation
  *
  *
  * @section intro_sec Introduction
  * @section intro_sec Introduction
- * Bullet Collision Detection & Physics SDK
- *
  * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ).
  * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ).
  *
  *
+ * The main documentation is Bullet_User_Manual.pdf, included in the source code distribution.
  * There is the Physics Forum for feedback and general Collision Detection and Physics discussions.
  * There is the Physics Forum for feedback and general Collision Detection and Physics discussions.
- * Please visit http://www.bulletphysics.com
+ * Please visit http://www.bulletphysics.org
  *
  *
  * @section install_sec Installation
  * @section install_sec Installation
  *
  *
  * @subsection step1 Step 1: Download
  * @subsection step1 Step 1: Download
- * You can download the Bullet Physics Library from the Google Code repository: http://code.google.com/p/bullet/downloads/list
+ * You can download the Bullet Physics Library from the github repository: https://github.com/bulletphysics/bullet3/releases 
+ *
  * @subsection step2 Step 2: Building
  * @subsection step2 Step 2: Building
- * Bullet comes with autogenerated Project Files for Microsoft Visual Studio 6, 7, 7.1 and 8.
- * The main Workspace/Solution is located in Bullet/msvc/8/wksbullet.sln (replace 8 with your version).
+ * Bullet has multiple build systems, including premake, cmake and autotools. Premake and cmake support all platforms.
+ * Premake is included in the Bullet/build folder for Windows, Mac OSX and Linux. 
+ * Under Windows you can click on Bullet/build/vs2010.bat to create Microsoft Visual Studio projects. 
+ * On Mac OSX and Linux you can open a terminal and generate Makefile, codeblocks or Xcode4 projects:
+ * cd Bullet/build
+ * ./premake4_osx gmake or ./premake4_linux gmake or ./premake4_linux64 gmake or (for Mac) ./premake4_osx xcode4
+ * cd Bullet/build/gmake
+ * make
  * 
  * 
- * Under other platforms, like Linux or Mac OS-X, Bullet can be build using either using make, cmake, http://www.cmake.org , or jam, http://www.perforce.com/jam/jam.html . cmake can autogenerate Xcode, KDevelop, MSVC and other build systems. just run cmake . in the root of Bullet.
- * So if you are not using MSVC or cmake, you can run ./autogen.sh ./configure to create both Makefile and Jamfile and then run make or jam.
- * Jam is a build system that can build the library, demos and also autogenerate the MSVC Project Files.
- * If you don't have jam installed, you can make jam from the included jam-2.5 sources, or download jam from ftp://ftp.perforce.com/jam
+ * An alternative to premake is cmake. You can download cmake from http://www.cmake.org
+ * cmake can autogenerate projectfiles for Microsoft Visual Studio, Apple Xcode, KDevelop and Unix Makefiles.
+ * The easiest is to run the CMake cmake-gui graphical user interface and choose the options and generate projectfiles.
+ * You can also use cmake in the command-line. Here are some examples for various platforms:
+ * cmake . -G "Visual Studio 9 2008"
+ * cmake . -G Xcode
+ * cmake . -G "Unix Makefiles"
+ * Although cmake is recommended, you can also use autotools for UNIX: ./autogen.sh ./configure to create a Makefile and then run make.
  * 
  * 
  * @subsection step3 Step 3: Testing demos
  * @subsection step3 Step 3: Testing demos
  * Try to run and experiment with BasicDemo executable as a starting point.
  * Try to run and experiment with BasicDemo executable as a starting point.
@@ -53,21 +63,20 @@ subject to the following restrictions:
  * Bullet has been designed in a modular way keeping dependencies to a minimum. The ConvexHullDistance demo demonstrates direct use of btGjkPairDetector.
  * Bullet has been designed in a modular way keeping dependencies to a minimum. The ConvexHullDistance demo demonstrates direct use of btGjkPairDetector.
  *
  *
  * @section copyright Copyright
  * @section copyright Copyright
- * Copyright (C) 2005-2008 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon
- * Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, John McCutchan, Nathanael Presson, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky,
- * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren, Marten Svanfeldt.
+ * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf
  * 
  * 
  */
  */
  
  
  
  
 
 
-#ifndef COLLISION_WORLD_H
-#define COLLISION_WORLD_H
+#ifndef BT_COLLISION_WORLD_H
+#define BT_COLLISION_WORLD_H
 
 
-class btStackAlloc;
 class btCollisionShape;
 class btCollisionShape;
 class btConvexShape;
 class btConvexShape;
 class btBroadphaseInterface;
 class btBroadphaseInterface;
+class btSerializer;
+
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btVector3.h"
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btTransform.h"
 #include "btCollisionObject.h"
 #include "btCollisionObject.h"
@@ -88,8 +97,6 @@ protected:
 
 
 	btDispatcherInfo	m_dispatchInfo;
 	btDispatcherInfo	m_dispatchInfo;
 
 
-	btStackAlloc*	m_stackAlloc;
-
 	btBroadphaseInterface*	m_broadphasePairCache;
 	btBroadphaseInterface*	m_broadphasePairCache;
 
 
 	btIDebugDraw*	m_debugDrawer;
 	btIDebugDraw*	m_debugDrawer;
@@ -98,6 +105,8 @@ protected:
 	///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);
+
 public:
 public:
 
 
 	//this constructor doesn't own the dispatcher and paircache/broadphase
 	//this constructor doesn't own the dispatcher and paircache/broadphase
@@ -139,6 +148,11 @@ public:
 	void	updateSingleAabb(btCollisionObject* colObj);
 	void	updateSingleAabb(btCollisionObject* colObj);
 
 
 	virtual void	updateAabbs();
 	virtual void	updateAabbs();
+
+	///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
+	virtual void	computeOverlappingPairs();
+
 	
 	
 	virtual void	setDebugDrawer(btIDebugDraw*	debugDrawer)
 	virtual void	setDebugDrawer(btIDebugDraw*	debugDrawer)
 	{
 	{
@@ -150,6 +164,10 @@ public:
 		return m_debugDrawer;
 		return m_debugDrawer;
 	}
 	}
 
 
+	virtual void	debugDrawWorld();
+
+	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
@@ -164,7 +182,7 @@ public:
 
 
 	struct	LocalRayResult
 	struct	LocalRayResult
 	{
 	{
-		LocalRayResult(btCollisionObject*	collisionObject, 
+		LocalRayResult(const btCollisionObject*	collisionObject, 
 			LocalShapeInfo*	localShapeInfo,
 			LocalShapeInfo*	localShapeInfo,
 			const btVector3&		hitNormalLocal,
 			const btVector3&		hitNormalLocal,
 			btScalar hitFraction)
 			btScalar hitFraction)
@@ -175,7 +193,7 @@ public:
 		{
 		{
 		}
 		}
 
 
-		btCollisionObject*		m_collisionObject;
+		const btCollisionObject*		m_collisionObject;
 		LocalShapeInfo*			m_localShapeInfo;
 		LocalShapeInfo*			m_localShapeInfo;
 		btVector3				m_hitNormalLocal;
 		btVector3				m_hitNormalLocal;
 		btScalar				m_hitFraction;
 		btScalar				m_hitFraction;
@@ -186,11 +204,11 @@ public:
 	struct	RayResultCallback
 	struct	RayResultCallback
 	{
 	{
 		btScalar	m_closestHitFraction;
 		btScalar	m_closestHitFraction;
-		btCollisionObject*		m_collisionObject;
+		const btCollisionObject*		m_collisionObject;
 		short int	m_collisionFilterGroup;
 		short int	m_collisionFilterGroup;
 		short int	m_collisionFilterMask;
 		short int	m_collisionFilterMask;
-      //@BP Mod - Custom flags, currently used to enable backface culling on tri-meshes, see btRaycastCallback
-      unsigned int m_flags;
+		//@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;
 
 
 		virtual ~RayResultCallback()
 		virtual ~RayResultCallback()
 		{
 		{
@@ -205,8 +223,8 @@ public:
 			m_collisionObject(0),
 			m_collisionObject(0),
 			m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
 			m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
 			m_collisionFilterMask(btBroadphaseProxy::AllFilter),
 			m_collisionFilterMask(btBroadphaseProxy::AllFilter),
-         //@BP Mod
-         m_flags(0)
+			//@BP Mod
+			m_flags(0)
 		{
 		{
 		}
 		}
 
 
@@ -255,10 +273,49 @@ public:
 		}
 		}
 	};
 	};
 
 
+	struct	AllHitsRayResultCallback : public RayResultCallback
+	{
+		AllHitsRayResultCallback(const btVector3&	rayFromWorld,const btVector3&	rayToWorld)
+		:m_rayFromWorld(rayFromWorld),
+		m_rayToWorld(rayToWorld)
+		{
+		}
+
+		btAlignedObjectArray<const btCollisionObject*>		m_collisionObjects;
+
+		btVector3	m_rayFromWorld;//used to calculate hitPointWorld from hitFraction
+		btVector3	m_rayToWorld;
+
+		btAlignedObjectArray<btVector3>	m_hitNormalWorld;
+		btAlignedObjectArray<btVector3>	m_hitPointWorld;
+		btAlignedObjectArray<btScalar> m_hitFractions;
+			
+		virtual	btScalar	addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace)
+		{
+			m_collisionObject = rayResult.m_collisionObject;
+			m_collisionObjects.push_back(rayResult.m_collisionObject);
+			btVector3 hitNormalWorld;
+			if (normalInWorldSpace)
+			{
+				hitNormalWorld = rayResult.m_hitNormalLocal;
+			} else
+			{
+				///need to transform normal into worldspace
+				hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;
+			}
+			m_hitNormalWorld.push_back(hitNormalWorld);
+			btVector3 hitPointWorld;
+			hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);
+			m_hitPointWorld.push_back(hitPointWorld);
+			m_hitFractions.push_back(rayResult.m_hitFraction);
+			return m_closestHitFraction;
+		}
+	};
+
 
 
 	struct LocalConvexResult
 	struct LocalConvexResult
 	{
 	{
-		LocalConvexResult(btCollisionObject*	hitCollisionObject, 
+		LocalConvexResult(const btCollisionObject*	hitCollisionObject, 
 			LocalShapeInfo*	localShapeInfo,
 			LocalShapeInfo*	localShapeInfo,
 			const btVector3&		hitNormalLocal,
 			const btVector3&		hitNormalLocal,
 			const btVector3&		hitPointLocal,
 			const btVector3&		hitPointLocal,
@@ -272,7 +329,7 @@ public:
 		{
 		{
 		}
 		}
 
 
-		btCollisionObject*		m_hitCollisionObject;
+		const btCollisionObject*		m_hitCollisionObject;
 		LocalShapeInfo*			m_localShapeInfo;
 		LocalShapeInfo*			m_localShapeInfo;
 		btVector3				m_hitNormalLocal;
 		btVector3				m_hitNormalLocal;
 		btVector3				m_hitPointLocal;
 		btVector3				m_hitPointLocal;
@@ -328,7 +385,7 @@ public:
 
 
 		btVector3	m_hitNormalWorld;
 		btVector3	m_hitNormalWorld;
 		btVector3	m_hitPointWorld;
 		btVector3	m_hitPointWorld;
-		btCollisionObject*	m_hitCollisionObject;
+		const btCollisionObject*	m_hitCollisionObject;
 		
 		
 		virtual	btScalar	addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace)
 		virtual	btScalar	addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace)
 		{
 		{
@@ -350,6 +407,36 @@ public:
 		}
 		}
 	};
 	};
 
 
+	///ContactResultCallback is used to report contact points
+	struct	ContactResultCallback
+	{
+		short int	m_collisionFilterGroup;
+		short int	m_collisionFilterMask;
+		btScalar	m_closestDistanceThreshold;
+
+		ContactResultCallback()
+			:m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
+			m_collisionFilterMask(btBroadphaseProxy::AllFilter),
+			m_closestDistanceThreshold(0)
+		{
+		}
+
+		virtual ~ContactResultCallback()
+		{
+		}
+		
+		virtual bool needsCollision(btBroadphaseProxy* proxy0) const
+		{
+			bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0;
+			collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask);
+			return collides;
+		}
+
+		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());
@@ -357,12 +444,20 @@ public:
 
 
 	/// 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.
-	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
-	// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.
+	/// 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.
 	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.
+	///it reports one or more contact points for every overlapping object (including the one with deepest penetration)
+	void	contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback);
+
+	///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)
+	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.
@@ -373,6 +468,10 @@ public:
 					  const btTransform& colObjWorldTransform,
 					  const btTransform& colObjWorldTransform,
 					  RayResultCallback& resultCallback);
 					  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,
 	static void	objectQuerySingle(const btConvexShape* castShape, const btTransform& rayFromTrans,const btTransform& rayToTrans,
 					  btCollisionObject* collisionObject,
 					  btCollisionObject* collisionObject,
@@ -380,6 +479,10 @@ public:
 					  const btTransform& colObjWorldTransform,
 					  const btTransform& colObjWorldTransform,
 					  ConvexResultCallback& resultCallback, btScalar	allowedPenetration);
 					  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,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);
 	virtual void	addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);
 
 
 	btCollisionObjectArray& getCollisionObjectArray()
 	btCollisionObjectArray& getCollisionObjectArray()
@@ -416,7 +519,10 @@ public:
 		m_forceUpdateAllAabbs = forceUpdateAllAabbs;
 		m_forceUpdateAllAabbs = forceUpdateAllAabbs;
 	}
 	}
 
 
+	///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo)
+	virtual	void	serialize(btSerializer* serializer);
+
 };
 };
 
 
 
 
-#endif //COLLISION_WORLD_H
+#endif //BT_COLLISION_WORLD_H

+ 1147 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp

@@ -0,0 +1,1147 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2014 Erwin Coumans  http://bulletphysics.org
+
+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 "btCollisionWorldImporter.h"
+#include "btBulletCollisionCommon.h"
+#include "LinearMath/btSerializer.h" //for btBulletSerializedArrays definition
+
+#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
+#include "BulletCollision/Gimpact/btGImpactShape.h"
+#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
+
+btCollisionWorldImporter::btCollisionWorldImporter(btCollisionWorld* world)
+:m_collisionWorld(world),
+m_verboseMode(0)
+{
+
+}
+
+btCollisionWorldImporter::~btCollisionWorldImporter()
+{
+}
+
+
+
+
+
+bool	btCollisionWorldImporter::convertAllObjects( btBulletSerializedArrays* arrays)
+{
+
+	m_shapeMap.clear();
+	m_bodyMap.clear();
+
+	int i;
+
+	for (i=0;i<arrays->m_bvhsDouble.size();i++)
+	{
+		btOptimizedBvh* bvh = createOptimizedBvh();
+		btQuantizedBvhDoubleData* bvhData = arrays->m_bvhsDouble[i];
+		bvh->deSerializeDouble(*bvhData);
+		m_bvhMap.insert(arrays->m_bvhsDouble[i],bvh);
+	}
+	for (i=0;i<arrays->m_bvhsFloat.size();i++)
+    {
+        btOptimizedBvh* bvh = createOptimizedBvh();
+   		btQuantizedBvhFloatData* bvhData = arrays->m_bvhsFloat[i];
+		bvh->deSerializeFloat(*bvhData);
+		m_bvhMap.insert(arrays->m_bvhsFloat[i],bvh);
+	}
+
+
+
+
+
+	for (i=0;i<arrays->m_colShapeData.size();i++)
+	{
+		btCollisionShapeData* shapeData = arrays->m_colShapeData[i];
+		btCollisionShape* shape = convertCollisionShape(shapeData);
+		if (shape)
+		{
+	//		printf("shapeMap.insert(%x,%x)\n",shapeData,shape);
+			m_shapeMap.insert(shapeData,shape);
+		}
+
+		if (shape&& shapeData->m_name)
+		{
+			char* newname = duplicateName(shapeData->m_name);
+			m_objectNameMap.insert(shape,newname);
+			m_nameShapeMap.insert(newname,shape);
+		}
+	}
+
+
+	for (i=0;i<arrays->m_collisionObjectDataDouble.size();i++)
+	{
+        btCollisionObjectDoubleData* colObjData = arrays->m_collisionObjectDataDouble[i];
+        btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape);
+        if (shapePtr && *shapePtr)
+        {
+            btTransform startTransform;
+            colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f;
+            startTransform.deSerializeDouble(colObjData->m_worldTransform);
+
+            btCollisionShape* shape = (btCollisionShape*)*shapePtr;
+            btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name);
+            body->setFriction(btScalar(colObjData->m_friction));
+            body->setRestitution(btScalar(colObjData->m_restitution));
+
+#ifdef USE_INTERNAL_EDGE_UTILITY
+            if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
+            {
+                btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape;
+                if (trimesh->getTriangleInfoMap())
+                {
+                    body->setCollisionFlags(body->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
+                }
+            }
+#endif //USE_INTERNAL_EDGE_UTILITY
+            m_bodyMap.insert(colObjData,body);
+        } else
+        {
+            printf("error: no shape found\n");
+        }
+	}
+	for (i=0;i<arrays->m_collisionObjectDataFloat.size();i++)
+	{
+        btCollisionObjectFloatData* colObjData = arrays->m_collisionObjectDataFloat[i];
+        btCollisionShape** shapePtr = m_shapeMap.find(colObjData->m_collisionShape);
+        if (shapePtr && *shapePtr)
+        {
+            btTransform startTransform;
+            colObjData->m_worldTransform.m_origin.m_floats[3] = 0.f;
+            startTransform.deSerializeFloat(colObjData->m_worldTransform);
+
+            btCollisionShape* shape = (btCollisionShape*)*shapePtr;
+            btCollisionObject* body = createCollisionObject(startTransform,shape,colObjData->m_name);
+
+#ifdef USE_INTERNAL_EDGE_UTILITY
+            if (shape->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)
+            {
+                btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)shape;
+                if (trimesh->getTriangleInfoMap())
+                {
+                    body->setCollisionFlags(body->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
+                }
+            }
+#endif //USE_INTERNAL_EDGE_UTILITY
+            m_bodyMap.insert(colObjData,body);
+        } else
+        {
+            printf("error: no shape found\n");
+        }
+    }
+
+	return true;
+}
+
+
+
+void btCollisionWorldImporter::deleteAllData()
+{
+	int i;
+
+	for (i=0;i<m_allocatedCollisionObjects.size();i++)
+	{
+		if(m_collisionWorld)
+			m_collisionWorld->removeCollisionObject(m_allocatedCollisionObjects[i]);
+		delete m_allocatedCollisionObjects[i];
+	}
+
+	m_allocatedCollisionObjects.clear();
+
+
+	for (i=0;i<m_allocatedCollisionShapes.size();i++)
+	{
+		delete m_allocatedCollisionShapes[i];
+	}
+	m_allocatedCollisionShapes.clear();
+
+
+	for (i=0;i<m_allocatedBvhs.size();i++)
+	{
+		delete m_allocatedBvhs[i];
+	}
+	m_allocatedBvhs.clear();
+
+	for (i=0;i<m_allocatedTriangleInfoMaps.size();i++)
+	{
+		delete m_allocatedTriangleInfoMaps[i];
+	}
+	m_allocatedTriangleInfoMaps.clear();
+	for (i=0;i<m_allocatedTriangleIndexArrays.size();i++)
+	{
+		delete m_allocatedTriangleIndexArrays[i];
+	}
+	m_allocatedTriangleIndexArrays.clear();
+	for (i=0;i<m_allocatedNames.size();i++)
+	{
+		delete[] m_allocatedNames[i];
+	}
+	m_allocatedNames.clear();
+
+	for (i=0;i<m_allocatedbtStridingMeshInterfaceDatas.size();i++)
+	{
+		btStridingMeshInterfaceData* curData = m_allocatedbtStridingMeshInterfaceDatas[i];
+
+		for(int a = 0;a < curData->m_numMeshParts;a++)
+		{
+			btMeshPartData* curPart = &curData->m_meshPartsPtr[a];
+			if(curPart->m_vertices3f)
+				delete [] curPart->m_vertices3f;
+
+			if(curPart->m_vertices3d)
+				delete [] curPart->m_vertices3d;
+
+			if(curPart->m_indices32)
+				delete [] curPart->m_indices32;
+
+			if(curPart->m_3indices16)
+				delete [] curPart->m_3indices16;
+
+			if(curPart->m_indices16)
+				delete [] curPart->m_indices16;
+
+			if (curPart->m_3indices8)
+				delete [] curPart->m_3indices8;
+
+		}
+		delete [] curData->m_meshPartsPtr;
+		delete curData;
+	}
+	m_allocatedbtStridingMeshInterfaceDatas.clear();
+
+	for (i=0;i<m_indexArrays.size();i++)
+	{
+		btAlignedFree(m_indexArrays[i]);
+	}
+  m_indexArrays.clear();
+
+	for (i=0;i<m_shortIndexArrays.size();i++)
+	{
+		btAlignedFree(m_shortIndexArrays[i]);
+	}
+  m_shortIndexArrays.clear();
+
+	for (i=0;i<m_charIndexArrays.size();i++)
+	{
+		btAlignedFree(m_charIndexArrays[i]);
+	}
+  m_charIndexArrays.clear();
+
+	for (i=0;i<m_floatVertexArrays.size();i++)
+	{
+		btAlignedFree(m_floatVertexArrays[i]);
+	}
+  m_floatVertexArrays.clear();
+
+	for (i=0;i<m_doubleVertexArrays.size();i++)
+	{
+		btAlignedFree(m_doubleVertexArrays[i]);
+	}
+   m_doubleVertexArrays.clear();
+
+
+}
+
+
+
+btCollisionShape* btCollisionWorldImporter::convertCollisionShape(  btCollisionShapeData* shapeData  )
+{
+	btCollisionShape* shape = 0;
+
+	switch (shapeData->m_shapeType)
+		{
+	case STATIC_PLANE_PROXYTYPE:
+		{
+			btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*)shapeData;
+			btVector3 planeNormal,localScaling;
+			planeNormal.deSerializeFloat(planeData->m_planeNormal);
+			localScaling.deSerializeFloat(planeData->m_localScaling);
+			shape = createPlaneShape(planeNormal,planeData->m_planeConstant);
+			shape->setLocalScaling(localScaling);
+
+			break;
+		}
+	case SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE:
+		{
+			btScaledTriangleMeshShapeData* scaledMesh = (btScaledTriangleMeshShapeData*) shapeData;
+			btCollisionShapeData* colShapeData = (btCollisionShapeData*) &scaledMesh->m_trimeshShapeData;
+			colShapeData->m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;
+			btCollisionShape* childShape = convertCollisionShape(colShapeData);
+			btBvhTriangleMeshShape* meshShape = (btBvhTriangleMeshShape*)childShape;
+			btVector3 localScaling;
+			localScaling.deSerializeFloat(scaledMesh->m_localScaling);
+
+			shape = createScaledTrangleMeshShape(meshShape, localScaling);
+			break;
+		}
+#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
+	case GIMPACT_SHAPE_PROXYTYPE:
+		{
+			btGImpactMeshShapeData* gimpactData = (btGImpactMeshShapeData*) shapeData;
+			if (gimpactData->m_gimpactSubType == CONST_GIMPACT_TRIMESH_SHAPE)
+			{
+				btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&gimpactData->m_meshInterface);
+				btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
+
+
+				btGImpactMeshShape* gimpactShape = createGimpactShape(meshInterface);
+				btVector3 localScaling;
+				localScaling.deSerializeFloat(gimpactData->m_localScaling);
+				gimpactShape->setLocalScaling(localScaling);
+				gimpactShape->setMargin(btScalar(gimpactData->m_collisionMargin));
+				gimpactShape->updateBound();
+				shape = gimpactShape;
+			} else
+			{
+				printf("unsupported gimpact sub type\n");
+			}
+			break;
+		}
+#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
+	//The btCapsuleShape* API has issue passing the margin/scaling/halfextents unmodified through the API
+	//so deal with this
+		case CAPSULE_SHAPE_PROXYTYPE:
+		{
+			btCapsuleShapeData* capData = (btCapsuleShapeData*)shapeData;
+
+
+			switch (capData->m_upAxis)
+			{
+			case 0:
+				{
+					shape = createCapsuleShapeX(1,1);
+					break;
+				}
+			case 1:
+				{
+					shape = createCapsuleShapeY(1,1);
+					break;
+				}
+			case 2:
+				{
+					shape = createCapsuleShapeZ(1,1);
+					break;
+				}
+			default:
+				{
+					printf("error: wrong up axis for btCapsuleShape\n");
+				}
+
+
+			};
+			if (shape)
+			{
+				btCapsuleShape* cap = (btCapsuleShape*) shape;
+				cap->deSerializeFloat(capData);
+			}
+			break;
+		}
+		case CYLINDER_SHAPE_PROXYTYPE:
+		case CONE_SHAPE_PROXYTYPE:
+		case BOX_SHAPE_PROXYTYPE:
+		case SPHERE_SHAPE_PROXYTYPE:
+		case MULTI_SPHERE_SHAPE_PROXYTYPE:
+		case CONVEX_HULL_SHAPE_PROXYTYPE:
+			{
+				btConvexInternalShapeData* bsd = (btConvexInternalShapeData*)shapeData;
+				btVector3 implicitShapeDimensions;
+				implicitShapeDimensions.deSerializeFloat(bsd->m_implicitShapeDimensions);
+				btVector3 localScaling;
+				localScaling.deSerializeFloat(bsd->m_localScaling);
+				btVector3 margin(bsd->m_collisionMargin,bsd->m_collisionMargin,bsd->m_collisionMargin);
+				switch (shapeData->m_shapeType)
+				{
+					case BOX_SHAPE_PROXYTYPE:
+						{
+							btBoxShape* box= (btBoxShape*)createBoxShape(implicitShapeDimensions/localScaling+margin);
+							//box->initializePolyhedralFeatures();
+							shape = box;
+
+							break;
+						}
+					case SPHERE_SHAPE_PROXYTYPE:
+						{
+							shape = createSphereShape(implicitShapeDimensions.getX());
+							break;
+						}
+
+					case CYLINDER_SHAPE_PROXYTYPE:
+						{
+							btCylinderShapeData* cylData = (btCylinderShapeData*) shapeData;
+							btVector3 halfExtents = implicitShapeDimensions+margin;
+							switch (cylData->m_upAxis)
+							{
+							case 0:
+								{
+									shape = createCylinderShapeX(halfExtents.getY(),halfExtents.getX());
+									break;
+								}
+							case 1:
+								{
+									shape = createCylinderShapeY(halfExtents.getX(),halfExtents.getY());
+									break;
+								}
+							case 2:
+								{
+									shape = createCylinderShapeZ(halfExtents.getX(),halfExtents.getZ());
+									break;
+								}
+							default:
+								{
+									printf("unknown Cylinder up axis\n");
+								}
+
+							};
+
+
+
+							break;
+						}
+					case CONE_SHAPE_PROXYTYPE:
+						{
+							btConeShapeData* conData = (btConeShapeData*) shapeData;
+							btVector3 halfExtents = implicitShapeDimensions;//+margin;
+							switch (conData->m_upIndex)
+							{
+							case 0:
+								{
+									shape = createConeShapeX(halfExtents.getY(),halfExtents.getX());
+									break;
+								}
+							case 1:
+								{
+									shape = createConeShapeY(halfExtents.getX(),halfExtents.getY());
+									break;
+								}
+							case 2:
+								{
+									shape = createConeShapeZ(halfExtents.getX(),halfExtents.getZ());
+									break;
+								}
+							default:
+								{
+									printf("unknown Cone up axis\n");
+								}
+
+							};
+
+
+
+							break;
+						}
+					case MULTI_SPHERE_SHAPE_PROXYTYPE:
+						{
+							btMultiSphereShapeData* mss = (btMultiSphereShapeData*)bsd;
+							int numSpheres = mss->m_localPositionArraySize;
+
+							btAlignedObjectArray<btVector3> tmpPos;
+							btAlignedObjectArray<btScalar> radii;
+							radii.resize(numSpheres);
+							tmpPos.resize(numSpheres);
+							int i;
+							for ( i=0;i<numSpheres;i++)
+							{
+								tmpPos[i].deSerializeFloat(mss->m_localPositionArrayPtr[i].m_pos);
+								radii[i] = mss->m_localPositionArrayPtr[i].m_radius;
+							}
+							shape = createMultiSphereShape(&tmpPos[0],&radii[0],numSpheres);
+							break;
+						}
+					case CONVEX_HULL_SHAPE_PROXYTYPE:
+						{
+						//	int sz = sizeof(btConvexHullShapeData);
+						//	int sz2 = sizeof(btConvexInternalShapeData);
+						//	int sz3 = sizeof(btCollisionShapeData);
+							btConvexHullShapeData* convexData = (btConvexHullShapeData*)bsd;
+							int numPoints = convexData->m_numUnscaledPoints;
+
+							btAlignedObjectArray<btVector3> tmpPoints;
+							tmpPoints.resize(numPoints);
+							int i;
+							for ( i=0;i<numPoints;i++)
+							{
+#ifdef BT_USE_DOUBLE_PRECISION
+							if (convexData->m_unscaledPointsDoublePtr)
+								tmpPoints[i].deSerialize(convexData->m_unscaledPointsDoublePtr[i]);
+							if (convexData->m_unscaledPointsFloatPtr)
+								tmpPoints[i].deSerializeFloat(convexData->m_unscaledPointsFloatPtr[i]);
+#else
+							if (convexData->m_unscaledPointsFloatPtr)
+								tmpPoints[i].deSerialize(convexData->m_unscaledPointsFloatPtr[i]);
+							if (convexData->m_unscaledPointsDoublePtr)
+								tmpPoints[i].deSerializeDouble(convexData->m_unscaledPointsDoublePtr[i]);
+#endif //BT_USE_DOUBLE_PRECISION
+							}
+							btConvexHullShape* hullShape = createConvexHullShape();
+							for (i=0;i<numPoints;i++)
+							{
+								hullShape->addPoint(tmpPoints[i]);
+							}
+							hullShape->setMargin(bsd->m_collisionMargin);
+							//hullShape->initializePolyhedralFeatures();
+							shape = hullShape;
+							break;
+						}
+					default:
+						{
+							printf("error: cannot create shape type (%d)\n",shapeData->m_shapeType);
+						}
+				}
+
+				if (shape)
+				{
+					shape->setMargin(bsd->m_collisionMargin);
+
+					btVector3 localScaling;
+					localScaling.deSerializeFloat(bsd->m_localScaling);
+					shape->setLocalScaling(localScaling);
+
+				}
+				break;
+			}
+		case TRIANGLE_MESH_SHAPE_PROXYTYPE:
+		{
+			btTriangleMeshShapeData* trimesh = (btTriangleMeshShapeData*)shapeData;
+			btStridingMeshInterfaceData* interfaceData = createStridingMeshInterfaceData(&trimesh->m_meshInterface);
+			btTriangleIndexVertexArray* meshInterface = createMeshInterface(*interfaceData);
+			if (!meshInterface->getNumSubParts())
+			{
+				return 0;
+			}
+
+			btVector3 scaling; scaling.deSerializeFloat(trimesh->m_meshInterface.m_scaling);
+			meshInterface->setScaling(scaling);
+
+
+			btOptimizedBvh* bvh = 0;
+#if 1
+			if (trimesh->m_quantizedFloatBvh)
+			{
+				btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedFloatBvh);
+				if (bvhPtr && *bvhPtr)
+				{
+					bvh = *bvhPtr;
+				} else
+				{
+					bvh = createOptimizedBvh();
+					bvh->deSerializeFloat(*trimesh->m_quantizedFloatBvh);
+				}
+			}
+			if (trimesh->m_quantizedDoubleBvh)
+			{
+				btOptimizedBvh** bvhPtr = m_bvhMap.find(trimesh->m_quantizedDoubleBvh);
+				if (bvhPtr && *bvhPtr)
+				{
+					bvh = *bvhPtr;
+				} else
+				{
+					bvh = createOptimizedBvh();
+					bvh->deSerializeDouble(*trimesh->m_quantizedDoubleBvh);
+				}
+			}
+#endif
+
+
+			btBvhTriangleMeshShape* trimeshShape = createBvhTriangleMeshShape(meshInterface,bvh);
+			trimeshShape->setMargin(trimesh->m_collisionMargin);
+			shape = trimeshShape;
+
+			if (trimesh->m_triangleInfoMap)
+			{
+				btTriangleInfoMap* map = createTriangleInfoMap();
+				map->deSerialize(*trimesh->m_triangleInfoMap);
+				trimeshShape->setTriangleInfoMap(map);
+
+#ifdef USE_INTERNAL_EDGE_UTILITY
+				gContactAddedCallback = btAdjustInternalEdgeContactsCallback;
+#endif //USE_INTERNAL_EDGE_UTILITY
+
+			}
+
+			//printf("trimesh->m_collisionMargin=%f\n",trimesh->m_collisionMargin);
+			break;
+		}
+		case COMPOUND_SHAPE_PROXYTYPE:
+			{
+				btCompoundShapeData* compoundData = (btCompoundShapeData*)shapeData;
+				btCompoundShape* compoundShape = createCompoundShape();
+
+				btCompoundShapeChildData* childShapeDataArray = &compoundData->m_childShapePtr[0];
+
+
+				btAlignedObjectArray<btCollisionShape*> childShapes;
+				for (int i=0;i<compoundData->m_numChildShapes;i++)
+				{
+					btCompoundShapeChildData* ptr = &compoundData->m_childShapePtr[i];
+
+					btCollisionShapeData* cd = compoundData->m_childShapePtr[i].m_childShape;
+
+					btCollisionShape* childShape = convertCollisionShape(cd);
+					if (childShape)
+					{
+						btTransform localTransform;
+						localTransform.deSerializeFloat(compoundData->m_childShapePtr[i].m_transform);
+						compoundShape->addChildShape(localTransform,childShape);
+					} else
+					{
+#ifdef _DEBUG
+						printf("error: couldn't create childShape for compoundShape\n");
+#endif
+					}
+
+				}
+				shape = compoundShape;
+
+				break;
+			}
+		case SOFTBODY_SHAPE_PROXYTYPE:
+			{
+				return 0;
+			}
+		default:
+			{
+#ifdef _DEBUG
+				printf("unsupported shape type (%d)\n",shapeData->m_shapeType);
+#endif
+			}
+		}
+
+		return shape;
+
+}
+
+
+
+char* btCollisionWorldImporter::duplicateName(const char* name)
+{
+	if (name)
+	{
+		int l = (int)strlen(name);
+		char* newName = new char[l+1];
+		memcpy(newName,name,l);
+		newName[l] = 0;
+		m_allocatedNames.push_back(newName);
+		return newName;
+	}
+	return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+btTriangleIndexVertexArray* btCollisionWorldImporter::createMeshInterface(btStridingMeshInterfaceData&  meshData)
+{
+	btTriangleIndexVertexArray* meshInterface = createTriangleMeshContainer();
+
+	for (int i=0;i<meshData.m_numMeshParts;i++)
+	{
+		btIndexedMesh meshPart;
+		meshPart.m_numTriangles = meshData.m_meshPartsPtr[i].m_numTriangles;
+		meshPart.m_numVertices = meshData.m_meshPartsPtr[i].m_numVertices;
+
+
+		if (meshData.m_meshPartsPtr[i].m_indices32)
+		{
+			meshPart.m_indexType = PHY_INTEGER;
+			meshPart.m_triangleIndexStride = 3*sizeof(int);
+			int* indexArray = (int*)btAlignedAlloc(sizeof(int)*3*meshPart.m_numTriangles,16);
+			m_indexArrays.push_back(indexArray);
+			for (int j=0;j<3*meshPart.m_numTriangles;j++)
+			{
+				indexArray[j] = meshData.m_meshPartsPtr[i].m_indices32[j].m_value;
+			}
+			meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
+		} else
+		{
+			if (meshData.m_meshPartsPtr[i].m_3indices16)
+			{
+				meshPart.m_indexType = PHY_SHORT;
+				meshPart.m_triangleIndexStride = sizeof(short int)*3;//sizeof(btShortIntIndexTripletData);
+
+				short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
+				m_shortIndexArrays.push_back(indexArray);
+
+				for (int j=0;j<meshPart.m_numTriangles;j++)
+				{
+					indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[0];
+					indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[1];
+					indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices16[j].m_values[2];
+				}
+
+				meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
+			}
+			if (meshData.m_meshPartsPtr[i].m_indices16)
+			{
+				meshPart.m_indexType = PHY_SHORT;
+				meshPart.m_triangleIndexStride = 3*sizeof(short int);
+				short int* indexArray = (short int*)btAlignedAlloc(sizeof(short int)*3*meshPart.m_numTriangles,16);
+				m_shortIndexArrays.push_back(indexArray);
+				for (int j=0;j<3*meshPart.m_numTriangles;j++)
+				{
+					indexArray[j] = meshData.m_meshPartsPtr[i].m_indices16[j].m_value;
+				}
+
+				meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
+			}
+
+			if (meshData.m_meshPartsPtr[i].m_3indices8)
+			{
+				meshPart.m_indexType = PHY_UCHAR;
+				meshPart.m_triangleIndexStride = sizeof(unsigned char)*3;
+
+				unsigned char* indexArray = (unsigned char*)btAlignedAlloc(sizeof(unsigned char)*3*meshPart.m_numTriangles,16);
+				m_charIndexArrays.push_back(indexArray);
+
+				for (int j=0;j<meshPart.m_numTriangles;j++)
+				{
+					indexArray[3*j] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[0];
+					indexArray[3*j+1] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[1];
+					indexArray[3*j+2] = meshData.m_meshPartsPtr[i].m_3indices8[j].m_values[2];
+				}
+
+				meshPart.m_triangleIndexBase = (const unsigned char*)indexArray;
+			}
+		}
+
+		if (meshData.m_meshPartsPtr[i].m_vertices3f)
+		{
+			meshPart.m_vertexType = PHY_FLOAT;
+			meshPart.m_vertexStride = sizeof(btVector3FloatData);
+			btVector3FloatData* vertices = (btVector3FloatData*) btAlignedAlloc(sizeof(btVector3FloatData)*meshPart.m_numVertices,16);
+			m_floatVertexArrays.push_back(vertices);
+
+			for (int j=0;j<meshPart.m_numVertices;j++)
+			{
+				vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[0];
+				vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[1];
+				vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[2];
+				vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3f[j].m_floats[3];
+			}
+			meshPart.m_vertexBase = (const unsigned char*)vertices;
+		} else
+		{
+			meshPart.m_vertexType = PHY_DOUBLE;
+			meshPart.m_vertexStride = sizeof(btVector3DoubleData);
+
+
+			btVector3DoubleData* vertices = (btVector3DoubleData*) btAlignedAlloc(sizeof(btVector3DoubleData)*meshPart.m_numVertices,16);
+			m_doubleVertexArrays.push_back(vertices);
+
+			for (int j=0;j<meshPart.m_numVertices;j++)
+			{
+				vertices[j].m_floats[0] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[0];
+				vertices[j].m_floats[1] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[1];
+				vertices[j].m_floats[2] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[2];
+				vertices[j].m_floats[3] = meshData.m_meshPartsPtr[i].m_vertices3d[j].m_floats[3];
+			}
+			meshPart.m_vertexBase = (const unsigned char*)vertices;
+		}
+
+		if (meshPart.m_triangleIndexBase && meshPart.m_vertexBase)
+		{
+			meshInterface->addIndexedMesh(meshPart,meshPart.m_indexType);
+		}
+	}
+
+	return meshInterface;
+}
+
+
+btStridingMeshInterfaceData* btCollisionWorldImporter::createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData)
+{
+	//create a new btStridingMeshInterfaceData that is an exact copy of shapedata and store it in the WorldImporter
+	btStridingMeshInterfaceData* newData = new btStridingMeshInterfaceData;
+
+	newData->m_scaling = interfaceData->m_scaling;
+	newData->m_numMeshParts = interfaceData->m_numMeshParts;
+	newData->m_meshPartsPtr = new btMeshPartData[newData->m_numMeshParts];
+
+	for(int i = 0;i < newData->m_numMeshParts;i++)
+	{
+		btMeshPartData* curPart = &interfaceData->m_meshPartsPtr[i];
+		btMeshPartData* curNewPart = &newData->m_meshPartsPtr[i];
+
+		curNewPart->m_numTriangles = curPart->m_numTriangles;
+		curNewPart->m_numVertices = curPart->m_numVertices;
+
+		if(curPart->m_vertices3f)
+		{
+			curNewPart->m_vertices3f = new btVector3FloatData[curNewPart->m_numVertices];
+			memcpy(curNewPart->m_vertices3f,curPart->m_vertices3f,sizeof(btVector3FloatData) * curNewPart->m_numVertices);
+		}
+		else
+			curNewPart->m_vertices3f = NULL;
+
+		if(curPart->m_vertices3d)
+		{
+			curNewPart->m_vertices3d = new btVector3DoubleData[curNewPart->m_numVertices];
+			memcpy(curNewPart->m_vertices3d,curPart->m_vertices3d,sizeof(btVector3DoubleData) * curNewPart->m_numVertices);
+		}
+		else
+			curNewPart->m_vertices3d = NULL;
+
+		int numIndices = curNewPart->m_numTriangles * 3;
+		///the m_3indices8 was not initialized in some Bullet versions, this can cause crashes at loading time
+		///we catch it by only dealing with m_3indices8 if none of the other indices are initialized
+		bool uninitialized3indices8Workaround =false;
+
+		if(curPart->m_indices32)
+		{
+			uninitialized3indices8Workaround=true;
+			curNewPart->m_indices32 = new btIntIndexData[numIndices];
+			memcpy(curNewPart->m_indices32,curPart->m_indices32,sizeof(btIntIndexData) * numIndices);
+		}
+		else
+			curNewPart->m_indices32 = NULL;
+
+		if(curPart->m_3indices16)
+		{
+			uninitialized3indices8Workaround=true;
+			curNewPart->m_3indices16 = new btShortIntIndexTripletData[curNewPart->m_numTriangles];
+			memcpy(curNewPart->m_3indices16,curPart->m_3indices16,sizeof(btShortIntIndexTripletData) * curNewPart->m_numTriangles);
+		}
+		else
+			curNewPart->m_3indices16 = NULL;
+
+		if(curPart->m_indices16)
+		{
+			uninitialized3indices8Workaround=true;
+			curNewPart->m_indices16 = new btShortIntIndexData[numIndices];
+			memcpy(curNewPart->m_indices16,curPart->m_indices16,sizeof(btShortIntIndexData) * numIndices);
+		}
+		else
+			curNewPart->m_indices16 = NULL;
+
+		if(!uninitialized3indices8Workaround && curPart->m_3indices8)
+		{
+			curNewPart->m_3indices8 = new btCharIndexTripletData[curNewPart->m_numTriangles];
+			memcpy(curNewPart->m_3indices8,curPart->m_3indices8,sizeof(btCharIndexTripletData) * curNewPart->m_numTriangles);
+		}
+		else
+			curNewPart->m_3indices8 = NULL;
+
+	}
+
+	m_allocatedbtStridingMeshInterfaceDatas.push_back(newData);
+
+	return(newData);
+}
+
+#ifdef USE_INTERNAL_EDGE_UTILITY
+extern ContactAddedCallback		gContactAddedCallback;
+
+static bool btAdjustInternalEdgeContactsCallback(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
+{
+
+	btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1);
+		//btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_BACKFACE_MODE);
+		//btAdjustInternalEdgeContacts(cp,colObj1,colObj0, partId1,index1, BT_TRIANGLE_CONVEX_DOUBLE_SIDED+BT_TRIANGLE_CONCAVE_DOUBLE_SIDED);
+	return true;
+}
+#endif //USE_INTERNAL_EDGE_UTILITY
+
+
+/*
+btRigidBody*  btWorldImporter::createRigidBody(bool isDynamic, btScalar mass, const btTransform& startTransform,btCollisionShape* shape,const char* bodyName)
+{
+	btVector3 localInertia;
+	localInertia.setZero();
+
+	if (mass)
+		shape->calculateLocalInertia(mass,localInertia);
+
+	btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
+	body->setWorldTransform(startTransform);
+
+	if (m_dynamicsWorld)
+		m_dynamicsWorld->addRigidBody(body);
+
+	if (bodyName)
+	{
+		char* newname = duplicateName(bodyName);
+		m_objectNameMap.insert(body,newname);
+		m_nameBodyMap.insert(newname,body);
+	}
+	m_allocatedRigidBodies.push_back(body);
+	return body;
+
+}
+*/
+
+btCollisionObject* btCollisionWorldImporter::getCollisionObjectByName(const char* name)
+{
+	btCollisionObject** bodyPtr = m_nameColObjMap.find(name);
+	if (bodyPtr && *bodyPtr)
+	{
+		return *bodyPtr;
+	}
+	return 0;
+}
+
+btCollisionObject* btCollisionWorldImporter::createCollisionObject(const btTransform& startTransform,btCollisionShape* shape, const char* bodyName)
+{
+	btCollisionObject* colObj = new btCollisionObject();
+	colObj->setWorldTransform(startTransform);
+	colObj->setCollisionShape(shape);
+	m_collisionWorld->addCollisionObject(colObj);//todo: flags etc
+
+	if (bodyName)
+	{
+		char* newname = duplicateName(bodyName);
+		m_objectNameMap.insert(colObj,newname);
+		m_nameColObjMap.insert(newname,colObj);
+	}
+	m_allocatedCollisionObjects.push_back(colObj);
+
+	return colObj;
+}
+
+
+
+btCollisionShape* btCollisionWorldImporter::createPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
+{
+	btStaticPlaneShape* shape = new btStaticPlaneShape(planeNormal,planeConstant);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+btCollisionShape* btCollisionWorldImporter::createBoxShape(const btVector3& halfExtents)
+{
+	btBoxShape* shape = new btBoxShape(halfExtents);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+btCollisionShape* btCollisionWorldImporter::createSphereShape(btScalar radius)
+{
+	btSphereShape* shape = new btSphereShape(radius);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+
+btCollisionShape* btCollisionWorldImporter::createCapsuleShapeX(btScalar radius, btScalar height)
+{
+	btCapsuleShapeX* shape = new btCapsuleShapeX(radius,height);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createCapsuleShapeY(btScalar radius, btScalar height)
+{
+	btCapsuleShape* shape = new btCapsuleShape(radius,height);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createCapsuleShapeZ(btScalar radius, btScalar height)
+{
+	btCapsuleShapeZ* shape = new btCapsuleShapeZ(radius,height);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createCylinderShapeX(btScalar radius,btScalar height)
+{
+	btCylinderShapeX* shape = new btCylinderShapeX(btVector3(height,radius,radius));
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createCylinderShapeY(btScalar radius,btScalar height)
+{
+	btCylinderShape* shape = new btCylinderShape(btVector3(radius,height,radius));
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createCylinderShapeZ(btScalar radius,btScalar height)
+{
+	btCylinderShapeZ* shape = new btCylinderShapeZ(btVector3(radius,radius,height));
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createConeShapeX(btScalar radius,btScalar height)
+{
+	btConeShapeX* shape = new btConeShapeX(radius,height);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createConeShapeY(btScalar radius,btScalar height)
+{
+	btConeShape* shape = new btConeShape(radius,height);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCollisionShape* btCollisionWorldImporter::createConeShapeZ(btScalar radius,btScalar height)
+{
+	btConeShapeZ* shape = new btConeShapeZ(radius,height);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btTriangleIndexVertexArray*	btCollisionWorldImporter::createTriangleMeshContainer()
+{
+	btTriangleIndexVertexArray* in = new btTriangleIndexVertexArray();
+	m_allocatedTriangleIndexArrays.push_back(in);
+	return in;
+}
+
+btOptimizedBvh*	btCollisionWorldImporter::createOptimizedBvh()
+{
+	btOptimizedBvh* bvh = new btOptimizedBvh();
+	m_allocatedBvhs.push_back(bvh);
+	return bvh;
+}
+
+
+btTriangleInfoMap* btCollisionWorldImporter::createTriangleInfoMap()
+{
+	btTriangleInfoMap* tim = new btTriangleInfoMap();
+	m_allocatedTriangleInfoMaps.push_back(tim);
+	return tim;
+}
+
+btBvhTriangleMeshShape* btCollisionWorldImporter::createBvhTriangleMeshShape(btStridingMeshInterface* trimesh, btOptimizedBvh* bvh)
+{
+	if (bvh)
+	{
+		btBvhTriangleMeshShape* bvhTriMesh = new btBvhTriangleMeshShape(trimesh,bvh->isQuantized(), false);
+		bvhTriMesh->setOptimizedBvh(bvh);
+		m_allocatedCollisionShapes.push_back(bvhTriMesh);
+		return bvhTriMesh;
+	}
+
+	btBvhTriangleMeshShape* ts = new btBvhTriangleMeshShape(trimesh,true);
+	m_allocatedCollisionShapes.push_back(ts);
+	return ts;
+
+}
+btCollisionShape* btCollisionWorldImporter::createConvexTriangleMeshShape(btStridingMeshInterface* trimesh)
+{
+	return 0;
+}
+#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
+btGImpactMeshShape* btCollisionWorldImporter::createGimpactShape(btStridingMeshInterface* trimesh)
+{
+	btGImpactMeshShape* shape = new btGImpactMeshShape(trimesh);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+
+}
+#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
+
+btConvexHullShape* btCollisionWorldImporter::createConvexHullShape()
+{
+	btConvexHullShape* shape = new btConvexHullShape();
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btCompoundShape* btCollisionWorldImporter::createCompoundShape()
+{
+	btCompoundShape* shape = new btCompoundShape();
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+
+btScaledBvhTriangleMeshShape* btCollisionWorldImporter::createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScaling)
+{
+	btScaledBvhTriangleMeshShape* shape = new btScaledBvhTriangleMeshShape(meshShape,localScaling);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+btMultiSphereShape* btCollisionWorldImporter::createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres)
+{
+	btMultiSphereShape* shape = new btMultiSphereShape(positions, radi, numSpheres);
+	m_allocatedCollisionShapes.push_back(shape);
+	return shape;
+}
+
+
+
+	// query for data
+int	btCollisionWorldImporter::getNumCollisionShapes() const
+{
+	return m_allocatedCollisionShapes.size();
+}
+
+btCollisionShape* btCollisionWorldImporter::getCollisionShapeByIndex(int index)
+{
+	return m_allocatedCollisionShapes[index];
+}
+
+btCollisionShape* btCollisionWorldImporter::getCollisionShapeByName(const char* name)
+{
+	btCollisionShape** shapePtr = m_nameShapeMap.find(name);
+	if (shapePtr&& *shapePtr)
+	{
+		return *shapePtr;
+	}
+	return 0;
+}
+
+
+const char*	btCollisionWorldImporter::getNameForPointer(const void* ptr) const
+{
+	const char*const * namePtr = m_objectNameMap.find(ptr);
+	if (namePtr && *namePtr)
+		return *namePtr;
+	return 0;
+}
+
+
+int btCollisionWorldImporter::getNumRigidBodies() const
+{
+	return m_allocatedRigidBodies.size();
+}
+
+btCollisionObject* btCollisionWorldImporter::getRigidBodyByIndex(int index) const
+{
+	return m_allocatedRigidBodies[index];
+}
+
+
+int btCollisionWorldImporter::getNumBvhs() const
+{
+	return m_allocatedBvhs.size();
+}
+ btOptimizedBvh* btCollisionWorldImporter::getBvhByIndex(int index) const
+{
+	return m_allocatedBvhs[index];
+}
+
+int btCollisionWorldImporter::getNumTriangleInfoMaps() const
+{
+	return m_allocatedTriangleInfoMaps.size();
+}
+
+btTriangleInfoMap* btCollisionWorldImporter::getTriangleInfoMapByIndex(int index) const
+{
+	return m_allocatedTriangleInfoMaps[index];
+}
+
+

+ 190 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.h

@@ -0,0 +1,190 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2014 Erwin Coumans  http://bulletphysics.org
+
+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_WORLD_IMPORTER_H
+#define BT_COLLISION_WORLD_IMPORTER_H
+
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btVector3.h"
+#include "LinearMath/btAlignedObjectArray.h"
+#include "LinearMath/btHashMap.h"
+
+class btCollisionShape;
+class btCollisionObject;
+struct btBulletSerializedArrays;
+
+
+struct ConstraintInput;
+class btCollisionWorld;
+struct btCollisionShapeData;
+class btTriangleIndexVertexArray;
+class btStridingMeshInterface;
+struct btStridingMeshInterfaceData;
+class btGImpactMeshShape;
+class btOptimizedBvh;
+struct btTriangleInfoMap;
+class btBvhTriangleMeshShape;
+class btPoint2PointConstraint;
+class btHingeConstraint;
+class btConeTwistConstraint;
+class btGeneric6DofConstraint;
+class btGeneric6DofSpringConstraint;
+class btSliderConstraint;
+class btGearConstraint;
+struct btContactSolverInfo;
+
+
+
+
+class btCollisionWorldImporter
+{
+protected:
+	btCollisionWorld* m_collisionWorld;
+
+	int m_verboseMode;
+
+	btAlignedObjectArray<btCollisionShape*>  m_allocatedCollisionShapes;
+	btAlignedObjectArray<btCollisionObject*> m_allocatedRigidBodies;
+
+	btAlignedObjectArray<btOptimizedBvh*>	 m_allocatedBvhs;
+	btAlignedObjectArray<btTriangleInfoMap*> m_allocatedTriangleInfoMaps;
+	btAlignedObjectArray<btTriangleIndexVertexArray*> m_allocatedTriangleIndexArrays;
+	btAlignedObjectArray<btStridingMeshInterfaceData*> m_allocatedbtStridingMeshInterfaceDatas;
+	btAlignedObjectArray<btCollisionObject*> m_allocatedCollisionObjects;
+
+
+	btAlignedObjectArray<char*>				m_allocatedNames;
+
+	btAlignedObjectArray<int*>				m_indexArrays;
+	btAlignedObjectArray<short int*>		m_shortIndexArrays;
+	btAlignedObjectArray<unsigned char*>	m_charIndexArrays;
+
+	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,const char*>	m_objectNameMap;
+
+	btHashMap<btHashPtr,btCollisionShape*>	m_shapeMap;
+	btHashMap<btHashPtr,btCollisionObject*>	m_bodyMap;
+
+
+	//methods
+
+
+
+	char*	duplicateName(const char* name);
+
+	btCollisionShape* convertCollisionShape(  btCollisionShapeData* shapeData  );
+
+
+public:
+
+	btCollisionWorldImporter(btCollisionWorld* world);
+
+	virtual ~btCollisionWorldImporter();
+
+    bool	convertAllObjects( btBulletSerializedArrays* arrays);
+
+		///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
+	virtual void deleteAllData();
+
+	void	setVerboseMode(int verboseMode)
+	{
+		m_verboseMode = verboseMode;
+	}
+
+	int getVerboseMode() const
+	{
+		return m_verboseMode;
+	}
+
+		// query for data
+	int	getNumCollisionShapes() const;
+	btCollisionShape* getCollisionShapeByIndex(int index);
+	int getNumRigidBodies() const;
+	btCollisionObject* getRigidBodyByIndex(int index) const;
+	int getNumConstraints() const;
+
+	int getNumBvhs() const;
+	btOptimizedBvh*  getBvhByIndex(int index) const;
+	int getNumTriangleInfoMaps() const;
+	btTriangleInfoMap* getTriangleInfoMapByIndex(int index) const;
+
+	// queris involving named objects
+	btCollisionShape* getCollisionShapeByName(const char* name);
+	btCollisionObject* getCollisionObjectByName(const char* name);
+
+
+	const char*	getNameForPointer(const void* ptr) const;
+
+	///those virtuals are called by load and can be overridden by the user
+
+
+
+	//bodies
+
+	virtual btCollisionObject*  createCollisionObject(	const btTransform& startTransform,	btCollisionShape* shape,const char* bodyName);
+
+	///shapes
+
+	virtual btCollisionShape* createPlaneShape(const btVector3& planeNormal,btScalar planeConstant);
+	virtual btCollisionShape* createBoxShape(const btVector3& halfExtents);
+	virtual btCollisionShape* createSphereShape(btScalar radius);
+	virtual btCollisionShape* createCapsuleShapeX(btScalar radius, btScalar height);
+	virtual btCollisionShape* createCapsuleShapeY(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* createConvexTriangleMeshShape(btStridingMeshInterface* trimesh);
+#ifdef SUPPORT_GIMPACT_SHAPE_IMPORT
+	virtual btGImpactMeshShape* createGimpactShape(btStridingMeshInterface* trimesh);
+#endif //SUPPORT_GIMPACT_SHAPE_IMPORT
+	virtual btStridingMeshInterfaceData* createStridingMeshInterfaceData(btStridingMeshInterfaceData* interfaceData);
+
+	virtual class btConvexHullShape* createConvexHullShape();
+	virtual class btCompoundShape* createCompoundShape();
+	virtual class btScaledBvhTriangleMeshShape* createScaledTrangleMeshShape(btBvhTriangleMeshShape* meshShape,const btVector3& localScalingbtBvhTriangleMeshShape);
+
+	virtual class btMultiSphereShape* createMultiSphereShape(const btVector3* positions,const btScalar* radi,int numSpheres);
+
+	virtual btTriangleIndexVertexArray* createMeshInterface(btStridingMeshInterfaceData& meshData);
+
+	///acceleration and connectivity structures
+	virtual btOptimizedBvh*	createOptimizedBvh();
+	virtual btTriangleInfoMap* createTriangleInfoMap();
+
+
+
+
+};
+
+
+#endif //BT_WORLD_IMPORTER_H

+ 136 - 85
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

@@ -11,6 +11,7 @@ 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.
 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.
 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.
 3. This notice may not be removed or altered from any source distribution.
+
 */
 */
 
 
 #include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
@@ -20,30 +21,34 @@ subject to the following restrictions:
 #include "LinearMath/btIDebugDraw.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "LinearMath/btAabbUtil2.h"
 #include "btManifoldResult.h"
 #include "btManifoldResult.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+
+btShapePairCallback gCompoundChildShapePairCallback = 0;
 
 
-btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
-:btActivatingCollisionAlgorithm(ci,body0,body1),
+btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
+:btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_isSwapped(isSwapped),
 m_isSwapped(isSwapped),
 m_sharedManifold(ci.m_manifold)
 m_sharedManifold(ci.m_manifold)
 {
 {
 	m_ownsManifold = false;
 	m_ownsManifold = false;
 
 
-	btCollisionObject* colObj = m_isSwapped? body1 : body0;
-	btAssert (colObj->getCollisionShape()->isCompound());
+	const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+	btAssert (colObjWrap->getCollisionShape()->isCompound());
 	
 	
-	btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
+	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 	m_compoundShapeRevision = compoundShape->getUpdateRevision();
 	m_compoundShapeRevision = compoundShape->getUpdateRevision();
 	
 	
-	preallocateChildAlgorithms(body0,body1);
+	
+	preallocateChildAlgorithms(body0Wrap,body1Wrap);
 }
 }
 
 
-void	btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1)
+void	btCompoundCollisionAlgorithm::preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
 {
 {
-	btCollisionObject* colObj = m_isSwapped? body1 : body0;
-	btCollisionObject* otherObj = m_isSwapped? body0 : body1;
-	btAssert (colObj->getCollisionShape()->isCompound());
+	const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* otherObjWrap = m_isSwapped? body0Wrap : body1Wrap;
+	btAssert (colObjWrap->getCollisionShape()->isCompound());
 	
 	
-	btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
+	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 
 
 	int numChildren = compoundShape->getNumChildShapes();
 	int numChildren = compoundShape->getNumChildShapes();
 	int i;
 	int i;
@@ -56,11 +61,17 @@ void	btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject*
 			m_childCollisionAlgorithms[i] = 0;
 			m_childCollisionAlgorithms[i] = 0;
 		} else
 		} else
 		{
 		{
-			btCollisionShape* tmpShape = colObj->getCollisionShape();
-			btCollisionShape* childShape = compoundShape->getChildShape(i);
-			colObj->internalSetTemporaryCollisionShape( childShape );
-			m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(colObj,otherObj,m_sharedManifold);
-			colObj->internalSetTemporaryCollisionShape( tmpShape );
+			
+			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);
+
+
+			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsContact;
+			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsClosestPoints;
+
+
 		}
 		}
 	}
 	}
 }
 }
@@ -92,19 +103,16 @@ struct	btCompoundLeafCallback : btDbvt::ICollide
 
 
 public:
 public:
 
 
-	btCollisionObject* m_compoundColObj;
-	btCollisionObject* m_otherObj;
+	const btCollisionObjectWrapper* m_compoundColObjWrap;
+	const btCollisionObjectWrapper* m_otherObjWrap;
 	btDispatcher* m_dispatcher;
 	btDispatcher* m_dispatcher;
 	const btDispatcherInfo& m_dispatchInfo;
 	const btDispatcherInfo& m_dispatchInfo;
 	btManifoldResult*	m_resultOut;
 	btManifoldResult*	m_resultOut;
 	btCollisionAlgorithm**	m_childCollisionAlgorithms;
 	btCollisionAlgorithm**	m_childCollisionAlgorithms;
 	btPersistentManifold*	m_sharedManifold;
 	btPersistentManifold*	m_sharedManifold;
-
-
-
-
-	btCompoundLeafCallback (btCollisionObject* compoundObj,btCollisionObject* otherObj,btDispatcher* dispatcher,const btDispatcherInfo& dispatchInfo,btManifoldResult*	resultOut,btCollisionAlgorithm**	childCollisionAlgorithms,btPersistentManifold*	sharedManifold)
-		:m_compoundColObj(compoundObj),m_otherObj(otherObj),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
+	
+	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_childCollisionAlgorithms(childCollisionAlgorithms),
 		m_sharedManifold(sharedManifold)
 		m_sharedManifold(sharedManifold)
 	{
 	{
@@ -112,72 +120,110 @@ public:
 	}
 	}
 
 
 
 
-	void	ProcessChildShape(btCollisionShape* childShape,int index)
+	void	ProcessChildShape(const btCollisionShape* childShape,int index)
 	{
 	{
-		
-		btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
+		btAssert(index>=0);
+		const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
+		btAssert(index<compoundShape->getNumChildShapes());
 
 
 
 
 		//backup
 		//backup
-		btTransform	orgTrans = m_compoundColObj->getWorldTransform();
-		btTransform	orgInterpolationTrans = m_compoundColObj->getInterpolationWorldTransform();
+		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,aabbMin1,aabbMax1;
+		btVector3 aabbMin0,aabbMax0;
 		childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
 		childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
-		m_otherObj->getCollisionShape()->getAabb(m_otherObj->getWorldTransform(),aabbMin1,aabbMax1);
 
 
-		if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+		btVector3 extendAabb(m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold, m_resultOut->m_closestPointDistanceThreshold);
+		aabbMin0 -= extendAabb;
+		aabbMax0 += extendAabb;
+
+		btVector3 aabbMin1, aabbMax1;
+		m_otherObjWrap->getCollisionShape()->getAabb(m_otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
+
+		if (gCompoundChildShapePairCallback)
 		{
 		{
+			if (!gCompoundChildShapePairCallback(m_otherObjWrap->getCollisionShape(), childShape))
+				return;
+		}
 
 
-			m_compoundColObj->setWorldTransform( newChildWorldTrans);
-			m_compoundColObj->setInterpolationWorldTransform(newChildWorldTrans);
+		if (TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+		{
 
 
-			//the contactpoint is still projected back using the original inverted worldtrans
-			btCollisionShape* tmpShape = m_compoundColObj->getCollisionShape();
-			m_compoundColObj->internalSetTemporaryCollisionShape( childShape );
+			btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap,childShape,m_compoundColObjWrap->getCollisionObject(),newChildWorldTrans,-1,index);
+			
+			btCollisionAlgorithm* algo = 0;
 
 
-			if (!m_childCollisionAlgorithms[index])
-				m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold);
+			if (m_resultOut->m_closestPointDistanceThreshold > 0)
+			{
+				algo = m_dispatcher->findAlgorithm(&compoundWrap, m_otherObjWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
+			}
+			else
+			{
+				//the contactpoint is still projected back using the original inverted worldtrans
+				if (!m_childCollisionAlgorithms[index])
+				{
+					m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(&compoundWrap, m_otherObjWrap, m_sharedManifold, BT_CONTACT_POINT_ALGORITHMS);
+				}
+				algo = m_childCollisionAlgorithms[index];
+			}
+			
+			const btCollisionObjectWrapper* tmpWrap = 0;
 
 
 			///detect swapping case
 			///detect swapping case
-			if (m_resultOut->getBody0Internal() == m_compoundColObj)
+			if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
 			{
 			{
+				tmpWrap = m_resultOut->getBody0Wrap();
+				m_resultOut->setBody0Wrap(&compoundWrap);
 				m_resultOut->setShapeIdentifiersA(-1,index);
 				m_resultOut->setShapeIdentifiersA(-1,index);
 			} else
 			} else
 			{
 			{
+				tmpWrap = m_resultOut->getBody1Wrap();
+				m_resultOut->setBody1Wrap(&compoundWrap);
 				m_resultOut->setShapeIdentifiersB(-1,index);
 				m_resultOut->setShapeIdentifiersB(-1,index);
 			}
 			}
 
 
-			m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut);
+			algo->processCollision(&compoundWrap,m_otherObjWrap,m_dispatchInfo,m_resultOut);
+
+#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))
 			{
 			{
 				btVector3 worldAabbMin,worldAabbMax;
 				btVector3 worldAabbMin,worldAabbMax;
 				m_dispatchInfo.m_debugDraw->drawAabb(aabbMin0,aabbMax0,btVector3(1,1,1));
 				m_dispatchInfo.m_debugDraw->drawAabb(aabbMin0,aabbMax0,btVector3(1,1,1));
 				m_dispatchInfo.m_debugDraw->drawAabb(aabbMin1,aabbMax1,btVector3(1,1,1));
 				m_dispatchInfo.m_debugDraw->drawAabb(aabbMin1,aabbMax1,btVector3(1,1,1));
 			}
 			}
+#endif
+
+			if (m_resultOut->getBody0Internal() == m_compoundColObjWrap->getCollisionObject())
+			{
+				m_resultOut->setBody0Wrap(tmpWrap);
+			} else
+			{
+				m_resultOut->setBody1Wrap(tmpWrap);
+			}
 			
 			
-			//revert back transform
-			m_compoundColObj->internalSetTemporaryCollisionShape( tmpShape);
-			m_compoundColObj->setWorldTransform(  orgTrans );
-			m_compoundColObj->setInterpolationWorldTransform(orgInterpolationTrans);
 		}
 		}
 	}
 	}
 	void		Process(const btDbvtNode* leaf)
 	void		Process(const btDbvtNode* leaf)
 	{
 	{
 		int index = leaf->dataAsInt;
 		int index = leaf->dataAsInt;
 
 
-		btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape());
-		btCollisionShape* childShape = compoundShape->getChildShape(index);
+		const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(m_compoundColObjWrap->getCollisionShape());
+		const btCollisionShape* childShape = compoundShape->getChildShape(index);
+
+#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))
 		{
 		{
 			btVector3 worldAabbMin,worldAabbMax;
 			btVector3 worldAabbMin,worldAabbMax;
-			btTransform	orgTrans = m_compoundColObj->getWorldTransform();
+			btTransform	orgTrans = m_compoundColObjWrap->getWorldTransform();
 			btTransformAabb(leaf->volume.Mins(),leaf->volume.Maxs(),0.,orgTrans,worldAabbMin,worldAabbMax);
 			btTransformAabb(leaf->volume.Mins(),leaf->volume.Maxs(),0.,orgTrans,worldAabbMin,worldAabbMax);
 			m_dispatchInfo.m_debugDraw->drawAabb(worldAabbMin,worldAabbMax,btVector3(1,0,0));
 			m_dispatchInfo.m_debugDraw->drawAabb(worldAabbMin,worldAabbMax,btVector3(1,0,0));
 		}
 		}
+#endif
+
 		ProcessChildShape(childShape,index);
 		ProcessChildShape(childShape,index);
 
 
 	}
 	}
@@ -188,15 +234,13 @@ public:
 
 
 
 
 
 
-void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
 {
-	btCollisionObject* colObj = m_isSwapped? body1 : body0;
-	btCollisionObject* otherObj = m_isSwapped? body0 : body1;
+	const btCollisionObjectWrapper* colObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* otherObjWrap = m_isSwapped? body0Wrap : body1Wrap;
 
 
-	
-
-	btAssert (colObj->getCollisionShape()->isCompound());
-	btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
+	btAssert (colObjWrap->getCollisionShape()->isCompound());
+	const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(colObjWrap->getCollisionShape());
 
 
 	///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
@@ -205,20 +249,23 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 		///clear and update all
 		///clear and update all
 		removeChildAlgorithms();
 		removeChildAlgorithms();
 		
 		
-		preallocateChildAlgorithms(body0,body1);
+		preallocateChildAlgorithms(body0Wrap,body1Wrap);
+		m_compoundShapeRevision = compoundShape->getUpdateRevision();
 	}
 	}
 
 
-
-	btDbvt* tree = compoundShape->getDynamicAabbTree();
+    if (m_childCollisionAlgorithms.size()==0)
+        return;
+    
+	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(colObj,otherObj,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
 	///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
 	///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
 	{
 	{
 		int i;
 		int i;
-		btManifoldArray manifoldArray;
+		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])
@@ -233,7 +280,7 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 						resultOut->setPersistentManifold(0);//??necessary?
 						resultOut->setPersistentManifold(0);//??necessary?
 					}
 					}
 				}
 				}
-				manifoldArray.clear();
+				manifoldArray.resize(0);
 			}
 			}
 		}
 		}
 	}
 	}
@@ -243,12 +290,15 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 
 
 		btVector3 localAabbMin,localAabbMax;
 		btVector3 localAabbMin,localAabbMax;
 		btTransform otherInCompoundSpace;
 		btTransform otherInCompoundSpace;
-		otherInCompoundSpace = colObj->getWorldTransform().inverse() * otherObj->getWorldTransform();
-		otherObj->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);
+		otherInCompoundSpace = colObjWrap->getWorldTransform().inverse() * otherObjWrap->getWorldTransform();
+		otherObjWrap->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);
+		btVector3 extraExtends(resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold);
+		localAabbMin -= 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->collideTV(tree->m_root,bounds,callback);
+		tree->collideTVNoStackAlloc(tree->m_root,bounds,stack2,callback);
 
 
 	} else
 	} else
 	{
 	{
@@ -265,23 +315,27 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 				//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;
-		btManifoldArray	manifoldArray;
-
+		manifoldArray.resize(0);
+        const btCollisionShape* childShape = 0;
+        btTransform	orgTrans;
+        
+        btTransform	newChildWorldTrans;
+        btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;        
+        
 		for (i=0;i<numChildren;i++)
 		for (i=0;i<numChildren;i++)
 		{
 		{
 			if (m_childCollisionAlgorithms[i])
 			if (m_childCollisionAlgorithms[i])
 			{
 			{
-				btCollisionShape* childShape = compoundShape->getChildShape(i);
+				childShape = compoundShape->getChildShape(i);
 			//if not longer overlapping, remove the algorithm
 			//if not longer overlapping, remove the algorithm
-				btTransform	orgTrans = colObj->getWorldTransform();
-				btTransform	orgInterpolationTrans = colObj->getInterpolationWorldTransform();
+				orgTrans = colObjWrap->getWorldTransform();
+                
 				const btTransform& childTrans = compoundShape->getChildTransform(i);
 				const btTransform& childTrans = compoundShape->getChildTransform(i);
-				btTransform	newChildWorldTrans = orgTrans*childTrans ;
+                newChildWorldTrans = orgTrans*childTrans ;
 
 
 				//perform an AABB check first
 				//perform an AABB check first
-				btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
 				childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
 				childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
-				otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1);
+				otherObjWrap->getCollisionShape()->getAabb(otherObjWrap->getWorldTransform(),aabbMin1,aabbMax1);
 
 
 				if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
 				if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
 				{
 				{
@@ -289,19 +343,15 @@ void btCompoundCollisionAlgorithm::processCollision (btCollisionObject* body0,bt
 					m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
 					m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
 					m_childCollisionAlgorithms[i] = 0;
 					m_childCollisionAlgorithms[i] = 0;
 				}
 				}
-
 			}
 			}
-			
 		}
 		}
-
-		
-
 	}
 	}
 }
 }
 
 
 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);
+	//needs to be fixed, using btCollisionObjectWrapper and NOT modifying internal data structures
 	btCollisionObject* colObj = m_isSwapped? body1 : body0;
 	btCollisionObject* colObj = m_isSwapped? body1 : body0;
 	btCollisionObject* otherObj = m_isSwapped? body0 : body1;
 	btCollisionObject* otherObj = m_isSwapped? body0 : body1;
 
 
@@ -320,27 +370,28 @@ 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++)
 	for (i=0;i<numChildren;i++)
 	{
 	{
-		//temporarily exchange parent btCollisionShape with childShape, and recurse
-		btCollisionShape* childShape = compoundShape->getChildShape(i);
+		//btCollisionShape* childShape = compoundShape->getChildShape(i);
 
 
 		//backup
 		//backup
-		btTransform	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();
-		colObj->internalSetTemporaryCollisionShape( childShape );
-		btScalar frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
+		//btCollisionShape* tmpShape = colObj->getCollisionShape();
+		//colObj->internalSetTemporaryCollisionShape( childShape );
+        frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);
 		if (frac<hitFraction)
 		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;

+ 28 - 10
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h

@@ -11,10 +11,11 @@ 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.
 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.
 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.
 3. This notice may not be removed or altered from any source distribution.
+
 */
 */
 
 
-#ifndef COMPOUND_COLLISION_ALGORITHM_H
-#define COMPOUND_COLLISION_ALGORITHM_H
+#ifndef BT_COMPOUND_COLLISION_ALGORITHM_H
+#define BT_COMPOUND_COLLISION_ALGORITHM_H
 
 
 #include "btActivatingCollisionAlgorithm.h"
 #include "btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
@@ -25,31 +26,47 @@ class btDispatcher;
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "btCollisionCreateFunc.h"
 #include "btCollisionCreateFunc.h"
 #include "LinearMath/btAlignedObjectArray.h"
 #include "LinearMath/btAlignedObjectArray.h"
+#include "BulletCollision/BroadphaseCollision/btDbvt.h"
 class btDispatcher;
 class btDispatcher;
 class btCollisionObject;
 class btCollisionObject;
 
 
+class btCollisionShape;
+typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
+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;
+	btManifoldArray manifoldArray;
+
+protected:
 	btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
 	btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
 	bool m_isSwapped;
 	bool m_isSwapped;
 
 
 	class btPersistentManifold*	m_sharedManifold;
 	class btPersistentManifold*	m_sharedManifold;
 	bool					m_ownsManifold;
 	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	removeChildAlgorithms();
 	
 	
-	void	preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1);
+	void	preallocateChildAlgorithms(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 
 public:
 public:
 
 
-	btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+	btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
 
 	virtual ~btCompoundCollisionAlgorithm();
 	virtual ~btCompoundCollisionAlgorithm();
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	btCollisionAlgorithm* getChildAlgorithm (int n) const
+	{
+		return m_childCollisionAlgorithms[n];
+	}
+
+
+	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);
 
 
@@ -63,24 +80,25 @@ public:
 		}
 		}
 	}
 	}
 
 
+	
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,false);
+			return new(mem) btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
 		}
 		}
 	};
 	};
 
 
 	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,true);
+			return new(mem) btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //COMPOUND_COLLISION_ALGORITHM_H
+#endif //BT_COMPOUND_COLLISION_ALGORITHM_H

+ 445 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp

@@ -0,0 +1,445 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2013 Erwin Coumans  http://bulletphysics.org
+
+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 "btCompoundCompoundCollisionAlgorithm.h"
+#include "LinearMath/btQuickprof.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionShapes/btCompoundShape.h"
+#include "BulletCollision/BroadphaseCollision/btDbvt.h"
+#include "LinearMath/btIDebugDraw.h"
+#include "LinearMath/btAabbUtil2.h"
+#include "BulletCollision/CollisionDispatch/btManifoldResult.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+
+
+btShapePairCallback gCompoundCompoundChildShapePairCallback = 0;
+
+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();
+
+	const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
+	btAssert (col0ObjWrap->getCollisionShape()->isCompound());
+
+	const btCollisionObjectWrapper* col1ObjWrap = body1Wrap;
+	btAssert (col1ObjWrap->getCollisionShape()->isCompound());
+	
+	const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
+	m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
+
+	const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
+	m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
+	
+	
+}
+
+
+btCompoundCompoundCollisionAlgorithm::~btCompoundCompoundCollisionAlgorithm()
+{
+	removeChildAlgorithms();
+	m_childCollisionAlgorithmCache->~btHashedSimplePairCache();
+	btAlignedFree(m_childCollisionAlgorithmCache);
+}
+
+void	btCompoundCompoundCollisionAlgorithm::getAllContactManifolds(btManifoldArray&	manifoldArray)
+{
+	int i;
+	btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
+	for (i=0;i<pairs.size();i++)
+	{
+		if (pairs[i].m_userPointer)
+		{
+			
+			((btCollisionAlgorithm*)pairs[i].m_userPointer)->getAllContactManifolds(manifoldArray);
+		}
+	}
+}
+
+
+void	btCompoundCompoundCollisionAlgorithm::removeChildAlgorithms()
+{
+	btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
+
+	int numChildren = pairs.size();
+	int i;
+	for (i=0;i<numChildren;i++)
+	{
+		if (pairs[i].m_userPointer)
+		{
+			btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
+			algo->~btCollisionAlgorithm();
+			m_dispatcher->freeCollisionAlgorithm(algo);
+		}
+	}
+	m_childCollisionAlgorithmCache->removeAllPairs();
+}
+
+struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
+{
+	int m_numOverlapPairs;
+
+
+	const btCollisionObjectWrapper* m_compound0ColObjWrap;
+	const btCollisionObjectWrapper* m_compound1ColObjWrap;
+	btDispatcher* m_dispatcher;
+	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)
+	{
+
+	}
+
+
+
+	
+	void		Process(const btDbvtNode* leaf0,const btDbvtNode* leaf1)
+	{
+		BT_PROFILE("btCompoundCompoundLeafCallback::Process");
+		m_numOverlapPairs++;
+
+
+		int childIndex0 = leaf0->dataAsInt;
+		int childIndex1 = leaf1->dataAsInt;
+		
+
+		btAssert(childIndex0>=0);
+		btAssert(childIndex1>=0);
+
+
+		const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(m_compound0ColObjWrap->getCollisionShape());
+		btAssert(childIndex0<compoundShape0->getNumChildShapes());
+
+		const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(m_compound1ColObjWrap->getCollisionShape());
+		btAssert(childIndex1<compoundShape1->getNumChildShapes());
+
+		const btCollisionShape* childShape0 = compoundShape0->getChildShape(childIndex0);
+		const btCollisionShape* childShape1 = compoundShape1->getChildShape(childIndex1);
+
+		//backup
+		btTransform	orgTrans0 = m_compound0ColObjWrap->getWorldTransform();
+		const btTransform& childTrans0 = compoundShape0->getChildTransform(childIndex0);
+		btTransform	newChildWorldTrans0 = orgTrans0*childTrans0 ;
+		
+		btTransform	orgTrans1 = m_compound1ColObjWrap->getWorldTransform();
+		const btTransform& childTrans1 = compoundShape1->getChildTransform(childIndex1);
+		btTransform	newChildWorldTrans1 = orgTrans1*childTrans1 ;
+		
+
+		//perform an AABB check first
+		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);
+
+		aabbMin0 -= thresholdVec;
+		aabbMax0 += thresholdVec;
+
+		if (gCompoundCompoundChildShapePairCallback)
+		{
+			if (!gCompoundCompoundChildShapePairCallback(childShape0,childShape1))
+				return;
+		}
+
+		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);
+
+			btCollisionAlgorithm* colAlgo = 0;
+			if (m_resultOut->m_closestPointDistanceThreshold > 0)
+			{
+				colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0, &compoundWrap1, 0, BT_CLOSEST_POINT_ALGORITHMS);
+			}
+			else
+			{
+				if (pair)
+				{
+					colAlgo = (btCollisionAlgorithm*)pair->m_userPointer;
+
+				}
+				else
+				{
+					colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0, &compoundWrap1, m_sharedManifold, BT_CONTACT_POINT_ALGORITHMS);
+					pair = m_childCollisionAlgorithmCache->addOverlappingPair(childIndex0, childIndex1);
+					btAssert(pair);
+					pair->m_userPointer = colAlgo;
+				}
+			}
+
+			btAssert(colAlgo);
+						
+			const btCollisionObjectWrapper* tmpWrap0 = 0;
+			const btCollisionObjectWrapper* tmpWrap1 = 0;
+
+			tmpWrap0 = m_resultOut->getBody0Wrap();
+			tmpWrap1 = m_resultOut->getBody1Wrap();
+
+			m_resultOut->setBody0Wrap(&compoundWrap0);
+			m_resultOut->setBody1Wrap(&compoundWrap1);
+
+			m_resultOut->setShapeIdentifiersA(-1,childIndex0);
+			m_resultOut->setShapeIdentifiersB(-1,childIndex1);
+
+
+			colAlgo->processCollision(&compoundWrap0,&compoundWrap1,m_dispatchInfo,m_resultOut);
+			
+			m_resultOut->setBody0Wrap(tmpWrap0);
+			m_resultOut->setBody1Wrap(tmpWrap1);
+			
+
+
+		}
+	}
+};
+
+
+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);
+	newmin -= btVector3(distanceThreshold, distanceThreshold, distanceThreshold);
+	newmax += btVector3(distanceThreshold, distanceThreshold, distanceThreshold);
+	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)
+{
+
+		if(root0&&root1)
+		{
+			int								depth=1;
+			int								treshold=btDbvt::DOUBLE_STACKSIZE-4;
+			btAlignedObjectArray<btDbvt::sStkNN>	stkStack;
+			stkStack.resize(btDbvt::DOUBLE_STACKSIZE);
+			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)
+					{
+						stkStack.resize(stkStack.size()*2);
+						treshold=stkStack.size()-4;
+					}
+					if(p.a->isinternal())
+					{
+						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);
+						}
+					}
+					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);
+						}
+					}
+				}
+			} while(depth);
+		}
+}
+
+void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+
+	const btCollisionObjectWrapper* col0ObjWrap = body0Wrap;
+	const btCollisionObjectWrapper* col1ObjWrap= body1Wrap;
+
+	btAssert (col0ObjWrap->getCollisionShape()->isCompound());
+	btAssert (col1ObjWrap->getCollisionShape()->isCompound());
+	const btCompoundShape* compoundShape0 = static_cast<const btCompoundShape*>(col0ObjWrap->getCollisionShape());
+	const btCompoundShape* compoundShape1 = static_cast<const btCompoundShape*>(col1ObjWrap->getCollisionShape());
+
+	const btDbvt* tree0 = compoundShape0->getDynamicAabbTree();
+	const btDbvt* tree1 = compoundShape1->getDynamicAabbTree();
+	if (!tree0 || !tree1)
+	{
+		return btCompoundCollisionAlgorithm::processCollision(body0Wrap,body1Wrap,dispatchInfo,resultOut);
+	}
+	///btCompoundShape might have changed:
+	////make sure the internal child collision algorithm caches are still valid
+	if ((compoundShape0->getUpdateRevision() != m_compoundShapeRevision0) || (compoundShape1->getUpdateRevision() != m_compoundShapeRevision1))
+	{
+		///clear all
+		removeChildAlgorithms();
+		m_compoundShapeRevision0 = compoundShape0->getUpdateRevision();
+		m_compoundShapeRevision1 = compoundShape1->getUpdateRevision();
+
+	}
+
+
+	///we need to refresh all contact manifolds
+	///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
+	{
+		int i;
+		btManifoldArray manifoldArray;
+		btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
+		for (i=0;i<pairs.size();i++)
+		{
+			if (pairs[i].m_userPointer)
+			{
+				btCollisionAlgorithm* algo = (btCollisionAlgorithm*) pairs[i].m_userPointer;
+				algo->getAllContactManifolds(manifoldArray);
+				for (int m=0;m<manifoldArray.size();m++)
+				{
+					if (manifoldArray[m]->getNumContacts())
+					{
+						resultOut->setPersistentManifold(manifoldArray[m]);
+						resultOut->refreshContactPoints();
+						resultOut->setPersistentManifold(0);
+					}
+				}
+				manifoldArray.resize(0);
+			}
+		}
+	}
+
+
+	
+
+	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);
+
+	//printf("#compound-compound child/leaf overlap =%d                      \r",callback.m_numOverlapPairs);
+
+	//remove non-overlapping child pairs
+
+	{
+		btAssert(m_removePairs.size()==0);
+
+		//iterate over all children, perform an AABB check inside ProcessChildShape
+		btSimplePairArray& pairs = m_childCollisionAlgorithmCache->getOverlappingPairArray();
+		
+		int i;
+		btManifoldArray	manifoldArray;
+        
+		
+
+        
+        
+        btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;        
+        
+		for (i=0;i<pairs.size();i++)
+		{
+			if (pairs[i].m_userPointer)
+			{
+				btCollisionAlgorithm* algo = (btCollisionAlgorithm*)pairs[i].m_userPointer;
+
+				{
+					btTransform	orgTrans0;
+					const btCollisionShape* childShape0 = 0;
+					
+					btTransform	newChildWorldTrans0;
+					btTransform	orgInterpolationTrans0;
+					childShape0 = compoundShape0->getChildShape(pairs[i].m_indexA);
+					orgTrans0 = col0ObjWrap->getWorldTransform();
+					orgInterpolationTrans0 = col0ObjWrap->getWorldTransform();
+					const btTransform& childTrans0 = compoundShape0->getChildTransform(pairs[i].m_indexA);
+					newChildWorldTrans0 = orgTrans0*childTrans0 ;
+					childShape0->getAabb(newChildWorldTrans0,aabbMin0,aabbMax0);
+				}
+				btVector3 thresholdVec(resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold, resultOut->m_closestPointDistanceThreshold);
+				aabbMin0 -= thresholdVec;
+				aabbMax0 += thresholdVec;
+				{
+					btTransform	orgInterpolationTrans1;
+					const btCollisionShape* childShape1 = 0;
+					btTransform	orgTrans1;
+					btTransform	newChildWorldTrans1;
+
+					childShape1 = compoundShape1->getChildShape(pairs[i].m_indexB);
+					orgTrans1 = col1ObjWrap->getWorldTransform();
+					orgInterpolationTrans1 = col1ObjWrap->getWorldTransform();
+					const btTransform& childTrans1 = compoundShape1->getChildTransform(pairs[i].m_indexB);
+					newChildWorldTrans1 = orgTrans1*childTrans1 ;
+					childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
+				}
+				
+				aabbMin1 -= thresholdVec;
+				aabbMax1 += thresholdVec;
+
+				if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
+				{
+					algo->~btCollisionAlgorithm();
+					m_dispatcher->freeCollisionAlgorithm(algo);
+					m_removePairs.push_back(btSimplePair(pairs[i].m_indexA,pairs[i].m_indexB));
+				}
+			}
+		}
+		for (int i=0;i<m_removePairs.size();i++)
+		{
+			m_childCollisionAlgorithmCache->removeOverlappingPair(m_removePairs[i].m_indexA,m_removePairs[i].m_indexB);
+		}
+		m_removePairs.clear();
+	}
+
+}
+
+btScalar	btCompoundCompoundCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+{
+	btAssert(0);
+	return 0.f;
+
+}
+
+
+

+ 89 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h

@@ -0,0 +1,89 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2013 Erwin Coumans  http://bulletphysics.org
+
+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_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
+#define BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H
+
+#include "btCompoundCollisionAlgorithm.h"
+
+#include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
+#include "BulletCollision/BroadphaseCollision/btDispatcher.h"
+#include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h"
+
+#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
+class btDispatcher;
+#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
+#include "BulletCollision/CollisionDispatch/btCollisionCreateFunc.h"
+#include "LinearMath/btAlignedObjectArray.h"
+#include "BulletCollision/CollisionDispatch/btHashedSimplePairCache.h"
+class btDispatcher;
+class btCollisionObject;
+
+class btCollisionShape;
+typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
+extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
+
+/// btCompoundCompoundCollisionAlgorithm  supports collision between two btCompoundCollisionShape shapes
+class btCompoundCompoundCollisionAlgorithm  : public btCompoundCollisionAlgorithm
+{
+
+	class btHashedSimplePairCache*	m_childCollisionAlgorithmCache;
+	btSimplePairArray m_removePairs;
+
+
+	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);
+
+public:
+
+	btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
+
+	virtual ~btCompoundCompoundCollisionAlgorithm();
+
+	
+
+	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);
+
+	virtual	void	getAllContactManifolds(btManifoldArray&	manifoldArray);
+	
+	
+	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
+	{
+		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		{
+			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
+			return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
+		}
+	};
+
+	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
+	{
+		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+		{
+			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btCompoundCompoundCollisionAlgorithm));
+			return new(mem) btCompoundCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
+		}
+	};
+
+};
+
+#endif //BT_COMPOUND_COMPOUND_COLLISION_ALGORITHM_H

+ 12 - 17
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp

@@ -43,12 +43,10 @@ subject to the following restrictions:
 
 
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
-
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
 btConvex2dConvex2dAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
 btConvex2dConvex2dAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
 {
 {
-	m_numPerturbationIterations = 0;
-	m_minimumPointsPerturbationThreshold = 3;
 	m_simplexSolver = simplexSolver;
 	m_simplexSolver = simplexSolver;
 	m_pdSolver = pdSolver;
 	m_pdSolver = pdSolver;
 }
 }
@@ -57,18 +55,16 @@ btConvex2dConvex2dAlgorithm::CreateFunc::~CreateFunc()
 { 
 { 
 }
 }
 
 
-btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
-: btActivatingCollisionAlgorithm(ci,body0,body1),
+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_simplexSolver(simplexSolver),
 m_pdSolver(pdSolver),
 m_pdSolver(pdSolver),
 m_ownManifold (false),
 m_ownManifold (false),
 m_manifoldPtr(mf),
 m_manifoldPtr(mf),
-m_lowLevelOfDetail(false),
- m_numPerturbationIterations(numPerturbationIterations),
-m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
+m_lowLevelOfDetail(false)
 {
 {
-	(void)body0;
-	(void)body1;
+	(void)body0Wrap;
+	(void)body1Wrap;
 }
 }
 
 
 
 
@@ -96,13 +92,13 @@ extern btScalar gContactBreakingThreshold;
 //
 //
 // Convex-Convex collision algorithm
 // Convex-Convex collision algorithm
 //
 //
-void btConvex2dConvex2dAlgorithm ::processCollision (btCollisionObject* body0,btCollisionObject* body1,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(body0,body1);
+		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
@@ -111,8 +107,8 @@ void btConvex2dConvex2dAlgorithm ::processCollision (btCollisionObject* body0,bt
 	//resultOut->getPersistentManifold()->clearManifold();
 	//resultOut->getPersistentManifold()->clearManifold();
 
 
 
 
-	btConvexShape* min0 = static_cast<btConvexShape*>(body0->getCollisionShape());
-	btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape());
+	const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
+	const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
 
 
 	btVector3  normalOnB;
 	btVector3  normalOnB;
 	btVector3  pointOnBWorld;
 	btVector3  pointOnBWorld;
@@ -132,9 +128,8 @@ void btConvex2dConvex2dAlgorithm ::processCollision (btCollisionObject* body0,bt
 			input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
 			input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
 		}
 		}
 
 
-		input.m_stackAlloc = dispatchInfo.m_stackAllocator;
-		input.m_transformA = body0->getWorldTransform();
-		input.m_transformB = body1->getWorldTransform();
+		input.m_transformA = body0Wrap->getWorldTransform();
+		input.m_transformB = body1Wrap->getWorldTransform();
 
 
 		gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 		gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 
 

+ 7 - 10
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h

@@ -13,8 +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 CONVEX_2D_CONVEX_2D_ALGORITHM_H
-#define CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#ifndef BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#define BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H
 
 
 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
@@ -40,17 +40,14 @@ class btConvex2dConvex2dAlgorithm : public btActivatingCollisionAlgorithm
 	btPersistentManifold*	m_manifoldPtr;
 	btPersistentManifold*	m_manifoldPtr;
 	bool			m_lowLevelOfDetail;
 	bool			m_lowLevelOfDetail;
 	
 	
-	int m_numPerturbationIterations;
-	int m_minimumPointsPerturbationThreshold;
-
 public:
 public:
 
 
-	btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);
+	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 (btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -82,14 +79,14 @@ public:
 		
 		
 		virtual ~CreateFunc();
 		virtual ~CreateFunc();
 
 
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,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 //CONVEX_2D_CONVEX_2D_ALGORITHM_H
+#endif //BT_CONVEX_2D_CONVEX_2D_ALGORITHM_H

+ 82 - 53
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp

@@ -15,6 +15,7 @@ subject to the following restrictions:
 
 
 
 
 #include "btConvexConcaveCollisionAlgorithm.h"
 #include "btConvexConcaveCollisionAlgorithm.h"
+#include "LinearMath/btQuickprof.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -25,11 +26,12 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "LinearMath/btIDebugDraw.h"
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
 #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
-btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
-: btActivatingCollisionAlgorithm(ci,body0,body1),
+btConvexConcaveCollisionAlgorithm::btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_isSwapped(isSwapped),
 m_isSwapped(isSwapped),
-m_btConvexTriangleCallback(ci.m_dispatcher1,body0,body1,isSwapped)
+m_btConvexTriangleCallback(ci.m_dispatcher1,body0Wrap,body1Wrap,isSwapped)
 {
 {
 }
 }
 
 
@@ -46,17 +48,17 @@ void	btConvexConcaveCollisionAlgorithm::getAllContactManifolds(btManifoldArray&
 }
 }
 
 
 
 
-btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher*  dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped):
+btConvexTriangleCallback::btConvexTriangleCallback(btDispatcher*  dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped):
 	  m_dispatcher(dispatcher),
 	  m_dispatcher(dispatcher),
 	m_dispatchInfoPtr(0)
 	m_dispatchInfoPtr(0)
 {
 {
-	m_convexBody = isSwapped? body1:body0;
-	m_triBody = isSwapped? body0:body1;
+	m_convexBodyWrap = isSwapped? body1Wrap:body0Wrap;
+	m_triBodyWrap = isSwapped? body0Wrap:body1Wrap;
 	
 	
 	  //
 	  //
 	  // create the manifold from the dispatcher 'manifold pool'
 	  // create the manifold from the dispatcher 'manifold pool'
 	  //
 	  //
-	  m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBody,m_triBody);
+	  m_manifoldPtr = m_dispatcher->getNewManifold(m_convexBodyWrap->getCollisionObject(),m_triBodyWrap->getCollisionObject());
 
 
   	  clearCache();
   	  clearCache();
 }
 }
@@ -75,82 +77,109 @@ void	btConvexTriangleCallback::clearCache()
 }
 }
 
 
 
 
-
-void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex)
+void btConvexTriangleCallback::processTriangle(btVector3* triangle,int
+partId, int triangleIndex)
 {
 {
- 
-	//just for debugging purposes
-	//printf("triangle %d",m_triangleCount++);
+	BT_PROFILE("btConvexTriangleCallback::processTriangle");
+
+	if (!TestTriangleAgainstAabb2(triangle, m_aabbMin, m_aabbMax))
+	{
+		return;
+	}
+
+        //just for debugging purposes
+        //printf("triangle %d",m_triangleCount++);
 
 
 
 
-	//aabb filter is already applied!	
 
 
 	btCollisionAlgorithmConstructionInfo ci;
 	btCollisionAlgorithmConstructionInfo ci;
 	ci.m_dispatcher1 = m_dispatcher;
 	ci.m_dispatcher1 = m_dispatcher;
 
 
-	btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBody);
 
 
 
 
+#if 0	
 	
 	
 	///debug drawing of the overlapping triangles
 	///debug drawing of the overlapping triangles
 	if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
 	if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
 	{
 	{
-		btVector3 color(255,255,0);
+		const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
+		btVector3 color(1,1,0);
 		btTransform& tr = ob->getWorldTransform();
 		btTransform& tr = ob->getWorldTransform();
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(triangle[2]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(triangle[2]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(triangle[0]),color);
-
-		//btVector3 center = triangle[0] + triangle[1]+triangle[2];
-		//center *= btScalar(0.333333);
-		//m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(center),color);
-		//m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[1]),tr(center),color);
-		//m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[2]),tr(center),color);
-
 	}
 	}
-
-
-	//btCollisionObject* colObj = static_cast<btCollisionObject*>(m_convexProxy->m_clientObject);
+#endif
 	
 	
-	if (m_convexBody->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);
 		
 		
-		btCollisionShape* tmpShape = ob->getCollisionShape();
-		ob->internalSetTemporaryCollisionShape( &tm );
 		
 		
-		btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr);
-		///this should use the btDispatcher, so the actual registered algorithm is used
-		//		btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody);
+		btCollisionObjectWrapper triObWrap(m_triBodyWrap,&tm,m_triBodyWrap->getCollisionObject(),m_triBodyWrap->getWorldTransform(),partId,triangleIndex);//correct transform?
+		btCollisionAlgorithm* colAlgo = 0;
+		
+		if (m_resultOut->m_closestPointDistanceThreshold > 0)
+		{
+			colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap, &triObWrap, 0, BT_CLOSEST_POINT_ALGORITHMS);
+		}
+		else
+		{
+			colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap, &triObWrap, m_manifoldPtr, BT_CONTACT_POINT_ALGORITHMS);
+		}
+		const btCollisionObjectWrapper* tmpWrap = 0;
 
 
-		m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
+		if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
+		{
+			tmpWrap = m_resultOut->getBody0Wrap();
+			m_resultOut->setBody0Wrap(&triObWrap);
+			m_resultOut->setShapeIdentifiersA(partId,triangleIndex);
+		}
+		else
+		{
+			tmpWrap = m_resultOut->getBody1Wrap();
+			m_resultOut->setBody1Wrap(&triObWrap);
+			m_resultOut->setShapeIdentifiersB(partId,triangleIndex);
+		}
 	
 	
-//		cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
-		colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut);
+		colAlgo->processCollision(m_convexBodyWrap,&triObWrap,*m_dispatchInfoPtr,m_resultOut);
+
+		if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
+		{
+			m_resultOut->setBody0Wrap(tmpWrap);
+		} else
+		{
+			m_resultOut->setBody1Wrap(tmpWrap);
+		}
+		
+
+
 		colAlgo->~btCollisionAlgorithm();
 		colAlgo->~btCollisionAlgorithm();
 		ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
 		ci.m_dispatcher1->freeCollisionAlgorithm(colAlgo);
-		ob->internalSetTemporaryCollisionShape( tmpShape);
 	}
 	}
 
 
-
 }
 }
 
 
 
 
 
 
-void	btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void	btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut)
 {
 {
+	m_convexBodyWrap = convexBodyWrap;
+	m_triBodyWrap = triBodyWrap;
+
 	m_dispatchInfoPtr = &dispatchInfo;
 	m_dispatchInfoPtr = &dispatchInfo;
 	m_collisionMarginTriangle = collisionMarginTriangle;
 	m_collisionMarginTriangle = collisionMarginTriangle;
 	m_resultOut = resultOut;
 	m_resultOut = resultOut;
 
 
 	//recalc aabbs
 	//recalc aabbs
 	btTransform convexInTriangleSpace;
 	btTransform convexInTriangleSpace;
-	convexInTriangleSpace = m_triBody->getWorldTransform().inverse() * m_convexBody->getWorldTransform();
-	btCollisionShape* convexShape = static_cast<btCollisionShape*>(m_convexBody->getCollisionShape());
+	convexInTriangleSpace = m_triBodyWrap->getWorldTransform().inverse() * m_convexBodyWrap->getWorldTransform();
+	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);
 	convexShape->getAabb(convexInTriangleSpace,m_aabbMin,m_aabbMax);
-	btScalar extraMargin = collisionMarginTriangle;
+	btScalar extraMargin = collisionMarginTriangle+ resultOut->m_closestPointDistanceThreshold;
+	
 	btVector3 extra(extraMargin,extraMargin,extraMargin);
 	btVector3 extra(extraMargin,extraMargin,extraMargin);
 
 
 	m_aabbMax += extra;
 	m_aabbMax += extra;
@@ -164,35 +193,34 @@ void btConvexConcaveCollisionAlgorithm::clearCache()
 
 
 }
 }
 
 
-void btConvexConcaveCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexConcaveCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
 {
+	BT_PROFILE("btConvexConcaveCollisionAlgorithm::processCollision");
 	
 	
-	
-	btCollisionObject* convexBody = m_isSwapped ? body1 : body0;
-	btCollisionObject* triBody = m_isSwapped ? body0 : body1;
+	const btCollisionObjectWrapper* convexBodyWrap = m_isSwapped ? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* triBodyWrap = m_isSwapped ? body0Wrap : body1Wrap;
 
 
-	if (triBody->getCollisionShape()->isConcave())
+	if (triBodyWrap->getCollisionShape()->isConcave())
 	{
 	{
 
 
 
 
-		btCollisionObject*	triOb = triBody;
-		btConcaveShape* concaveShape = static_cast<btConcaveShape*>( triOb->getCollisionShape());
 		
 		
-		if (convexBody->getCollisionShape()->isConvex())
+		const btConcaveShape* concaveShape = static_cast<const btConcaveShape*>( triBodyWrap->getCollisionShape());
+		
+		if (convexBodyWrap->getCollisionShape()->isConvex())
 		{
 		{
 			btScalar collisionMarginTriangle = concaveShape->getMargin();
 			btScalar collisionMarginTriangle = concaveShape->getMargin();
 					
 					
 			resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
 			resultOut->setPersistentManifold(m_btConvexTriangleCallback.m_manifoldPtr);
-			m_btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,resultOut);
+			m_btConvexTriangleCallback.setTimeStepAndCounters(collisionMarginTriangle,dispatchInfo,convexBodyWrap,triBodyWrap,resultOut);
 
 
-			//Disable persistency. previously, some older algorithm calculated all contacts in one go, so you can clear it here.
-			//m_dispatcher->clearManifold(m_btConvexTriangleCallback.m_manifoldPtr);
-
-			m_btConvexTriangleCallback.m_manifoldPtr->setBodies(convexBody,triBody);
+			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();
 	
 	
 		}
 		}
 	
 	
@@ -248,6 +276,7 @@ btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObj
 		
 		
 		virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 		virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 		{
 		{
+			BT_PROFILE("processTriangle");
 			(void)partId;
 			(void)partId;
 			(void)triangleIndex;
 			(void)triangleIndex;
 			//do a swept sphere for now
 			//do a swept sphere for now

+ 28 - 17
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h

@@ -13,8 +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 CONVEX_CONCAVE_COLLISION_ALGORITHM_H
-#define CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#ifndef BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#define BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H
 
 
 #include "btActivatingCollisionAlgorithm.h"
 #include "btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
 #include "BulletCollision/BroadphaseCollision/btDispatcher.h"
@@ -26,14 +26,16 @@ 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.
-class btConvexTriangleCallback : public btTriangleCallback
+ATTRIBUTE_ALIGNED16(class)  btConvexTriangleCallback : public btTriangleCallback
 {
 {
-	btCollisionObject* m_convexBody;
-	btCollisionObject* m_triBody;
 
 
 	btVector3	m_aabbMin;
 	btVector3	m_aabbMin;
 	btVector3	m_aabbMax ;
 	btVector3	m_aabbMax ;
 
 
+	const btCollisionObjectWrapper* m_convexBodyWrap;
+	const btCollisionObjectWrapper* m_triBodyWrap;
+
+
 
 
 	btManifoldResult* m_resultOut;
 	btManifoldResult* m_resultOut;
 	btDispatcher*	m_dispatcher;
 	btDispatcher*	m_dispatcher;
@@ -41,14 +43,21 @@ class btConvexTriangleCallback : public btTriangleCallback
 	btScalar m_collisionMarginTriangle;
 	btScalar m_collisionMarginTriangle;
 	
 	
 public:
 public:
+	BT_DECLARE_ALIGNED_ALLOCATOR();
+	
 int	m_triangleCount;
 int	m_triangleCount;
 	
 	
 	btPersistentManifold*	m_manifoldPtr;
 	btPersistentManifold*	m_manifoldPtr;
 
 
-	btConvexTriangleCallback(btDispatcher* dispatcher,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+	btConvexTriangleCallback(btDispatcher* dispatcher,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
 
-	void	setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	void	setTimeStepAndCounters(btScalar collisionMarginTriangle,const btDispatcherInfo& dispatchInfo,const btCollisionObjectWrapper* convexBodyWrap, const btCollisionObjectWrapper* triBodyWrap, btManifoldResult* resultOut);
 
 
+	void	clearWrapperData()
+	{
+		m_convexBodyWrap = 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);
@@ -70,22 +79,24 @@ int	m_triangleCount;
 
 
 
 
 /// btConvexConcaveCollisionAlgorithm  supports collision between convex shapes and (concave) trianges meshes.
 /// btConvexConcaveCollisionAlgorithm  supports collision between convex shapes and (concave) trianges meshes.
-class btConvexConcaveCollisionAlgorithm  : public btActivatingCollisionAlgorithm
+ATTRIBUTE_ALIGNED16(class)  btConvexConcaveCollisionAlgorithm  : public btActivatingCollisionAlgorithm
 {
 {
 
 
-	bool	m_isSwapped;
-
 	btConvexTriangleCallback m_btConvexTriangleCallback;
 	btConvexTriangleCallback m_btConvexTriangleCallback;
 
 
+	bool	m_isSwapped;
+
 
 
 
 
 public:
 public:
 
 
-	btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped);
+	BT_DECLARE_ALIGNED_ALLOCATOR();
+	
+	btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
 
 	virtual ~btConvexConcaveCollisionAlgorithm();
 	virtual ~btConvexConcaveCollisionAlgorithm();
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -95,22 +106,22 @@ public:
 
 
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,false);
+			return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
 		}
 		}
 	};
 	};
 
 
 	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct SwappedCreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,true);
+			return new(mem) btConvexConcaveCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //CONVEX_CONCAVE_COLLISION_ALGORITHM_H
+#endif //BT_CONVEX_CONCAVE_COLLISION_ALGORITHM_H

+ 291 - 72
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp

@@ -17,6 +17,7 @@ subject to the following restrictions:
 ///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums
 ///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums
 ///with reproduction case
 ///with reproduction case
 //define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1
 //define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1
+//#define ZERO_MARGIN
 
 
 #include "btConvexConvexAlgorithm.h"
 #include "btConvexConvexAlgorithm.h"
 
 
@@ -26,6 +27,8 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
 #include "BulletCollision/CollisionShapes/btCapsuleShape.h"
+#include "BulletCollision/CollisionShapes/btTriangleShape.h"
+
 
 
 
 
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
@@ -48,8 +51,8 @@ subject to the following restrictions:
 
 
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpa2.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
-
-
+#include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
 ///////////
 ///////////
 
 
@@ -176,11 +179,10 @@ static SIMD_FORCE_INLINE btScalar capsuleCapsuleDistance(
 
 
 
 
 
 
-btConvexConvexAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
+btConvexConvexAlgorithm::CreateFunc::CreateFunc(btConvexPenetrationDepthSolver* pdSolver)
 {
 {
 	m_numPerturbationIterations = 0;
 	m_numPerturbationIterations = 0;
 	m_minimumPointsPerturbationThreshold = 3;
 	m_minimumPointsPerturbationThreshold = 3;
-	m_simplexSolver = simplexSolver;
 	m_pdSolver = pdSolver;
 	m_pdSolver = pdSolver;
 }
 }
 
 
@@ -188,9 +190,8 @@ btConvexConvexAlgorithm::CreateFunc::~CreateFunc()
 { 
 { 
 }
 }
 
 
-btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
-: btActivatingCollisionAlgorithm(ci,body0,body1),
-m_simplexSolver(simplexSolver),
+btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+: btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_pdSolver(pdSolver),
 m_pdSolver(pdSolver),
 m_ownManifold (false),
 m_ownManifold (false),
 m_manifoldPtr(mf),
 m_manifoldPtr(mf),
@@ -202,8 +203,8 @@ m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngu
 m_numPerturbationIterations(numPerturbationIterations),
 m_numPerturbationIterations(numPerturbationIterations),
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 {
 {
-	(void)body0;
-	(void)body1;
+	(void)body0Wrap;
+	(void)body1Wrap;
 }
 }
 
 
 
 
@@ -238,8 +239,8 @@ struct btPerturbedContactResult : public btManifoldResult
 		:m_originalManifoldResult(originalResult),
 		:m_originalManifoldResult(originalResult),
 		m_transformA(transformA),
 		m_transformA(transformA),
 		m_transformB(transformB),
 		m_transformB(transformB),
-		m_perturbA(perturbA),
 		m_unPerturbedTransform(unPerturbedTransform),
 		m_unPerturbedTransform(unPerturbedTransform),
+		m_perturbA(perturbA),
 		m_debugDrawer(debugDrawer)
 		m_debugDrawer(debugDrawer)
 	{
 	{
 	}
 	}
@@ -286,13 +287,13 @@ extern btScalar gContactBreakingThreshold;
 //
 //
 // Convex-Convex collision algorithm
 // Convex-Convex collision algorithm
 //
 //
-void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexConvexAlgorithm ::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(body0,body1);
+		m_manifoldPtr = m_dispatcher->getNewManifold(body0Wrap->getCollisionObject(),body1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
@@ -301,8 +302,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 	//resultOut->getPersistentManifold()->clearManifold();
 	//resultOut->getPersistentManifold()->clearManifold();
 	
 	
 
 
-	btConvexShape* min0 = static_cast<btConvexShape*>(body0->getCollisionShape());
-	btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape());
+	const btConvexShape* min0 = static_cast<const btConvexShape*>(body0Wrap->getCollisionShape());
+	const btConvexShape* min1 = static_cast<const btConvexShape*>(body1Wrap->getCollisionShape());
 
 
 	btVector3  normalOnB;
 	btVector3  normalOnB;
 		btVector3  pointOnBWorld;
 		btVector3  pointOnBWorld;
@@ -311,14 +312,14 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 	{
 	{
 		btCapsuleShape* capsuleA = (btCapsuleShape*) min0;
 		btCapsuleShape* capsuleA = (btCapsuleShape*) min0;
 		btCapsuleShape* capsuleB = (btCapsuleShape*) min1;
 		btCapsuleShape* capsuleB = (btCapsuleShape*) min1;
-		btVector3 localScalingA = capsuleA->getLocalScaling();
-		btVector3 localScalingB = capsuleB->getLocalScaling();
+	//	btVector3 localScalingA = capsuleA->getLocalScaling();
+	//	btVector3 localScalingB = capsuleB->getLocalScaling();
 		
 		
 		btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
 		btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
 
 
 		btScalar dist = capsuleCapsuleDistance(normalOnB,	pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(),
 		btScalar dist = capsuleCapsuleDistance(normalOnB,	pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(),
 			capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(),
 			capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(),
-			body0->getWorldTransform(),body1->getWorldTransform(),threshold);
+			body0Wrap->getWorldTransform(),body1Wrap->getWorldTransform(),threshold);
 
 
 		if (dist<threshold)
 		if (dist<threshold)
 		{
 		{
@@ -331,8 +332,14 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 #endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER
 #endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER
 
 
 
 
+
+
 #ifdef USE_SEPDISTANCE_UTIL2
 #ifdef USE_SEPDISTANCE_UTIL2
-	m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform());
+	if (dispatchInfo.m_useConvexConservativeDistanceUtil)
+	{
+		m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform());
+	}
+
 	if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f)
 	if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f)
 #endif //USE_SEPDISTANCE_UTIL2
 #endif //USE_SEPDISTANCE_UTIL2
 
 
@@ -340,8 +347,8 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 
 
 	
 	
 	btGjkPairDetector::ClosestPointInput input;
 	btGjkPairDetector::ClosestPointInput input;
-
-	btGjkPairDetector	gjkPairDetector(min0,min1,m_simplexSolver,m_pdSolver);
+    btVoronoiSimplexSolver simplexSolver;
+    btGjkPairDetector	gjkPairDetector( min0, min1, &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);
@@ -353,18 +360,22 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 	} else
 	} else
 #endif //USE_SEPDISTANCE_UTIL2
 #endif //USE_SEPDISTANCE_UTIL2
 	{
 	{
-		input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
+		//if (dispatchInfo.m_convexMaxDistanceUseCPT)
+		//{
+		//	input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold();
+		//} else
+		//{
+		input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold()+resultOut->m_closestPointDistanceThreshold;
+//		}
+
 		input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
 		input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
 	}
 	}
 
 
-	input.m_stackAlloc = dispatchInfo.m_stackAllocator;
-	input.m_transformA = body0->getWorldTransform();
-	input.m_transformB = body1->getWorldTransform();
+	input.m_transformA = body0Wrap->getWorldTransform();
+	input.m_transformB = body1Wrap->getWorldTransform();
+
 
 
-	gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
 
 
-	btVector3 v0,v1;
-	btVector3 sepNormalWorldSpace;
 	
 	
 
 
 #ifdef USE_SEPDISTANCE_UTIL2
 #ifdef USE_SEPDISTANCE_UTIL2
@@ -376,73 +387,281 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
 		{
 		{
 			sepDist += dispatchInfo.m_convexConservativeDistanceThreshold;
 			sepDist += dispatchInfo.m_convexConservativeDistanceThreshold;
 			//now perturbe directions to get multiple contact points
 			//now perturbe directions to get multiple contact points
-			sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized();
-			btPlaneSpace1(sepNormalWorldSpace,v0,v1);
+			
 		}
 		}
 	}
 	}
 #endif //USE_SEPDISTANCE_UTIL2
 #endif //USE_SEPDISTANCE_UTIL2
 
 
-	//now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
-	
-	//perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points
-	if (resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)
+	if (min0->isPolyhedral() && min1->isPolyhedral())
 	{
 	{
-		
-		int i;
 
 
-		bool perturbeA = true;
-		const btScalar angleLimit = 0.125f * SIMD_PI;
-		btScalar perturbeAngle;
-		btScalar radiusA = min0->getAngularMotionDisc();
-		btScalar radiusB = min1->getAngularMotionDisc();
-		if (radiusA < radiusB)
+
+		struct btDummyResult : public btDiscreteCollisionDetectorInterface::Result
 		{
 		{
-			perturbeAngle = gContactBreakingThreshold /radiusA;
-			perturbeA = true;
-		} else
+			virtual void setShapeIdentifiersA(int partId0,int index0){}
+			virtual void setShapeIdentifiersB(int partId1,int index1){}
+			virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) 
+			{
+			}
+		};
+
+		
+		struct btWithoutMarginResult : public btDiscreteCollisionDetectorInterface::Result
 		{
 		{
-			perturbeAngle = gContactBreakingThreshold / radiusB;
-			perturbeA = false;
-		}
-		if ( perturbeAngle > angleLimit ) 
-				perturbeAngle = angleLimit;
+			btDiscreteCollisionDetectorInterface::Result* m_originalResult;
+			btVector3	m_reportedNormalOnWorld;
+			btScalar m_marginOnA;
+			btScalar m_marginOnB;
+			btScalar	m_reportedDistance;
+			
+			bool		m_foundResult;
+			btWithoutMarginResult(btDiscreteCollisionDetectorInterface::Result* result, btScalar marginOnA, btScalar marginOnB)
+			:m_originalResult(result),
+			m_marginOnA(marginOnA),
+			m_marginOnB(marginOnB),
+			m_foundResult(false)
+			{
+			}
+			
+			virtual void setShapeIdentifiersA(int partId0,int index0){}
+			virtual void setShapeIdentifiersB(int partId1,int index1){}
+			virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorldOrg,btScalar depthOrg) 
+			{
+				m_reportedDistance = depthOrg;
+				m_reportedNormalOnWorld = normalOnBInWorld;
+				
+				btVector3 adjustedPointB = pointInWorldOrg - normalOnBInWorld*m_marginOnB;
+				m_reportedDistance = depthOrg+(m_marginOnA+m_marginOnB);
+				if (m_reportedDistance<0.f)
+				{
+					m_foundResult = true;					
+				}
+				m_originalResult->addContactPoint(normalOnBInWorld,adjustedPointB,m_reportedDistance);
+			}
+		};
 
 
-		btTransform unPerturbedTransform;
-		if (perturbeA)
+		
+		btDummyResult dummy;
+
+///btBoxShape is an exception: its vertices are created WITH margin so don't subtract it
+
+		btScalar min0Margin = min0->getShapeType()==BOX_SHAPE_PROXYTYPE? 0.f : min0->getMargin();
+		btScalar min1Margin = min1->getShapeType()==BOX_SHAPE_PROXYTYPE? 0.f : min1->getMargin();
+
+		btWithoutMarginResult	withoutMargin(resultOut, min0Margin,min1Margin);
+
+		btPolyhedralConvexShape* polyhedronA = (btPolyhedralConvexShape*) min0;
+		btPolyhedralConvexShape* polyhedronB = (btPolyhedralConvexShape*) min1;
+		if (polyhedronA->getConvexPolyhedron() && polyhedronB->getConvexPolyhedron())
 		{
 		{
-			unPerturbedTransform = input.m_transformA;
+
+
+			
+
+			btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
+
+			btScalar minDist = -1e30f;
+			btVector3 sepNormalWorldSpace;
+			bool foundSepAxis  = true;
+
+			if (dispatchInfo.m_enableSatConvex)
+			{
+				foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis(
+					*polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
+					body0Wrap->getWorldTransform(), 
+					body1Wrap->getWorldTransform(),
+					sepNormalWorldSpace,*resultOut);
+			} else
+			{
+#ifdef ZERO_MARGIN
+				gjkPairDetector.setIgnoreMargin(true);
+				gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+#else
+
+
+				gjkPairDetector.getClosestPoints(input,withoutMargin,dispatchInfo.m_debugDraw);
+				//gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw);
+#endif //ZERO_MARGIN
+				//btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2();
+				//if (l2>SIMD_EPSILON)
+				{
+					sepNormalWorldSpace = withoutMargin.m_reportedNormalOnWorld;//gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2);
+					//minDist = -1e30f;//gjkPairDetector.getCachedSeparatingDistance();
+					minDist = withoutMargin.m_reportedDistance;//gjkPairDetector.getCachedSeparatingDistance()+min0->getMargin()+min1->getMargin();
+	
+#ifdef ZERO_MARGIN
+					foundSepAxis = true;//gjkPairDetector.getCachedSeparatingDistance()<0.f;
+#else
+					foundSepAxis = withoutMargin.m_foundResult && minDist<0;//-(min0->getMargin()+min1->getMargin());
+#endif
+				}
+			}
+			if (foundSepAxis)
+			{
+				
+//				printf("sepNormalWorldSpace=%f,%f,%f\n",sepNormalWorldSpace.getX(),sepNormalWorldSpace.getY(),sepNormalWorldSpace.getZ());
+
+				worldVertsB1.resize(0);
+				btPolyhedralContactClipping::clipHullAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
+					body0Wrap->getWorldTransform(), 
+																 body1Wrap->getWorldTransform(), minDist-threshold, threshold, worldVertsB1,worldVertsB2,
+																 *resultOut);
+ 				
+			}
+			if (m_ownManifold)
+			{
+				resultOut->refreshContactPoints();
+			}
+			return;
+
 		} else
 		} else
 		{
 		{
-			unPerturbedTransform = input.m_transformB;
+			//we can also deal with convex versus triangle (without connectivity data)
+			if (polyhedronA->getConvexPolyhedron() && polyhedronB->getShapeType()==TRIANGLE_SHAPE_PROXYTYPE)
+			{
+
+				btVertexArray vertices;
+				btTriangleShape* tri = (btTriangleShape*)polyhedronB;
+				vertices.push_back(	body1Wrap->getWorldTransform()*tri->m_vertices1[0]);
+				vertices.push_back(	body1Wrap->getWorldTransform()*tri->m_vertices1[1]);
+				vertices.push_back(	body1Wrap->getWorldTransform()*tri->m_vertices1[2]);
+				
+				//tri->initializePolyhedralFeatures();
+
+				btScalar threshold = m_manifoldPtr->getContactBreakingThreshold();
+
+				btVector3 sepNormalWorldSpace;
+				btScalar minDist =-1e30f;
+				btScalar maxDist = threshold;
+				
+				bool foundSepAxis = false;
+				if (0)
+				{
+					polyhedronB->initializePolyhedralFeatures();
+					 foundSepAxis = btPolyhedralContactClipping::findSeparatingAxis(
+					*polyhedronA->getConvexPolyhedron(), *polyhedronB->getConvexPolyhedron(),
+					body0Wrap->getWorldTransform(), 
+					body1Wrap->getWorldTransform(),
+					sepNormalWorldSpace,*resultOut);
+				//	 printf("sepNormalWorldSpace=%f,%f,%f\n",sepNormalWorldSpace.getX(),sepNormalWorldSpace.getY(),sepNormalWorldSpace.getZ());
+
+				} else
+				{
+#ifdef ZERO_MARGIN
+					gjkPairDetector.setIgnoreMargin(true);
+					gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+#else
+					gjkPairDetector.getClosestPoints(input,dummy,dispatchInfo.m_debugDraw);
+#endif//ZERO_MARGIN
+					
+					btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2();
+					if (l2>SIMD_EPSILON)
+					{
+						sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2);
+						//minDist = gjkPairDetector.getCachedSeparatingDistance();
+						//maxDist = threshold;
+						minDist = gjkPairDetector.getCachedSeparatingDistance()-min0->getMargin()-min1->getMargin();
+						foundSepAxis = true;
+					}
+				}
+
+				
+			if (foundSepAxis)
+			{
+				worldVertsB2.resize(0);
+				btPolyhedralContactClipping::clipFaceAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), 
+					body0Wrap->getWorldTransform(), vertices, worldVertsB2,minDist-threshold, maxDist, *resultOut);
+			}
+				
+				
+				if (m_ownManifold)
+				{
+					resultOut->refreshContactPoints();
+				}
+				
+				return;
+			}
+			
 		}
 		}
+
+
+	}
+	
+	gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
+
+	//now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects
+	
+	//perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points
+	if (m_numPerturbationIterations && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)
+	{
 		
 		
-		for ( i=0;i<m_numPerturbationIterations;i++)
+		int i;
+		btVector3 v0,v1;
+		btVector3 sepNormalWorldSpace;
+		btScalar l2 = gjkPairDetector.getCachedSeparatingAxis().length2();
+	
+		if (l2>SIMD_EPSILON)
 		{
 		{
-			btQuaternion perturbeRot(v0,perturbeAngle);
-			btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
-			btQuaternion rotq(sepNormalWorldSpace,iterationAngle);
-			
+			sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis()*(1.f/l2);
 			
 			
+			btPlaneSpace1(sepNormalWorldSpace,v0,v1);
+
+
+			bool perturbeA = true;
+			const btScalar angleLimit = 0.125f * SIMD_PI;
+			btScalar perturbeAngle;
+			btScalar radiusA = min0->getAngularMotionDisc();
+			btScalar radiusB = min1->getAngularMotionDisc();
+			if (radiusA < radiusB)
+			{
+				perturbeAngle = gContactBreakingThreshold /radiusA;
+				perturbeA = true;
+			} else
+			{
+				perturbeAngle = gContactBreakingThreshold / radiusB;
+				perturbeA = false;
+			}
+			if ( perturbeAngle > angleLimit ) 
+					perturbeAngle = angleLimit;
+
+			btTransform unPerturbedTransform;
 			if (perturbeA)
 			if (perturbeA)
 			{
 			{
-				input.m_transformA.setBasis(  btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0->getWorldTransform().getBasis());
-				input.m_transformB = body1->getWorldTransform();
-#ifdef DEBUG_CONTACTS
-				dispatchInfo.m_debugDraw->drawTransform(input.m_transformA,10.0);
-#endif //DEBUG_CONTACTS
+				unPerturbedTransform = input.m_transformA;
 			} else
 			} else
 			{
 			{
-				input.m_transformA = body0->getWorldTransform();
-				input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1->getWorldTransform().getBasis());
-#ifdef DEBUG_CONTACTS
-				dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0);
-#endif
+				unPerturbedTransform = input.m_transformB;
 			}
 			}
 			
 			
-			btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw);
-			gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw);
-			
-			
+			for ( i=0;i<m_numPerturbationIterations;i++)
+			{
+				if (v0.length2()>SIMD_EPSILON)
+				{
+				btQuaternion perturbeRot(v0,perturbeAngle);
+				btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
+				btQuaternion rotq(sepNormalWorldSpace,iterationAngle);
+				
+				
+				if (perturbeA)
+				{
+					input.m_transformA.setBasis(  btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body0Wrap->getWorldTransform().getBasis());
+					input.m_transformB = body1Wrap->getWorldTransform();
+	#ifdef DEBUG_CONTACTS
+					dispatchInfo.m_debugDraw->drawTransform(input.m_transformA,10.0);
+	#endif //DEBUG_CONTACTS
+				} else
+				{
+					input.m_transformA = body0Wrap->getWorldTransform();
+					input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*body1Wrap->getWorldTransform().getBasis());
+	#ifdef DEBUG_CONTACTS
+					dispatchInfo.m_debugDraw->drawTransform(input.m_transformB,10.0);
+	#endif
+				}
+				
+				btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw);
+				gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw);
+				}
+			}
 		}
 		}
 	}
 	}
 
 

+ 12 - 12
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h

@@ -13,8 +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 CONVEX_CONVEX_ALGORITHM_H
-#define CONVEX_CONVEX_ALGORITHM_H
+#ifndef BT_CONVEX_CONVEX_ALGORITHM_H
+#define BT_CONVEX_CONVEX_ALGORITHM_H
 
 
 #include "btActivatingCollisionAlgorithm.h"
 #include "btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h"
@@ -24,6 +24,7 @@ subject to the following restrictions:
 #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"
 
 
 class btConvexPenetrationDepthSolver;
 class btConvexPenetrationDepthSolver;
 
 
@@ -32,7 +33,7 @@ class btConvexPenetrationDepthSolver;
 ///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util
 ///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util
 ///for certain pairs that have a small size ratio
 ///for certain pairs that have a small size ratio
 
 
-#define USE_SEPDISTANCE_UTIL2 1
+//#define USE_SEPDISTANCE_UTIL2 1
 
 
 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects.
 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects.
 ///Multiple contact points are calculated by perturbing the orientation of the smallest object orthogonal to the separating normal.
 ///Multiple contact points are calculated by perturbing the orientation of the smallest object orthogonal to the separating normal.
@@ -42,9 +43,10 @@ class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 #ifdef USE_SEPDISTANCE_UTIL2
 #ifdef USE_SEPDISTANCE_UTIL2
 	btConvexSeparatingDistanceUtil	m_sepDistance;
 	btConvexSeparatingDistanceUtil	m_sepDistance;
 #endif
 #endif
-	btSimplexSolverInterface*		m_simplexSolver;
 	btConvexPenetrationDepthSolver* m_pdSolver;
 	btConvexPenetrationDepthSolver* m_pdSolver;
 
 
+	btVertexArray worldVertsB1;
+	btVertexArray worldVertsB2;
 	
 	
 	bool	m_ownManifold;
 	bool	m_ownManifold;
 	btPersistentManifold*	m_manifoldPtr;
 	btPersistentManifold*	m_manifoldPtr;
@@ -59,12 +61,11 @@ class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 
 
 public:
 public:
 
 
-	btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1, btSimplexSolverInterface* simplexSolver, 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 (btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -88,22 +89,21 @@ public:
 	{
 	{
 
 
 		btConvexPenetrationDepthSolver*		m_pdSolver;
 		btConvexPenetrationDepthSolver*		m_pdSolver;
-		btSimplexSolverInterface*			m_simplexSolver;
 		int m_numPerturbationIterations;
 		int m_numPerturbationIterations;
 		int m_minimumPointsPerturbationThreshold;
 		int m_minimumPointsPerturbationThreshold;
 
 
-		CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
+		CreateFunc(btConvexPenetrationDepthSolver* pdSolver);
 		
 		
 		virtual ~CreateFunc();
 		virtual ~CreateFunc();
 
 
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+			return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
 		}
 		}
 	};
 	};
 
 
 
 
 };
 };
 
 
-#endif //CONVEX_CONVEX_ALGORITHM_H
+#endif //BT_CONVEX_CONVEX_ALGORITHM_H

+ 46 - 27
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp

@@ -19,10 +19,11 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btConvexShape.h"
 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
+btConvexPlaneCollisionAlgorithm::btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped, int numPerturbationIterations,int minimumPointsPerturbationThreshold)
 : btCollisionAlgorithm(ci),
 : btCollisionAlgorithm(ci),
 m_ownManifold(false),
 m_ownManifold(false),
 m_manifoldPtr(mf),
 m_manifoldPtr(mf),
@@ -30,12 +31,12 @@ m_isSwapped(isSwapped),
 m_numPerturbationIterations(numPerturbationIterations),
 m_numPerturbationIterations(numPerturbationIterations),
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
 {
 {
-	btCollisionObject* convexObj = m_isSwapped? col1 : col0;
-	btCollisionObject* planeObj = m_isSwapped? col0 : col1;
+	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? col1Wrap : col0Wrap;
+	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? col0Wrap : col1Wrap;
 
 
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObj,planeObj))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(convexObjWrap->getCollisionObject(),planeObjWrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(convexObj,planeObj);
+		m_manifoldPtr = m_dispatcher->getNewManifold(convexObjWrap->getCollisionObject(),planeObjWrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -50,25 +51,25 @@ btConvexPlaneCollisionAlgorithm::~btConvexPlaneCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion& perturbeRot, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
 {
-    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
-	btCollisionObject* planeObj = m_isSwapped? body0: body1;
+    const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? body0Wrap: body1Wrap;
 
 
-	btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
-	btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->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 = convexObj->getWorldTransform();
+	btTransform convexWorldTransform = convexObjWrap->getWorldTransform();
 	btTransform convexInPlaneTrans;
 	btTransform convexInPlaneTrans;
-	convexInPlaneTrans= planeObj->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() * planeObj->getWorldTransform();
+	planeInConvex= convexWorldTransform.inverse() * planeObjWrap->getWorldTransform();
 	
 	
 	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
 	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
 
 
@@ -76,43 +77,61 @@ void btConvexPlaneCollisionAlgorithm::collideSingleContact (const btQuaternion&
 	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 
 
 	btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
 	btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
-	btVector3 vtxInPlaneWorld = planeObj->getWorldTransform() * vtxInPlaneProjected;
+	btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
 
 
 	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
 	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
 	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 = planeObj->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 (btCollisionObject* body0,btCollisionObject* body1,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;
 
 
-    btCollisionObject* convexObj = m_isSwapped? body1 : body0;
-	btCollisionObject* planeObj = m_isSwapped? body0: body1;
+	const btCollisionObjectWrapper* convexObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* planeObjWrap = m_isSwapped? body0Wrap: body1Wrap;
 
 
-	btConvexShape* convexShape = (btConvexShape*) convexObj->getCollisionShape();
-	btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape();
+	btConvexShape* convexShape = (btConvexShape*) convexObjWrap->getCollisionShape();
+	btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObjWrap->getCollisionShape();
 
 
-    
+	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;
+	planeInConvex= convexObjWrap->getWorldTransform().inverse() * planeObjWrap->getWorldTransform();
+	btTransform convexInPlaneTrans;
+	convexInPlaneTrans= planeObjWrap->getWorldTransform().inverse() * convexObjWrap->getWorldTransform();
+
+	btVector3 vtx = convexShape->localGetSupportingVertex(planeInConvex.getBasis()*-planeNormal);
+	btVector3 vtxInPlane = convexInPlaneTrans(vtx);
+	btScalar distance = (planeNormal.dot(vtxInPlane) - planeConstant);
 
 
-	//first perform a collision query with the non-perturbated collision objects
+	btVector3 vtxInPlaneProjected = vtxInPlane - distance*planeNormal;
+	btVector3 vtxInPlaneWorld = planeObjWrap->getWorldTransform() * vtxInPlaneProjected;
+
+	hasCollision = distance < m_manifoldPtr->getContactBreakingThreshold();
+	resultOut->setPersistentManifold(m_manifoldPtr);
+	if (hasCollision)
 	{
 	{
-		btQuaternion rotq(0,0,0,1);
-		collideSingleContact(rotq,body0,body1,dispatchInfo,resultOut);
+		/// report a contact. internally this will be kept persistent, and contact reduction is done
+		btVector3 normalOnSurfaceB = planeObjWrap->getWorldTransform().getBasis() * planeNormal;
+		btVector3 pOnB = vtxInPlaneWorld;
+		resultOut->addContactPoint(normalOnSurfaceB,pOnB,distance);
 	}
 	}
 
 
-	if (resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold)
+	//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
+	//so only enable the feature for polyhedral shapes (btBoxShape, btConvexHullShape etc)
+	if (convexShape->isPolyhedral() && resultOut->getPersistentManifold()->getNumContacts()<m_minimumPointsPerturbationThreshold)
 	{
 	{
 		btVector3 v0,v1;
 		btVector3 v0,v1;
 		btPlaneSpace1(planeNormal,v0,v1);
 		btPlaneSpace1(planeNormal,v0,v1);
@@ -130,7 +149,7 @@ void btConvexPlaneCollisionAlgorithm::processCollision (btCollisionObject* body0
 		{
 		{
 			btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
 			btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations));
 			btQuaternion rotq(planeNormal,iterationAngle);
 			btQuaternion rotq(planeNormal,iterationAngle);
-			collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0,body1,dispatchInfo,resultOut);
+			collideSingleContact(rotq.inverse()*perturbeRot*rotq,body0Wrap,body1Wrap,dispatchInfo,resultOut);
 		}
 		}
 	}
 	}
 
 

+ 10 - 10
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h

@@ -13,8 +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 CONVEX_PLANE_COLLISION_ALGORITHM_H
-#define CONVEX_PLANE_COLLISION_ALGORITHM_H
+#ifndef BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
+#define BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
 
 
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -36,13 +36,13 @@ class btConvexPlaneCollisionAlgorithm : public btCollisionAlgorithm
 
 
 public:
 public:
 
 
-	btConvexPlaneCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, 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 (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
+	virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
 
 
-	void collideSingleContact (const btQuaternion& perturbeRot, btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -61,24 +61,24 @@ public:
 			
 			
 		CreateFunc() 
 		CreateFunc() 
 			: m_numPerturbationIterations(1),
 			: m_numPerturbationIterations(1),
-			m_minimumPointsPerturbationThreshold(1)
+			m_minimumPointsPerturbationThreshold(0)
 		{
 		{
 		}
 		}
 		
 		
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,false,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+				return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
 			} else
 			} else
 			{
 			{
-				return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0,body1,true,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+				return new(mem) btConvexPlaneCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
 			}
 			}
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //CONVEX_PLANE_COLLISION_ALGORITHM_H
+#endif //BT_CONVEX_PLANE_COLLISION_ALGORITHM_H
 
 

+ 112 - 27
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp

@@ -19,6 +19,8 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h"
+#include "BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h"
+
 #include "BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
@@ -32,7 +34,6 @@ subject to the following restrictions:
 
 
 
 
 
 
-#include "LinearMath/btStackAlloc.h"
 #include "LinearMath/btPoolAllocator.h"
 #include "LinearMath/btPoolAllocator.h"
 
 
 
 
@@ -43,9 +44,7 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 //btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc*	stackAlloc,btPoolAllocator*	persistentManifoldPool,btPoolAllocator*	collisionAlgorithmPool)
 //btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(btStackAlloc*	stackAlloc,btPoolAllocator*	persistentManifoldPool,btPoolAllocator*	collisionAlgorithmPool)
 {
 {
 
 
-	void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16);
-	m_simplexSolver = new (mem)btVoronoiSimplexSolver();
-
+    void* mem = NULL;
 	if (constructionInfo.m_useEpaPenetrationAlgorithm)
 	if (constructionInfo.m_useEpaPenetrationAlgorithm)
 	{
 	{
 		mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
 		mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
@@ -58,13 +57,17 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 	
 	
 	//default CreationFunctions, filling the m_doubleDispatch table
 	//default CreationFunctions, filling the m_doubleDispatch table
 	mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16);
 	mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16);
-	m_convexConvexCreateFunc = new(mem) btConvexConvexAlgorithm::CreateFunc(m_simplexSolver,m_pdSolver);
+	m_convexConvexCreateFunc = new(mem) btConvexConvexAlgorithm::CreateFunc(m_pdSolver);
 	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
 	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
 	m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc;
 	m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc;
 	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
 	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
 	m_swappedConvexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
 	m_swappedConvexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::SwappedCreateFunc;
 	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc),16);
 	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::CreateFunc),16);
 	m_compoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::CreateFunc;
 	m_compoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::CreateFunc;
+
+	mem = btAlignedAlloc(sizeof(btCompoundCompoundCollisionAlgorithm::CreateFunc),16);
+	m_compoundCompoundCreateFunc = new (mem)btCompoundCompoundCollisionAlgorithm::CreateFunc;
+
 	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc),16);
 	mem = btAlignedAlloc(sizeof(btCompoundCollisionAlgorithm::SwappedCreateFunc),16);
 	m_swappedCompoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::SwappedCreateFunc;
 	m_swappedCompoundCreateFunc = new (mem)btCompoundCollisionAlgorithm::SwappedCreateFunc;
 	mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc),16);
 	mem = btAlignedAlloc(sizeof(btEmptyAlgorithm::CreateFunc),16);
@@ -100,22 +103,12 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 	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 sl = sizeof(btConvexSeparatingDistanceUtil);
-	sl = sizeof(btGjkPairDetector);
+	int maxSize4 = sizeof(btCompoundCompoundCollisionAlgorithm);
+
 	int	collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
 	int	collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
 	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
 	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
 	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
 	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
-
-	if (constructionInfo.m_stackAlloc)
-	{
-		m_ownsStackAllocator = false;
-		this->m_stackAlloc = constructionInfo.m_stackAlloc;
-	} else
-	{
-		m_ownsStackAllocator = true;
-		void* mem = btAlignedAlloc(sizeof(btStackAlloc),16);
-		m_stackAlloc = new(mem)btStackAlloc(constructionInfo.m_defaultStackAllocatorSize);
-	}
+	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize4);
 		
 		
 	if (constructionInfo.m_persistentManifoldPool)
 	if (constructionInfo.m_persistentManifoldPool)
 	{
 	{
@@ -128,6 +121,7 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 		m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
 		m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
 	}
 	}
 	
 	
+	collisionAlgorithmMaxElementSize = (collisionAlgorithmMaxElementSize+16)&0xffffffffffff0;
 	if (constructionInfo.m_collisionAlgorithmPool)
 	if (constructionInfo.m_collisionAlgorithmPool)
 	{
 	{
 		m_ownsCollisionAlgorithmPool = false;
 		m_ownsCollisionAlgorithmPool = false;
@@ -144,12 +138,6 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 
 
 btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 {
 {
-	if (m_ownsStackAllocator)
-	{
-		m_stackAlloc->destroy();
-		m_stackAlloc->~btStackAlloc();
-		btAlignedFree(m_stackAlloc);
-	}
 	if (m_ownsCollisionAlgorithmPool)
 	if (m_ownsCollisionAlgorithmPool)
 	{
 	{
 		m_collisionAlgorithmPool->~btPoolAllocator();
 		m_collisionAlgorithmPool->~btPoolAllocator();
@@ -172,6 +160,9 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 	m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_compoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	btAlignedFree( m_compoundCreateFunc);
 	btAlignedFree( m_compoundCreateFunc);
 
 
+	m_compoundCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
+	btAlignedFree(m_compoundCompoundCreateFunc);
+
 	m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	m_swappedCompoundCreateFunc->~btCollisionAlgorithmCreateFunc();
 	btAlignedFree( m_swappedCompoundCreateFunc);
 	btAlignedFree( m_swappedCompoundCreateFunc);
 
 
@@ -200,9 +191,6 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 	m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
 	m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
 	btAlignedFree( m_planeConvexCF);
 	btAlignedFree( m_planeConvexCF);
 
 
-	m_simplexSolver->~btVoronoiSimplexSolver();
-	btAlignedFree(m_simplexSolver);
-
 	m_pdSolver->~btConvexPenetrationDepthSolver();
 	m_pdSolver->~btConvexPenetrationDepthSolver();
 	
 	
 	btAlignedFree(m_pdSolver);
 	btAlignedFree(m_pdSolver);
@@ -210,6 +198,86 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 
 
 }
 }
 
 
+btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1)
+{
+
+
+	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
+	{
+		return	m_sphereSphereCF;
+	}
+#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
+	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == BOX_SHAPE_PROXYTYPE))
+	{
+		return	m_sphereBoxCF;
+	}
+
+	if ((proxyType0 == BOX_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
+	{
+		return	m_boxSphereCF;
+	}
+#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
+
+
+	if ((proxyType0 == SPHERE_SHAPE_PROXYTYPE) && (proxyType1 == TRIANGLE_SHAPE_PROXYTYPE))
+	{
+		return	m_sphereTriangleCF;
+	}
+
+	if ((proxyType0 == TRIANGLE_SHAPE_PROXYTYPE) && (proxyType1 == SPHERE_SHAPE_PROXYTYPE))
+	{
+		return	m_triangleSphereCF;
+	}
+
+	if (btBroadphaseProxy::isConvex(proxyType0) && (proxyType1 == STATIC_PLANE_PROXYTYPE))
+	{
+		return m_convexPlaneCF;
+	}
+
+	if (btBroadphaseProxy::isConvex(proxyType1) && (proxyType0 == STATIC_PLANE_PROXYTYPE))
+	{
+		return m_planeConvexCF;
+	}
+
+
+
+	if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConvex(proxyType1))
+	{
+		return m_convexConvexCreateFunc;
+	}
+
+	if (btBroadphaseProxy::isConvex(proxyType0) && btBroadphaseProxy::isConcave(proxyType1))
+	{
+		return m_convexConcaveCreateFunc;
+	}
+
+	if (btBroadphaseProxy::isConvex(proxyType1) && btBroadphaseProxy::isConcave(proxyType0))
+	{
+		return m_swappedConvexConcaveCreateFunc;
+	}
+
+
+	if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
+	{
+		return m_compoundCompoundCreateFunc;
+	}
+
+	if (btBroadphaseProxy::isCompound(proxyType0))
+	{
+		return m_compoundCreateFunc;
+	}
+	else
+	{
+		if (btBroadphaseProxy::isCompound(proxyType1))
+		{
+			return m_swappedCompoundCreateFunc;
+		}
+	}
+
+	//failed to find an algorithm
+	return m_emptyCreateFunc;
+
+}
 
 
 btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
 btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1)
 {
 {
@@ -275,6 +343,12 @@ btCollisionAlgorithmCreateFunc* btDefaultCollisionConfiguration::getCollisionAlg
 		return m_swappedConvexConcaveCreateFunc;
 		return m_swappedConvexConcaveCreateFunc;
 	}
 	}
 
 
+
+	if (btBroadphaseProxy::isCompound(proxyType0) && btBroadphaseProxy::isCompound(proxyType1))
+	{
+		return m_compoundCompoundCreateFunc;
+	}
+
 	if (btBroadphaseProxy::isCompound(proxyType0))
 	if (btBroadphaseProxy::isCompound(proxyType0))
 	{
 	{
 		return m_compoundCreateFunc;
 		return m_compoundCreateFunc;
@@ -296,3 +370,14 @@ void btDefaultCollisionConfiguration::setConvexConvexMultipointIterations(int nu
 	convexConvex->m_numPerturbationIterations = numPerturbationIterations;
 	convexConvex->m_numPerturbationIterations = numPerturbationIterations;
 	convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
 	convexConvex->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
 }
 }
+
+void	btDefaultCollisionConfiguration::setPlaneConvexMultipointIterations(int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+{
+	btConvexPlaneCollisionAlgorithm::CreateFunc* cpCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_convexPlaneCF;
+	cpCF->m_numPerturbationIterations = numPerturbationIterations;
+	cpCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
+	
+	btConvexPlaneCollisionAlgorithm::CreateFunc* pcCF = (btConvexPlaneCollisionAlgorithm::CreateFunc*)m_planeConvexCF;
+	pcCF->m_numPerturbationIterations = numPerturbationIterations;
+	pcCF->m_minimumPointsPerturbationThreshold = minimumPointsPerturbationThreshold;
+}

+ 8 - 16
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h

@@ -22,23 +22,19 @@ class btConvexPenetrationDepthSolver;
 
 
 struct	btDefaultCollisionConstructionInfo
 struct	btDefaultCollisionConstructionInfo
 {
 {
-	btStackAlloc*		m_stackAlloc;
 	btPoolAllocator*	m_persistentManifoldPool;
 	btPoolAllocator*	m_persistentManifoldPool;
 	btPoolAllocator*	m_collisionAlgorithmPool;
 	btPoolAllocator*	m_collisionAlgorithmPool;
 	int					m_defaultMaxPersistentManifoldPoolSize;
 	int					m_defaultMaxPersistentManifoldPoolSize;
 	int					m_defaultMaxCollisionAlgorithmPoolSize;
 	int					m_defaultMaxCollisionAlgorithmPoolSize;
 	int					m_customCollisionAlgorithmMaxElementSize;
 	int					m_customCollisionAlgorithmMaxElementSize;
-	int					m_defaultStackAllocatorSize;
 	int					m_useEpaPenetrationAlgorithm;
 	int					m_useEpaPenetrationAlgorithm;
 
 
 	btDefaultCollisionConstructionInfo()
 	btDefaultCollisionConstructionInfo()
-		:m_stackAlloc(0),
-		m_persistentManifoldPool(0),
+		:m_persistentManifoldPool(0),
 		m_collisionAlgorithmPool(0),
 		m_collisionAlgorithmPool(0),
 		m_defaultMaxPersistentManifoldPoolSize(4096),
 		m_defaultMaxPersistentManifoldPoolSize(4096),
 		m_defaultMaxCollisionAlgorithmPoolSize(4096),
 		m_defaultMaxCollisionAlgorithmPoolSize(4096),
 		m_customCollisionAlgorithmMaxElementSize(0),
 		m_customCollisionAlgorithmMaxElementSize(0),
-		m_defaultStackAllocatorSize(0),
 		m_useEpaPenetrationAlgorithm(true)
 		m_useEpaPenetrationAlgorithm(true)
 	{
 	{
 	}
 	}
@@ -56,8 +52,6 @@ protected:
 
 
 	int	m_persistentManifoldPoolSize;
 	int	m_persistentManifoldPoolSize;
 	
 	
-	btStackAlloc*	m_stackAlloc;
-	bool	m_ownsStackAllocator;
 
 
 	btPoolAllocator*	m_persistentManifoldPool;
 	btPoolAllocator*	m_persistentManifoldPool;
 	bool	m_ownsPersistentManifoldPool;
 	bool	m_ownsPersistentManifoldPool;
@@ -66,8 +60,7 @@ protected:
 	btPoolAllocator*	m_collisionAlgorithmPool;
 	btPoolAllocator*	m_collisionAlgorithmPool;
 	bool	m_ownsCollisionAlgorithmPool;
 	bool	m_ownsCollisionAlgorithmPool;
 
 
-	//default simplex/penetration depth solvers
-	btVoronoiSimplexSolver*	m_simplexSolver;
+	//default penetration depth solver
 	btConvexPenetrationDepthSolver*	m_pdSolver;
 	btConvexPenetrationDepthSolver*	m_pdSolver;
 	
 	
 	//default CreationFunctions, filling the m_doubleDispatch table
 	//default CreationFunctions, filling the m_doubleDispatch table
@@ -75,13 +68,13 @@ protected:
 	btCollisionAlgorithmCreateFunc*	m_convexConcaveCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_convexConcaveCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_swappedConvexConcaveCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_swappedConvexConcaveCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_compoundCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_compoundCreateFunc;
+	btCollisionAlgorithmCreateFunc*	m_compoundCompoundCreateFunc;
+	
 	btCollisionAlgorithmCreateFunc*	m_swappedCompoundCreateFunc;
 	btCollisionAlgorithmCreateFunc*	m_swappedCompoundCreateFunc;
 	btCollisionAlgorithmCreateFunc* m_emptyCreateFunc;
 	btCollisionAlgorithmCreateFunc* m_emptyCreateFunc;
 	btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
 	btCollisionAlgorithmCreateFunc* m_sphereSphereCF;
-#ifdef USE_BUGGY_SPHERE_BOX_ALGORITHM
 	btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
 	btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
 	btCollisionAlgorithmCreateFunc* m_boxSphereCF;
 	btCollisionAlgorithmCreateFunc* m_boxSphereCF;
-#endif //USE_BUGGY_SPHERE_BOX_ALGORITHM
 
 
 	btCollisionAlgorithmCreateFunc* m_boxBoxCF;
 	btCollisionAlgorithmCreateFunc* m_boxBoxCF;
 	btCollisionAlgorithmCreateFunc*	m_sphereTriangleCF;
 	btCollisionAlgorithmCreateFunc*	m_sphereTriangleCF;
@@ -107,14 +100,11 @@ public:
 		return m_collisionAlgorithmPool;
 		return m_collisionAlgorithmPool;
 	}
 	}
 
 
-	virtual btStackAlloc*	getStackAllocator()
-	{
-		return m_stackAlloc;
-	}
-
 
 
 	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1);
 	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1);
 
 
+	virtual btCollisionAlgorithmCreateFunc* getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1);
+
 	///Use this method to allow to generate multiple contact points between at once, between two objects using the generic convex-convex algorithm.
 	///Use this method to allow to generate multiple contact points between at once, between two objects using the generic convex-convex algorithm.
 	///By default, this feature is disabled for best performance.
 	///By default, this feature is disabled for best performance.
 	///@param numPerturbationIterations controls the number of collision queries. Set it to zero to disable the feature.
 	///@param numPerturbationIterations controls the number of collision queries. Set it to zero to disable the feature.
@@ -124,6 +114,8 @@ public:
 	///@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	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

+ 1 - 1
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.cpp

@@ -22,7 +22,7 @@ btEmptyAlgorithm::btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& c
 {
 {
 }
 }
 
 
-void btEmptyAlgorithm::processCollision (btCollisionObject* ,btCollisionObject* ,const btDispatcherInfo& ,btManifoldResult* )
+void btEmptyAlgorithm::processCollision (const btCollisionObjectWrapper* ,const btCollisionObjectWrapper* ,const btDispatcherInfo& ,btManifoldResult* )
 {
 {
 }
 }
 
 

+ 8 - 8
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btEmptyCollisionAlgorithm.h

@@ -13,8 +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 EMPTY_ALGORITH
-#define EMPTY_ALGORITH
+#ifndef BT_EMPTY_ALGORITH
+#define BT_EMPTY_ALGORITH
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 #include "btCollisionCreateFunc.h"
 #include "btCollisionCreateFunc.h"
 #include "btCollisionDispatcher.h"
 #include "btCollisionDispatcher.h"
@@ -30,7 +30,7 @@ public:
 	
 	
 	btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 	btEmptyAlgorithm(const btCollisionAlgorithmConstructionInfo& ci);
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -40,10 +40,10 @@ public:
 
 
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
-		{
-			(void)body0;
-			(void)body1;
+        virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
+        {
+			(void)body0Wrap;
+			(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);
 		}
 		}
@@ -51,4 +51,4 @@ public:
 
 
 } ATTRIBUTE_ALIGNED(16);
 } ATTRIBUTE_ALIGNED(16);
 
 
-#endif //EMPTY_ALGORITH
+#endif //BT_EMPTY_ALGORITH

+ 3 - 2
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btGhostObject.h

@@ -160,7 +160,7 @@ public:
 		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
@@ -171,4 +171,5 @@ public:
 
 
 };
 };
 
 
-#endif
+#endif
+

+ 276 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp

@@ -0,0 +1,276 @@
+/*
+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 "btHashedSimplePairCache.h"
+
+
+#include <stdio.h>
+
+int	gOverlappingSimplePairs = 0;
+int gRemoveSimplePairs =0;
+int gAddedSimplePairs =0;
+int gFindSimplePairs =0;
+
+
+
+
+btHashedSimplePairCache::btHashedSimplePairCache() {
+	int initialAllocatedSize= 2;
+	m_overlappingPairArray.reserve(initialAllocatedSize);
+	growTables();
+}
+
+
+
+
+btHashedSimplePairCache::~btHashedSimplePairCache()
+{
+}
+
+
+
+
+
+
+void btHashedSimplePairCache::removeAllPairs()
+{
+	m_overlappingPairArray.clear();
+	m_hashTable.clear();
+	m_next.clear();
+
+	int initialAllocatedSize= 2;
+	m_overlappingPairArray.reserve(initialAllocatedSize);
+	growTables();
+}
+
+
+
+btSimplePair* btHashedSimplePairCache::findPair(int indexA, int indexB)
+{
+	gFindSimplePairs++;
+	
+	
+	/*if (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));
+
+	if (hash >= m_hashTable.size())
+	{
+		return NULL;
+	}
+
+	int index = m_hashTable[hash];
+	while (index != BT_SIMPLE_NULL_PAIR && equalsPair(m_overlappingPairArray[index], indexA, indexB) == false)
+	{
+		index = m_next[index];
+	}
+
+	if (index == BT_SIMPLE_NULL_PAIR)
+	{
+		return NULL;
+	}
+
+	btAssert(index < m_overlappingPairArray.size());
+
+	return &m_overlappingPairArray[index];
+}
+
+//#include <stdio.h>
+
+void	btHashedSimplePairCache::growTables()
+{
+
+	int newCapacity = m_overlappingPairArray.capacity();
+
+	if (m_hashTable.size() < newCapacity)
+	{
+		//grow hashtable and next table
+		int curHashtableSize = m_hashTable.size();
+
+		m_hashTable.resize(newCapacity);
+		m_next.resize(newCapacity);
+
+
+		int i;
+
+		for (i= 0; i < newCapacity; ++i)
+		{
+			m_hashTable[i] = BT_SIMPLE_NULL_PAIR;
+		}
+		for (i = 0; i < newCapacity; ++i)
+		{
+			m_next[i] = BT_SIMPLE_NULL_PAIR;
+		}
+
+		for(i=0;i<curHashtableSize;i++)
+		{
+	
+			const btSimplePair& pair = m_overlappingPairArray[i];
+			int indexA = pair.m_indexA;
+			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
+			m_next[i] = m_hashTable[hashValue];
+			m_hashTable[hashValue] = i;
+		}
+
+
+	}
+}
+
+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
+
+
+	btSimplePair* pair = internalFindPair(indexA, indexB, hash);
+	if (pair != NULL)
+	{
+		return pair;
+	}
+
+	int count = m_overlappingPairArray.size();
+	int oldCapacity = m_overlappingPairArray.capacity();
+	void* mem = &m_overlappingPairArray.expandNonInitializing();
+
+	int newCapacity = m_overlappingPairArray.capacity();
+
+	if (oldCapacity < newCapacity)
+	{
+		growTables();
+		//hash with new capacity
+		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->m_userPointer = 0;
+	
+	m_next[count] = m_hashTable[hash];
+	m_hashTable[hash] = count;
+
+	return pair;
+}
+
+
+
+void* btHashedSimplePairCache::removeOverlappingPair(int indexA, int indexB)
+{
+	gRemoveSimplePairs++;
+	
+
+	/*if (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));
+
+	btSimplePair* pair = internalFindPair(indexA, indexB, hash);
+	if (pair == NULL)
+	{
+		return 0;
+	}
+
+	
+	void* userData = pair->m_userPointer;
+
+
+	int pairIndex = int(pair - &m_overlappingPairArray[0]);
+	btAssert(pairIndex < m_overlappingPairArray.size());
+
+	// Remove the pair from the hash table.
+	int index = m_hashTable[hash];
+	btAssert(index != BT_SIMPLE_NULL_PAIR);
+
+	int previous = BT_SIMPLE_NULL_PAIR;
+	while (index != pairIndex)
+	{
+		previous = index;
+		index = m_next[index];
+	}
+
+	if (previous != BT_SIMPLE_NULL_PAIR)
+	{
+		btAssert(m_next[previous] == pairIndex);
+		m_next[previous] = m_next[pairIndex];
+	}
+	else
+	{
+		m_hashTable[hash] = m_next[pairIndex];
+	}
+
+	// We now move the last pair into spot of the
+	// pair being removed. We need to fix the hash
+	// table indices to support the move.
+
+	int lastPairIndex = m_overlappingPairArray.size() - 1;
+
+	// If the removed pair is the last pair, we are done.
+	if (lastPairIndex == pairIndex)
+	{
+		m_overlappingPairArray.pop_back();
+		return userData;
+	}
+
+	// Remove the last pair from the hash table.
+	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));
+
+	index = m_hashTable[lastHash];
+	btAssert(index != BT_SIMPLE_NULL_PAIR);
+
+	previous = BT_SIMPLE_NULL_PAIR;
+	while (index != lastPairIndex)
+	{
+		previous = index;
+		index = m_next[index];
+	}
+
+	if (previous != BT_SIMPLE_NULL_PAIR)
+	{
+		btAssert(m_next[previous] == lastPairIndex);
+		m_next[previous] = m_next[lastPairIndex];
+	}
+	else
+	{
+		m_hashTable[lastHash] = m_next[lastPairIndex];
+	}
+
+	// Copy the last pair into the remove pair's spot.
+	m_overlappingPairArray[pairIndex] = m_overlappingPairArray[lastPairIndex];
+
+	// Insert the last pair into the hash table
+	m_next[pairIndex] = m_hashTable[lastHash];
+	m_hashTable[lastHash] = pairIndex;
+
+	m_overlappingPairArray.pop_back();
+
+	return userData;
+}
+//#include <stdio.h>
+
+
+
+
+
+
+
+
+
+

+ 172 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.h

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

+ 838 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp

@@ -0,0 +1,838 @@
+#include "btInternalEdgeUtility.h"
+
+#include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
+#include "BulletCollision/CollisionShapes/btTriangleShape.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"
+#include "LinearMath/btIDebugDraw.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+
+//#define DEBUG_INTERNAL_EDGE
+
+#ifdef DEBUG_INTERNAL_EDGE
+#include <stdio.h>
+#endif //DEBUG_INTERNAL_EDGE
+
+
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+static btIDebugDraw* gDebugDrawer = 0;
+
+void	btSetDebugDrawer(btIDebugDraw* debugDrawer)
+{
+	gDebugDrawer = debugDrawer;
+}
+
+static void    btDebugDrawLine(const btVector3& from,const btVector3& to, const btVector3& color)
+{
+	if (gDebugDrawer)
+		gDebugDrawer->drawLine(from,to,color);
+}
+#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
+
+
+static int	btGetHash(int partId, int triangleIndex)
+{
+	int hash = (partId<<(31-MAX_NUM_PARTS_IN_BITS)) | triangleIndex;
+	return hash;
+}
+
+
+
+static btScalar btGetAngle(const btVector3& edgeA, const btVector3& normalA,const btVector3& normalB)
+{
+	const btVector3 refAxis0  = edgeA;
+	const btVector3 refAxis1  = normalA;
+	const btVector3 swingAxis = normalB;
+	btScalar angle = btAtan2(swingAxis.dot(refAxis0), swingAxis.dot(refAxis1));
+	return  angle;
+}
+
+
+struct btConnectivityProcessor : public btTriangleCallback
+{
+	int				m_partIdA;
+	int				m_triangleIndexA;
+	btVector3*		m_triangleVerticesA;
+	btTriangleInfoMap*	m_triangleInfoMap;
+
+
+	virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
+	{
+		//skip self-collisions
+		if ((m_partIdA == partId) && (m_triangleIndexA == triangleIndex))
+			return;
+
+		//skip duplicates (disabled for now)
+		//if ((m_partIdA <= partId) && (m_triangleIndexA <= triangleIndex))
+		//	return;
+
+		//search for shared vertices and edges
+		int numshared = 0;
+		int sharedVertsA[3]={-1,-1,-1};
+		int sharedVertsB[3]={-1,-1,-1};
+
+		///skip degenerate triangles
+		btScalar crossBSqr = ((triangle[1]-triangle[0]).cross(triangle[2]-triangle[0])).length2();
+		if (crossBSqr < m_triangleInfoMap->m_equalVertexThreshold)
+			return;
+
+
+		btScalar crossASqr = ((m_triangleVerticesA[1]-m_triangleVerticesA[0]).cross(m_triangleVerticesA[2]-m_triangleVerticesA[0])).length2();
+		///skip degenerate triangles
+		if (crossASqr< m_triangleInfoMap->m_equalVertexThreshold)
+			return;
+
+#if 0
+		printf("triangle A[0]	=	(%f,%f,%f)\ntriangle A[1]	=	(%f,%f,%f)\ntriangle A[2]	=	(%f,%f,%f)\n",
+			m_triangleVerticesA[0].getX(),m_triangleVerticesA[0].getY(),m_triangleVerticesA[0].getZ(),
+			m_triangleVerticesA[1].getX(),m_triangleVerticesA[1].getY(),m_triangleVerticesA[1].getZ(),
+			m_triangleVerticesA[2].getX(),m_triangleVerticesA[2].getY(),m_triangleVerticesA[2].getZ());
+
+		printf("partId=%d, triangleIndex=%d\n",partId,triangleIndex);
+		printf("triangle B[0]	=	(%f,%f,%f)\ntriangle B[1]	=	(%f,%f,%f)\ntriangle B[2]	=	(%f,%f,%f)\n",
+			triangle[0].getX(),triangle[0].getY(),triangle[0].getZ(),
+			triangle[1].getX(),triangle[1].getY(),triangle[1].getZ(),
+			triangle[2].getX(),triangle[2].getY(),triangle[2].getZ());
+#endif
+
+		for (int i=0;i<3;i++)
+		{
+			for (int j=0;j<3;j++)
+			{
+				if ( (m_triangleVerticesA[i]-triangle[j]).length2() < m_triangleInfoMap->m_equalVertexThreshold)
+				{
+					sharedVertsA[numshared] = i;
+					sharedVertsB[numshared] = j;
+					numshared++;
+					///degenerate case
+					if(numshared >= 3)
+						return;
+				}
+			}
+			///degenerate case
+			if(numshared >= 3)
+				return;
+		}
+		switch (numshared)
+		{
+		case 0:
+			{
+				break;
+			}
+		case 1:
+			{
+				//shared vertex
+				break;
+			}
+		case 2:
+			{
+				//shared edge
+				//we need to make sure the edge is in the order V2V0 and not V0V2 so that the signs are correct
+				if (sharedVertsA[0] == 0 && sharedVertsA[1] == 2)
+				{
+					sharedVertsA[0] = 2;
+					sharedVertsA[1] = 0;
+					int tmp = sharedVertsB[1];
+					sharedVertsB[1] = sharedVertsB[0];
+					sharedVertsB[0] = tmp;
+				}
+
+				int hash = btGetHash(m_partIdA,m_triangleIndexA);
+
+				btTriangleInfo* info = m_triangleInfoMap->find(hash);
+				if (!info)
+				{
+					btTriangleInfo tmp;
+					m_triangleInfoMap->insert(hash,tmp);
+					info = m_triangleInfoMap->find(hash);
+				}
+
+				int sumvertsA = sharedVertsA[0]+sharedVertsA[1];
+				int otherIndexA = 3-sumvertsA;
+
+				
+				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 tB(triangle[sharedVertsB[1]],triangle[sharedVertsB[0]],triangle[otherIndexB]);
+				//btTriangleShape tB(triangle[0],triangle[1],triangle[2]);
+
+				btVector3 normalA;
+				btVector3 normalB;
+				tA.calcNormal(normalA);
+				tB.calcNormal(normalB);
+				edge.normalize();
+				btVector3 edgeCrossA = edge.cross(normalA).normalize();
+
+				{
+					btVector3 tmp = m_triangleVerticesA[otherIndexA]-m_triangleVerticesA[sharedVertsA[0]];
+					if (edgeCrossA.dot(tmp) < 0)
+					{
+						edgeCrossA*=-1;
+					}
+				}
+
+				btVector3 edgeCrossB = edge.cross(normalB).normalize();
+
+				{
+					btVector3 tmp = triangle[otherIndexB]-triangle[sharedVertsB[0]];
+					if (edgeCrossB.dot(tmp) < 0)
+					{
+						edgeCrossB*=-1;
+					}
+				}
+
+				btScalar	angle2 = 0;
+				btScalar	ang4 = 0.f;
+
+
+				btVector3 calculatedEdge = edgeCrossA.cross(edgeCrossB);
+				btScalar len2 = calculatedEdge.length2();
+
+				btScalar correctedAngle(0);
+				//btVector3 calculatedNormalB = normalA;
+				bool isConvex = false;
+
+				if (len2<m_triangleInfoMap->m_planarEpsilon)
+				{
+					angle2 = 0.f;
+					ang4 = 0.f;
+				} else
+				{
+
+					calculatedEdge.normalize();
+					btVector3 calculatedNormalA = calculatedEdge.cross(edgeCrossA);
+					calculatedNormalA.normalize();
+					angle2 = btGetAngle(calculatedNormalA,edgeCrossA,edgeCrossB);
+					ang4 = SIMD_PI-angle2;
+					btScalar dotA = normalA.dot(edgeCrossB);
+					///@todo: check if we need some epsilon, due to floating point imprecision
+					isConvex = (dotA<0.);
+
+					correctedAngle = isConvex ? ang4 : -ang4;
+				}
+
+				
+
+				
+							
+				//alternatively use 
+				//btVector3 calculatedNormalB2 = quatRotate(orn,normalA);
+
+
+				switch (sumvertsA)
+				{
+				case 1:
+					{
+						btVector3 edge = m_triangleVerticesA[0]-m_triangleVerticesA[1];
+						btQuaternion orn(edge,-correctedAngle);
+						btVector3 computedNormalB = quatRotate(orn,normalA);
+						btScalar bla = computedNormalB.dot(normalB);
+						if (bla<0)
+						{
+							computedNormalB*=-1;
+							info->m_flags |= TRI_INFO_V0V1_SWAP_NORMALB;
+						}
+#ifdef DEBUG_INTERNAL_EDGE
+						if ((computedNormalB-normalB).length()>0.0001)
+						{
+							printf("warning: normals not identical\n");
+						}
+#endif//DEBUG_INTERNAL_EDGE
+
+						info->m_edgeV0V1Angle = -correctedAngle;
+
+						if (isConvex)
+							info->m_flags |= TRI_INFO_V0V1_CONVEX;
+						break;
+					}
+				case 2:
+					{
+						btVector3 edge = m_triangleVerticesA[2]-m_triangleVerticesA[0];
+						btQuaternion orn(edge,-correctedAngle);
+						btVector3 computedNormalB = quatRotate(orn,normalA);
+						if (computedNormalB.dot(normalB)<0)
+						{
+							computedNormalB*=-1;
+							info->m_flags |= TRI_INFO_V2V0_SWAP_NORMALB;
+						}
+
+#ifdef DEBUG_INTERNAL_EDGE
+						if ((computedNormalB-normalB).length()>0.0001)
+						{
+							printf("warning: normals not identical\n");
+						}
+#endif //DEBUG_INTERNAL_EDGE
+						info->m_edgeV2V0Angle = -correctedAngle;
+						if (isConvex)
+							info->m_flags |= TRI_INFO_V2V0_CONVEX;
+						break;	
+					}
+				case 3:
+					{
+						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;
+							computedNormalB*=-1;
+						}
+#ifdef DEBUG_INTERNAL_EDGE
+						if ((computedNormalB-normalB).length()>0.0001)
+						{
+							printf("warning: normals not identical\n");
+						}
+#endif //DEBUG_INTERNAL_EDGE
+						info->m_edgeV1V2Angle = -correctedAngle;
+
+						if (isConvex)
+							info->m_flags |= TRI_INFO_V1V2_CONVEX;
+						break;
+					}
+				}
+
+				break;
+			}
+		default:
+			{
+				//				printf("warning: duplicate triangle\n");
+			}
+
+		}
+	}
+};
+/////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////
+
+void btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangleInfoMap* triangleInfoMap)
+{
+	//the user pointer shouldn't already be used for other purposes, we intend to store connectivity info there!
+	if (trimeshShape->getTriangleInfoMap())
+		return;
+
+	trimeshShape->setTriangleInfoMap(triangleInfoMap);
+
+	btStridingMeshInterface* meshInterface = trimeshShape->getMeshInterface();
+	const btVector3& meshScaling = meshInterface->getScaling();
+
+	for (int partId = 0; partId< meshInterface->getNumSubParts();partId++)
+	{
+		const unsigned char *vertexbase = 0;
+		int numverts = 0;
+		PHY_ScalarType type = PHY_INTEGER;
+		int stride = 0;
+		const unsigned char *indexbase = 0;
+		int indexstride = 0;
+		int numfaces = 0;
+		PHY_ScalarType indicestype = PHY_INTEGER;
+		//PHY_ScalarType indexType=0;
+
+		btVector3 triangleVerts[3];
+		meshInterface->getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,	type,stride,&indexbase,indexstride,numfaces,indicestype,partId);
+		btVector3 aabbMin,aabbMax;
+
+		for (int triangleIndex = 0 ; triangleIndex < numfaces;triangleIndex++)
+		{
+			unsigned int* gfxbase = (unsigned int*)(indexbase+triangleIndex*indexstride);
+
+			for (int j=2;j>=0;j--)
+			{
+
+				int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
+				if (type == PHY_FLOAT)
+				{
+					float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
+					triangleVerts[j] = btVector3(
+						graphicsbase[0]*meshScaling.getX(),
+						graphicsbase[1]*meshScaling.getY(),
+						graphicsbase[2]*meshScaling.getZ());
+				}
+				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()));
+				}
+			}
+			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]);
+			aabbMax.setMax(triangleVerts[0]);
+			aabbMin.setMin(triangleVerts[1]);
+			aabbMax.setMax(triangleVerts[1]);
+			aabbMin.setMin(triangleVerts[2]);
+			aabbMax.setMax(triangleVerts[2]);
+
+			btConnectivityProcessor connectivityProcessor;
+			connectivityProcessor.m_partIdA = partId;
+			connectivityProcessor.m_triangleIndexA = triangleIndex;
+			connectivityProcessor.m_triangleVerticesA = &triangleVerts[0];
+			connectivityProcessor.m_triangleInfoMap  = triangleInfoMap;
+
+			trimeshShape->processAllTriangles(&connectivityProcessor,aabbMin,aabbMax);
+		}
+
+	}
+
+}
+
+
+
+
+// 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.
+void btNearestPointInLineSegment(const btVector3 &point, const btVector3& line0, const btVector3& line1, btVector3& nearestPoint)
+{
+	btVector3 lineDelta     = line1 - line0;
+
+	// Handle degenerate lines
+	if ( lineDelta.fuzzyZero())
+	{
+		nearestPoint = line0;
+	}
+	else
+	{
+		btScalar delta = (point-line0).dot(lineDelta) / (lineDelta).dot(lineDelta);
+
+		// Clamp the point to conform to the segment's endpoints
+		if ( delta < 0 )
+			delta = 0;
+		else if ( delta > 1 )
+			delta = 1;
+
+		nearestPoint = line0 + lineDelta*delta;
+	}
+}
+
+
+
+
+bool	btClampNormal(const btVector3& edge,const btVector3& tri_normal_org,const btVector3& localContactNormalOnB, btScalar correctedEdgeAngle, btVector3 & clampedLocalNormal)
+{
+	btVector3 tri_normal = tri_normal_org;
+	//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
+
+	btVector3 edgeCross = edge.cross(tri_normal).normalize();
+	btScalar curAngle = btGetAngle(edgeCross,tri_normal,localContactNormalOnB);
+
+	if (correctedEdgeAngle<0)
+	{
+		if (curAngle < correctedEdgeAngle)
+		{
+			btScalar diffAngle = correctedEdgeAngle-curAngle;
+			btQuaternion rotation(edge,diffAngle );
+			clampedLocalNormal = btMatrix3x3(rotation)*localContactNormalOnB;
+			return true;
+		}
+	}
+
+	if (correctedEdgeAngle>=0)
+	{
+		if (curAngle > correctedEdgeAngle)
+		{
+			btScalar diffAngle = correctedEdgeAngle-curAngle;
+			btQuaternion rotation(edge,diffAngle );
+			clampedLocalNormal = btMatrix3x3(rotation)*localContactNormalOnB;
+			return true;
+		}
+	}
+	return false;
+}
+
+
+
+/// 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)
+{
+	//btAssert(colObj0->getCollisionShape()->getShapeType() == TRIANGLE_SHAPE_PROXYTYPE);
+	if (colObj0Wrap->getCollisionShape()->getShapeType() != TRIANGLE_SHAPE_PROXYTYPE)
+		return;
+
+	btBvhTriangleMeshShape* trimesh = 0;
+	
+	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)
+		return;
+
+	int hash = btGetHash(partId0,index0);
+
+
+	btTriangleInfo* info = triangleInfoMapPtr->find(hash);
+	if (!info)
+		return;
+
+	btScalar frontFacing = (normalAdjustFlags & BT_TRIANGLE_CONVEX_BACKFACE_MODE)==0? 1.f : -1.f;
+	
+	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 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 tri_normal;
+	tri_shape->calcNormal(tri_normal);
+
+	//btScalar dot = tri_normal.dot(cp.m_normalWorldOnB);
+	btVector3 nearest;
+	btNearestPointInLineSegment(cp.m_localPointB,v0,v1,nearest);
+
+	btVector3 contact = cp.m_localPointB;
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+	const btTransform& tr = colObj0->getWorldTransform();
+	btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,red);
+#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
+
+
+
+	bool isNearEdge = false;
+
+	int numConcaveEdgeHits = 0;
+	int numConvexEdgeHits = 0;
+
+	btVector3 localContactNormalOnB = colObj0Wrap->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB;
+	localContactNormalOnB.normalize();//is this necessary?
+	
+	// Get closest edge
+	int      bestedge=-1;
+	btScalar    disttobestedge=BT_LARGE_FLOAT;
+	//
+	// 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;
+      }	      
+   }	   
+	// 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;
+      }	      
+   }	   
+	// 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;
+      }	      
+   }   	      	
+	
+#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)
+	{
+#ifdef BT_INTERNAL_EDGE_DEBUG_DRAW
+		btDebugDrawLine(tr*contact,tr*(contact+cp.m_normalWorldOnB*10),black);
+#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
+			{
+
+				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;
+
+				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);
+
+#ifdef 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 (((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);
+#ifdef 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
+   btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix , green );
+#endif   
+
+	if (btFabs(info->m_edgeV1V2Angle)< 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==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;
+
+			if (info->m_edgeV1V2Angle == btScalar(0))
+			{
+				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
+
+
+				btScalar	NdotA = localContactNormalOnB.dot(nA);
+				btScalar	NdotB = localContactNormalOnB.dot(nB);
+				bool backFacingNormal = (NdotA< triangleInfoMapPtr->m_convexEpsilon) && (NdotB<triangleInfoMapPtr->m_convexEpsilon);
+
+				if (backFacingNormal)
+				{
+					numConcaveEdgeHits++;
+				}
+				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)
+					{
+						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);
+#ifdef 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
+   btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix , blue );
+#endif   
+
+	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
+			btDebugDrawLine(tr*nearest,tr*(nearest+tri_normal*10),white);
+#endif //BT_INTERNAL_EDGE_DEBUG_DRAW
+
+			btVector3 edge(v2-v0);
+
+			if (info->m_edgeV2V0Angle==btScalar(0))
+			{
+				numConcaveEdgeHits++;
+			} else
+			{
+
+				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);
+
+				if (backFacingNormal)
+				{
+					numConcaveEdgeHits++;
+				}
+				else
+				{
+					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)
+					{
+						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
+	{
+		btVector3 color(0,1,1);
+		btDebugDrawLine(cp.getPositionWorldOnB(),cp.getPositionWorldOnB()+cp.m_normalWorldOnB*10,color);
+	}
+#endif //DEBUG_INTERNAL_EDGE
+
+	if (isNearEdge)
+	{
+
+		if (numConcaveEdgeHits>0)
+		{
+			if ((normalAdjustFlags & BT_TRIANGLE_CONCAVE_DOUBLE_SIDED)!=0)
+			{
+				//fix tri_normal so it pointing the same direction as the current local contact normal
+				if (tri_normal.dot(localContactNormalOnB) < 0)
+				{
+					tri_normal *= -1;
+				}
+				cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis()*tri_normal;
+			} else
+			{
+				btVector3 newNormal = tri_normal *frontFacing;
+				//if the tri_normal is pointing opposite direction as the current local contact normal, skip it
+				btScalar d = newNormal.dot(localContactNormalOnB) ;
+				if (d< 0)
+				{
+					return;
+				}
+				//modify the normal to be the triangle normal (or backfacing normal)
+				cp.m_normalWorldOnB = colObj0Wrap->getWorldTransform().getBasis() *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);
+		}
+	}
+}

+ 47 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.h

@@ -0,0 +1,47 @@
+
+#ifndef BT_INTERNAL_EDGE_UTILITY_H
+#define BT_INTERNAL_EDGE_UTILITY_H
+
+#include "LinearMath/btHashMap.h"
+#include "LinearMath/btVector3.h"
+
+#include "BulletCollision/CollisionShapes/btTriangleInfoMap.h"
+
+///The btInternalEdgeUtility helps to avoid or reduce artifacts due to wrong collision normals caused by internal edges.
+///See also http://code.google.com/p/bullet/issues/detail?id=27
+
+class btBvhTriangleMeshShape;
+class btCollisionObject;
+struct btCollisionObjectWrapper;
+class btManifoldPoint;
+class btIDebugDraw;
+
+
+
+enum btInternalEdgeAdjustFlags
+{
+	BT_TRIANGLE_CONVEX_BACKFACE_MODE = 1,
+	BT_TRIANGLE_CONCAVE_DOUBLE_SIDED = 2, //double sided options are experimental, single sided is recommended
+	BT_TRIANGLE_CONVEX_DOUBLE_SIDED = 4
+};
+
+
+///Call btGenerateInternalEdgeInfo to create triangle info, store in the shape 'userInfo'
+void	btGenerateInternalEdgeInfo (btBvhTriangleMeshShape*trimeshShape, btTriangleInfoMap* triangleInfoMap);
+
+
+///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
+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.
+///If the utility doesn't work properly, you might have to adjust the threshold values in btTriangleInfoMap
+//#define 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
+

+ 78 - 21
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp

@@ -17,13 +17,40 @@ subject to the following restrictions:
 #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"
 
 
 ///This is to allow MaterialCombiner/Custom Friction/Restitution values
 ///This is to allow MaterialCombiner/Custom Friction/Restitution values
 ContactAddedCallback		gContactAddedCallback=0;
 ContactAddedCallback		gContactAddedCallback=0;
 
 
+
+
+btScalar	btManifoldResult::calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+{
+	btScalar friction = body0->getRollingFriction() * body1->getFriction() + body1->getRollingFriction() * 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	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;
+}
+
 ///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;
-inline btScalar	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();
 
 
@@ -36,26 +63,41 @@ inline btScalar	calculateCombinedFriction(const btCollisionObject* body0,const b
 
 
 }
 }
 
 
-inline btScalar	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)
+{
+    return body0->getContactDamping() + body1->getContactDamping();
+}
+
+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;
+}
 
 
 
 
-btManifoldResult::btManifoldResult(btCollisionObject* body0,btCollisionObject* body1)
+btManifoldResult::btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
 		:m_manifoldPtr(0),
 		:m_manifoldPtr(0),
-		m_body0(body0),
-		m_body1(body1)
+		m_body0Wrap(body0Wrap),
+		m_body1Wrap(body1Wrap)
 #ifdef DEBUG_PART_INDEX
 #ifdef DEBUG_PART_INDEX
 		,m_partId0(-1),
 		,m_partId0(-1),
 	m_partId1(-1),
 	m_partId1(-1),
 	m_index0(-1),
 	m_index0(-1),
 	m_index1(-1)
 	m_index1(-1)
 #endif //DEBUG_PART_INDEX
 #endif //DEBUG_PART_INDEX
+	, m_closestPointDistanceThreshold(0)
 {
 {
-	m_rootTransA = body0->getWorldTransform();
-	m_rootTransB = body1->getWorldTransform();
 }
 }
 
 
 
 
@@ -63,11 +105,12 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
 {
 {
 	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())
 		return;
 		return;
 
 
-	bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
+	bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
 
 
 	btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
 	btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
 
 
@@ -76,12 +119,12 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
 	
 	
 	if (isSwapped)
 	if (isSwapped)
 	{
 	{
-		localA = m_rootTransB.invXform(pointA );
-		localB = m_rootTransA.invXform(pointInWorld);
+		localA = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+		localB = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
 	} else
 	} else
 	{
 	{
-		localA = m_rootTransA.invXform(pointA );
-		localB = m_rootTransB.invXform(pointInWorld);
+		localA = m_body0Wrap->getCollisionObject()->getWorldTransform().invXform(pointA );
+		localB = m_body1Wrap->getCollisionObject()->getWorldTransform().invXform(pointInWorld);
 	}
 	}
 
 
 	btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
 	btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
@@ -90,9 +133,23 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
 	
 	
 	int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
 	int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
 
 
-	newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
-	newPt.m_combinedRestitution = calculateCombinedRestitution(m_body0,m_body1);
+	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.
    //BP mod, store contact triangles.
 	if (isSwapped)
 	if (isSwapped)
 	{
 	{
@@ -121,13 +178,13 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
 	//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_body0->getCollisionFlags() & btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK) ||
-		   (m_body1->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.
-		btCollisionObject* obj0 = isSwapped? m_body1 : m_body0;
-		btCollisionObject* obj1 = isSwapped? m_body0 : m_body1;
-		(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,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);
 	}
 	}
 
 
 }
 }

+ 51 - 19
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.h

@@ -14,18 +14,22 @@ subject to the following restrictions:
 */
 */
 
 
 
 
-#ifndef MANIFOLD_RESULT_H
-#define MANIFOLD_RESULT_H
+#ifndef BT_MANIFOLD_RESULT_H
+#define BT_MANIFOLD_RESULT_H
 
 
 class btCollisionObject;
 class btCollisionObject;
+struct btCollisionObjectWrapper;
+
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
 class btManifoldPoint;
 class btManifoldPoint;
 
 
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 #include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
 
 
 #include "LinearMath/btTransform.h"
 #include "LinearMath/btTransform.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 
 
-typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);
+typedef bool (*ContactAddedCallback)(btManifoldPoint& cp,	const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1);
 extern ContactAddedCallback		gContactAddedCallback;
 extern ContactAddedCallback		gContactAddedCallback;
 
 
 //#define DEBUG_PART_INDEX 1
 //#define DEBUG_PART_INDEX 1
@@ -34,34 +38,34 @@ extern ContactAddedCallback		gContactAddedCallback;
 ///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
 {
 {
-	btPersistentManifold* m_manifoldPtr;
+protected:
 
 
-	//we need this for compounds
-	btTransform	m_rootTransA;
-	btTransform	m_rootTransB;
+	btPersistentManifold* m_manifoldPtr;
 
 
-	btCollisionObject* m_body0;
-	btCollisionObject* m_body1;
+	const btCollisionObjectWrapper* m_body0Wrap;
+	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_partId0(-1),
 	m_partId1(-1),
 	m_partId1(-1),
 	m_index0(-1),
 	m_index0(-1),
 	m_index1(-1)
 	m_index1(-1)
 #endif //DEBUG_PART_INDEX
 #endif //DEBUG_PART_INDEX
+		m_closestPointDistanceThreshold(0)
 	{
 	{
 	}
 	}
 
 
-	btManifoldResult(btCollisionObject* body0,btCollisionObject* body1);
+	btManifoldResult(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap);
 
 
 	virtual ~btManifoldResult() {};
 	virtual ~btManifoldResult() {};
 
 
@@ -100,27 +104,55 @@ public:
 		if (!m_manifoldPtr->getNumContacts())
 		if (!m_manifoldPtr->getNumContacts())
 			return;
 			return;
 
 
-		bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
+		bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
 
 
 		if (isSwapped)
 		if (isSwapped)
 		{
 		{
-			m_manifoldPtr->refreshContactPoints(m_rootTransB,m_rootTransA);
+			m_manifoldPtr->refreshContactPoints(m_body1Wrap->getCollisionObject()->getWorldTransform(),m_body0Wrap->getCollisionObject()->getWorldTransform());
 		} else
 		} else
 		{
 		{
-			m_manifoldPtr->refreshContactPoints(m_rootTransA,m_rootTransB);
+			m_manifoldPtr->refreshContactPoints(m_body0Wrap->getCollisionObject()->getWorldTransform(),m_body1Wrap->getCollisionObject()->getWorldTransform());
 		}
 		}
 	}
 	}
 
 
+	const btCollisionObjectWrapper* getBody0Wrap() const
+	{
+		return m_body0Wrap;
+	}
+	const btCollisionObjectWrapper* getBody1Wrap() const
+	{
+		return m_body1Wrap;
+	}
+
+	void setBody0Wrap(const btCollisionObjectWrapper* obj0Wrap)
+	{
+		m_body0Wrap = obj0Wrap;
+	}
+
+	void setBody1Wrap(const btCollisionObjectWrapper* obj1Wrap)
+	{
+		m_body1Wrap = obj1Wrap;
+	}
+
 	const btCollisionObject* getBody0Internal() const
 	const btCollisionObject* getBody0Internal() const
 	{
 	{
-		return m_body0;
+		return m_body0Wrap->getCollisionObject();
 	}
 	}
 
 
 	const btCollisionObject* getBody1Internal() const
 	const btCollisionObject* getBody1Internal() const
 	{
 	{
-		return m_body1;
+		return m_body1Wrap->getCollisionObject();
 	}
 	}
-	
+
+	btScalar	m_closestPointDistanceThreshold;
+
+	/// 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);
 };
 };
 
 
-#endif //MANIFOLD_RESULT_H
+#endif //BT_MANIFOLD_RESULT_H

+ 86 - 26
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp

@@ -1,3 +1,4 @@
+
 /*
 /*
 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/
@@ -44,10 +45,14 @@ void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */,btColl
 {
 {
 	
 	
 	{
 	{
+		btOverlappingPairCache* pairCachePtr = colWorld->getPairCache();
+		const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs();
+		if (numOverlappingPairs)
+		{
+		btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr();
 		
 		
-		for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++)
+		for (int i=0;i<numOverlappingPairs;i++)
 		{
 		{
-			btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr();
 			const btBroadphasePair& collisionPair = pairPtr[i];
 			const btBroadphasePair& collisionPair = pairPtr[i];
 			btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
 			btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject;
 			btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
 			btCollisionObject* colObj1 = (btCollisionObject*)collisionPair.m_pProxy1->m_clientObject;
@@ -60,18 +65,73 @@ void btSimulationIslandManager::findUnions(btDispatcher* /* dispatcher */,btColl
 					(colObj1)->getIslandTag());
 					(colObj1)->getIslandTag());
 			}
 			}
 		}
 		}
+		}
+	}
+}
+
+#ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION
+void   btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
+{
+
+	// put the index into m_controllers into m_tag   
+	int index = 0;
+	{
+
+		int i;
+		for (i=0;i<colWorld->getCollisionObjectArray().size(); i++)
+		{
+			btCollisionObject*   collisionObject= colWorld->getCollisionObjectArray()[i];
+			//Adding filtering here
+			if (!collisionObject->isStaticOrKinematicObject())
+			{
+				collisionObject->setIslandTag(index++);
+			}
+			collisionObject->setCompanionId(-1);
+			collisionObject->setHitFraction(btScalar(1.));
+		}
+	}
+	// do the union find
+
+	initUnionFind( index );
+
+	findUnions(dispatcher,colWorld);
+}
+
+void   btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld)
+{
+	// put the islandId ('find' value) into m_tag   
+	{
+		int index = 0;
+		int i;
+		for (i=0;i<colWorld->getCollisionObjectArray().size();i++)
+		{
+			btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i];
+			if (!collisionObject->isStaticOrKinematicObject())
+			{
+				collisionObject->setIslandTag( m_unionFind.find(index) );
+				//Set the correct object offset in Collision Object Array
+				m_unionFind.getElement(index).m_sz = i;
+				collisionObject->setCompanionId(-1);
+				index++;
+			} else
+			{
+				collisionObject->setIslandTag(-1);
+				collisionObject->setCompanionId(-2);
+			}
+		}
 	}
 	}
 }
 }
 
 
 
 
+#else //STATIC_SIMULATION_ISLAND_OPTIMIZATION
 void	btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher)
 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++)
@@ -81,26 +141,20 @@ void	btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld
 			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++)
@@ -120,6 +174,8 @@ void	btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* col
 	}
 	}
 }
 }
 
 
+#endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION
+
 inline	int	getIslandId(const btPersistentManifold* lhs)
 inline	int	getIslandId(const btPersistentManifold* lhs)
 {
 {
 	int islandId;
 	int islandId;
@@ -137,7 +193,7 @@ class btPersistentManifoldSortPredicate
 {
 {
 	public:
 	public:
 
 
-		SIMD_FORCE_INLINE bool operator() ( const btPersistentManifold* lhs, const btPersistentManifold* rhs )
+		SIMD_FORCE_INLINE bool operator() ( const btPersistentManifold* lhs, const btPersistentManifold* rhs ) const
 		{
 		{
 			return getIslandId(lhs) < getIslandId(rhs);
 			return getIslandId(lhs) < getIslandId(rhs);
 		}
 		}
@@ -263,8 +319,8 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
 	{
 	{
 		 btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
 		 btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
 		 
 		 
-		 btCollisionObject* colObj0 = static_cast<btCollisionObject*>(manifold->getBody0());
-		 btCollisionObject* colObj1 = static_cast<btCollisionObject*>(manifold->getBody1());
+		 const btCollisionObject* colObj0 = static_cast<const btCollisionObject*>(manifold->getBody0());
+		 const btCollisionObject* colObj1 = static_cast<const btCollisionObject*>(manifold->getBody1());
 		
 		
 		 ///@todo: check sleeping conditions!
 		 ///@todo: check sleeping conditions!
 		 if (((colObj0) && colObj0->getActivationState() != ISLAND_SLEEPING) ||
 		 if (((colObj0) && colObj0->getActivationState() != ISLAND_SLEEPING) ||
@@ -274,11 +330,13 @@ void btSimulationIslandManager::buildIslands(btDispatcher* dispatcher,btCollisio
 			//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)
 			{
 			{
-				colObj1->activate();
+				if (colObj0->hasContactResponse())
+					colObj1->activate();
 			}
 			}
 			if (colObj1->isKinematicObject() && colObj1->getActivationState() != ISLAND_SLEEPING)
 			if (colObj1->isKinematicObject() && colObj1->getActivationState() != ISLAND_SLEEPING)
 			{
 			{
-				colObj0->activate();
+				if (colObj1->hasContactResponse())
+					colObj0->activate();
 			}
 			}
 			if(m_splitIslands)
 			if(m_splitIslands)
 			{ 
 			{ 
@@ -309,7 +367,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 	{
 	{
 		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
 	{
 	{
@@ -319,8 +377,10 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 
 
 		int numManifolds = int (m_islandmanifold.size());
 		int numManifolds = int (m_islandmanifold.size());
 
 
-		//we should do radix sort, it it much faster (O(n) instead of O (n log2(n))
+		//tried a radix sort, but quicksort/heapsort seems still faster
+		//@todo rewrite island management
 		m_islandmanifold.quickSort(btPersistentManifoldSortPredicate());
 		m_islandmanifold.quickSort(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)
 
 
@@ -339,15 +399,15 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 			int islandId = getUnionFind().getElement(startIslandIndex).m_id;
 			int islandId = getUnionFind().getElement(startIslandIndex).m_id;
 
 
 
 
-			   bool islandSleeping = false;
+			   bool islandSleeping = true;
 	                
 	                
 					for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++)
 					for (endIslandIndex = startIslandIndex;(endIslandIndex<numElem) && (getUnionFind().getElement(endIslandIndex).m_id == islandId);endIslandIndex++)
 					{
 					{
 							int i = getUnionFind().getElement(endIslandIndex).m_sz;
 							int i = getUnionFind().getElement(endIslandIndex).m_sz;
 							btCollisionObject* colObj0 = collisionObjects[i];
 							btCollisionObject* colObj0 = collisionObjects[i];
 							m_islandBodies.push_back(colObj0);
 							m_islandBodies.push_back(colObj0);
-							if (!colObj0->isActive())
-									islandSleeping = true;
+							if (colObj0->isActive())
+									islandSleeping = false;
 					}
 					}
 	                
 	                
 
 
@@ -374,7 +434,7 @@ void btSimulationIslandManager::buildAndProcessIslands(btDispatcher* dispatcher,
 
 
 			if (!islandSleeping)
 			if (!islandSleeping)
 			{
 			{
-				callback->ProcessIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId);
+				callback->processIsland(&m_islandBodies[0],m_islandBodies.size(),startManifold,numIslandManifolds, islandId);
 	//			printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
 	//			printf("Island callback of size:%d bodies, %d manifolds\n",islandBodies.size(),numIslandManifolds);
 			}
 			}
 			
 			

+ 4 - 4
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSimulationIslandManager.h

@@ -13,8 +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 SIMULATION_ISLAND_MANAGER_H
-#define SIMULATION_ISLAND_MANAGER_H
+#ifndef BT_SIMULATION_ISLAND_MANAGER_H
+#define BT_SIMULATION_ISLAND_MANAGER_H
 
 
 #include "BulletCollision/CollisionDispatch/btUnionFind.h"
 #include "BulletCollision/CollisionDispatch/btUnionFind.h"
 #include "btCollisionCreateFunc.h"
 #include "btCollisionCreateFunc.h"
@@ -59,7 +59,7 @@ public:
 	{
 	{
 		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	buildAndProcessIslands(btDispatcher* dispatcher,btCollisionWorld* collisionWorld, IslandCallback* callback);
@@ -77,5 +77,5 @@ public:
 
 
 };
 };
 
 
-#endif //SIMULATION_ISLAND_MANAGER_H
+#endif //BT_SIMULATION_ISLAND_MANAGER_H
 
 

+ 109 - 155
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp

@@ -18,20 +18,21 @@ subject to the following restrictions:
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btBoxShape.h"
 #include "BulletCollision/CollisionShapes/btBoxShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 //#include <stdio.h>
 //#include <stdio.h>
 
 
-btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped)
-: btActivatingCollisionAlgorithm(ci,col0,col1),
+btSphereBoxCollisionAlgorithm::btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped)
+: btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
 m_ownManifold(false),
 m_ownManifold(false),
 m_manifoldPtr(mf),
 m_manifoldPtr(mf),
 m_isSwapped(isSwapped)
 m_isSwapped(isSwapped)
 {
 {
-	btCollisionObject* sphereObj = m_isSwapped? col1 : col0;
-	btCollisionObject* boxObj = m_isSwapped? col0 : col1;
+	const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped? col1Wrap : col0Wrap;
+	const btCollisionObjectWrapper* boxObjWrap = m_isSwapped? col0Wrap : col1Wrap;
 	
 	
-	if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObj,boxObj))
+	if (!m_manifoldPtr && m_dispatcher->needsCollision(sphereObjWrap->getCollisionObject(),boxObjWrap->getCollisionObject()))
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(sphereObj,boxObj);
+		m_manifoldPtr = m_dispatcher->getNewManifold(sphereObjWrap->getCollisionObject(),boxObjWrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -48,36 +49,31 @@ btSphereBoxCollisionAlgorithm::~btSphereBoxCollisionAlgorithm()
 
 
 
 
 
 
-void btSphereBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,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;
 
 
-	btCollisionObject* sphereObj = m_isSwapped? body1 : body0;
-	btCollisionObject* boxObj = m_isSwapped? body0 : body1;
+	const btCollisionObjectWrapper* sphereObjWrap = m_isSwapped? body1Wrap : body0Wrap;
+	const btCollisionObjectWrapper* boxObjWrap = m_isSwapped? body0Wrap : body1Wrap;
 
 
-
-	btSphereShape* sphere0 = (btSphereShape*)sphereObj->getCollisionShape();
+	btVector3 pOnBox;
 
 
 	btVector3 normalOnSurfaceB;
 	btVector3 normalOnSurfaceB;
-	btVector3 pOnBox,pOnSphere;
-	btVector3 sphereCenter = sphereObj->getWorldTransform().getOrigin();
+	btScalar penetrationDepth;
+	btVector3 sphereCenter = sphereObjWrap->getWorldTransform().getOrigin();
+	const btSphereShape* sphere0 = (const btSphereShape*)sphereObjWrap->getCollisionShape();
 	btScalar radius = sphere0->getRadius();
 	btScalar radius = sphere0->getRadius();
-	
-	btScalar dist = getSphereDistance(boxObj,pOnBox,pOnSphere,sphereCenter,radius);
+	btScalar maxContactDistance = m_manifoldPtr->getContactBreakingThreshold();
 
 
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
 
 
-	if (dist < SIMD_EPSILON)
+	if (getSphereDistance(boxObjWrap, pOnBox, normalOnSurfaceB, penetrationDepth, sphereCenter, radius, maxContactDistance))
 	{
 	{
-		btVector3 normalOnSurfaceB = (pOnBox- pOnSphere).normalize();
-
 		/// 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,pOnBox,dist);
-		
+		resultOut->addContactPoint(normalOnSurfaceB, pOnBox, penetrationDepth);
 	}
 	}
 
 
 	if (m_ownManifold)
 	if (m_ownManifold)
@@ -102,159 +98,117 @@ btScalar btSphereBoxCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject*
 }
 }
 
 
 
 
-btScalar btSphereBoxCollisionAlgorithm::getSphereDistance(btCollisionObject* boxObj, btVector3& pointOnBox, btVector3& v3PointOnSphere, const btVector3& sphereCenter, btScalar fRadius ) 
+bool btSphereBoxCollisionAlgorithm::getSphereDistance(const btCollisionObjectWrapper* boxObjWrap, btVector3& pointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& sphereCenter, btScalar fRadius, btScalar maxContactDistance ) 
 {
 {
-
-	btScalar margins;
-	btVector3 bounds[2];
-	btBoxShape* boxShape= (btBoxShape*)boxObj->getCollisionShape();
+	const btBoxShape* boxShape= (const btBoxShape*)boxObjWrap->getCollisionShape();
+	btVector3 const &boxHalfExtent = boxShape->getHalfExtentsWithoutMargin();
+	btScalar boxMargin = boxShape->getMargin();
+	penetrationDepth = 1.0f;
+
+	// convert the sphere position to the box's local space
+	btTransform const &m44T = boxObjWrap->getWorldTransform();
+	btVector3 sphereRelPos = m44T.invXform(sphereCenter);
+
+	// Determine the closest point to the sphere center in the box
+	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()) );
 	
 	
-	bounds[0] = -boxShape->getHalfExtentsWithoutMargin();
-	bounds[1] = boxShape->getHalfExtentsWithoutMargin();
-
-	margins = boxShape->getMargin();//also add sphereShape margin?
-
-	const btTransform&	m44T = boxObj->getWorldTransform();
-
-	btVector3	boundsVec[2];
-	btScalar	fPenetration;
-
-	boundsVec[0] = bounds[0];
-	boundsVec[1] = bounds[1];
-
-	btVector3	marginsVec( margins, margins, margins );
-
-	// add margins
-	bounds[0] += marginsVec;
-	bounds[1] -= marginsVec;
-
-	/////////////////////////////////////////////////
-
-	btVector3	tmp, prel, n[6], normal, v3P;
-	btScalar   fSep = btScalar(10000000.0), fSepThis;
+	btScalar intersectionDist = fRadius + boxMargin;
+	btScalar contactDist = intersectionDist + maxContactDistance;
+	normal = sphereRelPos - closestPoint;
 
 
-	n[0].setValue( btScalar(-1.0),  btScalar(0.0),  btScalar(0.0) );
-	n[1].setValue(  btScalar(0.0), btScalar(-1.0),  btScalar(0.0) );
-	n[2].setValue(  btScalar(0.0),  btScalar(0.0), btScalar(-1.0) );
-	n[3].setValue(  btScalar(1.0),  btScalar(0.0),  btScalar(0.0) );
-	n[4].setValue(  btScalar(0.0),  btScalar(1.0),  btScalar(0.0) );
-	n[5].setValue(  btScalar(0.0),  btScalar(0.0),  btScalar(1.0) );
-
-	// convert  point in local space
-	prel = m44T.invXform( sphereCenter);
-	
-	bool	bFound = false;
+	//if there is no penetration, we are done
+	btScalar dist2 = normal.length2();
+	if (dist2 > contactDist * contactDist)
+	{
+		return false;
+	}
 
 
-	v3P = prel;
+	btScalar distance;
 
 
-	for (int i=0;i<6;i++)
+	//special case if the sphere center is inside the box
+	if (dist2 <= SIMD_EPSILON)
 	{
 	{
-		int j = i<3? 0:1;
-		if ( (fSepThis = ((v3P-bounds[j]) .dot(n[i]))) > btScalar(0.0) )
-		{
-			v3P = v3P - n[i]*fSepThis;		
-			bFound = true;
-		}
+		distance = -getSpherePenetration(boxHalfExtent, sphereRelPos, closestPoint, normal);
 	}
 	}
-	
-	//
-
-	if ( bFound )
+	else //compute the penetration details
 	{
 	{
-		bounds[0] = boundsVec[0];
-		bounds[1] = boundsVec[1];
-
-		normal = (prel - v3P).normalize();
-		pointOnBox = v3P + normal*margins;
-		v3PointOnSphere = prel - normal*fRadius;
-
-		if ( ((v3PointOnSphere - pointOnBox) .dot (normal)) > btScalar(0.0) )
-		{
-			return btScalar(1.0);
-		}
-
-		// transform back in world space
-		tmp = m44T( pointOnBox);
-		pointOnBox    = tmp;
-		tmp  = m44T( v3PointOnSphere);		
-		v3PointOnSphere = tmp;
-		btScalar fSeps2 = (pointOnBox-v3PointOnSphere).length2();
-		
-		//if this fails, fallback into deeper penetration case, below
-		if (fSeps2 > SIMD_EPSILON)
-		{
-			fSep = - btSqrt(fSeps2);
-			normal = (pointOnBox-v3PointOnSphere);
-			normal *= btScalar(1.)/fSep;
-		}
-
-		return fSep;
+		distance = normal.length();
+		normal /= distance;
 	}
 	}
 
 
-	//////////////////////////////////////////////////
-	// Deep penetration case
-
-	fPenetration = getSpherePenetration( boxObj,pointOnBox, v3PointOnSphere, sphereCenter, fRadius,bounds[0],bounds[1] );
+	pointOnBox = closestPoint + normal * boxMargin;
+//	v3PointOnSphere = sphereRelPos - (normal * fRadius);	
+	penetrationDepth = distance - intersectionDist;
 
 
-	bounds[0] = boundsVec[0];
-	bounds[1] = boundsVec[1];
-
-	if ( fPenetration <= btScalar(0.0) )
-		return (fPenetration-margins);
-	else
-		return btScalar(1.0);
+	// transform back in world space
+	btVector3 tmp = m44T(pointOnBox);
+	pointOnBox = tmp;
+//	tmp = m44T(v3PointOnSphere);
+//	v3PointOnSphere = tmp;
+	tmp = m44T.getBasis() * normal;
+	normal = tmp;
+
+	return true;
 }
 }
 
 
-btScalar btSphereBoxCollisionAlgorithm::getSpherePenetration( btCollisionObject* boxObj,btVector3& pointOnBox, btVector3& v3PointOnSphere, const btVector3& sphereCenter, btScalar fRadius, const btVector3& aabbMin, const btVector3& aabbMax) 
+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
+	btScalar faceDist = boxHalfExtent.getX() - sphereRelPos.getX();
+	btScalar minDist = faceDist;
+	closestPoint.setX( boxHalfExtent.getX() );
+	normal.setValue(btScalar(1.0f),  btScalar(0.0f),  btScalar(0.0f));
+
+	faceDist = boxHalfExtent.getX() + sphereRelPos.getX();
+	if (faceDist < minDist)
+	{
+		minDist = faceDist;
+		closestPoint = sphereRelPos;
+		closestPoint.setX( -boxHalfExtent.getX() );
+		normal.setValue(btScalar(-1.0f),  btScalar(0.0f),  btScalar(0.0f));
+	}
 
 
-	btVector3 bounds[2];
-
-	bounds[0] = aabbMin;
-	bounds[1] = aabbMax;
-
-	btVector3	p0, tmp, prel, n[6], normal;
-	btScalar   fSep = btScalar(-10000000.0), fSepThis;
-
-	// set p0 and normal to a default value to shup up GCC
-	p0.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
-	normal.setValue(btScalar(0.), btScalar(0.), btScalar(0.));
-
-	n[0].setValue( btScalar(-1.0),  btScalar(0.0),  btScalar(0.0) );
-	n[1].setValue(  btScalar(0.0), btScalar(-1.0),  btScalar(0.0) );
-	n[2].setValue(  btScalar(0.0),  btScalar(0.0), btScalar(-1.0) );
-	n[3].setValue(  btScalar(1.0),  btScalar(0.0),  btScalar(0.0) );
-	n[4].setValue(  btScalar(0.0),  btScalar(1.0),  btScalar(0.0) );
-	n[5].setValue(  btScalar(0.0),  btScalar(0.0),  btScalar(1.0) );
-
-	const btTransform&	m44T = boxObj->getWorldTransform();
-
-	// convert  point in local space
-	prel = m44T.invXform( sphereCenter);
-
-	///////////
-
-	for (int i=0;i<6;i++)
+	faceDist = boxHalfExtent.getY() - sphereRelPos.getY();
+	if (faceDist < minDist)
 	{
 	{
-		int j = i<3 ? 0:1;
-		if ( (fSepThis = ((prel-bounds[j]) .dot( n[i]))-fRadius) > btScalar(0.0) )	return btScalar(1.0);
-		if ( fSepThis > fSep )
-		{
-			p0 = bounds[j];	normal = (btVector3&)n[i];
-			fSep = fSepThis;
-		}
+		minDist = faceDist;
+		closestPoint = sphereRelPos;
+		closestPoint.setY( boxHalfExtent.getY() );
+		normal.setValue(btScalar(0.0f),  btScalar(1.0f),  btScalar(0.0f));
 	}
 	}
 
 
-	pointOnBox = prel - normal*(normal.dot((prel-p0)));
-	v3PointOnSphere = pointOnBox + normal*fSep;
+	faceDist = boxHalfExtent.getY() + sphereRelPos.getY();
+	if (faceDist < minDist)
+	{
+		minDist = faceDist;
+		closestPoint = sphereRelPos;
+		closestPoint.setY( -boxHalfExtent.getY() );
+		normal.setValue(btScalar(0.0f),  btScalar(-1.0f),  btScalar(0.0f));
+	}
 
 
-	// transform back in world space
-	tmp  = m44T( pointOnBox);		
-	pointOnBox    = tmp;
-	tmp  = m44T( v3PointOnSphere);		v3PointOnSphere = tmp;
-	normal = (pointOnBox-v3PointOnSphere).normalize();
+	faceDist = boxHalfExtent.getZ() - sphereRelPos.getZ();
+	if (faceDist < minDist)
+	{
+		minDist = faceDist;
+		closestPoint = sphereRelPos;
+		closestPoint.setZ( boxHalfExtent.getZ() );
+		normal.setValue(btScalar(0.0f),  btScalar(0.0f),  btScalar(1.0f));
+	}
 
 
-	return fSep;
+	faceDist = boxHalfExtent.getZ() + sphereRelPos.getZ();
+	if (faceDist < minDist)
+	{
+		minDist = faceDist;
+		closestPoint = sphereRelPos;
+		closestPoint.setZ( -boxHalfExtent.getZ() );
+		normal.setValue(btScalar(0.0f),  btScalar(0.0f),  btScalar(-1.0f));
+	}
 
 
+	return minDist;
 }
 }
-

+ 10 - 10
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereBoxCollisionAlgorithm.h

@@ -13,8 +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 SPHERE_BOX_COLLISION_ALGORITHM_H
-#define SPHERE_BOX_COLLISION_ALGORITHM_H
+#ifndef BT_SPHERE_BOX_COLLISION_ALGORITHM_H
+#define BT_SPHERE_BOX_COLLISION_ALGORITHM_H
 
 
 #include "btActivatingCollisionAlgorithm.h"
 #include "btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -34,11 +34,11 @@ class btSphereBoxCollisionAlgorithm : public btActivatingCollisionAlgorithm
 	
 	
 public:
 public:
 
 
-	btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped);
+	btSphereBoxCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, bool isSwapped);
 
 
 	virtual ~btSphereBoxCollisionAlgorithm();
 	virtual ~btSphereBoxCollisionAlgorithm();
 
 
-	virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -50,26 +50,26 @@ public:
 		}
 		}
 	}
 	}
 
 
-	btScalar getSphereDistance( btCollisionObject* boxObj,btVector3& v3PointOnBox, btVector3& v3PointOnSphere, const btVector3& v3SphereCenter, btScalar fRadius );
+	bool getSphereDistance( const btCollisionObjectWrapper* boxObjWrap, btVector3& v3PointOnBox, btVector3& normal, btScalar& penetrationDepth, const btVector3& v3SphereCenter, btScalar fRadius, btScalar maxContactDistance );
 
 
-	btScalar getSpherePenetration( btCollisionObject* boxObj, btVector3& v3PointOnBox, btVector3& v3PointOnSphere, const btVector3& v3SphereCenter, btScalar fRadius, const btVector3& aabbMin, const btVector3& aabbMax);
+	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, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1,false);
+				return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,false);
 			} else
 			} else
 			{
 			{
-				return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0,body1,true);
+				return new(mem) btSphereBoxCollisionAlgorithm(0,ci,body0Wrap,body1Wrap,true);
 			}
 			}
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //SPHERE_BOX_COLLISION_ALGORITHM_H
+#endif //BT_SPHERE_BOX_COLLISION_ALGORITHM_H
 
 

+ 11 - 9
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp

@@ -12,20 +12,22 @@ subject to the following restrictions:
 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
 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.
 3. This notice may not be removed or altered from any source distribution.
 */
 */
+#define CLEAR_MANIFOLD 1
 
 
 #include "btSphereSphereCollisionAlgorithm.h"
 #include "btSphereSphereCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionShapes/btSphereShape.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
+#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
 
 
-btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1)
-: btActivatingCollisionAlgorithm(ci,col0,col1),
+btSphereSphereCollisionAlgorithm::btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap)
+: btActivatingCollisionAlgorithm(ci,col0Wrap,col1Wrap),
 m_ownManifold(false),
 m_ownManifold(false),
 m_manifoldPtr(mf)
 m_manifoldPtr(mf)
 {
 {
 	if (!m_manifoldPtr)
 	if (!m_manifoldPtr)
 	{
 	{
-		m_manifoldPtr = m_dispatcher->getNewManifold(col0,col1);
+		m_manifoldPtr = m_dispatcher->getNewManifold(col0Wrap->getCollisionObject(),col1Wrap->getCollisionObject());
 		m_ownManifold = true;
 		m_ownManifold = true;
 	}
 	}
 }
 }
@@ -39,7 +41,7 @@ btSphereSphereCollisionAlgorithm::~btSphereSphereCollisionAlgorithm()
 	}
 	}
 }
 }
 
 
-void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
+void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
 {
 	(void)dispatchInfo;
 	(void)dispatchInfo;
 
 
@@ -48,10 +50,10 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
 
 
 	resultOut->setPersistentManifold(m_manifoldPtr);
 	resultOut->setPersistentManifold(m_manifoldPtr);
 
 
-	btSphereShape* sphere0 = (btSphereShape*)col0->getCollisionShape();
-	btSphereShape* sphere1 = (btSphereShape*)col1->getCollisionShape();
+	btSphereShape* sphere0 = (btSphereShape*)col0Wrap->getCollisionShape();
+	btSphereShape* sphere1 = (btSphereShape*)col1Wrap->getCollisionShape();
 
 
-	btVector3 diff = col0->getWorldTransform().getOrigin()-  col1->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();
@@ -61,7 +63,7 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
 #endif
 #endif
 
 
 	///iff distance positive, don't generate a new contact
 	///iff distance positive, don't generate a new contact
-	if ( len > (radius0+radius1))
+	if ( len > (radius0+radius1+resultOut->m_closestPointDistanceThreshold))
 	{
 	{
 #ifndef CLEAR_MANIFOLD
 #ifndef CLEAR_MANIFOLD
 		resultOut->refreshContactPoints();
 		resultOut->refreshContactPoints();
@@ -80,7 +82,7 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
 	///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 = col1->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
 	
 	

+ 7 - 7
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h

@@ -13,8 +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 SPHERE_SPHERE_COLLISION_ALGORITHM_H
-#define SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#ifndef BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#define BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
 
 
 #include "btActivatingCollisionAlgorithm.h"
 #include "btActivatingCollisionAlgorithm.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -32,12 +32,12 @@ class btSphereSphereCollisionAlgorithm : public btActivatingCollisionAlgorithm
 	btPersistentManifold*	m_manifoldPtr;
 	btPersistentManifold*	m_manifoldPtr;
 	
 	
 public:
 public:
-	btSphereSphereCollisionAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1);
+	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 (btCollisionObject* body0,btCollisionObject* body1,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);
 
 
@@ -53,14 +53,14 @@ public:
 
 
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	struct CreateFunc :public 	btCollisionAlgorithmCreateFunc
 	{
 	{
-		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
+		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,body0,body1);
+			return new(mem) btSphereSphereCollisionAlgorithm(0,ci,col0Wrap,col1Wrap);
 		}
 		}
 	};
 	};
 
 
 };
 };
 
 
-#endif //SPHERE_SPHERE_COLLISION_ALGORITHM_H
+#endif //BT_SPHERE_SPHERE_COLLISION_ALGORITHM_H
 
 

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