Set Callback from class

Started by
11 comments, last by VanillaSnake21 17 years, 1 month ago
Quote:Original post by Anonymous Poster
I'm smelling the perfect place to use Boost to send Newton that class function.


boost?

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement
Quote:Original post by VanillaSnake21
Quote:Original post by Anonymous Poster
I'm smelling the perfect place to use Boost to send Newton that class function.


boost?
If you're asking what Boost is, it's a collection of C++ libraries that compliment and extend the standard C++ library (some of these libraries are actually on their way to becoming part of the SC++L).

Before considering Boost though, let's take a look at your error:
c:\Documents and Settings\Owner\My Documents\Visual Studio Projects    Physics Tester 2003\Physics.cpp(34) :error C2664: 'NewtonBodySetForceAndTorqueCallback' : cannot convert parameter 2 from 'void (const NewtonBody *,float)' to 'NewtonApplyForceAndTorque'None of the functions with this name in scope match the target type
It looks to me as if Newton is expecting a pointer to a function with a different signature than that of your callback function. A quick Google search for NewtonApplyForceAndTorque turns up the following:
typedef void (*NewtonApplyForceAndTorque) (const NewtonBody* body);
Which matches yours, except for the second parameter of type float.

So the short answer is, drop the second parameter from your function and it will probably work. I can't really give you the long answer without investigating the Newton API though (I'm not really sure how the callback is supposed to work, or what led you to believe there was supposed to be a 'gravity' parameter).

As for Boost, I'm not sure a Boost library can be applied directly here (emphasis on 'directly'). NewtonBodySetForceAndTorqueCallback() is expecting a pointer to a function with a specific signature, no more, no less, and I don't think there's any way to 'trick' the Newton API into accepting a more sophisticated delegate object in its place (now watch me be proven wrong by one of our resident gurus :). There are certainly more sophisticated things that you could do on your end with respect to callbacks, delegates, and so forth, but I can't really comment on that further without being more familiar with the Newton API.
Quote:Original post by jyk
Quote:Original post by VanillaSnake21
Quote:Original post by Anonymous Poster
I'm smelling the perfect place to use Boost to send Newton that class function.


boost?
If you're asking what Boost is, it's a collection of C++ libraries that compliment and extend the standard C++ library (some of these libraries are actually on there way to becoming part of the SC++L).

Before considering Boost though, let's take a look at your error:
c:\Documents and Settings\Owner\My Documents\Visual Studio Projects    Physics Tester 2003\Physics.cpp(34) :error C2664: 'NewtonBodySetForceAndTorqueCallback' : cannot convert parameter 2 from 'void (const NewtonBody *,float)' to 'NewtonApplyForceAndTorque'None of the functions with this name in scope match the target type
It looks to me as if Newton is expecting a pointer to a function with a different signature than that of your callback function. A quick Google search for NewtonApplyForceAndTorque turns up the following:
typedef void (*NewtonApplyForceAndTorque) (const NewtonBody* body);
Which matches yours, except for the second parameter of type float.

So the short answer is, drop the second parameter from your function and it will probably work. I can't really give you the long answer without investigating the Newton API though (I'm not really sure how the callback is supposed to work, or what led you to believe there was supposed to be a 'gravity' parameter).

As for Boost, I'm not sure a Boost library can be applied directly here (emphasis on 'directly'). NewtonBodySetForceAndTorqueCallback() is expecting a pointer to a function with a specific signature, no more, no less, and I don't think there's any way to 'trick' the Newton API into accepting a more sophisticated delegate object in its place. There are certainly more sophisticated things that you could do on your end with respect to callbacks, delegates, and so forth, but I can't really comment on that further without being more familiar with the Newton API.


Thank you so much, that was it, I don't know how I overlooked it, I probably tried everything except changing the signature. The reason i had Gravity in there is because the method has to be static, and so I have to make Gravity static as well to reference it, but if Gravity is static it will be shared among every instance of the class (I think) and I might want different objects to be infuenced by different gravity constants. Anyways thanks again :)

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

This topic is closed to new replies.

Advertisement