Changeset 8351
- Timestamp:
- Apr 28, 2011, 7:15:14 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 15 deleted
- 401 edited
- 45 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/CMakeLists.txt
r7383 r8351 24 24 # 25 25 26 # Defined LINUX 27 IF(UNIX AND NOT APPLE) 28 SET(LINUX TRUE) 29 ENDIF() 30 26 31 IF(WIN32) 27 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) 32 IF(MSVC10) 33 CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3 FATAL_ERROR) 34 ELSE() 35 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) 36 ENDIF() 28 37 ELSE() 29 CMAKE_MINIMUM_REQUIRED(VERSION 2.6 38 CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR) 30 39 ENDIF() 31 40 … … 57 66 SET(DEFAULT_CONFIG_PATH config) 58 67 SET(DEFAULT_LOG_PATH log) 68 SET(DEFAULT_BUNDLE_PATH bundle) 59 69 60 70 # Set output directories … … 98 108 ENDIF() 99 109 110 # Debug builds can not be installed 111 INSTALL(SCRIPT cmake/InstallCheck.cmake) 112 100 113 # Enable expensive optimisations: use this for a binary release build 101 114 OPTION(ORXONOX_RELEASE "Enable when building restributable releases" FALSE) 102 115 116 IF(APPLE) 117 # Set 10.5 as the base SDK by default 118 SET(XCODE_ATTRIBUTE_SDKROOT macosx10.5) 119 120 # 10.6 sets x86_64 as the default architecture. 121 # Because Carbon isn't supported on 64-bit and we still need it, force the architectures to ppc and i386 122 IF(CMAKE_OSX_ARCHITECTURES MATCHES "x86_64") 123 SET(CMAKE_OSX_ARCHITECTURES "i386") 124 ENDIF() 125 IF(CMAKE_OSX_ARCHITECTURES MATCHES "ppc64") 126 SET(CMAKE_OSX_ARCHITECTURES "ppc") 127 ENDIF() 128 IF(NOT CMAKE_OSX_ARCHITECTURES) 129 SET(CMAKE_OSX_ARCHITECTURES "i386") 130 ENDIF() 131 ENDIF() 132 103 133 ########### Subfolders and Subscripts ########### 134 135 # General build and compiler options and configurations 136 INCLUDE(CompilerConfig) 104 137 105 138 # Library finding 106 139 INCLUDE(LibraryConfig) 107 108 # General build and compiler options and configurations109 INCLUDE(CompilerConfig)110 140 111 141 # Configure installation paths and options … … 121 151 ADD_SUBDIRECTORY(bin) 122 152 153 # System specific files (mostly for installation) 154 ADD_SUBDIRECTORY(contrib) 155 123 156 # Last but not least: Try to make a doc target with Doxygen 124 157 ADD_SUBDIRECTORY(doc) 158 159 ########### CPack Packaging ########### 160 161 # Currently only testing on Apple 162 #IF(APPLE) 163 # INCLUDE(BundleConfig) 164 #ENDIF(APPLE) -
code/trunk/INSTALL
r7248 r8351 9 9 (for windows there are already precompiled packages on the website) 10 10 11 OGRE 3D Graphics Engine 1. 4- 1.712 CEGUI (Crazy Eddie's GUI System) 0. 5 - 0.611 OGRE 3D Graphics Engine 1.6 - 1.7 12 CEGUI (Crazy Eddie's GUI System) 0.6 13 13 Boost libraries 1.35 - 14 ENet (Network library) 1.1 - 1.215 14 Lua (scripting language) 5.0 - 5.1 16 15 Tcl (shell script language) 8.4 - 8.5 -
code/trunk/bin/CMakeLists.txt
r7801 r8351 69 69 # Make a symlink to be able to run from the root directory when installing copyable on Unix 70 70 IF(UNIX AND INSTALL_COPYABLE) 71 INSTAll(CODE "EXECUTE_PROCESS(COMMAND ln -sf ${RUNTIME_INSTALL_DIRECTORY}/${ORXONOX_EXECUTABLE_NAME} ${CMAKE_INSTALL_PREFIX}/orxonox)")71 INSTAll(CODE "EXECUTE_PROCESS(COMMAND cmake -E create_symlink \"${CMAKE_INSTALL_PREFIX}/${RUNTIME_INSTALL_DIRECTORY}/${ORXONOX_EXECUTABLE_NAME}\" \"${CMAKE_INSTALL_PREFIX}/${ORXONOX_EXECUTABLE_NAME}\")") 72 72 ENDIF() -
code/trunk/bin/client1.bat.in
r5781 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--client --writingPathSuffix client13 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --client --writingPathSuffix client1 4 4 pause -
code/trunk/bin/client2.bat.in
r5781 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--client --writingPathSuffix client23 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --client --writingPathSuffix client2 4 4 pause -
code/trunk/bin/dedicated.bat.in
r5781 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--dedicated --writingPathSuffix dedicated3 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --dedicated --writingPathSuffix dedicated 4 4 pause -
code/trunk/bin/dedicatedClient.bat.in
r6417 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--dedicatedClient --writingPathSuffix dedicatedClient3 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --dedicatedClient --writingPathSuffix dedicatedClient 4 4 pause -
code/trunk/bin/masterserver.bat.in
- Property svn:eol-style set to native
r7801 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--masterserver --writingPathSuffix masterserver3 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --masterserver --writingPathSuffix masterserver 4 4 pause -
code/trunk/bin/masterserver.in
- Property svn:eol-style set to native
-
code/trunk/bin/run.bat.in
r5695 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@ 3 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" 4 4 pause -
code/trunk/bin/server.bat.in
r5781 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--server --writingPathSuffix server3 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --server --writingPathSuffix server 4 4 pause -
code/trunk/bin/standalone.bat.in
r5781 r8351 1 1 title @PROJECT_NAME@ 2 2 path @RUNTIME_LIBRARY_DIRECTORY_WINDOWS@;%path% 3 @CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@--standalone --writingPathSuffix standalone3 "@CURRENT_RUNTIME_DIR_WINDOWS@\@ORXONOX_EXECUTABLE_NAME@" --standalone --writingPathSuffix standalone 4 4 pause -
code/trunk/bin/vld.ini.in
r5929 r8351 56 56 ; Default: None. 57 57 ; 58 ForceIncludeModules = boost_date_time-vc 80-mt-gd-1_39.dll, boost_filesystem-vc80-mt-gd-1_39.dll, boost_system-vc80-mt-gd-1_39.dll, boost_thread-vc80-mt-gd-1_39.dll, enet_d.dll, lua_d.dll, ogg_d.dll, vorbis_d.dll, vorbifile_d.dll58 ForceIncludeModules = boost_date_time-vc90-mt-gd-1_44.dll, boost_filesystem-vc90-mt-gd-1_44.dll, boost_system-vc90-mt-gd-1_44.dll, boost_thread-vc90-mt-gd-1_44.dll, lua_d.dll, ogg_d.dll, vorbis_d.dll, vorbifile_d.dll 59 59 60 60 ; Maximum number of data bytes to display for each leaked block. If zero, then -
code/trunk/cmake/CompilerConfig.cmake
r5781 r8351 34 34 MESSAGE(STATUS "Warning: Your compiler is not officially supported.") 35 35 ENDIF() 36 37 SET(COMPILER_CONFIG_USER_SCRIPT "" CACHE FILEPATH38 "Specify a CMake script if you wish to write your own compiler config.39 See CompilerConfigGCC.cmake or CompilerConfigMSVC.cmake for examples.")40 IF(COMPILER_CONFIG_USER_SCRIPT)41 IF(EXISTS ${CMAKE_MODULE_PATH}/${COMPILER_CONFIG_USER_SCRIPT})42 INCLUDE(${CMAKE_MODULE_PATH}/${COMPILER_CONFIG_USER_SCRIPT})43 ENDIF()44 ENDIF(COMPILER_CONFIG_USER_SCRIPT) -
code/trunk/cmake/CompilerConfigGCC.cmake
r7458 r8351 26 26 INCLUDE(FlagUtilities) 27 27 INCLUDE(CompareVersionStrings) 28 INCLUDE(CheckCXXCompilerFlag) 28 29 29 30 # Shortcut for CMAKE_COMPILER_IS_GNUCXX and ..._GNUC … … 36 37 OUTPUT_VARIABLE GCC_VERSION 37 38 ) 38 39 # Complain about incompatibilities40 COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.4.0" _compare_result)41 IF(NOT _compare_result LESS 0)42 IF(${Boost_VERSION} LESS 103700)43 MESSAGE(STATUS "Warning: Boost versions earlier than 1.37 may not compile with GCC 4.4 or later!")44 ENDIF()45 ENDIF()46 47 # GCC may not support #pragma GCC system_header correctly when using48 # templates. According to Bugzilla, it was fixed March 07 but tests49 # have confirmed that GCC 4.0.0 does not pose a problem for our cases.50 COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.0.0" _compare_result)51 IF(_compare_result LESS 0)52 SET(GCC_NO_SYSTEM_HEADER_SUPPORT TRUE)53 ENDIF()54 39 55 40 # GCC only supports PCH in versions 3.4 and above … … 72 57 73 58 # CMake doesn't seem to set the PIC flags right on certain 64 bit systems 74 IF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")59 IF(NOT MINGW AND ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") 75 60 ADD_COMPILER_FLAGS("-fPIC" CACHE) 61 ENDIF() 62 63 # Enable non standard floating point optimisations 64 ADD_COMPILER_FLAGS("-ffast-math" CACHE) 65 66 # Use SSE if possible 67 # Commented because this might not work for cross compiling 68 #CHECK_CXX_COMPILER_FLAG(-msse _gcc_have_sse) 69 #IF(_gcc_have_sse) 70 # ADD_COMPILER_FLAGS("-msse" CACHE) 71 #ENDIF() 72 73 IF(NOT MINGW) 74 # Have GCC visibility? 75 CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" _gcc_have_visibility) 76 IF(_gcc_have_visibility) 77 # Note: There is a possible bug with the flag in gcc < 4.2 and Debug versions 78 COMPARE_VERSION_STRINGS("${GCC_VERSION}" "4.2.0" _compare_result) 79 IF(NOT CMAKE_BUILD_TYPE STREQUAL "Debug" OR _compare_result GREATER -1) 80 ADD_COMPILER_FLAGS("-DORXONOX_GCC_VISIBILITY -fvisibility=default -fvisibility-inlines-hidden" CACHE) 81 ENDIF() 82 ENDIF(_gcc_have_visibility) 76 83 ENDIF() 77 84 78 85 # We have some unconformant code, disable an optimisation feature 79 86 ADD_COMPILER_FLAGS("-fno-strict-aliasing" CACHE) 80 81 # For GCC older than version 4, do not display sign compare warnings82 # because of boost::filesystem (which creates about a hundred per include)83 ADD_COMPILER_FLAGS("-Wno-sign-compare" GCC_NO_SYSTEM_HEADER_SUPPORT CACHE)84 87 85 88 # For newer GCC (4.3 and above), don't display hundreds of annoying deprecated … … 98 101 ENDIF() 99 102 100 # General linker flags 101 SET_LINKER_FLAGS("--no-undefined" CACHE) 103 # Linker flags 104 IF(LINUX) 105 # Don't allow undefined symbols in a shared library 106 SET_LINKER_FLAGS("-Wl,--no-undefined" CACHE) 107 ENDIF() 102 108 103 109 # Add compiler and linker flags for MinGW -
code/trunk/cmake/CompilerConfigMSVC.cmake
r7818 r8351 60 60 61 61 # Overwrite CMake default flags here for the individual configurations 62 SET_COMPILER_FLAGS("-MDd -Od -Zi -D_DEBUG -RTC1" Debug CACHE) 63 SET_COMPILER_FLAGS("-MD -O2 -DNDEBUG" Release CACHE) 64 SET_COMPILER_FLAGS("-MD -O2 -Zi -DNDEBUG" RelWithDebInfo CACHE) 65 SET_COMPILER_FLAGS("-MD -O1 -DNDEBUG" MinSizeRel CACHE) 66 ADD_COMPILER_FLAGS("-D_SECURE_SCL=0" MSVC9 ReleaseAll CACHE) 62 SET_COMPILER_FLAGS("-MDd -Od -Oi -Zi -D_DEBUG -RTC1" Debug CACHE) 63 SET_COMPILER_FLAGS("-MD -O2 -DNDEBUG" Release CACHE) 64 SET_COMPILER_FLAGS("-MD -O2 -Zi -DNDEBUG" RelWithDebInfo CACHE) 65 SET_COMPILER_FLAGS("-MD -O1 -DNDEBUG" MinSizeRel CACHE) 66 67 # Enable non standard floating point optimisations 68 ADD_COMPILER_FLAGS("-fp:fast" CACHE) 67 69 68 70 # Use Link time code generation for Release config if ORXONOX_RELEASE is defined -
code/trunk/cmake/InstallConfig.cmake
r7163 r8351 39 39 ENDIF() 40 40 41 # Default installation paths42 SET(RUNTIME_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_RUNTIME_PATH})43 SET(LIBRARY_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_LIBRARY_PATH})44 SET(ARCHIVE_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_ARCHIVE_PATH})45 SET(MODULE_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_MODULE_PATH})46 SET(DOC_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_DOC_PATH})47 SET(DATA_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_DATA_PATH})48 SET(CONFIG_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_CONFIG_PATH})49 SET(LOG_INSTALL_DIRECTORY ${ CMAKE_INSTALL_PREFIX}/${DEFAULT_LOG_PATH})41 # Default relative installation paths 42 SET(RUNTIME_INSTALL_DIRECTORY ${DEFAULT_RUNTIME_PATH}) 43 SET(LIBRARY_INSTALL_DIRECTORY ${DEFAULT_LIBRARY_PATH}) 44 SET(ARCHIVE_INSTALL_DIRECTORY ${DEFAULT_ARCHIVE_PATH}) 45 SET(MODULE_INSTALL_DIRECTORY ${DEFAULT_MODULE_PATH}) 46 SET(DOC_INSTALL_DIRECTORY ${DEFAULT_DOC_PATH}) 47 SET(DATA_INSTALL_DIRECTORY ${DEFAULT_DATA_PATH}) 48 SET(CONFIG_INSTALL_DIRECTORY ${DEFAULT_CONFIG_PATH}) 49 SET(LOG_INSTALL_DIRECTORY ${DEFAULT_LOG_PATH}) 50 50 51 51 IF(NOT INSTALL_COPYABLE) 52 IF( UNIX) # Apple too?52 IF(LINUX) 53 53 # Using absolute paths 54 SET(RUNTIME_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/games) 55 SET(LIBRARY_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/games/orxonox) 56 SET(ARCHIVE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/games/orxonox/static) 57 SET(MODULE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/lib/games/orxonox/modules) 58 SET(DOC_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/doc/orxonox) 59 SET(DATA_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX}/share/games/orxonox) 54 SET(RUNTIME_INSTALL_DIRECTORY games) 55 SET(LIBRARY_INSTALL_DIRECTORY lib/games/orxonox) 56 SET(ARCHIVE_INSTALL_DIRECTORY lib/games/orxonox/static) 57 SET(MODULE_INSTALL_DIRECTORY lib/games/orxonox/modules) 58 SET(DOC_INSTALL_DIRECTORY share/doc/orxonox) 59 SET(DATA_INSTALL_DIRECTORY share/games/orxonox) 60 ELSEIF(WIN32) 61 # Leave on default (installs to only one location anyway) 62 ELSEIF(APPLE) 63 # TODO: Figure out what's the best way to install the application 60 64 ENDIF() 61 65 … … 67 71 ################## Unix rpath ################### 68 72 73 # Use, i.e. don't skip the full RPATH for the build tree 74 SET(CMAKE_SKIP_BUILD_RPATH FALSE) 75 69 76 # When building, don't use the install RPATH already 70 77 # (but later on when installing) … … 73 80 # The RPATH to be used when installing 74 81 IF(INSTALL_COPYABLE) 75 SET(CMAKE_INSTALL_RPATH ${DEFAULT_LIBRARY_PATH}) 82 # Get relative paths from run to lib and from module to lib directory. 83 FILE(RELATIVE_PATH _runtime_rpath "/${RUNTIME_INSTALL_DIRECTORY}" "/${LIBRARY_INSTALL_DIRECTORY}") 84 FILE(RELATIVE_PATH _module_rpath "/${MODULE_INSTALL_DIRECTORY}" "/${LIBRARY_INSTALL_DIRECTORY}") 85 # $ORIGIN (with $ escaped) refers to the actual location of the library 86 # The UNIX loader recognises this special variable 87 SET(RUNTIME_RPATH "\$ORIGIN/${_runtime_rpath}") 88 SET(LIBRARY_RPATH "\$ORIGIN") 89 SET(MODULE_RPATH "\$ORIGIN:\$ORIGIN/${_module_rpath}") 76 90 ELSE() 77 SET(CMAKE_INSTALL_RPATH ${LIBRARY_INSTALL_DIRECTORY}) 91 SET(RUNTIME_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIRECTORY}") 92 SET(LIBRARY_RPATH "${CMAKE_INSTALL_PREFIX}/${LIBRARY_INSTALL_DIRECTORY}") 93 SET(MODULE_RPATH "${LIBRARY_RPATH}:${CMAKE_INSTALL_PREFIX}/${MODULE_INSTALL_DIRECTORY}") 78 94 ENDIF() 79 95 -
code/trunk/cmake/LibraryConfig.cmake
r8264 r8351 40 40 # On Windows using a package causes way less problems 41 41 SET(_option_msg "Set this to true to use precompiled dependecy archives") 42 IF(WIN32 )42 IF(WIN32 OR APPLE) 43 43 OPTION(DEPENDENCY_PACKAGE_ENABLE "${_option_msg}" ON) 44 ELSE( WIN32)44 ELSE() 45 45 OPTION(DEPENDENCY_PACKAGE_ENABLE "${_option_msg}" FALSE) 46 ENDIF( WIN32)46 ENDIF() 47 47 48 48 # Scripts for specific library and CMake config 49 49 INCLUDE(LibraryConfigTardis) 50 INCLUDE(LibraryConfigApple)51 50 52 51 IF(DEPENDENCY_PACKAGE_ENABLE) 52 IF(APPLE AND NOT EXISTS ${CMAKE_SOURCE_DIR}/dependencies) 53 # Let CMake automatically download and extract the dependency package on Mac OS X 54 # TODO: Handle download errors and always select newest package 55 SET(_dep_package_current "OrxonoxDeps_110428_2.0_OSX.tar.bz2") 56 SET(_dep_package_url "http://svn.orxonox.net/ogre/apple/precompiled_dependencies") 57 MESSAGE(STATUS "Downloading Mac OS X dependency package.") 58 FILE(DOWNLOAD 59 ${_dep_package_url}/${_dep_package_current} 60 ${CMAKE_SOURCE_DIR}/${_dep_package_current} 61 ) 62 MESSAGE(STATUS "Extracting Mac OS X dependency package.") 63 EXECUTE_PROCESS( 64 COMMAND ${CMAKE_COMMAND} -E tar -jxf ${_dep_package_current} 65 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 66 OUTPUT_FILE ${CMAKE_BINARY_DIR}/dep_pack_extract_log.keep_me 67 ) 68 # Delete the dependency archive once we no longer need it 69 FILE(REMOVE ${CMAKE_SOURCE_DIR}/${_dep_package_current}) 70 ENDIF() 71 53 72 GET_FILENAME_COMPONENT(_dep_dir_1 ${CMAKE_SOURCE_DIR}/../dependencies ABSOLUTE) 54 73 GET_FILENAME_COMPONENT(_dep_dir_2 ${CMAKE_SOURCE_DIR}/../lib_dist ABSOLUTE) … … 59 78 ELSEIF(MSVC90) 60 79 SET(_compiler_prefix msvc9) 80 ELSEIF(MSVC10) 81 SET(_compiler_prefix msvc10) 61 82 ENDIF() 62 83 FIND_PATH(DEPENDENCY_PACKAGE_DIR … … 73 94 "Disable LIBRARY_USE_PACKAGE if you have none intalled.") 74 95 ELSE() 75 INCLUDE(PackageConfigMinGW) 76 INCLUDE(PackageConfigMSVC) 77 INCLUDE(PackageConfig) # For both msvc and mingw 96 IF(WIN32) 97 INCLUDE(PackageConfigMinGW) 98 INCLUDE(PackageConfigMSVC) 99 INCLUDE(PackageConfig) # For both msvc and mingw 100 ELSEIF(APPLE) 101 INCLUDE(PackageConfigOSX) 102 ENDIF(WIN32) 78 103 ENDIF() 79 104 ENDIF(DEPENDENCY_PACKAGE_ENABLE) … … 93 118 # Performs the search and sets the variables # 94 119 95 FIND_PACKAGE(OGRE 1.4 REQUIRED) 96 #FIND_PACKAGE(ENet 1.1 REQUIRED) 120 #FIND_PACKAGE(ENet 1.2 REQUIRED) 121 FIND_PACKAGE(CEGUI 0.6 REQUIRED) 122 FIND_PACKAGE(Lua5.1 REQUIRED) 97 123 FIND_PACKAGE(Ogg REQUIRED) 98 124 FIND_PACKAGE(Vorbis REQUIRED) 99 125 FIND_PACKAGE(ALUT REQUIRED) 100 126 FIND_PACKAGE(ZLIB REQUIRED) 101 IF(POCO_REQUIRED) 102 FIND_PACKAGE(POCO REQUIRED) 103 # Always link against POCO too because of threading 104 SET(OGRE_LIBRARY ${OGRE_LIBRARY} ${POCO_LIBRARY}) 105 ENDIF() 127 106 128 IF(WIN32) 107 129 FIND_PACKAGE(DbgHelp) … … 109 131 ENDIF() 110 132 111 ##### CEGUI #####112 # We make use of the CEGUI script module called CEGUILua.113 # However there is a small issue with that: We use Tolua, a C++ binding114 # generator ourselves. And we also have to use our bindings in the same115 # lua state is CEGUILua's. Unfortunately this implies that both lua runtime116 # version are equal or else you get segmentation faults.117 # In order to match the Lua versions we decided to ship CEGUILua in our118 # repository, mainly because there is no way to determine which version of119 # Lua CEGUILua was linked against (you'd have to specify yourself) and secondly120 # because we can then choose the Lua version. Future plans might involve only121 # accepting Lua 5.1.122 123 # Insert all internally supported CEGUILua versions here124 SET(CEGUILUA_INTERNAL_SUPPORT 0.5.0 0.6.0 0.6.1 0.6.2)125 OPTION(CEGUILUA_USE_EXTERNAL_LIBRARY "Force the use of external CEGUILua library" OFF)126 FIND_PACKAGE(CEGUI 0.5 REQUIRED)127 128 ##### Lua #####129 IF(CEGUILUA_USE_EXTERNAL_LIBRARY)130 COMPARE_VERSION_STRINGS(${CEGUI_VERSION} "0.6" _version_comparison)131 IF(version_comparison LESS 0)132 SET(LUA_VERSION_REQUEST 5.0)133 ELSE()134 SET(LUA_VERSION_REQUEST 5.1)135 ENDIF()136 ELSE()137 SET(LUA_VERSION_REQUEST 5)138 ENDIF()139 FIND_PACKAGE(Lua ${LUA_VERSION_REQUEST} EXACT REQUIRED)140 133 141 134 ##### OpenAL ##### … … 161 154 162 155 ##### Boost ##### 163 # Expand the next statement if newer boost versions than 1.36.1are released164 SET(Boost_ADDITIONAL_VERSIONS 1. 37 1.37.0 1.38 1.38.0 1.39 1.39.0 1.40 1.40.0165 1.4 1 1.41.0 1.42 1.42.0 1.43 1.43.0 1.44 1.44.0)166 IF( NOT TARDIS)167 FIND_PACKAGE(Boost 1. 35REQUIRED thread filesystem system date_time)156 # Expand the next statement if newer boost versions are released 157 SET(Boost_ADDITIONAL_VERSIONS 1.40 1.40.0 1.41 1.41.0 1.42 1.42.0 1.43 1.43.0 158 1.44 1.44.0 1.45 1.45.0 1.46 1.46.0 1.46.1) 159 IF(NOT TARDIS) 160 FIND_PACKAGE(Boost 1.40 REQUIRED thread filesystem system date_time) 168 161 ENDIF() 169 162 # No auto linking, so this option is useless anyway 170 163 MARK_AS_ADVANCED(Boost_LIB_DIAGNOSTIC_DEFINITIONS) 164 165 ##### OGRE ##### 166 FIND_PACKAGE(OGRE 1.6 REQUIRED) 167 # For Ogre >= 1.7, we might need a threading library 168 # Variables are either defined by dependency package config or by FindOGRE 169 IF(OGRE_NEEDS_POCO) 170 FIND_PACKAGE(POCO REQUIRED) 171 # Always link against POCO too because of threading 172 SET(OGRE_LIBRARY ${OGRE_LIBRARY} ${POCO_LIBRARY}) 173 ELSEIF(OGRE_NEEDS_BOOST) 174 # Always link against boost too because of threading 175 SET(OGRE_LIBRARY ${OGRE_LIBRARY} ${Boost_THREAD_LIBRARY}) 176 ENDIF() 171 177 172 178 … … 177 183 # Note: Default option in the libraries vary, but our default option is dynamic 178 184 IF(WIN32) 179 OPTION(LINK_BOOST_DYNAMIC "Link Boost dynamically on Windows" TRUE) 180 OPTION(LINK_CEGUI_DYNAMIC "Link CEGUI dynamicylly on Windows" TRUE) 181 #OPTION(LINK_ENET_DYNAMIC "Link ENet dynamically on Windows" TRUE) 182 OPTION(LINK_OGRE_DYNAMIC "Link OGRE dynamically on Windows" TRUE) 183 OPTION(LINK_TCL_DYNAMIC "Link TCL dynamically on Windows" TRUE) 184 OPTION(LINK_ZLIB_DYNAMIC "Link ZLib dynamically on Windows" TRUE) 185 COMPARE_VERSION_STRINGS("${LUA_VERSION}" "5.1" _version_comparison) 186 IF(_version_comparison LESS 0) 187 OPTION(LINK_LUA_DYNAMIC "Link Lua dynamically on Windows" FALSE) 188 ELSE(_version_comparison LESS 0) 189 OPTION(LINK_LUA_DYNAMIC "Link Lua dynamically on Windows" TRUE) 190 ENDIF(_version_comparison LESS 0) 185 OPTION(LINK_BOOST_DYNAMIC "Link Boost dynamically on Windows" TRUE) 186 OPTION(LINK_CEGUI_DYNAMIC "Link CEGUI dynamicylly on Windows" TRUE) 187 #OPTION(LINK_ENET_DYNAMIC "Link ENet dynamically on Windows" TRUE) 188 OPTION(LINK_OGRE_DYNAMIC "Link OGRE dynamically on Windows" TRUE) 189 OPTION(LINK_TCL_DYNAMIC "Link TCL dynamically on Windows" TRUE) 190 OPTION(LINK_ZLIB_DYNAMIC "Link ZLib dynamically on Windows" TRUE) 191 OPTION(LINK_LUA5.1_DYNAMIC "Link Lua dynamically on Windows" TRUE) 191 192 192 193 IF(DEPENDENCY_PACKAGE_ENABLE) … … 194 195 LINK_BOOST_DYNAMIC LINK_CEGUI_DYNAMIC #LINK_ENET_DYNAMIC 195 196 LINK_OGRE_DYNAMIC LINK_TCL_DYNAMIC LINK_ZLIB_DYNAMIC 196 LINK_LUA _DYNAMIC197 LINK_LUA5.1_DYNAMIC 197 198 ) 198 199 ENDIF() -
code/trunk/cmake/LibraryConfigTardis.cmake
r6746 r8351 25 25 # 26 26 27 IF(UNIX AND NOT APPLE) 28 IF(EXISTS /etc/hostname) 29 FILE(STRINGS /etc/hostname HOSTNAME LIMIT_COUNT 1) 30 IF(${HOSTNAME} MATCHES "^tardis-[a-z][0-9][0-9]$") 31 SET (TARDIS ON) 32 ENDIF() 27 IF(LINUX AND EXISTS /etc/hostname) 28 FILE(STRINGS /etc/hostname HOSTNAME LIMIT_COUNT 1) 29 IF(${HOSTNAME} MATCHES "^tardis-[a-z][0-9][0-9]$") 30 SET (TARDIS ON) 33 31 ENDIF() 34 32 ENDIF() … … 77 75 #SET(ENV{OGGDIR} "/usr/pack/oggvorbis-1.0-ds;/usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0") 78 76 #SET(ENV{VORBISDIR} "/usr/pack/oggvorbis-1.0-ds;/usr/pack/oggvorbis-1.0-ds/i686-debian-linux3.0") 79 #SET(ENV{LUA _DIR}"/usr/pack/lua-5.1.4-sd;/usr/pack/lua-5.1.4-sd/i686-debian-linux4.0")77 #SET(ENV{LUA5.1_DIR} "/usr/pack/lua-5.1.4-sd;/usr/pack/lua-5.1.4-sd/i686-debian-linux4.0") 80 78 #SET(ENV{OGRE_HOME} "/usr/pack/ogre-1.4.9-sd;/usr/pack/ogre-1.4.9-sd/i686-debian-linux4.0") 81 79 #SET(ENV{OPENALDIR} "/usr/pack/openal-0.0.8-cl;/usr/pack/openal-0.0.8-cl/i686-debian-linux3.1") -
code/trunk/cmake/PackageConfig.cmake
r7459 r8351 25 25 # 26 26 27 # Check package version info28 # MAJOR: Breaking change29 # MINOR: No breaking changes by the dependency package30 # For example any code running on 3.0 should still run on 3.131 # But you can specify that the code only runs on 3.1 and higher32 # or 4.0 and higher (so both 3.1 and 4.0 will work).33 SET(ALLOWED_MINIMUM_VERSIONS 3.1 4.0 5.0)34 35 IF(NOT EXISTS ${DEPENDENCY_PACKAGE_DIR}/version.txt)36 SET(DEPENDENCY_VERSION 1.0)37 ELSE()38 # Get version from file39 FILE(READ ${DEPENDENCY_PACKAGE_DIR}/version.txt _file_content)40 SET(_match)41 STRING(REGEX MATCH "([0-9]+.[0-9]+)" _match ${_file_content})42 IF(_match)43 SET(DEPENDENCY_VERSION ${_match})44 ELSE()45 MESSAGE(FATAL_ERROR "The version.txt file in the dependency file has corrupt version information.")46 ENDIF()47 ENDIF()48 49 INCLUDE(CompareVersionStrings)50 SET(_version_match FALSE)51 FOREACH(_version ${ALLOWED_MINIMUM_VERSIONS})52 # Get major version53 STRING(REGEX REPLACE "^([0-9]+)\\..*$" "\\1" _major_version "${_version}")54 COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${_major_version} _result TRUE)55 IF(_result EQUAL 0)56 COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} ${_version} _result FALSE)57 IF(NOT _result LESS 0)58 SET(_version_match TRUE)59 ENDIF()60 ENDIF()61 ENDFOREACH(_version)62 IF(NOT _version_match)63 MESSAGE(FATAL_ERROR "Your dependency package version is ${DEPENDENCY_VERSION}\n"64 "Possible required versions: ${ALLOWED_MINIMUM_VERSIONS}\n"65 "You can get a new version from www.orxonox.net")66 ENDIF()67 68 27 IF(NOT _INTERNAL_PACKAGE_MESSAGE) 69 28 MESSAGE(STATUS "Using library package for the dependencies.") … … 73 32 # Ogre versions >= 1.7 require the POCO library on Windows with MSVC for threading 74 33 COMPARE_VERSION_STRINGS(${DEPENDENCY_VERSION} 5 _result TRUE) 75 IF(NOT _result EQUAL -1 AND NOT MINGW)76 SET(POCO_REQUIREDTRUE)34 IF(NOT _result EQUAL -1 AND NOT APPLE) 35 SET(OGRE_NEEDS_POCO TRUE) 77 36 ENDIF() 78 37 … … 84 43 SET(ENV{DXSDK_DIR} ${DEP_INCLUDE_DIR}/directx) 85 44 #SET(ENV{ENETDIR} ${DEP_INCLUDE_DIR}/enet) 86 SET(ENV{LUA _DIR}${DEP_INCLUDE_DIR}/lua)45 SET(ENV{LUA5.1_DIR} ${DEP_INCLUDE_DIR}/lua) 87 46 SET(ENV{OGGDIR} ${DEP_INCLUDE_DIR}/libogg) 88 47 SET(ENV{VORBISDIR} ${DEP_INCLUDE_DIR}/libvorbis) … … 116 75 117 76 ## RELEASE 118 # Try to filter out all the debug libraries. If the regex doesn't do the 119 # job anymore, simply adjust it. 120 INSTALL( 121 DIRECTORY ${DEP_BINARY_DIR}/ 122 DESTINATION bin 123 CONFIGURATIONS Release RelWithDebInfo MinSizeRel 124 REGEX "_[Dd]\\.[a-zA-Z0-9+-]+$|-mt-gd-|^.*\\.pdb$" EXCLUDE 125 ) 77 IF(EXISTS ${DEP_BINARY_DIR}/install_manifest.txt) 78 FILE(STRINGS ${DEP_BINARY_DIR}/install_manifest.txt _files) 79 FOREACH(_file ${_files}) 80 INSTALL( 81 FILES ${DEP_BINARY_DIR}/${_file} 82 DESTINATION bin 83 CONFIGURATIONS Release RelWithDebInfo MinSizeRel 84 ) 85 ENDFOREACH(_file) 86 ELSE() 87 # Try to filter out all the debug libraries. If the regex doesn't do the 88 # job anymore, simply adjust it. 89 INSTALL( 90 DIRECTORY ${DEP_BINARY_DIR}/ 91 DESTINATION bin 92 CONFIGURATIONS Release RelWithDebInfo MinSizeRel 93 REGEX "_[Dd]\\.[a-zA-Z0-9+-]+$|-mt-gd-|^.*\\.pdb$" EXCLUDE 94 ) 95 ENDIF() 126 96 ENDIF() -
code/trunk/cmake/PackageConfigMSVC.cmake
r7818 r8351 28 28 IF(MSVC) 29 29 30 INCLUDE(CheckPackageVersion) 31 CHECK_PACKAGE_VERSION(4.3 6.0) 32 30 33 # 64 bit system? 31 34 IF(CMAKE_SIZEOF_VOID_P EQUAL 8) … … 36 39 37 40 # Choose right MSVC version 38 STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?) 41 STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?).*$" "\\1" 39 42 _msvc_version "${CMAKE_GENERATOR}") 40 43 … … 54 57 # Certain find scripts don't behave as ecpected to we have 55 58 # to specify the libraries ourselves. 56 SET(TCL_LIBRARY ${DEP_LIBRARY_DIR}/tcl85.lib CACHE FILEPATH "") 57 SET(ZLIB_LIBRARY ${DEP_LIBRARY_DIR}/zdll.lib CACHE FILEPATH "") 59 IF(MSVC10) 60 SET(TCL_LIBRARY 61 optimized ${DEP_LIBRARY_DIR}/tcl85t.lib 62 debug ${DEP_LIBRARY_DIR}/tcl85tg.lib 63 CACHE FILEPATH "" 64 ) 65 SET(ZLIB_LIBRARY 66 optimized ${DEP_LIBRARY_DIR}/zlib-vc100.lib 67 debug ${DEP_LIBRARY_DIR}/zlib-vc100_d.lib 68 CACHE FILEPATH "" 69 ) 70 ELSE() 71 SET(TCL_LIBRARY ${DEP_LIBRARY_DIR}/tcl85.lib CACHE FILEPATH "") 72 SET(ZLIB_LIBRARY ${DEP_LIBRARY_DIR}/zdll.lib CACHE FILEPATH "") 73 ENDIF() 74 # Part of Platform SDK and usually gets linked automatically 75 SET(WMI_LIBRARY wbemuuid.lib) 58 76 59 77 ENDIF(MSVC) -
code/trunk/cmake/PackageConfigMinGW.cmake
r5781 r8351 28 28 IF(MINGW) 29 29 30 INCLUDE(CheckPackageVersion) 31 CHECK_PACKAGE_VERSION(6.0) 32 30 33 # 64 bit system? 31 34 IF(CMAKE_SIZEOF_VOID_P EQUAL 8) … … 48 51 # to specify the libraries ourselves. 49 52 SET(TCL_LIBRARY ${DEP_BINARY_DIR}/tcl85.dll CACHE FILEPATH "") 50 SET(ZLIB_LIBRARY ${DEP_BINARY_DIR}/zlib1.dll CACHE FILEPATH "") 53 SET(ZLIB_LIBRARY ${DEP_BINARY_DIR}/libzlib.dll CACHE FILEPATH "") 54 55 # Not included in MinGW, so we need to supply it for OIS 56 SET(WMI_INCLUDE_DIR ${DEP_INCLUDE_DIR}/wmi/include) 57 SET(WMI_LIBRARY ${DEP_LIBRARY_DIR}/wbemuuid.lib) 51 58 52 59 ENDIF(MINGW) -
code/trunk/cmake/tools/CheckOGREPlugins.cmake
r8264 r8351 52 52 NAMES ${_plugin} 53 53 PATHS $ENV{OGRE_HOME} $ENV{OGRE_PLUGIN_DIR} 54 PATH_SUFFIXES bin/Release bin/release Release release lib lib/OGRE bin 54 PATH_SUFFIXES bin/Release bin/release Release release lib lib/OGRE bin Ogre.framework/Resources 55 55 ) 56 56 FIND_LIBRARY(OGRE_PLUGIN_${_plugin}_DEBUG 57 57 NAMES ${_plugin}d ${_plugin}_d ${_plugin} 58 58 PATHS $ENV{OGRE_HOME} $ENV{OGRE_PLUGIN_DIR} 59 PATH_SUFFIXES bin/Debug bin/debug Debug debug lib lib/OGRE bin 59 PATH_SUFFIXES bin/Debug bin/debug Debug debug lib lib/OGRE bin Ogre.framework/Resources 60 60 ) 61 61 # We only need at least one render system. Check at the end. -
code/trunk/cmake/tools/FindALUT.cmake
r7163 r8351 1 # - Locate FreeAlut 2 # This module defines 3 # ALUT_LIBRARY 4 # ALUT_FOUND, if false, do not try to link against Alut 5 # ALUT_INCLUDE_DIR, where to find the headers 6 # 7 # $ALUTDIR is an environment variable that would 8 # correspond to the ./configure --prefix=$ALUTDIR 9 # used in building Alut. 10 # 11 # Created by Eric Wing. This was influenced by the FindSDL.cmake module. 12 # On OSX, this will prefer the Framework version (if found) over others. 13 # People will have to manually change the cache values of 14 # ALUT_LIBRARY to override this selection. 15 # Tiger will include OpenAL as part of the System. 16 # But for now, we have to look around. 17 # Other (Unix) systems should be able to utilize the non-framework paths. 18 # 19 # Several changes and additions by Fabian 'x3n' Landau 20 # Some simplifications by Adrian Friedli and Reto Grieder 21 # > www.orxonox.net < 1 # 2 # ORXONOX - the hottest 3D action shooter ever to exist 3 # > www.orxonox.net < 4 # 5 # This program is free software; you can redistribute it and/or 6 # modify it under the terms of the GNU General Public License 7 # as published by the Free Software Foundation; either version 2 8 # of the License, or (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License along 16 # with this program; if not, write to the Free Software Foundation, 17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # 19 # 20 # Author: 21 # Kevin Young 22 # Description: 23 # Variables defined: 24 # ALUT_FOUND 25 # ALUT_INCLUDE_DIR 26 # ALUT_LIBRARY 27 # 22 28 23 29 INCLUDE(FindPackageHandleStandardArgs) 24 30 INCLUDE(HandleLibraryTypes) 25 31 26 FIND_PATH(ALUT_INCLUDE_DIR AL/alut.h 27 PATHS 28 $ENV{ALUTDIR} 29 ~/Library/Frameworks/OpenAL.framework 30 /Library/Frameworks/OpenAL.framework 31 /System/Library/Frameworks/OpenAL.framework # Tiger 32 PATH_SUFFIXES include include/OpenAL include/AL Headers 32 FIND_PATH(ALUT_INCLUDE_DIR alut.h 33 PATHS $ENV{ALUTDIR} 34 PATH_SUFFIXES include include/AL 33 35 ) 34 35 # I'm not sure if I should do a special casing for Apple. It is 36 # unlikely that other Unix systems will find the framework path. 37 # But if they do ([Next|Open|GNU]Step?), 38 # do they want the -framework option also? 39 IF(${ALUT_INCLUDE_DIR} MATCHES ".framework") 40 41 STRING(REGEX REPLACE "(.*)/.*\\.framework/.*" "\\1" ALUT_FRAMEWORK_PATH_TMP ${ALUT_INCLUDE_DIR}) 42 IF("${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/Library/Frameworks" 43 OR "${ALUT_FRAMEWORK_PATH_TMP}" STREQUAL "/System/Library/Frameworks" 44 ) 45 # String is in default search path, don't need to use -F 46 SET (ALUT_LIBRARY_OPTIMIZED "-framework OpenAL" CACHE STRING "OpenAL framework for OSX") 47 ELSE() 48 # String is not /Library/Frameworks, need to use -F 49 SET(ALUT_LIBRARY_OPTIMIZED "-F${ALUT_FRAMEWORK_PATH_TMP} -framework OpenAL" CACHE STRING "OpenAL framework for OSX") 50 ENDIF() 51 # Clear the temp variable so nobody can see it 52 SET(ALUT_FRAMEWORK_PATH_TMP "" CACHE INTERNAL "") 53 54 ELSE() 55 FIND_LIBRARY(ALUT_LIBRARY_OPTIMIZED 56 NAMES alut 57 PATHS $ENV{ALUTDIR} 58 PATH_SUFFIXES lib libs 59 ) 60 FIND_LIBRARY(ALUT_LIBRARY_DEBUG 61 NAMES alutd alut_d alutD alut_D 62 PATHS $ENV{ALUTDIR} 63 PATH_SUFFIXES lib libs 64 ) 65 ENDIF() 36 FIND_LIBRARY(ALUT_LIBRARY_OPTIMIZED 37 NAMES alut ALUT 38 PATHS $ENV{ALUTDIR} 39 PATH_SUFFIXES lib bin/Release bin/release Release release ALUT 40 ) 41 FIND_LIBRARY(ALUT_LIBRARY_DEBUG 42 NAMES alutd alut_d alutD alut_D ALUTd ALUT_d ALUTD ALUT_D 43 PATHS $ENV{ALUTDIR} 44 PATH_SUFFIXES lib bin/Debug bin/debug Debug debug ALUT 45 ) 66 46 67 47 # Handle the REQUIRED argument and set ALUT_FOUND 68 48 FIND_PACKAGE_HANDLE_STANDARD_ARGS(ALUT DEFAULT_MSG 69 70 49 ALUT_LIBRARY_OPTIMIZED 50 ALUT_INCLUDE_DIR 71 51 ) 72 52 … … 75 55 76 56 MARK_AS_ADVANCED( 77 78 79 57 ALUT_INCLUDE_DIR 58 ALUT_LIBRARY_OPTIMIZED 59 ALUT_LIBRARY_DEBUG 80 60 ) -
code/trunk/cmake/tools/FindCEGUI.cmake
r7163 r8351 4 4 # CEGUI_INCLUDE_DIR 5 5 # CEGUI_LIBRARY, the library to link against to use CEGUI. 6 # CEGUILUA_LIBRARY, the library to link against to use the CEGUI script module. 7 # CEGUI_TOLUA_LIBRARY, the library to link against to use Tolua++. 6 8 # CEGUI_FOUND, If false, do not try to use CEGUI 7 9 # CEGUI_VERSION, the version as string "x.y.z" 8 # CEGUILUA_LIBRARY, Script module library9 # CEGUILUA_USE_INTERNAL_LIBRARY, True if CEGUILUA_LIBRARY was not defined here10 10 # 11 11 # Input: 12 12 # ENV{CEGUIDIR}, CEGUI path, optional 13 # FIND CEGUILUA_INTERNAL_SUPPORT, List of all CEGUILua version supported14 # in the source repository15 # CEGUILUA_USE_EXTERNAL_LIBRARY, Force finding of CEGUILua16 13 # 17 14 # Created by Matt Williams to find OGRE libraries … … 29 26 # > www.orxonox.net < 30 27 28 INCLUDE(CompareVersionStrings) 31 29 INCLUDE(DetermineVersion) 32 30 INCLUDE(FindPackageHandleAdvancedArgs) 33 31 INCLUDE(HandleLibraryTypes) 34 32 33 # Find CEGUI headers 35 34 FIND_PATH(CEGUI_INCLUDE_DIR CEGUI.h 36 35 PATHS $ENV{CEGUIDIR} 37 PATH_SUFFIXES include include/CEGUI CEGUI.framework/Headers36 PATH_SUFFIXES include include/CEGUI 38 37 ) 38 39 # Inspect CEGUIVersion.h for the version number 40 DETERMINE_VERSION(CEGUI ${CEGUI_INCLUDE_DIR}/CEGUIVersion.h) 41 42 # Find CEGUI library 39 43 FIND_LIBRARY(CEGUI_LIBRARY_OPTIMIZED 40 44 NAMES CEGUIBase CEGUI … … 50 54 ) 51 55 52 # Inspect CEGUIVersion.h for the version number 53 DETERMINE_VERSION(CEGUI ${CEGUI_INCLUDE_DIR}/CEGUIVersion.h) 56 # Find CEGUILua headers 57 FIND_PATH(CEGUILUA_INCLUDE_DIR CEGUILua.h 58 PATHS 59 $ENV{CEGUIDIR} 60 $ENV{CEGUILUADIR} 61 ${CEGUI_INCLUDE_DIR}/ScriptingModules/LuaScriptModule 62 PATH_SUFFIXES include include/CEGUI 63 ) 64 # Find CEGUILua libraries 65 FIND_LIBRARY(CEGUILUA_LIBRARY_OPTIMIZED 66 NAMES CEGUILua CEGUILuaScriptModule 67 PATHS $ENV{CEGUIDIR} $ENV{CEGUILUADIR} 68 PATH_SUFFIXES lib bin 69 ) 70 FIND_LIBRARY(CEGUILUA_LIBRARY_DEBUG 71 NAMES CEGUILuad CEGUILua_d CEGUILuaScriptModuled CEGUILuaScriptModule_d 72 PATHS $ENV{CEGUIDIR} $ENV{CEGUILUADIR} 73 PATH_SUFFIXES lib bin 74 ) 75 76 # Find CEGUI Tolua++ include file 77 # We only need to add this path since we use tolua++ like a normal 78 # dependency but it is shipped with CEGUILua. 79 FIND_PATH(CEGUI_TOLUA_INCLUDE_DIR tolua++.h 80 PATHS 81 ${CEGUILUA_INCLUDE_DIR} 82 # For newer CEGUI versions >= 0.7 83 ${CEGUILUA_INCLUDE_DIR}/support/tolua++ 84 # For Mac OS X, tolua++ is a separate framework in the dependency package 85 ${DEP_FRAMEWORK_DIR} 86 NO_DEFAULT_PATH # Don't attempt to find tolua++ installed on the system 87 ) 88 # Find CEGUI Tolua++ libraries 89 FIND_LIBRARY(CEGUI_TOLUA_LIBRARY_OPTIMIZED 90 NAMES CEGUItoluapp tolua++ ceguitolua++ 91 PATHS $ENV{CEGUIDIR} ${CEGUITOLUADIR} 92 PATH_SUFFIXES lib bin 93 ) 94 FIND_LIBRARY(CEGUI_TOLUA_LIBRARY_DEBUG 95 NAMES CEGUItoluappd CEGUItoluapp_d tolua++d tolua++_d 96 PATHS $ENV{CEGUIDIR} ${CEGUITOLUADIR} 97 PATH_SUFFIXES lib bin 98 ) 99 100 # Newer versions of CEGUI have the renderer for OGRE shipped with them 101 COMPARE_VERSION_STRINGS("${CEGUI_VERSION}" "0.7" _version_compare TRUE) 102 IF(_version_compare GREATER -1) 103 # Find CEGUI OGRE Renderer headers 104 FIND_PATH(CEGUI_OGRE_RENDERER_INCLUDE_DIR CEGUIOgreRenderer.h 105 PATHS 106 $ENV{CEGUIDIR} 107 $ENV{CEGUIOGRERENDERERDIR} 108 ${CEGUI_INCLUDE_DIR}/RendererModules/Ogre 109 PATH_SUFFIXES include include/CEGUI 110 ) 111 # Find CEGUI OGRE Renderer libraries 112 FIND_LIBRARY(CEGUI_OGRE_RENDERER_LIBRARY_OPTIMIZED 113 NAMES CEGUIOgreRenderer 114 PATHS $ENV{CEGUIDIR} $ENV{CEGUIOGRERENDERERDIR} 115 PATH_SUFFIXES lib bin 116 ) 117 FIND_LIBRARY(CEGUI_OGRE_RENDERER_LIBRARY_DEBUG 118 NAMES CEGUIOgreRendererd CEGUIOgreRenderer_d 119 PATHS $ENV{CEGUIDIR} $ENV{CEGUIOGRERENDERERDIR} 120 PATH_SUFFIXES lib bin 121 ) 122 SET(CEGUI_OGRE_RENDERER_REQUIRED_VARIABLES 123 CEGUI_OGRE_RENDERER_INCLUDE_DIR 124 CEGUI_OGRE_RENDERER_LIBRARY_OPTIMIZED 125 ) 126 ELSE() 127 SET(CEGUI_OLD_VERSION TRUE) 128 SET(CEGUI_OGRE_RENDERER_BUILD_REQUIRED TRUE) 129 ENDIF() 54 130 55 131 # Handle the REQUIRED argument and set CEGUI_FOUND 56 132 # Also checks the version requirements if given 57 133 FIND_PACKAGE_HANDLE_ADVANCED_ARGS(CEGUI DEFAULT_MSG "${CEGUI_VERSION}" 134 CEGUI_INCLUDE_DIR 58 135 CEGUI_LIBRARY_OPTIMIZED 59 CEGUI_INCLUDE_DIR 136 CEGUILUA_INCLUDE_DIR 137 CEGUILUA_LIBRARY_OPTIMIZED 138 CEGUI_TOLUA_INCLUDE_DIR 139 CEGUI_TOLUA_LIBRARY_OPTIMIZED 140 ${CEGUI_OGRE_RENDERER_REQUIRED_VARIABLES} 60 141 ) 61 142 62 143 # Collect optimized and debug libraries 63 144 HANDLE_LIBRARY_TYPES(CEGUI) 145 HANDLE_LIBRARY_TYPES(CEGUILUA) 146 HANDLE_LIBRARY_TYPES(CEGUI_TOLUA) 147 IF(NOT CEGUI_OGRE_RENDERER_BUILD_REQUIRED) 148 HANDLE_LIBRARY_TYPES(CEGUI_OGRE_RENDERER) 149 ENDIF() 64 150 65 151 MARK_AS_ADVANCED( … … 67 153 CEGUI_LIBRARY_OPTIMIZED 68 154 CEGUI_LIBRARY_DEBUG 155 CEGUILUA_INCLUDE_DIR 156 CEGUILUA_LIBRARY_OPTIMIZED 157 CEGUILUA_LIBRARY_DEBUG 158 CEGUI_TOLUA_INCLUDE_DIR 159 CEGUI_TOLUA_LIBRARY_OPTIMIZED 160 CEGUI_TOLUA_LIBRARY_DEBUG 161 CEGUI_OGRE_RENDERER_INCLUDE_DIR 162 CEGUI_OGRE_RENDERER_LIBRARY_OPTIMIZED 163 CEGUI_OGRE_RENDERER_LIBRARY_DEBUG 69 164 ) 70 71 LIST(FIND CEGUILUA_INTERNAL_SUPPORT "${CEGUI_VERSION}" _find_result)72 IF(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1)73 # Also try to find the CEGUILua libraries.74 # There would already be libraries in src/ for versions 0.5 and 0.675 FIND_LIBRARY(CEGUILUA_LIBRARY_OPTIMIZED76 NAMES CEGUILua77 PATHS $ENV{CEGUIDIR}78 PATH_SUFFIXES lib bin79 )80 FIND_LIBRARY(CEGUILUA_LIBRARY_DEBUG81 NAMES CEGUILuad CEGUILua_d82 PATHS $ENV{CEGUIDIR}83 PATH_SUFFIXES lib bin84 )85 86 SET(CEGUILua_FIND_REQUIRED ${CEGUI_FIND_REQUIRED})87 # Handle the REQUIRED argument and set CEGUILUA_FOUND88 FIND_PACKAGE_HANDLE_STANDARD_ARGS(CEGUILua DEFAULT_MSG89 CEGUILUA_LIBRARY_OPTIMIZED90 )91 92 # Collect optimized and debug libraries93 HANDLE_LIBRARY_TYPES(CEGUILUA)94 95 MARK_AS_ADVANCED(96 CEGUILUA_LIBRARY_OPTIMIZED97 CEGUILUA_LIBRARY_DEBUG98 )99 100 ELSE(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1)101 SET(CEGUILUA_USE_INTERNAL_LIBRARY TRUE)102 ENDIF(CEGUILUA_USE_EXTERNAL_LIBRARY OR _find_result EQUAL -1)103 -
code/trunk/cmake/tools/FindOGRE.cmake
r7163 r8351 23 23 FIND_PATH(OGRE_INCLUDE_DIR Ogre.h 24 24 PATHS $ENV{OGRE_HOME} 25 PATH_SUFFIXES include include/OGRE Ogre.framework/Headers25 PATH_SUFFIXES include include/OGRE 26 26 ) 27 27 FIND_LIBRARY(OGRE_LIBRARY_OPTIMIZED … … 33 33 NAMES OgreMaind OgreMain_d OgreMainD OgreMain_D Ogred Ogre_d OgreD Ogre_d 34 34 PATHS $ENV{OGRE_HOME} 35 PATH_SUFFIXES lib bin/Debug bin/debug Debug debug Versions/A35 PATH_SUFFIXES lib bin/Debug bin/debug Debug debug 36 36 ) 37 37 -
code/trunk/cmake/tools/FindOgg.cmake
r7163 r8351 22 22 ) 23 23 FIND_LIBRARY(OGG_LIBRARY_OPTIMIZED 24 NAMES ogg 24 NAMES ogg ogg-0 libogg 25 25 PATHS $ENV{OGGDIR} 26 26 PATH_SUFFIXES lib 27 27 ) 28 28 FIND_LIBRARY(OGG_LIBRARY_DEBUG 29 NAMES oggd ogg_d oggD ogg_D 29 NAMES oggd ogg_d oggD ogg_D libogg_d 30 30 PATHS $ENV{OGGDIR} 31 31 PATH_SUFFIXES lib -
code/trunk/cmake/tools/FindPOCO.cmake
r7285 r8351 29 29 FIND_PATH(POCO_INCLUDE_DIR Poco/Poco.h 30 30 PATHS $ENV{POCODIR} 31 PATH_SUFFIXES include 31 PATH_SUFFIXES include Foundation/include 32 32 ) 33 33 FIND_LIBRARY(POCO_LIBRARY_OPTIMIZED -
code/trunk/cmake/tools/FindVorbis.cmake
r7163 r8351 22 22 ) 23 23 FIND_LIBRARY(VORBIS_LIBRARY_OPTIMIZED 24 NAMES vorbis 24 NAMES vorbis vorbis-0 libvorbis 25 25 PATHS $ENV{VORBISDIR} 26 26 PATH_SUFFIXES lib 27 27 ) 28 28 FIND_LIBRARY(VORBIS_LIBRARY_DEBUG 29 NAMES vorbisd vorbis_d vorbisD vorbis_D 29 NAMES vorbisd vorbis_d vorbisD vorbis_D libvorbis_d 30 30 PATHS $ENV{VORBISDIR} 31 31 PATH_SUFFIXES lib 32 32 ) 33 33 FIND_LIBRARY(VORBISFILE_LIBRARY_OPTIMIZED 34 NAMES vorbisfile 34 NAMES vorbisfile vorbisfile-3 libvorbisfile 35 35 PATHS $ENV{VORBISDIR} 36 36 PATH_SUFFIXES lib 37 37 ) 38 38 FIND_LIBRARY(VORBISFILE_LIBRARY_DEBUG 39 NAMES vorbisfiled vorbisfile_d vorbisfileD vorbisfile_D 39 NAMES vorbisfiled vorbisfile_d vorbisfileD vorbisfile_D libvorbisfile_d 40 40 PATHS $ENV{VORBISDIR} 41 41 PATH_SUFFIXES lib -
code/trunk/cmake/tools/GenerateToluaBindings.cmake
r7415 r8351 32 32 # RUNTIME_LIBRARY_DIRECTORY - Working directory 33 33 # 34 35 # Workaround for XCode: The folder where the bind files are written to has 36 # to be present beforehand. 37 # We have to do this here because the header files are all stored in a single 38 # location per configuration. 39 IF(CMAKE_CONFIGURATION_TYPES) 40 FOREACH(_dir ${CMAKE_CONFIGURATION_TYPES}) 41 FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/src/toluabind/${_dir}") 42 ENDFOREACH(_dir) 43 ENDIF() 34 44 35 45 FUNCTION(GENERATE_TOLUA_BINDINGS _tolua_package _target_source_files) -
code/trunk/cmake/tools/TargetUtilities.cmake
r8079 r8351 43 43 # Lists: 44 44 # LINK_LIBRARIES: Redirects to TARGET_LINK_LIBRARIES 45 # LINK_LIBS_LINUX: Redirects to TARGET_LINK_LIBRARIES only on Linux 46 # LINK_LIBS_WIN32: Redirects to TARGET_LINK_LIBRARIES only on Windows 47 # LINK_LIBS_APPLE: Redirects to TARGET_LINK_LIBRARIES only on Apple 48 # LINK_LIBS_UNIX: Redirects to TARGET_LINK_LIBRARIES only on UNIX 45 49 # VERSION: Set version to the binary 46 50 # SOURCE_FILES: Source files for the target … … 53 57 # This function also installs the target! 54 58 # Prerequisistes: 55 # ORXONOX_DEFAULT_LINK , ORXONOX_CONFIG_FILES59 # ORXONOX_DEFAULT_LINK 56 60 # Parameters: 57 61 # _target_name, ARGN for the macro arguments … … 86 90 SET(_list_names LINK_LIBRARIES VERSION SOURCE_FILES 87 91 DEFINE_SYMBOL TOLUA_FILES PCH_FILE 88 PCH_EXCLUDE OUTPUT_NAME) 92 PCH_EXCLUDE OUTPUT_NAME LINK_LIBS_LINUX 93 LINK_LIBS_WIN32 LINK_LIBS_APPLE LINK_LIBS_UNIX) 89 94 90 95 PARSE_MACRO_ARGUMENTS("${_switches}" "${_list_names}" ${ARGN}) … … 104 109 MESSAGE(FATAL_ERROR "No name provided for source file compilation") 105 110 ENDIF() 106 IF(NOT _compilation_include_string)107 MESSAGE(STATUS "Warning: Empty source file compilation!")108 ENDIF()109 111 IF(NOT DISABLE_COMPILATIONS) 112 IF(NOT _compilation_include_string) 113 MESSAGE(STATUS "Warning: Empty source file compilation!") 114 ENDIF() 110 115 IF(EXISTS ${_compilation_file}) 111 116 FILE(READ ${_compilation_file} _include_string_file) … … 169 174 GENERATE_TOLUA_BINDINGS(${_target_name_capitalised} _${_target_name}_files 170 175 INPUTFILES ${_arg_TOLUA_FILES}) 176 # Workaround for XCode: The folder where the bind files are written to has 177 # to be present beforehand. 178 IF(CMAKE_CONFIGURATION_TYPES) 179 FOREACH(_dir ${CMAKE_CONFIGURATION_TYPES}) 180 FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_dir}) 181 ENDFOREACH(_dir) 182 ENDIF() 171 183 ENDIF() 172 184 … … 192 204 193 205 IF(NOT _arg_ORXONOX_EXTERNAL) 194 # Move the prereqs.h file to the configsection206 # Move the ...Prereqs.h and the PCH files to the 'Config' section 195 207 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_target_name_capitalised}Prereqs.h) 196 208 SOURCE_GROUP("Config" FILES ${_target_name_capitalised}Prereqs.h) 197 209 ENDIF() 198 # Add config files to the config section199 LIST(APPEND _${_target_name}_files ${ORXONOX_CONFIG_FILES})200 SOURCE_GROUP("Config" FILES ${ORXONOX_CONFIG_FILES})210 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE}) 211 SOURCE_GROUP("Config" FILES ${CMAKE_CURRENT_SOURCE_DIR}/${_arg_PCH_FILE}) 212 ENDIF() 201 213 ENDIF() 202 214 ENDIF() … … 217 229 IF(_arg_ORXONOX_EXTERNAL) 218 230 REMOVE_COMPILER_FLAGS("-W3 -W4" MSVC) 219 ADD_COMPILER_FLAGS("-w") 231 ADD_COMPILER_FLAGS("-w" NOT MSVC) 232 ADD_COMPILER_FLAGS("-W0" MSVC) 220 233 ENDIF() 221 234 222 235 # Don't compile header files 223 236 FOREACH(_file ${_${_target_name}_files}) 224 IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx )$")237 IF(NOT _file MATCHES "\\.(c|cc|cpp|cxx|mm)$") 225 238 SET_SOURCE_FILES_PROPERTIES(${_file} PROPERTIES HEADER_FILE_ONLY TRUE) 226 239 ENDIF() … … 278 291 TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBRARIES}) 279 292 ENDIF() 293 IF(_arg_LINK_LIBS_LINUX AND LINUX) 294 TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_LINUX}) 295 ENDIF() 296 IF(_arg_LINK_LIBS_WIN32 AND WIN32) 297 TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_WIN32}) 298 ENDIF() 299 IF(_arg_LINK_LIBS_APPLE AND APPLE) 300 TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_APPLE}) 301 ENDIF() 302 IF(_arg_LINK_LIBS_UNIX AND UNIX) 303 TARGET_LINK_LIBRARIES(${_target_name} ${_arg_LINK_LIBS_UNIX}) 304 ENDIF() 305 306 # RPATH settings for the installation 307 IF("${_target_type}" STREQUAL "LIBRARY") 308 IF(_arg_MODULE) 309 SET(_rpath "${MODULE_RPATH}") 310 ELSE() 311 SET(_rpath "${LIBRARY_RPATH}") 312 ENDIF() 313 ELSE() 314 SET(_rpath "${RUNTIME_RPATH}") 315 ENDIF() 316 SET_TARGET_PROPERTIES(${_target_name} PROPERTIES INSTALL_RPATH "${_rpath}") 280 317 281 318 # DEFINE_SYMBOL -
code/trunk/contrib/orxonox.desktop
- Property svn:eol-style set to native
r8229 r8351 2 2 Name=Orxonox 3 3 Comment=A spacecraft shooter 4 Exec= orxonox4 Exec=/usr/games/orxonox 5 5 Icon=/usr/share/pixmaps/orxonox.png 6 6 Type=Application -
code/trunk/contrib/orxonox.manpage.xml
- Property svn:eol-style set to native
-
code/trunk/data/CMakeLists.txt
r7163 r8351 59 59 DIRECTORY ${EXTERNAL_DATA_DIRECTORY}/ 60 60 DESTINATION ${DATA_INSTALL_DIRECTORY} 61 REGEX "\\.svn$|_svn$| resources\\.oxr|AUTHORS|LICENSE" EXCLUDE61 REGEX "\\.svn$|_svn$|AUTHORS|LICENSE" EXCLUDE 62 62 ) 63 # Configure the install scripts (variables not available during installation)64 CONFIGURE_FILE(DataInstallScript.cmake ${CMAKE_CURRENT_BINARY_DIR}/DataInstallScript.cmake @ONLY)65 # Join both resources.oxr files66 INSTALL(SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/DataInstallScript.cmake) -
code/trunk/data/gui/scripts/AudioMenu.lua
r8079 r8351 32 32 table.insert(themeList, "Default") 33 33 table.insert(themeList, "Drum n' Bass") 34 table.insert(themeList, "8-Bit Style") 35 table.insert(themeList, "Corny Jazz") 34 36 for k,v in pairs(themeList) do 35 37 item = CEGUI.createListboxTextItem(v) … … 39 41 if orxonox.getConfig("MoodManager", "mood_") == "dnb" then 40 42 listboxwindow:setItemSelectState(1,true) 43 elseif orxonox.getConfig("MoodManager", "mood_") == "eightbit" then 44 listboxwindow:setItemSelectState(2,true) 45 elseif orxonox.getConfig("MoodManager", "mood_") == "jazzy" then 46 listboxwindow:setItemSelectState(3,true) 41 47 else 42 48 listboxwindow:setItemSelectState(0,true) … … 168 174 if listboxwindow:isItemSelected(1) then 169 175 orxonox.config("MoodManager", "mood_", "dnb") 176 elseif listboxwindow:isItemSelected(2) then 177 orxonox.config("MoodManager", "mood_", "eightbit") 178 elseif listboxwindow:isItemSelected(3) then 179 orxonox.config("MoodManager", "mood_", "jazzy") 170 180 else 171 181 orxonox.config("MoodManager", "mood_", "default") -
code/trunk/data/gui/scripts/GUITools.lua
r8079 r8351 31 31 32 32 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(window:getLookNFeel()) 33 local height = window:getFont():getLineSpacing() + window:getUnclipped PixelRect():getHeight() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getHeight()34 local width = window:getFont():getTextExtent(window:getText()) + window:getUnclipped PixelRect():getWidth() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getWidth()33 local height = window:getFont():getLineSpacing() + window:getUnclippedOuterRect():getHeight() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getHeight() 34 local width = window:getFont():getTextExtent(window:getText()) + window:getUnclippedOuterRect():getWidth() - lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window):getWidth() 35 35 36 36 table.insert(size, height) … … 40 40 41 41 function getScrollingStepSize(window) 42 local height = window:getUnclipped PixelRect():getHeight()43 local maxHeight = CEGUI.System:getSingleton():getGUISheet():getUnclipped PixelRect():getHeight()42 local height = window:getUnclippedOuterRect():getHeight() 43 local maxHeight = CEGUI.System:getSingleton():getGUISheet():getUnclippedOuterRect():getHeight() 44 44 local ratio = height/maxHeight 45 45 return 0.008*ratio/0.3204 … … 47 47 48 48 function getStaticTextWindowHeight(window) 49 -- Get the area the text is formatted and drawn into. 49 50 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(window:getLookNFeel()) 50 51 local formattedArea = lookAndFeel:getNamedArea("WithFrameTextRenderArea"):getArea():getPixelRect(window) 51 local frameHeight = window:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() 52 local lines = window:getFont():getFormattedLineCount(window:getText(), formattedArea, CEGUI.WordWrapLeftAligned) 53 local height = lines * window:getFont():getLineSpacing() + frameHeight 52 -- Calculate the pixel height of the frame by subtracting the height of the area above from the total height of the window. 53 local frameHeight = window:getUnclippedOuterRect():getHeight() - formattedArea:getHeight() 54 55 local height = 0 56 if ORXONOX_OLD_CEGUI then 57 local lines = window:getFont():getFormattedLineCount(window:getText(), formattedArea, CEGUI.WordWrapLeftAligned) 58 height = lines * window:getFont():getLineSpacing() + frameHeight 59 else 60 height = math.floor(CEGUI.PropertyHelper:stringToFloat(window:getProperty("VertExtent")) + frameHeight) + 1 61 end 54 62 return height 55 63 end -
code/trunk/data/gui/scripts/InitialiseGUI.lua
r7801 r8351 7 7 local scheme = orxonox.CommandExecutor:query("getConfig GUIManager guiScheme_") 8 8 -- Load all required skins 9 --schemeMgr: loadScheme("TaharezGreenLook.scheme")10 schemeMgr: loadScheme(scheme .. "Look.scheme")11 --schemeMgr: loadScheme("TaharezLook.scheme")12 --schemeMgr: loadScheme("WindowsLook.scheme")13 --schemeMgr: loadScheme("VanillaLook.scheme")14 --schemeMgr: loadScheme("SleekSpaceLook.scheme")9 --schemeMgr:create("TaharezGreenLook.scheme") 10 schemeMgr:create(scheme .. "Look.scheme") 11 --schemeMgr:create("TaharezLook.scheme") 12 --schemeMgr:create("WindowsLook.scheme") 13 --schemeMgr:create("VanillaLook.scheme") 14 --schemeMgr:create("SleekSpaceLook.scheme") 15 15 16 16 -- Connect skin specific window types with our own window types 17 17 -- By loading a different file (if there is) you can change the skin 18 18 -- of the menus or the HUD independently 19 --schemeMgr: loadScheme("TaharezGreenMenuWidgets.scheme")19 --schemeMgr:create("TaharezGreenMenuWidgets.scheme") 20 20 --menuImageSet = "TaharezGreenLook" 21 --schemeMgr: loadScheme("TaharezGreenHUDWidgets.scheme")21 --schemeMgr:create("TaharezGreenHUDWidgets.scheme") 22 22 --hudImageSet = "TaharezGreenLook" 23 schemeMgr: loadScheme(scheme .. "MenuWidgets.scheme")23 schemeMgr:create(scheme .. "MenuWidgets.scheme") 24 24 menuImageSet = scheme .. "Look" 25 schemeMgr: loadScheme(scheme .. "HUDWidgets.scheme")25 schemeMgr:create(scheme .. "HUDWidgets.scheme") 26 26 hudImageSet = scheme .. "Look" 27 27 28 28 -- Just a remaining test hack 29 schemeMgr: loadScheme("OrxonoxGUIScheme.scheme")29 schemeMgr:create("OrxonoxGUIScheme.scheme") 30 30 31 31 local system = CEGUI.System:getSingleton() -
code/trunk/data/gui/scripts/NotificationLayer.lua
r8079 r8351 484 484 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) 485 485 local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) 486 local frameHeight = queue:getUnclipped PixelRect():getHeight() - formattedArea:getHeight()486 local frameHeight = queue:getUnclippedOuterRect():getHeight() - formattedArea:getHeight() 487 487 listbox:removeItem(item) 488 488 return frameHeight + singleItemHeight*size -
code/trunk/data/gui/scripts/SettingsMenu.lua
r8079 r8351 35 35 end 36 36 37 function P.onShow() 38 local window = winMgr:getWindow("orxonox/SettingsMenu/AudioButton") 39 if not orxonox.SoundManager:exists() then 40 window:setProperty("Disabled", "true") 41 else 42 window:setProperty("Disabled", "false") 43 end 44 end 45 37 46 function P.SettingsGameplayButton_clicked(e) 38 47 showMenuSheet("GameplayMenu", true) -
code/trunk/data/levels/lastTeamStandingII.oxw
- Property svn:eol-style set to native
-
code/trunk/data/overlays/lastTeamStandingHUD.oxo
- Property svn:eol-style set to native
-
code/trunk/doc/api/doxy.config.in
r7818 r8351 626 626 EXCLUDE = @CMAKE_SOURCE_DIR@/src/external/bullet/ \ 627 627 @CMAKE_SOURCE_DIR@/src/external/cpptcl/ \ 628 @CMAKE_SOURCE_DIR@/src/external/ceguilua/ceguilua-0.5.0 \629 @CMAKE_SOURCE_DIR@/src/external/ceguilua/ceguilua-0.6.0 \630 @CMAKE_SOURCE_DIR@/src/external/ceguilua/ceguilua-0.6.1 \631 628 @CMAKE_SOURCE_DIR@/src/libraries/core/command/IOConsoleWindows.h \ 632 629 @CMAKE_SOURCE_DIR@/src/libraries/core/command/IOConsoleWindows.cc \ -
code/trunk/doc/api/groups/Notifications.dox
- Property svn:eol-style set to native
-
code/trunk/doc/api/groups/Pickup.dox
- Property svn:eol-style set to native
-
code/trunk/doc/api/groups/Questsystem.dox
- Property svn:eol-style set to native
-
code/trunk/doc/api/groups/Triggers.dox
- Property svn:eol-style set to native
-
code/trunk/src/CMakeLists.txt
r8079 r8351 37 37 ADD_COMPILER_FLAGS("-DPOCO_NO_AUTOMATIC_LIBS") 38 38 39 # If no defines are specified, these libs get linked statically 40 ADD_COMPILER_FLAGS("-DBOOST_ALL_DYN_LINK" WIN32 LINK_BOOST_DYNAMIC) 41 #ADD_COMPILER_FLAGS("-DENET_DLL" WIN32 LINK_ENET_DYNAMIC) 42 ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL" WIN32 LINK_LUA_DYNAMIC) 43 ADD_COMPILER_FLAGS("-DZLIB_DLL" WIN32 LINK_ZLIB_DYNAMIC) 44 # If no defines are specified, these libs get linked dynamically 45 ADD_COMPILER_FLAGS("-DCEGUI_STATIC" WIN32 NOT LINK_CEGUI_DYNAMIC) 46 ADD_COMPILER_FLAGS("-DOGRE_STATIC_LIB" WIN32 NOT LINK_OGRE_DYNAMIC) 47 ADD_COMPILER_FLAGS("-DSTATIC_BUILD" WIN32 NOT LINK_TCL_DYNAMIC) 39 IF(WIN32) 40 # If no defines are specified, these libs get linked statically 41 ADD_COMPILER_FLAGS("-DBOOST_ALL_DYN_LINK" LINK_BOOST_DYNAMIC) 42 #ADD_COMPILER_FLAGS("-DENET_DLL" LINK_ENET_DYNAMIC) 43 ADD_COMPILER_FLAGS("-DLUA_BUILD_AS_DLL" LINK_LUA5.1_DYNAMIC) 44 # If no defines are specified, these libs get linked dynamically 45 ADD_COMPILER_FLAGS("-DCEGUI_STATIC -DTOLUA_STATIC" NOT LINK_CEGUI_DYNAMIC) 46 ADD_COMPILER_FLAGS("-DOGRE_STATIC_LIB" NOT LINK_OGRE_DYNAMIC) 47 ADD_COMPILER_FLAGS("-DSTATIC_BUILD" NOT LINK_TCL_DYNAMIC) 48 49 # Target Windows XP as minimum Windows version 50 # And try to catch all the different macro defines for that... 51 ADD_COMPILER_FLAGS("-D_WIN32_WINNT=0x0501") 52 ADD_COMPILER_FLAGS("-D_WIN32_WINDOWS=0x0501") 53 ADD_COMPILER_FLAGS("-DWINVER=0x0501") 54 ADD_COMPILER_FLAGS("-DNTDDI_VERSION=0x05010000") 55 ENDIF(WIN32) 48 56 49 57 ######### Library Behaviour (external) ########## … … 61 69 ENDIF() 62 70 # If no defines are specified, these libs get linked dynamically 63 ADD_COMPILER_FLAGS("-DCEGUILUA_STATIC" WIN32 NOT _external_shared_link)64 71 ADD_COMPILER_FLAGS("-DENET_DLL" WIN32 _external_shared_link) 65 72 ADD_COMPILER_FLAGS("-DOGRE_GUIRENDERER_STATIC_LIB" WIN32 NOT _external_shared_link) 66 73 ADD_COMPILER_FLAGS("-DOIS_STATIC_LIB" WIN32 NOT _external_shared_link) 67 ADD_COMPILER_FLAGS("-DTOLUA_STATIC_BUILD" WIN32 NOT _external_shared_link)68 74 69 75 ############## Include Directories ############## … … 71 77 # Set the search paths for include files 72 78 INCLUDE_DIRECTORIES( 79 # OrxonoxConfig.h 80 ${CMAKE_CURRENT_BINARY_DIR} 81 82 # All includes in "externals" should be prefixed with the path 83 # relative to "external" to avoid conflicts 84 ${CMAKE_CURRENT_SOURCE_DIR}/external 85 # Include directories needed even if only included by Orxonox 86 ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet 87 ${CMAKE_CURRENT_SOURCE_DIR}/external/ois 88 73 89 # External 74 90 ${OGRE_INCLUDE_DIR} 75 91 ${CEGUI_INCLUDE_DIR} 92 ${CEGUI_TOLUA_INCLUDE_DIR} 76 93 #${ENET_INCLUDE_DIR} 77 94 ${Boost_INCLUDE_DIRS} … … 81 98 ${VORBIS_INCLUDE_DIR} 82 99 ${OGG_INCLUDE_DIR} 83 ${LUA _INCLUDE_DIR}100 ${LUA5.1_INCLUDE_DIR} 84 101 ${TCL_INCLUDE_PATH} 85 102 ${DIRECTX_INCLUDE_DIR} 86 103 ${ZLIB_INCLUDE_DIR} 87 88 # All includes in "externals" should be prefixed with the path89 # relative to "external" to avoid conflicts90 ${CMAKE_CURRENT_SOURCE_DIR}/external91 # Include directories needed even if only included by Orxonox92 ${CMAKE_CURRENT_SOURCE_DIR}/external/bullet93 ${CMAKE_CURRENT_SOURCE_DIR}/external/ois94 95 # OrxonoxConfig.h96 ${CMAKE_CURRENT_BINARY_DIR}97 104 ) 98 105 99 IF(CEGUI LUA_USE_INTERNAL_LIBRARY)100 INCLUDE_DIRECTORIES(${C MAKE_CURRENT_SOURCE_DIR}/external/ceguilua/ceguilua-${CEGUI_VERSION})106 IF(CEGUI_OLD_VERSION) 107 INCLUDE_DIRECTORIES(${CEGUILUA_INCLUDE_DIR}) 101 108 ENDIF() 102 109 103 110 IF (DBGHELP_FOUND) 104 111 INCLUDE_DIRECTORIES(${DBGHELP_INCLUDE_DIR}) 112 ENDIF() 113 114 ############## CEGUI OGRE Renderer ############## 115 116 IF(CEGUI_OGRE_RENDERER_BUILD_REQUIRED) 117 SET(CEGUI_OGRE_RENDERER_LIBRARY ogreceguirenderer_orxonox) 105 118 ENDIF() 106 119 … … 132 145 IF(ORXONOX_USE_WINMAIN) 133 146 SET(ORXONOX_WIN32 WIN32) 147 ENDIF() 148 149 SET(ORXONOX_MAIN_FILES Orxonox.cc) 150 151 # Add special source file for OS X 152 IF(APPLE) 153 LIST(APPEND ORXONOX_MAIN_FILES OrxonoxMac.mm) 134 154 ENDIF() 135 155 … … 140 160 orxonox 141 161 SOURCE_FILES 142 Orxonox.cc162 ${ORXONOX_MAIN_FILES} 143 163 OUTPUT_NAME orxonox 144 164 ) … … 165 185 SET(MSVC_PLATFORM "Win32") 166 186 ENDIF() 167 STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?) .*$" "\\1" 168 VISUAL_STUDIO_VERSION_SIMPLE "${CMAKE_GENERATOR}") 169 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcproj.user") 187 IF(MSVC10) 188 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcxproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcxproj.user") 189 ELSE() 190 STRING(REGEX REPLACE "^Visual Studio ([0-9][0-9]?).*$" "\\1" 191 VISUAL_STUDIO_VERSION_SIMPLE "${CMAKE_GENERATOR}") 192 CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/orxonox-main.vcproj.user.in" "${CMAKE_CURRENT_BINARY_DIR}/orxonox-main.vcproj.user") 193 ENDIF() 170 194 ENDIF(MSVC) 195 196 # Apple Mac OS X specific build settings 197 IF(APPLE) 198 # On Apple we need to link to AppKit and Foundation frameworks 199 TARGET_LINK_LIBRARIES(orxonox-main 200 "-framework AppKit" 201 "-framework Foundation" 202 ) 203 204 # Post-build step for the creation of the Dev-App bundle 205 INCLUDE(PrepareDevBundle) 206 ADD_CUSTOM_COMMAND( 207 TARGET orxonox-main 208 POST_BUILD 209 # Copy the executable into the Orxonox.app 210 COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${ORXONOX_EXECUTABLE_NAME}" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${PROJECT_NAME}.app/Contents/MacOS" 211 # Copy the dev-build marker file to Orxonox.app 212 COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/orxonox_dev_build.keep_me" "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${PROJECT_NAME}.app/Contents/MacOS" 213 # Create a shortcut of the application to the root of the build tree 214 COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${PROJECT_NAME}.app" "${CMAKE_BINARY_DIR}/${PROJECT_NAME}.app" 215 ) 216 ENDIF(APPLE) 171 217 172 218 #################### Doxygen #################### -
code/trunk/src/Orxonox.cc
r6417 r8351 53 53 #ifdef ORXONOX_USE_WINMAIN 54 54 INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT) 55 #elif defined(ORXONOX_PLATFORM_APPLE) 56 int main_mac(int argc, char** argv) 55 57 #else 56 58 int main(int argc, char** argv) … … 60 62 { 61 63 #ifndef ORXONOX_USE_WINMAIN 64 65 #ifdef ORXONOX_PLATFORM_APPLE 66 // On Apples, the kernel supplies a second argument, which we have to circumvent 67 const int firstArgument = 2; 68 #else 69 // 0 is the execution path 70 const int firstArgument = 1; 71 #endif 72 62 73 std::string strCmdLine; 63 for (int i = 1; i < argc; ++i)74 for (int i = firstArgument; i < argc; ++i) 64 75 strCmdLine = strCmdLine + argv[i] + ' '; 65 76 #endif -
code/trunk/src/OrxonoxConfig.cmake
r7818 r8351 28 28 #################### Options #################### 29 29 30 # Use, i.e. don't skip the full RPATH for the build tree31 SET(CMAKE_SKIP_BUILD_RPATH FALSE)32 33 30 # Global switch to disable Precompiled Header Files 34 IF(PCH_COMPILER_SUPPORT) 31 # Note: PCH temporarily disabled on Mac because of severe problems 32 IF(PCH_COMPILER_SUPPORT AND NOT APPLE) 35 33 OPTION(PCH_ENABLE "Global PCH switch" TRUE) 36 34 ENDIF() … … 53 51 ENDIF() 54 52 55 # 32/64 bit system check56 IF(CMAKE_SIZEOF_VOID_P EQUAL 8)57 SET(ORXONOX_ARCH_64 TRUE)58 ELSE()59 SET(ORXONOX_ARCH_32 TRUE)60 ENDIF()61 62 53 # Platforms 63 54 SET(ORXONOX_PLATFORM_WINDOWS ${WIN32}) 64 SET(ORXONOX_PLATFORM_APPLE ${APPLE}) 65 SET(ORXONOX_PLATFORM_UNIX ${UNIX}) 66 IF(UNIX AND NOT APPLE) 67 SET(ORXONOX_PLATFORM_LINUX TRUE) 68 ENDIF() 55 SET(ORXONOX_PLATFORM_APPLE ${APPLE}) 56 SET(ORXONOX_PLATFORM_UNIX ${UNIX}) 57 SET(ORXONOX_PLATFORM_LINUX ${LINUX}) 69 58 70 59 # Check __forceinline … … 75 64 ENDIF(MSVC) 76 65 77 # Check iso646.h include (literal operators)66 # Check some non standard system includes 78 67 INCLUDE(CheckIncludeFileCXX) 79 68 CHECK_INCLUDE_FILE_CXX(iso646.h HAVE_ISO646_H) 69 CHECK_INCLUDE_FILE_CXX(stdint.h HAVE_STDINT_H) 70 71 # Part of a woraround for OS X warnings. See OrxonoxConfig.h.in 72 SET(ORX_HAVE_STDINT_H ${HAVE_STDINT_H}) 80 73 81 74 IF(MSVC) … … 106 99 107 100 SET(ORXONOX_CONFIG_FILES 108 ${CMAKE_CURRENT_BINARY_DIR}/OrxonoxConfig.h109 101 ${CMAKE_CURRENT_SOURCE_DIR}/OrxonoxConfig.h.in 110 ${CMAKE_CURRENT_BINARY_DIR}/SpecialConfig.h111 102 ${CMAKE_CURRENT_SOURCE_DIR}/SpecialConfig.h.in 112 103 ) 104 SET(ORXONOX_CONFIG_FILES_GENERATED 105 ${CMAKE_CURRENT_BINARY_DIR}/OrxonoxConfig.h 106 ${CMAKE_CURRENT_BINARY_DIR}/SpecialConfig.h 107 ) 108 109 # Make special target including the configured header files for Visual Studio 110 IF(MSVC) 111 ADD_CUSTOM_TARGET(config 112 SOURCES 113 ${ORXONOX_CONFIG_FILES} 114 ${ORXONOX_CONFIG_FILES_GENERATED} 115 ) 116 ENDIF() -
code/trunk/src/OrxonoxConfig.h.in
r7818 r8351 80 80 81 81 // Architecture 82 #cmakedefine ORXONOX_ARCH_32 83 #cmakedefine ORXONOX_ARCH_64 82 #if defined(__x86_64__) || defined(_M_X64) || defined(__powerpc64__) || defined(__alpha__) || defined(__ia64__) || defined(__s390__) || defined(__s390x__) 83 # define ORXONOX_ARCH_64 84 #else 85 # define ORXONOX_ARCH_32 86 #endif 84 87 85 88 // See if we can use __forceinline or if we need to use __inline instead 86 89 #cmakedefine HAVE_FORCEINLINE 87 #ifndef FORCEINLINE90 #ifndef ORX_FORCEINLINE 88 91 # ifdef HAVE_FORCEINLINE 89 # define FORCEINLINE __forceinline92 # define ORX_FORCEINLINE __forceinline 90 93 # else 91 # define FORCEINLINE __inline94 # define ORX_FORCEINLINE __inline 92 95 # endif 93 96 #endif … … 158 161 #endif 159 162 160 #cmakedefine HAVE_STDINT_H 161 #ifdef HAVE_STDINT_H 163 // On OS X some headers already define HAVE_STDINT_H and that spits out 164 // some warnings. Therefore we use this macro. 165 // Note: This requires some extra code in OrxonoxConfig.cmake 166 #cmakedefine ORX_HAVE_STDINT_H 167 #ifdef ORX_HAVE_STDINT_H 162 168 # include <stdint.h> 163 169 #elif defined(ORXONOX_COMPILER_MSVC) … … 222 228 } 223 229 230 // Define Boost Filesystem version 231 #include <boost/version.hpp> 232 #ifndef BOOST_FILESYSTEM_VERSION 233 # if (BOOST_VERSION < 104600) 234 # define BOOST_FILESYSTEM_VERSION 2 235 # else 236 # define BOOST_FILESYSTEM_VERSION 3 237 # endif 238 #endif 239 224 240 #endif /* _OrxonoxConfig_H__ */ -
code/trunk/src/SpecialConfig.h.in
r7818 r8351 42 42 #include "OrxonoxConfig.h" 43 43 44 #cmakedefine CEGUILUA_USE_INTERNAL_LIBRARY ///< Set whether we must suffix "ceguilua/" for the CEGUILua.h include45 46 44 #cmakedefine DEPENDENCY_PACKAGE_ENABLE ///< Defined if a precompiled depdency package was used. We then copy all libraries too when installing. 47 45 … … 69 67 #ifndef INSTALL_COPYABLE 70 68 // INSTALLATION PATHS 71 const char dataInstallDirectory[] = "@ DATA_INSTALL_DIRECTORY@";72 const char moduleInstallDirectory[] = "@ MODULE_INSTALL_DIRECTORY@";69 const char dataInstallDirectory[] = "@CMAKE_INSTALL_PREFIX@/@DATA_INSTALL_DIRECTORY@"; 70 const char moduleInstallDirectory[] = "@CMAKE_INSTALL_PREFIX@/@MODULE_INSTALL_DIRECTORY@"; 73 71 #endif 74 72 … … 96 94 #ifdef NDEBUG 97 95 const char ogrePlugins[] = "@OGRE_PLUGINS_RELEASE@"; 98 # ifdef DEPENDENCY_PACKAGE_ENABLE99 const char ogrePluginsDirectory[] = ".";100 # else101 96 const char ogrePluginsDirectory[] = "@OGRE_PLUGINS_FOLDER_RELEASE@"; 102 # endif103 97 #else 104 98 const char ogrePlugins[] = "@OGRE_PLUGINS_DEBUG@"; 105 # ifdef DEPENDENCY_PACKAGE_ENABLE106 const char ogrePluginsDirectory[] = ".";107 # else108 99 const char ogrePluginsDirectory[] = "@OGRE_PLUGINS_FOLDER_DEBUG@"; 109 # endif110 100 #endif 111 101 } } -
code/trunk/src/external/CMakeLists.txt
r7459 r8351 21 21 22 22 ADD_SUBDIRECTORY(tolua) 23 24 # Include CEGUILua if not requested otherwise25 IF(CEGUILUA_USE_INTERNAL_LIBRARY)26 IF(NOT IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ceguilua/ceguilua-${CEGUI_VERSION})27 MESSAGE(FATAL_ERROR "CEGUILua version not found in src folder. Update list of supported versions in LibraryConfig.cmake!")28 ENDIF()29 30 ADD_SUBDIRECTORY(ceguilua)31 SET(CEGUILUA_LIBRARY ${CEGUILUA_LIBRARY} PARENT_SCOPE)32 ENDIF()33 34 23 ADD_SUBDIRECTORY(bullet) 35 24 ADD_SUBDIRECTORY(cpptcl) 36 25 ADD_SUBDIRECTORY(enet) 37 26 ADD_SUBDIRECTORY(loki) 38 ADD_SUBDIRECTORY(ogreceguirenderer) 27 IF(CEGUI_OGRE_RENDERER_BUILD_REQUIRED) 28 ADD_SUBDIRECTORY(ogreceguirenderer) 29 ENDIF() 39 30 ADD_SUBDIRECTORY(ois) 40 31 ADD_SUBDIRECTORY(tinyxml) -
code/trunk/src/external/bullet/Bullet-C-Api.h
r5781 r8351 148 148 extern void plSetOrientation(plRigidBodyHandle object, const plQuaternion orientation); 149 149 extern void plSetEuler(plReal yaw,plReal pitch,plReal roll, plQuaternion orient); 150 extern void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix); 150 151 151 152 typedef struct plRayCastResult { -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btAxisSweep3.h
r5781 r8351 151 151 152 152 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)); 153 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 154 153 155 154 156 void quantize(BP_FP_INT_TYPE* out, const btVector3& point, int isMax) const; … … 281 283 { 282 284 rayCallback.process(getHandle(m_pEdges[axis][i].m_handle)); 285 } 286 } 287 } 288 } 289 290 template <typename BP_FP_INT_TYPE> 291 void btAxisSweep3Internal<BP_FP_INT_TYPE>::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) 292 { 293 if (m_raycastAccelerator) 294 { 295 m_raycastAccelerator->aabbTest(aabbMin,aabbMax,callback); 296 } else 297 { 298 //choose axis? 299 BP_FP_INT_TYPE axis = 0; 300 //for each proxy 301 for (BP_FP_INT_TYPE i=1;i<m_numHandles*2+1;i++) 302 { 303 if (m_pEdges[axis][i].IsMax()) 304 { 305 Handle* handle = getHandle(m_pEdges[axis][i].m_handle); 306 if (TestAabbAgainstAabb2(aabbMin,aabbMax,handle->m_aabbMin,handle->m_aabbMax)) 307 { 308 callback.process(handle); 309 } 283 310 } 284 311 } -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseInterface.h
r5781 r8351 27 27 28 28 29 struct btBroadphaseRayCallback 29 struct btBroadphaseAabbCallback 30 { 31 virtual ~btBroadphaseAabbCallback() {} 32 virtual bool process(const btBroadphaseProxy* proxy) = 0; 33 }; 34 35 36 struct btBroadphaseRayCallback : public btBroadphaseAabbCallback 30 37 { 31 38 ///added some cached data to accelerate ray-AABB tests … … 35 42 36 43 virtual ~btBroadphaseRayCallback() {} 37 virtual bool process(const btBroadphaseProxy* proxy) = 0;38 44 }; 39 45 … … 55 61 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)) = 0; 56 62 63 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) = 0; 64 57 65 ///calculateOverlappingPairs is optional: incremental algorithms (sweep and prune) might do it during the set aabb 58 66 virtual void calculateOverlappingPairs(btDispatcher* dispatcher)=0; … … 66 74 67 75 ///reset broadphase internal structures, to ensure determinism/reproducability 68 virtual void resetPool(btDispatcher* dispatcher) { };76 virtual void resetPool(btDispatcher* dispatcher) { (void) dispatcher; }; 69 77 70 78 virtual void printStats() = 0; -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btBroadphaseProxy.h
r5781 r8351 47 47 MINKOWSKI_SUM_SHAPE_PROXYTYPE, 48 48 MINKOWSKI_DIFFERENCE_SHAPE_PROXYTYPE, 49 BOX_2D_SHAPE_PROXYTYPE, 50 CONVEX_2D_SHAPE_PROXYTYPE, 49 51 CUSTOM_CONVEX_SHAPE_TYPE, 50 52 //concave shapes … … 140 142 } 141 143 144 static SIMD_FORCE_INLINE bool isNonMoving(int proxyType) 145 { 146 return (isConcave(proxyType) && !(proxyType==GIMPACT_SHAPE_PROXYTYPE)); 147 } 148 142 149 static SIMD_FORCE_INLINE bool isConcave(int proxyType) 143 150 { … … 149 156 return (proxyType == COMPOUND_SHAPE_PROXYTYPE); 150 157 } 158 159 static SIMD_FORCE_INLINE bool isSoftBody(int proxyType) 160 { 161 return (proxyType == SOFTBODY_SHAPE_PROXYTYPE); 162 } 163 151 164 static SIMD_FORCE_INLINE bool isInfinite(int proxyType) 152 165 { 153 166 return (proxyType == STATIC_PLANE_PROXYTYPE); 154 167 } 168 169 static SIMD_FORCE_INLINE bool isConvex2d(int proxyType) 170 { 171 return (proxyType == BOX_2D_SHAPE_PROXYTYPE) || (proxyType == CONVEX_2D_SHAPE_PROXYTYPE); 172 } 173 155 174 156 175 } -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvt.cpp
r5781 r8351 62 62 { 63 63 getmaxdepth(node->childs[0],depth+1,maxdepth); 64 getmaxdepth(node->childs[ 0],depth+1,maxdepth);64 getmaxdepth(node->childs[1],depth+1,maxdepth); 65 65 } else maxdepth=btMax(maxdepth,depth); 66 66 } … … 239 239 for(int i=0,ni=leaves.size();i<ni;++i) 240 240 { 241 if( dot(axis,leaves[i]->volume.Center()-org)<0)241 if(btDot(axis,leaves[i]->volume.Center()-org)<0) 242 242 left.push_back(leaves[i]); 243 243 else … … 320 320 for(int j=0;j<3;++j) 321 321 { 322 ++splitcount[j][ dot(x,axis[j])>0?1:0];322 ++splitcount[j][btDot(x,axis[j])>0?1:0]; 323 323 } 324 324 } -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvt.h
r5781 r8351 33 33 34 34 // Template implementation of ICollide 35 #ifdef WIN3235 #ifdef _WIN32 36 36 #if (defined (_MSC_VER) && _MSC_VER >= 1400) 37 37 #define DBVT_USE_TEMPLATE 1 … … 58 58 59 59 //SSE gives errors on a MSVC 7.1 60 #if def BT_USE_SSE60 #if defined (BT_USE_SSE) && defined (_WIN32) 61 61 #define DBVT_SELECT_IMPL DBVT_IMPL_SSE 62 62 #define DBVT_MERGE_IMPL DBVT_IMPL_SSE … … 93 93 94 94 #if DBVT_USE_MEMMOVE 95 #if ndef __CELLOS_LV2__95 #if !defined( __CELLOS_LV2__) && !defined(__MWERKS__) 96 96 #include <memory.h> 97 97 #endif … … 485 485 pi=btVector3(mi.x(),mi.y(),mi.z());break; 486 486 } 487 if(( dot(n,px)+o)<0) return(-1);488 if(( dot(n,pi)+o)>=0) return(+1);487 if((btDot(n,px)+o)<0) return(-1); 488 if((btDot(n,pi)+o)>=0) return(+1); 489 489 return(0); 490 490 } … … 497 497 b[(signs>>1)&1]->y(), 498 498 b[(signs>>2)&1]->z()); 499 return( dot(p,v));499 return(btDot(p,v)); 500 500 } 501 501 … … 948 948 DBVT_IPOLICY) const 949 949 { 950 (void) rayTo; 950 951 DBVT_CHECKTYPE 951 952 if(root) … … 962 963 { 963 964 const btDbvtNode* node=stack[--depth]; 964 bounds[0] = node->volume.Mins() +aabbMin;965 bounds[1] = node->volume.Maxs() +aabbMax;965 bounds[0] = node->volume.Mins()-aabbMax; 966 bounds[1] = node->volume.Maxs()-aabbMin; 966 967 btScalar tmin=1.f,lambda_min=0.f; 967 968 unsigned int result1=false; … … 1001 1002 rayDir.normalize (); 1002 1003 1003 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e301004 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 1004 1005 btVector3 rayDirectionInverse; 1005 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];1006 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];1007 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];1006 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 1007 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 1008 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 1008 1009 unsigned int signs[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; 1009 1010 -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 7 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 ///btDbvtBroadphase implementation by Nathanael Presson 16 17 … … 124 125 m_needcleanup = true; 125 126 m_releasepaircache = (paircache!=0)?false:true; 126 m_prediction = 1/(btScalar)2;127 m_prediction = 0; 127 128 m_stageCurrent = 0; 128 129 m_fixedleft = 0; … … 250 251 } 251 252 253 254 struct BroadphaseAabbTester : btDbvt::ICollide 255 { 256 btBroadphaseAabbCallback& m_aabbCallback; 257 BroadphaseAabbTester(btBroadphaseAabbCallback& orgCallback) 258 :m_aabbCallback(orgCallback) 259 { 260 } 261 void Process(const btDbvtNode* leaf) 262 { 263 btDbvtProxy* proxy=(btDbvtProxy*)leaf->data; 264 m_aabbCallback.process(proxy); 265 } 266 }; 267 268 void btDbvtBroadphase::aabbTest(const btVector3& aabbMin,const btVector3& aabbMax,btBroadphaseAabbCallback& aabbCallback) 269 { 270 BroadphaseAabbTester callback(aabbCallback); 271 272 const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(aabbMin,aabbMax); 273 //process all children, that overlap with the given AABB bounds 274 m_sets[0].collideTV(m_sets[0].m_root,bounds,callback); 275 m_sets[1].collideTV(m_sets[1].m_root,bounds,callback); 276 277 } 278 279 280 252 281 // 253 282 void btDbvtBroadphase::setAabb( btBroadphaseProxy* absproxy, … … 315 344 } 316 345 } 346 } 347 348 349 // 350 void btDbvtBroadphase::setAabbForceUpdate( btBroadphaseProxy* absproxy, 351 const btVector3& aabbMin, 352 const btVector3& aabbMax, 353 btDispatcher* /*dispatcher*/) 354 { 355 btDbvtProxy* proxy=(btDbvtProxy*)absproxy; 356 ATTRIBUTE_ALIGNED16(btDbvtVolume) aabb=btDbvtVolume::FromMM(aabbMin,aabbMax); 357 bool docollide=false; 358 if(proxy->stage==STAGECOUNT) 359 {/* fixed -> dynamic set */ 360 m_sets[1].remove(proxy->leaf); 361 proxy->leaf=m_sets[0].insert(aabb,proxy); 362 docollide=true; 363 } 364 else 365 {/* dynamic set */ 366 ++m_updates_call; 367 /* Teleporting */ 368 m_sets[0].update(proxy->leaf,aabb); 369 ++m_updates_done; 370 docollide=true; 371 } 372 listremove(proxy,m_stageRoots[proxy->stage]); 373 proxy->m_aabbMin = aabbMin; 374 proxy->m_aabbMax = aabbMax; 375 proxy->stage = m_stageCurrent; 376 listappend(proxy,m_stageRoots[m_stageCurrent]); 377 if(docollide) 378 { 379 m_needcleanup=true; 380 if(!m_deferedcollide) 381 { 382 btDbvtTreeCollider collider(this); 383 m_sets[1].collideTTpersistentStack(m_sets[1].m_root,proxy->leaf,collider); 384 m_sets[0].collideTTpersistentStack(m_sets[0].m_root,proxy->leaf,collider); 385 } 386 } 317 387 } 318 388 … … 572 642 m_deferedcollide = false; 573 643 m_needcleanup = true; 574 m_prediction = 1/(btScalar)2;575 644 m_stageCurrent = 0; 576 645 m_fixedleft = 0; -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDbvtBroadphase.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 7 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 ///btDbvtBroadphase implementation by Nathanael Presson 16 17 #ifndef BT_DBVT_BROADPHASE_H … … 102 103 void collide(btDispatcher* dispatcher); 103 104 void optimize(); 104 /* btBroadphaseInterface Implementation */ 105 106 /* btBroadphaseInterface Implementation */ 105 107 btBroadphaseProxy* createProxy(const btVector3& aabbMin,const btVector3& aabbMax,int shapeType,void* userPtr,short int collisionFilterGroup,short int collisionFilterMask,btDispatcher* dispatcher,void* multiSapProxy); 106 void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); 107 void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher); 108 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)); 108 virtual void destroyProxy(btBroadphaseProxy* proxy,btDispatcher* dispatcher); 109 virtual void setAabb(btBroadphaseProxy* proxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* dispatcher); 110 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0), const btVector3& aabbMax = btVector3(0,0,0)); 111 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 109 112 110 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const; 111 void calculateOverlappingPairs(btDispatcher* dispatcher); 112 btOverlappingPairCache* getOverlappingPairCache(); 113 const btOverlappingPairCache* getOverlappingPairCache() const; 114 void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const; 115 void printStats(); 116 static void benchmark(btBroadphaseInterface*); 113 virtual void getAabb(btBroadphaseProxy* proxy,btVector3& aabbMin, btVector3& aabbMax ) const; 114 virtual void calculateOverlappingPairs(btDispatcher* dispatcher); 115 virtual btOverlappingPairCache* getOverlappingPairCache(); 116 virtual const btOverlappingPairCache* getOverlappingPairCache() const; 117 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const; 118 virtual void printStats(); 117 119 118 119 void performDeferredRemoval(btDispatcher* dispatcher);120 120 121 121 ///reset broadphase internal structures, to ensure determinism/reproducability 122 122 virtual void resetPool(btDispatcher* dispatcher); 123 123 124 void performDeferredRemoval(btDispatcher* dispatcher); 125 126 void setVelocityPrediction(btScalar prediction) 127 { 128 m_prediction = prediction; 129 } 130 btScalar getVelocityPrediction() const 131 { 132 return m_prediction; 133 } 134 135 ///this setAabbForceUpdate is similar to setAabb but always forces the aabb update. 136 ///it is not part of the btBroadphaseInterface but specific to btDbvtBroadphase. 137 ///it bypasses certain optimizations that prevent aabb updates (when the aabb shrinks), see 138 ///http://code.google.com/p/bullet/issues/detail?id=223 139 void setAabbForceUpdate( btBroadphaseProxy* absproxy,const btVector3& aabbMin,const btVector3& aabbMax,btDispatcher* /*dispatcher*/); 140 141 static void benchmark(btBroadphaseInterface*); 142 143 124 144 }; 125 145 -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btDispatcher.h
r5781 r8351 47 47 m_useEpa(true), 48 48 m_allowedCcdPenetration(btScalar(0.04)), 49 m_useConvexConservativeDistanceUtil( true),49 m_useConvexConservativeDistanceUtil(false), 50 50 m_convexConservativeDistanceThreshold(0.0f), 51 m_convexMaxDistanceUseCPT(false), 51 52 m_stackAllocator(0) 52 53 { … … 65 66 bool m_useConvexConservativeDistanceUtil; 66 67 btScalar m_convexConservativeDistanceThreshold; 68 bool m_convexMaxDistanceUseCPT; 67 69 btStackAlloc* m_stackAllocator; 68 70 }; -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btMultiSapBroadphase.h
r5781 r8351 134 134 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const 135 135 { 136 aabbMin.setValue(- 1e30f,-1e30f,-1e30f);137 aabbMax.setValue( 1e30f,1e30f,1e30f);136 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 137 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 138 138 } 139 139 -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.cpp
r5781 r8351 241 241 int count = m_overlappingPairArray.size(); 242 242 int oldCapacity = m_overlappingPairArray.capacity(); 243 void* mem = &m_overlappingPairArray.expand ();243 void* mem = &m_overlappingPairArray.expandNonInitializing(); 244 244 245 245 //this is where we add an actual pair, so also call the 'ghost' … … 468 468 return 0; 469 469 470 void* mem = &m_overlappingPairArray.expand ();470 void* mem = &m_overlappingPairArray.expandNonInitializing(); 471 471 btBroadphasePair* pair = new (mem) btBroadphasePair(*proxy0,*proxy1); 472 472 -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btOverlappingPairCache.h
r5781 r8351 458 458 virtual void sortOverlappingPairs(btDispatcher* dispatcher) 459 459 { 460 (void) dispatcher; 460 461 } 461 462 -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
r5781 r8351 18 18 #include "LinearMath/btAabbUtil2.h" 19 19 #include "LinearMath/btIDebugDraw.h" 20 #include "LinearMath/btSerializer.h" 20 21 21 22 #define RAYAABB2 … … 79 80 btVector3 color[4]= 80 81 { 81 btVector3( 255,0,0),82 btVector3(0, 255,0),83 btVector3(0,0, 255),84 btVector3(0, 255,255)82 btVector3(1,0,0), 83 btVector3(0,1,0), 84 btVector3(0,0,1), 85 btVector3(0,1,1) 85 86 }; 86 87 #endif //DEBUG_PATCH_COLORS … … 475 476 ///what about division by zero? --> just set rayDirection[i] to 1.0 476 477 btVector3 rayDirectionInverse; 477 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];478 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];479 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];478 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 479 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 480 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 480 481 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; 481 482 #endif … … 494 495 bounds[1] = rootNode->m_aabbMaxOrg; 495 496 /* Add box cast extents */ 496 bounds[0] += aabbMin;497 bounds[1] += aabbMax;497 bounds[0] -= aabbMax; 498 bounds[1] -= aabbMin; 498 499 499 500 aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg); … … 562 563 lambda_max = rayDirection.dot(rayTarget-raySource); 563 564 ///what about division by zero? --> just set rayDirection[i] to 1.0 564 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[0];565 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[1];566 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDirection[2];565 rayDirection[0] = rayDirection[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[0]; 566 rayDirection[1] = rayDirection[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[1]; 567 rayDirection[2] = rayDirection[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDirection[2]; 567 568 unsigned int sign[3] = { rayDirection[0] < 0.0, rayDirection[1] < 0.0, rayDirection[2] < 0.0}; 568 569 #endif … … 618 619 bounds[1] = unQuantize(rootNode->m_quantizedAabbMax); 619 620 /* Add box cast extents */ 620 bounds[0] += aabbMin;621 bounds[1] += aabbMax;621 bounds[0] -= aabbMax; 622 bounds[1] -= aabbMin; 622 623 btVector3 normal; 623 624 #if 0 … … 831 832 } 832 833 833 unsigned btQuantizedBvh::calculateSerializeBufferSize() 834 unsigned btQuantizedBvh::calculateSerializeBufferSize() const 834 835 { 835 836 unsigned baseSize = sizeof(btQuantizedBvh) + getAlignmentSerializationPadding(); … … 842 843 } 843 844 844 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) 845 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) const 845 846 { 846 847 btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size()); … … 1144 1145 } 1145 1146 1146 1147 1148 1147 void btQuantizedBvh::deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData) 1148 { 1149 m_bvhAabbMax.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMax); 1150 m_bvhAabbMin.deSerializeFloat(quantizedBvhFloatData.m_bvhAabbMin); 1151 m_bvhQuantization.deSerializeFloat(quantizedBvhFloatData.m_bvhQuantization); 1152 1153 m_curNodeIndex = quantizedBvhFloatData.m_curNodeIndex; 1154 m_useQuantization = quantizedBvhFloatData.m_useQuantization!=0; 1155 1156 { 1157 int numElem = quantizedBvhFloatData.m_numContiguousLeafNodes; 1158 m_contiguousNodes.resize(numElem); 1159 1160 if (numElem) 1161 { 1162 btOptimizedBvhNodeFloatData* memPtr = quantizedBvhFloatData.m_contiguousNodesPtr; 1163 1164 for (int i=0;i<numElem;i++,memPtr++) 1165 { 1166 m_contiguousNodes[i].m_aabbMaxOrg.deSerializeFloat(memPtr->m_aabbMaxOrg); 1167 m_contiguousNodes[i].m_aabbMinOrg.deSerializeFloat(memPtr->m_aabbMinOrg); 1168 m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex; 1169 m_contiguousNodes[i].m_subPart = memPtr->m_subPart; 1170 m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex; 1171 } 1172 } 1173 } 1174 1175 { 1176 int numElem = quantizedBvhFloatData.m_numQuantizedContiguousNodes; 1177 m_quantizedContiguousNodes.resize(numElem); 1178 1179 if (numElem) 1180 { 1181 btQuantizedBvhNodeData* memPtr = quantizedBvhFloatData.m_quantizedContiguousNodesPtr; 1182 for (int i=0;i<numElem;i++,memPtr++) 1183 { 1184 m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex; 1185 m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0]; 1186 m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1187 m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1188 m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1189 m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1190 m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1191 } 1192 } 1193 } 1194 1195 m_traversalMode = btTraversalMode(quantizedBvhFloatData.m_traversalMode); 1196 1197 { 1198 int numElem = quantizedBvhFloatData.m_numSubtreeHeaders; 1199 m_SubtreeHeaders.resize(numElem); 1200 if (numElem) 1201 { 1202 btBvhSubtreeInfoData* memPtr = quantizedBvhFloatData.m_subTreeInfoPtr; 1203 for (int i=0;i<numElem;i++,memPtr++) 1204 { 1205 m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ; 1206 m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1207 m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1208 m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1209 m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1210 m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1211 m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex; 1212 m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize; 1213 } 1214 } 1215 } 1216 } 1217 1218 void btQuantizedBvh::deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData) 1219 { 1220 m_bvhAabbMax.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMax); 1221 m_bvhAabbMin.deSerializeDouble(quantizedBvhDoubleData.m_bvhAabbMin); 1222 m_bvhQuantization.deSerializeDouble(quantizedBvhDoubleData.m_bvhQuantization); 1223 1224 m_curNodeIndex = quantizedBvhDoubleData.m_curNodeIndex; 1225 m_useQuantization = quantizedBvhDoubleData.m_useQuantization!=0; 1226 1227 { 1228 int numElem = quantizedBvhDoubleData.m_numContiguousLeafNodes; 1229 m_contiguousNodes.resize(numElem); 1230 1231 if (numElem) 1232 { 1233 btOptimizedBvhNodeDoubleData* memPtr = quantizedBvhDoubleData.m_contiguousNodesPtr; 1234 1235 for (int i=0;i<numElem;i++,memPtr++) 1236 { 1237 m_contiguousNodes[i].m_aabbMaxOrg.deSerializeDouble(memPtr->m_aabbMaxOrg); 1238 m_contiguousNodes[i].m_aabbMinOrg.deSerializeDouble(memPtr->m_aabbMinOrg); 1239 m_contiguousNodes[i].m_escapeIndex = memPtr->m_escapeIndex; 1240 m_contiguousNodes[i].m_subPart = memPtr->m_subPart; 1241 m_contiguousNodes[i].m_triangleIndex = memPtr->m_triangleIndex; 1242 } 1243 } 1244 } 1245 1246 { 1247 int numElem = quantizedBvhDoubleData.m_numQuantizedContiguousNodes; 1248 m_quantizedContiguousNodes.resize(numElem); 1249 1250 if (numElem) 1251 { 1252 btQuantizedBvhNodeData* memPtr = quantizedBvhDoubleData.m_quantizedContiguousNodesPtr; 1253 for (int i=0;i<numElem;i++,memPtr++) 1254 { 1255 m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex = memPtr->m_escapeIndexOrTriangleIndex; 1256 m_quantizedContiguousNodes[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0]; 1257 m_quantizedContiguousNodes[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1258 m_quantizedContiguousNodes[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1259 m_quantizedContiguousNodes[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1260 m_quantizedContiguousNodes[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1261 m_quantizedContiguousNodes[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1262 } 1263 } 1264 } 1265 1266 m_traversalMode = btTraversalMode(quantizedBvhDoubleData.m_traversalMode); 1267 1268 { 1269 int numElem = quantizedBvhDoubleData.m_numSubtreeHeaders; 1270 m_SubtreeHeaders.resize(numElem); 1271 if (numElem) 1272 { 1273 btBvhSubtreeInfoData* memPtr = quantizedBvhDoubleData.m_subTreeInfoPtr; 1274 for (int i=0;i<numElem;i++,memPtr++) 1275 { 1276 m_SubtreeHeaders[i].m_quantizedAabbMax[0] = memPtr->m_quantizedAabbMax[0] ; 1277 m_SubtreeHeaders[i].m_quantizedAabbMax[1] = memPtr->m_quantizedAabbMax[1]; 1278 m_SubtreeHeaders[i].m_quantizedAabbMax[2] = memPtr->m_quantizedAabbMax[2]; 1279 m_SubtreeHeaders[i].m_quantizedAabbMin[0] = memPtr->m_quantizedAabbMin[0]; 1280 m_SubtreeHeaders[i].m_quantizedAabbMin[1] = memPtr->m_quantizedAabbMin[1]; 1281 m_SubtreeHeaders[i].m_quantizedAabbMin[2] = memPtr->m_quantizedAabbMin[2]; 1282 m_SubtreeHeaders[i].m_rootNodeIndex = memPtr->m_rootNodeIndex; 1283 m_SubtreeHeaders[i].m_subtreeSize = memPtr->m_subtreeSize; 1284 } 1285 } 1286 } 1287 1288 } 1289 1290 1291 1292 ///fills the dataBuffer and returns the struct name (and 0 on failure) 1293 const char* btQuantizedBvh::serialize(void* dataBuffer, btSerializer* serializer) const 1294 { 1295 btQuantizedBvhData* quantizedData = (btQuantizedBvhData*)dataBuffer; 1296 1297 m_bvhAabbMax.serialize(quantizedData->m_bvhAabbMax); 1298 m_bvhAabbMin.serialize(quantizedData->m_bvhAabbMin); 1299 m_bvhQuantization.serialize(quantizedData->m_bvhQuantization); 1300 1301 quantizedData->m_curNodeIndex = m_curNodeIndex; 1302 quantizedData->m_useQuantization = m_useQuantization; 1303 1304 quantizedData->m_numContiguousLeafNodes = m_contiguousNodes.size(); 1305 quantizedData->m_contiguousNodesPtr = (btOptimizedBvhNodeData*) (m_contiguousNodes.size() ? serializer->getUniquePointer((void*)&m_contiguousNodes[0]) : 0); 1306 if (quantizedData->m_contiguousNodesPtr) 1307 { 1308 int sz = sizeof(btOptimizedBvhNodeData); 1309 int numElem = m_contiguousNodes.size(); 1310 btChunk* chunk = serializer->allocate(sz,numElem); 1311 btOptimizedBvhNodeData* memPtr = (btOptimizedBvhNodeData*)chunk->m_oldPtr; 1312 for (int i=0;i<numElem;i++,memPtr++) 1313 { 1314 m_contiguousNodes[i].m_aabbMaxOrg.serialize(memPtr->m_aabbMaxOrg); 1315 m_contiguousNodes[i].m_aabbMinOrg.serialize(memPtr->m_aabbMinOrg); 1316 memPtr->m_escapeIndex = m_contiguousNodes[i].m_escapeIndex; 1317 memPtr->m_subPart = m_contiguousNodes[i].m_subPart; 1318 memPtr->m_triangleIndex = m_contiguousNodes[i].m_triangleIndex; 1319 } 1320 serializer->finalizeChunk(chunk,"btOptimizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_contiguousNodes[0]); 1321 } 1322 1323 quantizedData->m_numQuantizedContiguousNodes = m_quantizedContiguousNodes.size(); 1324 // printf("quantizedData->m_numQuantizedContiguousNodes=%d\n",quantizedData->m_numQuantizedContiguousNodes); 1325 quantizedData->m_quantizedContiguousNodesPtr =(btQuantizedBvhNodeData*) (m_quantizedContiguousNodes.size() ? serializer->getUniquePointer((void*)&m_quantizedContiguousNodes[0]) : 0); 1326 if (quantizedData->m_quantizedContiguousNodesPtr) 1327 { 1328 int sz = sizeof(btQuantizedBvhNodeData); 1329 int numElem = m_quantizedContiguousNodes.size(); 1330 btChunk* chunk = serializer->allocate(sz,numElem); 1331 btQuantizedBvhNodeData* memPtr = (btQuantizedBvhNodeData*)chunk->m_oldPtr; 1332 for (int i=0;i<numElem;i++,memPtr++) 1333 { 1334 memPtr->m_escapeIndexOrTriangleIndex = m_quantizedContiguousNodes[i].m_escapeIndexOrTriangleIndex; 1335 memPtr->m_quantizedAabbMax[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[0]; 1336 memPtr->m_quantizedAabbMax[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[1]; 1337 memPtr->m_quantizedAabbMax[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMax[2]; 1338 memPtr->m_quantizedAabbMin[0] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[0]; 1339 memPtr->m_quantizedAabbMin[1] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[1]; 1340 memPtr->m_quantizedAabbMin[2] = m_quantizedContiguousNodes[i].m_quantizedAabbMin[2]; 1341 } 1342 serializer->finalizeChunk(chunk,"btQuantizedBvhNodeData",BT_ARRAY_CODE,(void*)&m_quantizedContiguousNodes[0]); 1343 } 1344 1345 quantizedData->m_traversalMode = int(m_traversalMode); 1346 quantizedData->m_numSubtreeHeaders = m_SubtreeHeaders.size(); 1347 1348 quantizedData->m_subTreeInfoPtr = (btBvhSubtreeInfoData*) (m_SubtreeHeaders.size() ? serializer->getUniquePointer((void*)&m_SubtreeHeaders[0]) : 0); 1349 if (quantizedData->m_subTreeInfoPtr) 1350 { 1351 int sz = sizeof(btBvhSubtreeInfoData); 1352 int numElem = m_SubtreeHeaders.size(); 1353 btChunk* chunk = serializer->allocate(sz,numElem); 1354 btBvhSubtreeInfoData* memPtr = (btBvhSubtreeInfoData*)chunk->m_oldPtr; 1355 for (int i=0;i<numElem;i++,memPtr++) 1356 { 1357 memPtr->m_quantizedAabbMax[0] = m_SubtreeHeaders[i].m_quantizedAabbMax[0]; 1358 memPtr->m_quantizedAabbMax[1] = m_SubtreeHeaders[i].m_quantizedAabbMax[1]; 1359 memPtr->m_quantizedAabbMax[2] = m_SubtreeHeaders[i].m_quantizedAabbMax[2]; 1360 memPtr->m_quantizedAabbMin[0] = m_SubtreeHeaders[i].m_quantizedAabbMin[0]; 1361 memPtr->m_quantizedAabbMin[1] = m_SubtreeHeaders[i].m_quantizedAabbMin[1]; 1362 memPtr->m_quantizedAabbMin[2] = m_SubtreeHeaders[i].m_quantizedAabbMin[2]; 1363 1364 memPtr->m_rootNodeIndex = m_SubtreeHeaders[i].m_rootNodeIndex; 1365 memPtr->m_subtreeSize = m_SubtreeHeaders[i].m_subtreeSize; 1366 } 1367 serializer->finalizeChunk(chunk,"btBvhSubtreeInfoData",BT_ARRAY_CODE,(void*)&m_SubtreeHeaders[0]); 1368 } 1369 return btQuantizedBvhDataName; 1370 } 1371 1372 1373 1374 1375 -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.h
r5781 r8351 17 17 #define QUANTIZED_BVH_H 18 18 19 class btSerializer; 20 19 21 //#define DEBUG_CHECK_DEQUANTIZATION 1 20 22 #ifdef DEBUG_CHECK_DEQUANTIZATION … … 29 31 #include "LinearMath/btVector3.h" 30 32 #include "LinearMath/btAlignedAllocator.h" 33 34 #ifdef BT_USE_DOUBLE_PRECISION 35 #define btQuantizedBvhData btQuantizedBvhDoubleData 36 #define btOptimizedBvhNodeData btOptimizedBvhNodeDoubleData 37 #define btQuantizedBvhDataName "btQuantizedBvhDoubleData" 38 #else 39 #define btQuantizedBvhData btQuantizedBvhFloatData 40 #define btOptimizedBvhNodeData btOptimizedBvhNodeFloatData 41 #define btQuantizedBvhDataName "btQuantizedBvhFloatData" 42 #endif 43 31 44 32 45 … … 191 204 192 205 //This is only used for serialization so we don't have to add serialization directly to btAlignedObjectArray 193 int m_subtreeHeaderCount;206 mutable int m_subtreeHeaderCount; 194 207 195 208 … … 444 457 } 445 458 459 //////////////////////////////////////////////////////////////////// 446 460 447 461 /////Calculate space needed to store BVH for serialization 448 unsigned calculateSerializeBufferSize() ;462 unsigned calculateSerializeBufferSize() const; 449 463 450 464 /// Data buffer MUST be 16 byte aligned 451 virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) ;465 virtual bool serialize(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const; 452 466 453 467 ///deSerializeInPlace loads and initializes a BVH from a buffer in memory 'in place' … … 455 469 456 470 static unsigned int getAlignmentSerializationPadding(); 471 ////////////////////////////////////////////////////////////////////// 472 473 474 virtual int calculateSerializeBufferSizeNew() const; 475 476 ///fills the dataBuffer and returns the struct name (and 0 on failure) 477 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 478 479 virtual void deSerializeFloat(struct btQuantizedBvhFloatData& quantizedBvhFloatData); 480 481 virtual void deSerializeDouble(struct btQuantizedBvhDoubleData& quantizedBvhDoubleData); 482 483 484 //////////////////////////////////////////////////////////////////// 457 485 458 486 SIMD_FORCE_INLINE bool isQuantized() … … 471 499 472 500 501 struct btBvhSubtreeInfoData 502 { 503 int m_rootNodeIndex; 504 int m_subtreeSize; 505 unsigned short m_quantizedAabbMin[3]; 506 unsigned short m_quantizedAabbMax[3]; 507 }; 508 509 struct btOptimizedBvhNodeFloatData 510 { 511 btVector3FloatData m_aabbMinOrg; 512 btVector3FloatData m_aabbMaxOrg; 513 int m_escapeIndex; 514 int m_subPart; 515 int m_triangleIndex; 516 char m_pad[4]; 517 }; 518 519 struct btOptimizedBvhNodeDoubleData 520 { 521 btVector3DoubleData m_aabbMinOrg; 522 btVector3DoubleData m_aabbMaxOrg; 523 int m_escapeIndex; 524 int m_subPart; 525 int m_triangleIndex; 526 char m_pad[4]; 527 }; 528 529 530 struct btQuantizedBvhNodeData 531 { 532 unsigned short m_quantizedAabbMin[3]; 533 unsigned short m_quantizedAabbMax[3]; 534 int m_escapeIndexOrTriangleIndex; 535 }; 536 537 struct btQuantizedBvhFloatData 538 { 539 btVector3FloatData m_bvhAabbMin; 540 btVector3FloatData m_bvhAabbMax; 541 btVector3FloatData m_bvhQuantization; 542 int m_curNodeIndex; 543 int m_useQuantization; 544 int m_numContiguousLeafNodes; 545 int m_numQuantizedContiguousNodes; 546 btOptimizedBvhNodeFloatData *m_contiguousNodesPtr; 547 btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; 548 btBvhSubtreeInfoData *m_subTreeInfoPtr; 549 int m_traversalMode; 550 int m_numSubtreeHeaders; 551 552 }; 553 554 struct btQuantizedBvhDoubleData 555 { 556 btVector3DoubleData m_bvhAabbMin; 557 btVector3DoubleData m_bvhAabbMax; 558 btVector3DoubleData m_bvhQuantization; 559 int m_curNodeIndex; 560 int m_useQuantization; 561 int m_numContiguousLeafNodes; 562 int m_numQuantizedContiguousNodes; 563 btOptimizedBvhNodeDoubleData *m_contiguousNodesPtr; 564 btQuantizedBvhNodeData *m_quantizedContiguousNodesPtr; 565 566 int m_traversalMode; 567 int m_numSubtreeHeaders; 568 btBvhSubtreeInfoData *m_subTreeInfoPtr; 569 }; 570 571 572 SIMD_FORCE_INLINE int btQuantizedBvh::calculateSerializeBufferSizeNew() const 573 { 574 return sizeof(btQuantizedBvhData); 575 } 576 577 578 473 579 #endif //QUANTIZED_BVH_H -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.cpp
r5781 r8351 21 21 #include "LinearMath/btTransform.h" 22 22 #include "LinearMath/btMatrix3x3.h" 23 #include "LinearMath/btAabbUtil2.h" 24 23 25 #include <new> 24 26 … … 163 165 } 164 166 rayCallback.process(proxy); 167 } 168 } 169 170 171 void btSimpleBroadphase::aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback) 172 { 173 for (int i=0; i <= m_LastHandleIndex; i++) 174 { 175 btSimpleBroadphaseProxy* proxy = &m_pHandles[i]; 176 if(!proxy->m_clientObject) 177 { 178 continue; 179 } 180 if (TestAabbAgainstAabb2(aabbMin,aabbMax,proxy->m_aabbMin,proxy->m_aabbMax)) 181 { 182 callback.process(proxy); 183 } 165 184 } 166 185 } -
code/trunk/src/external/bullet/BulletCollision/BroadphaseCollision/btSimpleBroadphase.h
r5781 r8351 137 137 138 138 virtual void rayTest(const btVector3& rayFrom,const btVector3& rayTo, btBroadphaseRayCallback& rayCallback, const btVector3& aabbMin=btVector3(0,0,0),const btVector3& aabbMax=btVector3(0,0,0)); 139 virtual void aabbTest(const btVector3& aabbMin, const btVector3& aabbMax, btBroadphaseAabbCallback& callback); 139 140 140 141 btOverlappingPairCache* getOverlappingPairCache() … … 154 155 virtual void getBroadphaseAabb(btVector3& aabbMin,btVector3& aabbMax) const 155 156 { 156 aabbMin.setValue(- 1e30f,-1e30f,-1e30f);157 aabbMax.setValue( 1e30f,1e30f,1e30f);157 aabbMin.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 158 aabbMax.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 158 159 } 159 160 -
code/trunk/src/external/bullet/BulletCollision/CMakeLists.txt
r5929 r8351 6 6 BroadphaseCollision/btBroadphaseProxy.cpp 7 7 BroadphaseCollision/btCollisionAlgorithm.cpp 8 BroadphaseCollision/btDbvt.cpp 9 BroadphaseCollision/btDbvtBroadphase.cpp 8 10 BroadphaseCollision/btDispatcher.cpp 9 BroadphaseCollision/btDbvtBroadphase.cpp10 BroadphaseCollision/btDbvt.cpp11 11 BroadphaseCollision/btMultiSapBroadphase.cpp 12 12 BroadphaseCollision/btOverlappingPairCache.cpp … … 15 15 16 16 CollisionDispatch/btActivatingCollisionAlgorithm.cpp 17 CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp 18 CollisionDispatch/btBox2dBox2dCollisionAlgorithm.cpp 19 CollisionDispatch/btBoxBoxDetector.cpp 17 20 CollisionDispatch/btCollisionDispatcher.cpp 18 21 CollisionDispatch/btCollisionObject.cpp … … 20 23 CollisionDispatch/btCompoundCollisionAlgorithm.cpp 21 24 CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp 25 CollisionDispatch/btConvexConvexAlgorithm.cpp 26 CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp 27 CollisionDispatch/btConvex2dConvex2dAlgorithm.cpp 22 28 CollisionDispatch/btDefaultCollisionConfiguration.cpp 23 CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp 24 CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp 25 CollisionDispatch/btBoxBoxDetector.cpp 29 CollisionDispatch/btEmptyCollisionAlgorithm.cpp 26 30 CollisionDispatch/btGhostObject.cpp 27 CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp 28 CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp 29 CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp 30 CollisionDispatch/btConvexConvexAlgorithm.cpp 31 CollisionDispatch/btEmptyCollisionAlgorithm.cpp 31 CollisionDispatch/btInternalEdgeUtility.cpp 32 CollisionDispatch/btInternalEdgeUtility.h 32 33 CollisionDispatch/btManifoldResult.cpp 33 34 CollisionDispatch/btSimulationIslandManager.cpp 35 CollisionDispatch/btSphereBoxCollisionAlgorithm.cpp 36 CollisionDispatch/btSphereSphereCollisionAlgorithm.cpp 37 CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp 34 38 CollisionDispatch/btUnionFind.cpp 35 39 CollisionDispatch/SphereTriangleDetector.cpp 36 40 37 41 CollisionShapes/btBoxShape.cpp 42 CollisionShapes/btBox2dShape.cpp 38 43 CollisionShapes/btBvhTriangleMeshShape.cpp 39 44 CollisionShapes/btCapsuleShape.cpp … … 43 48 CollisionShapes/btConeShape.cpp 44 49 CollisionShapes/btConvexHullShape.cpp 50 CollisionShapes/btConvexInternalShape.cpp 45 51 CollisionShapes/btConvexPointCloudShape.cpp 46 52 CollisionShapes/btConvexShape.cpp 47 CollisionShapes/btConvex InternalShape.cpp53 CollisionShapes/btConvex2dShape.cpp 48 54 CollisionShapes/btConvexTriangleMeshShape.cpp 49 55 CollisionShapes/btCylinderShape.cpp … … 56 62 CollisionShapes/btPolyhedralConvexShape.cpp 57 63 CollisionShapes/btScaledBvhTriangleMeshShape.cpp 58 CollisionShapes/bt TetrahedronShape.cpp64 CollisionShapes/btShapeHull.cpp 59 65 CollisionShapes/btSphereShape.cpp 60 CollisionShapes/btShapeHull.cpp61 66 CollisionShapes/btStaticPlaneShape.cpp 62 67 CollisionShapes/btStridingMeshInterface.cpp 68 CollisionShapes/btTetrahedronShape.cpp 69 CollisionShapes/btTriangleBuffer.cpp 63 70 CollisionShapes/btTriangleCallback.cpp 64 CollisionShapes/btTriangleBuffer.cpp65 71 CollisionShapes/btTriangleIndexVertexArray.cpp 66 72 CollisionShapes/btTriangleIndexVertexMaterialArray.cpp … … 69 75 CollisionShapes/btUniformScalingShape.cpp 70 76 71 Gimpact/btContactProcessing.cpp72 Gimpact/btGImpactShape.cpp73 Gimpact/btGImpactBvh.cpp74 Gimpact/btGenericPoolAllocator.cpp75 Gimpact/btGImpactCollisionAlgorithm.cpp76 Gimpact/btTriangleShapeEx.cpp77 Gimpact/btGImpactQuantizedBvh.cpp78 79 77 NarrowPhaseCollision/btContinuousConvexCollision.cpp 78 NarrowPhaseCollision/btConvexCast.cpp 79 NarrowPhaseCollision/btGjkConvexCast.cpp 80 80 NarrowPhaseCollision/btGjkEpa2.cpp 81 81 NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp 82 NarrowPhaseCollision/btConvexCast.cpp83 NarrowPhaseCollision/btGjkConvexCast.cpp84 82 NarrowPhaseCollision/btGjkPairDetector.cpp 85 83 NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp … … 91 89 COMPILATION_END 92 90 93 COMPILATION_BEGIN BulletGImpactCompilation.cpp94 Gimpact/gim_contact.cpp95 Gimpact/gim_memory.cpp96 Gimpact/gim_tri_collision.cpp97 Gimpact/gim_box_set.cpp98 COMPILATION_END99 100 91 # Headers 101 92 BroadphaseCollision/btAxisSweep3.h … … 103 94 BroadphaseCollision/btBroadphaseProxy.h 104 95 BroadphaseCollision/btCollisionAlgorithm.h 96 BroadphaseCollision/btDbvt.h 97 BroadphaseCollision/btDbvtBroadphase.h 105 98 BroadphaseCollision/btDispatcher.h 106 BroadphaseCollision/btDbvtBroadphase.h107 BroadphaseCollision/btDbvt.h108 99 BroadphaseCollision/btMultiSapBroadphase.h 109 100 BroadphaseCollision/btOverlappingPairCache.h … … 113 104 114 105 CollisionDispatch/btActivatingCollisionAlgorithm.h 106 CollisionDispatch/btBoxBoxCollisionAlgorithm.h 107 CollisionDispatch/btBox2dBox2dCollisionAlgorithm.h 108 CollisionDispatch/btBoxBoxDetector.h 115 109 CollisionDispatch/btCollisionConfiguration.h 116 110 CollisionDispatch/btCollisionCreateFunc.h … … 120 114 CollisionDispatch/btCompoundCollisionAlgorithm.h 121 115 CollisionDispatch/btConvexConcaveCollisionAlgorithm.h 116 CollisionDispatch/btConvexConvexAlgorithm.h 117 CollisionDispatch/btConvex2dConvex2dAlgorithm.h 118 CollisionDispatch/btConvexPlaneCollisionAlgorithm.h 122 119 CollisionDispatch/btDefaultCollisionConfiguration.h 123 CollisionDispatch/btSphereSphereCollisionAlgorithm.h 124 CollisionDispatch/btBoxBoxCollisionAlgorithm.h 125 CollisionDispatch/btBoxBoxDetector.h 120 CollisionDispatch/btEmptyCollisionAlgorithm.h 126 121 CollisionDispatch/btGhostObject.h 127 CollisionDispatch/btSphereBoxCollisionAlgorithm.h128 CollisionDispatch/btConvexPlaneCollisionAlgorithm.h129 CollisionDispatch/btSphereTriangleCollisionAlgorithm.h130 CollisionDispatch/btConvexConvexAlgorithm.h131 CollisionDispatch/btEmptyCollisionAlgorithm.h132 122 CollisionDispatch/btManifoldResult.h 133 123 CollisionDispatch/btSimulationIslandManager.h 124 CollisionDispatch/btSphereBoxCollisionAlgorithm.h 125 CollisionDispatch/btSphereSphereCollisionAlgorithm.h 126 CollisionDispatch/btSphereTriangleCollisionAlgorithm.h 134 127 CollisionDispatch/btUnionFind.h 135 128 CollisionDispatch/SphereTriangleDetector.h 136 129 137 130 CollisionShapes/btBoxShape.h 131 CollisionShapes/btBox2dShape.h 138 132 CollisionShapes/btBvhTriangleMeshShape.h 139 133 CollisionShapes/btCapsuleShape.h 140 CollisionShapes/btCollisionMargin 134 CollisionShapes/btCollisionMargin.h 141 135 CollisionShapes/btCollisionShape.h 142 136 CollisionShapes/btCompoundShape.h … … 144 138 CollisionShapes/btConeShape.h 145 139 CollisionShapes/btConvexHullShape.h 140 CollisionShapes/btConvexInternalShape.h 146 141 CollisionShapes/btConvexPointCloudShape.h 147 142 CollisionShapes/btConvexShape.h 148 CollisionShapes/btConvex InternalShape.h143 CollisionShapes/btConvex2dShape.h 149 144 CollisionShapes/btConvexTriangleMeshShape.h 150 145 CollisionShapes/btCylinderShape.h 151 146 CollisionShapes/btEmptyShape.h 152 147 CollisionShapes/btHeightfieldTerrainShape.h 148 CollisionShapes/btMaterial.h 153 149 CollisionShapes/btMinkowskiSumShape.h 154 CollisionShapes/btMaterial.h155 150 CollisionShapes/btMultimaterialTriangleMeshShape.h 156 151 CollisionShapes/btMultiSphereShape.h … … 158 153 CollisionShapes/btPolyhedralConvexShape.h 159 154 CollisionShapes/btScaledBvhTriangleMeshShape.h 160 CollisionShapes/bt TetrahedronShape.h155 CollisionShapes/btShapeHull.h 161 156 CollisionShapes/btSphereShape.h 162 CollisionShapes/btShapeHull.h163 157 CollisionShapes/btStaticPlaneShape.h 164 158 CollisionShapes/btStridingMeshInterface.h 159 CollisionShapes/btTetrahedronShape.h 160 CollisionShapes/btTriangleBuffer.h 165 161 CollisionShapes/btTriangleCallback.h 166 CollisionShapes/btTriangleBuffer.h167 162 CollisionShapes/btTriangleIndexVertexArray.h 168 163 CollisionShapes/btTriangleIndexVertexMaterialArray.h 164 CollisionShapes/btTriangleInfoMap.h 169 165 CollisionShapes/btTriangleMesh.h 170 166 CollisionShapes/btTriangleMeshShape.h 167 CollisionShapes/btTriangleShape.h 171 168 CollisionShapes/btUniformScalingShape.h 172 173 Gimpact/btGImpactShape.h174 Gimpact/gim_contact.h175 Gimpact/btGImpactBvh.h176 Gimpact/btGenericPoolAllocator.h177 Gimpact/gim_memory.h178 Gimpact/btGImpactCollisionAlgorithm.h179 Gimpact/btTriangleShapeEx.h180 Gimpact/gim_tri_collision.h181 Gimpact/btGImpactQuantizedBvh.h182 Gimpact/gim_box_set.h183 169 184 170 NarrowPhaseCollision/btContinuousConvexCollision.h -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.cpp
r5781 r8351 38 38 btScalar timeOfImpact = btScalar(1.); 39 39 btScalar depth = btScalar(0.); 40 // output.m_distance = btScalar( 1e30);40 // output.m_distance = btScalar(BT_LARGE_FLOAT); 41 41 //move sphere into triangle space 42 42 btTransform sphereInTr = transformB.inverseTimes(transformA); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/SphereTriangleDetector.h
r5781 r8351 35 35 virtual ~SphereTriangleDetector() {}; 36 36 37 bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold); 38 37 39 private: 38 40 39 bool collide(const btVector3& sphereCenter,btVector3 &point, btVector3& resultNormal, btScalar& depth, btScalar &timeOfImpact, btScalar contactBreakingThreshold);41 40 42 bool pointInTriangle(const btVector3 vertices[], const btVector3 &normal, btVector3 *p ); 41 43 bool facecontains(const btVector3 &p,const btVector3* vertices,btVector3& normal); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxCollisionAlgorithm.cpp
r5781 r8351 62 62 63 63 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 64 input.m_maximumDistanceSquared = 1e30f;64 input.m_maximumDistanceSquared = BT_LARGE_FLOAT; 65 65 input.m_transformA = body0->getWorldTransform(); 66 66 input.m_transformB = body1->getWorldTransform(); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btBoxBoxDetector.cpp
r5781 r8351 1 2 1 /* 3 2 * Box-Box collision detection re-distributed under the ZLib license with permission from Russell L. Smith … … 213 212 } else 214 213 { 215 a= 1e30f;214 a=BT_LARGE_FLOAT; 216 215 } 217 216 cx = a*(cx + q*(p[n*2-2]+p[0])); … … 268 267 { 269 268 const btScalar fudge_factor = btScalar(1.05); 270 btVector3 p,pp,normalC ;269 btVector3 p,pp,normalC(0.f,0.f,0.f); 271 270 const btScalar *normalR = 0; 272 271 btScalar A[3],B[3],R11,R12,R13,R21,R22,R23,R31,R32,R33, … … 334 333 #define TST(expr1,expr2,n1,n2,n3,cc) \ 335 334 s2 = btFabs(expr1) - (expr2); \ 336 if (s2 > 0) return 0; \335 if (s2 > SIMD_EPSILON) return 0; \ 337 336 l = btSqrt((n1)*(n1) + (n2)*(n2) + (n3)*(n3)); \ 338 if (l > 0) { \337 if (l > SIMD_EPSILON) { \ 339 338 s2 /= l; \ 340 339 if (s2*fudge_factor > s) { \ … … 346 345 } \ 347 346 } 347 348 btScalar fudge2 (1.0e-5f); 349 350 Q11 += fudge2; 351 Q12 += fudge2; 352 Q13 += fudge2; 353 354 Q21 += fudge2; 355 Q22 += fudge2; 356 Q23 += fudge2; 357 358 Q31 += fudge2; 359 Q32 += fudge2; 360 Q33 += fudge2; 348 361 349 362 // separating axis = u1 x (v1,v2,v3) … … 425 438 #else 426 439 output.addContactPoint(-normal,pb,-*depth); 440 427 441 #endif // 428 442 *return_code = code; … … 594 608 595 609 if (cnum <= maxc) { 610 611 if (code<4) 612 { 596 613 // we have less contacts than we need, so we use them all 597 for (j=0; j < cnum; j++) { 598 599 //AddContactPoint... 600 601 //dContactGeom *con = CONTACT(contact,skip*j); 602 //for (i=0; i<3; i++) con->pos[i] = point[j*3+i] + pa[i]; 603 //con->depth = dep[j]; 604 614 for (j=0; j < cnum; j++) 615 { 605 616 btVector3 pointInWorld; 606 617 for (i=0; i<3; i++) … … 609 620 610 621 } 622 } else 623 { 624 // we have less contacts than we need, so we use them all 625 for (j=0; j < cnum; j++) 626 { 627 btVector3 pointInWorld; 628 for (i=0; i<3; i++) 629 pointInWorld[i] = point[j*3+i] + pa[i]-normal[i]*dep[j]; 630 //pointInWorld[i] = point[j*3+i] + pa[i]; 631 output.addContactPoint(-normal,pointInWorld,-dep[j]); 632 } 633 } 611 634 } 612 635 else { … … 633 656 for (i=0; i<3; i++) 634 657 posInWorld[i] = point[iret[j]*3+i] + pa[i]; 635 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]); 658 if (code<4) 659 { 660 output.addContactPoint(-normal,posInWorld,-dep[iret[j]]); 661 } else 662 { 663 output.addContactPoint(-normal,posInWorld-normal*dep[iret[j]],-dep[iret[j]]); 664 } 636 665 } 637 666 cnum = maxc; -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.cpp
r5781 r8351 35 35 36 36 btCollisionDispatcher::btCollisionDispatcher (btCollisionConfiguration* collisionConfiguration): 37 m_count(0), 38 m_useIslands(true), 39 m_staticWarningReported(false), 37 m_dispatcherFlags(btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD), 40 38 m_collisionConfiguration(collisionConfiguration) 41 39 { … … 80 78 btCollisionObject* body1 = (btCollisionObject*)b1; 81 79 82 //test for Bullet 2.74: use a relative contact breaking threshold without clamping against 'gContactBreakingThreshold' 83 //btScalar contactBreakingThreshold = btMin(gContactBreakingThreshold,btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold())); 84 btScalar contactBreakingThreshold = btMin(body0->getCollisionShape()->getContactBreakingThreshold(),body1->getCollisionShape()->getContactBreakingThreshold()); 80 //optional relative contact breaking threshold, turned on by default (use setDispatcherFlags to switch off feature for improved performance) 81 82 btScalar contactBreakingThreshold = (m_dispatcherFlags & btCollisionDispatcher::CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD) ? 83 btMin(body0->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold) , body1->getCollisionShape()->getContactBreakingThreshold(gContactBreakingThreshold)) 84 : gContactBreakingThreshold ; 85 85 86 86 btScalar contactProcessingThreshold = btMin(body0->getContactProcessingThreshold(),body1->getContactProcessingThreshold()); … … 170 170 171 171 #ifdef BT_DEBUG 172 if (! m_staticWarningReported)172 if (!(m_dispatcherFlags & btCollisionDispatcher::CD_STATIC_STATIC_REPORTED)) 173 173 { 174 174 //broadphase filtering already deals with this … … 176 176 (body1->isStaticObject() || body1->isKinematicObject())) 177 177 { 178 m_ staticWarningReported = true;178 m_dispatcherFlags |= btCollisionDispatcher::CD_STATIC_STATIC_REPORTED; 179 179 printf("warning btCollisionDispatcher::needsCollision: static-static collision!\n"); 180 180 } -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionDispatcher.h
r5781 r8351 43 43 class btCollisionDispatcher : public btDispatcher 44 44 { 45 int m_count;45 int m_dispatcherFlags; 46 46 47 47 btAlignedObjectArray<btPersistentManifold*> m_manifoldsPtr; 48 48 49 bool m_useIslands;50 51 bool m_staticWarningReported;52 53 49 btManifoldResult m_defaultManifoldResult; 54 50 … … 60 56 61 57 btCollisionAlgorithmCreateFunc* m_doubleDispatch[MAX_BROADPHASE_COLLISION_TYPES][MAX_BROADPHASE_COLLISION_TYPES]; 62 63 58 64 59 btCollisionConfiguration* m_collisionConfiguration; … … 66 61 67 62 public: 63 64 enum DispatcherFlags 65 { 66 CD_STATIC_STATIC_REPORTED = 1, 67 CD_USE_RELATIVE_CONTACT_BREAKING_THRESHOLD = 2 68 }; 69 70 int getDispatcherFlags() const 71 { 72 return m_dispatcherFlags; 73 } 74 75 void setDispatcherFlags(int flags) 76 { 77 (void) flags; 78 m_dispatcherFlags = 0; 79 } 68 80 69 81 ///registerCollisionCreateFunc allows registration of custom/alternative collision create functions -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.cpp
r5781 r8351 16 16 17 17 #include "btCollisionObject.h" 18 #include "LinearMath/btSerializer.h" 18 19 19 20 btCollisionObject::btCollisionObject() 20 21 : m_anisotropicFriction(1.f,1.f,1.f), 21 22 m_hasAnisotropicFriction(false), 22 m_contactProcessingThreshold( 1e30f),23 m_contactProcessingThreshold(BT_LARGE_FLOAT), 23 24 m_broadphaseHandle(0), 24 25 m_collisionShape(0), 26 m_extensionPointer(0), 25 27 m_rootCollisionShape(0), 26 28 m_collisionFlags(btCollisionObject::CF_STATIC_OBJECT), … … 31 33 m_friction(btScalar(0.5)), 32 34 m_restitution(btScalar(0.)), 35 m_internalType(CO_COLLISION_OBJECT), 33 36 m_userObjectPointer(0), 34 m_internalType(CO_COLLISION_OBJECT),35 37 m_hitFraction(btScalar(1.)), 36 38 m_ccdSweptSphereRadius(btScalar(0.)), … … 38 40 m_checkCollideWith(false) 39 41 { 40 42 m_worldTransform.setIdentity(); 41 43 } 42 44 … … 65 67 } 66 68 69 const char* btCollisionObject::serialize(void* dataBuffer, btSerializer* serializer) const 70 { 71 72 btCollisionObjectData* dataOut = (btCollisionObjectData*)dataBuffer; 73 74 m_worldTransform.serialize(dataOut->m_worldTransform); 75 m_interpolationWorldTransform.serialize(dataOut->m_interpolationWorldTransform); 76 m_interpolationLinearVelocity.serialize(dataOut->m_interpolationLinearVelocity); 77 m_interpolationAngularVelocity.serialize(dataOut->m_interpolationAngularVelocity); 78 m_anisotropicFriction.serialize(dataOut->m_anisotropicFriction); 79 dataOut->m_hasAnisotropicFriction = m_hasAnisotropicFriction; 80 dataOut->m_contactProcessingThreshold = m_contactProcessingThreshold; 81 dataOut->m_broadphaseHandle = 0; 82 dataOut->m_collisionShape = serializer->getUniquePointer(m_collisionShape); 83 dataOut->m_rootCollisionShape = 0;//@todo 84 dataOut->m_collisionFlags = m_collisionFlags; 85 dataOut->m_islandTag1 = m_islandTag1; 86 dataOut->m_companionId = m_companionId; 87 dataOut->m_activationState1 = m_activationState1; 88 dataOut->m_activationState1 = m_activationState1; 89 dataOut->m_deactivationTime = m_deactivationTime; 90 dataOut->m_friction = m_friction; 91 dataOut->m_restitution = m_restitution; 92 dataOut->m_internalType = m_internalType; 93 94 char* name = (char*) serializer->findNameForPointer(this); 95 dataOut->m_name = (char*)serializer->getUniquePointer(name); 96 if (dataOut->m_name) 97 { 98 serializer->serializeName(name); 99 } 100 dataOut->m_hitFraction = m_hitFraction; 101 dataOut->m_ccdSweptSphereRadius = m_ccdSweptSphereRadius; 102 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 103 dataOut->m_ccdMotionThreshold = m_ccdMotionThreshold; 104 dataOut->m_checkCollideWith = m_checkCollideWith; 105 106 return btCollisionObjectDataName; 107 } 67 108 68 109 110 void btCollisionObject::serializeSingleObject(class btSerializer* serializer) const 111 { 112 int len = calculateSerializeBufferSize(); 113 btChunk* chunk = serializer->allocate(len,1); 114 const char* structType = serialize(chunk->m_oldPtr, serializer); 115 serializer->finalizeChunk(chunk,structType,BT_COLLISIONOBJECT_CODE,(void*)this); 116 } -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionObject.h
r5781 r8351 28 28 struct btBroadphaseProxy; 29 29 class btCollisionShape; 30 struct btCollisionShapeData; 30 31 #include "LinearMath/btMotionState.h" 31 32 #include "LinearMath/btAlignedAllocator.h" 32 33 #include "LinearMath/btAlignedObjectArray.h" 33 34 34 35 35 typedef btAlignedObjectArray<class btCollisionObject*> btCollisionObjectArray; 36 37 #ifdef BT_USE_DOUBLE_PRECISION 38 #define btCollisionObjectData btCollisionObjectDoubleData 39 #define btCollisionObjectDataName "btCollisionObjectDoubleData" 40 #else 41 #define btCollisionObjectData btCollisionObjectFloatData 42 #define btCollisionObjectDataName "btCollisionObjectFloatData" 43 #endif 36 44 37 45 … … 54 62 btVector3 m_interpolationAngularVelocity; 55 63 56 btVector3 57 boolm_hasAnisotropicFriction;58 btScalar 64 btVector3 m_anisotropicFriction; 65 int m_hasAnisotropicFriction; 66 btScalar m_contactProcessingThreshold; 59 67 60 68 btBroadphaseProxy* m_broadphaseHandle; 61 69 btCollisionShape* m_collisionShape; 70 ///m_extensionPointer is used by some internal low-level Bullet extensions. 71 void* m_extensionPointer; 62 72 63 73 ///m_rootCollisionShape is temporarily used to store the original collision shape … … 77 87 btScalar m_restitution; 78 88 79 ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer80 void* m_userObjectPointer;81 82 89 ///m_internalType is reserved to distinguish Bullet's btCollisionObject, btRigidBody, btSoftBody, btGhostObject etc. 83 90 ///do not assign your own m_internalType unless you write a new dynamics object class. 84 91 int m_internalType; 85 92 93 ///users can point to their objects, m_userPointer is not used by Bullet, see setUserPointer/getUserPointer 94 void* m_userObjectPointer; 95 86 96 ///time of impact calculation 87 97 btScalar m_hitFraction; … … 94 104 95 105 /// If some object should have elaborate collision filtering by sub-classes 96 bool m_checkCollideWith; 97 98 char m_pad[7]; 106 int m_checkCollideWith; 99 107 100 108 virtual bool checkCollideWithOverride(btCollisionObject* /* co */) … … 113 121 CF_NO_CONTACT_RESPONSE = 4, 114 122 CF_CUSTOM_MATERIAL_CALLBACK = 8,//this allows per-triangle material (friction/restitution) 115 CF_CHARACTER_OBJECT = 16 123 CF_CHARACTER_OBJECT = 16, 124 CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing 125 CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing 116 126 }; 117 127 … … 119 129 { 120 130 CO_COLLISION_OBJECT =1, 121 CO_RIGID_BODY ,131 CO_RIGID_BODY=2, 122 132 ///CO_GHOST_OBJECT keeps track of all objects overlapping its AABB and that pass its collision filter 123 133 ///It is useful for collision sensors, explosion objects, character controller etc. 124 CO_GHOST_OBJECT, 125 CO_SOFT_BODY, 126 CO_HF_FLUID 134 CO_GHOST_OBJECT=4, 135 CO_SOFT_BODY=8, 136 CO_HF_FLUID=16, 137 CO_USER_TYPE=32 127 138 }; 128 139 … … 144 155 bool hasAnisotropicFriction() const 145 156 { 146 return m_hasAnisotropicFriction ;157 return m_hasAnisotropicFriction!=0; 147 158 } 148 159 … … 214 225 } 215 226 227 ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions. 228 ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead. 229 void* internalGetExtensionPointer() const 230 { 231 return m_extensionPointer; 232 } 233 ///Avoid using this internal API call, the extension pointer is used by some Bullet extensions 234 ///If you need to store your own user pointer, use 'setUserPointer/getUserPointer' instead. 235 void internalSetExtensionPointer(void* pointer) 236 { 237 m_extensionPointer = pointer; 238 } 239 216 240 SIMD_FORCE_INLINE int getActivationState() const { return m_activationState1;} 217 241 … … 394 418 void setCcdMotionThreshold(btScalar ccdMotionThreshold) 395 419 { 396 m_ccdMotionThreshold = ccdMotionThreshold *ccdMotionThreshold;420 m_ccdMotionThreshold = ccdMotionThreshold; 397 421 } 398 422 … … 417 441 return true; 418 442 } 443 444 virtual int calculateSerializeBufferSize() const; 445 446 ///fills the dataBuffer and returns the struct name (and 0 on failure) 447 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const; 448 449 virtual void serializeSingleObject(class btSerializer* serializer) const; 450 419 451 }; 420 452 453 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 454 struct btCollisionObjectDoubleData 455 { 456 void *m_broadphaseHandle; 457 void *m_collisionShape; 458 btCollisionShapeData *m_rootCollisionShape; 459 char *m_name; 460 461 btTransformDoubleData m_worldTransform; 462 btTransformDoubleData m_interpolationWorldTransform; 463 btVector3DoubleData m_interpolationLinearVelocity; 464 btVector3DoubleData m_interpolationAngularVelocity; 465 btVector3DoubleData m_anisotropicFriction; 466 double m_contactProcessingThreshold; 467 double m_deactivationTime; 468 double m_friction; 469 double m_restitution; 470 double m_hitFraction; 471 double m_ccdSweptSphereRadius; 472 double m_ccdMotionThreshold; 473 474 int m_hasAnisotropicFriction; 475 int m_collisionFlags; 476 int m_islandTag1; 477 int m_companionId; 478 int m_activationState1; 479 int m_internalType; 480 int m_checkCollideWith; 481 482 char m_padding[4]; 483 }; 484 485 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 486 struct btCollisionObjectFloatData 487 { 488 void *m_broadphaseHandle; 489 void *m_collisionShape; 490 btCollisionShapeData *m_rootCollisionShape; 491 char *m_name; 492 493 btTransformFloatData m_worldTransform; 494 btTransformFloatData m_interpolationWorldTransform; 495 btVector3FloatData m_interpolationLinearVelocity; 496 btVector3FloatData m_interpolationAngularVelocity; 497 btVector3FloatData m_anisotropicFriction; 498 float m_contactProcessingThreshold; 499 float m_deactivationTime; 500 float m_friction; 501 float m_restitution; 502 float m_hitFraction; 503 float m_ccdSweptSphereRadius; 504 float m_ccdMotionThreshold; 505 506 int m_hasAnisotropicFriction; 507 int m_collisionFlags; 508 int m_islandTag1; 509 int m_companionId; 510 int m_activationState1; 511 int m_internalType; 512 int m_checkCollideWith; 513 }; 514 515 516 517 SIMD_FORCE_INLINE int btCollisionObject::calculateSerializeBufferSize() const 518 { 519 return sizeof(btCollisionObjectData); 520 } 521 522 523 421 524 #endif //COLLISION_OBJECT_H -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.cpp
r5781 r8351 27 27 #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h" 28 28 #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h" 29 29 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 30 30 #include "BulletCollision/BroadphaseCollision/btBroadphaseInterface.h" 31 31 #include "LinearMath/btAabbUtil2.h" 32 32 #include "LinearMath/btQuickprof.h" 33 33 #include "LinearMath/btStackAlloc.h" 34 #include "LinearMath/btSerializer.h" 34 35 35 36 //#define USE_BRUTEFORCE_RAYBROADPHASE 1 … … 43 44 44 45 46 ///for debug drawing 47 48 //for debug rendering 49 #include "BulletCollision/CollisionShapes/btBoxShape.h" 50 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 51 #include "BulletCollision/CollisionShapes/btCompoundShape.h" 52 #include "BulletCollision/CollisionShapes/btConeShape.h" 53 #include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h" 54 #include "BulletCollision/CollisionShapes/btCylinderShape.h" 55 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h" 56 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 57 #include "BulletCollision/CollisionShapes/btSphereShape.h" 58 #include "BulletCollision/CollisionShapes/btTriangleCallback.h" 59 #include "BulletCollision/CollisionShapes/btTriangleMeshShape.h" 60 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h" 61 62 63 45 64 btCollisionWorld::btCollisionWorld(btDispatcher* dispatcher,btBroadphaseInterface* pairCache, btCollisionConfiguration* collisionConfiguration) 46 65 :m_dispatcher1(dispatcher), 47 66 m_broadphasePairCache(pairCache), 48 m_debugDrawer(0) 67 m_debugDrawer(0), 68 m_forceUpdateAllAabbs(true) 49 69 { 50 70 m_stackAlloc = collisionConfiguration->getStackAllocator(); … … 89 109 { 90 110 111 btAssert(collisionObject); 112 91 113 //check that the object isn't already added 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 114 btAssert( m_collisionObjects.findLinearSearch(collisionObject) == m_collisionObjects.size()); 115 116 m_collisionObjects.push_back(collisionObject); 117 118 //calculate new AABB 119 btTransform trans = collisionObject->getWorldTransform(); 120 121 btVector3 minAabb; 122 btVector3 maxAabb; 123 collisionObject->getCollisionShape()->getAabb(trans,minAabb,maxAabb); 124 125 int type = collisionObject->getCollisionShape()->getShapeType(); 126 collisionObject->setBroadphaseHandle( getBroadphase()->createProxy( 127 minAabb, 128 maxAabb, 129 type, 130 collisionObject, 131 collisionFilterGroup, 132 collisionFilterMask, 133 m_dispatcher1,0 134 )) ; 113 135 114 136 … … 163 185 164 186 //only update aabb of active objects 165 if ( colObj->isActive())187 if (m_forceUpdateAllAabbs || colObj->isActive()) 166 188 { 167 189 updateSingleAabb(colObj); … … 226 248 227 249 void btCollisionWorld::rayTestSingle(const btTransform& rayFromTrans,const btTransform& rayToTrans, 228 229 230 231 250 btCollisionObject* collisionObject, 251 const btCollisionShape* collisionShape, 252 const btTransform& colObjWorldTransform, 253 RayResultCallback& resultCallback) 232 254 { 233 255 btSphereShape pointShape(btScalar(0.0)); … … 237 259 if (collisionShape->isConvex()) 238 260 { 239 // BT_PROFILE("rayTestConvex");261 // BT_PROFILE("rayTestConvex"); 240 262 btConvexCast::CastResult castResult; 241 263 castResult.m_fraction = resultCallback.m_closestHitFraction; … … 266 288 btCollisionWorld::LocalRayResult localRayResult 267 289 ( 268 269 270 271 290 collisionObject, 291 0, 292 castResult.m_normal, 293 castResult.m_fraction 272 294 ); 273 295 … … 281 303 if (collisionShape->isConcave()) 282 304 { 283 // BT_PROFILE("rayTestConcave");305 // BT_PROFILE("rayTestConcave"); 284 306 if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE) 285 307 { … … 297 319 btTriangleMeshShape* m_triangleMesh; 298 320 321 btTransform m_colObjWorldTransform; 322 299 323 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 300 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh): 301 //@BP Mod 302 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 303 m_resultCallback(resultCallback), 304 m_collisionObject(collisionObject), 305 m_triangleMesh(triangleMesh) 306 { 307 } 324 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh,const btTransform& colObjWorldTransform): 325 //@BP Mod 326 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 327 m_resultCallback(resultCallback), 328 m_collisionObject(collisionObject), 329 m_triangleMesh(triangleMesh), 330 m_colObjWorldTransform(colObjWorldTransform) 331 { 332 } 308 333 309 334 … … 314 339 shapeInfo.m_triangleIndex = triangleIndex; 315 340 341 btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal; 342 316 343 btCollisionWorld::LocalRayResult rayResult 317 (m_collisionObject,344 (m_collisionObject, 318 345 &shapeInfo, 319 hitNormal Local,346 hitNormalWorld, 320 347 hitFraction); 321 348 322 bool normalInWorldSpace = false;349 bool normalInWorldSpace = true; 323 350 return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace); 324 351 } … … 326 353 }; 327 354 328 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh );355 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,triangleMesh,colObjWorldTransform); 329 356 rcb.m_hitFraction = resultCallback.m_closestHitFraction; 330 357 triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal); … … 347 374 btConcaveShape* m_triangleMesh; 348 375 376 btTransform m_colObjWorldTransform; 377 349 378 BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to, 350 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh): 351 //@BP Mod 352 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 353 m_resultCallback(resultCallback), 354 m_collisionObject(collisionObject), 355 m_triangleMesh(triangleMesh) 356 { 357 } 379 btCollisionWorld::RayResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& colObjWorldTransform): 380 //@BP Mod 381 btTriangleRaycastCallback(from,to, resultCallback->m_flags), 382 m_resultCallback(resultCallback), 383 m_collisionObject(collisionObject), 384 m_triangleMesh(triangleMesh), 385 m_colObjWorldTransform(colObjWorldTransform) 386 { 387 } 358 388 359 389 … … 364 394 shapeInfo.m_triangleIndex = triangleIndex; 365 395 396 btVector3 hitNormalWorld = m_colObjWorldTransform.getBasis() * hitNormalLocal; 397 366 398 btCollisionWorld::LocalRayResult rayResult 367 (m_collisionObject,399 (m_collisionObject, 368 400 &shapeInfo, 369 hitNormal Local,401 hitNormalWorld, 370 402 hitFraction); 371 403 372 bool normalInWorldSpace = false;404 bool normalInWorldSpace = true; 373 405 return m_resultCallback->addSingleResult(rayResult,normalInWorldSpace); 374 375 376 406 } 377 407 … … 379 409 380 410 381 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape );411 BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObject,concaveShape, colObjWorldTransform); 382 412 rcb.m_hitFraction = resultCallback.m_closestHitFraction; 383 413 … … 390 420 } 391 421 } else { 392 // BT_PROFILE("rayTestCompound");422 // BT_PROFILE("rayTestCompound"); 393 423 ///@todo: use AABB tree or other BVH acceleration structure, see btDbvt 394 424 if (collisionShape->isCompound()) … … 404 434 btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape(); 405 435 collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape); 436 struct LocalInfoAdder2 : public RayResultCallback { 437 RayResultCallback* m_userCallback; 438 int m_i; 439 LocalInfoAdder2 (int i, RayResultCallback *user) 440 : m_userCallback(user), 441 m_i(i) 442 { 443 m_closestHitFraction = m_userCallback->m_closestHitFraction; 444 } 445 virtual btScalar addSingleResult (btCollisionWorld::LocalRayResult &r, bool b) 446 { 447 btCollisionWorld::LocalShapeInfo shapeInfo; 448 shapeInfo.m_shapePart = -1; 449 shapeInfo.m_triangleIndex = m_i; 450 if (r.m_localShapeInfo == NULL) 451 r.m_localShapeInfo = &shapeInfo; 452 453 const btScalar result = m_userCallback->addSingleResult(r, b); 454 m_closestHitFraction = m_userCallback->m_closestHitFraction; 455 return result; 456 } 457 }; 458 459 LocalInfoAdder2 my_cb(i, &resultCallback); 460 406 461 rayTestSingle(rayFromTrans,rayToTrans, 407 462 collisionObject, 408 463 childCollisionShape, 409 464 childWorldTrans, 410 resultCallback);465 my_cb); 411 466 // restore 412 467 collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); … … 418 473 419 474 void btCollisionWorld::objectQuerySingle(const btConvexShape* castShape,const btTransform& convexFromTrans,const btTransform& convexToTrans, 420 421 422 423 475 btCollisionObject* collisionObject, 476 const btCollisionShape* collisionShape, 477 const btTransform& colObjWorldTransform, 478 ConvexResultCallback& resultCallback, btScalar allowedPenetration) 424 479 { 425 480 if (collisionShape->isConvex()) … … 433 488 btVoronoiSimplexSolver simplexSolver; 434 489 btGjkEpaPenetrationDepthSolver gjkEpaPenetrationSolver; 435 490 436 491 btContinuousConvexCollision convexCaster1(castShape,convexShape,&simplexSolver,&gjkEpaPenetrationSolver); 437 492 //btGjkConvexCast convexCaster2(castShape,convexShape,&simplexSolver); … … 439 494 440 495 btConvexCast* castPtr = &convexCaster1; 441 442 443 496 497 498 444 499 if (castPtr->calcTimeOfImpact(convexFromTrans,convexToTrans,colObjWorldTransform,colObjWorldTransform,castResult)) 445 500 { … … 451 506 castResult.m_normal.normalize(); 452 507 btCollisionWorld::LocalConvexResult localConvexResult 453 454 455 456 457 458 459 508 ( 509 collisionObject, 510 0, 511 castResult.m_normal, 512 castResult.m_hitPoint, 513 castResult.m_fraction 514 ); 460 515 461 516 bool normalInWorldSpace = true; … … 487 542 BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to, 488 543 btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh, const btTransform& triangleToWorld): 489 490 491 492 493 494 544 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), 545 m_resultCallback(resultCallback), 546 m_collisionObject(collisionObject), 547 m_triangleMesh(triangleMesh) 548 { 549 } 495 550 496 551 … … 504 559 505 560 btCollisionWorld::LocalConvexResult convexResult 506 (m_collisionObject,561 (m_collisionObject, 507 562 &shapeInfo, 508 563 hitNormalLocal, … … 544 599 BridgeTriangleConvexcastCallback(const btConvexShape* castShape, const btTransform& from,const btTransform& to, 545 600 btCollisionWorld::ConvexResultCallback* resultCallback, btCollisionObject* collisionObject,btConcaveShape* triangleMesh, const btTransform& triangleToWorld): 546 547 548 549 550 551 601 btTriangleConvexcastCallback(castShape, from,to, triangleToWorld, triangleMesh->getMargin()), 602 m_resultCallback(resultCallback), 603 m_collisionObject(collisionObject), 604 m_triangleMesh(triangleMesh) 605 { 606 } 552 607 553 608 … … 561 616 562 617 btCollisionWorld::LocalConvexResult convexResult 563 (m_collisionObject,618 (m_collisionObject, 564 619 &shapeInfo, 565 620 hitNormalLocal, … … 604 659 btCollisionShape* saveCollisionShape = collisionObject->getCollisionShape(); 605 660 collisionObject->internalSetTemporaryCollisionShape((btCollisionShape*)childCollisionShape); 661 struct LocalInfoAdder : public ConvexResultCallback { 662 ConvexResultCallback* m_userCallback; 663 int m_i; 664 665 LocalInfoAdder (int i, ConvexResultCallback *user) 666 : m_userCallback(user), m_i(i) 667 { 668 m_closestHitFraction = m_userCallback->m_closestHitFraction; 669 } 670 virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult& r, bool b) 671 { 672 btCollisionWorld::LocalShapeInfo shapeInfo; 673 shapeInfo.m_shapePart = -1; 674 shapeInfo.m_triangleIndex = m_i; 675 if (r.m_localShapeInfo == NULL) 676 r.m_localShapeInfo = &shapeInfo; 677 const btScalar result = m_userCallback->addSingleResult(r, b); 678 m_closestHitFraction = m_userCallback->m_closestHitFraction; 679 return result; 680 681 } 682 }; 683 684 LocalInfoAdder my_cb(i, &resultCallback); 685 686 606 687 objectQuerySingle(castShape, convexFromTrans,convexToTrans, 607 688 collisionObject, 608 689 childCollisionShape, 609 690 childWorldTrans, 610 resultCallback, allowedPenetration);691 my_cb, allowedPenetration); 611 692 // restore 612 693 collisionObject->internalSetTemporaryCollisionShape(saveCollisionShape); … … 631 712 632 713 btSingleRayCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld,const btCollisionWorld* world,btCollisionWorld::RayResultCallback& resultCallback) 633 :m_rayFromWorld(rayFromWorld),634 m_rayToWorld(rayToWorld),635 m_world(world),636 m_resultCallback(resultCallback)714 :m_rayFromWorld(rayFromWorld), 715 m_rayToWorld(rayToWorld), 716 m_world(world), 717 m_resultCallback(resultCallback) 637 718 { 638 719 m_rayFromTrans.setIdentity(); … … 644 725 645 726 rayDir.normalize (); 646 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e30647 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];648 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];649 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];727 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 728 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 729 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 730 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 650 731 m_signs[0] = m_rayDirectionInverse[0] < 0.0; 651 732 m_signs[1] = m_rayDirectionInverse[1] < 0.0; … … 656 737 } 657 738 658 739 659 740 660 741 virtual bool process(const btBroadphaseProxy* proxy) … … 687 768 m_world->rayTestSingle(m_rayFromTrans,m_rayToTrans, 688 769 collisionObject, 689 690 691 770 collisionObject->getCollisionShape(), 771 collisionObject->getWorldTransform(), 772 m_resultCallback); 692 773 } 693 774 } … … 698 779 void btCollisionWorld::rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const 699 780 { 700 BT_PROFILE("rayTest");781 //BT_PROFILE("rayTest"); 701 782 /// use the broadphase to accelerate the search for objects, based on their aabb 702 783 /// and for each object with ray-aabb overlap, perform an exact ray test … … 737 818 btVector3 unnormalizedRayDir = (m_convexToTrans.getOrigin()-m_convexFromTrans.getOrigin()); 738 819 btVector3 rayDir = unnormalizedRayDir.normalized(); 739 ///what about division by zero? --> just set rayDirection[i] to INF/ 1e30740 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[0];741 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[1];742 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar( 1e30) : btScalar(1.0) / rayDir[2];820 ///what about division by zero? --> just set rayDirection[i] to INF/BT_LARGE_FLOAT 821 m_rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[0]; 822 m_rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[1]; 823 m_rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(BT_LARGE_FLOAT) : btScalar(1.0) / rayDir[2]; 743 824 m_signs[0] = m_rayDirectionInverse[0] < 0.0; 744 825 m_signs[1] = m_rayDirectionInverse[1] < 0.0; … … 761 842 //RigidcollisionObject* collisionObject = ctrl->GetRigidcollisionObject(); 762 843 m_world->objectQuerySingle(m_castShape, m_convexFromTrans,m_convexToTrans, 763 764 765 766 767 768 } 769 844 collisionObject, 845 collisionObject->getCollisionShape(), 846 collisionObject->getWorldTransform(), 847 m_resultCallback, 848 m_allowedCcdPenetration); 849 } 850 770 851 return true; 771 852 } … … 782 863 /// unfortunately the implementation for rayTest and convexSweepTest duplicated, albeit practically identical 783 864 784 865 785 866 786 867 btTransform convexFromTrans,convexToTrans; … … 825 906 objectQuerySingle(castShape, convexFromTrans,convexToTrans, 826 907 collisionObject, 827 828 829 830 908 collisionObject->getCollisionShape(), 909 collisionObject->getWorldTransform(), 910 resultCallback, 911 allowedCcdPenetration); 831 912 } 832 913 } … … 834 915 #endif //USE_BRUTEFORCE_RAYBROADPHASE 835 916 } 917 918 919 920 struct btBridgedManifoldResult : public btManifoldResult 921 { 922 923 btCollisionWorld::ContactResultCallback& m_resultCallback; 924 925 btBridgedManifoldResult( btCollisionObject* obj0,btCollisionObject* obj1,btCollisionWorld::ContactResultCallback& resultCallback ) 926 :btManifoldResult(obj0,obj1), 927 m_resultCallback(resultCallback) 928 { 929 } 930 931 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth) 932 { 933 bool isSwapped = m_manifoldPtr->getBody0() != m_body0; 934 btVector3 pointA = pointInWorld + normalOnBInWorld * depth; 935 btVector3 localA; 936 btVector3 localB; 937 if (isSwapped) 938 { 939 localA = m_rootTransB.invXform(pointA ); 940 localB = m_rootTransA.invXform(pointInWorld); 941 } else 942 { 943 localA = m_rootTransA.invXform(pointA ); 944 localB = m_rootTransB.invXform(pointInWorld); 945 } 946 947 btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth); 948 newPt.m_positionWorldOnA = pointA; 949 newPt.m_positionWorldOnB = pointInWorld; 950 951 //BP mod, store contact triangles. 952 if (isSwapped) 953 { 954 newPt.m_partId0 = m_partId1; 955 newPt.m_partId1 = m_partId0; 956 newPt.m_index0 = m_index1; 957 newPt.m_index1 = m_index0; 958 } else 959 { 960 newPt.m_partId0 = m_partId0; 961 newPt.m_partId1 = m_partId1; 962 newPt.m_index0 = m_index0; 963 newPt.m_index1 = m_index1; 964 } 965 966 //experimental feature info, for per-triangle material etc. 967 btCollisionObject* obj0 = isSwapped? m_body1 : m_body0; 968 btCollisionObject* obj1 = isSwapped? m_body0 : m_body1; 969 m_resultCallback.addSingleResult(newPt,obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1); 970 971 } 972 973 }; 974 975 976 977 struct btSingleContactCallback : public btBroadphaseAabbCallback 978 { 979 980 btCollisionObject* m_collisionObject; 981 btCollisionWorld* m_world; 982 btCollisionWorld::ContactResultCallback& m_resultCallback; 983 984 985 btSingleContactCallback(btCollisionObject* collisionObject, btCollisionWorld* world,btCollisionWorld::ContactResultCallback& resultCallback) 986 :m_collisionObject(collisionObject), 987 m_world(world), 988 m_resultCallback(resultCallback) 989 { 990 } 991 992 virtual bool process(const btBroadphaseProxy* proxy) 993 { 994 btCollisionObject* collisionObject = (btCollisionObject*)proxy->m_clientObject; 995 if (collisionObject == m_collisionObject) 996 return true; 997 998 //only perform raycast if filterMask matches 999 if(m_resultCallback.needsCollision(collisionObject->getBroadphaseHandle())) 1000 { 1001 btCollisionAlgorithm* algorithm = m_world->getDispatcher()->findAlgorithm(m_collisionObject,collisionObject); 1002 if (algorithm) 1003 { 1004 btBridgedManifoldResult contactPointResult(m_collisionObject,collisionObject, m_resultCallback); 1005 //discrete collision detection query 1006 algorithm->processCollision(m_collisionObject,collisionObject, m_world->getDispatchInfo(),&contactPointResult); 1007 1008 algorithm->~btCollisionAlgorithm(); 1009 m_world->getDispatcher()->freeCollisionAlgorithm(algorithm); 1010 } 1011 } 1012 return true; 1013 } 1014 }; 1015 1016 1017 ///contactTest performs a discrete collision test against all objects in the btCollisionWorld, and calls the resultCallback. 1018 ///it reports one or more contact points for every overlapping object (including the one with deepest penetration) 1019 void btCollisionWorld::contactTest( btCollisionObject* colObj, ContactResultCallback& resultCallback) 1020 { 1021 btVector3 aabbMin,aabbMax; 1022 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(),aabbMin,aabbMax); 1023 btSingleContactCallback contactCB(colObj,this,resultCallback); 1024 1025 m_broadphasePairCache->aabbTest(aabbMin,aabbMax,contactCB); 1026 } 1027 1028 1029 ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected. 1030 ///it reports one or more contact points (including the one with deepest penetration) 1031 void btCollisionWorld::contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback) 1032 { 1033 btCollisionAlgorithm* algorithm = getDispatcher()->findAlgorithm(colObjA,colObjB); 1034 if (algorithm) 1035 { 1036 btBridgedManifoldResult contactPointResult(colObjA,colObjB, resultCallback); 1037 //discrete collision detection query 1038 algorithm->processCollision(colObjA,colObjB, getDispatchInfo(),&contactPointResult); 1039 1040 algorithm->~btCollisionAlgorithm(); 1041 getDispatcher()->freeCollisionAlgorithm(algorithm); 1042 } 1043 1044 } 1045 1046 1047 1048 1049 class DebugDrawcallback : public btTriangleCallback, public btInternalTriangleIndexCallback 1050 { 1051 btIDebugDraw* m_debugDrawer; 1052 btVector3 m_color; 1053 btTransform m_worldTrans; 1054 1055 public: 1056 1057 DebugDrawcallback(btIDebugDraw* debugDrawer,const btTransform& worldTrans,const btVector3& color) : 1058 m_debugDrawer(debugDrawer), 1059 m_color(color), 1060 m_worldTrans(worldTrans) 1061 { 1062 } 1063 1064 virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex) 1065 { 1066 processTriangle(triangle,partId,triangleIndex); 1067 } 1068 1069 virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex) 1070 { 1071 (void)partId; 1072 (void)triangleIndex; 1073 1074 btVector3 wv0,wv1,wv2; 1075 wv0 = m_worldTrans*triangle[0]; 1076 wv1 = m_worldTrans*triangle[1]; 1077 wv2 = m_worldTrans*triangle[2]; 1078 btVector3 center = (wv0+wv1+wv2)*btScalar(1./3.); 1079 1080 btVector3 normal = (wv1-wv0).cross(wv2-wv0); 1081 normal.normalize(); 1082 btVector3 normalColor(1,1,0); 1083 m_debugDrawer->drawLine(center,center+normal,normalColor); 1084 1085 1086 1087 1088 m_debugDrawer->drawLine(wv0,wv1,m_color); 1089 m_debugDrawer->drawLine(wv1,wv2,m_color); 1090 m_debugDrawer->drawLine(wv2,wv0,m_color); 1091 } 1092 }; 1093 1094 1095 void btCollisionWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color) 1096 { 1097 // Draw a small simplex at the center of the object 1098 getDebugDrawer()->drawTransform(worldTransform,1); 1099 1100 if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) 1101 { 1102 const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape); 1103 for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--) 1104 { 1105 btTransform childTrans = compoundShape->getChildTransform(i); 1106 const btCollisionShape* colShape = compoundShape->getChildShape(i); 1107 debugDrawObject(worldTransform*childTrans,colShape,color); 1108 } 1109 1110 } else 1111 { 1112 switch (shape->getShapeType()) 1113 { 1114 1115 case BOX_SHAPE_PROXYTYPE: 1116 { 1117 const btBoxShape* boxShape = static_cast<const btBoxShape*>(shape); 1118 btVector3 halfExtents = boxShape->getHalfExtentsWithMargin(); 1119 getDebugDrawer()->drawBox(-halfExtents,halfExtents,worldTransform,color); 1120 break; 1121 } 1122 1123 case SPHERE_SHAPE_PROXYTYPE: 1124 { 1125 const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape); 1126 btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin 1127 1128 getDebugDrawer()->drawSphere(radius, worldTransform, color); 1129 break; 1130 } 1131 case MULTI_SPHERE_SHAPE_PROXYTYPE: 1132 { 1133 const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape); 1134 1135 btTransform childTransform; 1136 childTransform.setIdentity(); 1137 1138 for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--) 1139 { 1140 childTransform.setOrigin(multiSphereShape->getSpherePosition(i)); 1141 getDebugDrawer()->drawSphere(multiSphereShape->getSphereRadius(i), worldTransform*childTransform, color); 1142 } 1143 1144 break; 1145 } 1146 case CAPSULE_SHAPE_PROXYTYPE: 1147 { 1148 const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape); 1149 1150 btScalar radius = capsuleShape->getRadius(); 1151 btScalar halfHeight = capsuleShape->getHalfHeight(); 1152 1153 int upAxis = capsuleShape->getUpAxis(); 1154 1155 1156 btVector3 capStart(0.f,0.f,0.f); 1157 capStart[upAxis] = -halfHeight; 1158 1159 btVector3 capEnd(0.f,0.f,0.f); 1160 capEnd[upAxis] = halfHeight; 1161 1162 // Draw the ends 1163 { 1164 1165 btTransform childTransform = worldTransform; 1166 childTransform.getOrigin() = worldTransform * capStart; 1167 getDebugDrawer()->drawSphere(radius, childTransform, color); 1168 } 1169 1170 { 1171 btTransform childTransform = worldTransform; 1172 childTransform.getOrigin() = worldTransform * capEnd; 1173 getDebugDrawer()->drawSphere(radius, childTransform, color); 1174 } 1175 1176 // Draw some additional lines 1177 btVector3 start = worldTransform.getOrigin(); 1178 1179 1180 capStart[(upAxis+1)%3] = radius; 1181 capEnd[(upAxis+1)%3] = radius; 1182 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1183 capStart[(upAxis+1)%3] = -radius; 1184 capEnd[(upAxis+1)%3] = -radius; 1185 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1186 1187 capStart[(upAxis+1)%3] = 0.f; 1188 capEnd[(upAxis+1)%3] = 0.f; 1189 1190 capStart[(upAxis+2)%3] = radius; 1191 capEnd[(upAxis+2)%3] = radius; 1192 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1193 capStart[(upAxis+2)%3] = -radius; 1194 capEnd[(upAxis+2)%3] = -radius; 1195 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color); 1196 1197 1198 break; 1199 } 1200 case CONE_SHAPE_PROXYTYPE: 1201 { 1202 const btConeShape* coneShape = static_cast<const btConeShape*>(shape); 1203 btScalar radius = coneShape->getRadius();//+coneShape->getMargin(); 1204 btScalar height = coneShape->getHeight();//+coneShape->getMargin(); 1205 btVector3 start = worldTransform.getOrigin(); 1206 1207 int upAxis= coneShape->getConeUpIndex(); 1208 1209 1210 btVector3 offsetHeight(0,0,0); 1211 offsetHeight[upAxis] = height * btScalar(0.5); 1212 btVector3 offsetRadius(0,0,0); 1213 offsetRadius[(upAxis+1)%3] = radius; 1214 btVector3 offset2Radius(0,0,0); 1215 offset2Radius[(upAxis+2)%3] = radius; 1216 1217 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color); 1218 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color); 1219 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color); 1220 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color); 1221 1222 // Drawing the base of the cone 1223 btVector3 yaxis(0,0,0); 1224 yaxis[upAxis] = btScalar(1.0); 1225 btVector3 xaxis(0,0,0); 1226 xaxis[(upAxis+1)%3] = btScalar(1.0); 1227 getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,10.0); 1228 break; 1229 1230 } 1231 case CYLINDER_SHAPE_PROXYTYPE: 1232 { 1233 const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape); 1234 int upAxis = cylinder->getUpAxis(); 1235 btScalar radius = cylinder->getRadius(); 1236 btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis]; 1237 btVector3 start = worldTransform.getOrigin(); 1238 btVector3 offsetHeight(0,0,0); 1239 offsetHeight[upAxis] = halfHeight; 1240 btVector3 offsetRadius(0,0,0); 1241 offsetRadius[(upAxis+1)%3] = radius; 1242 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color); 1243 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color); 1244 1245 // Drawing top and bottom caps of the cylinder 1246 btVector3 yaxis(0,0,0); 1247 yaxis[upAxis] = btScalar(1.0); 1248 btVector3 xaxis(0,0,0); 1249 xaxis[(upAxis+1)%3] = btScalar(1.0); 1250 getDebugDrawer()->drawArc(start-worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0)); 1251 getDebugDrawer()->drawArc(start+worldTransform.getBasis()*(offsetHeight),worldTransform.getBasis()*yaxis,worldTransform.getBasis()*xaxis,radius,radius,0,SIMD_2_PI,color,false,btScalar(10.0)); 1252 break; 1253 } 1254 1255 case STATIC_PLANE_PROXYTYPE: 1256 { 1257 const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape); 1258 btScalar planeConst = staticPlaneShape->getPlaneConstant(); 1259 const btVector3& planeNormal = staticPlaneShape->getPlaneNormal(); 1260 btVector3 planeOrigin = planeNormal * planeConst; 1261 btVector3 vec0,vec1; 1262 btPlaneSpace1(planeNormal,vec0,vec1); 1263 btScalar vecLen = 100.f; 1264 btVector3 pt0 = planeOrigin + vec0*vecLen; 1265 btVector3 pt1 = planeOrigin - vec0*vecLen; 1266 btVector3 pt2 = planeOrigin + vec1*vecLen; 1267 btVector3 pt3 = planeOrigin - vec1*vecLen; 1268 getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color); 1269 getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color); 1270 break; 1271 1272 } 1273 default: 1274 { 1275 1276 if (shape->isConcave()) 1277 { 1278 btConcaveShape* concaveMesh = (btConcaveShape*) shape; 1279 1280 ///@todo pass camera, for some culling? no -> we are not a graphics lib 1281 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 1282 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 1283 1284 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); 1285 concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax); 1286 1287 } 1288 1289 if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE) 1290 { 1291 btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape; 1292 //todo: pass camera for some culling 1293 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 1294 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 1295 //DebugDrawcallback drawCallback; 1296 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color); 1297 convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax); 1298 } 1299 1300 1301 /// for polyhedral shapes 1302 if (shape->isPolyhedral()) 1303 { 1304 btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape; 1305 1306 int i; 1307 for (i=0;i<polyshape->getNumEdges();i++) 1308 { 1309 btVector3 a,b; 1310 polyshape->getEdge(i,a,b); 1311 btVector3 wa = worldTransform * a; 1312 btVector3 wb = worldTransform * b; 1313 getDebugDrawer()->drawLine(wa,wb,color); 1314 1315 } 1316 1317 1318 } 1319 } 1320 } 1321 } 1322 } 1323 1324 1325 void btCollisionWorld::debugDrawWorld() 1326 { 1327 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) 1328 { 1329 int numManifolds = getDispatcher()->getNumManifolds(); 1330 btVector3 color(0,0,0); 1331 for (int i=0;i<numManifolds;i++) 1332 { 1333 btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i); 1334 //btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0()); 1335 //btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1()); 1336 1337 int numContacts = contactManifold->getNumContacts(); 1338 for (int j=0;j<numContacts;j++) 1339 { 1340 btManifoldPoint& cp = contactManifold->getContactPoint(j); 1341 getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color); 1342 } 1343 } 1344 } 1345 1346 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & (btIDebugDraw::DBG_DrawWireframe | btIDebugDraw::DBG_DrawAabb)) 1347 { 1348 int i; 1349 1350 for ( i=0;i<m_collisionObjects.size();i++) 1351 { 1352 btCollisionObject* colObj = m_collisionObjects[i]; 1353 if ((colObj->getCollisionFlags() & btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT)==0) 1354 { 1355 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe) 1356 { 1357 btVector3 color(btScalar(1.),btScalar(1.),btScalar(1.)); 1358 switch(colObj->getActivationState()) 1359 { 1360 case ACTIVE_TAG: 1361 color = btVector3(btScalar(1.),btScalar(1.),btScalar(1.)); break; 1362 case ISLAND_SLEEPING: 1363 color = btVector3(btScalar(0.),btScalar(1.),btScalar(0.));break; 1364 case WANTS_DEACTIVATION: 1365 color = btVector3(btScalar(0.),btScalar(1.),btScalar(1.));break; 1366 case DISABLE_DEACTIVATION: 1367 color = btVector3(btScalar(1.),btScalar(0.),btScalar(0.));break; 1368 case DISABLE_SIMULATION: 1369 color = btVector3(btScalar(1.),btScalar(1.),btScalar(0.));break; 1370 default: 1371 { 1372 color = btVector3(btScalar(1),btScalar(0.),btScalar(0.)); 1373 } 1374 }; 1375 1376 debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color); 1377 } 1378 if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb)) 1379 { 1380 btVector3 minAabb,maxAabb; 1381 btVector3 colorvec(1,0,0); 1382 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb); 1383 m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec); 1384 } 1385 } 1386 1387 } 1388 } 1389 } 1390 1391 1392 void btCollisionWorld::serializeCollisionObjects(btSerializer* serializer) 1393 { 1394 int i; 1395 //serialize all collision objects 1396 for (i=0;i<m_collisionObjects.size();i++) 1397 { 1398 btCollisionObject* colObj = m_collisionObjects[i]; 1399 if (colObj->getInternalType() == btCollisionObject::CO_COLLISION_OBJECT) 1400 { 1401 colObj->serializeSingleObject(serializer); 1402 } 1403 } 1404 1405 ///keep track of shapes already serialized 1406 btHashMap<btHashPtr,btCollisionShape*> serializedShapes; 1407 1408 for (i=0;i<m_collisionObjects.size();i++) 1409 { 1410 btCollisionObject* colObj = m_collisionObjects[i]; 1411 btCollisionShape* shape = colObj->getCollisionShape(); 1412 1413 if (!serializedShapes.find(shape)) 1414 { 1415 serializedShapes.insert(shape,shape); 1416 shape->serializeSingleShape(serializer); 1417 } 1418 } 1419 1420 } 1421 1422 1423 void btCollisionWorld::serialize(btSerializer* serializer) 1424 { 1425 1426 serializer->startSerialization(); 1427 1428 serializeCollisionObjects(serializer); 1429 1430 serializer->finishSerialization(); 1431 } 1432 -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCollisionWorld.h
r5781 r8351 23 23 * Bullet is a Collision Detection and Rigid Body Dynamics Library. The Library is Open Source and free for commercial use, under the ZLib license ( http://opensource.org/licenses/zlib-license.php ). 24 24 * 25 * The main documentation is Bullet_User_Manual.pdf, included in the source code distribution. 25 26 * There is the Physics Forum for feedback and general Collision Detection and Physics discussions. 26 27 * Please visit http://www.bulletphysics.com … … 30 31 * @subsection step1 Step 1: Download 31 32 * You can download the Bullet Physics Library from the Google Code repository: http://code.google.com/p/bullet/downloads/list 33 * 32 34 * @subsection step2 Step 2: Building 33 * Bullet comes with autogenerated Project Files for Microsoft Visual Studio 6, 7, 7.1 and 8. 34 * The main Workspace/Solution is located in Bullet/msvc/8/wksbullet.sln (replace 8 with your version). 35 * 36 * Under other platforms, like Linux or Mac OS-X, Bullet can be build using either using make, cmake, http://www.cmake.org , or jam, http://www.perforce.com/jam/jam.html . cmake can autogenerate Xcode, KDevelop, MSVC and other build systems. just run cmake . in the root of Bullet. 37 * So if you are not using MSVC or cmake, you can run ./autogen.sh ./configure to create both Makefile and Jamfile and then run make or jam. 38 * Jam is a build system that can build the library, demos and also autogenerate the MSVC Project Files. 39 * If you don't have jam installed, you can make jam from the included jam-2.5 sources, or download jam from ftp://ftp.perforce.com/jam 35 * Bullet main build system for all platforms is cmake, you can download http://www.cmake.org 36 * cmake can autogenerate projectfiles for Microsoft Visual Studio, Apple Xcode, KDevelop and Unix Makefiles. 37 * The easiest is to run the CMake cmake-gui graphical user interface and choose the options and generate projectfiles. 38 * You can also use cmake in the command-line. Here are some examples for various platforms: 39 * cmake . -G "Visual Studio 9 2008" 40 * cmake . -G Xcode 41 * cmake . -G "Unix Makefiles" 42 * Although cmake is recommended, you can also use autotools for UNIX: ./autogen.sh ./configure to create a Makefile and then run make. 40 43 * 41 44 * @subsection step3 Step 3: Testing demos … … 54 57 * 55 58 * @section copyright Copyright 56 * Copyright (C) 2005-2008 Erwin Coumans, some contributions Copyright Gino van den Bergen, Christer Ericson, Simon Hobbs, Ricardo Padrela, F Richter(res), Stephane Redon 57 * Special thanks to all visitors of the Bullet Physics forum, and in particular above contributors, John McCutchan, Nathanael Presson, Dave Eberle, Dirk Gregorius, Erin Catto, Dave Eberle, Adam Moravanszky, 58 * Pierre Terdiman, Kenny Erleben, Russell Smith, Oliver Strunk, Jan Paul van Waveren, Marten Svanfeldt. 59 * For up-to-data information and copyright and contributors list check out the Bullet_User_Manual.pdf 59 60 * 60 61 */ 61 62 63 62 64 63 … … 71 70 class btConvexShape; 72 71 class btBroadphaseInterface; 72 class btSerializer; 73 73 74 #include "LinearMath/btVector3.h" 74 75 #include "LinearMath/btTransform.h" … … 82 83 { 83 84 84 85 85 86 86 protected: 87 87 88 88 btAlignedObjectArray<btCollisionObject*> m_collisionObjects; 89 90 89 91 90 btDispatcher* m_dispatcher1; … … 99 98 btIDebugDraw* m_debugDrawer; 100 99 101 102 100 ///m_forceUpdateAllAabbs can be set to false as an optimization to only update active object AABBs 101 ///it is true by default, because it is error-prone (setting the position of static objects wouldn't update their AABB) 102 bool m_forceUpdateAllAabbs; 103 104 void serializeCollisionObjects(btSerializer* serializer); 105 103 106 public: 104 107 … … 142 145 143 146 virtual void updateAabbs(); 144 145 147 146 148 virtual void setDebugDrawer(btIDebugDraw* debugDrawer) … … 153 155 return m_debugDrawer; 154 156 } 157 158 virtual void debugDrawWorld(); 159 160 virtual void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color); 155 161 156 162 … … 161 167 int m_shapePart; 162 168 int m_triangleIndex; 163 164 169 165 170 //const btCollisionShape* m_shapeTemp; … … 239 244 btVector3 m_hitNormalWorld; 240 245 btVector3 m_hitPointWorld; 241 242 246 243 247 virtual btScalar addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) … … 245 249 //caller already does the filter on the m_closestHitFraction 246 250 btAssert(rayResult.m_hitFraction <= m_closestHitFraction); 247 248 251 249 252 m_closestHitFraction = rayResult.m_hitFraction; … … 262 265 }; 263 266 267 struct AllHitsRayResultCallback : public RayResultCallback 268 { 269 AllHitsRayResultCallback(const btVector3& rayFromWorld,const btVector3& rayToWorld) 270 :m_rayFromWorld(rayFromWorld), 271 m_rayToWorld(rayToWorld) 272 { 273 } 274 275 btAlignedObjectArray<btCollisionObject*> m_collisionObjects; 276 277 btVector3 m_rayFromWorld;//used to calculate hitPointWorld from hitFraction 278 btVector3 m_rayToWorld; 279 280 btAlignedObjectArray<btVector3> m_hitNormalWorld; 281 btAlignedObjectArray<btVector3> m_hitPointWorld; 282 btAlignedObjectArray<btScalar> m_hitFractions; 283 284 virtual btScalar addSingleResult(LocalRayResult& rayResult,bool normalInWorldSpace) 285 { 286 m_collisionObject = rayResult.m_collisionObject; 287 m_collisionObjects.push_back(rayResult.m_collisionObject); 288 btVector3 hitNormalWorld; 289 if (normalInWorldSpace) 290 { 291 hitNormalWorld = rayResult.m_hitNormalLocal; 292 } else 293 { 294 ///need to transform normal into worldspace 295 hitNormalWorld = m_collisionObject->getWorldTransform().getBasis()*rayResult.m_hitNormalLocal; 296 } 297 m_hitNormalWorld.push_back(hitNormalWorld); 298 btVector3 hitPointWorld; 299 hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction); 300 m_hitPointWorld.push_back(hitPointWorld); 301 m_hitFractions.push_back(rayResult.m_hitFraction); 302 return m_closestHitFraction; 303 } 304 }; 305 264 306 265 307 struct LocalConvexResult … … 292 334 short int m_collisionFilterGroup; 293 335 short int m_collisionFilterMask; 294 295 336 296 337 ConvexResultCallback() … … 304 345 { 305 346 } 306 307 347 308 348 bool hasHit() const … … 310 350 return (m_closestHitFraction < btScalar(1.)); 311 351 } 312 313 352 314 353 … … 339 378 btVector3 m_hitPointWorld; 340 379 btCollisionObject* m_hitCollisionObject; 341 342 380 343 381 virtual btScalar addSingleResult(LocalConvexResult& convexResult,bool normalInWorldSpace) … … 345 383 //caller already does the filter on the m_closestHitFraction 346 384 btAssert(convexResult.m_hitFraction <= m_closestHitFraction); 347 348 385 349 386 m_closestHitFraction = convexResult.m_hitFraction; … … 362 399 }; 363 400 401 ///ContactResultCallback is used to report contact points 402 struct ContactResultCallback 403 { 404 short int m_collisionFilterGroup; 405 short int m_collisionFilterMask; 406 407 ContactResultCallback() 408 :m_collisionFilterGroup(btBroadphaseProxy::DefaultFilter), 409 m_collisionFilterMask(btBroadphaseProxy::AllFilter) 410 { 411 } 412 413 virtual ~ContactResultCallback() 414 { 415 } 416 417 virtual bool needsCollision(btBroadphaseProxy* proxy0) const 418 { 419 bool collides = (proxy0->m_collisionFilterGroup & m_collisionFilterMask) != 0; 420 collides = collides && (m_collisionFilterGroup & proxy0->m_collisionFilterMask); 421 return collides; 422 } 423 424 virtual btScalar addSingleResult(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1) = 0; 425 }; 426 427 428 364 429 int getNumCollisionObjects() const 365 430 { … … 369 434 /// rayTest performs a raycast on all objects in the btCollisionWorld, and calls the resultCallback 370 435 /// This allows for several queries: first hit, all hits, any hit, dependent on the value returned by the callback. 371 v oidrayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const;372 373 // convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback374 // This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback.436 virtual void rayTest(const btVector3& rayFromWorld, const btVector3& rayToWorld, RayResultCallback& resultCallback) const; 437 438 /// convexTest performs a swept convex cast on all objects in the btCollisionWorld, and calls the resultCallback 439 /// This allows for several queries: first hit, all hits, any hit, dependent on the value return by the callback. 375 440 void convexSweepTest (const btConvexShape* castShape, const btTransform& from, const btTransform& to, ConvexResultCallback& resultCallback, btScalar allowedCcdPenetration = btScalar(0.)) const; 441 442 ///contactTest performs a discrete collision test between colObj against all objects in the btCollisionWorld, and calls the resultCallback. 443 ///it reports one or more contact points for every overlapping object (including the one with deepest penetration) 444 void contactTest(btCollisionObject* colObj, ContactResultCallback& resultCallback); 445 446 ///contactTest performs a discrete collision test between two collision objects and calls the resultCallback if overlap if detected. 447 ///it reports one or more contact points (including the one with deepest penetration) 448 void contactPairTest(btCollisionObject* colObjA, btCollisionObject* colObjB, ContactResultCallback& resultCallback); 376 449 377 450 … … 392 465 ConvexResultCallback& resultCallback, btScalar allowedPenetration); 393 466 394 v oid addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter);467 virtual void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::DefaultFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter); 395 468 396 469 btCollisionObjectArray& getCollisionObjectArray() … … 405 478 406 479 407 v oid removeCollisionObject(btCollisionObject* collisionObject);480 virtual void removeCollisionObject(btCollisionObject* collisionObject); 408 481 409 482 virtual void performDiscreteCollisionDetection(); … … 418 491 return m_dispatchInfo; 419 492 } 493 494 bool getForceUpdateAllAabbs() const 495 { 496 return m_forceUpdateAllAabbs; 497 } 498 void setForceUpdateAllAabbs( bool forceUpdateAllAabbs) 499 { 500 m_forceUpdateAllAabbs = forceUpdateAllAabbs; 501 } 502 503 ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (Bullet/Demos/SerializeDemo) 504 virtual void serialize(btSerializer* serializer); 420 505 421 506 }; -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp
r5781 r8351 115 115 void ProcessChildShape(btCollisionShape* childShape,int index) 116 116 { 117 117 btAssert(index>=0); 118 118 btCompoundShape* compoundShape = static_cast<btCompoundShape*>(m_compoundColObj->getCollisionShape()); 119 btAssert(index<compoundShape->getNumChildShapes()); 119 120 120 121 … … 142 143 if (!m_childCollisionAlgorithms[index]) 143 144 m_childCollisionAlgorithms[index] = m_dispatcher->findAlgorithm(m_compoundColObj,m_otherObj,m_sharedManifold); 145 146 ///detect swapping case 147 if (m_resultOut->getBody0Internal() == m_compoundColObj) 148 { 149 m_resultOut->setShapeIdentifiersA(-1,index); 150 } else 151 { 152 m_resultOut->setShapeIdentifiersB(-1,index); 153 } 144 154 145 155 m_childCollisionAlgorithms[index]->processCollision(m_compoundColObj,m_otherObj,m_dispatchInfo,m_resultOut); … … 258 268 int i; 259 269 btManifoldArray manifoldArray; 260 270 btCollisionShape* childShape = 0; 271 btTransform orgTrans; 272 btTransform orgInterpolationTrans; 273 btTransform newChildWorldTrans; 274 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1; 275 261 276 for (i=0;i<numChildren;i++) 262 277 { 263 278 if (m_childCollisionAlgorithms[i]) 264 279 { 265 btCollisionShape*childShape = compoundShape->getChildShape(i);280 childShape = compoundShape->getChildShape(i); 266 281 //if not longer overlapping, remove the algorithm 267 btTransformorgTrans = colObj->getWorldTransform();268 btTransformorgInterpolationTrans = colObj->getInterpolationWorldTransform();282 orgTrans = colObj->getWorldTransform(); 283 orgInterpolationTrans = colObj->getInterpolationWorldTransform(); 269 284 const btTransform& childTrans = compoundShape->getChildTransform(i); 270 btTransformnewChildWorldTrans = orgTrans*childTrans ;285 newChildWorldTrans = orgTrans*childTrans ; 271 286 272 287 //perform an AABB check first 273 btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;274 288 childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0); 275 289 otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1); … … 281 295 m_childCollisionAlgorithms[i] = 0; 282 296 } 283 284 297 } 285 286 } 287 288 289 298 } 290 299 } 291 300 } … … 312 321 int numChildren = m_childCollisionAlgorithms.size(); 313 322 int i; 323 btTransform orgTrans; 324 btScalar frac; 314 325 for (i=0;i<numChildren;i++) 315 326 { … … 318 329 319 330 //backup 320 btTransformorgTrans = colObj->getWorldTransform();331 orgTrans = colObj->getWorldTransform(); 321 332 322 333 const btTransform& childTrans = compoundShape->getChildTransform(i); … … 326 337 btCollisionShape* tmpShape = colObj->getCollisionShape(); 327 338 colObj->internalSetTemporaryCollisionShape( childShape ); 328 btScalarfrac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut);339 frac = m_childCollisionAlgorithms[i]->calculateTimeOfImpact(colObj,otherObj,dispatchInfo,resultOut); 329 340 if (frac<hitFraction) 330 341 { -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConcaveCollisionAlgorithm.cpp
r5781 r8351 96 96 if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe )) 97 97 { 98 btVector3 color( 255,255,0);98 btVector3 color(1,1,0); 99 99 btTransform& tr = ob->getWorldTransform(); 100 100 m_dispatchInfoPtr->m_debugDraw->drawLine(tr(triangle[0]),tr(triangle[1]),color); … … 122 122 123 123 btCollisionAlgorithm* colAlgo = ci.m_dispatcher1->findAlgorithm(m_convexBody,m_triBody,m_manifoldPtr); 124 ///this should use the btDispatcher, so the actual registered algorithm is used 125 // btConvexConvexAlgorithm cvxcvxalgo(m_manifoldPtr,ci,m_convexBody,m_triBody); 126 127 m_resultOut->setShapeIdentifiers(-1,-1,partId,triangleIndex); 128 // cvxcvxalgo.setShapeIdentifiers(-1,-1,partId,triangleIndex); 129 // cvxcvxalgo.processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); 124 125 if (m_resultOut->getBody0Internal() == m_triBody) 126 { 127 m_resultOut->setShapeIdentifiersA(partId,triangleIndex); 128 } 129 else 130 { 131 m_resultOut->setShapeIdentifiersB(partId,triangleIndex); 132 } 133 130 134 colAlgo->processCollision(m_convexBody,m_triBody,*m_dispatchInfoPtr,m_resultOut); 131 135 colAlgo->~btCollisionAlgorithm(); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.cpp
r5781 r8351 14 14 */ 15 15 16 ///Specialized capsule-capsule collision algorithm has been added for Bullet 2.75 release to increase ragdoll performance 17 ///If you experience problems with capsule-capsule collision, try to define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER and report it in the Bullet forums 18 ///with reproduction case 19 //define BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 1 20 16 21 #include "btConvexConvexAlgorithm.h" 17 22 … … 21 26 #include "BulletCollision/CollisionDispatch/btCollisionObject.h" 22 27 #include "BulletCollision/CollisionShapes/btConvexShape.h" 28 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 29 30 23 31 #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" 24 32 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" … … 44 52 45 53 46 54 /////////// 55 56 57 58 static SIMD_FORCE_INLINE void segmentsClosestPoints( 59 btVector3& ptsVector, 60 btVector3& offsetA, 61 btVector3& offsetB, 62 btScalar& tA, btScalar& tB, 63 const btVector3& translation, 64 const btVector3& dirA, btScalar hlenA, 65 const btVector3& dirB, btScalar hlenB ) 66 { 67 // compute the parameters of the closest points on each line segment 68 69 btScalar dirA_dot_dirB = btDot(dirA,dirB); 70 btScalar dirA_dot_trans = btDot(dirA,translation); 71 btScalar dirB_dot_trans = btDot(dirB,translation); 72 73 btScalar denom = 1.0f - dirA_dot_dirB * dirA_dot_dirB; 74 75 if ( denom == 0.0f ) { 76 tA = 0.0f; 77 } else { 78 tA = ( dirA_dot_trans - dirB_dot_trans * dirA_dot_dirB ) / denom; 79 if ( tA < -hlenA ) 80 tA = -hlenA; 81 else if ( tA > hlenA ) 82 tA = hlenA; 83 } 84 85 tB = tA * dirA_dot_dirB - dirB_dot_trans; 86 87 if ( tB < -hlenB ) { 88 tB = -hlenB; 89 tA = tB * dirA_dot_dirB + dirA_dot_trans; 90 91 if ( tA < -hlenA ) 92 tA = -hlenA; 93 else if ( tA > hlenA ) 94 tA = hlenA; 95 } else if ( tB > hlenB ) { 96 tB = hlenB; 97 tA = tB * dirA_dot_dirB + dirA_dot_trans; 98 99 if ( tA < -hlenA ) 100 tA = -hlenA; 101 else if ( tA > hlenA ) 102 tA = hlenA; 103 } 104 105 // compute the closest points relative to segment centers. 106 107 offsetA = dirA * tA; 108 offsetB = dirB * tB; 109 110 ptsVector = translation - offsetA + offsetB; 111 } 112 113 114 static SIMD_FORCE_INLINE btScalar capsuleCapsuleDistance( 115 btVector3& normalOnB, 116 btVector3& pointOnB, 117 btScalar capsuleLengthA, 118 btScalar capsuleRadiusA, 119 btScalar capsuleLengthB, 120 btScalar capsuleRadiusB, 121 int capsuleAxisA, 122 int capsuleAxisB, 123 const btTransform& transformA, 124 const btTransform& transformB, 125 btScalar distanceThreshold ) 126 { 127 btVector3 directionA = transformA.getBasis().getColumn(capsuleAxisA); 128 btVector3 translationA = transformA.getOrigin(); 129 btVector3 directionB = transformB.getBasis().getColumn(capsuleAxisB); 130 btVector3 translationB = transformB.getOrigin(); 131 132 // translation between centers 133 134 btVector3 translation = translationB - translationA; 135 136 // compute the closest points of the capsule line segments 137 138 btVector3 ptsVector; // the vector between the closest points 139 140 btVector3 offsetA, offsetB; // offsets from segment centers to their closest points 141 btScalar tA, tB; // parameters on line segment 142 143 segmentsClosestPoints( ptsVector, offsetA, offsetB, tA, tB, translation, 144 directionA, capsuleLengthA, directionB, capsuleLengthB ); 145 146 btScalar distance = ptsVector.length() - capsuleRadiusA - capsuleRadiusB; 147 148 if ( distance > distanceThreshold ) 149 return distance; 150 151 btScalar lenSqr = ptsVector.length2(); 152 if (lenSqr<= (SIMD_EPSILON*SIMD_EPSILON)) 153 { 154 //degenerate case where 2 capsules are likely at the same location: take a vector tangential to 'directionA' 155 btVector3 q; 156 btPlaneSpace1(directionA,normalOnB,q); 157 } else 158 { 159 // compute the contact normal 160 normalOnB = ptsVector*-btRecipSqrt(lenSqr); 161 } 162 pointOnB = transformB.getOrigin()+offsetB + normalOnB * capsuleRadiusB; 163 164 return distance; 165 } 166 167 168 169 170 171 172 173 ////////// 47 174 48 175 … … 70 197 m_lowLevelOfDetail(false), 71 198 #ifdef USE_SEPDISTANCE_UTIL2 72 ,m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(),199 m_sepDistance((static_cast<btConvexShape*>(body0->getCollisionShape()))->getAngularMotionDisc(), 73 200 (static_cast<btConvexShape*>(body1->getCollisionShape()))->getAngularMotionDisc()), 74 201 #endif … … 112 239 m_transformA(transformA), 113 240 m_transformB(transformB), 241 m_unPerturbedTransform(unPerturbedTransform), 114 242 m_perturbA(perturbA), 115 m_unPerturbedTransform(unPerturbedTransform),116 243 m_debugDrawer(debugDrawer) 117 244 { … … 156 283 extern btScalar gContactBreakingThreshold; 157 284 285 158 286 // 159 287 // Convex-Convex collision algorithm … … 177 305 btConvexShape* min1 = static_cast<btConvexShape*>(body1->getCollisionShape()); 178 306 307 btVector3 normalOnB; 308 btVector3 pointOnBWorld; 309 #ifndef BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 310 if ((min0->getShapeType() == CAPSULE_SHAPE_PROXYTYPE) && (min1->getShapeType() == CAPSULE_SHAPE_PROXYTYPE)) 311 { 312 btCapsuleShape* capsuleA = (btCapsuleShape*) min0; 313 btCapsuleShape* capsuleB = (btCapsuleShape*) min1; 314 btVector3 localScalingA = capsuleA->getLocalScaling(); 315 btVector3 localScalingB = capsuleB->getLocalScaling(); 316 317 btScalar threshold = m_manifoldPtr->getContactBreakingThreshold(); 318 319 btScalar dist = capsuleCapsuleDistance(normalOnB, pointOnBWorld,capsuleA->getHalfHeight(),capsuleA->getRadius(), 320 capsuleB->getHalfHeight(),capsuleB->getRadius(),capsuleA->getUpAxis(),capsuleB->getUpAxis(), 321 body0->getWorldTransform(),body1->getWorldTransform(),threshold); 322 323 if (dist<threshold) 324 { 325 btAssert(normalOnB.length2()>=(SIMD_EPSILON*SIMD_EPSILON)); 326 resultOut->addContactPoint(normalOnB,pointOnBWorld,dist); 327 } 328 resultOut->refreshContactPoints(); 329 return; 330 } 331 #endif //BT_DISABLE_CAPSULE_CAPSULE_COLLIDER 332 333 179 334 #ifdef USE_SEPDISTANCE_UTIL2 180 m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); 335 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 336 { 337 m_sepDistance.updateSeparatingDistance(body0->getWorldTransform(),body1->getWorldTransform()); 338 } 339 181 340 if (!dispatchInfo.m_useConvexConservativeDistanceUtil || m_sepDistance.getConservativeSeparatingDistance()<=0.f) 182 341 #endif //USE_SEPDISTANCE_UTIL2 … … 195 354 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 196 355 { 197 input.m_maximumDistanceSquared = 1e30f;356 input.m_maximumDistanceSquared = BT_LARGE_FLOAT; 198 357 } else 199 358 #endif //USE_SEPDISTANCE_UTIL2 200 359 { 201 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); 360 if (dispatchInfo.m_convexMaxDistanceUseCPT) 361 { 362 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactProcessingThreshold(); 363 } else 364 { 365 input.m_maximumDistanceSquared = min0->getMargin() + min1->getMargin() + m_manifoldPtr->getContactBreakingThreshold(); 366 } 202 367 input.m_maximumDistanceSquared*= input.m_maximumDistanceSquared; 203 368 } … … 208 373 209 374 gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw); 210 btScalar sepDist = gjkPairDetector.getCachedSeparatingDistance()+dispatchInfo.m_convexConservativeDistanceThreshold; 211 212 //now perturbe directions to get multiple contact points 213 btVector3 v0,v1; 214 btVector3 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 215 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 375 376 377 378 #ifdef USE_SEPDISTANCE_UTIL2 379 btScalar sepDist = 0.f; 380 if (dispatchInfo.m_useConvexConservativeDistanceUtil) 381 { 382 sepDist = gjkPairDetector.getCachedSeparatingDistance(); 383 if (sepDist>SIMD_EPSILON) 384 { 385 sepDist += dispatchInfo.m_convexConservativeDistanceThreshold; 386 //now perturbe directions to get multiple contact points 387 388 } 389 } 390 #endif //USE_SEPDISTANCE_UTIL2 391 216 392 //now perform 'm_numPerturbationIterations' collision queries with the perturbated collision objects 217 393 218 394 //perform perturbation when more then 'm_minimumPointsPerturbationThreshold' points 219 if ( resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold)395 if (m_numPerturbationIterations && resultOut->getPersistentManifold()->getNumContacts() < m_minimumPointsPerturbationThreshold) 220 396 { 221 397 222 398 int i; 399 btVector3 v0,v1; 400 btVector3 sepNormalWorldSpace; 401 402 sepNormalWorldSpace = gjkPairDetector.getCachedSeparatingAxis().normalized(); 403 btPlaneSpace1(sepNormalWorldSpace,v0,v1); 404 223 405 224 406 bool perturbeA = true; … … 250 432 for ( i=0;i<m_numPerturbationIterations;i++) 251 433 { 434 if (v0.length2()>SIMD_EPSILON) 435 { 252 436 btQuaternion perturbeRot(v0,perturbeAngle); 253 437 btScalar iterationAngle = i*(SIMD_2_PI/btScalar(m_numPerturbationIterations)); … … 273 457 btPerturbedContactResult perturbedResultOut(resultOut,input.m_transformA,input.m_transformB,unPerturbedTransform,perturbeA,dispatchInfo.m_debugDraw); 274 458 gjkPairDetector.getClosestPoints(input,perturbedResultOut,dispatchInfo.m_debugDraw); 459 } 275 460 276 277 461 } 278 462 } … … 281 465 282 466 #ifdef USE_SEPDISTANCE_UTIL2 283 if (dispatchInfo.m_useConvexConservativeDistanceUtil )467 if (dispatchInfo.m_useConvexConservativeDistanceUtil && (sepDist>SIMD_EPSILON)) 284 468 { 285 469 m_sepDistance.initSeparatingDistance(gjkPairDetector.getCachedSeparatingAxis(),sepDist,body0->getWorldTransform(),body1->getWorldTransform()); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexConvexAlgorithm.h
r5781 r8351 32 32 ///Either improve GJK for large size ratios (testing a 100 units versus a 0.1 unit object) or only enable the util 33 33 ///for certain pairs that have a small size ratio 34 ///#define USE_SEPDISTANCE_UTIL2 1 34 35 //#define USE_SEPDISTANCE_UTIL2 1 35 36 36 37 ///The convexConvexAlgorithm collision algorithm implements time of impact, convex closest points and penetration depth calculations between two convex objects. -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.cpp
r5781 r8351 103 103 btStaticPlaneShape* planeShape = (btStaticPlaneShape*) planeObj->getCollisionShape(); 104 104 105 bool hasCollision = false;105 106 106 const btVector3& planeNormal = planeShape->getPlaneNormal(); 107 const btScalar& planeConstant = planeShape->getPlaneConstant();107 //const btScalar& planeConstant = planeShape->getPlaneConstant(); 108 108 109 109 //first perform a collision query with the non-perturbated collision objects -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btConvexPlaneCollisionAlgorithm.h
r5781 r8351 61 61 62 62 CreateFunc() 63 : m_numPerturbationIterations( 3),64 m_minimumPointsPerturbationThreshold( 3)63 : m_numPerturbationIterations(1), 64 m_minimumPointsPerturbationThreshold(1) 65 65 { 66 66 } -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.cpp
r5781 r8351 46 46 void* mem = btAlignedAlloc(sizeof(btVoronoiSimplexSolver),16); 47 47 m_simplexSolver = new (mem)btVoronoiSimplexSolver(); 48 49 #define USE_EPA 1 50 #ifdef USE_EPA 51 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16);52 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver;53 #else54 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16);55 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver;56 #endif//USE_EPA 57 58 48 49 if (constructionInfo.m_useEpaPenetrationAlgorithm) 50 { 51 mem = btAlignedAlloc(sizeof(btGjkEpaPenetrationDepthSolver),16); 52 m_pdSolver = new (mem)btGjkEpaPenetrationDepthSolver; 53 }else 54 { 55 mem = btAlignedAlloc(sizeof(btMinkowskiPenetrationDepthSolver),16); 56 m_pdSolver = new (mem)btMinkowskiPenetrationDepthSolver; 57 } 58 59 59 //default CreationFunctions, filling the m_doubleDispatch table 60 60 mem = btAlignedAlloc(sizeof(btConvexConvexAlgorithm::CreateFunc),16); … … 103 103 int sl = sizeof(btConvexSeparatingDistanceUtil); 104 104 sl = sizeof(btGjkPairDetector); 105 int collisionAlgorithmMaxElementSize = btMax(maxSize,maxSize2); 105 int collisionAlgorithmMaxElementSize = btMax(maxSize,constructionInfo.m_customCollisionAlgorithmMaxElementSize); 106 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize2); 106 107 collisionAlgorithmMaxElementSize = btMax(collisionAlgorithmMaxElementSize,maxSize3); 107 108 -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h
r5781 r8351 28 28 int m_defaultMaxPersistentManifoldPoolSize; 29 29 int m_defaultMaxCollisionAlgorithmPoolSize; 30 int m_customCollisionAlgorithmMaxElementSize; 30 31 int m_defaultStackAllocatorSize; 32 int m_useEpaPenetrationAlgorithm; 31 33 32 34 btDefaultCollisionConstructionInfo() … … 36 38 m_defaultMaxPersistentManifoldPoolSize(4096), 37 39 m_defaultMaxCollisionAlgorithmPoolSize(4096), 38 m_defaultStackAllocatorSize(0) 40 m_customCollisionAlgorithmMaxElementSize(0), 41 m_defaultStackAllocatorSize(0), 42 m_useEpaPenetrationAlgorithm(true) 39 43 { 40 44 } … … 109 113 } 110 114 115 virtual btVoronoiSimplexSolver* getSimplexSolver() 116 { 117 return m_simplexSolver; 118 } 119 111 120 112 121 virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btGhostObject.h
r5781 r8351 161 161 } 162 162 163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* proxy0,btDispatcher* dispatcher)163 virtual void removeOverlappingPairsContainingProxy(btBroadphaseProxy* /*proxy0*/,btDispatcher* /*dispatcher*/) 164 164 { 165 165 btAssert(0); … … 173 173 174 174 #endif 175 -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.cpp
r5781 r8351 48 48 m_body0(body0), 49 49 m_body1(body1) 50 #ifdef DEBUG_PART_INDEX 51 ,m_partId0(-1), 52 m_partId1(-1), 53 m_index0(-1), 54 m_index1(-1) 55 #endif //DEBUG_PART_INDEX 50 56 { 51 57 m_rootTransA = body0->getWorldTransform(); … … 89 95 90 96 //BP mod, store contact triangles. 91 newPt.m_partId0 = m_partId0; 92 newPt.m_partId1 = m_partId1; 93 newPt.m_index0 = m_index0; 94 newPt.m_index1 = m_index1; 97 if (isSwapped) 98 { 99 newPt.m_partId0 = m_partId1; 100 newPt.m_partId1 = m_partId0; 101 newPt.m_index0 = m_index1; 102 newPt.m_index1 = m_index0; 103 } else 104 { 105 newPt.m_partId0 = m_partId0; 106 newPt.m_partId1 = m_partId1; 107 newPt.m_index0 = m_index0; 108 newPt.m_index1 = m_index1; 109 } 95 110 //printf("depth=%f\n",depth); 96 111 ///@todo, check this for any side effects … … 113 128 btCollisionObject* obj0 = isSwapped? m_body1 : m_body0; 114 129 btCollisionObject* obj1 = isSwapped? m_body0 : m_body1; 115 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0, m_partId0,m_index0,obj1,m_partId1,m_index1);130 (*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0,newPt.m_partId0,newPt.m_index0,obj1,newPt.m_partId1,newPt.m_index1); 116 131 } 117 132 -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btManifoldResult.h
r5781 r8351 29 29 extern ContactAddedCallback gContactAddedCallback; 30 30 31 //#define DEBUG_PART_INDEX 1 31 32 32 33 … … 34 35 class btManifoldResult : public btDiscreteCollisionDetectorInterface::Result 35 36 { 37 protected: 38 36 39 btPersistentManifold* m_manifoldPtr; 37 40 … … 51 54 52 55 btManifoldResult() 56 #ifdef DEBUG_PART_INDEX 57 : 58 m_partId0(-1), 59 m_partId1(-1), 60 m_index0(-1), 61 m_index1(-1) 62 #endif //DEBUG_PART_INDEX 53 63 { 54 64 } … … 72 82 } 73 83 74 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)84 virtual void setShapeIdentifiersA(int partId0,int index0) 75 85 { 76 m_partId0=partId0; 77 m_partId1=partId1; 78 m_index0=index0; 79 m_index1=index1; 86 m_partId0=partId0; 87 m_index0=index0; 88 } 89 90 virtual void setShapeIdentifiersB( int partId1,int index1) 91 { 92 m_partId1=partId1; 93 m_index1=index1; 80 94 } 81 95 … … 100 114 } 101 115 116 const btCollisionObject* getBody0Internal() const 117 { 118 return m_body0; 119 } 102 120 121 const btCollisionObject* getBody1Internal() const 122 { 123 return m_body1; 124 } 125 103 126 }; 104 127 -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSimulationIslandManager.cpp
r5781 r8351 1 1 2 /* 2 3 Bullet Continuous Collision Detection and Physics Library … … 45 46 46 47 { 48 btOverlappingPairCache* pairCachePtr = colWorld->getPairCache(); 49 const int numOverlappingPairs = pairCachePtr->getNumOverlappingPairs(); 50 btBroadphasePair* pairPtr = pairCachePtr->getOverlappingPairArrayPtr(); 47 51 48 for (int i=0;i<colWorld->getPairCache()->getNumOverlappingPairs();i++) 49 { 50 btBroadphasePair* pairPtr = colWorld->getPairCache()->getOverlappingPairArrayPtr(); 52 for (int i=0;i<numOverlappingPairs;i++) 53 { 51 54 const btBroadphasePair& collisionPair = pairPtr[i]; 52 55 btCollisionObject* colObj0 = (btCollisionObject*)collisionPair.m_pProxy0->m_clientObject; … … 64 67 } 65 68 66 69 #ifdef STATIC_SIMULATION_ISLAND_OPTIMIZATION 70 void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher) 71 { 72 73 // put the index into m_controllers into m_tag 74 int index = 0; 75 { 76 77 int i; 78 for (i=0;i<colWorld->getCollisionObjectArray().size(); i++) 79 { 80 btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i]; 81 //Adding filtering here 82 if (!collisionObject->isStaticOrKinematicObject()) 83 { 84 collisionObject->setIslandTag(index++); 85 } 86 collisionObject->setCompanionId(-1); 87 collisionObject->setHitFraction(btScalar(1.)); 88 } 89 } 90 // do the union find 91 92 initUnionFind( index ); 93 94 findUnions(dispatcher,colWorld); 95 } 96 97 void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld) 98 { 99 // put the islandId ('find' value) into m_tag 100 { 101 int index = 0; 102 int i; 103 for (i=0;i<colWorld->getCollisionObjectArray().size();i++) 104 { 105 btCollisionObject* collisionObject= colWorld->getCollisionObjectArray()[i]; 106 if (!collisionObject->isStaticOrKinematicObject()) 107 { 108 collisionObject->setIslandTag( m_unionFind.find(index) ); 109 //Set the correct object offset in Collision Object Array 110 m_unionFind.getElement(index).m_sz = i; 111 collisionObject->setCompanionId(-1); 112 index++; 113 } else 114 { 115 collisionObject->setIslandTag(-1); 116 collisionObject->setCompanionId(-2); 117 } 118 } 119 } 120 } 121 122 123 #else //STATIC_SIMULATION_ISLAND_OPTIMIZATION 67 124 void btSimulationIslandManager::updateActivationState(btCollisionWorld* colWorld,btDispatcher* dispatcher) 68 125 { 69 126 70 127 initUnionFind( int (colWorld->getCollisionObjectArray().size())); 71 128 72 129 // put the index into m_controllers into m_tag 73 130 { 74 131 75 132 int index = 0; 76 133 int i; … … 82 139 collisionObject->setHitFraction(btScalar(1.)); 83 140 index++; 84 141 85 142 } 86 143 } 87 144 // do the union find 88 145 89 146 findUnions(dispatcher,colWorld); 90 91 92 93 } 94 95 96 147 } 97 148 98 149 void btSimulationIslandManager::storeIslandActivationState(btCollisionWorld* colWorld) … … 100 151 // put the islandId ('find' value) into m_tag 101 152 { 102 103 153 154 104 155 int index = 0; 105 156 int i; … … 120 171 } 121 172 } 173 174 #endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION 122 175 123 176 inline int getIslandId(const btPersistentManifold* lhs) -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.cpp
r5781 r8351 60 60 61 61 btDiscreteCollisionDetectorInterface::ClosestPointInput input; 62 input.m_maximumDistanceSquared = btScalar( 1e30);///@todo: tighter bounds62 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);///@todo: tighter bounds 63 63 input.m_transformA = sphereObj->getWorldTransform(); 64 64 input.m_transformB = triObj->getWorldTransform(); -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.cpp
r5781 r8351 71 71 { 72 72 m_elements[i].m_id = find(i); 73 #ifndef STATIC_SIMULATION_ISLAND_OPTIMIZATION 73 74 m_elements[i].m_sz = i; 75 #endif //STATIC_SIMULATION_ISLAND_OPTIMIZATION 74 76 } 75 77 … … 79 81 80 82 } 81 -
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btUnionFind.h
r5781 r8351 19 19 #include "LinearMath/btAlignedObjectArray.h" 20 20 21 #define USE_PATH_COMPRESSION 1 21 #define USE_PATH_COMPRESSION 1 22 23 ///see for discussion of static island optimizations by Vroonsh here: http://code.google.com/p/bullet/issues/detail?id=406 24 #define STATIC_SIMULATION_ISLAND_OPTIMIZATION 1 22 25 23 26 struct btElement … … 107 110 108 111 #ifdef USE_PATH_COMPRESSION 109 // 110 m_elements[x].m_id = m_elements[m_elements[x].m_id].m_id; 111 #endif // 112 const btElement* elementPtr = &m_elements[m_elements[x].m_id]; 113 m_elements[x].m_id = elementPtr->m_id; 114 x = elementPtr->m_id; 115 #else// 112 116 x = m_elements[x].m_id; 117 #endif 113 118 //btAssert(x < m_N); 114 119 //btAssert(x >= 0); -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 #include "btBoxShape.h" 17 16 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBoxShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 42 42 const btVector3& getHalfExtentsWithoutMargin() const 43 43 { 44 return m_implicitShapeDimensions;// changed in Bullet 2.63: assume the scaling and margin are included44 return m_implicitShapeDimensions;//scaling is included, margin is not 45 45 } 46 46 … … 313 313 }; 314 314 315 315 316 #endif //OBB_BOX_MINKOWSKI_H 316 317 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 18 18 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" 19 19 #include "BulletCollision/CollisionShapes/btOptimizedBvh.h" 20 #include "LinearMath/btSerializer.h" 20 21 21 22 ///Bvh Concave triangle mesh is a static-triangle mesh shape with Bounding Volume Hierarchy optimization. … … 24 25 :btTriangleMeshShape(meshInterface), 25 26 m_bvh(0), 27 m_triangleInfoMap(0), 26 28 m_useQuantizedAabbCompression(useQuantizedAabbCompression), 27 29 m_ownsBvh(false) … … 31 33 #ifndef DISABLE_BVH 32 34 33 btVector3 bvhAabbMin,bvhAabbMax;34 if(meshInterface->hasPremadeAabb())35 {36 meshInterface->getPremadeAabb(&bvhAabbMin, &bvhAabbMax);37 }38 else39 {40 meshInterface->calculateAabbBruteForce(bvhAabbMin,bvhAabbMax);41 }42 43 35 if (buildBvh) 44 36 { 45 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 46 m_bvh = new (mem) btOptimizedBvh(); 47 m_bvh->build(meshInterface,m_useQuantizedAabbCompression,bvhAabbMin,bvhAabbMax); 48 m_ownsBvh = true; 37 buildOptimizedBvh(); 49 38 } 50 39 … … 56 45 :btTriangleMeshShape(meshInterface), 57 46 m_bvh(0), 47 m_triangleInfoMap(0), 58 48 m_useQuantizedAabbCompression(useQuantizedAabbCompression), 59 49 m_ownsBvh(false) … … 344 334 { 345 335 btTriangleMeshShape::setLocalScaling(scaling); 346 if (m_ownsBvh) 347 { 348 m_bvh->~btOptimizedBvh(); 349 btAlignedFree(m_bvh); 350 } 351 ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work 352 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 353 m_bvh = new(mem) btOptimizedBvh(); 354 //rebuild the bvh... 355 m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); 356 m_ownsBvh = true; 336 buildOptimizedBvh(); 357 337 } 338 } 339 340 void btBvhTriangleMeshShape::buildOptimizedBvh() 341 { 342 if (m_ownsBvh) 343 { 344 m_bvh->~btOptimizedBvh(); 345 btAlignedFree(m_bvh); 346 } 347 ///m_localAabbMin/m_localAabbMax is already re-calculated in btTriangleMeshShape. We could just scale aabb, but this needs some more work 348 void* mem = btAlignedAlloc(sizeof(btOptimizedBvh),16); 349 m_bvh = new(mem) btOptimizedBvh(); 350 //rebuild the bvh... 351 m_bvh->build(m_meshInterface,m_useQuantizedAabbCompression,m_localAabbMin,m_localAabbMax); 352 m_ownsBvh = true; 358 353 } 359 354 … … 373 368 374 369 370 371 ///fills the dataBuffer and returns the struct name (and 0 on failure) 372 const char* btBvhTriangleMeshShape::serialize(void* dataBuffer, btSerializer* serializer) const 373 { 374 btTriangleMeshShapeData* trimeshData = (btTriangleMeshShapeData*) dataBuffer; 375 376 btCollisionShape::serialize(&trimeshData->m_collisionShapeData,serializer); 377 378 m_meshInterface->serialize(&trimeshData->m_meshInterface, serializer); 379 380 trimeshData->m_collisionMargin = float(m_collisionMargin); 381 382 383 384 if (m_bvh && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_BVH)) 385 { 386 void* chunk = serializer->findPointer(m_bvh); 387 if (chunk) 388 { 389 #ifdef BT_USE_DOUBLE_PRECISION 390 trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)chunk; 391 trimeshData->m_quantizedFloatBvh = 0; 392 #else 393 trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)chunk; 394 trimeshData->m_quantizedDoubleBvh= 0; 395 #endif //BT_USE_DOUBLE_PRECISION 396 } else 397 { 398 399 #ifdef BT_USE_DOUBLE_PRECISION 400 trimeshData->m_quantizedDoubleBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh); 401 trimeshData->m_quantizedFloatBvh = 0; 402 #else 403 trimeshData->m_quantizedFloatBvh = (btQuantizedBvhData*)serializer->getUniquePointer(m_bvh); 404 trimeshData->m_quantizedDoubleBvh= 0; 405 #endif //BT_USE_DOUBLE_PRECISION 406 407 int sz = m_bvh->calculateSerializeBufferSizeNew(); 408 btChunk* chunk = serializer->allocate(sz,1); 409 const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); 410 serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,m_bvh); 411 } 412 } else 413 { 414 trimeshData->m_quantizedFloatBvh = 0; 415 trimeshData->m_quantizedDoubleBvh = 0; 416 } 417 418 419 420 if (m_triangleInfoMap && !(serializer->getSerializationFlags()&BT_SERIALIZE_NO_TRIANGLEINFOMAP)) 421 { 422 void* chunk = serializer->findPointer(m_triangleInfoMap); 423 if (chunk) 424 { 425 trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)chunk; 426 } else 427 { 428 trimeshData->m_triangleInfoMap = (btTriangleInfoMapData*)serializer->getUniquePointer(m_triangleInfoMap); 429 int sz = m_triangleInfoMap->calculateSerializeBufferSize(); 430 btChunk* chunk = serializer->allocate(sz,1); 431 const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); 432 serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,m_triangleInfoMap); 433 } 434 } else 435 { 436 trimeshData->m_triangleInfoMap = 0; 437 } 438 439 return "btTriangleMeshShapeData"; 440 } 441 442 void btBvhTriangleMeshShape::serializeSingleBvh(btSerializer* serializer) const 443 { 444 if (m_bvh) 445 { 446 int len = m_bvh->calculateSerializeBufferSizeNew(); //make sure not to use calculateSerializeBufferSize because it is used for in-place 447 btChunk* chunk = serializer->allocate(len,1); 448 const char* structType = m_bvh->serialize(chunk->m_oldPtr, serializer); 449 serializer->finalizeChunk(chunk,structType,BT_QUANTIZED_BVH_CODE,(void*)m_bvh); 450 } 451 } 452 453 void btBvhTriangleMeshShape::serializeSingleTriangleInfoMap(btSerializer* serializer) const 454 { 455 if (m_triangleInfoMap) 456 { 457 int len = m_triangleInfoMap->calculateSerializeBufferSize(); 458 btChunk* chunk = serializer->allocate(len,1); 459 const char* structType = m_triangleInfoMap->serialize(chunk->m_oldPtr, serializer); 460 serializer->finalizeChunk(chunk,structType,BT_TRIANLGE_INFO_MAP,(void*)m_triangleInfoMap); 461 } 462 } 463 464 465 466 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "btOptimizedBvh.h" 21 21 #include "LinearMath/btAlignedAllocator.h" 22 22 #include "btTriangleInfoMap.h" 23 23 24 24 ///The btBvhTriangleMeshShape is a static-triangle mesh shape with several optimizations, such as bounding volume hierarchy and cache friendly traversal for PlayStation 3 Cell SPU. It is recommended to enable useQuantizedAabbCompression for better memory usage. … … 30 30 31 31 btOptimizedBvh* m_bvh; 32 btTriangleInfoMap* m_triangleInfoMap; 33 32 34 bool m_useQuantizedAabbCompression; 33 35 bool m_ownsBvh; … … 38 40 BT_DECLARE_ALIGNED_ALLOCATOR(); 39 41 40 btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_ ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;};42 btBvhTriangleMeshShape() : btTriangleMeshShape(0),m_bvh(0),m_triangleInfoMap(0),m_ownsBvh(false) {m_shapeType = TRIANGLE_MESH_SHAPE_PROXYTYPE;}; 41 43 btBvhTriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true); 42 44 … … 74 76 } 75 77 78 void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1)); 76 79 77 void setOptimizedBvh(btOptimizedBvh* bvh, const btVector3& localScaling=btVector3(1,1,1));80 void buildOptimizedBvh(); 78 81 79 82 bool usesQuantizedAabbCompression() const … … 81 84 return m_useQuantizedAabbCompression; 82 85 } 86 87 void setTriangleInfoMap(btTriangleInfoMap* triangleInfoMap) 88 { 89 m_triangleInfoMap = triangleInfoMap; 90 } 91 92 const btTriangleInfoMap* getTriangleInfoMap() const 93 { 94 return m_triangleInfoMap; 95 } 96 97 btTriangleInfoMap* getTriangleInfoMap() 98 { 99 return m_triangleInfoMap; 100 } 101 102 virtual int calculateSerializeBufferSize() const; 103 104 ///fills the dataBuffer and returns the struct name (and 0 on failure) 105 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 106 107 virtual void serializeSingleBvh(btSerializer* serializer) const; 108 109 virtual void serializeSingleTriangleInfoMap(btSerializer* serializer) const; 110 111 }; 112 113 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 114 struct btTriangleMeshShapeData 115 { 116 btCollisionShapeData m_collisionShapeData; 117 118 btStridingMeshInterfaceData m_meshInterface; 119 120 btQuantizedBvhFloatData *m_quantizedFloatBvh; 121 btQuantizedBvhDoubleData *m_quantizedDoubleBvh; 122 123 btTriangleInfoMapData *m_triangleInfoMap; 124 125 float m_collisionMargin; 126 127 char m_pad3[4]; 128 129 }; 130 131 132 SIMD_FORCE_INLINE int btBvhTriangleMeshShape::calculateSerializeBufferSize() const 133 { 134 return sizeof(btTriangleMeshShapeData); 83 135 } 84 ; 136 137 85 138 86 139 #endif //BVH_TRIANGLE_MESH_SHAPE_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCapsuleShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 33 33 btVector3 supVec(0,0,0); 34 34 35 btScalar maxDot(btScalar(- 1e30));35 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 36 36 37 37 btVector3 vec = vec0; … … 89 89 for (int j=0;j<numVectors;j++) 90 90 { 91 btScalar maxDot(btScalar(- 1e30));91 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 92 92 const btVector3& vec = vectors[j]; 93 93 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 44 44 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 45 45 46 virtual void setMargin(btScalar collisionMargin) 47 { 48 //correct the m_implicitShapeDimensions for the margin 49 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 50 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 51 52 btConvexInternalShape::setMargin(collisionMargin); 53 btVector3 newMargin(getMargin(),getMargin(),getMargin()); 54 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; 55 56 } 57 46 58 virtual void getAabb (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const 47 59 { … … 77 89 return m_implicitShapeDimensions[m_upAxis]; 78 90 } 91 92 virtual void setLocalScaling(const btVector3& scaling) 93 { 94 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 95 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 96 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling; 97 98 btConvexInternalShape::setLocalScaling(scaling); 99 100 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin; 101 102 } 103 104 virtual int calculateSerializeBufferSize() const; 105 106 ///fills the dataBuffer and returns the struct name (and 0 on failure) 107 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 108 79 109 80 110 }; … … 114 144 }; 115 145 146 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 147 struct btCapsuleShapeData 148 { 149 btConvexInternalShapeData m_convexInternalShapeData; 116 150 151 int m_upAxis; 152 153 char m_padding[4]; 154 }; 155 156 SIMD_FORCE_INLINE int btCapsuleShape::calculateSerializeBufferSize() const 157 { 158 return sizeof(btCapsuleShapeData); 159 } 160 161 ///fills the dataBuffer and returns the struct name (and 0 on failure) 162 SIMD_FORCE_INLINE const char* btCapsuleShape::serialize(void* dataBuffer, btSerializer* serializer) const 163 { 164 btCapsuleShapeData* shapeData = (btCapsuleShapeData*) dataBuffer; 165 166 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer); 167 168 shapeData->m_upAxis = m_upAxis; 169 170 return "btCapsuleShapeData"; 171 } 117 172 118 173 #endif //BT_CAPSULE_SHAPE_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionMargin.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 17 18 19 btScalar gContactThresholdFactor=btScalar(0.02); 20 16 #include "LinearMath/btSerializer.h" 21 17 22 18 /* … … 46 42 } 47 43 48 btScalar btCollisionShape::getContactBreakingThreshold() const 44 45 btScalar btCollisionShape::getContactBreakingThreshold(btScalar defaultContactThreshold) const 49 46 { 50 return getAngularMotionDisc() * gContactThresholdFactor;47 return getAngularMotionDisc() * defaultContactThreshold; 51 48 } 49 52 50 btScalar btCollisionShape::getAngularMotionDisc() const 53 51 { … … 97 95 temporalAabbMax += angularMotion3d; 98 96 } 97 98 ///fills the dataBuffer and returns the struct name (and 0 on failure) 99 const char* btCollisionShape::serialize(void* dataBuffer, btSerializer* serializer) const 100 { 101 btCollisionShapeData* shapeData = (btCollisionShapeData*) dataBuffer; 102 char* name = (char*) serializer->findNameForPointer(this); 103 shapeData->m_name = (char*)serializer->getUniquePointer(name); 104 if (shapeData->m_name) 105 { 106 serializer->serializeName(name); 107 } 108 shapeData->m_shapeType = m_shapeType; 109 //shapeData->m_padding//?? 110 return "btCollisionShapeData"; 111 } 112 113 void btCollisionShape::serializeSingleShape(btSerializer* serializer) const 114 { 115 int len = calculateSerializeBufferSize(); 116 btChunk* chunk = serializer->allocate(len,1); 117 const char* structType = serialize(chunk->m_oldPtr, serializer); 118 serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,(void*)this); 119 } -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCollisionShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 21 21 #include "LinearMath/btMatrix3x3.h" 22 22 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types 23 class btSerializer; 24 23 25 24 26 ///The btCollisionShape class provides an interface for collision shapes that can be shared among btCollisionObjects. … … 47 49 virtual btScalar getAngularMotionDisc() const; 48 50 49 virtual btScalar getContactBreakingThreshold( ) const;51 virtual btScalar getContactBreakingThreshold(btScalar defaultContactThresholdFactor) const; 50 52 51 53 … … 54 56 void calculateTemporalAabb(const btTransform& curTrans,const btVector3& linvel,const btVector3& angvel,btScalar timeStep, btVector3& temporalAabbMin,btVector3& temporalAabbMax) const; 55 57 56 #ifndef __SPU__ 58 57 59 58 60 SIMD_FORCE_INLINE bool isPolyhedral() const … … 61 63 } 62 64 65 SIMD_FORCE_INLINE bool isConvex2d() const 66 { 67 return btBroadphaseProxy::isConvex2d(getShapeType()); 68 } 69 63 70 SIMD_FORCE_INLINE bool isConvex() const 64 71 { 65 72 return btBroadphaseProxy::isConvex(getShapeType()); 73 } 74 SIMD_FORCE_INLINE bool isNonMoving() const 75 { 76 return btBroadphaseProxy::isNonMoving(getShapeType()); 66 77 } 67 78 SIMD_FORCE_INLINE bool isConcave() const … … 74 85 } 75 86 87 SIMD_FORCE_INLINE bool isSoftBody() const 88 { 89 return btBroadphaseProxy::isSoftBody(getShapeType()); 90 } 91 76 92 ///isInfinite is used to catch simulation error (aabb check) 77 93 SIMD_FORCE_INLINE bool isInfinite() const … … 80 96 } 81 97 82 98 #ifndef __SPU__ 83 99 virtual void setLocalScaling(const btVector3& scaling) =0; 84 100 virtual const btVector3& getLocalScaling() const =0; … … 107 123 } 108 124 125 virtual int calculateSerializeBufferSize() const; 126 127 ///fills the dataBuffer and returns the struct name (and 0 on failure) 128 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 129 130 virtual void serializeSingleShape(btSerializer* serializer) const; 131 109 132 }; 133 134 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 135 struct btCollisionShapeData 136 { 137 char *m_name; 138 int m_shapeType; 139 char m_padding[4]; 140 }; 141 142 SIMD_FORCE_INLINE int btCollisionShape::calculateSerializeBufferSize() const 143 { 144 return sizeof(btCollisionShapeData); 145 } 146 147 110 148 111 149 #endif //COLLISION_SHAPE_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 17 17 #include "btCollisionShape.h" 18 18 #include "BulletCollision/BroadphaseCollision/btDbvt.h" 19 #include "LinearMath/btSerializer.h" 19 20 20 21 btCompoundShape::btCompoundShape(bool enableDynamicAabbTree) 21 : m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)), 22 m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)), 22 : m_localAabbMin(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)), 23 m_localAabbMax(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)), 24 m_dynamicAabbTree(0), 25 m_updateRevision(1), 23 26 m_collisionMargin(btScalar(0.)), 24 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)), 25 m_dynamicAabbTree(0), 26 m_updateRevision(1) 27 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)) 27 28 { 28 29 m_shapeType = COMPOUND_SHAPE_PROXYTYPE; … … 52 53 //m_childShapes.push_back(shape); 53 54 btCompoundShapeChild child; 55 child.m_node = 0; 54 56 child.m_transform = localTransform; 55 57 child.m_childShape = shape; … … 94 96 m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax); 95 97 ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 96 int index = m_children.size()-1;98 //int index = m_children.size()-1; 97 99 m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds); 98 100 } … … 110 112 } 111 113 m_children.swap(childShapeIndex,m_children.size()-1); 114 if (m_dynamicAabbTree) 115 m_children[childShapeIndex].m_node->dataAsInt = childShapeIndex; 112 116 m_children.pop_back(); 113 117 … … 125 129 if(m_children[i].m_childShape == shape) 126 130 { 127 m_children.swap(i,m_children.size()-1); 128 m_children.pop_back(); 129 //remove it from the m_dynamicAabbTree too 130 //@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm 131 //so effectively, removeChildShape is broken at the moment 132 //m_dynamicAabbTree->remove(m_aabbProxies[i]); 133 //m_aabbProxies.swap(i,m_children.size()-1); 134 //m_aabbProxies.pop_back(); 131 removeChildShapeByIndex(i); 135 132 } 136 133 } … … 146 143 // Brute force, it iterates over all the shapes left. 147 144 148 m_localAabbMin = btVector3(btScalar( 1e30),btScalar(1e30),btScalar(1e30));149 m_localAabbMax = btVector3(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));145 m_localAabbMin = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 146 m_localAabbMax = btVector3(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 150 147 151 148 //extend the local aabbMin/aabbMax … … 224 221 for (k = 0; k < n; k++) 225 222 { 223 btAssert(masses[k]>0); 226 224 center += m_children[k].m_transform.getOrigin() * masses[k]; 227 225 totalMass += masses[k]; 228 226 } 227 228 btAssert(totalMass>0); 229 229 230 center /= totalMass; 230 231 principal.setOrigin(center); … … 272 273 273 274 275 void btCompoundShape::setLocalScaling(const btVector3& scaling) 276 { 277 278 for(int i = 0; i < m_children.size(); i++) 279 { 280 btTransform childTrans = getChildTransform(i); 281 btVector3 childScale = m_children[i].m_childShape->getLocalScaling(); 282 // childScale = childScale * (childTrans.getBasis() * scaling); 283 childScale = childScale * scaling / m_localScaling; 284 m_children[i].m_childShape->setLocalScaling(childScale); 285 childTrans.setOrigin((childTrans.getOrigin())*scaling); 286 updateChildTransform(i, childTrans); 287 recalculateLocalAabb(); 288 } 289 m_localScaling = scaling; 290 } 291 292 293 void btCompoundShape::createAabbTreeFromChildren() 294 { 295 if ( !m_dynamicAabbTree ) 296 { 297 void* mem = btAlignedAlloc(sizeof(btDbvt),16); 298 m_dynamicAabbTree = new(mem) btDbvt(); 299 btAssert(mem==m_dynamicAabbTree); 300 301 for ( int index = 0; index < m_children.size(); index++ ) 302 { 303 btCompoundShapeChild &child = m_children[index]; 304 305 //extend the local aabbMin/aabbMax 306 btVector3 localAabbMin,localAabbMax; 307 child.m_childShape->getAabb(child.m_transform,localAabbMin,localAabbMax); 308 309 const btDbvtVolume bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax); 310 child.m_node = m_dynamicAabbTree->insert(bounds,(void*)index); 311 } 312 } 313 } 314 315 316 ///fills the dataBuffer and returns the struct name (and 0 on failure) 317 const char* btCompoundShape::serialize(void* dataBuffer, btSerializer* serializer) const 318 { 319 320 btCompoundShapeData* shapeData = (btCompoundShapeData*) dataBuffer; 321 btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer); 322 323 shapeData->m_collisionMargin = float(m_collisionMargin); 324 shapeData->m_numChildShapes = m_children.size(); 325 shapeData->m_childShapePtr = 0; 326 if (shapeData->m_numChildShapes) 327 { 328 btChunk* chunk = serializer->allocate(sizeof(btCompoundShapeChildData),shapeData->m_numChildShapes); 329 btCompoundShapeChildData* memPtr = (btCompoundShapeChildData*)chunk->m_oldPtr; 330 shapeData->m_childShapePtr = (btCompoundShapeChildData*)serializer->getUniquePointer(memPtr); 331 332 for (int i=0;i<shapeData->m_numChildShapes;i++,memPtr++) 333 { 334 memPtr->m_childMargin = float(m_children[i].m_childMargin); 335 memPtr->m_childShape = (btCollisionShapeData*)serializer->getUniquePointer(m_children[i].m_childShape); 336 //don't serialize shapes that already have been serialized 337 if (!serializer->findPointer(m_children[i].m_childShape)) 338 { 339 btChunk* chunk = serializer->allocate(m_children[i].m_childShape->calculateSerializeBufferSize(),1); 340 const char* structType = m_children[i].m_childShape->serialize(chunk->m_oldPtr,serializer); 341 serializer->finalizeChunk(chunk,structType,BT_SHAPE_CODE,m_children[i].m_childShape); 342 } 343 344 memPtr->m_childShapeType = m_children[i].m_childShapeType; 345 m_children[i].m_transform.serializeFloat(memPtr->m_transform); 346 } 347 serializer->finalizeChunk(chunk,"btCompoundShapeChildData",BT_ARRAY_CODE,chunk->m_oldPtr); 348 } 349 return "btCompoundShapeData"; 350 } 351 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCompoundShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 63 63 int m_updateRevision; 64 64 65 btScalar m_collisionMargin; 66 67 protected: 68 btVector3 m_localScaling; 69 65 70 public: 66 71 BT_DECLARE_ALIGNED_ALLOCATOR(); … … 117 122 virtual void recalculateLocalAabb(); 118 123 119 virtual void setLocalScaling(const btVector3& scaling) 120 { 121 m_localScaling = scaling; 122 } 124 virtual void setLocalScaling(const btVector3& scaling); 125 123 126 virtual const btVector3& getLocalScaling() const 124 127 { … … 141 144 } 142 145 143 //this is optional, but should make collision queries faster, by culling non-overlapping nodes144 void createAabbTreeFromChildren();145 146 146 147 btDbvt* getDynamicAabbTree() … … 148 149 return m_dynamicAabbTree; 149 150 } 151 152 void createAabbTreeFromChildren(); 150 153 151 154 ///computes the exact moment of inertia and the transform from the coordinate system defined by the principal axes of the moment of inertia … … 161 164 } 162 165 163 private: 164 btScalar m_collisionMargin; 165 protected: 166 btVector3 m_localScaling; 167 168 }; 166 virtual int calculateSerializeBufferSize() const; 167 168 ///fills the dataBuffer and returns the struct name (and 0 on failure) 169 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 170 171 172 }; 173 174 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 175 struct btCompoundShapeChildData 176 { 177 btTransformFloatData m_transform; 178 btCollisionShapeData *m_childShape; 179 int m_childShapeType; 180 float m_childMargin; 181 }; 182 183 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 184 struct btCompoundShapeData 185 { 186 btCollisionShapeData m_collisionShapeData; 187 188 btCompoundShapeChildData *m_childShapePtr; 189 190 int m_numChildShapes; 191 192 float m_collisionMargin; 193 194 }; 195 196 197 SIMD_FORCE_INLINE int btCompoundShape::calculateSerializeBufferSize() const 198 { 199 return sizeof(btCompoundShapeData); 200 } 201 202 203 204 169 205 170 206 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.cpp
r5781 r8351 1 2 1 /* 3 2 Bullet Continuous Collision Detection and Physics Library 4 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 5 4 6 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConcaveShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConeShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btConvexHullShape.h" 16 17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" 17 18 18 19 #include "LinearMath/btQuaternion.h" 19 20 21 22 btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexShape () 20 #include "LinearMath/btSerializer.h" 21 22 btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexAabbCachingShape () 23 23 { 24 24 m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE; 25 25 m_unscaledPoints.resize(numPoints); 26 26 27 unsigned char* points BaseAddress = (unsigned char*)points;27 unsigned char* pointsAddress = (unsigned char*)points; 28 28 29 29 for (int i=0;i<numPoints;i++) 30 30 { 31 btVector3* point = (btVector3*)(pointsBaseAddress + i*stride); 32 m_unscaledPoints[i] = point[0]; 31 btScalar* point = (btScalar*)pointsAddress; 32 m_unscaledPoints[i] = btVector3(point[0], point[1], point[2]); 33 pointsAddress += stride; 33 34 } 34 35 … … 52 53 } 53 54 54 btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec 0)const55 btVector3 btConvexHullShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const 55 56 { 56 57 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); 57 btScalar newDot,maxDot = btScalar(-1e30); 58 59 btVector3 vec = vec0; 60 btScalar lenSqr = vec.length2(); 61 if (lenSqr < btScalar(0.0001)) 62 { 63 vec.setValue(1,0,0); 64 } else 65 { 66 btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); 67 vec *= rlen; 68 } 69 58 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT); 70 59 71 60 for (int i=0;i<m_unscaledPoints.size();i++) … … 90 79 for (int i=0;i<numVectors;i++) 91 80 { 92 supportVerticesOut[i][3] = btScalar(- 1e30);81 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 93 82 } 94 83 } … … 186 175 } 187 176 177 ///fills the dataBuffer and returns the struct name (and 0 on failure) 178 const char* btConvexHullShape::serialize(void* dataBuffer, btSerializer* serializer) const 179 { 180 //int szc = sizeof(btConvexHullShapeData); 181 btConvexHullShapeData* shapeData = (btConvexHullShapeData*) dataBuffer; 182 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer); 183 184 int numElem = m_unscaledPoints.size(); 185 shapeData->m_numUnscaledPoints = numElem; 186 #ifdef BT_USE_DOUBLE_PRECISION 187 shapeData->m_unscaledPointsFloatPtr = 0; 188 shapeData->m_unscaledPointsDoublePtr = numElem ? (btVector3Data*)serializer->getUniquePointer((void*)&m_unscaledPoints[0]): 0; 189 #else 190 shapeData->m_unscaledPointsFloatPtr = numElem ? (btVector3Data*)serializer->getUniquePointer((void*)&m_unscaledPoints[0]): 0; 191 shapeData->m_unscaledPointsDoublePtr = 0; 192 #endif 193 194 if (numElem) 195 { 196 int sz = sizeof(btVector3Data); 197 // int sz2 = sizeof(btVector3DoubleData); 198 // int sz3 = sizeof(btVector3FloatData); 199 btChunk* chunk = serializer->allocate(sz,numElem); 200 btVector3Data* memPtr = (btVector3Data*)chunk->m_oldPtr; 201 for (int i=0;i<numElem;i++,memPtr++) 202 { 203 m_unscaledPoints[i].serialize(*memPtr); 204 } 205 serializer->finalizeChunk(chunk,btVector3DataName,BT_ARRAY_CODE,(void*)&m_unscaledPoints[0]); 206 } 207 208 return "btConvexHullShapeData"; 209 } 210 211 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 21 21 #include "LinearMath/btAlignedObjectArray.h" 22 22 23 23 24 ///The btConvexHullShape implements an implicit convex hull of an array of vertices. 24 25 ///Bullet provides a general and fast collision detector for convex shapes based on GJK and EPA using localGetSupportingVertex. 25 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvex Shape26 ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexAabbCachingShape 26 27 { 27 28 btAlignedObjectArray<btVector3> m_unscaledPoints; … … 89 90 virtual void setLocalScaling(const btVector3& scaling); 90 91 92 virtual int calculateSerializeBufferSize() const; 93 94 ///fills the dataBuffer and returns the struct name (and 0 on failure) 95 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 96 91 97 }; 98 99 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 100 struct btConvexHullShapeData 101 { 102 btConvexInternalShapeData m_convexInternalShapeData; 103 104 btVector3FloatData *m_unscaledPointsFloatPtr; 105 btVector3DoubleData *m_unscaledPointsDoublePtr; 106 107 int m_numUnscaledPoints; 108 char m_padding3[4]; 109 110 }; 111 112 113 SIMD_FORCE_INLINE int btConvexHullShape::calculateSerializeBufferSize() const 114 { 115 return sizeof(btConvexHullShapeData); 116 } 92 117 93 118 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 35 35 void btConvexInternalShape::getAabbSlow(const btTransform& trans,btVector3&minAabb,btVector3&maxAabb) const 36 36 { 37 37 #ifndef __SPU__ 38 //use localGetSupportingVertexWithoutMargin? 38 39 btScalar margin = getMargin(); 39 40 for (int i=0;i<3;i++) … … 50 51 minAabb[i] = tmp[i]-margin; 51 52 } 53 #endif 52 54 } 53 55 … … 80 82 81 83 84 btConvexInternalAabbCachingShape::btConvexInternalAabbCachingShape() 85 : btConvexInternalShape(), 86 m_localAabbMin(1,1,1), 87 m_localAabbMax(-1,-1,-1), 88 m_isLocalAabbValid(false) 89 { 90 } 91 92 93 void btConvexInternalAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 94 { 95 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 96 } 97 98 void btConvexInternalAabbCachingShape::setLocalScaling(const btVector3& scaling) 99 { 100 btConvexInternalShape::setLocalScaling(scaling); 101 recalcLocalAabb(); 102 } 103 104 105 void btConvexInternalAabbCachingShape::recalcLocalAabb() 106 { 107 m_isLocalAabbValid = true; 108 109 #if 1 110 static const btVector3 _directions[] = 111 { 112 btVector3( 1., 0., 0.), 113 btVector3( 0., 1., 0.), 114 btVector3( 0., 0., 1.), 115 btVector3( -1., 0., 0.), 116 btVector3( 0., -1., 0.), 117 btVector3( 0., 0., -1.) 118 }; 119 120 btVector3 _supporting[] = 121 { 122 btVector3( 0., 0., 0.), 123 btVector3( 0., 0., 0.), 124 btVector3( 0., 0., 0.), 125 btVector3( 0., 0., 0.), 126 btVector3( 0., 0., 0.), 127 btVector3( 0., 0., 0.) 128 }; 129 130 batchedUnitVectorGetSupportingVertexWithoutMargin(_directions, _supporting, 6); 131 132 for ( int i = 0; i < 3; ++i ) 133 { 134 m_localAabbMax[i] = _supporting[i][i] + m_collisionMargin; 135 m_localAabbMin[i] = _supporting[i + 3][i] - m_collisionMargin; 136 } 137 138 #else 139 140 for (int i=0;i<3;i++) 141 { 142 btVector3 vec(btScalar(0.),btScalar(0.),btScalar(0.)); 143 vec[i] = btScalar(1.); 144 btVector3 tmp = localGetSupportingVertex(vec); 145 m_localAabbMax[i] = tmp[i]+m_collisionMargin; 146 vec[i] = btScalar(-1.); 147 tmp = localGetSupportingVertex(vec); 148 m_localAabbMin[i] = tmp[i]-m_collisionMargin; 149 } 150 #endif 151 } -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h
r5781 r8351 1 /* 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 5 This software is provided 'as-is', without any express or implied warranty. 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 subject to the following restrictions: 10 11 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. 12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 13 3. This notice may not be removed or altered from any source distribution. 14 */ 1 15 2 16 #ifndef BT_CONVEX_INTERNAL_SHAPE_H … … 4 18 5 19 #include "btConvexShape.h" 20 #include "LinearMath/btAabbUtil2.h" 21 6 22 7 23 ///The btConvexInternalShape is an internal base class, shared by most convex shape implementations. … … 36 52 { 37 53 return m_implicitShapeDimensions; 54 } 55 56 ///warning: use setImplicitShapeDimensions with care 57 ///changing a collision shape while the body is in the world is not recommended, 58 ///it is best to remove the body from the world, then make the change, and re-add it 59 ///alternatively flush the contact points, see documentation for 'cleanProxyFromPairs' 60 void setImplicitShapeDimensions(const btVector3& dimensions) 61 { 62 m_implicitShapeDimensions = dimensions; 38 63 } 39 64 … … 86 111 } 87 112 113 virtual int calculateSerializeBufferSize() const; 114 115 ///fills the dataBuffer and returns the struct name (and 0 on failure) 116 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 88 117 89 118 90 119 }; 91 120 121 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 122 struct btConvexInternalShapeData 123 { 124 btCollisionShapeData m_collisionShapeData; 125 126 btVector3FloatData m_localScaling; 127 128 btVector3FloatData m_implicitShapeDimensions; 129 130 float m_collisionMargin; 131 132 int m_padding; 133 134 }; 135 136 137 138 SIMD_FORCE_INLINE int btConvexInternalShape::calculateSerializeBufferSize() const 139 { 140 return sizeof(btConvexInternalShapeData); 141 } 142 143 ///fills the dataBuffer and returns the struct name (and 0 on failure) 144 SIMD_FORCE_INLINE const char* btConvexInternalShape::serialize(void* dataBuffer, btSerializer* serializer) const 145 { 146 btConvexInternalShapeData* shapeData = (btConvexInternalShapeData*) dataBuffer; 147 btCollisionShape::serialize(&shapeData->m_collisionShapeData, serializer); 148 149 m_implicitShapeDimensions.serializeFloat(shapeData->m_implicitShapeDimensions); 150 m_localScaling.serializeFloat(shapeData->m_localScaling); 151 shapeData->m_collisionMargin = float(m_collisionMargin); 152 153 return "btConvexInternalShapeData"; 154 } 155 156 157 158 159 ///btConvexInternalAabbCachingShape adds local aabb caching for convex shapes, to avoid expensive bounding box calculations 160 class btConvexInternalAabbCachingShape : public btConvexInternalShape 161 { 162 btVector3 m_localAabbMin; 163 btVector3 m_localAabbMax; 164 bool m_isLocalAabbValid; 165 166 protected: 167 168 btConvexInternalAabbCachingShape(); 169 170 void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax) 171 { 172 m_isLocalAabbValid = true; 173 m_localAabbMin = aabbMin; 174 m_localAabbMax = aabbMax; 175 } 176 177 inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const 178 { 179 btAssert(m_isLocalAabbValid); 180 aabbMin = m_localAabbMin; 181 aabbMax = m_localAabbMax; 182 } 183 184 inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const 185 { 186 187 //lazy evaluation of local aabb 188 btAssert(m_isLocalAabbValid); 189 btTransformAabb(m_localAabbMin,m_localAabbMax,margin,trans,aabbMin,aabbMax); 190 } 191 192 public: 193 194 virtual void setLocalScaling(const btVector3& scaling); 195 196 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 197 198 void recalcLocalAabb(); 199 200 }; 92 201 93 202 #endif //BT_CONVEX_INTERNAL_SHAPE_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btConvexPointCloudShape.h" 16 17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" … … 28 29 { 29 30 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); 30 btScalar newDot,maxDot = btScalar(- 1e30);31 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT); 31 32 32 33 btVector3 vec = vec0; … … 63 64 for (int i=0;i<numVectors;i++) 64 65 { 65 supportVerticesOut[i][3] = btScalar(- 1e30);66 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 66 67 } 67 68 } -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 22 22 23 23 ///The btConvexPointCloudShape implements an implicit convex hull of an array of vertices. 24 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvex Shape24 ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexAabbCachingShape 25 25 { 26 26 btVector3* m_unscaledPoints; … … 29 29 public: 30 30 BT_DECLARE_ALIGNED_ALLOCATOR(); 31 32 btConvexPointCloudShape() 33 { 34 m_localScaling.setValue(1.f,1.f,1.f); 35 m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE; 36 m_unscaledPoints = 0; 37 m_numPoints = 0; 38 } 31 39 32 40 btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true) … … 41 49 } 42 50 43 void setPoints (btVector3* points, int numPoints, bool computeAabb = true )51 void setPoints (btVector3* points, int numPoints, bool computeAabb = true,const btVector3& localScaling=btVector3(1.f,1.f,1.f)) 44 52 { 45 53 m_unscaledPoints = points; 46 54 m_numPoints = numPoints; 55 m_localScaling = localScaling; 47 56 48 57 if (computeAabb) -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 22 22 #include "btConvexPointCloudShape.h" 23 23 24 ///not supported on IBM SDK, until we fix the alignment of btVector3 25 #if defined (__CELLOS_LV2__) && defined (__SPU__) 26 #include <spu_intrinsics.h> 27 static inline vec_float4 vec_dot3( vec_float4 vec0, vec_float4 vec1 ) 28 { 29 vec_float4 result; 30 result = spu_mul( vec0, vec1 ); 31 result = spu_madd( spu_rlqwbyte( vec0, 4 ), spu_rlqwbyte( vec1, 4 ), result ); 32 return spu_madd( spu_rlqwbyte( vec0, 8 ), spu_rlqwbyte( vec1, 8 ), result ); 33 } 34 #endif //__SPU__ 35 24 36 btConvexShape::btConvexShape () 25 37 { … … 33 45 34 46 35 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling) 36 { 37 btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.)); 38 btScalar newDot,maxDot = btScalar(-1e30); 39 40 btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ()); 41 btVector3 vec = vec0; 42 btScalar lenSqr = vec.length2(); 43 if (lenSqr < btScalar(0.0001)) 44 { 45 vec.setValue(1,0,0); 46 } else { 47 btScalar rlen = btScalar(1.) / btSqrt(lenSqr ); 48 vec *= rlen; 49 } 50 47 static btVector3 convexHullSupport (const btVector3& localDirOrg, const btVector3* points, int numPoints, const btVector3& localScaling) 48 { 49 50 btVector3 vec = localDirOrg * localScaling; 51 52 #if defined (__CELLOS_LV2__) && defined (__SPU__) 53 54 btVector3 localDir = vec; 55 56 vec_float4 v_distMax = {-FLT_MAX,0,0,0}; 57 vec_int4 v_idxMax = {-999,0,0,0}; 58 int v=0; 59 int numverts = numPoints; 60 61 for(;v<(int)numverts-4;v+=4) { 62 vec_float4 p0 = vec_dot3(points[v ].get128(),localDir.get128()); 63 vec_float4 p1 = vec_dot3(points[v+1].get128(),localDir.get128()); 64 vec_float4 p2 = vec_dot3(points[v+2].get128(),localDir.get128()); 65 vec_float4 p3 = vec_dot3(points[v+3].get128(),localDir.get128()); 66 const vec_int4 i0 = {v ,0,0,0}; 67 const vec_int4 i1 = {v+1,0,0,0}; 68 const vec_int4 i2 = {v+2,0,0,0}; 69 const vec_int4 i3 = {v+3,0,0,0}; 70 vec_uint4 retGt01 = spu_cmpgt(p0,p1); 71 vec_float4 pmax01 = spu_sel(p1,p0,retGt01); 72 vec_int4 imax01 = spu_sel(i1,i0,retGt01); 73 vec_uint4 retGt23 = spu_cmpgt(p2,p3); 74 vec_float4 pmax23 = spu_sel(p3,p2,retGt23); 75 vec_int4 imax23 = spu_sel(i3,i2,retGt23); 76 vec_uint4 retGt0123 = spu_cmpgt(pmax01,pmax23); 77 vec_float4 pmax0123 = spu_sel(pmax23,pmax01,retGt0123); 78 vec_int4 imax0123 = spu_sel(imax23,imax01,retGt0123); 79 vec_uint4 retGtMax = spu_cmpgt(v_distMax,pmax0123); 80 v_distMax = spu_sel(pmax0123,v_distMax,retGtMax); 81 v_idxMax = spu_sel(imax0123,v_idxMax,retGtMax); 82 } 83 for(;v<(int)numverts;v++) { 84 vec_float4 p = vec_dot3(points[v].get128(),localDir.get128()); 85 const vec_int4 i = {v,0,0,0}; 86 vec_uint4 retGtMax = spu_cmpgt(v_distMax,p); 87 v_distMax = spu_sel(p,v_distMax,retGtMax); 88 v_idxMax = spu_sel(i,v_idxMax,retGtMax); 89 } 90 int ptIndex = spu_extract(v_idxMax,0); 91 const btVector3& supVec= points[ptIndex] * localScaling; 92 return supVec; 93 #else 94 95 btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT); 96 int ptIndex = -1; 51 97 52 98 for (int i=0;i<numPoints;i++) 53 99 { 54 btVector3 vtx = points[i] * localScaling; 55 56 newDot = vec.dot(vtx); 100 101 newDot = vec.dot(points[i]); 57 102 if (newDot > maxDot) 58 103 { 59 104 maxDot = newDot; 60 supVec = vtx; 61 } 62 } 63 return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()); 105 ptIndex = i; 106 } 107 } 108 btAssert(ptIndex >= 0); 109 btVector3 supVec = points[ptIndex] * localScaling; 110 return supVec; 111 #endif //__SPU__ 64 112 } 65 113 … … 161 209 btVector3 supVec(0,0,0); 162 210 163 btScalar maxDot(btScalar(- 1e30));211 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 164 212 165 213 btVector3 vec = vec0; … … 293 341 return btScalar(0.0f); 294 342 } 295 343 #ifndef __SPU__ 296 344 void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const 297 345 { … … 361 409 case CONVEX_HULL_SHAPE_PROXYTYPE: 362 410 { 363 btPolyhedralConvex Shape* convexHullShape = (btPolyhedralConvexShape*)this;411 btPolyhedralConvexAabbCachingShape* convexHullShape = (btPolyhedralConvexAabbCachingShape*)this; 364 412 btScalar margin = convexHullShape->getMarginNonVirtual(); 365 413 convexHullShape->getNonvirtualAabb (t, aabbMin, aabbMax, margin); … … 378 426 btAssert (0); 379 427 } 428 429 #endif //__SPU__ -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btConvexTriangleMeshShape.h" 16 17 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" … … 21 22 22 23 btConvexTriangleMeshShape ::btConvexTriangleMeshShape (btStridingMeshInterface* meshInterface, bool calcAabb) 23 : btPolyhedralConvex Shape(), m_stridingMesh(meshInterface)24 : btPolyhedralConvexAabbCachingShape(), m_stridingMesh(meshInterface) 24 25 { 25 26 m_shapeType = CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE; … … 44 45 LocalSupportVertexCallback(const btVector3& supportVecLocal) 45 46 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), 46 m_maxDot(btScalar(- 1e30)),47 m_maxDot(btScalar(-BT_LARGE_FLOAT)), 47 48 m_supportVecLocal(supportVecLocal) 48 49 { … … 92 93 93 94 LocalSupportVertexCallback supportCallback(vec); 94 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));95 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 95 96 m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax); 96 97 supVec = supportCallback.GetSupportVertexLocal(); … … 105 106 for (int i=0;i<numVectors;i++) 106 107 { 107 supportVerticesOut[i][3] = btScalar(- 1e30);108 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 108 109 } 109 110 } … … 116 117 const btVector3& vec = vectors[j]; 117 118 LocalSupportVertexCallback supportCallback(vec); 118 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));119 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 119 120 m_stridingMesh->InternalProcessAllTriangles(&supportCallback,-aabbMax,aabbMax); 120 121 supportVerticesOut[j] = supportCallback.GetSupportVertexLocal(); … … 298 299 299 300 CenterCallback centerCallback; 300 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));301 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 301 302 m_stridingMesh->InternalProcessAllTriangles(¢erCallback, -aabbMax, aabbMax); 302 303 btVector3 center = centerCallback.getCenter(); -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h
r5781 r8351 1 /* 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 5 This software is provided 'as-is', without any express or implied warranty. 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 subject to the following restrictions: 10 11 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. 12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 13 3. This notice may not be removed or altered from any source distribution. 14 */ 1 15 #ifndef CONVEX_TRIANGLEMESH_SHAPE_H 2 16 #define CONVEX_TRIANGLEMESH_SHAPE_H … … 9 23 /// The btConvexTriangleMeshShape is a convex hull of a triangle mesh, but the performance is not as good as btConvexHullShape. 10 24 /// A small benefit of this class is that it uses the btStridingMeshInterface, so you can avoid the duplication of the triangle mesh data. Nevertheless, most users should use the much better performing btConvexHullShape instead. 11 class btConvexTriangleMeshShape : public btPolyhedralConvex Shape25 class btConvexTriangleMeshShape : public btPolyhedralConvexAabbCachingShape 12 26 { 13 27 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 #include "btCylinderShape.h" 16 17 17 18 btCylinderShape::btCylinderShape (const btVector3& halfExtents) 18 :bt BoxShape(halfExtents),19 :btConvexInternalShape(), 19 20 m_upAxis(1) 20 21 { 22 btVector3 margin(getMargin(),getMargin(),getMargin()); 23 m_implicitShapeDimensions = (halfExtents * m_localScaling) - margin; 21 24 m_shapeType = CYLINDER_SHAPE_PROXYTYPE; 22 recalcLocalAabb();23 25 } 24 26 … … 28 30 { 29 31 m_upAxis = 0; 30 recalcLocalAabb(); 32 31 33 } 32 34 … … 36 38 { 37 39 m_upAxis = 2; 38 recalcLocalAabb(); 40 39 41 } 40 42 41 43 void btCylinderShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const 42 44 { 43 //skip the box 'getAabb' 44 btPolyhedralConvexShape::getAabb(t,aabbMin,aabbMax); 45 btTransformAabb(getHalfExtentsWithoutMargin(),getMargin(),t,aabbMin,aabbMax); 46 } 47 48 void btCylinderShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const 49 { 50 //approximation of box shape, todo: implement cylinder shape inertia before people notice ;-) 51 btVector3 halfExtents = getHalfExtentsWithMargin(); 52 53 btScalar lx=btScalar(2.)*(halfExtents.x()); 54 btScalar ly=btScalar(2.)*(halfExtents.y()); 55 btScalar lz=btScalar(2.)*(halfExtents.z()); 56 57 inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz), 58 mass/(btScalar(12.0)) * (lx*lx + lz*lz), 59 mass/(btScalar(12.0)) * (lx*lx + ly*ly)); 60 45 61 } 46 62 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btCylinderShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 22 22 23 23 /// The btCylinderShape class implements a cylinder shape primitive, centered around the origin. Its central axis aligned with the Y axis. btCylinderShapeX is aligned with the X axis and btCylinderShapeZ around the Z axis. 24 class btCylinderShape : public bt BoxShape24 class btCylinderShape : public btConvexInternalShape 25 25 26 26 { … … 31 31 32 32 public: 33 34 btVector3 getHalfExtentsWithMargin() const 35 { 36 btVector3 halfExtents = getHalfExtentsWithoutMargin(); 37 btVector3 margin(getMargin(),getMargin(),getMargin()); 38 halfExtents += margin; 39 return halfExtents; 40 } 41 42 const btVector3& getHalfExtentsWithoutMargin() const 43 { 44 return m_implicitShapeDimensions;//changed in Bullet 2.63: assume the scaling and margin are included 45 } 46 33 47 btCylinderShape (const btVector3& halfExtents); 34 48 35 ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version36 49 void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 37 50 51 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 52 38 53 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; 39 54 40 55 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 56 57 virtual void setMargin(btScalar collisionMargin) 58 { 59 //correct the m_implicitShapeDimensions for the margin 60 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 61 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 62 63 btConvexInternalShape::setMargin(collisionMargin); 64 btVector3 newMargin(getMargin(),getMargin(),getMargin()); 65 m_implicitShapeDimensions = implicitShapeDimensionsWithMargin - newMargin; 66 67 } 41 68 42 69 virtual btVector3 localGetSupportingVertex(const btVector3& vec) const … … 74 101 } 75 102 103 virtual void setLocalScaling(const btVector3& scaling) 104 { 105 btVector3 oldMargin(getMargin(),getMargin(),getMargin()); 106 btVector3 implicitShapeDimensionsWithMargin = m_implicitShapeDimensions+oldMargin; 107 btVector3 unScaledImplicitShapeDimensionsWithMargin = implicitShapeDimensionsWithMargin / m_localScaling; 108 109 btConvexInternalShape::setLocalScaling(scaling); 110 111 m_implicitShapeDimensions = (unScaledImplicitShapeDimensionsWithMargin * m_localScaling) - oldMargin; 112 113 } 114 76 115 //debugging 77 116 virtual const char* getName()const … … 80 119 } 81 120 82 121 virtual int calculateSerializeBufferSize() const; 122 123 ///fills the dataBuffer and returns the struct name (and 0 on failure) 124 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 83 125 84 126 }; … … 113 155 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 114 156 115 virtual int getUpAxis() const116 {117 return 2;118 }119 157 //debugging 120 158 virtual const char* getName()const … … 130 168 }; 131 169 170 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 171 struct btCylinderShapeData 172 { 173 btConvexInternalShapeData m_convexInternalShapeData; 174 175 int m_upAxis; 176 177 char m_padding[4]; 178 }; 179 180 SIMD_FORCE_INLINE int btCylinderShape::calculateSerializeBufferSize() const 181 { 182 return sizeof(btCylinderShapeData); 183 } 184 185 ///fills the dataBuffer and returns the struct name (and 0 on failure) 186 SIMD_FORCE_INLINE const char* btCylinderShape::serialize(void* dataBuffer, btSerializer* serializer) const 187 { 188 btCylinderShapeData* shapeData = (btCylinderShapeData*) dataBuffer; 189 190 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData,serializer); 191 192 shapeData->m_upAxis = m_upAxis; 193 194 return "btCylinderShapeData"; 195 } 196 197 132 198 133 199 #endif //CYLINDER_MINKOWSKI_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btEmptyShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMaterial.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 33 33 34 34 #endif // MATERIAL_H 35 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "btMinkowskiSumShape.h" -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 14 14 */ 15 15 16 17 16 18 #include "btMultiSphereShape.h" 17 19 #include "BulletCollision/CollisionShapes/btCollisionMargin.h" 18 20 #include "LinearMath/btQuaternion.h" 21 #include "LinearMath/btSerializer.h" 19 22 20 btMultiSphereShape::btMultiSphereShape (const btVector3 & inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres)21 :btConvexInternal Shape (), m_inertiaHalfExtents(inertiaHalfExtents)23 btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres) 24 :btConvexInternalAabbCachingShape () 22 25 { 23 26 m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE; 24 btScalar startMargin = btScalar(1e30);27 //btScalar startMargin = btScalar(BT_LARGE_FLOAT); 25 28 26 m_numSpheres = numSpheres; 27 for (int i=0;i<m_numSpheres;i++) 29 m_localPositionArray.resize(numSpheres); 30 m_radiArray.resize(numSpheres); 31 for (int i=0;i<numSpheres;i++) 28 32 { 29 m_localPositions[i] = positions[i]; 30 m_radi[i] = radi[i]; 31 if (radi[i] < startMargin) 32 startMargin = radi[i]; 33 m_localPositionArray[i] = positions[i]; 34 m_radiArray[i] = radi[i]; 35 33 36 } 34 setMargin(startMargin); 37 38 recalcLocalAabb(); 35 39 36 40 } 37 38 39 41 40 42 … … 44 46 btVector3 supVec(0,0,0); 45 47 46 btScalar maxDot(btScalar(- 1e30));48 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 47 49 48 50 … … 61 63 btScalar newDot; 62 64 63 const btVector3* pos = &m_localPositions[0]; 64 const btScalar* rad = &m_radi[0]; 65 const btVector3* pos = &m_localPositionArray[0]; 66 const btScalar* rad = &m_radiArray[0]; 67 int numSpheres = m_localPositionArray.size(); 65 68 66 for (i=0;i< m_numSpheres;i++)69 for (i=0;i<numSpheres;i++) 67 70 { 68 71 vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin(); … … 86 89 for (int j=0;j<numVectors;j++) 87 90 { 88 btScalar maxDot(btScalar(- 1e30));91 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 89 92 90 93 const btVector3& vec = vectors[j]; … … 93 96 btScalar newDot; 94 97 95 const btVector3* pos = &m_localPosition s[0];96 const btScalar* rad = &m_radi [0];97 98 for (int i=0;i< m_numSpheres;i++)98 const btVector3* pos = &m_localPositionArray[0]; 99 const btScalar* rad = &m_radiArray[0]; 100 int numSpheres = m_localPositionArray.size(); 101 for (int i=0;i<numSpheres;i++) 99 102 { 100 103 vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin(); … … 122 125 //as an approximation, take the inertia of the box that bounds the spheres 123 126 124 bt Transform ident;125 ident.setIdentity();126 // btVector3 aabbMin,aabbMax;127 btVector3 localAabbMin,localAabbMax; 128 getCachedLocalAabb(localAabbMin,localAabbMax); 129 btVector3 halfExtents = (localAabbMax-localAabbMin)*btScalar(0.5); 127 130 128 // getAabb(ident,aabbMin,aabbMax); 131 btScalar lx=btScalar(2.)*(halfExtents.x()); 132 btScalar ly=btScalar(2.)*(halfExtents.y()); 133 btScalar lz=btScalar(2.)*(halfExtents.z()); 129 134 130 btVector3 halfExtents = m_inertiaHalfExtents;//(aabbMax - aabbMin)* btScalar(0.5); 131 132 btScalar margin = CONVEX_DISTANCE_MARGIN; 133 134 btScalar lx=btScalar(2.)*(halfExtents[0]+margin); 135 btScalar ly=btScalar(2.)*(halfExtents[1]+margin); 136 btScalar lz=btScalar(2.)*(halfExtents[2]+margin); 137 const btScalar x2 = lx*lx; 138 const btScalar y2 = ly*ly; 139 const btScalar z2 = lz*lz; 140 const btScalar scaledmass = mass * btScalar(.08333333); 141 142 inertia[0] = scaledmass * (y2+z2); 143 inertia[1] = scaledmass * (x2+z2); 144 inertia[2] = scaledmass * (x2+y2); 135 inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz), 136 mass/(btScalar(12.0)) * (lx*lx + lz*lz), 137 mass/(btScalar(12.0)) * (lx*lx + ly*ly)); 145 138 146 139 } 147 140 148 141 142 ///fills the dataBuffer and returns the struct name (and 0 on failure) 143 const char* btMultiSphereShape::serialize(void* dataBuffer, btSerializer* serializer) const 144 { 145 btMultiSphereShapeData* shapeData = (btMultiSphereShapeData*) dataBuffer; 146 btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer); 149 147 148 int numElem = m_localPositionArray.size(); 149 shapeData->m_localPositionArrayPtr = numElem ? (btPositionAndRadius*)serializer->getUniquePointer((void*)&m_localPositionArray[0]): 0; 150 151 shapeData->m_localPositionArraySize = numElem; 152 if (numElem) 153 { 154 btChunk* chunk = serializer->allocate(sizeof(btPositionAndRadius),numElem); 155 btPositionAndRadius* memPtr = (btPositionAndRadius*)chunk->m_oldPtr; 156 for (int i=0;i<numElem;i++,memPtr++) 157 { 158 m_localPositionArray[i].serializeFloat(memPtr->m_pos); 159 memPtr->m_radius = float(m_radiArray[i]); 160 } 161 serializer->finalizeChunk(chunk,"btPositionAndRadius",BT_ARRAY_CODE,(void*)&m_localPositionArray[0]); 162 } 163 164 return "btMultiSphereShapeData"; 165 } 166 167 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 19 19 #include "btConvexInternalShape.h" 20 20 #include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" // for the types 21 22 #define MAX_NUM_SPHERES 5 23 24 ///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes. 25 ///It is possible to animate the spheres for deformation. 26 class btMultiSphereShape : public btConvexInternalShape 27 28 { 29 30 btVector3 m_localPositions[MAX_NUM_SPHERES]; 31 btScalar m_radi[MAX_NUM_SPHERES]; 32 btVector3 m_inertiaHalfExtents; 33 34 int m_numSpheres; 35 21 #include "LinearMath/btAlignedObjectArray.h" 22 #include "LinearMath/btAabbUtil2.h" 36 23 37 24 38 25 26 ///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes. 27 ///It is possible to animate the spheres for deformation, but call 'recalcLocalAabb' after changing any sphere position/radius 28 class btMultiSphereShape : public btConvexInternalAabbCachingShape 29 { 30 31 btAlignedObjectArray<btVector3> m_localPositionArray; 32 btAlignedObjectArray<btScalar> m_radiArray; 33 39 34 public: 40 btMultiSphereShape (const btVector3 & inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres);35 btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres); 41 36 42 37 ///CollisionShape Interface … … 50 45 int getSphereCount() const 51 46 { 52 return m_ numSpheres;47 return m_localPositionArray.size(); 53 48 } 54 49 55 50 const btVector3& getSpherePosition(int index) const 56 51 { 57 return m_localPosition s[index];52 return m_localPositionArray[index]; 58 53 } 59 54 60 55 btScalar getSphereRadius(int index) const 61 56 { 62 return m_radi [index];57 return m_radiArray[index]; 63 58 } 64 59 … … 69 64 } 70 65 66 virtual int calculateSerializeBufferSize() const; 67 68 ///fills the dataBuffer and returns the struct name (and 0 on failure) 69 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 70 71 71 72 }; 72 73 73 74 75 struct btPositionAndRadius 76 { 77 btVector3FloatData m_pos; 78 float m_radius; 79 }; 80 81 struct btMultiSphereShapeData 82 { 83 btConvexInternalShapeData m_convexInternalShapeData; 84 85 btPositionAndRadius *m_localPositionArrayPtr; 86 int m_localPositionArraySize; 87 char m_padding[4]; 88 }; 89 90 91 92 SIMD_FORCE_INLINE int btMultiSphereShape::calculateSerializeBufferSize() const 93 { 94 return sizeof(btMultiSphereShapeData); 95 } 96 97 98 74 99 #endif //MULTI_SPHERE_MINKOWSKI_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btMultimaterialTriangleMeshShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 38 38 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 39 39 40 btVector3 m_triangle[3];41 40 const unsigned char *vertexbase; 42 41 int numverts; … … 72 71 m_shapeType = MULTIMATERIAL_TRIANGLE_MESH_PROXYTYPE; 73 72 74 btVector3 m_triangle[3];75 73 const unsigned char *vertexbase; 76 74 int numverts; -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 14 14 */ 15 15 16 16 17 #include "btOptimizedBvh.h" 17 18 #include "btStridingMeshInterface.h" … … 56 57 btOptimizedBvhNode node; 57 58 btVector3 aabbMin,aabbMax; 58 aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));59 aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));59 aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 60 aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 60 61 aabbMin.setMin(triangle[0]); 61 62 aabbMax.setMax(triangle[0]); … … 104 105 btQuantizedBvhNode node; 105 106 btVector3 aabbMin,aabbMax; 106 aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));107 aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));107 aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 108 aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 108 109 aabbMin.setMin(triangle[0]); 109 110 aabbMax.setMax(triangle[0]); … … 168 169 NodeTriangleCallback callback(m_leafNodes); 169 170 170 btVector3 aabbMin(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));171 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));171 btVector3 aabbMin(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 172 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 172 173 173 174 triangles->InternalProcessAllTriangles(&callback,aabbMin,aabbMax); … … 337 338 338 339 339 aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));340 aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));340 aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 341 aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 341 342 aabbMin.setMin(triangleVerts[0]); 342 343 aabbMax.setMax(triangleVerts[0]); -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 ///Contains contributions from Disney Studio's 15 17 16 18 #ifndef OPTIMIZED_BVH_H … … 46 48 47 49 /// Data buffer MUST be 16 byte aligned 48 virtual bool serialize (void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian)50 virtual bool serializeInPlace(void *o_alignedDataBuffer, unsigned i_dataBufferSize, bool i_swapEndian) const 49 51 { 50 52 return btQuantizedBvh::serialize(o_alignedDataBuffer,i_dataBufferSize,i_swapEndian); -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 16 16 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 17 17 18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(), 19 m_localAabbMin(1,1,1), 20 m_localAabbMax(-1,-1,-1), 21 m_isLocalAabbValid(false), 22 m_optionalHull(0) 18 btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape() 23 19 { 24 20 … … 28 24 btVector3 btPolyhedralConvexShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const 29 25 { 26 27 28 btVector3 supVec(0,0,0); 29 #ifndef __SPU__ 30 30 int i; 31 btVector3 supVec(0,0,0); 32 33 btScalar maxDot(btScalar(-1e30)); 31 btScalar maxDot(btScalar(-BT_LARGE_FLOAT)); 34 32 35 33 btVector3 vec = vec0; … … 58 56 } 59 57 58 59 #endif //__SPU__ 60 60 return supVec; 61 } 61 62 62 } 63 63 64 64 65 void btPolyhedralConvexShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const 65 66 { 67 #ifndef __SPU__ 66 68 int i; 67 69 … … 71 73 for (i=0;i<numVectors;i++) 72 74 { 73 supportVerticesOut[i][3] = btScalar(- 1e30);75 supportVerticesOut[i][3] = btScalar(-BT_LARGE_FLOAT); 74 76 } 75 77 … … 91 93 } 92 94 } 95 #endif //__SPU__ 93 96 } 94 97 … … 97 100 void btPolyhedralConvexShape::calculateLocalInertia(btScalar mass,btVector3& inertia) const 98 101 { 102 #ifndef __SPU__ 99 103 //not yet, return box inertia 100 104 … … 116 120 117 121 inertia = scaledmass * (btVector3(y2+z2,x2+z2,x2+y2)); 118 122 #endif //__SPU__ 119 123 } 120 124 121 125 122 126 123 void btPolyhedralConvexShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 124 { 125 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 126 } 127 128 129 130 void btPolyhedralConvexShape::setLocalScaling(const btVector3& scaling) 127 void btPolyhedralConvexAabbCachingShape::setLocalScaling(const btVector3& scaling) 131 128 { 132 129 btConvexInternalShape::setLocalScaling(scaling); … … 134 131 } 135 132 136 void btPolyhedralConvexShape::recalcLocalAabb() 133 btPolyhedralConvexAabbCachingShape::btPolyhedralConvexAabbCachingShape() 134 :btPolyhedralConvexShape(), 135 m_localAabbMin(1,1,1), 136 m_localAabbMax(-1,-1,-1), 137 m_isLocalAabbValid(false) 138 { 139 } 140 141 void btPolyhedralConvexAabbCachingShape::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const 142 { 143 getNonvirtualAabb(trans,aabbMin,aabbMax,getMargin()); 144 } 145 146 void btPolyhedralConvexAabbCachingShape::recalcLocalAabb() 137 147 { 138 148 m_isLocalAabbValid = true; … … 182 192 } 183 193 184 185 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 18 18 19 19 #include "LinearMath/btMatrix3x3.h" 20 #include "LinearMath/btAabbUtil2.h"21 20 #include "btConvexInternalShape.h" 22 21 … … 27 26 28 27 protected: 29 btVector3 m_localAabbMin; 30 btVector3 m_localAabbMax; 31 bool m_isLocalAabbValid; 32 28 33 29 public: 34 30 … … 39 35 virtual btVector3 localGetSupportingVertexWithoutMargin(const btVector3& vec)const; 40 36 virtual void batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const; 41 42 37 43 38 virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; 39 40 41 virtual int getNumVertices() const = 0 ; 42 virtual int getNumEdges() const = 0; 43 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0; 44 virtual void getVertex(int i,btVector3& vtx) const = 0; 45 virtual int getNumPlanes() const = 0; 46 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0; 47 // virtual int getIndex(int i) const = 0 ; 44 48 49 virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0; 50 51 }; 52 53 54 ///The btPolyhedralConvexAabbCachingShape adds aabb caching to the btPolyhedralConvexShape 55 class btPolyhedralConvexAabbCachingShape : public btPolyhedralConvexShape 56 { 57 58 btVector3 m_localAabbMin; 59 btVector3 m_localAabbMax; 60 bool m_isLocalAabbValid; 61 62 protected: 45 63 46 64 void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax) … … 58 76 } 59 77 78 public: 79 80 btPolyhedralConvexAabbCachingShape(); 81 60 82 inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const 61 83 { … … 66 88 } 67 89 68 90 virtual void setLocalScaling(const btVector3& scaling); 91 69 92 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 70 93 71 virtual void setLocalScaling(const btVector3& scaling);72 73 94 void recalcLocalAabb(); 74 75 virtual int getNumVertices() const = 0 ;76 virtual int getNumEdges() const = 0;77 virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0;78 virtual void getVertex(int i,btVector3& vtx) const = 0;79 virtual int getNumPlanes() const = 0;80 virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0;81 // virtual int getIndex(int i) const = 0 ;82 83 virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0;84 85 /// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp86 class Hull* m_optionalHull;87 95 88 96 }; -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "btScaledBvhTriangleMeshShape.h" -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.cpp
r5781 r8351 1 1 /* 2 btbtShapeHull implemented by John McCutchan.3 4 2 Bullet Continuous Collision Detection and Physics Library 5 Copyright (c) 2003-200 8 Erwin Coumans http://bulletphysics.com3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 6 4 7 5 This software is provided 'as-is', without any express or implied warranty. 8 6 In no event will the authors be held liable for any damages arising from the use of this software. 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 11 9 subject to the following restrictions: 12 10 … … 16 14 */ 17 15 16 //btShapeHull was implemented by John McCutchan. 17 18 18 19 #include "btShapeHull.h" 19 20 #include "LinearMath/btConvexHull.h" 20 21 21 22 #define NUM_UNITSPHERE_POINTS 42 22 23 static btVector3 btUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =24 {25 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),26 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),27 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),28 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),29 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),30 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),31 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),32 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),33 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),34 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),35 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),36 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),37 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),38 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),39 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),40 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),41 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),42 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),43 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),44 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),45 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),46 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),47 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),48 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),49 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),50 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),51 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),52 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),53 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),54 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),55 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),56 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),57 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),58 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),59 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),60 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),61 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),62 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),63 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),64 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),65 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),66 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))67 };68 23 69 24 btShapeHull::btShapeHull (const btConvexShape* shape) … … 93 48 btVector3 norm; 94 49 m_shape->getPreferredPenetrationDirection(i,norm); 95 btUnitSpherePoints[numSampleDirections] = norm;50 getUnitSpherePoints()[numSampleDirections] = norm; 96 51 numSampleDirections++; 97 52 } … … 103 58 for (i = 0; i < numSampleDirections; i++) 104 59 { 105 supportPoints[i] = m_shape->localGetSupportingVertex( btUnitSpherePoints[i]);60 supportPoints[i] = m_shape->localGetSupportingVertex(getUnitSpherePoints()[i]); 106 61 } 107 62 … … 163 118 } 164 119 120 121 btVector3* btShapeHull::getUnitSpherePoints() 122 { 123 static btVector3 sUnitSpherePoints[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = 124 { 125 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)), 126 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)), 127 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)), 128 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)), 129 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)), 130 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)), 131 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)), 132 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)), 133 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)), 134 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)), 135 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)), 136 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)), 137 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)), 138 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)), 139 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)), 140 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)), 141 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)), 142 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)), 143 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)), 144 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)), 145 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)), 146 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)), 147 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)), 148 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)), 149 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)), 150 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)), 151 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)), 152 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)), 153 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)), 154 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)), 155 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)), 156 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)), 157 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)), 158 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)), 159 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)), 160 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)), 161 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)), 162 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)), 163 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)), 164 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)), 165 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)), 166 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654)) 167 }; 168 return sUnitSpherePoints; 169 } 170 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btShapeHull.h
r5781 r8351 1 1 /* 2 btShapeHull implemented by John McCutchan.3 4 2 Bullet Continuous Collision Detection and Physics Library 5 Copyright (c) 2003-200 8 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 6 4 7 5 This software is provided 'as-is', without any express or implied warranty. 8 6 In no event will the authors be held liable for any damages arising from the use of this software. 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 11 9 subject to the following restrictions: 12 10 … … 15 13 3. This notice may not be removed or altered from any source distribution. 16 14 */ 15 16 ///btShapeHull implemented by John McCutchan. 17 17 18 18 #ifndef _SHAPE_HULL_H … … 28 28 class btShapeHull 29 29 { 30 protected: 31 32 btAlignedObjectArray<btVector3> m_vertices; 33 btAlignedObjectArray<unsigned int> m_indices; 34 unsigned int m_numIndices; 35 const btConvexShape* m_shape; 36 37 static btVector3* getUnitSpherePoints(); 38 30 39 public: 31 40 btShapeHull (const btConvexShape* shape); … … 46 55 return &m_indices[0]; 47 56 } 48 49 protected:50 btAlignedObjectArray<btVector3> m_vertices;51 btAlignedObjectArray<unsigned int> m_indices;52 unsigned int m_numIndices;53 const btConvexShape* m_shape;54 57 }; 55 58 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btSphereShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 #ifndef SPHERE_MINKOWSKI_H 17 16 #define SPHERE_MINKOWSKI_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 39 39 (void)t; 40 40 /* 41 btVector3 infvec (btScalar( 1e30),btScalar(1e30),btScalar(1e30));41 btVector3 infvec (btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 42 42 43 43 btVector3 center = m_planeNormal*m_planeConstant; … … 48 48 */ 49 49 50 aabbMin.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));51 aabbMax.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));50 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 51 aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 52 52 53 53 } -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStaticPlaneShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 21 21 22 22 ///The btStaticPlaneShape simulates an infinite non-moving (static) collision plane. 23 classbtStaticPlaneShape : public btConcaveShape23 ATTRIBUTE_ALIGNED16(class) btStaticPlaneShape : public btConcaveShape 24 24 { 25 25 protected: … … 59 59 virtual const char* getName()const {return "STATICPLANE";} 60 60 61 virtual int calculateSerializeBufferSize() const; 62 63 ///fills the dataBuffer and returns the struct name (and 0 on failure) 64 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 65 61 66 62 67 }; 63 68 69 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 70 struct btStaticPlaneShapeData 71 { 72 btCollisionShapeData m_collisionShapeData; 73 74 btVector3FloatData m_localScaling; 75 btVector3FloatData m_planeNormal; 76 float m_planeConstant; 77 char m_pad[4]; 78 }; 79 80 81 SIMD_FORCE_INLINE int btStaticPlaneShape::calculateSerializeBufferSize() const 82 { 83 return sizeof(btStaticPlaneShapeData); 84 } 85 86 ///fills the dataBuffer and returns the struct name (and 0 on failure) 87 SIMD_FORCE_INLINE const char* btStaticPlaneShape::serialize(void* dataBuffer, btSerializer* serializer) const 88 { 89 btStaticPlaneShapeData* planeData = (btStaticPlaneShapeData*) dataBuffer; 90 btCollisionShape::serialize(&planeData->m_collisionShapeData,serializer); 91 92 m_localScaling.serializeFloat(planeData->m_localScaling); 93 m_planeNormal.serializeFloat(planeData->m_planeNormal); 94 planeData->m_planeConstant = float(m_planeConstant); 95 96 return "btStaticPlaneShapeData"; 97 } 98 99 64 100 #endif //STATIC_PLANE_SHAPE_H 101 102 103 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 15 15 16 16 #include "btStridingMeshInterface.h" 17 #include "LinearMath/btSerializer.h" 17 18 18 19 btStridingMeshInterface::~btStridingMeshInterface() … … 36 37 int gfxindex; 37 38 btVector3 triangle[3]; 38 btScalar* graphicsbase;39 39 40 40 btVector3 meshScaling = getScaling(); … … 46 46 numtotalphysicsverts+=numtriangles*3; //upper bound 47 47 48 switch (gfxindextype) 48 ///unlike that developers want to pass in double-precision meshes in single-precision Bullet build 49 ///so disable this feature by default 50 ///see patch http://code.google.com/p/bullet/issues/detail?id=213 51 52 switch (type) 49 53 { 50 case PHY_INTEGER: 54 case PHY_FLOAT: 55 { 56 57 float* graphicsbase; 58 59 switch (gfxindextype) 60 { 61 case PHY_INTEGER: 62 { 63 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 64 { 65 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 66 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride); 67 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 68 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride); 69 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 70 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride); 71 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 72 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 73 } 74 break; 75 } 76 case PHY_SHORT: 77 { 78 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 79 { 80 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 81 graphicsbase = (float*)(vertexbase+tri_indices[0]*stride); 82 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 83 graphicsbase = (float*)(vertexbase+tri_indices[1]*stride); 84 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 85 graphicsbase = (float*)(vertexbase+tri_indices[2]*stride); 86 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 87 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 88 } 89 break; 90 } 91 default: 92 btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT)); 93 } 94 break; 95 } 96 97 case PHY_DOUBLE: 51 98 { 52 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 53 { 54 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 55 graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); 56 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 57 graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); 58 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 59 graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride); 60 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 61 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 62 } 63 break; 64 } 65 case PHY_SHORT: 66 { 67 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 68 { 69 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 70 graphicsbase = (btScalar*)(vertexbase+tri_indices[0]*stride); 71 triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ()); 72 graphicsbase = (btScalar*)(vertexbase+tri_indices[1]*stride); 73 triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 74 graphicsbase = (btScalar*)(vertexbase+tri_indices[2]*stride); 75 triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ()); 76 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 99 double* graphicsbase; 100 101 switch (gfxindextype) 102 { 103 case PHY_INTEGER: 104 { 105 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 106 { 107 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 108 graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); 109 triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); 110 graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); 111 triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 112 graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); 113 triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 114 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 115 } 116 break; 117 } 118 case PHY_SHORT: 119 { 120 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 121 { 122 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 123 graphicsbase = (double*)(vertexbase+tri_indices[0]*stride); 124 triangle[0].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(),(btScalar)graphicsbase[2]*meshScaling.getZ()); 125 graphicsbase = (double*)(vertexbase+tri_indices[1]*stride); 126 triangle[1].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 127 graphicsbase = (double*)(vertexbase+tri_indices[2]*stride); 128 triangle[2].setValue((btScalar)graphicsbase[0]*meshScaling.getX(),(btScalar)graphicsbase[1]*meshScaling.getY(), (btScalar)graphicsbase[2]*meshScaling.getZ()); 129 callback->internalProcessTriangleIndex(triangle,part,gfxindex); 130 } 131 break; 132 } 133 default: 134 btAssert((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT)); 77 135 } 78 136 break; 79 137 } 80 138 default: 81 btAssert(( gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));139 btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE)); 82 140 } 83 141 … … 96 154 AabbCalculationCallback() 97 155 { 98 m_aabbMin.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));99 m_aabbMax.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));156 m_aabbMin.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 157 m_aabbMax.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 100 158 } 101 159 … … 114 172 }; 115 173 116 174 //first calculate the total aabb for all triangles 117 175 AabbCalculationCallback aabbCallback; 118 aabbMin.setValue(btScalar(- 1e30),btScalar(-1e30),btScalar(-1e30));119 aabbMax.setValue(btScalar( 1e30),btScalar(1e30),btScalar(1e30));176 aabbMin.setValue(btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT),btScalar(-BT_LARGE_FLOAT)); 177 aabbMax.setValue(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 120 178 InternalProcessAllTriangles(&aabbCallback,aabbMin,aabbMax); 121 179 … … 123 181 aabbMax = aabbCallback.m_aabbMax; 124 182 } 183 184 185 186 ///fills the dataBuffer and returns the struct name (and 0 on failure) 187 const char* btStridingMeshInterface::serialize(void* dataBuffer, btSerializer* serializer) const 188 { 189 btStridingMeshInterfaceData* trimeshData = (btStridingMeshInterfaceData*) dataBuffer; 190 191 trimeshData->m_numMeshParts = getNumSubParts(); 192 193 //void* uniquePtr = 0; 194 195 trimeshData->m_meshPartsPtr = 0; 196 197 if (trimeshData->m_numMeshParts) 198 { 199 btChunk* chunk = serializer->allocate(sizeof(btMeshPartData),trimeshData->m_numMeshParts); 200 btMeshPartData* memPtr = (btMeshPartData*)chunk->m_oldPtr; 201 trimeshData->m_meshPartsPtr = (btMeshPartData *)serializer->getUniquePointer(memPtr); 202 203 204 // int numtotalphysicsverts = 0; 205 int part,graphicssubparts = getNumSubParts(); 206 const unsigned char * vertexbase; 207 const unsigned char * indexbase; 208 int indexstride; 209 PHY_ScalarType type; 210 PHY_ScalarType gfxindextype; 211 int stride,numverts,numtriangles; 212 int gfxindex; 213 // btVector3 triangle[3]; 214 215 btVector3 meshScaling = getScaling(); 216 217 ///if the number of parts is big, the performance might drop due to the innerloop switch on indextype 218 for (part=0;part<graphicssubparts ;part++,memPtr++) 219 { 220 getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part); 221 memPtr->m_numTriangles = numtriangles;//indices = 3*numtriangles 222 memPtr->m_numVertices = numverts; 223 memPtr->m_indices16 = 0; 224 memPtr->m_indices32 = 0; 225 memPtr->m_3indices16 = 0; 226 memPtr->m_vertices3f = 0; 227 memPtr->m_vertices3d = 0; 228 229 switch (gfxindextype) 230 { 231 case PHY_INTEGER: 232 { 233 int numindices = numtriangles*3; 234 235 if (numindices) 236 { 237 btChunk* chunk = serializer->allocate(sizeof(btIntIndexData),numindices); 238 btIntIndexData* tmpIndices = (btIntIndexData*)chunk->m_oldPtr; 239 memPtr->m_indices32 = (btIntIndexData*)serializer->getUniquePointer(tmpIndices); 240 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 241 { 242 unsigned int* tri_indices= (unsigned int*)(indexbase+gfxindex*indexstride); 243 tmpIndices[gfxindex*3].m_value = tri_indices[0]; 244 tmpIndices[gfxindex*3+1].m_value = tri_indices[1]; 245 tmpIndices[gfxindex*3+2].m_value = tri_indices[2]; 246 } 247 serializer->finalizeChunk(chunk,"btIntIndexData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 248 } 249 break; 250 } 251 case PHY_SHORT: 252 { 253 if (numtriangles) 254 { 255 btChunk* chunk = serializer->allocate(sizeof(btShortIntIndexTripletData),numtriangles); 256 btShortIntIndexTripletData* tmpIndices = (btShortIntIndexTripletData*)chunk->m_oldPtr; 257 memPtr->m_3indices16 = (btShortIntIndexTripletData*) serializer->getUniquePointer(tmpIndices); 258 for (gfxindex=0;gfxindex<numtriangles;gfxindex++) 259 { 260 unsigned short int* tri_indices= (unsigned short int*)(indexbase+gfxindex*indexstride); 261 tmpIndices[gfxindex].m_values[0] = tri_indices[0]; 262 tmpIndices[gfxindex].m_values[1] = tri_indices[1]; 263 tmpIndices[gfxindex].m_values[2] = tri_indices[2]; 264 } 265 serializer->finalizeChunk(chunk,"btShortIntIndexTripletData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 266 } 267 break; 268 } 269 default: 270 { 271 btAssert(0); 272 //unknown index type 273 } 274 } 275 276 switch (type) 277 { 278 case PHY_FLOAT: 279 { 280 float* graphicsbase; 281 282 if (numverts) 283 { 284 btChunk* chunk = serializer->allocate(sizeof(btVector3FloatData),numverts); 285 btVector3FloatData* tmpVertices = (btVector3FloatData*) chunk->m_oldPtr; 286 memPtr->m_vertices3f = (btVector3FloatData *)serializer->getUniquePointer(tmpVertices); 287 for (int i=0;i<numverts;i++) 288 { 289 graphicsbase = (float*)(vertexbase+i*stride); 290 tmpVertices[i].m_floats[0] = graphicsbase[0]; 291 tmpVertices[i].m_floats[1] = graphicsbase[1]; 292 tmpVertices[i].m_floats[2] = graphicsbase[2]; 293 } 294 serializer->finalizeChunk(chunk,"btVector3FloatData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 295 } 296 break; 297 } 298 299 case PHY_DOUBLE: 300 { 301 if (numverts) 302 { 303 btChunk* chunk = serializer->allocate(sizeof(btVector3DoubleData),numverts); 304 btVector3DoubleData* tmpVertices = (btVector3DoubleData*) chunk->m_oldPtr; 305 memPtr->m_vertices3d = (btVector3DoubleData *) serializer->getUniquePointer(tmpVertices); 306 for (int i=0;i<numverts;i++) 307 { 308 double* graphicsbase = (double*)(vertexbase+i*stride);//for now convert to float, might leave it at double 309 tmpVertices[i].m_floats[0] = graphicsbase[0]; 310 tmpVertices[i].m_floats[1] = graphicsbase[1]; 311 tmpVertices[i].m_floats[2] = graphicsbase[2]; 312 } 313 serializer->finalizeChunk(chunk,"btVector3DoubleData",BT_ARRAY_CODE,(void*)chunk->m_oldPtr); 314 } 315 break; 316 } 317 318 default: 319 btAssert((type == PHY_FLOAT) || (type == PHY_DOUBLE)); 320 } 321 322 unLockReadOnlyVertexBase(part); 323 } 324 325 serializer->finalizeChunk(chunk,"btMeshPartData",BT_ARRAY_CODE,chunk->m_oldPtr); 326 } 327 328 329 m_scaling.serializeFloat(trimeshData->m_scaling); 330 return "btStridingMeshInterfaceData"; 331 } -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "btTriangleCallback.h" 21 21 #include "btConcaveShape.h" 22 23 22 24 23 25 … … 90 92 } 91 93 92 94 virtual int calculateSerializeBufferSize() const; 95 96 ///fills the dataBuffer and returns the struct name (and 0 on failure) 97 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 98 93 99 94 100 }; 95 101 102 struct btIntIndexData 103 { 104 int m_value; 105 }; 106 107 struct btShortIntIndexData 108 { 109 short m_value; 110 char m_pad[2]; 111 }; 112 113 struct btShortIntIndexTripletData 114 { 115 short m_values[3]; 116 char m_pad[2]; 117 }; 118 119 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 120 struct btMeshPartData 121 { 122 btVector3FloatData *m_vertices3f; 123 btVector3DoubleData *m_vertices3d; 124 125 btIntIndexData *m_indices32; 126 btShortIntIndexTripletData *m_3indices16; 127 128 btShortIntIndexData *m_indices16;//backwards compatibility 129 130 int m_numTriangles;//length of m_indices = m_numTriangles 131 int m_numVertices; 132 }; 133 134 135 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 136 struct btStridingMeshInterfaceData 137 { 138 btMeshPartData *m_meshPartsPtr; 139 btVector3FloatData m_scaling; 140 int m_numMeshParts; 141 char m_padding[4]; 142 }; 143 144 145 146 147 SIMD_FORCE_INLINE int btStridingMeshInterface::calculateSerializeBufferSize() const 148 { 149 return sizeof(btStridingMeshInterfaceData); 150 } 151 152 153 96 154 #endif //STRIDING_MESHINTERFACE_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp
r5781 r8351 1 2 1 /* 3 2 Bullet Continuous Collision Detection and Physics Library 4 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 5 4 6 5 This software is provided 'as-is', without any express or implied warranty. … … 14 13 3. This notice may not be removed or altered from any source distribution. 15 14 */ 15 16 16 #include "btTetrahedronShape.h" 17 17 #include "LinearMath/btMatrix3x3.h" 18 18 19 btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvex Shape (),20 m_numVertices(0) 21 { 22 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 23 } 24 25 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvex Shape (),26 m_numVertices(0) 27 { 28 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 29 addVertex(pt0); 30 } 31 32 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvex Shape (),19 btBU_Simplex1to4::btBU_Simplex1to4() : btPolyhedralConvexAabbCachingShape (), 20 m_numVertices(0) 21 { 22 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 23 } 24 25 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexAabbCachingShape (), 26 m_numVertices(0) 27 { 28 m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE; 29 addVertex(pt0); 30 } 31 32 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexAabbCachingShape (), 33 33 m_numVertices(0) 34 34 { … … 38 38 } 39 39 40 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvex Shape (),40 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexAabbCachingShape (), 41 41 m_numVertices(0) 42 42 { … … 47 47 } 48 48 49 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvex Shape (),49 btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexAabbCachingShape (), 50 50 m_numVertices(0) 51 51 { … … 58 58 59 59 60 void btBU_Simplex1to4::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const 61 { 62 #if 1 63 btPolyhedralConvexAabbCachingShape::getAabb(t,aabbMin,aabbMax); 64 #else 65 aabbMin.setValue(BT_LARGE_FLOAT,BT_LARGE_FLOAT,BT_LARGE_FLOAT); 66 aabbMax.setValue(-BT_LARGE_FLOAT,-BT_LARGE_FLOAT,-BT_LARGE_FLOAT); 67 68 //just transform the vertices in worldspace, and take their AABB 69 for (int i=0;i<m_numVertices;i++) 70 { 71 btVector3 worldVertex = t(m_vertices[i]); 72 aabbMin.setMin(worldVertex); 73 aabbMax.setMax(worldVertex); 74 } 75 #endif 76 } 77 78 60 79 61 80 … … 64 83 { 65 84 m_vertices[m_numVertices++] = pt; 66 67 85 recalcLocalAabb(); 68 86 } -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 23 23 24 24 ///The btBU_Simplex1to4 implements tetrahedron, triangle, line, vertex collision shapes. In most cases it is better to use btConvexHullShape instead. 25 class btBU_Simplex1to4 : public btPolyhedralConvex Shape25 class btBU_Simplex1to4 : public btPolyhedralConvexAabbCachingShape 26 26 { 27 27 protected: … … 44 44 } 45 45 46 46 virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const; 47 47 48 48 void addVertex(const btVector3& pt); -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleCallback.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. 6 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 9 subject to the following restrictions: 10 10 … … 45 45 numverts = mesh.m_numVertices; 46 46 (*vertexbase) = (unsigned char *) mesh.m_vertexBase; 47 #ifdef BT_USE_DOUBLE_PRECISION 48 type = PHY_DOUBLE; 49 #else 50 type = PHY_FLOAT; 51 #endif 47 48 type = mesh.m_vertexType; 49 52 50 vertexStride = mesh.m_vertexStride; 53 51 … … 65 63 numverts = mesh.m_numVertices; 66 64 (*vertexbase) = (const unsigned char *)mesh.m_vertexBase; 67 #ifdef BT_USE_DOUBLE_PRECISION 68 type = PHY_DOUBLE; 69 #else 70 type = PHY_FLOAT; 71 #endif 65 66 type = mesh.m_vertexType; 67 72 68 vertexStride = mesh.m_vertexStride; 73 69 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 28 28 BT_DECLARE_ALIGNED_ALLOCATOR(); 29 29 30 int m_numTriangles; 31 const unsigned char * m_triangleIndexBase; 32 int m_triangleIndexStride; 33 int m_numVertices; 34 const unsigned char * m_vertexBase; 35 int m_vertexStride; 36 // The index type is set when adding an indexed mesh to the 37 // btTriangleIndexVertexArray, do not set it manually 38 PHY_ScalarType m_indexType; 39 int pad; 30 int m_numTriangles; 31 const unsigned char * m_triangleIndexBase; 32 int m_triangleIndexStride; 33 int m_numVertices; 34 const unsigned char * m_vertexBase; 35 int m_vertexStride; 36 37 // The index type is set when adding an indexed mesh to the 38 // btTriangleIndexVertexArray, do not set it manually 39 PHY_ScalarType m_indexType; 40 41 // The vertex type has a default type similar to Bullet's precision mode (float or double) 42 // but can be set manually if you for example run Bullet with double precision but have 43 // mesh data in single precision.. 44 PHY_ScalarType m_vertexType; 45 46 47 btIndexedMesh() 48 :m_indexType(PHY_INTEGER), 49 #ifdef BT_USE_DOUBLE_PRECISION 50 m_vertexType(PHY_DOUBLE) 51 #else // BT_USE_DOUBLE_PRECISION 52 m_vertexType(PHY_FLOAT) 53 #endif // BT_USE_DOUBLE_PRECISION 54 { 55 } 40 56 } 41 57 ; -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.cpp
r5781 r8351 1 2 1 /* 3 2 Bullet Continuous Collision Detection and Physics Library 4 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 5 4 6 5 This software is provided 'as-is', without any express or implied warranty. 7 6 In no event will the authors be held liable for any damages arising from the use of this software. 8 Permission is granted to anyone to use this software for any purpose, 9 including commercial applications, and to alter it and redistribute it freely, 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 10 9 subject to the following restrictions: 11 10 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleIndexVertexMaterialArray.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "btTriangleMesh.h" -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 15 17 16 #ifndef TRIANGLE_MESH_H … … 42 41 btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true); 43 42 44 int findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices);45 void addIndex(int index);46 47 43 bool getUse32bitIndices() const 48 44 { … … 63 59 virtual void preallocateIndices(int numindices){(void) numindices;} 64 60 61 ///findOrAddVertex is an internal method, use addTriangle instead 62 int findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices); 63 ///addIndex is an internal method, use addTriangle instead 64 void addIndex(int index); 65 65 66 66 }; -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 92 92 93 93 SupportVertexCallback(const btVector3& supportVecWorld,const btTransform& trans) 94 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(- 1e30))94 : m_supportVertexLocal(btScalar(0.),btScalar(0.),btScalar(0.)), m_worldTrans(trans) ,m_maxDot(btScalar(-BT_LARGE_FLOAT)) 95 95 96 96 { … … 200 200 SupportVertexCallback supportCallback(vec,ident); 201 201 202 btVector3 aabbMax(btScalar( 1e30),btScalar(1e30),btScalar(1e30));202 btVector3 aabbMax(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 203 203 204 204 processAllTriangles(&supportCallback,-aabbMax,aabbMax); … … 208 208 return supportVertex; 209 209 } 210 211 -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 80 80 virtual const char* getName()const {return "TRIANGLEMESH";} 81 81 82 82 83 83 84 }; 84 85 86 87 88 85 89 #endif //TRIANGLE_MESH_SHAPE_H -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btTriangleShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "btBoxShape.h" 21 21 22 classbtTriangleShape : public btPolyhedralConvexShape22 ATTRIBUTE_ALIGNED16(class) btTriangleShape : public btPolyhedralConvexShape 23 23 { 24 24 … … 31 31 { 32 32 return 3; 33 } 34 35 btVector3& getVertexPtr(int index) 36 { 37 return m_vertices1[index]; 33 38 } 34 39 … … 78 83 } 79 84 80 85 btTriangleShape() : btPolyhedralConvexShape () 86 { 87 m_shapeType = TRIANGLE_SHAPE_PROXYTYPE; 88 } 81 89 82 90 btTriangleShape(const btVector3& p0,const btVector3& p1,const btVector3& p2) : btPolyhedralConvexShape () -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 7 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/CollisionShapes/btUniformScalingShape.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.cpp
r5781 r8351 97 97 { 98 98 99 btGjkPairDetector gjk(m_convexA,m_convexB,m_ simplexSolver,m_penetrationDepthSolver);99 btGjkPairDetector gjk(m_convexA,m_convexB,m_convexA->getShapeType(),m_convexB->getShapeType(),m_convexA->getMargin(),m_convexB->getMargin(),m_simplexSolver,m_penetrationDepthSolver); 100 100 btGjkPairDetector::ClosestPointInput input; 101 101 … … 122 122 while (dist > radius) 123 123 { 124 if (result.m_debugDrawer) 125 { 126 result.m_debugDrawer->drawSphere(c,0.2f,btVector3(1,1,1)); 127 } 124 128 numIter++; 125 129 if (numIter > maxIter) … … 170 174 btTransformUtil::integrateTransform(fromB,linVelB,angVelB,lambda,interpolatedTransB); 171 175 relativeTrans = interpolatedTransB.inverseTimes(interpolatedTransA); 176 177 if (result.m_debugDrawer) 178 { 179 result.m_debugDrawer->drawSphere(interpolatedTransA.getOrigin(),0.2f,btVector3(1,0,0)); 180 } 172 181 173 182 result.DebugDraw( lambda ); … … 198 207 return false; 199 208 } 209 200 210 201 211 } … … 225 235 226 236 } 227 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexCast.h
r5781 r8351 42 42 43 43 CastResult() 44 :m_fraction(btScalar( 1e30)),44 :m_fraction(btScalar(BT_LARGE_FLOAT)), 45 45 m_debugDrawer(0), 46 46 m_allowedPenetration(btScalar(0)) -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h
r5781 r8351 15 15 16 16 17 #ifndef CONVEX_PENETRATION_DEPTH_H18 #define CONVEX_PENETRATION_DEPTH_H17 #ifndef __CONVEX_PENETRATION_DEPTH_H 18 #define __CONVEX_PENETRATION_DEPTH_H 19 19 20 20 class btStackAlloc; -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h
r5781 r8351 34 34 virtual ~Result(){} 35 35 36 ///setShapeIdentifiers provides experimental support for per-triangle material / custom material combiner 37 virtual void setShapeIdentifiers(int partId0,int index0, int partId1,int index1)=0; 36 ///setShapeIdentifiersA/B provides experimental support for per-triangle material / custom material combiner 37 virtual void setShapeIdentifiersA(int partId0,int index0)=0; 38 virtual void setShapeIdentifiersB(int partId1,int index1)=0; 38 39 virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth)=0; 39 40 }; … … 42 43 { 43 44 ClosestPointInput() 44 :m_maximumDistanceSquared(btScalar( 1e30)),45 :m_maximumDistanceSquared(btScalar(BT_LARGE_FLOAT)), 45 46 m_stackAlloc(0) 46 47 { … … 69 70 btScalar m_distance; //negative means penetration ! 70 71 71 btStorageResult() : m_distance(btScalar( 1e30))72 btStorageResult() : m_distance(btScalar(BT_LARGE_FLOAT)) 72 73 { 73 74 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.cpp
r5781 r8351 69 69 btMatrix3x3 m_toshape1; 70 70 btTransform m_toshape0; 71 #ifdef __SPU__ 72 bool m_enableMargin; 73 #else 71 74 btVector3 (btConvexShape::*Ls)(const btVector3&) const; 75 #endif//__SPU__ 76 77 78 MinkowskiDiff() 79 { 80 81 } 82 #ifdef __SPU__ 83 void EnableMargin(bool enable) 84 { 85 m_enableMargin = enable; 86 } 87 inline btVector3 Support0(const btVector3& d) const 88 { 89 if (m_enableMargin) 90 { 91 return m_shapes[0]->localGetSupportVertexNonVirtual(d); 92 } else 93 { 94 return m_shapes[0]->localGetSupportVertexWithoutMarginNonVirtual(d); 95 } 96 } 97 inline btVector3 Support1(const btVector3& d) const 98 { 99 if (m_enableMargin) 100 { 101 return m_toshape0*(m_shapes[1]->localGetSupportVertexNonVirtual(m_toshape1*d)); 102 } else 103 { 104 return m_toshape0*(m_shapes[1]->localGetSupportVertexWithoutMarginNonVirtual(m_toshape1*d)); 105 } 106 } 107 #else 72 108 void EnableMargin(bool enable) 73 109 { … … 85 121 return(m_toshape0*((m_shapes[1])->*(Ls))(m_toshape1*d)); 86 122 } 123 #endif //__SPU__ 124 87 125 inline btVector3 Support(const btVector3& d) const 88 126 { … … 203 241 } 204 242 /* Check for termination */ 205 const btScalar omega= dot(m_ray,w)/rl;243 const btScalar omega=btDot(m_ray,w)/rl; 206 244 alpha=btMax(omega,alpha); 207 245 if(((rl-alpha)-(GJK_ACCURARY*rl))<=0) … … 260 298 case eStatus::Valid: m_distance=m_ray.length();break; 261 299 case eStatus::Inside: m_distance=0;break; 300 default: 301 { 302 } 262 303 } 263 304 return(m_status); … … 289 330 btVector3 axis=btVector3(0,0,0); 290 331 axis[i]=1; 291 const btVector3 p= cross(d,axis);332 const btVector3 p=btCross(d,axis); 292 333 if(p.length2()>0) 293 334 { … … 304 345 case 3: 305 346 { 306 const btVector3 n= cross(m_simplex->c[1]->w-m_simplex->c[0]->w,347 const btVector3 n=btCross(m_simplex->c[1]->w-m_simplex->c[0]->w, 307 348 m_simplex->c[2]->w-m_simplex->c[0]->w); 308 349 if(n.length2()>0) … … 358 399 if(l>GJK_SIMPLEX2_EPS) 359 400 { 360 const btScalar t(l>0?- dot(a,d)/l:0);401 const btScalar t(l>0?-btDot(a,d)/l:0); 361 402 if(t>=1) { w[0]=0;w[1]=1;m=2;return(b.length2()); } 362 403 else if(t<=0) { w[0]=1;w[1]=0;m=1;return(a.length2()); } … … 373 414 const btVector3* vt[]={&a,&b,&c}; 374 415 const btVector3 dl[]={a-b,b-c,c-a}; 375 const btVector3 n= cross(dl[0],dl[1]);416 const btVector3 n=btCross(dl[0],dl[1]); 376 417 const btScalar l=n.length2(); 377 418 if(l>GJK_SIMPLEX3_EPS) 378 419 { 379 420 btScalar mindist=-1; 380 btScalar subw[2] ;381 U subm ;421 btScalar subw[2]={0.f,0.f}; 422 U subm(0); 382 423 for(U i=0;i<3;++i) 383 424 { 384 if( dot(*vt[i],cross(dl[i],n))>0)425 if(btDot(*vt[i],btCross(dl[i],n))>0) 385 426 { 386 427 const U j=imd3[i]; … … 398 439 if(mindist<0) 399 440 { 400 const btScalar d= dot(a,n);441 const btScalar d=btDot(a,n); 401 442 const btScalar s=btSqrt(l); 402 443 const btVector3 p=n*(d/l); 403 444 mindist = p.length2(); 404 445 m = 7; 405 w[0] = ( cross(dl[1],b-p)).length()/s;406 w[1] = ( cross(dl[2],c-p)).length()/s;446 w[0] = (btCross(dl[1],b-p)).length()/s; 447 w[1] = (btCross(dl[2],c-p)).length()/s; 407 448 w[2] = 1-(w[0]+w[1]); 408 449 } … … 421 462 const btVector3 dl[]={a-d,b-d,c-d}; 422 463 const btScalar vl=det(dl[0],dl[1],dl[2]); 423 const bool ng=(vl* dot(a,cross(b-c,a-b)))<=0;464 const bool ng=(vl*btDot(a,btCross(b-c,a-b)))<=0; 424 465 if(ng&&(btFabs(vl)>GJK_SIMPLEX4_EPS)) 425 466 { 426 467 btScalar mindist=-1; 427 btScalar subw[3] ;428 U subm ;468 btScalar subw[3]={0.f,0.f,0.f}; 469 U subm(0); 429 470 for(U i=0;i<3;++i) 430 471 { 431 472 const U j=imd3[i]; 432 const btScalar s=vl* dot(d,cross(dl[i],dl[j]));473 const btScalar s=vl*btDot(d,btCross(dl[i],dl[j])); 433 474 if(s>0) 434 475 { … … 602 643 best->pass = (U1)(++pass); 603 644 gjk.getsupport(best->n,*w); 604 const btScalar wdist= dot(best->n,w->w)-best->d;645 const btScalar wdist=btDot(best->n,w->w)-best->d; 605 646 if(wdist>EPA_ACCURACY) 606 647 { … … 629 670 m_result.c[1] = outer.c[1]; 630 671 m_result.c[2] = outer.c[2]; 631 m_result.p[0] = cross( outer.c[1]->w-projection,672 m_result.p[0] = btCross( outer.c[1]->w-projection, 632 673 outer.c[2]->w-projection).length(); 633 m_result.p[1] = cross( outer.c[2]->w-projection,674 m_result.p[1] = btCross( outer.c[2]->w-projection, 634 675 outer.c[0]->w-projection).length(); 635 m_result.p[2] = cross( outer.c[0]->w-projection,676 m_result.p[2] = btCross( outer.c[0]->w-projection, 636 677 outer.c[1]->w-projection).length(); 637 678 const btScalar sum=m_result.p[0]+m_result.p[1]+m_result.p[2]; … … 667 708 face->c[1] = b; 668 709 face->c[2] = c; 669 face->n = cross(b->w-a->w,c->w-a->w);710 face->n = btCross(b->w-a->w,c->w-a->w); 670 711 const btScalar l=face->n.length(); 671 712 const bool v=l>EPA_ACCURACY; 672 713 face->p = btMin(btMin( 673 dot(a->w,cross(face->n,a->w-b->w)),674 dot(b->w,cross(face->n,b->w-c->w))),675 dot(c->w,cross(face->n,c->w-a->w))) /714 btDot(a->w,btCross(face->n,a->w-b->w)), 715 btDot(b->w,btCross(face->n,b->w-c->w))), 716 btDot(c->w,btCross(face->n,c->w-a->w))) / 676 717 (v?l:1); 677 718 face->p = face->p>=-EPA_INSIDE_EPS?0:face->p; 678 719 if(v) 679 720 { 680 face->d = dot(a->w,face->n)/l;721 face->d = btDot(a->w,face->n)/l; 681 722 face->n /= l; 682 723 if(forced||(face->d>=-EPA_PLANE_EPS)) … … 716 757 { 717 758 const U e1=i1m3[e]; 718 if(( dot(f->n,w->w)-f->d)<-EPA_PLANE_EPS)759 if((btDot(f->n,w->w)-f->d)<-EPA_PLANE_EPS) 719 760 { 720 761 sFace* nf=newface(f->c[e1],f->c[e],w,false); … … 855 896 results.status=sResults::GJK_Failed; 856 897 break; 898 default: 899 { 900 } 857 901 } 858 902 return(false); 859 903 } 860 904 905 #ifndef __SPU__ 861 906 // 862 907 btScalar btGjkEpaSolver2::SignedDistance(const btVector3& position, … … 924 969 return(true); 925 970 } 971 #endif //__SPU__ 926 972 927 973 /* Symbols cleanup */ -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpa2.h
r5781 r8351 56 56 sResults& results, 57 57 bool usemargins=true); 58 58 #ifndef __SPU__ 59 59 static btScalar SignedDistance( const btVector3& position, 60 60 btScalar margin, … … 67 67 const btVector3& guess, 68 68 sResults& results); 69 #endif //__SPU__ 70 69 71 }; 70 72 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.cpp
r5781 r8351 33 33 (void)simplexSolver; 34 34 35 const btScalar radialmargin(btScalar(0.));35 // const btScalar radialmargin(btScalar(0.)); 36 36 37 37 btVector3 guessVector(transformA.getOrigin()-transformB.getOrigin()); 38 38 btGjkEpaSolver2::sResults results; 39 40 39 41 if(btGjkEpaSolver2::Penetration(pConvexA,transformA, 40 42 pConvexB,transformB, … … 46 48 wWitnessOnA = results.witnesses[0]; 47 49 wWitnessOnB = results.witnesses[1]; 50 v = results.normal; 48 51 return true; 52 } else 53 { 54 if(btGjkEpaSolver2::Distance(pConvexA,transformA,pConvexB,transformB,guessVector,results)) 55 { 56 wWitnessOnA = results.witnesses[0]; 57 wWitnessOnB = results.witnesses[1]; 58 v = results.normal; 59 return false; 49 60 } 61 } 50 62 51 63 return false; -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h
r5781 r8351 26 26 public : 27 27 28 btGjkEpaPenetrationDepthSolver() 29 { 30 } 31 28 32 bool calcPenDepth( btSimplexSolverInterface& simplexSolver, 29 33 const btConvexShape* pConvexA, const btConvexShape* pConvexB, -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.cpp
r5781 r8351 39 39 40 40 41 42 41 btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) 43 :m_cachedSeparatingAxis(btScalar(0.),btScalar( 0.),btScalar(1.)),42 :m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)), 44 43 m_penetrationDepthSolver(penetrationDepthSolver), 45 44 m_simplexSolver(simplexSolver), 46 45 m_minkowskiA(objectA), 47 46 m_minkowskiB(objectB), 47 m_shapeTypeA(objectA->getShapeType()), 48 m_shapeTypeB(objectB->getShapeType()), 49 m_marginA(objectA->getMargin()), 50 m_marginB(objectB->getMargin()), 48 51 m_ignoreMargin(false), 49 52 m_lastUsedMethod(-1), … … 51 54 { 52 55 } 53 54 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults) 56 btGjkPairDetector::btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver) 57 :m_cachedSeparatingAxis(btScalar(0.),btScalar(1.),btScalar(0.)), 58 m_penetrationDepthSolver(penetrationDepthSolver), 59 m_simplexSolver(simplexSolver), 60 m_minkowskiA(objectA), 61 m_minkowskiB(objectB), 62 m_shapeTypeA(shapeTypeA), 63 m_shapeTypeB(shapeTypeB), 64 m_marginA(marginA), 65 m_marginB(marginB), 66 m_ignoreMargin(false), 67 m_lastUsedMethod(-1), 68 m_catchDegeneracies(1) 69 { 70 } 71 72 void btGjkPairDetector::getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults) 73 { 74 (void)swapResults; 75 76 getClosestPointsNonVirtual(input,output,debugDraw); 77 } 78 79 #ifdef __SPU__ 80 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw) 81 #else 82 void btGjkPairDetector::getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw) 83 #endif 55 84 { 56 85 m_cachedSeparatingDistance = 0.f; … … 65 94 localTransB.getOrigin() -= positionOffset; 66 95 67 #ifdef __SPU__ 68 btScalar marginA = m_minkowskiA->getMarginNonVirtual(); 69 btScalar marginB = m_minkowskiB->getMarginNonVirtual(); 70 #else 71 btScalar marginA = m_minkowskiA->getMargin(); 72 btScalar marginB = m_minkowskiB->getMargin(); 73 #ifdef TEST_NON_VIRTUAL 74 btScalar marginAv = m_minkowskiA->getMarginNonVirtual(); 75 btScalar marginBv = m_minkowskiB->getMarginNonVirtual(); 76 btAssert(marginA == marginAv); 77 btAssert(marginB == marginBv); 78 #endif //TEST_NON_VIRTUAL 79 #endif 80 81 96 bool check2d = m_minkowskiA->isConvex2d() && m_minkowskiB->isConvex2d(); 97 98 btScalar marginA = m_marginA; 99 btScalar marginB = m_marginB; 82 100 83 101 gNumGjkChecks++; … … 108 126 109 127 { 110 btScalar squaredDistance = SIMD_INFINITY;128 btScalar squaredDistance = BT_LARGE_FLOAT; 111 129 btScalar delta = btScalar(0.); 112 130 … … 124 142 btVector3 seperatingAxisInB = m_cachedSeparatingAxis* input.m_transformB.getBasis(); 125 143 144 #if 1 145 146 btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); 147 btVector3 qInB = m_minkowskiB->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInB); 148 149 // btVector3 pInA = localGetSupportingVertexWithoutMargin(m_shapeTypeA, m_minkowskiA, seperatingAxisInA,input.m_convexVertexData[0]);//, &featureIndexA); 150 // btVector3 qInB = localGetSupportingVertexWithoutMargin(m_shapeTypeB, m_minkowskiB, seperatingAxisInB,input.m_convexVertexData[1]);//, &featureIndexB); 151 152 #else 126 153 #ifdef __SPU__ 127 154 btVector3 pInA = m_minkowskiA->localGetSupportVertexWithoutMarginNonVirtual(seperatingAxisInA); … … 137 164 #endif // 138 165 #endif //__SPU__ 166 #endif 167 139 168 140 169 btVector3 pWorld = localTransA(pInA); … … 145 174 #endif 146 175 176 if (check2d) 177 { 178 pWorld[2] = 0.f; 179 qWorld[2] = 0.f; 180 } 181 147 182 btVector3 w = pWorld - qWorld; 148 183 delta = m_cachedSeparatingAxis.dot(w); … … 151 186 if ((delta > btScalar(0.0)) && (delta * delta > squaredDistance * input.m_maximumDistanceSquared)) 152 187 { 188 m_degenerateSimplex = 10; 153 189 checkSimplex=true; 154 190 //checkPenetration = false; … … 172 208 { 173 209 m_degenerateSimplex = 2; 210 } else 211 { 212 m_degenerateSimplex = 11; 174 213 } 175 214 checkSimplex = true; … … 185 224 spu_printf("addVertex 2\n"); 186 225 #endif 226 btVector3 newCachedSeparatingAxis; 227 187 228 //calculate the closest point to the origin (update vector v) 188 if (!m_simplexSolver->closest( m_cachedSeparatingAxis))229 if (!m_simplexSolver->closest(newCachedSeparatingAxis)) 189 230 { 190 231 m_degenerateSimplex = 3; … … 193 234 } 194 235 195 if( m_cachedSeparatingAxis.length2()<REL_ERROR2)236 if(newCachedSeparatingAxis.length2()<REL_ERROR2) 196 237 { 238 m_cachedSeparatingAxis = newCachedSeparatingAxis; 197 239 m_degenerateSimplex = 6; 198 240 checkSimplex = true; … … 201 243 202 244 btScalar previousSquaredDistance = squaredDistance; 203 squaredDistance = m_cachedSeparatingAxis.length2(); 245 squaredDistance = newCachedSeparatingAxis.length2(); 246 #if 0 247 ///warning: this termination condition leads to some problems in 2d test case see Bullet/Demos/Box2dDemo 248 if (squaredDistance>previousSquaredDistance) 249 { 250 m_degenerateSimplex = 7; 251 squaredDistance = previousSquaredDistance; 252 checkSimplex = false; 253 break; 254 } 255 #endif // 204 256 257 m_cachedSeparatingAxis = newCachedSeparatingAxis; 258 205 259 //redundant m_simplexSolver->compute_points(pointOnA, pointOnB); 206 260 … … 210 264 m_simplexSolver->backup_closest(m_cachedSeparatingAxis); 211 265 checkSimplex = true; 266 m_degenerateSimplex = 12; 267 212 268 break; 213 269 } … … 240 296 //do we need this backup_closest here ? 241 297 m_simplexSolver->backup_closest(m_cachedSeparatingAxis); 298 m_degenerateSimplex = 13; 242 299 break; 243 300 } … … 248 305 m_simplexSolver->compute_points(pointOnA, pointOnB); 249 306 normalInB = pointOnA-pointOnB; 250 btScalar lenSqr = m_cachedSeparatingAxis.length2(); 307 btScalar lenSqr =m_cachedSeparatingAxis.length2(); 308 251 309 //valid normal 252 310 if (lenSqr < 0.0001) … … 280 338 { 281 339 //penetration case 282 340 283 341 //if there is no way to handle penetrations, bail out 284 342 if (m_penetrationDepthSolver) … … 288 346 289 347 gNumDeepPenetrationChecks++; 348 m_cachedSeparatingAxis.setZero(); 290 349 291 350 bool isValid2 = m_penetrationDepthSolver->calcPenDepth( … … 297 356 ); 298 357 358 299 359 if (isValid2) 300 360 { 301 361 btVector3 tmpNormalInB = tmpPointOnB-tmpPointOnA; 302 362 btScalar lenSqr = tmpNormalInB.length2(); 363 if (lenSqr <= (SIMD_EPSILON*SIMD_EPSILON)) 364 { 365 tmpNormalInB = m_cachedSeparatingAxis; 366 lenSqr = m_cachedSeparatingAxis.length2(); 367 } 368 303 369 if (lenSqr > (SIMD_EPSILON*SIMD_EPSILON)) 304 370 { … … 316 382 } else 317 383 { 318 384 m_lastUsedMethod = 8; 319 385 } 320 386 } else 321 387 { 322 //isValid = false; 323 m_lastUsedMethod = 4; 388 m_lastUsedMethod = 9; 324 389 } 325 390 } else 391 326 392 { 327 m_lastUsedMethod = 5; 393 ///this is another degenerate case, where the initial GJK calculation reports a degenerate case 394 ///EPA reports no penetration, and the second GJK (using the supporting vector without margin) 395 ///reports a valid positive distance. Use the results of the second GJK instead of failing. 396 ///thanks to Jacob.Langford for the reproduction case 397 ///http://code.google.com/p/bullet/issues/detail?id=250 398 399 400 if (m_cachedSeparatingAxis.length2() > btScalar(0.)) 401 { 402 btScalar distance2 = (tmpPointOnA-tmpPointOnB).length()-margin; 403 //only replace valid distances when the distance is less 404 if (!isValid || (distance2 < distance)) 405 { 406 distance = distance2; 407 pointOnA = tmpPointOnA; 408 pointOnB = tmpPointOnB; 409 pointOnA -= m_cachedSeparatingAxis * marginA ; 410 pointOnB += m_cachedSeparatingAxis * marginB ; 411 normalInB = m_cachedSeparatingAxis; 412 normalInB.normalize(); 413 isValid = true; 414 m_lastUsedMethod = 6; 415 } else 416 { 417 m_lastUsedMethod = 5; 418 } 419 } 328 420 } 329 421 330 422 } 423 331 424 } 332 425 } 333 426 334 if (isValid) 427 428 429 if (isValid && ((distance < 0) || (distance*distance < input.m_maximumDistanceSquared))) 335 430 { 336 #ifdef __SPU__ 337 //spu_printf("distance\n"); 338 #endif //__CELLOS_LV2__ 339 340 341 #ifdef DEBUG_SPU_COLLISION_DETECTION 342 spu_printf("output 1\n"); 343 #endif 431 #if 0 432 ///some debugging 433 // if (check2d) 434 { 435 printf("n = %2.3f,%2.3f,%2.3f. ",normalInB[0],normalInB[1],normalInB[2]); 436 printf("distance = %2.3f exit=%d deg=%d\n",distance,m_lastUsedMethod,m_degenerateSimplex); 437 } 438 #endif 439 344 440 m_cachedSeparatingAxis = normalInB; 345 441 m_cachedSeparatingDistance = distance; … … 350 446 distance); 351 447 352 #ifdef DEBUG_SPU_COLLISION_DETECTION353 spu_printf("output 2\n");354 #endif355 //printf("gjk add:%f",distance);356 448 } 357 449 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h
r5781 r8351 37 37 const btConvexShape* m_minkowskiA; 38 38 const btConvexShape* m_minkowskiB; 39 int m_shapeTypeA; 40 int m_shapeTypeB; 41 btScalar m_marginA; 42 btScalar m_marginB; 43 39 44 bool m_ignoreMargin; 40 45 btScalar m_cachedSeparatingDistance; … … 51 56 52 57 btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); 58 btGjkPairDetector(const btConvexShape* objectA,const btConvexShape* objectB,int shapeTypeA,int shapeTypeB,btScalar marginA, btScalar marginB, btSimplexSolverInterface* simplexSolver,btConvexPenetrationDepthSolver* penetrationDepthSolver); 53 59 virtual ~btGjkPairDetector() {}; 54 60 55 61 virtual void getClosestPoints(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw,bool swapResults=false); 62 63 void getClosestPointsNonVirtual(const ClosestPointInput& input,Result& output,class btIDebugDraw* debugDraw); 64 56 65 57 66 void setMinkowskiA(btConvexShape* minkA) -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h
r5781 r8351 20 20 #include "LinearMath/btTransformUtil.h" 21 21 22 // Don't change following order of parameters 23 ATTRIBUTE_ALIGNED16(struct) PfxConstraintRow { 24 btScalar mNormal[3]; 25 btScalar mRhs; 26 btScalar mJacDiagInv; 27 btScalar mLowerLimit; 28 btScalar mUpperLimit; 29 btScalar mAccumImpulse; 30 }; 22 31 23 32 … … 35 44 m_appliedImpulseLateral1(0.f), 36 45 m_appliedImpulseLateral2(0.f), 46 m_contactMotion1(0.f), 47 m_contactMotion2(0.f), 48 m_contactCFM1(0.f), 49 m_contactCFM2(0.f), 37 50 m_lifeTime(0) 38 51 { … … 53 66 m_appliedImpulseLateral1(0.f), 54 67 m_appliedImpulseLateral2(0.f), 68 m_contactMotion1(0.f), 69 m_contactMotion2(0.f), 70 m_contactCFM1(0.f), 71 m_contactCFM2(0.f), 55 72 m_lifeTime(0) 56 73 { 57 58 74 mConstraintRow[0].mAccumImpulse = 0.f; 75 mConstraintRow[1].mAccumImpulse = 0.f; 76 mConstraintRow[2].mAccumImpulse = 0.f; 59 77 } 60 78 … … 84 102 btScalar m_appliedImpulseLateral1; 85 103 btScalar m_appliedImpulseLateral2; 104 btScalar m_contactMotion1; 105 btScalar m_contactMotion2; 106 btScalar m_contactCFM1; 107 btScalar m_contactCFM2; 108 86 109 int m_lifeTime;//lifetime of the contactpoint in frames 87 110 88 111 btVector3 m_lateralFrictionDir1; 89 112 btVector3 m_lateralFrictionDir2; 113 114 115 116 PfxConstraintRow mConstraintRow[3]; 117 90 118 91 119 btScalar getDistance() const -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.cpp
r5781 r8351 21 21 22 22 #define NUM_UNITSPHERE_POINTS 42 23 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] =24 {25 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)),26 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)),27 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)),28 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)),29 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)),30 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)),31 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)),32 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)),33 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)),34 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)),35 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)),36 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)),37 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)),38 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)),39 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)),40 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)),41 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)),42 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)),43 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)),44 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)),45 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)),46 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)),47 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)),48 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)),49 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)),50 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)),51 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)),52 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)),53 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)),54 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)),55 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)),56 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)),57 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)),58 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)),59 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)),60 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)),61 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)),62 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)),63 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)),64 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)),65 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)),66 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654))67 };68 23 69 24 … … 79 34 (void)v; 80 35 36 bool check2d= convexA->isConvex2d() && convexB->isConvex2d(); 81 37 82 38 struct btIntermediateResult : public btDiscreteCollisionDetectorInterface::Result … … 92 48 bool m_hasResult; 93 49 94 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)50 virtual void setShapeIdentifiersA(int partId0,int index0) 95 51 { 96 52 (void)partId0; 97 53 (void)index0; 54 } 55 virtual void setShapeIdentifiersB(int partId1,int index1) 56 { 98 57 (void)partId1; 99 58 (void)index1; … … 109 68 110 69 //just take fixed number of orientation, and sample the penetration depth in that direction 111 btScalar minProj = btScalar( 1e30);70 btScalar minProj = btScalar(BT_LARGE_FLOAT); 112 71 btVector3 minNorm(btScalar(0.), btScalar(0.), btScalar(0.)); 113 72 btVector3 minA,minB; … … 130 89 for (i=0;i<numSampleDirections;i++) 131 90 { 132 const btVector3& norm = sPenetrationDirections[i];91 btVector3 norm = getPenetrationDirections()[i]; 133 92 seperatingAxisInABatch[i] = (-norm) * transA.getBasis() ; 134 93 seperatingAxisInBBatch[i] = norm * transB.getBasis() ; … … 144 103 convexA->getPreferredPenetrationDirection(i,norm); 145 104 norm = transA.getBasis() * norm; 146 sPenetrationDirections[numSampleDirections] = norm;105 getPenetrationDirections()[numSampleDirections] = norm; 147 106 seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis(); 148 107 seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis(); … … 161 120 convexB->getPreferredPenetrationDirection(i,norm); 162 121 norm = transB.getBasis() * norm; 163 sPenetrationDirections[numSampleDirections] = norm;122 getPenetrationDirections()[numSampleDirections] = norm; 164 123 seperatingAxisInABatch[numSampleDirections] = (-norm) * transA.getBasis(); 165 124 seperatingAxisInBBatch[numSampleDirections] = norm * transB.getBasis(); … … 171 130 172 131 132 173 133 convexA->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInABatch,supportVerticesABatch,numSampleDirections); 174 134 convexB->batchedUnitVectorGetSupportingVertexWithoutMargin(seperatingAxisInBBatch,supportVerticesBBatch,numSampleDirections); … … 176 136 for (i=0;i<numSampleDirections;i++) 177 137 { 178 const btVector3& norm = sPenetrationDirections[i]; 179 seperatingAxisInA = seperatingAxisInABatch[i]; 180 seperatingAxisInB = seperatingAxisInBBatch[i]; 181 182 pInA = supportVerticesABatch[i]; 183 qInB = supportVerticesBBatch[i]; 184 185 pWorld = transA(pInA); 186 qWorld = transB(qInB); 187 w = qWorld - pWorld; 188 btScalar delta = norm.dot(w); 189 //find smallest delta 190 if (delta < minProj) 191 { 192 minProj = delta; 193 minNorm = norm; 194 minA = pWorld; 195 minB = qWorld; 138 btVector3 norm = getPenetrationDirections()[i]; 139 if (check2d) 140 { 141 norm[2] = 0.f; 142 } 143 if (norm.length2()>0.01) 144 { 145 146 seperatingAxisInA = seperatingAxisInABatch[i]; 147 seperatingAxisInB = seperatingAxisInBBatch[i]; 148 149 pInA = supportVerticesABatch[i]; 150 qInB = supportVerticesBBatch[i]; 151 152 pWorld = transA(pInA); 153 qWorld = transB(qInB); 154 if (check2d) 155 { 156 pWorld[2] = 0.f; 157 qWorld[2] = 0.f; 158 } 159 160 w = qWorld - pWorld; 161 btScalar delta = norm.dot(w); 162 //find smallest delta 163 if (delta < minProj) 164 { 165 minProj = delta; 166 minNorm = norm; 167 minA = pWorld; 168 minB = qWorld; 169 } 196 170 } 197 171 } … … 210 184 convexA->getPreferredPenetrationDirection(i,norm); 211 185 norm = transA.getBasis() * norm; 212 sPenetrationDirections[numSampleDirections] = norm;186 getPenetrationDirections()[numSampleDirections] = norm; 213 187 numSampleDirections++; 214 188 } … … 225 199 convexB->getPreferredPenetrationDirection(i,norm); 226 200 norm = transB.getBasis() * norm; 227 sPenetrationDirections[numSampleDirections] = norm;201 getPenetrationDirections()[numSampleDirections] = norm; 228 202 numSampleDirections++; 229 203 } … … 234 208 for (int i=0;i<numSampleDirections;i++) 235 209 { 236 const btVector3& norm = sPenetrationDirections[i];210 const btVector3& norm = getPenetrationDirections()[i]; 237 211 seperatingAxisInA = (-norm)* transA.getBasis(); 238 212 seperatingAxisInB = norm* transB.getBasis(); … … 262 236 return false; 263 237 264 minProj += (convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual()); 238 btScalar extraSeparation = 0.5f;///scale dependent 239 minProj += extraSeparation+(convexA->getMarginNonVirtual() + convexB->getMarginNonVirtual()); 265 240 266 241 … … 300 275 input.m_transformA = displacedTrans; 301 276 input.m_transformB = transB; 302 input.m_maximumDistanceSquared = btScalar( 1e30);//minProj;277 input.m_maximumDistanceSquared = btScalar(BT_LARGE_FLOAT);//minProj; 303 278 304 279 btIntermediateResult res; 280 gjkdet.setCachedSeperatingAxis(-minNorm); 305 281 gjkdet.getClosestPoints(input,res,debugDraw); 306 282 … … 311 287 btScalar penetration_relaxation= btScalar(1.); 312 288 minNorm*=penetration_relaxation; 289 313 290 314 291 if (res.m_hasResult) … … 317 294 pa = res.m_pointInWorld - minNorm * correctedMinNorm; 318 295 pb = res.m_pointInWorld; 296 v = minNorm; 319 297 320 298 #ifdef DEBUG_DRAW … … 331 309 } 332 310 333 334 311 btVector3* btMinkowskiPenetrationDepthSolver::getPenetrationDirections() 312 { 313 static btVector3 sPenetrationDirections[NUM_UNITSPHERE_POINTS+MAX_PREFERRED_PENETRATION_DIRECTIONS*2] = 314 { 315 btVector3(btScalar(0.000000) , btScalar(-0.000000),btScalar(-1.000000)), 316 btVector3(btScalar(0.723608) , btScalar(-0.525725),btScalar(-0.447219)), 317 btVector3(btScalar(-0.276388) , btScalar(-0.850649),btScalar(-0.447219)), 318 btVector3(btScalar(-0.894426) , btScalar(-0.000000),btScalar(-0.447216)), 319 btVector3(btScalar(-0.276388) , btScalar(0.850649),btScalar(-0.447220)), 320 btVector3(btScalar(0.723608) , btScalar(0.525725),btScalar(-0.447219)), 321 btVector3(btScalar(0.276388) , btScalar(-0.850649),btScalar(0.447220)), 322 btVector3(btScalar(-0.723608) , btScalar(-0.525725),btScalar(0.447219)), 323 btVector3(btScalar(-0.723608) , btScalar(0.525725),btScalar(0.447219)), 324 btVector3(btScalar(0.276388) , btScalar(0.850649),btScalar(0.447219)), 325 btVector3(btScalar(0.894426) , btScalar(0.000000),btScalar(0.447216)), 326 btVector3(btScalar(-0.000000) , btScalar(0.000000),btScalar(1.000000)), 327 btVector3(btScalar(0.425323) , btScalar(-0.309011),btScalar(-0.850654)), 328 btVector3(btScalar(-0.162456) , btScalar(-0.499995),btScalar(-0.850654)), 329 btVector3(btScalar(0.262869) , btScalar(-0.809012),btScalar(-0.525738)), 330 btVector3(btScalar(0.425323) , btScalar(0.309011),btScalar(-0.850654)), 331 btVector3(btScalar(0.850648) , btScalar(-0.000000),btScalar(-0.525736)), 332 btVector3(btScalar(-0.525730) , btScalar(-0.000000),btScalar(-0.850652)), 333 btVector3(btScalar(-0.688190) , btScalar(-0.499997),btScalar(-0.525736)), 334 btVector3(btScalar(-0.162456) , btScalar(0.499995),btScalar(-0.850654)), 335 btVector3(btScalar(-0.688190) , btScalar(0.499997),btScalar(-0.525736)), 336 btVector3(btScalar(0.262869) , btScalar(0.809012),btScalar(-0.525738)), 337 btVector3(btScalar(0.951058) , btScalar(0.309013),btScalar(0.000000)), 338 btVector3(btScalar(0.951058) , btScalar(-0.309013),btScalar(0.000000)), 339 btVector3(btScalar(0.587786) , btScalar(-0.809017),btScalar(0.000000)), 340 btVector3(btScalar(0.000000) , btScalar(-1.000000),btScalar(0.000000)), 341 btVector3(btScalar(-0.587786) , btScalar(-0.809017),btScalar(0.000000)), 342 btVector3(btScalar(-0.951058) , btScalar(-0.309013),btScalar(-0.000000)), 343 btVector3(btScalar(-0.951058) , btScalar(0.309013),btScalar(-0.000000)), 344 btVector3(btScalar(-0.587786) , btScalar(0.809017),btScalar(-0.000000)), 345 btVector3(btScalar(-0.000000) , btScalar(1.000000),btScalar(-0.000000)), 346 btVector3(btScalar(0.587786) , btScalar(0.809017),btScalar(-0.000000)), 347 btVector3(btScalar(0.688190) , btScalar(-0.499997),btScalar(0.525736)), 348 btVector3(btScalar(-0.262869) , btScalar(-0.809012),btScalar(0.525738)), 349 btVector3(btScalar(-0.850648) , btScalar(0.000000),btScalar(0.525736)), 350 btVector3(btScalar(-0.262869) , btScalar(0.809012),btScalar(0.525738)), 351 btVector3(btScalar(0.688190) , btScalar(0.499997),btScalar(0.525736)), 352 btVector3(btScalar(0.525730) , btScalar(0.000000),btScalar(0.850652)), 353 btVector3(btScalar(0.162456) , btScalar(-0.499995),btScalar(0.850654)), 354 btVector3(btScalar(-0.425323) , btScalar(-0.309011),btScalar(0.850654)), 355 btVector3(btScalar(-0.425323) , btScalar(0.309011),btScalar(0.850654)), 356 btVector3(btScalar(0.162456) , btScalar(0.499995),btScalar(0.850654)) 357 }; 358 359 return sPenetrationDirections; 360 } 361 362 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h
r5781 r8351 23 23 class btMinkowskiPenetrationDepthSolver : public btConvexPenetrationDepthSolver 24 24 { 25 protected: 26 27 static btVector3* getPenetrationDirections(); 28 25 29 public: 26 30 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.cpp
r5781 r8351 26 26 27 27 btPersistentManifold::btPersistentManifold() 28 :m_body0(0), 28 :btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE), 29 m_body0(0), 29 30 m_body1(0), 30 31 m_cachedPoints (0), -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h
r5781 r8351 31 31 typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1); 32 32 extern ContactDestroyedCallback gContactDestroyedCallback; 33 34 35 33 extern ContactProcessedCallback gContactProcessedCallback; 34 35 36 enum btContactManifoldTypes 37 { 38 BT_PERSISTENT_MANIFOLD_TYPE = 1, 39 MAX_CONTACT_MANIFOLD_TYPE 40 }; 36 41 37 42 #define MANIFOLD_CACHE_SIZE 4 … … 44 49 ///the contact point with deepest penetration is always kept, and it tries to maximuze the area covered by the points 45 50 ///note that some pairs of objects might have more then one contact manifold. 46 ATTRIBUTE_ALIGNED16( class) btPersistentManifold 51 52 53 ATTRIBUTE_ALIGNED128( class) btPersistentManifold : public btTypedObject 54 //ATTRIBUTE_ALIGNED16( class) btPersistentManifold : public btTypedObject 47 55 { 48 56 … … 53 61 void* m_body0; 54 62 void* m_body1; 63 55 64 int m_cachedPoints; 56 65 … … 68 77 BT_DECLARE_ALIGNED_ALLOCATOR(); 69 78 79 int m_companionIdA; 80 int m_companionIdB; 81 70 82 int m_index1a; 71 83 … … 73 85 74 86 btPersistentManifold(void* body0,void* body1,int , btScalar contactBreakingThreshold,btScalar contactProcessingThreshold) 75 : m_body0(body0),m_body1(body1),m_cachedPoints(0), 87 : btTypedObject(BT_PERSISTENT_MANIFOLD_TYPE), 88 m_body0(body0),m_body1(body1),m_cachedPoints(0), 76 89 m_contactBreakingThreshold(contactBreakingThreshold), 77 90 m_contactProcessingThreshold(contactProcessingThreshold) 78 91 { 79 80 92 } 81 93 … … 135 147 //get rid of duplicated userPersistentData pointer 136 148 m_pointCache[lastUsedIndex].m_userPersistentData = 0; 149 m_pointCache[lastUsedIndex].mConstraintRow[0].mAccumImpulse = 0.f; 150 m_pointCache[lastUsedIndex].mConstraintRow[1].mAccumImpulse = 0.f; 151 m_pointCache[lastUsedIndex].mConstraintRow[2].mAccumImpulse = 0.f; 152 137 153 m_pointCache[lastUsedIndex].m_appliedImpulse = 0.f; 138 154 m_pointCache[lastUsedIndex].m_lateralFrictionInitialized = false; … … 152 168 #ifdef MAINTAIN_PERSISTENCY 153 169 int lifeTime = m_pointCache[insertIndex].getLifeTime(); 154 btScalar appliedImpulse = m_pointCache[insertIndex].m_appliedImpulse; 155 btScalar appliedLateralImpulse1 = m_pointCache[insertIndex].m_appliedImpulseLateral1; 156 btScalar appliedLateralImpulse2 = m_pointCache[insertIndex].m_appliedImpulseLateral2; 157 170 btScalar appliedImpulse = m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse; 171 btScalar appliedLateralImpulse1 = m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse; 172 btScalar appliedLateralImpulse2 = m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse; 173 // bool isLateralFrictionInitialized = m_pointCache[insertIndex].m_lateralFrictionInitialized; 174 175 176 158 177 btAssert(lifeTime>=0); 159 178 void* cache = m_pointCache[insertIndex].m_userPersistentData; … … 166 185 m_pointCache[insertIndex].m_appliedImpulseLateral2 = appliedLateralImpulse2; 167 186 187 m_pointCache[insertIndex].mConstraintRow[0].mAccumImpulse = appliedImpulse; 188 m_pointCache[insertIndex].mConstraintRow[1].mAccumImpulse = appliedLateralImpulse1; 189 m_pointCache[insertIndex].mConstraintRow[2].mAccumImpulse = appliedLateralImpulse2; 190 191 168 192 m_pointCache[insertIndex].m_lifeTime = lifeTime; 169 193 #else -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btPointCollector.h
r5781 r8351 32 32 33 33 btPointCollector () 34 : m_distance(btScalar( 1e30)),m_hasResult(false)34 : m_distance(btScalar(BT_LARGE_FLOAT)),m_hasResult(false) 35 35 { 36 36 } 37 37 38 virtual void setShapeIdentifiers (int partId0,int index0, int partId1,int index1)38 virtual void setShapeIdentifiersA(int partId0,int index0) 39 39 { 40 40 (void)partId0; 41 41 (void)index0; 42 43 } 44 virtual void setShapeIdentifiersB(int partId1,int index1) 45 { 42 46 (void)partId1; 43 47 (void)index1; 44 //??45 48 } 46 49 -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.cpp
r5781 r8351 115 115 } 116 116 } 117 m_simplexSolver->addVertex( w, supVertexA , supVertexB); 117 ///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. 118 if (!m_simplexSolver->inSimplex(w)) 119 m_simplexSolver->addVertex( w, supVertexA , supVertexB); 120 118 121 if (m_simplexSolver->closest(v)) 119 122 { -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.cpp
r5781 r8351 69 69 m_numVertices = 0; 70 70 m_needsUpdate = true; 71 m_lastW = btVector3(btScalar( 1e30),btScalar(1e30),btScalar(1e30));71 m_lastW = btVector3(btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT),btScalar(BT_LARGE_FLOAT)); 72 72 m_cachedBC.reset(); 73 73 } … … 290 290 for (i=0;i<numverts;i++) 291 291 { 292 #ifdef BT_USE_EQUAL_VERTEX_THRESHOLD 293 if ( m_simplexVectorW[i].distance2(w) <= m_equalVertexThreshold) 294 #else 292 295 if (m_simplexVectorW[i] == w) 296 #endif 293 297 found = true; 294 298 } -
code/trunk/src/external/bullet/BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h
r5781 r8351 24 24 25 25 #define VORONOI_SIMPLEX_MAX_VERTS 5 26 27 ///disable next define, or use defaultCollisionConfiguration->getSimplexSolver()->setEqualVertexThreshold(0.f) to disable/configure 28 #define BT_USE_EQUAL_VERTEX_THRESHOLD 29 #define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 0.0001f 30 26 31 27 32 struct btUsageBitfield{ … … 107 112 btVector3 m_cachedV; 108 113 btVector3 m_lastW; 114 115 btScalar m_equalVertexThreshold; 109 116 bool m_cachedValidClosest; 117 110 118 111 119 btSubSimplexClosestResult m_cachedBC; … … 123 131 public: 124 132 133 btVoronoiSimplexSolver() 134 : m_equalVertexThreshold(VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD) 135 { 136 } 125 137 void reset(); 126 138 127 139 void addVertex(const btVector3& w, const btVector3& p, const btVector3& q); 128 140 141 void setEqualVertexThreshold(btScalar threshold) 142 { 143 m_equalVertexThreshold = threshold; 144 } 145 146 btScalar getEqualVertexThreshold() const 147 { 148 return m_equalVertexThreshold; 149 } 129 150 130 151 bool closest(btVector3& v); -
code/trunk/src/external/bullet/BulletDynamics/CMakeLists.txt
r5929 r8351 3 3 COMPILATION_BEGIN BulletDynamicsCompilation.cpp 4 4 5 Character/btKinematicCharacterController.cpp 6 7 ConstraintSolver/btConeTwistConstraint.cpp 5 8 ConstraintSolver/btContactConstraint.cpp 6 ConstraintSolver/btConeTwistConstraint.cpp7 9 ConstraintSolver/btGeneric6DofConstraint.cpp 10 ConstraintSolver/btGeneric6DofSpringConstraint.cpp 11 ConstraintSolver/btHinge2Constraint.cpp 8 12 ConstraintSolver/btHingeConstraint.cpp 9 13 ConstraintSolver/btPoint2PointConstraint.cpp … … 12 16 ConstraintSolver/btSolve2LinearConstraint.cpp 13 17 ConstraintSolver/btTypedConstraint.cpp 18 ConstraintSolver/btUniversalConstraint.cpp 14 19 20 Dynamics/btContinuousDynamicsWorld.cpp 21 Dynamics/btDiscreteDynamicsWorld.cpp 22 Dynamics/btRigidBody.cpp 23 Dynamics/btSimpleDynamicsWorld.cpp 15 24 Dynamics/Bullet-C-API.cpp 16 Dynamics/btDiscreteDynamicsWorld.cpp17 Dynamics/btSimpleDynamicsWorld.cpp18 Dynamics/btRigidBody.cpp19 20 25 Vehicle/btRaycastVehicle.cpp 21 26 Vehicle/btWheelInfo.cpp 22 23 Character/btKinematicCharacterController.cpp24 27 25 28 COMPILATION_END 26 29 27 30 # Headers 31 ConstraintSolver/btConeTwistConstraint.h 28 32 ConstraintSolver/btConstraintSolver.h 29 33 ConstraintSolver/btContactConstraint.h 30 34 ConstraintSolver/btContactSolverInfo.h 31 ConstraintSolver/btConeTwistConstraint.h32 35 ConstraintSolver/btGeneric6DofConstraint.h 36 ConstraintSolver/btGeneric6DofSpringConstraint.h 37 ConstraintSolver/btHinge2Constraint.h 33 38 ConstraintSolver/btHingeConstraint.h 34 39 ConstraintSolver/btJacobianEntry.h … … 40 45 ConstraintSolver/btSolverConstraint.h 41 46 ConstraintSolver/btTypedConstraint.h 42 47 ConstraintSolver/btUniversalConstraint.h 43 48 Dynamics/btActionInterface.h 44 49 Dynamics/btContinuousDynamicsWorld.h -
code/trunk/src/external/bullet/BulletDynamics/Character/btCharacterControllerInterface.h
r5781 r8351 31 31 32 32 virtual void setWalkDirection(const btVector3& walkDirection) = 0; 33 virtual void setVelocityForTimeInterval(const btVector3& velocity, btScalar timeInterval) = 0; 33 34 virtual void reset () = 0; 34 35 virtual void warp (const btVector3& origin) = 0; -
code/trunk/src/external/bullet/BulletDynamics/Character/btKinematicCharacterController.cpp
r5781 r8351 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #include "LinearMath/btIDebugDraw.h" … … 23 24 #include "btKinematicCharacterController.h" 24 25 25 static btVector3 upAxisDirection[3] = { btVector3(1.0f, 0.0f, 0.0f), btVector3(0.0f, 1.0f, 0.0f), btVector3(0.0f, 0.0f, 1.0f) }; 26 27 // static helper method 28 static btVector3 29 getNormalizedVector(const btVector3& v) 30 { 31 btVector3 n = v.normalized(); 32 if (n.length() < SIMD_EPSILON) { 33 n.setValue(0, 0, 0); 34 } 35 return n; 36 } 37 26 38 27 39 ///@todo Interact with dynamic objects, … … 53 65 { 54 66 public: 55 btKinematicClosestNotMeConvexResultCallback (btCollisionObject* me) : btCollisionWorld::ClosestConvexResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0)) 56 { 57 m_me = me; 67 btKinematicClosestNotMeConvexResultCallback (btCollisionObject* me, const btVector3& up, btScalar minSlopeDot) 68 : btCollisionWorld::ClosestConvexResultCallback(btVector3(0.0, 0.0, 0.0), btVector3(0.0, 0.0, 0.0)) 69 , m_me(me) 70 , m_up(up) 71 , m_minSlopeDot(minSlopeDot) 72 { 58 73 } 59 74 … … 61 76 { 62 77 if (convexResult.m_hitCollisionObject == m_me) 63 return 1.0; 78 return btScalar(1.0); 79 80 btVector3 hitNormalWorld; 81 if (normalInWorldSpace) 82 { 83 hitNormalWorld = convexResult.m_hitNormalLocal; 84 } else 85 { 86 ///need to transform normal into worldspace 87 hitNormalWorld = m_hitCollisionObject->getWorldTransform().getBasis()*convexResult.m_hitNormalLocal; 88 } 89 90 btScalar dotUp = m_up.dot(hitNormalWorld); 91 if (dotUp < m_minSlopeDot) { 92 return btScalar(1.0); 93 } 64 94 65 95 return ClosestConvexResultCallback::addSingleResult (convexResult, normalInWorldSpace); … … 67 97 protected: 68 98 btCollisionObject* m_me; 99 const btVector3 m_up; 100 btScalar m_minSlopeDot; 69 101 }; 70 102 … … 99 131 { 100 132 m_upAxis = upAxis; 101 m_addedMargin = 0.02 f;133 m_addedMargin = 0.02; 102 134 m_walkDirection.setValue(0,0,0); 103 135 m_useGhostObjectSweepTest = true; … … 106 138 m_turnAngle = btScalar(0.0); 107 139 m_convexShape=convexShape; 140 m_useWalkDirection = true; // use walk direction by default, legacy behavior 141 m_velocityTimeInterval = 0.0; 142 m_verticalVelocity = 0.0; 143 m_verticalOffset = 0.0; 144 m_gravity = 9.8 * 3 ; // 3G acceleration. 145 m_fallSpeed = 55.0; // Terminal velocity of a sky diver in m/s. 146 m_jumpSpeed = 10.0; // ? 147 m_wasOnGround = false; 148 m_wasJumping = false; 149 setMaxSlope(btRadians(45.0)); 108 150 } 109 151 … … 145 187 const btManifoldPoint&pt = manifold->getContactPoint(p); 146 188 147 if (pt.getDistance() < 0.0) 189 btScalar dist = pt.getDistance(); 190 191 if (dist < 0.0) 148 192 { 149 if ( pt.getDistance()< maxPen)193 if (dist < maxPen) 150 194 { 151 maxPen = pt.getDistance();195 maxPen = dist; 152 196 m_touchingNormal = pt.m_normalWorldOnB * directionSign;//?? 153 197 154 198 } 155 m_currentPosition += pt.m_normalWorldOnB * directionSign * pt.getDistance()* btScalar(0.2);199 m_currentPosition += pt.m_normalWorldOnB * directionSign * dist * btScalar(0.2); 156 200 penetration = true; 157 201 } else { 158 //printf("touching %f\n", pt.getDistance());202 //printf("touching %f\n", dist); 159 203 } 160 204 } … … 174 218 // phase 1: up 175 219 btTransform start, end; 176 m_targetPosition = m_currentPosition + upAxisDirection[m_upAxis] * m_stepHeight;220 m_targetPosition = m_currentPosition + getUpAxisDirections()[m_upAxis] * (m_stepHeight + (m_verticalOffset > 0.f?m_verticalOffset:0.f)); 177 221 178 222 start.setIdentity (); … … 180 224 181 225 /* FIXME: Handle penetration properly */ 182 start.setOrigin (m_currentPosition + upAxisDirection[m_upAxis] * btScalar(0.1f));226 start.setOrigin (m_currentPosition + getUpAxisDirections()[m_upAxis] * (m_convexShape->getMargin() + m_addedMargin)); 183 227 end.setOrigin (m_targetPosition); 184 228 185 btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject );229 btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, -getUpAxisDirections()[m_upAxis], btScalar(0.7071)); 186 230 callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup; 187 231 callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask; … … 198 242 if (callback.hasHit()) 199 243 { 200 // we moved up only a fraction of the step height 201 m_currentStepOffset = m_stepHeight * callback.m_closestHitFraction; 202 m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); 244 // Only modify the position if the hit was a slope and not a wall or ceiling. 245 if(callback.m_hitNormalWorld.dot(getUpAxisDirections()[m_upAxis]) > 0.0) 246 { 247 // we moved up only a fraction of the step height 248 m_currentStepOffset = m_stepHeight * callback.m_closestHitFraction; 249 m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); 250 } 251 m_verticalVelocity = 0.0; 252 m_verticalOffset = 0.0; 203 253 } else { 204 254 m_currentStepOffset = m_stepHeight; … … 245 295 void btKinematicCharacterController::stepForwardAndStrafe ( btCollisionWorld* collisionWorld, const btVector3& walkMove) 246 296 { 247 248 btVector3 originalDir = walkMove.normalized(); 249 if (walkMove.length() < SIMD_EPSILON) 250 { 251 originalDir.setValue(0.f,0.f,0.f); 252 } 253 // printf("originalDir=%f,%f,%f\n",originalDir[0],originalDir[1],originalDir[2]); 297 // printf("m_normalizedDirection=%f,%f,%f\n", 298 // m_normalizedDirection[0],m_normalizedDirection[1],m_normalizedDirection[2]); 254 299 // phase 2: forward and strafe 255 300 btTransform start, end; 256 301 m_targetPosition = m_currentPosition + walkMove; 302 257 303 start.setIdentity (); 258 304 end.setIdentity (); … … 264 310 if (m_touchingContact) 265 311 { 266 if (originalDir.dot(m_touchingNormal) > btScalar(0.0)) 312 if (m_normalizedDirection.dot(m_touchingNormal) > btScalar(0.0)) 313 { 267 314 updateTargetPositionBasedOnCollision (m_touchingNormal); 315 } 268 316 } 269 317 … … 274 322 start.setOrigin (m_currentPosition); 275 323 end.setOrigin (m_targetPosition); 276 277 btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject); 324 btVector3 sweepDirNegative(m_currentPosition - m_targetPosition); 325 326 btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, sweepDirNegative, btScalar(0.0)); 278 327 callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup; 279 328 callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask; … … 300 349 { 301 350 // we moved only a fraction 302 btScalar hitDistance = (callback.m_hitPointWorld - m_currentPosition).length(); 303 if (hitDistance<0.f) 304 { 305 // printf("neg dist?\n"); 306 } 307 308 /* If the distance is farther than the collision margin, move */ 309 if (hitDistance > m_addedMargin) 310 { 311 // printf("callback.m_closestHitFraction=%f\n",callback.m_closestHitFraction); 312 m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); 313 } 351 btScalar hitDistance; 352 hitDistance = (callback.m_hitPointWorld - m_currentPosition).length(); 353 354 // m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); 314 355 315 356 updateTargetPositionBasedOnCollision (callback.m_hitNormalWorld); … … 320 361 currentDir.normalize(); 321 362 /* See Quake2: "If velocity is against original velocity, stop ead to avoid tiny oscilations in sloping corners." */ 322 if (currentDir.dot( originalDir) <= btScalar(0.0))363 if (currentDir.dot(m_normalizedDirection) <= btScalar(0.0)) 323 364 { 324 365 break; … … 329 370 break; 330 371 } 372 331 373 } else { 332 374 // we moved whole way … … 345 387 346 388 // phase 3: down 347 btVector3 step_drop = upAxisDirection[m_upAxis] * m_currentStepOffset; 348 btVector3 gravity_drop = upAxisDirection[m_upAxis] * m_stepHeight; 349 m_targetPosition -= (step_drop + gravity_drop); 389 /*btScalar additionalDownStep = (m_wasOnGround && !onGround()) ? m_stepHeight : 0.0; 390 btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + additionalDownStep); 391 btScalar downVelocity = (additionalDownStep == 0.0 && m_verticalVelocity<0.0?-m_verticalVelocity:0.0) * dt; 392 btVector3 gravity_drop = getUpAxisDirections()[m_upAxis] * downVelocity; 393 m_targetPosition -= (step_drop + gravity_drop);*/ 394 395 btScalar downVelocity = (m_verticalVelocity<0.f?-m_verticalVelocity:0.f) * dt; 396 if(downVelocity > 0.0 && downVelocity < m_stepHeight 397 && (m_wasOnGround || !m_wasJumping)) 398 { 399 downVelocity = m_stepHeight; 400 } 401 402 btVector3 step_drop = getUpAxisDirections()[m_upAxis] * (m_currentStepOffset + downVelocity); 403 m_targetPosition -= step_drop; 350 404 351 405 start.setIdentity (); … … 355 409 end.setOrigin (m_targetPosition); 356 410 357 btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject );411 btKinematicClosestNotMeConvexResultCallback callback (m_ghostObject, getUpAxisDirections()[m_upAxis], m_maxSlopeCosine); 358 412 callback.m_collisionFilterGroup = getGhostObject()->getBroadphaseHandle()->m_collisionFilterGroup; 359 413 callback.m_collisionFilterMask = getGhostObject()->getBroadphaseHandle()->m_collisionFilterMask; … … 371 425 // we dropped a fraction of the height -> hit floor 372 426 m_currentPosition.setInterpolate3 (m_currentPosition, m_targetPosition, callback.m_closestHitFraction); 427 m_verticalVelocity = 0.0; 428 m_verticalOffset = 0.0; 429 m_wasJumping = false; 373 430 } else { 374 431 // we dropped the full height … … 378 435 } 379 436 437 438 439 void btKinematicCharacterController::setWalkDirection 440 ( 441 const btVector3& walkDirection 442 ) 443 { 444 m_useWalkDirection = true; 445 m_walkDirection = walkDirection; 446 m_normalizedDirection = getNormalizedVector(m_walkDirection); 447 } 448 449 450 451 void btKinematicCharacterController::setVelocityForTimeInterval 452 ( 453 const btVector3& velocity, 454 btScalar timeInterval 455 ) 456 { 457 // printf("setVelocity!\n"); 458 // printf(" interval: %f\n", timeInterval); 459 // printf(" velocity: (%f, %f, %f)\n", 460 // velocity.x(), velocity.y(), velocity.z()); 461 462 m_useWalkDirection = false; 463 m_walkDirection = velocity; 464 m_normalizedDirection = getNormalizedVector(m_walkDirection); 465 m_velocityTimeInterval = timeInterval; 466 } 467 468 469 380 470 void btKinematicCharacterController::reset () 381 471 { … … 402 492 if (numPenetrationLoops > 4) 403 493 { 404 //printf("character could not recover from penetration = %d\n", numPenetrationLoops);494 //printf("character could not recover from penetration = %d\n", numPenetrationLoops); 405 495 break; 406 496 } … … 414 504 } 415 505 506 #include <stdio.h> 507 416 508 void btKinematicCharacterController::playerStep ( btCollisionWorld* collisionWorld, btScalar dt) 417 509 { 510 // printf("playerStep(): "); 511 // printf(" dt = %f", dt); 512 513 // quick check... 514 if (!m_useWalkDirection && m_velocityTimeInterval <= 0.0) { 515 // printf("\n"); 516 return; // no motion 517 } 518 519 m_wasOnGround = onGround(); 520 521 // Update fall velocity. 522 m_verticalVelocity -= m_gravity * dt; 523 if(m_verticalVelocity > 0.0 && m_verticalVelocity > m_jumpSpeed) 524 { 525 m_verticalVelocity = m_jumpSpeed; 526 } 527 if(m_verticalVelocity < 0.0 && btFabs(m_verticalVelocity) > btFabs(m_fallSpeed)) 528 { 529 m_verticalVelocity = -btFabs(m_fallSpeed); 530 } 531 m_verticalOffset = m_verticalVelocity * dt; 532 533 418 534 btTransform xform; 419 535 xform = m_ghostObject->getWorldTransform (); … … 423 539 424 540 stepUp (collisionWorld); 425 stepForwardAndStrafe (collisionWorld, m_walkDirection); 541 if (m_useWalkDirection) { 542 stepForwardAndStrafe (collisionWorld, m_walkDirection); 543 } else { 544 //printf(" time: %f", m_velocityTimeInterval); 545 // still have some time left for moving! 546 btScalar dtMoving = 547 (dt < m_velocityTimeInterval) ? dt : m_velocityTimeInterval; 548 m_velocityTimeInterval -= dt; 549 550 // how far will we move while we are moving? 551 btVector3 move = m_walkDirection * dtMoving; 552 553 //printf(" dtMoving: %f", dtMoving); 554 555 // okay, step 556 stepForwardAndStrafe(collisionWorld, move); 557 } 426 558 stepDown (collisionWorld, dt); 559 560 // printf("\n"); 427 561 428 562 xform.setOrigin (m_currentPosition); … … 454 588 if (!canJump()) 455 589 return; 590 591 m_verticalVelocity = m_jumpSpeed; 592 m_wasJumping = true; 456 593 457 594 #if 0 … … 466 603 } 467 604 605 void btKinematicCharacterController::setGravity(btScalar gravity) 606 { 607 m_gravity = gravity; 608 } 609 610 btScalar btKinematicCharacterController::getGravity() const 611 { 612 return m_gravity; 613 } 614 615 void btKinematicCharacterController::setMaxSlope(btScalar slopeRadians) 616 { 617 m_maxSlopeRadians = slopeRadians; 618 m_maxSlopeCosine = btCos(slopeRadians); 619 } 620 621 btScalar btKinematicCharacterController::getMaxSlope() const 622 { 623 return m_maxSlopeRadians; 624 } 625 468 626 bool btKinematicCharacterController::onGround () const 469 627 { 470 return true; 471 } 472 473 474 void btKinematicCharacterController::debugDraw(btIDebugDraw* debugDrawer) 475 { 476 } 628 return m_verticalVelocity == 0.0 && m_verticalOffset == 0.0; 629 } 630 631 632 btVector3* btKinematicCharacterController::getUpAxisDirections() 633 { 634 static btVector3 sUpAxisDirection[3] = { btVector3(1.0f, 0.0f, 0.0f), btVector3(0.0f, 1.0f, 0.0f), btVector3(0.0f, 0.0f, 1.0f) }; 635 636 return sUpAxisDirection; 637 } 638 639 void btKinematicCharacterController::debugDraw(btIDebugDraw* debugDrawer) 640 { 641 } -
code/trunk/src/external/bullet/BulletDynamics/Character/btKinematicCharacterController.h
r5781 r8351 14 14 */ 15 15 16 16 17 #ifndef KINEMATIC_CHARACTER_CONTROLLER_H 17 18 #define KINEMATIC_CHARACTER_CONTROLLER_H … … 20 21 21 22 #include "btCharacterControllerInterface.h" 23 24 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 25 22 26 23 27 class btCollisionShape; … … 33 37 { 34 38 protected: 39 35 40 btScalar m_halfHeight; 36 41 … … 38 43 btConvexShape* m_convexShape;//is also in m_ghostObject, but it needs to be convex, so we store it here to avoid upcast 39 44 45 btScalar m_verticalVelocity; 46 btScalar m_verticalOffset; 40 47 btScalar m_fallSpeed; 41 48 btScalar m_jumpSpeed; 42 49 btScalar m_maxJumpHeight; 50 btScalar m_maxSlopeRadians; // Slope angle that is set (used for returning the exact value) 51 btScalar m_maxSlopeCosine; // Cosine equivalent of m_maxSlopeRadians (calculated once when set, for optimization) 52 btScalar m_gravity; 43 53 44 54 btScalar m_turnAngle; … … 50 60 ///this is the desired walk direction, set by the user 51 61 btVector3 m_walkDirection; 62 btVector3 m_normalizedDirection; 52 63 53 64 //some internal variables … … 62 73 btVector3 m_touchingNormal; 63 74 75 bool m_wasOnGround; 76 bool m_wasJumping; 64 77 bool m_useGhostObjectSweepTest; 78 bool m_useWalkDirection; 79 btScalar m_velocityTimeInterval; 80 int m_upAxis; 65 81 66 int m_upAxis;67 82 static btVector3* getUpAxisDirections(); 83 68 84 btVector3 computeReflectionDirection (const btVector3& direction, const btVector3& normal); 69 85 btVector3 parallelComponent (const btVector3& direction, const btVector3& normal); … … 99 115 } 100 116 101 virtual void setWalkDirection(const btVector3& walkDirection) 102 { 103 m_walkDirection = walkDirection; 104 } 117 /// This should probably be called setPositionIncrementPerSimulatorStep. 118 /// This is neither a direction nor a velocity, but the amount to 119 /// increment the position each simulation iteration, regardless 120 /// of dt. 121 /// This call will reset any velocity set by setVelocityForTimeInterval(). 122 virtual void setWalkDirection(const btVector3& walkDirection); 123 124 /// Caller provides a velocity with which the character should move for 125 /// the given time period. After the time period, velocity is reset 126 /// to zero. 127 /// This call will reset any walk direction set by setWalkDirection(). 128 /// Negative time intervals will result in no motion. 129 virtual void setVelocityForTimeInterval(const btVector3& velocity, 130 btScalar timeInterval); 105 131 106 132 void reset (); … … 114 140 void setMaxJumpHeight (btScalar maxJumpHeight); 115 141 bool canJump () const; 142 116 143 void jump (); 144 145 void setGravity(btScalar gravity); 146 btScalar getGravity() const; 147 148 /// The max slope determines the maximum angle that the controller can walk up. 149 /// The slope angle is measured in radians. 150 void setMaxSlope(btScalar slopeRadians); 151 btScalar getMaxSlope() const; 117 152 118 153 btPairCachingGhostObject* getGhostObject(); -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btConeTwistConstraint.cpp
r5781 r8351 23 23 #include <new> 24 24 25 //----------------------------------------------------------------------------- 26 25 26 27 //#define CONETWIST_USE_OBSOLETE_SOLVER true 27 28 #define CONETWIST_USE_OBSOLETE_SOLVER false 28 29 #define CONETWIST_DEF_FIX_THRESH btScalar(.05f) 29 30 30 //----------------------------------------------------------------------------- 31 32 btConeTwistConstraint::btConeTwistConstraint() 33 :btTypedConstraint(CONETWIST_CONSTRAINT_TYPE), 34 m_useSolveConstraintObsolete(CONETWIST_USE_OBSOLETE_SOLVER) 35 { 36 } 31 32 SIMD_FORCE_INLINE btScalar computeAngularImpulseDenominator(const btVector3& axis, const btMatrix3x3& invInertiaWorld) 33 { 34 btVector3 vec = axis * invInertiaWorld; 35 return axis.dot(vec); 36 } 37 38 37 39 38 40 … … 64 66 m_maxMotorImpulse = btScalar(-1); 65 67 66 setLimit(btScalar( 1e30), btScalar(1e30), btScalar(1e30));68 setLimit(btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT), btScalar(BT_LARGE_FLOAT)); 67 69 m_damping = btScalar(0.01); 68 70 m_fixThresh = CONETWIST_DEF_FIX_THRESH; 69 } 70 71 72 //----------------------------------------------------------------------------- 71 m_flags = 0; 72 m_linCFM = btScalar(0.f); 73 m_linERP = btScalar(0.7f); 74 m_angCFM = btScalar(0.f); 75 } 76 73 77 74 78 void btConeTwistConstraint::getInfo1 (btConstraintInfo1* info) … … 83 87 info->m_numConstraintRows = 3; 84 88 info->nub = 3; 85 calcAngleInfo2( );89 calcAngleInfo2(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform(),m_rbA.getInvInertiaTensorWorld(),m_rbB.getInvInertiaTensorWorld()); 86 90 if(m_solveSwingLimit) 87 91 { … … 100 104 } 101 105 } 102 } // btConeTwistConstraint::getInfo1() 106 } 107 108 void btConeTwistConstraint::getInfo1NonVirtual (btConstraintInfo1* info) 109 { 110 //always reserve 6 rows: object transform is not available on SPU 111 info->m_numConstraintRows = 6; 112 info->nub = 0; 113 114 } 103 115 104 //-----------------------------------------------------------------------------105 116 106 117 void btConeTwistConstraint::getInfo2 (btConstraintInfo2* info) 107 118 { 119 getInfo2NonVirtual(info,m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform(),m_rbA.getInvInertiaTensorWorld(),m_rbB.getInvInertiaTensorWorld()); 120 } 121 122 void btConeTwistConstraint::getInfo2NonVirtual (btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB) 123 { 124 calcAngleInfo2(transA,transB,invInertiaWorldA,invInertiaWorldB); 125 108 126 btAssert(!m_useSolveConstraintObsolete); 109 //retrieve matrices110 btTransform body0_trans;111 body0_trans = m_rbA.getCenterOfMassTransform();112 btTransform body1_trans;113 body1_trans = m_rbB.getCenterOfMassTransform();114 127 // set jacobian 115 128 info->m_J1linearAxis[0] = 1; 116 129 info->m_J1linearAxis[info->rowskip+1] = 1; 117 130 info->m_J1linearAxis[2*info->rowskip+2] = 1; 118 btVector3 a1 = body0_trans.getBasis() * m_rbAFrame.getOrigin();131 btVector3 a1 = transA.getBasis() * m_rbAFrame.getOrigin(); 119 132 { 120 133 btVector3* angular0 = (btVector3*)(info->m_J1angularAxis); … … 124 137 a1neg.getSkewSymmetricMatrix(angular0,angular1,angular2); 125 138 } 126 btVector3 a2 = body1_trans.getBasis() * m_rbBFrame.getOrigin();139 btVector3 a2 = transB.getBasis() * m_rbBFrame.getOrigin(); 127 140 { 128 141 btVector3* angular0 = (btVector3*)(info->m_J2angularAxis); … … 132 145 } 133 146 // set right hand side 134 btScalar k = info->fps * info->erp; 147 btScalar linERP = (m_flags & BT_CONETWIST_FLAGS_LIN_ERP) ? m_linERP : info->erp; 148 btScalar k = info->fps * linERP; 135 149 int j; 136 150 for (j=0; j<3; j++) 137 151 { 138 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]);152 info->m_constraintError[j*info->rowskip] = k * (a2[j] + transB.getOrigin()[j] - a1[j] - transA.getOrigin()[j]); 139 153 info->m_lowerLimit[j*info->rowskip] = -SIMD_INFINITY; 140 154 info->m_upperLimit[j*info->rowskip] = SIMD_INFINITY; 155 if(m_flags & BT_CONETWIST_FLAGS_LIN_CFM) 156 { 157 info->cfm[j*info->rowskip] = m_linCFM; 158 } 141 159 } 142 160 int row = 3; … … 150 168 if((m_swingSpan1 < m_fixThresh) && (m_swingSpan2 < m_fixThresh)) 151 169 { 152 btTransform trA = m_rbA.getCenterOfMassTransform()*m_rbAFrame;170 btTransform trA = transA*m_rbAFrame; 153 171 btVector3 p = trA.getBasis().getColumn(1); 154 172 btVector3 q = trA.getBasis().getColumn(2); … … 187 205 188 206 info->m_constraintError[srow] = k * m_swingCorrection; 189 info->cfm[srow] = 0.0f; 207 if(m_flags & BT_CONETWIST_FLAGS_ANG_CFM) 208 { 209 info->cfm[srow] = m_angCFM; 210 } 190 211 // m_swingCorrection is always positive or 0 191 212 info->m_lowerLimit[srow] = 0; … … 207 228 btScalar k = info->fps * m_biasFactor; 208 229 info->m_constraintError[srow] = k * m_twistCorrection; 209 info->cfm[srow] = 0.0f; 230 if(m_flags & BT_CONETWIST_FLAGS_ANG_CFM) 231 { 232 info->cfm[srow] = m_angCFM; 233 } 210 234 if(m_twistSpan > 0.0f) 211 235 { … … 231 255 } 232 256 233 //----------------------------------------------------------------------------- 257 234 258 235 259 void btConeTwistConstraint::buildJacobian() … … 240 264 m_accTwistLimitImpulse = btScalar(0.); 241 265 m_accSwingLimitImpulse = btScalar(0.); 266 m_accMotorImpulse = btVector3(0.,0.,0.); 242 267 243 268 if (!m_angularOnly) … … 274 299 } 275 300 276 calcAngleInfo2(); 277 } 278 } 279 280 //----------------------------------------------------------------------------- 281 282 void btConeTwistConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) 283 { 301 calcAngleInfo2(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform(),m_rbA.getInvInertiaTensorWorld(),m_rbB.getInvInertiaTensorWorld()); 302 } 303 } 304 305 306 307 void btConeTwistConstraint::solveConstraintObsolete(btRigidBody& bodyA,btRigidBody& bodyB,btScalar timeStep) 308 { 309 #ifndef __SPU__ 284 310 if (m_useSolveConstraintObsolete) 285 311 { … … 296 322 297 323 btVector3 vel1; 298 bodyA. getVelocityInLocalPointObsolete(rel_pos1,vel1);324 bodyA.internalGetVelocityInLocalPointObsolete(rel_pos1,vel1); 299 325 btVector3 vel2; 300 bodyB. getVelocityInLocalPointObsolete(rel_pos2,vel2);326 bodyB.internalGetVelocityInLocalPointObsolete(rel_pos2,vel2); 301 327 btVector3 vel = vel1 - vel2; 302 328 … … 315 341 btVector3 ftorqueAxis1 = rel_pos1.cross(normal); 316 342 btVector3 ftorqueAxis2 = rel_pos2.cross(normal); 317 bodyA. applyImpulse(normal*m_rbA.getInvMass(), m_rbA.getInvInertiaTensorWorld()*ftorqueAxis1,impulse);318 bodyB. applyImpulse(normal*m_rbB.getInvMass(), m_rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-impulse);343 bodyA.internalApplyImpulse(normal*m_rbA.getInvMass(), m_rbA.getInvInertiaTensorWorld()*ftorqueAxis1,impulse); 344 bodyB.internalApplyImpulse(normal*m_rbB.getInvMass(), m_rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-impulse); 319 345 320 346 } … … 327 353 btTransform trACur = m_rbA.getCenterOfMassTransform(); 328 354 btTransform trBCur = m_rbB.getCenterOfMassTransform(); 329 btVector3 omegaA; bodyA. getAngularVelocity(omegaA);330 btVector3 omegaB; bodyB. getAngularVelocity(omegaB);355 btVector3 omegaA; bodyA.internalGetAngularVelocity(omegaA); 356 btVector3 omegaB; bodyB.internalGetAngularVelocity(omegaB); 331 357 btTransform trAPred; trAPred.setIdentity(); 332 358 btVector3 zerovec(0,0,0); … … 402 428 btVector3 impulseAxis = impulse / impulseMag; 403 429 404 bodyA. applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*impulseAxis, impulseMag);405 bodyB. applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*impulseAxis, -impulseMag);406 407 } 408 } 409 else // no motor: do a little damping410 { 411 const btVector3& angVelA = getRigidBodyA().getAngularVelocity();412 const btVector3& angVelB = getRigidBodyB().getAngularVelocity();430 bodyA.internalApplyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*impulseAxis, impulseMag); 431 bodyB.internalApplyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*impulseAxis, -impulseMag); 432 433 } 434 } 435 else if (m_damping > SIMD_EPSILON) // no motor: do a little damping 436 { 437 btVector3 angVelA; bodyA.internalGetAngularVelocity(angVelA); 438 btVector3 angVelB; bodyB.internalGetAngularVelocity(angVelB); 413 439 btVector3 relVel = angVelB - angVelA; 414 440 if (relVel.length2() > SIMD_EPSILON) … … 422 448 btScalar impulseMag = impulse.length(); 423 449 btVector3 impulseAxis = impulse / impulseMag; 424 bodyA. applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*impulseAxis, impulseMag);425 bodyB. applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*impulseAxis, -impulseMag);450 bodyA.internalApplyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*impulseAxis, impulseMag); 451 bodyB.internalApplyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*impulseAxis, -impulseMag); 426 452 } 427 453 } … … 431 457 ///solve angular part 432 458 btVector3 angVelA; 433 bodyA. getAngularVelocity(angVelA);459 bodyA.internalGetAngularVelocity(angVelA); 434 460 btVector3 angVelB; 435 bodyB. getAngularVelocity(angVelB);461 bodyB.internalGetAngularVelocity(angVelB); 436 462 437 463 // solve swing limit … … 462 488 btVector3 noTwistSwingAxis = impulse / impulseMag; 463 489 464 bodyA. applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*noTwistSwingAxis, impulseMag);465 bodyB. applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*noTwistSwingAxis, -impulseMag);490 bodyA.internalApplyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*noTwistSwingAxis, impulseMag); 491 bodyB.internalApplyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*noTwistSwingAxis, -impulseMag); 466 492 } 467 493 … … 483 509 btVector3 impulse = m_twistAxis * impulseMag; 484 510 485 bodyA. applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*m_twistAxis,impulseMag);486 bodyB. applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*m_twistAxis,-impulseMag);511 bodyA.internalApplyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*m_twistAxis,impulseMag); 512 bodyB.internalApplyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*m_twistAxis,-impulseMag); 487 513 } 488 514 } 489 515 } 490 491 } 492 493 //----------------------------------------------------------------------------- 516 #else 517 btAssert(0); 518 #endif //__SPU__ 519 } 520 521 522 494 523 495 524 void btConeTwistConstraint::updateRHS(btScalar timeStep) … … 499 528 } 500 529 501 //----------------------------------------------------------------------------- 502 530 531 #ifndef __SPU__ 503 532 void btConeTwistConstraint::calcAngleInfo() 504 533 { … … 585 614 } 586 615 } 587 } // btConeTwistConstraint::calcAngleInfo()588 616 } 617 #endif //__SPU__ 589 618 590 619 static btVector3 vTwist(1,0,0); // twist axis in constraint's space 591 620 592 //----------------------------------------------------------------------------- 593 594 void btConeTwistConstraint::calcAngleInfo2( )621 622 623 void btConeTwistConstraint::calcAngleInfo2(const btTransform& transA, const btTransform& transB, const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB) 595 624 { 596 625 m_swingCorrection = btScalar(0.); … … 598 627 m_solveTwistLimit = false; 599 628 m_solveSwingLimit = false; 629 // compute rotation of A wrt B (in constraint space) 630 if (m_bMotorEnabled && (!m_useSolveConstraintObsolete)) 631 { // it is assumed that setMotorTarget() was alredy called 632 // and motor target m_qTarget is within constraint limits 633 // TODO : split rotation to pure swing and pure twist 634 // compute desired transforms in world 635 btTransform trPose(m_qTarget); 636 btTransform trA = transA * m_rbAFrame; 637 btTransform trB = transB * m_rbBFrame; 638 btTransform trDeltaAB = trB * trPose * trA.inverse(); 639 btQuaternion qDeltaAB = trDeltaAB.getRotation(); 640 btVector3 swingAxis = btVector3(qDeltaAB.x(), qDeltaAB.y(), qDeltaAB.z()); 641 m_swingAxis = swingAxis; 642 m_swingAxis.normalize(); 643 m_swingCorrection = qDeltaAB.getAngle(); 644 if(!btFuzzyZero(m_swingCorrection)) 645 { 646 m_solveSwingLimit = true; 647 } 648 return; 649 } 650 600 651 601 652 { 602 653 // compute rotation of A wrt B (in constraint space) 603 btQuaternion qA = getRigidBodyA().getCenterOfMassTransform().getRotation() * m_rbAFrame.getRotation();604 btQuaternion qB = getRigidBodyB().getCenterOfMassTransform().getRotation() * m_rbBFrame.getRotation();654 btQuaternion qA = transA.getRotation() * m_rbAFrame.getRotation(); 655 btQuaternion qB = transB.getRotation() * m_rbBFrame.getRotation(); 605 656 btQuaternion qAB = qB.inverse() * qA; 606 607 657 // split rotation into cone and twist 608 658 // (all this is done from B's perspective. Maybe I should be averaging axes...) … … 642 692 643 693 m_kSwing = btScalar(1.) / 644 ( getRigidBodyA().computeAngularImpulseDenominator(m_swingAxis) +645 getRigidBodyB().computeAngularImpulseDenominator(m_swingAxis));694 (computeAngularImpulseDenominator(m_swingAxis,invInertiaWorldA) + 695 computeAngularImpulseDenominator(m_swingAxis,invInertiaWorldB)); 646 696 } 647 697 } … … 651 701 // or you're trying to set at least one of the swing limits too small. (if so, do you really want a conetwist constraint?) 652 702 // anyway, we have either hinge or fixed joint 653 btVector3 ivA = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(0);654 btVector3 jvA = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(1);655 btVector3 kvA = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(2);656 btVector3 ivB = getRigidBodyB().getCenterOfMassTransform().getBasis() * m_rbBFrame.getBasis().getColumn(0);703 btVector3 ivA = transA.getBasis() * m_rbAFrame.getBasis().getColumn(0); 704 btVector3 jvA = transA.getBasis() * m_rbAFrame.getBasis().getColumn(1); 705 btVector3 kvA = transA.getBasis() * m_rbAFrame.getBasis().getColumn(2); 706 btVector3 ivB = transB.getBasis() * m_rbBFrame.getBasis().getColumn(0); 657 707 btVector3 target; 658 708 btScalar x = ivB.dot(ivA); … … 745 795 746 796 m_kTwist = btScalar(1.) / 747 ( getRigidBodyA().computeAngularImpulseDenominator(m_twistAxis) +748 getRigidBodyB().computeAngularImpulseDenominator(m_twistAxis));797 (computeAngularImpulseDenominator(m_twistAxis,invInertiaWorldA) + 798 computeAngularImpulseDenominator(m_twistAxis,invInertiaWorldB)); 749 799 } 750 800 … … 757 807 } 758 808 } 759 } // btConeTwistConstraint::calcAngleInfo2()809 } 760 810 761 811 … … 982 1032 } 983 1033 984 985 //----------------------------------------------------------------------------- 986 //----------------------------------------------------------------------------- 987 //----------------------------------------------------------------------------- 988 989 1034 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 1035 ///If no axis is provided, it uses the default axis for this constraint. 1036 void btConeTwistConstraint::setParam(int num, btScalar value, int axis) 1037 { 1038 switch(num) 1039 { 1040 case BT_CONSTRAINT_ERP : 1041 case BT_CONSTRAINT_STOP_ERP : 1042 if((axis >= 0) && (axis < 3)) 1043 { 1044 m_linERP = value; 1045 m_flags |= BT_CONETWIST_FLAGS_LIN_ERP; 1046 } 1047 else 1048 { 1049 m_biasFactor = value; 1050 } 1051 break; 1052 case BT_CONSTRAINT_CFM : 1053 case BT_CONSTRAINT_STOP_CFM : 1054 if((axis >= 0) && (axis < 3)) 1055 { 1056 m_linCFM = value; 1057 m_flags |= BT_CONETWIST_FLAGS_LIN_CFM; 1058 } 1059 else 1060 { 1061 m_angCFM = value; 1062 m_flags |= BT_CONETWIST_FLAGS_ANG_CFM; 1063 } 1064 break; 1065 default: 1066 btAssertConstrParams(0); 1067 break; 1068 } 1069 } 1070 1071 ///return the local value of parameter 1072 btScalar btConeTwistConstraint::getParam(int num, int axis) const 1073 { 1074 btScalar retVal = 0; 1075 switch(num) 1076 { 1077 case BT_CONSTRAINT_ERP : 1078 case BT_CONSTRAINT_STOP_ERP : 1079 if((axis >= 0) && (axis < 3)) 1080 { 1081 btAssertConstrParams(m_flags & BT_CONETWIST_FLAGS_LIN_ERP); 1082 retVal = m_linERP; 1083 } 1084 else if((axis >= 3) && (axis < 6)) 1085 { 1086 retVal = m_biasFactor; 1087 } 1088 else 1089 { 1090 btAssertConstrParams(0); 1091 } 1092 break; 1093 case BT_CONSTRAINT_CFM : 1094 case BT_CONSTRAINT_STOP_CFM : 1095 if((axis >= 0) && (axis < 3)) 1096 { 1097 btAssertConstrParams(m_flags & BT_CONETWIST_FLAGS_LIN_CFM); 1098 retVal = m_linCFM; 1099 } 1100 else if((axis >= 3) && (axis < 6)) 1101 { 1102 btAssertConstrParams(m_flags & BT_CONETWIST_FLAGS_ANG_CFM); 1103 retVal = m_angCFM; 1104 } 1105 else 1106 { 1107 btAssertConstrParams(0); 1108 } 1109 break; 1110 default : 1111 btAssertConstrParams(0); 1112 } 1113 return retVal; 1114 } 1115 1116 1117 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btConeTwistConstraint.h
r5781 r8351 18 18 19 19 20 /* 21 Overview: 22 23 btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc). 24 It is a fixed translation, 3 degree-of-freedom (DOF) rotational "joint". 25 It divides the 3 rotational DOFs into swing (movement within a cone) and twist. 26 Swing is divided into swing1 and swing2 which can have different limits, giving an elliptical shape. 27 (Note: the cone's base isn't flat, so this ellipse is "embedded" on the surface of a sphere.) 28 29 In the contraint's frame of reference: 30 twist is along the x-axis, 31 and swing 1 and 2 are along the z and y axes respectively. 32 */ 33 34 35 20 36 #ifndef CONETWISTCONSTRAINT_H 21 37 #define CONETWISTCONSTRAINT_H … … 27 43 class btRigidBody; 28 44 45 enum btConeTwistFlags 46 { 47 BT_CONETWIST_FLAGS_LIN_CFM = 1, 48 BT_CONETWIST_FLAGS_LIN_ERP = 2, 49 BT_CONETWIST_FLAGS_ANG_CFM = 4 50 }; 29 51 30 52 ///btConeTwistConstraint can be used to simulate ragdoll joints (upper arm, leg etc) … … 84 106 btVector3 m_accMotorImpulse; 85 107 108 // parameters 109 int m_flags; 110 btScalar m_linCFM; 111 btScalar m_linERP; 112 btScalar m_angCFM; 113 114 protected: 115 116 void init(); 117 118 void computeConeLimitInfo(const btQuaternion& qCone, // in 119 btScalar& swingAngle, btVector3& vSwingAxis, btScalar& swingLimit); // all outs 120 121 void computeTwistLimitInfo(const btQuaternion& qTwist, // in 122 btScalar& twistAngle, btVector3& vTwistAxis); // all outs 123 124 void adjustSwingAxisToUseEllipseNormal(btVector3& vSwingAxis) const; 125 126 86 127 public: 87 128 … … 90 131 btConeTwistConstraint(btRigidBody& rbA,const btTransform& rbAFrame); 91 132 92 btConeTwistConstraint();93 94 133 virtual void buildJacobian(); 95 134 96 135 virtual void getInfo1 (btConstraintInfo1* info); 136 137 void getInfo1NonVirtual(btConstraintInfo1* info); 97 138 98 139 virtual void getInfo2 (btConstraintInfo2* info); 99 140 100 101 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep); 141 void getInfo2NonVirtual(btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB); 142 143 virtual void solveConstraintObsolete(btRigidBody& bodyA,btRigidBody& bodyB,btScalar timeStep); 102 144 103 145 void updateRHS(btScalar timeStep); … … 142 184 } 143 185 144 void setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan, btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) 186 // setLimit(), a few notes: 187 // _softness: 188 // 0->1, recommend ~0.8->1. 189 // describes % of limits where movement is free. 190 // beyond this softness %, the limit is gradually enforced until the "hard" (1.0) limit is reached. 191 // _biasFactor: 192 // 0->1?, recommend 0.3 +/-0.3 or so. 193 // strength with which constraint resists zeroth order (angular, not angular velocity) limit violation. 194 // __relaxationFactor: 195 // 0->1, recommend to stay near 1. 196 // the lower the value, the less the constraint will fight velocities which violate the angular limits. 197 void setLimit(btScalar _swingSpan1,btScalar _swingSpan2,btScalar _twistSpan, btScalar _softness = 1.f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) 145 198 { 146 199 m_swingSpan1 = _swingSpan1; … … 172 225 173 226 void calcAngleInfo(); 174 void calcAngleInfo2( );227 void calcAngleInfo2(const btTransform& transA, const btTransform& transB,const btMatrix3x3& invInertiaWorldA,const btMatrix3x3& invInertiaWorldB); 175 228 176 229 inline btScalar getSwingSpan1() … … 213 266 btVector3 GetPointForAngle(btScalar fAngleInRadians, btScalar fLength) const; 214 267 215 216 217 protected: 218 void init(); 219 220 void computeConeLimitInfo(const btQuaternion& qCone, // in 221 btScalar& swingAngle, btVector3& vSwingAxis, btScalar& swingLimit); // all outs 222 223 void computeTwistLimitInfo(const btQuaternion& qTwist, // in 224 btScalar& twistAngle, btVector3& vTwistAxis); // all outs 225 226 void adjustSwingAxisToUseEllipseNormal(btVector3& vSwingAxis) const; 268 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 269 ///If no axis is provided, it uses the default axis for this constraint. 270 virtual void setParam(int num, btScalar value, int axis = -1); 271 ///return the local value of parameter 272 virtual btScalar getParam(int num, int axis = -1) const; 273 274 virtual int calculateSerializeBufferSize() const; 275 276 ///fills the dataBuffer and returns the struct name (and 0 on failure) 277 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 278 227 279 }; 228 280 281 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 282 struct btConeTwistConstraintData 283 { 284 btTypedConstraintData m_typeConstraintData; 285 btTransformFloatData m_rbAFrame; 286 btTransformFloatData m_rbBFrame; 287 288 //limits 289 float m_swingSpan1; 290 float m_swingSpan2; 291 float m_twistSpan; 292 float m_limitSoftness; 293 float m_biasFactor; 294 float m_relaxationFactor; 295 296 float m_damping; 297 298 char m_pad[4]; 299 300 }; 301 302 303 304 SIMD_FORCE_INLINE int btConeTwistConstraint::calculateSerializeBufferSize() const 305 { 306 return sizeof(btConeTwistConstraintData); 307 308 } 309 310 311 ///fills the dataBuffer and returns the struct name (and 0 on failure) 312 SIMD_FORCE_INLINE const char* btConeTwistConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 313 { 314 btConeTwistConstraintData* cone = (btConeTwistConstraintData*) dataBuffer; 315 btTypedConstraint::serialize(&cone->m_typeConstraintData,serializer); 316 317 m_rbAFrame.serializeFloat(cone->m_rbAFrame); 318 m_rbBFrame.serializeFloat(cone->m_rbBFrame); 319 320 cone->m_swingSpan1 = float(m_swingSpan1); 321 cone->m_swingSpan2 = float(m_swingSpan2); 322 cone->m_twistSpan = float(m_twistSpan); 323 cone->m_limitSoftness = float(m_limitSoftness); 324 cone->m_biasFactor = float(m_biasFactor); 325 cone->m_relaxationFactor = float(m_relaxationFactor); 326 cone->m_damping = float(m_damping); 327 328 return "btConeTwistConstraintData"; 329 } 330 331 229 332 #endif //CONETWISTCONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.cpp
r5781 r8351 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 17 #include "btContactConstraint.h" 18 #include "BulletDynamics/Dynamics/btRigidBody.h" 19 #include "LinearMath/btVector3.h" 20 #include "btJacobianEntry.h" 21 #include "btContactSolverInfo.h" 22 #include "LinearMath/btMinMax.h" 23 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" 24 25 26 27 btContactConstraint::btContactConstraint(btPersistentManifold* contactManifold,btRigidBody& rbA,btRigidBody& rbB) 28 :btTypedConstraint(CONTACT_CONSTRAINT_TYPE,rbA,rbB), 29 m_contactManifold(*contactManifold) 30 { 31 32 } 33 34 btContactConstraint::~btContactConstraint() 35 { 36 37 } 38 39 void btContactConstraint::setContactManifold(btPersistentManifold* contactManifold) 40 { 41 m_contactManifold = *contactManifold; 42 } 43 44 void btContactConstraint::getInfo1 (btConstraintInfo1* info) 45 { 46 47 } 48 49 void btContactConstraint::getInfo2 (btConstraintInfo2* info) 50 { 51 52 } 53 54 void btContactConstraint::buildJacobian() 55 { 56 57 } 58 59 60 15 61 16 62 … … 86 132 87 133 88 //response between two dynamic objects with friction89 btScalar resolveSingleCollision(90 btRigidBody& body1,91 btRigidBody& body2,92 btManifoldPoint& contactPoint,93 const btContactSolverInfo& solverInfo)94 {95 134 96 const btVector3& pos1_ = contactPoint.getPositionWorldOnA();97 const btVector3& pos2_ = contactPoint.getPositionWorldOnB();98 const btVector3& normal = contactPoint.m_normalWorldOnB;99 100 //constant over all iterations101 btVector3 rel_pos1 = pos1_ - body1.getCenterOfMassPosition();102 btVector3 rel_pos2 = pos2_ - body2.getCenterOfMassPosition();103 104 btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);105 btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);106 btVector3 vel = vel1 - vel2;107 btScalar rel_vel;108 rel_vel = normal.dot(vel);109 110 btScalar Kfps = btScalar(1.) / solverInfo.m_timeStep ;111 112 // btScalar damping = solverInfo.m_damping ;113 btScalar Kerp = solverInfo.m_erp;114 btScalar Kcor = Kerp *Kfps;115 116 btConstraintPersistentData* cpd = (btConstraintPersistentData*) contactPoint.m_userPersistentData;117 btAssert(cpd);118 btScalar distance = cpd->m_penetration;119 btScalar positionalError = Kcor *-distance;120 btScalar velocityError = cpd->m_restitution - rel_vel;// * damping;121 122 btScalar penetrationImpulse = positionalError * cpd->m_jacDiagABInv;123 124 btScalar velocityImpulse = velocityError * cpd->m_jacDiagABInv;125 126 btScalar normalImpulse = penetrationImpulse+velocityImpulse;127 128 // See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse129 btScalar oldNormalImpulse = cpd->m_appliedImpulse;130 btScalar sum = oldNormalImpulse + normalImpulse;131 cpd->m_appliedImpulse = btScalar(0.) > sum ? btScalar(0.): sum;132 133 normalImpulse = cpd->m_appliedImpulse - oldNormalImpulse;134 135 #ifdef USE_INTERNAL_APPLY_IMPULSE136 if (body1.getInvMass())137 {138 body1.internalApplyImpulse(contactPoint.m_normalWorldOnB*body1.getInvMass(),cpd->m_angularComponentA,normalImpulse);139 }140 if (body2.getInvMass())141 {142 body2.internalApplyImpulse(contactPoint.m_normalWorldOnB*body2.getInvMass(),cpd->m_angularComponentB,-normalImpulse);143 }144 #else //USE_INTERNAL_APPLY_IMPULSE145 body1.applyImpulse(normal*(normalImpulse), rel_pos1);146 body2.applyImpulse(-normal*(normalImpulse), rel_pos2);147 #endif //USE_INTERNAL_APPLY_IMPULSE148 149 return normalImpulse;150 }151 152 153 btScalar resolveSingleFriction(154 btRigidBody& body1,155 btRigidBody& body2,156 btManifoldPoint& contactPoint,157 const btContactSolverInfo& solverInfo)158 {159 160 (void)solverInfo;161 162 const btVector3& pos1 = contactPoint.getPositionWorldOnA();163 const btVector3& pos2 = contactPoint.getPositionWorldOnB();164 165 btVector3 rel_pos1 = pos1 - body1.getCenterOfMassPosition();166 btVector3 rel_pos2 = pos2 - body2.getCenterOfMassPosition();167 168 btConstraintPersistentData* cpd = (btConstraintPersistentData*) contactPoint.m_userPersistentData;169 btAssert(cpd);170 171 btScalar combinedFriction = cpd->m_friction;172 173 btScalar limit = cpd->m_appliedImpulse * combinedFriction;174 175 if (cpd->m_appliedImpulse>btScalar(0.))176 //friction177 {178 //apply friction in the 2 tangential directions179 180 // 1st tangent181 btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);182 btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);183 btVector3 vel = vel1 - vel2;184 185 btScalar j1,j2;186 187 {188 189 btScalar vrel = cpd->m_frictionWorldTangential0.dot(vel);190 191 // calculate j that moves us to zero relative velocity192 j1 = -vrel * cpd->m_jacDiagABInvTangent0;193 btScalar oldTangentImpulse = cpd->m_accumulatedTangentImpulse0;194 cpd->m_accumulatedTangentImpulse0 = oldTangentImpulse + j1;195 btSetMin(cpd->m_accumulatedTangentImpulse0, limit);196 btSetMax(cpd->m_accumulatedTangentImpulse0, -limit);197 j1 = cpd->m_accumulatedTangentImpulse0 - oldTangentImpulse;198 199 }200 {201 // 2nd tangent202 203 btScalar vrel = cpd->m_frictionWorldTangential1.dot(vel);204 205 // calculate j that moves us to zero relative velocity206 j2 = -vrel * cpd->m_jacDiagABInvTangent1;207 btScalar oldTangentImpulse = cpd->m_accumulatedTangentImpulse1;208 cpd->m_accumulatedTangentImpulse1 = oldTangentImpulse + j2;209 btSetMin(cpd->m_accumulatedTangentImpulse1, limit);210 btSetMax(cpd->m_accumulatedTangentImpulse1, -limit);211 j2 = cpd->m_accumulatedTangentImpulse1 - oldTangentImpulse;212 }213 214 #ifdef USE_INTERNAL_APPLY_IMPULSE215 if (body1.getInvMass())216 {217 body1.internalApplyImpulse(cpd->m_frictionWorldTangential0*body1.getInvMass(),cpd->m_frictionAngularComponent0A,j1);218 body1.internalApplyImpulse(cpd->m_frictionWorldTangential1*body1.getInvMass(),cpd->m_frictionAngularComponent1A,j2);219 }220 if (body2.getInvMass())221 {222 body2.internalApplyImpulse(cpd->m_frictionWorldTangential0*body2.getInvMass(),cpd->m_frictionAngularComponent0B,-j1);223 body2.internalApplyImpulse(cpd->m_frictionWorldTangential1*body2.getInvMass(),cpd->m_frictionAngularComponent1B,-j2);224 }225 #else //USE_INTERNAL_APPLY_IMPULSE226 body1.applyImpulse((j1 * cpd->m_frictionWorldTangential0)+(j2 * cpd->m_frictionWorldTangential1), rel_pos1);227 body2.applyImpulse((j1 * -cpd->m_frictionWorldTangential0)+(j2 * -cpd->m_frictionWorldTangential1), rel_pos2);228 #endif //USE_INTERNAL_APPLY_IMPULSE229 230 231 }232 return cpd->m_appliedImpulse;233 }234 235 236 btScalar resolveSingleFrictionOriginal(237 btRigidBody& body1,238 btRigidBody& body2,239 btManifoldPoint& contactPoint,240 const btContactSolverInfo& solverInfo);241 242 btScalar resolveSingleFrictionOriginal(243 btRigidBody& body1,244 btRigidBody& body2,245 btManifoldPoint& contactPoint,246 const btContactSolverInfo& solverInfo)247 {248 249 (void)solverInfo;250 251 const btVector3& pos1 = contactPoint.getPositionWorldOnA();252 const btVector3& pos2 = contactPoint.getPositionWorldOnB();253 254 btVector3 rel_pos1 = pos1 - body1.getCenterOfMassPosition();255 btVector3 rel_pos2 = pos2 - body2.getCenterOfMassPosition();256 257 btConstraintPersistentData* cpd = (btConstraintPersistentData*) contactPoint.m_userPersistentData;258 btAssert(cpd);259 260 btScalar combinedFriction = cpd->m_friction;261 262 btScalar limit = cpd->m_appliedImpulse * combinedFriction;263 //if (contactPoint.m_appliedImpulse>btScalar(0.))264 //friction265 {266 //apply friction in the 2 tangential directions267 268 {269 // 1st tangent270 btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);271 btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);272 btVector3 vel = vel1 - vel2;273 274 btScalar vrel = cpd->m_frictionWorldTangential0.dot(vel);275 276 // calculate j that moves us to zero relative velocity277 btScalar j = -vrel * cpd->m_jacDiagABInvTangent0;278 btScalar total = cpd->m_accumulatedTangentImpulse0 + j;279 btSetMin(total, limit);280 btSetMax(total, -limit);281 j = total - cpd->m_accumulatedTangentImpulse0;282 cpd->m_accumulatedTangentImpulse0 = total;283 body1.applyImpulse(j * cpd->m_frictionWorldTangential0, rel_pos1);284 body2.applyImpulse(j * -cpd->m_frictionWorldTangential0, rel_pos2);285 }286 287 288 {289 // 2nd tangent290 btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);291 btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);292 btVector3 vel = vel1 - vel2;293 294 btScalar vrel = cpd->m_frictionWorldTangential1.dot(vel);295 296 // calculate j that moves us to zero relative velocity297 btScalar j = -vrel * cpd->m_jacDiagABInvTangent1;298 btScalar total = cpd->m_accumulatedTangentImpulse1 + j;299 btSetMin(total, limit);300 btSetMax(total, -limit);301 j = total - cpd->m_accumulatedTangentImpulse1;302 cpd->m_accumulatedTangentImpulse1 = total;303 body1.applyImpulse(j * cpd->m_frictionWorldTangential1, rel_pos1);304 body2.applyImpulse(j * -cpd->m_frictionWorldTangential1, rel_pos2);305 }306 }307 return cpd->m_appliedImpulse;308 }309 310 311 //velocity + friction312 //response between two dynamic objects with friction313 btScalar resolveSingleCollisionCombined(314 btRigidBody& body1,315 btRigidBody& body2,316 btManifoldPoint& contactPoint,317 const btContactSolverInfo& solverInfo)318 {319 320 const btVector3& pos1 = contactPoint.getPositionWorldOnA();321 const btVector3& pos2 = contactPoint.getPositionWorldOnB();322 const btVector3& normal = contactPoint.m_normalWorldOnB;323 324 btVector3 rel_pos1 = pos1 - body1.getCenterOfMassPosition();325 btVector3 rel_pos2 = pos2 - body2.getCenterOfMassPosition();326 327 btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);328 btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);329 btVector3 vel = vel1 - vel2;330 btScalar rel_vel;331 rel_vel = normal.dot(vel);332 333 btScalar Kfps = btScalar(1.) / solverInfo.m_timeStep ;334 335 //btScalar damping = solverInfo.m_damping ;336 btScalar Kerp = solverInfo.m_erp;337 btScalar Kcor = Kerp *Kfps;338 339 btConstraintPersistentData* cpd = (btConstraintPersistentData*) contactPoint.m_userPersistentData;340 btAssert(cpd);341 btScalar distance = cpd->m_penetration;342 btScalar positionalError = Kcor *-distance;343 btScalar velocityError = cpd->m_restitution - rel_vel;// * damping;344 345 btScalar penetrationImpulse = positionalError * cpd->m_jacDiagABInv;346 347 btScalar velocityImpulse = velocityError * cpd->m_jacDiagABInv;348 349 btScalar normalImpulse = penetrationImpulse+velocityImpulse;350 351 // See Erin Catto's GDC 2006 paper: Clamp the accumulated impulse352 btScalar oldNormalImpulse = cpd->m_appliedImpulse;353 btScalar sum = oldNormalImpulse + normalImpulse;354 cpd->m_appliedImpulse = btScalar(0.) > sum ? btScalar(0.): sum;355 356 normalImpulse = cpd->m_appliedImpulse - oldNormalImpulse;357 358 359 #ifdef USE_INTERNAL_APPLY_IMPULSE360 if (body1.getInvMass())361 {362 body1.internalApplyImpulse(contactPoint.m_normalWorldOnB*body1.getInvMass(),cpd->m_angularComponentA,normalImpulse);363 }364 if (body2.getInvMass())365 {366 body2.internalApplyImpulse(contactPoint.m_normalWorldOnB*body2.getInvMass(),cpd->m_angularComponentB,-normalImpulse);367 }368 #else //USE_INTERNAL_APPLY_IMPULSE369 body1.applyImpulse(normal*(normalImpulse), rel_pos1);370 body2.applyImpulse(-normal*(normalImpulse), rel_pos2);371 #endif //USE_INTERNAL_APPLY_IMPULSE372 373 {374 //friction375 btVector3 vel1 = body1.getVelocityInLocalPoint(rel_pos1);376 btVector3 vel2 = body2.getVelocityInLocalPoint(rel_pos2);377 btVector3 vel = vel1 - vel2;378 379 rel_vel = normal.dot(vel);380 381 382 btVector3 lat_vel = vel - normal * rel_vel;383 btScalar lat_rel_vel = lat_vel.length();384 385 btScalar combinedFriction = cpd->m_friction;386 387 if (cpd->m_appliedImpulse > 0)388 if (lat_rel_vel > SIMD_EPSILON)389 {390 lat_vel /= lat_rel_vel;391 btVector3 temp1 = body1.getInvInertiaTensorWorld() * rel_pos1.cross(lat_vel);392 btVector3 temp2 = body2.getInvInertiaTensorWorld() * rel_pos2.cross(lat_vel);393 btScalar friction_impulse = lat_rel_vel /394 (body1.getInvMass() + body2.getInvMass() + lat_vel.dot(temp1.cross(rel_pos1) + temp2.cross(rel_pos2)));395 btScalar normal_impulse = cpd->m_appliedImpulse * combinedFriction;396 397 btSetMin(friction_impulse, normal_impulse);398 btSetMax(friction_impulse, -normal_impulse);399 body1.applyImpulse(lat_vel * -friction_impulse, rel_pos1);400 body2.applyImpulse(lat_vel * friction_impulse, rel_pos2);401 }402 }403 404 405 406 return normalImpulse;407 }408 409 btScalar resolveSingleFrictionEmpty(410 btRigidBody& body1,411 btRigidBody& body2,412 btManifoldPoint& contactPoint,413 const btContactSolverInfo& solverInfo);414 415 btScalar resolveSingleFrictionEmpty(416 btRigidBody& body1,417 btRigidBody& body2,418 btManifoldPoint& contactPoint,419 const btContactSolverInfo& solverInfo)420 {421 (void)contactPoint;422 (void)body1;423 (void)body2;424 (void)solverInfo;425 426 427 return btScalar(0.);428 }429 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btContactConstraint.h
r5781 r8351 17 17 #define CONTACT_CONSTRAINT_H 18 18 19 ///@todo: make into a proper class working with the iterative constraint solver 19 #include "LinearMath/btVector3.h" 20 #include "btJacobianEntry.h" 21 #include "btTypedConstraint.h" 22 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" 20 23 21 class btRigidBody; 22 #include "LinearMath/btVector3.h" 23 #include "LinearMath/btScalar.h" 24 struct btContactSolverInfo; 25 class btManifoldPoint; 24 ///btContactConstraint can be automatically created to solve contact constraints using the unified btTypedConstraint interface 25 ATTRIBUTE_ALIGNED16(class) btContactConstraint : public btTypedConstraint 26 { 27 protected: 26 28 27 enum { 28 DEFAULT_CONTACT_SOLVER_TYPE=0, 29 CONTACT_SOLVER_TYPE1, 30 CONTACT_SOLVER_TYPE2, 31 USER_CONTACT_SOLVER_TYPE1, 32 MAX_CONTACT_SOLVER_TYPES 29 btPersistentManifold m_contactManifold; 30 31 public: 32 33 34 btContactConstraint(btPersistentManifold* contactManifold,btRigidBody& rbA,btRigidBody& rbB); 35 36 void setContactManifold(btPersistentManifold* contactManifold); 37 38 btPersistentManifold* getContactManifold() 39 { 40 return &m_contactManifold; 41 } 42 43 const btPersistentManifold* getContactManifold() const 44 { 45 return &m_contactManifold; 46 } 47 48 virtual ~btContactConstraint(); 49 50 virtual void getInfo1 (btConstraintInfo1* info); 51 52 virtual void getInfo2 (btConstraintInfo2* info); 53 54 ///obsolete methods 55 virtual void buildJacobian(); 56 57 33 58 }; 34 59 35 60 36 typedef btScalar (*ContactSolverFunc)(btRigidBody& body1, 37 btRigidBody& body2, 38 class btManifoldPoint& contactPoint, 39 const btContactSolverInfo& info); 40 41 ///stores some extra information to each contact point. It is not in the contact point, because that want to keep the collision detection independent from the constraint solver. 42 struct btConstraintPersistentData 43 { 44 inline btConstraintPersistentData() 45 :m_appliedImpulse(btScalar(0.)), 46 m_prevAppliedImpulse(btScalar(0.)), 47 m_accumulatedTangentImpulse0(btScalar(0.)), 48 m_accumulatedTangentImpulse1(btScalar(0.)), 49 m_jacDiagABInv(btScalar(0.)), 50 m_persistentLifeTime(0), 51 m_restitution(btScalar(0.)), 52 m_friction(btScalar(0.)), 53 m_penetration(btScalar(0.)), 54 m_contactSolverFunc(0), 55 m_frictionSolverFunc(0) 56 { 57 } 58 59 60 /// total applied impulse during most recent frame 61 btScalar m_appliedImpulse; 62 btScalar m_prevAppliedImpulse; 63 btScalar m_accumulatedTangentImpulse0; 64 btScalar m_accumulatedTangentImpulse1; 65 66 btScalar m_jacDiagABInv; 67 btScalar m_jacDiagABInvTangent0; 68 btScalar m_jacDiagABInvTangent1; 69 int m_persistentLifeTime; 70 btScalar m_restitution; 71 btScalar m_friction; 72 btScalar m_penetration; 73 btVector3 m_frictionWorldTangential0; 74 btVector3 m_frictionWorldTangential1; 75 76 btVector3 m_frictionAngularComponent0A; 77 btVector3 m_frictionAngularComponent0B; 78 btVector3 m_frictionAngularComponent1A; 79 btVector3 m_frictionAngularComponent1B; 80 81 //some data doesn't need to be persistent over frames: todo: clean/reuse this 82 btVector3 m_angularComponentA; 83 btVector3 m_angularComponentB; 84 85 ContactSolverFunc m_contactSolverFunc; 86 ContactSolverFunc m_frictionSolverFunc; 87 88 }; 89 90 ///bilateral constraint between two dynamic objects 91 ///positive distance = separation, negative distance = penetration 61 ///resolveSingleBilateral is an obsolete methods used for vehicle friction between two dynamic objects 92 62 void resolveSingleBilateral(btRigidBody& body1, const btVector3& pos1, 93 63 btRigidBody& body2, const btVector3& pos2, … … 95 65 96 66 97 ///contact constraint resolution:98 ///calculate and apply impulse to satisfy non-penetration and non-negative relative velocity constraint99 ///positive distance = separation, negative distance = penetration100 btScalar resolveSingleCollision(101 btRigidBody& body1,102 btRigidBody& body2,103 btManifoldPoint& contactPoint,104 const btContactSolverInfo& info);105 106 btScalar resolveSingleFriction(107 btRigidBody& body1,108 btRigidBody& body2,109 btManifoldPoint& contactPoint,110 const btContactSolverInfo& solverInfo111 );112 113 114 115 btScalar resolveSingleCollisionCombined(116 btRigidBody& body1,117 btRigidBody& body2,118 btManifoldPoint& contactPoint,119 const btContactSolverInfo& solverInfo120 );121 67 122 68 #endif //CONTACT_CONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btContactSolverInfo.h
r5781 r8351 36 36 37 37 btScalar m_tau; 38 btScalar m_damping; 38 btScalar m_damping;//global non-contact constraint damping, can be locally overridden by constraints during 'getInfo2'. 39 39 btScalar m_friction; 40 40 btScalar m_timeStep; … … 53 53 int m_solverMode; 54 54 int m_restingContactRestitutionThreshold; 55 int m_minimumSolverBatchSize; 55 56 56 57 … … 78 79 m_linearSlop = btScalar(0.0); 79 80 m_warmstartingFactor=btScalar(0.85); 80 m_solverMode = SOLVER_USE_WARMSTARTING | SOLVER_SIMD ;//SOLVER_RANDMIZE_ORDER81 m_solverMode = SOLVER_USE_WARMSTARTING | SOLVER_SIMD;// | SOLVER_RANDMIZE_ORDER; 81 82 m_restingContactRestitutionThreshold = 2;//resting contact lifetime threshold to disable restitution 83 m_minimumSolverBatchSize = 128; //try to combine islands until the amount of constraints reaches this limit 82 84 } 83 85 }; -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp
r5781 r8351 23 23 #include "BulletDynamics/Dynamics/btRigidBody.h" 24 24 #include "LinearMath/btTransformUtil.h" 25 #include "LinearMath/btTransformUtil.h" 25 26 #include <new> 26 27 27 28 29 28 30 #define D6_USE_OBSOLETE_METHOD false 29 //----------------------------------------------------------------------------- 30 31 btGeneric6DofConstraint::btGeneric6DofConstraint() 32 :btTypedConstraint(D6_CONSTRAINT_TYPE), 33 m_useLinearReferenceFrameA(true), 34 m_useSolveConstraintObsolete(D6_USE_OBSOLETE_METHOD) 35 { 36 } 37 38 //----------------------------------------------------------------------------- 31 #define D6_USE_FRAME_OFFSET true 32 33 34 35 36 39 37 40 38 btGeneric6DofConstraint::btGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA) … … 43 41 , m_frameInB(frameInB), 44 42 m_useLinearReferenceFrameA(useLinearReferenceFrameA), 43 m_useOffsetForConstraintFrame(D6_USE_FRAME_OFFSET), 44 m_flags(0), 45 45 m_useSolveConstraintObsolete(D6_USE_OBSOLETE_METHOD) 46 46 { 47 48 } 49 //----------------------------------------------------------------------------- 47 calculateTransforms(); 48 } 49 50 51 52 btGeneric6DofConstraint::btGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB) 53 : btTypedConstraint(D6_CONSTRAINT_TYPE, getFixedBody(), rbB), 54 m_frameInB(frameInB), 55 m_useLinearReferenceFrameA(useLinearReferenceFrameB), 56 m_useOffsetForConstraintFrame(D6_USE_FRAME_OFFSET), 57 m_flags(0), 58 m_useSolveConstraintObsolete(false) 59 { 60 ///not providing rigidbody A means implicitly using worldspace for body A 61 m_frameInA = rbB.getCenterOfMassTransform() * m_frameInB; 62 calculateTransforms(); 63 } 64 65 50 66 51 67 52 68 #define GENERIC_D6_DISABLE_WARMSTARTING 1 53 69 54 //----------------------------------------------------------------------------- 70 55 71 56 72 btScalar btGetMatrixElem(const btMatrix3x3& mat, int index); … … 62 78 } 63 79 64 //----------------------------------------------------------------------------- 80 65 81 66 82 ///MatrixToEulerXYZ from http://www.geometrictools.com/LibFoundation/Mathematics/Wm4Matrix3.inl.html … … 111 127 return 0; 112 128 } 113 114 129 if (test_value < m_loLimit) 115 130 { … … 130 145 } 131 146 132 //----------------------------------------------------------------------------- 147 133 148 134 149 btScalar btRotationalLimitMotor::solveAngularLimits( 135 150 btScalar timeStep,btVector3& axis,btScalar jacDiagABInv, 136 btRigidBody * body0, bt SolverBody& bodyA, btRigidBody * body1, btSolverBody& bodyB)151 btRigidBody * body0, btRigidBody * body1 ) 137 152 { 138 153 if (needApplyTorques()==false) return 0.0f; … … 144 159 if (m_currentLimit!=0) 145 160 { 146 target_velocity = -m_ ERP*m_currentLimitError/(timeStep);161 target_velocity = -m_stopERP*m_currentLimitError/(timeStep); 147 162 maxMotorForce = m_maxLimitForce; 148 163 } … … 153 168 154 169 btVector3 angVelA; 155 body A.getAngularVelocity(angVelA);170 body0->internalGetAngularVelocity(angVelA); 156 171 btVector3 angVelB; 157 body B.getAngularVelocity(angVelB);172 body1->internalGetAngularVelocity(angVelB); 158 173 159 174 btVector3 vel_diff; … … 192 207 193 208 // sort with accumulated impulses 194 btScalar lo = btScalar(- 1e30);195 btScalar hi = btScalar( 1e30);209 btScalar lo = btScalar(-BT_LARGE_FLOAT); 210 btScalar hi = btScalar(BT_LARGE_FLOAT); 196 211 197 212 btScalar oldaccumImpulse = m_accumulatedImpulse; … … 206 221 //body1->applyTorqueImpulse(-motorImp); 207 222 208 body A.applyImpulse(btVector3(0,0,0), body0->getInvInertiaTensorWorld()*axis,clippedMotorImpulse);209 body B.applyImpulse(btVector3(0,0,0), body1->getInvInertiaTensorWorld()*axis,-clippedMotorImpulse);223 body0->internalApplyImpulse(btVector3(0,0,0), body0->getInvInertiaTensorWorld()*axis,clippedMotorImpulse); 224 body1->internalApplyImpulse(btVector3(0,0,0), body1->getInvInertiaTensorWorld()*axis,-clippedMotorImpulse); 210 225 211 226 … … 250 265 m_currentLimitError[limitIndex] = btScalar(0.f); 251 266 return 0; 252 } // btTranslationalLimitMotor::testLimitValue()253 254 //----------------------------------------------------------------------------- 267 } 268 269 255 270 256 271 btScalar btTranslationalLimitMotor::solveLinearAxis( 257 272 btScalar timeStep, 258 273 btScalar jacDiagABInv, 259 btRigidBody& body1, btSolverBody& bodyA,const btVector3 &pointInA,260 btRigidBody& body2, btSolverBody& bodyB,const btVector3 &pointInB,274 btRigidBody& body1,const btVector3 &pointInA, 275 btRigidBody& body2,const btVector3 &pointInB, 261 276 int limit_index, 262 277 const btVector3 & axis_normal_on_a, … … 271 286 272 287 btVector3 vel1; 273 body A.getVelocityInLocalPointObsolete(rel_pos1,vel1);288 body1.internalGetVelocityInLocalPointObsolete(rel_pos1,vel1); 274 289 btVector3 vel2; 275 body B.getVelocityInLocalPointObsolete(rel_pos2,vel2);290 body2.internalGetVelocityInLocalPointObsolete(rel_pos2,vel2); 276 291 btVector3 vel = vel1 - vel2; 277 292 … … 284 299 //positional error (zeroth order error) 285 300 btScalar depth = -(pointInA - pointInB).dot(axis_normal_on_a); 286 btScalar lo = btScalar(- 1e30);287 btScalar hi = btScalar( 1e30);301 btScalar lo = btScalar(-BT_LARGE_FLOAT); 302 btScalar hi = btScalar(BT_LARGE_FLOAT); 288 303 289 304 btScalar minLimit = m_lowerLimit[limit_index]; … … 331 346 btVector3 ftorqueAxis1 = rel_pos1.cross(axis_normal_on_a); 332 347 btVector3 ftorqueAxis2 = rel_pos2.cross(axis_normal_on_a); 333 body A.applyImpulse(axis_normal_on_a*body1.getInvMass(), body1.getInvInertiaTensorWorld()*ftorqueAxis1,normalImpulse);334 body B.applyImpulse(axis_normal_on_a*body2.getInvMass(), body2.getInvInertiaTensorWorld()*ftorqueAxis2,-normalImpulse);348 body1.internalApplyImpulse(axis_normal_on_a*body1.getInvMass(), body1.getInvInertiaTensorWorld()*ftorqueAxis1,normalImpulse); 349 body2.internalApplyImpulse(axis_normal_on_a*body2.getInvMass(), body2.getInvInertiaTensorWorld()*ftorqueAxis2,-normalImpulse); 335 350 336 351 … … 373 388 } 374 389 375 //-----------------------------------------------------------------------------376 377 390 void btGeneric6DofConstraint::calculateTransforms() 378 391 { 379 m_calculatedTransformA = m_rbA.getCenterOfMassTransform() * m_frameInA; 380 m_calculatedTransformB = m_rbB.getCenterOfMassTransform() * m_frameInB; 392 calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 393 } 394 395 void btGeneric6DofConstraint::calculateTransforms(const btTransform& transA,const btTransform& transB) 396 { 397 m_calculatedTransformA = transA * m_frameInA; 398 m_calculatedTransformB = transB * m_frameInB; 381 399 calculateLinearInfo(); 382 400 calculateAngleInfo(); 383 } 384 385 //----------------------------------------------------------------------------- 401 if(m_useOffsetForConstraintFrame) 402 { // get weight factors depending on masses 403 btScalar miA = getRigidBodyA().getInvMass(); 404 btScalar miB = getRigidBodyB().getInvMass(); 405 m_hasStaticBody = (miA < SIMD_EPSILON) || (miB < SIMD_EPSILON); 406 btScalar miS = miA + miB; 407 if(miS > btScalar(0.f)) 408 { 409 m_factA = miB / miS; 410 } 411 else 412 { 413 m_factA = btScalar(0.5f); 414 } 415 m_factB = btScalar(1.0f) - m_factA; 416 } 417 } 418 419 386 420 387 421 void btGeneric6DofConstraint::buildLinearJacobian( … … 401 435 } 402 436 403 //----------------------------------------------------------------------------- 437 404 438 405 439 void btGeneric6DofConstraint::buildAngularJacobian( … … 414 448 } 415 449 416 //----------------------------------------------------------------------------- 450 417 451 418 452 bool btGeneric6DofConstraint::testAngularLimitMotor(int axis_index) 419 453 { 420 454 btScalar angle = m_calculatedAxisAngleDiff[axis_index]; 455 angle = btAdjustAngleToLimits(angle, m_angularLimits[axis_index].m_loLimit, m_angularLimits[axis_index].m_hiLimit); 456 m_angularLimits[axis_index].m_currentPosition = angle; 421 457 //test limits 422 458 m_angularLimits[axis_index].testLimitValue(angle); … … 424 460 } 425 461 426 //----------------------------------------------------------------------------- 462 427 463 428 464 void btGeneric6DofConstraint::buildJacobian() 429 465 { 466 #ifndef __SPU__ 430 467 if (m_useSolveConstraintObsolete) 431 468 { … … 439 476 } 440 477 //calculates transform 441 calculateTransforms( );478 calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 442 479 443 480 // const btVector3& pivotAInW = m_calculatedTransformA.getOrigin(); … … 482 519 483 520 } 484 } 485 486 //----------------------------------------------------------------------------- 521 #endif //__SPU__ 522 523 } 524 487 525 488 526 void btGeneric6DofConstraint::getInfo1 (btConstraintInfo1* info) … … 495 533 { 496 534 //prepare constraint 497 calculateTransforms( );535 calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 498 536 info->m_numConstraintRows = 0; 499 537 info->nub = 6; … … 520 558 } 521 559 522 //----------------------------------------------------------------------------- 560 void btGeneric6DofConstraint::getInfo1NonVirtual (btConstraintInfo1* info) 561 { 562 if (m_useSolveConstraintObsolete) 563 { 564 info->m_numConstraintRows = 0; 565 info->nub = 0; 566 } else 567 { 568 //pre-allocate all 6 569 info->m_numConstraintRows = 6; 570 info->nub = 0; 571 } 572 } 573 523 574 524 575 void btGeneric6DofConstraint::getInfo2 (btConstraintInfo2* info) 525 576 { 526 577 btAssert(!m_useSolveConstraintObsolete); 527 int row = setLinearLimits(info); 528 setAngularLimits(info, row); 529 } 530 531 //----------------------------------------------------------------------------- 532 533 int btGeneric6DofConstraint::setLinearLimits(btConstraintInfo2* info) 534 { 535 btGeneric6DofConstraint * d6constraint = this; 536 int row = 0; 578 579 const btTransform& transA = m_rbA.getCenterOfMassTransform(); 580 const btTransform& transB = m_rbB.getCenterOfMassTransform(); 581 const btVector3& linVelA = m_rbA.getLinearVelocity(); 582 const btVector3& linVelB = m_rbB.getLinearVelocity(); 583 const btVector3& angVelA = m_rbA.getAngularVelocity(); 584 const btVector3& angVelB = m_rbB.getAngularVelocity(); 585 586 if(m_useOffsetForConstraintFrame) 587 { // for stability better to solve angular limits first 588 int row = setAngularLimits(info, 0,transA,transB,linVelA,linVelB,angVelA,angVelB); 589 setLinearLimits(info, row, transA,transB,linVelA,linVelB,angVelA,angVelB); 590 } 591 else 592 { // leave old version for compatibility 593 int row = setLinearLimits(info, 0, transA,transB,linVelA,linVelB,angVelA,angVelB); 594 setAngularLimits(info, row,transA,transB,linVelA,linVelB,angVelA,angVelB); 595 } 596 597 } 598 599 600 void btGeneric6DofConstraint::getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB) 601 { 602 603 btAssert(!m_useSolveConstraintObsolete); 604 //prepare constraint 605 calculateTransforms(transA,transB); 606 607 int i; 608 for (i=0;i<3 ;i++ ) 609 { 610 testAngularLimitMotor(i); 611 } 612 613 if(m_useOffsetForConstraintFrame) 614 { // for stability better to solve angular limits first 615 int row = setAngularLimits(info, 0,transA,transB,linVelA,linVelB,angVelA,angVelB); 616 setLinearLimits(info, row, transA,transB,linVelA,linVelB,angVelA,angVelB); 617 } 618 else 619 { // leave old version for compatibility 620 int row = setLinearLimits(info, 0, transA,transB,linVelA,linVelB,angVelA,angVelB); 621 setAngularLimits(info, row,transA,transB,linVelA,linVelB,angVelA,angVelB); 622 } 623 } 624 625 626 627 int btGeneric6DofConstraint::setLinearLimits(btConstraintInfo2* info, int row, const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB) 628 { 629 // int row = 0; 537 630 //solve linear limits 538 631 btRotationalLimitMotor limot; … … 543 636 limot.m_bounce = btScalar(0.f); 544 637 limot.m_currentLimit = m_linearLimits.m_currentLimit[i]; 638 limot.m_currentPosition = m_linearLimits.m_currentLinearDiff[i]; 545 639 limot.m_currentLimitError = m_linearLimits.m_currentLimitError[i]; 546 640 limot.m_damping = m_linearLimits.m_damping; 547 641 limot.m_enableMotor = m_linearLimits.m_enableMotor[i]; 548 limot.m_ERP = m_linearLimits.m_restitution;549 642 limot.m_hiLimit = m_linearLimits.m_upperLimit[i]; 550 643 limot.m_limitSoftness = m_linearLimits.m_limitSoftness; … … 554 647 limot.m_targetVelocity = m_linearLimits.m_targetVelocity[i]; 555 648 btVector3 axis = m_calculatedTransformA.getBasis().getColumn(i); 556 row += get_limit_motor_info2(&limot, &m_rbA, &m_rbB, info, row, axis, 0); 649 int flags = m_flags >> (i * BT_6DOF_FLAGS_AXIS_SHIFT); 650 limot.m_normalCFM = (flags & BT_6DOF_FLAGS_CFM_NORM) ? m_linearLimits.m_normalCFM[i] : info->cfm[0]; 651 limot.m_stopCFM = (flags & BT_6DOF_FLAGS_CFM_STOP) ? m_linearLimits.m_stopCFM[i] : info->cfm[0]; 652 limot.m_stopERP = (flags & BT_6DOF_FLAGS_ERP_STOP) ? m_linearLimits.m_stopERP[i] : info->erp; 653 if(m_useOffsetForConstraintFrame) 654 { 655 int indx1 = (i + 1) % 3; 656 int indx2 = (i + 2) % 3; 657 int rotAllowed = 1; // rotations around orthos to current axis 658 if(m_angularLimits[indx1].m_currentLimit && m_angularLimits[indx2].m_currentLimit) 659 { 660 rotAllowed = 0; 661 } 662 row += get_limit_motor_info2(&limot, transA,transB,linVelA,linVelB,angVelA,angVelB, info, row, axis, 0, rotAllowed); 663 } 664 else 665 { 666 row += get_limit_motor_info2(&limot, transA,transB,linVelA,linVelB,angVelA,angVelB, info, row, axis, 0); 667 } 557 668 } 558 669 } … … 560 671 } 561 672 562 //----------------------------------------------------------------------------- 563 564 int btGeneric6DofConstraint::setAngularLimits(btConstraintInfo2 *info, int row_offset )673 674 675 int btGeneric6DofConstraint::setAngularLimits(btConstraintInfo2 *info, int row_offset, const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB) 565 676 { 566 677 btGeneric6DofConstraint * d6constraint = this; … … 572 683 { 573 684 btVector3 axis = d6constraint->getAxis(i); 574 row += get_limit_motor_info2( 575 d6constraint->getRotationalLimitMotor(i), 576 &m_rbA, 577 &m_rbB, 578 info,row,axis,1); 685 int flags = m_flags >> ((i + 3) * BT_6DOF_FLAGS_AXIS_SHIFT); 686 if(!(flags & BT_6DOF_FLAGS_CFM_NORM)) 687 { 688 m_angularLimits[i].m_normalCFM = info->cfm[0]; 689 } 690 if(!(flags & BT_6DOF_FLAGS_CFM_STOP)) 691 { 692 m_angularLimits[i].m_stopCFM = info->cfm[0]; 693 } 694 if(!(flags & BT_6DOF_FLAGS_ERP_STOP)) 695 { 696 m_angularLimits[i].m_stopERP = info->erp; 697 } 698 row += get_limit_motor_info2(d6constraint->getRotationalLimitMotor(i), 699 transA,transB,linVelA,linVelB,angVelA,angVelB, info,row,axis,1); 579 700 } 580 701 } … … 583 704 } 584 705 585 //----------------------------------------------------------------------------- 586 587 void btGeneric6DofConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) 588 { 589 if (m_useSolveConstraintObsolete) 590 { 591 592 593 m_timeStep = timeStep; 594 595 //calculateTransforms(); 596 597 int i; 598 599 // linear 600 601 btVector3 pointInA = m_calculatedTransformA.getOrigin(); 602 btVector3 pointInB = m_calculatedTransformB.getOrigin(); 603 604 btScalar jacDiagABInv; 605 btVector3 linear_axis; 606 for (i=0;i<3;i++) 607 { 608 if (m_linearLimits.isLimited(i)) 609 { 610 jacDiagABInv = btScalar(1.) / m_jacLinear[i].getDiagonal(); 611 612 if (m_useLinearReferenceFrameA) 613 linear_axis = m_calculatedTransformA.getBasis().getColumn(i); 614 else 615 linear_axis = m_calculatedTransformB.getBasis().getColumn(i); 616 617 m_linearLimits.solveLinearAxis( 618 m_timeStep, 619 jacDiagABInv, 620 m_rbA,bodyA,pointInA, 621 m_rbB,bodyB,pointInB, 622 i,linear_axis, m_AnchorPos); 623 624 } 625 } 626 627 // angular 628 btVector3 angular_axis; 629 btScalar angularJacDiagABInv; 630 for (i=0;i<3;i++) 631 { 632 if (m_angularLimits[i].needApplyTorques()) 633 { 634 635 // get axis 636 angular_axis = getAxis(i); 637 638 angularJacDiagABInv = btScalar(1.) / m_jacAng[i].getDiagonal(); 639 640 m_angularLimits[i].solveAngularLimits(m_timeStep,angular_axis,angularJacDiagABInv, &m_rbA,bodyA,&m_rbB,bodyB); 641 } 642 } 643 } 644 } 645 646 //----------------------------------------------------------------------------- 706 707 647 708 648 709 void btGeneric6DofConstraint::updateRHS(btScalar timeStep) … … 652 713 } 653 714 654 //----------------------------------------------------------------------------- 715 655 716 656 717 btVector3 btGeneric6DofConstraint::getAxis(int axis_index) const … … 659 720 } 660 721 661 //----------------------------------------------------------------------------- 662 663 btScalar btGeneric6DofConstraint::getAngle(int axis_index) const 664 { 665 return m_calculatedAxisAngleDiff[axis_index]; 666 } 667 668 //----------------------------------------------------------------------------- 722 723 btScalar btGeneric6DofConstraint::getRelativePivotPosition(int axisIndex) const 724 { 725 return m_calculatedLinearDiff[axisIndex]; 726 } 727 728 729 btScalar btGeneric6DofConstraint::getAngle(int axisIndex) const 730 { 731 return m_calculatedAxisAngleDiff[axisIndex]; 732 } 733 734 669 735 670 736 void btGeneric6DofConstraint::calcAnchorPos(void) … … 685 751 m_AnchorPos = pA * weight + pB * (btScalar(1.0) - weight); 686 752 return; 687 } // btGeneric6DofConstraint::calcAnchorPos()688 689 //----------------------------------------------------------------------------- 753 } 754 755 690 756 691 757 void btGeneric6DofConstraint::calculateLinearInfo() … … 695 761 for(int i = 0; i < 3; i++) 696 762 { 763 m_linearLimits.m_currentLinearDiff[i] = m_calculatedLinearDiff[i]; 697 764 m_linearLimits.testLimitValue(i, m_calculatedLinearDiff[i]); 698 765 } 699 } // btGeneric6DofConstraint::calculateLinearInfo()700 701 //----------------------------------------------------------------------------- 766 } 767 768 702 769 703 770 int btGeneric6DofConstraint::get_limit_motor_info2( 704 771 btRotationalLimitMotor * limot, 705 btRigidBody * body0, btRigidBody * body1,706 btConstraintInfo2 *info, int row, btVector3& ax1, int rotational )772 const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB, 773 btConstraintInfo2 *info, int row, btVector3& ax1, int rotational,int rotAllowed) 707 774 { 708 775 int srow = row * info->rowskip; … … 722 789 J2[srow+2] = -ax1[2]; 723 790 } 724 if((!rotational) && limit)791 if((!rotational)) 725 792 { 726 btVector3 ltd; // Linear Torque Decoupling vector 727 btVector3 c = m_calculatedTransformB.getOrigin() - body0->getCenterOfMassPosition(); 728 ltd = c.cross(ax1); 729 info->m_J1angularAxis[srow+0] = ltd[0]; 730 info->m_J1angularAxis[srow+1] = ltd[1]; 731 info->m_J1angularAxis[srow+2] = ltd[2]; 732 733 c = m_calculatedTransformB.getOrigin() - body1->getCenterOfMassPosition(); 734 ltd = -c.cross(ax1); 735 info->m_J2angularAxis[srow+0] = ltd[0]; 736 info->m_J2angularAxis[srow+1] = ltd[1]; 737 info->m_J2angularAxis[srow+2] = ltd[2]; 793 if (m_useOffsetForConstraintFrame) 794 { 795 btVector3 tmpA, tmpB, relA, relB; 796 // get vector from bodyB to frameB in WCS 797 relB = m_calculatedTransformB.getOrigin() - transB.getOrigin(); 798 // get its projection to constraint axis 799 btVector3 projB = ax1 * relB.dot(ax1); 800 // get vector directed from bodyB to constraint axis (and orthogonal to it) 801 btVector3 orthoB = relB - projB; 802 // same for bodyA 803 relA = m_calculatedTransformA.getOrigin() - transA.getOrigin(); 804 btVector3 projA = ax1 * relA.dot(ax1); 805 btVector3 orthoA = relA - projA; 806 // get desired offset between frames A and B along constraint axis 807 btScalar desiredOffs = limot->m_currentPosition - limot->m_currentLimitError; 808 // desired vector from projection of center of bodyA to projection of center of bodyB to constraint axis 809 btVector3 totalDist = projA + ax1 * desiredOffs - projB; 810 // get offset vectors relA and relB 811 relA = orthoA + totalDist * m_factA; 812 relB = orthoB - totalDist * m_factB; 813 tmpA = relA.cross(ax1); 814 tmpB = relB.cross(ax1); 815 if(m_hasStaticBody && (!rotAllowed)) 816 { 817 tmpA *= m_factA; 818 tmpB *= m_factB; 819 } 820 int i; 821 for (i=0; i<3; i++) info->m_J1angularAxis[srow+i] = tmpA[i]; 822 for (i=0; i<3; i++) info->m_J2angularAxis[srow+i] = -tmpB[i]; 823 } else 824 { 825 btVector3 ltd; // Linear Torque Decoupling vector 826 btVector3 c = m_calculatedTransformB.getOrigin() - transA.getOrigin(); 827 ltd = c.cross(ax1); 828 info->m_J1angularAxis[srow+0] = ltd[0]; 829 info->m_J1angularAxis[srow+1] = ltd[1]; 830 info->m_J1angularAxis[srow+2] = ltd[2]; 831 832 c = m_calculatedTransformB.getOrigin() - transB.getOrigin(); 833 ltd = -c.cross(ax1); 834 info->m_J2angularAxis[srow+0] = ltd[0]; 835 info->m_J2angularAxis[srow+1] = ltd[1]; 836 info->m_J2angularAxis[srow+2] = ltd[2]; 837 } 738 838 } 739 839 // if we're limited low and high simultaneously, the joint motor is … … 743 843 if (powered) 744 844 { 745 info->cfm[srow] = 0.0f;845 info->cfm[srow] = limot->m_normalCFM; 746 846 if(!limit) 747 847 { 748 info->m_constraintError[srow] += limot->m_targetVelocity; 848 btScalar tag_vel = rotational ? limot->m_targetVelocity : -limot->m_targetVelocity; 849 850 btScalar mot_fact = getMotorFactor( limot->m_currentPosition, 851 limot->m_loLimit, 852 limot->m_hiLimit, 853 tag_vel, 854 info->fps * limot->m_stopERP); 855 info->m_constraintError[srow] += mot_fact * limot->m_targetVelocity; 749 856 info->m_lowerLimit[srow] = -limot->m_maxMotorForce; 750 857 info->m_upperLimit[srow] = limot->m_maxMotorForce; … … 753 860 if(limit) 754 861 { 755 btScalar k = info->fps * limot->m_ ERP;862 btScalar k = info->fps * limot->m_stopERP; 756 863 if(!rotational) 757 864 { … … 762 869 info->m_constraintError[srow] += -k * limot->m_currentLimitError; 763 870 } 764 info->cfm[srow] = 0.0f;871 info->cfm[srow] = limot->m_stopCFM; 765 872 if (limot->m_loLimit == limot->m_hiLimit) 766 873 { // limited low and high simultaneously … … 787 894 if (rotational) 788 895 { 789 vel = body0->getAngularVelocity().dot(ax1); 790 if (body1) 791 vel -= body1->getAngularVelocity().dot(ax1); 896 vel = angVelA.dot(ax1); 897 //make sure that if no body -> angVelB == zero vec 898 // if (body1) 899 vel -= angVelB.dot(ax1); 792 900 } 793 901 else 794 902 { 795 vel = body0->getLinearVelocity().dot(ax1); 796 if (body1) 797 vel -= body1->getLinearVelocity().dot(ax1); 903 vel = linVelA.dot(ax1); 904 //make sure that if no body -> angVelB == zero vec 905 // if (body1) 906 vel -= linVelB.dot(ax1); 798 907 } 799 908 // only apply bounce if the velocity is incoming, and if the … … 825 934 } 826 935 827 //----------------------------------------------------------------------------- 828 //----------------------------------------------------------------------------- 829 //----------------------------------------------------------------------------- 936 937 938 939 940 941 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 942 ///If no axis is provided, it uses the default axis for this constraint. 943 void btGeneric6DofConstraint::setParam(int num, btScalar value, int axis) 944 { 945 if((axis >= 0) && (axis < 3)) 946 { 947 switch(num) 948 { 949 case BT_CONSTRAINT_STOP_ERP : 950 m_linearLimits.m_stopERP[axis] = value; 951 m_flags |= BT_6DOF_FLAGS_ERP_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT); 952 break; 953 case BT_CONSTRAINT_STOP_CFM : 954 m_linearLimits.m_stopCFM[axis] = value; 955 m_flags |= BT_6DOF_FLAGS_CFM_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT); 956 break; 957 case BT_CONSTRAINT_CFM : 958 m_linearLimits.m_normalCFM[axis] = value; 959 m_flags |= BT_6DOF_FLAGS_CFM_NORM << (axis * BT_6DOF_FLAGS_AXIS_SHIFT); 960 break; 961 default : 962 btAssertConstrParams(0); 963 } 964 } 965 else if((axis >=3) && (axis < 6)) 966 { 967 switch(num) 968 { 969 case BT_CONSTRAINT_STOP_ERP : 970 m_angularLimits[axis - 3].m_stopERP = value; 971 m_flags |= BT_6DOF_FLAGS_ERP_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT); 972 break; 973 case BT_CONSTRAINT_STOP_CFM : 974 m_angularLimits[axis - 3].m_stopCFM = value; 975 m_flags |= BT_6DOF_FLAGS_CFM_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT); 976 break; 977 case BT_CONSTRAINT_CFM : 978 m_angularLimits[axis - 3].m_normalCFM = value; 979 m_flags |= BT_6DOF_FLAGS_CFM_NORM << (axis * BT_6DOF_FLAGS_AXIS_SHIFT); 980 break; 981 default : 982 btAssertConstrParams(0); 983 } 984 } 985 else 986 { 987 btAssertConstrParams(0); 988 } 989 } 990 991 ///return the local value of parameter 992 btScalar btGeneric6DofConstraint::getParam(int num, int axis) const 993 { 994 btScalar retVal = 0; 995 if((axis >= 0) && (axis < 3)) 996 { 997 switch(num) 998 { 999 case BT_CONSTRAINT_STOP_ERP : 1000 btAssertConstrParams(m_flags & (BT_6DOF_FLAGS_ERP_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT))); 1001 retVal = m_linearLimits.m_stopERP[axis]; 1002 break; 1003 case BT_CONSTRAINT_STOP_CFM : 1004 btAssertConstrParams(m_flags & (BT_6DOF_FLAGS_CFM_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT))); 1005 retVal = m_linearLimits.m_stopCFM[axis]; 1006 break; 1007 case BT_CONSTRAINT_CFM : 1008 btAssertConstrParams(m_flags & (BT_6DOF_FLAGS_CFM_NORM << (axis * BT_6DOF_FLAGS_AXIS_SHIFT))); 1009 retVal = m_linearLimits.m_normalCFM[axis]; 1010 break; 1011 default : 1012 btAssertConstrParams(0); 1013 } 1014 } 1015 else if((axis >=3) && (axis < 6)) 1016 { 1017 switch(num) 1018 { 1019 case BT_CONSTRAINT_STOP_ERP : 1020 btAssertConstrParams(m_flags & (BT_6DOF_FLAGS_ERP_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT))); 1021 retVal = m_angularLimits[axis - 3].m_stopERP; 1022 break; 1023 case BT_CONSTRAINT_STOP_CFM : 1024 btAssertConstrParams(m_flags & (BT_6DOF_FLAGS_CFM_STOP << (axis * BT_6DOF_FLAGS_AXIS_SHIFT))); 1025 retVal = m_angularLimits[axis - 3].m_stopCFM; 1026 break; 1027 case BT_CONSTRAINT_CFM : 1028 btAssertConstrParams(m_flags & (BT_6DOF_FLAGS_CFM_NORM << (axis * BT_6DOF_FLAGS_AXIS_SHIFT))); 1029 retVal = m_angularLimits[axis - 3].m_normalCFM; 1030 break; 1031 default : 1032 btAssertConstrParams(0); 1033 } 1034 } 1035 else 1036 { 1037 btAssertConstrParams(0); 1038 } 1039 return retVal; 1040 } -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h
r5781 r8351 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 16 /// 2009 March: btGeneric6DofConstraint refactored by Roman Ponomarev 17 /// Added support for generic constraint solver through getInfo1/getInfo2 methods 18 15 19 /* 16 20 2007-09-09 … … 46 50 btScalar m_damping;//!< Damping. 47 51 btScalar m_limitSoftness;//! Relaxation factor 48 btScalar m_ERP;//!< Error tolerance factor when joint is at limit 52 btScalar m_normalCFM;//!< Constraint force mixing factor 53 btScalar m_stopERP;//!< Error tolerance factor when joint is at limit 54 btScalar m_stopCFM;//!< Constraint force mixing factor when joint is at limit 49 55 btScalar m_bounce;//!< restitution factor 50 56 bool m_enableMotor; … … 55 61 //!@{ 56 62 btScalar m_currentLimitError;//! How much is violated this limit 63 btScalar m_currentPosition; //! current value of angle 57 64 int m_currentLimit;//!< 0=free, 1=at lo limit, 2=at hi limit 58 65 btScalar m_accumulatedImpulse; … … 65 72 m_maxMotorForce = 0.1f; 66 73 m_maxLimitForce = 300.0f; 67 m_loLimit = -SIMD_INFINITY; 68 m_hiLimit = SIMD_INFINITY; 69 m_ERP = 0.5f; 74 m_loLimit = 1.0f; 75 m_hiLimit = -1.0f; 76 m_normalCFM = 0.f; 77 m_stopERP = 0.2f; 78 m_stopCFM = 0.f; 70 79 m_bounce = 0.0f; 71 80 m_damping = 1.0f; … … 83 92 m_loLimit = limot.m_loLimit; 84 93 m_hiLimit = limot.m_hiLimit; 85 m_ERP = limot.m_ERP; 94 m_normalCFM = limot.m_normalCFM; 95 m_stopERP = limot.m_stopERP; 96 m_stopCFM = limot.m_stopCFM; 86 97 m_bounce = limot.m_bounce; 87 98 m_currentLimit = limot.m_currentLimit; … … 113 124 114 125 //! apply the correction impulses for two bodies 115 btScalar solveAngularLimits(btScalar timeStep,btVector3& axis, btScalar jacDiagABInv,btRigidBody * body0, bt SolverBody& bodyA,btRigidBody * body1,btSolverBody& bodyB);126 btScalar solveAngularLimits(btScalar timeStep,btVector3& axis, btScalar jacDiagABInv,btRigidBody * body0, btRigidBody * body1); 116 127 117 128 }; … … 130 141 btScalar m_damping;//!< Damping for linear limit 131 142 btScalar m_restitution;//! Bounce parameter for linear limit 143 btVector3 m_normalCFM;//!< Constraint force mixing factor 144 btVector3 m_stopERP;//!< Error tolerance factor when joint is at limit 145 btVector3 m_stopCFM;//!< Constraint force mixing factor when joint is at limit 132 146 //!@} 133 147 bool m_enableMotor[3]; … … 135 149 btVector3 m_maxMotorForce;//!< max force on motor 136 150 btVector3 m_currentLimitError;//! How much is violated this limit 151 btVector3 m_currentLinearDiff;//! Current relative offset of constraint frames 137 152 int m_currentLimit[3];//!< 0=free, 1=at lower limit, 2=at upper limit 138 153 … … 142 157 m_upperLimit.setValue(0.f,0.f,0.f); 143 158 m_accumulatedImpulse.setValue(0.f,0.f,0.f); 159 m_normalCFM.setValue(0.f, 0.f, 0.f); 160 m_stopERP.setValue(0.2f, 0.2f, 0.2f); 161 m_stopCFM.setValue(0.f, 0.f, 0.f); 144 162 145 163 m_limitSoftness = 0.7f; … … 163 181 m_damping = other.m_damping; 164 182 m_restitution = other.m_restitution; 183 m_normalCFM = other.m_normalCFM; 184 m_stopERP = other.m_stopERP; 185 m_stopCFM = other.m_stopCFM; 186 165 187 for(int i=0; i < 3; i++) 166 188 { … … 193 215 btScalar timeStep, 194 216 btScalar jacDiagABInv, 195 btRigidBody& body1, btSolverBody& bodyA,const btVector3 &pointInA,196 btRigidBody& body2, btSolverBody& bodyB,const btVector3 &pointInB,217 btRigidBody& body1,const btVector3 &pointInA, 218 btRigidBody& body2,const btVector3 &pointInB, 197 219 int limit_index, 198 220 const btVector3 & axis_normal_on_a, … … 201 223 202 224 }; 225 226 enum bt6DofFlags 227 { 228 BT_6DOF_FLAGS_CFM_NORM = 1, 229 BT_6DOF_FLAGS_CFM_STOP = 2, 230 BT_6DOF_FLAGS_ERP_STOP = 4 231 }; 232 #define BT_6DOF_FLAGS_AXIS_SHIFT 3 // bits per axis 233 203 234 204 235 /// btGeneric6DofConstraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space … … 216 247 <li> Angulars limits have these possible ranges: 217 248 <table border=1 > 218 <tr 219 249 <tr> 220 250 <td><b>AXIS</b></td> 221 251 <td><b>MIN ANGLE</b></td> 222 252 <td><b>MAX ANGLE</b></td> 253 </tr><tr> 223 254 <td>X</td> 224 <td>-PI</td> 225 <td>PI</td> 255 <td>-PI</td> 256 <td>PI</td> 257 </tr><tr> 226 258 <td>Y</td> 227 <td>-PI/2</td> 228 <td>PI/2</td> 259 <td>-PI/2</td> 260 <td>PI/2</td> 261 </tr><tr> 229 262 <td>Z</td> 230 <td>-PI/2</td>231 <td>PI/2</td>263 <td>-PI</td> 264 <td>PI</td> 232 265 </tr> 233 266 </table> … … 273 306 btVector3 m_calculatedAxis[3]; 274 307 btVector3 m_calculatedLinearDiff; 308 btScalar m_factA; 309 btScalar m_factB; 310 bool m_hasStaticBody; 275 311 276 312 btVector3 m_AnchorPos; // point betwen pivots of bodies A and B to solve linear axes 277 313 278 314 bool m_useLinearReferenceFrameA; 315 bool m_useOffsetForConstraintFrame; 279 316 317 int m_flags; 318 280 319 //!@} 281 320 … … 288 327 289 328 290 int setAngularLimits(btConstraintInfo2 *info, int row_offset );291 292 int setLinearLimits(btConstraintInfo2 *info );329 int setAngularLimits(btConstraintInfo2 *info, int row_offset,const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB); 330 331 int setLinearLimits(btConstraintInfo2 *info, int row, const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB); 293 332 294 333 void buildLinearJacobian( … … 312 351 313 352 btGeneric6DofConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); 314 315 btGeneric6DofConstraint(); 316 353 btGeneric6DofConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameB); 354 317 355 //! Calcs global transform of the offsets 318 356 /*! … … 320 358 \sa btGeneric6DofConstraint.getCalculatedTransformA , btGeneric6DofConstraint.getCalculatedTransformB, btGeneric6DofConstraint.calculateAngleInfo 321 359 */ 322 void calculateTransforms(); 360 void calculateTransforms(const btTransform& transA,const btTransform& transB); 361 362 void calculateTransforms(); 323 363 324 364 //! Gets the global transform of the offset for body A … … 367 407 virtual void getInfo1 (btConstraintInfo1* info); 368 408 409 void getInfo1NonVirtual (btConstraintInfo1* info); 410 369 411 virtual void getInfo2 (btConstraintInfo2* info); 370 412 371 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep); 413 void getInfo2NonVirtual (btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB); 414 372 415 373 416 void updateRHS(btScalar timeStep); … … 381 424 //! Get the relative Euler angle 382 425 /*! 383 \pre btGeneric6DofConstraint .buildJacobianmust be called previously.426 \pre btGeneric6DofConstraint::calculateTransforms() must be called previously. 384 427 */ 385 428 btScalar getAngle(int axis_index) const; 429 430 //! Get the relative position of the constraint pivot 431 /*! 432 \pre btGeneric6DofConstraint::calculateTransforms() must be called previously. 433 */ 434 btScalar getRelativePivotPosition(int axis_index) const; 435 386 436 387 437 //! Test angular limit. 388 438 /*! 389 439 Calculates angular correction and returns true if limit needs to be corrected. 390 \pre btGeneric6DofConstraint .buildJacobianmust be called previously.440 \pre btGeneric6DofConstraint::calculateTransforms() must be called previously. 391 441 */ 392 442 bool testAngularLimitMotor(int axis_index); … … 404 454 void setAngularLowerLimit(const btVector3& angularLower) 405 455 { 406 m_angularLimits[0].m_loLimit = angularLower.getX(); 407 m_angularLimits[1].m_loLimit = angularLower.getY(); 408 m_angularLimits[2].m_loLimit = angularLower.getZ(); 456 for(int i = 0; i < 3; i++) 457 m_angularLimits[i].m_loLimit = btNormalizeAngle(angularLower[i]); 409 458 } 410 459 411 460 void setAngularUpperLimit(const btVector3& angularUpper) 412 461 { 413 m_angularLimits[0].m_hiLimit = angularUpper.getX(); 414 m_angularLimits[1].m_hiLimit = angularUpper.getY(); 415 m_angularLimits[2].m_hiLimit = angularUpper.getZ(); 462 for(int i = 0; i < 3; i++) 463 m_angularLimits[i].m_hiLimit = btNormalizeAngle(angularUpper[i]); 416 464 } 417 465 … … 438 486 else 439 487 { 488 lo = btNormalizeAngle(lo); 489 hi = btNormalizeAngle(hi); 440 490 m_angularLimits[axis-3].m_loLimit = lo; 441 491 m_angularLimits[axis-3].m_hiLimit = hi; … … 460 510 } 461 511 462 const btRigidBody& getRigidBodyA() const463 {464 return m_rbA;465 }466 const btRigidBody& getRigidBodyB() const467 {468 return m_rbB;469 }470 471 512 virtual void calcAnchorPos(void); // overridable 472 513 473 514 int get_limit_motor_info2( btRotationalLimitMotor * limot, 474 btRigidBody * body0, btRigidBody * body1, 475 btConstraintInfo2 *info, int row, btVector3& ax1, int rotational); 476 477 515 const btTransform& transA,const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB,const btVector3& angVelA,const btVector3& angVelB, 516 btConstraintInfo2 *info, int row, btVector3& ax1, int rotational, int rotAllowed = false); 517 518 // access for UseFrameOffset 519 bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; } 520 void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; } 521 522 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 523 ///If no axis is provided, it uses the default axis for this constraint. 524 virtual void setParam(int num, btScalar value, int axis = -1); 525 ///return the local value of parameter 526 virtual btScalar getParam(int num, int axis = -1) const; 527 528 virtual int calculateSerializeBufferSize() const; 529 530 ///fills the dataBuffer and returns the struct name (and 0 on failure) 531 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 532 533 478 534 }; 479 535 536 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 537 struct btGeneric6DofConstraintData 538 { 539 btTypedConstraintData m_typeConstraintData; 540 btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis. 541 btTransformFloatData m_rbBFrame; 542 543 btVector3FloatData m_linearUpperLimit; 544 btVector3FloatData m_linearLowerLimit; 545 546 btVector3FloatData m_angularUpperLimit; 547 btVector3FloatData m_angularLowerLimit; 548 549 int m_useLinearReferenceFrameA; 550 int m_useOffsetForConstraintFrame; 551 }; 552 553 SIMD_FORCE_INLINE int btGeneric6DofConstraint::calculateSerializeBufferSize() const 554 { 555 return sizeof(btGeneric6DofConstraintData); 556 } 557 558 ///fills the dataBuffer and returns the struct name (and 0 on failure) 559 SIMD_FORCE_INLINE const char* btGeneric6DofConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 560 { 561 562 btGeneric6DofConstraintData* dof = (btGeneric6DofConstraintData*)dataBuffer; 563 btTypedConstraint::serialize(&dof->m_typeConstraintData,serializer); 564 565 m_frameInA.serializeFloat(dof->m_rbAFrame); 566 m_frameInB.serializeFloat(dof->m_rbBFrame); 567 568 569 int i; 570 for (i=0;i<3;i++) 571 { 572 dof->m_angularLowerLimit.m_floats[i] = float(m_angularLimits[i].m_loLimit); 573 dof->m_angularUpperLimit.m_floats[i] = float(m_angularLimits[i].m_hiLimit); 574 dof->m_linearLowerLimit.m_floats[i] = float(m_linearLimits.m_lowerLimit[i]); 575 dof->m_linearUpperLimit.m_floats[i] = float(m_linearLimits.m_upperLimit[i]); 576 } 577 578 dof->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA? 1 : 0; 579 dof->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame ? 1 : 0; 580 581 return "btGeneric6DofConstraintData"; 582 } 583 584 585 586 587 480 588 #endif //GENERIC_6DOF_CONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btHingeConstraint.cpp
r5781 r8351 22 22 #include "btSolverBody.h" 23 23 24 //----------------------------------------------------------------------------- 25 24 25 26 //#define HINGE_USE_OBSOLETE_SOLVER false 26 27 #define HINGE_USE_OBSOLETE_SOLVER false 27 28 28 //----------------------------------------------------------------------------- 29 30 31 btHingeConstraint::btHingeConstraint() 32 : btTypedConstraint (HINGE_CONSTRAINT_TYPE), 33 m_enableAngularMotor(false), 34 m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), 35 m_useReferenceFrameA(false) 36 { 37 m_referenceSign = m_useReferenceFrameA ? btScalar(-1.f) : btScalar(1.f); 38 } 39 40 //----------------------------------------------------------------------------- 29 #define HINGE_USE_FRAME_OFFSET true 30 31 #ifndef __SPU__ 32 33 34 35 41 36 42 37 btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, 43 btVector3& axisInA,btVector3& axisInB, bool useReferenceFrameA)38 const btVector3& axisInA,const btVector3& axisInB, bool useReferenceFrameA) 44 39 :btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA,rbB), 45 40 m_angularOnly(false), 46 41 m_enableAngularMotor(false), 47 42 m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), 48 m_useReferenceFrameA(useReferenceFrameA) 43 m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), 44 m_useReferenceFrameA(useReferenceFrameA), 45 m_flags(0) 49 46 { 50 47 m_rbAFrame.getOrigin() = pivotInA; … … 80 77 81 78 //start with free 82 m_lowerLimit = btScalar(1 e30);83 m_upperLimit = btScalar(-1 e30);79 m_lowerLimit = btScalar(1.0f); 80 m_upperLimit = btScalar(-1.0f); 84 81 m_biasFactor = 0.3f; 85 82 m_relaxationFactor = 1.0f; … … 89 86 } 90 87 91 //----------------------------------------------------------------------------- 92 93 btHingeConstraint::btHingeConstraint(btRigidBody& rbA,const btVector3& pivotInA, btVector3& axisInA, bool useReferenceFrameA)88 89 90 btHingeConstraint::btHingeConstraint(btRigidBody& rbA,const btVector3& pivotInA,const btVector3& axisInA, bool useReferenceFrameA) 94 91 :btTypedConstraint(HINGE_CONSTRAINT_TYPE, rbA), m_angularOnly(false), m_enableAngularMotor(false), 95 92 m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), 96 m_useReferenceFrameA(useReferenceFrameA) 93 m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), 94 m_useReferenceFrameA(useReferenceFrameA), 95 m_flags(0) 97 96 { 98 97 … … 120 119 121 120 //start with free 122 m_lowerLimit = btScalar(1 e30);123 m_upperLimit = btScalar(-1 e30);121 m_lowerLimit = btScalar(1.0f); 122 m_upperLimit = btScalar(-1.0f); 124 123 m_biasFactor = 0.3f; 125 124 m_relaxationFactor = 1.0f; … … 129 128 } 130 129 131 //----------------------------------------------------------------------------- 130 132 131 133 132 btHingeConstraint::btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, … … 137 136 m_enableAngularMotor(false), 138 137 m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), 139 m_useReferenceFrameA(useReferenceFrameA) 138 m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), 139 m_useReferenceFrameA(useReferenceFrameA), 140 m_flags(0) 140 141 { 141 142 //start with free 142 m_lowerLimit = btScalar(1 e30);143 m_upperLimit = btScalar(-1 e30);143 m_lowerLimit = btScalar(1.0f); 144 m_upperLimit = btScalar(-1.0f); 144 145 m_biasFactor = 0.3f; 145 146 m_relaxationFactor = 1.0f; … … 149 150 } 150 151 151 //----------------------------------------------------------------------------- 152 152 153 153 154 btHingeConstraint::btHingeConstraint(btRigidBody& rbA, const btTransform& rbAFrame, bool useReferenceFrameA) … … 156 157 m_enableAngularMotor(false), 157 158 m_useSolveConstraintObsolete(HINGE_USE_OBSOLETE_SOLVER), 158 m_useReferenceFrameA(useReferenceFrameA) 159 m_useOffsetForConstraintFrame(HINGE_USE_FRAME_OFFSET), 160 m_useReferenceFrameA(useReferenceFrameA), 161 m_flags(0) 159 162 { 160 163 ///not providing rigidbody B means implicitly using worldspace for body B … … 163 166 164 167 //start with free 165 m_lowerLimit = btScalar(1 e30);166 m_upperLimit = btScalar(-1 e30);168 m_lowerLimit = btScalar(1.0f); 169 m_upperLimit = btScalar(-1.0f); 167 170 m_biasFactor = 0.3f; 168 171 m_relaxationFactor = 1.0f; … … 172 175 } 173 176 174 //----------------------------------------------------------------------------- 177 175 178 176 179 void btHingeConstraint::buildJacobian() … … 179 182 { 180 183 m_appliedImpulse = btScalar(0.); 184 m_accMotorImpulse = btScalar(0.); 181 185 182 186 if (!m_angularOnly) … … 222 226 btPlaneSpace1(m_rbAFrame.getBasis().getColumn(2),jointAxis0local,jointAxis1local); 223 227 224 getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(2);225 228 btVector3 jointAxis0 = getRigidBodyA().getCenterOfMassTransform().getBasis() * jointAxis0local; 226 229 btVector3 jointAxis1 = getRigidBodyA().getCenterOfMassTransform().getBasis() * jointAxis1local; … … 249 252 250 253 // test angular limit 251 testLimit( );254 testLimit(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 252 255 253 256 //Compute K = J*W*J' for hinge axis … … 259 262 } 260 263 261 //----------------------------------------------------------------------------- 264 265 #endif //__SPU__ 266 262 267 263 268 void btHingeConstraint::getInfo1(btConstraintInfo1* info) … … 272 277 info->m_numConstraintRows = 5; // Fixed 3 linear + 2 angular 273 278 info->nub = 1; 279 //always add the row, to avoid computation (data is not available yet) 274 280 //prepare constraint 275 testLimit( );281 testLimit(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 276 282 if(getSolveLimit() || getEnableAngularMotor()) 277 283 { … … 279 285 info->nub--; 280 286 } 281 } 282 } // btHingeConstraint::getInfo1 () 283 284 //----------------------------------------------------------------------------- 287 288 } 289 } 290 291 void btHingeConstraint::getInfo1NonVirtual(btConstraintInfo1* info) 292 { 293 if (m_useSolveConstraintObsolete) 294 { 295 info->m_numConstraintRows = 0; 296 info->nub = 0; 297 } 298 else 299 { 300 //always add the 'limit' row, to avoid computation (data is not available yet) 301 info->m_numConstraintRows = 6; // Fixed 3 linear + 2 angular 302 info->nub = 0; 303 } 304 } 285 305 286 306 void btHingeConstraint::getInfo2 (btConstraintInfo2* info) 287 307 { 308 if(m_useOffsetForConstraintFrame) 309 { 310 getInfo2InternalUsingFrameOffset(info, m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform(),m_rbA.getAngularVelocity(),m_rbB.getAngularVelocity()); 311 } 312 else 313 { 314 getInfo2Internal(info, m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform(),m_rbA.getAngularVelocity(),m_rbB.getAngularVelocity()); 315 } 316 } 317 318 319 void btHingeConstraint::getInfo2NonVirtual (btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btVector3& angVelA,const btVector3& angVelB) 320 { 321 ///the regular (virtual) implementation getInfo2 already performs 'testLimit' during getInfo1, so we need to do it now 322 testLimit(transA,transB); 323 324 getInfo2Internal(info,transA,transB,angVelA,angVelB); 325 } 326 327 328 void btHingeConstraint::getInfo2Internal(btConstraintInfo2* info, const btTransform& transA,const btTransform& transB,const btVector3& angVelA,const btVector3& angVelB) 329 { 330 288 331 btAssert(!m_useSolveConstraintObsolete); 289 int i, s = info->rowskip;332 int i, skip = info->rowskip; 290 333 // transforms in world space 291 btTransform trA = m_rbA.getCenterOfMassTransform()*m_rbAFrame;292 btTransform trB = m_rbB.getCenterOfMassTransform()*m_rbBFrame;334 btTransform trA = transA*m_rbAFrame; 335 btTransform trB = transB*m_rbBFrame; 293 336 // pivot point 294 337 btVector3 pivotAInW = trA.getOrigin(); 295 338 btVector3 pivotBInW = trB.getOrigin(); 339 #if 0 340 if (0) 341 { 342 for (i=0;i<6;i++) 343 { 344 info->m_J1linearAxis[i*skip]=0; 345 info->m_J1linearAxis[i*skip+1]=0; 346 info->m_J1linearAxis[i*skip+2]=0; 347 348 info->m_J1angularAxis[i*skip]=0; 349 info->m_J1angularAxis[i*skip+1]=0; 350 info->m_J1angularAxis[i*skip+2]=0; 351 352 info->m_J2angularAxis[i*skip]=0; 353 info->m_J2angularAxis[i*skip+1]=0; 354 info->m_J2angularAxis[i*skip+2]=0; 355 356 info->m_constraintError[i*skip]=0.f; 357 } 358 } 359 #endif //#if 0 296 360 // linear (all fixed) 297 info->m_J1linearAxis[0] = 1; 298 info->m_J1linearAxis[s + 1] = 1; 299 info->m_J1linearAxis[2 * s + 2] = 1; 300 btVector3 a1 = pivotAInW - m_rbA.getCenterOfMassTransform().getOrigin(); 361 362 if (!m_angularOnly) 363 { 364 info->m_J1linearAxis[0] = 1; 365 info->m_J1linearAxis[skip + 1] = 1; 366 info->m_J1linearAxis[2 * skip + 2] = 1; 367 } 368 369 370 371 372 btVector3 a1 = pivotAInW - transA.getOrigin(); 301 373 { 302 374 btVector3* angular0 = (btVector3*)(info->m_J1angularAxis); 303 btVector3* angular1 = (btVector3*)(info->m_J1angularAxis + s );304 btVector3* angular2 = (btVector3*)(info->m_J1angularAxis + 2 * s );375 btVector3* angular1 = (btVector3*)(info->m_J1angularAxis + skip); 376 btVector3* angular2 = (btVector3*)(info->m_J1angularAxis + 2 * skip); 305 377 btVector3 a1neg = -a1; 306 378 a1neg.getSkewSymmetricMatrix(angular0,angular1,angular2); 307 379 } 308 btVector3 a2 = pivotBInW - m_rbB.getCenterOfMassTransform().getOrigin();380 btVector3 a2 = pivotBInW - transB.getOrigin(); 309 381 { 310 382 btVector3* angular0 = (btVector3*)(info->m_J2angularAxis); 311 btVector3* angular1 = (btVector3*)(info->m_J2angularAxis + s );312 btVector3* angular2 = (btVector3*)(info->m_J2angularAxis + 2 * s );383 btVector3* angular1 = (btVector3*)(info->m_J2angularAxis + skip); 384 btVector3* angular2 = (btVector3*)(info->m_J2angularAxis + 2 * skip); 313 385 a2.getSkewSymmetricMatrix(angular0,angular1,angular2); 314 386 } 315 387 // linear RHS 316 388 btScalar k = info->fps * info->erp; 317 for(i = 0; i < 3; i++) 318 { 319 info->m_constraintError[i * s] = k * (pivotBInW[i] - pivotAInW[i]); 320 } 389 if (!m_angularOnly) 390 { 391 for(i = 0; i < 3; i++) 392 { 393 info->m_constraintError[i * skip] = k * (pivotBInW[i] - pivotAInW[i]); 394 } 395 } 321 396 // make rotations around X and Y equal 322 397 // the hinge axis should be the only unconstrained … … 403 478 } 404 479 info->m_constraintError[srow] = btScalar(0.0f); 480 btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : info->erp; 405 481 if(powered) 406 482 { 407 info->cfm[srow] = btScalar(0.0); 408 btScalar mot_fact = getMotorFactor(m_hingeAngle, lostop, histop, m_motorTargetVelocity, info->fps * info->erp); 483 if(m_flags & BT_HINGE_FLAGS_CFM_NORM) 484 { 485 info->cfm[srow] = m_normalCFM; 486 } 487 btScalar mot_fact = getMotorFactor(m_hingeAngle, lostop, histop, m_motorTargetVelocity, info->fps * currERP); 409 488 info->m_constraintError[srow] += mot_fact * m_motorTargetVelocity * m_referenceSign; 410 489 info->m_lowerLimit[srow] = - m_maxMotorImpulse; … … 413 492 if(limit) 414 493 { 415 k = info->fps * info->erp;494 k = info->fps * currERP; 416 495 info->m_constraintError[srow] += k * limit_err; 417 info->cfm[srow] = btScalar(0.0); 496 if(m_flags & BT_HINGE_FLAGS_CFM_STOP) 497 { 498 info->cfm[srow] = m_stopCFM; 499 } 418 500 if(lostop == histop) 419 501 { … … 436 518 if(bounce > btScalar(0.0)) 437 519 { 438 btScalar vel = m_rbA.getAngularVelocity().dot(ax1);439 vel -= m_rbB.getAngularVelocity().dot(ax1);520 btScalar vel = angVelA.dot(ax1); 521 vel -= angVelB.dot(ax1); 440 522 // only apply bounce if the velocity is incoming, and if the 441 523 // resulting c[] exceeds what we already have. … … 468 550 } 469 551 470 //----------------------------------------------------------------------------- 471 472 void btHingeConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) 473 { 474 475 ///for backwards compatibility during the transition to 'getInfo/getInfo2' 476 if (m_useSolveConstraintObsolete) 477 { 478 479 btVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_rbAFrame.getOrigin(); 480 btVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_rbBFrame.getOrigin(); 481 482 btScalar tau = btScalar(0.3); 483 484 //linear part 485 if (!m_angularOnly) 486 { 487 btVector3 rel_pos1 = pivotAInW - m_rbA.getCenterOfMassPosition(); 488 btVector3 rel_pos2 = pivotBInW - m_rbB.getCenterOfMassPosition(); 489 490 btVector3 vel1,vel2; 491 bodyA.getVelocityInLocalPointObsolete(rel_pos1,vel1); 492 bodyB.getVelocityInLocalPointObsolete(rel_pos2,vel2); 493 btVector3 vel = vel1 - vel2; 494 495 for (int i=0;i<3;i++) 496 { 497 const btVector3& normal = m_jac[i].m_linearJointAxis; 498 btScalar jacDiagABInv = btScalar(1.) / m_jac[i].getDiagonal(); 499 500 btScalar rel_vel; 501 rel_vel = normal.dot(vel); 502 //positional error (zeroth order error) 503 btScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal 504 btScalar impulse = depth*tau/timeStep * jacDiagABInv - rel_vel * jacDiagABInv; 505 m_appliedImpulse += impulse; 506 btVector3 impulse_vector = normal * impulse; 507 btVector3 ftorqueAxis1 = rel_pos1.cross(normal); 508 btVector3 ftorqueAxis2 = rel_pos2.cross(normal); 509 bodyA.applyImpulse(normal*m_rbA.getInvMass(), m_rbA.getInvInertiaTensorWorld()*ftorqueAxis1,impulse); 510 bodyB.applyImpulse(normal*m_rbB.getInvMass(), m_rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-impulse); 511 } 512 } 513 514 515 { 516 ///solve angular part 517 518 // get axes in world space 519 btVector3 axisA = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(2); 520 btVector3 axisB = getRigidBodyB().getCenterOfMassTransform().getBasis() * m_rbBFrame.getBasis().getColumn(2); 521 522 btVector3 angVelA; 523 bodyA.getAngularVelocity(angVelA); 524 btVector3 angVelB; 525 bodyB.getAngularVelocity(angVelB); 526 527 btVector3 angVelAroundHingeAxisA = axisA * axisA.dot(angVelA); 528 btVector3 angVelAroundHingeAxisB = axisB * axisB.dot(angVelB); 529 530 btVector3 angAorthog = angVelA - angVelAroundHingeAxisA; 531 btVector3 angBorthog = angVelB - angVelAroundHingeAxisB; 532 btVector3 velrelOrthog = angAorthog-angBorthog; 533 { 534 535 536 //solve orthogonal angular velocity correction 537 btScalar relaxation = btScalar(1.); 538 btScalar len = velrelOrthog.length(); 539 if (len > btScalar(0.00001)) 540 { 541 btVector3 normal = velrelOrthog.normalized(); 542 btScalar denom = getRigidBodyA().computeAngularImpulseDenominator(normal) + 543 getRigidBodyB().computeAngularImpulseDenominator(normal); 544 // scale for mass and relaxation 545 //velrelOrthog *= (btScalar(1.)/denom) * m_relaxationFactor; 546 547 bodyA.applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*velrelOrthog,-(btScalar(1.)/denom)); 548 bodyB.applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*velrelOrthog,(btScalar(1.)/denom)); 549 550 } 551 552 //solve angular positional correction 553 btVector3 angularError = axisA.cross(axisB) *(btScalar(1.)/timeStep); 554 btScalar len2 = angularError.length(); 555 if (len2>btScalar(0.00001)) 556 { 557 btVector3 normal2 = angularError.normalized(); 558 btScalar denom2 = getRigidBodyA().computeAngularImpulseDenominator(normal2) + 559 getRigidBodyB().computeAngularImpulseDenominator(normal2); 560 //angularError *= (btScalar(1.)/denom2) * relaxation; 561 562 bodyA.applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*angularError,(btScalar(1.)/denom2)); 563 bodyB.applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*angularError,-(btScalar(1.)/denom2)); 564 565 } 566 567 568 569 570 571 // solve limit 572 if (m_solveLimit) 573 { 574 btScalar amplitude = ( (angVelB - angVelA).dot( axisA )*m_relaxationFactor + m_correction* (btScalar(1.)/timeStep)*m_biasFactor ) * m_limitSign; 575 576 btScalar impulseMag = amplitude * m_kHinge; 577 578 // Clamp the accumulated impulse 579 btScalar temp = m_accLimitImpulse; 580 m_accLimitImpulse = btMax(m_accLimitImpulse + impulseMag, btScalar(0) ); 581 impulseMag = m_accLimitImpulse - temp; 582 583 584 585 bodyA.applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*axisA,impulseMag * m_limitSign); 586 bodyB.applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*axisA,-(impulseMag * m_limitSign)); 587 588 } 589 } 590 591 //apply motor 592 if (m_enableAngularMotor) 593 { 594 //todo: add limits too 595 btVector3 angularLimit(0,0,0); 596 597 btVector3 velrel = angVelAroundHingeAxisA - angVelAroundHingeAxisB; 598 btScalar projRelVel = velrel.dot(axisA); 599 600 btScalar desiredMotorVel = m_motorTargetVelocity; 601 btScalar motor_relvel = desiredMotorVel - projRelVel; 602 603 btScalar unclippedMotorImpulse = m_kHinge * motor_relvel;; 604 //todo: should clip against accumulated impulse 605 btScalar clippedMotorImpulse = unclippedMotorImpulse > m_maxMotorImpulse ? m_maxMotorImpulse : unclippedMotorImpulse; 606 clippedMotorImpulse = clippedMotorImpulse < -m_maxMotorImpulse ? -m_maxMotorImpulse : clippedMotorImpulse; 607 btVector3 motorImp = clippedMotorImpulse * axisA; 608 609 bodyA.applyImpulse(btVector3(0,0,0), m_rbA.getInvInertiaTensorWorld()*axisA,clippedMotorImpulse); 610 bodyB.applyImpulse(btVector3(0,0,0), m_rbB.getInvInertiaTensorWorld()*axisA,-clippedMotorImpulse); 611 612 } 613 } 614 } 615 616 } 617 618 //----------------------------------------------------------------------------- 552 553 554 555 619 556 620 557 void btHingeConstraint::updateRHS(btScalar timeStep) … … 624 561 } 625 562 626 //-----------------------------------------------------------------------------627 563 628 564 btScalar btHingeConstraint::getHingeAngle() 629 565 { 630 const btVector3 refAxis0 = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(0); 631 const btVector3 refAxis1 = getRigidBodyA().getCenterOfMassTransform().getBasis() * m_rbAFrame.getBasis().getColumn(1); 632 const btVector3 swingAxis = getRigidBodyB().getCenterOfMassTransform().getBasis() * m_rbBFrame.getBasis().getColumn(1); 633 btScalar angle = btAtan2Fast(swingAxis.dot(refAxis0), swingAxis.dot(refAxis1)); 566 return getHingeAngle(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 567 } 568 569 btScalar btHingeConstraint::getHingeAngle(const btTransform& transA,const btTransform& transB) 570 { 571 const btVector3 refAxis0 = transA.getBasis() * m_rbAFrame.getBasis().getColumn(0); 572 const btVector3 refAxis1 = transA.getBasis() * m_rbAFrame.getBasis().getColumn(1); 573 const btVector3 swingAxis = transB.getBasis() * m_rbBFrame.getBasis().getColumn(1); 574 // btScalar angle = btAtan2Fast(swingAxis.dot(refAxis0), swingAxis.dot(refAxis1)); 575 btScalar angle = btAtan2(swingAxis.dot(refAxis0), swingAxis.dot(refAxis1)); 634 576 return m_referenceSign * angle; 635 577 } 636 578 637 //----------------------------------------------------------------------------- 638 579 580 #if 0 639 581 void btHingeConstraint::testLimit() 640 582 { … … 660 602 } 661 603 return; 662 } // btHingeConstraint::testLimit() 663 664 //----------------------------------------------------------------------------- 665 //----------------------------------------------------------------------------- 666 //----------------------------------------------------------------------------- 604 } 605 #else 606 607 608 void btHingeConstraint::testLimit(const btTransform& transA,const btTransform& transB) 609 { 610 // Compute limit information 611 m_hingeAngle = getHingeAngle(transA,transB); 612 m_correction = btScalar(0.); 613 m_limitSign = btScalar(0.); 614 m_solveLimit = false; 615 if (m_lowerLimit <= m_upperLimit) 616 { 617 m_hingeAngle = btAdjustAngleToLimits(m_hingeAngle, m_lowerLimit, m_upperLimit); 618 if (m_hingeAngle <= m_lowerLimit) 619 { 620 m_correction = (m_lowerLimit - m_hingeAngle); 621 m_limitSign = 1.0f; 622 m_solveLimit = true; 623 } 624 else if (m_hingeAngle >= m_upperLimit) 625 { 626 m_correction = m_upperLimit - m_hingeAngle; 627 m_limitSign = -1.0f; 628 m_solveLimit = true; 629 } 630 } 631 return; 632 } 633 #endif 634 635 static btVector3 vHinge(0, 0, btScalar(1)); 636 637 void btHingeConstraint::setMotorTarget(const btQuaternion& qAinB, btScalar dt) 638 { 639 // convert target from body to constraint space 640 btQuaternion qConstraint = m_rbBFrame.getRotation().inverse() * qAinB * m_rbAFrame.getRotation(); 641 qConstraint.normalize(); 642 643 // extract "pure" hinge component 644 btVector3 vNoHinge = quatRotate(qConstraint, vHinge); vNoHinge.normalize(); 645 btQuaternion qNoHinge = shortestArcQuat(vHinge, vNoHinge); 646 btQuaternion qHinge = qNoHinge.inverse() * qConstraint; 647 qHinge.normalize(); 648 649 // compute angular target, clamped to limits 650 btScalar targetAngle = qHinge.getAngle(); 651 if (targetAngle > SIMD_PI) // long way around. flip quat and recalculate. 652 { 653 qHinge = operator-(qHinge); 654 targetAngle = qHinge.getAngle(); 655 } 656 if (qHinge.getZ() < 0) 657 targetAngle = -targetAngle; 658 659 setMotorTarget(targetAngle, dt); 660 } 661 662 void btHingeConstraint::setMotorTarget(btScalar targetAngle, btScalar dt) 663 { 664 if (m_lowerLimit < m_upperLimit) 665 { 666 if (targetAngle < m_lowerLimit) 667 targetAngle = m_lowerLimit; 668 else if (targetAngle > m_upperLimit) 669 targetAngle = m_upperLimit; 670 } 671 672 // compute angular velocity 673 btScalar curAngle = getHingeAngle(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 674 btScalar dAngle = targetAngle - curAngle; 675 m_motorTargetVelocity = dAngle / dt; 676 } 677 678 679 680 void btHingeConstraint::getInfo2InternalUsingFrameOffset(btConstraintInfo2* info, const btTransform& transA,const btTransform& transB,const btVector3& angVelA,const btVector3& angVelB) 681 { 682 btAssert(!m_useSolveConstraintObsolete); 683 int i, s = info->rowskip; 684 // transforms in world space 685 btTransform trA = transA*m_rbAFrame; 686 btTransform trB = transB*m_rbBFrame; 687 // pivot point 688 btVector3 pivotAInW = trA.getOrigin(); 689 btVector3 pivotBInW = trB.getOrigin(); 690 #if 1 691 // difference between frames in WCS 692 btVector3 ofs = trB.getOrigin() - trA.getOrigin(); 693 // now get weight factors depending on masses 694 btScalar miA = getRigidBodyA().getInvMass(); 695 btScalar miB = getRigidBodyB().getInvMass(); 696 bool hasStaticBody = (miA < SIMD_EPSILON) || (miB < SIMD_EPSILON); 697 btScalar miS = miA + miB; 698 btScalar factA, factB; 699 if(miS > btScalar(0.f)) 700 { 701 factA = miB / miS; 702 } 703 else 704 { 705 factA = btScalar(0.5f); 706 } 707 factB = btScalar(1.0f) - factA; 708 // get the desired direction of hinge axis 709 // as weighted sum of Z-orthos of frameA and frameB in WCS 710 btVector3 ax1A = trA.getBasis().getColumn(2); 711 btVector3 ax1B = trB.getBasis().getColumn(2); 712 btVector3 ax1 = ax1A * factA + ax1B * factB; 713 ax1.normalize(); 714 // fill first 3 rows 715 // we want: velA + wA x relA == velB + wB x relB 716 btTransform bodyA_trans = transA; 717 btTransform bodyB_trans = transB; 718 int s0 = 0; 719 int s1 = s; 720 int s2 = s * 2; 721 int nrow = 2; // last filled row 722 btVector3 tmpA, tmpB, relA, relB, p, q; 723 // get vector from bodyB to frameB in WCS 724 relB = trB.getOrigin() - bodyB_trans.getOrigin(); 725 // get its projection to hinge axis 726 btVector3 projB = ax1 * relB.dot(ax1); 727 // get vector directed from bodyB to hinge axis (and orthogonal to it) 728 btVector3 orthoB = relB - projB; 729 // same for bodyA 730 relA = trA.getOrigin() - bodyA_trans.getOrigin(); 731 btVector3 projA = ax1 * relA.dot(ax1); 732 btVector3 orthoA = relA - projA; 733 btVector3 totalDist = projA - projB; 734 // get offset vectors relA and relB 735 relA = orthoA + totalDist * factA; 736 relB = orthoB - totalDist * factB; 737 // now choose average ortho to hinge axis 738 p = orthoB * factA + orthoA * factB; 739 btScalar len2 = p.length2(); 740 if(len2 > SIMD_EPSILON) 741 { 742 p /= btSqrt(len2); 743 } 744 else 745 { 746 p = trA.getBasis().getColumn(1); 747 } 748 // make one more ortho 749 q = ax1.cross(p); 750 // fill three rows 751 tmpA = relA.cross(p); 752 tmpB = relB.cross(p); 753 for (i=0; i<3; i++) info->m_J1angularAxis[s0+i] = tmpA[i]; 754 for (i=0; i<3; i++) info->m_J2angularAxis[s0+i] = -tmpB[i]; 755 tmpA = relA.cross(q); 756 tmpB = relB.cross(q); 757 if(hasStaticBody && getSolveLimit()) 758 { // to make constraint between static and dynamic objects more rigid 759 // remove wA (or wB) from equation if angular limit is hit 760 tmpB *= factB; 761 tmpA *= factA; 762 } 763 for (i=0; i<3; i++) info->m_J1angularAxis[s1+i] = tmpA[i]; 764 for (i=0; i<3; i++) info->m_J2angularAxis[s1+i] = -tmpB[i]; 765 tmpA = relA.cross(ax1); 766 tmpB = relB.cross(ax1); 767 if(hasStaticBody) 768 { // to make constraint between static and dynamic objects more rigid 769 // remove wA (or wB) from equation 770 tmpB *= factB; 771 tmpA *= factA; 772 } 773 for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmpA[i]; 774 for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = -tmpB[i]; 775 776 btScalar k = info->fps * info->erp; 777 778 if (!m_angularOnly) 779 { 780 for (i=0; i<3; i++) info->m_J1linearAxis[s0+i] = p[i]; 781 for (i=0; i<3; i++) info->m_J1linearAxis[s1+i] = q[i]; 782 for (i=0; i<3; i++) info->m_J1linearAxis[s2+i] = ax1[i]; 783 784 // compute three elements of right hand side 785 786 btScalar rhs = k * p.dot(ofs); 787 info->m_constraintError[s0] = rhs; 788 rhs = k * q.dot(ofs); 789 info->m_constraintError[s1] = rhs; 790 rhs = k * ax1.dot(ofs); 791 info->m_constraintError[s2] = rhs; 792 } 793 // the hinge axis should be the only unconstrained 794 // rotational axis, the angular velocity of the two bodies perpendicular to 795 // the hinge axis should be equal. thus the constraint equations are 796 // p*w1 - p*w2 = 0 797 // q*w1 - q*w2 = 0 798 // where p and q are unit vectors normal to the hinge axis, and w1 and w2 799 // are the angular velocity vectors of the two bodies. 800 int s3 = 3 * s; 801 int s4 = 4 * s; 802 info->m_J1angularAxis[s3 + 0] = p[0]; 803 info->m_J1angularAxis[s3 + 1] = p[1]; 804 info->m_J1angularAxis[s3 + 2] = p[2]; 805 info->m_J1angularAxis[s4 + 0] = q[0]; 806 info->m_J1angularAxis[s4 + 1] = q[1]; 807 info->m_J1angularAxis[s4 + 2] = q[2]; 808 809 info->m_J2angularAxis[s3 + 0] = -p[0]; 810 info->m_J2angularAxis[s3 + 1] = -p[1]; 811 info->m_J2angularAxis[s3 + 2] = -p[2]; 812 info->m_J2angularAxis[s4 + 0] = -q[0]; 813 info->m_J2angularAxis[s4 + 1] = -q[1]; 814 info->m_J2angularAxis[s4 + 2] = -q[2]; 815 // compute the right hand side of the constraint equation. set relative 816 // body velocities along p and q to bring the hinge back into alignment. 817 // if ax1A,ax1B are the unit length hinge axes as computed from bodyA and 818 // bodyB, we need to rotate both bodies along the axis u = (ax1 x ax2). 819 // if "theta" is the angle between ax1 and ax2, we need an angular velocity 820 // along u to cover angle erp*theta in one step : 821 // |angular_velocity| = angle/time = erp*theta / stepsize 822 // = (erp*fps) * theta 823 // angular_velocity = |angular_velocity| * (ax1 x ax2) / |ax1 x ax2| 824 // = (erp*fps) * theta * (ax1 x ax2) / sin(theta) 825 // ...as ax1 and ax2 are unit length. if theta is smallish, 826 // theta ~= sin(theta), so 827 // angular_velocity = (erp*fps) * (ax1 x ax2) 828 // ax1 x ax2 is in the plane space of ax1, so we project the angular 829 // velocity to p and q to find the right hand side. 830 k = info->fps * info->erp; 831 btVector3 u = ax1A.cross(ax1B); 832 info->m_constraintError[s3] = k * u.dot(p); 833 info->m_constraintError[s4] = k * u.dot(q); 834 #endif 835 // check angular limits 836 nrow = 4; // last filled row 837 int srow; 838 btScalar limit_err = btScalar(0.0); 839 int limit = 0; 840 if(getSolveLimit()) 841 { 842 limit_err = m_correction * m_referenceSign; 843 limit = (limit_err > btScalar(0.0)) ? 1 : 2; 844 } 845 // if the hinge has joint limits or motor, add in the extra row 846 int powered = 0; 847 if(getEnableAngularMotor()) 848 { 849 powered = 1; 850 } 851 if(limit || powered) 852 { 853 nrow++; 854 srow = nrow * info->rowskip; 855 info->m_J1angularAxis[srow+0] = ax1[0]; 856 info->m_J1angularAxis[srow+1] = ax1[1]; 857 info->m_J1angularAxis[srow+2] = ax1[2]; 858 859 info->m_J2angularAxis[srow+0] = -ax1[0]; 860 info->m_J2angularAxis[srow+1] = -ax1[1]; 861 info->m_J2angularAxis[srow+2] = -ax1[2]; 862 863 btScalar lostop = getLowerLimit(); 864 btScalar histop = getUpperLimit(); 865 if(limit && (lostop == histop)) 866 { // the joint motor is ineffective 867 powered = 0; 868 } 869 info->m_constraintError[srow] = btScalar(0.0f); 870 btScalar currERP = (m_flags & BT_HINGE_FLAGS_ERP_STOP) ? m_stopERP : info->erp; 871 if(powered) 872 { 873 if(m_flags & BT_HINGE_FLAGS_CFM_NORM) 874 { 875 info->cfm[srow] = m_normalCFM; 876 } 877 btScalar mot_fact = getMotorFactor(m_hingeAngle, lostop, histop, m_motorTargetVelocity, info->fps * currERP); 878 info->m_constraintError[srow] += mot_fact * m_motorTargetVelocity * m_referenceSign; 879 info->m_lowerLimit[srow] = - m_maxMotorImpulse; 880 info->m_upperLimit[srow] = m_maxMotorImpulse; 881 } 882 if(limit) 883 { 884 k = info->fps * currERP; 885 info->m_constraintError[srow] += k * limit_err; 886 if(m_flags & BT_HINGE_FLAGS_CFM_STOP) 887 { 888 info->cfm[srow] = m_stopCFM; 889 } 890 if(lostop == histop) 891 { 892 // limited low and high simultaneously 893 info->m_lowerLimit[srow] = -SIMD_INFINITY; 894 info->m_upperLimit[srow] = SIMD_INFINITY; 895 } 896 else if(limit == 1) 897 { // low limit 898 info->m_lowerLimit[srow] = 0; 899 info->m_upperLimit[srow] = SIMD_INFINITY; 900 } 901 else 902 { // high limit 903 info->m_lowerLimit[srow] = -SIMD_INFINITY; 904 info->m_upperLimit[srow] = 0; 905 } 906 // bounce (we'll use slider parameter abs(1.0 - m_dampingLimAng) for that) 907 btScalar bounce = m_relaxationFactor; 908 if(bounce > btScalar(0.0)) 909 { 910 btScalar vel = angVelA.dot(ax1); 911 vel -= angVelB.dot(ax1); 912 // only apply bounce if the velocity is incoming, and if the 913 // resulting c[] exceeds what we already have. 914 if(limit == 1) 915 { // low limit 916 if(vel < 0) 917 { 918 btScalar newc = -bounce * vel; 919 if(newc > info->m_constraintError[srow]) 920 { 921 info->m_constraintError[srow] = newc; 922 } 923 } 924 } 925 else 926 { // high limit - all those computations are reversed 927 if(vel > 0) 928 { 929 btScalar newc = -bounce * vel; 930 if(newc < info->m_constraintError[srow]) 931 { 932 info->m_constraintError[srow] = newc; 933 } 934 } 935 } 936 } 937 info->m_constraintError[srow] *= m_biasFactor; 938 } // if(limit) 939 } // if angular limit or powered 940 } 941 942 943 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 944 ///If no axis is provided, it uses the default axis for this constraint. 945 void btHingeConstraint::setParam(int num, btScalar value, int axis) 946 { 947 if((axis == -1) || (axis == 5)) 948 { 949 switch(num) 950 { 951 case BT_CONSTRAINT_STOP_ERP : 952 m_stopERP = value; 953 m_flags |= BT_HINGE_FLAGS_ERP_STOP; 954 break; 955 case BT_CONSTRAINT_STOP_CFM : 956 m_stopCFM = value; 957 m_flags |= BT_HINGE_FLAGS_CFM_STOP; 958 break; 959 case BT_CONSTRAINT_CFM : 960 m_normalCFM = value; 961 m_flags |= BT_HINGE_FLAGS_CFM_NORM; 962 break; 963 default : 964 btAssertConstrParams(0); 965 } 966 } 967 else 968 { 969 btAssertConstrParams(0); 970 } 971 } 972 973 ///return the local value of parameter 974 btScalar btHingeConstraint::getParam(int num, int axis) const 975 { 976 btScalar retVal = 0; 977 if((axis == -1) || (axis == 5)) 978 { 979 switch(num) 980 { 981 case BT_CONSTRAINT_STOP_ERP : 982 btAssertConstrParams(m_flags & BT_HINGE_FLAGS_ERP_STOP); 983 retVal = m_stopERP; 984 break; 985 case BT_CONSTRAINT_STOP_CFM : 986 btAssertConstrParams(m_flags & BT_HINGE_FLAGS_CFM_STOP); 987 retVal = m_stopCFM; 988 break; 989 case BT_CONSTRAINT_CFM : 990 btAssertConstrParams(m_flags & BT_HINGE_FLAGS_CFM_NORM); 991 retVal = m_normalCFM; 992 break; 993 default : 994 btAssertConstrParams(0); 995 } 996 } 997 else 998 { 999 btAssertConstrParams(0); 1000 } 1001 return retVal; 1002 } 1003 1004 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btHingeConstraint.h
r5781 r8351 25 25 class btRigidBody; 26 26 27 #ifdef BT_USE_DOUBLE_PRECISION 28 #define btHingeConstraintData btHingeConstraintDoubleData 29 #define btHingeConstraintDataName "btHingeConstraintDoubleData" 30 #else 31 #define btHingeConstraintData btHingeConstraintFloatData 32 #define btHingeConstraintDataName "btHingeConstraintFloatData" 33 #endif //BT_USE_DOUBLE_PRECISION 34 35 36 enum btHingeFlags 37 { 38 BT_HINGE_FLAGS_CFM_STOP = 1, 39 BT_HINGE_FLAGS_ERP_STOP = 2, 40 BT_HINGE_FLAGS_CFM_NORM = 4 41 }; 42 43 27 44 /// hinge constraint between two rigidbodies each with a pivotpoint that descibes the axis location in local space 28 45 /// axis defines the orientation of the hinge axis 29 classbtHingeConstraint : public btTypedConstraint46 ATTRIBUTE_ALIGNED16(class) btHingeConstraint : public btTypedConstraint 30 47 { 31 48 #ifdef IN_PARALLELL_SOLVER … … 61 78 bool m_solveLimit; 62 79 bool m_useSolveConstraintObsolete; 80 bool m_useOffsetForConstraintFrame; 63 81 bool m_useReferenceFrameA; 64 82 83 btScalar m_accMotorImpulse; 84 85 int m_flags; 86 btScalar m_normalCFM; 87 btScalar m_stopCFM; 88 btScalar m_stopERP; 89 65 90 66 91 public: 67 92 68 btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, btVector3& axisInA,btVector3& axisInB, bool useReferenceFrameA = false);69 70 btHingeConstraint(btRigidBody& rbA,const btVector3& pivotInA, btVector3& axisInA, bool useReferenceFrameA = false);93 btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB, const btVector3& axisInA,const btVector3& axisInB, bool useReferenceFrameA = false); 94 95 btHingeConstraint(btRigidBody& rbA,const btVector3& pivotInA,const btVector3& axisInA, bool useReferenceFrameA = false); 71 96 72 97 btHingeConstraint(btRigidBody& rbA,btRigidBody& rbB, const btTransform& rbAFrame, const btTransform& rbBFrame, bool useReferenceFrameA = false); … … 74 99 btHingeConstraint(btRigidBody& rbA,const btTransform& rbAFrame, bool useReferenceFrameA = false); 75 100 76 btHingeConstraint();77 101 78 102 virtual void buildJacobian(); … … 80 104 virtual void getInfo1 (btConstraintInfo1* info); 81 105 106 void getInfo1NonVirtual(btConstraintInfo1* info); 107 82 108 virtual void getInfo2 (btConstraintInfo2* info); 83 84 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep); 109 110 void getInfo2NonVirtual(btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btVector3& angVelA,const btVector3& angVelB); 111 112 void getInfo2Internal(btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btVector3& angVelA,const btVector3& angVelB); 113 void getInfo2InternalUsingFrameOffset(btConstraintInfo2* info,const btTransform& transA,const btTransform& transB,const btVector3& angVelA,const btVector3& angVelB); 114 85 115 86 116 void updateRHS(btScalar timeStep); … … 117 147 } 118 148 149 // extra motor API, including ability to set a target rotation (as opposed to angular velocity) 150 // note: setMotorTarget sets angular velocity under the hood, so you must call it every tick to 151 // maintain a given angular target. 152 void enableMotor(bool enableMotor) { m_enableAngularMotor = enableMotor; } 153 void setMaxMotorImpulse(btScalar maxMotorImpulse) { m_maxMotorImpulse = maxMotorImpulse; } 154 void setMotorTarget(const btQuaternion& qAinB, btScalar dt); // qAinB is rotation of body A wrt body B. 155 void setMotorTarget(btScalar targetAngle, btScalar dt); 156 157 119 158 void setLimit(btScalar low,btScalar high,btScalar _softness = 0.9f, btScalar _biasFactor = 0.3f, btScalar _relaxationFactor = 1.0f) 120 159 { 121 m_lowerLimit = low;122 m_upperLimit = high;160 m_lowerLimit = btNormalizeAngle(low); 161 m_upperLimit = btNormalizeAngle(high); 123 162 124 163 m_limitSoftness = _softness; … … 128 167 } 129 168 169 void setAxis(btVector3& axisInA) 170 { 171 btVector3 rbAxisA1, rbAxisA2; 172 btPlaneSpace1(axisInA, rbAxisA1, rbAxisA2); 173 btVector3 pivotInA = m_rbAFrame.getOrigin(); 174 // m_rbAFrame.getOrigin() = pivotInA; 175 m_rbAFrame.getBasis().setValue( rbAxisA1.getX(),rbAxisA2.getX(),axisInA.getX(), 176 rbAxisA1.getY(),rbAxisA2.getY(),axisInA.getY(), 177 rbAxisA1.getZ(),rbAxisA2.getZ(),axisInA.getZ() ); 178 179 btVector3 axisInB = m_rbA.getCenterOfMassTransform().getBasis() * axisInA; 180 181 btQuaternion rotationArc = shortestArcQuat(axisInA,axisInB); 182 btVector3 rbAxisB1 = quatRotate(rotationArc,rbAxisA1); 183 btVector3 rbAxisB2 = axisInB.cross(rbAxisB1); 184 185 186 m_rbBFrame.getOrigin() = m_rbA.getCenterOfMassTransform()(pivotInA); 187 m_rbBFrame.getBasis().setValue( rbAxisB1.getX(),rbAxisB2.getX(),axisInB.getX(), 188 rbAxisB1.getY(),rbAxisB2.getY(),axisInB.getY(), 189 rbAxisB1.getZ(),rbAxisB2.getZ(),axisInB.getZ() ); 190 } 191 130 192 btScalar getLowerLimit() const 131 193 { … … 141 203 btScalar getHingeAngle(); 142 204 143 void testLimit(); 144 145 146 const btTransform& getAFrame() { return m_rbAFrame; }; 147 const btTransform& getBFrame() { return m_rbBFrame; }; 205 btScalar getHingeAngle(const btTransform& transA,const btTransform& transB); 206 207 void testLimit(const btTransform& transA,const btTransform& transB); 208 209 210 const btTransform& getAFrame() const { return m_rbAFrame; }; 211 const btTransform& getBFrame() const { return m_rbBFrame; }; 212 213 btTransform& getAFrame() { return m_rbAFrame; }; 214 btTransform& getBFrame() { return m_rbBFrame; }; 148 215 149 216 inline int getSolveLimit() … … 173 240 return m_maxMotorImpulse; 174 241 } 242 // access for UseFrameOffset 243 bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; } 244 void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; } 245 246 247 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 248 ///If no axis is provided, it uses the default axis for this constraint. 249 virtual void setParam(int num, btScalar value, int axis = -1); 250 ///return the local value of parameter 251 virtual btScalar getParam(int num, int axis = -1) const; 252 253 virtual int calculateSerializeBufferSize() const; 254 255 ///fills the dataBuffer and returns the struct name (and 0 on failure) 256 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 257 175 258 176 259 }; 177 260 261 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 262 struct btHingeConstraintDoubleData 263 { 264 btTypedConstraintData m_typeConstraintData; 265 btTransformDoubleData m_rbAFrame; // constraint axii. Assumes z is hinge axis. 266 btTransformDoubleData m_rbBFrame; 267 int m_useReferenceFrameA; 268 int m_angularOnly; 269 int m_enableAngularMotor; 270 float m_motorTargetVelocity; 271 float m_maxMotorImpulse; 272 273 float m_lowerLimit; 274 float m_upperLimit; 275 float m_limitSoftness; 276 float m_biasFactor; 277 float m_relaxationFactor; 278 279 }; 280 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 281 struct btHingeConstraintFloatData 282 { 283 btTypedConstraintData m_typeConstraintData; 284 btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis. 285 btTransformFloatData m_rbBFrame; 286 int m_useReferenceFrameA; 287 int m_angularOnly; 288 289 int m_enableAngularMotor; 290 float m_motorTargetVelocity; 291 float m_maxMotorImpulse; 292 293 float m_lowerLimit; 294 float m_upperLimit; 295 float m_limitSoftness; 296 float m_biasFactor; 297 float m_relaxationFactor; 298 299 }; 300 301 302 303 SIMD_FORCE_INLINE int btHingeConstraint::calculateSerializeBufferSize() const 304 { 305 return sizeof(btHingeConstraintData); 306 } 307 308 ///fills the dataBuffer and returns the struct name (and 0 on failure) 309 SIMD_FORCE_INLINE const char* btHingeConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 310 { 311 btHingeConstraintData* hingeData = (btHingeConstraintData*)dataBuffer; 312 btTypedConstraint::serialize(&hingeData->m_typeConstraintData,serializer); 313 314 m_rbAFrame.serialize(hingeData->m_rbAFrame); 315 m_rbBFrame.serialize(hingeData->m_rbBFrame); 316 317 hingeData->m_angularOnly = m_angularOnly; 318 hingeData->m_enableAngularMotor = m_enableAngularMotor; 319 hingeData->m_maxMotorImpulse = float(m_maxMotorImpulse); 320 hingeData->m_motorTargetVelocity = float(m_motorTargetVelocity); 321 hingeData->m_useReferenceFrameA = m_useReferenceFrameA; 322 323 hingeData->m_lowerLimit = float(m_lowerLimit); 324 hingeData->m_upperLimit = float(m_upperLimit); 325 hingeData->m_limitSoftness = float(m_limitSoftness); 326 hingeData->m_biasFactor = float(m_biasFactor); 327 hingeData->m_relaxationFactor = float(m_relaxationFactor); 328 329 return btHingeConstraintDataName; 330 } 331 178 332 #endif //HINGECONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btJacobianEntry.h
r5781 r8351 29 29 /// it can be used in combination with a constraint solver 30 30 /// Can be used to relate the effect of an impulse to the constraint error 31 classbtJacobianEntry31 ATTRIBUTE_ALIGNED16(class) btJacobianEntry 32 32 { 33 33 public: -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.cpp
r5781 r8351 21 21 22 22 23 btPoint2PointConstraint::btPoint2PointConstraint() 24 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE), 25 m_useSolveConstraintObsolete(false) 26 { 27 } 23 28 24 29 25 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB) 30 26 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA,rbB),m_pivotInA(pivotInA),m_pivotInB(pivotInB), 27 m_flags(0), 31 28 m_useSolveConstraintObsolete(false) 32 29 { … … 37 34 btPoint2PointConstraint::btPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA) 38 35 :btTypedConstraint(POINT2POINT_CONSTRAINT_TYPE,rbA),m_pivotInA(pivotInA),m_pivotInB(rbA.getCenterOfMassTransform()(pivotInA)), 36 m_flags(0), 39 37 m_useSolveConstraintObsolete(false) 40 38 { … … 44 42 void btPoint2PointConstraint::buildJacobian() 45 43 { 44 46 45 ///we need it for both methods 47 46 { … … 67 66 } 68 67 69 } 70 68 69 } 71 70 72 71 void btPoint2PointConstraint::getInfo1 (btConstraintInfo1* info) 72 { 73 getInfo1NonVirtual(info); 74 } 75 76 void btPoint2PointConstraint::getInfo1NonVirtual (btConstraintInfo1* info) 73 77 { 74 78 if (m_useSolveConstraintObsolete) … … 83 87 } 84 88 89 90 91 85 92 void btPoint2PointConstraint::getInfo2 (btConstraintInfo2* info) 86 93 { 94 getInfo2NonVirtual(info, m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 95 } 96 97 void btPoint2PointConstraint::getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& body0_trans, const btTransform& body1_trans) 98 { 87 99 btAssert(!m_useSolveConstraintObsolete); 88 100 89 101 //retrieve matrices 90 btTransform body0_trans;91 body0_trans = m_rbA.getCenterOfMassTransform();92 btTransform body1_trans;93 body1_trans = m_rbB.getCenterOfMassTransform();94 102 95 103 // anchor points in global coordinates with respect to body PORs. … … 97 105 // set jacobian 98 106 info->m_J1linearAxis[0] = 1; 99 100 107 info->m_J1linearAxis[info->rowskip+1] = 1; 108 info->m_J1linearAxis[2*info->rowskip+2] = 1; 101 109 102 110 btVector3 a1 = body0_trans.getBasis()*getPivotInA(); … … 127 135 128 136 // set right hand side 129 btScalar k = info->fps * info->erp; 137 btScalar currERP = (m_flags & BT_P2P_FLAGS_ERP) ? m_erp : info->erp; 138 btScalar k = info->fps * currERP; 130 139 int j; 131 132 140 for (j=0; j<3; j++) 133 141 { 134 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - 142 info->m_constraintError[j*info->rowskip] = k * (a2[j] + body1_trans.getOrigin()[j] - a1[j] - body0_trans.getOrigin()[j]); 135 143 //printf("info->m_constraintError[%d]=%f\n",j,info->m_constraintError[j]); 136 144 } 145 if(m_flags & BT_P2P_FLAGS_CFM) 146 { 147 for (j=0; j<3; j++) 148 { 149 info->cfm[j*info->rowskip] = m_cfm; 150 } 151 } 137 152 138 153 btScalar impulseClamp = m_setting.m_impulseClamp;// … … 145 160 } 146 161 } 147 148 } 149 150 151 void btPoint2PointConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) 152 { 153 if (m_useSolveConstraintObsolete) 154 { 155 btVector3 pivotAInW = m_rbA.getCenterOfMassTransform()*m_pivotInA; 156 btVector3 pivotBInW = m_rbB.getCenterOfMassTransform()*m_pivotInB; 157 158 159 btVector3 normal(0,0,0); 160 161 162 // btVector3 angvelA = m_rbA.getCenterOfMassTransform().getBasis().transpose() * m_rbA.getAngularVelocity(); 163 // btVector3 angvelB = m_rbB.getCenterOfMassTransform().getBasis().transpose() * m_rbB.getAngularVelocity(); 164 165 for (int i=0;i<3;i++) 166 { 167 normal[i] = 1; 168 btScalar jacDiagABInv = btScalar(1.) / m_jac[i].getDiagonal(); 169 170 btVector3 rel_pos1 = pivotAInW - m_rbA.getCenterOfMassPosition(); 171 btVector3 rel_pos2 = pivotBInW - m_rbB.getCenterOfMassPosition(); 172 //this jacobian entry could be re-used for all iterations 173 174 btVector3 vel1,vel2; 175 bodyA.getVelocityInLocalPointObsolete(rel_pos1,vel1); 176 bodyB.getVelocityInLocalPointObsolete(rel_pos2,vel2); 177 btVector3 vel = vel1 - vel2; 178 179 btScalar rel_vel; 180 rel_vel = normal.dot(vel); 181 182 /* 183 //velocity error (first order error) 184 btScalar rel_vel = m_jac[i].getRelativeVelocity(m_rbA.getLinearVelocity(),angvelA, 185 m_rbB.getLinearVelocity(),angvelB); 186 */ 187 188 //positional error (zeroth order error) 189 btScalar depth = -(pivotAInW - pivotBInW).dot(normal); //this is the error projected on the normal 190 191 btScalar deltaImpulse = depth*m_setting.m_tau/timeStep * jacDiagABInv - m_setting.m_damping * rel_vel * jacDiagABInv; 192 193 btScalar impulseClamp = m_setting.m_impulseClamp; 194 195 const btScalar sum = btScalar(m_appliedImpulse) + deltaImpulse; 196 if (sum < -impulseClamp) 197 { 198 deltaImpulse = -impulseClamp-m_appliedImpulse; 199 m_appliedImpulse = -impulseClamp; 200 } 201 else if (sum > impulseClamp) 202 { 203 deltaImpulse = impulseClamp-m_appliedImpulse; 204 m_appliedImpulse = impulseClamp; 205 } 206 else 207 { 208 m_appliedImpulse = sum; 209 } 210 211 212 btVector3 impulse_vector = normal * deltaImpulse; 213 214 btVector3 ftorqueAxis1 = rel_pos1.cross(normal); 215 btVector3 ftorqueAxis2 = rel_pos2.cross(normal); 216 bodyA.applyImpulse(normal*m_rbA.getInvMass(), m_rbA.getInvInertiaTensorWorld()*ftorqueAxis1,deltaImpulse); 217 bodyB.applyImpulse(normal*m_rbB.getInvMass(), m_rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-deltaImpulse); 218 219 220 normal[i] = 0; 221 } 222 } 223 } 162 info->m_damping = m_setting.m_damping; 163 164 } 165 166 224 167 225 168 void btPoint2PointConstraint::updateRHS(btScalar timeStep) … … 229 172 } 230 173 174 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 175 ///If no axis is provided, it uses the default axis for this constraint. 176 void btPoint2PointConstraint::setParam(int num, btScalar value, int axis) 177 { 178 if(axis != -1) 179 { 180 btAssertConstrParams(0); 181 } 182 else 183 { 184 switch(num) 185 { 186 case BT_CONSTRAINT_ERP : 187 case BT_CONSTRAINT_STOP_ERP : 188 m_erp = value; 189 m_flags |= BT_P2P_FLAGS_ERP; 190 break; 191 case BT_CONSTRAINT_CFM : 192 case BT_CONSTRAINT_STOP_CFM : 193 m_cfm = value; 194 m_flags |= BT_P2P_FLAGS_CFM; 195 break; 196 default: 197 btAssertConstrParams(0); 198 } 199 } 200 } 201 202 ///return the local value of parameter 203 btScalar btPoint2PointConstraint::getParam(int num, int axis) const 204 { 205 btScalar retVal(SIMD_INFINITY); 206 if(axis != -1) 207 { 208 btAssertConstrParams(0); 209 } 210 else 211 { 212 switch(num) 213 { 214 case BT_CONSTRAINT_ERP : 215 case BT_CONSTRAINT_STOP_ERP : 216 btAssertConstrParams(m_flags & BT_P2P_FLAGS_ERP); 217 retVal = m_erp; 218 break; 219 case BT_CONSTRAINT_CFM : 220 case BT_CONSTRAINT_STOP_CFM : 221 btAssertConstrParams(m_flags & BT_P2P_FLAGS_CFM); 222 retVal = m_cfm; 223 break; 224 default: 225 btAssertConstrParams(0); 226 } 227 } 228 return retVal; 229 } 230 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h
r5781 r8351 23 23 class btRigidBody; 24 24 25 26 #ifdef BT_USE_DOUBLE_PRECISION 27 #define btPoint2PointConstraintData btPoint2PointConstraintDoubleData 28 #define btPoint2PointConstraintDataName "btPoint2PointConstraintDoubleData" 29 #else 30 #define btPoint2PointConstraintData btPoint2PointConstraintFloatData 31 #define btPoint2PointConstraintDataName "btPoint2PointConstraintFloatData" 32 #endif //BT_USE_DOUBLE_PRECISION 33 25 34 struct btConstraintSetting 26 35 { … … 36 45 }; 37 46 47 enum btPoint2PointFlags 48 { 49 BT_P2P_FLAGS_ERP = 1, 50 BT_P2P_FLAGS_CFM = 2 51 }; 52 38 53 /// point to point constraint between two rigidbodies each with a pivotpoint that descibes the 'ballsocket' location in local space 39 classbtPoint2PointConstraint : public btTypedConstraint54 ATTRIBUTE_ALIGNED16(class) btPoint2PointConstraint : public btTypedConstraint 40 55 { 41 56 #ifdef IN_PARALLELL_SOLVER … … 47 62 btVector3 m_pivotInB; 48 63 49 64 int m_flags; 65 btScalar m_erp; 66 btScalar m_cfm; 50 67 51 68 public: … … 60 77 btPoint2PointConstraint(btRigidBody& rbA,const btVector3& pivotInA); 61 78 62 btPoint2PointConstraint();63 79 64 80 virtual void buildJacobian(); … … 66 82 virtual void getInfo1 (btConstraintInfo1* info); 67 83 84 void getInfo1NonVirtual (btConstraintInfo1* info); 85 68 86 virtual void getInfo2 (btConstraintInfo2* info); 69 87 70 71 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep); 88 void getInfo2NonVirtual (btConstraintInfo2* info, const btTransform& body0_trans, const btTransform& body1_trans); 72 89 73 90 void updateRHS(btScalar timeStep); … … 93 110 } 94 111 112 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 113 ///If no axis is provided, it uses the default axis for this constraint. 114 virtual void setParam(int num, btScalar value, int axis = -1); 115 ///return the local value of parameter 116 virtual btScalar getParam(int num, int axis = -1) const; 117 118 virtual int calculateSerializeBufferSize() const; 119 120 ///fills the dataBuffer and returns the struct name (and 0 on failure) 121 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 122 95 123 96 124 }; 97 125 126 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 127 struct btPoint2PointConstraintFloatData 128 { 129 btTypedConstraintData m_typeConstraintData; 130 btVector3FloatData m_pivotInA; 131 btVector3FloatData m_pivotInB; 132 }; 133 134 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 135 struct btPoint2PointConstraintDoubleData 136 { 137 btTypedConstraintData m_typeConstraintData; 138 btVector3DoubleData m_pivotInA; 139 btVector3DoubleData m_pivotInB; 140 }; 141 142 143 SIMD_FORCE_INLINE int btPoint2PointConstraint::calculateSerializeBufferSize() const 144 { 145 return sizeof(btPoint2PointConstraintData); 146 147 } 148 149 ///fills the dataBuffer and returns the struct name (and 0 on failure) 150 SIMD_FORCE_INLINE const char* btPoint2PointConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 151 { 152 btPoint2PointConstraintData* p2pData = (btPoint2PointConstraintData*)dataBuffer; 153 154 btTypedConstraint::serialize(&p2pData->m_typeConstraintData,serializer); 155 m_pivotInA.serialize(p2pData->m_pivotInA); 156 m_pivotInB.serialize(p2pData->m_pivotInB); 157 158 return btPoint2PointConstraintDataName; 159 } 160 98 161 #endif //POINT2POINTCONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.cpp
r5781 r8351 35 35 #include <string.h> //for memset 36 36 37 int gNumSplitImpulseRecoveries = 0; 38 37 39 btSequentialImpulseConstraintSolver::btSequentialImpulseConstraintSolver() 38 40 :m_btSeed2(0) … … 56 58 57 59 // Project Gauss Seidel or the equivalent Sequential Impulse 58 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGenericSIMD(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)60 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGenericSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& c) 59 61 { 60 62 #ifdef USE_SIMD … … 63 65 __m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit); 64 66 __m128 deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse),_mm_set1_ps(c.m_cfm))); 65 __m128 deltaVel1Dotn = _mm_add_ps(_vmathVfDot3(c.m_contactNormal.mVec128,body1. m_deltaLinearVelocity.mVec128), _vmathVfDot3(c.m_relpos1CrossNormal.mVec128,body1.m_deltaAngularVelocity.mVec128));66 __m128 deltaVel2Dotn = _mm_sub_ps(_vmathVfDot3(c.m_relpos2CrossNormal.mVec128,body2. m_deltaAngularVelocity.mVec128),_vmathVfDot3((c.m_contactNormal).mVec128,body2.m_deltaLinearVelocity.mVec128));67 __m128 deltaVel1Dotn = _mm_add_ps(_vmathVfDot3(c.m_contactNormal.mVec128,body1.internalGetDeltaLinearVelocity().mVec128), _vmathVfDot3(c.m_relpos1CrossNormal.mVec128,body1.internalGetDeltaAngularVelocity().mVec128)); 68 __m128 deltaVel2Dotn = _mm_sub_ps(_vmathVfDot3(c.m_relpos2CrossNormal.mVec128,body2.internalGetDeltaAngularVelocity().mVec128),_vmathVfDot3((c.m_contactNormal).mVec128,body2.internalGetDeltaLinearVelocity().mVec128)); 67 69 deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel1Dotn,_mm_set1_ps(c.m_jacDiagABInv))); 68 70 deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel2Dotn,_mm_set1_ps(c.m_jacDiagABInv))); … … 77 79 deltaImpulse = _mm_or_ps( _mm_and_ps(resultUpperLess, deltaImpulse), _mm_andnot_ps(resultUpperLess, upperMinApplied) ); 78 80 c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultUpperLess, c.m_appliedImpulse), _mm_andnot_ps(resultUpperLess, upperLimit1) ); 79 __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal.mVec128, _mm_set1_ps(body1.m_invMass));80 __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal).mVec128, _mm_set1_ps(body2.m_invMass));81 __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal.mVec128,body1.internalGetInvMass().mVec128); 82 __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal).mVec128,body2.internalGetInvMass().mVec128); 81 83 __m128 impulseMagnitude = deltaImpulse; 82 body1. m_deltaLinearVelocity.mVec128 = _mm_add_ps(body1.m_deltaLinearVelocity.mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude));83 body1. m_deltaAngularVelocity.mVec128 = _mm_add_ps(body1.m_deltaAngularVelocity.mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude));84 body2. m_deltaLinearVelocity.mVec128 = _mm_sub_ps(body2.m_deltaLinearVelocity.mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude));85 body2. m_deltaAngularVelocity.mVec128 = _mm_add_ps(body2.m_deltaAngularVelocity.mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude));84 body1.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude)); 85 body1.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude)); 86 body2.internalGetDeltaLinearVelocity().mVec128 = _mm_sub_ps(body2.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude)); 87 body2.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude)); 86 88 #else 87 89 resolveSingleConstraintRowGeneric(body1,body2,c); … … 90 92 91 93 // Project Gauss Seidel or the equivalent Sequential Impulse 92 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGeneric(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)94 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGeneric(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& c) 93 95 { 94 96 btScalar deltaImpulse = c.m_rhs-btScalar(c.m_appliedImpulse)*c.m_cfm; 95 const btScalar deltaVel1Dotn = c.m_contactNormal.dot(body1. m_deltaLinearVelocity) + c.m_relpos1CrossNormal.dot(body1.m_deltaAngularVelocity);96 const btScalar deltaVel2Dotn = -c.m_contactNormal.dot(body2. m_deltaLinearVelocity) + c.m_relpos2CrossNormal.dot(body2.m_deltaAngularVelocity);97 98 const btScalar delta_rel_vel = deltaVel1Dotn-deltaVel2Dotn;97 const btScalar deltaVel1Dotn = c.m_contactNormal.dot(body1.internalGetDeltaLinearVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetDeltaAngularVelocity()); 98 const btScalar deltaVel2Dotn = -c.m_contactNormal.dot(body2.internalGetDeltaLinearVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetDeltaAngularVelocity()); 99 100 // const btScalar delta_rel_vel = deltaVel1Dotn-deltaVel2Dotn; 99 101 deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv; 100 102 deltaImpulse -= deltaVel2Dotn*c.m_jacDiagABInv; … … 115 117 c.m_appliedImpulse = sum; 116 118 } 117 if (body1.m_invMass) 118 body1.applyImpulse(c.m_contactNormal*body1.m_invMass,c.m_angularComponentA,deltaImpulse); 119 if (body2.m_invMass) 120 body2.applyImpulse(-c.m_contactNormal*body2.m_invMass,c.m_angularComponentB,deltaImpulse); 121 } 122 123 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimitSIMD(btSolverBody& body1,btSolverBody& body2,const btSolverConstraint& c) 119 body1.internalApplyImpulse(c.m_contactNormal*body1.internalGetInvMass(),c.m_angularComponentA,deltaImpulse); 120 body2.internalApplyImpulse(-c.m_contactNormal*body2.internalGetInvMass(),c.m_angularComponentB,deltaImpulse); 121 } 122 123 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimitSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& c) 124 124 { 125 125 #ifdef USE_SIMD … … 128 128 __m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit); 129 129 __m128 deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse),_mm_set1_ps(c.m_cfm))); 130 __m128 deltaVel1Dotn = _mm_add_ps(_vmathVfDot3(c.m_contactNormal.mVec128,body1. m_deltaLinearVelocity.mVec128), _vmathVfDot3(c.m_relpos1CrossNormal.mVec128,body1.m_deltaAngularVelocity.mVec128));131 __m128 deltaVel2Dotn = _mm_sub_ps(_vmathVfDot3(c.m_relpos2CrossNormal.mVec128,body2. m_deltaAngularVelocity.mVec128),_vmathVfDot3((c.m_contactNormal).mVec128,body2.m_deltaLinearVelocity.mVec128));130 __m128 deltaVel1Dotn = _mm_add_ps(_vmathVfDot3(c.m_contactNormal.mVec128,body1.internalGetDeltaLinearVelocity().mVec128), _vmathVfDot3(c.m_relpos1CrossNormal.mVec128,body1.internalGetDeltaAngularVelocity().mVec128)); 131 __m128 deltaVel2Dotn = _mm_sub_ps(_vmathVfDot3(c.m_relpos2CrossNormal.mVec128,body2.internalGetDeltaAngularVelocity().mVec128),_vmathVfDot3((c.m_contactNormal).mVec128,body2.internalGetDeltaLinearVelocity().mVec128)); 132 132 deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel1Dotn,_mm_set1_ps(c.m_jacDiagABInv))); 133 133 deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel2Dotn,_mm_set1_ps(c.m_jacDiagABInv))); … … 139 139 deltaImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse) ); 140 140 c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum) ); 141 __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal.mVec128, _mm_set1_ps(body1.m_invMass));142 __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal).mVec128, _mm_set1_ps(body2.m_invMass));141 __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal.mVec128,body1.internalGetInvMass().mVec128); 142 __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal).mVec128,body2.internalGetInvMass().mVec128); 143 143 __m128 impulseMagnitude = deltaImpulse; 144 body1. m_deltaLinearVelocity.mVec128 = _mm_add_ps(body1.m_deltaLinearVelocity.mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude));145 body1. m_deltaAngularVelocity.mVec128 = _mm_add_ps(body1.m_deltaAngularVelocity.mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude));146 body2. m_deltaLinearVelocity.mVec128 = _mm_sub_ps(body2.m_deltaLinearVelocity.mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude));147 body2. m_deltaAngularVelocity.mVec128 = _mm_add_ps(body2.m_deltaAngularVelocity.mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude));144 body1.internalGetDeltaLinearVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude)); 145 body1.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body1.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude)); 146 body2.internalGetDeltaLinearVelocity().mVec128 = _mm_sub_ps(body2.internalGetDeltaLinearVelocity().mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude)); 147 body2.internalGetDeltaAngularVelocity().mVec128 = _mm_add_ps(body2.internalGetDeltaAngularVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude)); 148 148 #else 149 149 resolveSingleConstraintRowLowerLimit(body1,body2,c); … … 152 152 153 153 // Project Gauss Seidel or the equivalent Sequential Impulse 154 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimit(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& c)154 void btSequentialImpulseConstraintSolver::resolveSingleConstraintRowLowerLimit(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& c) 155 155 { 156 156 btScalar deltaImpulse = c.m_rhs-btScalar(c.m_appliedImpulse)*c.m_cfm; 157 const btScalar deltaVel1Dotn = c.m_contactNormal.dot(body1. m_deltaLinearVelocity) + c.m_relpos1CrossNormal.dot(body1.m_deltaAngularVelocity);158 const btScalar deltaVel2Dotn = -c.m_contactNormal.dot(body2. m_deltaLinearVelocity) + c.m_relpos2CrossNormal.dot(body2.m_deltaAngularVelocity);157 const btScalar deltaVel1Dotn = c.m_contactNormal.dot(body1.internalGetDeltaLinearVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetDeltaAngularVelocity()); 158 const btScalar deltaVel2Dotn = -c.m_contactNormal.dot(body2.internalGetDeltaLinearVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetDeltaAngularVelocity()); 159 159 160 160 deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv; … … 170 170 c.m_appliedImpulse = sum; 171 171 } 172 if (body1.m_invMass) 173 body1.applyImpulse(c.m_contactNormal*body1.m_invMass,c.m_angularComponentA,deltaImpulse); 174 if (body2.m_invMass) 175 body2.applyImpulse(-c.m_contactNormal*body2.m_invMass,c.m_angularComponentB,deltaImpulse); 172 body1.internalApplyImpulse(c.m_contactNormal*body1.internalGetInvMass(),c.m_angularComponentA,deltaImpulse); 173 body2.internalApplyImpulse(-c.m_contactNormal*body2.internalGetInvMass(),c.m_angularComponentB,deltaImpulse); 174 } 175 176 177 void btSequentialImpulseConstraintSolver::resolveSplitPenetrationImpulseCacheFriendly( 178 btRigidBody& body1, 179 btRigidBody& body2, 180 const btSolverConstraint& c) 181 { 182 if (c.m_rhsPenetration) 183 { 184 gNumSplitImpulseRecoveries++; 185 btScalar deltaImpulse = c.m_rhsPenetration-btScalar(c.m_appliedPushImpulse)*c.m_cfm; 186 const btScalar deltaVel1Dotn = c.m_contactNormal.dot(body1.internalGetPushVelocity()) + c.m_relpos1CrossNormal.dot(body1.internalGetTurnVelocity()); 187 const btScalar deltaVel2Dotn = -c.m_contactNormal.dot(body2.internalGetPushVelocity()) + c.m_relpos2CrossNormal.dot(body2.internalGetTurnVelocity()); 188 189 deltaImpulse -= deltaVel1Dotn*c.m_jacDiagABInv; 190 deltaImpulse -= deltaVel2Dotn*c.m_jacDiagABInv; 191 const btScalar sum = btScalar(c.m_appliedPushImpulse) + deltaImpulse; 192 if (sum < c.m_lowerLimit) 193 { 194 deltaImpulse = c.m_lowerLimit-c.m_appliedPushImpulse; 195 c.m_appliedPushImpulse = c.m_lowerLimit; 196 } 197 else 198 { 199 c.m_appliedPushImpulse = sum; 200 } 201 body1.internalApplyPushImpulse(c.m_contactNormal*body1.internalGetInvMass(),c.m_angularComponentA,deltaImpulse); 202 body2.internalApplyPushImpulse(-c.m_contactNormal*body2.internalGetInvMass(),c.m_angularComponentB,deltaImpulse); 203 } 204 } 205 206 void btSequentialImpulseConstraintSolver::resolveSplitPenetrationSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& c) 207 { 208 #ifdef USE_SIMD 209 if (!c.m_rhsPenetration) 210 return; 211 212 gNumSplitImpulseRecoveries++; 213 214 __m128 cpAppliedImp = _mm_set1_ps(c.m_appliedPushImpulse); 215 __m128 lowerLimit1 = _mm_set1_ps(c.m_lowerLimit); 216 __m128 upperLimit1 = _mm_set1_ps(c.m_upperLimit); 217 __m128 deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhsPenetration), _mm_mul_ps(_mm_set1_ps(c.m_appliedPushImpulse),_mm_set1_ps(c.m_cfm))); 218 __m128 deltaVel1Dotn = _mm_add_ps(_vmathVfDot3(c.m_contactNormal.mVec128,body1.internalGetPushVelocity().mVec128), _vmathVfDot3(c.m_relpos1CrossNormal.mVec128,body1.internalGetTurnVelocity().mVec128)); 219 __m128 deltaVel2Dotn = _mm_sub_ps(_vmathVfDot3(c.m_relpos2CrossNormal.mVec128,body2.internalGetTurnVelocity().mVec128),_vmathVfDot3((c.m_contactNormal).mVec128,body2.internalGetPushVelocity().mVec128)); 220 deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel1Dotn,_mm_set1_ps(c.m_jacDiagABInv))); 221 deltaImpulse = _mm_sub_ps(deltaImpulse,_mm_mul_ps(deltaVel2Dotn,_mm_set1_ps(c.m_jacDiagABInv))); 222 btSimdScalar sum = _mm_add_ps(cpAppliedImp,deltaImpulse); 223 btSimdScalar resultLowerLess,resultUpperLess; 224 resultLowerLess = _mm_cmplt_ps(sum,lowerLimit1); 225 resultUpperLess = _mm_cmplt_ps(sum,upperLimit1); 226 __m128 lowMinApplied = _mm_sub_ps(lowerLimit1,cpAppliedImp); 227 deltaImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowMinApplied), _mm_andnot_ps(resultLowerLess, deltaImpulse) ); 228 c.m_appliedImpulse = _mm_or_ps( _mm_and_ps(resultLowerLess, lowerLimit1), _mm_andnot_ps(resultLowerLess, sum) ); 229 __m128 linearComponentA = _mm_mul_ps(c.m_contactNormal.mVec128,body1.internalGetInvMass().mVec128); 230 __m128 linearComponentB = _mm_mul_ps((c.m_contactNormal).mVec128,body2.internalGetInvMass().mVec128); 231 __m128 impulseMagnitude = deltaImpulse; 232 body1.internalGetPushVelocity().mVec128 = _mm_add_ps(body1.internalGetPushVelocity().mVec128,_mm_mul_ps(linearComponentA,impulseMagnitude)); 233 body1.internalGetTurnVelocity().mVec128 = _mm_add_ps(body1.internalGetTurnVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentA.mVec128,impulseMagnitude)); 234 body2.internalGetPushVelocity().mVec128 = _mm_sub_ps(body2.internalGetPushVelocity().mVec128,_mm_mul_ps(linearComponentB,impulseMagnitude)); 235 body2.internalGetTurnVelocity().mVec128 = _mm_add_ps(body2.internalGetTurnVelocity().mVec128 ,_mm_mul_ps(c.m_angularComponentB.mVec128,impulseMagnitude)); 236 #else 237 resolveSplitPenetrationImpulseCacheFriendly(body1,body2,c); 238 #endif 176 239 } 177 240 … … 215 278 216 279 217 280 #if 0 218 281 void btSequentialImpulseConstraintSolver::initSolverBody(btSolverBody* solverBody, btCollisionObject* collisionObject) 219 282 { 220 283 btRigidBody* rb = collisionObject? btRigidBody::upcast(collisionObject) : 0; 221 284 222 solverBody->m_deltaLinearVelocity.setValue(0.f,0.f,0.f); 223 solverBody->m_deltaAngularVelocity.setValue(0.f,0.f,0.f); 285 solverBody->internalGetDeltaLinearVelocity().setValue(0.f,0.f,0.f); 286 solverBody->internalGetDeltaAngularVelocity().setValue(0.f,0.f,0.f); 287 solverBody->internalGetPushVelocity().setValue(0.f,0.f,0.f); 288 solverBody->internalGetTurnVelocity().setValue(0.f,0.f,0.f); 224 289 225 290 if (rb) 226 291 { 227 solverBody-> m_invMass = rb->getInvMass();292 solverBody->internalGetInvMass() = btVector3(rb->getInvMass(),rb->getInvMass(),rb->getInvMass())*rb->getLinearFactor(); 228 293 solverBody->m_originalBody = rb; 229 294 solverBody->m_angularFactor = rb->getAngularFactor(); 230 295 } else 231 296 { 232 solverBody-> m_invMass = 0.f;297 solverBody->internalGetInvMass().setValue(0,0,0); 233 298 solverBody->m_originalBody = 0; 234 solverBody->m_angularFactor = 1.f; 235 } 236 } 237 238 239 int gNumSplitImpulseRecoveries = 0; 299 solverBody->m_angularFactor.setValue(1,1,1); 300 } 301 } 302 #endif 303 304 305 306 240 307 241 308 btScalar btSequentialImpulseConstraintSolver::restitutionCurve(btScalar rel_vel, btScalar restitution) … … 263 330 264 331 265 266 btSolverConstraint& btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation) 332 void btSequentialImpulseConstraintSolver::setupFrictionConstraint(btSolverConstraint& solverConstraint, const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyB,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity, btScalar cfmSlip) 267 333 { 268 334 … … 271 337 btRigidBody* body1=btRigidBody::upcast(colObj1); 272 338 273 btSolverConstraint& solverConstraint = m_tmpSolverContactFrictionConstraintPool.expand();274 memset(&solverConstraint,0xff,sizeof(btSolverConstraint));275 339 solverConstraint.m_contactNormal = normalAxis; 276 340 277 solverConstraint.m_solverBodyIdA = solverBodyIdA; 278 solverConstraint.m_solverBodyIdB = solverBodyIdB; 279 solverConstraint.m_frictionIndex = frictionIndex; 341 solverConstraint.m_solverBodyA = body0 ? body0 : &getFixedBody(); 342 solverConstraint.m_solverBodyB = body1 ? body1 : &getFixedBody(); 280 343 281 344 solverConstraint.m_friction = cp.m_combinedFriction; … … 283 346 284 347 solverConstraint.m_appliedImpulse = 0.f; 285 //solverConstraint.m_appliedPushImpulse = 0.f;348 solverConstraint.m_appliedPushImpulse = 0.f; 286 349 287 350 { … … 338 401 rel_vel = vel1Dotn+vel2Dotn; 339 402 340 btScalar positionalError = 0.f;341 342 btSimdScalar velocityError = - rel_vel;403 // btScalar positionalError = 0.f; 404 405 btSimdScalar velocityError = desiredVelocity - rel_vel; 343 406 btSimdScalar velocityImpulse = velocityError * btSimdScalar(solverConstraint.m_jacDiagABInv); 344 407 solverConstraint.m_rhs = velocityImpulse; 345 solverConstraint.m_cfm = 0.f;408 solverConstraint.m_cfm = cfmSlip; 346 409 solverConstraint.m_lowerLimit = 0; 347 410 solverConstraint.m_upperLimit = 1e10f; 348 411 } 349 412 } 413 414 415 416 btSolverConstraint& btSequentialImpulseConstraintSolver::addFrictionConstraint(const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity, btScalar cfmSlip) 417 { 418 btSolverConstraint& solverConstraint = m_tmpSolverContactFrictionConstraintPool.expandNonInitializing(); 419 solverConstraint.m_frictionIndex = frictionIndex; 420 setupFrictionConstraint(solverConstraint, normalAxis, solverBodyA, solverBodyB, cp, rel_pos1, rel_pos2, 421 colObj0, colObj1, relaxation, desiredVelocity, cfmSlip); 350 422 return solverConstraint; 351 423 } … … 353 425 int btSequentialImpulseConstraintSolver::getOrInitSolverBody(btCollisionObject& body) 354 426 { 427 #if 0 355 428 int solverBodyIdA = -1; 356 429 … … 374 447 } 375 448 return solverBodyIdA; 449 #endif 450 return 0; 376 451 } 377 452 #include <stdio.h> 378 453 379 454 380 381 void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal) 382 { 383 btCollisionObject* colObj0=0,*colObj1=0; 384 385 colObj0 = (btCollisionObject*)manifold->getBody0(); 386 colObj1 = (btCollisionObject*)manifold->getBody1(); 387 388 int solverBodyIdA=-1; 389 int solverBodyIdB=-1; 390 391 if (manifold->getNumContacts()) 392 { 393 solverBodyIdA = getOrInitSolverBody(*colObj0); 394 solverBodyIdB = getOrInitSolverBody(*colObj1); 395 } 396 397 ///avoid collision response between two static objects 398 if (!solverBodyIdA && !solverBodyIdB) 399 return; 400 401 btVector3 rel_pos1; 402 btVector3 rel_pos2; 403 btScalar relaxation; 404 405 for (int j=0;j<manifold->getNumContacts();j++) 406 { 407 408 btManifoldPoint& cp = manifold->getContactPoint(j); 409 410 if (cp.getDistance() <= manifold->getContactProcessingThreshold()) 411 { 455 void btSequentialImpulseConstraintSolver::setupContactConstraint(btSolverConstraint& solverConstraint, 456 btCollisionObject* colObj0, btCollisionObject* colObj1, 457 btManifoldPoint& cp, const btContactSolverInfo& infoGlobal, 458 btVector3& vel, btScalar& rel_vel, btScalar& relaxation, 459 btVector3& rel_pos1, btVector3& rel_pos2) 460 { 461 btRigidBody* rb0 = btRigidBody::upcast(colObj0); 462 btRigidBody* rb1 = btRigidBody::upcast(colObj1); 412 463 413 464 const btVector3& pos1 = cp.getPositionWorldOnA(); 414 465 const btVector3& pos2 = cp.getPositionWorldOnB(); 415 466 467 // btVector3 rel_pos1 = pos1 - colObj0->getWorldTransform().getOrigin(); 468 // btVector3 rel_pos2 = pos2 - colObj1->getWorldTransform().getOrigin(); 416 469 rel_pos1 = pos1 - colObj0->getWorldTransform().getOrigin(); 417 470 rel_pos2 = pos2 - colObj1->getWorldTransform().getOrigin(); 418 471 419 420 472 relaxation = 1.f; 421 btScalar rel_vel; 422 btVector3 vel; 423 424 int frictionIndex = m_tmpSolverContactConstraintPool.size(); 425 426 { 427 btSolverConstraint& solverConstraint = m_tmpSolverContactConstraintPool.expand(); 428 btRigidBody* rb0 = btRigidBody::upcast(colObj0); 429 btRigidBody* rb1 = btRigidBody::upcast(colObj1); 430 431 solverConstraint.m_solverBodyIdA = solverBodyIdA; 432 solverConstraint.m_solverBodyIdB = solverBodyIdB; 433 434 solverConstraint.m_originalContactPoint = &cp; 435 436 btVector3 torqueAxis0 = rel_pos1.cross(cp.m_normalWorldOnB); 437 solverConstraint.m_angularComponentA = rb0 ? rb0->getInvInertiaTensorWorld()*torqueAxis0*rb0->getAngularFactor() : btVector3(0,0,0); 438 btVector3 torqueAxis1 = rel_pos2.cross(cp.m_normalWorldOnB); 439 solverConstraint.m_angularComponentB = rb1 ? rb1->getInvInertiaTensorWorld()*-torqueAxis1*rb1->getAngularFactor() : btVector3(0,0,0); 473 474 btVector3 torqueAxis0 = rel_pos1.cross(cp.m_normalWorldOnB); 475 solverConstraint.m_angularComponentA = rb0 ? rb0->getInvInertiaTensorWorld()*torqueAxis0*rb0->getAngularFactor() : btVector3(0,0,0); 476 btVector3 torqueAxis1 = rel_pos2.cross(cp.m_normalWorldOnB); 477 solverConstraint.m_angularComponentB = rb1 ? rb1->getInvInertiaTensorWorld()*-torqueAxis1*rb1->getAngularFactor() : btVector3(0,0,0); 478 440 479 { 441 480 #ifdef COMPUTE_IMPULSE_DENOM … … 467 506 468 507 469 btVector3 vel1 = rb0 ? rb0->getVelocityInLocalPoint(rel_pos1) : btVector3(0,0,0); 470 btVector3 vel2 = rb1 ? rb1->getVelocityInLocalPoint(rel_pos2) : btVector3(0,0,0); 471 472 vel = vel1 - vel2;473 474 508 509 510 btVector3 vel1 = rb0 ? rb0->getVelocityInLocalPoint(rel_pos1) : btVector3(0,0,0); 511 btVector3 vel2 = rb1 ? rb1->getVelocityInLocalPoint(rel_pos2) : btVector3(0,0,0); 512 vel = vel1 - vel2; 513 rel_vel = cp.m_normalWorldOnB.dot(vel); 475 514 476 515 btScalar penetration = cp.getDistance()+infoGlobal.m_linearSlop; … … 499 538 solverConstraint.m_appliedImpulse = cp.m_appliedImpulse * infoGlobal.m_warmstartingFactor; 500 539 if (rb0) 501 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].applyImpulse(solverConstraint.m_contactNormal*rb0->getInvMass(),solverConstraint.m_angularComponentA,solverConstraint.m_appliedImpulse);540 rb0->internalApplyImpulse(solverConstraint.m_contactNormal*rb0->getInvMass()*rb0->getLinearFactor(),solverConstraint.m_angularComponentA,solverConstraint.m_appliedImpulse); 502 541 if (rb1) 503 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].applyImpulse(solverConstraint.m_contactNormal*rb1->getInvMass(),-solverConstraint.m_angularComponentB,-solverConstraint.m_appliedImpulse);542 rb1->internalApplyImpulse(solverConstraint.m_contactNormal*rb1->getInvMass()*rb1->getLinearFactor(),-solverConstraint.m_angularComponentB,-(btScalar)solverConstraint.m_appliedImpulse); 504 543 } else 505 544 { … … 507 546 } 508 547 509 //solverConstraint.m_appliedPushImpulse = 0.f;548 solverConstraint.m_appliedPushImpulse = 0.f; 510 549 511 550 { … … 523 562 btScalar penetrationImpulse = positionalError*solverConstraint.m_jacDiagABInv; 524 563 btScalar velocityImpulse = velocityError *solverConstraint.m_jacDiagABInv; 525 solverConstraint.m_rhs = penetrationImpulse+velocityImpulse; 564 if (!infoGlobal.m_splitImpulse || (penetration > infoGlobal.m_splitImpulsePenetrationThreshold)) 565 { 566 //combine position and velocity into rhs 567 solverConstraint.m_rhs = penetrationImpulse+velocityImpulse; 568 solverConstraint.m_rhsPenetration = 0.f; 569 } else 570 { 571 //split position and velocity into rhs and m_rhsPenetration 572 solverConstraint.m_rhs = velocityImpulse; 573 solverConstraint.m_rhsPenetration = penetrationImpulse; 574 } 526 575 solverConstraint.m_cfm = 0.f; 527 576 solverConstraint.m_lowerLimit = 0; … … 530 579 531 580 532 /////setup the friction constraints 533 534 535 536 if (1) 537 { 538 solverConstraint.m_frictionIndex = m_tmpSolverContactFrictionConstraintPool.size(); 539 if (!(infoGlobal.m_solverMode & SOLVER_ENABLE_FRICTION_DIRECTION_CACHING) || !cp.m_lateralFrictionInitialized) 540 { 541 cp.m_lateralFrictionDir1 = vel - cp.m_normalWorldOnB * rel_vel; 542 btScalar lat_rel_vel = cp.m_lateralFrictionDir1.length2(); 543 if (!(infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION) && lat_rel_vel > SIMD_EPSILON) 544 { 545 cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel); 546 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1); 547 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1); 548 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 549 if((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) 550 { 551 cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB); 552 cp.m_lateralFrictionDir2.normalize();//?? 553 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2); 554 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2); 555 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 556 } 557 cp.m_lateralFrictionInitialized = true; 558 } else 559 { 560 //re-calculate friction direction every frame, todo: check if this is really needed 561 btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2); 562 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1); 563 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1); 564 565 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 566 if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) 567 { 568 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2); 569 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2); 570 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 571 } 572 cp.m_lateralFrictionInitialized = true; 573 } 574 575 } else 576 { 577 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 578 if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) 579 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyIdA,solverBodyIdB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 580 } 581 581 582 583 } 584 585 586 587 void btSequentialImpulseConstraintSolver::setFrictionConstraintImpulse( btSolverConstraint& solverConstraint, 588 btRigidBody* rb0, btRigidBody* rb1, 589 btManifoldPoint& cp, const btContactSolverInfo& infoGlobal) 590 { 582 591 if (infoGlobal.m_solverMode & SOLVER_USE_FRICTION_WARMSTARTING) 583 592 { … … 588 597 frictionConstraint1.m_appliedImpulse = cp.m_appliedImpulseLateral1 * infoGlobal.m_warmstartingFactor; 589 598 if (rb0) 590 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].applyImpulse(frictionConstraint1.m_contactNormal*rb0->getInvMass(),frictionConstraint1.m_angularComponentA,frictionConstraint1.m_appliedImpulse);599 rb0->internalApplyImpulse(frictionConstraint1.m_contactNormal*rb0->getInvMass()*rb0->getLinearFactor(),frictionConstraint1.m_angularComponentA,frictionConstraint1.m_appliedImpulse); 591 600 if (rb1) 592 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].applyImpulse(frictionConstraint1.m_contactNormal*rb1->getInvMass(),-frictionConstraint1.m_angularComponentB,-frictionConstraint1.m_appliedImpulse);601 rb1->internalApplyImpulse(frictionConstraint1.m_contactNormal*rb1->getInvMass()*rb1->getLinearFactor(),-frictionConstraint1.m_angularComponentB,-(btScalar)frictionConstraint1.m_appliedImpulse); 593 602 } else 594 603 { … … 604 613 frictionConstraint2.m_appliedImpulse = cp.m_appliedImpulseLateral2 * infoGlobal.m_warmstartingFactor; 605 614 if (rb0) 606 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].applyImpulse(frictionConstraint2.m_contactNormal*rb0->getInvMass(),frictionConstraint2.m_angularComponentA,frictionConstraint2.m_appliedImpulse);615 rb0->internalApplyImpulse(frictionConstraint2.m_contactNormal*rb0->getInvMass(),frictionConstraint2.m_angularComponentA,frictionConstraint2.m_appliedImpulse); 607 616 if (rb1) 608 m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].applyImpulse(frictionConstraint2.m_contactNormal*rb1->getInvMass(),-frictionConstraint2.m_angularComponentB,-frictionConstraint2.m_appliedImpulse);617 rb1->internalApplyImpulse(frictionConstraint2.m_contactNormal*rb1->getInvMass(),-frictionConstraint2.m_angularComponentB,-(btScalar)frictionConstraint2.m_appliedImpulse); 609 618 } else 610 619 { … … 622 631 } 623 632 } 633 } 634 635 636 637 638 void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal) 639 { 640 btCollisionObject* colObj0=0,*colObj1=0; 641 642 colObj0 = (btCollisionObject*)manifold->getBody0(); 643 colObj1 = (btCollisionObject*)manifold->getBody1(); 644 645 646 btRigidBody* solverBodyA = btRigidBody::upcast(colObj0); 647 btRigidBody* solverBodyB = btRigidBody::upcast(colObj1); 648 649 ///avoid collision response between two static objects 650 if ((!solverBodyA || !solverBodyA->getInvMass()) && (!solverBodyB || !solverBodyB->getInvMass())) 651 return; 652 653 for (int j=0;j<manifold->getNumContacts();j++) 654 { 655 656 btManifoldPoint& cp = manifold->getContactPoint(j); 657 658 if (cp.getDistance() <= manifold->getContactProcessingThreshold()) 659 { 660 btVector3 rel_pos1; 661 btVector3 rel_pos2; 662 btScalar relaxation; 663 btScalar rel_vel; 664 btVector3 vel; 665 666 int frictionIndex = m_tmpSolverContactConstraintPool.size(); 667 btSolverConstraint& solverConstraint = m_tmpSolverContactConstraintPool.expandNonInitializing(); 668 btRigidBody* rb0 = btRigidBody::upcast(colObj0); 669 btRigidBody* rb1 = btRigidBody::upcast(colObj1); 670 solverConstraint.m_solverBodyA = rb0? rb0 : &getFixedBody(); 671 solverConstraint.m_solverBodyB = rb1? rb1 : &getFixedBody(); 672 solverConstraint.m_originalContactPoint = &cp; 673 674 setupContactConstraint(solverConstraint, colObj0, colObj1, cp, infoGlobal, vel, rel_vel, relaxation, rel_pos1, rel_pos2); 675 676 // const btVector3& pos1 = cp.getPositionWorldOnA(); 677 // const btVector3& pos2 = cp.getPositionWorldOnB(); 678 679 /////setup the friction constraints 680 681 solverConstraint.m_frictionIndex = m_tmpSolverContactFrictionConstraintPool.size(); 682 683 if (!(infoGlobal.m_solverMode & SOLVER_ENABLE_FRICTION_DIRECTION_CACHING) || !cp.m_lateralFrictionInitialized) 684 { 685 cp.m_lateralFrictionDir1 = vel - cp.m_normalWorldOnB * rel_vel; 686 btScalar lat_rel_vel = cp.m_lateralFrictionDir1.length2(); 687 if (!(infoGlobal.m_solverMode & SOLVER_DISABLE_VELOCITY_DEPENDENT_FRICTION_DIRECTION) && lat_rel_vel > SIMD_EPSILON) 688 { 689 cp.m_lateralFrictionDir1 /= btSqrt(lat_rel_vel); 690 if((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) 691 { 692 cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB); 693 cp.m_lateralFrictionDir2.normalize();//?? 694 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2); 695 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2); 696 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 697 } 698 699 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1); 700 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1); 701 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 702 cp.m_lateralFrictionInitialized = true; 703 } else 704 { 705 //re-calculate friction direction every frame, todo: check if this is really needed 706 btPlaneSpace1(cp.m_normalWorldOnB,cp.m_lateralFrictionDir1,cp.m_lateralFrictionDir2); 707 if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) 708 { 709 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir2); 710 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir2); 711 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 712 } 713 714 applyAnisotropicFriction(colObj0,cp.m_lateralFrictionDir1); 715 applyAnisotropicFriction(colObj1,cp.m_lateralFrictionDir1); 716 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation); 717 718 cp.m_lateralFrictionInitialized = true; 624 719 } 625 } 626 627 628 } 629 } 630 } 631 632 633 btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCollisionObject** /*bodies */,int /*numBodies */,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc) 720 721 } else 722 { 723 addFrictionConstraint(cp.m_lateralFrictionDir1,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation,cp.m_contactMotion1, cp.m_contactCFM1); 724 if ((infoGlobal.m_solverMode & SOLVER_USE_2_FRICTION_DIRECTIONS)) 725 addFrictionConstraint(cp.m_lateralFrictionDir2,solverBodyA,solverBodyB,frictionIndex,cp,rel_pos1,rel_pos2,colObj0,colObj1, relaxation, cp.m_contactMotion2, cp.m_contactCFM2); 726 } 727 728 setFrictionConstraintImpulse( solverConstraint, rb0, rb1, cp, infoGlobal); 729 730 } 731 } 732 } 733 734 735 btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySetup(btCollisionObject** bodies, int numBodies, btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc) 634 736 { 635 737 BT_PROFILE("solveGroupCacheFriendlySetup"); … … 644 746 } 645 747 748 if (infoGlobal.m_splitImpulse) 749 { 750 for (int i = 0; i < numBodies; i++) 751 { 752 btRigidBody* body = btRigidBody::upcast(bodies[i]); 753 if (body) 754 { 755 body->internalGetDeltaLinearVelocity().setZero(); 756 body->internalGetDeltaAngularVelocity().setZero(); 757 body->internalGetPushVelocity().setZero(); 758 body->internalGetTurnVelocity().setZero(); 759 } 760 } 761 } 762 else 763 { 764 for (int i = 0; i < numBodies; i++) 765 { 766 btRigidBody* body = btRigidBody::upcast(bodies[i]); 767 if (body) 768 { 769 body->internalGetDeltaLinearVelocity().setZero(); 770 body->internalGetDeltaAngularVelocity().setZero(); 771 } 772 } 773 } 774 646 775 if (1) 647 776 { … … 653 782 } 654 783 } 655 656 btSolverBody& fixedBody = m_tmpSolverBodyPool.expand();657 initSolverBody(&fixedBody,0);658 659 784 //btRigidBody* rb0=0,*rb1=0; 660 785 … … 665 790 int totalNumRows = 0; 666 791 int i; 792 793 m_tmpConstraintSizesPool.resize(numConstraints); 667 794 //calculate the total number of contraint rows 668 795 for (i=0;i<numConstraints;i++) 669 796 { 670 671 btTypedConstraint::btConstraintInfo1 info1; 797 btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i]; 672 798 constraints[i]->getInfo1(&info1); 673 799 totalNumRows += info1.m_numConstraintRows; … … 675 801 m_tmpSolverNonContactConstraintPool.resize(totalNumRows); 676 802 677 btTypedConstraint::btConstraintInfo1 info1; 678 info1.m_numConstraintRows = 0; 679 680 803 681 804 ///setup the btSolverConstraints 682 805 int currentRow = 0; 683 806 684 for (i=0;i<numConstraints;i++ ,currentRow+=info1.m_numConstraintRows)807 for (i=0;i<numConstraints;i++) 685 808 { 686 constraints[i]->getInfo1(&info1); 809 const btTypedConstraint::btConstraintInfo1& info1 = m_tmpConstraintSizesPool[i]; 810 687 811 if (info1.m_numConstraintRows) 688 812 { … … 697 821 btRigidBody& rbB = constraint->getRigidBodyB(); 698 822 699 int solverBodyIdA = getOrInitSolverBody(rbA); 700 int solverBodyIdB = getOrInitSolverBody(rbB); 701 702 btSolverBody* bodyAPtr = &m_tmpSolverBodyPool[solverBodyIdA]; 703 btSolverBody* bodyBPtr = &m_tmpSolverBodyPool[solverBodyIdB]; 704 823 705 824 int j; 706 825 for ( j=0;j<info1.m_numConstraintRows;j++) … … 711 830 currentConstraintRow[j].m_appliedImpulse = 0.f; 712 831 currentConstraintRow[j].m_appliedPushImpulse = 0.f; 713 currentConstraintRow[j].m_solverBody IdA = solverBodyIdA;714 currentConstraintRow[j].m_solverBody IdB = solverBodyIdB;832 currentConstraintRow[j].m_solverBodyA = &rbA; 833 currentConstraintRow[j].m_solverBodyB = &rbB; 715 834 } 716 835 717 bodyAPtr->m_deltaLinearVelocity.setValue(0.f,0.f,0.f);718 bodyAPtr->m_deltaAngularVelocity.setValue(0.f,0.f,0.f);719 bodyBPtr->m_deltaLinearVelocity.setValue(0.f,0.f,0.f);720 bodyBPtr->m_deltaAngularVelocity.setValue(0.f,0.f,0.f);836 rbA.internalGetDeltaLinearVelocity().setValue(0.f,0.f,0.f); 837 rbA.internalGetDeltaAngularVelocity().setValue(0.f,0.f,0.f); 838 rbB.internalGetDeltaLinearVelocity().setValue(0.f,0.f,0.f); 839 rbB.internalGetDeltaAngularVelocity().setValue(0.f,0.f,0.f); 721 840 722 841 … … 733 852 btAssert(info2.rowskip*sizeof(btScalar)== sizeof(btSolverConstraint)); 734 853 info2.m_constraintError = ¤tConstraintRow->m_rhs; 854 currentConstraintRow->m_cfm = infoGlobal.m_globalCfm; 855 info2.m_damping = infoGlobal.m_damping; 735 856 info2.cfm = ¤tConstraintRow->m_cfm; 736 857 info2.m_lowerLimit = ¤tConstraintRow->m_lowerLimit; 737 858 info2.m_upperLimit = ¤tConstraintRow->m_upperLimit; 859 info2.m_numIterations = infoGlobal.m_numIterations; 738 860 constraints[i]->getInfo2(&info2); 739 861 … … 742 864 { 743 865 btSolverConstraint& solverConstraint = currentConstraintRow[j]; 866 solverConstraint.m_originalContactPoint = constraint; 744 867 745 868 { … … 778 901 btScalar restitution = 0.f; 779 902 btScalar positionalError = solverConstraint.m_rhs;//already filled in by getConstraintInfo2 780 btScalar velocityError = restitution - rel_vel ;// *damping;903 btScalar velocityError = restitution - rel_vel * info2.m_damping; 781 904 btScalar penetrationImpulse = positionalError*solverConstraint.m_jacDiagABInv; 782 905 btScalar velocityImpulse = velocityError *solverConstraint.m_jacDiagABInv; … … 787 910 } 788 911 } 912 currentRow+=m_tmpConstraintSizesPool[i].m_numConstraintRows; 789 913 } 790 914 } … … 793 917 int i; 794 918 btPersistentManifold* manifold = 0; 795 btCollisionObject* colObj0=0,*colObj1=0;919 // btCollisionObject* colObj0=0,*colObj1=0; 796 920 797 921 … … 830 954 } 831 955 832 btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(btCollisionObject** /*bodies */,int /*numBodies*/,btPersistentManifold** /*manifoldPtr*/, int /*numManifolds*/,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* /*debugDrawer*/,btStackAlloc* /*stackAlloc*/) 833 { 834 BT_PROFILE("solveGroupCacheFriendlyIterations"); 956 btScalar btSequentialImpulseConstraintSolver::solveSingleIteration(int iteration, btCollisionObject** /*bodies */,int /*numBodies*/,btPersistentManifold** /*manifoldPtr*/, int /*numManifolds*/,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* /*debugDrawer*/,btStackAlloc* /*stackAlloc*/) 957 { 835 958 836 959 int numConstraintPool = m_tmpSolverContactConstraintPool.size(); 837 960 int numFrictionPool = m_tmpSolverContactFrictionConstraintPool.size(); 838 961 962 int j; 963 964 if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER) 965 { 966 if ((iteration & 7) == 0) { 967 for (j=0; j<numConstraintPool; ++j) { 968 int tmp = m_orderTmpConstraintPool[j]; 969 int swapi = btRandInt2(j+1); 970 m_orderTmpConstraintPool[j] = m_orderTmpConstraintPool[swapi]; 971 m_orderTmpConstraintPool[swapi] = tmp; 972 } 973 974 for (j=0; j<numFrictionPool; ++j) { 975 int tmp = m_orderFrictionConstraintPool[j]; 976 int swapi = btRandInt2(j+1); 977 m_orderFrictionConstraintPool[j] = m_orderFrictionConstraintPool[swapi]; 978 m_orderFrictionConstraintPool[swapi] = tmp; 979 } 980 } 981 } 982 983 if (infoGlobal.m_solverMode & SOLVER_SIMD) 984 { 985 ///solve all joint constraints, using SIMD, if available 986 for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++) 987 { 988 btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; 989 resolveSingleConstraintRowGenericSIMD(*constraint.m_solverBodyA,*constraint.m_solverBodyB,constraint); 990 } 991 992 for (j=0;j<numConstraints;j++) 993 { 994 constraints[j]->solveConstraintObsolete(constraints[j]->getRigidBodyA(),constraints[j]->getRigidBodyB(),infoGlobal.m_timeStep); 995 } 996 997 ///solve all contact constraints using SIMD, if available 998 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 999 for (j=0;j<numPoolConstraints;j++) 1000 { 1001 const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; 1002 resolveSingleConstraintRowLowerLimitSIMD(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); 1003 1004 } 1005 ///solve all friction constraints, using SIMD, if available 1006 int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); 1007 for (j=0;j<numFrictionPoolConstraints;j++) 1008 { 1009 btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; 1010 btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; 1011 1012 if (totalImpulse>btScalar(0)) 1013 { 1014 solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); 1015 solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; 1016 1017 resolveSingleConstraintRowGenericSIMD(*solveManifold.m_solverBodyA, *solveManifold.m_solverBodyB,solveManifold); 1018 } 1019 } 1020 } else 1021 { 1022 1023 ///solve all joint constraints 1024 for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++) 1025 { 1026 btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; 1027 resolveSingleConstraintRowGeneric(*constraint.m_solverBodyA,*constraint.m_solverBodyB,constraint); 1028 } 1029 1030 for (j=0;j<numConstraints;j++) 1031 { 1032 constraints[j]->solveConstraintObsolete(constraints[j]->getRigidBodyA(),constraints[j]->getRigidBodyB(),infoGlobal.m_timeStep); 1033 } 1034 ///solve all contact constraints 1035 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 1036 for (j=0;j<numPoolConstraints;j++) 1037 { 1038 const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; 1039 resolveSingleConstraintRowLowerLimit(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); 1040 } 1041 ///solve all friction constraints 1042 int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); 1043 for (j=0;j<numFrictionPoolConstraints;j++) 1044 { 1045 btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; 1046 btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; 1047 1048 if (totalImpulse>btScalar(0)) 1049 { 1050 solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); 1051 solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; 1052 1053 resolveSingleConstraintRowGeneric(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); 1054 } 1055 } 1056 } 1057 return 0.f; 1058 } 1059 1060 1061 void btSequentialImpulseConstraintSolver::solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc) 1062 { 1063 int iteration; 1064 if (infoGlobal.m_splitImpulse) 1065 { 1066 if (infoGlobal.m_solverMode & SOLVER_SIMD) 1067 { 1068 for ( iteration = 0;iteration<infoGlobal.m_numIterations;iteration++) 1069 { 1070 { 1071 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 1072 int j; 1073 for (j=0;j<numPoolConstraints;j++) 1074 { 1075 const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; 1076 1077 resolveSplitPenetrationSIMD(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); 1078 } 1079 } 1080 } 1081 } 1082 else 1083 { 1084 for ( iteration = 0;iteration<infoGlobal.m_numIterations;iteration++) 1085 { 1086 { 1087 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 1088 int j; 1089 for (j=0;j<numPoolConstraints;j++) 1090 { 1091 const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; 1092 1093 resolveSplitPenetrationImpulseCacheFriendly(*solveManifold.m_solverBodyA,*solveManifold.m_solverBodyB,solveManifold); 1094 } 1095 } 1096 } 1097 } 1098 } 1099 } 1100 1101 btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyIterations(btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc) 1102 { 1103 BT_PROFILE("solveGroupCacheFriendlyIterations"); 1104 1105 839 1106 //should traverse the contacts random order... 840 1107 int iteration; … … 842 1109 for ( iteration = 0;iteration<infoGlobal.m_numIterations;iteration++) 843 1110 { 844 845 int j; 846 if (infoGlobal.m_solverMode & SOLVER_RANDMIZE_ORDER) 847 { 848 if ((iteration & 7) == 0) { 849 for (j=0; j<numConstraintPool; ++j) { 850 int tmp = m_orderTmpConstraintPool[j]; 851 int swapi = btRandInt2(j+1); 852 m_orderTmpConstraintPool[j] = m_orderTmpConstraintPool[swapi]; 853 m_orderTmpConstraintPool[swapi] = tmp; 854 } 855 856 for (j=0; j<numFrictionPool; ++j) { 857 int tmp = m_orderFrictionConstraintPool[j]; 858 int swapi = btRandInt2(j+1); 859 m_orderFrictionConstraintPool[j] = m_orderFrictionConstraintPool[swapi]; 860 m_orderFrictionConstraintPool[swapi] = tmp; 861 } 862 } 863 } 864 865 if (infoGlobal.m_solverMode & SOLVER_SIMD) 866 { 867 ///solve all joint constraints, using SIMD, if available 868 for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++) 869 { 870 btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; 871 resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[constraint.m_solverBodyIdA],m_tmpSolverBodyPool[constraint.m_solverBodyIdB],constraint); 872 } 873 874 for (j=0;j<numConstraints;j++) 875 { 876 int bodyAid = getOrInitSolverBody(constraints[j]->getRigidBodyA()); 877 int bodyBid = getOrInitSolverBody(constraints[j]->getRigidBodyB()); 878 btSolverBody& bodyA = m_tmpSolverBodyPool[bodyAid]; 879 btSolverBody& bodyB = m_tmpSolverBodyPool[bodyBid]; 880 constraints[j]->solveConstraintObsolete(bodyA,bodyB,infoGlobal.m_timeStep); 881 } 882 883 ///solve all contact constraints using SIMD, if available 884 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 885 for (j=0;j<numPoolConstraints;j++) 886 { 887 const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; 888 resolveSingleConstraintRowLowerLimitSIMD(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold); 889 890 } 891 ///solve all friction constraints, using SIMD, if available 892 int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); 893 for (j=0;j<numFrictionPoolConstraints;j++) 894 { 895 btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; 896 btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; 897 898 if (totalImpulse>btScalar(0)) 899 { 900 solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); 901 solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; 902 903 resolveSingleConstraintRowGenericSIMD(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA], m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold); 904 } 905 } 906 } else 907 { 908 909 ///solve all joint constraints 910 for (j=0;j<m_tmpSolverNonContactConstraintPool.size();j++) 911 { 912 btSolverConstraint& constraint = m_tmpSolverNonContactConstraintPool[j]; 913 resolveSingleConstraintRowGeneric(m_tmpSolverBodyPool[constraint.m_solverBodyIdA],m_tmpSolverBodyPool[constraint.m_solverBodyIdB],constraint); 914 } 915 916 for (j=0;j<numConstraints;j++) 917 { 918 int bodyAid = getOrInitSolverBody(constraints[j]->getRigidBodyA()); 919 int bodyBid = getOrInitSolverBody(constraints[j]->getRigidBodyB()); 920 btSolverBody& bodyA = m_tmpSolverBodyPool[bodyAid]; 921 btSolverBody& bodyB = m_tmpSolverBodyPool[bodyBid]; 922 923 constraints[j]->solveConstraintObsolete(bodyA,bodyB,infoGlobal.m_timeStep); 924 } 925 926 ///solve all contact constraints 927 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 928 for (j=0;j<numPoolConstraints;j++) 929 { 930 const btSolverConstraint& solveManifold = m_tmpSolverContactConstraintPool[m_orderTmpConstraintPool[j]]; 931 resolveSingleConstraintRowLowerLimit(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA],m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold); 932 } 933 ///solve all friction constraints 934 int numFrictionPoolConstraints = m_tmpSolverContactFrictionConstraintPool.size(); 935 for (j=0;j<numFrictionPoolConstraints;j++) 936 { 937 btSolverConstraint& solveManifold = m_tmpSolverContactFrictionConstraintPool[m_orderFrictionConstraintPool[j]]; 938 btScalar totalImpulse = m_tmpSolverContactConstraintPool[solveManifold.m_frictionIndex].m_appliedImpulse; 939 940 if (totalImpulse>btScalar(0)) 941 { 942 solveManifold.m_lowerLimit = -(solveManifold.m_friction*totalImpulse); 943 solveManifold.m_upperLimit = solveManifold.m_friction*totalImpulse; 944 945 resolveSingleConstraintRowGeneric(m_tmpSolverBodyPool[solveManifold.m_solverBodyIdA], m_tmpSolverBodyPool[solveManifold.m_solverBodyIdB],solveManifold); 946 } 947 } 948 } 949 950 951 952 } 1111 solveSingleIteration(iteration, bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer,stackAlloc); 1112 } 1113 1114 solveGroupCacheFriendlySplitImpulseIterations(bodies ,numBodies,manifoldPtr, numManifolds,constraints,numConstraints,infoGlobal,debugDrawer,stackAlloc); 953 1115 } 954 1116 return 0.f; 955 1117 } 956 1118 957 958 959 /// btSequentialImpulseConstraintSolver Sequentially applies impulses 960 btScalar btSequentialImpulseConstraintSolver::solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc,btDispatcher* /*dispatcher*/) 961 { 962 963 964 965 BT_PROFILE("solveGroup"); 966 //we only implement SOLVER_CACHE_FRIENDLY now 967 //you need to provide at least some bodies 968 btAssert(bodies); 969 btAssert(numBodies); 970 971 int i; 972 973 solveGroupCacheFriendlySetup( bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer, stackAlloc); 974 solveGroupCacheFriendlyIterations(bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer, stackAlloc); 975 1119 btScalar btSequentialImpulseConstraintSolver::solveGroupCacheFriendlyFinish(btCollisionObject** bodies ,int numBodies,btPersistentManifold** /*manifoldPtr*/, int /*numManifolds*/,btTypedConstraint** /*constraints*/,int /* numConstraints*/,const btContactSolverInfo& infoGlobal,btIDebugDraw* /*debugDrawer*/,btStackAlloc* /*stackAlloc*/) 1120 { 976 1121 int numPoolConstraints = m_tmpSolverContactConstraintPool.size(); 977 int j;1122 int i,j; 978 1123 979 1124 for (j=0;j<numPoolConstraints;j++) … … 993 1138 } 994 1139 1140 numPoolConstraints = m_tmpSolverNonContactConstraintPool.size(); 1141 for (j=0;j<numPoolConstraints;j++) 1142 { 1143 const btSolverConstraint& solverConstr = m_tmpSolverNonContactConstraintPool[j]; 1144 btTypedConstraint* constr = (btTypedConstraint*)solverConstr.m_originalContactPoint; 1145 btScalar sum = constr->internalGetAppliedImpulse(); 1146 sum += solverConstr.m_appliedImpulse; 1147 constr->internalSetAppliedImpulse(sum); 1148 } 1149 1150 995 1151 if (infoGlobal.m_splitImpulse) 996 1152 { 997 for ( i=0;i<m_tmpSolverBodyPool.size();i++) 998 { 999 m_tmpSolverBodyPool[i].writebackVelocity(infoGlobal.m_timeStep); 1153 for ( i=0;i<numBodies;i++) 1154 { 1155 btRigidBody* body = btRigidBody::upcast(bodies[i]); 1156 if (body) 1157 body->internalWritebackVelocity(infoGlobal.m_timeStep); 1000 1158 } 1001 1159 } else 1002 1160 { 1003 for ( i=0;i<m_tmpSolverBodyPool.size();i++) 1004 { 1005 m_tmpSolverBodyPool[i].writebackVelocity(); 1006 } 1007 } 1008 1009 1010 m_tmpSolverBodyPool.resize(0); 1161 for ( i=0;i<numBodies;i++) 1162 { 1163 btRigidBody* body = btRigidBody::upcast(bodies[i]); 1164 if (body) 1165 body->internalWritebackVelocity(); 1166 } 1167 } 1168 1169 1011 1170 m_tmpSolverContactConstraintPool.resize(0); 1012 1171 m_tmpSolverNonContactConstraintPool.resize(0); … … 1018 1177 1019 1178 1020 1021 1022 1023 1024 1179 /// btSequentialImpulseConstraintSolver Sequentially applies impulses 1180 btScalar btSequentialImpulseConstraintSolver::solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc,btDispatcher* /*dispatcher*/) 1181 { 1182 1183 BT_PROFILE("solveGroup"); 1184 //you need to provide at least some bodies 1185 btAssert(bodies); 1186 btAssert(numBodies); 1187 1188 solveGroupCacheFriendlySetup( bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer, stackAlloc); 1189 1190 solveGroupCacheFriendlyIterations(bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer, stackAlloc); 1191 1192 solveGroupCacheFriendlyFinish(bodies, numBodies, manifoldPtr, numManifolds,constraints, numConstraints,infoGlobal,debugDrawer, stackAlloc); 1193 1194 return 0.f; 1195 } 1025 1196 1026 1197 void btSequentialImpulseConstraintSolver::reset() … … 1029 1200 } 1030 1201 1031 1202 btRigidBody& btSequentialImpulseConstraintSolver::getFixedBody() 1203 { 1204 static btRigidBody s_fixed(0, 0,0); 1205 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); 1206 return s_fixed; 1207 } 1208 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h
r5781 r8351 22 22 #include "btSolverBody.h" 23 23 #include "btSolverConstraint.h" 24 25 24 #include "btTypedConstraint.h" 25 #include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h" 26 26 27 27 ///The btSequentialImpulseConstraintSolver is a fast SIMD implementation of the Projected Gauss Seidel (iterative LCP) method. … … 30 30 protected: 31 31 32 btAlignedObjectArray<btSolverBody> m_tmpSolverBodyPool;33 32 btConstraintArray m_tmpSolverContactConstraintPool; 34 33 btConstraintArray m_tmpSolverNonContactConstraintPool; … … 36 35 btAlignedObjectArray<int> m_orderTmpConstraintPool; 37 36 btAlignedObjectArray<int> m_orderFrictionConstraintPool; 37 btAlignedObjectArray<btTypedConstraint::btConstraintInfo1> m_tmpConstraintSizesPool; 38 38 39 btSolverConstraint& addFrictionConstraint(const btVector3& normalAxis,int solverBodyIdA,int solverBodyIdB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation); 39 void setupFrictionConstraint( btSolverConstraint& solverConstraint, const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyIdB, 40 btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2, 41 btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, 42 btScalar desiredVelocity=0., btScalar cfmSlip=0.); 43 44 btSolverConstraint& addFrictionConstraint(const btVector3& normalAxis,btRigidBody* solverBodyA,btRigidBody* solverBodyB,int frictionIndex,btManifoldPoint& cp,const btVector3& rel_pos1,const btVector3& rel_pos2,btCollisionObject* colObj0,btCollisionObject* colObj1, btScalar relaxation, btScalar desiredVelocity=0., btScalar cfmSlip=0.); 40 45 46 void setupContactConstraint(btSolverConstraint& solverConstraint, btCollisionObject* colObj0, btCollisionObject* colObj1, btManifoldPoint& cp, 47 const btContactSolverInfo& infoGlobal, btVector3& vel, btScalar& rel_vel, btScalar& relaxation, 48 btVector3& rel_pos1, btVector3& rel_pos2); 49 50 void setFrictionConstraintImpulse( btSolverConstraint& solverConstraint, btRigidBody* rb0, btRigidBody* rb1, 51 btManifoldPoint& cp, const btContactSolverInfo& infoGlobal); 52 41 53 ///m_btSeed2 is used for re-arranging the constraint rows. improves convergence/quality of friction 42 54 unsigned long m_btSeed2; 43 55 44 void initSolverBody(btSolverBody* solverBody, btCollisionObject* collisionObject);56 // void initSolverBody(btSolverBody* solverBody, btCollisionObject* collisionObject); 45 57 btScalar restitutionCurve(btScalar rel_vel, btScalar restitution); 46 58 47 59 void convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal); 48 60 61 62 void resolveSplitPenetrationSIMD( 63 btRigidBody& body1, 64 btRigidBody& body2, 65 const btSolverConstraint& contactConstraint); 66 49 67 void resolveSplitPenetrationImpulseCacheFriendly( 50 btSolverBody& body1, 51 btSolverBody& body2, 52 const btSolverConstraint& contactConstraint, 53 const btContactSolverInfo& solverInfo); 68 btRigidBody& body1, 69 btRigidBody& body2, 70 const btSolverConstraint& contactConstraint); 54 71 55 72 //internal method 56 73 int getOrInitSolverBody(btCollisionObject& body); 57 74 58 void resolveSingleConstraintRowGeneric(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint);75 void resolveSingleConstraintRowGeneric(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint); 59 76 60 void resolveSingleConstraintRowGenericSIMD(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint);77 void resolveSingleConstraintRowGenericSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint); 61 78 62 void resolveSingleConstraintRowLowerLimit(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint);79 void resolveSingleConstraintRowLowerLimit(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint); 63 80 64 void resolveSingleConstraintRowLowerLimitSIMD(bt SolverBody& body1,btSolverBody& body2,const btSolverConstraint& contactConstraint);81 void resolveSingleConstraintRowLowerLimitSIMD(btRigidBody& body1,btRigidBody& body2,const btSolverConstraint& contactConstraint); 65 82 83 protected: 84 static btRigidBody& getFixedBody(); 85 86 virtual void solveGroupCacheFriendlySplitImpulseIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); 87 virtual btScalar solveGroupCacheFriendlyFinish(btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); 88 btScalar solveSingleIteration(int iteration, btCollisionObject** bodies ,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); 89 90 virtual btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); 91 virtual btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc); 92 93 66 94 public: 67 95 … … 72 100 virtual btScalar solveGroup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifold,int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& info, btIDebugDraw* debugDrawer, btStackAlloc* stackAlloc,btDispatcher* dispatcher); 73 101 74 btScalar solveGroupCacheFriendlySetup(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);75 btScalar solveGroupCacheFriendlyIterations(btCollisionObject** bodies,int numBodies,btPersistentManifold** manifoldPtr, int numManifolds,btTypedConstraint** constraints,int numConstraints,const btContactSolverInfo& infoGlobal,btIDebugDraw* debugDrawer,btStackAlloc* stackAlloc);76 102 103 77 104 ///clear internal cached data and reset random seed 78 105 virtual void reset(); -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.cpp
r5781 r8351 19 19 */ 20 20 21 //----------------------------------------------------------------------------- 21 22 22 23 23 #include "btSliderConstraint.h" … … 26 26 #include <new> 27 27 28 //----------------------------------------------------------------------------- 28 #define USE_OFFSET_FOR_CONSTANT_FRAME true 29 29 30 30 void btSliderConstraint::initParams() … … 37 37 m_restitutionDirLin = SLIDER_CONSTRAINT_DEF_RESTITUTION; 38 38 m_dampingDirLin = btScalar(0.); 39 m_cfmDirLin = SLIDER_CONSTRAINT_DEF_CFM; 39 40 m_softnessDirAng = SLIDER_CONSTRAINT_DEF_SOFTNESS; 40 41 m_restitutionDirAng = SLIDER_CONSTRAINT_DEF_RESTITUTION; 41 42 m_dampingDirAng = btScalar(0.); 43 m_cfmDirAng = SLIDER_CONSTRAINT_DEF_CFM; 42 44 m_softnessOrthoLin = SLIDER_CONSTRAINT_DEF_SOFTNESS; 43 45 m_restitutionOrthoLin = SLIDER_CONSTRAINT_DEF_RESTITUTION; 44 46 m_dampingOrthoLin = SLIDER_CONSTRAINT_DEF_DAMPING; 47 m_cfmOrthoLin = SLIDER_CONSTRAINT_DEF_CFM; 45 48 m_softnessOrthoAng = SLIDER_CONSTRAINT_DEF_SOFTNESS; 46 49 m_restitutionOrthoAng = SLIDER_CONSTRAINT_DEF_RESTITUTION; 47 50 m_dampingOrthoAng = SLIDER_CONSTRAINT_DEF_DAMPING; 51 m_cfmOrthoAng = SLIDER_CONSTRAINT_DEF_CFM; 48 52 m_softnessLimLin = SLIDER_CONSTRAINT_DEF_SOFTNESS; 49 53 m_restitutionLimLin = SLIDER_CONSTRAINT_DEF_RESTITUTION; 50 54 m_dampingLimLin = SLIDER_CONSTRAINT_DEF_DAMPING; 55 m_cfmLimLin = SLIDER_CONSTRAINT_DEF_CFM; 51 56 m_softnessLimAng = SLIDER_CONSTRAINT_DEF_SOFTNESS; 52 57 m_restitutionLimAng = SLIDER_CONSTRAINT_DEF_RESTITUTION; 53 58 m_dampingLimAng = SLIDER_CONSTRAINT_DEF_DAMPING; 59 m_cfmLimAng = SLIDER_CONSTRAINT_DEF_CFM; 54 60 55 61 m_poweredLinMotor = false; … … 63 69 m_accumulatedAngMotorImpulse = btScalar(0.0); 64 70 65 } // btSliderConstraint::initParams() 66 67 //----------------------------------------------------------------------------- 68 69 btSliderConstraint::btSliderConstraint() 70 :btTypedConstraint(SLIDER_CONSTRAINT_TYPE), 71 m_useLinearReferenceFrameA(true), 72 m_useSolveConstraintObsolete(false) 73 // m_useSolveConstraintObsolete(true) 71 m_flags = 0; 72 m_flags = 0; 73 74 m_useOffsetForConstraintFrame = USE_OFFSET_FOR_CONSTANT_FRAME; 75 76 calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 77 } 78 79 80 81 82 83 btSliderConstraint::btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA) 84 : btTypedConstraint(SLIDER_CONSTRAINT_TYPE, rbA, rbB), 85 m_useSolveConstraintObsolete(false), 86 m_frameInA(frameInA), 87 m_frameInB(frameInB), 88 m_useLinearReferenceFrameA(useLinearReferenceFrameA) 74 89 { 75 90 initParams(); 76 } // btSliderConstraint::btSliderConstraint() 77 78 //----------------------------------------------------------------------------- 79 80 btSliderConstraint::btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB, bool useLinearReferenceFrameA) 81 : btTypedConstraint(SLIDER_CONSTRAINT_TYPE, rbA, rbB) 82 , m_frameInA(frameInA) 83 , m_frameInB(frameInB), 84 m_useLinearReferenceFrameA(useLinearReferenceFrameA), 85 m_useSolveConstraintObsolete(false) 86 // m_useSolveConstraintObsolete(true) 87 { 91 } 92 93 94 95 btSliderConstraint::btSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA) 96 : btTypedConstraint(SLIDER_CONSTRAINT_TYPE, getFixedBody(), rbB), 97 m_useSolveConstraintObsolete(false), 98 m_frameInB(frameInB), 99 m_useLinearReferenceFrameA(useLinearReferenceFrameA) 100 { 101 ///not providing rigidbody A means implicitly using worldspace for body A 102 m_frameInA = rbB.getCenterOfMassTransform() * m_frameInB; 103 // m_frameInA.getOrigin() = m_rbA.getCenterOfMassTransform()(m_frameInA.getOrigin()); 104 88 105 initParams(); 89 } // btSliderConstraint::btSliderConstraint()90 91 //----------------------------------------------------------------------------- 92 93 void btSliderConstraint::buildJacobian() 94 { 95 if (!m_useSolveConstraintObsolete) 96 { 97 return; 98 }99 if(m_useLinearReferenceFrameA)100 {101 buildJacobianInt(m_rbA, m_rbB, m_frameInA, m_frameInB);106 } 107 108 109 110 111 112 113 void btSliderConstraint::getInfo1(btConstraintInfo1* info) 114 { 115 if (m_useSolveConstraintObsolete) 116 { 117 info->m_numConstraintRows = 0; 118 info->nub = 0; 102 119 } 103 120 else 104 121 { 105 buildJacobianInt(m_rbB, m_rbA, m_frameInB, m_frameInA); 106 } 107 } // btSliderConstraint::buildJacobian() 108 109 //----------------------------------------------------------------------------- 110 111 void btSliderConstraint::buildJacobianInt(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB) 112 { 113 //calculate transforms 114 m_calculatedTransformA = rbA.getCenterOfMassTransform() * frameInA; 115 m_calculatedTransformB = rbB.getCenterOfMassTransform() * frameInB; 122 info->m_numConstraintRows = 4; // Fixed 2 linear + 2 angular 123 info->nub = 2; 124 //prepare constraint 125 calculateTransforms(m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform()); 126 testAngLimits(); 127 testLinLimits(); 128 if(getSolveLinLimit() || getPoweredLinMotor()) 129 { 130 info->m_numConstraintRows++; // limit 3rd linear as well 131 info->nub--; 132 } 133 if(getSolveAngLimit() || getPoweredAngMotor()) 134 { 135 info->m_numConstraintRows++; // limit 3rd angular as well 136 info->nub--; 137 } 138 } 139 } 140 141 void btSliderConstraint::getInfo1NonVirtual(btConstraintInfo1* info) 142 { 143 144 info->m_numConstraintRows = 6; // Fixed 2 linear + 2 angular + 1 limit (even if not used) 145 info->nub = 0; 146 } 147 148 void btSliderConstraint::getInfo2(btConstraintInfo2* info) 149 { 150 getInfo2NonVirtual(info,m_rbA.getCenterOfMassTransform(),m_rbB.getCenterOfMassTransform(), m_rbA.getLinearVelocity(),m_rbB.getLinearVelocity(), m_rbA.getInvMass(),m_rbB.getInvMass()); 151 } 152 153 154 155 156 157 158 159 void btSliderConstraint::calculateTransforms(const btTransform& transA,const btTransform& transB) 160 { 161 if(m_useLinearReferenceFrameA || (!m_useSolveConstraintObsolete)) 162 { 163 m_calculatedTransformA = transA * m_frameInA; 164 m_calculatedTransformB = transB * m_frameInB; 165 } 166 else 167 { 168 m_calculatedTransformA = transB * m_frameInB; 169 m_calculatedTransformB = transA * m_frameInA; 170 } 116 171 m_realPivotAInW = m_calculatedTransformA.getOrigin(); 117 172 m_realPivotBInW = m_calculatedTransformB.getOrigin(); 118 173 m_sliderAxis = m_calculatedTransformA.getBasis().getColumn(0); // along X 119 m_delta = m_realPivotBInW - m_realPivotAInW; 174 if(m_useLinearReferenceFrameA || m_useSolveConstraintObsolete) 175 { 176 m_delta = m_realPivotBInW - m_realPivotAInW; 177 } 178 else 179 { 180 m_delta = m_realPivotAInW - m_realPivotBInW; 181 } 120 182 m_projPivotInW = m_realPivotAInW + m_sliderAxis.dot(m_delta) * m_sliderAxis; 121 m_relPosA = m_projPivotInW - rbA.getCenterOfMassPosition();122 m_relPosB = m_realPivotBInW - rbB.getCenterOfMassPosition();123 183 btVector3 normalWorld; 124 184 int i; … … 127 187 { 128 188 normalWorld = m_calculatedTransformA.getBasis().getColumn(i); 129 new (&m_jacLin[i]) btJacobianEntry(130 rbA.getCenterOfMassTransform().getBasis().transpose(),131 rbB.getCenterOfMassTransform().getBasis().transpose(),132 m_relPosA,133 m_relPosB,134 normalWorld,135 rbA.getInvInertiaDiagLocal(),136 rbA.getInvMass(),137 rbB.getInvInertiaDiagLocal(),138 rbB.getInvMass()139 );140 m_jacLinDiagABInv[i] = btScalar(1.) / m_jacLin[i].getDiagonal();141 189 m_depth[i] = m_delta.dot(normalWorld); 142 190 } 143 testLinLimits(); 144 // angular part 145 for(i = 0; i < 3; i++) 146 { 147 normalWorld = m_calculatedTransformA.getBasis().getColumn(i); 148 new (&m_jacAng[i]) btJacobianEntry( 149 normalWorld, 150 rbA.getCenterOfMassTransform().getBasis().transpose(), 151 rbB.getCenterOfMassTransform().getBasis().transpose(), 152 rbA.getInvInertiaDiagLocal(), 153 rbB.getInvInertiaDiagLocal() 154 ); 155 } 156 testAngLimits(); 157 btVector3 axisA = m_calculatedTransformA.getBasis().getColumn(0); 158 m_kAngle = btScalar(1.0 )/ (rbA.computeAngularImpulseDenominator(axisA) + rbB.computeAngularImpulseDenominator(axisA)); 159 // clear accumulator for motors 160 m_accumulatedLinMotorImpulse = btScalar(0.0); 161 m_accumulatedAngMotorImpulse = btScalar(0.0); 162 } // btSliderConstraint::buildJacobianInt() 163 164 //----------------------------------------------------------------------------- 165 166 void btSliderConstraint::getInfo1(btConstraintInfo1* info) 167 { 168 if (m_useSolveConstraintObsolete) 169 { 170 info->m_numConstraintRows = 0; 171 info->nub = 0; 191 } 192 193 194 195 void btSliderConstraint::testLinLimits(void) 196 { 197 m_solveLinLim = false; 198 m_linPos = m_depth[0]; 199 if(m_lowerLinLimit <= m_upperLinLimit) 200 { 201 if(m_depth[0] > m_upperLinLimit) 202 { 203 m_depth[0] -= m_upperLinLimit; 204 m_solveLinLim = true; 205 } 206 else if(m_depth[0] < m_lowerLinLimit) 207 { 208 m_depth[0] -= m_lowerLinLimit; 209 m_solveLinLim = true; 210 } 211 else 212 { 213 m_depth[0] = btScalar(0.); 214 } 172 215 } 173 216 else 174 217 { 175 info->m_numConstraintRows = 4; // Fixed 2 linear + 2 angular 176 info->nub = 2; 177 //prepare constraint 178 calculateTransforms(); 179 testLinLimits(); 180 if(getSolveLinLimit() || getPoweredLinMotor()) 181 { 182 info->m_numConstraintRows++; // limit 3rd linear as well 183 info->nub--; 184 } 185 testAngLimits(); 186 if(getSolveAngLimit() || getPoweredAngMotor()) 187 { 188 info->m_numConstraintRows++; // limit 3rd angular as well 189 info->nub--; 190 } 191 } 192 } // btSliderConstraint::getInfo1() 193 194 //----------------------------------------------------------------------------- 195 196 void btSliderConstraint::getInfo2(btConstraintInfo2* info) 197 { 218 m_depth[0] = btScalar(0.); 219 } 220 } 221 222 223 224 void btSliderConstraint::testAngLimits(void) 225 { 226 m_angDepth = btScalar(0.); 227 m_solveAngLim = false; 228 if(m_lowerAngLimit <= m_upperAngLimit) 229 { 230 const btVector3 axisA0 = m_calculatedTransformA.getBasis().getColumn(1); 231 const btVector3 axisA1 = m_calculatedTransformA.getBasis().getColumn(2); 232 const btVector3 axisB0 = m_calculatedTransformB.getBasis().getColumn(1); 233 // btScalar rot = btAtan2Fast(axisB0.dot(axisA1), axisB0.dot(axisA0)); 234 btScalar rot = btAtan2(axisB0.dot(axisA1), axisB0.dot(axisA0)); 235 rot = btAdjustAngleToLimits(rot, m_lowerAngLimit, m_upperAngLimit); 236 m_angPos = rot; 237 if(rot < m_lowerAngLimit) 238 { 239 m_angDepth = rot - m_lowerAngLimit; 240 m_solveAngLim = true; 241 } 242 else if(rot > m_upperAngLimit) 243 { 244 m_angDepth = rot - m_upperAngLimit; 245 m_solveAngLim = true; 246 } 247 } 248 } 249 250 btVector3 btSliderConstraint::getAncorInA(void) 251 { 252 btVector3 ancorInA; 253 ancorInA = m_realPivotAInW + (m_lowerLinLimit + m_upperLinLimit) * btScalar(0.5) * m_sliderAxis; 254 ancorInA = m_rbA.getCenterOfMassTransform().inverse() * ancorInA; 255 return ancorInA; 256 } 257 258 259 260 btVector3 btSliderConstraint::getAncorInB(void) 261 { 262 btVector3 ancorInB; 263 ancorInB = m_frameInB.getOrigin(); 264 return ancorInB; 265 } 266 267 268 void btSliderConstraint::getInfo2NonVirtual(btConstraintInfo2* info, const btTransform& transA,const btTransform& transB, const btVector3& linVelA,const btVector3& linVelB, btScalar rbAinvMass,btScalar rbBinvMass ) 269 { 270 const btTransform& trA = getCalculatedTransformA(); 271 const btTransform& trB = getCalculatedTransformB(); 272 198 273 btAssert(!m_useSolveConstraintObsolete); 199 274 int i, s = info->rowskip; 200 const btTransform& trA = getCalculatedTransformA(); 201 const btTransform& trB = getCalculatedTransformB(); 275 202 276 btScalar signFact = m_useLinearReferenceFrameA ? btScalar(1.0f) : btScalar(-1.0f); 203 // make rotations around Y and Z equal 277 278 // difference between frames in WCS 279 btVector3 ofs = trB.getOrigin() - trA.getOrigin(); 280 // now get weight factors depending on masses 281 btScalar miA = rbAinvMass; 282 btScalar miB = rbBinvMass; 283 bool hasStaticBody = (miA < SIMD_EPSILON) || (miB < SIMD_EPSILON); 284 btScalar miS = miA + miB; 285 btScalar factA, factB; 286 if(miS > btScalar(0.f)) 287 { 288 factA = miB / miS; 289 } 290 else 291 { 292 factA = btScalar(0.5f); 293 } 294 factB = btScalar(1.0f) - factA; 295 btVector3 ax1, p, q; 296 btVector3 ax1A = trA.getBasis().getColumn(0); 297 btVector3 ax1B = trB.getBasis().getColumn(0); 298 if(m_useOffsetForConstraintFrame) 299 { 300 // get the desired direction of slider axis 301 // as weighted sum of X-orthos of frameA and frameB in WCS 302 ax1 = ax1A * factA + ax1B * factB; 303 ax1.normalize(); 304 // construct two orthos to slider axis 305 btPlaneSpace1 (ax1, p, q); 306 } 307 else 308 { // old way - use frameA 309 ax1 = trA.getBasis().getColumn(0); 310 // get 2 orthos to slider axis (Y, Z) 311 p = trA.getBasis().getColumn(1); 312 q = trA.getBasis().getColumn(2); 313 } 314 // make rotations around these orthos equal 204 315 // the slider axis should be the only unconstrained 205 316 // rotational axis, the angular velocity of the two bodies perpendicular to … … 209 320 // where p and q are unit vectors normal to the slider axis, and w1 and w2 210 321 // are the angular velocity vectors of the two bodies. 211 // get slider axis (X)212 btVector3 ax1 = trA.getBasis().getColumn(0);213 // get 2 orthos to slider axis (Y, Z)214 btVector3 p = trA.getBasis().getColumn(1);215 btVector3 q = trA.getBasis().getColumn(2);216 // set the two slider rows217 322 info->m_J1angularAxis[0] = p[0]; 218 323 info->m_J1angularAxis[1] = p[1]; … … 230 335 // compute the right hand side of the constraint equation. set relative 231 336 // body velocities along p and q to bring the slider back into alignment. 232 // if ax1 ,ax2 are the unit length slider axes as computed from body1and233 // body 2, we need to rotate both bodies along the axis u = (ax1 x ax2).337 // if ax1A,ax1B are the unit length slider axes as computed from bodyA and 338 // bodyB, we need to rotate both bodies along the axis u = (ax1 x ax2). 234 339 // if "theta" is the angle between ax1 and ax2, we need an angular velocity 235 340 // along u to cover angle erp*theta in one step : … … 243 348 // ax1 x ax2 is in the plane space of ax1, so we project the angular 244 349 // velocity to p and q to find the right hand side. 245 btScalar k = info->fps * info->erp * getSoftnessOrthoAng(); 246 btVector3 ax2 = trB.getBasis().getColumn(0); 247 btVector3 u = ax1.cross(ax2); 350 // btScalar k = info->fps * info->erp * getSoftnessOrthoAng(); 351 btScalar currERP = (m_flags & BT_SLIDER_FLAGS_ERP_ORTANG) ? m_softnessOrthoAng : m_softnessOrthoAng * info->erp; 352 btScalar k = info->fps * currERP; 353 354 btVector3 u = ax1A.cross(ax1B); 248 355 info->m_constraintError[0] = k * u.dot(p); 249 356 info->m_constraintError[s] = k * u.dot(q); 250 // pull out pos and R for both bodies. also get the connection 251 // vector c = pos2-pos1. 252 // next two rows. we want: vel2 = vel1 + w1 x c ... but this would 253 // result in three equations, so we project along the planespace vectors 254 // so that sliding along the slider axis is disregarded. for symmetry we 255 // also consider rotation around center of mass of two bodies (factA and factB). 256 btTransform bodyA_trans = m_rbA.getCenterOfMassTransform(); 257 btTransform bodyB_trans = m_rbB.getCenterOfMassTransform(); 258 int s2 = 2 * s, s3 = 3 * s; 259 btVector3 c; 260 btScalar miA = m_rbA.getInvMass(); 261 btScalar miB = m_rbB.getInvMass(); 262 btScalar miS = miA + miB; 263 btScalar factA, factB; 264 if(miS > btScalar(0.f)) 265 { 266 factA = miB / miS; 267 } 268 else 269 { 270 factA = btScalar(0.5f); 271 } 272 if(factA > 0.99f) factA = 0.99f; 273 if(factA < 0.01f) factA = 0.01f; 274 factB = btScalar(1.0f) - factA; 275 c = bodyB_trans.getOrigin() - bodyA_trans.getOrigin(); 276 btVector3 tmp = c.cross(p); 277 for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = factA*tmp[i]; 278 for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = factB*tmp[i]; 279 tmp = c.cross(q); 280 for (i=0; i<3; i++) info->m_J1angularAxis[s3+i] = factA*tmp[i]; 281 for (i=0; i<3; i++) info->m_J2angularAxis[s3+i] = factB*tmp[i]; 282 283 for (i=0; i<3; i++) info->m_J1linearAxis[s2+i] = p[i]; 284 for (i=0; i<3; i++) info->m_J1linearAxis[s3+i] = q[i]; 285 // compute two elements of right hand side. we want to align the offset 286 // point (in body 2's frame) with the center of body 1. 287 btVector3 ofs; // offset point in global coordinates 288 ofs = trB.getOrigin() - trA.getOrigin(); 289 k = info->fps * info->erp * getSoftnessOrthoLin(); 290 info->m_constraintError[s2] = k * p.dot(ofs); 291 info->m_constraintError[s3] = k * q.dot(ofs); 292 int nrow = 3; // last filled row 357 if(m_flags & BT_SLIDER_FLAGS_CFM_ORTANG) 358 { 359 info->cfm[0] = m_cfmOrthoAng; 360 info->cfm[s] = m_cfmOrthoAng; 361 } 362 363 int nrow = 1; // last filled row 293 364 int srow; 294 // check linear limits linear 295 btScalar limit_err = btScalar(0.0); 296 int limit = 0; 365 btScalar limit_err; 366 int limit; 367 int powered; 368 369 // next two rows. 370 // we want: velA + wA x relA == velB + wB x relB ... but this would 371 // result in three equations, so we project along two orthos to the slider axis 372 373 btTransform bodyA_trans = transA; 374 btTransform bodyB_trans = transB; 375 nrow++; 376 int s2 = nrow * s; 377 nrow++; 378 int s3 = nrow * s; 379 btVector3 tmpA(0,0,0), tmpB(0,0,0), relA(0,0,0), relB(0,0,0), c(0,0,0); 380 if(m_useOffsetForConstraintFrame) 381 { 382 // get vector from bodyB to frameB in WCS 383 relB = trB.getOrigin() - bodyB_trans.getOrigin(); 384 // get its projection to slider axis 385 btVector3 projB = ax1 * relB.dot(ax1); 386 // get vector directed from bodyB to slider axis (and orthogonal to it) 387 btVector3 orthoB = relB - projB; 388 // same for bodyA 389 relA = trA.getOrigin() - bodyA_trans.getOrigin(); 390 btVector3 projA = ax1 * relA.dot(ax1); 391 btVector3 orthoA = relA - projA; 392 // get desired offset between frames A and B along slider axis 393 btScalar sliderOffs = m_linPos - m_depth[0]; 394 // desired vector from projection of center of bodyA to projection of center of bodyB to slider axis 395 btVector3 totalDist = projA + ax1 * sliderOffs - projB; 396 // get offset vectors relA and relB 397 relA = orthoA + totalDist * factA; 398 relB = orthoB - totalDist * factB; 399 // now choose average ortho to slider axis 400 p = orthoB * factA + orthoA * factB; 401 btScalar len2 = p.length2(); 402 if(len2 > SIMD_EPSILON) 403 { 404 p /= btSqrt(len2); 405 } 406 else 407 { 408 p = trA.getBasis().getColumn(1); 409 } 410 // make one more ortho 411 q = ax1.cross(p); 412 // fill two rows 413 tmpA = relA.cross(p); 414 tmpB = relB.cross(p); 415 for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = tmpA[i]; 416 for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = -tmpB[i]; 417 tmpA = relA.cross(q); 418 tmpB = relB.cross(q); 419 if(hasStaticBody && getSolveAngLimit()) 420 { // to make constraint between static and dynamic objects more rigid 421 // remove wA (or wB) from equation if angular limit is hit 422 tmpB *= factB; 423 tmpA *= factA; 424 } 425 for (i=0; i<3; i++) info->m_J1angularAxis[s3+i] = tmpA[i]; 426 for (i=0; i<3; i++) info->m_J2angularAxis[s3+i] = -tmpB[i]; 427 for (i=0; i<3; i++) info->m_J1linearAxis[s2+i] = p[i]; 428 for (i=0; i<3; i++) info->m_J1linearAxis[s3+i] = q[i]; 429 } 430 else 431 { // old way - maybe incorrect if bodies are not on the slider axis 432 // see discussion "Bug in slider constraint" http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?f=9&t=4024&start=0 433 c = bodyB_trans.getOrigin() - bodyA_trans.getOrigin(); 434 btVector3 tmp = c.cross(p); 435 for (i=0; i<3; i++) info->m_J1angularAxis[s2+i] = factA*tmp[i]; 436 for (i=0; i<3; i++) info->m_J2angularAxis[s2+i] = factB*tmp[i]; 437 tmp = c.cross(q); 438 for (i=0; i<3; i++) info->m_J1angularAxis[s3+i] = factA*tmp[i]; 439 for (i=0; i<3; i++) info->m_J2angularAxis[s3+i] = factB*tmp[i]; 440 441 for (i=0; i<3; i++) info->m_J1linearAxis[s2+i] = p[i]; 442 for (i=0; i<3; i++) info->m_J1linearAxis[s3+i] = q[i]; 443 } 444 // compute two elements of right hand side 445 446 // k = info->fps * info->erp * getSoftnessOrthoLin(); 447 currERP = (m_flags & BT_SLIDER_FLAGS_ERP_ORTLIN) ? m_softnessOrthoLin : m_softnessOrthoLin * info->erp; 448 k = info->fps * currERP; 449 450 btScalar rhs = k * p.dot(ofs); 451 info->m_constraintError[s2] = rhs; 452 rhs = k * q.dot(ofs); 453 info->m_constraintError[s3] = rhs; 454 if(m_flags & BT_SLIDER_FLAGS_CFM_ORTLIN) 455 { 456 info->cfm[s2] = m_cfmOrthoLin; 457 info->cfm[s3] = m_cfmOrthoLin; 458 } 459 460 461 // check linear limits 462 limit_err = btScalar(0.0); 463 limit = 0; 297 464 if(getSolveLinLimit()) 298 465 { … … 300 467 limit = (limit_err > btScalar(0.0)) ? 2 : 1; 301 468 } 302 intpowered = 0;469 powered = 0; 303 470 if(getPoweredLinMotor()) 304 471 { … … 320 487 // a torque couple will result in limited slider-jointed free 321 488 // bodies from gaining angular momentum. 322 // the solution used here is to apply the constraint forces at the center of mass of the two bodies 323 btVector3 ltd; // Linear Torque Decoupling vector (a torque) 324 // c = btScalar(0.5) * c; 325 ltd = c.cross(ax1); 326 info->m_J1angularAxis[srow+0] = factA*ltd[0]; 327 info->m_J1angularAxis[srow+1] = factA*ltd[1]; 328 info->m_J1angularAxis[srow+2] = factA*ltd[2]; 329 info->m_J2angularAxis[srow+0] = factB*ltd[0]; 330 info->m_J2angularAxis[srow+1] = factB*ltd[1]; 331 info->m_J2angularAxis[srow+2] = factB*ltd[2]; 489 if(m_useOffsetForConstraintFrame) 490 { 491 // this is needed only when bodyA and bodyB are both dynamic. 492 if(!hasStaticBody) 493 { 494 tmpA = relA.cross(ax1); 495 tmpB = relB.cross(ax1); 496 info->m_J1angularAxis[srow+0] = tmpA[0]; 497 info->m_J1angularAxis[srow+1] = tmpA[1]; 498 info->m_J1angularAxis[srow+2] = tmpA[2]; 499 info->m_J2angularAxis[srow+0] = -tmpB[0]; 500 info->m_J2angularAxis[srow+1] = -tmpB[1]; 501 info->m_J2angularAxis[srow+2] = -tmpB[2]; 502 } 503 } 504 else 505 { // The old way. May be incorrect if bodies are not on the slider axis 506 btVector3 ltd; // Linear Torque Decoupling vector (a torque) 507 ltd = c.cross(ax1); 508 info->m_J1angularAxis[srow+0] = factA*ltd[0]; 509 info->m_J1angularAxis[srow+1] = factA*ltd[1]; 510 info->m_J1angularAxis[srow+2] = factA*ltd[2]; 511 info->m_J2angularAxis[srow+0] = factB*ltd[0]; 512 info->m_J2angularAxis[srow+1] = factB*ltd[1]; 513 info->m_J2angularAxis[srow+2] = factB*ltd[2]; 514 } 332 515 // right-hand part 333 516 btScalar lostop = getLowerLinLimit(); … … 340 523 info->m_lowerLimit[srow] = 0.; 341 524 info->m_upperLimit[srow] = 0.; 525 currERP = (m_flags & BT_SLIDER_FLAGS_ERP_LIMLIN) ? m_softnessLimLin : info->erp; 342 526 if(powered) 343 527 { 344 info->cfm[nrow] = btScalar(0.0); 528 if(m_flags & BT_SLIDER_FLAGS_CFM_DIRLIN) 529 { 530 info->cfm[srow] = m_cfmDirLin; 531 } 345 532 btScalar tag_vel = getTargetLinMotorVelocity(); 346 btScalar mot_fact = getMotorFactor(m_linPos, m_lowerLinLimit, m_upperLinLimit, tag_vel, info->fps * info->erp); 347 // info->m_constraintError[srow] += mot_fact * getTargetLinMotorVelocity(); 533 btScalar mot_fact = getMotorFactor(m_linPos, m_lowerLinLimit, m_upperLinLimit, tag_vel, info->fps * currERP); 348 534 info->m_constraintError[srow] -= signFact * mot_fact * getTargetLinMotorVelocity(); 349 535 info->m_lowerLimit[srow] += -getMaxLinMotorForce() * info->fps; … … 352 538 if(limit) 353 539 { 354 k = info->fps * info->erp;540 k = info->fps * currERP; 355 541 info->m_constraintError[srow] += k * limit_err; 356 info->cfm[srow] = btScalar(0.0); // stop_cfm; 542 if(m_flags & BT_SLIDER_FLAGS_CFM_LIMLIN) 543 { 544 info->cfm[srow] = m_cfmLimLin; 545 } 357 546 if(lostop == histop) 358 547 { // limited low and high simultaneously … … 374 563 if(bounce > btScalar(0.0)) 375 564 { 376 btScalar vel = m_rbA.getLinearVelocity().dot(ax1);377 vel -= m_rbB.getLinearVelocity().dot(ax1);565 btScalar vel = linVelA.dot(ax1); 566 vel -= linVelB.dot(ax1); 378 567 vel *= signFact; 379 568 // only apply bounce if the velocity is incoming, and if the … … 437 626 powered = 0; 438 627 } 628 currERP = (m_flags & BT_SLIDER_FLAGS_ERP_LIMANG) ? m_softnessLimAng : info->erp; 439 629 if(powered) 440 630 { 441 info->cfm[srow] = btScalar(0.0); 442 btScalar mot_fact = getMotorFactor(m_angPos, m_lowerAngLimit, m_upperAngLimit, getTargetAngMotorVelocity(), info->fps * info->erp); 631 if(m_flags & BT_SLIDER_FLAGS_CFM_DIRANG) 632 { 633 info->cfm[srow] = m_cfmDirAng; 634 } 635 btScalar mot_fact = getMotorFactor(m_angPos, m_lowerAngLimit, m_upperAngLimit, getTargetAngMotorVelocity(), info->fps * currERP); 443 636 info->m_constraintError[srow] = mot_fact * getTargetAngMotorVelocity(); 444 637 info->m_lowerLimit[srow] = -getMaxAngMotorForce() * info->fps; … … 447 640 if(limit) 448 641 { 449 k = info->fps * info->erp;642 k = info->fps * currERP; 450 643 info->m_constraintError[srow] += k * limit_err; 451 info->cfm[srow] = btScalar(0.0); // stop_cfm; 644 if(m_flags & BT_SLIDER_FLAGS_CFM_LIMANG) 645 { 646 info->cfm[srow] = m_cfmLimAng; 647 } 452 648 if(lostop == histop) 453 649 { … … 500 696 } // if(limit) 501 697 } // if angular limit or powered 502 } // btSliderConstraint::getInfo2() 503 504 //----------------------------------------------------------------------------- 505 506 void btSliderConstraint::solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) 507 { 508 if (m_useSolveConstraintObsolete) 509 { 510 m_timeStep = timeStep; 511 if(m_useLinearReferenceFrameA) 512 { 513 solveConstraintInt(m_rbA,bodyA, m_rbB,bodyB); 698 } 699 700 701 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 702 ///If no axis is provided, it uses the default axis for this constraint. 703 void btSliderConstraint::setParam(int num, btScalar value, int axis) 704 { 705 switch(num) 706 { 707 case BT_CONSTRAINT_STOP_ERP : 708 if(axis < 1) 709 { 710 m_softnessLimLin = value; 711 m_flags |= BT_SLIDER_FLAGS_ERP_LIMLIN; 712 } 713 else if(axis < 3) 714 { 715 m_softnessOrthoLin = value; 716 m_flags |= BT_SLIDER_FLAGS_ERP_ORTLIN; 717 } 718 else if(axis == 3) 719 { 720 m_softnessLimAng = value; 721 m_flags |= BT_SLIDER_FLAGS_ERP_LIMANG; 722 } 723 else if(axis < 6) 724 { 725 m_softnessOrthoAng = value; 726 m_flags |= BT_SLIDER_FLAGS_ERP_ORTANG; 514 727 } 515 728 else 516 729 { 517 solveConstraintInt(m_rbB,bodyB, m_rbA,bodyA); 518 } 519 } 520 } // btSliderConstraint::solveConstraint() 521 522 //----------------------------------------------------------------------------- 523 524 void btSliderConstraint::solveConstraintInt(btRigidBody& rbA, btSolverBody& bodyA,btRigidBody& rbB, btSolverBody& bodyB) 525 { 526 int i; 527 // linear 528 btVector3 velA; 529 bodyA.getVelocityInLocalPointObsolete(m_relPosA,velA); 530 btVector3 velB; 531 bodyB.getVelocityInLocalPointObsolete(m_relPosB,velB); 532 btVector3 vel = velA - velB; 533 for(i = 0; i < 3; i++) 534 { 535 const btVector3& normal = m_jacLin[i].m_linearJointAxis; 536 btScalar rel_vel = normal.dot(vel); 537 // calculate positional error 538 btScalar depth = m_depth[i]; 539 // get parameters 540 btScalar softness = (i) ? m_softnessOrthoLin : (m_solveLinLim ? m_softnessLimLin : m_softnessDirLin); 541 btScalar restitution = (i) ? m_restitutionOrthoLin : (m_solveLinLim ? m_restitutionLimLin : m_restitutionDirLin); 542 btScalar damping = (i) ? m_dampingOrthoLin : (m_solveLinLim ? m_dampingLimLin : m_dampingDirLin); 543 // calcutate and apply impulse 544 btScalar normalImpulse = softness * (restitution * depth / m_timeStep - damping * rel_vel) * m_jacLinDiagABInv[i]; 545 btVector3 impulse_vector = normal * normalImpulse; 546 547 //rbA.applyImpulse( impulse_vector, m_relPosA); 548 //rbB.applyImpulse(-impulse_vector, m_relPosB); 549 { 550 btVector3 ftorqueAxis1 = m_relPosA.cross(normal); 551 btVector3 ftorqueAxis2 = m_relPosB.cross(normal); 552 bodyA.applyImpulse(normal*rbA.getInvMass(), rbA.getInvInertiaTensorWorld()*ftorqueAxis1,normalImpulse); 553 bodyB.applyImpulse(normal*rbB.getInvMass(), rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-normalImpulse); 554 } 555 556 557 558 if(m_poweredLinMotor && (!i)) 559 { // apply linear motor 560 if(m_accumulatedLinMotorImpulse < m_maxLinMotorForce) 561 { 562 btScalar desiredMotorVel = m_targetLinMotorVelocity; 563 btScalar motor_relvel = desiredMotorVel + rel_vel; 564 normalImpulse = -motor_relvel * m_jacLinDiagABInv[i]; 565 // clamp accumulated impulse 566 btScalar new_acc = m_accumulatedLinMotorImpulse + btFabs(normalImpulse); 567 if(new_acc > m_maxLinMotorForce) 568 { 569 new_acc = m_maxLinMotorForce; 570 } 571 btScalar del = new_acc - m_accumulatedLinMotorImpulse; 572 if(normalImpulse < btScalar(0.0)) 573 { 574 normalImpulse = -del; 575 } 576 else 577 { 578 normalImpulse = del; 579 } 580 m_accumulatedLinMotorImpulse = new_acc; 581 // apply clamped impulse 582 impulse_vector = normal * normalImpulse; 583 //rbA.applyImpulse( impulse_vector, m_relPosA); 584 //rbB.applyImpulse(-impulse_vector, m_relPosB); 585 586 { 587 btVector3 ftorqueAxis1 = m_relPosA.cross(normal); 588 btVector3 ftorqueAxis2 = m_relPosB.cross(normal); 589 bodyA.applyImpulse(normal*rbA.getInvMass(), rbA.getInvInertiaTensorWorld()*ftorqueAxis1,normalImpulse); 590 bodyB.applyImpulse(normal*rbB.getInvMass(), rbB.getInvInertiaTensorWorld()*ftorqueAxis2,-normalImpulse); 591 } 592 593 594 595 } 596 } 597 } 598 // angular 599 // get axes in world space 600 btVector3 axisA = m_calculatedTransformA.getBasis().getColumn(0); 601 btVector3 axisB = m_calculatedTransformB.getBasis().getColumn(0); 602 603 btVector3 angVelA; 604 bodyA.getAngularVelocity(angVelA); 605 btVector3 angVelB; 606 bodyB.getAngularVelocity(angVelB); 607 608 btVector3 angVelAroundAxisA = axisA * axisA.dot(angVelA); 609 btVector3 angVelAroundAxisB = axisB * axisB.dot(angVelB); 610 611 btVector3 angAorthog = angVelA - angVelAroundAxisA; 612 btVector3 angBorthog = angVelB - angVelAroundAxisB; 613 btVector3 velrelOrthog = angAorthog-angBorthog; 614 //solve orthogonal angular velocity correction 615 btScalar len = velrelOrthog.length(); 616 btScalar orthorImpulseMag = 0.f; 617 618 if (len > btScalar(0.00001)) 619 { 620 btVector3 normal = velrelOrthog.normalized(); 621 btScalar denom = rbA.computeAngularImpulseDenominator(normal) + rbB.computeAngularImpulseDenominator(normal); 622 //velrelOrthog *= (btScalar(1.)/denom) * m_dampingOrthoAng * m_softnessOrthoAng; 623 orthorImpulseMag = (btScalar(1.)/denom) * m_dampingOrthoAng * m_softnessOrthoAng; 624 } 625 //solve angular positional correction 626 btVector3 angularError = axisA.cross(axisB) *(btScalar(1.)/m_timeStep); 627 btVector3 angularAxis = angularError; 628 btScalar angularImpulseMag = 0; 629 630 btScalar len2 = angularError.length(); 631 if (len2>btScalar(0.00001)) 632 { 633 btVector3 normal2 = angularError.normalized(); 634 btScalar denom2 = rbA.computeAngularImpulseDenominator(normal2) + rbB.computeAngularImpulseDenominator(normal2); 635 angularImpulseMag = (btScalar(1.)/denom2) * m_restitutionOrthoAng * m_softnessOrthoAng; 636 angularError *= angularImpulseMag; 637 } 638 // apply impulse 639 //rbA.applyTorqueImpulse(-velrelOrthog+angularError); 640 //rbB.applyTorqueImpulse(velrelOrthog-angularError); 641 642 bodyA.applyImpulse(btVector3(0,0,0), rbA.getInvInertiaTensorWorld()*velrelOrthog,-orthorImpulseMag); 643 bodyB.applyImpulse(btVector3(0,0,0), rbB.getInvInertiaTensorWorld()*velrelOrthog,orthorImpulseMag); 644 bodyA.applyImpulse(btVector3(0,0,0), rbA.getInvInertiaTensorWorld()*angularAxis,angularImpulseMag); 645 bodyB.applyImpulse(btVector3(0,0,0), rbB.getInvInertiaTensorWorld()*angularAxis,-angularImpulseMag); 646 647 648 btScalar impulseMag; 649 //solve angular limits 650 if(m_solveAngLim) 651 { 652 impulseMag = (angVelB - angVelA).dot(axisA) * m_dampingLimAng + m_angDepth * m_restitutionLimAng / m_timeStep; 653 impulseMag *= m_kAngle * m_softnessLimAng; 654 } 655 else 656 { 657 impulseMag = (angVelB - angVelA).dot(axisA) * m_dampingDirAng + m_angDepth * m_restitutionDirAng / m_timeStep; 658 impulseMag *= m_kAngle * m_softnessDirAng; 659 } 660 btVector3 impulse = axisA * impulseMag; 661 //rbA.applyTorqueImpulse(impulse); 662 //rbB.applyTorqueImpulse(-impulse); 663 664 bodyA.applyImpulse(btVector3(0,0,0), rbA.getInvInertiaTensorWorld()*axisA,impulseMag); 665 bodyB.applyImpulse(btVector3(0,0,0), rbB.getInvInertiaTensorWorld()*axisA,-impulseMag); 666 667 668 669 //apply angular motor 670 if(m_poweredAngMotor) 671 { 672 if(m_accumulatedAngMotorImpulse < m_maxAngMotorForce) 673 { 674 btVector3 velrel = angVelAroundAxisA - angVelAroundAxisB; 675 btScalar projRelVel = velrel.dot(axisA); 676 677 btScalar desiredMotorVel = m_targetAngMotorVelocity; 678 btScalar motor_relvel = desiredMotorVel - projRelVel; 679 680 btScalar angImpulse = m_kAngle * motor_relvel; 681 // clamp accumulated impulse 682 btScalar new_acc = m_accumulatedAngMotorImpulse + btFabs(angImpulse); 683 if(new_acc > m_maxAngMotorForce) 684 { 685 new_acc = m_maxAngMotorForce; 686 } 687 btScalar del = new_acc - m_accumulatedAngMotorImpulse; 688 if(angImpulse < btScalar(0.0)) 689 { 690 angImpulse = -del; 691 } 692 else 693 { 694 angImpulse = del; 695 } 696 m_accumulatedAngMotorImpulse = new_acc; 697 // apply clamped impulse 698 btVector3 motorImp = angImpulse * axisA; 699 //rbA.applyTorqueImpulse(motorImp); 700 //rbB.applyTorqueImpulse(-motorImp); 701 702 bodyA.applyImpulse(btVector3(0,0,0), rbA.getInvInertiaTensorWorld()*axisA,angImpulse); 703 bodyB.applyImpulse(btVector3(0,0,0), rbB.getInvInertiaTensorWorld()*axisA,-angImpulse); 704 } 705 } 706 } // btSliderConstraint::solveConstraint() 707 708 //----------------------------------------------------------------------------- 709 710 //----------------------------------------------------------------------------- 711 712 void btSliderConstraint::calculateTransforms(void){ 713 if(m_useLinearReferenceFrameA || (!m_useSolveConstraintObsolete)) 714 { 715 m_calculatedTransformA = m_rbA.getCenterOfMassTransform() * m_frameInA; 716 m_calculatedTransformB = m_rbB.getCenterOfMassTransform() * m_frameInB; 717 } 718 else 719 { 720 m_calculatedTransformA = m_rbB.getCenterOfMassTransform() * m_frameInB; 721 m_calculatedTransformB = m_rbA.getCenterOfMassTransform() * m_frameInA; 722 } 723 m_realPivotAInW = m_calculatedTransformA.getOrigin(); 724 m_realPivotBInW = m_calculatedTransformB.getOrigin(); 725 m_sliderAxis = m_calculatedTransformA.getBasis().getColumn(0); // along X 726 if(m_useLinearReferenceFrameA || m_useSolveConstraintObsolete) 727 { 728 m_delta = m_realPivotBInW - m_realPivotAInW; 729 } 730 else 731 { 732 m_delta = m_realPivotAInW - m_realPivotBInW; 733 } 734 m_projPivotInW = m_realPivotAInW + m_sliderAxis.dot(m_delta) * m_sliderAxis; 735 btVector3 normalWorld; 736 int i; 737 //linear part 738 for(i = 0; i < 3; i++) 739 { 740 normalWorld = m_calculatedTransformA.getBasis().getColumn(i); 741 m_depth[i] = m_delta.dot(normalWorld); 742 } 743 } // btSliderConstraint::calculateTransforms() 744 745 //----------------------------------------------------------------------------- 746 747 void btSliderConstraint::testLinLimits(void) 748 { 749 m_solveLinLim = false; 750 m_linPos = m_depth[0]; 751 if(m_lowerLinLimit <= m_upperLinLimit) 752 { 753 if(m_depth[0] > m_upperLinLimit) 754 { 755 m_depth[0] -= m_upperLinLimit; 756 m_solveLinLim = true; 757 } 758 else if(m_depth[0] < m_lowerLinLimit) 759 { 760 m_depth[0] -= m_lowerLinLimit; 761 m_solveLinLim = true; 730 btAssertConstrParams(0); 731 } 732 break; 733 case BT_CONSTRAINT_CFM : 734 if(axis < 1) 735 { 736 m_cfmDirLin = value; 737 m_flags |= BT_SLIDER_FLAGS_CFM_DIRLIN; 738 } 739 else if(axis == 3) 740 { 741 m_cfmDirAng = value; 742 m_flags |= BT_SLIDER_FLAGS_CFM_DIRANG; 762 743 } 763 744 else 764 745 { 765 m_depth[0] = btScalar(0.); 766 } 767 } 768 else 769 { 770 m_depth[0] = btScalar(0.); 771 } 772 } // btSliderConstraint::testLinLimits() 773 774 //----------------------------------------------------------------------------- 775 776 void btSliderConstraint::testAngLimits(void) 777 { 778 m_angDepth = btScalar(0.); 779 m_solveAngLim = false; 780 if(m_lowerAngLimit <= m_upperAngLimit) 781 { 782 const btVector3 axisA0 = m_calculatedTransformA.getBasis().getColumn(1); 783 const btVector3 axisA1 = m_calculatedTransformA.getBasis().getColumn(2); 784 const btVector3 axisB0 = m_calculatedTransformB.getBasis().getColumn(1); 785 btScalar rot = btAtan2Fast(axisB0.dot(axisA1), axisB0.dot(axisA0)); 786 m_angPos = rot; 787 if(rot < m_lowerAngLimit) 788 { 789 m_angDepth = rot - m_lowerAngLimit; 790 m_solveAngLim = true; 791 } 792 else if(rot > m_upperAngLimit) 793 { 794 m_angDepth = rot - m_upperAngLimit; 795 m_solveAngLim = true; 796 } 797 } 798 } // btSliderConstraint::testAngLimits() 799 800 //----------------------------------------------------------------------------- 801 802 btVector3 btSliderConstraint::getAncorInA(void) 803 { 804 btVector3 ancorInA; 805 ancorInA = m_realPivotAInW + (m_lowerLinLimit + m_upperLinLimit) * btScalar(0.5) * m_sliderAxis; 806 ancorInA = m_rbA.getCenterOfMassTransform().inverse() * ancorInA; 807 return ancorInA; 808 } // btSliderConstraint::getAncorInA() 809 810 //----------------------------------------------------------------------------- 811 812 btVector3 btSliderConstraint::getAncorInB(void) 813 { 814 btVector3 ancorInB; 815 ancorInB = m_frameInB.getOrigin(); 816 return ancorInB; 817 } // btSliderConstraint::getAncorInB(); 746 btAssertConstrParams(0); 747 } 748 break; 749 case BT_CONSTRAINT_STOP_CFM : 750 if(axis < 1) 751 { 752 m_cfmLimLin = value; 753 m_flags |= BT_SLIDER_FLAGS_CFM_LIMLIN; 754 } 755 else if(axis < 3) 756 { 757 m_cfmOrthoLin = value; 758 m_flags |= BT_SLIDER_FLAGS_CFM_ORTLIN; 759 } 760 else if(axis == 3) 761 { 762 m_cfmLimAng = value; 763 m_flags |= BT_SLIDER_FLAGS_CFM_LIMANG; 764 } 765 else if(axis < 6) 766 { 767 m_cfmOrthoAng = value; 768 m_flags |= BT_SLIDER_FLAGS_CFM_ORTANG; 769 } 770 else 771 { 772 btAssertConstrParams(0); 773 } 774 break; 775 } 776 } 777 778 ///return the local value of parameter 779 btScalar btSliderConstraint::getParam(int num, int axis) const 780 { 781 btScalar retVal(SIMD_INFINITY); 782 switch(num) 783 { 784 case BT_CONSTRAINT_STOP_ERP : 785 if(axis < 1) 786 { 787 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_ERP_LIMLIN); 788 retVal = m_softnessLimLin; 789 } 790 else if(axis < 3) 791 { 792 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_ERP_ORTLIN); 793 retVal = m_softnessOrthoLin; 794 } 795 else if(axis == 3) 796 { 797 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_ERP_LIMANG); 798 retVal = m_softnessLimAng; 799 } 800 else if(axis < 6) 801 { 802 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_ERP_ORTANG); 803 retVal = m_softnessOrthoAng; 804 } 805 else 806 { 807 btAssertConstrParams(0); 808 } 809 break; 810 case BT_CONSTRAINT_CFM : 811 if(axis < 1) 812 { 813 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_CFM_DIRLIN); 814 retVal = m_cfmDirLin; 815 } 816 else if(axis == 3) 817 { 818 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_CFM_DIRANG); 819 retVal = m_cfmDirAng; 820 } 821 else 822 { 823 btAssertConstrParams(0); 824 } 825 break; 826 case BT_CONSTRAINT_STOP_CFM : 827 if(axis < 1) 828 { 829 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_CFM_LIMLIN); 830 retVal = m_cfmLimLin; 831 } 832 else if(axis < 3) 833 { 834 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_CFM_ORTLIN); 835 retVal = m_cfmOrthoLin; 836 } 837 else if(axis == 3) 838 { 839 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_CFM_LIMANG); 840 retVal = m_cfmLimAng; 841 } 842 else if(axis < 6) 843 { 844 btAssertConstrParams(m_flags & BT_SLIDER_FLAGS_CFM_ORTANG); 845 retVal = m_cfmOrthoAng; 846 } 847 else 848 { 849 btAssertConstrParams(0); 850 } 851 break; 852 } 853 return retVal; 854 } 855 856 857 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSliderConstraint.h
r5781 r8351 26 26 #define SLIDER_CONSTRAINT_H 27 27 28 //----------------------------------------------------------------------------- 28 29 29 30 30 #include "LinearMath/btVector3.h" … … 32 32 #include "btTypedConstraint.h" 33 33 34 //----------------------------------------------------------------------------- 34 35 35 36 36 class btRigidBody; 37 37 38 //----------------------------------------------------------------------------- 38 39 39 40 40 #define SLIDER_CONSTRAINT_DEF_SOFTNESS (btScalar(1.0)) 41 41 #define SLIDER_CONSTRAINT_DEF_DAMPING (btScalar(1.0)) 42 42 #define SLIDER_CONSTRAINT_DEF_RESTITUTION (btScalar(0.7)) 43 44 //----------------------------------------------------------------------------- 43 #define SLIDER_CONSTRAINT_DEF_CFM (btScalar(0.f)) 44 45 46 enum btSliderFlags 47 { 48 BT_SLIDER_FLAGS_CFM_DIRLIN = (1 << 0), 49 BT_SLIDER_FLAGS_ERP_DIRLIN = (1 << 1), 50 BT_SLIDER_FLAGS_CFM_DIRANG = (1 << 2), 51 BT_SLIDER_FLAGS_ERP_DIRANG = (1 << 3), 52 BT_SLIDER_FLAGS_CFM_ORTLIN = (1 << 4), 53 BT_SLIDER_FLAGS_ERP_ORTLIN = (1 << 5), 54 BT_SLIDER_FLAGS_CFM_ORTANG = (1 << 6), 55 BT_SLIDER_FLAGS_ERP_ORTANG = (1 << 7), 56 BT_SLIDER_FLAGS_CFM_LIMLIN = (1 << 8), 57 BT_SLIDER_FLAGS_ERP_LIMLIN = (1 << 9), 58 BT_SLIDER_FLAGS_CFM_LIMANG = (1 << 10), 59 BT_SLIDER_FLAGS_ERP_LIMANG = (1 << 11) 60 }; 61 45 62 46 63 class btSliderConstraint : public btTypedConstraint … … 49 66 ///for backwards compatibility during the transition to 'getInfo/getInfo2' 50 67 bool m_useSolveConstraintObsolete; 68 bool m_useOffsetForConstraintFrame; 51 69 btTransform m_frameInA; 52 70 btTransform m_frameInB; … … 68 86 btScalar m_restitutionDirLin; 69 87 btScalar m_dampingDirLin; 88 btScalar m_cfmDirLin; 89 70 90 btScalar m_softnessDirAng; 71 91 btScalar m_restitutionDirAng; 72 92 btScalar m_dampingDirAng; 93 btScalar m_cfmDirAng; 94 73 95 btScalar m_softnessLimLin; 74 96 btScalar m_restitutionLimLin; 75 97 btScalar m_dampingLimLin; 98 btScalar m_cfmLimLin; 99 76 100 btScalar m_softnessLimAng; 77 101 btScalar m_restitutionLimAng; 78 102 btScalar m_dampingLimAng; 103 btScalar m_cfmLimAng; 104 79 105 btScalar m_softnessOrthoLin; 80 106 btScalar m_restitutionOrthoLin; 81 107 btScalar m_dampingOrthoLin; 108 btScalar m_cfmOrthoLin; 109 82 110 btScalar m_softnessOrthoAng; 83 111 btScalar m_restitutionOrthoAng; 84 112 btScalar m_dampingOrthoAng; 113 btScalar m_cfmOrthoAng; 85 114 86 115 // for interlal use 87 116 bool m_solveLinLim; 88 117 bool m_solveAngLim; 118 119 int m_flags; 89 120 90 121 btJacobianEntry m_jacLin[3]; … … 127 158 // constructors 128 159 btSliderConstraint(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB ,bool useLinearReferenceFrameA); 129 btSliderConstraint(); 160 btSliderConstraint(btRigidBody& rbB, const btTransform& frameInB, bool useLinearReferenceFrameA); 161 130 162 // overrides 131 virtual void buildJacobian(); 163 132 164 virtual void getInfo1 (btConstraintInfo1* info); 165 166 void getInfo1NonVirtual(btConstraintInfo1* info); 133 167 134 168 virtual void getInfo2 (btConstraintInfo2* info); 135 169 136 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep);137 170 void getInfo2NonVirtual(btConstraintInfo2* info, const btTransform& transA, const btTransform& transB,const btVector3& linVelA,const btVector3& linVelB, btScalar rbAinvMass,btScalar rbBinvMass); 171 138 172 139 173 // access … … 151 185 void setUpperLinLimit(btScalar upperLimit) { m_upperLinLimit = upperLimit; } 152 186 btScalar getLowerAngLimit() { return m_lowerAngLimit; } 153 void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = lowerLimit; }187 void setLowerAngLimit(btScalar lowerLimit) { m_lowerAngLimit = btNormalizeAngle(lowerLimit); } 154 188 btScalar getUpperAngLimit() { return m_upperAngLimit; } 155 void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = upperLimit; }189 void setUpperAngLimit(btScalar upperLimit) { m_upperAngLimit = btNormalizeAngle(upperLimit); } 156 190 bool getUseLinearReferenceFrameA() { return m_useLinearReferenceFrameA; } 157 191 btScalar getSoftnessDirLin() { return m_softnessDirLin; } … … 211 245 bool getSolveAngLimit() { return m_solveAngLim; } 212 246 btScalar getAngDepth() { return m_angDepth; } 213 // internal214 void buildJacobianInt(btRigidBody& rbA, btRigidBody& rbB, const btTransform& frameInA, const btTransform& frameInB);215 void solveConstraintInt(btRigidBody& rbA, btSolverBody& bodyA,btRigidBody& rbB, btSolverBody& bodyB);216 247 // shared code used by ODE solver 217 void calculateTransforms(void); 218 void testLinLimits(void); 219 void testLinLimits2(btConstraintInfo2* info); 220 void testAngLimits(void); 248 void calculateTransforms(const btTransform& transA,const btTransform& transB); 249 void testLinLimits(); 250 void testAngLimits(); 221 251 // access for PE Solver 222 btVector3 getAncorInA(void); 223 btVector3 getAncorInB(void); 252 btVector3 getAncorInA(); 253 btVector3 getAncorInB(); 254 // access for UseFrameOffset 255 bool getUseFrameOffset() { return m_useOffsetForConstraintFrame; } 256 void setUseFrameOffset(bool frameOffsetOnOff) { m_useOffsetForConstraintFrame = frameOffsetOnOff; } 257 258 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 259 ///If no axis is provided, it uses the default axis for this constraint. 260 virtual void setParam(int num, btScalar value, int axis = -1); 261 ///return the local value of parameter 262 virtual btScalar getParam(int num, int axis = -1) const; 263 264 virtual int calculateSerializeBufferSize() const; 265 266 ///fills the dataBuffer and returns the struct name (and 0 on failure) 267 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 268 269 224 270 }; 225 271 226 //----------------------------------------------------------------------------- 272 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 273 struct btSliderConstraintData 274 { 275 btTypedConstraintData m_typeConstraintData; 276 btTransformFloatData m_rbAFrame; // constraint axii. Assumes z is hinge axis. 277 btTransformFloatData m_rbBFrame; 278 279 float m_linearUpperLimit; 280 float m_linearLowerLimit; 281 282 float m_angularUpperLimit; 283 float m_angularLowerLimit; 284 285 int m_useLinearReferenceFrameA; 286 int m_useOffsetForConstraintFrame; 287 288 }; 289 290 291 SIMD_FORCE_INLINE int btSliderConstraint::calculateSerializeBufferSize() const 292 { 293 return sizeof(btSliderConstraintData); 294 } 295 296 ///fills the dataBuffer and returns the struct name (and 0 on failure) 297 SIMD_FORCE_INLINE const char* btSliderConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 298 { 299 300 btSliderConstraintData* sliderData = (btSliderConstraintData*) dataBuffer; 301 btTypedConstraint::serialize(&sliderData->m_typeConstraintData,serializer); 302 303 m_frameInA.serializeFloat(sliderData->m_rbAFrame); 304 m_frameInB.serializeFloat(sliderData->m_rbBFrame); 305 306 sliderData->m_linearUpperLimit = float(m_upperLinLimit); 307 sliderData->m_linearLowerLimit = float(m_lowerLinLimit); 308 309 sliderData->m_angularUpperLimit = float(m_upperAngLimit); 310 sliderData->m_angularLowerLimit = float(m_lowerAngLimit); 311 312 sliderData->m_useLinearReferenceFrameA = m_useLinearReferenceFrameA; 313 sliderData->m_useOffsetForConstraintFrame = m_useOffsetForConstraintFrame; 314 315 return "btSliderConstraintData"; 316 } 317 318 227 319 228 320 #endif //SLIDER_CONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSolverBody.h
r5781 r8351 106 106 107 107 ///The btSolverBody is an internal datastructure for the constraint solver. Only necessary data is packed to increase cache coherence/performance. 108 ATTRIBUTE_ALIGNED 16 (struct) btSolverBody108 ATTRIBUTE_ALIGNED64 (struct) btSolverBodyObsolete 109 109 { 110 110 BT_DECLARE_ALIGNED_ALLOCATOR(); 111 111 btVector3 m_deltaLinearVelocity; 112 112 btVector3 m_deltaAngularVelocity; 113 btScalar m_angularFactor; 114 btScalar m_invMass; 115 btScalar m_friction; 113 btVector3 m_angularFactor; 114 btVector3 m_invMass; 116 115 btRigidBody* m_originalBody; 117 116 btVector3 m_pushVelocity; 118 //btVector3 m_turnVelocity;117 btVector3 m_turnVelocity; 119 118 120 119 … … 146 145 } 147 146 148 149 /* 147 SIMD_FORCE_INLINE void internalApplyPushImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude) 148 { 149 if (m_originalBody) 150 { 151 m_pushVelocity += linearComponent*impulseMagnitude; 152 m_turnVelocity += angularComponent*(impulseMagnitude*m_angularFactor); 153 } 154 } 150 155 151 156 void writebackVelocity() 152 157 { 153 if (m_ invMass)158 if (m_originalBody) 154 159 { 155 160 m_originalBody->setLinearVelocity(m_originalBody->getLinearVelocity()+ m_deltaLinearVelocity); … … 159 164 } 160 165 } 161 */162 166 163 void writebackVelocity(btScalar timeStep=0) 167 168 void writebackVelocity(btScalar timeStep) 164 169 { 165 if (m_invMass) 170 (void) timeStep; 171 if (m_originalBody) 166 172 { 167 m_originalBody->setLinearVelocity(m_originalBody->getLinearVelocity()+ m_deltaLinearVelocity);173 m_originalBody->setLinearVelocity(m_originalBody->getLinearVelocity()+ m_deltaLinearVelocity); 168 174 m_originalBody->setAngularVelocity(m_originalBody->getAngularVelocity()+m_deltaAngularVelocity); 175 176 //correct the position/orientation based on push/turn recovery 177 btTransform newTransform; 178 btTransformUtil::integrateTransform(m_originalBody->getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform); 179 m_originalBody->setWorldTransform(newTransform); 180 169 181 //m_originalBody->setCompanionId(-1); 170 182 } -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btSolverConstraint.h
r5781 r8351 27 27 28 28 ///1D constraint along a normal axis between bodyA and bodyB. It can be combined to solve contact and friction constraints. 29 ATTRIBUTE_ALIGNED 16(struct) btSolverConstraint29 ATTRIBUTE_ALIGNED64 (struct) btSolverConstraint 30 30 { 31 31 BT_DECLARE_ALIGNED_ALLOCATOR(); … … 59 59 union 60 60 { 61 int m_solverBodyIdA;62 btScalar m_unusedPadding2;61 btRigidBody* m_solverBodyA; 62 int m_companionIdA; 63 63 }; 64 64 union 65 65 { 66 int m_solverBodyIdB;67 btScalar m_unusedPadding3;66 btRigidBody* m_solverBodyB; 67 int m_companionIdB; 68 68 }; 69 69 … … 78 78 btScalar m_lowerLimit; 79 79 btScalar m_upperLimit; 80 81 btScalar m_rhsPenetration; 80 82 81 83 enum btSolverConstraintType -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btTypedConstraint.cpp
r5781 r8351 17 17 #include "btTypedConstraint.h" 18 18 #include "BulletDynamics/Dynamics/btRigidBody.h" 19 #include "LinearMath/btSerializer.h" 19 20 20 static btRigidBody s_fixed(0, 0,0);21 21 22 22 #define DEFAULT_DEBUGDRAW_SIZE btScalar(0.3f) 23 23 24 btTypedConstraint::btTypedConstraint(btTypedConstraintType type) 25 :m_userConstraintType(-1), 24 btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA) 25 :btTypedObject(type), 26 m_userConstraintType(-1), 26 27 m_userConstraintId(-1), 27 m_ constraintType (type),28 m_rbA( s_fixed),29 m_rbB( s_fixed),28 m_needsFeedback(false), 29 m_rbA(rbA), 30 m_rbB(getFixedBody()), 30 31 m_appliedImpulse(btScalar(0.)), 31 32 m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) 32 33 { 33 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));34 }35 btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA)36 :m_userConstraintType(-1),37 m_userConstraintId(-1),38 m_constraintType (type),39 m_rbA(rbA),40 m_rbB(s_fixed),41 m_appliedImpulse(btScalar(0.)),42 m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE)43 {44 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));45 46 34 } 47 35 48 36 49 37 btTypedConstraint::btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA,btRigidBody& rbB) 50 :m_userConstraintType(-1), 38 :btTypedObject(type), 39 m_userConstraintType(-1), 51 40 m_userConstraintId(-1), 52 m_ constraintType (type),41 m_needsFeedback(false), 53 42 m_rbA(rbA), 54 43 m_rbB(rbB), … … 56 45 m_dbgDrawSize(DEFAULT_DEBUGDRAW_SIZE) 57 46 { 58 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.)));59 60 47 } 61 48 62 49 63 //----------------------------------------------------------------------------- 50 64 51 65 52 btScalar btTypedConstraint::getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact) … … 110 97 } 111 98 return lim_fact; 112 } // btTypedConstraint::getMotorFactor()99 } 113 100 101 ///fills the dataBuffer and returns the struct name (and 0 on failure) 102 const char* btTypedConstraint::serialize(void* dataBuffer, btSerializer* serializer) const 103 { 104 btTypedConstraintData* tcd = (btTypedConstraintData*) dataBuffer; 114 105 106 tcd->m_rbA = (btRigidBodyData*)serializer->getUniquePointer(&m_rbA); 107 tcd->m_rbB = (btRigidBodyData*)serializer->getUniquePointer(&m_rbB); 108 char* name = (char*) serializer->findNameForPointer(this); 109 tcd->m_name = (char*)serializer->getUniquePointer(name); 110 if (tcd->m_name) 111 { 112 serializer->serializeName(name); 113 } 114 115 tcd->m_objectType = m_objectType; 116 tcd->m_needsFeedback = m_needsFeedback; 117 tcd->m_userConstraintId =m_userConstraintId; 118 tcd->m_userConstraintType =m_userConstraintType; 119 120 tcd->m_appliedImpulse = float(m_appliedImpulse); 121 tcd->m_dbgDrawSize = float(m_dbgDrawSize ); 122 123 tcd->m_disableCollisionsBetweenLinkedBodies = false; 124 125 int i; 126 for (i=0;i<m_rbA.getNumConstraintRefs();i++) 127 if (m_rbA.getConstraintRef(i) == this) 128 tcd->m_disableCollisionsBetweenLinkedBodies = true; 129 for (i=0;i<m_rbB.getNumConstraintRefs();i++) 130 if (m_rbB.getConstraintRef(i) == this) 131 tcd->m_disableCollisionsBetweenLinkedBodies = true; 132 133 return "btTypedConstraintData"; 134 } 135 136 btRigidBody& btTypedConstraint::getFixedBody() 137 { 138 static btRigidBody s_fixed(0, 0,0); 139 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); 140 return s_fixed; 141 } 142 -
code/trunk/src/external/bullet/BulletDynamics/ConstraintSolver/btTypedConstraint.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-20 06Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/ 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "LinearMath/btScalar.h" 21 21 #include "btSolverConstraint.h" 22 struct btSolverBody; 23 24 25 22 #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" 23 24 class btSerializer; 26 25 27 26 enum btTypedConstraintType 28 27 { 29 POINT2POINT_CONSTRAINT_TYPE ,28 POINT2POINT_CONSTRAINT_TYPE=MAX_CONTACT_MANIFOLD_TYPE+1, 30 29 HINGE_CONSTRAINT_TYPE, 31 30 CONETWIST_CONSTRAINT_TYPE, 32 31 D6_CONSTRAINT_TYPE, 33 SLIDER_CONSTRAINT_TYPE 32 SLIDER_CONSTRAINT_TYPE, 33 CONTACT_CONSTRAINT_TYPE 34 34 }; 35 35 36 37 enum btConstraintParams 38 { 39 BT_CONSTRAINT_ERP=1, 40 BT_CONSTRAINT_STOP_ERP, 41 BT_CONSTRAINT_CFM, 42 BT_CONSTRAINT_STOP_CFM 43 }; 44 45 #if 1 46 #define btAssertConstrParams(_par) btAssert(_par) 47 #else 48 #define btAssertConstrParams(_par) 49 #endif 50 51 36 52 ///TypedConstraint is the baseclass for Bullet constraints and vehicles 37 class btTypedConstraint 53 class btTypedConstraint : public btTypedObject 38 54 { 39 55 int m_userConstraintType; 40 int m_userConstraintId; 41 42 btTypedConstraintType m_constraintType; 56 57 union 58 { 59 int m_userConstraintId; 60 void* m_userConstraintPtr; 61 }; 62 63 bool m_needsFeedback; 43 64 44 65 btTypedConstraint& operator=(btTypedConstraint& other) … … 55 76 btScalar m_dbgDrawSize; 56 77 78 ///internal method used by the constraint solver, don't use them directly 79 btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact); 80 81 static btRigidBody& getFixedBody(); 57 82 58 83 public: 59 84 60 btTypedConstraint(btTypedConstraintType type);61 85 virtual ~btTypedConstraint() {}; 62 86 btTypedConstraint(btTypedConstraintType type, btRigidBody& rbA); … … 94 118 // the constraint. 95 119 int *findex; 120 // number of solver iterations 121 int m_numIterations; 122 123 //damping of the velocity 124 btScalar m_damping; 96 125 }; 97 126 98 99 virtual void buildJacobian() = 0; 100 127 ///internal method used by the constraint solver, don't use them directly 128 virtual void buildJacobian() {}; 129 130 ///internal method used by the constraint solver, don't use them directly 101 131 virtual void setupSolverConstraint(btConstraintArray& ca, int solverBodyA,int solverBodyB, btScalar timeStep) 102 132 { 103 } 133 (void)ca; 134 (void)solverBodyA; 135 (void)solverBodyB; 136 (void)timeStep; 137 } 138 139 ///internal method used by the constraint solver, don't use them directly 104 140 virtual void getInfo1 (btConstraintInfo1* info)=0; 105 141 142 ///internal method used by the constraint solver, don't use them directly 106 143 virtual void getInfo2 (btConstraintInfo2* info)=0; 107 144 108 virtual void solveConstraintObsolete(btSolverBody& bodyA,btSolverBody& bodyB,btScalar timeStep) = 0; 109 110 btScalar getMotorFactor(btScalar pos, btScalar lowLim, btScalar uppLim, btScalar vel, btScalar timeFact); 145 ///internal method used by the constraint solver, don't use them directly 146 void internalSetAppliedImpulse(btScalar appliedImpulse) 147 { 148 m_appliedImpulse = appliedImpulse; 149 } 150 ///internal method used by the constraint solver, don't use them directly 151 btScalar internalGetAppliedImpulse() 152 { 153 return m_appliedImpulse; 154 } 155 156 ///internal method used by the constraint solver, don't use them directly 157 virtual void solveConstraintObsolete(btRigidBody& /*bodyA*/,btRigidBody& /*bodyB*/,btScalar /*timeStep*/) {}; 158 111 159 112 160 const btRigidBody& getRigidBodyA() const … … 148 196 } 149 197 198 void setUserConstraintPtr(void* ptr) 199 { 200 m_userConstraintPtr = ptr; 201 } 202 203 void* getUserConstraintPtr() 204 { 205 return m_userConstraintPtr; 206 } 207 150 208 int getUid() const 151 209 { … … 153 211 } 154 212 213 bool needsFeedback() const 214 { 215 return m_needsFeedback; 216 } 217 218 ///enableFeedback will allow to read the applied linear and angular impulse 219 ///use getAppliedImpulse, getAppliedLinearImpulse and getAppliedAngularImpulse to read feedback information 220 void enableFeedback(bool needsFeedback) 221 { 222 m_needsFeedback = needsFeedback; 223 } 224 225 ///getAppliedImpulse is an estimated total applied impulse. 226 ///This feedback could be used to determine breaking constraints or playing sounds. 155 227 btScalar getAppliedImpulse() const 156 228 { 229 btAssert(m_needsFeedback); 157 230 return m_appliedImpulse; 158 231 } … … 160 233 btTypedConstraintType getConstraintType () const 161 234 { 162 return m_constraintType;235 return btTypedConstraintType(m_objectType); 163 236 } 164 237 … … 171 244 return m_dbgDrawSize; 172 245 } 173 246 247 ///override the default global value of a parameter (such as ERP or CFM), optionally provide the axis (0..5). 248 ///If no axis is provided, it uses the default axis for this constraint. 249 virtual void setParam(int num, btScalar value, int axis = -1) = 0; 250 251 ///return the local value of parameter 252 virtual btScalar getParam(int num, int axis = -1) const = 0; 253 254 virtual int calculateSerializeBufferSize() const; 255 256 ///fills the dataBuffer and returns the struct name (and 0 on failure) 257 virtual const char* serialize(void* dataBuffer, btSerializer* serializer) const; 258 174 259 }; 175 260 261 // returns angle in range [-SIMD_2_PI, SIMD_2_PI], closest to one of the limits 262 // all arguments should be normalized angles (i.e. in range [-SIMD_PI, SIMD_PI]) 263 SIMD_FORCE_INLINE btScalar btAdjustAngleToLimits(btScalar angleInRadians, btScalar angleLowerLimitInRadians, btScalar angleUpperLimitInRadians) 264 { 265 if(angleLowerLimitInRadians >= angleUpperLimitInRadians) 266 { 267 return angleInRadians; 268 } 269 else if(angleInRadians < angleLowerLimitInRadians) 270 { 271 btScalar diffLo = btFabs(btNormalizeAngle(angleLowerLimitInRadians - angleInRadians)); 272 btScalar diffHi = btFabs(btNormalizeAngle(angleUpperLimitInRadians - angleInRadians)); 273 return (diffLo < diffHi) ? angleInRadians : (angleInRadians + SIMD_2_PI); 274 } 275 else if(angleInRadians > angleUpperLimitInRadians) 276 { 277 btScalar diffHi = btFabs(btNormalizeAngle(angleInRadians - angleUpperLimitInRadians)); 278 btScalar diffLo = btFabs(btNormalizeAngle(angleInRadians - angleLowerLimitInRadians)); 279 return (diffLo < diffHi) ? (angleInRadians - SIMD_2_PI) : angleInRadians; 280 } 281 else 282 { 283 return angleInRadians; 284 } 285 } 286 287 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 288 struct btTypedConstraintData 289 { 290 btRigidBodyData *m_rbA; 291 btRigidBodyData *m_rbB; 292 char *m_name; 293 294 int m_objectType; 295 int m_userConstraintType; 296 int m_userConstraintId; 297 int m_needsFeedback; 298 299 float m_appliedImpulse; 300 float m_dbgDrawSize; 301 302 int m_disableCollisionsBetweenLinkedBodies; 303 char m_pad4[4]; 304 305 }; 306 307 SIMD_FORCE_INLINE int btTypedConstraint::calculateSerializeBufferSize() const 308 { 309 return sizeof(btTypedConstraintData); 310 } 311 312 313 314 176 315 #endif //TYPED_CONSTRAINT_H -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/Bullet-C-API.cpp
r5781 r8351 44 44 #include "BulletCollision/NarrowPhaseCollision/btSimplexSolverInterface.h" 45 45 #include "BulletCollision/NarrowPhaseCollision/btMinkowskiPenetrationDepthSolver.h" 46 #include "LinearMath/btStackAlloc.h" 46 47 47 48 48 /* … … 182 182 { 183 183 //capsule is convex hull of 2 spheres, so use btMultiSphereShape 184 btVector3 inertiaHalfExtents(radius,height,radius);184 185 185 const int numSpheres = 2; 186 186 btVector3 positions[numSpheres] = {btVector3(0,height,0),btVector3(0,-height,0)}; 187 187 btScalar radi[numSpheres] = {radius,radius}; 188 188 void* mem = btAlignedAlloc(sizeof(btMultiSphereShape),16); 189 return (plCollisionShapeHandle) new (mem)btMultiSphereShape( inertiaHalfExtents,positions,radi,numSpheres);189 return (plCollisionShapeHandle) new (mem)btMultiSphereShape(positions,radi,numSpheres); 190 190 } 191 191 plCollisionShapeHandle plNewConeShape(plReal radius, plReal height) … … 294 294 worldTrans.setRotation(orn); 295 295 body->setWorldTransform(worldTrans); 296 } 297 298 void plSetOpenGLMatrix(plRigidBodyHandle object, plReal* matrix) 299 { 300 btRigidBody* body = reinterpret_cast< btRigidBody* >(object); 301 btAssert(body); 302 btTransform& worldTrans = body->getWorldTransform(); 303 worldTrans.setFromOpenGLMatrix(matrix); 296 304 } 297 305 … … 366 374 btGjkPairDetector::ClosestPointInput input; 367 375 368 btStackAlloc gStackAlloc(1024*1024*2); 369 370 input.m_stackAlloc = &gStackAlloc; 371 376 372 377 btTransform tr; 373 378 tr.setIdentity(); -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btActionInterface.h
r5781 r8351 21 21 22 22 #include "LinearMath/btScalar.h" 23 #include "btRigidBody.h" 23 24 24 25 ///Basic interface to allow actions such as vehicles and characters to be updated inside a btDynamicsWorld 25 26 class btActionInterface 26 27 { 27 public: 28 protected: 29 30 static btRigidBody& getFixedBody(); 31 32 33 public: 28 34 29 35 virtual ~btActionInterface() … … 38 44 39 45 #endif //_BT_ACTION_INTERFACE_H 46 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btContinuousDynamicsWorld.cpp
r5781 r8351 49 49 startProfiling(timeStep); 50 50 51 if(0 != m_internalPreTickCallback) { 52 (*m_internalPreTickCallback)(this, timeStep); 53 } 54 51 55 52 56 ///update aabbs information -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.cpp
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 20 20 #include "BulletCollision/CollisionDispatch/btCollisionDispatcher.h" 21 21 #include "BulletCollision/BroadphaseCollision/btSimpleBroadphase.h" 22 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 22 23 #include "BulletCollision/CollisionShapes/btCollisionShape.h" 23 24 #include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h" … … 36 37 #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" 37 38 38 //for debug rendering 39 #include "BulletCollision/CollisionShapes/btBoxShape.h" 40 #include "BulletCollision/CollisionShapes/btCapsuleShape.h" 41 #include "BulletCollision/CollisionShapes/btCompoundShape.h" 42 #include "BulletCollision/CollisionShapes/btConeShape.h" 43 #include "BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h" 44 #include "BulletCollision/CollisionShapes/btCylinderShape.h" 45 #include "BulletCollision/CollisionShapes/btMultiSphereShape.h" 46 #include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h" 39 #include "LinearMath/btIDebugDraw.h" 47 40 #include "BulletCollision/CollisionShapes/btSphereShape.h" 48 #include "BulletCollision/CollisionShapes/btTriangleCallback.h"49 #include "BulletCollision/CollisionShapes/btTriangleMeshShape.h"50 #include "BulletCollision/CollisionShapes/btStaticPlaneShape.h"51 #include "LinearMath/btIDebugDraw.h"52 41 53 42 … … 56 45 #include "LinearMath/btMotionState.h" 57 46 58 47 #include "LinearMath/btSerializer.h" 59 48 60 49 … … 64 53 m_constraintSolver(constraintSolver), 65 54 m_gravity(0,-10,0), 66 m_localTime(btScalar(1.)/btScalar(60.)), 55 m_localTime(0), 56 m_synchronizeAllMotionStates(false), 67 57 m_profileTimings(0) 68 58 { … … 104 94 void btDiscreteDynamicsWorld::saveKinematicState(btScalar timeStep) 105 95 { 106 96 ///would like to iterate over m_nonStaticRigidBodies, but unfortunately old API allows 97 ///to switch status _after_ adding kinematic objects to the world 98 ///fix it for Bullet 3.x release 107 99 for (int i=0;i<m_collisionObjects.size();i++) 108 100 { 109 101 btCollisionObject* colObj = m_collisionObjects[i]; 110 102 btRigidBody* body = btRigidBody::upcast(colObj); 111 if (body) 112 { 113 if (body->getActivationState() != ISLAND_SLEEPING) 114 { 115 if (body->isKinematicObject()) 116 { 117 //to calculate velocities next frame 118 body->saveKinematicState(timeStep); 119 } 120 } 121 } 122 } 103 if (body && body->getActivationState() != ISLAND_SLEEPING) 104 { 105 if (body->isKinematicObject()) 106 { 107 //to calculate velocities next frame 108 body->saveKinematicState(timeStep); 109 } 110 } 111 } 112 123 113 } 124 114 … … 127 117 BT_PROFILE("debugDrawWorld"); 128 118 129 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints) 130 { 131 int numManifolds = getDispatcher()->getNumManifolds(); 132 btVector3 color(0,0,0); 133 for (int i=0;i<numManifolds;i++) 134 { 135 btPersistentManifold* contactManifold = getDispatcher()->getManifoldByIndexInternal(i); 136 //btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0()); 137 //btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1()); 138 139 int numContacts = contactManifold->getNumContacts(); 140 for (int j=0;j<numContacts;j++) 141 { 142 btManifoldPoint& cp = contactManifold->getContactPoint(j); 143 getDebugDrawer()->drawContactPoint(cp.m_positionWorldOnB,cp.m_normalWorldOnB,cp.getDistance(),cp.getLifeTime(),color); 144 } 145 } 146 } 119 btCollisionWorld::debugDrawWorld(); 120 147 121 bool drawConstraints = false; 148 122 if (getDebugDrawer()) … … 169 143 int i; 170 144 171 for ( i=0;i<m_collisionObjects.size();i++)172 {173 btCollisionObject* colObj = m_collisionObjects[i];174 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe)175 {176 btVector3 color(btScalar(255.),btScalar(255.),btScalar(255.));177 switch(colObj->getActivationState())178 {179 case ACTIVE_TAG:180 color = btVector3(btScalar(255.),btScalar(255.),btScalar(255.)); break;181 case ISLAND_SLEEPING:182 color = btVector3(btScalar(0.),btScalar(255.),btScalar(0.));break;183 case WANTS_DEACTIVATION:184 color = btVector3(btScalar(0.),btScalar(255.),btScalar(255.));break;185 case DISABLE_DEACTIVATION:186 color = btVector3(btScalar(255.),btScalar(0.),btScalar(0.));break;187 case DISABLE_SIMULATION:188 color = btVector3(btScalar(255.),btScalar(255.),btScalar(0.));break;189 default:190 {191 color = btVector3(btScalar(255.),btScalar(0.),btScalar(0.));192 }193 };194 195 debugDrawObject(colObj->getWorldTransform(),colObj->getCollisionShape(),color);196 }197 if (m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawAabb))198 {199 btVector3 minAabb,maxAabb;200 btVector3 colorvec(1,0,0);201 colObj->getCollisionShape()->getAabb(colObj->getWorldTransform(), minAabb,maxAabb);202 m_debugDrawer->drawAabb(minAabb,maxAabb,colorvec);203 }204 205 }206 207 145 if (getDebugDrawer() && getDebugDrawer()->getDebugMode()) 208 146 { … … 218 156 { 219 157 ///@todo: iterate over awake simulation islands! 220 for ( int i=0;i<m_collisionObjects.size();i++) 221 { 222 btCollisionObject* colObj = m_collisionObjects[i]; 223 224 btRigidBody* body = btRigidBody::upcast(colObj); 225 if (body) 226 { 227 body->clearForces(); 228 } 158 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 159 { 160 btRigidBody* body = m_nonStaticRigidBodies[i]; 161 //need to check if next line is ok 162 //it might break backward compatibility (people applying forces on sleeping objects get never cleared and accumulate on wake-up 163 body->clearForces(); 229 164 } 230 165 } … … 234 169 { 235 170 ///@todo: iterate over awake simulation islands! 236 for ( int i=0;i<m_collisionObjects.size();i++) 237 { 238 btCollisionObject* colObj = m_collisionObjects[i]; 239 240 btRigidBody* body = btRigidBody::upcast(colObj); 241 if (body && body->isActive()) 171 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 172 { 173 btRigidBody* body = m_nonStaticRigidBodies[i]; 174 if (body->isActive()) 242 175 { 243 176 body->applyGravity(); … … 270 203 { 271 204 BT_PROFILE("synchronizeMotionStates"); 272 { 273 //todo: iterate over awake simulation islands! 205 if (m_synchronizeAllMotionStates) 206 { 207 //iterate over all collision objects 274 208 for ( int i=0;i<m_collisionObjects.size();i++) 275 209 { 276 210 btCollisionObject* colObj = m_collisionObjects[i]; 277 278 211 btRigidBody* body = btRigidBody::upcast(colObj); 279 212 if (body) 280 213 synchronizeSingleMotionState(body); 281 214 } 282 } 283 /* 284 if (getDebugDrawer() && getDebugDrawer()->getDebugMode() & btIDebugDraw::DBG_DrawWireframe) 285 { 286 for ( int i=0;i<this->m_vehicles.size();i++) 287 { 288 for (int v=0;v<m_vehicles[i]->getNumWheels();v++) 289 { 290 //synchronize the wheels with the (interpolated) chassis worldtransform 291 m_vehicles[i]->updateWheelTransform(v,true); 292 } 293 } 294 } 295 */ 296 297 215 } else 216 { 217 //iterate over all active rigid bodies 218 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 219 { 220 btRigidBody* body = m_nonStaticRigidBodies[i]; 221 if (body->isActive()) 222 synchronizeSingleMotionState(body); 223 } 224 } 298 225 } 299 226 … … 341 268 { 342 269 343 saveKinematicState(fixedTimeStep);344 345 applyGravity();346 347 270 //clamp the number of substeps, to prevent simulation grinding spiralling down to a halt 348 271 int clampedSimulationSteps = (numSimulationSubSteps > maxSubSteps)? maxSubSteps : numSimulationSubSteps; 349 272 273 saveKinematicState(fixedTimeStep*clampedSimulationSteps); 274 275 applyGravity(); 276 277 278 350 279 for (int i=0;i<clampedSimulationSteps;i++) 351 280 { … … 354 283 } 355 284 356 } 357 358 synchronizeMotionStates(); 285 } else 286 { 287 synchronizeMotionStates(); 288 } 359 289 360 290 clearForces(); … … 372 302 BT_PROFILE("internalSingleStepSimulation"); 373 303 304 if(0 != m_internalPreTickCallback) { 305 (*m_internalPreTickCallback)(this, timeStep); 306 } 307 374 308 ///apply gravity, predict motion 375 309 predictUnconstraintMotion(timeStep); … … 412 346 { 413 347 m_gravity = gravity; 414 for ( int i=0;i<m_collisionObjects.size();i++) 415 { 416 btCollisionObject* colObj = m_collisionObjects[i]; 417 btRigidBody* body = btRigidBody::upcast(colObj); 418 if (body) 348 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 349 { 350 btRigidBody* body = m_nonStaticRigidBodies[i]; 351 if (body->isActive() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY)) 419 352 { 420 353 body->setGravity(gravity); … … 428 361 } 429 362 363 void btDiscreteDynamicsWorld::addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup,short int collisionFilterMask) 364 { 365 btCollisionWorld::addCollisionObject(collisionObject,collisionFilterGroup,collisionFilterMask); 366 } 367 368 void btDiscreteDynamicsWorld::removeCollisionObject(btCollisionObject* collisionObject) 369 { 370 btRigidBody* body = btRigidBody::upcast(collisionObject); 371 if (body) 372 removeRigidBody(body); 373 else 374 btCollisionWorld::removeCollisionObject(collisionObject); 375 } 430 376 431 377 void btDiscreteDynamicsWorld::removeRigidBody(btRigidBody* body) 432 378 { 433 removeCollisionObject(body); 434 } 379 m_nonStaticRigidBodies.remove(body); 380 btCollisionWorld::removeCollisionObject(body); 381 } 382 435 383 436 384 void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body) 437 385 { 438 if (!body->isStaticOrKinematicObject() )386 if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY)) 439 387 { 440 388 body->setGravity(m_gravity); … … 443 391 if (body->getCollisionShape()) 444 392 { 393 if (!body->isStaticObject()) 394 { 395 m_nonStaticRigidBodies.push_back(body); 396 } else 397 { 398 body->setActivationState(ISLAND_SLEEPING); 399 } 400 445 401 bool isDynamic = !(body->isStaticObject() || body->isKinematicObject()); 446 402 short collisionFilterGroup = isDynamic? short(btBroadphaseProxy::DefaultFilter) : short(btBroadphaseProxy::StaticFilter); … … 453 409 void btDiscreteDynamicsWorld::addRigidBody(btRigidBody* body, short group, short mask) 454 410 { 455 if (!body->isStaticOrKinematicObject() )411 if (!body->isStaticOrKinematicObject() && !(body->getFlags() &BT_DISABLE_WORLD_GRAVITY)) 456 412 { 457 413 body->setGravity(m_gravity); … … 460 416 if (body->getCollisionShape()) 461 417 { 418 if (!body->isStaticObject()) 419 { 420 m_nonStaticRigidBodies.push_back(body); 421 } 422 else 423 { 424 body->setActivationState(ISLAND_SLEEPING); 425 } 462 426 addCollisionObject(body,group,mask); 463 427 } … … 480 444 BT_PROFILE("updateActivationState"); 481 445 482 for ( int i=0;i<m_collisionObjects.size();i++) 483 { 484 btCollisionObject* colObj = m_collisionObjects[i]; 485 btRigidBody* body = btRigidBody::upcast(colObj); 446 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 447 { 448 btRigidBody* body = m_nonStaticRigidBodies[i]; 486 449 if (body) 487 450 { … … 586 549 } 587 550 }; 588 589 551 590 552 … … 604 566 btStackAlloc* m_stackAlloc; 605 567 btDispatcher* m_dispatcher; 568 569 btAlignedObjectArray<btCollisionObject*> m_bodies; 570 btAlignedObjectArray<btPersistentManifold*> m_manifolds; 571 btAlignedObjectArray<btTypedConstraint*> m_constraints; 572 606 573 607 574 InplaceSolverIslandCallback( … … 624 591 } 625 592 593 626 594 InplaceSolverIslandCallback& operator=(InplaceSolverIslandCallback& other) 627 595 { … … 664 632 } 665 633 666 ///only call solveGroup if there is some work: avoid virtual function call, its overhead can be excessive 667 if (numManifolds + numCurConstraints) 668 { 669 m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); 670 } 671 672 } 634 if (m_solverInfo.m_minimumSolverBatchSize<=1) 635 { 636 ///only call solveGroup if there is some work: avoid virtual function call, its overhead can be excessive 637 if (numManifolds + numCurConstraints) 638 { 639 m_solver->solveGroup( bodies,numBodies,manifolds, numManifolds,startConstraint,numCurConstraints,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); 640 } 641 } else 642 { 643 644 for (i=0;i<numBodies;i++) 645 m_bodies.push_back(bodies[i]); 646 for (i=0;i<numManifolds;i++) 647 m_manifolds.push_back(manifolds[i]); 648 for (i=0;i<numCurConstraints;i++) 649 m_constraints.push_back(startConstraint[i]); 650 if ((m_constraints.size()+m_manifolds.size())>m_solverInfo.m_minimumSolverBatchSize) 651 { 652 processConstraints(); 653 } else 654 { 655 //printf("deferred\n"); 656 } 657 } 658 } 659 } 660 void processConstraints() 661 { 662 if (m_manifolds.size() + m_constraints.size()>0) 663 { 664 m_solver->solveGroup( &m_bodies[0],m_bodies.size(), &m_manifolds[0], m_manifolds.size(), &m_constraints[0], m_constraints.size() ,m_solverInfo,m_debugDrawer,m_stackAlloc,m_dispatcher); 665 } 666 m_bodies.resize(0); 667 m_manifolds.resize(0); 668 m_constraints.resize(0); 669 673 670 } 674 671 675 672 }; 673 674 676 675 677 676 //sorted version of all btTypedConstraint, based on islandId … … 699 698 m_islandManager->buildAndProcessIslands(getCollisionWorld()->getDispatcher(),getCollisionWorld(),&solverCallback); 700 699 700 solverCallback.processConstraints(); 701 701 702 m_constraintSolver->allSolved(solverInfo, m_debugDrawer, m_stackAlloc); 702 703 } … … 741 742 742 743 743 #include "BulletCollision/BroadphaseCollision/btCollisionAlgorithm.h" 744 744 745 745 746 class btClosestNotMeConvexResultCallback : public btCollisionWorld::ClosestConvexResultCallback … … 754 755 btClosestNotMeConvexResultCallback (btCollisionObject* me,const btVector3& fromA,const btVector3& toA,btOverlappingPairCache* pairCache,btDispatcher* dispatcher) : 755 756 btCollisionWorld::ClosestConvexResultCallback(fromA,toA), 757 m_me(me), 756 758 m_allowedPenetration(0.0f), 757 m_me(me),758 759 m_pairCache(pairCache), 759 760 m_dispatcher(dispatcher) … … 829 830 BT_PROFILE("integrateTransforms"); 830 831 btTransform predictedTrans; 831 for ( int i=0;i<m_collisionObjects.size();i++) 832 { 833 btCollisionObject* colObj = m_collisionObjects[i]; 834 btRigidBody* body = btRigidBody::upcast(colObj); 835 if (body) 836 { 837 body->setHitFraction(1.f); 838 839 if (body->isActive() && (!body->isStaticOrKinematicObject())) 840 { 841 body->predictIntegratedTransform(timeStep, predictedTrans); 842 btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); 843 844 if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion) 845 { 846 BT_PROFILE("CCD motion clamping"); 847 if (body->getCollisionShape()->isConvex()) 848 { 849 gNumClampedCcdMotions++; 850 851 btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher()); 852 btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 853 btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 854 855 sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup; 856 sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask; 857 858 convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults); 859 if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f)) 860 { 861 body->setHitFraction(sweepResults.m_closestHitFraction); 862 body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans); 863 body->setHitFraction(0.f); 832 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 833 { 834 btRigidBody* body = m_nonStaticRigidBodies[i]; 835 body->setHitFraction(1.f); 836 837 if (body->isActive() && (!body->isStaticOrKinematicObject())) 838 { 839 body->predictIntegratedTransform(timeStep, predictedTrans); 840 btScalar squareMotion = (predictedTrans.getOrigin()-body->getWorldTransform().getOrigin()).length2(); 841 842 if (body->getCcdSquareMotionThreshold() && body->getCcdSquareMotionThreshold() < squareMotion) 843 { 844 BT_PROFILE("CCD motion clamping"); 845 if (body->getCollisionShape()->isConvex()) 846 { 847 gNumClampedCcdMotions++; 848 849 btClosestNotMeConvexResultCallback sweepResults(body,body->getWorldTransform().getOrigin(),predictedTrans.getOrigin(),getBroadphase()->getOverlappingPairCache(),getDispatcher()); 850 //btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 851 btSphereShape tmpSphere(body->getCcdSweptSphereRadius());//btConvexShape* convexShape = static_cast<btConvexShape*>(body->getCollisionShape()); 852 853 sweepResults.m_collisionFilterGroup = body->getBroadphaseProxy()->m_collisionFilterGroup; 854 sweepResults.m_collisionFilterMask = body->getBroadphaseProxy()->m_collisionFilterMask; 855 856 convexSweepTest(&tmpSphere,body->getWorldTransform(),predictedTrans,sweepResults); 857 if (sweepResults.hasHit() && (sweepResults.m_closestHitFraction < 1.f)) 858 { 859 body->setHitFraction(sweepResults.m_closestHitFraction); 860 body->predictIntegratedTransform(timeStep*body->getHitFraction(), predictedTrans); 861 body->setHitFraction(0.f); 864 862 // printf("clamped integration to hit fraction = %f\n",fraction); 865 }866 863 } 867 864 } 868 869 body->proceedToTransform( predictedTrans);870 }865 } 866 867 body->proceedToTransform( predictedTrans); 871 868 } 872 869 } … … 880 877 { 881 878 BT_PROFILE("predictUnconstraintMotion"); 882 for ( int i=0;i<m_collisionObjects.size();i++) 883 { 884 btCollisionObject* colObj = m_collisionObjects[i]; 885 btRigidBody* body = btRigidBody::upcast(colObj); 886 if (body) 887 { 888 if (!body->isStaticOrKinematicObject()) 889 { 890 891 body->integrateVelocities( timeStep); 892 //damping 893 body->applyDamping(timeStep); 894 895 body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform()); 896 } 879 for ( int i=0;i<m_nonStaticRigidBodies.size();i++) 880 { 881 btRigidBody* body = m_nonStaticRigidBodies[i]; 882 if (!body->isStaticOrKinematicObject()) 883 { 884 body->integrateVelocities( timeStep); 885 //damping 886 body->applyDamping(timeStep); 887 888 body->predictIntegratedTransform(timeStep,body->getInterpolationWorldTransform()); 897 889 } 898 890 } … … 914 906 915 907 916 917 class DebugDrawcallback : public btTriangleCallback, public btInternalTriangleIndexCallback918 {919 btIDebugDraw* m_debugDrawer;920 btVector3 m_color;921 btTransform m_worldTrans;922 923 public:924 925 DebugDrawcallback(btIDebugDraw* debugDrawer,const btTransform& worldTrans,const btVector3& color) :926 m_debugDrawer(debugDrawer),927 m_color(color),928 m_worldTrans(worldTrans)929 {930 }931 932 virtual void internalProcessTriangleIndex(btVector3* triangle,int partId,int triangleIndex)933 {934 processTriangle(triangle,partId,triangleIndex);935 }936 937 virtual void processTriangle(btVector3* triangle,int partId, int triangleIndex)938 {939 (void)partId;940 (void)triangleIndex;941 942 btVector3 wv0,wv1,wv2;943 wv0 = m_worldTrans*triangle[0];944 wv1 = m_worldTrans*triangle[1];945 wv2 = m_worldTrans*triangle[2];946 m_debugDrawer->drawLine(wv0,wv1,m_color);947 m_debugDrawer->drawLine(wv1,wv2,m_color);948 m_debugDrawer->drawLine(wv2,wv0,m_color);949 }950 };951 952 void btDiscreteDynamicsWorld::debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color)953 {954 btVector3 start = transform.getOrigin();955 956 const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0);957 const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0);958 const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius);959 960 // XY961 getDebugDrawer()->drawLine(start-xoffs, start+yoffs, color);962 getDebugDrawer()->drawLine(start+yoffs, start+xoffs, color);963 getDebugDrawer()->drawLine(start+xoffs, start-yoffs, color);964 getDebugDrawer()->drawLine(start-yoffs, start-xoffs, color);965 966 // XZ967 getDebugDrawer()->drawLine(start-xoffs, start+zoffs, color);968 getDebugDrawer()->drawLine(start+zoffs, start+xoffs, color);969 getDebugDrawer()->drawLine(start+xoffs, start-zoffs, color);970 getDebugDrawer()->drawLine(start-zoffs, start-xoffs, color);971 972 // YZ973 getDebugDrawer()->drawLine(start-yoffs, start+zoffs, color);974 getDebugDrawer()->drawLine(start+zoffs, start+yoffs, color);975 getDebugDrawer()->drawLine(start+yoffs, start-zoffs, color);976 getDebugDrawer()->drawLine(start-zoffs, start-yoffs, color);977 }978 979 void btDiscreteDynamicsWorld::debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color)980 {981 // Draw a small simplex at the center of the object982 {983 btVector3 start = worldTransform.getOrigin();984 getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(1,0,0), btVector3(1,0,0));985 getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(0,1,0), btVector3(0,1,0));986 getDebugDrawer()->drawLine(start, start+worldTransform.getBasis() * btVector3(0,0,1), btVector3(0,0,1));987 }988 989 if (shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE)990 {991 const btCompoundShape* compoundShape = static_cast<const btCompoundShape*>(shape);992 for (int i=compoundShape->getNumChildShapes()-1;i>=0;i--)993 {994 btTransform childTrans = compoundShape->getChildTransform(i);995 const btCollisionShape* colShape = compoundShape->getChildShape(i);996 debugDrawObject(worldTransform*childTrans,colShape,color);997 }998 999 } else1000 {1001 switch (shape->getShapeType())1002 {1003 1004 case SPHERE_SHAPE_PROXYTYPE:1005 {1006 const btSphereShape* sphereShape = static_cast<const btSphereShape*>(shape);1007 btScalar radius = sphereShape->getMargin();//radius doesn't include the margin, so draw with margin1008 1009 debugDrawSphere(radius, worldTransform, color);1010 break;1011 }1012 case MULTI_SPHERE_SHAPE_PROXYTYPE:1013 {1014 const btMultiSphereShape* multiSphereShape = static_cast<const btMultiSphereShape*>(shape);1015 1016 for (int i = multiSphereShape->getSphereCount()-1; i>=0;i--)1017 {1018 btTransform childTransform = worldTransform;1019 childTransform.getOrigin() += multiSphereShape->getSpherePosition(i);1020 debugDrawSphere(multiSphereShape->getSphereRadius(i), childTransform, color);1021 }1022 1023 break;1024 }1025 case CAPSULE_SHAPE_PROXYTYPE:1026 {1027 const btCapsuleShape* capsuleShape = static_cast<const btCapsuleShape*>(shape);1028 1029 btScalar radius = capsuleShape->getRadius();1030 btScalar halfHeight = capsuleShape->getHalfHeight();1031 1032 int upAxis = capsuleShape->getUpAxis();1033 1034 1035 btVector3 capStart(0.f,0.f,0.f);1036 capStart[upAxis] = -halfHeight;1037 1038 btVector3 capEnd(0.f,0.f,0.f);1039 capEnd[upAxis] = halfHeight;1040 1041 // Draw the ends1042 {1043 1044 btTransform childTransform = worldTransform;1045 childTransform.getOrigin() = worldTransform * capStart;1046 debugDrawSphere(radius, childTransform, color);1047 }1048 1049 {1050 btTransform childTransform = worldTransform;1051 childTransform.getOrigin() = worldTransform * capEnd;1052 debugDrawSphere(radius, childTransform, color);1053 }1054 1055 // Draw some additional lines1056 btVector3 start = worldTransform.getOrigin();1057 1058 1059 capStart[(upAxis+1)%3] = radius;1060 capEnd[(upAxis+1)%3] = radius;1061 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);1062 capStart[(upAxis+1)%3] = -radius;1063 capEnd[(upAxis+1)%3] = -radius;1064 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);1065 1066 capStart[(upAxis+1)%3] = 0.f;1067 capEnd[(upAxis+1)%3] = 0.f;1068 1069 capStart[(upAxis+2)%3] = radius;1070 capEnd[(upAxis+2)%3] = radius;1071 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);1072 capStart[(upAxis+2)%3] = -radius;1073 capEnd[(upAxis+2)%3] = -radius;1074 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * capStart,start+worldTransform.getBasis() * capEnd, color);1075 1076 1077 break;1078 }1079 case CONE_SHAPE_PROXYTYPE:1080 {1081 const btConeShape* coneShape = static_cast<const btConeShape*>(shape);1082 btScalar radius = coneShape->getRadius();//+coneShape->getMargin();1083 btScalar height = coneShape->getHeight();//+coneShape->getMargin();1084 btVector3 start = worldTransform.getOrigin();1085 1086 int upAxis= coneShape->getConeUpIndex();1087 1088 1089 btVector3 offsetHeight(0,0,0);1090 offsetHeight[upAxis] = height * btScalar(0.5);1091 btVector3 offsetRadius(0,0,0);1092 offsetRadius[(upAxis+1)%3] = radius;1093 btVector3 offset2Radius(0,0,0);1094 offset2Radius[(upAxis+2)%3] = radius;1095 1096 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);1097 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);1098 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight+offset2Radius),color);1099 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight),start+worldTransform.getBasis() * (-offsetHeight-offset2Radius),color);1100 1101 1102 1103 break;1104 1105 }1106 case CYLINDER_SHAPE_PROXYTYPE:1107 {1108 const btCylinderShape* cylinder = static_cast<const btCylinderShape*>(shape);1109 int upAxis = cylinder->getUpAxis();1110 btScalar radius = cylinder->getRadius();1111 btScalar halfHeight = cylinder->getHalfExtentsWithMargin()[upAxis];1112 btVector3 start = worldTransform.getOrigin();1113 btVector3 offsetHeight(0,0,0);1114 offsetHeight[upAxis] = halfHeight;1115 btVector3 offsetRadius(0,0,0);1116 offsetRadius[(upAxis+1)%3] = radius;1117 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight+offsetRadius),start+worldTransform.getBasis() * (-offsetHeight+offsetRadius),color);1118 getDebugDrawer()->drawLine(start+worldTransform.getBasis() * (offsetHeight-offsetRadius),start+worldTransform.getBasis() * (-offsetHeight-offsetRadius),color);1119 break;1120 }1121 1122 case STATIC_PLANE_PROXYTYPE:1123 {1124 const btStaticPlaneShape* staticPlaneShape = static_cast<const btStaticPlaneShape*>(shape);1125 btScalar planeConst = staticPlaneShape->getPlaneConstant();1126 const btVector3& planeNormal = staticPlaneShape->getPlaneNormal();1127 btVector3 planeOrigin = planeNormal * planeConst;1128 btVector3 vec0,vec1;1129 btPlaneSpace1(planeNormal,vec0,vec1);1130 btScalar vecLen = 100.f;1131 btVector3 pt0 = planeOrigin + vec0*vecLen;1132 btVector3 pt1 = planeOrigin - vec0*vecLen;1133 btVector3 pt2 = planeOrigin + vec1*vecLen;1134 btVector3 pt3 = planeOrigin - vec1*vecLen;1135 getDebugDrawer()->drawLine(worldTransform*pt0,worldTransform*pt1,color);1136 getDebugDrawer()->drawLine(worldTransform*pt2,worldTransform*pt3,color);1137 break;1138 1139 }1140 default:1141 {1142 1143 if (shape->isConcave())1144 {1145 btConcaveShape* concaveMesh = (btConcaveShape*) shape;1146 1147 ///@todo pass camera, for some culling? no -> we are not a graphics lib1148 btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));1149 btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));1150 1151 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);1152 concaveMesh->processAllTriangles(&drawCallback,aabbMin,aabbMax);1153 1154 }1155 1156 if (shape->getShapeType() == CONVEX_TRIANGLEMESH_SHAPE_PROXYTYPE)1157 {1158 btConvexTriangleMeshShape* convexMesh = (btConvexTriangleMeshShape*) shape;1159 //todo: pass camera for some culling1160 btVector3 aabbMax(btScalar(1e30),btScalar(1e30),btScalar(1e30));1161 btVector3 aabbMin(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30));1162 //DebugDrawcallback drawCallback;1163 DebugDrawcallback drawCallback(getDebugDrawer(),worldTransform,color);1164 convexMesh->getMeshInterface()->InternalProcessAllTriangles(&drawCallback,aabbMin,aabbMax);1165 }1166 1167 1168 /// for polyhedral shapes1169 if (shape->isPolyhedral())1170 {1171 btPolyhedralConvexShape* polyshape = (btPolyhedralConvexShape*) shape;1172 1173 int i;1174 for (i=0;i<polyshape->getNumEdges();i++)1175 {1176 btVector3 a,b;1177 polyshape->getEdge(i,a,b);1178 btVector3 wa = worldTransform * a;1179 btVector3 wb = worldTransform * b;1180 getDebugDrawer()->drawLine(wa,wb,color);1181 1182 }1183 1184 1185 }1186 }1187 }1188 }1189 }1190 1191 908 1192 909 void btDiscreteDynamicsWorld::debugDrawConstraint(btTypedConstraint* constraint) … … 1350 1067 if(drawLimits) 1351 1068 { 1352 btTransform tr = pSlider->get CalculatedTransformA();1069 btTransform tr = pSlider->getUseLinearReferenceFrameA() ? pSlider->getCalculatedTransformA() : pSlider->getCalculatedTransformB(); 1353 1070 btVector3 li_min = tr * btVector3(pSlider->getLowerLinLimit(), 0.f, 0.f); 1354 1071 btVector3 li_max = tr * btVector3(pSlider->getUpperLinLimit(), 0.f, 0.f); … … 1367 1084 } 1368 1085 return; 1369 } // btDiscreteDynamicsWorld::debugDrawConstraint()1086 } 1370 1087 1371 1088 … … 1403 1120 1404 1121 1122 1123 void btDiscreteDynamicsWorld::serializeRigidBodies(btSerializer* serializer) 1124 { 1125 int i; 1126 //serialize all collision objects 1127 for (i=0;i<m_collisionObjects.size();i++) 1128 { 1129 btCollisionObject* colObj = m_collisionObjects[i]; 1130 if (colObj->getInternalType() & btCollisionObject::CO_RIGID_BODY) 1131 { 1132 int len = colObj->calculateSerializeBufferSize(); 1133 btChunk* chunk = serializer->allocate(len,1); 1134 const char* structType = colObj->serialize(chunk->m_oldPtr, serializer); 1135 serializer->finalizeChunk(chunk,structType,BT_RIGIDBODY_CODE,colObj); 1136 } 1137 } 1138 1139 for (i=0;i<m_constraints.size();i++) 1140 { 1141 btTypedConstraint* constraint = m_constraints[i]; 1142 int size = constraint->calculateSerializeBufferSize(); 1143 btChunk* chunk = serializer->allocate(size,1); 1144 const char* structType = constraint->serialize(chunk->m_oldPtr,serializer); 1145 serializer->finalizeChunk(chunk,structType,BT_CONSTRAINT_CODE,constraint); 1146 } 1147 } 1148 1149 1150 void btDiscreteDynamicsWorld::serialize(btSerializer* serializer) 1151 { 1152 1153 serializer->startSerialization(); 1154 1155 serializeRigidBodies(serializer); 1156 1157 serializeCollisionObjects(serializer); 1158 1159 serializer->finishSerialization(); 1160 } 1161 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h
r5781 r8351 1 1 /* 2 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-200 6 Erwin Coumans http://continuousphysics.com/Bullet/3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 4 5 5 This software is provided 'as-is', without any express or implied warranty. … … 13 13 3. This notice may not be removed or altered from any source distribution. 14 14 */ 15 15 16 16 17 #ifndef BT_DISCRETE_DYNAMICS_WORLD_H … … 42 43 btAlignedObjectArray<btTypedConstraint*> m_constraints; 43 44 45 btAlignedObjectArray<btRigidBody*> m_nonStaticRigidBodies; 46 44 47 btVector3 m_gravity; 45 48 … … 50 53 bool m_ownsIslandManager; 51 54 bool m_ownsConstraintSolver; 55 bool m_synchronizeAllMotionStates; 52 56 53 57 btAlignedObjectArray<btActionInterface*> m_actions; … … 74 78 virtual void saveKinematicState(btScalar timeStep); 75 79 76 void debugDrawSphere(btScalar radius, const btTransform& transform, const btVector3& color); 77 80 void serializeRigidBodies(btSerializer* serializer); 78 81 79 82 public: … … 121 124 virtual btVector3 getGravity () const; 122 125 126 virtual void addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup=btBroadphaseProxy::StaticFilter,short int collisionFilterMask=btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter); 127 123 128 virtual void addRigidBody(btRigidBody* body); 124 129 … … 127 132 virtual void removeRigidBody(btRigidBody* body); 128 133 129 void debugDrawObject(const btTransform& worldTransform, const btCollisionShape* shape, const btVector3& color); 134 ///removeCollisionObject will first check if it is a rigid body, if so call removeRigidBody otherwise call btCollisionWorld::removeCollisionObject 135 virtual void removeCollisionObject(btCollisionObject* collisionObject); 136 130 137 131 138 void debugDrawConstraint(btTypedConstraint* constraint); … … 175 182 virtual void removeCharacter(btActionInterface* character); 176 183 184 void setSynchronizeAllMotionStates(bool synchronizeAll) 185 { 186 m_synchronizeAllMotionStates = synchronizeAll; 187 } 188 bool getSynchronizeAllMotionStates() const 189 { 190 return m_synchronizeAllMotionStates; 191 } 192 193 ///Preliminary serialization test for Bullet 2.76. Loading those files requires a separate parser (see Bullet/Demos/SerializeDemo) 194 virtual void serialize(btSerializer* serializer); 195 177 196 }; 178 197 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btDynamicsWorld.h
r5781 r8351 42 42 protected: 43 43 btInternalTickCallback m_internalTickCallback; 44 btInternalTickCallback m_internalPreTickCallback; 44 45 void* m_worldUserInfo; 45 46 … … 50 51 51 52 btDynamicsWorld(btDispatcher* dispatcher,btBroadphaseInterface* broadphase,btCollisionConfiguration* collisionConfiguration) 52 :btCollisionWorld(dispatcher,broadphase,collisionConfiguration), m_internalTickCallback(0), m_worldUserInfo(0)53 :btCollisionWorld(dispatcher,broadphase,collisionConfiguration), m_internalTickCallback(0),m_internalPreTickCallback(0), m_worldUserInfo(0) 53 54 { 54 55 } … … 103 104 104 105 /// Set the callback for when an internal tick (simulation substep) happens, optional user info 105 void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo=0 )106 void setInternalTickCallback(btInternalTickCallback cb, void* worldUserInfo=0,bool isPreTick=false) 106 107 { 107 m_internalTickCallback = cb; 108 if (isPreTick) 109 { 110 m_internalPreTickCallback = cb; 111 } else 112 { 113 m_internalTickCallback = cb; 114 } 108 115 m_worldUserInfo = worldUserInfo; 109 116 } -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btRigidBody.cpp
r5781 r8351 20 20 #include "LinearMath/btMotionState.h" 21 21 #include "BulletDynamics/ConstraintSolver/btTypedConstraint.h" 22 #include "LinearMath/btSerializer.h" 22 23 23 24 //'temporarily' global variables … … 45 46 m_linearVelocity.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); 46 47 m_angularVelocity.setValue(btScalar(0.),btScalar(0.),btScalar(0.)); 47 m_angularFactor = btScalar(1.); 48 m_angularFactor.setValue(1,1,1); 49 m_linearFactor.setValue(1,1,1); 48 50 m_gravity.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); 49 51 m_gravity_acceleration.setValue(btScalar(0.0), btScalar(0.0), btScalar(0.0)); … … 86 88 updateInertiaTensor(); 87 89 90 m_rigidbodyFlags = 0; 91 92 93 m_deltaLinearVelocity.setZero(); 94 m_deltaAngularVelocity.setZero(); 95 m_invMass = m_inverseMass*m_linearFactor; 96 m_pushVelocity.setZero(); 97 m_turnVelocity.setZero(); 98 99 100 88 101 } 89 102 … … 136 149 void btRigidBody::setDamping(btScalar lin_damping, btScalar ang_damping) 137 150 { 138 m_linearDamping = GEN_clamped(lin_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));139 m_angularDamping = GEN_clamped(ang_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0));151 m_linearDamping = btClamped(lin_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0)); 152 m_angularDamping = btClamped(ang_damping, (btScalar)btScalar(0.0), (btScalar)btScalar(1.0)); 140 153 } 141 154 … … 227 240 m_inverseMass = btScalar(1.0) / mass; 228 241 } 242 243 //Fg = m * a 244 m_gravity = mass * m_gravity_acceleration; 229 245 230 246 m_invInertiaLocal.setValue(inertia.x() != btScalar(0.0) ? btScalar(1.0) / inertia.x(): btScalar(0.0), … … 232 248 inertia.z() != btScalar(0.0) ? btScalar(1.0) / inertia.z(): btScalar(0.0)); 233 249 250 m_invMass = m_linearFactor*m_inverseMass; 234 251 } 235 252 … … 301 318 } 302 319 320 void btRigidBody::internalWritebackVelocity(btScalar timeStep) 321 { 322 (void) timeStep; 323 if (m_inverseMass) 324 { 325 setLinearVelocity(getLinearVelocity()+ m_deltaLinearVelocity); 326 setAngularVelocity(getAngularVelocity()+m_deltaAngularVelocity); 327 328 //correct the position/orientation based on push/turn recovery 329 btTransform newTransform; 330 btTransformUtil::integrateTransform(getWorldTransform(),m_pushVelocity,m_turnVelocity,timeStep,newTransform); 331 setWorldTransform(newTransform); 332 //m_originalBody->setCompanionId(-1); 333 } 334 // m_deltaLinearVelocity.setZero(); 335 // m_deltaAngularVelocity .setZero(); 336 // m_pushVelocity.setZero(); 337 // m_turnVelocity.setZero(); 338 } 339 340 341 303 342 void btRigidBody::addConstraintRef(btTypedConstraint* c) 304 343 { … … 315 354 m_checkCollideWith = m_constraintRefs.size() > 0; 316 355 } 356 357 int btRigidBody::calculateSerializeBufferSize() const 358 { 359 int sz = sizeof(btRigidBodyData); 360 return sz; 361 } 362 363 ///fills the dataBuffer and returns the struct name (and 0 on failure) 364 const char* btRigidBody::serialize(void* dataBuffer, class btSerializer* serializer) const 365 { 366 btRigidBodyData* rbd = (btRigidBodyData*) dataBuffer; 367 368 btCollisionObject::serialize(&rbd->m_collisionObjectData, serializer); 369 370 m_invInertiaTensorWorld.serialize(rbd->m_invInertiaTensorWorld); 371 m_linearVelocity.serialize(rbd->m_linearVelocity); 372 m_angularVelocity.serialize(rbd->m_angularVelocity); 373 rbd->m_inverseMass = m_inverseMass; 374 m_angularFactor.serialize(rbd->m_angularFactor); 375 m_linearFactor.serialize(rbd->m_linearFactor); 376 m_gravity.serialize(rbd->m_gravity); 377 m_gravity_acceleration.serialize(rbd->m_gravity_acceleration); 378 m_invInertiaLocal.serialize(rbd->m_invInertiaLocal); 379 m_totalForce.serialize(rbd->m_totalForce); 380 m_totalTorque.serialize(rbd->m_totalTorque); 381 rbd->m_linearDamping = m_linearDamping; 382 rbd->m_angularDamping = m_angularDamping; 383 rbd->m_additionalDamping = m_additionalDamping; 384 rbd->m_additionalDampingFactor = m_additionalDampingFactor; 385 rbd->m_additionalLinearDampingThresholdSqr = m_additionalLinearDampingThresholdSqr; 386 rbd->m_additionalAngularDampingThresholdSqr = m_additionalAngularDampingThresholdSqr; 387 rbd->m_additionalAngularDampingFactor = m_additionalAngularDampingFactor; 388 rbd->m_linearSleepingThreshold=m_linearSleepingThreshold; 389 rbd->m_angularSleepingThreshold = m_angularSleepingThreshold; 390 391 return btRigidBodyDataName; 392 } 393 394 395 396 void btRigidBody::serializeSingleObject(class btSerializer* serializer) const 397 { 398 btChunk* chunk = serializer->allocate(calculateSerializeBufferSize(),1); 399 const char* structType = serialize(chunk->m_oldPtr, serializer); 400 serializer->finalizeChunk(chunk,structType,BT_RIGIDBODY_CODE,(void*)this); 401 } 402 403 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btRigidBody.h
r5781 r8351 29 29 extern btScalar gDeactivationTime; 30 30 extern bool gDisableDeactivation; 31 32 #ifdef BT_USE_DOUBLE_PRECISION 33 #define btRigidBodyData btRigidBodyDoubleData 34 #define btRigidBodyDataName "btRigidBodyDoubleData" 35 #else 36 #define btRigidBodyData btRigidBodyFloatData 37 #define btRigidBodyDataName "btRigidBodyFloatData" 38 #endif //BT_USE_DOUBLE_PRECISION 39 40 41 enum btRigidBodyFlags 42 { 43 BT_DISABLE_WORLD_GRAVITY = 1 44 }; 31 45 32 46 … … 46 60 btVector3 m_angularVelocity; 47 61 btScalar m_inverseMass; 48 bt Scalar m_angularFactor;62 btVector3 m_linearFactor; 49 63 50 64 btVector3 m_gravity; … … 72 86 //keep track of typed constraints referencing this rigid body 73 87 btAlignedObjectArray<btTypedConstraint*> m_constraintRefs; 88 89 int m_rigidbodyFlags; 90 91 int m_debugBodyId; 92 93 94 protected: 95 96 ATTRIBUTE_ALIGNED64(btVector3 m_deltaLinearVelocity); 97 btVector3 m_deltaAngularVelocity; 98 btVector3 m_angularFactor; 99 btVector3 m_invMass; 100 btVector3 m_pushVelocity; 101 btVector3 m_turnVelocity; 102 74 103 75 104 public: … … 111 140 btScalar m_additionalAngularDampingFactor; 112 141 113 114 142 btRigidBodyConstructionInfo( btScalar mass, btMotionState* motionState, btCollisionShape* collisionShape, const btVector3& localInertia=btVector3(0,0,0)): 115 143 m_mass(mass), … … 161 189 static const btRigidBody* upcast(const btCollisionObject* colObj) 162 190 { 163 if (colObj->getInternalType() ==btCollisionObject::CO_RIGID_BODY)191 if (colObj->getInternalType()&btCollisionObject::CO_RIGID_BODY) 164 192 return (const btRigidBody*)colObj; 165 193 return 0; … … 167 195 static btRigidBody* upcast(btCollisionObject* colObj) 168 196 { 169 if (colObj->getInternalType() ==btCollisionObject::CO_RIGID_BODY)197 if (colObj->getInternalType()&btCollisionObject::CO_RIGID_BODY) 170 198 return (btRigidBody*)colObj; 171 199 return 0; … … 220 248 void setMassProps(btScalar mass, const btVector3& inertia); 221 249 250 const btVector3& getLinearFactor() const 251 { 252 return m_linearFactor; 253 } 254 void setLinearFactor(const btVector3& linearFactor) 255 { 256 m_linearFactor = linearFactor; 257 m_invMass = m_linearFactor*m_inverseMass; 258 } 222 259 btScalar getInvMass() const { return m_inverseMass; } 223 260 const btMatrix3x3& getInvInertiaTensorWorld() const { … … 231 268 void applyCentralForce(const btVector3& force) 232 269 { 233 m_totalForce += force ;270 m_totalForce += force*m_linearFactor; 234 271 } 235 272 … … 262 299 void applyTorque(const btVector3& torque) 263 300 { 264 m_totalTorque += torque ;301 m_totalTorque += torque*m_angularFactor; 265 302 } 266 303 … … 268 305 { 269 306 applyCentralForce(force); 270 applyTorque(rel_pos.cross(force )*m_angularFactor);307 applyTorque(rel_pos.cross(force*m_linearFactor)); 271 308 } 272 309 273 310 void applyCentralImpulse(const btVector3& impulse) 274 311 { 275 m_linearVelocity += impulse * m_inverseMass;312 m_linearVelocity += impulse *m_linearFactor * m_inverseMass; 276 313 } 277 314 278 315 void applyTorqueImpulse(const btVector3& torque) 279 316 { 280 m_angularVelocity += m_invInertiaTensorWorld * torque ;317 m_angularVelocity += m_invInertiaTensorWorld * torque * m_angularFactor; 281 318 } 282 319 … … 288 325 if (m_angularFactor) 289 326 { 290 applyTorqueImpulse(rel_pos.cross(impulse )*m_angularFactor);327 applyTorqueImpulse(rel_pos.cross(impulse*m_linearFactor)); 291 328 } 292 329 } 293 330 } 294 331 295 //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position296 SIMD_FORCE_INLINE void internalApplyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude)297 {298 if (m_inverseMass != btScalar(0.))299 {300 m_linearVelocity += linearComponent*impulseMagnitude;301 if (m_angularFactor)302 {303 m_angularVelocity += angularComponent*impulseMagnitude*m_angularFactor;304 }305 }306 }307 308 332 void clearForces() 309 333 { … … 451 475 int m_frictionSolverType; 452 476 477 void setAngularFactor(const btVector3& angFac) 478 { 479 m_angularFactor = angFac; 480 } 481 453 482 void setAngularFactor(btScalar angFac) 454 483 { 455 m_angularFactor = angFac;456 } 457 btScalargetAngularFactor() const484 m_angularFactor.setValue(angFac,angFac,angFac); 485 } 486 const btVector3& getAngularFactor() const 458 487 { 459 488 return m_angularFactor; … … 481 510 } 482 511 483 int m_debugBodyId; 512 void setFlags(int flags) 513 { 514 m_rigidbodyFlags = flags; 515 } 516 517 int getFlags() const 518 { 519 return m_rigidbodyFlags; 520 } 521 522 const btVector3& getDeltaLinearVelocity() const 523 { 524 return m_deltaLinearVelocity; 525 } 526 527 const btVector3& getDeltaAngularVelocity() const 528 { 529 return m_deltaAngularVelocity; 530 } 531 532 const btVector3& getPushVelocity() const 533 { 534 return m_pushVelocity; 535 } 536 537 const btVector3& getTurnVelocity() const 538 { 539 return m_turnVelocity; 540 } 541 542 543 //////////////////////////////////////////////// 544 ///some internal methods, don't use them 545 546 btVector3& internalGetDeltaLinearVelocity() 547 { 548 return m_deltaLinearVelocity; 549 } 550 551 btVector3& internalGetDeltaAngularVelocity() 552 { 553 return m_deltaAngularVelocity; 554 } 555 556 const btVector3& internalGetAngularFactor() const 557 { 558 return m_angularFactor; 559 } 560 561 const btVector3& internalGetInvMass() const 562 { 563 return m_invMass; 564 } 565 566 btVector3& internalGetPushVelocity() 567 { 568 return m_pushVelocity; 569 } 570 571 btVector3& internalGetTurnVelocity() 572 { 573 return m_turnVelocity; 574 } 575 576 SIMD_FORCE_INLINE void internalGetVelocityInLocalPointObsolete(const btVector3& rel_pos, btVector3& velocity ) const 577 { 578 velocity = getLinearVelocity()+m_deltaLinearVelocity + (getAngularVelocity()+m_deltaAngularVelocity).cross(rel_pos); 579 } 580 581 SIMD_FORCE_INLINE void internalGetAngularVelocity(btVector3& angVel) const 582 { 583 angVel = getAngularVelocity()+m_deltaAngularVelocity; 584 } 585 586 587 //Optimization for the iterative solver: avoid calculating constant terms involving inertia, normal, relative position 588 SIMD_FORCE_INLINE void internalApplyImpulse(const btVector3& linearComponent, const btVector3& angularComponent,const btScalar impulseMagnitude) 589 { 590 if (m_inverseMass) 591 { 592 m_deltaLinearVelocity += linearComponent*impulseMagnitude; 593 m_deltaAngularVelocity += angularComponent*(impulseMagnitude*m_angularFactor); 594 } 595 } 596 597 SIMD_FORCE_INLINE void internalApplyPushImpulse(const btVector3& linearComponent, const btVector3& angularComponent,btScalar impulseMagnitude) 598 { 599 if (m_inverseMass) 600 { 601 m_pushVelocity += linearComponent*impulseMagnitude; 602 m_turnVelocity += angularComponent*(impulseMagnitude*m_angularFactor); 603 } 604 } 605 606 void internalWritebackVelocity() 607 { 608 if (m_inverseMass) 609 { 610 setLinearVelocity(getLinearVelocity()+ m_deltaLinearVelocity); 611 setAngularVelocity(getAngularVelocity()+m_deltaAngularVelocity); 612 //m_deltaLinearVelocity.setZero(); 613 //m_deltaAngularVelocity .setZero(); 614 //m_originalBody->setCompanionId(-1); 615 } 616 } 617 618 619 void internalWritebackVelocity(btScalar timeStep); 620 621 622 /////////////////////////////////////////////// 623 624 virtual int calculateSerializeBufferSize() const; 625 626 ///fills the dataBuffer and returns the struct name (and 0 on failure) 627 virtual const char* serialize(void* dataBuffer, class btSerializer* serializer) const; 628 629 virtual void serializeSingleObject(class btSerializer* serializer) const; 630 484 631 }; 485 632 633 //@todo add m_optionalMotionState and m_constraintRefs to btRigidBodyData 634 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 635 struct btRigidBodyFloatData 636 { 637 btCollisionObjectFloatData m_collisionObjectData; 638 btMatrix3x3FloatData m_invInertiaTensorWorld; 639 btVector3FloatData m_linearVelocity; 640 btVector3FloatData m_angularVelocity; 641 btVector3FloatData m_angularFactor; 642 btVector3FloatData m_linearFactor; 643 btVector3FloatData m_gravity; 644 btVector3FloatData m_gravity_acceleration; 645 btVector3FloatData m_invInertiaLocal; 646 btVector3FloatData m_totalForce; 647 btVector3FloatData m_totalTorque; 648 float m_inverseMass; 649 float m_linearDamping; 650 float m_angularDamping; 651 float m_additionalDampingFactor; 652 float m_additionalLinearDampingThresholdSqr; 653 float m_additionalAngularDampingThresholdSqr; 654 float m_additionalAngularDampingFactor; 655 float m_linearSleepingThreshold; 656 float m_angularSleepingThreshold; 657 int m_additionalDamping; 658 }; 659 660 ///do not change those serialization structures, it requires an updated sBulletDNAstr/sBulletDNAstr64 661 struct btRigidBodyDoubleData 662 { 663 btCollisionObjectDoubleData m_collisionObjectData; 664 btMatrix3x3DoubleData m_invInertiaTensorWorld; 665 btVector3DoubleData m_linearVelocity; 666 btVector3DoubleData m_angularVelocity; 667 btVector3DoubleData m_angularFactor; 668 btVector3DoubleData m_linearFactor; 669 btVector3DoubleData m_gravity; 670 btVector3DoubleData m_gravity_acceleration; 671 btVector3DoubleData m_invInertiaLocal; 672 btVector3DoubleData m_totalForce; 673 btVector3DoubleData m_totalTorque; 674 double m_inverseMass; 675 double m_linearDamping; 676 double m_angularDamping; 677 double m_additionalDampingFactor; 678 double m_additionalLinearDampingThresholdSqr; 679 double m_additionalAngularDampingThresholdSqr; 680 double m_additionalAngularDampingFactor; 681 double m_linearSleepingThreshold; 682 double m_angularSleepingThreshold; 683 int m_additionalDamping; 684 char m_padding[4]; 685 }; 686 486 687 487 688 -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.cpp
r5781 r8351 133 133 void btSimpleDynamicsWorld::removeRigidBody(btRigidBody* body) 134 134 { 135 removeCollisionObject(body); 136 } 135 btCollisionWorld::removeCollisionObject(body); 136 } 137 138 void btSimpleDynamicsWorld::removeCollisionObject(btCollisionObject* collisionObject) 139 { 140 btRigidBody* body = btRigidBody::upcast(collisionObject); 141 if (body) 142 removeRigidBody(body); 143 else 144 btCollisionWorld::removeCollisionObject(collisionObject); 145 } 146 137 147 138 148 void btSimpleDynamicsWorld::addRigidBody(btRigidBody* body) -
code/trunk/src/external/bullet/BulletDynamics/Dynamics/btSimpleDynamicsWorld.h
r5781 r8351 58 58 59 59 virtual void removeRigidBody(btRigidBody* body); 60 61 ///removeCollisionObject will first check if it is a rigid body, if so call removeRigidBody otherwise call btCollisionWorld::removeCollisionObject 62 virtual void removeCollisionObject(btCollisionObject* collisionObject); 60 63 61 64 virtual void updateAabbs(); -
code/trunk/src/external/bullet/BulletDynamics/Vehicle/btRaycastVehicle.cpp
r5781 r8351 23 23 #include "BulletDynamics/ConstraintSolver/btContactConstraint.h" 24 24 25 static btRigidBody s_fixedObject( 0,0,0); 25 btRigidBody& btActionInterface::getFixedBody() 26 { 27 static btRigidBody s_fixed(0, 0,0); 28 s_fixed.setMassProps(btScalar(0.),btVector3(btScalar(0.),btScalar(0.),btScalar(0.))); 29 return s_fixed; 30 } 26 31 27 32 btRaycastVehicle::btRaycastVehicle(const btVehicleTuning& tuning,btRigidBody* chassis, btVehicleRaycaster* raycaster ) … … 71 76 ci.m_bIsFrontWheel = isFrontWheel; 72 77 ci.m_maxSuspensionTravelCm = tuning.m_maxSuspensionTravelCm; 78 ci.m_maxSuspensionForce = tuning.m_maxSuspensionForce; 73 79 74 80 m_wheelInfo.push_back( btWheelInfo(ci)); … … 187 193 wheel.m_raycastInfo.m_isInContact = true; 188 194 189 wheel.m_raycastInfo.m_groundObject = & s_fixedObject;///@todo for driving on dynamic/movable objects!;195 wheel.m_raycastInfo.m_groundObject = &getFixedBody();///@todo for driving on dynamic/movable objects!; 190 196 //wheel.m_raycastInfo.m_groundObject = object; 191 197 … … 302 308 btScalar suspensionForce = wheel.m_wheelsSuspensionForce; 303 309 304 btScalar gMaxSuspensionForce = btScalar(6000.); 305 if (suspensionForce > gMaxSuspensionForce) 306 { 307 suspensionForce = gMaxSuspensionForce; 310 if (suspensionForce > wheel.m_maxSuspensionForce) 311 { 312 suspensionForce = wheel.m_maxSuspensionForce; 308 313 } 309 314 btVector3 impulse = wheel.m_raycastInfo.m_contactNormalWS * suspensionForce * step; … … 690 695 btVector3 sideImp = m_axle[wheel] * m_sideImpulse[wheel]; 691 696 692 rel_pos[m_index ForwardAxis] *= wheelInfo.m_rollInfluence;697 rel_pos[m_indexUpAxis] *= wheelInfo.m_rollInfluence; 693 698 m_chassisBody->applyImpulse(sideImp,rel_pos); 694 699 … … 709 714 for (int v=0;v<this->getNumWheels();v++) 710 715 { 711 btVector3 wheelColor(0, 255,255);716 btVector3 wheelColor(0,1,1); 712 717 if (getWheelInfo(v).m_raycastInfo.m_isInContact) 713 718 { 714 wheelColor.setValue(0,0, 255);719 wheelColor.setValue(0,0,1); 715 720 } else 716 721 { 717 wheelColor.setValue( 255,0,255);722 wheelColor.setValue(1,0,1); 718 723 } 719 724 -
code/trunk/src/external/bullet/BulletDynamics/Vehicle/btRaycastVehicle.h
r5781 r8351 30 30 btAlignedObjectArray<btScalar> m_forwardImpulse; 31 31 btAlignedObjectArray<btScalar> m_sideImpulse; 32 33 ///backwards compatibility 34 int m_userConstraintType; 35 int m_userConstraintId; 32 36 33 37 public: … … 41 45 m_suspensionDamping(btScalar(0.88)), 42 46 m_maxSuspensionTravelCm(btScalar(500.)), 43 m_frictionSlip(btScalar(10.5)) 47 m_frictionSlip(btScalar(10.5)), 48 m_maxSuspensionForce(btScalar(6000.)) 44 49 { 45 50 } … … 49 54 btScalar m_maxSuspensionTravelCm; 50 55 btScalar m_frictionSlip; 56 btScalar m_maxSuspensionForce; 51 57 52 58 }; … … 79 85 virtual void updateAction( btCollisionWorld* collisionWorld, btScalar step) 80 86 { 87 (void) collisionWorld; 81 88 updateVehicle(step); 82 89 } … … 189 196 190 197 198 ///backwards compatibility 199 int getUserConstraintType() const 200 { 201 return m_userConstraintType ; 202 } 203 204 void setUserConstraintType(int userConstraintType) 205 { 206 m_userConstraintType = userConstraintType; 207 }; 208 209 void setUserConstraintId(int uid) 210 { 211 m_userConstraintId = uid; 212 } 213 214 int getUserConstraintId() const 215 { 216 return m_userConstraintId; 217 } 191 218 192 219 }; -
code/trunk/src/external/bullet/BulletDynamics/Vehicle/btWheelInfo.h
r5781 r8351 30 30 btScalar m_wheelsDampingRelaxation; 31 31 btScalar m_frictionSlip; 32 btScalar m_maxSuspensionForce; 32 33 bool m_bIsFrontWheel; 33 34 … … 69 70 btScalar m_deltaRotation; 70 71 btScalar m_rollInfluence; 72 btScalar m_maxSuspensionForce; 71 73 72 74 btScalar m_engineForce; … … 100 102 m_rollInfluence = btScalar(0.1); 101 103 m_bIsFrontWheel = ci.m_bIsFrontWheel; 104 m_maxSuspensionForce = ci.m_maxSuspensionForce; 102 105 103 106 } -
code/trunk/src/external/bullet/BulletLicense.txt
r5781 r8351 1 1 /* 2 Copyright (c) 2003-20 06Erwin Coumans http://continuousphysics.com/Bullet/2 Copyright (c) 2003-2010 Erwin Coumans http://continuousphysics.com/Bullet/ 3 3 4 4 This software is provided 'as-is', without any express or implied warranty. … … 14 14 15 15 16 Free for commercial use, but please mail bullet@erwincoumans.com to report projects, and join the forum at 17 www.continuousphysics.com/Bullet/phpBB2 16 Free for commercial use, please report projects in the forum at http://www.bulletphysics.org 17 18 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 -
code/trunk/src/external/bullet/CMakeLists.txt
r5929 r8351 31 31 NO_DLL_INTERFACE 32 32 VERSION 33 2.7 433 2.77 34 34 SOURCE_FILES 35 35 ${BULLET_FILES} -
code/trunk/src/external/bullet/ChangeLog
r5781 r8351 2 2 Primary author and maintainer: Erwin Coumans 3 3 4 Todo: update changelog from April - July 2008 5 See http://code.google.com/p/bullet/source/list for more complete log in Subversion 4 This ChangeLog is incomplete, for an up-to-date list of all fixed issues see http://bullet.googlecode.com 5 using http://tinyurl.com/yabmjjj 6 7 8 2010 September 21 9 - Bullet 2.77 release based on revision 2218 10 - Added Visual Studio project files for OpenCL and Direct Compute in msvc folder 11 12 2010 September 7 13 - autotools now uses CamelCase naming for libraryes just like cmake: 14 libbulletdynamics -> libBulletDynamics, libbulletmath -> libLinearMath 15 16 2010 July 21 17 - Preparing for Bullet 2.77 release, around revision r2135 18 - Added an OpenCL particle demo, running on NVidia, AMD and MiniCL 19 Thanks to NVidia for the original particle demo from their OpenCL SDK 20 - Added GPU deformable object solvers for OpenCL and DirectCompute, and a DirectX 11 cloth demo 21 Thanks to AMD 22 - Create a separate library for MiniCL, 23 MiniCL is a rudimentary OpenCL wrapper that allows to compile OpenCL kernels for multi-core CPU, using Win32 Threads or Posix 24 - Moved vectormath into Bullet/src, and added a SSE implementation 25 - Added a btParallelConstraintSolver, mainly for PlayStation 3 Cell SPUs (although it runs fine on CPU too) 26 27 2010 March 6 28 - Dynamica Maya plugin (and COLLADA support) is moved to http://dynamica.googlecode.com 29 30 2010 February 31 - Bullet 2.76 release, revision 2010 32 - support for the .bullet binary file format 33 - btInternalEdgeUtility to adjust unwanted collisions against internal triangle edges 34 - Improved Maya Dynamica plugin with better constraint authoring and .bullet file export 35 36 37 2009 September 17 38 - Minor update to Bullet 2.75 release, revision 1776 39 - Support for btConvex2dShape, check out Bullet/Demos/Box2dDemo 40 - Fixes in build systems 41 - Minor fix in btGjkPairDetector 42 - Initialize world transform for btCollisionShape in constructor 43 44 45 2009 September 6 46 - Bullet 2.75 release 47 - Added SPH fluid simulation in Extras, not integrated with rigid body / soft body yet 48 Thanks to Rama Hoetzlein to make this contribution available under the ZLib license 49 - add special capsule-capsule collider code in btConvexConvexCollisionAlgorithm, to speed up capsule-ragdolls 50 - soft body improvement: faster building of bending constraints 51 - soft body improvement: allow to disable/enable cluster self-collision 52 - soft body fix: 'exploding' soft bodies when using cluster collision 53 - fix some degenerate cases in continuous convex cast, could impact ray cast/convex cast 54 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 55 - re-enabled split impulse 56 - added btHinge2Constraint, btUniversalConstraint, btGeneric6DofSpringConstraint 57 - demonstrate 2D physics with 2D/3D object interaction 58 59 60 2008 December 2 61 - Fix contact refresh issues with btCompoundShape, introduced with btDbvt acceleration structure in btCompoundCollisionAlgorithm 62 - Made btSequentialImpulseConstraintSolver 100% compatible with ODE quickstep 63 constraints can use 'solveConstraint' method or 'getInfo/getInfo2' 64 65 2008 November 30 66 - Add highly optimized SIMD branchless PGS/SI solver innerloop 6 67 7 68 2008 November 12 -
code/trunk/src/external/bullet/LinearMath/CMakeLists.txt
r5929 r8351 2 2 3 3 COMPILATION_BEGIN BulletLinearMathCompilation.cpp 4 btConvexHull.cpp 5 btQuickprof.cpp 6 btGeometryUtil.cpp 7 btAlignedAllocator.cpp 4 btAlignedAllocator.cpp 5 btConvexHull.cpp 6 btGeometryUtil.cpp 7 btQuickprof.cpp 8 btSerializer.cpp 8 9 COMPILATION_END 9 10 10 # Headers 11 btAlignedObjectArray.h 12 btList.h 13 btPoolAllocator.h 14 btRandom.h 15 btVector3.h 16 btDefaultMotionState.h 17 btMatrix3x3.h 18 btQuadWord.h 19 btHashMap.h 20 btScalar.h 21 btAabbUtil2.h 22 btConvexHull.h 23 btMinMax.h 24 btQuaternion.h 25 btStackAlloc.h 26 btGeometryUtil.h 27 btMotionState.h 28 btTransform.h 29 btAlignedAllocator.h 30 btIDebugDraw.h 31 btQuickprof.h 32 btTransformUtil.h 11 # Headers 12 btAabbUtil2.h 13 btAlignedAllocator.h 14 btAlignedObjectArray.h 15 btConvexHull.h 16 btDefaultMotionState.h 17 btGeometryUtil.h 18 btHashMap.h 19 btIDebugDraw.h 20 btList.h 21 btMatrix3x3.h 22 btMinMax.h 23 btMotionState.h 24 btPoolAllocator.h 25 btQuadWord.h 26 btQuaternion.h 27 btQuickprof.h 28 btRandom.h 29 btScalar.h 30 btSerializer.h 31 btStackAlloc.h 32 btTransform.h 33 btTransformUtil.h 34 btVector3.h 33 35 ) -
code/trunk/src/external/bullet/LinearMath/btAlignedAllocator.cpp
r5781 r8351 161 161 { 162 162 gNumAlignedAllocs++; 163 void* ptr; 164 #if defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__) 163 void* ptr; 165 164 ptr = sAlignedAllocFunc(size, alignment); 166 #else167 char *real;168 unsigned long offset;169 170 real = (char *)sAllocFunc(size + sizeof(void *) + (alignment-1));171 if (real) {172 offset = (alignment - (unsigned long)(real + sizeof(void *))) & (alignment-1);173 ptr = (void *)((real + sizeof(void *)) + offset);174 *((void **)(ptr)-1) = (void *)(real);175 } else {176 ptr = (void *)(real);177 }178 #endif // defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)179 165 // printf("btAlignedAllocInternal %d, %x\n",size,ptr); 180 166 return ptr; … … 190 176 gNumAlignedFree++; 191 177 // printf("btAlignedFreeInternal %x\n",ptr); 192 #if defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)193 178 sAlignedFreeFunc(ptr); 194 #else195 void* real;196 197 if (ptr) {198 real = *((void **)(ptr)-1);199 sFreeFunc(real);200 }201 #endif // defined (BT_HAS_ALIGNED_ALLOCATOR) || defined(__CELLOS_LV2__)202 179 } 203 180 -
code/trunk/src/external/bullet/LinearMath/btAlignedObjectArray.h
r5781 r8351 139 139 } 140 140 141 SIMD_FORCE_INLINE const T& at(int n) const 142 { 143 return m_data[n]; 144 } 145 146 SIMD_FORCE_INLINE T& at(int n) 147 { 148 return m_data[n]; 149 } 150 141 151 SIMD_FORCE_INLINE const T& operator[](int n) const 142 152 { … … 172 182 int curSize = size(); 173 183 174 if (newsize < size())175 { 176 for(int i = curSize; i < newsize; i++)184 if (newsize < curSize) 185 { 186 for(int i = newsize; i < curSize; i++) 177 187 { 178 188 m_data[i].~T(); … … 196 206 } 197 207 208 SIMD_FORCE_INLINE T& expandNonInitializing( ) 209 { 210 int sz = size(); 211 if( sz == capacity() ) 212 { 213 reserve( allocSize(size()) ); 214 } 215 m_size++; 216 217 return m_data[sz]; 218 } 219 198 220 199 221 SIMD_FORCE_INLINE T& expand( const T& fillValue=T()) … … 438 460 } 439 461 462 void copyFromArray(const btAlignedObjectArray& otherArray) 463 { 464 int otherSize = otherArray.size(); 465 resize (otherSize); 466 otherArray.copy(0, otherSize, m_data); 467 } 468 440 469 }; 441 470 -
code/trunk/src/external/bullet/LinearMath/btConvexHull.cpp
r5781 r8351 17 17 18 18 #include "btConvexHull.h" 19 #include " LinearMath/btAlignedObjectArray.h"20 #include " LinearMath/btMinMax.h"21 #include " LinearMath/btVector3.h"19 #include "btAlignedObjectArray.h" 20 #include "btMinMax.h" 21 #include "btVector3.h" 22 22 23 23 … … 97 97 static btVector3 dif; 98 98 dif = p1-p0; 99 btScalar dn= dot(plane.normal,dif);100 btScalar t = -(plane.dist+ dot(plane.normal,p0) )/dn;99 btScalar dn= btDot(plane.normal,dif); 100 btScalar t = -(plane.dist+btDot(plane.normal,p0) )/dn; 101 101 return p0 + (dif*t); 102 102 } … … 104 104 btVector3 PlaneProject(const btPlane &plane, const btVector3 &point) 105 105 { 106 return point - plane.normal * ( dot(point,plane.normal)+plane.dist);106 return point - plane.normal * (btDot(point,plane.normal)+plane.dist); 107 107 } 108 108 … … 111 111 // return the normal of the triangle 112 112 // inscribed by v0, v1, and v2 113 btVector3 cp= cross(v1-v0,v2-v1);113 btVector3 cp=btCross(v1-v0,v2-v1); 114 114 btScalar m=cp.length(); 115 115 if(m==0) return btVector3(1,0,0); … … 121 121 { 122 122 static btVector3 cp; 123 cp = cross(udir,vdir).normalized();124 125 btScalar distu = - dot(cp,ustart);126 btScalar distv = - dot(cp,vstart);123 cp = btCross(udir,vdir).normalized(); 124 125 btScalar distu = -btDot(cp,ustart); 126 btScalar distv = -btDot(cp,vstart); 127 127 btScalar dist = (btScalar)fabs(distu-distv); 128 128 if(upoint) 129 129 { 130 130 btPlane plane; 131 plane.normal = cross(vdir,cp).normalized();132 plane.dist = - dot(plane.normal,vstart);131 plane.normal = btCross(vdir,cp).normalized(); 132 plane.dist = -btDot(plane.normal,vstart); 133 133 *upoint = PlaneLineIntersection(plane,ustart,ustart+udir); 134 134 } … … 136 136 { 137 137 btPlane plane; 138 plane.normal = cross(udir,cp).normalized();139 plane.dist = - dot(plane.normal,ustart);138 plane.normal = btCross(udir,cp).normalized(); 139 plane.dist = -btDot(plane.normal,ustart); 140 140 *vpoint = PlaneLineIntersection(plane,vstart,vstart+vdir); 141 141 } … … 171 171 int PlaneTest(const btPlane &p, const btVector3 &v); 172 172 int PlaneTest(const btPlane &p, const btVector3 &v) { 173 btScalar a = dot(v,p.normal)+p.dist;173 btScalar a = btDot(v,p.normal)+p.dist; 174 174 int flag = (a>planetestepsilon)?OVER:((a<-planetestepsilon)?UNDER:COPLANAR); 175 175 return flag; … … 229 229 if(allow[i]) 230 230 { 231 if(m==-1 || dot(p[i],dir)>dot(p[m],dir))231 if(m==-1 || btDot(p[i],dir)>btDot(p[m],dir)) 232 232 m=i; 233 233 } … … 239 239 btVector3 orth(const btVector3 &v) 240 240 { 241 btVector3 a= cross(v,btVector3(0,0,1));242 btVector3 b= cross(v,btVector3(0,1,0));241 btVector3 a=btCross(v,btVector3(0,0,1)); 242 btVector3 b=btCross(v,btVector3(0,1,0)); 243 243 if (a.length() > b.length()) 244 244 { … … 259 259 if(allow[m]==3) return m; 260 260 T u = orth(dir); 261 T v = cross(u,dir);261 T v = btCross(u,dir); 262 262 int ma=-1; 263 263 for(btScalar x = btScalar(0.0) ; x<= btScalar(360.0) ; x+= btScalar(45.0)) … … 314 314 { 315 315 btVector3 n=TriNormal(vertices[t[0]],vertices[t[1]],vertices[t[2]]); 316 return ( dot(n,p-vertices[t[0]]) > epsilon); // EPSILON???316 return (btDot(n,p-vertices[t[0]]) > epsilon); // EPSILON??? 317 317 } 318 318 int hasedge(const int3 &t, int a,int b); … … 496 496 if(p0==p1 || basis[0]==btVector3(0,0,0)) 497 497 return int4(-1,-1,-1,-1); 498 basis[1] = cross(btVector3( btScalar(1),btScalar(0.02), btScalar(0)),basis[0]);499 basis[2] = cross(btVector3(btScalar(-0.02), btScalar(1), btScalar(0)),basis[0]);498 basis[1] = btCross(btVector3( btScalar(1),btScalar(0.02), btScalar(0)),basis[0]); 499 basis[2] = btCross(btVector3(btScalar(-0.02), btScalar(1), btScalar(0)),basis[0]); 500 500 if (basis[1].length() > basis[2].length()) 501 501 { … … 513 513 return int4(-1,-1,-1,-1); 514 514 basis[1] = verts[p2] - verts[p0]; 515 basis[2] = cross(basis[1],basis[0]).normalized();515 basis[2] = btCross(basis[1],basis[0]).normalized(); 516 516 int p3 = maxdirsterid(verts,verts_count,basis[2],allow); 517 517 if(p3==p0||p3==p1||p3==p2) p3 = maxdirsterid(verts,verts_count,-basis[2],allow); … … 519 519 return int4(-1,-1,-1,-1); 520 520 btAssert(!(p0==p1||p0==p2||p0==p3||p1==p2||p1==p3||p2==p3)); 521 if( dot(verts[p3]-verts[p0],cross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {Swap(p2,p3);}521 if(btDot(verts[p3]-verts[p0],btCross(verts[p1]-verts[p0],verts[p2]-verts[p0])) <0) {Swap(p2,p3);} 522 522 return int4(p0,p1,p2,p3); 523 523 } … … 565 565 btVector3 n=TriNormal(verts[(*t)[0]],verts[(*t)[1]],verts[(*t)[2]]); 566 566 t->vmax = maxdirsterid(verts,verts_count,n,allow); 567 t->rise = dot(n,verts[t->vmax]-verts[(*t)[0]]);567 t->rise = btDot(n,verts[t->vmax]-verts[(*t)[0]]); 568 568 } 569 569 btHullTriangle *te; … … 593 593 if(!hasvert(*m_tris[j],v)) break; 594 594 int3 nt=*m_tris[j]; 595 if(above(verts,nt,center,btScalar(0.01)*epsilon) || cross(verts[nt[1]]-verts[nt[0]],verts[nt[2]]-verts[nt[1]]).length()< epsilon*epsilon*btScalar(0.1) )595 if(above(verts,nt,center,btScalar(0.01)*epsilon) || btCross(verts[nt[1]]-verts[nt[0]],verts[nt[2]]-verts[nt[1]]).length()< epsilon*epsilon*btScalar(0.1) ) 596 596 { 597 597 btHullTriangle *nb = m_tris[m_tris[j]->n[0]]; … … 615 615 else 616 616 { 617 t->rise = dot(n,verts[t->vmax]-verts[(*t)[0]]);617 t->rise = btDot(n,verts[t->vmax]-verts[(*t)[0]]); 618 618 } 619 619 } … … 877 877 vcount = 0; 878 878 879 btScalar recip[3] ;879 btScalar recip[3]={0.f,0.f,0.f}; 880 880 881 881 if ( scale ) … … 1012 1012 btScalar z = v[2]; 1013 1013 1014 btScalar dx = fabsf(x - px );1015 btScalar dy = fabsf(y - py );1016 btScalar dz = fabsf(z - pz );1014 btScalar dx = btFabs(x - px ); 1015 btScalar dy = btFabs(y - py ); 1016 btScalar dz = btFabs(z - pz ); 1017 1017 1018 1018 if ( dx < normalepsilon && dy < normalepsilon && dz < normalepsilon ) … … 1136 1136 ocount = 0; 1137 1137 1138 for (i=0; i<in dexcount; i++)1138 for (i=0; i<int (indexcount); i++) 1139 1139 { 1140 1140 unsigned int v = indices[i]; // original array index … … 1157 1157 for (int k=0;k<m_vertexIndexMapping.size();k++) 1158 1158 { 1159 if (tmpIndices[k]== v)1159 if (tmpIndices[k]==int(v)) 1160 1160 m_vertexIndexMapping[k]=ocount; 1161 1161 } -
code/trunk/src/external/bullet/LinearMath/btConvexHull.h
r5781 r8351 20 20 #define CD_HULL_H 21 21 22 #include " LinearMath/btVector3.h"23 #include " LinearMath/btAlignedObjectArray.h"22 #include "btVector3.h" 23 #include "btAlignedObjectArray.h" 24 24 25 25 typedef btAlignedObjectArray<unsigned int> TUIntArray; -
code/trunk/src/external/bullet/LinearMath/btDefaultMotionState.h
r5781 r8351 1 1 #ifndef DEFAULT_MOTION_STATE_H 2 2 #define DEFAULT_MOTION_STATE_H 3 4 #include "btMotionState.h" 3 5 4 6 ///The btDefaultMotionState provides a common implementation to synchronize world transforms with offsets. -
code/trunk/src/external/bullet/LinearMath/btHashMap.h
r5781 r8351 4 4 #include "btAlignedObjectArray.h" 5 5 6 ///very basic hashable string implementation, compatible with btHashMap 7 struct btHashString 8 { 9 const char* m_string; 10 unsigned int m_hash; 11 12 SIMD_FORCE_INLINE unsigned int getHash()const 13 { 14 return m_hash; 15 } 16 17 btHashString(const char* name) 18 :m_string(name) 19 { 20 /* magic numbers from http://www.isthe.com/chongo/tech/comp/fnv/ */ 21 static const unsigned int InitialFNV = 2166136261u; 22 static const unsigned int FNVMultiple = 16777619u; 23 24 /* Fowler / Noll / Vo (FNV) Hash */ 25 unsigned int hash = InitialFNV; 26 27 for(int i = 0; m_string[i]; i++) 28 { 29 hash = hash ^ (m_string[i]); /* xor the low 8 bits */ 30 hash = hash * FNVMultiple; /* multiply by the magic number */ 31 } 32 m_hash = hash; 33 } 34 35 int portableStringCompare(const char* src, const char* dst) const 36 { 37 int ret = 0 ; 38 39 while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst) 40 ++src, ++dst; 41 42 if ( ret < 0 ) 43 ret = -1 ; 44 else if ( ret > 0 ) 45 ret = 1 ; 46 47 return( ret ); 48 } 49 50 bool equals(const btHashString& other) const 51 { 52 return (m_string == other.m_string) || 53 (0==portableStringCompare(m_string,other.m_string)); 54 55 } 56 57 }; 58 6 59 const int BT_HASH_NULL=0xffffffff; 60 61 62 class btHashInt 63 { 64 int m_uid; 65 public: 66 btHashInt(int uid) :m_uid(uid) 67 { 68 } 69 70 int getUid1() const 71 { 72 return m_uid; 73 } 74 75 void setUid1(int uid) 76 { 77 m_uid = uid; 78 } 79 80 bool equals(const btHashInt& other) const 81 { 82 return getUid1() == other.getUid1(); 83 } 84 //to our success 85 SIMD_FORCE_INLINE unsigned int getHash()const 86 { 87 int key = m_uid; 88 // Thomas Wang's hash 89 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); 90 return key; 91 } 92 }; 93 94 95 96 class btHashPtr 97 { 98 99 union 100 { 101 const void* m_pointer; 102 int m_hashValues[2]; 103 }; 104 105 public: 106 107 btHashPtr(const void* ptr) 108 :m_pointer(ptr) 109 { 110 } 111 112 const void* getPointer() const 113 { 114 return m_pointer; 115 } 116 117 bool equals(const btHashPtr& other) const 118 { 119 return getPointer() == other.getPointer(); 120 } 121 122 //to our success 123 SIMD_FORCE_INLINE unsigned int getHash()const 124 { 125 const bool VOID_IS_8 = ((sizeof(void*)==8)); 126 127 int key = VOID_IS_8? m_hashValues[0]+m_hashValues[1] : m_hashValues[0]; 128 129 // Thomas Wang's hash 130 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); 131 return key; 132 } 133 134 135 }; 136 137 138 template <class Value> 139 class btHashKeyPtr 140 { 141 int m_uid; 142 public: 143 144 btHashKeyPtr(int uid) :m_uid(uid) 145 { 146 } 147 148 int getUid1() const 149 { 150 return m_uid; 151 } 152 153 bool equals(const btHashKeyPtr<Value>& other) const 154 { 155 return getUid1() == other.getUid1(); 156 } 157 158 //to our success 159 SIMD_FORCE_INLINE unsigned int getHash()const 160 { 161 int key = m_uid; 162 // Thomas Wang's hash 163 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); 164 return key; 165 } 166 167 168 }; 169 7 170 8 171 template <class Value> … … 12 175 public: 13 176 14 btHashKey(int uid) 15 :m_uid(uid) 16 { 17 } 18 19 int getUid() const 177 btHashKey(int uid) :m_uid(uid) 178 { 179 } 180 181 int getUid1() const 20 182 { 21 183 return m_uid; 22 184 } 23 185 186 bool equals(const btHashKey<Value>& other) const 187 { 188 return getUid1() == other.getUid1(); 189 } 24 190 //to our success 25 191 SIMD_FORCE_INLINE unsigned int getHash()const … … 27 193 int key = m_uid; 28 194 // Thomas Wang's hash 29 key += ~(key << 15); 30 key ^= (key >> 10); 31 key += (key << 3); 32 key ^= (key >> 6); 33 key += ~(key << 11); 34 key ^= (key >> 16); 195 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16); 35 196 return key; 36 197 } 37 38 btHashKey getKey(const Value& value) const 39 { 40 return btHashKey(value.getUid()); 41 } 42 }; 43 44 45 template <class Value> 46 class btHashKeyPtr 47 { 48 int m_uid; 49 public: 50 51 btHashKeyPtr(int uid) 52 :m_uid(uid) 53 { 54 } 55 56 int getUid() const 57 { 58 return m_uid; 59 } 60 61 //to our success 62 SIMD_FORCE_INLINE unsigned int getHash()const 63 { 64 int key = m_uid; 65 // Thomas Wang's hash 66 key += ~(key << 15); 67 key ^= (key >> 10); 68 key += (key << 3); 69 key ^= (key >> 6); 70 key += ~(key << 11); 71 key ^= (key >> 16); 72 return key; 73 } 74 75 btHashKeyPtr getKey(const Value& value) const 76 { 77 return btHashKeyPtr(value->getUid()); 78 } 79 }; 198 }; 199 80 200 81 201 ///The btHashMap template class implements a generic and lightweight hashmap. … … 85 205 { 86 206 207 protected: 87 208 btAlignedObjectArray<int> m_hashTable; 88 209 btAlignedObjectArray<int> m_next; 210 89 211 btAlignedObjectArray<Value> m_valueArray; 90 91 92 93 void growTables(const Key& key) 212 btAlignedObjectArray<Key> m_keyArray; 213 214 void growTables(const Key& /*key*/) 94 215 { 95 216 int newCapacity = m_valueArray.capacity(); … … 116 237 for(i=0;i<curHashtableSize;i++) 117 238 { 118 const Value& value = m_valueArray[i]; 119 120 int hashValue = key.getKey(value).getHash() & (m_valueArray.capacity()-1); // New hash value with new mask 239 //const Value& value = m_valueArray[i]; 240 //const Key& key = m_keyArray[i]; 241 242 int hashValue = m_keyArray[i].getHash() & (m_valueArray.capacity()-1); // New hash value with new mask 121 243 m_next[i] = m_hashTable[hashValue]; 122 244 m_hashTable[hashValue] = i; … … 131 253 void insert(const Key& key, const Value& value) { 132 254 int hash = key.getHash() & (m_valueArray.capacity()-1); 133 //don't add it if it is already there 134 if (find(key)) 135 { 255 256 //replace value if the key is already there 257 int index = findIndex(key); 258 if (index != BT_HASH_NULL) 259 { 260 m_valueArray[index]=value; 136 261 return; 137 262 } 263 138 264 int count = m_valueArray.size(); 139 265 int oldCapacity = m_valueArray.capacity(); 140 266 m_valueArray.push_back(value); 267 m_keyArray.push_back(key); 268 141 269 int newCapacity = m_valueArray.capacity(); 142 270 if (oldCapacity < newCapacity) … … 192 320 { 193 321 m_valueArray.pop_back(); 322 m_keyArray.pop_back(); 194 323 return; 195 324 } 196 325 197 326 // Remove the last pair from the hash table. 198 const Value* lastValue = &m_valueArray[lastPairIndex]; 199 int lastHash = key.getKey(*lastValue).getHash() & (m_valueArray.capacity()-1); 327 int lastHash = m_keyArray[lastPairIndex].getHash() & (m_valueArray.capacity()-1); 200 328 201 329 index = m_hashTable[lastHash]; … … 221 349 // Copy the last pair into the remove pair's spot. 222 350 m_valueArray[pairIndex] = m_valueArray[lastPairIndex]; 351 m_keyArray[pairIndex] = m_keyArray[lastPairIndex]; 223 352 224 353 // Insert the last pair into the hash table … … 227 356 228 357 m_valueArray.pop_back(); 358 m_keyArray.pop_back(); 229 359 230 360 } … … 277 407 int findIndex(const Key& key) const 278 408 { 279 int hash = key.getHash() & (m_valueArray.capacity()-1);280 281 if (hash >= m_hashTable.size())409 unsigned int hash = key.getHash() & (m_valueArray.capacity()-1); 410 411 if (hash >= (unsigned int)m_hashTable.size()) 282 412 { 283 413 return BT_HASH_NULL; … … 285 415 286 416 int index = m_hashTable[hash]; 287 while ((index != BT_HASH_NULL) && (key.getUid() == key.getKey(m_valueArray[index]).getUid()) == false)417 while ((index != BT_HASH_NULL) && key.equals(m_keyArray[index]) == false) 288 418 { 289 419 index = m_next[index]; … … 297 427 m_next.clear(); 298 428 m_valueArray.clear(); 429 m_keyArray.clear(); 299 430 } 300 431 -
code/trunk/src/external/bullet/LinearMath/btIDebugDraw.h
r5781 r8351 1 1 /* 2 Copyright (c) 2005 Gino van den Bergen / Erwin Coumans http://continuousphysics.com 3 4 Permission is hereby granted, free of charge, to any person or organization 5 obtaining a copy of the software and accompanying documentation covered by 6 this license (the "Software") to use, reproduce, display, distribute, 7 execute, and transmit the Software, and to prepare derivative works of the 8 Software, and to permit third-parties to whom the Software is furnished to 9 do so, all subject to the following: 10 11 The copyright notices in the Software and this entire statement, including 12 the above license grant, this restriction and the following disclaimer, 13 must be included in all copies of the Software, in whole or in part, and 14 all derivative works of the Software, unless such copies or derivative 15 works are solely in the form of machine-executable object code generated by 16 a source language processor. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 21 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 22 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 DEALINGS IN THE SOFTWARE. 2 Bullet Continuous Collision Detection and Physics Library 3 Copyright (c) 2003-2009 Erwin Coumans http://bulletphysics.org 4 5 This software is provided 'as-is', without any express or implied warranty. 6 In no event will the authors be held liable for any damages arising from the use of this software. 7 Permission is granted to anyone to use this software for any purpose, 8 including commercial applications, and to alter it and redistribute it freely, 9 subject to the following restrictions: 10 11 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. 12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 13 3. This notice may not be removed or altered from any source distribution. 25 14 */ 26 15 … … 36 25 ///Typical use case: create a debug drawer object, and assign it to a btCollisionWorld or btDynamicsWorld using setDebugDrawer and call debugDrawWorld. 37 26 ///A class that implements the btIDebugDraw interface has to implement the drawLine method at a minimum. 27 ///For color arguments the X,Y,Z components refer to Red, Green and Blue each in the range [0..1] 38 28 class btIDebugDraw 39 29 { … … 56 46 DBG_DrawConstraints = (1 << 11), 57 47 DBG_DrawConstraintLimits = (1 << 12), 48 DBG_FastWireframe = (1<<13), 58 49 DBG_MAX_DEBUG_DRAW_MODE 59 50 }; … … 61 52 virtual ~btIDebugDraw() {}; 62 53 54 virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0; 55 63 56 virtual void drawLine(const btVector3& from,const btVector3& to, const btVector3& fromColor, const btVector3& toColor) 64 57 { 58 (void) toColor; 65 59 drawLine (from, to, fromColor); 66 60 } 67 61 68 virtual void drawBox (const btVector3& boxMin, const btVector3& boxMax, const btVector3& color, btScalar alpha) 69 { 70 } 71 62 virtual void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color) 63 { 64 btVector3 start = transform.getOrigin(); 65 66 const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0); 67 const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0); 68 const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius); 69 70 // XY 71 drawLine(start-xoffs, start+yoffs, color); 72 drawLine(start+yoffs, start+xoffs, color); 73 drawLine(start+xoffs, start-yoffs, color); 74 drawLine(start-yoffs, start-xoffs, color); 75 76 // XZ 77 drawLine(start-xoffs, start+zoffs, color); 78 drawLine(start+zoffs, start+xoffs, color); 79 drawLine(start+xoffs, start-zoffs, color); 80 drawLine(start-zoffs, start-xoffs, color); 81 82 // YZ 83 drawLine(start-yoffs, start+zoffs, color); 84 drawLine(start+zoffs, start+yoffs, color); 85 drawLine(start+yoffs, start-zoffs, color); 86 drawLine(start-zoffs, start-yoffs, color); 87 } 88 72 89 virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color) 73 90 { 74 } 75 76 virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)=0; 91 btTransform tr; 92 tr.setIdentity(); 93 tr.setOrigin(p); 94 drawSphere(radius,tr,color); 95 } 77 96 78 97 virtual void drawTriangle(const btVector3& v0,const btVector3& v1,const btVector3& v2,const btVector3& /*n0*/,const btVector3& /*n1*/,const btVector3& /*n2*/,const btVector3& color, btScalar alpha) … … 97 116 virtual int getDebugMode() const = 0; 98 117 99 inlinevoid drawAabb(const btVector3& from,const btVector3& to,const btVector3& color)118 virtual void drawAabb(const btVector3& from,const btVector3& to,const btVector3& color) 100 119 { 101 120 … … 126 145 } 127 146 } 128 v oid drawTransform(const btTransform& transform, btScalar orthoLen)147 virtual void drawTransform(const btTransform& transform, btScalar orthoLen) 129 148 { 130 149 btVector3 start = transform.getOrigin(); … … 134 153 } 135 154 136 v oid drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle,155 virtual void drawArc(const btVector3& center, const btVector3& normal, const btVector3& axis, btScalar radiusA, btScalar radiusB, btScalar minAngle, btScalar maxAngle, 137 156 const btVector3& color, bool drawSect, btScalar stepDegrees = btScalar(10.f)) 138 157 { … … 159 178 } 160 179 } 161 v oid drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius,180 virtual void drawSpherePatch(const btVector3& center, const btVector3& up, const btVector3& axis, btScalar radius, 162 181 btScalar minTh, btScalar maxTh, btScalar minPs, btScalar maxPs, const btVector3& color, btScalar stepDegrees = btScalar(10.f)) 163 182 { … … 261 280 } 262 281 263 v oid drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color)282 virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color) 264 283 { 265 284 drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMin[2]), color); … … 276 295 drawLine(btVector3(bbMin[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color); 277 296 } 278 v oid drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color)297 virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color) 279 298 { 280 299 drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), color); -
code/trunk/src/external/bullet/LinearMath/btMatrix3x3.h
r5781 r8351 14 14 15 15 16 #ifndef btMatrix3x3_H 17 #define btMatrix3x3_H 18 19 #include "btScalar.h" 16 #ifndef BT_MATRIX3x3_H 17 #define BT_MATRIX3x3_H 20 18 21 19 #include "btVector3.h" 22 20 #include "btQuaternion.h" 23 21 22 #ifdef BT_USE_DOUBLE_PRECISION 23 #define btMatrix3x3Data btMatrix3x3DoubleData 24 #else 25 #define btMatrix3x3Data btMatrix3x3FloatData 26 #endif //BT_USE_DOUBLE_PRECISION 24 27 25 28 26 29 /**@brief The btMatrix3x3 class implements a 3x3 rotation matrix, to perform linear algebra in combination with btQuaternion, btTransform and btVector3. 27 30 * Make sure to only include a pure orthogonal matrix without scaling. */ 28 31 class btMatrix3x3 { 29 public: 30 /** @brief No initializaion constructor */ 31 btMatrix3x3 () {} 32 33 // explicit btMatrix3x3(const btScalar *m) { setFromOpenGLSubMatrix(m); } 34 35 /**@brief Constructor from Quaternion */ 36 explicit btMatrix3x3(const btQuaternion& q) { setRotation(q); } 37 /* 38 template <typename btScalar> 39 Matrix3x3(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) 40 { 41 setEulerYPR(yaw, pitch, roll); 42 } 43 */ 44 /** @brief Constructor with row major formatting */ 45 btMatrix3x3(const btScalar& xx, const btScalar& xy, const btScalar& xz, 46 const btScalar& yx, const btScalar& yy, const btScalar& yz, 47 const btScalar& zx, const btScalar& zy, const btScalar& zz) 48 { 49 setValue(xx, xy, xz, 50 yx, yy, yz, 51 zx, zy, zz); 52 } 53 /** @brief Copy constructor */ 54 SIMD_FORCE_INLINE btMatrix3x3 (const btMatrix3x3& other) 55 { 56 m_el[0] = other.m_el[0]; 57 m_el[1] = other.m_el[1]; 58 m_el[2] = other.m_el[2]; 59 } 60 /** @brief Assignment Operator */ 61 SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& other) 62 { 63 m_el[0] = other.m_el[0]; 64 m_el[1] = other.m_el[1]; 65 m_el[2] = other.m_el[2]; 66 return *this; 67 } 68 69 /** @brief Get a column of the matrix as a vector 70 * @param i Column number 0 indexed */ 71 SIMD_FORCE_INLINE btVector3 getColumn(int i) const 72 { 73 return btVector3(m_el[0][i],m_el[1][i],m_el[2][i]); 74 } 75 76 77 /** @brief Get a row of the matrix as a vector 78 * @param i Row number 0 indexed */ 79 SIMD_FORCE_INLINE const btVector3& getRow(int i) const 80 { 81 btFullAssert(0 <= i && i < 3); 82 return m_el[i]; 83 } 84 85 /** @brief Get a mutable reference to a row of the matrix as a vector 86 * @param i Row number 0 indexed */ 87 SIMD_FORCE_INLINE btVector3& operator[](int i) 88 { 89 btFullAssert(0 <= i && i < 3); 90 return m_el[i]; 91 } 92 93 /** @brief Get a const reference to a row of the matrix as a vector 94 * @param i Row number 0 indexed */ 95 SIMD_FORCE_INLINE const btVector3& operator[](int i) const 96 { 97 btFullAssert(0 <= i && i < 3); 98 return m_el[i]; 99 } 100 101 /** @brief Multiply by the target matrix on the right 102 * @param m Rotation matrix to be applied 103 * Equivilant to this = this * m */ 104 btMatrix3x3& operator*=(const btMatrix3x3& m); 105 106 /** @brief Set from a carray of btScalars 107 * @param m A pointer to the beginning of an array of 9 btScalars */ 32 33 ///Data storage for the matrix, each vector is a row of the matrix 34 btVector3 m_el[3]; 35 36 public: 37 /** @brief No initializaion constructor */ 38 btMatrix3x3 () {} 39 40 // explicit btMatrix3x3(const btScalar *m) { setFromOpenGLSubMatrix(m); } 41 42 /**@brief Constructor from Quaternion */ 43 explicit btMatrix3x3(const btQuaternion& q) { setRotation(q); } 44 /* 45 template <typename btScalar> 46 Matrix3x3(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) 47 { 48 setEulerYPR(yaw, pitch, roll); 49 } 50 */ 51 /** @brief Constructor with row major formatting */ 52 btMatrix3x3(const btScalar& xx, const btScalar& xy, const btScalar& xz, 53 const btScalar& yx, const btScalar& yy, const btScalar& yz, 54 const btScalar& zx, const btScalar& zy, const btScalar& zz) 55 { 56 setValue(xx, xy, xz, 57 yx, yy, yz, 58 zx, zy, zz); 59 } 60 /** @brief Copy constructor */ 61 SIMD_FORCE_INLINE btMatrix3x3 (const btMatrix3x3& other) 62 { 63 m_el[0] = other.m_el[0]; 64 m_el[1] = other.m_el[1]; 65 m_el[2] = other.m_el[2]; 66 } 67 /** @brief Assignment Operator */ 68 SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& other) 69 { 70 m_el[0] = other.m_el[0]; 71 m_el[1] = other.m_el[1]; 72 m_el[2] = other.m_el[2]; 73 return *this; 74 } 75 76 /** @brief Get a column of the matrix as a vector 77 * @param i Column number 0 indexed */ 78 SIMD_FORCE_INLINE btVector3 getColumn(int i) const 79 { 80 return btVector3(m_el[0][i],m_el[1][i],m_el[2][i]); 81 } 82 83 84 /** @brief Get a row of the matrix as a vector 85 * @param i Row number 0 indexed */ 86 SIMD_FORCE_INLINE const btVector3& getRow(int i) const 87 { 88 btFullAssert(0 <= i && i < 3); 89 return m_el[i]; 90 } 91 92 /** @brief Get a mutable reference to a row of the matrix as a vector 93 * @param i Row number 0 indexed */ 94 SIMD_FORCE_INLINE btVector3& operator[](int i) 95 { 96 btFullAssert(0 <= i && i < 3); 97 return m_el[i]; 98 } 99 100 /** @brief Get a const reference to a row of the matrix as a vector 101 * @param i Row number 0 indexed */ 102 SIMD_FORCE_INLINE const btVector3& operator[](int i) const 103 { 104 btFullAssert(0 <= i && i < 3); 105 return m_el[i]; 106 } 107 108 /** @brief Multiply by the target matrix on the right 109 * @param m Rotation matrix to be applied 110 * Equivilant to this = this * m */ 111 btMatrix3x3& operator*=(const btMatrix3x3& m); 112 113 /** @brief Set from a carray of btScalars 114 * @param m A pointer to the beginning of an array of 9 btScalars */ 108 115 void setFromOpenGLSubMatrix(const btScalar *m) 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 116 { 117 m_el[0].setValue(m[0],m[4],m[8]); 118 m_el[1].setValue(m[1],m[5],m[9]); 119 m_el[2].setValue(m[2],m[6],m[10]); 120 121 } 122 /** @brief Set the values of the matrix explicitly (row major) 123 * @param xx Top left 124 * @param xy Top Middle 125 * @param xz Top Right 126 * @param yx Middle Left 127 * @param yy Middle Middle 128 * @param yz Middle Right 129 * @param zx Bottom Left 130 * @param zy Bottom Middle 131 * @param zz Bottom Right*/ 132 void setValue(const btScalar& xx, const btScalar& xy, const btScalar& xz, 133 const btScalar& yx, const btScalar& yy, const btScalar& yz, 134 const btScalar& zx, const btScalar& zy, const btScalar& zz) 135 { 136 m_el[0].setValue(xx,xy,xz); 137 m_el[1].setValue(yx,yy,yz); 138 m_el[2].setValue(zx,zy,zz); 139 } 140 141 /** @brief Set the matrix from a quaternion 142 * @param q The Quaternion to match */ 143 void setRotation(const btQuaternion& q) 144 { 145 btScalar d = q.length2(); 146 btFullAssert(d != btScalar(0.0)); 147 btScalar s = btScalar(2.0) / d; 148 btScalar xs = q.x() * s, ys = q.y() * s, zs = q.z() * s; 149 btScalar wx = q.w() * xs, wy = q.w() * ys, wz = q.w() * zs; 150 btScalar xx = q.x() * xs, xy = q.x() * ys, xz = q.x() * zs; 151 btScalar yy = q.y() * ys, yz = q.y() * zs, zz = q.z() * zs; 152 setValue(btScalar(1.0) - (yy + zz), xy - wz, xz + wy, 153 xy + wz, btScalar(1.0) - (xx + zz), yz - wx, 154 xz - wy, yz + wx, btScalar(1.0) - (xx + yy)); 155 } 156 157 158 /** @brief Set the matrix from euler angles using YPR around YXZ respectively 159 * @param yaw Yaw about Y axis 160 * @param pitch Pitch about X axis 161 * @param roll Roll about Z axis 162 */ 163 void setEulerYPR(const btScalar& yaw, const btScalar& pitch, const btScalar& roll) 164 { 165 setEulerZYX(roll, pitch, yaw); 166 } 160 167 161 168 /** @brief Set the matrix from euler angles YPR around ZYX axes 162 163 164 165 166 167 168 169 169 * @param eulerX Roll about X axis 170 * @param eulerY Pitch around Y axis 171 * @param eulerZ Yaw aboud Z axis 172 * 173 * These angles are used to produce a rotation matrix. The euler 174 * angles are applied in ZYX order. I.e a vector is first rotated 175 * about X then Y and then Z 176 **/ 170 177 void setEulerZYX(btScalar eulerX,btScalar eulerY,btScalar eulerZ) { 171 178 ///@todo proposed to reverse this since it's labeled zyx but takes arguments xyz and it will match all other parts of the code 172 179 btScalar ci ( btCos(eulerX)); 173 180 btScalar cj ( btCos(eulerY)); … … 180 187 btScalar sc = si * ch; 181 188 btScalar ss = si * sh; 182 189 183 190 setValue(cj * ch, sj * sc - cs, sj * cc + ss, 184 cj * sh, sj * ss + cc, sj * cs - sc, 185 -sj, cj * si, cj * ci); 186 } 187 188 /**@brief Set the matrix to the identity */ 189 void setIdentity() 191 cj * sh, sj * ss + cc, sj * cs - sc, 192 -sj, cj * si, cj * ci); 193 } 194 195 /**@brief Set the matrix to the identity */ 196 void setIdentity() 197 { 198 setValue(btScalar(1.0), btScalar(0.0), btScalar(0.0), 199 btScalar(0.0), btScalar(1.0), btScalar(0.0), 200 btScalar(0.0), btScalar(0.0), btScalar(1.0)); 201 } 202 203 static const btMatrix3x3& getIdentity() 204 { 205 static const btMatrix3x3 identityMatrix(btScalar(1.0), btScalar(0.0), btScalar(0.0), 206 btScalar(0.0), btScalar(1.0), btScalar(0.0), 207 btScalar(0.0), btScalar(0.0), btScalar(1.0)); 208 return identityMatrix; 209 } 210 211 /**@brief Fill the values of the matrix into a 9 element array 212 * @param m The array to be filled */ 213 void getOpenGLSubMatrix(btScalar *m) const 214 { 215 m[0] = btScalar(m_el[0].x()); 216 m[1] = btScalar(m_el[1].x()); 217 m[2] = btScalar(m_el[2].x()); 218 m[3] = btScalar(0.0); 219 m[4] = btScalar(m_el[0].y()); 220 m[5] = btScalar(m_el[1].y()); 221 m[6] = btScalar(m_el[2].y()); 222 m[7] = btScalar(0.0); 223 m[8] = btScalar(m_el[0].z()); 224 m[9] = btScalar(m_el[1].z()); 225 m[10] = btScalar(m_el[2].z()); 226 m[11] = btScalar(0.0); 227 } 228 229 /**@brief Get the matrix represented as a quaternion 230 * @param q The quaternion which will be set */ 231 void getRotation(btQuaternion& q) const 232 { 233 btScalar trace = m_el[0].x() + m_el[1].y() + m_el[2].z(); 234 btScalar temp[4]; 235 236 if (trace > btScalar(0.0)) 237 { 238 btScalar s = btSqrt(trace + btScalar(1.0)); 239 temp[3]=(s * btScalar(0.5)); 240 s = btScalar(0.5) / s; 241 242 temp[0]=((m_el[2].y() - m_el[1].z()) * s); 243 temp[1]=((m_el[0].z() - m_el[2].x()) * s); 244 temp[2]=((m_el[1].x() - m_el[0].y()) * s); 245 } 246 else 247 { 248 int i = m_el[0].x() < m_el[1].y() ? 249 (m_el[1].y() < m_el[2].z() ? 2 : 1) : 250 (m_el[0].x() < m_el[2].z() ? 2 : 0); 251 int j = (i + 1) % 3; 252 int k = (i + 2) % 3; 253 254 btScalar s = btSqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + btScalar(1.0)); 255 temp[i] = s * btScalar(0.5); 256 s = btScalar(0.5) / s; 257 258 temp[3] = (m_el[k][j] - m_el[j][k]) * s; 259 temp[j] = (m_el[j][i] + m_el[i][j]) * s; 260 temp[k] = (m_el[k][i] + m_el[i][k]) * s; 261 } 262 q.setValue(temp[0],temp[1],temp[2],temp[3]); 263 } 264 265 /**@brief Get the matrix represented as euler angles around YXZ, roundtrip with setEulerYPR 266 * @param yaw Yaw around Y axis 267 * @param pitch Pitch around X axis 268 * @param roll around Z axis */ 269 void getEulerYPR(btScalar& yaw, btScalar& pitch, btScalar& roll) const 270 { 271 272 // first use the normal calculus 273 yaw = btScalar(btAtan2(m_el[1].x(), m_el[0].x())); 274 pitch = btScalar(btAsin(-m_el[2].x())); 275 roll = btScalar(btAtan2(m_el[2].y(), m_el[2].z())); 276 277 // on pitch = +/-HalfPI 278 if (btFabs(pitch)==SIMD_HALF_PI) 279 { 280 if (yaw>0) 281 yaw-=SIMD_PI; 282 else 283 yaw+=SIMD_PI; 284 285 if (roll>0) 286 roll-=SIMD_PI; 287 else 288 roll+=SIMD_PI; 289 } 290 }; 291 292 293 /**@brief Get the matrix represented as euler angles around ZYX 294 * @param yaw Yaw around X axis 295 * @param pitch Pitch around Y axis 296 * @param roll around X axis 297 * @param solution_number Which solution of two possible solutions ( 1 or 2) are possible values*/ 298 void getEulerZYX(btScalar& yaw, btScalar& pitch, btScalar& roll, unsigned int solution_number = 1) const 299 { 300 struct Euler 301 { 302 btScalar yaw; 303 btScalar pitch; 304 btScalar roll; 305 }; 306 307 Euler euler_out; 308 Euler euler_out2; //second solution 309 //get the pointer to the raw data 310 311 // Check that pitch is not at a singularity 312 if (btFabs(m_el[2].x()) >= 1) 313 { 314 euler_out.yaw = 0; 315 euler_out2.yaw = 0; 316 317 // From difference of angles formula 318 btScalar delta = btAtan2(m_el[0].x(),m_el[0].z()); 319 if (m_el[2].x() > 0) //gimbal locked up 320 { 321 euler_out.pitch = SIMD_PI / btScalar(2.0); 322 euler_out2.pitch = SIMD_PI / btScalar(2.0); 323 euler_out.roll = euler_out.pitch + delta; 324 euler_out2.roll = euler_out.pitch + delta; 325 } 326 else // gimbal locked down 327 { 328 euler_out.pitch = -SIMD_PI / btScalar(2.0); 329 euler_out2.pitch = -SIMD_PI / btScalar(2.0); 330 euler_out.roll = -euler_out.pitch + delta; 331 euler_out2.roll = -euler_out.pitch + delta; 332 } 333 } 334 else 335 { 336 euler_out.pitch = - btAsin(m_el[2].x()); 337 euler_out2.pitch = SIMD_PI - euler_out.pitch; 338 339 euler_out.roll = btAtan2(m_el[2].y()/btCos(euler_out.pitch), 340 m_el[2].z()/btCos(euler_out.pitch)); 341 euler_out2.roll = btAtan2(m_el[2].y()/btCos(euler_out2.pitch), 342 m_el[2].z()/btCos(euler_out2.pitch)); 343 344 euler_out.yaw = btAtan2(m_el[1].x()/btCos(euler_out.pitch), 345 m_el[0].x()/btCos(euler_out.pitch)); 346 euler_out2.yaw = btAtan2(m_el[1].x()/btCos(euler_out2.pitch), 347 m_el[0].x()/btCos(euler_out2.pitch)); 348 } 349 350 if (solution_number == 1) 190 351 { 191 setValue(btScalar(1.0), btScalar(0.0), btScalar(0.0),192 btScalar(0.0), btScalar(1.0), btScalar(0.0),193 btScalar(0.0), btScalar(0.0), btScalar(1.0));352 yaw = euler_out.yaw; 353 pitch = euler_out.pitch; 354 roll = euler_out.roll; 194 355 } 195 196 static const btMatrix3x3& getIdentity() 356 else 357 { 358 yaw = euler_out2.yaw; 359 pitch = euler_out2.pitch; 360 roll = euler_out2.roll; 361 } 362 } 363 364 /**@brief Create a scaled copy of the matrix 365 * @param s Scaling vector The elements of the vector will scale each column */ 366 367 btMatrix3x3 scaled(const btVector3& s) const 368 { 369 return btMatrix3x3(m_el[0].x() * s.x(), m_el[0].y() * s.y(), m_el[0].z() * s.z(), 370 m_el[1].x() * s.x(), m_el[1].y() * s.y(), m_el[1].z() * s.z(), 371 m_el[2].x() * s.x(), m_el[2].y() * s.y(), m_el[2].z() * s.z()); 372 } 373 374 /**@brief Return the determinant of the matrix */ 375 btScalar determinant() const; 376 /**@brief Return the adjoint of the matrix */ 377 btMatrix3x3 adjoint() const; 378 /**@brief Return the matrix with all values non negative */ 379 btMatrix3x3 absolute() const; 380 /**@brief Return the transpose of the matrix */ 381 btMatrix3x3 transpose() const; 382 /**@brief Return the inverse of the matrix */ 383 btMatrix3x3 inverse() const; 384 385 btMatrix3x3 transposeTimes(const btMatrix3x3& m) const; 386 btMatrix3x3 timesTranspose(const btMatrix3x3& m) const; 387 388 SIMD_FORCE_INLINE btScalar tdotx(const btVector3& v) const 389 { 390 return m_el[0].x() * v.x() + m_el[1].x() * v.y() + m_el[2].x() * v.z(); 391 } 392 SIMD_FORCE_INLINE btScalar tdoty(const btVector3& v) const 393 { 394 return m_el[0].y() * v.x() + m_el[1].y() * v.y() + m_el[2].y() * v.z(); 395 } 396 SIMD_FORCE_INLINE btScalar tdotz(const btVector3& v) const 397 { 398 return m_el[0].z() * v.x() + m_el[1].z() * v.y() + m_el[2].z() * v.z(); 399 } 400 401 402 /**@brief diagonalizes this matrix by the Jacobi method. 403 * @param rot stores the rotation from the coordinate system in which the matrix is diagonal to the original 404 * coordinate system, i.e., old_this = rot * new_this * rot^T. 405 * @param threshold See iteration 406 * @param iteration The iteration stops when all off-diagonal elements are less than the threshold multiplied 407 * by the sum of the absolute values of the diagonal, or when maxSteps have been executed. 408 * 409 * Note that this matrix is assumed to be symmetric. 410 */ 411 void diagonalize(btMatrix3x3& rot, btScalar threshold, int maxSteps) 412 { 413 rot.setIdentity(); 414 for (int step = maxSteps; step > 0; step--) 197 415 { 198 static const btMatrix3x3 identityMatrix(btScalar(1.0), btScalar(0.0), btScalar(0.0),199 btScalar(0.0), btScalar(1.0), btScalar(0.0),200 btScalar(0.0), btScalar(0.0), btScalar(1.0));201 return identityMatrix;202 }203 204 /**@brief Fill the values of the matrix into a 9 element array205 * @param m The array to be filled */206 void getOpenGLSubMatrix(btScalar *m) const207 {208 m[0] = btScalar(m_el[0].x());209 m[1] = btScalar(m_el[1].x());210 m[2] = btScalar(m_el[2].x());211 m[3] = btScalar(0.0);212 m[4] = btScalar(m_el[0].y());213 m[5] = btScalar(m_el[1].y());214 m[6] = btScalar(m_el[2].y());215 m[7] = btScalar(0.0);216 m[8] = btScalar(m_el[0].z());217 m[9] = btScalar(m_el[1].z());218 m[10] = btScalar(m_el[2].z());219 m[11] = btScalar(0.0);220 }221 222 /**@brief Get the matrix represented as a quaternion223 * @param q The quaternion which will be set */224 void getRotation(btQuaternion& q) const225 {226 btScalar trace = m_el[0].x() + m_el[1].y() + m_el[2].z();227 btScalar temp[4];228 229 if (trace > btScalar(0.0))230 {231 btScalar s = btSqrt(trace + btScalar(1.0));232 temp[3]=(s * btScalar(0.5));233 s = btScalar(0.5) / s;234 235 temp[0]=((m_el[2].y() - m_el[1].z()) * s);236 temp[1]=((m_el[0].z() - m_el[2].x()) * s);237 temp[2]=((m_el[1].x() - m_el[0].y()) * s);238 }239 else240 {241 int i = m_el[0].x() < m_el[1].y() ?242 (m_el[1].y() < m_el[2].z() ? 2 : 1) :243 (m_el[0].x() < m_el[2].z() ? 2 : 0);244 int j = (i + 1) % 3;245 int k = (i + 2) % 3;246 247 btScalar s = btSqrt(m_el[i][i] - m_el[j][j] - m_el[k][k] + btScalar(1.0));248 temp[i] = s * btScalar(0.5);249 s = btScalar(0.5) / s;250 251 temp[3] = (m_el[k][j] - m_el[j][k]) * s;252 temp[j] = (m_el[j][i] + m_el[i][j]) * s;253 temp[k] = (m_el[k][i] + m_el[i][k]) * s;254 }255 q.setValue(temp[0],temp[1],temp[2],temp[3]);256 }257 258 /**@brief Get the matrix represented as euler angles around YXZ, roundtrip with setEulerYPR259 * @param yaw Yaw around Y axis260 * @param pitch Pitch around X axis261 * @param roll around Z axis */262 void getEulerYPR(btScalar& yaw, btScalar& pitch, btScalar& roll) const263 {264 265 // first use the normal calculus266 yaw = btScalar(btAtan2(m_el[1].x(), m_el[0].x()));267 pitch = btScalar(btAsin(-m_el[2].x()));268 roll = btScalar(btAtan2(m_el[2].y(), m_el[2].z()));269 270 // on pitch = +/-HalfPI271 if (btFabs(pitch)==SIMD_HALF_PI)272 {273 if (yaw>0)274 yaw-=SIMD_PI;275 else276 yaw+=SIMD_PI;277 278 if (roll>0)279 roll-=SIMD_PI;280 else281 roll+=SIMD_PI;282 }283 };284 285 286 /**@brief Get the matrix represented as euler angles around ZYX287 * @param yaw Yaw around X axis288 * @param pitch Pitch around Y axis289 * @param roll around X axis290 * @param solution_number Which solution of two possible solutions ( 1 or 2) are possible values*/291 void getEulerZYX(btScalar& yaw, btScalar& pitch, btScalar& roll, unsigned int solution_number = 1) const292 {293 struct Euler{btScalar yaw, pitch, roll;};294 Euler euler_out;295 Euler euler_out2; //second solution296 //get the pointer to the raw data297 298 // Check that pitch is not at a singularity299 if (btFabs(m_el[2].x()) >= 1)300 {301 euler_out.yaw = 0;302 euler_out2.yaw = 0;303 304 // From difference of angles formula305 btScalar delta = btAtan2(m_el[0].x(),m_el[0].z());306 if (m_el[2].x() > 0) //gimbal locked up307 {308 euler_out.pitch = SIMD_PI / btScalar(2.0);309 euler_out2.pitch = SIMD_PI / btScalar(2.0);310 euler_out.roll = euler_out.pitch + delta;311 euler_out2.roll = euler_out.pitch + delta;312 }313 else // gimbal locked down314 {315 euler_out.pitch = -SIMD_PI / btScalar(2.0);316 euler_out2.pitch = -SIMD_PI / btScalar(2.0);317 euler_out.roll = -euler_out.pitch + delta;318 euler_out2.roll = -euler_out.pitch + delta;319 }320 }321 else322 {323 euler_out.pitch = - btAsin(m_el[2].x());324 euler_out2.pitch = SIMD_PI - euler_out.pitch;325 326 euler_out.roll = btAtan2(m_el[2].y()/btCos(euler_out.pitch),327 m_el[2].z()/btCos(euler_out.pitch));328 euler_out2.roll = btAtan2(m_el[2].y()/btCos(euler_out2.pitch),329 m_el[2].z()/btCos(euler_out2.pitch));330 331 euler_out.yaw = btAtan2(m_el[1].x()/btCos(euler_out.pitch),332 m_el[0].x()/btCos(euler_out.pitch));333 euler_out2.yaw = btAtan2(m_el[1].x()/btCos(euler_out2.pitch),334 m_el[0].x()/btCos(euler_out2.pitch));335 }336 337 if (solution_number == 1)338 {339 yaw = euler_out.yaw;340 pitch = euler_out.pitch;341 roll = euler_out.roll;342 }343 else344 {345 yaw = euler_out2.yaw;346 pitch = euler_out2.pitch;347 roll = euler_out2.roll;348 }349 }350 351 /**@brief Create a scaled copy of the matrix352 * @param s Scaling vector The elements of the vector will scale each column */353 354 btMatrix3x3 scaled(const btVector3& s) const355 {356 return btMatrix3x3(m_el[0].x() * s.x(), m_el[0].y() * s.y(), m_el[0].z() * s.z(),357 m_el[1].x() * s.x(), m_el[1].y() * s.y(), m_el[1].z() * s.z(),358 m_el[2].x() * s.x(), m_el[2].y() * s.y(), m_el[2].z() * s.z());359 }360 361 /**@brief Return the determinant of the matrix */362 btScalar determinant() const;363 /**@brief Return the adjoint of the matrix */364 btMatrix3x3 adjoint() const;365 /**@brief Return the matrix with all values non negative */366 btMatrix3x3 absolute() const;367 /**@brief Return the transpose of the matrix */368 btMatrix3x3 transpose() const;369 /**@brief Return the inverse of the matrix */370 btMatrix3x3 inverse() const;371 372 btMatrix3x3 transposeTimes(const btMatrix3x3& m) const;373 btMatrix3x3 timesTranspose(const btMatrix3x3& m) const;374 375 SIMD_FORCE_INLINE btScalar tdotx(const btVector3& v) const376 {377 return m_el[0].x() * v.x() + m_el[1].x() * v.y() + m_el[2].x() * v.z();378 }379 SIMD_FORCE_INLINE btScalar tdoty(const btVector3& v) const380 {381 return m_el[0].y() * v.x() + m_el[1].y() * v.y() + m_el[2].y() * v.z();382 }383 SIMD_FORCE_INLINE btScalar tdotz(const btVector3& v) const384 {385 return m_el[0].z() * v.x() + m_el[1].z() * v.y() + m_el[2].z() * v.z();386 }387 388 389 /**@brief diagonalizes this matrix by the Jacobi method.390 * @param rot stores the rotation from the coordinate system in which the matrix is diagonal to the original391 * coordinate system, i.e., old_this = rot * new_this * rot^T.392 * @param threshold See iteration393 * @param iteration The iteration stops when all off-diagonal elements are less than the threshold multiplied394 * by the sum of the absolute values of the diagonal, or when maxSteps have been executed.395 *396 * Note that this matrix is assumed to be symmetric.397 */398 void diagonalize(btMatrix3x3& rot, btScalar threshold, int maxSteps)399 {400 rot.setIdentity();401 for (int step = maxSteps; step > 0; step--)402 {403 416 // find off-diagonal element [p][q] with largest magnitude 404 417 int p = 0; … … 409 422 if (v > max) 410 423 { 411 412 413 424 q = 2; 425 r = 1; 426 max = v; 414 427 } 415 428 v = btFabs(m_el[1][2]); 416 429 if (v > max) 417 430 { 418 419 420 421 431 p = 1; 432 q = 2; 433 r = 0; 434 max = v; 422 435 } 423 436 … … 425 438 if (max <= t) 426 439 { 427 428 429 430 431 440 if (max <= SIMD_EPSILON * t) 441 { 442 return; 443 } 444 step = 1; 432 445 } 433 446 … … 440 453 if (theta2 * theta2 < btScalar(10 / SIMD_EPSILON)) 441 454 { 442 443 444 445 455 t = (theta >= 0) ? 1 / (theta + btSqrt(1 + theta2)) 456 : 1 / (theta - btSqrt(1 + theta2)); 457 cos = 1 / btSqrt(1 + t * t); 458 sin = cos * t; 446 459 } 447 460 else 448 461 { 449 450 451 452 462 // approximation for large theta-value, i.e., a nearly diagonal matrix 463 t = 1 / (theta * (2 + btScalar(0.5) / theta2)); 464 cos = 1 - btScalar(0.5) * t * t; 465 sin = cos * t; 453 466 } 454 467 … … 465 478 for (int i = 0; i < 3; i++) 466 479 { 467 btVector3& row = rot[i]; 468 mrp = row[p]; 469 mrq = row[q]; 470 row[p] = cos * mrp - sin * mrq; 471 row[q] = cos * mrq + sin * mrp; 472 } 473 } 480 btVector3& row = rot[i]; 481 mrp = row[p]; 482 mrq = row[q]; 483 row[p] = cos * mrp - sin * mrq; 484 row[q] = cos * mrq + sin * mrp; 485 } 474 486 } 475 476 477 478 protected: 479 /**@brief Calculate the matrix cofactor 480 * @param r1 The first row to use for calculating the cofactor 481 * @param c1 The first column to use for calculating the cofactor 482 * @param r1 The second row to use for calculating the cofactor 483 * @param c1 The second column to use for calculating the cofactor 484 * See http://en.wikipedia.org/wiki/Cofactor_(linear_algebra) for more details 485 */ 486 btScalar cofac(int r1, int c1, int r2, int c2) const 487 { 488 return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1]; 489 } 490 ///Data storage for the matrix, each vector is a row of the matrix 491 btVector3 m_el[3]; 492 }; 487 } 488 489 490 491 492 /**@brief Calculate the matrix cofactor 493 * @param r1 The first row to use for calculating the cofactor 494 * @param c1 The first column to use for calculating the cofactor 495 * @param r1 The second row to use for calculating the cofactor 496 * @param c1 The second column to use for calculating the cofactor 497 * See http://en.wikipedia.org/wiki/Cofactor_(linear_algebra) for more details 498 */ 499 btScalar cofac(int r1, int c1, int r2, int c2) const 500 { 501 return m_el[r1][c1] * m_el[r2][c2] - m_el[r1][c2] * m_el[r2][c1]; 502 } 503 504 void serialize(struct btMatrix3x3Data& dataOut) const; 505 506 void serializeFloat(struct btMatrix3x3FloatData& dataOut) const; 507 508 void deSerialize(const struct btMatrix3x3Data& dataIn); 509 510 void deSerializeFloat(const struct btMatrix3x3FloatData& dataIn); 511 512 void deSerializeDouble(const struct btMatrix3x3DoubleData& dataIn); 513 514 }; 515 516 517 SIMD_FORCE_INLINE btMatrix3x3& 518 btMatrix3x3::operator*=(const btMatrix3x3& m) 519 { 520 setValue(m.tdotx(m_el[0]), m.tdoty(m_el[0]), m.tdotz(m_el[0]), 521 m.tdotx(m_el[1]), m.tdoty(m_el[1]), m.tdotz(m_el[1]), 522 m.tdotx(m_el[2]), m.tdoty(m_el[2]), m.tdotz(m_el[2])); 523 return *this; 524 } 525 526 SIMD_FORCE_INLINE btScalar 527 btMatrix3x3::determinant() const 528 { 529 return btTriple((*this)[0], (*this)[1], (*this)[2]); 530 } 531 532 533 SIMD_FORCE_INLINE btMatrix3x3 534 btMatrix3x3::absolute() const 535 { 536 return btMatrix3x3( 537 btFabs(m_el[0].x()), btFabs(m_el[0].y()), btFabs(m_el[0].z()), 538 btFabs(m_el[1].x()), btFabs(m_el[1].y()), btFabs(m_el[1].z()), 539 btFabs(m_el[2].x()), btFabs(m_el[2].y()), btFabs(m_el[2].z())); 540 } 541 542 SIMD_FORCE_INLINE btMatrix3x3 543 btMatrix3x3::transpose() const 544 { 545 return btMatrix3x3(m_el[0].x(), m_el[1].x(), m_el[2].x(), 546 m_el[0].y(), m_el[1].y(), m_el[2].y(), 547 m_el[0].z(), m_el[1].z(), m_el[2].z()); 548 } 549 550 SIMD_FORCE_INLINE btMatrix3x3 551 btMatrix3x3::adjoint() const 552 { 553 return btMatrix3x3(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2), 554 cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0), 555 cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1)); 556 } 557 558 SIMD_FORCE_INLINE btMatrix3x3 559 btMatrix3x3::inverse() const 560 { 561 btVector3 co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)); 562 btScalar det = (*this)[0].dot(co); 563 btFullAssert(det != btScalar(0.0)); 564 btScalar s = btScalar(1.0) / det; 565 return btMatrix3x3(co.x() * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s, 566 co.y() * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s, 567 co.z() * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s); 568 } 569 570 SIMD_FORCE_INLINE btMatrix3x3 571 btMatrix3x3::transposeTimes(const btMatrix3x3& m) const 572 { 573 return btMatrix3x3( 574 m_el[0].x() * m[0].x() + m_el[1].x() * m[1].x() + m_el[2].x() * m[2].x(), 575 m_el[0].x() * m[0].y() + m_el[1].x() * m[1].y() + m_el[2].x() * m[2].y(), 576 m_el[0].x() * m[0].z() + m_el[1].x() * m[1].z() + m_el[2].x() * m[2].z(), 577 m_el[0].y() * m[0].x() + m_el[1].y() * m[1].x() + m_el[2].y() * m[2].x(), 578 m_el[0].y() * m[0].y() + m_el[1].y() * m[1].y() + m_el[2].y() * m[2].y(), 579 m_el[0].y() * m[0].z() + m_el[1].y() * m[1].z() + m_el[2].y() * m[2].z(), 580 m_el[0].z() * m[0].x() + m_el[1].z() * m[1].x() + m_el[2].z() * m[2].x(), 581 m_el[0].z() * m[0].y() + m_el[1].z() * m[1].y() + m_el[2].z() * m[2].y(), 582 m_el[0].z() * m[0].z() + m_el[1].z() * m[1].z() + m_el[2].z() * m[2].z()); 583 } 584 585 SIMD_FORCE_INLINE btMatrix3x3 586 btMatrix3x3::timesTranspose(const btMatrix3x3& m) const 587 { 588 return btMatrix3x3( 589 m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]), 590 m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]), 591 m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2])); 592 593 } 594 595 SIMD_FORCE_INLINE btVector3 596 operator*(const btMatrix3x3& m, const btVector3& v) 597 { 598 return btVector3(m[0].dot(v), m[1].dot(v), m[2].dot(v)); 599 } 600 601 602 SIMD_FORCE_INLINE btVector3 603 operator*(const btVector3& v, const btMatrix3x3& m) 604 { 605 return btVector3(m.tdotx(v), m.tdoty(v), m.tdotz(v)); 606 } 607 608 SIMD_FORCE_INLINE btMatrix3x3 609 operator*(const btMatrix3x3& m1, const btMatrix3x3& m2) 610 { 611 return btMatrix3x3( 612 m2.tdotx( m1[0]), m2.tdoty( m1[0]), m2.tdotz( m1[0]), 613 m2.tdotx( m1[1]), m2.tdoty( m1[1]), m2.tdotz( m1[1]), 614 m2.tdotx( m1[2]), m2.tdoty( m1[2]), m2.tdotz( m1[2])); 615 } 616 617 /* 618 SIMD_FORCE_INLINE btMatrix3x3 btMultTransposeLeft(const btMatrix3x3& m1, const btMatrix3x3& m2) { 619 return btMatrix3x3( 620 m1[0][0] * m2[0][0] + m1[1][0] * m2[1][0] + m1[2][0] * m2[2][0], 621 m1[0][0] * m2[0][1] + m1[1][0] * m2[1][1] + m1[2][0] * m2[2][1], 622 m1[0][0] * m2[0][2] + m1[1][0] * m2[1][2] + m1[2][0] * m2[2][2], 623 m1[0][1] * m2[0][0] + m1[1][1] * m2[1][0] + m1[2][1] * m2[2][0], 624 m1[0][1] * m2[0][1] + m1[1][1] * m2[1][1] + m1[2][1] * m2[2][1], 625 m1[0][1] * m2[0][2] + m1[1][1] * m2[1][2] + m1[2][1] * m2[2][2], 626 m1[0][2] * m2[0][0] + m1[1][2] * m2[1][0] + m1[2][2] * m2[2][0], 627 m1[0][2] * m2[0][1] + m1[1][2] * m2[1][1] + m1[2][2] * m2[2][1], 628 m1[0][2] * m2[0][2] + m1[1][2] * m2[1][2] + m1[2][2] * m2[2][2]); 629 } 630 */ 631 632 /**@brief Equality operator between two matrices 633 * It will test all elements are equal. */ 634 SIMD_FORCE_INLINE bool operator==(const btMatrix3x3& m1, const btMatrix3x3& m2) 635 { 636 return ( m1[0][0] == m2[0][0] && m1[1][0] == m2[1][0] && m1[2][0] == m2[2][0] && 637 m1[0][1] == m2[0][1] && m1[1][1] == m2[1][1] && m1[2][1] == m2[2][1] && 638 m1[0][2] == m2[0][2] && m1[1][2] == m2[1][2] && m1[2][2] == m2[2][2] ); 639 } 640 641 ///for serialization 642 struct btMatrix3x3FloatData 643 { 644 btVector3FloatData m_el[3]; 645 }; 646 647 ///for serialization 648 struct btMatrix3x3DoubleData 649 { 650 btVector3DoubleData m_el[3]; 651 }; 652 653 493 654 494 SIMD_FORCE_INLINE btMatrix3x3& 495 btMatrix3x3::operator*=(const btMatrix3x3& m) 496 { 497 setValue(m.tdotx(m_el[0]), m.tdoty(m_el[0]), m.tdotz(m_el[0]), 498 m.tdotx(m_el[1]), m.tdoty(m_el[1]), m.tdotz(m_el[1]), 499 m.tdotx(m_el[2]), m.tdoty(m_el[2]), m.tdotz(m_el[2])); 500 return *this; 501 } 502 503 SIMD_FORCE_INLINE btScalar 504 btMatrix3x3::determinant() const 505 { 506 return triple((*this)[0], (*this)[1], (*this)[2]); 507 } 508 509 510 SIMD_FORCE_INLINE btMatrix3x3 511 btMatrix3x3::absolute() const 512 { 513 return btMatrix3x3( 514 btFabs(m_el[0].x()), btFabs(m_el[0].y()), btFabs(m_el[0].z()), 515 btFabs(m_el[1].x()), btFabs(m_el[1].y()), btFabs(m_el[1].z()), 516 btFabs(m_el[2].x()), btFabs(m_el[2].y()), btFabs(m_el[2].z())); 517 } 518 519 SIMD_FORCE_INLINE btMatrix3x3 520 btMatrix3x3::transpose() const 521 { 522 return btMatrix3x3(m_el[0].x(), m_el[1].x(), m_el[2].x(), 523 m_el[0].y(), m_el[1].y(), m_el[2].y(), 524 m_el[0].z(), m_el[1].z(), m_el[2].z()); 525 } 526 527 SIMD_FORCE_INLINE btMatrix3x3 528 btMatrix3x3::adjoint() const 529 { 530 return btMatrix3x3(cofac(1, 1, 2, 2), cofac(0, 2, 2, 1), cofac(0, 1, 1, 2), 531 cofac(1, 2, 2, 0), cofac(0, 0, 2, 2), cofac(0, 2, 1, 0), 532 cofac(1, 0, 2, 1), cofac(0, 1, 2, 0), cofac(0, 0, 1, 1)); 533 } 534 535 SIMD_FORCE_INLINE btMatrix3x3 536 btMatrix3x3::inverse() const 537 { 538 btVector3 co(cofac(1, 1, 2, 2), cofac(1, 2, 2, 0), cofac(1, 0, 2, 1)); 539 btScalar det = (*this)[0].dot(co); 540 btFullAssert(det != btScalar(0.0)); 541 btScalar s = btScalar(1.0) / det; 542 return btMatrix3x3(co.x() * s, cofac(0, 2, 2, 1) * s, cofac(0, 1, 1, 2) * s, 543 co.y() * s, cofac(0, 0, 2, 2) * s, cofac(0, 2, 1, 0) * s, 544 co.z() * s, cofac(0, 1, 2, 0) * s, cofac(0, 0, 1, 1) * s); 545 } 546 547 SIMD_FORCE_INLINE btMatrix3x3 548 btMatrix3x3::transposeTimes(const btMatrix3x3& m) const 549 { 550 return btMatrix3x3( 551 m_el[0].x() * m[0].x() + m_el[1].x() * m[1].x() + m_el[2].x() * m[2].x(), 552 m_el[0].x() * m[0].y() + m_el[1].x() * m[1].y() + m_el[2].x() * m[2].y(), 553 m_el[0].x() * m[0].z() + m_el[1].x() * m[1].z() + m_el[2].x() * m[2].z(), 554 m_el[0].y() * m[0].x() + m_el[1].y() * m[1].x() + m_el[2].y() * m[2].x(), 555 m_el[0].y() * m[0].y() + m_el[1].y() * m[1].y() + m_el[2].y() * m[2].y(), 556 m_el[0].y() * m[0].z() + m_el[1].y() * m[1].z() + m_el[2].y() * m[2].z(), 557 m_el[0].z() * m[0].x() + m_el[1].z() * m[1].x() + m_el[2].z() * m[2].x(), 558 m_el[0].z() * m[0].y() + m_el[1].z() * m[1].y() + m_el[2].z() * m[2].y(), 559 m_el[0].z() * m[0].z() + m_el[1].z() * m[1].z() + m_el[2].z() * m[2].z()); 560 } 561 562 SIMD_FORCE_INLINE btMatrix3x3 563 btMatrix3x3::timesTranspose(const btMatrix3x3& m) const 564 { 565 return btMatrix3x3( 566 m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]), 567 m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]), 568 m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2])); 569 570 } 571 572 SIMD_FORCE_INLINE btVector3 573 operator*(const btMatrix3x3& m, const btVector3& v) 574 { 575 return btVector3(m[0].dot(v), m[1].dot(v), m[2].dot(v)); 576 } 577 578 579 SIMD_FORCE_INLINE btVector3 580 operator*(const btVector3& v, const btMatrix3x3& m) 581 { 582 return btVector3(m.tdotx(v), m.tdoty(v), m.tdotz(v)); 583 } 584 585 SIMD_FORCE_INLINE btMatrix3x3 586 operator*(const btMatrix3x3& m1, const btMatrix3x3& m2) 587 { 588 return btMatrix3x3( 589 m2.tdotx( m1[0]), m2.tdoty( m1[0]), m2.tdotz( m1[0]), 590 m2.tdotx( m1[1]), m2.tdoty( m1[1]), m2.tdotz( m1[1]), 591 m2.tdotx( m1[2]), m2.tdoty( m1[2]), m2.tdotz( m1[2])); 592 } 593 594 /* 595 SIMD_FORCE_INLINE btMatrix3x3 btMultTransposeLeft(const btMatrix3x3& m1, const btMatrix3x3& m2) { 596 return btMatrix3x3( 597 m1[0][0] * m2[0][0] + m1[1][0] * m2[1][0] + m1[2][0] * m2[2][0], 598 m1[0][0] * m2[0][1] + m1[1][0] * m2[1][1] + m1[2][0] * m2[2][1], 599 m1[0][0] * m2[0][2] + m1[1][0] * m2[1][2] + m1[2][0] * m2[2][2], 600 m1[0][1] * m2[0][0] + m1[1][1] * m2[1][0] + m1[2][1] * m2[2][0], 601 m1[0][1] * m2[0][1] + m1[1][1] * m2[1][1] + m1[2][1] * m2[2][1], 602 m1[0][1] * m2[0][2] + m1[1][1] * m2[1][2] + m1[2][1] * m2[2][2], 603 m1[0][2] * m2[0][0] + m1[1][2] * m2[1][0] + m1[2][2] * m2[2][0], 604 m1[0][2] * m2[0][1] + m1[1][2] * m2[1][1] + m1[2][2] * m2[2][1], 605 m1[0][2] * m2[0][2] + m1[1][2] * m2[1][2] + m1[2][2] * m2[2][2]); 606 } 607 */ 608 609 /**@brief Equality operator between two matrices 610 * It will test all elements are equal. */ 611 SIMD_FORCE_INLINE bool operator==(const btMatrix3x3& m1, const btMatrix3x3& m2) 612 { 613 return ( m1[0][0] == m2[0][0] && m1[1][0] == m2[1][0] && m1[2][0] == m2[2][0] && 614 m1[0][1] == m2[0][1] && m1[1][1] == m2[1][1] && m1[2][1] == m2[2][1] && 615 m1[0][2] == m2[0][2] && m1[1][2] == m2[1][2] && m1[2][2] == m2[2][2] ); 616 } 617 618 #endif 655 656 SIMD_FORCE_INLINE void btMatrix3x3::serialize(struct btMatrix3x3Data& dataOut) const 657 { 658 for (int i=0;i<3;i++) 659 m_el[i].serialize(dataOut.m_el[i]); 660 } 661 662 SIMD_FORCE_INLINE void btMatrix3x3::serializeFloat(struct btMatrix3x3FloatData& dataOut) const 663 { 664 for (int i=0;i<3;i++) 665 m_el[i].serializeFloat(dataOut.m_el[i]); 666 } 667 668 669 SIMD_FORCE_INLINE void btMatrix3x3::deSerialize(const struct btMatrix3x3Data& dataIn) 670 { 671 for (int i=0;i<3;i++) 672 m_el[i].deSerialize(dataIn.m_el[i]); 673 } 674 675 SIMD_FORCE_INLINE void btMatrix3x3::deSerializeFloat(const struct btMatrix3x3FloatData& dataIn) 676 { 677 for (int i=0;i<3;i++) 678 m_el[i].deSerializeFloat(dataIn.m_el[i]); 679 } 680 681 SIMD_FORCE_INLINE void btMatrix3x3::deSerializeDouble(const struct btMatrix3x3DoubleData& dataIn) 682 { 683 for (int i=0;i<3;i++) 684 m_el[i].deSerializeDouble(dataIn.m_el[i]); 685 } 686 687 #endif //BT_MATRIX3x3_H 688 -
code/trunk/src/external/bullet/LinearMath/btMinMax.h
r5781 r8351 18 18 #define GEN_MINMAX_H 19 19 20 #include "LinearMath/btScalar.h" 21 20 22 template <class T> 21 23 SIMD_FORCE_INLINE const T& btMin(const T& a, const T& b) … … 31 33 32 34 template <class T> 33 SIMD_FORCE_INLINE const T& GEN_clamped(const T& a, const T& lb, const T& ub)35 SIMD_FORCE_INLINE const T& btClamped(const T& a, const T& lb, const T& ub) 34 36 { 35 37 return a < lb ? lb : (ub < a ? ub : a); … … 55 57 56 58 template <class T> 57 SIMD_FORCE_INLINE void GEN_clamp(T& a, const T& lb, const T& ub)59 SIMD_FORCE_INLINE void btClamp(T& a, const T& lb, const T& ub) 58 60 { 59 61 if (a < lb) -
code/trunk/src/external/bullet/LinearMath/btPoolAllocator.h
r5781 r8351 58 58 } 59 59 60 int getUsedCount() const 61 { 62 return m_maxElements - m_freeCount; 63 } 64 60 65 void* allocate(int size) 61 66 { … … 97 102 } 98 103 104 unsigned char* getPoolAddress() 105 { 106 return m_pool; 107 } 108 109 const unsigned char* getPoolAddress() const 110 { 111 return m_pool; 112 } 99 113 100 114 }; -
code/trunk/src/external/bullet/LinearMath/btQuaternion.h
r5781 r8351 210 210 } 211 211 212 213 /**@brief Return the inverse of this quaternion */ 212 /**@brief Return the axis of the rotation represented by this quaternion */ 213 btVector3 getAxis() const 214 { 215 btScalar s_squared = btScalar(1.) - btPow(m_floats[3], btScalar(2.)); 216 if (s_squared < btScalar(10.) * SIMD_EPSILON) //Check for divide by zero 217 return btVector3(1.0, 0.0, 0.0); // Arbitrary 218 btScalar s = btSqrt(s_squared); 219 return btVector3(m_floats[0] / s, m_floats[1] / s, m_floats[2] / s); 220 } 221 222 /**@brief Return the inverse of this quaternion */ 214 223 btQuaternion inverse() const 215 224 { … … 253 262 } 254 263 264 /**@todo document this and it's use */ 265 SIMD_FORCE_INLINE btQuaternion nearest( const btQuaternion& qd) const 266 { 267 btQuaternion diff,sum; 268 diff = *this - qd; 269 sum = *this + qd; 270 if( diff.dot(diff) < sum.dot(sum) ) 271 return qd; 272 return (-qd); 273 } 274 275 255 276 /**@brief Return the quaternion which is the result of Spherical Linear Interpolation between this and the other quaternion 256 277 * @param q The other quaternion to interpolate with … … 265 286 btScalar s0 = btSin((btScalar(1.0) - t) * theta); 266 287 btScalar s1 = btSin(t * theta); 267 return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d, 268 (m_floats[1] * s0 + q.y() * s1) * d, 269 (m_floats[2] * s0 + q.z() * s1) * d, 270 (m_floats[3] * s0 + q.m_floats[3] * s1) * d); 288 if (dot(q) < 0) // Take care of long angle case see http://en.wikipedia.org/wiki/Slerp 289 return btQuaternion((m_floats[0] * s0 + -q.x() * s1) * d, 290 (m_floats[1] * s0 + -q.y() * s1) * d, 291 (m_floats[2] * s0 + -q.z() * s1) * d, 292 (m_floats[3] * s0 + -q.m_floats[3] * s1) * d); 293 else 294 return btQuaternion((m_floats[0] * s0 + q.x() * s1) * d, 295 (m_floats[1] * s0 + q.y() * s1) * d, 296 (m_floats[2] * s0 + q.z() * s1) * d, 297 (m_floats[3] * s0 + q.m_floats[3] * s1) * d); 298 271 299 } 272 300 else … … 379 407 380 408 if (d < -1.0 + SIMD_EPSILON) 381 return btQuaternion(0.0f,1.0f,0.0f,0.0f); // just pick any vector 409 { 410 btVector3 n,unused; 411 btPlaneSpace1(v0,n,unused); 412 return btQuaternion(n.x(),n.y(),n.z(),0.0f); // just pick any vector that is orthogonal to v0 413 } 382 414 383 415 btScalar s = btSqrt((1.0f + d) * 2.0f); -
code/trunk/src/external/bullet/LinearMath/btQuickprof.cpp
r5781 r8351 1 1 /* 2 2 3 /***************************************************************************************************3 *************************************************************************************************** 4 4 ** 5 5 ** profile.cpp … … 14 14 // Ogre (www.ogre3d.org). 15 15 16 #include " LinearMath/btQuickprof.h"17 18 19 #ifdef USE_BT_CLOCK 16 #include "btQuickprof.h" 17 18 #ifndef BT_NO_PROFILE 19 20 20 21 21 static btClock gProfileClock; 22 23 24 #ifdef __CELLOS_LV2__ 25 #include <sys/sys_time.h> 26 #include <sys/time_util.h> 27 #include <stdio.h> 28 #endif 29 30 #if defined (SUNOS) || defined (__SUNOS__) 31 #include <stdio.h> 32 #endif 33 34 #if defined(WIN32) || defined(_WIN32) 35 36 #define BT_USE_WINDOWS_TIMERS 37 #define WIN32_LEAN_AND_MEAN 38 #define NOWINRES 39 #define NOMCX 40 #define NOIME 41 42 #ifdef _XBOX 43 #include <Xtl.h> 44 #else //_XBOX 45 #include <windows.h> 46 #endif //_XBOX 47 48 #include <time.h> 49 50 51 #else //_WIN32 52 #include <sys/time.h> 53 #endif //_WIN32 54 55 #define mymin(a,b) (a > b ? a : b) 56 57 struct btClockData 58 { 59 60 #ifdef BT_USE_WINDOWS_TIMERS 61 LARGE_INTEGER mClockFrequency; 62 DWORD mStartTick; 63 LONGLONG mPrevElapsedTime; 64 LARGE_INTEGER mStartTime; 65 #else 66 #ifdef __CELLOS_LV2__ 67 uint64_t mStartTime; 68 #else 69 struct timeval mStartTime; 70 #endif 71 #endif //__CELLOS_LV2__ 72 73 }; 74 75 ///The btClock is a portable basic clock that measures accurate time in seconds, use for profiling. 76 btClock::btClock() 77 { 78 m_data = new btClockData; 79 #ifdef BT_USE_WINDOWS_TIMERS 80 QueryPerformanceFrequency(&m_data->mClockFrequency); 81 #endif 82 reset(); 83 } 84 85 btClock::~btClock() 86 { 87 delete m_data; 88 } 89 90 btClock::btClock(const btClock& other) 91 { 92 m_data = new btClockData; 93 *m_data = *other.m_data; 94 } 95 96 btClock& btClock::operator=(const btClock& other) 97 { 98 *m_data = *other.m_data; 99 return *this; 100 } 101 102 103 /// Resets the initial reference time. 104 void btClock::reset() 105 { 106 #ifdef BT_USE_WINDOWS_TIMERS 107 QueryPerformanceCounter(&m_data->mStartTime); 108 m_data->mStartTick = GetTickCount(); 109 m_data->mPrevElapsedTime = 0; 110 #else 111 #ifdef __CELLOS_LV2__ 112 113 typedef uint64_t ClockSize; 114 ClockSize newTime; 115 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 116 SYS_TIMEBASE_GET( newTime ); 117 m_data->mStartTime = newTime; 118 #else 119 gettimeofday(&m_data->mStartTime, 0); 120 #endif 121 #endif 122 } 123 124 /// Returns the time in ms since the last call to reset or since 125 /// the btClock was created. 126 unsigned long int btClock::getTimeMilliseconds() 127 { 128 #ifdef BT_USE_WINDOWS_TIMERS 129 LARGE_INTEGER currentTime; 130 QueryPerformanceCounter(¤tTime); 131 LONGLONG elapsedTime = currentTime.QuadPart - 132 m_data->mStartTime.QuadPart; 133 // Compute the number of millisecond ticks elapsed. 134 unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / 135 m_data->mClockFrequency.QuadPart); 136 // Check for unexpected leaps in the Win32 performance counter. 137 // (This is caused by unexpected data across the PCI to ISA 138 // bridge, aka south bridge. See Microsoft KB274323.) 139 unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; 140 signed long msecOff = (signed long)(msecTicks - elapsedTicks); 141 if (msecOff < -100 || msecOff > 100) 142 { 143 // Adjust the starting time forwards. 144 LONGLONG msecAdjustment = mymin(msecOff * 145 m_data->mClockFrequency.QuadPart / 1000, elapsedTime - 146 m_data->mPrevElapsedTime); 147 m_data->mStartTime.QuadPart += msecAdjustment; 148 elapsedTime -= msecAdjustment; 149 150 // Recompute the number of millisecond ticks elapsed. 151 msecTicks = (unsigned long)(1000 * elapsedTime / 152 m_data->mClockFrequency.QuadPart); 153 } 154 155 // Store the current elapsed time for adjustments next time. 156 m_data->mPrevElapsedTime = elapsedTime; 157 158 return msecTicks; 159 #else 160 161 #ifdef __CELLOS_LV2__ 162 uint64_t freq=sys_time_get_timebase_frequency(); 163 double dFreq=((double) freq) / 1000.0; 164 typedef uint64_t ClockSize; 165 ClockSize newTime; 166 SYS_TIMEBASE_GET( newTime ); 167 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 168 169 return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq); 170 #else 171 172 struct timeval currentTime; 173 gettimeofday(¤tTime, 0); 174 return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 + 175 (currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000; 176 #endif //__CELLOS_LV2__ 177 #endif 178 } 179 180 /// Returns the time in us since the last call to reset or since 181 /// the Clock was created. 182 unsigned long int btClock::getTimeMicroseconds() 183 { 184 #ifdef BT_USE_WINDOWS_TIMERS 185 LARGE_INTEGER currentTime; 186 QueryPerformanceCounter(¤tTime); 187 LONGLONG elapsedTime = currentTime.QuadPart - 188 m_data->mStartTime.QuadPart; 189 190 // Compute the number of millisecond ticks elapsed. 191 unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / 192 m_data->mClockFrequency.QuadPart); 193 194 // Check for unexpected leaps in the Win32 performance counter. 195 // (This is caused by unexpected data across the PCI to ISA 196 // bridge, aka south bridge. See Microsoft KB274323.) 197 unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; 198 signed long msecOff = (signed long)(msecTicks - elapsedTicks); 199 if (msecOff < -100 || msecOff > 100) 200 { 201 // Adjust the starting time forwards. 202 LONGLONG msecAdjustment = mymin(msecOff * 203 m_data->mClockFrequency.QuadPart / 1000, elapsedTime - 204 m_data->mPrevElapsedTime); 205 m_data->mStartTime.QuadPart += msecAdjustment; 206 elapsedTime -= msecAdjustment; 207 } 208 209 // Store the current elapsed time for adjustments next time. 210 m_data->mPrevElapsedTime = elapsedTime; 211 212 // Convert to microseconds. 213 unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime / 214 m_data->mClockFrequency.QuadPart); 215 216 return usecTicks; 217 #else 218 219 #ifdef __CELLOS_LV2__ 220 uint64_t freq=sys_time_get_timebase_frequency(); 221 double dFreq=((double) freq)/ 1000000.0; 222 typedef uint64_t ClockSize; 223 ClockSize newTime; 224 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 225 SYS_TIMEBASE_GET( newTime ); 226 227 return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq); 228 #else 229 230 struct timeval currentTime; 231 gettimeofday(¤tTime, 0); 232 return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 + 233 (currentTime.tv_usec - m_data->mStartTime.tv_usec); 234 #endif//__CELLOS_LV2__ 235 #endif 236 } 237 238 239 240 22 241 23 242 inline void Profile_Get_Ticks(unsigned long int * ticks) … … 343 562 344 563 345 #endif //USE_BT_CLOCK 346 564 565 #endif //BT_NO_PROFILE -
code/trunk/src/external/bullet/LinearMath/btQuickprof.h
r5781 r8351 19 19 //#define BT_NO_PROFILE 1 20 20 #ifndef BT_NO_PROFILE 21 21 #include <stdio.h>//@todo remove this, backwards compatibility 22 22 #include "btScalar.h" 23 #include " LinearMath/btAlignedAllocator.h"23 #include "btAlignedAllocator.h" 24 24 #include <new> 25 25 … … 27 27 28 28 29 //if you don't need btClock, you can comment next line 29 30 30 #define USE_BT_CLOCK 1 31 31 32 32 #ifdef USE_BT_CLOCK 33 #ifdef __CELLOS_LV2__34 #include <sys/sys_time.h>35 #include <sys/time_util.h>36 #include <stdio.h>37 #endif38 39 #if defined (SUNOS) || defined (__SUNOS__)40 #include <stdio.h>41 #endif42 43 #if defined(WIN32) || defined(_WIN32)44 45 #define USE_WINDOWS_TIMERS46 #define WIN32_LEAN_AND_MEAN47 #define NOWINRES48 #define NOMCX49 #define NOIME50 #ifdef _XBOX51 #include <Xtl.h>52 #else53 #include <windows.h>54 #endif55 #include <time.h>56 57 #else58 #include <sys/time.h>59 #endif60 61 #define mymin(a,b) (a > b ? a : b)62 33 63 34 ///The btClock is a portable basic clock that measures accurate time in seconds, use for profiling. … … 65 36 { 66 37 public: 67 btClock() 68 { 69 #ifdef USE_WINDOWS_TIMERS 70 QueryPerformanceFrequency(&mClockFrequency); 71 #endif 72 reset(); 73 } 38 btClock(); 74 39 75 ~btClock() 76 { 77 } 40 btClock(const btClock& other); 41 btClock& operator=(const btClock& other); 42 43 ~btClock(); 78 44 79 45 /// Resets the initial reference time. 80 void reset() 81 { 82 #ifdef USE_WINDOWS_TIMERS 83 QueryPerformanceCounter(&mStartTime); 84 mStartTick = GetTickCount(); 85 mPrevElapsedTime = 0; 86 #else 87 #ifdef __CELLOS_LV2__ 88 89 typedef uint64_t ClockSize; 90 ClockSize newTime; 91 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 92 SYS_TIMEBASE_GET( newTime ); 93 mStartTime = newTime; 94 #else 95 gettimeofday(&mStartTime, 0); 96 #endif 97 98 #endif 99 } 46 void reset(); 100 47 101 48 /// Returns the time in ms since the last call to reset or since 102 49 /// the btClock was created. 103 unsigned long int getTimeMilliseconds() 104 { 105 #ifdef USE_WINDOWS_TIMERS 106 LARGE_INTEGER currentTime; 107 QueryPerformanceCounter(¤tTime); 108 LONGLONG elapsedTime = currentTime.QuadPart - 109 mStartTime.QuadPart; 110 111 // Compute the number of millisecond ticks elapsed. 112 unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / 113 mClockFrequency.QuadPart); 114 115 // Check for unexpected leaps in the Win32 performance counter. 116 // (This is caused by unexpected data across the PCI to ISA 117 // bridge, aka south bridge. See Microsoft KB274323.) 118 unsigned long elapsedTicks = GetTickCount() - mStartTick; 119 signed long msecOff = (signed long)(msecTicks - elapsedTicks); 120 if (msecOff < -100 || msecOff > 100) 121 { 122 // Adjust the starting time forwards. 123 LONGLONG msecAdjustment = mymin(msecOff * 124 mClockFrequency.QuadPart / 1000, elapsedTime - 125 mPrevElapsedTime); 126 mStartTime.QuadPart += msecAdjustment; 127 elapsedTime -= msecAdjustment; 128 129 // Recompute the number of millisecond ticks elapsed. 130 msecTicks = (unsigned long)(1000 * elapsedTime / 131 mClockFrequency.QuadPart); 132 } 133 134 // Store the current elapsed time for adjustments next time. 135 mPrevElapsedTime = elapsedTime; 136 137 return msecTicks; 138 #else 139 140 #ifdef __CELLOS_LV2__ 141 uint64_t freq=sys_time_get_timebase_frequency(); 142 double dFreq=((double) freq) / 1000.0; 143 typedef uint64_t ClockSize; 144 ClockSize newTime; 145 SYS_TIMEBASE_GET( newTime ); 146 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 147 148 return (unsigned long int)((double(newTime-mStartTime)) / dFreq); 149 #else 150 151 struct timeval currentTime; 152 gettimeofday(¤tTime, 0); 153 return (currentTime.tv_sec - mStartTime.tv_sec) * 1000 + 154 (currentTime.tv_usec - mStartTime.tv_usec) / 1000; 155 #endif //__CELLOS_LV2__ 156 #endif 157 } 50 unsigned long int getTimeMilliseconds(); 158 51 159 52 /// Returns the time in us since the last call to reset or since 160 53 /// the Clock was created. 161 unsigned long int getTimeMicroseconds() 162 { 163 #ifdef USE_WINDOWS_TIMERS 164 LARGE_INTEGER currentTime; 165 QueryPerformanceCounter(¤tTime); 166 LONGLONG elapsedTime = currentTime.QuadPart - 167 mStartTime.QuadPart; 168 169 // Compute the number of millisecond ticks elapsed. 170 unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / 171 mClockFrequency.QuadPart); 172 173 // Check for unexpected leaps in the Win32 performance counter. 174 // (This is caused by unexpected data across the PCI to ISA 175 // bridge, aka south bridge. See Microsoft KB274323.) 176 unsigned long elapsedTicks = GetTickCount() - mStartTick; 177 signed long msecOff = (signed long)(msecTicks - elapsedTicks); 178 if (msecOff < -100 || msecOff > 100) 179 { 180 // Adjust the starting time forwards. 181 LONGLONG msecAdjustment = mymin(msecOff * 182 mClockFrequency.QuadPart / 1000, elapsedTime - 183 mPrevElapsedTime); 184 mStartTime.QuadPart += msecAdjustment; 185 elapsedTime -= msecAdjustment; 186 } 187 188 // Store the current elapsed time for adjustments next time. 189 mPrevElapsedTime = elapsedTime; 190 191 // Convert to microseconds. 192 unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime / 193 mClockFrequency.QuadPart); 194 195 return usecTicks; 196 #else 197 198 #ifdef __CELLOS_LV2__ 199 uint64_t freq=sys_time_get_timebase_frequency(); 200 double dFreq=((double) freq)/ 1000000.0; 201 typedef uint64_t ClockSize; 202 ClockSize newTime; 203 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 204 SYS_TIMEBASE_GET( newTime ); 205 206 return (unsigned long int)((double(newTime-mStartTime)) / dFreq); 207 #else 208 209 struct timeval currentTime; 210 gettimeofday(¤tTime, 0); 211 return (currentTime.tv_sec - mStartTime.tv_sec) * 1000000 + 212 (currentTime.tv_usec - mStartTime.tv_usec); 213 #endif//__CELLOS_LV2__ 214 #endif 215 } 216 54 unsigned long int getTimeMicroseconds(); 217 55 private: 218 #ifdef USE_WINDOWS_TIMERS 219 LARGE_INTEGER mClockFrequency; 220 DWORD mStartTick; 221 LONGLONG mPrevElapsedTime; 222 LARGE_INTEGER mStartTime; 223 #else 224 #ifdef __CELLOS_LV2__ 225 uint64_t mStartTime; 226 #else 227 struct timeval mStartTime; 228 #endif 229 #endif //__CELLOS_LV2__ 230 56 struct btClockData* m_data; 231 57 }; 232 58 -
code/trunk/src/external/bullet/LinearMath/btScalar.h
r5781 r8351 1 1 /* 2 Copyright (c) 2003-200 6 Gino van den Bergen / Erwin Coumans http://continuousphysics.com/Bullet/2 Copyright (c) 2003-2009 Erwin Coumans http://bullet.googlecode.com 3 3 4 4 This software is provided 'as-is', without any express or implied warranty. … … 18 18 #define SIMD___SCALAR_H 19 19 20 #ifdef BT_MANAGED_CODE 21 //Aligned data types not supported in managed code 22 #pragma unmanaged 23 #endif 24 25 20 26 #include <math.h> 21 22 27 #include <stdlib.h>//size_t for MSVC 6.0 23 24 28 #include <cstdlib> 25 29 #include <cfloat> 26 30 #include <float.h> 27 31 28 #define BT_BULLET_VERSION 274 32 /* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/ 33 #define BT_BULLET_VERSION 277 29 34 30 35 inline int btGetVersion() … … 38 43 39 44 40 #ifdef WIN3245 #ifdef _WIN32 41 46 42 47 #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300) … … 44 49 #define SIMD_FORCE_INLINE inline 45 50 #define ATTRIBUTE_ALIGNED16(a) a 51 #define ATTRIBUTE_ALIGNED64(a) a 46 52 #define ATTRIBUTE_ALIGNED128(a) a 47 53 #else … … 54 60 #define SIMD_FORCE_INLINE __forceinline 55 61 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a 62 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a 56 63 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a 57 64 #ifdef _XBOX … … 63 70 #else 64 71 65 #if (defined ( WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))72 #if (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION)) 66 73 #define BT_USE_SSE 67 74 #include <emmintrin.h> … … 87 94 88 95 #if defined (__CELLOS_LV2__) 89 #define SIMD_FORCE_INLINE inline 96 #define SIMD_FORCE_INLINE inline __attribute__((always_inline)) 90 97 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 98 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 99 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 100 #ifndef assert 101 #include <assert.h> 102 #endif 103 #ifdef BT_DEBUG 104 #ifdef __SPU__ 105 #include <spu_printf.h> 106 #define printf spu_printf 107 #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}} 108 #else 109 #define btAssert assert 110 #endif 111 112 #else 113 #define btAssert(x) 114 #endif 115 //btFullAssert is optional, slows down a lot 116 #define btFullAssert(x) 117 118 #define btLikely(_c) _c 119 #define btUnlikely(_c) _c 120 121 #else 122 123 #ifdef USE_LIBSPE2 124 125 #define SIMD_FORCE_INLINE __inline 126 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 127 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 91 128 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 92 129 #ifndef assert … … 101 138 #define btFullAssert(x) 102 139 103 #define btLikely(_c) _c104 #define btUnlikely(_c) _c105 106 #else107 108 #ifdef USE_LIBSPE2109 110 #define SIMD_FORCE_INLINE __inline111 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))112 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))113 #ifndef assert114 #include <assert.h>115 #endif116 #ifdef BT_DEBUG117 #define btAssert assert118 #else119 #define btAssert(x)120 #endif121 //btFullAssert is optional, slows down a lot122 #define btFullAssert(x)123 124 140 125 141 #define btLikely(_c) __builtin_expect((_c), 1) … … 130 146 //non-windows systems 131 147 148 #if (defined (__APPLE__) && defined (__i386__) && (!defined (BT_USE_DOUBLE_PRECISION))) 149 #define BT_USE_SSE 150 #include <emmintrin.h> 151 152 #define SIMD_FORCE_INLINE inline 153 ///@todo: check out alignment methods for other platforms/compilers 154 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 155 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 156 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 157 #ifndef assert 158 #include <assert.h> 159 #endif 160 161 #if defined(DEBUG) || defined (_DEBUG) 162 #define btAssert assert 163 #else 164 #define btAssert(x) 165 #endif 166 167 //btFullAssert is optional, slows down a lot 168 #define btFullAssert(x) 169 #define btLikely(_c) _c 170 #define btUnlikely(_c) _c 171 172 #else 173 132 174 #define SIMD_FORCE_INLINE inline 133 175 ///@todo: check out alignment methods for other platforms/compilers 134 176 ///#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16))) 177 ///#define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64))) 135 178 ///#define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128))) 136 179 #define ATTRIBUTE_ALIGNED16(a) a 180 #define ATTRIBUTE_ALIGNED64(a) a 137 181 #define ATTRIBUTE_ALIGNED128(a) a 138 182 #ifndef assert … … 150 194 #define btLikely(_c) _c 151 195 #define btUnlikely(_c) _c 152 196 #endif //__APPLE__ 153 197 154 198 #endif // LIBSPE2 … … 157 201 #endif 158 202 159 /// older compilers (gcc 3.x) and Sun needs double version of sqrt etc.160 /// exclude Apple Intel (i's assumed to be a Macbook or new Intel Dual Core Processor)161 #if defined (__sun) || defined (__sun__) || defined (__sparc) || (defined (__APPLE__) && ! defined (__i386__))162 //use slow double float precision operation on those platforms163 #ifndef BT_USE_DOUBLE_PRECISION164 #define BT_FORCE_DOUBLE_FUNCTIONS165 #endif166 #endif167 203 168 204 ///The btScalar type abstracts floating point numbers, to easily switch between double and single floating point precision. 169 205 #if defined(BT_USE_DOUBLE_PRECISION) 170 206 typedef double btScalar; 207 //this number could be bigger in double precision 208 #define BT_LARGE_FLOAT 1e30 171 209 #else 172 210 typedef float btScalar; 211 //keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX 212 #define BT_LARGE_FLOAT 1e18f 173 213 #endif 174 214 … … 194 234 SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sin(x); } 195 235 SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tan(x); } 196 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { return acos(x); }197 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asin(x); }236 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { if (x<btScalar(-1)) x=btScalar(-1); if (x>btScalar(1)) x=btScalar(1); return acos(x); } 237 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { if (x<btScalar(-1)) x=btScalar(-1); if (x>btScalar(1)) x=btScalar(1); return asin(x); } 198 238 SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atan(x); } 199 239 SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2(x, y); } … … 201 241 SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return log(x); } 202 242 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return pow(x,y); } 243 SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmod(x,y); } 203 244 204 245 #else … … 213 254 *tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */ 214 255 x = tempf; 215 z = y*btScalar(0.5); /* hoist out the /2 */256 z = y*btScalar(0.5); 216 257 x = (btScalar(1.5)*x)-(x*x)*(x*z); /* iteration formula */ 217 258 x = (btScalar(1.5)*x)-(x*x)*(x*z); … … 229 270 SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); } 230 271 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { 231 btAssert(x <= btScalar(1.)); 272 if (x<btScalar(-1)) 273 x=btScalar(-1); 274 if (x>btScalar(1)) 275 x=btScalar(1); 232 276 return acosf(x); 233 277 } 234 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asinf(x); } 278 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { 279 if (x<btScalar(-1)) 280 x=btScalar(-1); 281 if (x>btScalar(1)) 282 x=btScalar(1); 283 return asinf(x); 284 } 235 285 SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); } 236 286 SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); } … … 242 292 SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 243 293 #endif 294 SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmodf(x,y); } 244 295 245 296 #endif … … 250 301 #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0)) 251 302 #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI) 303 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490) 304 305 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x)))) /* reciprocal square root */ 306 252 307 253 308 #ifdef BT_USE_DOUBLE_PRECISION … … 440 495 } 441 496 442 497 // returns normalized value in range [-SIMD_PI, SIMD_PI] 498 SIMD_FORCE_INLINE btScalar btNormalizeAngle(btScalar angleInRadians) 499 { 500 angleInRadians = btFmod(angleInRadians, SIMD_2_PI); 501 if(angleInRadians < -SIMD_PI) 502 { 503 return angleInRadians + SIMD_2_PI; 504 } 505 else if(angleInRadians > SIMD_PI) 506 { 507 return angleInRadians - SIMD_2_PI; 508 } 509 else 510 { 511 return angleInRadians; 512 } 513 } 514 515 ///rudimentary class to provide type info 516 struct btTypedObject 517 { 518 btTypedObject(int objectType) 519 :m_objectType(objectType) 520 { 521 } 522 int m_objectType; 523 inline int getObjectType() const 524 { 525 return m_objectType; 526 } 527 }; 443 528 #endif //SIMD___SCALAR_H -
code/trunk/src/external/bullet/LinearMath/btTransform.h
r5781 r8351 18 18 #define btTransform_H 19 19 20 #include "btVector3.h" 20 21 21 #include "btMatrix3x3.h" 22 23 #ifdef BT_USE_DOUBLE_PRECISION 24 #define btTransformData btTransformDoubleData 25 #else 26 #define btTransformData btTransformFloatData 27 #endif 28 29 22 30 23 31 … … 26 34 class btTransform { 27 35 36 ///Storage for the rotation 37 btMatrix3x3 m_basis; 38 ///Storage for the translation 39 btVector3 m_origin; 28 40 29 41 public: … … 196 208 return identityTransform; 197 209 } 198 199 private: 200 ///Storage for the rotation 201 btMatrix3x3 m_basis; 202 ///Storage for the translation 203 btVector3 m_origin; 210 211 void serialize(struct btTransformData& dataOut) const; 212 213 void serializeFloat(struct btTransformFloatData& dataOut) const; 214 215 void deSerialize(const struct btTransformData& dataIn); 216 217 void deSerializeDouble(const struct btTransformDoubleData& dataIn); 218 219 void deSerializeFloat(const struct btTransformFloatData& dataIn); 220 204 221 }; 205 222 … … 235 252 236 253 254 ///for serialization 255 struct btTransformFloatData 256 { 257 btMatrix3x3FloatData m_basis; 258 btVector3FloatData m_origin; 259 }; 260 261 struct btTransformDoubleData 262 { 263 btMatrix3x3DoubleData m_basis; 264 btVector3DoubleData m_origin; 265 }; 266 267 268 269 SIMD_FORCE_INLINE void btTransform::serialize(btTransformData& dataOut) const 270 { 271 m_basis.serialize(dataOut.m_basis); 272 m_origin.serialize(dataOut.m_origin); 273 } 274 275 SIMD_FORCE_INLINE void btTransform::serializeFloat(btTransformFloatData& dataOut) const 276 { 277 m_basis.serializeFloat(dataOut.m_basis); 278 m_origin.serializeFloat(dataOut.m_origin); 279 } 280 281 282 SIMD_FORCE_INLINE void btTransform::deSerialize(const btTransformData& dataIn) 283 { 284 m_basis.deSerialize(dataIn.m_basis); 285 m_origin.deSerialize(dataIn.m_origin); 286 } 287 288 SIMD_FORCE_INLINE void btTransform::deSerializeFloat(const btTransformFloatData& dataIn) 289 { 290 m_basis.deSerializeFloat(dataIn.m_basis); 291 m_origin.deSerializeFloat(dataIn.m_origin); 292 } 293 294 SIMD_FORCE_INLINE void btTransform::deSerializeDouble(const btTransformDoubleData& dataIn) 295 { 296 m_basis.deSerializeDouble(dataIn.m_basis); 297 m_origin.deSerializeDouble(dataIn.m_origin); 298 } 299 300 237 301 #endif 238 302 -
code/trunk/src/external/bullet/LinearMath/btTransformUtil.h
r5781 r8351 22 22 23 23 24 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)25 26 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x)))) /* reciprocal square root */27 24 28 25 SIMD_FORCE_INLINE btVector3 btAabbSupport(const btVector3& halfExtents,const btVector3& supportDir) … … 34 31 35 32 36 SIMD_FORCE_INLINE void btPlaneSpace1 (const btVector3& n, btVector3& p, btVector3& q) 37 { 38 if (btFabs(n.z()) > SIMDSQRT12) { 39 // choose p in y-z plane 40 btScalar a = n[1]*n[1] + n[2]*n[2]; 41 btScalar k = btRecipSqrt (a); 42 p.setValue(0,-n[2]*k,n[1]*k); 43 // set q = n x p 44 q.setValue(a*k,-n[0]*p[2],n[0]*p[1]); 45 } 46 else { 47 // choose p in x-y plane 48 btScalar a = n.x()*n.x() + n.y()*n.y(); 49 btScalar k = btRecipSqrt (a); 50 p.setValue(-n.y()*k,n.x()*k,0); 51 // set q = n x p 52 q.setValue(-n.z()*p.y(),n.z()*p.x(),a*k); 53 } 54 } 33 55 34 56 35 … … 118 97 static void calculateDiffAxisAngleQuaternion(const btQuaternion& orn0,const btQuaternion& orn1a,btVector3& axis,btScalar& angle) 119 98 { 120 btQuaternion orn1 = orn0. farthest(orn1a);99 btQuaternion orn1 = orn0.nearest(orn1a); 121 100 btQuaternion dorn = orn1 * orn0.inverse(); 122 ///floating point inaccuracy can lead to w component > 1..., which breaks123 dorn.normalize();124 101 angle = dorn.getAngle(); 125 102 axis = btVector3(dorn.x(),dorn.y(),dorn.z()); … … 210 187 btScalar maxAngularProjectedVelocity = angVelA.length() * m_boundingRadiusA + angVelB.length() * m_boundingRadiusB; 211 188 btVector3 relLinVel = (linVelB-linVelA); 212 btScalar relLinVelocLength = (linVelB-linVelA).dot(m_separatingNormal);189 btScalar relLinVelocLength = relLinVel.dot(m_separatingNormal); 213 190 if (relLinVelocLength<0.f) 214 191 { … … 228 205 void initSeparatingDistance(const btVector3& separatingVector,btScalar separatingDistance,const btTransform& transA,const btTransform& transB) 229 206 { 230 m_separatingNormal = separatingVector;231 207 m_separatingDistance = separatingDistance; 232 233 const btVector3& toPosA = transA.getOrigin(); 234 const btVector3& toPosB = transB.getOrigin(); 235 btQuaternion toOrnA = transA.getRotation(); 236 btQuaternion toOrnB = transB.getRotation(); 237 m_posA = toPosA; 238 m_posB = toPosB; 239 m_ornA = toOrnA; 240 m_ornB = toOrnB; 208 209 if (m_separatingDistance>0.f) 210 { 211 m_separatingNormal = separatingVector; 212 213 const btVector3& toPosA = transA.getOrigin(); 214 const btVector3& toPosB = transB.getOrigin(); 215 btQuaternion toOrnA = transA.getRotation(); 216 btQuaternion toOrnB = transB.getRotation(); 217 m_posA = toPosA; 218 m_posB = toPosB; 219 m_ornA = toOrnA; 220 m_ornB = toOrnB; 221 } 241 222 } 242 223 -
code/trunk/src/external/bullet/LinearMath/btVector3.h
r5781 r8351 20 20 21 21 #include "btScalar.h" 22 #include "btScalar.h"23 22 #include "btMinMax.h" 23 24 #ifdef BT_USE_DOUBLE_PRECISION 25 #define btVector3Data btVector3DoubleData 26 #define btVector3DataName "btVector3DoubleData" 27 #else 28 #define btVector3Data btVector3FloatData 29 #define btVector3DataName "btVector3FloatData" 30 #endif //BT_USE_DOUBLE_PRECISION 31 32 33 34 24 35 /**@brief btVector3 can be used to represent 3D points and vectors. 25 36 * It has an un-used w component to suit 16-byte alignment when btVector3 is stored in containers. This extra component can be used by derived classes (Quaternion?) or by user 26 37 * Ideally, this class should be replaced by a platform optimized SIMD version that keeps the data in registers 27 38 */ 28 29 39 ATTRIBUTE_ALIGNED16(class) btVector3 30 40 { … … 32 42 33 43 #if defined (__SPU__) && defined (__CELLOS_LV2__) 34 union {35 vec_float4 mVec128;36 44 btScalar m_floats[4]; 37 };38 45 public: 39 vec_float4get128() const40 { 41 return mVec128;46 SIMD_FORCE_INLINE const vec_float4& get128() const 47 { 48 return *((const vec_float4*)&m_floats[0]); 42 49 } 43 50 public: 44 51 #else //__CELLOS_LV2__ __SPU__ 45 #ifdef BT_USE_SSE // WIN3252 #ifdef BT_USE_SSE // _WIN32 46 53 union { 47 54 __m128 mVec128; … … 142 149 SIMD_FORCE_INLINE btScalar distance(const btVector3& v) const; 143 150 151 SIMD_FORCE_INLINE btVector3& safeNormalize() 152 { 153 btVector3 absVec = this->absolute(); 154 int maxIndex = absVec.maxAxis(); 155 if (absVec[maxIndex]>0) 156 { 157 *this /= absVec[maxIndex]; 158 return *this /= length(); 159 } 160 setValue(1,0,0); 161 return *this; 162 } 163 144 164 /**@brief Normalize this vector 145 165 * x^2 + y^2 + z^2 = 1 */ … … 152 172 SIMD_FORCE_INLINE btVector3 normalized() const; 153 173 154 /**@brief R otate this vector174 /**@brief Return a rotated version of this vector 155 175 * @param wAxis The axis to rotate about 156 176 * @param angle The angle to rotate by */ 157 SIMD_FORCE_INLINE btVector3 rotate( const btVector3& wAxis, const btScalar angle ) ;177 SIMD_FORCE_INLINE btVector3 rotate( const btVector3& wAxis, const btScalar angle ) const; 158 178 159 179 /**@brief Return the angle between this and another vector … … 307 327 m_floats[1]=y; 308 328 m_floats[2]=z; 309 m_floats[3] = 0.f;329 m_floats[3] = btScalar(0.); 310 330 } 311 331 … … 316 336 v2->setValue(-y() ,x() ,0.); 317 337 } 338 339 void setZero() 340 { 341 setValue(btScalar(0.),btScalar(0.),btScalar(0.)); 342 } 343 344 SIMD_FORCE_INLINE bool isZero() const 345 { 346 return m_floats[0] == btScalar(0) && m_floats[1] == btScalar(0) && m_floats[2] == btScalar(0); 347 } 348 349 SIMD_FORCE_INLINE bool fuzzyZero() const 350 { 351 return length2() < SIMD_EPSILON; 352 } 353 354 SIMD_FORCE_INLINE void serialize(struct btVector3Data& dataOut) const; 355 356 SIMD_FORCE_INLINE void deSerialize(const struct btVector3Data& dataIn); 357 358 SIMD_FORCE_INLINE void serializeFloat(struct btVector3FloatData& dataOut) const; 359 360 SIMD_FORCE_INLINE void deSerializeFloat(const struct btVector3FloatData& dataIn); 361 362 SIMD_FORCE_INLINE void serializeDouble(struct btVector3DoubleData& dataOut) const; 363 364 SIMD_FORCE_INLINE void deSerializeDouble(const struct btVector3DoubleData& dataIn); 318 365 319 366 }; … … 377 424 /**@brief Return the dot product between two vectors */ 378 425 SIMD_FORCE_INLINE btScalar 379 dot(const btVector3& v1, const btVector3& v2)426 btDot(const btVector3& v1, const btVector3& v2) 380 427 { 381 428 return v1.dot(v2); … … 385 432 /**@brief Return the distance squared between two vectors */ 386 433 SIMD_FORCE_INLINE btScalar 387 distance2(const btVector3& v1, const btVector3& v2)434 btDistance2(const btVector3& v1, const btVector3& v2) 388 435 { 389 436 return v1.distance2(v2); … … 393 440 /**@brief Return the distance between two vectors */ 394 441 SIMD_FORCE_INLINE btScalar 395 distance(const btVector3& v1, const btVector3& v2)442 btDistance(const btVector3& v1, const btVector3& v2) 396 443 { 397 444 return v1.distance(v2); … … 400 447 /**@brief Return the angle between two vectors */ 401 448 SIMD_FORCE_INLINE btScalar 402 angle(const btVector3& v1, const btVector3& v2)449 btAngle(const btVector3& v1, const btVector3& v2) 403 450 { 404 451 return v1.angle(v2); … … 407 454 /**@brief Return the cross product of two vectors */ 408 455 SIMD_FORCE_INLINE btVector3 409 cross(const btVector3& v1, const btVector3& v2)456 btCross(const btVector3& v1, const btVector3& v2) 410 457 { 411 458 return v1.cross(v2); … … 413 460 414 461 SIMD_FORCE_INLINE btScalar 415 triple(const btVector3& v1, const btVector3& v2, const btVector3& v3)462 btTriple(const btVector3& v1, const btVector3& v2, const btVector3& v3) 416 463 { 417 464 return v1.triple(v2, v3); … … 445 492 } 446 493 447 SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btScalar angle ) 494 SIMD_FORCE_INLINE btVector3 btVector3::rotate( const btVector3& wAxis, const btScalar angle ) const 448 495 { 449 496 // wAxis must be a unit lenght vector … … 489 536 { 490 537 int maxIndex = -1; 491 btScalar maxVal = btScalar(- 1e30);538 btScalar maxVal = btScalar(-BT_LARGE_FLOAT); 492 539 if (m_floats[0] > maxVal) 493 540 { … … 522 569 { 523 570 int minIndex = -1; 524 btScalar minVal = btScalar( 1e30);571 btScalar minVal = btScalar(BT_LARGE_FLOAT); 525 572 if (m_floats[0] < minVal) 526 573 { … … 585 632 } 586 633 587 588 589 634 590 635 }; … … 636 681 } 637 682 683 template <class T> 684 SIMD_FORCE_INLINE void btPlaneSpace1 (const T& n, T& p, T& q) 685 { 686 if (btFabs(n[2]) > SIMDSQRT12) { 687 // choose p in y-z plane 688 btScalar a = n[1]*n[1] + n[2]*n[2]; 689 btScalar k = btRecipSqrt (a); 690 p[0] = 0; 691 p[1] = -n[2]*k; 692 p[2] = n[1]*k; 693 // set q = n x p 694 q[0] = a*k; 695 q[1] = -n[0]*p[2]; 696 q[2] = n[0]*p[1]; 697 } 698 else { 699 // choose p in x-y plane 700 btScalar a = n[0]*n[0] + n[1]*n[1]; 701 btScalar k = btRecipSqrt (a); 702 p[0] = -n[1]*k; 703 p[1] = n[0]*k; 704 p[2] = 0; 705 // set q = n x p 706 q[0] = -n[2]*p[1]; 707 q[1] = n[2]*p[0]; 708 q[2] = a*k; 709 } 710 } 711 712 713 struct btVector3FloatData 714 { 715 float m_floats[4]; 716 }; 717 718 struct btVector3DoubleData 719 { 720 double m_floats[4]; 721 722 }; 723 724 SIMD_FORCE_INLINE void btVector3::serializeFloat(struct btVector3FloatData& dataOut) const 725 { 726 ///could also do a memcpy, check if it is worth it 727 for (int i=0;i<4;i++) 728 dataOut.m_floats[i] = float(m_floats[i]); 729 } 730 731 SIMD_FORCE_INLINE void btVector3::deSerializeFloat(const struct btVector3FloatData& dataIn) 732 { 733 for (int i=0;i<4;i++) 734 m_floats[i] = btScalar(dataIn.m_floats[i]); 735 } 736 737 738 SIMD_FORCE_INLINE void btVector3::serializeDouble(struct btVector3DoubleData& dataOut) const 739 { 740 ///could also do a memcpy, check if it is worth it 741 for (int i=0;i<4;i++) 742 dataOut.m_floats[i] = double(m_floats[i]); 743 } 744 745 SIMD_FORCE_INLINE void btVector3::deSerializeDouble(const struct btVector3DoubleData& dataIn) 746 { 747 for (int i=0;i<4;i++) 748 m_floats[i] = btScalar(dataIn.m_floats[i]); 749 } 750 751 752 SIMD_FORCE_INLINE void btVector3::serialize(struct btVector3Data& dataOut) const 753 { 754 ///could also do a memcpy, check if it is worth it 755 for (int i=0;i<4;i++) 756 dataOut.m_floats[i] = m_floats[i]; 757 } 758 759 SIMD_FORCE_INLINE void btVector3::deSerialize(const struct btVector3Data& dataIn) 760 { 761 for (int i=0;i<4;i++) 762 m_floats[i] = dataIn.m_floats[i]; 763 } 764 765 638 766 #endif //SIMD__VECTOR3_H -
code/trunk/src/external/bullet/NEWS
r5781 r8351 1 1 2 For news, visit the Bullet Physics Forumat3 http://www. continuousphysics.com/Bullet/phpBB2/viewforum.php?f=92 For news, visit the Bullet Physics forums at 3 http://www.bulletphysics.org 4 4 -
code/trunk/src/external/bullet/README
r5781 r8351 2 2 Bullet is a 3D Collision Detection and Rigid Body Dynamics Library for games and animation. 3 3 Free for commercial use, including Playstation 3, open source under the ZLib License. 4 Discrete and continuous collision detection, integrated into Blender 3D, and COLLADA 1.4 Physics import.5 4 6 5 See the Bullet_User_Manual.pdf for more info and visit the Bullet Physics Forum at 7 http://bulletphysics. com6 http://bulletphysics.org -
code/trunk/src/external/bullet/VERSION
r5781 r8351 1 2.7 31 2.77 -
code/trunk/src/external/bullet/btBulletCollisionCommon.h
r5781 r8351 62 62 #include "LinearMath/btQuickprof.h" 63 63 #include "LinearMath/btIDebugDraw.h" 64 #include "LinearMath/btSerializer.h" 65 64 66 65 67 #endif //BULLET_COLLISION_COMMON_H -
code/trunk/src/external/bullet/btBulletDynamicsCommon.h
r5781 r8351 31 31 #include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h" 32 32 #include "BulletDynamics/ConstraintSolver/btSliderConstraint.h" 33 #include "BulletDynamics/ConstraintSolver/btGeneric6DofSpringConstraint.h" 34 #include "BulletDynamics/ConstraintSolver/btUniversalConstraint.h" 35 #include "BulletDynamics/ConstraintSolver/btHinge2Constraint.h" 33 36 34 37 #include "BulletDynamics/ConstraintSolver/btSequentialImpulseConstraintSolver.h" -
code/trunk/src/external/bullet/changes_orxonox.diff
r5781 r8351 1 Index: btScalar.h 2 =================================================================== 3 --- btScalar.h (revision 2882) 4 +++ btScalar.h (working copy) 5 @@ -236,7 +236,11 @@ 1 --- LinearMath/btScalar.h Tue Aug 10 13:19:44 2010 2 +++ LinearMath/btScalar.h Sun Feb 27 01:27:34 2011 3 @@ -286,7 +286,11 @@ 6 4 SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); } 7 5 SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return expf(x); } … … 13 11 + SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); } 14 12 + #endif 15 13 SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmodf(x,y); } 14 16 15 #endif 17 -
code/trunk/src/external/cpptcl/changes_orxonox.diff
r5781 r8351 1 --- cpptcl.cc So Feb 8 23:14:34 2009 2 +++ cpptcl.cc So Feb 8 23:13:07 2009 3 @@ -320,7 +320,7 @@ 1 --- cpptcl.cc Fri Apr 22 12:18:47 2011 2 +++ cpptcl.cc Fri Apr 22 12:20:02 2011 3 @@ -16,7 +16,8 @@ 4 using namespace Tcl; 5 using namespace Tcl::details; 6 using namespace std; 7 -using namespace boost; 8 +// boost::shared_ptr conflicts with the new std::shared_ptr 9 +//using namespace boost; 10 11 12 result::result(Tcl_Interp *interp) : interp_(interp) {} 13 @@ -166,7 +167,7 @@ 14 { 15 16 // map of polymorphic callbacks 17 -typedef map<string, shared_ptr<callback_base> > callback_interp_map; 18 +typedef map<string, boost::shared_ptr<callback_base> > callback_interp_map; 19 typedef map<Tcl_Interp *, callback_interp_map> callback_map; 20 21 callback_map callbacks; 22 @@ -179,7 +180,7 @@ 23 policies_map call_policies; 24 25 // map of object handlers 26 -typedef map<string, shared_ptr<class_handler_base> > class_interp_map; 27 +typedef map<string, boost::shared_ptr<class_handler_base> > class_interp_map; 28 typedef map<Tcl_Interp *, class_interp_map> class_handlers_map; 29 30 class_handlers_map class_handlers; 31 @@ -320,7 +321,7 @@ 4 32 5 33 post_process_policies(interp, pol, objv, false); … … 10 38 Tcl_SetResult(interp, const_cast<char*>(e.what()), TCL_VOLATILE); 11 39 return TCL_ERROR; 12 @@ -363,7 +36 3,7 @@40 @@ -363,7 +364,7 @@ 13 41 14 42 post_process_policies(interp, pol, objv, true); … … 19 47 Tcl_SetResult(interp, const_cast<char*>(e.what()), TCL_VOLATILE); 20 48 return TCL_ERROR; 21 @@ -430,7 +43 0,7 @@49 @@ -430,7 +431,7 @@ 22 50 Tcl_GetString(Tcl_GetObjResult(interp)), 23 51 object_handler, static_cast<ClientData>(chb), 0); … … 28 56 Tcl_SetResult(interp, const_cast<char*>(e.what()), TCL_VOLATILE); 29 57 return TCL_ERROR; 58 @@ -490,7 +491,7 @@ 59 } 60 61 void class_handler_base::register_method(string const &name, 62 - shared_ptr<object_cmd_base> ocb, policies const &p) 63 + boost::shared_ptr<object_cmd_base> ocb, policies const &p) 64 { 65 methods_[name] = ocb; 66 policies_[name] = p; 67 @@ -989,7 +990,7 @@ 68 } 69 70 void interpreter::add_function(string const &name, 71 - shared_ptr<callback_base> cb, policies const &p) 72 + boost::shared_ptr<callback_base> cb, policies const &p) 73 { 74 Tcl_CreateObjCommand(interp_, name.c_str(), 75 callback_handler, 0, 0); 76 @@ -999,13 +1000,13 @@ 77 } 78 79 void interpreter::add_class(string const &name, 80 - shared_ptr<class_handler_base> chb) 81 + boost::shared_ptr<class_handler_base> chb) 82 { 83 class_handlers[interp_][name] = chb; 84 } 85 86 void interpreter::add_constructor(string const &name, 87 - shared_ptr<class_handler_base> chb, shared_ptr<callback_base> cb, 88 + boost::shared_ptr<class_handler_base> chb, boost::shared_ptr<callback_base> cb, 89 policies const &p) 90 { 91 Tcl_CreateObjCommand(interp_, name.c_str(), -
code/trunk/src/external/cpptcl/cpptcl.cc
r5781 r8351 17 17 using namespace Tcl::details; 18 18 using namespace std; 19 using namespace boost; 19 // boost::shared_ptr conflicts with the new std::shared_ptr 20 //using namespace boost; 20 21 21 22 … … 167 168 168 169 // map of polymorphic callbacks 169 typedef map<string, shared_ptr<callback_base> > callback_interp_map;170 typedef map<string, boost::shared_ptr<callback_base> > callback_interp_map; 170 171 typedef map<Tcl_Interp *, callback_interp_map> callback_map; 171 172 … … 180 181 181 182 // map of object handlers 182 typedef map<string, shared_ptr<class_handler_base> > class_interp_map;183 typedef map<string, boost::shared_ptr<class_handler_base> > class_interp_map; 183 184 typedef map<Tcl_Interp *, class_interp_map> class_handlers_map; 184 185 … … 491 492 492 493 void class_handler_base::register_method(string const &name, 493 shared_ptr<object_cmd_base> ocb, policies const &p)494 boost::shared_ptr<object_cmd_base> ocb, policies const &p) 494 495 { 495 496 methods_[name] = ocb; … … 990 991 991 992 void interpreter::add_function(string const &name, 992 shared_ptr<callback_base> cb, policies const &p)993 boost::shared_ptr<callback_base> cb, policies const &p) 993 994 { 994 995 Tcl_CreateObjCommand(interp_, name.c_str(), … … 1000 1001 1001 1002 void interpreter::add_class(string const &name, 1002 shared_ptr<class_handler_base> chb)1003 boost::shared_ptr<class_handler_base> chb) 1003 1004 { 1004 1005 class_handlers[interp_][name] = chb; … … 1006 1007 1007 1008 void interpreter::add_constructor(string const &name, 1008 shared_ptr<class_handler_base> chb,shared_ptr<callback_base> cb,1009 boost::shared_ptr<class_handler_base> chb, boost::shared_ptr<callback_base> cb, 1009 1010 policies const &p) 1010 1011 { -
code/trunk/src/external/enet/CMakeLists.txt
r7459 r8351 29 29 win32.h 30 30 31 win32.c32 33 31 COMPILATION_BEGIN ENetCompilation.c 34 32 callbacks.c … … 40 38 protocol.c 41 39 unix.c 40 win32.c 42 41 COMPILATION_END 43 42 ) … … 45 44 ADD_COMPILER_FLAGS("-DHAS_POLL -DHAS_FCNTL -DHAS_MSGHDR_FLAGS -DHAS_SOCKLEN_T") 46 45 47 IF(WIN32)48 SET(ENET_WIN_LIBS odbc32 odbccp32 winmm ws2_32)49 ENDIF()50 51 46 ORXONOX_ADD_LIBRARY(enet_orxonox 52 47 ORXONOX_EXTERNAL 53 VERSION 1.3.054 DEFINE_SYMBOL "ENET_BUILDING_LIB"55 LINK_LIB RARIES ${ENET_WIN_LIBS}56 SOURCE_FILES ${ENET_FILES}48 VERSION 1.3.1 49 DEFINE_SYMBOL "ENET_BUILDING_LIB" 50 LINK_LIBS_WIN32 odbc32 odbccp32 winmm ws2_32 51 SOURCE_FILES ${ENET_FILES} 57 52 ) -
code/trunk/src/external/enet/patches/0001-Add-IPv6-support-to-Enet.patch
r8088 r8351 908 908 + 909 909 #include <time.h> 910 + #include <ws2tcpip.h>910 + 911 911 #define ENET_BUILDING_LIB 1 912 912 #include "enet/enet.h" -
code/trunk/src/external/enet/win32.c
r8079 r8351 8 8 9 9 #include <time.h> 10 #include <ws2tcpip.h>11 10 #define ENET_BUILDING_LIB 1 12 11 #include "enet/enet.h" -
code/trunk/src/external/ogreceguirenderer/CMakeLists.txt
r7163 r8351 34 34 DEFINE_SYMBOL 35 35 "OGRE_GUIRENDERER_EXPORTS" 36 VERSION37 1.4.938 36 LINK_LIBRARIES 39 37 ${OGRE_LIBRARY} -
code/trunk/src/external/ogreceguirenderer/OgreCEGUIRenderer.cpp
r5781 r8351 455 455 d_render_sys->_setTextureAddressingMode(0, d_uvwAddressMode); 456 456 d_render_sys->_setTextureMatrix(0, Matrix4::IDENTITY); 457 #if OGRE_VERSION >= 0x010600458 457 d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0, false); 459 #else460 d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0);461 #endif462 458 d_render_sys->_setTextureBlendMode(0, d_colourBlendMode); 463 459 d_render_sys->_setTextureBlendMode(0, d_alphaBlendMode); -
code/trunk/src/external/ogreceguirenderer/VERSION
r5781 r8351 1 This library is part of the OGRE v1.6. 1source.1 This library is part of the OGRE v1.6.5 source. 2 2 3 3 ----- -
code/trunk/src/external/ogreceguirenderer/changes_orxonox.diff
r7163 r8351 18 18 #include "OgreCEGUIRenderer.h" 19 19 #include "OgreCEGUITexture.h" 20 @@ -454,7 +454,11 @@21 d_render_sys->_setTextureUnitFiltering(0, FO_LINEAR, FO_LINEAR, FO_POINT);22 d_render_sys->_setTextureAddressingMode(0, d_uvwAddressMode);23 d_render_sys->_setTextureMatrix(0, Matrix4::IDENTITY);24 +#if OGRE_VERSION >= 0x01060025 + d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0, false);26 +#else27 d_render_sys->_setAlphaRejectSettings(CMPF_ALWAYS_PASS, 0);28 +#endif29 d_render_sys->_setTextureBlendMode(0, d_colourBlendMode);30 d_render_sys->_setTextureBlendMode(0, d_alphaBlendMode);31 d_render_sys->_disableTextureUnitsFrom(1);32 20 --- OgreCEGUIRenderer.h Wed Jan 28 21:14:09 2009 33 21 +++ OgreCEGUIRenderer.h Wed Jan 28 21:06:46 2009 -
code/trunk/src/external/ois/CMakeLists.txt
r5929 r8351 31 31 OISKeyboard.h 32 32 OISMouse.h 33 OISMultiTouch.h 33 34 OISObject.h 34 35 OISPrereqs.h 35 36 36 COMPILATION_BEGIN OISCompilation.cpp37 #COMPILATION_BEGIN OISCompilation.cpp 37 38 OISEffect.cpp 38 39 OISException.cpp … … 42 43 OISKeyboard.cpp 43 44 OISObject.cpp 44 COMPILATION_END45 #COMPILATION_END 45 46 ) 46 47 IF(WIN32) … … 52 53 ENDIF() 53 54 54 INCLUDE_DIRECTORIES(.) 55 # MinGW doesn't come with some required Windows headers 56 IF(MINGW) 57 INCLUDE_DIRECTORIES(${WMI_INCLUDE_DIR}) 58 ENDIF() 55 59 56 60 ORXONOX_ADD_LIBRARY(ois_orxonox … … 59 63 "OIS_NONCLIENT_BUILD" 60 64 VERSION 61 1.2 65 1.3 66 LINK_LIBS_WIN32 67 ${DIRECTX_LIBRARIES} 68 ${WMI_LIBRARY} 69 LINK_LIBS_APPLE 70 /System/Library/Frameworks/IOKit.framework 71 /System/Library/Frameworks/Carbon.framework 72 LINK_LIBS_LINUX 73 X11 62 74 SOURCE_FILES 63 75 ${OIS_FILES} 64 76 ) 65 66 IF(WIN32)67 TARGET_LINK_LIBRARIES(ois_orxonox ${DIRECTX_LIBRARIES})68 ENDIF() -
code/trunk/src/external/ois/OIS.h
r5781 r8351 29 29 #include "OISKeyboard.h" 30 30 #include "OISJoyStick.h" 31 #include "OISMultiTouch.h" 31 32 #include "OISInputManager.h" 32 33 #include "OISFactoryCreator.h" -
code/trunk/src/external/ois/OISConfig.h
r5781 r8351 70 70 @remarks 71 71 Build in support for Win32 XInput (Xbox 360 Controller) 72 @notes73 Not Yet Implemented74 72 */ 75 73 //#define OIS_WIN32_XINPUT_SUPPORT -
code/trunk/src/external/ois/OISInputManager.cpp
r5781 r8351 37 37 #elif defined OIS_APPLE_PLATFORM 38 38 # include "mac/MacInputManager.h" 39 #elif defined OIS_IPHONE_PLATFORM 40 # include "iphone/iPhoneInputManager.h" 39 41 #elif defined OIS_XBOX_PLATFORM 40 42 # include "xbox/XBoxInputManager.h" … … 59 61 m_wiiMoteSupport(0) 60 62 { 63 mFactories.clear(); 64 mFactoryObjects.clear(); 61 65 } 62 66 … … 111 115 #elif defined OIS_APPLE_PLATFORM 112 116 im = new MacInputManager(); 117 #elif defined OIS_IPHONE_PLATFORM 118 im = new iPhoneInputManager(); 113 119 #else 114 120 OIS_EXCEPT(E_General, "No platform library.. check build platform defines!"); -
code/trunk/src/external/ois/OISKeyboard.h
r5781 r8351 184 184 { 185 185 public: 186 KeyEvent( Object* obj, KeyCode kc, unsigned int txt) : EventArg(obj), key(kc), text(txt) {}186 KeyEvent(Object* obj, KeyCode kc, unsigned int txt) : EventArg(obj), key(kc), text(txt) {} 187 187 virtual ~KeyEvent() {} 188 188 … … 201 201 public: 202 202 virtual ~KeyListener() {} 203 virtual bool keyPressed( const KeyEvent &arg) = 0;204 virtual bool keyReleased( const KeyEvent &arg) = 0;203 virtual bool keyPressed(const KeyEvent &arg) = 0; 204 virtual bool keyReleased(const KeyEvent &arg) = 0; 205 205 }; 206 206 …