FW: RE: [ODE] Moving ode test program into a class

whitt013 whitt013 at bama.ua.edu
Sun Feb 16 13:07:01 2003


Grrr, forwarding this to the list.... I sent it straight to Pete.

--------------------

C++ classes and callback functions don't mix all that well.  The way I've
always done it that I know works is this:  you create a standard callback
function with one line, that calls class.function() and passes the parameters
on through.

You could try playing with the drawstuff source to take a pointer to your
class and use that instead of a dsFunctions.  There might be some problems
with incompatibilities with drawstuff and c++.  I noticed there was an extern
"C" around the drawstuff.h file.

Finally, the best alternative for c++ is probably not to use drawstuff.  Qt
has a nice QGLWidget class that handles cross-platform openGL window setup if
you want a nice fancy GUI around it.  Or you could use glut to do the window
setup.  And you can use GLU, glut, or just borrow the functions out of
drawstuff to draw your spheres, boxes, and cylinders.

I've got a class that is similar to drawstuff except that it uses stencil
buffer shadows instead of ground plane compression.  It only has sphere and
box support right now, though it would be a fairly simple matter to add in the
cylinders.  And it assumes the window is setup already.  Let me know if you'd
like me to send it to you, and I'll try to get it to you tomorrow night when I
get back into town.

Hope that helps,
David

>===== Original Message From "Pete Graves" <pete_graves@hotmail.com> =====
>I'm quite new to C++ (but some with C & Java experience), and trying to
>experiment with ODE.
>
>I've tried moving some functions [eg void start()] into a new class called
>Simulation to use as part of another program. There is a few lines that
>stores pointers to some of the functions, and passes them to another
>function within the physics library.
>
>// setup pointers to drawstuff callback functions
>dsFunctions fn;
>fn.start = &start;
>fn.step = &simLoop;
>fn.command = &command;
>..
>// run simulation
>dsSimulationLoop (argc,argv,352,288,&fn);
>
>So in the class version I have tried to write:
>fn.start = &Simulation::start;
>fn.step = &Simulation::simLoop;
>fn.command = &Simulation::command;
>But I get the error "cannot convert `void (Simulation::*)()' to `void (*)()'
>in assignment"
>
>I also tried:
>fn.start = &(Simulation::start);
>fn.step = &(Simulation::simLoop);
>fn.command = &(Simulation::command);
>But this said: "taking address of bound pointer-to-member expression".
>
>Could someone explain what I am doing wrong?
>
>Thanks,
>
>Pete.
>
>_________________________________________________________________
>Surf together with new Shared Browsing
>http://join.msn.com/?page=features/browse&pgmarket=en-gb&XAPID=74&DI=1059
>
>_______________________________________________
>ODE mailing list
>ODE@q12.org
>http://q12.org/mailman/listinfo/ode