From 884a4944124030387381a0af10221e2806033413 Mon Sep 17 00:00:00 2001 From: "erwin.coumans" Date: Tue, 15 Jul 2008 23:27:18 +0000 Subject: [PATCH] make the source code compile with older compilers again (Visual Studio 2006 in particular) renamed btDbvt::Volume to btDbvtVolume and btDbvt::Node to btDbvtNode to distinguish from btSoftBody::Node --- msvc/6/appAllBulletDemos.dsp | 155 +- .../BroadphaseCollision/btDbvt.cpp | 2331 +++++++++-------- .../BroadphaseCollision/btDbvt.h | 171 +- .../BroadphaseCollision/btDbvtBroadphase.cpp | 6 +- .../BroadphaseCollision/btDbvtBroadphase.h | 2 +- .../btMultiSapBroadphase.cpp | 5 +- .../btMultiSapBroadphase.h | 5 +- .../CollisionDispatch/btBoxBoxDetector.cpp | 24 +- .../btCollisionDispatcher.cpp | 2 +- .../NarrowPhaseCollision/btGjkEpa2.cpp | 49 +- .../ConstraintSolver/btOdeMacros.h | 4 +- .../btSequentialImpulseConstraintSolver.cpp | 2 +- src/BulletSoftBody/btSoftBody.cpp | 174 +- src/BulletSoftBody/btSoftBody.h | 10 +- src/BulletSoftBody/btSoftBodyHelpers.cpp | 29 +- src/BulletSoftBody/btSparseSDF.h | 65 +- src/LinearMath/btScalar.h | 5 +- 17 files changed, 1557 insertions(+), 1482 deletions(-) diff --git a/msvc/6/appAllBulletDemos.dsp b/msvc/6/appAllBulletDemos.dsp index 8054ace75..82572fda9 100644 --- a/msvc/6/appAllBulletDemos.dsp +++ b/msvc/6/appAllBulletDemos.dsp @@ -28,65 +28,36 @@ CFG=appAllBulletDemos - Win32 Release # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe -MTL=midl.exe RSC=rc.exe -!IF "$(CFG)" == "appAllBulletDemos - Win32 Release" +!IF "$(CFG)" == "appAllBulletDemos - Win32 DebugDoublePrecision" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "release" -# PROP BASE Intermediate_Dir "release" +# PROP BASE Output_Dir "debug_dbl" +# PROP BASE Intermediate_Dir "debug_dbl" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 -# PROP Output_Dir "..\..\out\release6\build\appAllBulletDemos\" -# PROP Intermediate_Dir "..\..\out\release6\build\appAllBulletDemos\" -# PROP Ignore_Export_Lib 0 +# PROP Output_Dir "..\..\out\debug_dbl6\build\appAllBulletDemos\" +# PROP Intermediate_Dir "..\..\out\debug_dbl6\build\appAllBulletDemos\" # PROP Target_Dir "" -# ADD BASE CPP /nologo /vmb /vms /W3 /Gm /G5 /D "WIN32" /FD /c -# ADD CPP /nologo /vmb /vms /W3 /Gm /G5 /FD /c /Gy /GF /MD /Ob2 /Og /Oi /Ot /Oy /D "_MT" /D "_MBCS" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo +MTL=midl.exe # ADD BASE MTL /nologo /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" +# ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "_DEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" +# ADD BASE CPP /nologo /G5 /W3 /D "WIN32" /FD /c +# ADD CPP /nologo /G5 /W3 /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" /D "_MT" /D "_MBCS" /D "_DEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /FD /c # ADD BASE RSC /l 0x409 -# ADD RSC /l 0x409 /fo".\..\..\out\release6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" +# ADD RSC /l 0x409 /fo".\..\..\out\debug_dbl6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo LINK32=link.exe # ADD BASE LINK32 user32.lib gdi32.lib advapi32.lib /nologo /machine:I386 -# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /machine:I386 /OPT:NOREF /out:"..\..\AllBulletDemos.exe" /subsystem:console /libpath:"..\..\Glut" - -!ELSEIF "$(CFG)" == "appAllBulletDemos - Win32 ReleaseDoublePrecision" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries -# PROP BASE Output_Dir "release_dbl" -# PROP BASE Intermediate_Dir "release_dbl" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries -# PROP Output_Dir "..\..\out\release_dbl6\build\appAllBulletDemos\" -# PROP Intermediate_Dir "..\..\out\release_dbl6\build\appAllBulletDemos\" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /vmb /vms /W3 /Gm /G5 /D "WIN32" /FD /c -# ADD CPP /nologo /vmb /vms /W3 /Gm /G5 /FD /c /D "_MT" /D "_MBCS" /D "NDEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" -# ADD BASE MTL /nologo /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "NDEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" -# ADD BASE RSC /l 0x409 -# ADD RSC /l 0x409 /fo".\..\..\out\release_dbl6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo -LINK32=link.exe -# ADD BASE LINK32 user32.lib gdi32.lib advapi32.lib /nologo /machine:I386 -# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /machine:I386 /out:"..\..\AllBulletDemos.exe" /subsystem:console /libpath:"..\..\Glut" +# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /out:"..\..\AllBulletDemos.exe" /libpath:"..\..\Glut" !ELSEIF "$(CFG)" == "appAllBulletDemos - Win32 Debug" @@ -101,58 +72,90 @@ LINK32=link.exe # PROP Intermediate_Dir "..\..\out\debug6\build\appAllBulletDemos\" # PROP Ignore_Export_Lib 1 # PROP Target_Dir "" -# ADD BASE CPP /nologo /vmb /vms /W3 /Gm /G5 /D "WIN32" /FD /c -# ADD CPP /nologo /vmb /vms /W3 /Gm /G5 /FD /c /GR /MDd /ZI /Od /D "_MT" /D "_MBCS" /D "_DEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo +MTL=midl.exe # ADD BASE MTL /nologo /mktyplib203 /o "NUL" /win32 # ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "_DEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" +# ADD BASE CPP /nologo /G5 /W3 /D "WIN32" /FD /c +# ADD CPP /nologo /G5 /MDd /W3 /Gm /GR /ZI /Od /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" /D "_MT" /D "_MBCS" /D "_DEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /FD /Zm1000 /c # ADD BASE RSC /l 0x409 # ADD RSC /l 0x409 /fo".\..\..\out\debug6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo LINK32=link.exe # ADD BASE LINK32 user32.lib gdi32.lib advapi32.lib /nologo /machine:I386 -# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /machine:I386 /debug /pdbtype:sept /out:"..\..\AllBulletDemos.exe" /subsystem:console /libpath:"..\..\Glut" +# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /subsystem:console /debug /machine:I386 /out:"..\..\AllBulletDemos.exe" /pdbtype:sept /libpath:"..\..\Glut" -!ELSEIF "$(CFG)" == "appAllBulletDemos - Win32 DebugDoublePrecision" +!ELSEIF "$(CFG)" == "appAllBulletDemos - Win32 ReleaseDoublePrecision" # PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries -# PROP BASE Output_Dir "debug_dbl" -# PROP BASE Intermediate_Dir "debug_dbl" +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "release_dbl" +# PROP BASE Intermediate_Dir "release_dbl" # PROP BASE Target_Dir "" # PROP Use_MFC 0 -# PROP Use_Debug_Libraries -# PROP Output_Dir "..\..\out\debug_dbl6\build\appAllBulletDemos\" -# PROP Intermediate_Dir "..\..\out\debug_dbl6\build\appAllBulletDemos\" +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\out\release_dbl6\build\appAllBulletDemos\" +# PROP Intermediate_Dir "..\..\out\release_dbl6\build\appAllBulletDemos\" # PROP Target_Dir "" -# ADD BASE CPP /nologo /vmb /vms /W3 /Gm /G5 /D "WIN32" /FD /c -# ADD CPP /nologo /vmb /vms /W3 /Gm /G5 /FD /c /D "_MT" /D "_MBCS" /D "_DEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo +MTL=midl.exe # ADD BASE MTL /nologo /mktyplib203 /o "NUL" /win32 -# ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "_DEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" +# ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "NDEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" +# ADD BASE CPP /nologo /G5 /W3 /D "WIN32" /FD /c +# ADD CPP /nologo /G5 /W3 /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" /D "_MT" /D "_MBCS" /D "NDEBUG" /D "BT_USE_DOUBLE_PRECISION" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /FD /c # ADD BASE RSC /l 0x409 -# ADD RSC /l 0x409 /fo".\..\..\out\debug_dbl6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" +# ADD RSC /l 0x409 /fo".\..\..\out\release_dbl6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo LINK32=link.exe # ADD BASE LINK32 user32.lib gdi32.lib advapi32.lib /nologo /machine:I386 -# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /machine:I386 /out:"..\..\AllBulletDemos.exe" /subsystem:console /libpath:"..\..\Glut" +# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /out:"..\..\AllBulletDemos.exe" /libpath:"..\..\Glut" + +!ELSEIF "$(CFG)" == "appAllBulletDemos - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "release" +# PROP BASE Intermediate_Dir "release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "..\..\out\release6\build\appAllBulletDemos\" +# PROP Intermediate_Dir "..\..\out\release6\build\appAllBulletDemos\" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +LIB32=link.exe -lib +# ADD BASE LIB32 /nologo +# ADD LIB32 /nologo +MTL=midl.exe +# ADD BASE MTL /nologo /mktyplib203 /o "NUL" /win32 +# ADD MTL /nologo /mktyplib203 /o "NUL" /win32 /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" +# ADD BASE CPP /nologo /G5 /W3 /D "WIN32" /FD /c +# ADD CPP /nologo /G5 /MD /W3 /Ot /Og /Oi /Oy /Ob2 /Gy /I "." /I "..\.." /I "..\..\src" /I "..\..\Glut" /I "..\..\Extras" /I "..\..\Extras\ConvexHull" /I "..\..\Demos\OpenGL" /I "..\..\Extras\ConvexDecomposition" /I "..\..\Extras\GIMPACT\include" /I "..\..\Extras\GIMPACTUtils" /D "_MT" /D "_MBCS" /D "NDEBUG" /D "_CONSOLE" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" /FR /FD /GF /Zm1000 /c +# ADD BASE RSC /l 0x409 +# ADD RSC /l 0x409 /fo".\..\..\out\release6\build\appAllBulletDemos\appAllBulletDemos.res" /i "." /i "..\.." /i "..\..\src" /i "..\..\Glut" /i "..\..\Extras" /i "..\..\Extras\ConvexHull" /i "..\..\Demos\OpenGL" /i "..\..\Extras\ConvexDecomposition" /i "..\..\Extras\GIMPACT\include" /i "..\..\Extras\GIMPACTUtils" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 user32.lib gdi32.lib advapi32.lib /nologo /machine:I386 +# ADD LINK32 shell32.lib user32.lib gdi32.lib advapi32.lib glut32.lib /nologo /version:4.0 /subsystem:console /machine:I386 /out:"..\..\AllBulletDemos.exe" /libpath:"..\..\Glut" /OPT:NOREF !ENDIF # Begin Target -# Name "appAllBulletDemos - Win32 Release" -# Name "appAllBulletDemos - Win32 ReleaseDoublePrecision" -# Name "appAllBulletDemos - Win32 Debug" # Name "appAllBulletDemos - Win32 DebugDoublePrecision" +# Name "appAllBulletDemos - Win32 Debug" +# Name "appAllBulletDemos - Win32 ReleaseDoublePrecision" +# Name "appAllBulletDemos - Win32 Release" # Begin Group "Source Files" # PROP Default_Filter "" @@ -202,7 +205,7 @@ SOURCE=..\..\Demos\AllBulletDemos\..\ConvexDecompositionDemo\ConvexDecomposition # End Source File # Begin Source File -SOURCE=..\..\Demos\AllBulletDemos\..\DynamicControlDemo\MotorDemo.cpp +SOURCE=..\..\Demos\AllBulletDemos\DemoEntries.cpp # End Source File # Begin Source File @@ -214,6 +217,14 @@ SOURCE=..\..\Demos\AllBulletDemos\..\GjkConvexCastDemo\LinearConvexCastDemo.cpp # End Source File # Begin Source File +SOURCE=..\..\Demos\AllBulletDemos\Main.cpp +# End Source File +# Begin Source File + +SOURCE=..\..\Demos\AllBulletDemos\..\DynamicControlDemo\MotorDemo.cpp +# End Source File +# Begin Source File + SOURCE=..\..\Demos\AllBulletDemos\..\RagdollDemo\RagdollDemo.cpp # End Source File # Begin Source File @@ -232,14 +243,6 @@ SOURCE=..\..\Demos\AllBulletDemos\..\SoftDemo\SoftDemo.cpp SOURCE=..\..\Demos\AllBulletDemos\..\VehicleDemo\VehicleDemo.cpp # End Source File -# Begin Source File - -SOURCE=..\..\Demos\AllBulletDemos\DemoEntries.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Demos\AllBulletDemos\Main.cpp -# End Source File # End Group # Begin Group "Header Files" diff --git a/src/BulletCollision/BroadphaseCollision/btDbvt.cpp b/src/BulletCollision/BroadphaseCollision/btDbvt.cpp index f5d94c353..2630ceb29 100644 --- a/src/BulletCollision/BroadphaseCollision/btDbvt.cpp +++ b/src/BulletCollision/BroadphaseCollision/btDbvt.cpp @@ -1,1165 +1,1166 @@ -/* -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. -*/ -///btDbvt implementation by Nathanael Presson - -#include "btDbvt.h" - -// -typedef btAlignedObjectArray tNodeArray; -typedef btAlignedObjectArray tConstNodeArray; - -// -struct btDbvtNodeEnumerator : btDbvt::ICollide -{ -tConstNodeArray nodes; -void Process(const btDbvt::Node* n) { nodes.push_back(n); } -}; - -// -static inline int indexof(const btDbvt::Node* node) -{ -return(node->parent->childs[1]==node); -} - -// -static inline btDbvt::Volume merge( const btDbvt::Volume& a, - const btDbvt::Volume& b) -{ -btDbvt::Volume res; -Merge(a,b,res); -return(res); -} - -// volume+edge lengths -static inline btScalar size(const btDbvt::Volume& a) -{ -const btVector3 edges=a.Lengths(); -return( edges.x()*edges.y()*edges.z()+ - edges.x()+edges.y()+edges.z()); -} - -// -static inline void deletenode( btDbvt* pdbvt, - btDbvt::Node* node) -{ -btAlignedFree(pdbvt->m_free); -pdbvt->m_free=node; -} - -// -static inline void recursedeletenode( btDbvt* pdbvt, - btDbvt::Node* node) -{ -if(!node->isleaf()) - { - recursedeletenode(pdbvt,node->childs[0]); - recursedeletenode(pdbvt,node->childs[1]); - } -if(node==pdbvt->m_root) pdbvt->m_root=0; -deletenode(pdbvt,node); -} - -// -static inline btDbvt::Node* createnode( btDbvt* pdbvt, - btDbvt::Node* parent, - const btDbvt::Volume& volume, - void* data) -{ -btDbvt::Node* node; -if(pdbvt->m_free) - { node=pdbvt->m_free;pdbvt->m_free=0; } - else - { node=new(btAlignedAlloc(sizeof(btDbvt::Node),16)) btDbvt::Node(); } -node->parent = parent; -node->volume = volume; -node->data = data; -node->childs[1] = 0; -return(node); -} - -// -static inline void insertleaf( btDbvt* pdbvt, - btDbvt::Node* root, - btDbvt::Node* leaf) -{ -if(!pdbvt->m_root) - { - pdbvt->m_root = leaf; - leaf->parent = 0; - } - else - { - if(!root->isleaf()) - { - do { - if( Proximity(root->childs[0]->volume,leaf->volume)< - Proximity(root->childs[1]->volume,leaf->volume)) - root=root->childs[0]; - else - root=root->childs[1]; - } while(!root->isleaf()); - } - btDbvt::Node* prev=root->parent; - btDbvt::Node* node=createnode(pdbvt,prev,merge(leaf->volume,root->volume),0); - if(prev) - { - prev->childs[indexof(root)] = node; - node->childs[0] = root;root->parent=node; - node->childs[1] = leaf;leaf->parent=node; - do { - if(!prev->volume.Contain(node->volume)) - Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume); - else - break; - node=prev; - } while(0!=(prev=node->parent)); - } - else - { - node->childs[0] = root;root->parent=node; - node->childs[1] = leaf;leaf->parent=node; - pdbvt->m_root = node; - } - } -} - -// -static inline btDbvt::Node* removeleaf( btDbvt* pdbvt, - btDbvt::Node* leaf) -{ -if(leaf==pdbvt->m_root) - { - pdbvt->m_root=0; - return(0); - } - else - { - btDbvt::Node* parent=leaf->parent; - btDbvt::Node* prev=parent->parent; - btDbvt::Node* sibling=parent->childs[1-indexof(leaf)]; - if(prev) - { - prev->childs[indexof(parent)]=sibling; - sibling->parent=prev; - deletenode(pdbvt,parent); - while(prev) - { - const btDbvt::Volume pb=prev->volume; - Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume); - if(NotEqual(pb,prev->volume)) - { - prev=prev->parent; - } else break; - } - return(prev?prev:pdbvt->m_root); - } - else - { - pdbvt->m_root=sibling; - sibling->parent=0; - deletenode(pdbvt,parent); - return(pdbvt->m_root); - } - } -} - -// -static void fetchleaves(btDbvt* pdbvt, - btDbvt::Node* root, - tNodeArray& leaves, - int depth=-1) -{ -if(root->isinternal()&&depth) - { - fetchleaves(pdbvt,root->childs[0],leaves,depth-1); - fetchleaves(pdbvt,root->childs[1],leaves,depth-1); - deletenode(pdbvt,root); - } - else - { - leaves.push_back(root); - } -} - -// -static void split( const tNodeArray& leaves, - tNodeArray& left, - tNodeArray& right, - const btVector3& org, - const btVector3& axis) -{ -left.resize(0); -right.resize(0); -for(int i=0,ni=leaves.size();ivolume.Center()-org)<0) - left.push_back(leaves[i]); - else - right.push_back(leaves[i]); - } -} - -// -static btDbvt::Volume bounds( const tNodeArray& leaves) -{ -btDbvt::Volume volume=leaves[0]->volume; -for(int i=1,ni=leaves.size();ivolume); - } -return(volume); -} - -// -static void bottomup( btDbvt* pdbvt, - tNodeArray& leaves) -{ -while(leaves.size()>1) - { - btScalar minsize=SIMD_INFINITY; - int minidx[2]={-1,-1}; - for(int i=0;ivolume,leaves[j]->volume)); - if(szvolume,n[1]->volume),0); - p->childs[0] = n[0]; - p->childs[1] = n[1]; - n[0]->parent = p; - n[1]->parent = p; - leaves[minidx[0]] = p; - leaves.swap(minidx[1],leaves.size()-1); - leaves.pop_back(); - } -} - -// -static btDbvt::Node* topdown(btDbvt* pdbvt, - tNodeArray& leaves, - int bu_treshold) -{ -static const btVector3 axis[]={btVector3(1,0,0), - btVector3(0,1,0), - btVector3(0,0,1)}; -if(leaves.size()>1) - { - if(leaves.size()>bu_treshold) - { - const btDbvt::Volume vol=bounds(leaves); - const btVector3 org=vol.Center(); - tNodeArray sets[2]; - int bestaxis=-1; - int bestmidp=leaves.size(); - int splitcount[3][2]={{0,0},{0,0},{0,0}}; - for(int i=0;ivolume.Center()-org; - for(int j=0;j<3;++j) - { - ++splitcount[j][dot(x,axis[j])>0?1:0]; - } - } - for(int i=0;i<3;++i) - { - if((splitcount[i][0]>0)&&(splitcount[i][1]>0)) - { - const int midp=(int)btFabs(btScalar(splitcount[i][0]-splitcount[i][1])); - if(midp=0) - { - sets[0].reserve(splitcount[bestaxis][0]); - sets[1].reserve(splitcount[bestaxis][1]); - split(leaves,sets[0],sets[1],org,axis[bestaxis]); - } - else - { - sets[0].reserve(leaves.size()/2+1); - sets[1].reserve(leaves.size()/2); - for(int i=0,ni=leaves.size();ichilds[0]=topdown(pdbvt,sets[0],bu_treshold); - node->childs[1]=topdown(pdbvt,sets[1],bu_treshold); - node->childs[0]->parent=node; - node->childs[1]->parent=node; - return(node); - } - else - { - bottomup(pdbvt,leaves); - return(leaves[0]); - } - } -return(leaves[0]); -} - -// -static inline btDbvt::Node* sort(btDbvt::Node* n,btDbvt::Node*& r) -{ -btDbvt::Node* p=n->parent; -btAssert(n->isinternal()); -if(p>n) - { - const int i=indexof(n); - const int j=1-i; - btDbvt::Node* s=p->childs[j]; - btDbvt::Node* q=p->parent; - btAssert(n==p->childs[i]); - if(q) q->childs[indexof(p)]=n; else r=n; - s->parent=n; - p->parent=n; - n->parent=q; - p->childs[0]=n->childs[0]; - p->childs[1]=n->childs[1]; - n->childs[0]->parent=p; - n->childs[1]->parent=p; - n->childs[i]=p; - n->childs[j]=s; - btSwap(p->volume,n->volume); - return(p); - } -return(n); -} - -// -static inline btDbvt::Node* walkup(btDbvt::Node* n,int count) -{ -while(n&&(count--)) n=n->parent; -return(n); -} - -// -// Api -// - -// - btDbvt::btDbvt() -{ -m_root = 0; -m_free = 0; -m_lkhd = -1; -m_leaves = 0; -m_opath = 0; -} - -// - btDbvt::~btDbvt() -{ -clear(); -} - -// -void btDbvt::clear() -{ -if(m_root) recursedeletenode(this,m_root); -btAlignedFree(m_free); -m_free=0; -} - -// -void btDbvt::optimizeBottomUp() -{ -if(m_root) - { - tNodeArray leaves; - leaves.reserve(m_leaves); - fetchleaves(this,m_root,leaves); - bottomup(this,leaves); - m_root=leaves[0]; - } -} - -// -void btDbvt::optimizeTopDown(int bu_treshold) -{ -if(m_root) - { - tNodeArray leaves; - leaves.reserve(m_leaves); - fetchleaves(this,m_root,leaves); - m_root=topdown(this,leaves,bu_treshold); - } -} - -// -void btDbvt::optimizeIncremental(int passes) -{ -if(passes<0) passes=m_leaves; -if(m_root&&(passes>0)) - { - do { - Node* node=m_root; - unsigned bit=0; - while(node->isinternal()) - { - node=sort(node,m_root)->childs[(m_opath>>bit)&1]; - bit=(bit+1)&(sizeof(unsigned)*8-1); - } - update(node); - ++m_opath; - } while(--passes); - } -} - -// -btDbvt::Node* btDbvt::insert(const Volume& volume,void* data) -{ -Node* leaf=createnode(this,0,volume,data); -insertleaf(this,m_root,leaf); -++m_leaves; -return(leaf); -} - -// -void btDbvt::update(Node* leaf,int lookahead) -{ -Node* root=removeleaf(this,leaf); -if(root) - { - if(lookahead>=0) - { - for(int i=0;(iparent;++i) - { - root=root->parent; - } - } else root=m_root; - } -insertleaf(this,root,leaf); -} - -// -void btDbvt::update(Node* leaf,const Volume& volume) -{ -Node* root=removeleaf(this,leaf); -if(root) - { - if(m_lkhd>=0) - { - for(int i=0;(iparent;++i) - { - root=root->parent; - } - } else root=m_root; - } -leaf->volume=volume; -insertleaf(this,root,leaf); -} - -// -bool btDbvt::update(Node* leaf,Volume volume,const btVector3& velocity,btScalar margin) -{ -if(leaf->volume.Contain(volume)) return(false); -volume.Expand(btVector3(margin,margin,margin)); -volume.SignedExpand(velocity); -update(leaf,volume); -return(true); -} - -// -bool btDbvt::update(Node* leaf,Volume volume,const btVector3& velocity) -{ -if(leaf->volume.Contain(volume)) return(false); -volume.SignedExpand(velocity); -update(leaf,volume); -return(true); -} - -// -bool btDbvt::update(Node* leaf,Volume volume,btScalar margin) -{ -if(leaf->volume.Contain(volume)) return(false); -volume.Expand(btVector3(margin,margin,margin)); -update(leaf,volume); -return(true); -} - -// -void btDbvt::remove(Node* leaf) -{ -removeleaf(this,leaf); -deletenode(this,leaf); ---m_leaves; -} - -// -void btDbvt::write(IWriter* iwriter) const -{ -btDbvtNodeEnumerator nodes; -nodes.nodes.reserve(m_leaves*2); -enumNodes(m_root,nodes); -iwriter->Prepare(m_root,nodes.nodes.size()); -for(int i=0;iparent) p=nodes.nodes.findLinearSearch(n->parent); - if(n->isinternal()) - { - const int c0=nodes.nodes.findLinearSearch(n->childs[0]); - const int c1=nodes.nodes.findLinearSearch(n->childs[1]); - iwriter->WriteNode(n,i,p,c0,c1); - } - else - { - iwriter->WriteLeaf(n,i,p); - } - } -} - -// -void btDbvt::clone(btDbvt& dest,IClone* iclone) const -{ -dest.clear(); -if(m_root!=0) - { - btAlignedObjectArray stack; - stack.reserve(m_leaves); - stack.push_back(sStkCLN(m_root,0)); - do { - const int i=stack.size()-1; - const sStkCLN e=stack[i]; - Node* n=createnode(&dest,e.parent,e.node->volume,e.node->data); - stack.pop_back(); - if(e.parent!=0) - e.parent->childs[i&1]=n; - else - dest.m_root=n; - if(e.node->isinternal()) - { - stack.push_back(sStkCLN(e.node->childs[0],n)); - stack.push_back(sStkCLN(e.node->childs[1],n)); - } - else - { - iclone->CloneLeaf(n); - } - } while(stack.size()>0); - } -} - -// -int btDbvt::countLeaves(const Node* node) -{ -if(node->isinternal()) - return(countLeaves(node->childs[0])+countLeaves(node->childs[1])); - else - return(1); -} - -// -void btDbvt::extractLeaves(const Node* node,btAlignedObjectArray& leaves) -{ -if(node->isinternal()) - { - extractLeaves(node->childs[0],leaves); - extractLeaves(node->childs[1],leaves); - } - else - { - leaves.push_back(node); - } -} - -// -#if DBVT_ENABLE_BENCHMARK - -#include -#include -#include "LinearMath/btQuickProf.h" - -/* -q6600,2.4ghz - -/Ox /Ob2 /Oi /Ot /I "." /I "..\.." /I "..\..\src" /D "NDEBUG" /D "_LIB" /D "_WINDOWS" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" -/GF /FD /MT /GS- /Gy /arch:SSE2 /Zc:wchar_t- /Fp"..\..\out\release8\build\libbulletcollision\libbulletcollision.pch" -/Fo"..\..\out\release8\build\libbulletcollision\\" -/Fd"..\..\out\release8\build\libbulletcollision\bulletcollision.pdb" -/W3 /nologo /c /Wp64 /Zi /errorReport:prompt - -Benchmarking dbvt... - World scale: 100.000000 - Extents base: 1.000000 - Extents range: 4.000000 - Leaves: 8192 -[1] btDbvt::Volume intersections: 3986 ms (0%) -[2] btDbvt::Volume merges: 5815 ms (-1%) -[3] btDbvt::collideTT: 3267 ms (0%) -[4] btDbvt::collideTT self: 1657 ms (0%) -[5] btDbvt::collideTT xform: 7201 ms (0%) -[6] btDbvt::collideTT xform,self: 7382 ms (0%) -[7] btDbvt::collideRAY: 8855 ms (-1%),(236832 r/s) -[8] insert/remove: 3574 ms (0%),(586780 ir/s) -[9] updates (teleport): 3281 ms (0%),(639180 u/s) -[10] updates (jitter): 2658 ms (0%),(788996 u/s) -[11] optimize (incremental): 5091 ms (0%),(823000 o/s) -[12] btDbvt::Volume notequal: 4151 ms (0%) -[13] culling(OCL): 2486 ms (0%),(411 t/s) -[14] culling(OCL+qsort): 599 ms (-2%),(1709 t/s) -[15] culling(KDOP+qsort): 306 ms (0%),(3346 t/s) -*/ - -struct btDbvtBenchmark -{ -struct NilPolicy : btDbvt::ICollide - { - NilPolicy() : m_pcount(0),m_depth(-SIMD_INFINITY),m_checksort(true) {} - void Process(const btDbvt::Node*,const btDbvt::Node*) { ++m_pcount; } - void Process(const btDbvt::Node*) { ++m_pcount; } - void Process(const btDbvt::Node*,btScalar depth) - { - ++m_pcount; - if(m_checksort) - { if(depth>=m_depth) m_depth=depth; else printf("wrong depth: %f\r\n",depth); } - } - int m_pcount; - btScalar m_depth; - bool m_checksort; - }; -struct P14 : btDbvt::ICollide - { - struct Node - { - const btDbvt::Node* leaf; - btScalar depth; - }; - void Process(const btDbvt::Node* leaf,btScalar depth) - { - Node n; - n.leaf = leaf; - n.depth = depth; - } - static int sortfnc(const Node& a,const Node& b) - { - if(a.depthb.depth) return(-1); - return(0); - } - btAlignedObjectArray m_nodes; - }; -struct P15 : btDbvt::ICollide - { - struct Node - { - const btDbvt::Node* leaf; - btScalar depth; - }; - void Process(const btDbvt::Node* leaf) - { - Node n; - n.leaf = leaf; - n.depth = dot(leaf->volume.Center(),m_axis); - } - static int sortfnc(const Node& a,const Node& b) - { - if(a.depthb.depth) return(-1); - return(0); - } - btAlignedObjectArray m_nodes; - btVector3 m_axis; - }; -static btScalar RandUnit() - { - return(rand()/(btScalar)RAND_MAX); - } -static btVector3 RandVector3() - { - return(btVector3(RandUnit(),RandUnit(),RandUnit())); - } -static btVector3 RandVector3(btScalar cs) - { - return(RandVector3()*cs-btVector3(cs,cs,cs)/2); - } -static btDbvt::Volume RandVolume(btScalar cs,btScalar eb,btScalar es) - { - return(btDbvt::Volume::FromCE(RandVector3(cs),btVector3(eb,eb,eb)+RandVector3()*es)); - } -static btTransform RandTransform(btScalar cs) - { - btTransform t; - t.setOrigin(RandVector3(cs)); - t.setRotation(btQuaternion(RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2).normalized()); - return(t); - } -static void RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& dbvt) - { - dbvt.clear(); - for(int i=0;i volumes; - btAlignedObjectArray results; - volumes.resize(cfgLeaves); - results.resize(cfgLeaves); - for(int i=0;i volumes; - btAlignedObjectArray results; - volumes.resize(cfgLeaves); - results.resize(cfgLeaves); - for(int i=0;i transforms; - btDbvtBenchmark::NilPolicy policy; - transforms.resize(cfgBenchmark5_Iterations); - for(int i=0;i transforms; - btDbvtBenchmark::NilPolicy policy; - transforms.resize(cfgBenchmark6_Iterations); - for(int i=0;i rayorg; - btAlignedObjectArray raydir; - btDbvtBenchmark::NilPolicy policy; - rayorg.resize(cfgBenchmark7_Iterations); - raydir.resize(cfgBenchmark7_Iterations); - for(int i=0;i leaves; - btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt); - dbvt.optimizeTopDown(); - dbvt.extractLeaves(dbvt.m_root,leaves); - printf("[9] updates (teleport): "); - wallclock.reset(); - for(int i=0;i(leaves[rand()%cfgLeaves]), - btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale)); - } - } - const int time=(int)wallclock.getTimeMilliseconds(); - const int up=cfgBenchmark9_Passes*cfgBenchmark9_Iterations; - printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark9_Reference)*100/time,up*1000/time); - } -if(cfgBenchmark10_Enable) - {// Benchmark 10 - srand(380843); - btDbvt dbvt; - btAlignedObjectArray leaves; - btAlignedObjectArray vectors; - vectors.resize(cfgBenchmark10_Iterations); - for(int i=0;i(leaves[rand()%cfgLeaves]); - btDbvt::Volume v=btDbvt::Volume::FromMM(l->volume.Mins()+d,l->volume.Maxs()+d); - dbvt.update(l,v); - } - } - const int time=(int)wallclock.getTimeMilliseconds(); - const int up=cfgBenchmark10_Passes*cfgBenchmark10_Iterations; - printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark10_Reference)*100/time,up*1000/time); - } -if(cfgBenchmark11_Enable) - {// Benchmark 11 - srand(380843); - btDbvt dbvt; - btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt); - dbvt.optimizeTopDown(); - printf("[11] optimize (incremental): "); - wallclock.reset(); - for(int i=0;i volumes; - btAlignedObjectArray results; - volumes.resize(cfgLeaves); - results.resize(cfgLeaves); - for(int i=0;i vectors; - btDbvtBenchmark::NilPolicy policy; - vectors.resize(cfgBenchmark13_Iterations); - for(int i=0;i vectors; - btDbvtBenchmark::P14 policy; - vectors.resize(cfgBenchmark14_Iterations); - for(int i=0;i vectors; - btDbvtBenchmark::P15 policy; - vectors.resize(cfgBenchmark15_Iterations); - for(int i=0;i tNodeArray; +typedef btAlignedObjectArray tConstNodeArray; + +// +struct btDbvtNodeEnumerator : btDbvt::ICollide +{ +tConstNodeArray nodes; +void Process(const btDbvtNode* n) { nodes.push_back(n); } +}; + +// +static inline int indexof(const btDbvtNode* node) +{ +return(node->parent->childs[1]==node); +} + +// +static inline btDbvtVolume merge( const btDbvtVolume& a, + const btDbvtVolume& b) +{ +btDbvtVolume res; +Merge(a,b,res); +return(res); +} + +// volume+edge lengths +static inline btScalar size(const btDbvtVolume& a) +{ +const btVector3 edges=a.Lengths(); +return( edges.x()*edges.y()*edges.z()+ + edges.x()+edges.y()+edges.z()); +} + +// +static inline void deletenode( btDbvt* pdbvt, + btDbvtNode* node) +{ +btAlignedFree(pdbvt->m_free); +pdbvt->m_free=node; +} + +// +static inline void recursedeletenode( btDbvt* pdbvt, + btDbvtNode* node) +{ +if(!node->isleaf()) + { + recursedeletenode(pdbvt,node->childs[0]); + recursedeletenode(pdbvt,node->childs[1]); + } +if(node==pdbvt->m_root) pdbvt->m_root=0; +deletenode(pdbvt,node); +} + +// +static inline btDbvtNode* createnode( btDbvt* pdbvt, + btDbvtNode* parent, + const btDbvtVolume& volume, + void* data) +{ +btDbvtNode* node; +if(pdbvt->m_free) + { node=pdbvt->m_free;pdbvt->m_free=0; } + else + { node=new(btAlignedAlloc(sizeof(btDbvtNode),16)) btDbvtNode(); } +node->parent = parent; +node->volume = volume; +node->data = data; +node->childs[1] = 0; +return(node); +} + +// +static inline void insertleaf( btDbvt* pdbvt, + btDbvtNode* root, + btDbvtNode* leaf) +{ +if(!pdbvt->m_root) + { + pdbvt->m_root = leaf; + leaf->parent = 0; + } + else + { + if(!root->isleaf()) + { + do { + if( Proximity(root->childs[0]->volume,leaf->volume)< + Proximity(root->childs[1]->volume,leaf->volume)) + root=root->childs[0]; + else + root=root->childs[1]; + } while(!root->isleaf()); + } + btDbvtNode* prev=root->parent; + btDbvtNode* node=createnode(pdbvt,prev,merge(leaf->volume,root->volume),0); + if(prev) + { + prev->childs[indexof(root)] = node; + node->childs[0] = root;root->parent=node; + node->childs[1] = leaf;leaf->parent=node; + do { + if(!prev->volume.Contain(node->volume)) + Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume); + else + break; + node=prev; + } while(0!=(prev=node->parent)); + } + else + { + node->childs[0] = root;root->parent=node; + node->childs[1] = leaf;leaf->parent=node; + pdbvt->m_root = node; + } + } +} + +// +static inline btDbvtNode* removeleaf( btDbvt* pdbvt, + btDbvtNode* leaf) +{ +if(leaf==pdbvt->m_root) + { + pdbvt->m_root=0; + return(0); + } + else + { + btDbvtNode* parent=leaf->parent; + btDbvtNode* prev=parent->parent; + btDbvtNode* sibling=parent->childs[1-indexof(leaf)]; + if(prev) + { + prev->childs[indexof(parent)]=sibling; + sibling->parent=prev; + deletenode(pdbvt,parent); + while(prev) + { + const btDbvtVolume pb=prev->volume; + Merge(prev->childs[0]->volume,prev->childs[1]->volume,prev->volume); + if(NotEqual(pb,prev->volume)) + { + prev=prev->parent; + } else break; + } + return(prev?prev:pdbvt->m_root); + } + else + { + pdbvt->m_root=sibling; + sibling->parent=0; + deletenode(pdbvt,parent); + return(pdbvt->m_root); + } + } +} + +// +static void fetchleaves(btDbvt* pdbvt, + btDbvtNode* root, + tNodeArray& leaves, + int depth=-1) +{ +if(root->isinternal()&&depth) + { + fetchleaves(pdbvt,root->childs[0],leaves,depth-1); + fetchleaves(pdbvt,root->childs[1],leaves,depth-1); + deletenode(pdbvt,root); + } + else + { + leaves.push_back(root); + } +} + +// +static void split( const tNodeArray& leaves, + tNodeArray& left, + tNodeArray& right, + const btVector3& org, + const btVector3& axis) +{ +left.resize(0); +right.resize(0); +for(int i=0,ni=leaves.size();ivolume.Center()-org)<0) + left.push_back(leaves[i]); + else + right.push_back(leaves[i]); + } +} + +// +static btDbvtVolume bounds( const tNodeArray& leaves) +{ +btDbvtVolume volume=leaves[0]->volume; +for(int i=1,ni=leaves.size();ivolume); + } +return(volume); +} + +// +static void bottomup( btDbvt* pdbvt, + tNodeArray& leaves) +{ +while(leaves.size()>1) + { + btScalar minsize=SIMD_INFINITY; + int minidx[2]={-1,-1}; + for(int i=0;ivolume,leaves[j]->volume)); + if(szvolume,n[1]->volume),0); + p->childs[0] = n[0]; + p->childs[1] = n[1]; + n[0]->parent = p; + n[1]->parent = p; + leaves[minidx[0]] = p; + leaves.swap(minidx[1],leaves.size()-1); + leaves.pop_back(); + } +} + +// +static btDbvtNode* topdown(btDbvt* pdbvt, + tNodeArray& leaves, + int bu_treshold) +{ +static const btVector3 axis[]={btVector3(1,0,0), + btVector3(0,1,0), + btVector3(0,0,1)}; +if(leaves.size()>1) + { + if(leaves.size()>bu_treshold) + { + const btDbvtVolume vol=bounds(leaves); + const btVector3 org=vol.Center(); + tNodeArray sets[2]; + int bestaxis=-1; + int bestmidp=leaves.size(); + int splitcount[3][2]={{0,0},{0,0},{0,0}}; + int i; + for( i=0;ivolume.Center()-org; + for(int j=0;j<3;++j) + { + ++splitcount[j][dot(x,axis[j])>0?1:0]; + } + } + for( i=0;i<3;++i) + { + if((splitcount[i][0]>0)&&(splitcount[i][1]>0)) + { + const int midp=(int)btFabs(btScalar(splitcount[i][0]-splitcount[i][1])); + if(midp=0) + { + sets[0].reserve(splitcount[bestaxis][0]); + sets[1].reserve(splitcount[bestaxis][1]); + split(leaves,sets[0],sets[1],org,axis[bestaxis]); + } + else + { + sets[0].reserve(leaves.size()/2+1); + sets[1].reserve(leaves.size()/2); + for(int i=0,ni=leaves.size();ichilds[0]=topdown(pdbvt,sets[0],bu_treshold); + node->childs[1]=topdown(pdbvt,sets[1],bu_treshold); + node->childs[0]->parent=node; + node->childs[1]->parent=node; + return(node); + } + else + { + bottomup(pdbvt,leaves); + return(leaves[0]); + } + } +return(leaves[0]); +} + +// +static inline btDbvtNode* sort(btDbvtNode* n,btDbvtNode*& r) +{ +btDbvtNode* p=n->parent; +btAssert(n->isinternal()); +if(p>n) + { + const int i=indexof(n); + const int j=1-i; + btDbvtNode* s=p->childs[j]; + btDbvtNode* q=p->parent; + btAssert(n==p->childs[i]); + if(q) q->childs[indexof(p)]=n; else r=n; + s->parent=n; + p->parent=n; + n->parent=q; + p->childs[0]=n->childs[0]; + p->childs[1]=n->childs[1]; + n->childs[0]->parent=p; + n->childs[1]->parent=p; + n->childs[i]=p; + n->childs[j]=s; + btSwap(p->volume,n->volume); + return(p); + } +return(n); +} + +// +static inline btDbvtNode* walkup(btDbvtNode* n,int count) +{ +while(n&&(count--)) n=n->parent; +return(n); +} + +// +// Api +// + +// + btDbvt::btDbvt() +{ +m_root = 0; +m_free = 0; +m_lkhd = -1; +m_leaves = 0; +m_opath = 0; +} + +// + btDbvt::~btDbvt() +{ +clear(); +} + +// +void btDbvt::clear() +{ +if(m_root) recursedeletenode(this,m_root); +btAlignedFree(m_free); +m_free=0; +} + +// +void btDbvt::optimizeBottomUp() +{ +if(m_root) + { + tNodeArray leaves; + leaves.reserve(m_leaves); + fetchleaves(this,m_root,leaves); + bottomup(this,leaves); + m_root=leaves[0]; + } +} + +// +void btDbvt::optimizeTopDown(int bu_treshold) +{ +if(m_root) + { + tNodeArray leaves; + leaves.reserve(m_leaves); + fetchleaves(this,m_root,leaves); + m_root=topdown(this,leaves,bu_treshold); + } +} + +// +void btDbvt::optimizeIncremental(int passes) +{ +if(passes<0) passes=m_leaves; +if(m_root&&(passes>0)) + { + do { + btDbvtNode* node=m_root; + unsigned bit=0; + while(node->isinternal()) + { + node=sort(node,m_root)->childs[(m_opath>>bit)&1]; + bit=(bit+1)&(sizeof(unsigned)*8-1); + } + update(node); + ++m_opath; + } while(--passes); + } +} + +// +btDbvtNode* btDbvt::insert(const btDbvtVolume& volume,void* data) +{ +btDbvtNode* leaf=createnode(this,0,volume,data); +insertleaf(this,m_root,leaf); +++m_leaves; +return(leaf); +} + +// +void btDbvt::update(btDbvtNode* leaf,int lookahead) +{ +btDbvtNode* root=removeleaf(this,leaf); +if(root) + { + if(lookahead>=0) + { + for(int i=0;(iparent;++i) + { + root=root->parent; + } + } else root=m_root; + } +insertleaf(this,root,leaf); +} + +// +void btDbvt::update(btDbvtNode* leaf,const btDbvtVolume& volume) +{ +btDbvtNode* root=removeleaf(this,leaf); +if(root) + { + if(m_lkhd>=0) + { + for(int i=0;(iparent;++i) + { + root=root->parent; + } + } else root=m_root; + } +leaf->volume=volume; +insertleaf(this,root,leaf); +} + +// +bool btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity,btScalar margin) +{ +if(leaf->volume.Contain(volume)) return(false); +volume.Expand(btVector3(margin,margin,margin)); +volume.SignedExpand(velocity); +update(leaf,volume); +return(true); +} + +// +bool btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity) +{ +if(leaf->volume.Contain(volume)) return(false); +volume.SignedExpand(velocity); +update(leaf,volume); +return(true); +} + +// +bool btDbvt::update(btDbvtNode* leaf,btDbvtVolume volume,btScalar margin) +{ +if(leaf->volume.Contain(volume)) return(false); +volume.Expand(btVector3(margin,margin,margin)); +update(leaf,volume); +return(true); +} + +// +void btDbvt::remove(btDbvtNode* leaf) +{ +removeleaf(this,leaf); +deletenode(this,leaf); +--m_leaves; +} + +// +void btDbvt::write(IWriter* iwriter) const +{ +btDbvtNodeEnumerator nodes; +nodes.nodes.reserve(m_leaves*2); +enumNodes(m_root,nodes); +iwriter->Prepare(m_root,nodes.nodes.size()); +for(int i=0;iparent) p=nodes.nodes.findLinearSearch(n->parent); + if(n->isinternal()) + { + const int c0=nodes.nodes.findLinearSearch(n->childs[0]); + const int c1=nodes.nodes.findLinearSearch(n->childs[1]); + iwriter->WriteNode(n,i,p,c0,c1); + } + else + { + iwriter->WriteLeaf(n,i,p); + } + } +} + +// +void btDbvt::clone(btDbvt& dest,IClone* iclone) const +{ +dest.clear(); +if(m_root!=0) + { + btAlignedObjectArray stack; + stack.reserve(m_leaves); + stack.push_back(sStkCLN(m_root,0)); + do { + const int i=stack.size()-1; + const sStkCLN e=stack[i]; + btDbvtNode* n=createnode(&dest,e.parent,e.node->volume,e.node->data); + stack.pop_back(); + if(e.parent!=0) + e.parent->childs[i&1]=n; + else + dest.m_root=n; + if(e.node->isinternal()) + { + stack.push_back(sStkCLN(e.node->childs[0],n)); + stack.push_back(sStkCLN(e.node->childs[1],n)); + } + else + { + iclone->CloneLeaf(n); + } + } while(stack.size()>0); + } +} + +// +int btDbvt::countLeaves(const btDbvtNode* node) +{ +if(node->isinternal()) + return(countLeaves(node->childs[0])+countLeaves(node->childs[1])); + else + return(1); +} + +// +void btDbvt::extractLeaves(const btDbvtNode* node,btAlignedObjectArray& leaves) +{ +if(node->isinternal()) + { + extractLeaves(node->childs[0],leaves); + extractLeaves(node->childs[1],leaves); + } + else + { + leaves.push_back(node); + } +} + +// +#if DBVT_ENABLE_BENCHMARK + +#include +#include +#include "LinearMath/btQuickProf.h" + +/* +q6600,2.4ghz + +/Ox /Ob2 /Oi /Ot /I "." /I "..\.." /I "..\..\src" /D "NDEBUG" /D "_LIB" /D "_WINDOWS" /D "_CRT_SECURE_NO_DEPRECATE" /D "_CRT_NONSTDC_NO_DEPRECATE" /D "WIN32" +/GF /FD /MT /GS- /Gy /arch:SSE2 /Zc:wchar_t- /Fp"..\..\out\release8\build\libbulletcollision\libbulletcollision.pch" +/Fo"..\..\out\release8\build\libbulletcollision\\" +/Fd"..\..\out\release8\build\libbulletcollision\bulletcollision.pdb" +/W3 /nologo /c /Wp64 /Zi /errorReport:prompt + +Benchmarking dbvt... + World scale: 100.000000 + Extents base: 1.000000 + Extents range: 4.000000 + Leaves: 8192 +[1] btDbvtVolume intersections: 3986 ms (0%) +[2] btDbvtVolume merges: 5815 ms (-1%) +[3] btDbvt::collideTT: 3267 ms (0%) +[4] btDbvt::collideTT self: 1657 ms (0%) +[5] btDbvt::collideTT xform: 7201 ms (0%) +[6] btDbvt::collideTT xform,self: 7382 ms (0%) +[7] btDbvt::collideRAY: 8855 ms (-1%),(236832 r/s) +[8] insert/remove: 3574 ms (0%),(586780 ir/s) +[9] updates (teleport): 3281 ms (0%),(639180 u/s) +[10] updates (jitter): 2658 ms (0%),(788996 u/s) +[11] optimize (incremental): 5091 ms (0%),(823000 o/s) +[12] btDbvtVolume notequal: 4151 ms (0%) +[13] culling(OCL): 2486 ms (0%),(411 t/s) +[14] culling(OCL+qsort): 599 ms (-2%),(1709 t/s) +[15] culling(KDOP+qsort): 306 ms (0%),(3346 t/s) +*/ + +struct btDbvtBenchmark +{ +struct NilPolicy : btDbvt::ICollide + { + NilPolicy() : m_pcount(0),m_depth(-SIMD_INFINITY),m_checksort(true) {} + void Process(const btDbvtNode*,const btDbvtNode*) { ++m_pcount; } + void Process(const btDbvtNode*) { ++m_pcount; } + void Process(const btDbvtNode*,btScalar depth) + { + ++m_pcount; + if(m_checksort) + { if(depth>=m_depth) m_depth=depth; else printf("wrong depth: %f\r\n",depth); } + } + int m_pcount; + btScalar m_depth; + bool m_checksort; + }; +struct P14 : btDbvt::ICollide + { + struct btDbvtNode + { + const btDbvtNode* leaf; + btScalar depth; + }; + void Process(const btDbvtNode* leaf,btScalar depth) + { + btDbvtNode n; + n.leaf = leaf; + n.depth = depth; + } + static int sortfnc(const btDbvtNode& a,const btDbvtNode& b) + { + if(a.depthb.depth) return(-1); + return(0); + } + btAlignedObjectArray m_nodes; + }; +struct P15 : btDbvt::ICollide + { + struct btDbvtNode + { + const btDbvtNode* leaf; + btScalar depth; + }; + void Process(const btDbvtNode* leaf) + { + btDbvtNode n; + n.leaf = leaf; + n.depth = dot(leaf->volume.Center(),m_axis); + } + static int sortfnc(const btDbvtNode& a,const btDbvtNode& b) + { + if(a.depthb.depth) return(-1); + return(0); + } + btAlignedObjectArray m_nodes; + btVector3 m_axis; + }; +static btScalar RandUnit() + { + return(rand()/(btScalar)RAND_MAX); + } +static btVector3 RandVector3() + { + return(btVector3(RandUnit(),RandUnit(),RandUnit())); + } +static btVector3 RandVector3(btScalar cs) + { + return(RandVector3()*cs-btVector3(cs,cs,cs)/2); + } +static btDbvtVolume RandVolume(btScalar cs,btScalar eb,btScalar es) + { + return(btDbvtVolume::FromCE(RandVector3(cs),btVector3(eb,eb,eb)+RandVector3()*es)); + } +static btTransform RandTransform(btScalar cs) + { + btTransform t; + t.setOrigin(RandVector3(cs)); + t.setRotation(btQuaternion(RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2,RandUnit()*SIMD_PI*2).normalized()); + return(t); + } +static void RandTree(btScalar cs,btScalar eb,btScalar es,int leaves,btDbvt& dbvt) + { + dbvt.clear(); + for(int i=0;i volumes; + btAlignedObjectArray results; + volumes.resize(cfgLeaves); + results.resize(cfgLeaves); + for(int i=0;i volumes; + btAlignedObjectArray results; + volumes.resize(cfgLeaves); + results.resize(cfgLeaves); + for(int i=0;i transforms; + btDbvtBenchmark::NilPolicy policy; + transforms.resize(cfgBenchmark5_Iterations); + for(int i=0;i transforms; + btDbvtBenchmark::NilPolicy policy; + transforms.resize(cfgBenchmark6_Iterations); + for(int i=0;i rayorg; + btAlignedObjectArray raydir; + btDbvtBenchmark::NilPolicy policy; + rayorg.resize(cfgBenchmark7_Iterations); + raydir.resize(cfgBenchmark7_Iterations); + for(int i=0;i leaves; + btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt); + dbvt.optimizeTopDown(); + dbvt.extractLeaves(dbvt.m_root,leaves); + printf("[9] updates (teleport): "); + wallclock.reset(); + for(int i=0;i(leaves[rand()%cfgLeaves]), + btDbvtBenchmark::RandVolume(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale)); + } + } + const int time=(int)wallclock.getTimeMilliseconds(); + const int up=cfgBenchmark9_Passes*cfgBenchmark9_Iterations; + printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark9_Reference)*100/time,up*1000/time); + } +if(cfgBenchmark10_Enable) + {// Benchmark 10 + srand(380843); + btDbvt dbvt; + btAlignedObjectArray leaves; + btAlignedObjectArray vectors; + vectors.resize(cfgBenchmark10_Iterations); + for(int i=0;i(leaves[rand()%cfgLeaves]); + btDbvtVolume v=btDbvtVolume::FromMM(l->volume.Mins()+d,l->volume.Maxs()+d); + dbvt.update(l,v); + } + } + const int time=(int)wallclock.getTimeMilliseconds(); + const int up=cfgBenchmark10_Passes*cfgBenchmark10_Iterations; + printf("%u ms (%i%%),(%u u/s)\r\n",time,(time-cfgBenchmark10_Reference)*100/time,up*1000/time); + } +if(cfgBenchmark11_Enable) + {// Benchmark 11 + srand(380843); + btDbvt dbvt; + btDbvtBenchmark::RandTree(cfgVolumeCenterScale,cfgVolumeExentsBase,cfgVolumeExentsScale,cfgLeaves,dbvt); + dbvt.optimizeTopDown(); + printf("[11] optimize (incremental): "); + wallclock.reset(); + for(int i=0;i volumes; + btAlignedObjectArray results; + volumes.resize(cfgLeaves); + results.resize(cfgLeaves); + for(int i=0;i vectors; + btDbvtBenchmark::NilPolicy policy; + vectors.resize(cfgBenchmark13_Iterations); + for(int i=0;i vectors; + btDbvtBenchmark::P14 policy; + vectors.resize(cfgBenchmark14_Iterations); + for(int i=0;i vectors; + btDbvtBenchmark::P15 policy; + vectors.resize(cfgBenchmark15_Iterations); + for(int i=0;i= 1400) #define DBVT_USE_TEMPLATE 1 // Enable template for ICollide #else +#define DBVT_USE_TEMPLATE 0 // Don't +#endif +#else #define DBVT_USE_TEMPLATE 0 // Enable template for ICollide #endif @@ -117,51 +122,55 @@ private: btVector3 mi,mx; }; +// Types +typedef btDbvtAabbMm btDbvtVolume; + +/* btDbvtNode */ +struct btDbvtNode +{ + btDbvtVolume volume; + btDbvtNode* parent; + bool isleaf() const { return(childs[1]==0); } + bool isinternal() const { return(!isleaf()); } + union { + btDbvtNode* childs[2]; + void* data; + }; +}; + // // Dynamic bounding volume tree // struct btDbvt { - // Types - typedef btDbvtAabbMm Volume; - /* Node */ - struct Node - { - Volume volume; - Node* parent; - bool isleaf() const { return(childs[1]==0); } - bool isinternal() const { return(!isleaf()); } - union { - Node* childs[2]; - void* data; - }; - }; + + /* Stack element */ struct sStkNN { - const Node* a; - const Node* b; - sStkNN(const Node* na,const Node* nb) : a(na),b(nb) {} + const btDbvtNode* a; + const btDbvtNode* b; + sStkNN(const btDbvtNode* na,const btDbvtNode* nb) : a(na),b(nb) {} }; struct sStkNP { - const Node* node; + const btDbvtNode* node; int mask; - sStkNP(const Node* n,unsigned m) : node(n),mask(m) {} + sStkNP(const btDbvtNode* n,unsigned m) : node(n),mask(m) {} }; struct sStkNPS { - const Node* node; + const btDbvtNode* node; int mask; btScalar value; sStkNPS() {} - sStkNPS(const Node* n,unsigned m,btScalar v) : node(n),mask(m),value(v) {} + sStkNPS(const btDbvtNode* n,unsigned m,btScalar v) : node(n),mask(m),value(v) {} }; struct sStkCLN { - const Node* node; - Node* parent; - sStkCLN(const Node* n,Node* p) : node(n),parent(p) {} + const btDbvtNode* node; + btDbvtNode* parent; + sStkCLN(const btDbvtNode* n,btDbvtNode* p) : node(n),parent(p) {} }; // Policies/Interfaces @@ -169,25 +178,25 @@ struct btDbvt struct ICollide { DBVT_VIRTUAL_DTOR(ICollide) - DBVT_VIRTUAL void Process(const Node*,const Node*) {} - DBVT_VIRTUAL void Process(const Node*) {} - DBVT_VIRTUAL void Process(const Node* n,btScalar) { Process(n); } - DBVT_VIRTUAL bool Descent(const Node*) { return(true); } - DBVT_VIRTUAL bool AllLeaves(const Node*) { return(true); } + DBVT_VIRTUAL void Process(const btDbvtNode*,const btDbvtNode*) {} + DBVT_VIRTUAL void Process(const btDbvtNode*) {} + DBVT_VIRTUAL void Process(const btDbvtNode* n,btScalar) { Process(n); } + DBVT_VIRTUAL bool Descent(const btDbvtNode*) { return(true); } + DBVT_VIRTUAL bool AllLeaves(const btDbvtNode*) { return(true); } }; /* IWriter */ struct IWriter { virtual ~IWriter() {} - virtual void Prepare(const Node* root,int numnodes)=0; - virtual void WriteNode(const Node*,int index,int parent,int child0,int child1)=0; - virtual void WriteLeaf(const Node*,int index,int parent)=0; + virtual void Prepare(const btDbvtNode* root,int numnodes)=0; + virtual void WriteNode(const btDbvtNode*,int index,int parent,int child0,int child1)=0; + virtual void WriteLeaf(const btDbvtNode*,int index,int parent)=0; }; /* IClone */ struct IClone { virtual ~IClone() {} - virtual void CloneLeaf(Node*) {} + virtual void CloneLeaf(btDbvtNode*) {} }; // Constants @@ -197,8 +206,8 @@ struct btDbvt }; // Fields - Node* m_root; - Node* m_free; + btDbvtNode* m_root; + btDbvtNode* m_free; int m_lkhd; int m_leaves; unsigned m_opath; @@ -210,17 +219,17 @@ struct btDbvt void optimizeBottomUp(); void optimizeTopDown(int bu_treshold=128); void optimizeIncremental(int passes); - Node* insert(const Volume& box,void* data); - void update(Node* leaf,int lookahead=-1); - void update(Node* leaf,const Volume& volume); - bool update(Node* leaf,Volume volume,const btVector3& velocity,btScalar margin); - bool update(Node* leaf,Volume volume,const btVector3& velocity); - bool update(Node* leaf,Volume volume,btScalar margin); - void remove(Node* leaf); + btDbvtNode* insert(const btDbvtVolume& box,void* data); + void update(btDbvtNode* leaf,int lookahead=-1); + void update(btDbvtNode* leaf,const btDbvtVolume& volume); + bool update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity,btScalar margin); + bool update(btDbvtNode* leaf,btDbvtVolume volume,const btVector3& velocity); + bool update(btDbvtNode* leaf,btDbvtVolume volume,btScalar margin); + void remove(btDbvtNode* leaf); void write(IWriter* iwriter) const; void clone(btDbvt& dest,IClone* iclone=0) const; - static int countLeaves(const Node* node); - static void extractLeaves(const Node* node,btAlignedObjectArray& leaves); + static int countLeaves(const btDbvtNode* node); + static void extractLeaves(const btDbvtNode* node,btAlignedObjectArray& leaves); #if DBVT_ENABLE_BENCHMARK static void benchmark(); #else @@ -228,43 +237,43 @@ struct btDbvt #endif // DBVT_IPOLICY must support ICollide policy/interface DBVT_PREFIX - static void enumNodes( const Node* root, + static void enumNodes( const btDbvtNode* root, DBVT_IPOLICY); DBVT_PREFIX - static void enumLeaves( const Node* root, + static void enumLeaves( const btDbvtNode* root, DBVT_IPOLICY); DBVT_PREFIX - static void collideTT( const Node* root0, - const Node* root1, + static void collideTT( const btDbvtNode* root0, + const btDbvtNode* root1, DBVT_IPOLICY); DBVT_PREFIX - static void collideTT( const Node* root0, - const Node* root1, + static void collideTT( const btDbvtNode* root0, + const btDbvtNode* root1, const btTransform& xform, DBVT_IPOLICY); DBVT_PREFIX - static void collideTT( const Node* root0, + static void collideTT( const btDbvtNode* root0, const btTransform& xform0, - const Node* root1, + const btDbvtNode* root1, const btTransform& xform1, DBVT_IPOLICY); DBVT_PREFIX - static void collideTV( const Node* root, - const Volume& volume, + static void collideTV( const btDbvtNode* root, + const btDbvtVolume& volume, DBVT_IPOLICY); DBVT_PREFIX - static void collideRAY( const Node* root, + static void collideRAY( const btDbvtNode* root, const btVector3& origin, const btVector3& direction, DBVT_IPOLICY); DBVT_PREFIX - static void collideKDOP(const Node* root, + static void collideKDOP(const btDbvtNode* root, const btVector3* normals, const btScalar* offsets, int count, DBVT_IPOLICY); DBVT_PREFIX - static void collideOCL( const Node* root, + static void collideOCL( const btDbvtNode* root, const btVector3* normals, const btScalar* offsets, const btVector3& sortaxis, @@ -272,7 +281,7 @@ struct btDbvt DBVT_IPOLICY, bool fullsort=true); DBVT_PREFIX - static void collideTU( const Node* root, + static void collideTU( const btDbvtNode* root, DBVT_IPOLICY); // Helpers static inline int nearest(const int* i,const btDbvt::sStkNPS* a,btScalar v,int l,int h) @@ -286,8 +295,8 @@ struct btDbvt return(h); } static inline int allocate( btAlignedObjectArray& ifree, - btAlignedObjectArray& stock, - const btDbvt::sStkNPS& value) + btAlignedObjectArray& stock, + const sStkNPS& value) { int i; if(ifree.size()>0) @@ -528,7 +537,7 @@ return( (a.mi.x()!=b.mi.x())|| // DBVT_PREFIX -inline void btDbvt::enumNodes( const Node* root, +inline void btDbvt::enumNodes( const btDbvtNode* root, DBVT_IPOLICY) { DBVT_CHECKTYPE @@ -542,7 +551,7 @@ if(root->isinternal()) // DBVT_PREFIX -inline void btDbvt::enumLeaves( const Node* root, +inline void btDbvt::enumLeaves( const btDbvtNode* root, DBVT_IPOLICY) { DBVT_CHECKTYPE @@ -559,8 +568,8 @@ if(root->isinternal()) // DBVT_PREFIX -inline void btDbvt::collideTT( const Node* root0, - const Node* root1, +inline void btDbvt::collideTT( const btDbvtNode* root0, + const btDbvtNode* root1, DBVT_IPOLICY) { DBVT_CHECKTYPE @@ -617,8 +626,8 @@ if(root0&&root1) // DBVT_PREFIX -inline void btDbvt::collideTT( const Node* root0, - const Node* root1, +inline void btDbvt::collideTT( const btDbvtNode* root0, + const btDbvtNode* root1, const btTransform& xform, DBVT_IPOLICY) { @@ -667,9 +676,9 @@ if(root0&&root1) // DBVT_PREFIX -inline void btDbvt::collideTT( const Node* root0, +inline void btDbvt::collideTT( const btDbvtNode* root0, const btTransform& xform0, - const Node* root1, + const btDbvtNode* root1, const btTransform& xform1, DBVT_IPOLICY) { @@ -679,18 +688,18 @@ collideTT(root0,root1,xform,policy); // DBVT_PREFIX -inline void btDbvt::collideTV( const Node* root, - const Volume& volume, +inline void btDbvt::collideTV( const btDbvtNode* root, + const btDbvtVolume& volume, DBVT_IPOLICY) { DBVT_CHECKTYPE if(root) { - btAlignedObjectArray stack; + btAlignedObjectArray stack; stack.reserve(SIMPLE_STACKSIZE); stack.push_back(root); do { - const Node* n=stack[stack.size()-1]; + const btDbvtNode* n=stack[stack.size()-1]; stack.pop_back(); if(Intersect(n->volume,volume)) { @@ -710,7 +719,7 @@ if(root) // DBVT_PREFIX -inline void btDbvt::collideRAY( const Node* root, +inline void btDbvt::collideRAY( const btDbvtNode* root, const btVector3& origin, const btVector3& direction, DBVT_IPOLICY) @@ -725,11 +734,11 @@ if(root) const unsigned signs[]={ direction.x()<0, direction.y()<0, direction.z()<0}; - btAlignedObjectArray stack; + btAlignedObjectArray stack; stack.reserve(SIMPLE_STACKSIZE); stack.push_back(root); do { - const Node* node=stack[stack.size()-1]; + const btDbvtNode* node=stack[stack.size()-1]; stack.pop_back(); if(Intersect(node->volume,origin,invdir,signs)) { @@ -749,7 +758,7 @@ if(root) // DBVT_PREFIX -inline void btDbvt::collideKDOP(const Node* root, +inline void btDbvt::collideKDOP(const btDbvtNode* root, const btVector3* normals, const btScalar* offsets, int count, @@ -804,7 +813,7 @@ if(root) // DBVT_PREFIX -inline void btDbvt::collideOCL( const Node* root, +inline void btDbvt::collideOCL( const btDbvtNode* root, const btVector3* normals, const btScalar* offsets, const btVector3& sortaxis, @@ -859,7 +868,7 @@ if(root) { if(se.node->isinternal()) { - const Node* pns[]={ se.node->childs[0],se.node->childs[1]}; + const btDbvtNode* pns[]={ se.node->childs[0],se.node->childs[1]}; sStkNPS nes[]={ sStkNPS(pns[0],se.mask,pns[0]->volume.ProjectMinimum(sortaxis,srtsgns)), sStkNPS(pns[1],se.mask,pns[1]->volume.ProjectMinimum(sortaxis,srtsgns))}; const int q=nes[0].value stack; + btAlignedObjectArray stack; stack.reserve(SIMPLE_STACKSIZE); stack.push_back(root); do { - const Node* n=stack[stack.size()-1]; + const btDbvtNode* n=stack[stack.size()-1]; stack.pop_back(); if(policy.Descent(n)) { diff --git a/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp index 23f2ca8e9..83ae922df 100644 --- a/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp @@ -92,9 +92,9 @@ struct btDbvtLeafCollider : btDbvt::ICollide btDbvtBroadphase* pbp; btDbvtProxy* ppx; btDbvtLeafCollider(btDbvtBroadphase* p,btDbvtProxy* px) : pbp(p),ppx(px) {} -void Process(const btDbvt::Node* na) +void Process(const btDbvtNode* na) { - const btDbvt::Node* nb=ppx->leaf; + const btDbvtNode* nb=ppx->leaf; if(nb!=na) { btDbvtProxy* pa=(btDbvtProxy*)na->data; @@ -115,7 +115,7 @@ struct btDbvtTreeCollider : btDbvt::ICollide { btDbvtBroadphase* pbp; btDbvtTreeCollider(btDbvtBroadphase* p) : pbp(p) {} -void Process(const btDbvt::Node* na,const btDbvt::Node* nb) +void Process(const btDbvtNode* na,const btDbvtNode* nb) { btDbvtProxy* pa=(btDbvtProxy*)na->data; btDbvtProxy* pb=(btDbvtProxy*)nb->data; diff --git a/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h b/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h index 874ed11ce..0deb75ba6 100644 --- a/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h +++ b/src/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h @@ -39,7 +39,7 @@ struct btDbvtProxy : btBroadphaseProxy { /* Fields */ btDbvtAabbMm aabb; -btDbvt::Node* leaf; +btDbvtNode* leaf; btDbvtProxy* links[2]; int stage; /* ctor */ diff --git a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp index 7219514ba..199a9022f 100644 --- a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp +++ b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.cpp @@ -209,8 +209,9 @@ void btMultiSapBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aab m_optimizedAabbTree->reportAabbOverlappingNodex(&myNodeCallback,aabbMin,aabbMax); + int i; - for (int i=0;im_bridgeProxies.size();i++) + for ( i=0;im_bridgeProxies.size();i++) { btVector3 worldAabbMin,worldAabbMax; multiProxy->m_bridgeProxies[i]->m_childBroadphase->getBroadphaseAabb(worldAabbMin,worldAabbMax); @@ -307,7 +308,7 @@ void btMultiSapBroadphase::setAabb(btBroadphaseProxy* proxy,const btVector3& aab //update - for (int i=0;im_bridgeProxies.size();i++) + for ( i=0;im_bridgeProxies.size();i++) { btBridgeProxy* bridgeProxyRef = multiProxy->m_bridgeProxies[i]; bridgeProxyRef->m_childBroadphase->setAabb(bridgeProxyRef->m_childProxy,aabbMin,aabbMax,dispatcher); diff --git a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h index e5578c446..ef8991102 100644 --- a/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h +++ b/src/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h @@ -83,7 +83,6 @@ public: protected: - void addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface* childBroadphase); btAlignedObjectArray m_multiSapProxies; @@ -107,7 +106,9 @@ public: virtual btBroadphaseProxy* createProxy( const btVector3& aabbMin, const btVector3& aabbMax,int shapeType,void* userPtr, short int collisionFilterGroup,short int collisionFilterMask, btDispatcher* dispatcher,void* multiSapProxy); virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax, btDispatcher* dispatcher); - + + void addToChildBroadphase(btMultiSapProxy* parentMultiSapProxy, btBroadphaseProxy* childProxy, btBroadphaseInterface* childBroadphase); + ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb virtual void calculateOverlappingPairs(btDispatcher* dispatcher); diff --git a/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp b/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp index efc858cbd..85cfe39f2 100644 --- a/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp +++ b/src/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp @@ -171,7 +171,7 @@ static int intersectRectQuad2 (btScalar h[2], btScalar p[8], btScalar ret[16]) return nr; } -#define dAtan2(y,x) ((float)atan2f((y),(x))) /* arc tangent with 2 args */ + #define M__PI 3.14159265f // given n points in the plane (array p, of size 2*n), generate m points that @@ -214,7 +214,7 @@ void cullPoints2 (int n, btScalar p[], int m, int i0, int iret[]) // compute the angle of each point w.r.t. the centroid btScalar A[8]; - for (i=0; i M__PI) diff = 2*M__PI - diff; if (diff < maxdiff) { maxdiff = diff; @@ -284,9 +284,9 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1, R21 = dDOT44(R1+1,R2+0); R22 = dDOT44(R1+1,R2+1); R23 = dDOT44(R1+1,R2+2); R31 = dDOT44(R1+2,R2+0); R32 = dDOT44(R1+2,R2+1); R33 = dDOT44(R1+2,R2+2); - Q11 = fabsf(R11); Q12 = fabsf(R12); Q13 = fabsf(R13); - Q21 = fabsf(R21); Q22 = fabsf(R22); Q23 = fabsf(R23); - Q31 = fabsf(R31); Q32 = fabsf(R32); Q33 = fabsf(R33); + Q11 = btFabs(R11); Q12 = btFabs(R12); Q13 = btFabs(R13); + Q21 = btFabs(R21); Q22 = btFabs(R22); Q23 = btFabs(R23); + Q31 = btFabs(R31); Q32 = btFabs(R32); Q33 = btFabs(R33); // for all 15 possible separating axes: // * see if the axis separates the boxes. if so, return 0. @@ -299,7 +299,7 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1, // the normal should be flipped. #define TST(expr1,expr2,norm,cc) \ - s2 = fabsf(expr1) - (expr2); \ + s2 = btFabs(expr1) - (expr2); \ if (s2 > 0) return 0; \ if (s2 > s) { \ s = s2; \ @@ -326,9 +326,9 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1, // normal (n1,n2,n3) is relative to box 1. #undef TST #define TST(expr1,expr2,n1,n2,n3,cc) \ - s2 = fabsf(expr1) - (expr2); \ + s2 = btFabs(expr1) - (expr2); \ if (s2 > 0) return 0; \ - l = sqrtf((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \ + l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \ if (l > 0) { \ s2 /= l; \ if (s2*fudge_factor > s) { \ @@ -461,9 +461,9 @@ int dBoxBox2 (const btVector3& p1, const dMatrix3 R1, normal2[2] = -normal[2]; } dMULTIPLY1_331 (nr,Rb,normal2); - anr[0] = fabsf (nr[0]); - anr[1] = fabsf (nr[1]); - anr[2] = fabsf (nr[2]); + anr[0] = btFabs (nr[0]); + anr[1] = btFabs (nr[1]); + anr[2] = btFabs (nr[2]); // find the largest compontent of anr: this corresponds to the normal // for the indident face. the other axis numbers of the indicent face diff --git a/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp b/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp index 7c6829295..a031a9f97 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp @@ -283,7 +283,7 @@ void* btCollisionDispatcher::allocateCollisionAlgorithm(int size) } //warn user for overflow? - return btAlignedAlloc(static_cast(size), 16); + return btAlignedAlloc(static_cast(size), 16); } void btCollisionDispatcher::freeCollisionAlgorithm(void* ptr) diff --git a/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp b/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp index bf1c01401..f4f061ad1 100644 --- a/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp +++ b/src/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp @@ -99,6 +99,7 @@ struct MinkowskiDiff typedef MinkowskiDiff tShape; + // GJK struct GJK { @@ -515,6 +516,30 @@ sList m_stock; { 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 = eStatus::Failed; @@ -531,10 +556,11 @@ eStatus::_ Evaluate(GJK& gjk,const btVector3& guess) GJK::sSimplex& simplex=*gjk.m_simplex; if((simplex.rank>1)&&gjk.EncloseOrigin()) { + /* Clean up */ while(m_hull.root) { - sFace* f(m_hull.root); + sFace* f = m_hull.root; remove(m_hull,f); append(m_stock,f); } @@ -716,26 +742,7 @@ bool expand(U pass,sSV* w,sFace* f,U e,sHorizon& horizon) } return(false); } -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; - } + }; // diff --git a/src/BulletDynamics/ConstraintSolver/btOdeMacros.h b/src/BulletDynamics/ConstraintSolver/btOdeMacros.h index af64e4ac6..f9bdca4cc 100644 --- a/src/BulletDynamics/ConstraintSolver/btOdeMacros.h +++ b/src/BulletDynamics/ConstraintSolver/btOdeMacros.h @@ -131,8 +131,8 @@ typedef btScalar *dRealMutablePtr; //#define dRealAllocaArray(name,size) btScalar *name = (btScalar*) stackAlloc->allocate(dEFFICIENT_SIZE(size)*sizeof(btScalar)); #define dRealAllocaArray(name,size) btScalar *name = NULL; \ unsigned int memNeeded_##name = dEFFICIENT_SIZE(size)*sizeof(btScalar); \ - if (memNeeded_##name < static_cast(stackAlloc->getAvailableMemory())) name = (btScalar*) stackAlloc->allocate(memNeeded_##name); \ - else{ btAssert(memNeeded_##name < static_cast(stackAlloc->getAvailableMemory())); name = (btScalar*) alloca(memNeeded_##name); } + if (memNeeded_##name < static_cast(stackAlloc->getAvailableMemory())) name = (btScalar*) stackAlloc->allocate(memNeeded_##name); \ + else{ btAssert(memNeeded_##name < static_cast(stackAlloc->getAvailableMemory())); name = (btScalar*) alloca(memNeeded_##name); } diff --git a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp index e853ea238..130321be6 100644 --- a/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp +++ b/src/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp @@ -716,7 +716,7 @@ btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCol rel_vel = cp.m_normalWorldOnB.dot(vel); - solverConstraint.m_penetration = btMin(cp.getDistance()+infoGlobal.m_linearSlop,0.f); + solverConstraint.m_penetration = btMin(cp.getDistance()+infoGlobal.m_linearSlop,btScalar(0.)); //solverConstraint.m_penetration = cp.getDistance(); solverConstraint.m_friction = cp.m_combinedFriction; diff --git a/src/BulletSoftBody/btSoftBody.cpp b/src/BulletSoftBody/btSoftBody.cpp index aea0e7a69..6039c0f28 100644 --- a/src/BulletSoftBody/btSoftBody.cpp +++ b/src/BulletSoftBody/btSoftBody.cpp @@ -421,19 +421,21 @@ static void PointersToIndices(btSoftBody* psb) { #define PTR2IDX(_p_,_b_) reinterpret_cast((_p_)-(_b_)) btSoftBody::Node* base=&psb->m_nodes[0]; - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();im_nodes[i].m_leaf) { psb->m_nodes[i].m_leaf->data=*(void**)&i; } } - for(int i=0,ni=psb->m_links.size();im_links.size();im_links[i].m_n[0]=PTR2IDX(psb->m_links[i].m_n[0],base); psb->m_links[i].m_n[1]=PTR2IDX(psb->m_links[i].m_n[1],base); } - for(int i=0,ni=psb->m_faces.size();im_faces.size();im_faces[i].m_n[0]=PTR2IDX(psb->m_faces[i].m_n[0],base); psb->m_faces[i].m_n[1]=PTR2IDX(psb->m_faces[i].m_n[1],base); @@ -443,11 +445,11 @@ static void PointersToIndices(btSoftBody* psb) psb->m_faces[i].m_leaf->data=*(void**)&i; } } - for(int i=0,ni=psb->m_anchors.size();im_anchors.size();im_anchors[i].m_node=PTR2IDX(psb->m_anchors[i].m_node,base); } - for(int i=0,ni=psb->m_notes.size();im_notes.size();im_notes[i].m_rank;++j) { @@ -463,19 +465,21 @@ static void IndicesToPointers(btSoftBody* psb,const int* map=0) #define IDX2PTR(_p_,_b_) map?(&(_b_)[map[(((char*)_p_)-(char*)0)]]): \ (&(_b_)[(((char*)_p_)-(char*)0)]) btSoftBody::Node* base=&psb->m_nodes[0]; - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();im_nodes[i].m_leaf) { psb->m_nodes[i].m_leaf->data=&psb->m_nodes[i]; } } - for(int i=0,ni=psb->m_links.size();im_links.size();im_links[i].m_n[0]=IDX2PTR(psb->m_links[i].m_n[0],base); psb->m_links[i].m_n[1]=IDX2PTR(psb->m_links[i].m_n[1],base); } - for(int i=0,ni=psb->m_faces.size();im_faces.size();im_faces[i].m_n[0]=IDX2PTR(psb->m_faces[i].m_n[0],base); psb->m_faces[i].m_n[1]=IDX2PTR(psb->m_faces[i].m_n[1],base); @@ -485,11 +489,11 @@ static void IndicesToPointers(btSoftBody* psb,const int* map=0) psb->m_faces[i].m_leaf->data=&psb->m_faces[i]; } } - for(int i=0,ni=psb->m_anchors.size();im_anchors.size();im_anchors[i].m_node=IDX2PTR(psb->m_anchors[i].m_node,base); } - for(int i=0,ni=psb->m_notes.size();im_notes.size();im_notes[i].m_rank;++j) { @@ -500,13 +504,13 @@ static void IndicesToPointers(btSoftBody* psb,const int* map=0) } // -static inline btDbvt::Volume VolumeOf( const btSoftBody::Face& f, +static inline btDbvtVolume VolumeOf( const btSoftBody::Face& f, btScalar margin) { const btVector3* pts[]={ &f.m_n[0]->m_x, &f.m_n[1]->m_x, &f.m_n[2]->m_x}; -btDbvt::Volume vol=btDbvt::Volume::FromPoints(pts,3); +btDbvtVolume vol=btDbvtVolume::FromPoints(pts,3); vol.Expand(btVector3(margin,margin,margin)); return(vol); } @@ -585,7 +589,7 @@ struct RayCaster : btDbvt::ICollide face = 0; tests = 0; } - void Process(const btDbvt::Node* leaf) + void Process(const btDbvtNode* leaf) { btSoftBody::Face& f=*(btSoftBody::Face*)leaf->data; const btScalar t=RayTriangle( o,d, @@ -723,11 +727,13 @@ static bool CheckContact( btSoftBody* psb, static void UpdateNormals(btSoftBody* psb) { const btVector3 zv(0,0,0); - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();im_nodes[i].m_n=zv; } - for(int i=0,ni=psb->m_faces.size();im_faces.size();im_faces[i]; const btVector3 n=cross(f.m_n[1]->m_x-f.m_n[0]->m_x, @@ -737,7 +743,7 @@ static void UpdateNormals(btSoftBody* psb) f.m_n[1]->m_n+=n; f.m_n[2]->m_n+=n; } - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();im_nodes[i].m_n.normalize(); } @@ -811,8 +817,10 @@ static void UpdatePose(btSoftBody* psb) // static void UpdateConstants(btSoftBody* psb) { + int i,ni; + /* Links */ - for(int i=0,ni=psb->m_links.size();im_links.size();im_links[i]; btSoftBody::Material& m=*l.m_material; @@ -821,7 +829,7 @@ static void UpdateConstants(btSoftBody* psb) l.m_c1 = l.m_rl*l.m_rl; } /* Faces */ - for(int i=0,ni=psb->m_faces.size();im_faces.size();im_faces[i]; f.m_ra = AreaOf(f.m_n[0]->m_x,f.m_n[1]->m_x,f.m_n[2]->m_x); @@ -829,11 +837,11 @@ static void UpdateConstants(btSoftBody* psb) /* Area's */ btAlignedObjectArray counts; counts.resize(psb->m_nodes.size(),0); - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();im_nodes[i].m_area = 0; } - for(int i=0,ni=psb->m_faces.size();im_faces.size();im_faces[i]; for(int j=0;j<3;++j) @@ -843,7 +851,7 @@ static void UpdateConstants(btSoftBody* psb) f.m_n[j]->m_area+=btFabs(f.m_ra); } } - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();i0) psb->m_nodes[i].m_area/=(btScalar)counts[i]; @@ -872,6 +880,7 @@ static inline void ApplyClampedForce( btSoftBody::Node& n, static void ApplyForces(btSoftBody* psb,btScalar dt) { BT_PROFILE("SoftBody applyForces"); + int i,ni; const btScalar kLF=psb->m_cfg.kLF; const btScalar kDG=psb->m_cfg.kDG; const btScalar kPR=psb->m_cfg.kPR; @@ -900,7 +909,7 @@ static void ApplyForces(btSoftBody* psb,btScalar dt) dvolumetv = (psb->m_pose.m_volume-volume)*kVC; } /* Per vertex forces */ - for(int i=0,ni=psb->m_nodes.size();im_nodes.size();im_nodes[i]; if(n.m_im>0) @@ -951,7 +960,7 @@ static void ApplyForces(btSoftBody* psb,btScalar dt) } } /* Per face forces */ - for(int i=0,ni=psb->m_faces.size();im_faces.size();im_faces[i]; if(as_faero) @@ -1171,7 +1180,7 @@ btSoftBody::btSoftBody(btSoftBody::btSoftBodyWorldInfo* worldInfo,int node_count n.m_q = n.m_x; n.m_im = m?*m++:1; n.m_im = n.m_im>0?1/n.m_im:0; - n.m_leaf = m_ndbvt.insert(btDbvt::Volume::FromCR(n.m_x,margin),&n); + n.m_leaf = m_ndbvt.insert(btDbvtVolume::FromCR(n.m_x,margin),&n); n.m_material= pm; } UpdateBounds(this); @@ -1313,7 +1322,7 @@ n.m_x = x; n.m_q = n.m_x; n.m_im = m>0?1/m:0; n.m_material = m_materials[0]; -n.m_leaf = m_ndbvt.insert(btDbvt::Volume::FromCR(n.m_x,margin),&n); +n.m_leaf = m_ndbvt.insert(btDbvtVolume::FromCR(n.m_x,margin),&n); } // @@ -1448,13 +1457,16 @@ btScalar btSoftBody::getTotalMass() const // void btSoftBody::setTotalMass(btScalar mass,bool fromfaces) { + int i; if(fromfaces) { - for(int i=0;im_x, @@ -1465,14 +1477,14 @@ void btSoftBody::setTotalMass(btScalar mass,bool fromfaces) f.m_n[j]->m_im+=twicearea; } } - for(int i=0;i0 ? @@ -1560,7 +1574,7 @@ void btSoftBody::setPose(bool bvolume,bool bframe) /* Pos */ const btVector3 com=EvaluateCom(this); m_pose.m_pos.resize(m_nodes.size()); - for(int i=0,ni=m_nodes.size();i>1; unsigned* adj=new unsigned[n*n]; #define IDX(_x_,_y_) ((_y_)*n+(_x_)) - for(int j=0;j edges(ncount,-2); int newnodes=0; +int i,ni; + /* Filter out */ -for(int i=0;i=pcount)||(btFabs(ifn->Eval(x))Eval(n[0]->m_x) ranks; btAlignedObjectArray todelete; ranks.resize(nnodes,0); - for(int i=0,ni=m_links.size();i=0;--i) + for(i=nnodes-1;i>=0;--i) { if(!ranks[i]) todelete.push_back(i); } @@ -1957,7 +1979,9 @@ Node* pn[2]={ &m_nodes[m_nodes.size()-2], &m_nodes[m_nodes.size()-1]}; pn[0]->m_v=v; pn[1]->m_v=v; -for(int i=0,ni=m_links.size();im_x-l.m_n[0]->m_x; l.m_c2 = 1/(l.m_c3.length2()*l.m_c0); } /* Prepare anchors */ -for(int i=0,ni=m_anchors.size();igetWorldTransform().getBasis()*a.m_local; @@ -2177,7 +2203,7 @@ if(m_cfg.piterations>0) if(m_cfg.diterations>0) { const btScalar vcf=m_cfg.kVCF*m_sst.isdt; - for(int i=0,ni=m_nodes.size();i0) PSolvers[m_cfg.m_dsequence[iseq]](this,1); } } - for(int i=0,ni=m_nodes.size();idata; + btSoftBody::Node* node=(btSoftBody::Node*)leaf->data; DoNode(*node); } - void DoNode(Node& n) const + void DoNode(btSoftBody::Node& n) const { const btScalar m=n.m_im>0?dynmargin:stamargin; - RContact c; + btSoftBody::RContact c; if( (!n.m_battach)&& CheckContact(psb,prb,n.m_x,m,c.m_cti)) { @@ -2280,11 +2306,11 @@ switch(m_cfg.collisions&fCollision::RVSmask) const btScalar basemargin=getCollisionShape()->getMargin(); btVector3 mins; btVector3 maxs; - btDbvt::Volume volume; + btDbvtVolume volume; pco->getCollisionShape()->getAabb( pco->getInterpolationWorldTransform(), mins, maxs); - volume=btDbvt::Volume::FromMM(mins,maxs); + volume=btDbvtVolume::FromMM(mins,maxs); volume.Expand(btVector3(basemargin,basemargin,basemargin)); docollide.psb = this; docollide.prb = prb; @@ -2306,11 +2332,11 @@ switch(cf&fCollision::SVSmask) { struct DoCollide : btDbvt::ICollide { - void Process(const btDbvt::Node* lnode, - const btDbvt::Node* lface) + void Process(const btDbvtNode* lnode, + const btDbvtNode* lface) { - Node* node=(Node*)lnode->data; - Face* face=(Face*)lface->data; + btSoftBody::Node* node=(btSoftBody::Node*)lnode->data; + btSoftBody::Face* face=(btSoftBody::Face*)lface->data; btVector3 o=node->m_x; btVector3 p; btScalar d=SIMD_INFINITY; @@ -2321,7 +2347,7 @@ switch(cf&fCollision::SVSmask) const btScalar m=mrg+(o-node->m_q).length()*2; if(d<(m*m)) { - const Node* n[]={face->m_n[0],face->m_n[1],face->m_n[2]}; + const btSoftBody::Node* n[]={face->m_n[0],face->m_n[1],face->m_n[2]}; const btVector3 w=BaryCoord(n[0]->m_x,n[1]->m_x,n[2]->m_x,p+o); const btScalar ma=node->m_im; btScalar mb=BaryEval(n[0]->m_im,n[1]->m_im,n[2]->m_im,w); @@ -2334,7 +2360,7 @@ switch(cf&fCollision::SVSmask) const btScalar ms=ma+mb; if(ms>0) { - SContact c; + btSoftBody::SContact c; c.m_normal = p/-btSqrt(d); c.m_margin = m; c.m_node = node; diff --git a/src/BulletSoftBody/btSoftBody.h b/src/BulletSoftBody/btSoftBody.h index 1a24f6fe0..c9e5ee03b 100644 --- a/src/BulletSoftBody/btSoftBody.h +++ b/src/BulletSoftBody/btSoftBody.h @@ -192,7 +192,7 @@ public: btVector3 m_n; // Normal btScalar m_im; // 1/mass btScalar m_area; // Area - btDbvt::Node* m_leaf; // Leaf data + btDbvtNode* m_leaf; // Leaf data int m_battach:1; // Attached }; /* Link */ @@ -212,12 +212,12 @@ public: Node* m_n[3]; // Node pointers btVector3 m_normal; // Normal btScalar m_ra; // Rest area - btDbvt::Node* m_leaf; // Leaf data + btDbvtNode* m_leaf; // Leaf data }; /* RContact */ struct RContact { - btSoftBody::sCti m_cti; // Contact infos + sCti m_cti; // Contact infos Node* m_node; // Owner node btMatrix3x3 m_c0; // Impulse matrix btVector3 m_c1; // Relative anchor @@ -310,7 +310,7 @@ public: typedef btAlignedObjectArray tNoteArray; typedef btAlignedObjectArray tNodeArray; - typedef btAlignedObjectArray tLeafArray; + typedef btAlignedObjectArray tLeafArray; typedef btAlignedObjectArray tLinkArray; typedef btAlignedObjectArray tFaceArray; typedef btAlignedObjectArray tAnchorArray; @@ -346,7 +346,7 @@ public: // /* ctor */ - btSoftBody( btSoftBody::btSoftBodyWorldInfo* worldInfo,int node_count, + btSoftBody( btSoftBodyWorldInfo* worldInfo,int node_count, const btVector3* x, const btScalar* m); /* dtor */ diff --git a/src/BulletSoftBody/btSoftBodyHelpers.cpp b/src/BulletSoftBody/btSoftBodyHelpers.cpp index ef73baeb3..967755a9d 100644 --- a/src/BulletSoftBody/btSoftBodyHelpers.cpp +++ b/src/BulletSoftBody/btSoftBodyHelpers.cpp @@ -53,7 +53,7 @@ idraw->drawLine(c[2],c[6],color);idraw->drawLine(c[3],c[7],color); // static void drawTree( btIDebugDraw* idraw, - const btDbvt::Node* node, + const btDbvtNode* node, int depth, const btVector3& ncolor, const btVector3& lcolor, @@ -175,7 +175,9 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb, /* Anchors */ if(0!=(drawflags&fDrawFlags::Anchors)) { - for(int i=0;im_anchors.size();++i) + int i; + + for(i=0;im_anchors.size();++i) { const btSoftBody::Anchor& a=psb->m_anchors[i]; const btVector3 q=a.m_body->getWorldTransform()*a.m_local; @@ -183,7 +185,7 @@ void btSoftBodyHelpers::Draw( btSoftBody* psb, drawVertex(idraw,q,0.25,btVector3(0,1,0)); idraw->drawLine(a.m_node->m_x,q,btVector3(1,1,1)); } - for(int i=0;im_nodes.size();++i) + for(i=0;im_nodes.size();++i) { const btSoftBody::Node& n=psb->m_nodes[i]; if(0==(n.m_material->m_flags&btSoftBody::fMaterial::DebugDraw)) continue; @@ -313,7 +315,9 @@ btSoftBody* btSoftBodyHelpers::CreateRope( btSoftBody::btSoftBodyWorldInfo& wor const int r=res+2; btVector3* x=new btVector3[r]; btScalar* m=new btScalar[r]; - for(int i=0;iappendLink(i-1,i); } @@ -351,7 +355,9 @@ btSoftBody* btSoftBodyHelpers::CreatePatch(btSoftBody::btSoftBodyWorldInfo& wor const int tot=rx*ry; btVector3* x=new btVector3[tot]; btScalar* m=new btScalar[tot]; - for(int iy=0;iy vtx; chks.resize(maxidx*maxidx,false); vtx.resize(maxidx); - for(int i=0,j=0,ni=maxidx*3;i +unsigned int HsiehHash(const void* pdata) + { + const unsigned short* data=(const unsigned short*)pdata; + unsigned hash=DWORDLEN<<2,tmp; + for(int i=0;i>11; + } + hash^=hash<<3;hash+=hash>>5; + hash^=hash<<4;hash+=hash>>17; + hash^=hash<<25;hash+=hash>>6; + return(hash); + } + template struct btSparseSdf { @@ -258,32 +278,29 @@ struct btSparseSdf { return(a+(b-a)*t); } + + + // - static inline unsigned Hash(int x,int y,int z,btCollisionShape* shape) + static inline unsigned int Hash(int x,int y,int z,btCollisionShape* shape) { - struct { int x,y,z;void* p; } set; - set.x=x;set.y=y;set.z=z;set.p=shape; - return(HsiehHash(&set)); + struct btS + { + int x,y,z; + void* p; + }; + + btS myset; + + myset.x=x;myset.y=y;myset.z=z;myset.p=shape; + const void* ptr = &myset; + + unsigned int result = HsiehHash (ptr); + + + return result; } - // Modified Paul Hsieh hash - template - static inline unsigned HsiehHash(const void* pdata) - { - const unsigned short* data=(const unsigned short*)pdata; - unsigned hash=DWORDLEN<<2,tmp; - for(int i=0;i>11; - } - hash^=hash<<3;hash+=hash>>5; - hash^=hash<<4;hash+=hash>>17; - hash^=hash<<25;hash+=hash>>6; - return(hash); - } - }; +}; + #endif diff --git a/src/LinearMath/btScalar.h b/src/LinearMath/btScalar.h index 671e373c5..f3e27b98b 100644 --- a/src/LinearMath/btScalar.h +++ b/src/LinearMath/btScalar.h @@ -18,6 +18,7 @@ subject to the following restrictions: #define SIMD___SCALAR_H #include +#include //size_t for MSVC 6.0 #include #include @@ -144,9 +145,9 @@ typedef float btScalar; #define BT_DECLARE_ALIGNED_ALLOCATOR() \ - SIMD_FORCE_INLINE void* operator new(std::size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \ + SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes,16); } \ SIMD_FORCE_INLINE void operator delete(void* ptr) { btAlignedFree(ptr); } \ - SIMD_FORCE_INLINE void* operator new(std::size_t, void* ptr) { return ptr; } \ + SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \ SIMD_FORCE_INLINE void operator delete(void*, void*) { } \