Skip to content

Instantly share code, notes, and snippets.

@mxgrey
Created August 11, 2016 16:41
Show Gist options
  • Save mxgrey/affcd5e402f7406fba05f224b9d37dfa to your computer and use it in GitHub Desktop.
Save mxgrey/affcd5e402f7406fba05f224b9d37dfa to your computer and use it in GitHub Desktop.
class CustomCollisionFilter : public dart::collision::BodyNodeCollisionFilter
{
public:
inline CustomCollisionFilter(const std::vector<std::pair<std::string, std::string>>& pairs)
{
for(const std::pair<std::string, std::string>& pair : pairs)
{
mPairs[pair.first] = pair.second;
mPairs[pair.second] = pair.first;
}
}
inline bool needCollision(const dart::collision::CollisionObject* object1,
const dart::collision::CollisionObject* object2) const override
{
const std::string& name1 = object1->getShapeFrame()->asShapeNode()->
getBodyNodePtr()->getName();
PairMap::const_iterator it = mPairs.find(name1);
if(mPairs.end() != it)
{
const std::string& name2 = object2->getShapeFrame()->asShapeNode()->
getBodyNodePtr()->getName();
if(it->second == name2)
return false;
}
return BodyNodeCollisionFilter::needCollision(object1, object2);
}
using PairMap = std::unordered_map<std::string, std::string>;
PairMap mPairs;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment