A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Auradrummer » Wed Dec 22, 2010 9:04 am
Is possible to do this?
That is because I have a bunch of variables that can cause interference, and all of them are private. So, would make the things easier if the ForceAndTorqueCallback was a member of my class. Is possible doing this?
Thanks
Ney
Last edited by
Auradrummer on Wed Dec 22, 2010 12:11 pm, edited 1 time in total.
Developing a racing game.
-
Auradrummer
-
- Posts: 132
- Joined: Sat May 17, 2008 9:17 am
by ledahut » Wed Dec 22, 2010 9:40 am
-
ledahut
-
- Posts: 98
- Joined: Mon Jun 21, 2010 8:03 am
- Location: France
by Auradrummer » Wed Dec 22, 2010 10:04 am
Hello ledahut,
Thanks for the fast reply, but I'm still confused:
I made the following:
obj.h
- Code: Select all
class obj
{
private:
void applyPlayerForce (const NewtonBody* body, dFloat timestep, int thread);
};
obj.cpp
- Code: Select all
obj::applyPlayerForce (const NewtonBody* body, dFloat timestep, int thread)
{
... code ...
}
obj::constructPhysics (..args..)
{
....
SetTorqueAndForceCallback(obj_body,applyPlayerForce)
...
};
As I saw in the example, this should work, but when I compile I receive the following compiler error:
error: argument of type `void (obj::)(const NewtonBody*, float, int)' does not match `void (*)(const NewtonBody*, float, int)'|
I'm still working here, but I'm still confused... Thanks again.
Developing a racing game.
-
Auradrummer
-
- Posts: 132
- Joined: Sat May 17, 2008 9:17 am
by Auradrummer » Wed Dec 22, 2010 12:15 pm
Hello guys,
Solved, but I not understood why.
Inside the prototype, I have to declare static void instead of void, but at the implementation stills void.
But I not understood why this works. Is someone have some time to explain me what happens, should be good. I'll try to discover too, and post the answer here.
Thanks
Ney
Developing a racing game.
-
Auradrummer
-
- Posts: 132
- Joined: Sat May 17, 2008 9:17 am
by Auradrummer » Wed Dec 22, 2010 1:07 pm
Another information if someones has the same question as mine.
To access all the members of you class inside the callback (including the privates), just pass 'this' as user data together NewtonBody. In the post by ledahut this is done, and works very fine.
Developing a racing game.
-
Auradrummer
-
- Posts: 132
- Joined: Sat May 17, 2008 9:17 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 1 guest