From: Daniel F Johnston (dan.johnston++at++nrc.ca)
Date: 05/31/2000 05:10:30
Ken Lindsay wrote:
> hi,
>
> I am trying to implement traverser callbacks in a c++ class. If I try to
> make the function a member function, I get this error:
>
> "NelAircraft.cpp", line 333: error(1515): a value of type
> "void (NelAircraft::*)(pfuTraverser *)" cannot be assigned to an
> entity of type "pfuTravFuncType"
> trav.preFunc = foo_preTravCB;
> ^
>
> if I prototype the functions separately:
>
> int foo_postTravCB(pfuTraverser *trav);
>
> then I compile with no problem. How am I supposed to write this to
> get the c++ compiler to be happy?
>
> thanks
>
> ken
>
> -==-
>
> ken "fire a few neurons" lindsay kl++at++mars.arc.nasa.gov
> NASA Ames Research Center QSS Group, Inc.
Declare your callback function (ie in the .h file) like this...
/** Callback function for this ViewPoint. As Performer traverses the
scene graph, it will issue a callback when it gets to checking this
'branch'. We use the callback to store the current position/orientation
of the branch in world coordinates, i.e. we know Performer has already
done this 'chain' of transform calculations so we just record the
intermediate (and useful to us) result.
++at++param trav The pfTraverser class is passed as a standard parameter
for the callback function. The traverser will hold the matrix value
we are searching for (via a trav->getMat()).
++at++param data Another standard callback function. In this case we pass
a pointer to the class so that we can access the class-private data
even when the callback function is declared as a method of this class.
*/
static int altViewSave( pfTraverser *trav, void *data );
Then in the .C code you do this..
First the code (in the constructor) to build the 'viewpoint'
scene graph 'branch'
...
// Define the DCS to 'hold' the callback
viewPointDCS = new pfDCS();
root->addChild(viewPointDCS);
viewPointDCS->setTravData( PFTRAV_APP, static_cast<void *>(this));
viewPointDCS->setTravFuncs( PFTRAV_APP, altViewSave, NULL);
...
Then the callback function itself...
int
GFXViewPoint::altViewSave( pfTraverser *trav, void *data)
{
// store the current SCS value (in world coordinates) as our viewpoint
// get a class pointer so we can reference the common memory
if( shared->verbosity > 0 )
pfNotify(PFNFY_WARN, PFNFY_PRINT, "GFXViewPoint::altViewSave\n");
GFXViewPoint *pSelf = static_cast<GFXViewPoint*>(data);
// trav-getMat() will have the current world coordinates of our node
trav->getMat( pSelf->shared->cabViewPoint );
return PFTRAV_CONT;
}
Thats all there is to it!
Good luck!
--
___|__ |
/ | \ ||\ Daniel (Dan) Johnston
/___|___\ || \ Dan.Johnston++at++nrc.ca
_____|____ || \ National Research Council of Canada, London, ON
| | | || \ Integrated Manufacturing Technologies Institute
\___| | | ||____\ Tel: (519) 430-7081 Fax: (519) 430-7090
\_o_\___|____|_|______\_ Inst: http://www.nrc.ca/imti
\ o / These opinions are my own! Not those of NRC.
\________________/ Virtual Reality:
http://www.nrc.ca/imti/vetc/home.html
More Tall Ships - Fewer Computers!
This archive was generated by hypermail 2b29 : Thu Jun 01 2000 - 12:22:49 PDT