Quellcode durchsuchen

Merge pull request #1889 from rextimmy/bullet_285

Bullet 2.85 update
Areloch vor 8 Jahren
Ursprung
Commit
8098f8f9ef
100 geänderte Dateien mit 5222 neuen und 6466 gelöschten Zeilen
  1. 27 0
      Engine/lib/bullet/.travis.yml
  2. 0 22
      Engine/lib/bullet/AUTHORS
  3. 40 0
      Engine/lib/bullet/AUTHORS.txt
  4. 25 0
      Engine/lib/bullet/BulletConfig.cmake.in
  5. 0 18
      Engine/lib/bullet/BulletLicense.txt
  6. 155 242
      Engine/lib/bullet/CMakeLists.txt
  7. 0 17
      Engine/lib/bullet/COPYING
  8. 0 795
      Engine/lib/bullet/ChangeLog
  9. 2 2
      Engine/lib/bullet/Doxyfile
  10. 0 111
      Engine/lib/bullet/INSTALL
  11. 6 10
      Engine/lib/bullet/LICENSE.txt
  12. 0 7
      Engine/lib/bullet/Makefile.am
  13. 0 5
      Engine/lib/bullet/NEWS
  14. 0 6
      Engine/lib/bullet/README
  15. 107 0
      Engine/lib/bullet/README.md
  16. 0 36
      Engine/lib/bullet/RELEASING.TXT
  17. 10 0
      Engine/lib/bullet/UseBullet.cmake
  18. 1 1
      Engine/lib/bullet/VERSION
  19. 0 3054
      Engine/lib/bullet/acinclude.m4
  20. 19 0
      Engine/lib/bullet/appveyor.yml
  21. 0 61
      Engine/lib/bullet/autogen.sh
  22. 6 0
      Engine/lib/bullet/bullet.pc.cmake
  23. 0 11
      Engine/lib/bullet/bullet.pc.in
  24. 0 113
      Engine/lib/bullet/config.h.in
  25. 0 172
      Engine/lib/bullet/configure.ac
  26. 0 322
      Engine/lib/bullet/install-sh
  27. 0 176
      Engine/lib/bullet/src/Bullet-C-Api.h
  28. 5 3
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.cpp
  29. 92 30
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.h
  30. 25 0
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
  31. 1 0
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
  32. 7 1
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.h
  33. 2 3
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
  34. 0 1
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
  35. 2 0
      Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
  36. 5 3
      Engine/lib/bullet/src/BulletCollision/CMakeLists.txt
  37. 1 1
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
  38. 3 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h
  39. 36 23
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
  40. 6 2
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
  41. 11 3
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.cpp
  42. 128 16
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.h
  43. 213 117
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
  44. 5 3
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.h
  45. 1147 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.cpp
  46. 190 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorldImporter.h
  47. 44 17
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
  48. 5 0
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.h
  49. 47 23
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp
  50. 3 4
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h
  51. 2 6
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp
  52. 0 3
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h
  53. 19 8
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
  54. 12 6
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
  55. 10 9
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
  56. 6 5
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
  57. 86 10
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
  58. 3 8
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
  59. 1 3
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.cpp
  60. 1 3
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btHashedSimplePairCache.h
  61. 1 5
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
  62. 40 3
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp
  63. 10 2
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.h
  64. 2 1
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp
  65. 1 1
      Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
  66. 5 4
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
  67. 4 0
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
  68. 10 0
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCapsuleShape.h
  69. 13 2
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCollisionShape.h
  70. 7 4
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCompoundShape.cpp
  71. 2 2
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCompoundShape.h
  72. 9 0
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConeShape.h
  73. 13 4
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp
  74. 2 3
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexHullShape.h
  75. 2 1
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp
  76. 6 2
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexShape.cpp
  77. 2 1
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexShape.h
  78. 12 13
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
  79. 2 2
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
  80. 0 1
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
  81. 1 1
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
  82. 7 0
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp
  83. 4 1
      Engine/lib/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.h
  84. 0 746
      Engine/lib/bullet/src/BulletCollision/Doxyfile
  85. 1 1
      Engine/lib/bullet/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h
  86. 53 0
      Engine/lib/bullet/src/BulletCollision/Gimpact/btGImpactShape.cpp
  87. 4 24
      Engine/lib/bullet/src/BulletCollision/Gimpact/btGImpactShape.h
  88. 7 7
      Engine/lib/bullet/src/BulletCollision/Gimpact/gim_basic_geometry_operations.h
  89. 369 0
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btComputeGjkEpaPenetration.h
  90. 25 21
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkCollisionDescription.h
  91. 28 11
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp
  92. 1035 0
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkEpa3.h
  93. 60 73
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
  94. 39 16
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
  95. 908 0
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btMprPenetration.h
  96. 1 6
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
  97. 7 7
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp
  98. 5 2
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h
  99. 4 2
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h
  100. 5 5
      Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp

+ 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 - 18
Engine/lib/bullet/BulletLicense.txt

@@ -1,18 +0,0 @@
-/*
-Copyright (c) 2003-2010 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, please report projects in the forum at http://www.bulletphysics.org
-
-In case you want to display a Bullet logo in your software: you can download the Bullet logo in various vector formats and high resolution at the download section in http://bullet.googlecode.com

+ 155 - 242
Engine/lib/bullet/CMakeLists.txt

@@ -5,178 +5,43 @@ set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
 SET(MSVC_INCREMENTAL_DEFAULT ON)
 
 PROJECT(BULLET_PHYSICS)
-SET(BULLET_VERSION 2.82)
+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)
 # SET(CMAKE_BUILD_TYPE "Debug")
  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_RUNTIME_LIBRARY_DLL "Use MSVC Runtime Library DLL (/MD or /MDd)" OFF)
 OPTION(USE_MSVC_INCREMENTAL_LINKING "Use MSVC Incremental Linking" OFF)
-
 OPTION(USE_CUSTOM_VECTOR_MATH "Use custom vectormath library" OFF)
 
-IF (USE_CUSTOM_VECTOR_MATH)
-	ADD_DEFINITIONS(-DUSE_SYSTEM_VECTORMATH)
-	IF(WIN32)
-	SET (VECTOR_MATH_INCLUDE ${BULLET_PHYSICS_SOURCE_DIR}/src/vectormath/sse CACHE PATH "Vector Math library include path.")
-	ELSE(WIN32)
-	SET (VECTOR_MATH_INCLUDE ${BULLET_PHYSICS_SOURCE_DIR}/src/vectormath/scalar CACHE PATH "Vector Math library include path.")
-	ENDIF(WIN32)
-ENDIF(USE_CUSTOM_VECTOR_MATH)
-
-
-IF (APPLE OR MSVC)
-	OPTION(BUILD_MULTITHREADING "Use BulletMultiThreading" ON)
-ELSE()
-	OPTION(BUILD_MULTITHREADING "Use BulletMultiThreading" OFF)
-ENDIF()
-
-IF (BUILD_MULTITHREADING)
-	OPTION(USE_MULTITHREADED_BENCHMARK "Use Multithreaded Benchmark" OFF)
-	IF (USE_MULTITHREADED_BENCHMARK)
-		ADD_DEFINITIONS(-DUSE_PARALLEL_SOLVER_BENCHMARK -DUSE_PARALLEL_DISPATCHER_BENCHMARK)
-	ENDIF(USE_MULTITHREADED_BENCHMARK)
-
-	IF (MSVC OR APPLE)
-		OPTION(BUILD_MINICL_OPENCL_DEMOS "Build OpenCL demos for MiniCL (Generic CPU)"  ON)
-	ELSE()
-		OPTION(BUILD_MINICL_OPENCL_DEMOS "Build OpenCL demos for MiniCL (Generic CPU)" OFF)
-	ENDIF(MSVC OR APPLE)
+#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)
 
-	IF(MSVC)
-		FIND_PATH(DIRECTX_SDK_BASE_DIR Include/D3D11.h PATH  $ENV{DXSDK_DIR} )
-		IF(DIRECTX_SDK_BASE_DIR)
-			OPTION(USE_DX11 "Use DirectX 11"	ON)
-		ELSE()
-			OPTION(USE_DX11 "Use DirectX 11"	OFF)
-		ENDIF()
-	
-		FIND_PATH(AMD_OPENCL_BASE_DIR include/CL/cl.h PATH  $ENV{ATISTREAMSDKROOT} $ENV{AMDAPPSDKROOT} )
-		IF(AMD_OPENCL_BASE_DIR)
-			#AMD adds an extras slash at the end of the ATISTREAMSDKROOT variable
-			SET(AMD_OPENCL_INCLUDES ${AMD_OPENCL_BASE_DIR}/include )
-			MESSAGE("AMD OPENCL SDK FOUND")
-			IF (CMAKE_CL_64)
-				SET(CMAKE_ATISTREAMSDK_LIBPATH 		${AMD_OPENCL_BASE_DIR}/lib/x86_64 )
-			ELSE(CMAKE_CL_64)
-				SET(CMAKE_ATISTREAMSDK_LIBPATH		${AMD_OPENCL_BASE_DIR}/lib/x86 )
-			ENDIF(CMAKE_CL_64)
-			SET(CMAKE_ATISTREAMSDK_LIBRARY		${CMAKE_ATISTREAMSDK_LIBPATH}/OpenCL.lib )
-			OPTION(BUILD_AMD_OPENCL_DEMOS "Build OpenCL demos for AMD (GPU or CPU)"	ON)
-			IF (CMAKE_CL_64)
-				SET(CMAK_GLEW_LIBRARY
-					${BULLET_PHYSICS_SOURCE_DIR}/Glut/glew64s.lib		)
-			ELSE(CMAKE_CL_64)
-				SET(CMAK_GLEW_LIBRARY		${BULLET_PHYSICS_SOURCE_DIR}/Glut/glew32s.lib		)
-			ENDIF(CMAKE_CL_64)
-		ELSE()
-			OPTION(BUILD_AMD_OPENCL_DEMOS "Build OpenCL demos for AMD (GPU or CPU)"	OFF)
-		ENDIF()
-		
-		FIND_PATH(INTEL_OPENCL_BASE_DIR include/CL/cl.h PATH  $ENV{INTELOCLSDKROOT} )
-		IF(INTEL_OPENCL_BASE_DIR)
-			SET(INTEL_OPENCL_INCLUDES ${INTEL_OPENCL_BASE_DIR}/include )
-			MESSAGE("INTEL OPENCL SDK FOUND")
-			MESSAGE(${INTEL_OPENCL_INCLUDES})
-			IF (CMAKE_CL_64)
-				SET(CMAKE_INTELOCLSDK_LIBPATH 		${INTEL_OPENCL_BASE_DIR}/lib/x64 )
-			ELSE(CMAKE_CL_64)
-				SET(CMAKE_INTELOCLSDK_LIBPATH		${INTEL_OPENCL_BASE_DIR}/lib/x86 )
-			ENDIF(CMAKE_CL_64)
-			SET(INTEL_OPENCL_LIBRARIES ${CMAKE_INTELOCLSDK_LIBPATH}/OpenCL.lib)
-			OPTION(BUILD_INTEL_OPENCL_DEMOS "Build OpenCL demos for Intel (CPU)"	ON)
-		ELSE()
-			OPTION(BUILD_INTEL_OPENCL_DEMOS "Build OpenCL demos for Intel (CPU)"	OFF)
-		ENDIF()
-		
-		FIND_PATH(NVIDIA_OPENCL_BASE_DIR include/CL/cl.h PATH  $ENV{CUDA_PATH} )
-		IF(NVIDIA_OPENCL_BASE_DIR)
-			SET(NVIDIA_OPENCL_INCLUDES ${NVIDIA_OPENCL_BASE_DIR}/include )
-			MESSAGE("NVIDIA OPENCL SDK FOUND")
-			MESSAGE(${NVIDIA_OPENCL_INCLUDES})
-			IF (CMAKE_CL_64)
-				SET(CMAKE_NVSDKCOMPUTE_LIBPATH		${NVIDIA_OPENCL_BASE_DIR}/lib/x64 )
-			ELSE(CMAKE_CL_64)
-				SET(CMAKE_NVSDKCOMPUTE_LIBPATH		${NVIDIA_OPENCL_BASE_DIR}/lib/Win32	)
-			ENDIF(CMAKE_CL_64)
-			SET(NVIDIA_OPENCL_LIBRARIES		${CMAKE_NVSDKCOMPUTE_LIBPATH}/OpenCL.lib)
-		
-			OPTION(BUILD_NVIDIA_OPENCL_DEMOS "Build OpenCL demos for NVidia (GPU)"	ON)
-		ELSE()
-			OPTION(BUILD_NVIDIA_OPENCL_DEMOS "Build OpenCL demos for NVidia (GPU)"	OFF)
-		ENDIF()
-	ELSE(MSVC)
-		FIND_PATH(AMD_OPENCL_BASE_DIR include/CL/cl.h PATH  $ENV{ATISTREAMSDKROOT} $ENV{AMDAPPSDKROOT} )
-		IF(AMD_OPENCL_BASE_DIR)
-			#AMD adds an extras slash at the end of the ATISTREAMSDKROOT variable
-			SET(AMD_OPENCL_INCLUDES ${AMD_OPENCL_BASE_DIR}/include )
-			MESSAGE("AMD OPENCL SDK FOUND")
-			MESSAGE(${AMD_OPENCL_INCLUDES})
-			IF (CMAKE_CL_64)
-				SET(CMAKE_ATISTREAMSDK_LIBPATH 		${AMD_OPENCL_BASE_DIR}/lib/x86_64 )
-			ELSE(CMAKE_CL_64)
-				SET(CMAKE_ATISTREAMSDK_LIBPATH		${AMD_OPENCL_BASE_DIR}/lib/x86 )
-			ENDIF(CMAKE_CL_64)
-			OPTION(BUILD_AMD_OPENCL_DEMOS "Build OpenCL demos for AMD (GPU or CPU)"	ON)
-			SET(CMAKE_ATISTREAMSDK_LIBRARY		OpenCL )
-		ELSE()
-			OPTION(BUILD_AMD_OPENCL_DEMOS "Build OpenCL demos for AMD (GPU or CPU)"	OFF)
-		ENDIF(AMD_OPENCL_BASE_DIR)
-		
-    FIND_PATH(INTEL_OPENCL_INCLUDES CL/cl.h)
-    FIND_PATH(INTEL_OPENCL_ICD_CFG intelocl64.icd /etc/OpenCL/vendors)
-    FIND_LIBRARY(INTEL_OPENCL_LIBRARIES OpenCL PATH /usr/lib64)
-    IF (INTEL_OPENCL_INCLUDES AND INTEL_OPENCL_LIBRARIES AND INTEL_OPENCL_ICD_CFG)
-            MESSAGE("INTEL OPENCL SDK FOUND")
-            MESSAGE(${INTEL_OPENCL_LIBRARIES})
-            OPTION(BUILD_INTEL_OPENCL_DEMOS "Build OpenCL demos for Intel (CPU)"        ON)
-    ELSE ()
-            MESSAGE("INTEL OPENCL NOT FOUND")
-            OPTION(BUILD_INTEL_OPENCL_DEMOS "Build OpenCL demos for Intel (CPU)"        OFF)
-    ENDIF ()
-
-
-		FIND_PATH(NVIDIA_OPENCL_INCLUDES CL/cl.h)
-    FIND_PATH(NVIDIA_OPENCL_ICD_CFG nvidia.icd /etc/OpenCL/vendors)
-    FIND_LIBRARY(NVIDIA_OPENCL_LIBRARIES OpenCL PATH /usr/lib64 /usr/local/lib)
-    IF (NVIDIA_OPENCL_INCLUDES AND NVIDIA_OPENCL_LIBRARIES AND NVIDIA_OPENCL_ICD_CFG)
-                MESSAGE("NVidia OPENCL FOUND")
-			MESSAGE(${NVIDIA_OPENCL_LIBRARIES})
-			OPTION(BUILD_NVIDIA_OPENCL_DEMOS "Build OpenCL demos for NVidia (GPU)"	ON)
-		ELSE ()
-	                MESSAGE("NVidia OPENCL NOT FOUND")
-			OPTION(BUILD_NVIDIA_OPENCL_DEMOS "Build OpenCL demos for NVidia (GPU)"	OFF)
-		ENDIF ()
-	ENDIF(MSVC)
-
-ELSE(BUILD_MULTITHREADING)
-# 	SET(BUILD_NVIDIA_OPENCL_DEMOS OFF CACHE BOOL "Build OpenCL demos for NVidia" FORCE)
-# 	SET(BUILD_AMD_OPENCL_DEMOS OFF CACHE BOOL "Build OpenCL demos for AMD" FORCE)
-# 	SET(BUILD_INTEL_OPENCL_DEMOS OFF CACHE BOOL "Build OpenCL demos for Intel (CPU)" FORCE)
-# 	SET(BUILD_MINICL_OPENCL_DEMOS  OFF CACHE BOOL "Build OpenCL demos for MiniCL (Generic CPU)" FORCE)
-# 	SET(USE_DX11  OFF CACHE BOOL "Use DirectX 11" FORCE)
-# 	SET(USE_MULTITHREADED_BENCHMARK  OFF CACHE BOOL "Use Multithreaded Benchmark" FORCE)
-ENDIF(BUILD_MULTITHREADING)
-
-
-
-
-#SET(CMAKE_EXE_LINKER_FLAGS_INIT    "/STACK:10000000 /INCREMENTAL:NO")	
-#SET(CMAKE_EXE_LINKER_FLAGS    "/STACK:10000000 /INCREMENTAL:NO")	
+#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})
 
@@ -185,26 +50,28 @@ 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}) 
+
+		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}) 
+
+		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)
+		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")
@@ -219,13 +86,15 @@ IF(MSVC)
 	ELSE()
 	  OPTION(USE_MSVC_SSE "Use MSVC /arch:sse option"	ON)
 	  IF (USE_MSVC_SSE)
-		ADD_DEFINITIONS(/arch: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)
-		ADD_DEFINITIONS(/fp:fast)
+		  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /fp:fast")
   ENDIF()
+
+	SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267")
 ENDIF(MSVC)
 
 
@@ -265,7 +134,7 @@ ENDIF(INTERNAL_CREATE_MSVC_RELATIVE_PATH_PROJECTFILES)
 ENDIF (WIN32)
 
 
-OPTION(BUILD_CPU_DEMOS "Build original Bullet CPU demos"        ON)
+OPTION(BUILD_CPU_DEMOS "Build original Bullet CPU examples" ON)
 
 
 
@@ -279,20 +148,30 @@ 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_IRR_STATIC_LIB_ )
 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 )
+	string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
+	remove_definitions(-D_WINDOWS )
 ENDIF()
 
 
@@ -301,11 +180,11 @@ ELSE(WIN32)
 OPTION(USE_GLUT "Use Glut"	ON)
 ENDIF(WIN32)
 
-   
+
 IF(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
 ENDIF(COMMAND cmake_policy)
-   
+
 
 # This is the shortcut to finding GLU, GLUT and OpenGL if they are properly installed on your system
 # This should be the case.
@@ -320,60 +199,89 @@ ELSE (OPENGL_FOUND)
 	SET(OPENGL_glu_LIBRARY glu32)
 ENDIF (OPENGL_FOUND)
 
-# ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
-
-FIND_PACKAGE(GLU)
-
-IF (USE_GLUT)
-	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)
-			#TODO add better GLUT detection for MinGW
-			SET(GLUT_FOUND TRUE)
-		ENDIF (MINGW)
-		IF (MSVC)
-			SET(GLUT_FOUND TRUE)
-			IF (CMAKE_CL_64)
-				message("Win64 using Glut/glut64.lib")
-				SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut64.lib)
-			ELSE(CMAKE_CL_64)
-				message("Win32 using Glut/glut32.lib")
-				SET(GLUT_glut_LIBRARY ${BULLET_PHYSICS_SOURCE_DIR}/Glut/glut32.lib)
-			ENDIF (CMAKE_CL_64)
-		 	INCLUDE_DIRECTORIES(${BULLET_PHYSICS_SOURCE_DIR}/Glut)
-		ELSE()
-			MESSAGE("GLUT NOT FOUND")	
-		ENDIF (MSVC)
-	ENDIF (GLUT_FOUND)
 
-	IF(NOT WIN32)	
-		# This is added for linux. This should always work if everything is installed and working fine.
-		INCLUDE_DIRECTORIES(/usr/include /usr/local/include) 
-	ENDIF()
-ENDIF(USE_GLUT)
+#FIND_PACKAGE(GLU)
+
+
+IF (APPLE)
+  FIND_LIBRARY(COCOA_LIBRARY Cocoa)
+ENDIF()
+
+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(BUILD_PYBULLET)
 
-OPTION(BUILD_DEMOS "Set when you want to build the demos" ON)
-IF(BUILD_DEMOS)
-	IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos)
-		SUBDIRS(Demos)
+	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()
-ENDIF(BUILD_DEMOS)
-
-#  "Demos_ps3")
-IF (MSVC)
-	IF (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
-		IF(EXISTS ${BULLET_PHYSICS_SOURCE_DIR}/Demos_ps3 AND IS_DIRECTORY ${BULLET_PHYSICS_SOURCE_DIR}/Demos_ps3)
-		MESSAGE("Demos_ps3 found")
-			SUBDIRS(Demos_ps3)
+	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()
-ENDIF(MSVC)
+
+        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_EXTRAS "Set when you want to build the extras" ON)
@@ -381,6 +289,7 @@ IF(BUILD_EXTRAS)
   SUBDIRS(Extras)
 ENDIF(BUILD_EXTRAS)
 
+
 #Maya Dynamica plugin is moved to http://dynamica.googlecode.com
 
 SUBDIRS(src)
@@ -398,18 +307,18 @@ ENDIF()
 
 IF(INSTALL_LIBS)
 	SET (LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
-	SET (LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE STRING "Library directory name")
+	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      "${CMAKE_INSTALL_PREFIX}/include/bullet/" CACHE PATH "The subdirectory to the header prefix")
-	SET(PKGCONFIG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/pkgconfig/" CACHE STRING "Base directory for pkgconfig files")
-	IF(NOT WIN32)
+	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 WIN32)
+		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
@@ -417,23 +326,27 @@ 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"	OFF)
+OPTION(BUILD_UNIT_TESTS "Build Unit Tests"	ON)
 
 IF (BUILD_UNIT_TESTS)
-	SUBDIRS(UnitTests)
+	ENABLE_TESTING()
+	SUBDIRS(test)
 ENDIF()
 
 set (BULLET_CONFIG_CMAKE_PATH lib${LIB_SUFFIX}/cmake/bullet )
 list (APPEND BULLET_LIBRARIES LinearMath)
-list (APPEND BULLET_LIBRARIES BulletCollisions)
+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 ${CMAKE_INSTALL_PREFIX}/${BULLET_CONFIG_CMAKE_PATH}/UseBullet.cmake)
-configure_file ( ${CMAKE_SOURCE_DIR}/BulletConfig.cmake.in
-                 ${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake
-                 @ONLY ESCAPE_QUOTES
-               )
-install ( FILES ${CMAKE_SOURCE_DIR}/UseBullet.cmake
-                ${CMAKE_CURRENT_BINARY_DIR}/BulletConfig.cmake
-          DESTINATION ${BULLET_CONFIG_CMAKE_PATH}
-        )
+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 - 17
Engine/lib/bullet/COPYING

@@ -1,17 +0,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2011 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.
-*/
-
-All files in the Bullet/src folder are under this Zlib license.
-Files in the Extras and Demos folder may have a different license, see the respective files.

+ 0 - 795
Engine/lib/bullet/ChangeLog

@@ -1,795 +0,0 @@
-Bullet Continuous Collision Detection and Physics Library
-Primary author and maintainer: Erwin Coumans
-
-This ChangeLog is incomplete, for an up-to-date list of all fixed issues see http://bullet.googlecode.com
-using http://tinyurl.com/yabmjjj
-
-2013 October 23
-	- Bullet 2.82 release
-	- See docs/BulletQuickstart.pdf or issue tracked for details.
-
-2012 September 10
-	- Bullet 2.81 release preparation
-	
-2011 September 15
-	- Bullet 2.79 release, revision 2433 (mainly a bugfix release)
-	- Revert a change in 2.78 related to speculative contacts (it has undesired side effects)
-	- Use HACD Hierachical Approximate Convex Decomposition (thanks to Khaled Mammou and Sujeon Kim)
-	- Add Intel cmake-build support for OpenCL accelerated cloth/particle
-	- add premake4 build system support to autogenerate visual studio project files that can be shipped (see msvc folder)
-	- preliminary build support for Google NativeClient, using premake4 (see msvc folder)
-			
-	
-2011 April 8
-	- Bullet 2.78 release 2383
-	- Added FractureDemo
-	- Added Separatinx Axis Test and Polyhedral Clipping support (See InternalEdgeDemo)
-	- Added speculative contacts as CCD response method (See CcdPhysicsDemo)
-	- OpenCL and DirectCompute cloth as basic support for capsule collision
-
-2010 September 7
-	- autotools now uses CamelCase naming for libraries just like cmake:
-	libbulletdynamics -> libBulletDynamics, libbulletmath -> libLinearMath
-
-2010 July 21
-	- Preparing for Bullet 2.77 release, around revision r2135
-	- Added an OpenCL particle demo, running on NVidia, AMD and MiniCL
-	Thanks to NVidia for the original particle demo from their OpenCL SDK
-	- Added GPU deformable object solvers for OpenCL and DirectCompute, and a DirectX 11 cloth demo
-	Thanks to AMD
-	- Create a separate library for MiniCL, 
-	MiniCL is a rudimentary OpenCL wrapper that allows to compile OpenCL kernels for multi-core CPU, using Win32 Threads or Posix
-	- Moved vectormath into Bullet/src, and added a SSE implementation
-	- Added a btParallelConstraintSolver, mainly for PlayStation 3 Cell SPUs (although it runs fine on CPU too)
-
-2010 March 6
-	- Dynamica Maya plugin (and COLLADA support) is moved to http://dynamica.googlecode.com
-
-2010 February
-	- Bullet 2.76 release, revision 2010
-	- support for the .bullet binary file format
-	- btInternalEdgeUtility to adjust unwanted collisions against internal triangle edges
-	- Improved Maya Dynamica plugin with better constraint authoring and .bullet file export
-
-
-2009 September 17
-	- Minor update to Bullet 2.75 release, revision 1776
-	- Support for btConvex2dShape, check out Bullet/Demos/Box2dDemo
-	- Fixes in build systems
-	- 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)

+ 2 - 2
Engine/lib/bullet/Doxyfile

@@ -270,7 +270,7 @@ WARN_LOGFILE           =
 # directories like "/usr/src/myproject". Separate the files or directories 
 # 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 
@@ -605,7 +605,7 @@ SEARCH_INCLUDES        = YES
 # contain include files that are not input files but should be processed by 
 # the preprocessor. 
 
-INCLUDE_PATH           = src
+INCLUDE_PATH           = 
 
 # 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 

+ 0 - 111
Engine/lib/bullet/INSTALL

@@ -1,111 +0,0 @@
-Bullet Collision Detection and Physics Library
-
-See also http://bulletphysics.org/mediawiki-1.5.8/index.php/Creating_a_project_from_scratch
-
-** Windows Compilation **
-
-	Open the Microsoft Visual Studio solution in msvc/20xx/BULLET_PHYSICS.sln
-
-Alternatively, use CMake to autogenerate a build system for Windows:
-	
-	- Download/install CMake from www.cmake.org or package manager
-	- Use cmake-gui or
-	- List available build systems by running 'cmake' in the Bullet root folder
-	- Use cmake-gui 
-	- 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
-
-	- List available build systems by running 'cmake' in the Bullet root folder
-	- Create a build system using the -G option for example:
-
-	cmake . -G "Unix Makefiles"
-
-  - 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.
-      CMAKE_BUILD_TYPE: default 'Release', can include debug symbols with
-        either 'Debug' or 'RelWithDebInfo'.
-    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 -DCMAKE_BUILD_TYPE=RelWithDebugInfo
-
-  - 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
-
-	- List available build systems by running 'cmake' in the Bullet root folder
-	- Create a build system using the -G option for example:
-
-  cmake . -G Xcode
-  cmake . -G "Unix Makefiles"
-
-  - 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. 
-      CMAKE_OSX_ARCHITECTURES: defaults to the native architecture, but can be
-        set to a semicolon separated list for fat binaries, e.g. ppc;i386;x86_64
-      CMAKE_BUILD_TYPE: default 'Release', can include debug symbols with
-        either 'Debug' or 'RelWithDebInfo'.
-
-    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 \
-              -DCMAKE_OSX_ARCHITECTURES='ppc;i386;x86_64' \
-              -DCMAKE_BUILD_TYPE=RelWithDebugInfo
-
-  - Assuming using the default Makefile output from cmake, run 'make' to build 
-    and then 'make install'.
-
-
-** Alternative Mac OS X and Linux via autoconf/make **
-  - at the command line:
-    ./autogen.sh
-    ./configure
-    make
-
-
-** For more help, visit http://www.bulletphysics.org **

+ 6 - 10
Engine/lib/bullet/src/BulletMultiThreaded/SpuNarrowPhaseCollisionTask/SpuLocalSupport.h → Engine/lib/bullet/LICENSE.txt

@@ -1,19 +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
-Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
+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, 
+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 
-endif
-pkgconfigdir = $(libdir)/pkgconfig
-pkgconfig_DATA = bullet.pc

+ 0 - 5
Engine/lib/bullet/NEWS

@@ -1,5 +0,0 @@
-
-For news, visit the Bullet Physics forums at
-http://www.bulletphysics.org and http://bullet.googlecode.com
-
-

+ 0 - 6
Engine/lib/bullet/README

@@ -1,6 +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.
-
-See the Bullet_User_Manual.pdf for more info and visit the Bullet Physics Forum at
-http://bulletphysics.org

+ 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 - 36
Engine/lib/bullet/RELEASING.TXT

@@ -1,36 +0,0 @@
-This document details the steps necessary to package a release of Bullet.
-
-1) Preparing for release:
-
-update VERSION in several places (/VERSION file, /CMakeLists.txt, /configure.ac, /src/LinearMath/btScalar.h, /src/LinearMath/btSerializer.h around line 441)
-re-generate serialization structures, if they changed (/src/LinearMath/btSerializer.cpp using makesdna)
-update ChangeLog with larger/important changes
-regenerate MSVC project files using build/vs_all.bat
-create a Subversion tag revision in bullet.googlecode.com/svn/tags/bullet-<VERSION>
-
-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.82
+2.85

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

@@ -1,3054 +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
-    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
-    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} -lBulletSoftBody -lBulletDynamics -lBulletCollision -lLinearMath
-Cflags: -I${includedir}/bullet

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

@@ -1,113 +0,0 @@
-/* config.h.in.  Generated from configure.ac by autoheader.  */
-
-/* Define if building universal (internal helper macro) */
-#undef AC_APPLE_UNIVERSAL_BUILD
-
-/* Architecture is PowerPC */
-#undef ARCH_PPC
-
-/* Architecture is x86 */
-#undef ARCH_X86
-
-/* Architecture is x86-64 */
-#undef ARCH_X86_64
-
-/* Use the Apple OpenGL framework. */
-#undef HAVE_APPLE_OPENGL_FRAMEWORK
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <GL/glext.h> header file. */
-#undef HAVE_GL_GLEXT_H
-
-/* Define to 1 if you have the <GL/glut.h> header file. */
-#undef HAVE_GL_GLUT_H
-
-/* Define to 1 if you have the <GL/glu.h> header file. */
-#undef HAVE_GL_GLU_H
-
-/* Define to 1 if you have the <GL/gl.h> header file. */
-#undef HAVE_GL_GL_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* 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
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Define to the sub-directory in which libtool stores uninstalled libraries.
-   */
-#undef LT_OBJDIR
-
-/* Define to 1 if your C compiler doesn't accept -c and -o together. */
-#undef NO_MINUS_C_MINUS_O
-
-/* 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 home page for this package. */
-#undef PACKAGE_URL
-
-/* 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 WORDS_BIGENDIAN to 1 if your processor stores words with the most
-   significant byte first (like Motorola and SPARC, unlike Intel). */
-#if defined AC_APPLE_UNIVERSAL_BUILD
-# if defined __BIG_ENDIAN__
-#  define WORDS_BIGENDIAN 1
-# endif
-#else
-# ifndef WORDS_BIGENDIAN
-#  undef WORDS_BIGENDIAN
-# endif
-#endif

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

@@ -1,172 +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.82],
-    [[email protected]])
-AC_CANONICAL_HOST
-AC_CONFIG_SRCDIR([configure.ac])
-AM_INIT_AUTOMAKE
-AM_PROG_CC_C_O
-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_MSG_WARN([Hello])
-                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_MSG_WARN([HI THERE!])
-                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])
-#----------------------------------------------------------------------------
-# 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])
-
-dnl Check for OpenGL and GLUT
-
-
-case "$host" in
-        *-*-darwin*)
-                  AC_DEFINE([HAVE_APPLE_OPENGL_FRAMEWORK], [1],
-                            [Use the Apple OpenGL framework.])
-                  GL_LIBS="-framework GLUT -framework OpenGL -framework Carbon -framework AGL"
-                  have_glut=yes
-                  have_glu=yes
-                  have_gl=yes
-                ;;
-        *)
-                     have_gl_headers=yes
-                      AC_CHECK_HEADERS(GL/gl.h GL/glu.h GL/glext.h GL/glut.h, ,
-                            [have_gl_headers=no],
-                           [[#ifdef WIN32
-                             #include <windows.h>
-                             #endif
-                             #if HAVE_GL_GL_H
-                             #include <GL/gl.h>
-                             #endif
-                                 #if HAVE_GL_GLU_H
-                             #include <GL/glu.h>
-                             #endif
-                           ]])
-                      have_gl=no
-                      have_glu=no
-                      have_glut=no
-                      TEMP_LDFLAGS="$LDFLAGS"
-                      AC_CHECK_LIB(GL, main, [GL_LIBS="-lGL"; have_gl=yes])
-                      AC_CHECK_LIB(GLU, main, [GL_LIBS="-lGLU $GL_LIBS"; have_glu=yes], , -lGL)
-                      AC_CHECK_LIB(GLUT, main, [GL_LIBS="-lGLUT -LGLU  $GL_LIBS"; have_glut=yes], ,-lGLUT)
-                      AC_CHECK_LIB(opengl32, main, [GL_LIBS="-lopengl32"; have_gl=yes])
-                      AC_CHECK_LIB(glu32, main, [GL_LIBS="-lglu32 $GL_LIBS"; have_glu=yes], , -lopengl32)
-                      LDFLAGS="$TEMP_LDFLAGS"
-                      if test $have_gl = no -o $have_glu = no -o $have_gl_headers = no; then
-                        if test x$enable_demos = xyes; then
-                          AC_MSG_WARN([Demos and Extras will not be built because OpenGL and GLUT doesn't seem to work. See `config.log' for details.])
-                        fi
-                        enable_demos=no
-                      else
-                      AC_MSG_NOTICE([Found OpenGL])
-                      fi
-                ;;
-esac
-
-
-
-AC_SUBST(GL_LIBS)
-
-
-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])
-
-
-
-CFLAGS="$ARCH_SPECIFIC_CFLAGS $CFLAGS"
-CXXFLAGS="$ARCH_SPECIFIC_CFLAGS $CXXFLAGS $CFLAGS"
-#----------------------------------------------------------------------------
-# Emit generated files.
-#----------------------------------------------------------------------------
-AC_CONFIG_FILES([bullet.pc Makefile Demos/Makefile Demos/SoftDemo/Makefile Demos/AllBulletDemos/Makefile Demos/MultiThreadedDemo/Makefile  Demos/OpenGL/Makefile  Demos/ForkLiftDemo/Makefile Demos/FeatherstoneMultiBodyDemo/Makefile Demos/BasicDemo/Makefile Demos/CcdPhysicsDemo/Makefile Demos/VehicleDemo/Makefile Demos/TerrainDemo/Makefile src/Makefile Extras/Makefile])
-AC_OUTPUT
-
-AC_MSG_NOTICE([
-
-Please type 'make' to build Bullet
-])

+ 0 - 322
Engine/lib/bullet/install-sh

@@ -1,322 +0,0 @@
-#!/bin/sh
-# install - install a program, script, or datafile
-
-scriptversion=2004-07-05.00
-
-# This originates from X11R5 (mit/util/scripts/install.sh), which was
-# later released in X11R6 (xc/config/util/install.sh) with the
-# following copyright and license.
-#
-# Copyright (C) 1994 X Consortium
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to
-# deal in the Software without restriction, including without limitation the
-# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-# sell copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
-# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
-# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
-# Except as contained in this notice, the name of the X Consortium shall not
-# be used in advertising or otherwise to promote the sale, use or other deal-
-# ings in this Software without prior written authorization from the X Consor-
-# tium.
-#
-#
-# FSF changes to this file are in the public domain.
-#
-# Calling this script install-sh is preferred over install.sh, to prevent
-# `make' implicit rules from creating a file called install from it
-# when there is no Makefile.
-#
-# This script is compatible with the BSD install script, but was written
-# from scratch.  It can only install one file at a time, a restriction
-# shared with many OS's install programs.
-
-# set DOITPROG to echo to test this script
-
-# Don't use :- since 4.3BSD and earlier shells don't like it.
-doit="${DOITPROG-}"
-
-# put in absolute paths if you don't have them in your path; or use env. vars.
-
-mvprog="${MVPROG-mv}"
-cpprog="${CPPROG-cp}"
-chmodprog="${CHMODPROG-chmod}"
-chownprog="${CHOWNPROG-chown}"
-chgrpprog="${CHGRPPROG-chgrp}"
-stripprog="${STRIPPROG-strip}"
-rmprog="${RMPROG-rm}"
-mkdirprog="${MKDIRPROG-mkdir}"
-
-chmodcmd="$chmodprog 0755"
-chowncmd=
-chgrpcmd=
-stripcmd=
-rmcmd="$rmprog -f"
-mvcmd="$mvprog"
-src=
-dst=
-dir_arg=
-dstarg=
-no_target_directory=
-
-usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
-   or: $0 [OPTION]... SRCFILES... DIRECTORY
-   or: $0 [OPTION]... -t DIRECTORY SRCFILES...
-   or: $0 [OPTION]... -d DIRECTORIES...
-
-In the 1st form, copy SRCFILE to DSTFILE.
-In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
-In the 4th, create DIRECTORIES.
-
-Options:
--c         (ignored)
--d         create directories instead of installing files.
--g GROUP   $chgrpprog installed files to GROUP.
--m MODE    $chmodprog installed files to MODE.
--o USER    $chownprog installed files to USER.
--s         $stripprog installed files.
--t DIRECTORY  install into DIRECTORY.
--T         report an error if DSTFILE is a directory.
---help     display this help and exit.
---version  display version info and exit.
-
-Environment variables override the default commands:
-  CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG
-"
-
-while test -n "$1"; do
-  case $1 in
-    -c) shift
-        continue;;
-
-    -d) dir_arg=true
-        shift
-        continue;;
-
-    -g) chgrpcmd="$chgrpprog $2"
-        shift
-        shift
-        continue;;
-
-    --help) echo "$usage"; exit 0;;
-
-    -m) chmodcmd="$chmodprog $2"
-        shift
-        shift
-        continue;;
-
-    -o) chowncmd="$chownprog $2"
-        shift
-        shift
-        continue;;
-
-    -s) stripcmd=$stripprog
-        shift
-        continue;;
-
-    -t) dstarg=$2
-	shift
-	shift
-	continue;;
-
-    -T) no_target_directory=true
-	shift
-	continue;;
-
-    --version) echo "$0 $scriptversion"; exit 0;;
-
-    *)  # When -d is used, all remaining arguments are directories to create.
-	# When -t is used, the destination is already specified.
-	test -n "$dir_arg$dstarg" && break
-        # Otherwise, the last argument is the destination.  Remove it from $@.
-	for arg
-	do
-          if test -n "$dstarg"; then
-	    # $@ is not empty: it contains at least $arg.
-	    set fnord "$@" "$dstarg"
-	    shift # fnord
-	  fi
-	  shift # arg
-	  dstarg=$arg
-	done
-	break;;
-  esac
-done
-
-if test -z "$1"; then
-  if test -z "$dir_arg"; then
-    echo "$0: no input file specified." >&2
-    exit 1
-  fi
-  # It's OK to call `install-sh -d' without argument.
-  # This can happen when creating conditional directories.
-  exit 0
-fi
-
-for src
-do
-  # Protect names starting with `-'.
-  case $src in
-    -*) src=./$src ;;
-  esac
-
-  if test -n "$dir_arg"; then
-    dst=$src
-    src=
-
-    if test -d "$dst"; then
-      mkdircmd=:
-      chmodcmd=
-    else
-      mkdircmd=$mkdirprog
-    fi
-  else
-    # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
-    # might cause directories to be created, which would be especially bad
-    # if $src (and thus $dsttmp) contains '*'.
-    if test ! -f "$src" && test ! -d "$src"; then
-      echo "$0: $src does not exist." >&2
-      exit 1
-    fi
-
-    if test -z "$dstarg"; then
-      echo "$0: no destination specified." >&2
-      exit 1
-    fi
-
-    dst=$dstarg
-    # Protect names starting with `-'.
-    case $dst in
-      -*) dst=./$dst ;;
-    esac
-
-    # If destination is a directory, append the input filename; won't work
-    # if double slashes aren't ignored.
-    if test -d "$dst"; then
-      if test -n "$no_target_directory"; then
-	echo "$0: $dstarg: Is a directory" >&2
-	exit 1
-      fi
-      dst=$dst/`basename "$src"`
-    fi
-  fi
-
-  # This sed command emulates the dirname command.
-  dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
-
-  # Make sure that the destination directory exists.
-
-  # Skip lots of stat calls in the usual case.
-  if test ! -d "$dstdir"; then
-    defaultIFS='
-	 '
-    IFS="${IFS-$defaultIFS}"
-
-    oIFS=$IFS
-    # Some sh's can't handle IFS=/ for some reason.
-    IFS='%'
-    set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'`
-    IFS=$oIFS
-
-    pathcomp=
-
-    while test $# -ne 0 ; do
-      pathcomp=$pathcomp$1
-      shift
-      if test ! -d "$pathcomp"; then
-        $mkdirprog "$pathcomp"
-	# mkdir can fail with a `File exist' error in case several
-	# install-sh are creating the directory concurrently.  This
-	# is OK.
-	test -d "$pathcomp" || exit
-      fi
-      pathcomp=$pathcomp/
-    done
-  fi
-
-  if test -n "$dir_arg"; then
-    $doit $mkdircmd "$dst" \
-      && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \
-      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \
-      && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \
-      && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; }
-
-  else
-    dstfile=`basename "$dst"`
-
-    # Make a couple of temp file names in the proper directory.
-    dsttmp=$dstdir/_inst.$$_
-    rmtmp=$dstdir/_rm.$$_
-
-    # Trap to clean up those temp files at exit.
-    trap 'status=$?; rm -f "$dsttmp" "$rmtmp" && exit $status' 0
-    trap '(exit $?); exit' 1 2 13 15
-
-    # Copy the file name to the temp name.
-    $doit $cpprog "$src" "$dsttmp" &&
-
-    # and set any options; do chmod last to preserve setuid bits.
-    #
-    # If any of these fail, we abort the whole thing.  If we want to
-    # ignore errors from any of these, just make sure not to ignore
-    # errors from the above "$doit $cpprog $src $dsttmp" command.
-    #
-    { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \
-      && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \
-      && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \
-      && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } &&
-
-    # Now rename the file to the real destination.
-    { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \
-      || {
-	   # The rename failed, perhaps because mv can't rename something else
-	   # to itself, or perhaps because mv is so ancient that it does not
-	   # support -f.
-
-	   # Now remove or move aside any old file at destination location.
-	   # We try this two ways since rm can't unlink itself on some
-	   # systems and the destination file might be busy for other
-	   # reasons.  In this case, the final cleanup might fail but the new
-	   # file should still install successfully.
-	   {
-	     if test -f "$dstdir/$dstfile"; then
-	       $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \
-	       || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \
-	       || {
-		 echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2
-		 (exit 1); exit
-	       }
-	     else
-	       :
-	     fi
-	   } &&
-
-	   # Now rename the file to the real destination.
-	   $doit $mvcmd "$dsttmp" "$dstdir/$dstfile"
-	 }
-    }
-  fi || { (exit 1); exit; }
-done
-
-# The final little trick to "correctly" pass the exit status to the exit trap.
-{
-  (exit 0); exit
-}
-
-# Local variables:
-# eval: (add-hook 'write-file-hooks 'time-stamp)
-# time-stamp-start: "scriptversion="
-# time-stamp-format: "%:y-%02m-%02d.%02H"
-# time-stamp-end: "$"
-# End:

+ 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(void); //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(void);
-	extern	void	plAddChildShape(plCollisionShapeHandle compoundShape,plCollisionShapeHandle childShape, plVector3 childPos,plQuaternion childOrn);
-
-	extern  void plDeleteShape(plCollisionShapeHandle shape);
-
-	/* Convex Meshes */
-	extern  plCollisionShapeHandle plNewConvexHullShape(void);
-	extern  void		plAddVertex(plCollisionShapeHandle convexHull, plReal x,plReal y,plReal z);
-/* Concave static triangle meshes */
-	extern  plMeshInterfaceHandle		   plNewMeshInterface(void);
-	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
-

+ 5 - 3
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.cpp

@@ -38,8 +38,9 @@ static DBVT_INLINE btDbvtVolume	merge(	const btDbvtVolume& a,
 									  const btDbvtVolume& b)
 {
 #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
 		btDbvtVolume	res;
 #endif
@@ -250,7 +251,8 @@ static btDbvtVolume				bounds(	const tNodeArray& leaves)
 {
 #if DBVT_MERGE_IMPL==DBVT_IMPL_SSE
 	ATTRIBUTE_ALIGNED16(char	locals[sizeof(btDbvtVolume)]);
-	btDbvtVolume&	volume=*(btDbvtVolume*)locals;
+	btDbvtVolume* ptr = (btDbvtVolume*) locals;
+	btDbvtVolume&	volume=*ptr;
 	volume=leaves[0]->volume;
 #else
 	btDbvtVolume volume=leaves[0]->volume;

+ 92 - 30
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDbvt.h

@@ -122,6 +122,7 @@ subject to the following restrictions:
 #error "DBVT_INT0_IMPL undefined"
 #endif
 
+
 //
 // Defaults volumes
 //
@@ -188,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).
 ///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.
@@ -263,7 +267,6 @@ struct	btDbvt
 
 	
 	btAlignedObjectArray<sStkNN>	m_stkStack;
-	mutable btAlignedObjectArray<const btDbvtNode*>	m_rayTestStack;
 
 
 	// Methods
@@ -325,6 +328,16 @@ struct	btDbvt
 		void		collideTV(	const btDbvtNode* root,
 		const btDbvtVolume& volume,
 		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 slower than rayTestInternal, because it builds a local stack, using memory allocations, and it recomputes signs/rayDirectionInverses each time
 	DBVT_PREFIX
@@ -343,6 +356,7 @@ struct	btDbvt
 								btScalar lambda_max,
 								const btVector3& aabbMin,
 								const btVector3& aabbMax,
+                                btAlignedObjectArray<const btDbvtNode*>& stack,
 								DBVT_IPOLICY) const;
 
 	DBVT_PREFIX
@@ -917,39 +931,72 @@ inline void		btDbvt::collideTT(	const btDbvtNode* root0,
 }
 #endif 
 
-//
 DBVT_PREFIX
 inline void		btDbvt::collideTV(	const btDbvtNode* root,
 								  const btDbvtVolume& vol,
 								  DBVT_IPOLICY) const
 {
 	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
 inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 								const btVector3& rayFrom,
@@ -959,7 +1006,8 @@ inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 								btScalar lambda_max,
 								const btVector3& aabbMin,
 								const btVector3& aabbMax,
-								DBVT_IPOLICY) const
+                                btAlignedObjectArray<const btDbvtNode*>& stack,
+                                DBVT_IPOLICY ) const
 {
         (void) rayTo;
 	DBVT_CHECKTYPE
@@ -969,7 +1017,6 @@ inline void		btDbvt::rayTestInternal(	const btDbvtNode* root,
 
 		int								depth=1;
 		int								treshold=DOUBLE_STACKSIZE-2;
-		btAlignedObjectArray<const btDbvtNode*>&	stack = m_rayTestStack;
 		stack.resize(DOUBLE_STACKSIZE);
 		stack[0]=root;
 		btVector3 bounds[2];
@@ -1193,19 +1240,34 @@ inline void		btDbvt::collideOCL(	const btDbvtNode* root,
 							/* Insert 0	*/ 
 							j=nearest(&stack[0],&stock[0],nes[q].value,0,stack.size());
 							stack.push_back(0);
+							
+							//void * memmove ( void * destination, const void * source, size_t num );
+							
 #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
-							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
 							stack[j]=allocate(ifree,stock,nes[q]);
 							/* Insert 1	*/ 
 							j=nearest(&stack[0],&stock[0],nes[1-q].value,j,stack.size());
 							stack.push_back(0);
 #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
-							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
 							stack[j]=allocate(ifree,stock,nes[1-q]);
 						}

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

@@ -16,6 +16,7 @@ subject to the following restrictions:
 ///btDbvtBroadphase implementation by Nathanael Presson
 
 #include "btDbvtBroadphase.h"
+#include "LinearMath/btThreads.h"
 
 //
 // Profiling
@@ -142,6 +143,11 @@ btDbvtBroadphase::btDbvtBroadphase(btOverlappingPairCache* paircache)
 	{
 		m_stageRoots[i]=0;
 	}
+#if BT_THREADSAFE
+    m_rayTestStacks.resize(BT_MAX_THREAD_COUNT);
+#else
+    m_rayTestStacks.resize(1);
+#endif
 #if DBVT_BP_PROFILE
 	clear(m_profiling);
 #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)
 {
 	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,
 		rayFrom,
@@ -236,6 +259,7 @@ void	btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
 		rayCallback.m_lambda_max,
 		aabbMin,
 		aabbMax,
+        *stack,
 		callback);
 
 	m_sets[1].rayTestInternal(	m_sets[1].m_root,
@@ -246,6 +270,7 @@ void	btDbvtBroadphase::rayTest(const btVector3& rayFrom,const btVector3& rayTo,
 		rayCallback.m_lambda_max,
 		aabbMin,
 		aabbMax,
+        *stack,
 		callback);
 
 }

+ 1 - 0
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_deferedcollide;			// Defere dynamic/static collision to collide call
 	bool					m_needcleanup;				// Need to run cleanup?
+    btAlignedObjectArray< btAlignedObjectArray<const btDbvtNode*> > m_rayTestStacks;
 #if DBVT_BP_PROFILE
 	btClock					m_clock;
 	struct	{

+ 7 - 1
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btDispatcher.h

@@ -64,6 +64,12 @@ struct btDispatcherInfo
 	btScalar	m_convexConservativeDistanceThreshold;
 };
 
+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.
 ///For example for pairwise collision detection, calculating contact points stored in btPersistentManifold or user callbacks (game logic).
 class btDispatcher
@@ -73,7 +79,7 @@ class btDispatcher
 public:
 	virtual ~btDispatcher() ;
 
-	virtual btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold=0) = 0;
+	virtual btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType) = 0;
 
 	virtual btPersistentManifold*	getNewManifold(const btCollisionObject* b0,const btCollisionObject* b1)=0;
 

+ 2 - 3
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp

@@ -34,7 +34,6 @@ int gFindPairs =0;
 
 btHashedOverlappingPairCache::btHashedOverlappingPairCache():
 	m_overlapFilterCallback(0),
-	m_blockedForChanges(false),
 	m_ghostPairCallback(0)
 {
 	int initialAllocatedSize= 2;
@@ -373,10 +372,10 @@ void* btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* pro
 	return userData;
 }
 //#include <stdio.h>
-
+#include "LinearMath/btQuickprof.h"
 void	btHashedOverlappingPairCache::processAllOverlappingPairs(btOverlapCallback* callback,btDispatcher* dispatcher)
 {
-
+	BT_PROFILE("btHashedOverlappingPairCache::processAllOverlappingPairs");
 	int i;
 
 //	printf("m_overlappingPairArray.size()=%d\n",m_overlappingPairArray.size());

+ 0 - 1
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h

@@ -94,7 +94,6 @@ class btHashedOverlappingPairCache : public btOverlappingPairCache
 {
 	btBroadphasePairArray	m_overlappingPairArray;
 	btOverlapFilterCallback* m_overlapFilterCallback;
-	bool		m_blockedForChanges;
 
 protected:
 	

+ 2 - 0
Engine/lib/bullet/src/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp

@@ -107,6 +107,8 @@ void	btQuantizedBvh::setQuantizationValues(const btVector3& bvhAabbMin,const btV
 			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);

+ 5 - 3
Engine/lib/bullet/src/BulletCollision/CMakeLists.txt

@@ -18,6 +18,7 @@ SET(BulletCollision_SRCS
 	CollisionDispatch/btCollisionDispatcher.cpp
 	CollisionDispatch/btCollisionObject.cpp
 	CollisionDispatch/btCollisionWorld.cpp
+	CollisionDispatch/btCollisionWorldImporter.cpp
 	CollisionDispatch/btCompoundCollisionAlgorithm.cpp
 	CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp
 	CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
@@ -126,6 +127,7 @@ SET(CollisionDispatch_HDRS
 	CollisionDispatch/btCollisionObject.h
 	CollisionDispatch/btCollisionObjectWrapper.h
 	CollisionDispatch/btCollisionWorld.h
+	CollisionDispatch/btCollisionWorldImporter.h
 	CollisionDispatch/btCompoundCollisionAlgorithm.h
 	CollisionDispatch/btCompoundCompoundCollisionAlgorithm.h
 	CollisionDispatch/btConvexConcaveCollisionAlgorithm.h
@@ -269,10 +271,10 @@ DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" E
 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)
-		
+
 			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)
@@ -280,7 +282,7 @@ DESTINATION ${INCLUDE_INSTALL_DIR}/BulletCollision)
 			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 (NOT INTERNAL_CREATE_DISTRIBUTABLE_MSVC_PROJECTFILES)
 ENDIF (INSTALL_LIBS)

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

@@ -100,7 +100,7 @@ bool SphereTriangleDetector::collide(const btVector3& sphereCenter,btVector3 &po
 	btScalar radiusWithThreshold = radius + contactBreakingThreshold;
 
 	btVector3 normal = (vertices[1]-vertices[0]).cross(vertices[2]-vertices[0]);
-	normal.normalize();
+	normal.safeNormalize();
 	btVector3 p1ToCentre = sphereCenter - vertices[0];
 	btScalar distanceFromPlane = p1ToCentre.dot(normal);
 

+ 3 - 0
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionConfiguration.h

@@ -40,6 +40,9 @@ public:
 
 	virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1) =0;
 
+	virtual btCollisionAlgorithmCreateFunc* getClosestPointsAlgorithmCreateFunc(int proxyType0, int proxyType1) = 0;
+
+
 };
 
 #endif //BT_COLLISION_CONFIGURATION

+ 36 - 23
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp

@@ -16,7 +16,7 @@ subject to the following restrictions:
 
 
 #include "btCollisionDispatcher.h"
-
+#include "LinearMath/btQuickprof.h"
 
 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h"
 
@@ -50,8 +50,10 @@ m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESH
 	{
 		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);
+
 		}
 	}
 	
@@ -61,7 +63,12 @@ m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESH
 
 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()
@@ -84,14 +91,10 @@ btPersistentManifold*	btCollisionDispatcher::getNewManifold(const btCollisionObj
 
 	btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold());
 		
- 	void* mem = 0;
-	
-	if (m_persistentManifoldPoolAllocator->getFreeCount())
-	{
-		mem = m_persistentManifoldPoolAllocator->allocate(sizeof(btPersistentManifold));
-	} else
+ 	void* mem = m_persistentManifoldPoolAllocator->allocate( sizeof( btPersistentManifold ) );
+    if (NULL == mem)
 	{
-		//we got a pool memory overflow, by default we fallback to dynamically allocate memory. If we require a contiguous contact pool then assert.
+        //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);
@@ -142,14 +145,23 @@ void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
 
 	
 
-btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold)
+
+btCollisionAlgorithm* btCollisionDispatcher::findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType algoType)
 {
 	
 	btCollisionAlgorithmConstructionInfo ci;
 
 	ci.m_dispatcher1 = this;
 	ci.m_manifold = sharedManifold;
-	btCollisionAlgorithm* algo = m_doubleDispatch[body0Wrap->getCollisionShape()->getShapeType()][body1Wrap->getCollisionShape()->getShapeType()]->CreateCollisionAlgorithm(ci,body0Wrap,body1Wrap);
+	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;
 }
@@ -189,7 +201,7 @@ bool	btCollisionDispatcher::needsCollision(const btCollisionObject* body0,const
 
 	if ((!body0->isActive()) && (!body1->isActive()))
 		needsCollision = false;
-	else if (!body0->checkCollideWith(body1))
+	else if ((!body0->checkCollideWith(body1)) || (!body1->checkCollideWith(body0)))
 		needsCollision = false;
 	
 	return needsCollision ;
@@ -227,6 +239,8 @@ public:
 
 	virtual bool	processOverlap(btBroadphasePair& pair)
 	{
+		BT_PROFILE("btCollisionDispatcher::processOverlap");
+
 		(*m_dispatcher->getNearCallback())(pair,*m_dispatcher,m_dispatchInfo);
 
 		return false;
@@ -249,7 +263,6 @@ void	btCollisionDispatcher::dispatchAllCollisionPairs(btOverlappingPairCache* pa
 
 
 
-
 //by default, Bullet will use this near callback
 void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
 {
@@ -265,7 +278,7 @@ void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair,
 			//dispatcher will keep algorithms persistent in the collision pair
 			if (!collisionPair.m_algorithm)
 			{
-				collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap);
+				collisionPair.m_algorithm = dispatcher.findAlgorithm(&obj0Wrap,&obj1Wrap,0, BT_CONTACT_POINT_ALGORITHMS);
 			}
 
 			if (collisionPair.m_algorithm)
@@ -293,13 +306,13 @@ void btCollisionDispatcher::defaultNearCallback(btBroadphasePair& collisionPair,
 
 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)

+ 6 - 2
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.h

@@ -57,7 +57,9 @@ protected:
 
 	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;
 
@@ -84,6 +86,8 @@ public:
 	///registerCollisionCreateFunc allows registration of custom/alternative collision create functions
 	void	registerCollisionCreateFunc(int proxyType0,int proxyType1, btCollisionAlgorithmCreateFunc* createFunc);
 
+	void	registerClosestPointsCreateFunc(int proxyType0, int proxyType1, btCollisionAlgorithmCreateFunc *createFunc);
+
 	int	getNumManifolds() const
 	{ 
 		return int( m_manifoldsPtr.size());
@@ -115,7 +119,7 @@ public:
 
 	virtual void clearManifold(btPersistentManifold* manifold);
 
-	btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold = 0);
+	btCollisionAlgorithm* findAlgorithm(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btPersistentManifold* sharedManifold, ebtDispatcherQueryType queryType);
 		
 	virtual bool	needsCollision(const btCollisionObject* body0,const btCollisionObject* body1);
 	

+ 11 - 3
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.
 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:
 
 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.
@@ -28,13 +28,19 @@ btCollisionObject::btCollisionObject()
 		m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT),
 		m_islandTag1(-1),
 		m_companionId(-1),
+        m_worldArrayIndex(-1),
 		m_activationState1(1),
 		m_deactivationTime(btScalar(0.)),
 		m_friction(btScalar(0.5)),
-		m_rollingFriction(0.0f),
 		m_restitution(btScalar(0.)),
+		m_rollingFriction(0.0f),
+        m_spinningFriction(0.f),
+		m_contactDamping(.1),
+		m_contactStiffness(1e4),
 		m_internalType(CO_COLLISION_OBJECT),
 		m_userObjectPointer(0),
+		m_userIndex2(-1),
+		m_userIndex(-1),
 		m_hitFraction(btScalar(1.)),
 		m_ccdSweptSphereRadius(btScalar(0.)),
 		m_ccdMotionThreshold(btScalar(0.)),
@@ -90,6 +96,8 @@ const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* seriali
 	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;
 	

+ 128 - 16
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionObject.h

@@ -79,24 +79,31 @@ protected:
 
 	int				m_islandTag1;
 	int				m_companionId;
+    int             m_worldArrayIndex;  // index of object in world's collisionObjects array
 
 	mutable int				m_activationState1;
 	mutable btScalar			m_deactivationTime;
 
 	btScalar		m_friction;
 	btScalar		m_restitution;
-	btScalar		m_rollingFriction;
+	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.
 	///do not assign your own m_internalType unless you write a new dynamics object class.
 	int				m_internalType;
 
 	///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer
-	union
-	{
-		void*			m_userObjectPointer;
-		int	m_userIndex;
-	};
+
+	void*			m_userObjectPointer;
+
+	int				m_userIndex2;
+	
+    int	m_userIndex;
 
 	///time of impact calculation
 	btScalar		m_hitFraction; 
@@ -110,13 +117,12 @@ protected:
 	/// If some object should have elaborate collision filtering by sub-classes
 	int			m_checkCollideWith;
 
+	btAlignedObjectArray<const btCollisionObject*> m_objectsWithoutCollisionCheck;
+
 	///internal update revision number. It will be increased when the object changes. This allows some subsystems to perform lazy evaluation.
 	int			m_updateRevision;
 
-	virtual bool	checkCollideWithOverride(const btCollisionObject* /* co */) const
-	{
-		return true;
-	}
+	btVector3	m_customDebugColorRGB;
 
 public:
 
@@ -130,7 +136,9 @@ public:
 		CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution)
 		CF_CHARACTER_OBJECT = 16,
 		CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
-		CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
+		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
@@ -225,7 +233,34 @@ public:
 		return m_collisionShape;
 	}
 
-	
+	void	setIgnoreCollisionCheck(const btCollisionObject* co, bool ignoreCollisionCheck)
+	{
+		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;
+	}
+
+	virtual bool	checkCollideWithOverride(const btCollisionObject*  co) const
+	{
+		int index = m_objectsWithoutCollisionCheck.findLinearSearch(co);
+		if (index < m_objectsWithoutCollisionCheck.size())
+		{
+			return false;
+		}
+		return true;
+	}
+
 
 	
 
@@ -292,8 +327,40 @@ public:
 	{
 		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
 	int	getInternalType() const
 	{
@@ -391,7 +458,18 @@ public:
 		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; 
 	}
@@ -452,6 +530,12 @@ public:
 	{
 		return m_userIndex;
 	}
+	
+	int	getUserIndex2() const
+	{
+		return m_userIndex2;
+	}
+	
 	///users can point to their objects, userPointer is not used by Bullet
 	void	setUserPointer(void* userPointer)
 	{
@@ -463,12 +547,37 @@ public:
 	{
 		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(const btCollisionObject* co) const
 	{
@@ -504,6 +613,8 @@ struct	btCollisionObjectDoubleData
 	double					m_deactivationTime;
 	double					m_friction;
 	double					m_rollingFriction;
+	double                  m_contactDamping;
+	double                  m_contactStiffness;
 	double					m_restitution;
 	double					m_hitFraction; 
 	double					m_ccdSweptSphereRadius;
@@ -537,7 +648,8 @@ struct	btCollisionObjectFloatData
 	float					m_deactivationTime;
 	float					m_friction;
 	float					m_rollingFriction;
-
+    float                   m_contactDamping;
+    float                   m_contactStiffness;
 	float					m_restitution;
 	float					m_hitFraction; 
 	float					m_ccdSweptSphereRadius;

+ 213 - 117
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp

@@ -34,7 +34,7 @@ subject to the following restrictions:
 #include "LinearMath/btSerializer.h"
 #include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
-#include "BulletCollision/Gimpact/btGImpactShape.h"
+
 //#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
 
 
@@ -115,7 +115,9 @@ void	btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,sho
 
 	//check that the object isn't already added
 	btAssert( m_collisionObjects.findLinearSearch(collisionObject)  == m_collisionObjects.size());
+    btAssert(collisionObject->getWorldArrayIndex() == -1);  // do not add the same object to more than one collision world
 
+    collisionObject->setWorldArrayIndex(m_collisionObjects.size());
 	m_collisionObjects.push_back(collisionObject);
 
 	//calculate new AABB
@@ -195,6 +197,7 @@ void	btCollisionWorld::updateAabbs()
 	for ( int i=0;i<m_collisionObjects.size();i++)
 	{
 		btCollisionObject* colObj = m_collisionObjects[i];
+        btAssert(colObj->getWorldArrayIndex() == i);
 
 		//only update aabb of active objects
 		if (m_forceUpdateAllAabbs || colObj->isActive())
@@ -253,9 +256,25 @@ 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);
 }
 
 
@@ -292,12 +311,13 @@ void	btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
 		btGjkConvexCast	gjkConvexCaster(castShape,convexShape,&simplexSolver);
 		
 		//btContinuousConvexCollision convexCaster(castShape,convexShape,&simplexSolver,0);
-		bool condition = true;
+
 		btConvexCast* convexCasterPtr = 0;
-		if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest)
-			convexCasterPtr = &subSimplexConvexCaster;
-		else
+		//use kF_UseSubSimplexConvexCastRaytest by default
+		if (resultCallback.m_flags & btTriangleRaycastCallback::kF_UseGjkConvexCastRaytest)
 			convexCasterPtr = &gjkConvexCaster;
+		else
+			convexCasterPtr = &subSimplexConvexCaster;
 		
 		btConvexCast& convexCaster = *convexCasterPtr;
 
@@ -308,6 +328,7 @@ void	btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
 			{
 				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
 					//rotate normal into worldspace
 					castResult.m_normal = rayFromTrans.getBasis() * castResult.m_normal;
@@ -387,14 +408,7 @@ void	btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
 				rcb.m_hitFraction = resultCallback.m_closestHitFraction;
 				triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
 			}
-			else if(collisionShape->getShapeType()==GIMPACT_SHAPE_PROXYTYPE)
-			{
-				btGImpactMeshShape* concaveShape = (btGImpactMeshShape*)collisionShape;
-
-				BridgeTriangleRaycastCallback	rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
-				rcb.m_hitFraction = resultCallback.m_closestHitFraction;
-				concaveShape->processAllTrianglesRay(&rcb,rayFromLocal,rayToLocal);
-			}else
+			else
 			{
 				//generic (slower) case
 				btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;
@@ -770,7 +784,7 @@ void	btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape,
 									hitPointLocal,
 									hitFraction);
 
-								bool	normalInWorldSpace = false;
+								bool	normalInWorldSpace = true;
 
 								return m_resultCallback->addSingleResult(convexResult,normalInWorldSpace);
 							}
@@ -795,23 +809,50 @@ void	btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape,
 				}
 			}
 		} else {
-			///@todo : use AABB tree or other BVH acceleration structure!
 			if (collisionShape->isCompound())
 			{
-				BT_PROFILE("convexSweepCompound");
-				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
-				int i=0;
-				for (i=0;i<compoundShape->getNumChildShapes();i++)
+				struct	btCompoundLeafCallback : btDbvt::ICollide
 				{
-					btTransform childTrans = compoundShape->getChildTransform(i);
-					const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i);
-					btTransform childWorldTrans = colObjWorldTransform * childTrans;
-					
-                    struct	LocalInfoAdder : public ConvexResultCallback {
-                            ConvexResultCallback* m_userCallback;
+					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) {
+					}
+
+				  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;
+
+				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)
+							LocalInfoAdder(int i, ConvexResultCallback *user)
 								: m_userCallback(user), m_i(i)
 							{
 								m_closestHitFraction = m_userCallback->m_closestHitFraction;
@@ -820,27 +861,66 @@ void	btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape,
 							{
 								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;
-                                    
-                            }
-                    };
+							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(i, &resultCallback);
-					
-					btCollisionObjectWrapper tmpObj(colObjWrap,childCollisionShape,colObjWrap->getCollisionObject(),childWorldTrans,-1,i);
+							}
+						};
 
-					objectQuerySingleInternal(castShape, convexFromTrans,convexToTrans,
-						&tmpObj,my_cb, allowedPenetration);
-					
+						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;
+
+						btTransform childTrans = m_compoundShape->getChildTransform(index);
+						const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index);
+
+						ProcessChild(index, childTrans, childCollisionShape);
+					}
+				};
+
+				BT_PROFILE("convexSweepCompound");
+				const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(collisionShape);
+
+				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);
+					}
 				}
 			}
 		}
@@ -1151,7 +1231,7 @@ struct btSingleContactCallback : public btBroadphaseAabbCallback
 			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);
+			btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(&ob0,&ob1,0, BT_CLOSEST_POINT_ALGORITHMS);
 			if (algorithm)
 			{
 				btBridgedManifoldResult contactPointResult(&ob0,&ob1, m_resultCallback);
@@ -1187,10 +1267,11 @@ void	btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionOb
 	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);
+	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);
 
@@ -1251,7 +1332,10 @@ public:
 void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)
 {
 	// Draw a small simplex at the center of the object
-	getDebugDrawer()->drawTransform(worldTransform,1);
+	if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawFrames)
+	{
+		getDebugDrawer()->drawTransform(worldTransform,1);
+	}
 
 	if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)
 	{
@@ -1429,81 +1513,93 @@ void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const
 
 void	btCollisionWorld::debugDrawWorld()
 {
-	if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
+	if (getDebugDrawer())
 	{
-		int numManifolds = getDispatcher()->getNumManifolds();
-		btVector3 color(1,1,0);
-		for (int i=0;i<numManifolds;i++)
+		btIDebugDraw::DefaultColors defaultColors = getDebugDrawer()->getDefaultColors();
+
+		if ( getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints)
 		{
-			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++)
+			if (getDispatcher())
 			{
-				btManifoldPoint& cp = contactManifold->getContactPoint(j);
-				getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color);
+				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() && (getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
-	{
-		int i;
 
-		for (  i=0;i<m_collisionObjects.size();i++)
+		if ((getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)))
 		{
-			btCollisionObject* colObj = m_collisionObjects[i];
-			if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
+			int i;
+
+			for (  i=0;i<m_collisionObjects.size();i++)
 			{
-				if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
+				btCollisionObject* colObj = m_collisionObjects[i];
+				if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0)
 				{
-					btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.));
-					switch(colObj->getActivationState())
+					if (getDebugDrawer() && (getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe))
 					{
-					case  ACTIVE_TAG:
-						color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break;
-					case ISLAND_SLEEPING:
-						color =  btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break;
-					case WANTS_DEACTIVATION:
-						color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break;
-					case DISABLE_DEACTIVATION:
-						color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break;
-					case DISABLE_SIMULATION:
-						color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break;
-					default:
-						{
-							color = btVector3(btScalar(1),btScalar(0.),btScalar(0.));
-						}
-					};
+						btVector3 color(btScalar(0.4),btScalar(0.4),btScalar(0.4));
 
-					debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);
-				}
-				if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))
-				{
-					btVector3 minAabb,maxAabb;
-					btVector3 colorvec(1,0,0);
-					colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);
-					btVector3 contactThreshold(gContactBreakingThreshold,gContactBreakingThreshold,gContactBreakingThreshold);
-					minAabb -= contactThreshold;
-					maxAabb += contactThreshold;
+						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));
+							}
+						};
 
-					btVector3 minAabb2,maxAabb2;
+						colObj->getCustomDebugColor(color);
 
-					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);
+						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);
+						m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);
+					}
 				}
 			}
-
 		}
 	}
 }
@@ -1512,15 +1608,6 @@ void	btCollisionWorld::debugDrawWorld()
 void	btCollisionWorld::serializeCollisionObjects(btSerializer* serializer)
 {
 	int i;
-	//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->serializeSingleObject(serializer);
-		}
-	}
 
 	///keep track of shapes already serialized
 	btHashMap<btHashPtr,btCollisionShape*>	serializedShapes;
@@ -1537,6 +1624,15 @@ void	btCollisionWorld::serializeCollisionObjects(btSerializer* 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);
+		}
+	}
 }
 
 

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

@@ -27,7 +27,7 @@ subject to the following restrictions:
  * @section install_sec Installation
  *
  * @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
  * Bullet has multiple build systems, including premake, cmake and autotools. Premake and cmake support all platforms.
@@ -412,10 +412,12 @@ public:
 	{
 		short int	m_collisionFilterGroup;
 		short int	m_collisionFilterMask;
-		
+		btScalar	m_closestDistanceThreshold;
+
 		ContactResultCallback()
 			:m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter),
-			m_collisionFilterMask(btBroadphaseProxy::AllFilter)
+			m_collisionFilterMask(btBroadphaseProxy::AllFilter),
+			m_closestDistanceThreshold(0)
 		{
 		}
 

+ 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

+ 44 - 17
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

@@ -65,7 +65,13 @@ void	btCompoundCollisionAlgorithm::preallocateChildAlgorithms(const btCollisionO
 			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);
+			m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(&childWrap,otherObjWrap,m_sharedManifold, BT_CONTACT_POINT_ALGORITHMS);
+
+
+			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsContact;
+			btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithmsClosestPoints;
+
+
 		}
 	}
 }
@@ -123,13 +129,19 @@ public:
 
 		//backup
 		btTransform	orgTrans = m_compoundColObjWrap->getWorldTransform();
-		btTransform	orgInterpolationTrans = m_compoundColObjWrap->getWorldTransform();
+		
 		const btTransform& childTrans = compoundShape->getChildTransform(index);
 		btTransform	newChildWorldTrans = orgTrans*childTrans ;
 
 		//perform an AABB check first
-		btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
+		btVector3 aabbMin0,aabbMax0;
 		childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
+
+		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)
@@ -142,12 +154,22 @@ public:
 		{
 
 			btCollisionObjectWrapper compoundWrap(this->m_compoundColObjWrap,childShape,m_compoundColObjWrap->getCollisionObject(),newChildWorldTrans,-1,index);
+			
+			btCollisionAlgorithm* algo = 0;
 
-
-			//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);
-
+			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;
 
@@ -164,8 +186,7 @@ public:
 				m_resultOut->setShapeIdentifiersB(-1,index);
 			}
 
-
-			m_childCollisionAlgorithms[index]->processCollision(&compoundWrap,m_otherObjWrap,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))
@@ -229,9 +250,12 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 		removeChildAlgorithms();
 		
 		preallocateChildAlgorithms(body0Wrap,body1Wrap);
+		m_compoundShapeRevision = compoundShape->getUpdateRevision();
 	}
 
-
+    if (m_childCollisionAlgorithms.size()==0)
+        return;
+    
 	const btDbvt* tree = compoundShape->getDynamicAabbTree();
 	//use a dynamic aabb tree to cull potential child-overlaps
 	btCompoundLeafCallback  callback(colObjWrap,otherObjWrap,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
@@ -241,7 +265,7 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 	///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
 	{
 		int i;
-		btManifoldArray manifoldArray;
+		manifoldArray.resize(0);
 		for (i=0;i<m_childCollisionAlgorithms.size();i++)
 		{
 			if (m_childCollisionAlgorithms[i])
@@ -268,10 +292,13 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 		btTransform otherInCompoundSpace;
 		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);
 		//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
 	{
@@ -288,10 +315,10 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 				//iterate over all children, perform an AABB check inside ProcessChildShape
 		int numChildren = m_childCollisionAlgorithms.size();
 		int i;
-		btManifoldArray	manifoldArray;
+		manifoldArray.resize(0);
         const btCollisionShape* childShape = 0;
         btTransform	orgTrans;
-        btTransform	orgInterpolationTrans;
+        
         btTransform	newChildWorldTrans;
         btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;        
         
@@ -301,8 +328,8 @@ void btCompoundCollisionAlgorithm::processCollision (const btCollisionObjectWrap
 			{
 				childShape = compoundShape->getChildShape(i);
 			//if not longer overlapping, remove the algorithm
-                orgTrans = colObjWrap->getWorldTransform();
-                orgInterpolationTrans = colObjWrap->getWorldTransform();
+				orgTrans = colObjWrap->getWorldTransform();
+                
 				const btTransform& childTrans = compoundShape->getChildTransform(i);
                 newChildWorldTrans = orgTrans*childTrans ;
 

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

@@ -26,6 +26,7 @@ class btDispatcher;
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
 #include "btCollisionCreateFunc.h"
 #include "LinearMath/btAlignedObjectArray.h"
+#include "BulletCollision/BroadphaseCollision/btDbvt.h"
 class btDispatcher;
 class btCollisionObject;
 
@@ -36,6 +37,10 @@ extern btShapePairCallback gCompoundChildShapePairCallback;
 /// btCompoundCollisionAlgorithm  supports collision between CompoundCollisionShapes and other collision shapes
 class btCompoundCollisionAlgorithm  : public btActivatingCollisionAlgorithm
 {
+	btNodeStack stack2;
+	btManifoldArray manifoldArray;
+
+protected:
 	btAlignedObjectArray<btCollisionAlgorithm*> m_childCollisionAlgorithms;
 	bool m_isSwapped;
 

+ 47 - 23
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btCompoundCompoundCollisionAlgorithm.cpp

@@ -15,6 +15,7 @@ subject to the following restrictions:
 */
 
 #include "btCompoundCompoundCollisionAlgorithm.h"
+#include "LinearMath/btQuickprof.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionShapes/btCompoundShape.h"
 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
@@ -27,10 +28,8 @@ subject to the following restrictions:
 btShapePairCallback gCompoundCompoundChildShapePairCallback = 0;
 
 btCompoundCompoundCollisionAlgorithm::btCompoundCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped)
-:btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_sharedManifold(ci.m_manifold)
+:btCompoundCollisionAlgorithm(ci,body0Wrap,body1Wrap,isSwapped)
 {
-	m_ownsManifold = false;
 
 	void* ptr = btAlignedAlloc(sizeof(btHashedSimplePairCache),16);
 	m_childCollisionAlgorithmCache= new(ptr) btHashedSimplePairCache();
@@ -114,10 +113,9 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 									btManifoldResult*	resultOut,
 									btHashedSimplePairCache* childAlgorithmsCache,
 									btPersistentManifold*	sharedManifold)
-		:m_compound0ColObjWrap(compound1ObjWrap),m_compound1ColObjWrap(compound0ObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
+		:m_numOverlapPairs(0),m_compound0ColObjWrap(compound1ObjWrap),m_compound1ColObjWrap(compound0ObjWrap),m_dispatcher(dispatcher),m_dispatchInfo(dispatchInfo),m_resultOut(resultOut),
 		m_childCollisionAlgorithmCache(childAlgorithmsCache),
-		m_sharedManifold(sharedManifold),
-		m_numOverlapPairs(0)
+		m_sharedManifold(sharedManifold)
 	{
 
 	}
@@ -127,6 +125,7 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 	
 	void		Process(const btDbvtNode* leaf0,const btDbvtNode* leaf1)
 	{
+		BT_PROFILE("btCompoundCompoundLeafCallback::Process");
 		m_numOverlapPairs++;
 
 
@@ -162,6 +161,11 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 		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))
@@ -177,17 +181,24 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 			btSimplePair* pair = m_childCollisionAlgorithmCache->findPair(childIndex0,childIndex1);
 
 			btCollisionAlgorithm* colAlgo = 0;
-
-			if (pair)
+			if (m_resultOut->m_closestPointDistanceThreshold > 0)
 			{
-				colAlgo = (btCollisionAlgorithm*)pair->m_userPointer;
-				
-			} else
+				colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0, &compoundWrap1, 0, BT_CLOSEST_POINT_ALGORITHMS);
+			}
+			else
 			{
-				colAlgo = m_dispatcher->findAlgorithm(&compoundWrap0,&compoundWrap1,m_sharedManifold);
-				pair = m_childCollisionAlgorithmCache->addOverlappingPair(childIndex0,childIndex1);
-				btAssert(pair);
-				pair->m_userPointer = colAlgo;
+				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);
@@ -218,10 +229,12 @@ struct	btCompoundCompoundLeafCallback : btDbvt::ICollide
 
 
 static DBVT_INLINE bool		MyIntersect(	const btDbvtAabbMm& a,
-								  const btDbvtAabbMm& b, const btTransform& xform)
+								  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);
 }
@@ -230,7 +243,7 @@ static DBVT_INLINE bool		MyIntersect(	const btDbvtAabbMm& a,
 static inline void		MycollideTT(	const btDbvtNode* root0,
 								  const btDbvtNode* root1,
 								  const btTransform& xform,
-								  btCompoundCompoundLeafCallback* callback)
+								  btCompoundCompoundLeafCallback* callback, btScalar distanceThreshold)
 {
 
 		if(root0&&root1)
@@ -242,7 +255,7 @@ static inline void		MycollideTT(	const btDbvtNode* root0,
 			stkStack[0]=btDbvt::sStkNN(root0,root1);
 			do	{
 				btDbvt::sStkNN	p=stkStack[--depth];
-				if(MyIntersect(p.a->volume,p.b->volume,xform))
+				if(MyIntersect(p.a->volume,p.b->volume,xform, distanceThreshold))
 				{
 					if(depth>treshold)
 					{
@@ -292,12 +305,21 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 	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();
+
 	}
 
 
@@ -329,14 +351,13 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 	}
 
 
-	const btDbvt* tree0 = compoundShape0->getDynamicAabbTree();
-	const btDbvt* tree1 = compoundShape1->getDynamicAabbTree();
+	
 
 	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);
+	MycollideTT(tree0->m_root,tree1->m_root,xform,&callback, resultOut->m_closestPointDistanceThreshold);
 
 	//printf("#compound-compound child/leaf overlap =%d                      \r",callback.m_numOverlapPairs);
 
@@ -376,7 +397,9 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 					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;
@@ -391,7 +414,8 @@ void btCompoundCompoundCollisionAlgorithm::processCollision (const btCollisionOb
 					childShape1->getAabb(newChildWorldTrans1,aabbMin1,aabbMax1);
 				}
 				
-				
+				aabbMin1 -= thresholdVec;
+				aabbMax1 += thresholdVec;
 
 				if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
 				{

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

@@ -17,6 +17,8 @@ subject to the following restrictions:
 #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"
@@ -35,15 +37,12 @@ typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCol
 extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
 
 /// btCompoundCompoundCollisionAlgorithm  supports collision between two btCompoundCollisionShape shapes
-class btCompoundCompoundCollisionAlgorithm  : public btActivatingCollisionAlgorithm
+class btCompoundCompoundCollisionAlgorithm  : public btCompoundCollisionAlgorithm
 {
 
 	class btHashedSimplePairCache*	m_childCollisionAlgorithmCache;
 	btSimplePairArray m_removePairs;
 
-	class btPersistentManifold*	m_sharedManifold;
-	bool					m_ownsManifold;
-
 
 	int	m_compoundShapeRevision0;//to keep track of changes, so that childAlgorithm array can be updated
 	int	m_compoundShapeRevision1;

+ 2 - 6
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp

@@ -47,8 +47,6 @@ subject to the following restrictions:
 
 btConvex2dConvex2dAlgorithm::CreateFunc::CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
 {
-	m_numPerturbationIterations = 0;
-	m_minimumPointsPerturbationThreshold = 3;
 	m_simplexSolver = simplexSolver;
 	m_pdSolver = pdSolver;
 }
@@ -57,15 +55,13 @@ btConvex2dConvex2dAlgorithm::CreateFunc::~CreateFunc()
 { 
 }
 
-btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+btConvex2dConvex2dAlgorithm::btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int /* numPerturbationIterations */, int /* minimumPointsPerturbationThreshold */)
 : btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
 m_simplexSolver(simplexSolver),
 m_pdSolver(pdSolver),
 m_ownManifold (false),
 m_manifoldPtr(mf),
-m_lowLevelOfDetail(false),
- m_numPerturbationIterations(numPerturbationIterations),
-m_minimumPointsPerturbationThreshold(minimumPointsPerturbationThreshold)
+m_lowLevelOfDetail(false)
 {
 	(void)body0Wrap;
 	(void)body1Wrap;

+ 0 - 3
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvex2dConvex2dAlgorithm.h

@@ -40,9 +40,6 @@ class btConvex2dConvex2dAlgorithm : public btActivatingCollisionAlgorithm
 	btPersistentManifold*	m_manifoldPtr;
 	bool			m_lowLevelOfDetail;
 	
-	int m_numPerturbationIterations;
-	int m_minimumPointsPerturbationThreshold;
-
 public:
 
 	btConvex2dConvex2dAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver, int numPerturbationIterations, int minimumPointsPerturbationThreshold);

+ 19 - 8
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp

@@ -15,6 +15,7 @@ subject to the following restrictions:
 
 
 #include "btConvexConcaveCollisionAlgorithm.h"
+#include "LinearMath/btQuickprof.h"
 #include "BulletCollision/CollisionDispatch/btCollisionObject.h"
 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
@@ -79,6 +80,7 @@ void	btConvexTriangleCallback::clearCache()
 void btConvexTriangleCallback::processTriangle(btVector3* triangle,int
 partId, int triangleIndex)
 {
+	BT_PROFILE("btConvexTriangleCallback::processTriangle");
 
 	if (!TestTriangleAgainstAabb2(triangle, m_aabbMin, m_aabbMax))
 	{
@@ -88,20 +90,19 @@ partId, int triangleIndex)
         //just for debugging purposes
         //printf("triangle %d",m_triangleCount++);
 
-        const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
+
 
 	btCollisionAlgorithmConstructionInfo ci;
 	ci.m_dispatcher1 = m_dispatcher;
 
-	//const btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
-
-	
 
 
 #if 0	
+	
 	///debug drawing of the overlapping triangles
 	if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
 	{
+		const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
 		btVector3 color(1,1,0);
 		btTransform& tr = ob->getWorldTransform();
 		m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color);
@@ -117,8 +118,16 @@ partId, int triangleIndex)
 		
 		
 		btCollisionObjectWrapper triObWrap(m_triBodyWrap,&tm,m_triBodyWrap->getCollisionObject(),m_triBodyWrap->getWorldTransform(),partId,triangleIndex);//correct transform?
-		btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBodyWrap,&triObWrap,m_manifoldPtr);
-
+		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;
 
 		if (m_resultOut->getBody0Internal() == m_triBodyWrap->getCollisionObject())
@@ -169,7 +178,8 @@ void	btConvexTriangleCallback::setTimeStepAndCounters(btScalar collisionMarginTr
 	const btCollisionShape* convexShape = static_cast<const btCollisionShape*>(m_convexBodyWrap->getCollisionShape());
 	//CollisionShape* triangleShape = static_cast<btCollisionShape*>(triBody->m_collisionShape);
 	convexShape->getAabb(convexInTriangleSpace,m_aabbMin,m_aabbMax);
-	btScalar extraMargin = collisionMarginTriangle;
+	btScalar extraMargin = collisionMarginTriangle+ resultOut->m_closestPointDistanceThreshold;
+	
 	btVector3 extra(extraMargin,extraMargin,extraMargin);
 
 	m_aabbMax += extra;
@@ -185,7 +195,7 @@ void btConvexConcaveCollisionAlgorithm::clearCache()
 
 void btConvexConcaveCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
 {
-	
+	BT_PROFILE("btConvexConcaveCollisionAlgorithm::processCollision");
 	
 	const btCollisionObjectWrapper* convexBodyWrap = m_isSwapped ? body1Wrap : body0Wrap;
 	const btCollisionObjectWrapper* triBodyWrap = m_isSwapped ? body0Wrap : body1Wrap;
@@ -266,6 +276,7 @@ btScalar btConvexConcaveCollisionAlgorithm::calculateTimeOfImpact(btCollisionObj
 		
 		virtual void processTriangle(btVector3* triangle, int partId, int triangleIndex)
 		{
+			BT_PROFILE("processTriangle");
 			(void)partId;
 			(void)triangleIndex;
 			//do a swept sphere for now

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

@@ -26,14 +26,16 @@ class btDispatcher;
 #include "btCollisionCreateFunc.h"
 
 ///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
 {
-	const btCollisionObjectWrapper* m_convexBodyWrap;
-	const btCollisionObjectWrapper* m_triBodyWrap;
 
 	btVector3	m_aabbMin;
 	btVector3	m_aabbMax ;
 
+	const btCollisionObjectWrapper* m_convexBodyWrap;
+	const btCollisionObjectWrapper* m_triBodyWrap;
+
+
 
 	btManifoldResult* m_resultOut;
 	btDispatcher*	m_dispatcher;
@@ -41,6 +43,8 @@ class btConvexTriangleCallback : public btTriangleCallback
 	btScalar m_collisionMarginTriangle;
 	
 public:
+	BT_DECLARE_ALIGNED_ALLOCATOR();
+	
 int	m_triangleCount;
 	
 	btPersistentManifold*	m_manifoldPtr;
@@ -75,17 +79,19 @@ int	m_triangleCount;
 
 
 /// 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;
 
+	bool	m_isSwapped;
+
 
 
 public:
 
+	BT_DECLARE_ALIGNED_ALLOCATOR();
+	
 	btConvexConcaveCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,bool isSwapped);
 
 	virtual ~btConvexConcaveCollisionAlgorithm();

+ 10 - 9
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp

@@ -179,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_minimumPointsPerturbationThreshold = 3;
-	m_simplexSolver = simplexSolver;
 	m_pdSolver = pdSolver;
 }
 
@@ -191,9 +190,8 @@ btConvexConvexAlgorithm::CreateFunc::~CreateFunc()
 { 
 }
 
-btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
+btConvexConvexAlgorithm::btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,btConvexPenetrationDepthSolver* pdSolver,int numPerturbationIterations, int minimumPointsPerturbationThreshold)
 : btActivatingCollisionAlgorithm(ci,body0Wrap,body1Wrap),
-m_simplexSolver(simplexSolver),
 m_pdSolver(pdSolver),
 m_ownManifold (false),
 m_manifoldPtr(mf),
@@ -349,8 +347,8 @@ void btConvexConvexAlgorithm ::processCollision (const btCollisionObjectWrapper*
 
 	
 	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)
 	gjkPairDetector.setMinkowskiA(min0);
 	gjkPairDetector.setMinkowskiB(min1);
@@ -367,7 +365,7 @@ void btConvexConvexAlgorithm ::processCollision (const btCollisionObjectWrapper*
 		//	input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold();
 		//} else
 		//{
-		input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold();
+		input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold()+resultOut->m_closestPointDistanceThreshold;
 //		}
 
 		input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared;
@@ -503,9 +501,11 @@ void btConvexConvexAlgorithm ::processCollision (const btCollisionObjectWrapper*
 				
 //				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, *resultOut);
+																 body1Wrap->getWorldTransform(), minDist-threshold, threshold, worldVertsB1,worldVertsB2,
+																 *resultOut);
  				
 			}
 			if (m_ownManifold)
@@ -568,8 +568,9 @@ void btConvexConvexAlgorithm ::processCollision (const btCollisionObjectWrapper*
 				
 			if (foundSepAxis)
 			{
+				worldVertsB2.resize(0);
 				btPolyhedralContactClipping::clipFaceAgainstHull(sepNormalWorldSpace, *polyhedronA->getConvexPolyhedron(), 
-					body0Wrap->getWorldTransform(), vertices, minDist-threshold, maxDist, *resultOut);
+					body0Wrap->getWorldTransform(), vertices, worldVertsB2,minDist-threshold, maxDist, *resultOut);
 			}
 				
 				

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

@@ -24,6 +24,7 @@ subject to the following restrictions:
 #include "btCollisionCreateFunc.h"
 #include "btCollisionDispatcher.h"
 #include "LinearMath/btTransformUtil.h" //for btConvexSeparatingDistanceUtil
+#include "BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h"
 
 class btConvexPenetrationDepthSolver;
 
@@ -42,9 +43,10 @@ class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 #ifdef USE_SEPDISTANCE_UTIL2
 	btConvexSeparatingDistanceUtil	m_sepDistance;
 #endif
-	btSimplexSolverInterface*		m_simplexSolver;
 	btConvexPenetrationDepthSolver* m_pdSolver;
 
+	btVertexArray worldVertsB1;
+	btVertexArray worldVertsB2;
 	
 	bool	m_ownManifold;
 	btPersistentManifold*	m_manifoldPtr;
@@ -59,7 +61,7 @@ class btConvexConvexAlgorithm : public btActivatingCollisionAlgorithm
 
 public:
 
-	btConvexConvexAlgorithm(btPersistentManifold* mf,const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap, 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();
 
@@ -87,18 +89,17 @@ public:
 	{
 
 		btConvexPenetrationDepthSolver*		m_pdSolver;
-		btSimplexSolverInterface*			m_simplexSolver;
 		int m_numPerturbationIterations;
 		int m_minimumPointsPerturbationThreshold;
 
-		CreateFunc(btSimplexSolverInterface*			simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
+		CreateFunc(btConvexPenetrationDepthSolver* pdSolver);
 		
 		virtual ~CreateFunc();
 
 		virtual	btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
 		{
 			void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btConvexConvexAlgorithm));
-			return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_simplexSolver,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
+			return new(mem) btConvexConvexAlgorithm(ci.m_manifold,ci,body0Wrap,body1Wrap,m_pdSolver,m_numPerturbationIterations,m_minimumPointsPerturbationThreshold);
 		}
 	};
 

+ 86 - 10
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp

@@ -44,9 +44,7 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 //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)
 	{
 		mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);
@@ -59,7 +57,7 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 	
 	//default CreationFunctions, filling the m_doubleDispatch table
 	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);
 	m_convexConcaveCreateFunc = new (mem)btConvexConcaveCollisionAlgorithm::CreateFunc;
 	mem = btAlignedAlloc(sizeof(btConvexConcaveCollisionAlgorithm::CreateFunc),16);
@@ -105,12 +103,12 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 	int maxSize = sizeof(btConvexConvexAlgorithm);
 	int maxSize2 = sizeof(btConvexConcaveCollisionAlgorithm);
 	int maxSize3 = sizeof(btCompoundCollisionAlgorithm);
-	int sl = sizeof(btConvexSeparatingDistanceUtil);
-	sl = sizeof(btGjkPairDetector);
+	int maxSize4 = sizeof(btCompoundCompoundCollisionAlgorithm);
+
 	int	collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize);
 	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2);
 	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3);
-
+	collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize4);
 		
 	if (constructionInfo.m_persistentManifoldPool)
 	{
@@ -123,6 +121,7 @@ btDefaultCollisionConfiguration::btDefaultCollisionConfiguration(const btDefault
 		m_persistentManifoldPool = new (mem) btPoolAllocator(sizeof(btPersistentManifold),constructionInfo.m_defaultMaxPersistentManifoldPoolSize);
 	}
 	
+	collisionAlgorithmMaxElementSize = (collisionAlgorithmMaxElementSize+16)&0xffffffffffff0;
 	if (constructionInfo.m_collisionAlgorithmPool)
 	{
 		m_ownsCollisionAlgorithmPool = false;
@@ -192,9 +191,6 @@ btDefaultCollisionConfiguration::~btDefaultCollisionConfiguration()
 	m_planeConvexCF->~btCollisionAlgorithmCreateFunc();
 	btAlignedFree( m_planeConvexCF);
 
-	m_simplexSolver->~btVoronoiSimplexSolver();
-	btAlignedFree(m_simplexSolver);
-
 	m_pdSolver->~btConvexPenetrationDepthSolver();
 	
 	btAlignedFree(m_pdSolver);
@@ -202,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)
 {

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

@@ -60,8 +60,7 @@ protected:
 	btPoolAllocator*	m_collisionAlgorithmPool;
 	bool	m_ownsCollisionAlgorithmPool;
 
-	//default simplex/penetration depth solvers
-	btVoronoiSimplexSolver*	m_simplexSolver;
+	//default penetration depth solver
 	btConvexPenetrationDepthSolver*	m_pdSolver;
 	
 	//default CreationFunctions, filling the m_doubleDispatch table
@@ -102,14 +101,10 @@ public:
 	}
 
 
-	virtual	btVoronoiSimplexSolver*	getSimplexSolver()
-	{
-		return m_simplexSolver;
-	}
-
-
 	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.
 	///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.

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

@@ -28,9 +28,7 @@ int gFindSimplePairs =0;
 
 
 
-btHashedSimplePairCache::btHashedSimplePairCache():
-	m_blockedForChanges(false)
-{
+btHashedSimplePairCache::btHashedSimplePairCache() {
 	int initialAllocatedSize= 2;
 	m_overlappingPairArray.reserve(initialAllocatedSize);
 	growTables();

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

@@ -55,9 +55,7 @@ extern int gFindSimplePairs;
 class btHashedSimplePairCache
 {
 	btSimplePairArray	m_overlappingPairArray;
-	
-	bool		m_blockedForChanges;
-	
+		
 
 protected:
 	

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

@@ -193,7 +193,7 @@ struct btConnectivityProcessor : public btTriangleCallback
 				btScalar len2 = calculatedEdge.length2();
 
 				btScalar correctedAngle(0);
-				btVector3 calculatedNormalB = normalA;
+				//btVector3 calculatedNormalB = normalA;
 				bool isConvex = false;
 
 				if (len2<m_triangleInfoMap->m_planarEpsilon)
@@ -213,10 +213,6 @@ struct btConnectivityProcessor : public btTriangleCallback
 					isConvex = (dotA<0.);
 
 					correctedAngle = isConvex ? ang4 : -ang4;
-					btQuaternion orn2(calculatedEdge,-correctedAngle);
-					calculatedNormalB = btMatrix3x3(orn2)*normalA;
-
-
 				}
 
 				

+ 40 - 3
Engine/lib/bullet/src/BulletCollision/CollisionDispatch/btManifoldResult.cpp

@@ -24,10 +24,9 @@ ContactAddedCallback		gContactAddedCallback=0;
 
 
 
-///User can override this material combiner by implementing gContactAddedCallback and setting body0->m_collisionFlags |= btCollisionObject::customMaterialCallback;
-inline btScalar	calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1)
+btScalar	btManifoldResult::calculateCombinedRollingFriction(const btCollisionObject* body0,const btCollisionObject* body1)
 {
-	btScalar friction = body0->getRollingFriction() * body1->getRollingFriction();
+	btScalar friction = body0->getRollingFriction() * body1->getFriction() + body1->getRollingFriction() * body0->getFriction();
 
 	const btScalar MAX_FRICTION  = btScalar(10.);
 	if (friction < -MAX_FRICTION)
@@ -38,6 +37,17 @@ inline btScalar	calculateCombinedRollingFriction(const btCollisionObject* body0,
 
 }
 
+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;
 btScalar	btManifoldResult::calculateCombinedFriction(const btCollisionObject* body0,const btCollisionObject* body1)
@@ -58,6 +68,22 @@ btScalar	btManifoldResult::calculateCombinedRestitution(const btCollisionObject*
 	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(const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
@@ -70,6 +96,7 @@ btManifoldResult::btManifoldResult(const btCollisionObjectWrapper* body0Wrap,con
 	m_index0(-1),
 	m_index1(-1)
 #endif //DEBUG_PART_INDEX
+	, m_closestPointDistanceThreshold(0)
 {
 }
 
@@ -109,6 +136,16 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
 	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);
 	
 

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

@@ -49,17 +49,19 @@ protected:
 	int m_index0;
 	int m_index1;
 	
-
+	
 public:
 
 	btManifoldResult()
-#ifdef DEBUG_PART_INDEX
 		:
+#ifdef DEBUG_PART_INDEX
+		
 	m_partId0(-1),
 	m_partId1(-1),
 	m_index0(-1),
 	m_index1(-1)
 #endif //DEBUG_PART_INDEX
+		m_closestPointDistanceThreshold(0)
 	{
 	}
 
@@ -142,9 +144,15 @@ public:
 		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 //BT_MANIFOLD_RESULT_H

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

@@ -12,6 +12,7 @@ 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.
 3. This notice may not be removed or altered from any source distribution.
 */
+#define CLEAR_MANIFOLD 1
 
 #include "btSphereSphereCollisionAlgorithm.h"
 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h"
@@ -62,7 +63,7 @@ void btSphereSphereCollisionAlgorithm::processCollision (const btCollisionObject
 #endif
 
 	///iff distance positive, don't generate a new contact
-	if ( len > (radius0+radius1))
+	if ( len > (radius0+radius1+resultOut->m_closestPointDistanceThreshold))
 	{
 #ifndef CLEAR_MANIFOLD
 		resultOut->refreshContactPoints();

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

@@ -56,7 +56,7 @@ void btSphereTriangleCollisionAlgorithm::processCollision (const btCollisionObje
 	
 	/// report a contact. internally this will be kept persistent, and contact reduction is done
 	resultOut->setPersistentManifold(m_manifoldPtr);
-	SphereTriangleDetector detector(sphere,triangle, m_manifoldPtr->getContactBreakingThreshold());
+	SphereTriangleDetector detector(sphere,triangle, m_manifoldPtr->getContactBreakingThreshold()+ resultOut->m_closestPointDistanceThreshold);
 	
 	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
 	input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds

+ 5 - 4
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp

@@ -245,16 +245,18 @@ void	btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
 		btStridingMeshInterface*	m_meshInterface;
 		btTriangleCallback*		m_callback;
 		btVector3				m_triangle[3];
-
+		int m_numOverlap;
 
 		MyNodeOverlapCallback(btTriangleCallback* callback,btStridingMeshInterface* meshInterface)
 			:m_meshInterface(meshInterface),
-			m_callback(callback)
+			m_callback(callback),
+			m_numOverlap(0)
 		{
 		}
 				
 		virtual void processNode(int nodeSubPart, int nodeTriangleIndex)
 		{
+			m_numOverlap++;
 			const unsigned char *vertexbase;
 			int numverts;
 			PHY_ScalarType type;
@@ -321,8 +323,7 @@ void	btBvhTriangleMeshShape::processAllTriangles(btTriangleCallback* callback,co
 	MyNodeOverlapCallback	myNodeCallback(callback,m_meshInterface);
 
 	m_bvh->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax);
-
-
+	
 #endif//DISABLE_BVH
 
 

+ 4 - 0
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h

@@ -39,7 +39,11 @@ ATTRIBUTE_ALIGNED16(class) btBvhTriangleMeshShape : public btTriangleMeshShape
 
 	bool m_useQuantizedAabbCompression;
 	bool m_ownsBvh;
+#ifdef __clang__
+	bool m_pad[11] __attribute__((unused));////need padding due to alignment
+#else
 	bool m_pad[11];////need padding due to alignment
+#endif
 
 public:
 

+ 10 - 0
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCapsuleShape.h

@@ -117,6 +117,7 @@ public:
 	///fills the dataBuffer and returns the struct name (and 0 on failure)
 	virtual	const char*	serialize(void* dataBuffer, btSerializer* serializer) const;
 
+	SIMD_FORCE_INLINE	void	deSerializeFloat(struct btCapsuleShapeData* dataBuffer);
 
 };
 
@@ -181,4 +182,13 @@ SIMD_FORCE_INLINE	const char*	btCapsuleShape::serialize(void* dataBuffer, btSeri
 	return "btCapsuleShapeData";
 }
 
+SIMD_FORCE_INLINE	void	btCapsuleShape::deSerializeFloat(btCapsuleShapeData* dataBuffer)
+{
+	m_implicitShapeDimensions.deSerializeFloat(dataBuffer->m_convexInternalShapeData.m_implicitShapeDimensions);
+	m_collisionMargin = dataBuffer->m_convexInternalShapeData.m_collisionMargin;
+	m_localScaling.deSerializeFloat(dataBuffer->m_convexInternalShapeData.m_localScaling);
+	//it is best to already pre-allocate the matching btCapsuleShape*(X/Z) version to match m_upAxis
+	m_upAxis = dataBuffer->m_upAxis;
+}
+
 #endif //BT_CAPSULE_SHAPE_H

+ 13 - 2
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCollisionShape.h

@@ -29,12 +29,13 @@ ATTRIBUTE_ALIGNED16(class) btCollisionShape
 protected:
 	int m_shapeType;
 	void* m_userPointer;
+	int m_userIndex;
 
 public:
 
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0)
+	btCollisionShape() : m_shapeType (INVALID_SHAPE_PROXYTYPE), m_userPointer(0), m_userIndex(-1)
 	{
 	}
 
@@ -47,7 +48,7 @@ public:
 
 	virtual void	getBoundingSphere(btVector3& center,btScalar& radius) const;
 
-	///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
+	///getAngularMotionDisc returns the maximum radius needed for Conservative Advancement to handle time-of-impact with rotations.
 	virtual btScalar	getAngularMotionDisc() const;
 
 	virtual btScalar	getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const;
@@ -130,6 +131,16 @@ public:
 	{
 		return m_userPointer;
 	}
+	void setUserIndex(int index)
+	{
+		m_userIndex = index;
+	}
+
+	int getUserIndex() const
+	{
+		return m_userIndex;
+	}
+
 
 	virtual	int	calculateSerializeBufferSize() const;
 

+ 7 - 4
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCompoundShape.cpp

@@ -18,7 +18,7 @@ subject to the following restrictions:
 #include "BulletCollision/BroadphaseCollision/btDbvt.h"
 #include "LinearMath/btSerializer.h"
 
-btCompoundShape::btCompoundShape(bool enableDynamicAabbTree)
+btCompoundShape::btCompoundShape(bool enableDynamicAabbTree, const int initialChildCapacity)
 : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)),
 m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)),
 m_dynamicAabbTree(0),
@@ -34,6 +34,8 @@ m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
 		m_dynamicAabbTree = new(mem) btDbvt();
 		btAssert(mem==m_dynamicAabbTree);
 	}
+
+	m_children.reserve(initialChildCapacity);
 }
 
 
@@ -77,8 +79,8 @@ void	btCompoundShape::addChildShape(const btTransform& localTransform,btCollisio
 	if (m_dynamicAabbTree)
 	{
 		const btDbvtVolume	bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
-		int index = m_children.size();
-		child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
+		size_t index = m_children.size();
+		child.m_node = m_dynamicAabbTree->insert(bounds,reinterpret_cast<void*>(index) );
 	}
 
 	m_children.push_back(child);
@@ -312,7 +314,8 @@ void btCompoundShape::createAabbTreeFromChildren()
             child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax);
 
             const btDbvtVolume  bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
-            child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index);
+			size_t index2 = index;
+            child.m_node = m_dynamicAabbTree->insert(bounds, reinterpret_cast<void*>(index2) );
         }
     }
 }

