From af442778a64a7c5ea94ee961ac1749d32069909b Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 16 Nov 2015 14:38:14 -0800 Subject: [PATCH 01/11] Add early rejection tests during CCD against compound objects --- .../CollisionDispatch/btCollisionWorld.cpp | 136 +++++++++++++----- 1 file changed, 97 insertions(+), 39 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index c505ed5d5..f407260e3 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -793,50 +793,108 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, ///@todo : use AABB tree or other BVH acceleration structure! if (collisionShape->isCompound()) { + struct btCompoundLeafCallback : btDbvt::ICollide + { + btCompoundLeafCallback( + const btConvexShape* castShape, + const btTransform& convexFromTrans, + const btTransform& convexToTrans, + btScalar allowedPenetration, + const btCompoundShape* compoundShape, + const btTransform& colObjWorldTransform, + ConvexResultCallback& resultCallback) + : + m_castShape(castShape), + m_convexFromTrans(convexFromTrans), + m_convexToTrans(convexToTrans), + m_allowedPenetration(allowedPenetration), + m_compoundShape(compoundShape), + m_colObjWorldTransform(colObjWorldTransform), + m_resultCallback(resultCallback) { + } + + const btConvexShape* m_castShape; + const btTransform& m_convexFromTrans; + const btTransform& m_convexToTrans; + btScalar m_allowedPenetration; + const btCompoundShape* m_compoundShape; + const btTransform& m_colObjWorldTransform; + ConvexResultCallback& m_resultCallback; + const btCollisionObjectWrapper* m_colObjWrap; + + public: + + void Process(const btDbvtNode* leaf) + { + // Processing leaf node + int index = leaf->dataAsInt; + + //const btCompoundShape* compoundShape = static_cast(m_compoundColObjWrap->getCollisionShape()); + btTransform childTrans = m_compoundShape->getChildTransform(index); + const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index); + btTransform childWorldTrans = m_colObjWorldTransform * childTrans; + + struct LocalInfoAdder : public ConvexResultCallback { + ConvexResultCallback* m_userCallback; + int m_i; + + LocalInfoAdder(int i, ConvexResultCallback *user) + : m_userCallback(user), m_i(i) + { + m_closestHitFraction = m_userCallback->m_closestHitFraction; + } + virtual bool needsCollision(btBroadphaseProxy* p) const + { + return m_userCallback->needsCollision(p); + } + virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& r, bool b) + { + btCollisionWorld::LocalShapeInfo shapeInfo; + shapeInfo.m_shapePart = -1; + shapeInfo.m_triangleIndex = m_i; + if (r.m_localShapeInfo == NULL) + r.m_localShapeInfo = &shapeInfo; + const btScalar result = m_userCallback->addSingleResult(r, b); + m_closestHitFraction = m_userCallback->m_closestHitFraction; + return result; + + } + }; + + LocalInfoAdder my_cb(index, &m_resultCallback); + + btCollisionObjectWrapper tmpObj(m_colObjWrap, childCollisionShape, m_colObjWrap->getCollisionObject(), childWorldTrans, -1, index); + + objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, + &tmpObj, my_cb, m_allowedPenetration); + } + }; + BT_PROFILE("convexSweepCompound"); const btCompoundShape* compoundShape = static_cast(collisionShape); - int i=0; - for (i=0;igetNumChildShapes();i++) - { - btTransform childTrans = compoundShape->getChildTransform(i); - const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i); - btTransform childWorldTrans = colObjWorldTransform * childTrans; - - struct LocalInfoAdder : public ConvexResultCallback { - ConvexResultCallback* m_userCallback; - int m_i; - LocalInfoAdder (int i, ConvexResultCallback *user) - : m_userCallback(user), m_i(i) - { - m_closestHitFraction = m_userCallback->m_closestHitFraction; - } - virtual bool needsCollision(btBroadphaseProxy* p) const - { - return m_userCallback->needsCollision(p); - } - virtual btScalar addSingleResult (btCollisionWorld::LocalConvexResult& r, bool b) - { - btCollisionWorld::LocalShapeInfo shapeInfo; - shapeInfo.m_shapePart = -1; - shapeInfo.m_triangleIndex = m_i; - if (r.m_localShapeInfo == NULL) - r.m_localShapeInfo = &shapeInfo; - const btScalar result = m_userCallback->addSingleResult(r, b); - m_closestHitFraction = m_userCallback->m_closestHitFraction; - return result; - - } - }; + btVector3 fromLocalAabbMin, fromLocalAabbMax; + btVector3 toLocalAabbMin, toLocalAabbMax; - LocalInfoAdder my_cb(i, &resultCallback); - - btCollisionObjectWrapper tmpObj(colObjWrap,childCollisionShape,colObjWrap->getCollisionObject(),childWorldTrans,-1,i); + castShape->getAabb(convexFromTrans, fromLocalAabbMin, fromLocalAabbMax); + castShape->getAabb(convexToTrans, toLocalAabbMin, toLocalAabbMax); - objectQuerySingleInternal(castShape, convexFromTrans,convexToTrans, - &tmpObj,my_cb, allowedPenetration); - - } + fromLocalAabbMin.setMin(toLocalAabbMin); + fromLocalAabbMax.setMax(toLocalAabbMax); + + const btDbvt* tree = compoundShape->getDynamicAabbTree(); + + if (tree) { + btCompoundLeafCallback callback { castShape, convexFromTrans, convexToTrans, + allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; + const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); + tree->collideTV(tree->m_root, bounds, callback); + } else { + int i; + for (i=0;igetNumChildShapes();i++) + { + } + } } } } From 25ee137390f57c8df97ebc3e3b3f5c80cd5c667d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Mon, 16 Nov 2015 15:48:08 -0800 Subject: [PATCH 02/11] Fix missing colObjWrap --- .../CollisionDispatch/btCollisionWorld.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index f407260e3..f0b57f0a2 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -796,14 +796,16 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, struct btCompoundLeafCallback : btDbvt::ICollide { btCompoundLeafCallback( - const btConvexShape* castShape, - const btTransform& convexFromTrans, - const btTransform& convexToTrans, - btScalar allowedPenetration, - const btCompoundShape* compoundShape, - const btTransform& colObjWorldTransform, - ConvexResultCallback& resultCallback) - : + const btCollisionObjectWrapper* colObjWrap, + const btConvexShape* castShape, + const btTransform& convexFromTrans, + const btTransform& convexToTrans, + btScalar allowedPenetration, + const btCompoundShape* compoundShape, + const btTransform& colObjWorldTransform, + ConvexResultCallback& resultCallback) + : + m_colObjWrap(colObjWrap), m_castShape(castShape), m_convexFromTrans(convexFromTrans), m_convexToTrans(convexToTrans), @@ -813,6 +815,7 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, m_resultCallback(resultCallback) { } + const btCollisionObjectWrapper* m_colObjWrap; const btConvexShape* m_castShape; const btTransform& m_convexFromTrans; const btTransform& m_convexToTrans; @@ -820,7 +823,6 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, const btCompoundShape* m_compoundShape; const btTransform& m_colObjWorldTransform; ConvexResultCallback& m_resultCallback; - const btCollisionObjectWrapper* m_colObjWrap; public: @@ -885,7 +887,7 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, const btDbvt* tree = compoundShape->getDynamicAabbTree(); if (tree) { - btCompoundLeafCallback callback { castShape, convexFromTrans, convexToTrans, + btCompoundLeafCallback callback { colObjWrap, castShape, convexFromTrans, convexToTrans, allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); tree->collideTV(tree->m_root, bounds, callback); From b1356993253e754146ea9dab44bc9929e868d10d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 17 Nov 2015 13:50:51 -0800 Subject: [PATCH 03/11] Fix errors in ccd against compound objects --- .../CollisionDispatch/btCollisionWorld.cpp | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index f0b57f0a2..4232cc927 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -826,15 +826,10 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, public: - void Process(const btDbvtNode* leaf) + void ProcessChild(int index, const btTransform& childTrans, const btCollisionShape* childCollisionShape) { - // Processing leaf node - int index = leaf->dataAsInt; - - //const btCompoundShape* compoundShape = static_cast(m_compoundColObjWrap->getCollisionShape()); - btTransform childTrans = m_compoundShape->getChildTransform(index); - const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index); btTransform childWorldTrans = m_colObjWorldTransform * childTrans; + //btTransform childWorldTrans = childTrans; struct LocalInfoAdder : public ConvexResultCallback { ConvexResultCallback* m_userCallback; @@ -870,6 +865,18 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, &tmpObj, my_cb, m_allowedPenetration); } + + void Process(const btDbvtNode* leaf) + { + // Processing leaf node + int index = leaf->dataAsInt; + + //const btCompoundShape* compoundShape = static_cast(m_compoundColObjWrap->getCollisionShape()); + btTransform childTrans = m_compoundShape->getChildTransform(index); + const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index); + + ProcessChild(index, childTrans, childCollisionShape); + } }; BT_PROFILE("convexSweepCompound"); @@ -878,23 +885,27 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, btVector3 fromLocalAabbMin, fromLocalAabbMax; btVector3 toLocalAabbMin, toLocalAabbMax; - castShape->getAabb(convexFromTrans, fromLocalAabbMin, fromLocalAabbMax); - castShape->getAabb(convexToTrans, toLocalAabbMin, toLocalAabbMax); + castShape->getAabb(colObjWorldTransform.inverse() * convexFromTrans, fromLocalAabbMin, fromLocalAabbMax); + castShape->getAabb(colObjWorldTransform.inverse() * convexToTrans, toLocalAabbMin, toLocalAabbMax); fromLocalAabbMin.setMin(toLocalAabbMin); fromLocalAabbMax.setMax(toLocalAabbMax); const btDbvt* tree = compoundShape->getDynamicAabbTree(); + btCompoundLeafCallback callback { colObjWrap, castShape, convexFromTrans, convexToTrans, + allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; + if (tree) { - btCompoundLeafCallback callback { colObjWrap, castShape, convexFromTrans, convexToTrans, - allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); tree->collideTV(tree->m_root, bounds, callback); } else { int i; for (i=0;igetNumChildShapes();i++) { + const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i); + btTransform childTrans = compoundShape->getChildTransform(i); + callback.ProcessChild(i, childTrans, childCollisionShape); } } } From 7f0877339ebf93b75178cdf463aa681874aa881a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 17 Nov 2015 15:03:08 -0800 Subject: [PATCH 04/11] Replace spaces with tabs --- .../CollisionDispatch/btCollisionWorld.cpp | 188 +++++++++--------- 1 file changed, 93 insertions(+), 95 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index 4232cc927..523d80113 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -790,124 +790,122 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, } } } else { - ///@todo : use AABB tree or other BVH acceleration structure! if (collisionShape->isCompound()) { - struct btCompoundLeafCallback : btDbvt::ICollide - { - btCompoundLeafCallback( - const btCollisionObjectWrapper* colObjWrap, - const btConvexShape* castShape, - const btTransform& convexFromTrans, - const btTransform& convexToTrans, - btScalar allowedPenetration, - const btCompoundShape* compoundShape, - const btTransform& colObjWorldTransform, - ConvexResultCallback& resultCallback) - : - m_colObjWrap(colObjWrap), - m_castShape(castShape), - m_convexFromTrans(convexFromTrans), - m_convexToTrans(convexToTrans), - m_allowedPenetration(allowedPenetration), - m_compoundShape(compoundShape), - m_colObjWorldTransform(colObjWorldTransform), - m_resultCallback(resultCallback) { - } + struct btCompoundLeafCallback : btDbvt::ICollide + { + btCompoundLeafCallback( + const btCollisionObjectWrapper* colObjWrap, + const btConvexShape* castShape, + const btTransform& convexFromTrans, + const btTransform& convexToTrans, + btScalar allowedPenetration, + const btCompoundShape* compoundShape, + const btTransform& colObjWorldTransform, + ConvexResultCallback& resultCallback) + : + m_colObjWrap(colObjWrap), + m_castShape(castShape), + m_convexFromTrans(convexFromTrans), + m_convexToTrans(convexToTrans), + m_allowedPenetration(allowedPenetration), + m_compoundShape(compoundShape), + m_colObjWorldTransform(colObjWorldTransform), + m_resultCallback(resultCallback) { + } - const btCollisionObjectWrapper* m_colObjWrap; - const btConvexShape* m_castShape; - const btTransform& m_convexFromTrans; - const btTransform& m_convexToTrans; - btScalar m_allowedPenetration; - const btCompoundShape* m_compoundShape; - const btTransform& m_colObjWorldTransform; - ConvexResultCallback& m_resultCallback; + const btCollisionObjectWrapper* m_colObjWrap; + const btConvexShape* m_castShape; + const btTransform& m_convexFromTrans; + const btTransform& m_convexToTrans; + btScalar m_allowedPenetration; + const btCompoundShape* m_compoundShape; + const btTransform& m_colObjWorldTransform; + ConvexResultCallback& m_resultCallback; - public: + public: - void ProcessChild(int index, const btTransform& childTrans, const btCollisionShape* childCollisionShape) - { - btTransform childWorldTrans = m_colObjWorldTransform * childTrans; - //btTransform childWorldTrans = childTrans; + void ProcessChild(int index, const btTransform& childTrans, const btCollisionShape* childCollisionShape) + { + btTransform childWorldTrans = m_colObjWorldTransform * childTrans; - struct LocalInfoAdder : public ConvexResultCallback { - ConvexResultCallback* m_userCallback; - int m_i; + struct LocalInfoAdder : public ConvexResultCallback { + ConvexResultCallback* m_userCallback; + int m_i; - LocalInfoAdder(int i, ConvexResultCallback *user) - : m_userCallback(user), m_i(i) - { - m_closestHitFraction = m_userCallback->m_closestHitFraction; - } - virtual bool needsCollision(btBroadphaseProxy* p) const - { - return m_userCallback->needsCollision(p); - } - virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& r, bool b) - { - btCollisionWorld::LocalShapeInfo shapeInfo; - shapeInfo.m_shapePart = -1; - shapeInfo.m_triangleIndex = m_i; - if (r.m_localShapeInfo == NULL) - r.m_localShapeInfo = &shapeInfo; - const btScalar result = m_userCallback->addSingleResult(r, b); - m_closestHitFraction = m_userCallback->m_closestHitFraction; - return result; + LocalInfoAdder(int i, ConvexResultCallback *user) + : m_userCallback(user), m_i(i) + { + m_closestHitFraction = m_userCallback->m_closestHitFraction; + } + virtual bool needsCollision(btBroadphaseProxy* p) const + { + return m_userCallback->needsCollision(p); + } + virtual btScalar addSingleResult(btCollisionWorld::LocalConvexResult& r, bool b) + { + btCollisionWorld::LocalShapeInfo shapeInfo; + shapeInfo.m_shapePart = -1; + shapeInfo.m_triangleIndex = m_i; + if (r.m_localShapeInfo == NULL) + r.m_localShapeInfo = &shapeInfo; + const btScalar result = m_userCallback->addSingleResult(r, b); + m_closestHitFraction = m_userCallback->m_closestHitFraction; + return result; - } - }; + } + }; - LocalInfoAdder my_cb(index, &m_resultCallback); + LocalInfoAdder my_cb(index, &m_resultCallback); - btCollisionObjectWrapper tmpObj(m_colObjWrap, childCollisionShape, m_colObjWrap->getCollisionObject(), childWorldTrans, -1, index); + btCollisionObjectWrapper tmpObj(m_colObjWrap, childCollisionShape, m_colObjWrap->getCollisionObject(), childWorldTrans, -1, index); - objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, - &tmpObj, my_cb, m_allowedPenetration); - } + objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, + &tmpObj, my_cb, m_allowedPenetration); + } - void Process(const btDbvtNode* leaf) - { - // Processing leaf node - int index = leaf->dataAsInt; + void Process(const btDbvtNode* leaf) + { + // Processing leaf node + int index = leaf->dataAsInt; - //const btCompoundShape* compoundShape = static_cast(m_compoundColObjWrap->getCollisionShape()); - btTransform childTrans = m_compoundShape->getChildTransform(index); - const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index); + //const btCompoundShape* compoundShape = static_cast(m_compoundColObjWrap->getCollisionShape()); + btTransform childTrans = m_compoundShape->getChildTransform(index); + const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index); - ProcessChild(index, childTrans, childCollisionShape); - } - }; + ProcessChild(index, childTrans, childCollisionShape); + } + }; BT_PROFILE("convexSweepCompound"); const btCompoundShape* compoundShape = static_cast(collisionShape); - btVector3 fromLocalAabbMin, fromLocalAabbMax; - btVector3 toLocalAabbMin, toLocalAabbMax; + btVector3 fromLocalAabbMin, fromLocalAabbMax; + btVector3 toLocalAabbMin, toLocalAabbMax; - castShape->getAabb(colObjWorldTransform.inverse() * convexFromTrans, fromLocalAabbMin, fromLocalAabbMax); - castShape->getAabb(colObjWorldTransform.inverse() * convexToTrans, toLocalAabbMin, toLocalAabbMax); + castShape->getAabb(colObjWorldTransform.inverse() * convexFromTrans, fromLocalAabbMin, fromLocalAabbMax); + castShape->getAabb(colObjWorldTransform.inverse() * convexToTrans, toLocalAabbMin, toLocalAabbMax); - fromLocalAabbMin.setMin(toLocalAabbMin); - fromLocalAabbMax.setMax(toLocalAabbMax); + fromLocalAabbMin.setMin(toLocalAabbMin); + fromLocalAabbMax.setMax(toLocalAabbMax); - const btDbvt* tree = compoundShape->getDynamicAabbTree(); + const btDbvt* tree = compoundShape->getDynamicAabbTree(); - btCompoundLeafCallback callback { colObjWrap, castShape, convexFromTrans, convexToTrans, - allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; + btCompoundLeafCallback callback { colObjWrap, castShape, convexFromTrans, convexToTrans, + allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; - if (tree) { - const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); - tree->collideTV(tree->m_root, bounds, callback); - } else { - int i; - for (i=0;igetNumChildShapes();i++) - { - const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i); - btTransform childTrans = compoundShape->getChildTransform(i); - callback.ProcessChild(i, childTrans, childCollisionShape); - } - } + if (tree) { + const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); + tree->collideTV(tree->m_root, bounds, callback); + } else { + int i; + for (i=0;igetNumChildShapes();i++) + { + const btCollisionShape* childCollisionShape = compoundShape->getChildShape(i); + btTransform childTrans = compoundShape->getChildTransform(i); + callback.ProcessChild(i, childTrans, childCollisionShape); + } + } } } } From 76d39d443966c3d8d008eb64d85efff984f98350 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 20 Nov 2015 16:08:18 -0800 Subject: [PATCH 05/11] Fix build error on OSX + Linux --- src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index 523d80113..080f336df 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -891,8 +891,8 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, const btDbvt* tree = compoundShape->getDynamicAabbTree(); - btCompoundLeafCallback callback { colObjWrap, castShape, convexFromTrans, convexToTrans, - allowedPenetration, compoundShape, colObjWorldTransform, resultCallback }; + btCompoundLeafCallback callback(colObjWrap, castShape, convexFromTrans, convexToTrans, + allowedPenetration, compoundShape, colObjWorldTransform, resultCallback); if (tree) { const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); From 8d970e5c044207b826276dda6722def53c9b1015 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 27 Apr 2016 13:41:42 -0700 Subject: [PATCH 06/11] minor cleanup --- src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp index 080f336df..fa4cac660 100644 --- a/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp +++ b/src/BulletCollision/CollisionDispatch/btCollisionWorld.cpp @@ -860,8 +860,7 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, btCollisionObjectWrapper tmpObj(m_colObjWrap, childCollisionShape, m_colObjWrap->getCollisionObject(), childWorldTrans, -1, index); - objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, - &tmpObj, my_cb, m_allowedPenetration); + objectQuerySingleInternal(m_castShape, m_convexFromTrans, m_convexToTrans, &tmpObj, my_cb, m_allowedPenetration); } void Process(const btDbvtNode* leaf) @@ -869,7 +868,6 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, // Processing leaf node int index = leaf->dataAsInt; - //const btCompoundShape* compoundShape = static_cast(m_compoundColObjWrap->getCollisionShape()); btTransform childTrans = m_compoundShape->getChildTransform(index); const btCollisionShape* childCollisionShape = m_compoundShape->getChildShape(index); @@ -889,11 +887,10 @@ void btCollisionWorld::objectQuerySingleInternal(const btConvexShape* castShape, fromLocalAabbMin.setMin(toLocalAabbMin); fromLocalAabbMax.setMax(toLocalAabbMax); - const btDbvt* tree = compoundShape->getDynamicAabbTree(); - btCompoundLeafCallback callback(colObjWrap, castShape, convexFromTrans, convexToTrans, allowedPenetration, compoundShape, colObjWorldTransform, resultCallback); + const btDbvt* tree = compoundShape->getDynamicAabbTree(); if (tree) { const ATTRIBUTE_ALIGNED16(btDbvtVolume) bounds = btDbvtVolume::FromMM(fromLocalAabbMin, fromLocalAabbMax); tree->collideTV(tree->m_root, bounds, callback); From 3c5b4af1c3421139720b17806ab352d7736cc8b5 Mon Sep 17 00:00:00 2001 From: Ciro Santilli Date: Sun, 1 May 2016 15:45:03 +0200 Subject: [PATCH 07/11] Improve HelloWorld - explain in comments the shape of the ground and better group that code - give enough time for the sphere to hit the ground - don't ask for confirmation to exit, it's annoying --- examples/HelloWorld/HelloWorld.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/HelloWorld/HelloWorld.cpp b/examples/HelloWorld/HelloWorld.cpp index f7a195746..e51e6d541 100644 --- a/examples/HelloWorld/HelloWorld.cpp +++ b/examples/HelloWorld/HelloWorld.cpp @@ -44,20 +44,24 @@ int main(int argc, char** argv) ///-----initialization_end----- - ///create a few basic rigid bodies - btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); - //keep track of the shapes, we release memory at exit. //make sure to re-use collision shapes among rigid bodies whenever possible! btAlignedObjectArray collisionShapes; - collisionShapes.push_back(groundShape); - btTransform groundTransform; - groundTransform.setIdentity(); - groundTransform.setOrigin(btVector3(0,-56,0)); + ///create a few basic rigid bodies + //the ground is a cube of side 100 at position y = -56. + //the sphere will hit it at y = -6, with center at -5 { + btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(50.),btScalar(50.))); + + collisionShapes.push_back(groundShape); + + btTransform groundTransform; + groundTransform.setIdentity(); + groundTransform.setOrigin(btVector3(0,-56,0)); + btScalar mass(0.); //rigidbody is dynamic if and only if mass is non zero, otherwise static @@ -113,7 +117,7 @@ int main(int argc, char** argv) ///-----stepsimulation_start----- - for (i=0;i<100;i++) + for (i=0;i<150;i++) { dynamicsWorld->stepSimulation(1.f/60.f,10); @@ -178,9 +182,5 @@ int main(int argc, char** argv) //next line is optional: it will be cleared by the destructor when the array goes out of scope collisionShapes.clear(); - - ///-----cleanup_end----- - printf("Press a key to exit\n"); - getchar(); } From 194009f46e4697a1bc89ca3f31124d554472e8b2 Mon Sep 17 00:00:00 2001 From: "Erwin Coumans (Google)" Date: Wed, 4 May 2016 00:17:39 -0700 Subject: [PATCH 08/11] linux fixes --- examples/OpenGLWindow/X11OpenGLWindow.cpp | 14 ++++++++++++++ examples/OpenGLWindow/X11OpenGLWindow.h | 7 ++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/examples/OpenGLWindow/X11OpenGLWindow.cpp b/examples/OpenGLWindow/X11OpenGLWindow.cpp index e6d0f666d..f2a077145 100644 --- a/examples/OpenGLWindow/X11OpenGLWindow.cpp +++ b/examples/OpenGLWindow/X11OpenGLWindow.cpp @@ -1076,6 +1076,20 @@ b3KeyboardCallback X11OpenGLWindow::getKeyboardCallback() return m_data->m_keyboardCallback; } +int X11OpenGLWindow::getWidth() const +{ + if (m_data) + return m_data->m_glWidth; + return 0; +} +int X11OpenGLWindow::getHeight() const +{ + if (m_data) + return m_data->m_glHeight; + return 0; +} + + #include int X11OpenGLWindow::fileOpenDialog(char* filename, int maxNameLength) diff --git a/examples/OpenGLWindow/X11OpenGLWindow.h b/examples/OpenGLWindow/X11OpenGLWindow.h index cc28aae1a..fd88689bc 100644 --- a/examples/OpenGLWindow/X11OpenGLWindow.h +++ b/examples/OpenGLWindow/X11OpenGLWindow.h @@ -54,7 +54,7 @@ public: virtual void setResizeCallback(b3ResizeCallback resizeCallback); virtual void setWheelCallback(b3WheelCallback wheelCallback); virtual void setKeyboardCallback( b3KeyboardCallback keyboardCallback); - + virtual b3MouseMoveCallback getMouseMoveCallback(); virtual b3MouseButtonCallback getMouseButtonCallback(); virtual b3ResizeCallback getResizeCallback(); @@ -65,9 +65,14 @@ public: virtual void setWindowTitle(const char* title); + virtual int getWidth() const; + + virtual int getHeight() const; + int fileOpenDialog(char* filename, int maxNameLength); }; + #endif From 372c4ef9c1cc9b8ae1a6a6e5c69d2fbb5f56a3e2 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 4 May 2016 13:01:06 -0700 Subject: [PATCH 09/11] Add btConvexHullShape::optimizeConvexHull method, it automatically removes vertices that are not on the convex hull. It uses the btConvexHullComputer for this. --- .../CollisionShapes/btConvexHullShape.cpp | 17 +++++++++++++---- .../CollisionShapes/btConvexHullShape.h | 5 ++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp b/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp index 0623e351a..c1aa6ca46 100644 --- a/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp +++ b/src/BulletCollision/CollisionShapes/btConvexHullShape.cpp @@ -22,6 +22,8 @@ subject to the following restrictions: #include "LinearMath/btQuaternion.h" #include "LinearMath/btSerializer.h" +#include "btConvexPolyhedron.h" +#include "LinearMath/btConvexHullComputer.h" btConvexHullShape ::btConvexHullShape (const btScalar* points,int numPoints,int stride) : btPolyhedralConvexAabbCachingShape () { @@ -121,10 +123,17 @@ btVector3 btConvexHullShape::localGetSupportingVertex(const btVector3& vec)const } - - - - +void btConvexHullShape::optimizeConvexHull() +{ + btConvexHullComputer conv; + conv.compute(&m_unscaledPoints[0].getX(), sizeof(btVector3),m_unscaledPoints.size(),0.f,0.f); + int numVerts = conv.vertices.size(); + m_unscaledPoints.resize(0); + for (int i=0;i Date: Wed, 4 May 2016 13:24:06 -0700 Subject: [PATCH 10/11] use cmake FIND_PACKAGE(PythonLibs 2.7 REQUIRED) if pybullet is build --- CMakeLists.txt | 3 +++ examples/ExampleBrowser/ExampleEntries.cpp | 2 ++ examples/pybullet/CMakeLists.txt | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e3321091..7809a87ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,9 @@ ENDIF() OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON) OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF) +IF(BUILD_PYBULLET) + FIND_PACKAGE(PythonLibs 2.7 REQUIRED) +ENDIF(BUILD_PYBULLET) IF(BUILD_BULLET3) IF(APPLE) diff --git a/examples/ExampleBrowser/ExampleEntries.cpp b/examples/ExampleBrowser/ExampleEntries.cpp index 3ec1403d6..08f71cf69 100644 --- a/examples/ExampleBrowser/ExampleEntries.cpp +++ b/examples/ExampleBrowser/ExampleEntries.cpp @@ -83,8 +83,10 @@ static ExampleEntry gDefaultExamples[]= ExampleEntry(0,"API"), + ExampleEntry(1,"Basic Example","Create some rigid bodies using box collision shapes. This is a good example to familiarize with the basic initialization of Bullet. The Basic Example can also be compiled without graphical user interface, as a console application. Press W for wireframe, A to show AABBs, I to suspend/restart physics simulation. Press D to toggle auto-deactivation of the simulation. ", BasicExampleCreateFunc), + ExampleEntry(1,"Rolling Friction", "Damping is often not good enough to keep rounded objects from rolling down a sloped surface. Instead, you can set the rolling friction of a rigid body. Generally it is best to leave the rolling friction to zero, to avoid artifacts.", RollingFrictionCreateFunc), ExampleEntry(1,"Constraints","Show the use of the various constraints in Bullet. Press the L key to visualize the constraint limits. Press the C key to visualize the constraint frames.", diff --git a/examples/pybullet/CMakeLists.txt b/examples/pybullet/CMakeLists.txt index b5ee53a0e..a583192ab 100644 --- a/examples/pybullet/CMakeLists.txt +++ b/examples/pybullet/CMakeLists.txt @@ -4,7 +4,7 @@ INCLUDE_DIRECTORIES( ${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/examples ${BULLET_PHYSICS_SOURCE_DIR}/examples/ThirdPartyLibs - /usr/include/python2.7 + ${PYTHON_INCLUDE_DIRS} ) SET(pybullet_SRCS @@ -18,7 +18,7 @@ ADD_LIBRARY(pybullet ${pybullet_SRCS}) SET_TARGET_PROPERTIES(pybullet PROPERTIES VERSION ${BULLET_VERSION}) SET_TARGET_PROPERTIES(pybullet PROPERTIES SOVERSION ${BULLET_VERSION}) - TARGET_LINK_LIBRARIES(pybullet BulletExampleBrowserLib BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen Bullet3Common Python) + TARGET_LINK_LIBRARIES(pybullet BulletExampleBrowserLib BulletSoftBody BulletDynamics BulletCollision BulletInverseDynamicsUtils BulletInverseDynamics LinearMath OpenGLWindow gwen Bullet3Common ${PYTHON_LIBRARIES}) ENDIF (BUILD_SHARED_LIBS) From 85368973a1a8b5d0d230feb512fd19540611f923 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Wed, 4 May 2016 13:46:55 -0700 Subject: [PATCH 11/11] When using cmake -DBUILD_PYBULLET=ON, force BUILD_SHARED_LIBS option --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7809a87ef..2f04917ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -194,6 +194,7 @@ OPTION(BUILD_BULLET3 "Set when you want to build Bullet 3" ON) OPTION(BUILD_PYBULLET "Set when you want to build pybullet (experimental Python bindings for Bullet)" OFF) IF(BUILD_PYBULLET) FIND_PACKAGE(PythonLibs 2.7 REQUIRED) + SET(BUILD_SHARED_LIBS ON CACHE BOOL "Shared Libs" FORCE) ENDIF(BUILD_PYBULLET) IF(BUILD_BULLET3)