From: Christian Skluzacek (c.skluzacek++at++fokkerspace.nl)
Date: 04/19/2000 06:22:27
Daniel,
This looks like the classic "C++ static member function as a callback" type
situation. The function you passed to setTravFuncs() must be a static
function (i.e. no this pointer) so you have to pass a pointer to your object
to that function somehow (notice the void * second argument in your
altViewSave() function. You set this data pointer by using setTravData(). So
basically, you have to do this:
class GFXViewPoint {
static int altViewSave(...);
};
int GFXViewPoint::altViewSave( pfTraverser *trav, void *data)
{
GFXViewPoint * pSelf = static_cast<GFXViewPoint *>data;
// use pSelf instead of this
}
viewPointDCS->setTravData( PFTRAV_APP, static_cast<void *>(this) );
viewPointDCS->setTravFuncs( PFTRAV_APP, NULL, altViewSave);
Daniel F Johnston schreef:
> We have defined some 'graphics object' class in C++ to allow us to
> easily build
> up a scene graph from a readable text description.
>
> One of these classes is a ViewPoint - implemented as a traverser
> callback on
> an offset DCS (DCS makes it easer to read the matrix) so that the
> forward
> value of the matrix can be used to define the viewing
> position/orientation
> and the displays 'follow' a moving object.
>
> I would like to implement the pfTravFuncs call inside one method of the
> class. The function name is of type 'pdNodeTravFuncType'. I would
> like to encapsulate the callback function also as a method of the class,
> so
> each viewpoint has its own callback defined within it. The type of this
>
> callback function is int - so it can pass back the 'PFTRAV_CONT" flag.
>
> How do I declare/cast these methods so that the compiler will pass them
> and so they work as I wish. I looked at this for a hour os so yesterday
>
> but my brain wasn't working too well - then or today. So, lets ask
> the experts out in Performer land.
>
> Thanks for any help!
>
> PS Here is a code snippet - the stuff that doesn't work
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> ...
> viewPointDCS = new pfDCS();
> root->addChild(viewPointDCS);
> viewPointDCS->setTravFuncs( PFTRAV_APP, NULL, altViewSave);
> setGraphRoot(root);
>
> // Remember that we have been initialized...
> setGraphInitialized(true);
> if( shared->verbosity > 0 )
> pfNotify(PFNFY_NOTICE, PFNFY_PRINT, "GFXViewPoint::init -
> Done\n");
> return true;
> }
>
> int
> GFXViewPoint::altViewSave( pfTraverser *trav, void *data)
> {
> // store the current DCS value (in world coordinates) as our
> viewpoint
> pfDCS *node;
>
> node = (pfDCS *)trav->getNode();
> node->getMat( shared->cabViewPoint );
> return PFTRAV_CONT;
> }
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> --
> ___|__ |
> / | \ ||\ 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!
>
> -----------------------------------------------------------------------
> List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
This archive was generated by hypermail 2b29 : Wed Apr 19 2000 - 06:22:54 PDT