+ 2 - 2
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btCompoundShape.h

@@ -53,6 +53,7 @@ SIMD_FORCE_INLINE bool operator==(const btCompoundShapeChild& c1, const btCompou
 /// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
 ATTRIBUTE_ALIGNED16(class) btCompoundShape	: public btCollisionShape
 {
+protected:
 	btAlignedObjectArray<btCompoundShapeChild> m_children;
 	btVector3						m_localAabbMin;
 	btVector3						m_localAabbMax;
@@ -64,13 +65,12 @@ ATTRIBUTE_ALIGNED16(class) btCompoundShape	: public btCollisionShape
 
 	btScalar	m_collisionMargin;
 
-protected:
 	btVector3	m_localScaling;
 
 public:
 	BT_DECLARE_ALIGNED_ALLOCATOR();
 
-	btCompoundShape(bool enableDynamicAabbTree = true);
+	explicit btCompoundShape(bool enableDynamicAabbTree = true, const int initialChildCapacity = 0);
 
 	virtual ~btCompoundShape();
 

+ 9 - 0
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConeShape.h

@@ -43,6 +43,15 @@ public:
 	btScalar getRadius() const { return m_radius;}
 	btScalar getHeight() const { return m_height;}
 
+	void setRadius(const btScalar radius)
+	{
+		m_radius = radius;
+	}
+	void setHeight(const btScalar height)
+	{
+		m_height = height;
+	}
+
 
 	virtual void	calculateLocalInertia(btScalar mass,btVector3& inertia) const
 	{

+ 13 - 4
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp

@@ -22,6 +22,8 @@ subject to the following restrictions:
 
 #include "LinearMath/btQuaternion.h"
 #include "LinearMath/btSerializer.h"
+#include "btConvexPolyhedron.h"
+#include "LinearMath/btConvexHullComputer.h"
 
 btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexAabbCachingShape ()
 {
@@ -121,10 +123,17 @@ btVector3	btConvexHullShape::localGetSupportingVertex(const btVector3& vec)const
 }
 
 
-
-
-
-
+void btConvexHullShape::optimizeConvexHull()
+{
+	btConvexHullComputer conv;
+	conv.compute(&m_unscaledPoints[0].getX(), sizeof(btVector3),m_unscaledPoints.size(),0.f,0.f);
+	int numVerts = conv.vertices.size();
+	m_unscaledPoints.resize(0);
+	for (int i=0;i<numVerts;i++)
+    {
+        m_unscaledPoints.push_back(conv.vertices[i]);
+    }
+}
 
 
 

+ 2 - 3
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexHullShape.h

@@ -55,9 +55,8 @@ public:
 		return getUnscaledPoints();
 	}
 
-	
-
-
+    void optimizeConvexHull();
+    
 	SIMD_FORCE_INLINE	btVector3 getScaledPoint(int i) const
 	{
 		return m_unscaledPoints[i] * m_localScaling;

+ 2 - 1
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexPolyhedron.cpp

@@ -21,6 +21,7 @@ subject to the following restrictions:
 #include "btConvexPolyhedron.h"
 #include "LinearMath/btHashMap.h"
 
+
 btConvexPolyhedron::btConvexPolyhedron()
 {
 
@@ -33,7 +34,7 @@ btConvexPolyhedron::~btConvexPolyhedron()
 
 inline bool IsAlmostZero(const btVector3& v)
 {
-	if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6)	return false;
+	if(btFabs(v.x())>1e-6 || btFabs(v.y())>1e-6 || btFabs(v.z())>1e-6)	return false;
 	return true;
 }
 

+ 6 - 2
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexShape.cpp

@@ -48,7 +48,7 @@ btConvexShape::~btConvexShape()
 }
 
 
-void btConvexShape::project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const
+void btConvexShape::project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max, btVector3& witnesPtMin,btVector3& witnesPtMax) const
 {
 	btVector3 localAxis = dir*trans.getBasis();
 	btVector3 vtx1 = trans(localGetSupportingVertex(localAxis));
@@ -56,12 +56,16 @@ void btConvexShape::project(const btTransform& trans, const btVector3& dir, btSc
 
 	min = vtx1.dot(dir);
 	max = vtx2.dot(dir);
-
+	witnesPtMax = vtx2;
+	witnesPtMin = vtx1;
+	
 	if(min>max)
 	{
 		btScalar tmp = min;
 		min = max;
 		max = tmp;
+		witnesPtMax = vtx1;
+		witnesPtMin = vtx2;
 	}
 }
 

+ 2 - 1
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btConvexShape.h

@@ -52,7 +52,8 @@ public:
 	btScalar getMarginNonVirtual () const;
 	void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
 
-	virtual void project(const btTransform& trans, const btVector3& dir, btScalar& min, btScalar& max) const;
+
+	virtual void project(const btTransform& trans, const btVector3& dir, btScalar& minProj, btScalar& maxProj, btVector3& witnesPtMin,btVector3& witnesPtMax) const;
 
 	
 	//notice that the vectors should be unit length

+ 12 - 13
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp

@@ -59,15 +59,13 @@ PHY_ScalarType hdt, bool flipQuadEdges
 )
 {
 	// validation
-	btAssert(heightStickWidth > 1 && "bad width");
-	btAssert(heightStickLength > 1 && "bad length");
-	btAssert(heightfieldData && "null heightfield data");
+	btAssert(heightStickWidth > 1);// && "bad width");
+	btAssert(heightStickLength > 1);// && "bad length");
+	btAssert(heightfieldData);// && "null heightfield data");
 	// btAssert(heightScale) -- do we care?  Trust caller here
-	btAssert(minHeight <= maxHeight && "bad min/max height");
-	btAssert(upAxis >= 0 && upAxis < 3 &&
-	    "bad upAxis--should be in range [0,2]");
-	btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_SHORT &&
-	    "Bad height data type enum");
+	btAssert(minHeight <= maxHeight);// && "bad min/max height");
+	btAssert(upAxis >= 0 && upAxis < 3);// && "bad upAxis--should be in range [0,2]");
+	btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_SHORT);// && "Bad height data type enum");
 
 	// initialize member variables
 	m_shapeType = TERRAIN_SHAPE_PROXYTYPE;
@@ -110,7 +108,7 @@ PHY_ScalarType hdt, bool flipQuadEdges
 	default:
 		{
 			//need to get valid m_upAxis
-			btAssert(0 && "Bad m_upAxis");
+			btAssert(0);// && "Bad m_upAxis");
 		}
 	}
 
@@ -365,14 +363,15 @@ void	btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback
 			{
         //first triangle
         getVertex(x,j,vertices[0]);
-        getVertex(x+1,j,vertices[1]);
-        getVertex(x+1,j+1,vertices[2]);
+		getVertex(x, j + 1, vertices[1]);
+		getVertex(x + 1, j + 1, vertices[2]);
         callback->processTriangle(vertices,x,j);
         //second triangle
       //  getVertex(x,j,vertices[0]);//already got this vertex before, thanks to Danny Chapman
         getVertex(x+1,j+1,vertices[1]);
-        getVertex(x,j+1,vertices[2]);
-        callback->processTriangle(vertices,x,j);				
+		getVertex(x + 1, j, vertices[2]);
+		callback->processTriangle(vertices, x, j);
+
 			} else
 			{
         //first triangle

+ 2 - 2
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp

@@ -75,7 +75,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScala
 		int inner_count = MIN( numSpheres - k, 128 );
         for( long i = 0; i < inner_count; i++ )
         {
-            temp[i] = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
+            temp[i] = (*pos)*m_localScaling +vec*m_localScaling*(*rad) - vec * getMargin();
             pos++;
             rad++;
         }
@@ -113,7 +113,7 @@ btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScala
             int inner_count = MIN( numSpheres - k, 128 );
             for( long i = 0; i < inner_count; i++ )
             {
-                temp[i] = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
+                temp[i] = (*pos)*m_localScaling +vec*m_localScaling*(*rad) - vec * getMargin();
                 pos++;
                 rad++;
             }

+ 0 - 1
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h

@@ -25,7 +25,6 @@ subject to the following restrictions:
 ATTRIBUTE_ALIGNED16(class) btMultimaterialTriangleMeshShape : public btBvhTriangleMeshShape
 {
     btAlignedObjectArray <btMaterial*> m_materialList;
-    int ** m_triangleMaterials;
 
 public:
 

+ 1 - 1
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp

@@ -21,7 +21,7 @@ subject to the following restrictions:
 btStaticPlaneShape::btStaticPlaneShape(const btVector3& planeNormal,btScalar planeConstant)
 : btConcaveShape (), m_planeNormal(planeNormal.normalized()),
 m_planeConstant(planeConstant),
-m_localScaling(btScalar(0.),btScalar(0.),btScalar(0.))
+m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
 {
 	m_shapeType = STATIC_PLANE_PROXYTYPE;
 	//	btAssert( btFuzzyZero(m_planeNormal.length() - btScalar(1.)) );

+ 7 - 0
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.cpp

@@ -75,6 +75,13 @@ void	btTriangleMesh::addIndex(int index)
 	}
 }
 
+void	btTriangleMesh::addTriangleIndices(int index1, int index2, int index3 )
+{
+	m_indexedMeshes[0].m_numTriangles++;
+	addIndex( index1 );
+	addIndex( index2 );
+	addIndex( index3 );
+}
 
 int	btTriangleMesh::findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices)
 {

+ 4 - 1
Engine/lib/bullet/src/BulletCollision/CollisionShapes/btTriangleMesh.h

@@ -52,7 +52,10 @@ class btTriangleMesh : public btTriangleIndexVertexArray
 		///By default addTriangle won't search for duplicate vertices, because the search is very slow for large triangle meshes.
 		///In general it is better to directly use btTriangleIndexVertexArray instead.
 		void	addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2, bool removeDuplicateVertices=false);
-		
+
+		///Add a triangle using its indices. Make sure the indices are pointing within the vertices array, so add the vertices first (and to be sure, avoid removal of duplicate vertices)	
+		void	addTriangleIndices(int index1, int index2, int index3 );
+	
 		int getNumTriangles() const;
 
 		virtual void	preallocateVertices(int numverts);

+ 0 - 746
Engine/lib/bullet/src/BulletCollision/Doxyfile

@@ -1,746 +0,0 @@
-# Doxyfile 1.2.4
-
-# This file describes the settings to be used by doxygen for a project
-#
-# All text after a hash (#) is considered a comment and will be ignored
-# The format is:
-#       TAG = value [value, ...]
-# For lists items can also be appended using:
-#       TAG += value [value, ...]
-# Values that contain spaces should be placed between quotes (" ")
-
-#---------------------------------------------------------------------------
-# General configuration options
-#---------------------------------------------------------------------------
-
-# The PROJECT_NAME tag is a single word (or a sequence of words surrounded 
-# by quotes) that should identify the project. 
-PROJECT_NAME           = "Bullet Continuous Collision Detection Library"
-
-# The PROJECT_NUMBER tag can be used to enter a project or revision number. 
-# This could be handy for archiving the generated documentation or 
-# if some version control system is used.
-
-PROJECT_NUMBER         = 
-
-# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) 
-# base path where the generated documentation will be put. 
-# If a relative path is entered, it will be relative to the location 
-# where doxygen was started. If left blank the current directory will be used.
-
-OUTPUT_DIRECTORY       = 
-
-# The OUTPUT_LANGUAGE tag is used to specify the language in which all 
-# documentation generated by doxygen is written. Doxygen will use this 
-# information to generate all constant output in the proper language. 
-# The default language is English, other supported languages are: 
-# Dutch, French, Italian, Czech, Swedish, German, Finnish, Japanese, 
-# Korean, Hungarian, Norwegian, Spanish, Romanian, Russian, Croatian, 
-# Polish, Portuguese and Slovene.
-
-OUTPUT_LANGUAGE        = English
-
-# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in 
-# documentation are documented, even if no documentation was available. 
-# Private class members and static file members will be hidden unless 
-# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES 
-
-EXTRACT_ALL            = YES
-
-# If the EXTRACT_PRIVATE tag is set to YES all private members of a class 
-# will be included in the documentation. 
-
-EXTRACT_PRIVATE        = YES
-
-# If the EXTRACT_STATIC tag is set to YES all static members of a file 
-# will be included in the documentation. 
-
-EXTRACT_STATIC         = YES
-
-# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all 
-# undocumented members of documented classes, files or namespaces. 
-# If set to NO (the default) these members will be included in the 
-# various overviews, but no documentation section is generated. 
-# This option has no effect if EXTRACT_ALL is enabled. 
-
-HIDE_UNDOC_MEMBERS     = NO
-
-# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all 
-# undocumented classes that are normally visible in the class hierarchy. 
-# If set to NO (the default) these class will be included in the various 
-# overviews. This option has no effect if EXTRACT_ALL is enabled. 
-
-HIDE_UNDOC_CLASSES     = NO
-
-# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will 
-# include brief member descriptions after the members that are listed in 
-# the file and class documentation (similar to JavaDoc). 
-# Set to NO to disable this. 
-
-BRIEF_MEMBER_DESC      = YES
-
-# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend 
-# the brief description of a member or function before the detailed description. 
-# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the 
-# brief descriptions will be completely suppressed. 
-
-REPEAT_BRIEF           = YES
-
-# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then 
-# Doxygen will generate a detailed section even if there is only a brief 
-# description. 
-
-ALWAYS_DETAILED_SEC    = NO
-
-# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full 
-# path before files name in the file list and in the header files. If set 
-# to NO the shortest path that makes the file name unique will be used. 
-
-FULL_PATH_NAMES        = NO
-
-# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag 
-# can be used to strip a user defined part of the path. Stripping is 
-# only done if one of the specified strings matches the left-hand part of 
-# the path. It is allowed to use relative paths in the argument list.
-
-STRIP_FROM_PATH        = 
-
-# The INTERNAL_DOCS tag determines if documentation 
-# that is typed after a \internal command is included. If the tag is set 
-# to NO (the default) then the documentation will be excluded. 
-# Set it to YES to include the internal documentation. 
-
-INTERNAL_DOCS          = NO
-
-# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will 
-# generate a class diagram (in Html and LaTeX) for classes with base or 
-# super classes. Setting the tag to NO turns the diagrams off. 
-
-CLASS_DIAGRAMS         = YES
-
-# If the SOURCE_BROWSER tag is set to YES then a list of source files will 
-# be generated. Documented entities will be cross-referenced with these sources. 
-
-SOURCE_BROWSER         = YES
-
-# Setting the INLINE_SOURCES tag to YES will include the body 
-# of functions and classes directly in the documentation. 
-
-INLINE_SOURCES         = NO
-
-# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct 
-# doxygen to hide any special comment blocks from generated source code 
-# fragments. Normal C and C++ comments will always remain visible. 
-
-STRIP_CODE_COMMENTS    = YES
-
-# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate 
-# file names in lower case letters. If set to YES upper case letters are also 
-# allowed. This is useful if you have classes or files whose names only differ 
-# in case and if your file system supports case sensitive file names. Windows 
-# users are adviced to set this option to NO.
-
-CASE_SENSE_NAMES       = YES
-
-# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen 
-# will show members with their full class and namespace scopes in the 
-# documentation. If set to YES the scope will be hidden. 
-
-HIDE_SCOPE_NAMES       = NO
-
-# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen 
-# will generate a verbatim copy of the header file for each class for 
-# which an include is specified. Set to NO to disable this. 
-
-VERBATIM_HEADERS       = YES
-
-# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen 
-# will put list of the files that are included by a file in the documentation 
-# of that file. 
-
-SHOW_INCLUDE_FILES     = YES
-
-# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen 
-# will interpret the first line (until the first dot) of a JavaDoc-style 
-# comment as the brief description. If set to NO, the JavaDoc 
-# comments  will behave just like the Qt-style comments (thus requiring an 
-# explict @brief command for a brief description. 
-
-JAVADOC_AUTOBRIEF      = YES
-
-# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented 
-# member inherits the documentation from any documented member that it 
-# reimplements. 
-
-INHERIT_DOCS           = YES
-
-# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] 
-# is inserted in the documentation for inline members. 
-
-INLINE_INFO            = YES
-
-# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen 
-# will sort the (detailed) documentation of file and class members 
-# alphabetically by member name. If set to NO the members will appear in 
-# declaration order. 
-
-SORT_MEMBER_DOCS       = YES
-
-# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC 
-# tag is set to YES, then doxygen will reuse the documentation of the first 
-# member in the group (if any) for the other members of the group. By default 
-# all members of a group must be documented explicitly.
-
-DISTRIBUTE_GROUP_DOC   = NO
-
-# The TAB_SIZE tag can be used to set the number of spaces in a tab. 
-# Doxygen uses this value to replace tabs by spaces in code fragments. 
-
-TAB_SIZE               = 8
-
-# The ENABLE_SECTIONS tag can be used to enable conditional 
-# documentation sections, marked by \if sectionname ... \endif. 
-
-ENABLED_SECTIONS       = 
-
-# The GENERATE_TODOLIST tag can be used to enable (YES) or 
-# disable (NO) the todo list. This list is created by putting \todo 
-# commands in the documentation.
-
-GENERATE_TODOLIST      = YES
-
-# The GENERATE_TESTLIST tag can be used to enable (YES) or 
-# disable (NO) the test list. This list is created by putting \test 
-# commands in the documentation.
-
-GENERATE_TESTLIST      = YES
-
-# This tag can be used to specify a number of aliases that acts 
-# as commands in the documentation. An alias has the form "name=value". 
-# For example adding "sideeffect=\par Side Effects:\n" will allow you to 
-# put the command \sideeffect (or @sideeffect) in the documentation, which 
-# will result in a user defined paragraph with heading "Side Effects:". 
-# You can put \n's in the value part of an alias to insert newlines. 
-
-ALIASES                = 
-
-#---------------------------------------------------------------------------
-# configuration options related to warning and progress messages
-#---------------------------------------------------------------------------
-
-# The QUIET tag can be used to turn on/off the messages that are generated 
-# by doxygen. Possible values are YES and NO. If left blank NO is used. 
-
-QUIET                  = NO
-
-# The WARNINGS tag can be used to turn on/off the warning messages that are 
-# generated by doxygen. Possible values are YES and NO. If left blank 
-# NO is used. 
-
-WARNINGS               = YES
-
-# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings 
-# for undocumented members. If EXTRACT_ALL is set to YES then this flag will 
-# automatically be disabled. 
-
-WARN_IF_UNDOCUMENTED   = YES
-
-# The WARN_FORMAT tag determines the format of the warning messages that 
-# doxygen can produce. The string should contain the $file, $line, and $text 
-# tags, which will be replaced by the file and line number from which the 
-# warning originated and the warning text. 
-
-WARN_FORMAT            = "$file:$line: $text"
-
-# The WARN_LOGFILE tag can be used to specify a file to which warning 
-# and error messages should be written. If left blank the output is written 
-# to stderr. 
-
-WARN_LOGFILE           = 
-
-#---------------------------------------------------------------------------
-# configuration options related to the input files
-#---------------------------------------------------------------------------
-
-# The INPUT tag can be used to specify the files and/or directories that contain 
-# documented source files. You may enter file names like "myfile.cpp" or 
-# directories like "/usr/src/myproject". Separate the files or directories 
-# with spaces. 
-
-INPUT                  = .
-
-
-# If the value of the INPUT tag contains directories, you can use the 
-# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
-# and *.h) to filter out the source-files in the directories. If left 
-# blank all files are included. 
-
-FILE_PATTERNS          = *.h *.cpp *.c
-
-# The RECURSIVE tag can be used to turn specify whether or not subdirectories 
-# should be searched for input files as well. Possible values are YES and NO. 
-# If left blank NO is used. 
-
-RECURSIVE              = YES
-
-# The EXCLUDE tag can be used to specify files and/or directories that should 
-# excluded from the INPUT source files. This way you can easily exclude a 
-# subdirectory from a directory tree whose root is specified with the INPUT tag. 
-
-EXCLUDE                = 
-
-# If the value of the INPUT tag contains directories, you can use the 
-# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude 
-# certain files from those directories. 
-
-EXCLUDE_PATTERNS       = 
-
-# The EXAMPLE_PATH tag can be used to specify one or more files or 
-# directories that contain example code fragments that are included (see 
-# the \include command). 
-
-EXAMPLE_PATH           = 
-
-# If the value of the EXAMPLE_PATH tag contains directories, you can use the 
-# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp 
-# and *.h) to filter out the source-files in the directories. If left 
-# blank all files are included. 
-
-EXAMPLE_PATTERNS       = 
-
-# The IMAGE_PATH tag can be used to specify one or more files or 
-# directories that contain image that are included in the documentation (see 
-# the \image command). 
-
-IMAGE_PATH             = 
-
-# The INPUT_FILTER tag can be used to specify a program that doxygen should 
-# invoke to filter for each input file. Doxygen will invoke the filter program 
-# by executing (via popen()) the command <filter> <input-file>, where <filter> 
-# is the value of the INPUT_FILTER tag, and <input-file> is the name of an 
-# input file. Doxygen will then use the output that the filter program writes 
-# to standard output. 
-
-INPUT_FILTER           = 
-
-# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using 
-# INPUT_FILTER) will be used to filter the input files when producing source 
-# files to browse. 
-
-FILTER_SOURCE_FILES    = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the alphabetical class index
-#---------------------------------------------------------------------------
-
-# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index 
-# of all compounds will be generated. Enable this if the project 
-# contains a lot of classes, structs, unions or interfaces. 
-
-ALPHABETICAL_INDEX     = NO
-
-# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then 
-# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns 
-# in which this list will be split (can be a number in the range [1..20]) 
-
-COLS_IN_ALPHA_INDEX    = 5
-
-# In case all classes in a project start with a common prefix, all 
-# classes will be put under the same header in the alphabetical index. 
-# The IGNORE_PREFIX tag can be used to specify one or more prefixes that 
-# should be ignored while generating the index headers. 
-
-IGNORE_PREFIX          = 
-
-#---------------------------------------------------------------------------
-# configuration options related to the HTML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_HTML tag is set to YES (the default) Doxygen will 
-# generate HTML output. 
-
-GENERATE_HTML          = YES
-
-# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
-# put in front of it. If left blank `html' will be used as the default path. 
-
-HTML_OUTPUT            = html
-
-# The HTML_HEADER tag can be used to specify a personal HTML header for 
-# each generated HTML page. If it is left blank doxygen will generate a 
-# standard header.
-
-HTML_HEADER            = 
-
-# The HTML_FOOTER tag can be used to specify a personal HTML footer for 
-# each generated HTML page. If it is left blank doxygen will generate a 
-# standard footer.
-
-HTML_FOOTER            = 
-
-# The HTML_STYLESHEET tag can be used to specify a user defined cascading 
-# style sheet that is used by each HTML page. It can be used to 
-# fine-tune the look of the HTML output. If the tag is left blank doxygen 
-# will generate a default style sheet 
-
-HTML_STYLESHEET        = 
-
-# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, 
-# files or namespaces will be aligned in HTML using tables. If set to 
-# NO a bullet list will be used. 
-
-HTML_ALIGN_MEMBERS     = YES
-
-# If the GENERATE_HTMLHELP tag is set to YES, additional index files 
-# will be generated that can be used as input for tools like the 
-# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) 
-# of the generated HTML documentation. 
-
-GENERATE_HTMLHELP      = NO
-
-# The DISABLE_INDEX tag can be used to turn on/off the condensed index at 
-# top of each HTML page. The value NO (the default) enables the index and 
-# the value YES disables it. 
-
-DISABLE_INDEX          = NO
-
-# This tag can be used to set the number of enum values (range [1..20]) 
-# that doxygen will group on one line in the generated HTML documentation. 
-
-ENUM_VALUES_PER_LINE   = 4
-
-# If the GENERATE_TREEVIEW tag is set to YES, a side pannel will be
-# generated containing a tree-like index structure (just like the one that 
-# is generated for HTML Help). For this to work a browser that supports 
-# JavaScript and frames is required (for instance Netscape 4.0+ 
-# or Internet explorer 4.0+). 
-
-GENERATE_TREEVIEW      = NO
-
-# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be 
-# used to set the initial width (in pixels) of the frame in which the tree 
-# is shown. 
-
-TREEVIEW_WIDTH         = 250
-
-#---------------------------------------------------------------------------
-# configuration options related to the LaTeX output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will 
-# generate Latex output. 
-
-GENERATE_LATEX         = NO
-
-# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
-# put in front of it. If left blank `latex' will be used as the default path. 
-
-LATEX_OUTPUT           = latex
-
-# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact 
-# LaTeX documents. This may be useful for small projects and may help to 
-# save some trees in general. 
-
-COMPACT_LATEX          = NO
-
-# The PAPER_TYPE tag can be used to set the paper type that is used 
-# by the printer. Possible values are: a4, a4wide, letter, legal and 
-# executive. If left blank a4wide will be used. 
-
-PAPER_TYPE             = a4wide
-
-# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX 
-# packages that should be included in the LaTeX output. 
-
-EXTRA_PACKAGES         = 
-
-# The LATEX_HEADER tag can be used to specify a personal LaTeX header for 
-# the generated latex document. The header should contain everything until 
-# the first chapter. If it is left blank doxygen will generate a 
-# standard header. Notice: only use this tag if you know what you are doing! 
-
-LATEX_HEADER           = 
-
-# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated 
-# is prepared for conversion to pdf (using ps2pdf). The pdf file will 
-# contain links (just like the HTML output) instead of page references 
-# This makes the output suitable for online browsing using a pdf viewer. 
-
-PDF_HYPERLINKS         = NO
-
-# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of 
-# plain latex in the generated Makefile. Set this option to YES to get a 
-# higher quality PDF documentation. 
-
-USE_PDFLATEX           = NO
-
-# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. 
-# command to the generated LaTeX files. This will instruct LaTeX to keep 
-# running if errors occur, instead of asking the user for help. 
-# This option is also used when generating formulas in HTML. 
-
-LATEX_BATCHMODE        = NO
-
-#---------------------------------------------------------------------------
-# configuration options related to the RTF output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output 
-# The RTF output is optimised for Word 97 and may not look very pretty with 
-# other RTF readers or editors.
-
-GENERATE_RTF           = NO
-
-# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
-# put in front of it. If left blank `rtf' will be used as the default path. 
-
-RTF_OUTPUT             = rtf
-
-# If the COMPACT_RTF tag is set to YES Doxygen generates more compact 
-# RTF documents. This may be useful for small projects and may help to 
-# save some trees in general. 
-
-COMPACT_RTF            = NO
-
-# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated 
-# will contain hyperlink fields. The RTF file will 
-# contain links (just like the HTML output) instead of page references. 
-# This makes the output suitable for online browsing using a WORD or other. 
-# programs which support those fields. 
-# Note: wordpad (write) and others do not support links. 
-
-RTF_HYPERLINKS         = NO
-
-# Load stylesheet definitions from file. Syntax is similar to doxygen's 
-# config file, i.e. a series of assigments. You only have to provide 
-# replacements, missing definitions are set to their default value. 
-
-RTF_STYLESHEET_FILE    = 
-
-#---------------------------------------------------------------------------
-# configuration options related to the man page output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_MAN tag is set to YES (the default) Doxygen will 
-# generate man pages 
-
-GENERATE_MAN           = NO
-
-# The MAN_OUTPUT tag is used to specify where the man pages will be put. 
-# If a relative path is entered the value of OUTPUT_DIRECTORY will be 
-# put in front of it. If left blank `man' will be used as the default path. 
-
-MAN_OUTPUT             = man
-
-# The MAN_EXTENSION tag determines the extension that is added to 
-# the generated man pages (default is the subroutine's section .3) 
-
-MAN_EXTENSION          = .3
-
-#---------------------------------------------------------------------------
-# configuration options related to the XML output
-#---------------------------------------------------------------------------
-
-# If the GENERATE_XML tag is set to YES Doxygen will 
-# generate an XML file that captures the structure of 
-# the code including all documentation. Warning: This feature 
-# is still experimental and very incomplete.
-
-GENERATE_XML           = NO
-
-#---------------------------------------------------------------------------
-# Configuration options related to the preprocessor   
-#---------------------------------------------------------------------------
-
-# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will 
-# evaluate all C-preprocessor directives found in the sources and include 
-# files. 
-
-ENABLE_PREPROCESSING   = YES
-
-# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro 
-# names in the source code. If set to NO (the default) only conditional 
-# compilation will be performed. Macro expansion can be done in a controlled 
-# way by setting EXPAND_ONLY_PREDEF to YES. 
-
-MACRO_EXPANSION        = NO
-
-# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES 
-# then the macro expansion is limited to the macros specified with the 
-# PREDEFINED and EXPAND_AS_PREDEFINED tags. 
-
-EXPAND_ONLY_PREDEF     = NO
-
-# 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. 
-
-SEARCH_INCLUDES        = YES
-
-# The INCLUDE_PATH tag can be used to specify one or more directories that 
-# contain include files that are not input files but should be processed by 
-# the preprocessor. 
-
-INCLUDE_PATH           = ../../generic/extern
-
-# 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 
-# directories. If left blank, the patterns specified with FILE_PATTERNS will 
-# be used. 
-
-INCLUDE_FILE_PATTERNS  = 
-
-# The PREDEFINED tag can be used to specify one or more macro names that 
-# are defined before the preprocessor is started (similar to the -D option of 
-# gcc). The argument of the tag is a list of macros of the form: name 
-# or name=definition (no spaces). If the definition and the = are 
-# omitted =1 is assumed. 
-
-PREDEFINED             = 
-
-# 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. 
-# The macro definition that is found in the sources will be used. 
-# Use the PREDEFINED tag if you want to use a different macro definition. 
-
-EXPAND_AS_DEFINED      = 
-
-#---------------------------------------------------------------------------
-# Configuration::addtions related to external references   
-#---------------------------------------------------------------------------
-
-# The TAGFILES tag can be used to specify one or more tagfiles. 
-
-TAGFILES               = 
-
-# When a file name is specified after GENERATE_TAGFILE, doxygen will create 
-# a tag file that is based on the input files it reads. 
-
-GENERATE_TAGFILE       = 
-
-# If the ALLEXTERNALS tag is set to YES all external classes will be listed 
-# in the class index. If set to NO only the inherited external classes 
-# will be listed. 
-
-ALLEXTERNALS           = NO
-
-# The PERL_PATH should be the absolute path and name of the perl script 
-# interpreter (i.e. the result of `which perl'). 
-
-PERL_PATH              = /usr/bin/perl
-
-#---------------------------------------------------------------------------
-# Configuration options related to the dot tool   
-#---------------------------------------------------------------------------
-
-# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is 
-# available from the path. This tool is part of Graphviz, a graph visualization 
-# toolkit from AT&T and Lucent Bell Labs. The other options in this section 
-# have no effect if this option is set to NO (the default) 
-
-HAVE_DOT               = YES
-
-# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen 
-# will generate a graph for each documented class showing the direct and 
-# indirect inheritance relations. Setting this tag to YES will force the 
-# the CLASS_DIAGRAMS tag to NO.
-
-CLASS_GRAPH            = YES
-
-# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen 
-# will generate a graph for each documented class showing the direct and 
-# indirect implementation dependencies (inheritance, containment, and 
-# class references variables) of the class with other documented classes. 
-
-COLLABORATION_GRAPH    = YES
-
-# If the ENABLE_PREPROCESSING, INCLUDE_GRAPH, and HAVE_DOT tags are set to 
-# YES then doxygen will generate a graph for each documented file showing 
-# the direct and indirect include dependencies of the file with other 
-# documented files. 
-
-INCLUDE_GRAPH          = YES
-
-# If the ENABLE_PREPROCESSING, INCLUDED_BY_GRAPH, and HAVE_DOT tags are set to 
-# YES then doxygen will generate a graph for each documented header file showing 
-# the documented files that directly or indirectly include this file 
-
-INCLUDED_BY_GRAPH      = YES
-
-# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen 
-# will graphical hierarchy of all classes instead of a textual one. 
-
-GRAPHICAL_HIERARCHY    = YES
-
-# The tag DOT_PATH can be used to specify the path where the dot tool can be 
-# found. If left blank, it is assumed the dot tool can be found on the path. 
-
-DOT_PATH               = 
-
-# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width 
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than 
-# this value, doxygen will try to truncate the graph, so that it fits within 
-# the specified constraint. Beware that most browsers cannot cope with very 
-# large images. 
-
-MAX_DOT_GRAPH_WIDTH    = 1024
-
-# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height 
-# (in pixels) of the graphs generated by dot. If a graph becomes larger than 
-# this value, doxygen will try to truncate the graph, so that it fits within 
-# the specified constraint. Beware that most browsers cannot cope with very 
-# large images. 
-
-MAX_DOT_GRAPH_HEIGHT   = 1024
-
-# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will 
-# generate a legend page explaining the meaning of the various boxes and 
-# arrows in the dot generated graphs. 
-
-GENERATE_LEGEND        = YES
-
-#---------------------------------------------------------------------------
-# Configuration::addtions related to the search engine   
-#---------------------------------------------------------------------------
-
-# The SEARCHENGINE tag specifies whether or not a search engine should be 
-# used. If set to NO the values of all tags below this one will be ignored. 
-
-SEARCHENGINE           = NO
-
-# The CGI_NAME tag should be the name of the CGI script that 
-# starts the search engine (doxysearch) with the correct parameters. 
-# A script with this name will be generated by doxygen. 
-
-CGI_NAME               = search.cgi
-
-# The CGI_URL tag should be the absolute URL to the directory where the 
-# cgi binaries are located. See the documentation of your http daemon for 
-# details. 
-
-CGI_URL                = 
-
-# The DOC_URL tag should be the absolute URL to the directory where the 
-# documentation is located. If left blank the absolute path to the 
-# documentation, with file:// prepended to it, will be used. 
-
-DOC_URL                = 
-
-# The DOC_ABSPATH tag should be the absolute path to the directory where the 
-# documentation is located. If left blank the directory on the local machine 
-# will be used. 
-
-DOC_ABSPATH            = 
-
-# The BIN_ABSPATH tag must point to the directory where the doxysearch binary 
-# is installed. 
-
-BIN_ABSPATH            = c:\program files\doxygen\bin
-
-# The EXT_DOC_PATHS tag can be used to specify one or more paths to 
-# documentation generated for other projects. This allows doxysearch to search 
-# the documentation for these projects as well. 
-
-EXT_DOC_PATHS          = 

+ 1 - 1
Engine/lib/bullet/src/BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h

@@ -122,7 +122,7 @@ protected:
 		checkManifold(body0Wrap,body1Wrap);
 
 		btCollisionAlgorithm * convex_algorithm = m_dispatcher->findAlgorithm(
-				body0Wrap,body1Wrap,getLastManifold());
+				body0Wrap,body1Wrap,getLastManifold(), BT_CONTACT_POINT_ALGORITHMS);
 		return convex_algorithm ;
 	}
 

+ 53 - 0
Engine/lib/bullet/src/BulletCollision/Gimpact/btGImpactShape.cpp

@@ -23,6 +23,59 @@ subject to the following restrictions:
 #include "btGImpactMassUtil.h"
 
 
+btGImpactMeshShapePart::btGImpactMeshShapePart( btStridingMeshInterface * meshInterface, int part )
+{
+    // moved from .h to .cpp because of conditional compilation
+    // (The setting of BT_THREADSAFE may differ between various cpp files, so it is best to
+    // avoid using it in h files)
+    m_primitive_manager.m_meshInterface = meshInterface;
+    m_primitive_manager.m_part = part;
+    m_box_set.setPrimitiveManager( &m_primitive_manager );
+#if BT_THREADSAFE
+    // If threadsafe is requested, this object uses a different lock/unlock
+    //  model with the btStridingMeshInterface -- lock once when the object is constructed
+    //  and unlock once in the destructor.
+    // The other way of locking and unlocking for each collision check in the narrowphase
+    // is not threadsafe.  Note these are not thread-locks, they are calls to the meshInterface's
+    // getLockedReadOnlyVertexIndexBase virtual function, which by default just returns a couple of
+    // pointers.  In theory a client could override the lock function to do all sorts of
+    // things like reading data from GPU memory, or decompressing data on the fly, but such things
+    // do not seem all that likely or useful, given the performance cost.
+    m_primitive_manager.lock();
+#endif
+}
+
+btGImpactMeshShapePart::~btGImpactMeshShapePart()
+{
+    // moved from .h to .cpp because of conditional compilation
+#if BT_THREADSAFE
+    m_primitive_manager.unlock();
+#endif
+}
+
+void btGImpactMeshShapePart::lockChildShapes() const
+{
+    // moved from .h to .cpp because of conditional compilation
+#if ! BT_THREADSAFE
+    // called in the narrowphase -- not threadsafe!
+    void * dummy = (void*) ( m_box_set.getPrimitiveManager() );
+    TrimeshPrimitiveManager * dummymanager = static_cast<TrimeshPrimitiveManager *>( dummy );
+    dummymanager->lock();
+#endif
+}
+
+void btGImpactMeshShapePart::unlockChildShapes()  const
+{
+    // moved from .h to .cpp because of conditional compilation
+#if ! BT_THREADSAFE
+    // called in the narrowphase -- not threadsafe!
+    void * dummy = (void*) ( m_box_set.getPrimitiveManager() );
+    TrimeshPrimitiveManager * dummymanager = static_cast<TrimeshPrimitiveManager *>( dummy );
+    dummymanager->unlock();
+#endif
+}
+
+
 #define CALC_EXACT_INERTIA 1
 
 

+ 4 - 24
Engine/lib/bullet/src/BulletCollision/Gimpact/btGImpactShape.h

@@ -722,17 +722,8 @@ public:
 		m_box_set.setPrimitiveManager(&m_primitive_manager);
 	}
 
-
-	btGImpactMeshShapePart(btStridingMeshInterface * meshInterface,	int part)
-	{
-		m_primitive_manager.m_meshInterface = meshInterface;
-		m_primitive_manager.m_part = part;
-		m_box_set.setPrimitiveManager(&m_primitive_manager);
-	}
-
-	virtual ~btGImpactMeshShapePart()
-	{
-	}
+    btGImpactMeshShapePart( btStridingMeshInterface * meshInterface, int part );
+    virtual ~btGImpactMeshShapePart();
 
 	//! if true, then its children must get transforms.
 	virtual bool childrenHasTransform() const
@@ -742,19 +733,8 @@ public:
 
 
 	//! call when reading child shapes
-	virtual void lockChildShapes() const
-	{
-		void * dummy = (void*)(m_box_set.getPrimitiveManager());
-		TrimeshPrimitiveManager * dummymanager = static_cast<TrimeshPrimitiveManager *>(dummy);
-		dummymanager->lock();
-	}
-
-	virtual void unlockChildShapes()  const
-	{
-		void * dummy = (void*)(m_box_set.getPrimitiveManager());
-		TrimeshPrimitiveManager * dummymanager = static_cast<TrimeshPrimitiveManager *>(dummy);
-		dummymanager->unlock();
-	}
+    virtual void lockChildShapes() const;
+    virtual void unlockChildShapes()  const;
 
 	//! Gets the number of children
 	virtual int	getNumChildShapes() const

+ 7 - 7
Engine/lib/bullet/src/BulletCollision/Gimpact/gim_basic_geometry_operations.h

@@ -404,12 +404,12 @@ SIMD_FORCE_INLINE void SEGMENT_COLLISION(
 	CLASS_POINT & vPointA,
 	CLASS_POINT & vPointB)
 {
-    CLASS_POINT _AD,_BD,_N;
+    CLASS_POINT _AD,_BD,n;
     vec4f _M;//plane
     VEC_DIFF(_AD,vA2,vA1);
     VEC_DIFF(_BD,vB2,vB1);
-    VEC_CROSS(_N,_AD,_BD);
-    GREAL _tp = VEC_DOT(_N,_N);
+    VEC_CROSS(n,_AD,_BD);
+    GREAL _tp = VEC_DOT(n,n);
     if(_tp<G_EPSILON)//ARE PARALELE
     {
     	//project B over A
@@ -424,10 +424,10 @@ SIMD_FORCE_INLINE void SEGMENT_COLLISION(
     	_M[2] = VEC_DOT(vA1,_AD);
     	_M[3] = VEC_DOT(vA2,_AD);
     	//mid points
-    	_N[0] = (_M[0]+_M[1])*0.5f;
-    	_N[1] = (_M[2]+_M[3])*0.5f;
+    	n[0] = (_M[0]+_M[1])*0.5f;
+    	n[1] = (_M[2]+_M[3])*0.5f;
 
-    	if(_N[0]<_N[1])
+    	if(n[0]<n[1])
     	{
     		if(_M[1]<_M[2])
     		{
@@ -467,7 +467,7 @@ SIMD_FORCE_INLINE void SEGMENT_COLLISION(
     }
 
 
-    VEC_CROSS(_M,_N,_BD);
+    VEC_CROSS(_M,n,_BD);
     _M[3] = VEC_DOT(_M,vB1);
 
     LINE_PLANE_COLLISION(_M,_AD,vA1,vPointA,_tp,btScalar(0), btScalar(1));

+ 369 - 0
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btComputeGjkEpaPenetration.h

@@ -0,0 +1,369 @@
+/*
+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_GJK_EPA_PENETATION_CONVEX_COLLISION_H
+#define BT_GJK_EPA_PENETATION_CONVEX_COLLISION_H
+
+#include "LinearMath/btTransform.h" // Note that btVector3 might be double precision...
+#include "btGjkEpa3.h"
+#include "btGjkCollisionDescription.h"
+#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
+
+
+
+
+
+
+template <typename btConvexTemplate>
+bool btGjkEpaCalcPenDepth(const btConvexTemplate& a, const btConvexTemplate& b,
+                          const btGjkCollisionDescription& colDesc,
+                          btVector3& v, btVector3& wWitnessOnA, btVector3& wWitnessOnB)
+{
+    (void)v;
+    
+    //	const btScalar				radialmargin(btScalar(0.));
+    
+    btVector3	guessVector(b.getWorldTransform().getOrigin()-a.getWorldTransform().getOrigin());//?? why not use the GJK input?
+    
+    btGjkEpaSolver3::sResults	results;
+
+    
+    if(btGjkEpaSolver3_Penetration(a,b,guessVector,results))
+        
+    {
+        //	debugDraw->drawLine(results.witnesses[1],results.witnesses[1]+results.normal,btVector3(255,0,0));
+        //resultOut->addContactPoint(results.normal,results.witnesses[1],-results.depth);
+        wWitnessOnA = results.witnesses[0];
+        wWitnessOnB = results.witnesses[1];
+        v = results.normal;
+        return true;
+    } else
+    {
+        if(btGjkEpaSolver3_Distance(a,b,guessVector,results))
+        {
+            wWitnessOnA = results.witnesses[0];
+            wWitnessOnB = results.witnesses[1];
+            v = results.normal;
+            return false;
+        }
+    }
+    return false;
+}
+
+template <typename btConvexTemplate, typename btGjkDistanceTemplate>
+int	btComputeGjkEpaPenetration(const btConvexTemplate& a, const btConvexTemplate& b, const btGjkCollisionDescription& colDesc, btVoronoiSimplexSolver& simplexSolver, btGjkDistanceTemplate* distInfo)
+{
+    
+    bool m_catchDegeneracies  = true;
+    btScalar m_cachedSeparatingDistance = 0.f;
+    
+    btScalar distance=btScalar(0.);
+    btVector3	normalInB(btScalar(0.),btScalar(0.),btScalar(0.));
+    
+    btVector3 pointOnA,pointOnB;
+    btTransform	localTransA = a.getWorldTransform();
+    btTransform localTransB = b.getWorldTransform();
+    
+    btScalar marginA = a.getMargin();
+    btScalar marginB = b.getMargin();
+    
+    int m_curIter = 0;
+    int gGjkMaxIter = colDesc.m_maxGjkIterations;//this is to catch invalid input, perhaps check for #NaN?
+    btVector3 m_cachedSeparatingAxis = colDesc.m_firstDir;
+    
+    bool isValid = false;
+    bool checkSimplex = false;
+    bool checkPenetration = true;
+    int m_degenerateSimplex = 0;
+    
+    int m_lastUsedMethod = -1;
+    
+    {
+        btScalar squaredDistance = BT_LARGE_FLOAT;
+        btScalar delta = btScalar(0.);
+        
+        btScalar margin = marginA + marginB;
+        
+        
+        
+        simplexSolver.reset();
+        
+        for ( ; ; )
+            //while (true)
+        {
+            
+            btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* localTransA.getBasis();
+            btVector3 seperatingAxisInB = m_cachedSeparatingAxis* localTransB.getBasis();
+            
+            btVector3 pInA = a.getLocalSupportWithoutMargin(seperatingAxisInA);
+            btVector3 qInB = b.getLocalSupportWithoutMargin(seperatingAxisInB);
+            
+            btVector3  pWorld = localTransA(pInA);
+            btVector3  qWorld = localTransB(qInB);
+            
+            
+            
+            btVector3 w	= pWorld - qWorld;
+            delta = m_cachedSeparatingAxis.dot(w);
+            
+            // potential exit, they don't overlap
+            if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * colDesc.m_maximumDistanceSquared))
+            {
+                m_degenerateSimplex = 10;
+                checkSimplex=true;
+                //checkPenetration = false;
+                break;
+            }
+            
+            //exit 0: the new point is already in the simplex, or we didn't come any closer
+            if (simplexSolver.inSimplex(w))
+            {
+                m_degenerateSimplex = 1;
+                checkSimplex = true;
+                break;
+            }
+            // are we getting any closer ?
+            btScalar f0 = squaredDistance - delta;
+            btScalar f1 = squaredDistance * colDesc.m_gjkRelError2;
+            
+            if (f0 <= f1)
+            {
+                if (f0 <= btScalar(0.))
+                {
+                    m_degenerateSimplex = 2;
+                } else
+                {
+                    m_degenerateSimplex = 11;
+                }
+                checkSimplex = true;
+                break;
+            }
+            
+            //add current vertex to simplex
+            simplexSolver.addVertex(w, pWorld, qWorld);
+            btVector3 newCachedSeparatingAxis;
+            
+            //calculate the closest point to the origin (update vector v)
+            if (!simplexSolver.closest(newCachedSeparatingAxis))
+            {
+                m_degenerateSimplex = 3;
+                checkSimplex = true;
+                break;
+            }
+            
+            if(newCachedSeparatingAxis.length2()<colDesc.m_gjkRelError2)
+            {
+                m_cachedSeparatingAxis = newCachedSeparatingAxis;
+                m_degenerateSimplex = 6;
+                checkSimplex = true;
+                break;
+            }
+            
+            btScalar previousSquaredDistance = squaredDistance;
+            squaredDistance = newCachedSeparatingAxis.length2();
+#if 0
+            ///warning: this termination condition leads to some problems in 2d test case see Bullet/Demos/Box2dDemo
+            if (squaredDistance>previousSquaredDistance)
+            {
+                m_degenerateSimplex = 7;
+                squaredDistance = previousSquaredDistance;
+                checkSimplex = false;
+                break;
+            }
+#endif //
+            
+            
+            //redundant m_simplexSolver->compute_points(pointOnA, pointOnB);
+            
+            //are we getting any closer ?
+            if (previousSquaredDistance - squaredDistance <= SIMD_EPSILON * previousSquaredDistance)
+            {
+                //				m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
+                checkSimplex = true;
+                m_degenerateSimplex = 12;
+                
+                break;
+            }
+            
+            m_cachedSeparatingAxis = newCachedSeparatingAxis;
+            
+            //degeneracy, this is typically due to invalid/uninitialized worldtransforms for a btCollisionObject
+            if (m_curIter++ > gGjkMaxIter)
+            {
+#if defined(DEBUG) || defined (_DEBUG)
+                
+                printf("btGjkPairDetector maxIter exceeded:%i\n",m_curIter);
+                printf("sepAxis=(%f,%f,%f), squaredDistance = %f\n",
+                       m_cachedSeparatingAxis.getX(),
+                       m_cachedSeparatingAxis.getY(),
+                       m_cachedSeparatingAxis.getZ(),
+                       squaredDistance);
+#endif
+                
+                break;
+                
+            }
+            
+            
+            bool check = (!simplexSolver.fullSimplex());
+            //bool check = (!m_simplexSolver->fullSimplex() && squaredDistance > SIMD_EPSILON * m_simplexSolver->maxVertex());
+            
+            if (!check)
+            {
+                //do we need this backup_closest here ?
+                //				m_simplexSolver->backup_closest(m_cachedSeparatingAxis);
+                m_degenerateSimplex = 13;
+                break;
+            }
+        }
+        
+        if (checkSimplex)
+        {
+            simplexSolver.compute_points(pointOnA, pointOnB);
+            normalInB = m_cachedSeparatingAxis;
+            
+            btScalar lenSqr =m_cachedSeparatingAxis.length2();
+            
+            //valid normal
+            if (lenSqr < 0.0001)
+            {
+                m_degenerateSimplex = 5;
+            }
+            if (lenSqr > SIMD_EPSILON*SIMD_EPSILON)
+            {
+                btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
+                normalInB *= rlen; //normalize
+                
+                btScalar s = btSqrt(squaredDistance);
+                
+                btAssert(s > btScalar(0.0));
+                pointOnA -= m_cachedSeparatingAxis * (marginA / s);
+                pointOnB += m_cachedSeparatingAxis * (marginB / s);
+                distance = ((btScalar(1.)/rlen) - margin);
+                isValid = true;
+                
+                m_lastUsedMethod = 1;
+            } else
+            {
+                m_lastUsedMethod = 2;
+            }
+        }
+        
+        bool catchDegeneratePenetrationCase =
+        (m_catchDegeneracies &&  m_degenerateSimplex && ((distance+margin) < 0.01));
+        
+        //if (checkPenetration && !isValid)
+        if (checkPenetration && (!isValid || catchDegeneratePenetrationCase ))
+        {
+            //penetration case
+            
+            //if there is no way to handle penetrations, bail out
+            
+            // Penetration depth case.
+            btVector3 tmpPointOnA,tmpPointOnB;
+            
+            m_cachedSeparatingAxis.setZero();
+            
+            bool isValid2 = btGjkEpaCalcPenDepth(a,b,
+                                                 colDesc,
+                                                 m_cachedSeparatingAxis, tmpPointOnA, tmpPointOnB);
+            
+            if (isValid2)
+            {
+                btVector3 tmpNormalInB = tmpPointOnB-tmpPointOnA;
+                btScalar lenSqr = tmpNormalInB.length2();
+                if (lenSqr <= (SIMD_EPSILON*SIMD_EPSILON))
+                {
+                    tmpNormalInB = m_cachedSeparatingAxis;
+                    lenSqr = m_cachedSeparatingAxis.length2();
+                }
+                
+                if (lenSqr > (SIMD_EPSILON*SIMD_EPSILON))
+                {
+                    tmpNormalInB /= btSqrt(lenSqr);
+                    btScalar distance2 = -(tmpPointOnA-tmpPointOnB).length();
+                    //only replace valid penetrations when the result is deeper (check)
+                    if (!isValid || (distance2 < distance))
+                    {
+                        distance = distance2;
+                        pointOnA = tmpPointOnA;
+                        pointOnB = tmpPointOnB;
+                        normalInB = tmpNormalInB;
+                        
+                        isValid = true;
+                        m_lastUsedMethod = 3;
+                    } else
+                    {
+                        m_lastUsedMethod = 8;
+                    }
+                } else
+                {
+                    m_lastUsedMethod = 9;
+                }
+            } else
+                
+            {
+                ///this is another degenerate case, where the initial GJK calculation reports a degenerate case
+                ///EPA reports no penetration, and the second GJK (using the supporting vector without margin)
+                ///reports a valid positive distance. Use the results of the second GJK instead of failing.
+                ///thanks to Jacob.Langford for the reproduction case
+                ///http://code.google.com/p/bullet/issues/detail?id=250
+                
+                
+                if (m_cachedSeparatingAxis.length2() > btScalar(0.))
+                {
+                    btScalar distance2 = (tmpPointOnA-tmpPointOnB).length()-margin;
+                    //only replace valid distances when the distance is less
+                    if (!isValid || (distance2 < distance))
+                    {
+                        distance = distance2;
+                        pointOnA = tmpPointOnA;
+                        pointOnB = tmpPointOnB;
+                        pointOnA -= m_cachedSeparatingAxis * marginA ;
+                        pointOnB += m_cachedSeparatingAxis * marginB ;
+                        normalInB = m_cachedSeparatingAxis;
+                        normalInB.normalize();
+                        
+                        isValid = true;
+                        m_lastUsedMethod = 6;
+                    } else
+                    {
+                        m_lastUsedMethod = 5;
+                    }
+                }
+            }
+        }
+    }
+    
+    
+    
+    if (isValid && ((distance < 0) || (distance*distance < colDesc.m_maximumDistanceSquared)))
+    {
+        
+        m_cachedSeparatingAxis = normalInB;
+        m_cachedSeparatingDistance = distance;
+        distInfo->m_distance = distance;
+        distInfo->m_normalBtoA = normalInB;
+        distInfo->m_pointOnB = pointOnB;
+        distInfo->m_pointOnA = pointOnB+normalInB*distance;
+        return 0;
+    }
+    return -m_lastUsedMethod;
+}
+
+
+
+
+#endif //BT_GJK_EPA_PENETATION_CONVEX_COLLISION_H

+ 25 - 21
Engine/lib/bullet/src/BulletMultiThreaded/PpuAddressSpace.h → Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkCollisionDescription.h

@@ -1,6 +1,6 @@
 /*
 Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2010 Erwin Coumans  http://bulletphysics.org
+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.
@@ -14,24 +14,28 @@ subject to the following restrictions:
 */
 
 
-#ifndef BT_PPU_ADDRESS_SPACE_H
-#define BT_PPU_ADDRESS_SPACE_H
-
-
-#ifdef _WIN32
-//stop those casting warnings until we have a better solution for ppu_address_t / void* / uint64 conversions
-#pragma warning (disable: 4311)
-#pragma warning (disable: 4312)
-#endif //_WIN32
-
-
-#if defined(_WIN64)
-	typedef unsigned __int64 ppu_address_t;
-#elif defined(__LP64__) || defined(__x86_64__)
-	typedef uint64_t ppu_address_t;
-#else
-	typedef uint32_t ppu_address_t;
-#endif //defined(_WIN64)
-
-#endif //BT_PPU_ADDRESS_SPACE_H
+#ifndef GJK_COLLISION_DESCRIPTION_H
+#define GJK_COLLISION_DESCRIPTION_H
+
+#include "LinearMath/btVector3.h"
+
+struct btGjkCollisionDescription
+{
+    btVector3	m_firstDir;
+    int			m_maxGjkIterations;
+    btScalar	m_maximumDistanceSquared;
+    btScalar	m_gjkRelError2;
+    btGjkCollisionDescription()
+    :m_firstDir(0,1,0),
+    m_maxGjkIterations(1000),
+    m_maximumDistanceSquared(1e30f),
+    m_gjkRelError2(1.0e-6)
+    {
+    }
+    virtual ~btGjkCollisionDescription()
+    {
+    }
+};
+
+#endif //GJK_COLLISION_DESCRIPTION_H
 

+ 28 - 11
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp

@@ -41,21 +41,38 @@ namespace gjkepa2_impl
 
 	/* GJK	*/ 
 #define GJK_MAX_ITERATIONS	128
-#define GJK_ACCURARY		((btScalar)0.0001)
-#define GJK_MIN_DISTANCE	((btScalar)0.0001)
-#define GJK_DUPLICATED_EPS	((btScalar)0.0001)
+
+#ifdef BT_USE_DOUBLE_PRECISION
+	#define GJK_ACCURACY		((btScalar)1e-12)
+	#define GJK_MIN_DISTANCE	((btScalar)1e-12)
+	#define GJK_DUPLICATED_EPS	((btScalar)1e-12)
+#else
+	#define GJK_ACCURACY		((btScalar)0.0001)
+	#define GJK_MIN_DISTANCE	((btScalar)0.0001)
+	#define GJK_DUPLICATED_EPS	((btScalar)0.0001)
+#endif //BT_USE_DOUBLE_PRECISION
+
+
 #define GJK_SIMPLEX2_EPS	((btScalar)0.0)
 #define GJK_SIMPLEX3_EPS	((btScalar)0.0)
 #define GJK_SIMPLEX4_EPS	((btScalar)0.0)
 
 	/* EPA	*/ 
-#define EPA_MAX_VERTICES	64
-#define EPA_MAX_FACES		(EPA_MAX_VERTICES*2)
+#define EPA_MAX_VERTICES	128
 #define EPA_MAX_ITERATIONS	255
-#define EPA_ACCURACY		((btScalar)0.0001)
-#define EPA_FALLBACK		(10*EPA_ACCURACY)
-#define EPA_PLANE_EPS		((btScalar)0.00001)
-#define EPA_INSIDE_EPS		((btScalar)0.01)
+
+#ifdef BT_USE_DOUBLE_PRECISION
+	#define EPA_ACCURACY		((btScalar)1e-12)
+	#define EPA_PLANE_EPS		((btScalar)1e-14)
+	#define EPA_INSIDE_EPS		((btScalar)1e-9)
+#else
+	#define EPA_ACCURACY		((btScalar)0.0001)
+	#define EPA_PLANE_EPS		((btScalar)0.00001)
+	#define EPA_INSIDE_EPS		((btScalar)0.01)
+#endif
+
+#define EPA_FALLBACK            (10*EPA_ACCURACY)
+#define EPA_MAX_FACES           (EPA_MAX_VERTICES*2)
 
 
 	// Shorthands
@@ -242,7 +259,7 @@ namespace gjkepa2_impl
 					/* Check for termination				*/ 
 					const btScalar	omega=btDot(m_ray,w)/rl;
 					alpha=btMax(omega,alpha);
-					if(((rl-alpha)-(GJK_ACCURARY*rl))<=0)
+					if(((rl-alpha)-(GJK_ACCURACY*rl))<=0)
 					{/* Return old simplex				*/ 
 						removevertice(m_simplices[m_current]);
 						break;
@@ -1015,7 +1032,7 @@ bool	btGjkEpaSolver2::SignedDistance(const btConvexShape*	shape0,
 /* Symbols cleanup		*/ 
 
 #undef GJK_MAX_ITERATIONS
-#undef GJK_ACCURARY
+#undef GJK_ACCURACY
 #undef GJK_MIN_DISTANCE
 #undef GJK_DUPLICATED_EPS
 #undef GJK_SIMPLEX2_EPS

+ 1035 - 0
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkEpa3.h

@@ -0,0 +1,1035 @@
+/*
+Bullet Continuous Collision Detection and Physics Library
+Copyright (c) 2003-2014 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.
+*/
+
+/*
+Initial GJK-EPA collision solver by Nathanael Presson, 2008
+Improvements and refactoring by Erwin Coumans, 2008-2014
+*/
+#ifndef BT_GJK_EPA3_H
+#define BT_GJK_EPA3_H
+
+#include "LinearMath/btTransform.h"
+#include "btGjkCollisionDescription.h"
+
+
+
+struct	btGjkEpaSolver3
+{
+struct	sResults
+	{
+	enum eStatus
+		{
+		Separated,		/* Shapes doesnt penetrate												*/ 
+		Penetrating,	/* Shapes are penetrating												*/ 
+		GJK_Failed,		/* GJK phase fail, no big issue, shapes are probably just 'touching'	*/ 
+		EPA_Failed		/* EPA phase fail, bigger problem, need to save parameters, and debug	*/ 
+		}		status;
+	btVector3	witnesses[2];
+	btVector3	normal;
+	btScalar	distance;
+	};
+
+
+};
+
+
+
+#if defined(DEBUG) || defined (_DEBUG)
+#include <stdio.h> //for debug printf
+#ifdef __SPU__
+#include <spu_printf.h>
+#define printf spu_printf
+#endif //__SPU__
+#endif
+
+
+    
+    // Config
+    
+    /* GJK	*/
+#define GJK_MAX_ITERATIONS	128
+#define GJK_ACCURARY		((btScalar)0.0001)
+#define GJK_MIN_DISTANCE	((btScalar)0.0001)
+#define GJK_DUPLICATED_EPS	((btScalar)0.0001)
+#define GJK_SIMPLEX2_EPS	((btScalar)0.0)
+#define GJK_SIMPLEX3_EPS	((btScalar)0.0)
+#define GJK_SIMPLEX4_EPS	((btScalar)0.0)
+    
+    /* EPA	*/
+#define EPA_MAX_VERTICES	64
+#define EPA_MAX_FACES		(EPA_MAX_VERTICES*2)
+#define EPA_MAX_ITERATIONS	255
+#define EPA_ACCURACY		((btScalar)0.0001)
+#define EPA_FALLBACK		(10*EPA_ACCURACY)
+#define EPA_PLANE_EPS		((btScalar)0.00001)
+#define EPA_INSIDE_EPS		((btScalar)0.01)
+    
+    
+    // Shorthands
+    typedef unsigned int	U;
+    typedef unsigned char	U1;
+    
+    // MinkowskiDiff
+    template <typename btConvexTemplate>
+    struct	MinkowskiDiff
+    {
+        const btConvexTemplate* m_convexAPtr;
+        const btConvexTemplate* m_convexBPtr;
+        
+        btMatrix3x3				m_toshape1;
+        btTransform				m_toshape0;
+        
+        bool					m_enableMargin;
+        
+        
+        MinkowskiDiff(const btConvexTemplate& a, const btConvexTemplate& b)
+        :m_convexAPtr(&a),
+        m_convexBPtr(&b)
+        {
+        }
+        
+        void					EnableMargin(bool enable)
+        {
+            m_enableMargin = enable;
+        }
+        inline btVector3		Support0(const btVector3& d) const
+        {
+            return m_convexAPtr->getLocalSupportWithMargin(d);
+        }
+        inline btVector3		Support1(const btVector3& d) const
+        {
+            return m_toshape0*m_convexBPtr->getLocalSupportWithMargin(m_toshape1*d);
+        }
+        
+        
+        inline btVector3		Support(const btVector3& d) const
+        {
+            return(Support0(d)-Support1(-d));
+        }
+        btVector3				Support(const btVector3& d,U index) const
+        {
+            if(index)
+                return(Support1(d));
+            else
+                return(Support0(d));
+        }
+    };
+    
+enum	eGjkStatus
+{
+    eGjkValid,
+    eGjkInside,
+    eGjkFailed
+};
+
+    // GJK
+    template <typename btConvexTemplate>
+    struct	GJK
+    {
+        /* Types		*/
+        struct	sSV
+        {
+            btVector3	d,w;
+        };
+        struct	sSimplex
+        {
+            sSV*		c[4];
+            btScalar	p[4];
+            U			rank;
+        };
+        
+        /* Fields		*/
+        
+        MinkowskiDiff<btConvexTemplate>			m_shape;
+        btVector3		m_ray;
+        btScalar		m_distance;
+        sSimplex		m_simplices[2];
+        sSV				m_store[4];
+        sSV*			m_free[4];
+        U				m_nfree;
+        U				m_current;
+        sSimplex*		m_simplex;
+        eGjkStatus      m_status;
+        /* Methods		*/
+        
+        GJK(const btConvexTemplate& a, const btConvexTemplate& b)
+        :m_shape(a,b)
+        {
+            Initialize();
+        }
+        void				Initialize()
+        {
+            m_ray		=	btVector3(0,0,0);
+            m_nfree		=	0;
+            m_status	=	eGjkFailed;
+            m_current	=	0;
+            m_distance	=	0;
+        }
+        eGjkStatus			Evaluate(const MinkowskiDiff<btConvexTemplate>& shapearg,const btVector3& guess)
+        {
+            U			iterations=0;
+            btScalar	sqdist=0;
+            btScalar	alpha=0;
+            btVector3	lastw[4];
+            U			clastw=0;
+            /* Initialize solver		*/
+            m_free[0]			=	&m_store[0];
+            m_free[1]			=	&m_store[1];
+            m_free[2]			=	&m_store[2];
+            m_free[3]			=	&m_store[3];
+            m_nfree				=	4;
+            m_current			=	0;
+            m_status			=	eGjkValid;
+            m_shape				=	shapearg;
+            m_distance			=	0;
+            /* Initialize simplex		*/
+            m_simplices[0].rank	=	0;
+            m_ray				=	guess;
+            const btScalar	sqrl=	m_ray.length2();
+            appendvertice(m_simplices[0],sqrl>0?-m_ray:btVector3(1,0,0));
+            m_simplices[0].p[0]	=	1;
+            m_ray				=	m_simplices[0].c[0]->w;
+            sqdist				=	sqrl;
+            lastw[0]			=
+            lastw[1]			=
+            lastw[2]			=
+            lastw[3]			=	m_ray;
+            /* Loop						*/
+            do	{
+                const U		next=1-m_current;
+                sSimplex&	cs=m_simplices[m_current];
+                sSimplex&	ns=m_simplices[next];
+                /* Check zero							*/
+                const btScalar	rl=m_ray.length();
+                if(rl<GJK_MIN_DISTANCE)
+                {/* Touching or inside				*/
+                    m_status=eGjkInside;
+                    break;
+                }
+                /* Append new vertice in -'v' direction	*/
+                appendvertice(cs,-m_ray);
+                const btVector3&	w=cs.c[cs.rank-1]->w;
+                bool				found=false;
+                for(U i=0;i<4;++i)
+                {
+                    if((w-lastw[i]).length2()<GJK_DUPLICATED_EPS)
+                    { found=true;break; }
+                }
+                if(found)
+                {/* Return old simplex				*/
+                    removevertice(m_simplices[m_current]);
+                    break;
+                }
+                else
+                {/* Update lastw					*/
+                    lastw[clastw=(clastw+1)&3]=w;
+                }
+                /* Check for termination				*/
+                const btScalar	omega=btDot(m_ray,w)/rl;
+                alpha=btMax(omega,alpha);
+                if(((rl-alpha)-(GJK_ACCURARY*rl))<=0)
+                {/* Return old simplex				*/
+                    removevertice(m_simplices[m_current]);
+                    break;
+                }
+                /* Reduce simplex						*/
+                btScalar	weights[4];
+                U			mask=0;
+                switch(cs.rank)
+                {
+                    case	2:	sqdist=projectorigin(	cs.c[0]->w,
+                                                     cs.c[1]->w,
+                                                     weights,mask);break;
+                    case	3:	sqdist=projectorigin(	cs.c[0]->w,
+                                                     cs.c[1]->w,
+                                                     cs.c[2]->w,
+                                                     weights,mask);break;
+                    case	4:	sqdist=projectorigin(	cs.c[0]->w,
+                                                     cs.c[1]->w,
+                                                     cs.c[2]->w,
+                                                     cs.c[3]->w,
+                                                     weights,mask);break;
+                }
+                if(sqdist>=0)
+                {/* Valid	*/
+                    ns.rank		=	0;
+                    m_ray		=	btVector3(0,0,0);
+                    m_current	=	next;
+                    for(U i=0,ni=cs.rank;i<ni;++i)
+                    {
+                        if(mask&(1<<i))
+                        {
+                            ns.c[ns.rank]		=	cs.c[i];
+                            ns.p[ns.rank++]		=	weights[i];
+                            m_ray				+=	cs.c[i]->w*weights[i];
+                        }
+                        else
+                        {
+                            m_free[m_nfree++]	=	cs.c[i];
+                        }
+                    }
+                    if(mask==15) m_status=eGjkInside;
+                }
+                else
+                {/* Return old simplex				*/
+                    removevertice(m_simplices[m_current]);
+                    break;
+                }
+                m_status=((++iterations)<GJK_MAX_ITERATIONS)?m_status:eGjkFailed;
+            } while(m_status==eGjkValid);
+            m_simplex=&m_simplices[m_current];
+            switch(m_status)
+            {
+                case	eGjkValid:		m_distance=m_ray.length();break;
+                case	eGjkInside:	m_distance=0;break;
+                default:
+                {
+                }
+            }
+            return(m_status);
+        }
+        bool					EncloseOrigin()
+        {
+            switch(m_simplex->rank)
+            {
+                case	1:
+                {
+                    for(U i=0;i<3;++i)
+                    {
+                        btVector3		axis=btVector3(0,0,0);
+                        axis[i]=1;
+                        appendvertice(*m_simplex, axis);
+                        if(EncloseOrigin())	return(true);
+                        removevertice(*m_simplex);
+                        appendvertice(*m_simplex,-axis);
+                        if(EncloseOrigin())	return(true);
+                        removevertice(*m_simplex);
+                    }
+                }
+                    break;
+                case	2:
+                {
+                    const btVector3	d=m_simplex->c[1]->w-m_simplex->c[0]->w;
+                    for(U i=0;i<3;++i)
+                    {
+                        btVector3		axis=btVector3(0,0,0);
+                        axis[i]=1;
+                        const btVector3	p=btCross(d,axis);
+                        if(p.length2()>0)
+                        {
+                            appendvertice(*m_simplex, p);
+                            if(EncloseOrigin())	return(true);
+                            removevertice(*m_simplex);
+                            appendvertice(*m_simplex,-p);
+                            if(EncloseOrigin())	return(true);
+                            removevertice(*m_simplex);
+                        }
+                    }
+                }
+                    break;
+                case	3:
+                {
+                    const btVector3	n=btCross(m_simplex->c[1]->w-m_simplex->c[0]->w,
+                                              m_simplex->c[2]->w-m_simplex->c[0]->w);
+                    if(n.length2()>0)
+                    {
+                        appendvertice(*m_simplex,n);
+                        if(EncloseOrigin())	return(true);
+                        removevertice(*m_simplex);
+                        appendvertice(*m_simplex,-n);
+                        if(EncloseOrigin())	return(true);
+                        removevertice(*m_simplex);
+                    }
+                }
+                    break;
+                case	4:
+                {
+                    if(btFabs(det(	m_simplex->c[0]->w-m_simplex->c[3]->w,
+                                  m_simplex->c[1]->w-m_simplex->c[3]->w,
+                                  m_simplex->c[2]->w-m_simplex->c[3]->w))>0)
+                        return(true);
+                }
+                    break;
+            }
+            return(false);
+        }
+        /* Internals	*/
+        void				getsupport(const btVector3& d,sSV& sv) const
+        {
+            sv.d	=	d/d.length();
+            sv.w	=	m_shape.Support(sv.d);
+        }
+        void				removevertice(sSimplex& simplex)
+        {
+            m_free[m_nfree++]=simplex.c[--simplex.rank];
+        }
+        void				appendvertice(sSimplex& simplex,const btVector3& v)
+        {
+            simplex.p[simplex.rank]=0;
+            simplex.c[simplex.rank]=m_free[--m_nfree];
+            getsupport(v,*simplex.c[simplex.rank++]);
+        }
+        static btScalar		det(const btVector3& a,const btVector3& b,const btVector3& c)
+        {
+            return(	a.y()*b.z()*c.x()+a.z()*b.x()*c.y()-
+                   a.x()*b.z()*c.y()-a.y()*b.x()*c.z()+
+                   a.x()*b.y()*c.z()-a.z()*b.y()*c.x());
+        }
+        static btScalar		projectorigin(	const btVector3& a,
+                                          const btVector3& b,
+                                          btScalar* w,U& m)
+        {
+            const btVector3	d=b-a;
+            const btScalar	l=d.length2();
+            if(l>GJK_SIMPLEX2_EPS)
+            {
+                const btScalar	t(l>0?-btDot(a,d)/l:0);
+                if(t>=1)		{ w[0]=0;w[1]=1;m=2;return(b.length2()); }
+                else if(t<=0)	{ w[0]=1;w[1]=0;m=1;return(a.length2()); }
+                else			{ w[0]=1-(w[1]=t);m=3;return((a+d*t).length2()); }
+            }
+            return(-1);
+        }
+        static btScalar		projectorigin(	const btVector3& a,
+                                          const btVector3& b,
+                                          const btVector3& c,
+                                          btScalar* w,U& m)
+        {
+            static const U		imd3[]={1,2,0};
+            const btVector3*	vt[]={&a,&b,&c};
+            const btVector3		dl[]={a-b,b-c,c-a};
+            const btVector3		n=btCross(dl[0],dl[1]);
+            const btScalar		l=n.length2();
+            if(l>GJK_SIMPLEX3_EPS)
+            {
+                btScalar	mindist=-1;
+                btScalar	subw[2]={0.f,0.f};
+                U			subm(0);
+                for(U i=0;i<3;++i)
+                {
+                    if(btDot(*vt[i],btCross(dl[i],n))>0)
+                    {
+                        const U			j=imd3[i];
+                        const btScalar	subd(projectorigin(*vt[i],*vt[j],subw,subm));
+                        if((mindist<0)||(subd<mindist))
+                        {
+                            mindist		=	subd;
+                            m			=	static_cast<U>(((subm&1)?1<<i:0)+((subm&2)?1<<j:0));
+                            w[i]		=	subw[0];
+                            w[j]		=	subw[1];
+                            w[imd3[j]]	=	0;
+                        }
+                    }
+                }
+                if(mindist<0)
+                {
+                    const btScalar	d=btDot(a,n);
+                    const btScalar	s=btSqrt(l);
+                    const btVector3	p=n*(d/l);
+                    mindist	=	p.length2();
+                    m		=	7;
+                    w[0]	=	(btCross(dl[1],b-p)).length()/s;
+                    w[1]	=	(btCross(dl[2],c-p)).length()/s;
+                    w[2]	=	1-(w[0]+w[1]);
+                }
+                return(mindist);
+            }
+            return(-1);
+        }
+        static btScalar		projectorigin(	const btVector3& a,
+                                          const btVector3& b,
+                                          const btVector3& c,
+                                          const btVector3& d,
+                                          btScalar* w,U& m)
+        {
+            static const U		imd3[]={1,2,0};
+            const btVector3*	vt[]={&a,&b,&c,&d};
+            const btVector3		dl[]={a-d,b-d,c-d};
+            const btScalar		vl=det(dl[0],dl[1],dl[2]);
+            const bool			ng=(vl*btDot(a,btCross(b-c,a-b)))<=0;
+            if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS))
+            {
+                btScalar	mindist=-1;
+                btScalar	subw[3]={0.f,0.f,0.f};
+                U			subm(0);
+                for(U i=0;i<3;++i)
+                {
+                    const U			j=imd3[i];
+                    const btScalar	s=vl*btDot(d,btCross(dl[i],dl[j]));
+                    if(s>0)
+                    {
+                        const btScalar	subd=projectorigin(*vt[i],*vt[j],d,subw,subm);
+                        if((mindist<0)||(subd<mindist))
+                        {
+                            mindist		=	subd;
+                            m			=	static_cast<U>((subm&1?1<<i:0)+
+                                                           (subm&2?1<<j:0)+
+                                                           (subm&4?8:0));
+                            w[i]		=	subw[0];
+                            w[j]		=	subw[1];
+                            w[imd3[j]]	=	0;
+                            w[3]		=	subw[2];
+                        }
+                    }
+                }
+                if(mindist<0)
+                {
+                    mindist	=	0;
+                    m		=	15;
+                    w[0]	=	det(c,b,d)/vl;
+                    w[1]	=	det(a,c,d)/vl;
+                    w[2]	=	det(b,a,d)/vl;
+                    w[3]	=	1-(w[0]+w[1]+w[2]);
+                }
+                return(mindist);
+            }
+            return(-1);
+        }
+    };
+
+
+enum	eEpaStatus
+{
+    eEpaValid,
+    eEpaTouching,
+    eEpaDegenerated,
+    eEpaNonConvex,
+    eEpaInvalidHull,
+    eEpaOutOfFaces,
+    eEpaOutOfVertices,
+    eEpaAccuraryReached,
+    eEpaFallBack,
+    eEpaFailed
+};
+
+
+    // EPA
+template <typename btConvexTemplate>
+    struct	EPA
+    {
+        /* Types		*/
+       
+        struct	sFace
+        {
+            btVector3	n;
+            btScalar	d;
+            typename GJK<btConvexTemplate>::sSV*		c[3];
+            sFace*		f[3];
+            sFace*		l[2];
+            U1			e[3];
+            U1			pass;
+        };
+        struct	sList
+        {
+            sFace*		root;
+            U			count;
+            sList() : root(0),count(0)	{}
+        };
+        struct	sHorizon
+        {
+            sFace*		cf;
+            sFace*		ff;
+            U			nf;
+            sHorizon() : cf(0),ff(0),nf(0)	{}
+        };
+       
+        /* Fields		*/
+        eEpaStatus		m_status;
+        typename GJK<btConvexTemplate>::sSimplex	m_result;
+        btVector3		m_normal;
+        btScalar		m_depth;
+        typename GJK<btConvexTemplate>::sSV				m_sv_store[EPA_MAX_VERTICES];
+        sFace			m_fc_store[EPA_MAX_FACES];
+        U				m_nextsv;
+        sList			m_hull;
+        sList			m_stock;
+        /* Methods		*/
+        EPA()
+        {
+            Initialize();
+        }
+        
+        
+        static inline void		bind(sFace* fa,U ea,sFace* fb,U eb)
+        {
+            fa->e[ea]=(U1)eb;fa->f[ea]=fb;
+            fb->e[eb]=(U1)ea;fb->f[eb]=fa;
+        }
+        static inline void		append(sList& list,sFace* face)
+        {
+            face->l[0]	=	0;
+            face->l[1]	=	list.root;
+            if(list.root) list.root->l[0]=face;
+            list.root	=	face;
+            ++list.count;
+        }
+        static inline void		remove(sList& list,sFace* face)
+        {
+            if(face->l[1]) face->l[1]->l[0]=face->l[0];
+            if(face->l[0]) face->l[0]->l[1]=face->l[1];
+            if(face==list.root) list.root=face->l[1];
+            --list.count;
+        }
+        
+        
+        void				Initialize()
+        {
+            m_status	=	eEpaFailed;
+            m_normal	=	btVector3(0,0,0);
+            m_depth		=	0;
+            m_nextsv	=	0;
+            for(U i=0;i<EPA_MAX_FACES;++i)
+            {
+                append(m_stock,&m_fc_store[EPA_MAX_FACES-i-1]);
+            }
+        }
+        eEpaStatus			Evaluate(GJK<btConvexTemplate>& gjk,const btVector3& guess)
+        {
+            typename GJK<btConvexTemplate>::sSimplex&	simplex=*gjk.m_simplex;
+            if((simplex.rank>1)&&gjk.EncloseOrigin())
+            {
+                
+                /* Clean up				*/
+                while(m_hull.root)
+                {
+                    sFace*	f = m_hull.root;
+                    remove(m_hull,f);
+                    append(m_stock,f);
+                }
+                m_status	=	eEpaValid;
+                m_nextsv	=	0;
+                /* Orient simplex		*/
+                if(gjk.det(	simplex.c[0]->w-simplex.c[3]->w,
+                           simplex.c[1]->w-simplex.c[3]->w,
+                           simplex.c[2]->w-simplex.c[3]->w)<0)
+                {
+                    btSwap(simplex.c[0],simplex.c[1]);
+                    btSwap(simplex.p[0],simplex.p[1]);
+                }
+                /* Build initial hull	*/
+                sFace*	tetra[]={newface(simplex.c[0],simplex.c[1],simplex.c[2],true),
+                    newface(simplex.c[1],simplex.c[0],simplex.c[3],true),
+                    newface(simplex.c[2],simplex.c[1],simplex.c[3],true),
+                    newface(simplex.c[0],simplex.c[2],simplex.c[3],true)};
+                if(m_hull.count==4)
+                {
+                    sFace*		best=findbest();
+                    sFace		outer=*best;
+                    U			pass=0;
+                    U			iterations=0;
+                    bind(tetra[0],0,tetra[1],0);
+                    bind(tetra[0],1,tetra[2],0);
+                    bind(tetra[0],2,tetra[3],0);
+                    bind(tetra[1],1,tetra[3],2);
+                    bind(tetra[1],2,tetra[2],1);
+                    bind(tetra[2],2,tetra[3],1);
+                    m_status=eEpaValid;
+                    for(;iterations<EPA_MAX_ITERATIONS;++iterations)
+                    {
+                        if(m_nextsv<EPA_MAX_VERTICES)
+                        {
+                            sHorizon		horizon;
+                            typename GJK<btConvexTemplate>::sSV*			w=&m_sv_store[m_nextsv++];
+                            bool			valid=true;
+                            best->pass	=	(U1)(++pass);
+                            gjk.getsupport(best->n,*w);
+                            const btScalar	wdist=btDot(best->n,w->w)-best->d;
+                            if(wdist>EPA_ACCURACY)
+                            {
+                                for(U j=0;(j<3)&&valid;++j)
+                                {
+                                    valid&=expand(	pass,w,
+                                                  best->f[j],best->e[j],
+                                                  horizon);
+                                }
+                                if(valid&&(horizon.nf>=3))
+                                {
+                                    bind(horizon.cf,1,horizon.ff,2);
+                                    remove(m_hull,best);
+                                    append(m_stock,best);
+                                    best=findbest();
+                                    outer=*best;
+                                } else { m_status=eEpaInvalidHull;break; }
+                            } else { m_status=eEpaAccuraryReached;break; }
+                        } else { m_status=eEpaOutOfVertices;break; }
+                    }
+                    const btVector3	projection=outer.n*outer.d;
+                    m_normal	=	outer.n;
+                    m_depth		=	outer.d;
+                    m_result.rank	=	3;
+                    m_result.c[0]	=	outer.c[0];
+                    m_result.c[1]	=	outer.c[1];
+                    m_result.c[2]	=	outer.c[2];
+                    m_result.p[0]	=	btCross(	outer.c[1]->w-projection,
+                                                outer.c[2]->w-projection).length();
+                    m_result.p[1]	=	btCross(	outer.c[2]->w-projection,
+                                                outer.c[0]->w-projection).length();
+                    m_result.p[2]	=	btCross(	outer.c[0]->w-projection,
+                                                outer.c[1]->w-projection).length();
+                    const btScalar	sum=m_result.p[0]+m_result.p[1]+m_result.p[2];
+                    m_result.p[0]	/=	sum;
+                    m_result.p[1]	/=	sum;
+                    m_result.p[2]	/=	sum;
+                    return(m_status);
+                }
+            }
+            /* Fallback		*/
+            m_status	=	eEpaFallBack;
+            m_normal	=	-guess;
+            const btScalar	nl=m_normal.length();
+            if(nl>0)
+                m_normal	=	m_normal/nl;
+            else
+                m_normal	=	btVector3(1,0,0);
+            m_depth	=	0;
+            m_result.rank=1;
+            m_result.c[0]=simplex.c[0];
+            m_result.p[0]=1;
+            return(m_status);
+        }
+        bool getedgedist(sFace* face, typename GJK<btConvexTemplate>::sSV* a, typename GJK<btConvexTemplate>::sSV* b, btScalar& dist)
+        {
+            const btVector3 ba = b->w - a->w;
+            const btVector3 n_ab = btCross(ba, face->n); // Outward facing edge normal direction, on triangle plane
+            const btScalar a_dot_nab = btDot(a->w, n_ab); // Only care about the sign to determine inside/outside, so not normalization required
+            
+            if(a_dot_nab < 0)
+            {
+                // Outside of edge a->b
+                
+                const btScalar ba_l2 = ba.length2();
+                const btScalar a_dot_ba = btDot(a->w, ba);
+                const btScalar b_dot_ba = btDot(b->w, ba);
+                
+                if(a_dot_ba > 0)
+                {
+                    // Pick distance vertex a
+                    dist = a->w.length();
+                }
+                else if(b_dot_ba < 0)
+                {
+                    // Pick distance vertex b
+                    dist = b->w.length();
+                }
+                else
+                {
+                    // Pick distance to edge a->b
+                    const btScalar a_dot_b = btDot(a->w, b->w);
+                    dist = btSqrt(btMax((a->w.length2() * b->w.length2() - a_dot_b * a_dot_b) / ba_l2, (btScalar)0));
+                }
+                
+                return true;
+            }
+            
+            return false;
+        }
+        sFace*				newface(typename GJK<btConvexTemplate>::sSV* a,typename GJK<btConvexTemplate>::sSV* b,typename GJK<btConvexTemplate>::sSV* c,bool forced)
+        {
+            if(m_stock.root)
+            {
+                sFace*	face=m_stock.root;
+                remove(m_stock,face);
+                append(m_hull,face);
+                face->pass	=	0;
+                face->c[0]	=	a;
+                face->c[1]	=	b;
+                face->c[2]	=	c;
+                face->n		=	btCross(b->w-a->w,c->w-a->w);
+                const btScalar	l=face->n.length();
+                const bool		v=l>EPA_ACCURACY;
+                
+                if(v)
+                {
+                    if(!(getedgedist(face, a, b, face->d) ||
+                         getedgedist(face, b, c, face->d) ||
+                         getedgedist(face, c, a, face->d)))
+                    {
+                        // Origin projects to the interior of the triangle
+                        // Use distance to triangle plane
+                        face->d = btDot(a->w, face->n) / l;
+                    }
+                    
+                    face->n /= l;
+                    if(forced || (face->d >= -EPA_PLANE_EPS))
+                    {
+                        return face;
+                    }
+                    else
+                        m_status=eEpaNonConvex;
+                }
+                else
+                    m_status=eEpaDegenerated;
+                
+                remove(m_hull, face);
+                append(m_stock, face);
+                return 0;
+                
+            }
+            m_status = m_stock.root ? eEpaOutOfVertices : eEpaOutOfFaces;
+            return 0;
+        }
+        sFace*				findbest()
+        {
+            sFace*		minf=m_hull.root;
+            btScalar	mind=minf->d*minf->d;
+            for(sFace* f=minf->l[1];f;f=f->l[1])
+            {
+                const btScalar	sqd=f->d*f->d;
+                if(sqd<mind)
+                {
+                    minf=f;
+                    mind=sqd;
+                }
+            }
+            return(minf);
+        }
+        bool				expand(U pass,typename GJK<btConvexTemplate>::sSV* w,sFace* f,U e,sHorizon& horizon)
+        {
+            static const U	i1m3[]={1,2,0};
+            static const U	i2m3[]={2,0,1};
+            if(f->pass!=pass)
+            {
+                const U	e1=i1m3[e];
+                if((btDot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)
+                {
+                    sFace*	nf=newface(f->c[e1],f->c[e],w,false);
+                    if(nf)
+                    {
+                        bind(nf,0,f,e);
+                        if(horizon.cf) bind(horizon.cf,1,nf,2); else horizon.ff=nf;
+                        horizon.cf=nf;
+                        ++horizon.nf;
+                        return(true);
+                    }
+                }
+                else
+                {
+                    const U	e2=i2m3[e];
+                    f->pass		=	(U1)pass;
+                    if(	expand(pass,w,f->f[e1],f->e[e1],horizon)&&
+                       expand(pass,w,f->f[e2],f->e[e2],horizon))
+                    {
+                        remove(m_hull,f);
+                        append(m_stock,f);
+                        return(true);
+                    }
+                }
+            }
+            return(false);
+        }
+        
+    };
+    
+    template <typename btConvexTemplate>
+    static void	Initialize(	const btConvexTemplate& a, const btConvexTemplate& b,
+                           btGjkEpaSolver3::sResults& results,
+                           MinkowskiDiff<btConvexTemplate>& shape)
+    {
+        /* Results		*/ 
+        results.witnesses[0]	=
+        results.witnesses[1]	=	btVector3(0,0,0);
+        results.status			=	btGjkEpaSolver3::sResults::Separated;
+        /* Shape		*/ 
+       
+        shape.m_toshape1		=	b.getWorldTransform().getBasis().transposeTimes(a.getWorldTransform().getBasis());
+        shape.m_toshape0		=	a.getWorldTransform().inverseTimes(b.getWorldTransform());
+        
+    }
+    
+
+//
+// Api
+//
+
+
+
+//
+template <typename btConvexTemplate>
+bool		btGjkEpaSolver3_Distance(const btConvexTemplate& a, const btConvexTemplate& b,
+                                      const btVector3& guess,
+                                      btGjkEpaSolver3::sResults& results)
+{
+    MinkowskiDiff<btConvexTemplate>			shape(a,b);
+    Initialize(a,b,results,shape);
+    GJK<btConvexTemplate>				gjk(a,b);
+    eGjkStatus	gjk_status=gjk.Evaluate(shape,guess);
+    if(gjk_status==eGjkValid)
+    {
+        btVector3	w0=btVector3(0,0,0);
+        btVector3	w1=btVector3(0,0,0);
+        for(U i=0;i<gjk.m_simplex->rank;++i)
+        {
+            const btScalar	p=gjk.m_simplex->p[i];
+            w0+=shape.Support( gjk.m_simplex->c[i]->d,0)*p;
+            w1+=shape.Support(-gjk.m_simplex->c[i]->d,1)*p;
+        }
+        results.witnesses[0]	=	a.getWorldTransform()*w0;
+        results.witnesses[1]	=	a.getWorldTransform()*w1;
+        results.normal			=	w0-w1;
+        results.distance		=	results.normal.length();
+        results.normal			/=	results.distance>GJK_MIN_DISTANCE?results.distance:1;
+        return(true);
+    }
+    else
+    {
+        results.status	=	gjk_status==eGjkInside?
+        btGjkEpaSolver3::sResults::Penetrating	:
+        btGjkEpaSolver3::sResults::GJK_Failed	;
+        return(false);
+    }
+}
+
+
+template <typename btConvexTemplate>
+bool	btGjkEpaSolver3_Penetration(const btConvexTemplate& a,
+                                     const btConvexTemplate& b,
+                                     const btVector3& guess,
+                                     btGjkEpaSolver3::sResults& results)
+{
+    MinkowskiDiff<btConvexTemplate>			shape(a,b);
+    Initialize(a,b,results,shape);
+    GJK<btConvexTemplate>				gjk(a,b);
+    eGjkStatus	gjk_status=gjk.Evaluate(shape,-guess);
+    switch(gjk_status)
+    {
+        case	eGjkInside:
+        {
+            EPA<btConvexTemplate>				epa;
+            eEpaStatus	epa_status=epa.Evaluate(gjk,-guess);
+            if(epa_status!=eEpaFailed)
+            {
+                btVector3	w0=btVector3(0,0,0);
+                for(U i=0;i<epa.m_result.rank;++i)
+                {
+                    w0+=shape.Support(epa.m_result.c[i]->d,0)*epa.m_result.p[i];
+                }
+                results.status			=	btGjkEpaSolver3::sResults::Penetrating;
+                results.witnesses[0]	=	a.getWorldTransform()*w0;
+                results.witnesses[1]	=	a.getWorldTransform()*(w0-epa.m_normal*epa.m_depth);
+                results.normal			=	-epa.m_normal;
+                results.distance		=	-epa.m_depth;
+                return(true);
+            } else results.status=btGjkEpaSolver3::sResults::EPA_Failed;
+        }
+            break;
+        case	eGjkFailed:
+            results.status=btGjkEpaSolver3::sResults::GJK_Failed;
+            break;
+        default:
+        {
+        }
+    }
+    return(false);
+}
+
+#if 0
+int	btComputeGjkEpaPenetration2(const btCollisionDescription& colDesc, btDistanceInfo* distInfo)
+{
+    btGjkEpaSolver3::sResults results;
+    btVector3 guess = colDesc.m_firstDir;
+    
+    bool res = btGjkEpaSolver3::Penetration(colDesc.m_objA,colDesc.m_objB,
+                                            colDesc.m_transformA,colDesc.m_transformB,
+                                            colDesc.m_localSupportFuncA,colDesc.m_localSupportFuncB,
+                                            guess,
+                                            results);
+    if (res)
+    {
+        if ((results.status==btGjkEpaSolver3::sResults::Penetrating) || results.status==GJK::eStatus::Inside)
+        {
+            //normal could be 'swapped'
+            
+            distInfo->m_distance = results.distance;
+            distInfo->m_normalBtoA = results.normal;
+            btVector3 tmpNormalInB = results.witnesses[1]-results.witnesses[0];
+            btScalar lenSqr = tmpNormalInB.length2();
+            if (lenSqr <= (SIMD_EPSILON*SIMD_EPSILON))
+            {
+                tmpNormalInB = results.normal;
+                lenSqr = results.normal.length2();
+            }
+            
+            if (lenSqr > (SIMD_EPSILON*SIMD_EPSILON))
+            {
+                tmpNormalInB /= btSqrt(lenSqr);
+                btScalar distance2 = -(results.witnesses[0]-results.witnesses[1]).length();
+                //only replace valid penetrations when the result is deeper (check)
+                //if ((distance2 < results.distance))
+                {
+                    distInfo->m_distance = distance2;
+                    distInfo->m_pointOnA= results.witnesses[0];
+                    distInfo->m_pointOnB= results.witnesses[1];
+                    distInfo->m_normalBtoA= tmpNormalInB;
+                    return 0;
+                }
+            }
+        }
+        
+    }
+    
+    return -1;
+}
+#endif
+
+template <typename btConvexTemplate, typename btDistanceInfoTemplate>
+int	btComputeGjkDistance(const btConvexTemplate& a, const btConvexTemplate& b,
+                         const btGjkCollisionDescription& colDesc, btDistanceInfoTemplate* distInfo)
+{
+    btGjkEpaSolver3::sResults results;
+    btVector3 guess = colDesc.m_firstDir;
+    
+    bool isSeparated = btGjkEpaSolver3_Distance(	a,b,
+                                                 guess,
+                                                 results);
+    if (isSeparated)
+    {
+        distInfo->m_distance = results.distance;
+        distInfo->m_pointOnA= results.witnesses[0];
+        distInfo->m_pointOnB= results.witnesses[1];
+        distInfo->m_normalBtoA= results.normal;
+        return 0;
+    }
+    
+    return -1;
+}
+
+/* Symbols cleanup		*/ 
+
+#undef GJK_MAX_ITERATIONS
+#undef GJK_ACCURARY
+#undef GJK_MIN_DISTANCE
+#undef GJK_DUPLICATED_EPS
+#undef GJK_SIMPLEX2_EPS
+#undef GJK_SIMPLEX3_EPS
+#undef GJK_SIMPLEX4_EPS
+
+#undef EPA_MAX_VERTICES
+#undef EPA_MAX_FACES
+#undef EPA_MAX_ITERATIONS
+#undef EPA_ACCURACY
+#undef EPA_FALLBACK
+#undef EPA_PLANE_EPS
+#undef EPA_INSIDE_EPS
+
+
+
+#endif //BT_GJK_EPA3_H
+

+ 60 - 73
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp

@@ -26,12 +26,17 @@ subject to the following restrictions:
 #ifdef __SPU__
 #include <spu_printf.h>
 #define printf spu_printf
-//#define DEBUG_SPU_COLLISION_DETECTION 1
 #endif //__SPU__
 #endif
 
 //must be above the machine epsilon
-#define REL_ERROR2 btScalar(1.0e-6)
+#ifdef  BT_USE_DOUBLE_PRECISION
+	#define REL_ERROR2 btScalar(1.0e-12)
+	btScalar gGjkEpaPenetrationTolerance = 1e-7;
+#else
+	#define REL_ERROR2 btScalar(1.0e-6)
+	btScalar gGjkEpaPenetrationTolerance = 0.001;
+#endif
 
 //temp globals, to improve GJK/EPA/penetration calculations
 int gNumDeepPenetrationChecks = 0;
@@ -81,17 +86,18 @@ void	btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result&
 #ifdef __SPU__
 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw)
 #else
-void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw)
+void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input, Result& output, class btIDebugDraw* debugDraw)
 #endif
 {
 	m_cachedSeparatingDistance = 0.f;
 
 	btScalar distance=btScalar(0.);
 	btVector3	normalInB(btScalar(0.),btScalar(0.),btScalar(0.));
+
 	btVector3 pointOnA,pointOnB;
 	btTransform	localTransA = input.m_transformA;
 	btTransform localTransB = input.m_transformB;
-	btVector3 positionOffset = (localTransA.getOrigin() + localTransB.getOrigin()) * btScalar(0.5);
+	btVector3 positionOffset=(localTransA.getOrigin() + localTransB.getOrigin()) * btScalar(0.5);
 	localTransA.getOrigin() -= positionOffset;
 	localTransB.getOrigin() -= positionOffset;
 
@@ -102,17 +108,11 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 
 	gNumGjkChecks++;
 
-#ifdef DEBUG_SPU_COLLISION_DETECTION
-	spu_printf("inside gjk\n");
-#endif
 	//for CCD we don't use margins
 	if (m_ignoreMargin)
 	{
 		marginA = btScalar(0.);
 		marginB = btScalar(0.);
-#ifdef DEBUG_SPU_COLLISION_DETECTION
-		spu_printf("ignoring margin\n");
-#endif
 	}
 
 	m_curIter = 0;
@@ -143,37 +143,13 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 			btVector3 seperatingAxisInA = (-m_cachedSeparatingAxis)* input.m_transformA.getBasis();
 			btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis();
 
-#if 1
 
 			btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
 			btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
 
-//			btVector3 pInA  = localGetSupportingVertexWithoutMargin(m_shapeTypeA, m_minkowskiA, seperatingAxisInA,input.m_convexVertexData[0]);//, &featureIndexA);
-//			btVector3 qInB  = localGetSupportingVertexWithoutMargin(m_shapeTypeB, m_minkowskiB, seperatingAxisInB,input.m_convexVertexData[1]);//, &featureIndexB);
-
-#else
-#ifdef __SPU__
-			btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
-			btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
-#else
-			btVector3 pInA = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
-			btVector3 qInB = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
-#ifdef TEST_NON_VIRTUAL
-			btVector3 pInAv = m_minkowskiA->localGetSupportingVertexWithoutMargin(seperatingAxisInA);
-			btVector3 qInBv = m_minkowskiB->localGetSupportingVertexWithoutMargin(seperatingAxisInB);
-			btAssert((pInAv-pInA).length() < 0.0001);
-			btAssert((qInBv-qInB).length() < 0.0001);
-#endif //
-#endif //__SPU__
-#endif
-
-
 			btVector3  pWorld = localTransA(pInA);	
 			btVector3  qWorld = localTransB(qInB);
 
-#ifdef DEBUG_SPU_COLLISION_DETECTION
-		spu_printf("got local supporting vertices\n");
-#endif
 
 			if (check2d)
 			{
@@ -217,14 +193,8 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 				break;
 			}
 
-#ifdef DEBUG_SPU_COLLISION_DETECTION
-		spu_printf("addVertex 1\n");
-#endif
 			//add current vertex to simplex
 			m_simplexSolver->addVertex(w, pWorld, qWorld);
-#ifdef DEBUG_SPU_COLLISION_DETECTION
-		spu_printf("addVertex 2\n");
-#endif
 			btVector3 newCachedSeparatingAxis;
 
 			//calculate the closest point to the origin (update vector v)
@@ -274,7 +244,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 			  //degeneracy, this is typically due to invalid/uninitialized worldtransforms for a btCollisionObject   
               if (m_curIter++ > gGjkMaxIter)   
               {   
-                      #if defined(DEBUG) || defined (_DEBUG) || defined (DEBUG_SPU_COLLISION_DETECTION)
+                      #if defined(DEBUG) || defined (_DEBUG)
 
                               printf("btGjkPairDetector maxIter exceeded:%i\n",m_curIter);   
                               printf("sepAxis=(%f,%f,%f), squaredDistance = %f, shapeTypeA=%i,shapeTypeB=%i\n",   
@@ -307,10 +277,11 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 		{
 			m_simplexSolver->compute_points(pointOnA, pointOnB);
 			normalInB = m_cachedSeparatingAxis;
+
 			btScalar lenSqr =m_cachedSeparatingAxis.length2();
 			
 			//valid normal
-			if (lenSqr < 0.0001)
+			if (lenSqr < REL_ERROR2)
 			{
 				m_degenerateSimplex = 5;
 			} 
@@ -318,6 +289,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 			{
 				btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
 				normalInB *= rlen; //normalize
+
 				btScalar s = btSqrt(squaredDistance);
 			
 				btAssert(s > btScalar(0.0));
@@ -334,7 +306,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 		}
 
 		bool catchDegeneratePenetrationCase = 
-			(m_catchDegeneracies && m_penetrationDepthSolver && m_degenerateSimplex && ((distance+margin) < 0.01));
+			(m_catchDegeneracies && m_penetrationDepthSolver && m_degenerateSimplex && ((distance+margin) < gGjkEpaPenetrationTolerance));
 
 		//if (checkPenetration && !isValid)
 		if (checkPenetration && (!isValid || catchDegeneratePenetrationCase ))
@@ -373,6 +345,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 					{
 						tmpNormalInB /= btSqrt(lenSqr);
 						btScalar distance2 = -(tmpPointOnA-tmpPointOnB).length();
+						m_lastUsedMethod = 3;
 						//only replace valid penetrations when the result is deeper (check)
 						if (!isValid || (distance2 < distance))
 						{
@@ -380,8 +353,9 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 							pointOnA = tmpPointOnA;
 							pointOnB = tmpPointOnB;
 							normalInB = tmpNormalInB;
+							
 							isValid = true;
-							m_lastUsedMethod = 3;
+							
 						} else
 						{
 							m_lastUsedMethod = 8;
@@ -413,6 +387,7 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 							pointOnB += m_cachedSeparatingAxis * marginB ;
 							normalInB = m_cachedSeparatingAxis;
 							normalInB.normalize();
+
 							isValid = true;
 							m_lastUsedMethod = 6;
 						} else
@@ -431,39 +406,51 @@ void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& inpu
 
 	if (isValid && ((distance < 0) || (distance*distance < input.m_maximumDistanceSquared)))
 	{
-#if 0
-///some debugging
-//		if (check2d)
-		{
-			printf("n = %2.3f,%2.3f,%2.3f. ",normalInB[0],normalInB[1],normalInB[2]);
-			printf("distance = %2.3f exit=%d deg=%d\n",distance,m_lastUsedMethod,m_degenerateSimplex);
-		}
-#endif 
-
-		if (m_fixContactNormalDirection)
-		{
-			///@workaround for sticky convex collisions
-			//in some degenerate cases (usually when the use uses very small margins) 
-			//the contact normal is pointing the wrong direction
-			//so fix it now (until we can deal with all degenerate cases in GJK and EPA)
-			//contact normals need to point from B to A in all cases, so we can simply check if the contact normal really points from B to A
-			//We like to use a dot product of the normal against the difference of the centroids, 
-			//once the centroid is available in the API
-			//until then we use the center of the aabb to approximate the centroid
-			btVector3 aabbMin,aabbMax;
-			m_minkowskiA->getAabb(localTransA,aabbMin,aabbMax);
-			btVector3 posA  = (aabbMax+aabbMin)*btScalar(0.5);
-		
-			m_minkowskiB->getAabb(localTransB,aabbMin,aabbMax);
-			btVector3 posB = (aabbMin+aabbMax)*btScalar(0.5);
 
-			btVector3 diff = posA-posB;
-			if (diff.dot(normalInB) < 0.f)
-				normalInB *= -1.f;
-		}
 		m_cachedSeparatingAxis = normalInB;
 		m_cachedSeparatingDistance = distance;
 
+		{
+		///todo: need to track down this EPA penetration solver degeneracy
+		///the penetration solver reports penetration but the contact normal
+		///connecting the contact points is pointing in the opposite direction
+		///until then, detect the issue and revert the normal
+
+			btScalar d1=0;
+			{
+				btVector3 seperatingAxisInA = (normalInB)* input.m_transformA.getBasis();
+				btVector3 seperatingAxisInB = -normalInB* input.m_transformB.getBasis();
+			
+
+				btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
+				btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
+
+				btVector3  pWorld = localTransA(pInA);	
+				btVector3  qWorld = localTransB(qInB);
+				btVector3 w	= pWorld - qWorld;
+				d1 = (-normalInB).dot(w);
+			}
+			btScalar d0 = 0.f;
+			{
+				btVector3 seperatingAxisInA = (-normalInB)* input.m_transformA.getBasis();
+				btVector3 seperatingAxisInB = normalInB* input.m_transformB.getBasis();
+			
+
+				btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA);
+				btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB);
+
+				btVector3  pWorld = localTransA(pInA);	
+				btVector3  qWorld = localTransB(qInB);
+				btVector3 w	= pWorld - qWorld;
+				d0 = normalInB.dot(w);
+			}
+			if (d1>d0)
+			{
+				m_lastUsedMethod = 10;
+				normalInB*=-1;
+			} 
+
+		}
 		output.addContactPoint(
 			normalInB,
 			pointOnB+positionOffset,

+ 39 - 16
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h

@@ -35,7 +35,13 @@ typedef sce::PhysicsEffects::PfxConstraintRow btConstraintRow;
 	typedef btConstraintRow PfxConstraintRow;
 #endif //PFX_USE_FREE_VECTORMATH
 
-
+enum btContactPointFlags
+{
+	BT_CONTACT_FLAG_LATERAL_FRICTION_INITIALIZED=1,
+	BT_CONTACT_FLAG_HAS_CONTACT_CFM=2,
+	BT_CONTACT_FLAG_HAS_CONTACT_ERP=4,
+    BT_CONTACT_FLAG_CONTACT_STIFFNESS_DAMPING = 8,
+};
 
 /// ManifoldContactPoint collects and maintains persistent contactpoints.
 /// used to improve stability and performance of rigidbody dynamics response.
@@ -44,14 +50,15 @@ class btManifoldPoint
 		public:
 			btManifoldPoint()
 				:m_userPersistentData(0),
-				m_lateralFrictionInitialized(false),
-                m_appliedImpulse(0.f),
+				m_contactPointFlags(0),
+				m_appliedImpulse(0.f),
                 m_appliedImpulseLateral1(0.f),
 				m_appliedImpulseLateral2(0.f),
 				m_contactMotion1(0.f),
 				m_contactMotion2(0.f),
-				m_contactCFM1(0.f),
-				m_contactCFM2(0.f),
+				m_contactCFM(0.f),
+				m_contactERP(0.f),
+				m_frictionCFM(0.f),
 				m_lifeTime(0)
 			{
 			}
@@ -65,16 +72,18 @@ class btManifoldPoint
 					m_distance1( distance ),
 					m_combinedFriction(btScalar(0.)),
 					m_combinedRollingFriction(btScalar(0.)),
-					m_combinedRestitution(btScalar(0.)),
+                    m_combinedSpinningFriction(btScalar(0.)),
+                    m_combinedRestitution(btScalar(0.)),
 					m_userPersistentData(0),
-					m_lateralFrictionInitialized(false),
-                    m_appliedImpulse(0.f),
+					m_contactPointFlags(0),
+					m_appliedImpulse(0.f),
                     m_appliedImpulseLateral1(0.f),
 					m_appliedImpulseLateral2(0.f),
 					m_contactMotion1(0.f),
 					m_contactMotion2(0.f),
-					m_contactCFM1(0.f),
-					m_contactCFM2(0.f),
+					m_contactCFM(0.f),
+					m_contactERP(0.f),
+					m_frictionCFM(0.f),
 					m_lifeTime(0)
 			{
 				
@@ -91,8 +100,9 @@ class btManifoldPoint
 		
 			btScalar	m_distance1;
 			btScalar	m_combinedFriction;
-			btScalar	m_combinedRollingFriction;
-			btScalar	m_combinedRestitution;
+			btScalar	m_combinedRollingFriction;//torsional friction orthogonal to contact normal, useful to make spheres stop rolling forever
+            btScalar	m_combinedSpinningFriction;//torsional friction around contact normal, useful for grasping objects
+            btScalar	m_combinedRestitution;
 
 			//BP mod, store contact triangles.
 			int			m_partId0;
@@ -101,15 +111,28 @@ class btManifoldPoint
 			int			m_index1;
 				
 			mutable void*	m_userPersistentData;
-			bool			m_lateralFrictionInitialized;
-
+			//bool			m_lateralFrictionInitialized;
+			int				m_contactPointFlags;
+			
 			btScalar		m_appliedImpulse;
 			btScalar		m_appliedImpulseLateral1;
 			btScalar		m_appliedImpulseLateral2;
 			btScalar		m_contactMotion1;
 			btScalar		m_contactMotion2;
-			btScalar		m_contactCFM1;
-			btScalar		m_contactCFM2;
+			
+			union
+			{
+                btScalar		m_contactCFM;
+                btScalar        m_combinedContactStiffness1;
+			};
+			
+			union
+			{
+                btScalar		m_contactERP;
+                btScalar        m_combinedContactDamping1;
+			};
+
+			btScalar		m_frictionCFM;
 
 			int				m_lifeTime;//lifetime of the contactpoint in frames
 			

+ 908 - 0
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btMprPenetration.h

@@ -0,0 +1,908 @@
+
+/***
+ * ---------------------------------
+ * Copyright (c)2012 Daniel Fiser <[email protected]>
+ *
+ *  This file was ported from mpr.c file, part of libccd.
+ *  The Minkoski Portal Refinement implementation was ported 
+ *  to OpenCL by Erwin Coumans for the Bullet 3 Physics library.
+ *  The original MPR idea and implementation is by Gary Snethen
+ *  in XenoCollide, see http://github.com/erwincoumans/xenocollide
+ *
+ *  Distributed under the OSI-approved BSD License (the "License");
+ *  see <http://www.opensource.org/licenses/bsd-license.php>.
+ *  This software is distributed WITHOUT ANY WARRANTY; without even the
+ *  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the License for more information.
+ */
+
+///2014 Oct, Erwin Coumans, Use templates to avoid void* casts
+
+#ifndef BT_MPR_PENETRATION_H
+#define BT_MPR_PENETRATION_H
+
+#define BT_DEBUG_MPR1
+
+#include "LinearMath/btTransform.h"
+#include "LinearMath/btAlignedObjectArray.h"
+
+//#define MPR_AVERAGE_CONTACT_POSITIONS
+
+
+struct btMprCollisionDescription
+{
+    btVector3	m_firstDir;
+    int			m_maxGjkIterations;
+    btScalar	m_maximumDistanceSquared;
+    btScalar	m_gjkRelError2;
+   
+    btMprCollisionDescription()
+    :	m_firstDir(0,1,0),
+        m_maxGjkIterations(1000),
+        m_maximumDistanceSquared(1e30f),
+        m_gjkRelError2(1.0e-6)
+    {
+    }
+    virtual ~btMprCollisionDescription()
+    {
+    }
+};
+
+struct btMprDistanceInfo
+{
+    btVector3	m_pointOnA;
+    btVector3	m_pointOnB;
+    btVector3	m_normalBtoA;
+    btScalar	m_distance;
+};
+
+#ifdef __cplusplus
+#define BT_MPR_SQRT sqrtf
+#else
+#define BT_MPR_SQRT sqrt
+#endif
+#define BT_MPR_FMIN(x, y) ((x) < (y) ? (x) : (y))
+#define BT_MPR_FABS fabs
+
+#define BT_MPR_TOLERANCE 1E-6f
+#define BT_MPR_MAX_ITERATIONS 1000
+
+struct _btMprSupport_t 
+{
+    btVector3 v;  //!< Support point in minkowski sum
+    btVector3 v1; //!< Support point in obj1
+    btVector3 v2; //!< Support point in obj2
+};
+typedef struct _btMprSupport_t btMprSupport_t;
+
+struct _btMprSimplex_t 
+{
+    btMprSupport_t ps[4];
+    int last; //!< index of last added point
+};
+typedef struct _btMprSimplex_t btMprSimplex_t;
+
+inline btMprSupport_t* btMprSimplexPointW(btMprSimplex_t *s, int idx)
+{
+    return &s->ps[idx];
+}
+
+inline void btMprSimplexSetSize(btMprSimplex_t *s, int size)
+{
+    s->last = size - 1;
+}
+
+#ifdef DEBUG_MPR
+inline void btPrintPortalVertex(_btMprSimplex_t* portal, int index)
+{
+    printf("portal[%d].v = %f,%f,%f, v1=%f,%f,%f, v2=%f,%f,%f\n", index, portal->ps[index].v.x(),portal->ps[index].v.y(),portal->ps[index].v.z(),
+           portal->ps[index].v1.x(),portal->ps[index].v1.y(),portal->ps[index].v1.z(),
+           portal->ps[index].v2.x(),portal->ps[index].v2.y(),portal->ps[index].v2.z());
+}
+#endif //DEBUG_MPR
+
+
+
+
+inline int btMprSimplexSize(const btMprSimplex_t *s)
+{
+    return s->last + 1;
+}
+
+
+inline const btMprSupport_t* btMprSimplexPoint(const btMprSimplex_t* s, int idx)
+{
+    // here is no check on boundaries
+    return &s->ps[idx];
+}
+
+inline void btMprSupportCopy(btMprSupport_t *d, const btMprSupport_t *s)
+{
+    *d = *s;
+}
+
+inline void btMprSimplexSet(btMprSimplex_t *s, size_t pos, const btMprSupport_t *a)
+{
+    btMprSupportCopy(s->ps + pos, a);
+}
+
+
+inline void btMprSimplexSwap(btMprSimplex_t *s, size_t pos1, size_t pos2)
+{
+    btMprSupport_t supp;
+
+    btMprSupportCopy(&supp, &s->ps[pos1]);
+    btMprSupportCopy(&s->ps[pos1], &s->ps[pos2]);
+    btMprSupportCopy(&s->ps[pos2], &supp);
+}
+
+
+inline int btMprIsZero(float val)
+{
+    return BT_MPR_FABS(val) < FLT_EPSILON;
+}
+
+
+
+inline int btMprEq(float _a, float _b)
+{
+    float ab;
+    float a, b;
+
+    ab = BT_MPR_FABS(_a - _b);
+    if (BT_MPR_FABS(ab) < FLT_EPSILON)
+        return 1;
+
+    a = BT_MPR_FABS(_a);
+    b = BT_MPR_FABS(_b);
+    if (b > a){
+        return ab < FLT_EPSILON * b;
+    }else{
+        return ab < FLT_EPSILON * a;
+    }
+}
+
+
+inline int btMprVec3Eq(const btVector3* a, const btVector3 *b)
+{
+    return btMprEq((*a).x(), (*b).x())
+            && btMprEq((*a).y(), (*b).y())
+            && btMprEq((*a).z(), (*b).z());
+}
+
+
+
+
+
+
+
+
+
+
+
+template <typename btConvexTemplate>
+inline void btFindOrigin(const btConvexTemplate& a, const btConvexTemplate& b, const btMprCollisionDescription& colDesc,btMprSupport_t *center)
+{
+
+	center->v1 = a.getObjectCenterInWorld();
+    center->v2 = b.getObjectCenterInWorld();
+    center->v = center->v1 - center->v2;
+}
+
+inline void btMprVec3Set(btVector3 *v, float x, float y, float z)
+{
+	v->setValue(x,y,z);
+}
+
+inline void btMprVec3Add(btVector3 *v, const btVector3 *w)
+{
+	*v += *w;
+}
+
+inline void btMprVec3Copy(btVector3 *v, const btVector3 *w)
+{
+    *v = *w;
+}
+
+inline void btMprVec3Scale(btVector3 *d, float k)
+{
+    *d *= k;
+}
+
+inline float btMprVec3Dot(const btVector3 *a, const btVector3 *b)
+{
+    float dot;
+
+	dot = btDot(*a,*b);
+    return dot;
+}
+
+
+inline float btMprVec3Len2(const btVector3 *v)
+{
+    return btMprVec3Dot(v, v);
+}
+
+inline void btMprVec3Normalize(btVector3 *d)
+{
+    float k = 1.f / BT_MPR_SQRT(btMprVec3Len2(d));
+    btMprVec3Scale(d, k);
+}
+
+inline void btMprVec3Cross(btVector3 *d, const btVector3 *a, const btVector3 *b)
+{
+	*d = btCross(*a,*b);
+	
+}
+
+
+inline void btMprVec3Sub2(btVector3 *d, const btVector3 *v, const btVector3 *w)
+{
+	*d = *v - *w;
+}
+
+inline void btPortalDir(const btMprSimplex_t *portal, btVector3 *dir)
+{
+    btVector3 v2v1, v3v1;
+
+    btMprVec3Sub2(&v2v1, &btMprSimplexPoint(portal, 2)->v,
+                       &btMprSimplexPoint(portal, 1)->v);
+    btMprVec3Sub2(&v3v1, &btMprSimplexPoint(portal, 3)->v,
+                       &btMprSimplexPoint(portal, 1)->v);
+    btMprVec3Cross(dir, &v2v1, &v3v1);
+    btMprVec3Normalize(dir);
+}
+
+
+inline int portalEncapsulesOrigin(const btMprSimplex_t *portal,
+                                       const btVector3 *dir)
+{
+    float dot;
+    dot = btMprVec3Dot(dir, &btMprSimplexPoint(portal, 1)->v);
+    return btMprIsZero(dot) || dot > 0.f;
+}
+
+inline int portalReachTolerance(const btMprSimplex_t *portal,
+                                     const btMprSupport_t *v4,
+                                     const btVector3 *dir)
+{
+    float dv1, dv2, dv3, dv4;
+    float dot1, dot2, dot3;
+
+    // find the smallest dot product of dir and {v1-v4, v2-v4, v3-v4}
+
+    dv1 = btMprVec3Dot(&btMprSimplexPoint(portal, 1)->v, dir);
+    dv2 = btMprVec3Dot(&btMprSimplexPoint(portal, 2)->v, dir);
+    dv3 = btMprVec3Dot(&btMprSimplexPoint(portal, 3)->v, dir);
+    dv4 = btMprVec3Dot(&v4->v, dir);
+
+    dot1 = dv4 - dv1;
+    dot2 = dv4 - dv2;
+    dot3 = dv4 - dv3;
+
+    dot1 = BT_MPR_FMIN(dot1, dot2);
+    dot1 = BT_MPR_FMIN(dot1, dot3);
+
+    return btMprEq(dot1, BT_MPR_TOLERANCE) || dot1 < BT_MPR_TOLERANCE;
+}
+
+inline int portalCanEncapsuleOrigin(const btMprSimplex_t *portal,
+                                         const btMprSupport_t *v4,
+                                         const btVector3 *dir)
+{
+    float dot;
+    dot = btMprVec3Dot(&v4->v, dir);
+    return btMprIsZero(dot) || dot > 0.f;
+}
+
+inline void btExpandPortal(btMprSimplex_t *portal,
+                              const btMprSupport_t *v4)
+{
+    float dot;
+    btVector3 v4v0;
+
+    btMprVec3Cross(&v4v0, &v4->v, &btMprSimplexPoint(portal, 0)->v);
+    dot = btMprVec3Dot(&btMprSimplexPoint(portal, 1)->v, &v4v0);
+    if (dot > 0.f){
+        dot = btMprVec3Dot(&btMprSimplexPoint(portal, 2)->v, &v4v0);
+        if (dot > 0.f){
+            btMprSimplexSet(portal, 1, v4);
+        }else{
+            btMprSimplexSet(portal, 3, v4);
+        }
+    }else{
+        dot = btMprVec3Dot(&btMprSimplexPoint(portal, 3)->v, &v4v0);
+        if (dot > 0.f){
+            btMprSimplexSet(portal, 2, v4);
+        }else{
+            btMprSimplexSet(portal, 1, v4);
+        }
+    }
+}
+template <typename btConvexTemplate>
+inline void btMprSupport(const btConvexTemplate& a, const btConvexTemplate& b,
+                         const btMprCollisionDescription& colDesc,
+													const btVector3& dir, btMprSupport_t *supp)
+{
+	btVector3 seperatingAxisInA = dir* a.getWorldTransform().getBasis();
+	btVector3 seperatingAxisInB = -dir* b.getWorldTransform().getBasis();
+
+	btVector3 pInA = a.getLocalSupportWithMargin(seperatingAxisInA);
+	btVector3 qInB = b.getLocalSupportWithMargin(seperatingAxisInB);
+
+	supp->v1 = a.getWorldTransform()(pInA);
+	supp->v2 = b.getWorldTransform()(qInB);
+	supp->v = supp->v1 - supp->v2;
+}
+
+
+template <typename btConvexTemplate>
+static int btDiscoverPortal(const btConvexTemplate& a, const btConvexTemplate& b,
+                            const btMprCollisionDescription& colDesc,
+													btMprSimplex_t *portal)
+{
+    btVector3 dir, va, vb;
+    float dot;
+    int cont;
+	
+	
+
+    // vertex 0 is center of portal
+    btFindOrigin(a,b,colDesc, btMprSimplexPointW(portal, 0));
+   
+    
+    // vertex 0 is center of portal
+    btMprSimplexSetSize(portal, 1);
+    
+
+
+	btVector3 zero = btVector3(0,0,0);
+	btVector3* org = &zero;
+
+    if (btMprVec3Eq(&btMprSimplexPoint(portal, 0)->v, org)){
+        // Portal's center lies on origin (0,0,0) => we know that objects
+        // intersect but we would need to know penetration info.
+        // So move center little bit...
+        btMprVec3Set(&va, FLT_EPSILON * 10.f, 0.f, 0.f);
+        btMprVec3Add(&btMprSimplexPointW(portal, 0)->v, &va);
+    }
+
+
+    // vertex 1 = support in direction of origin
+    btMprVec3Copy(&dir, &btMprSimplexPoint(portal, 0)->v);
+    btMprVec3Scale(&dir, -1.f);
+    btMprVec3Normalize(&dir);
+
+
+    btMprSupport(a,b,colDesc, dir, btMprSimplexPointW(portal, 1));
+ 
+    btMprSimplexSetSize(portal, 2);
+
+    // test if origin isn't outside of v1
+    dot = btMprVec3Dot(&btMprSimplexPoint(portal, 1)->v, &dir);
+	
+
+    if (btMprIsZero(dot) || dot < 0.f)
+        return -1;
+
+
+    // vertex 2
+    btMprVec3Cross(&dir, &btMprSimplexPoint(portal, 0)->v,
+                       &btMprSimplexPoint(portal, 1)->v);
+    if (btMprIsZero(btMprVec3Len2(&dir))){
+        if (btMprVec3Eq(&btMprSimplexPoint(portal, 1)->v, org)){
+            // origin lies on v1
+            return 1;
+        }else{
+            // origin lies on v0-v1 segment
+            return 2;
+        }
+    }
+
+    btMprVec3Normalize(&dir);
+    btMprSupport(a,b,colDesc, dir, btMprSimplexPointW(portal, 2));
+    
+    
+    
+    dot = btMprVec3Dot(&btMprSimplexPoint(portal, 2)->v, &dir);
+    if (btMprIsZero(dot) || dot < 0.f)
+        return -1;
+
+    btMprSimplexSetSize(portal, 3);
+
+    // vertex 3 direction
+    btMprVec3Sub2(&va, &btMprSimplexPoint(portal, 1)->v,
+                     &btMprSimplexPoint(portal, 0)->v);
+    btMprVec3Sub2(&vb, &btMprSimplexPoint(portal, 2)->v,
+                     &btMprSimplexPoint(portal, 0)->v);
+    btMprVec3Cross(&dir, &va, &vb);
+    btMprVec3Normalize(&dir);
+
+    // it is better to form portal faces to be oriented "outside" origin
+    dot = btMprVec3Dot(&dir, &btMprSimplexPoint(portal, 0)->v);
+    if (dot > 0.f){
+        btMprSimplexSwap(portal, 1, 2);
+        btMprVec3Scale(&dir, -1.f);
+    }
+
+    while (btMprSimplexSize(portal) < 4){
+		 btMprSupport(a,b,colDesc, dir, btMprSimplexPointW(portal, 3));
+        
+        dot = btMprVec3Dot(&btMprSimplexPoint(portal, 3)->v, &dir);
+        if (btMprIsZero(dot) || dot < 0.f)
+            return -1;
+
+        cont = 0;
+
+        // test if origin is outside (v1, v0, v3) - set v2 as v3 and
+        // continue
+        btMprVec3Cross(&va, &btMprSimplexPoint(portal, 1)->v,
+                          &btMprSimplexPoint(portal, 3)->v);
+        dot = btMprVec3Dot(&va, &btMprSimplexPoint(portal, 0)->v);
+        if (dot < 0.f && !btMprIsZero(dot)){
+            btMprSimplexSet(portal, 2, btMprSimplexPoint(portal, 3));
+            cont = 1;
+        }
+
+        if (!cont){
+            // test if origin is outside (v3, v0, v2) - set v1 as v3 and
+            // continue
+            btMprVec3Cross(&va, &btMprSimplexPoint(portal, 3)->v,
+                              &btMprSimplexPoint(portal, 2)->v);
+            dot = btMprVec3Dot(&va, &btMprSimplexPoint(portal, 0)->v);
+            if (dot < 0.f && !btMprIsZero(dot)){
+                btMprSimplexSet(portal, 1, btMprSimplexPoint(portal, 3));
+                cont = 1;
+            }
+        }
+
+        if (cont){
+            btMprVec3Sub2(&va, &btMprSimplexPoint(portal, 1)->v,
+                             &btMprSimplexPoint(portal, 0)->v);
+            btMprVec3Sub2(&vb, &btMprSimplexPoint(portal, 2)->v,
+                             &btMprSimplexPoint(portal, 0)->v);
+            btMprVec3Cross(&dir, &va, &vb);
+            btMprVec3Normalize(&dir);
+        }else{
+            btMprSimplexSetSize(portal, 4);
+        }
+    }
+
+    return 0;
+}
+
+template <typename btConvexTemplate>
+static int btRefinePortal(const btConvexTemplate& a, const btConvexTemplate& b,const btMprCollisionDescription& colDesc,
+							btMprSimplex_t *portal)
+{
+    btVector3 dir;
+    btMprSupport_t v4;
+
+	for (int i=0;i<BT_MPR_MAX_ITERATIONS;i++)
+    //while (1)
+	{
+        // compute direction outside the portal (from v0 throught v1,v2,v3
+        // face)
+        btPortalDir(portal, &dir);
+
+        // test if origin is inside the portal
+        if (portalEncapsulesOrigin(portal, &dir))
+            return 0;
+
+        // get next support point
+        
+		 btMprSupport(a,b,colDesc, dir, &v4);
+
+
+        // test if v4 can expand portal to contain origin and if portal
+        // expanding doesn't reach given tolerance
+        if (!portalCanEncapsuleOrigin(portal, &v4, &dir)
+                || portalReachTolerance(portal, &v4, &dir))
+		{
+            return -1;
+        }
+
+        // v1-v2-v3 triangle must be rearranged to face outside Minkowski
+        // difference (direction from v0).
+        btExpandPortal(portal, &v4);
+    }
+
+    return -1;
+}
+
+static void btFindPos(const btMprSimplex_t *portal, btVector3 *pos)
+{
+
+	btVector3 zero = btVector3(0,0,0);
+	btVector3* origin = &zero;
+
+    btVector3 dir;
+    size_t i;
+    float b[4], sum, inv;
+    btVector3 vec, p1, p2;
+
+    btPortalDir(portal, &dir);
+
+    // use barycentric coordinates of tetrahedron to find origin
+    btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 1)->v,
+                       &btMprSimplexPoint(portal, 2)->v);
+    b[0] = btMprVec3Dot(&vec, &btMprSimplexPoint(portal, 3)->v);
+
+    btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 3)->v,
+                       &btMprSimplexPoint(portal, 2)->v);
+    b[1] = btMprVec3Dot(&vec, &btMprSimplexPoint(portal, 0)->v);
+
+    btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 0)->v,
+                       &btMprSimplexPoint(portal, 1)->v);
+    b[2] = btMprVec3Dot(&vec, &btMprSimplexPoint(portal, 3)->v);
+
+    btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 2)->v,
+                       &btMprSimplexPoint(portal, 1)->v);
+    b[3] = btMprVec3Dot(&vec, &btMprSimplexPoint(portal, 0)->v);
+
+	sum = b[0] + b[1] + b[2] + b[3];
+
+    if (btMprIsZero(sum) || sum < 0.f){
+		b[0] = 0.f;
+
+        btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 2)->v,
+                           &btMprSimplexPoint(portal, 3)->v);
+        b[1] = btMprVec3Dot(&vec, &dir);
+        btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 3)->v,
+                           &btMprSimplexPoint(portal, 1)->v);
+        b[2] = btMprVec3Dot(&vec, &dir);
+        btMprVec3Cross(&vec, &btMprSimplexPoint(portal, 1)->v,
+                           &btMprSimplexPoint(portal, 2)->v);
+        b[3] = btMprVec3Dot(&vec, &dir);
+
+		sum = b[1] + b[2] + b[3];
+	}
+
+	inv = 1.f / sum;
+
+    btMprVec3Copy(&p1, origin);
+    btMprVec3Copy(&p2, origin);
+    for (i = 0; i < 4; i++){
+        btMprVec3Copy(&vec, &btMprSimplexPoint(portal, i)->v1);
+        btMprVec3Scale(&vec, b[i]);
+        btMprVec3Add(&p1, &vec);
+
+        btMprVec3Copy(&vec, &btMprSimplexPoint(portal, i)->v2);
+        btMprVec3Scale(&vec, b[i]);
+        btMprVec3Add(&p2, &vec);
+    }
+    btMprVec3Scale(&p1, inv);
+    btMprVec3Scale(&p2, inv);
+#ifdef MPR_AVERAGE_CONTACT_POSITIONS
+    btMprVec3Copy(pos, &p1);
+    btMprVec3Add(pos, &p2);
+    btMprVec3Scale(pos, 0.5);
+#else
+    btMprVec3Copy(pos, &p2);
+#endif//MPR_AVERAGE_CONTACT_POSITIONS
+}
+
+inline float btMprVec3Dist2(const btVector3 *a, const btVector3 *b)
+{
+    btVector3 ab;
+    btMprVec3Sub2(&ab, a, b);
+    return btMprVec3Len2(&ab);
+}
+
+inline float _btMprVec3PointSegmentDist2(const btVector3 *P,
+                                                  const btVector3 *x0,
+                                                  const btVector3 *b,
+                                                  btVector3 *witness)
+{
+    // The computation comes from solving equation of segment:
+    //      S(t) = x0 + t.d
+    //          where - x0 is initial point of segment
+    //                - d is direction of segment from x0 (|d| > 0)
+    //                - t belongs to <0, 1> interval
+    // 
+    // Than, distance from a segment to some point P can be expressed:
+    //      D(t) = |x0 + t.d - P|^2
+    //          which is distance from any point on segment. Minimization
+    //          of this function brings distance from P to segment.
+    // Minimization of D(t) leads to simple quadratic equation that's
+    // solving is straightforward.
+    //
+    // Bonus of this method is witness point for free.
+
+    float dist, t;
+    btVector3 d, a;
+
+    // direction of segment
+    btMprVec3Sub2(&d, b, x0);
+
+    // precompute vector from P to x0
+    btMprVec3Sub2(&a, x0, P);
+
+    t  = -1.f * btMprVec3Dot(&a, &d);
+    t /= btMprVec3Len2(&d);
+
+    if (t < 0.f || btMprIsZero(t)){
+        dist = btMprVec3Dist2(x0, P);
+        if (witness)
+            btMprVec3Copy(witness, x0);
+    }else if (t > 1.f || btMprEq(t, 1.f)){
+        dist = btMprVec3Dist2(b, P);
+        if (witness)
+            btMprVec3Copy(witness, b);
+    }else{
+        if (witness){
+            btMprVec3Copy(witness, &d);
+            btMprVec3Scale(witness, t);
+            btMprVec3Add(witness, x0);
+            dist = btMprVec3Dist2(witness, P);
+        }else{
+            // recycling variables
+            btMprVec3Scale(&d, t);
+            btMprVec3Add(&d, &a);
+            dist = btMprVec3Len2(&d);
+        }
+    }
+
+    return dist;
+}
+
+
+
+inline float btMprVec3PointTriDist2(const btVector3 *P,
+                                const btVector3 *x0, const btVector3 *B,
+                                const btVector3 *C,
+                                btVector3 *witness)
+{
+    // Computation comes from analytic expression for triangle (x0, B, C)
+    //      T(s, t) = x0 + s.d1 + t.d2, where d1 = B - x0 and d2 = C - x0 and
+    // Then equation for distance is:
+    //      D(s, t) = | T(s, t) - P |^2
+    // This leads to minimization of quadratic function of two variables.
+    // The solution from is taken only if s is between 0 and 1, t is
+    // between 0 and 1 and t + s < 1, otherwise distance from segment is
+    // computed.
+
+    btVector3 d1, d2, a;
+    float u, v, w, p, q, r;
+    float s, t, dist, dist2;
+    btVector3 witness2;
+
+    btMprVec3Sub2(&d1, B, x0);
+    btMprVec3Sub2(&d2, C, x0);
+    btMprVec3Sub2(&a, x0, P);
+
+    u = btMprVec3Dot(&a, &a);
+    v = btMprVec3Dot(&d1, &d1);
+    w = btMprVec3Dot(&d2, &d2);
+    p = btMprVec3Dot(&a, &d1);
+    q = btMprVec3Dot(&a, &d2);
+    r = btMprVec3Dot(&d1, &d2);
+
+	btScalar div = (w * v - r * r);
+	if (btMprIsZero(div))
+	{
+		s=-1;
+	} else
+	{
+		s = (q * r - w * p) / div;
+		t = (-s * r - q) / w;
+	}
+
+    if ((btMprIsZero(s) || s > 0.f)
+            && (btMprEq(s, 1.f) || s < 1.f)
+            && (btMprIsZero(t) || t > 0.f)
+            && (btMprEq(t, 1.f) || t < 1.f)
+            && (btMprEq(t + s, 1.f) || t + s < 1.f)){
+
+        if (witness){
+            btMprVec3Scale(&d1, s);
+            btMprVec3Scale(&d2, t);
+            btMprVec3Copy(witness, x0);
+            btMprVec3Add(witness, &d1);
+            btMprVec3Add(witness, &d2);
+
+            dist = btMprVec3Dist2(witness, P);
+        }else{
+            dist  = s * s * v;
+            dist += t * t * w;
+            dist += 2.f * s * t * r;
+            dist += 2.f * s * p;
+            dist += 2.f * t * q;
+            dist += u;
+        }
+    }else{
+        dist = _btMprVec3PointSegmentDist2(P, x0, B, witness);
+
+        dist2 = _btMprVec3PointSegmentDist2(P, x0, C, &witness2);
+        if (dist2 < dist){
+            dist = dist2;
+            if (witness)
+                btMprVec3Copy(witness, &witness2);
+        }
+
+        dist2 = _btMprVec3PointSegmentDist2(P, B, C, &witness2);
+        if (dist2 < dist){
+            dist = dist2;
+            if (witness)
+                btMprVec3Copy(witness, &witness2);
+        }
+    }
+
+    return dist;
+}
+
+template <typename btConvexTemplate>
+static void btFindPenetr(const btConvexTemplate& a, const btConvexTemplate& b,
+                         const btMprCollisionDescription& colDesc,
+                         btMprSimplex_t *portal,
+                         float *depth, btVector3 *pdir, btVector3 *pos)
+{
+    btVector3 dir;
+    btMprSupport_t v4;
+    unsigned long iterations;
+
+	btVector3 zero = btVector3(0,0,0);
+	btVector3* origin = &zero;
+
+
+    iterations = 1UL;
+	for (int i=0;i<BT_MPR_MAX_ITERATIONS;i++)
+    //while (1)
+	{
+        // compute portal direction and obtain next support point
+        btPortalDir(portal, &dir);
+        
+		 btMprSupport(a,b,colDesc, dir, &v4);
+
+
+        // reached tolerance -> find penetration info
+        if (portalReachTolerance(portal, &v4, &dir)
+                || iterations ==BT_MPR_MAX_ITERATIONS)
+		{
+            *depth = btMprVec3PointTriDist2(origin,&btMprSimplexPoint(portal, 1)->v,&btMprSimplexPoint(portal, 2)->v,&btMprSimplexPoint(portal, 3)->v,pdir);
+            *depth = BT_MPR_SQRT(*depth);
+			
+			if (btMprIsZero((*pdir).x()) && btMprIsZero((*pdir).y()) && btMprIsZero((*pdir).z()))
+			{
+				
+				*pdir = dir;
+			} 
+			btMprVec3Normalize(pdir);
+			
+            // barycentric coordinates:
+            btFindPos(portal, pos);
+
+
+            return;
+        }
+
+        btExpandPortal(portal, &v4);
+
+        iterations++;
+    }
+}
+
+static void btFindPenetrTouch(btMprSimplex_t *portal,float *depth, btVector3 *dir, btVector3 *pos)
+{
+    // Touching contact on portal's v1 - so depth is zero and direction
+    // is unimportant and pos can be guessed
+    *depth = 0.f;
+    btVector3 zero = btVector3(0,0,0);
+	btVector3* origin = &zero;
+
+
+	btMprVec3Copy(dir, origin);
+#ifdef MPR_AVERAGE_CONTACT_POSITIONS
+    btMprVec3Copy(pos, &btMprSimplexPoint(portal, 1)->v1);
+    btMprVec3Add(pos, &btMprSimplexPoint(portal, 1)->v2);
+    btMprVec3Scale(pos, 0.5);
+#else
+     btMprVec3Copy(pos, &btMprSimplexPoint(portal, 1)->v2);
+#endif
+}
+
+static void btFindPenetrSegment(btMprSimplex_t *portal,
+                              float *depth, btVector3 *dir, btVector3 *pos)
+{
+    
+    // Origin lies on v0-v1 segment.
+    // Depth is distance to v1, direction also and position must be
+    // computed
+#ifdef MPR_AVERAGE_CONTACT_POSITIONS
+    btMprVec3Copy(pos, &btMprSimplexPoint(portal, 1)->v1);
+    btMprVec3Add(pos, &btMprSimplexPoint(portal, 1)->v2);
+    btMprVec3Scale(pos, 0.5f);
+#else
+     btMprVec3Copy(pos, &btMprSimplexPoint(portal, 1)->v2);
+#endif//MPR_AVERAGE_CONTACT_POSITIONS
+
+    btMprVec3Copy(dir, &btMprSimplexPoint(portal, 1)->v);
+    *depth = BT_MPR_SQRT(btMprVec3Len2(dir));
+    btMprVec3Normalize(dir);
+
+    
+}
+
+
+template <typename btConvexTemplate>
+inline int btMprPenetration( const btConvexTemplate& a, const btConvexTemplate& b,
+                            const btMprCollisionDescription& colDesc,
+					float *depthOut, btVector3* dirOut, btVector3* posOut)
+{
+	
+	 btMprSimplex_t portal;
+
+
+    // Phase 1: Portal discovery
+    int result = btDiscoverPortal(a,b,colDesc, &portal);
+	
+	  
+	//sepAxis[pairIndex] = *pdir;//or -dir?
+
+	switch (result)
+	{
+	case 0:
+		{
+			// Phase 2: Portal refinement
+		
+			result = btRefinePortal(a,b,colDesc, &portal);
+			if (result < 0)
+				return -1;
+
+			// Phase 3. Penetration info
+			btFindPenetr(a,b,colDesc, &portal, depthOut, dirOut, posOut);
+			
+			
+			break;
+		}
+	case 1:
+		{
+			 // Touching contact on portal's v1.
+			btFindPenetrTouch(&portal, depthOut, dirOut, posOut);
+			result=0;
+			break;
+		}
+	case 2:
+		{
+			
+			btFindPenetrSegment( &portal, depthOut, dirOut, posOut);
+			result=0;
+			break;
+		}
+	default:
+		{
+			//if (res < 0)
+			//{
+				// Origin isn't inside portal - no collision.
+				result = -1;
+			//}
+		}
+	};
+	
+	return result;
+};
+
+
+template<typename btConvexTemplate, typename btMprDistanceTemplate>
+inline int	btComputeMprPenetration( const btConvexTemplate& a, const btConvexTemplate& b, const
+                                    btMprCollisionDescription& colDesc, btMprDistanceTemplate* distInfo)
+{
+	btVector3 dir,pos;
+	float depth;
+
+	int res = btMprPenetration(a,b,colDesc,&depth, &dir, &pos);
+	if (res==0)
+	{
+		distInfo->m_distance = -depth;
+		distInfo->m_pointOnB = pos;
+		distInfo->m_normalBtoA = -dir;
+		distInfo->m_pointOnA = pos-distInfo->m_distance*dir;
+		return 0;
+	}
+
+	return -1;
+}
+
+
+
+#endif //BT_MPR_PENETRATION_H

