Jump to content

[SOLVED] Get contact number for Body contact callback?


photo

Recommended Posts

Posted

I am trying to set up a contact callback for a Body. The Body::setContactCallback documentation only seems to cover UnigineScript. I guessed at the required signature for the C++ callback function based on the required signature for the UnigineScript function and arrived at the following basic setup:

static void OnContact(Unigine::Ptr<Unigine::Body> body, int num){}
myBodyRigid->setContactCallback(Unigine::MakeCallback(OnContact));

OnContact seems to be called with the correct "body", but the int num is not what I expected it to be during runtime -- it appears to be an uninitialized value (e.g. -842150451). In UnigineScript, it represents the contact number that can be passed to getContactImpulse, getContactVelocity, etc. How can I get the contact number in C++?

 

(*EDIT: documentation only currently seems to cover UnigineScript, not C++)

Posted

Hi,

 

You've found a bug in C++ API.

We'll fix this issue in the future releases.

Unfortunately, I can't suggest a workaround for now except using script for physics callbacks.

Posted

OK. Can you post a C++ engine source diff that fixes the bug? It would be convenient to be able to get our implementation working now instead of having to revisit it next Unigine engine release.

Posted

Maybe you have already fixed this internally but here is what I found:

 

UniginePhysics.cpp:122, BodyInterface::setContactCallback is creating new EngineCallbackInterface<::Body>. EngineCallbackInterface derives from CallbackBase1, so second argument does not get processed when callbacks are run.

 

I add this class as sibling of EngineCallbackInterface:

template<typename TYPE, typename TYPE2>
class EngineCallbackInterface2 : public CallbackBase2<TYPE*,TYPE2*>
{
private:
Unigine::CallbackBase *func;

public:
EngineCallbackInterface2(Unigine::CallbackBase *func): func(func) {}
virtual ~EngineCallbackInterface2() { Unigine::CallbackBase::release_ptr(func); }
virtual void run(TYPE *obj, TYPE2 *obj2) { func->run(Unigine::api(obj),obj2); }
};
then change BodyInterface::setContactCallback to use new 2-argument class:
void BodyInterface::setContactCallback(CallbackBase *func) { obj->setContactCallback(func ? new EngineCallbackInterface2< ::Body, int >(func) : NULL); }
Contact callback is now called with what looks like a valid contact number.
Posted

Hi Adam,

 

Thanks for the information!

 

We've already fixed and refactored this part of code in similar manner. Fix will be available in the next SDK update (2.2.1) which is planned for next week.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

×
×
  • Create New...