In lib Bullet there is defined a type:
typedef void (*btNearCallback)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
in there docs there is presented a sample of usage (page 23):
void MyNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo) {
// Do your collision logic here
// Only dispatch the Bullet collision information if you want the physics to continue
dispatcher.defaultNearCallback(collisionPair, dispatcher, dispatchInfo);
}
I copied this sample code into my class defention so my class got this function and I shall be capable to do such casts like:
dispatcher->setNearCallback(boost::bind(&BulletAPIWrapper::MyNearCallback, this, _1, _2, _3));
instead of C like dispatcher->setNearCallback(MyNearCallback);
from Bullet tutorial.
Yet my VS2010 sp1 gives me an error:
Error 44 error C2664: 'btCollisionDispatcher::setNearCallback' : cannot convert parameter 1 from 'boost::_bi::bind_t<R,F,L>' to 'btNearCallback'
So I wonder how to cast boost::bind to such typedef?
Is it possible having having static class function (or at least global function like):
void MyNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo, BulletAPI* api) {
}
call dispatcher->setNearCallback( boost::bind(MyNearCallback, _1, _2, _3, this));
because it results in nearly same error for me:
Error 44 error C2664: 'btCollisionDispatcher::setNearCallback' : cannot convert parameter 1 from 'boost::_bi::bind_t<R,F,L>' to 'btNearCallback'
I also tried as described here:
template<unsigned ID,typename Functor>
boost::optional<Functor> &get_local()
{
static boost::optional<Functor> local;
return local;
}
template<unsigned ID,typename Functor>
typename Functor::result_type wrapper(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo)
{
return get_local<ID,Functor>().get()(collisionPair, dispatcher, dispatchInfo);
}
template<typename ReturnType>
struct Func
{
typedef ReturnType (*type)(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo);
};
template<unsigned ID,typename Functor>
typename Func<typename Functor::result_type>::type get_wrapper(Functor f)
{
(get_local<ID,Functor>()) = f;
return wrapper<ID,Functor>;
}
struct NearCallbackWrapper
{
class BulletAPI;
void MyNearCallback(btBroadphasePair& collisionPair, btCollisionDispatcher& dispatcher, const btDispatcherInfo& dispatchInfo) {
std::cout << "called" << std::endl;
}
};
//....
dispatcher->setNearCallback( get_wrapper<0>( boost::bind(&NearCallbackWrapper::MyNearCallback,this) ) );
yet I got such error out from it:
error C2664: 'btCollisionDispatcher::setNearCallback' : cannot convert parameter 1 from 'void (__cdecl *)(btBroadphasePair &,btCollisionDispatcher &,const btDispatcherInfo &)' to 'btNearCallback'