+ 1 - 6
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h

@@ -163,7 +163,7 @@ public:
 			//get rid of duplicated userPersistentData pointer
 			m_pointCache[lastUsedIndex].m_userPersistentData = 0;
 			m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f;
-			m_pointCache[lastUsedIndex].m_lateralFrictionInitialized = false;
+			m_pointCache[lastUsedIndex].m_contactPointFlags = 0;
 			m_pointCache[lastUsedIndex].m_appliedImpulseLateral1 = 0.f;
 			m_pointCache[lastUsedIndex].m_appliedImpulseLateral2 = 0.f;
 			m_pointCache[lastUsedIndex].m_lifeTime = 0;
@@ -190,16 +190,11 @@ public:
 		void* cache = m_pointCache[insertIndex].m_userPersistentData;
 		
 		m_pointCache[insertIndex] = newPoint;
-
 		m_pointCache[insertIndex].m_userPersistentData = cache;
 		m_pointCache[insertIndex].m_appliedImpulse = appliedImpulse;
 		m_pointCache[insertIndex].m_appliedImpulseLateral1 = appliedLateralImpulse1;
 		m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2;
 		
-		m_pointCache[insertIndex].m_appliedImpulse =  appliedImpulse;
-		m_pointCache[insertIndex].m_appliedImpulseLateral1 = appliedLateralImpulse1;
-		m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2;
-
 
 		m_pointCache[insertIndex].m_lifeTime = lifeTime;
 #else

