Created
July 11, 2011 12:09
-
-
Save vaiorabbit/1075729 to your computer and use it in GitHub Desktop.
std::tr1::bind
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <algorithm> | |
#include <tr1/functional> | |
#include <vector> | |
struct Contact | |
{ | |
Vec3 Position; | |
// ... | |
}; | |
typedef std::vector<Contact> ContactContainer; | |
ContactContainer contacts; | |
#define TOLERANCE 0.01f | |
struct SameContacts : public std::binary_function<const Contact&, const Contact&, bool> | |
{ | |
bool operator()( const Contact& c0, const Contact& c1 ) const | |
{ | |
// [Tentative] 位置が近いなら同じ衝突点とみなす | |
return (c0.Position - c1.Position).Length() <= TOLERANCE ? true : false; | |
} | |
}; | |
// ... | |
Contact c; | |
if ( DetectCollision( pRigidBody0, pRigidBody1, &c ) > 0 ) | |
{ | |
// 似た衝突点が既存の配列内に見つからないなら追加 | |
ContactContainer::iterator it = std::find_if( contacts.begin(), contacts.end(), | |
std::tr1::bind(SameContacts(), c, std::tr1::placeholders::_1) ); | |
if ( it == contacts.end() ) | |
contacts.push_back( c ); | |
} | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment