Report any bugs here and we'll post fixes
Moderators: Sascha Willems, Thomas
by XenonGP » Fri Nov 07, 2008 8:40 am
Hi all,
I'd like to know if somebody can use NGD inside c++ classes. I can find no way to specify a correct callback pointer (pointer-to-member):
- Code: Select all
class MyClass
{
public:
void myCallBack(const NewtonBody* body, const dFloat* matrix) {
}
void run()
{
NewtonBodySetTransformCallback(rigidBodyBox, ?????? );
}
}
Do you have the same problem ?
Thanks!
-
XenonGP
-
- Posts: 3
- Joined: Fri Nov 07, 2008 8:30 am
by Aphex » Fri Nov 07, 2008 9:20 am
You probably want to use something like this (from my engine):
- Code: Select all
static void TransformChangedCallback(const NewtonBody* aBody, const dFloat* aMatrix, int aThreadIndex)
{
IPhysicsObject* physObj = reinterpret_cast<IPhysicsObject*>(NewtonBodyGetUserData(aBody));
ASSERT(physObj);
physObj->HandlePhysicsMessage(IPhysicsObject::ETransformChanged, (void*)aMatrix);
}
I.e. use a static callback function and the body user data as a context.
-
Aphex
-
- Posts: 144
- Joined: Fri Jun 18, 2004 6:08 am
- Location: UK
-
by XenonGP » Sat Nov 08, 2008 12:49 pm
No sorry, my callback cannot be static. I must find a way to make a "C" pointer out of a "C++" class method. I've found a few sites saying it is not possible... But it's strange, for me, a pointer is pointer... c++ or not. What do you think ?
-
XenonGP
-
- Posts: 3
- Joined: Fri Nov 07, 2008 8:30 am
by martinsm » Sat Nov 08, 2008 1:18 pm
Actual callback method in Aphex code is HandlePhysicsMessage method. And it is nonstatic member of class.
-
martinsm
-
- Posts: 86
- Joined: Mon Dec 19, 2005 3:15 pm
- Location: Latvia
by Julio Jerez » Sat Nov 08, 2008 10:54 pm
XenonGP wrote:No sorry, my callback cannot be static. I must find a way to make a "C" pointer out of a "C++" class method. I've found a few sites saying it is not possible... But it's strange, for me, a pointer is pointer... c++ or not. What do you think ?
Netwon callback system support interfacing with c++ bacause each callback take a context pointer.
basically you can make your funtion a static member, and pass the pointer ot the class are context.
read the FAQ for more detail.
Also the custom joints use that method.
-
Julio Jerez
- Moderator
-
- Posts: 12249
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by XenonGP » Sun Nov 09, 2008 6:47 am
Thank you all for your replies, It was indeed in the FAQ, sorry.
Thanks!
-
XenonGP
-
- Posts: 3
- Joined: Fri Nov 07, 2008 8:30 am
Return to Bugs and Fixes
Who is online
Users browsing this forum: No registered users and 11 guests