+ 7 - 7
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.cpp

@@ -116,7 +116,7 @@ static int gActualSATPairTests=0;
 
 inline bool IsAlmostZero(const btVector3& v)
 {
-	if(fabsf(v.x())>1e-6 || fabsf(v.y())>1e-6 || fabsf(v.z())>1e-6)	return false;
+	if(btFabs(v.x())>1e-6 || btFabs(v.y())>1e-6 || btFabs(v.z())>1e-6)	return false;
 	return true;
 }
 
@@ -313,7 +313,7 @@ bool btPolyhedralContactClipping::findSeparatingAxis(	const btConvexPolyhedron&
 	int edgeB=-1;
 	btVector3 worldEdgeA;
 	btVector3 worldEdgeB;
-	btVector3 witnessPointA,witnessPointB;
+	btVector3 witnessPointA(0,0,0),witnessPointB(0,0,0);
 	
 
 	int curEdgeEdge = 0;
@@ -411,9 +411,9 @@ bool btPolyhedralContactClipping::findSeparatingAxis(	const btConvexPolyhedron&
 	return true;
 }
 
-void	btPolyhedralContactClipping::clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA,  const btTransform& transA, btVertexArray& worldVertsB1, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut)
+void	btPolyhedralContactClipping::clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA,  const btTransform& transA, btVertexArray& worldVertsB1,btVertexArray& worldVertsB2, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut)
 {
-	btVertexArray worldVertsB2;
+	worldVertsB2.resize(0);
 	btVertexArray* pVtxIn = &worldVertsB1;
 	btVertexArray* pVtxOut = &worldVertsB2;
 	pVtxOut->reserve(pVtxIn->size());
@@ -527,7 +527,7 @@ void	btPolyhedralContactClipping::clipFaceAgainstHull(const btVector3& separatin
 
 
 
-void	btPolyhedralContactClipping::clipHullAgainstHull(const btVector3& separatingNormal1, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut)
+void	btPolyhedralContactClipping::clipHullAgainstHull(const btVector3& separatingNormal1, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist,btVertexArray& worldVertsB1,btVertexArray& worldVertsB2,btDiscreteCollisionDetectorInterface::Result& resultOut)
 {
 
 	btVector3 separatingNormal = separatingNormal1.normalized();
@@ -552,7 +552,7 @@ void	btPolyhedralContactClipping::clipHullAgainstHull(const btVector3& separatin
 			}
 		}
 	}
-				btVertexArray worldVertsB1;
+	worldVertsB1.resize(0);
 				{
 					const btFace& polyB = hullB.m_faces[closestFaceB];
 					const int numVertices = polyB.m_indices.size();
@@ -565,6 +565,6 @@ void	btPolyhedralContactClipping::clipHullAgainstHull(const btVector3& separatin
 
 	
 	if (closestFaceB>=0)
-		clipFaceAgainstHull(separatingNormal, hullA, transA,worldVertsB1, minDist, maxDist,resultOut);
+		clipFaceAgainstHull(separatingNormal, hullA, transA,worldVertsB1, worldVertsB2,minDist, maxDist,resultOut);
 
 }

+ 5 - 2
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btPolyhedralContactClipping.h

@@ -32,8 +32,11 @@ typedef btAlignedObjectArray<btVector3> btVertexArray;
 // Clips a face to the back of a plane
 struct btPolyhedralContactClipping
 {
-	static void clipHullAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist, btDiscreteCollisionDetectorInterface::Result& resultOut);
-	static void	clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA,  const btTransform& transA, btVertexArray& worldVertsB1, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut);
+
+	static void	clipHullAgainstHull(const btVector3& separatingNormal1, const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, const btScalar minDist, btScalar maxDist,btVertexArray& worldVertsB1,btVertexArray& worldVertsB2,btDiscreteCollisionDetectorInterface::Result& resultOut);
+
+	static void	clipFaceAgainstHull(const btVector3& separatingNormal, const btConvexPolyhedron& hullA,  const btTransform& transA, btVertexArray& worldVertsB1,btVertexArray& worldVertsB2, const btScalar minDist, btScalar maxDist,btDiscreteCollisionDetectorInterface::Result& resultOut);
+
 
 	static bool findSeparatingAxis(	const btConvexPolyhedron& hullA, const btConvexPolyhedron& hullB, const btTransform& transA,const btTransform& transB, btVector3& sep, btDiscreteCollisionDetectorInterface::Result& resultOut);
 

+ 4 - 2
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h

@@ -32,10 +32,12 @@ public:
    //@BP Mod - allow backface filtering and unflipped normals
    enum EFlags
    {
-      kF_None                 = 0,
+	  kF_None                 = 0,
       kF_FilterBackfaces      = 1 << 0,
       kF_KeepUnflippedNormal  = 1 << 1,   // Prevents returned face normal getting flipped when a ray hits a back-facing triangle
-	  kF_UseSubSimplexConvexCastRaytest =  1 << 2,   // Uses an approximate but faster ray versus convex intersection algorithm
+		///SubSimplexConvexCastRaytest is the default, even if kF_None is set.
+	  kF_UseSubSimplexConvexCastRaytest = 1 << 2,   // Uses an approximate but faster ray versus convex intersection algorithm
+	  kF_UseGjkConvexCastRaytest = 1 << 3,
       kF_Terminator        = 0xFFFFFFFF
    };
    unsigned int m_flags;

+ 5 - 5
Engine/lib/bullet/src/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp

@@ -65,10 +65,10 @@ bool	btSubsimplexConvexCast::calcTimeOfImpact(
 
 	btVector3 n;
 	n.setValue(btScalar(0.),btScalar(0.),btScalar(0.));
-	bool hasResult = false;
+	
 	btVector3 c;
 
-	btScalar lastLambda = lambda;
+	
 
 
 	btScalar dist2 = v.length2();
@@ -109,9 +109,9 @@ bool	btSubsimplexConvexCast::calcTimeOfImpact(
 				//m_simplexSolver->reset();
 				//check next line
 				 w = supVertexA-supVertexB;
-				lastLambda = lambda;
+				
 				n = v;
-				hasResult = true;
+				
 			}
 		} 
 		///Just like regular GJK only add the vertex if it isn't already (close) to current vertex, it would lead to divisions by zero and NaN etc.
@@ -121,7 +121,7 @@ bool	btSubsimplexConvexCast::calcTimeOfImpact(
 		if (m_simplexSolver->closest(v))
 		{
 			dist2 = v.length2();
-			hasResult = true;
+			
 			//todo: check this normal for validity
 			//n=v;
 			//printf("V=%f , %f, %f\n",v[0],v[1],v[2]);

Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden.