From b75e053e9deb3d92d54abb719870d13d0f363bd4 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 23 Oct 2015 13:37:49 -0700 Subject: [PATCH 1/9] Add automatic CCD activation to the physics engine --- libraries/physics/src/ObjectMotionState.cpp | 18 ++++++++++++++++++ libraries/physics/src/ObjectMotionState.h | 1 + 2 files changed, 19 insertions(+) diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index be0edafff5..6f1b928456 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -115,6 +115,21 @@ void ObjectMotionState::setMotionType(MotionType motionType) { _motionType = motionType; } +void ObjectMotionState::updateCCDConfiguration() { + if (_body) { + if (_shape) { + btVector3 center; + btScalar radius; + _shape->getBoundingSphere(center, radius); + _body->setCcdMotionThreshold(radius * 2.0f); + _body->setCcdSweptSphereRadius(radius); + } else { + // Disable CCD + _body->setCcdMotionThreshold(0); + } + } +} + void ObjectMotionState::setRigidBody(btRigidBody* body) { // give the body a (void*) back-pointer to this ObjectMotionState if (_body != body) { @@ -125,6 +140,7 @@ void ObjectMotionState::setRigidBody(btRigidBody* body) { if (_body) { _body->setUserPointer(this); } + updateCCDConfiguration(); } } @@ -187,6 +203,8 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine* if (_shape != newShape) { _shape = newShape; _body->setCollisionShape(_shape); + + updateCCDConfiguration(); } else { // huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag flags &= ~Simulation::DIRTY_SHAPE; diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index 992bdd11d7..8c3f3aaca1 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -151,6 +151,7 @@ protected: virtual bool isReadyToComputeShape() = 0; virtual btCollisionShape* computeNewShape() = 0; void setMotionType(MotionType motionType); + void updateCCDConfiguration(); // clearObjectBackPointer() overrrides should call the base method, then actually clear the object back pointer. virtual void clearObjectBackPointer() { _type = MOTIONSTATE_TYPE_INVALID; } From b410604475a606a53efede906cabc22f1ddacbe1 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 3 Nov 2015 11:18:38 -0800 Subject: [PATCH 2/9] Add comments to updateCCDConfiguration --- libraries/physics/src/ObjectMotionState.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index 6f1b928456..5101eabd6a 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -118,10 +118,18 @@ void ObjectMotionState::setMotionType(MotionType motionType) { void ObjectMotionState::updateCCDConfiguration() { if (_body) { if (_shape) { + // If this object moves faster than its bounding radius * RADIUS_MOTION_THRESHOLD_MULTIPLIER, + // CCD will be enabled for this object. + const auto RADIUS_MOTION_THRESHOLD_MULTIPLIER = 2.0f; + btVector3 center; btScalar radius; _shape->getBoundingSphere(center, radius); - _body->setCcdMotionThreshold(radius * 2.0f); + _body->setCcdMotionThreshold(radius * RADIUS_MOTION_THRESHOLD_MULTIPLIER); + + // TODO: Ideally the swept sphere radius would be contained by the object. Using the bounding sphere + // radius works well for spherical objects, but may cause issues with other shapes. For arbitrary + // objects we may want to consider a different approach, such as grouping rigid bodies together. _body->setCcdSweptSphereRadius(radius); } else { // Disable CCD From c0a7da0b88b8903fa1e0aedac464b7b77ac0b35b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 3 Nov 2015 11:22:15 -0800 Subject: [PATCH 3/9] Add comment to ObjectMotionState::updateCCDConfiguration --- libraries/physics/src/ObjectMotionState.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index 5101eabd6a..4f2f2b8184 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -115,6 +115,8 @@ void ObjectMotionState::setMotionType(MotionType motionType) { _motionType = motionType; } +// Update the Continuous Collision Detection (CCD) configuration settings of our RigidBody so that +// CCD will be enabled automatically when its speed surpasses a certain threshold. void ObjectMotionState::updateCCDConfiguration() { if (_body) { if (_shape) { From 7c5f0bb62058283579bfc615c4cc53b0358a6e40 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 10 Nov 2015 08:51:22 -0800 Subject: [PATCH 4/9] Update RADIUS_MOTION_THRESHOLD_MULTIPLIER --- libraries/physics/src/ObjectMotionState.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index 4f2f2b8184..24acb3358c 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -122,7 +122,7 @@ void ObjectMotionState::updateCCDConfiguration() { if (_shape) { // If this object moves faster than its bounding radius * RADIUS_MOTION_THRESHOLD_MULTIPLIER, // CCD will be enabled for this object. - const auto RADIUS_MOTION_THRESHOLD_MULTIPLIER = 2.0f; + const auto RADIUS_MOTION_THRESHOLD_MULTIPLIER = 0.5f; btVector3 center; btScalar radius; From 784df60a9750ae2ad32ec4ae9d9d2321e5024abb Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Nov 2015 13:56:20 -0800 Subject: [PATCH 5/9] Update bullet archive to include CCD+Compound improvements --- cmake/externals/bullet/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index efe5b694fa..3322779272 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -18,8 +18,8 @@ if (WIN32) ExternalProject_Add( ${EXTERNAL_NAME} # URL https://bullet.googlecode.com/files/bullet-2.82-r2704.zip - URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-r2704.zip - URL_MD5 f5e8914fc9064ad32e0d62d19d33d977 + URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-ccd-fix.zip + URL_MD5 d95b07eb120de7dd7786361c0b5a8d9f CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 -DUSE_DX11=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1 @@ -30,8 +30,8 @@ else () ExternalProject_Add( ${EXTERNAL_NAME} #URL http://bullet.googlecode.com/files/bullet-2.82-r2704.tgz - URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-r2704.tgz - URL_MD5 70b3c8d202dee91a0854b4cbc88173e8 + URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-ccd-fix.tgz + URL_MD5 eae10a936e100ddf9fe7b1645018f561 CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1 @@ -80,4 +80,4 @@ endif () if (DEFINED ${EXTERNAL_NAME_UPPER}_DYNAMICS_LIBRARY_RELEASE) set(${EXTERNAL_NAME_UPPER}_INCLUDE_DIR ${INSTALL_DIR}/include/bullet CACHE PATH "Path to bullet include directory") -endif () \ No newline at end of file +endif () From 7e87ad5114febc0105e1155b62940271f7dff23d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Nov 2015 14:50:31 -0800 Subject: [PATCH 6/9] Update bullet tgz md5sum --- cmake/externals/bullet/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index 3322779272..867ff85ea2 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -31,7 +31,7 @@ else () ${EXTERNAL_NAME} #URL http://bullet.googlecode.com/files/bullet-2.82-r2704.tgz URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-ccd-fix.tgz - URL_MD5 eae10a936e100ddf9fe7b1645018f561 + URL_MD5 3ffdde88230ddf3c5125a6b25373a2be CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1 From 67d07921736a05deb5d7be780269b00ee5ef909d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Nov 2015 15:09:06 -0800 Subject: [PATCH 7/9] Update bullet tgz md5sum --- cmake/externals/bullet/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index 867ff85ea2..402cfbb3dc 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -31,7 +31,7 @@ else () ${EXTERNAL_NAME} #URL http://bullet.googlecode.com/files/bullet-2.82-r2704.tgz URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-ccd-fix.tgz - URL_MD5 3ffdde88230ddf3c5125a6b25373a2be + URL_MD5 8082947ba8b07480ea785e5e6b2bab23 CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1 From 3aa271d688c87ba4cea77190ae9505214f33a515 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Nov 2015 15:21:53 -0800 Subject: [PATCH 8/9] Update bullet tgz md5sum --- cmake/externals/bullet/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index 402cfbb3dc..8990167e1c 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -31,7 +31,7 @@ else () ${EXTERNAL_NAME} #URL http://bullet.googlecode.com/files/bullet-2.82-r2704.tgz URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-ccd-fix.tgz - URL_MD5 8082947ba8b07480ea785e5e6b2bab23 + URL_MD5 8d9daf5a46409120fa02c77d02c23c56 CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1 From d1e9e28522c2075da9bb2e8a580cc5c3859ce7d3 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Nov 2015 16:11:12 -0800 Subject: [PATCH 9/9] Update bullet tgz md5sum --- cmake/externals/bullet/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/externals/bullet/CMakeLists.txt b/cmake/externals/bullet/CMakeLists.txt index 8990167e1c..ff0eb22241 100644 --- a/cmake/externals/bullet/CMakeLists.txt +++ b/cmake/externals/bullet/CMakeLists.txt @@ -31,7 +31,7 @@ else () ${EXTERNAL_NAME} #URL http://bullet.googlecode.com/files/bullet-2.82-r2704.tgz URL http://hifi-public.s3.amazonaws.com/dependencies/bullet-2.82-ccd-fix.tgz - URL_MD5 8d9daf5a46409120fa02c77d02c23c56 + URL_MD5 fb140a4983b4109aa1c825a162aa8d64 CMAKE_ARGS ${PLATFORM_CMAKE_ARGS} -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX:PATH= -DBUILD_EXTRAS=0 -DINSTALL_LIBS=1 -DBUILD_DEMOS=0 -DUSE_GLUT=0 LOG_DOWNLOAD 1 LOG_CONFIGURE 1