From: Don Burns (don_burns++at++peru.engr.sgi.com)
Date: 10/20/2000 12:16:41
> Can anyone clue me towards the documentation for the
> pfdRegisterUserFunc?????
Ahhh... you've just stumbled upon one of my favorite undocumented features of
Performer. The best documentation you'll find for this call is reading the
specification for the call in the header file, and this email.
/usr/include/pf/pfdu.h sez something like:
extern int pfdRegisterUserFunc(void *func,
const char *name, const char *dso_name);
func - is a pointer (or the address of) the funcntion you are registering,
name - Name of the callback routine
dso_name - Name of the DSO in which the function is stored.
Below is a simple example. The ".C" file is compiled by the Makefile to both
an executable "uf" and a shared object "uf.so". (Context is IRIX... just a
couple of Makefile changes to make it work in Linux). Running
% uf my_favorite_model.pfb
Will create an output file 'out.pfb'. This file stores the model parented by a
DCS, which has a callback, which does nothing more than spin the model. Very
cool, because, you can now store callbacks with your database!
To see the new model, with the autospin callback run:
% setenv LD_LIBRARY_PATH `pwd`
% perfly out.pfb
Have fun!
-don
########################### Makefile ################################
#!smake
OBJS = uf.o
LIBS = -lpfutil -lpfdu -lpf
C++FLAGS = -g
LDFLAGS = -g
all :: uf uf.so
uf : $(OBJS)
$(C++) $(LDFLAGS) $(OBJS) $(LIBS) -o $++at++
uf.so : $(OBJS)
$(C++) $(LDFLAGS) -shared -set_version "sgi4.0" $(OBJS) -o $++at++
########################################################################
////////////////////// uf.C /////////////////////////////////////////
#include <Performer/pf.h>
#include <Performer/pfdu.h>
#include <Performer/pf/pfDCS.h>
#include <Performer/pf/pfTraverser.h>
extern "C" int myDCSCallback( pfTraverser *trav, void *data );
int myDCSCallback( pfTraverser *trav, void *data )
{
pfDCS *dcs = (pfDCS *)trav->getNode();
static float a = 0.0;
dcs->setRot( a, 0, 0 );
a++;
return PFTRAV_CONT;
}
main( int argc, char **argv )
{
if( argc < 2 )
pfNotify( PFNFY_FATAL, PFNFY_PRINT, "Usage : %s <some_model>\n",
argv[0] );
pfInit();
pfdInitConverter( argv[1] );
pfdInitConverter( ".pfb" );
pfConfig();
pfFilePath( ".:/usr/share/Performer/data" );
pfNode *node = pfdLoadFile( argv[1] );
// HERE IT IS..
int (*dcsCallback)(pfTraverser *, void *);
dcsCallback = myDCSCallback;
pfdRegisterUserFunc( (void *)dcsCallback, "myDCSCallback", "uf.so" );
pfDCS *dcs = new pfDCS;
dcs->setTravFuncs( PFTRAV_APP, dcsCallback, 0L );
dcs->addChild( node );
pfdStoreFile( dcs, "out.pfb" );
pfExit();
}
///////////////////////////////////////////////////////////////////////////
This archive was generated by hypermail 2b29 : Fri Oct 20 2000 - 12:17:57 PDT