Callback in class

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Callback in class

Postby nathanf534 » Sun Jul 11, 2010 4:48 pm

I want the callback to be a method in a class I have, but it gets a compilation error that I don't know how to fix... (function pointers still confuse me a bit)

Here is the class
Code: Select all
#include "PhysicsManager.h"

PhysicsManager::PhysicsManager() {
   nWorld = NewtonCreate();
}
PhysicsManager::~PhysicsManager() {
   // TODO Auto-generated destructor stub
}
void PhysicsManager::addHullCollisionBody(IMeshSceneNode* node){
   NewtonCollision* collision =NewtonCreateConvexHull(nWorld,4,(const float*)(node->getMesh()->getMeshBuffer(0)->getVertices()),12,0,0,NULL);
   NewtonBody* body=NewtonCreateBody(nWorld,collision);
   UserData userData;
   userData.node=node;
   NewtonBodySetUserData(body,&userData);
   NewtonBodySetForceAndTorqueCallback(body,ApplyForceAndTorqueEvent);//this is where im getting the error
}
void PhysicsManager::update(){
   NewtonUpdate(nWorld,.016);
}
void _cdecl PhysicsManager::ApplyForceAndTorqueEvent (const NewtonBody* body,float matrix,int x){//this is the method I want to be the callback
   cout<<"apply force and torque event callback"<<endl;
}


and here is the error: "error: argument of type `void (PhysicsManager::)(const NewtonBody*, float, int)' does not match `void (*)(const NewtonBody*, float, int)'"

hopefully there is a simple cast I can do to fix it, but I haven't been able to figure it out.
nathanf534
 
Posts: 19
Joined: Sun Jul 11, 2010 9:01 am

Re: Callback in class

Postby add2005 » Sun Jul 11, 2010 5:53 pm

You can't use a method for this.

You can point the newtonbody userdata to a class where you keep functions and properties that you want to use in callback function.
add2005
 
Posts: 2
Joined: Sun Jul 11, 2010 6:44 am

Re: Callback in class

Postby Julio Jerez » Sun Jul 11, 2010 10:10 pm

There is a way to do it explained in the FAQ forum
viewtopic.php?f=15&t=1102
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron