/******************************************************************************* // // kishan@hackorama.com http://www.hackorama.com Mon Nov 1 19:17:26 PST 1999 // // g++ teapot.cc -lpf -lpfdu -lpfutil -o teapot // *******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include static pfNode *load_model(); static void mydraw( pfChannel *chan, void *data ); main (int argc, char *argv[]) { pfSphere bsphere; pfVec3 view_xyz, view_hpr; /* Initialise Performer processes and configs */ pfInit(); pfMultiprocess( PFMP_DEFAULT ); pfConfig(); /* Craete a Pipe and a pipewindow */ pfPipe *mypipe = pfGetPipe(0); pfPipeWindow *pipewin = new pfPipeWindow(mypipe); pipewin->setWinType(PFPWIN_TYPE_X); pipewin->setName("hello cube" ); pipewin->setOriginSize(0,0,512,512); pipewin->open(); /* load the nodel as a node */ pfNode *modelnode = load_model(); /* Create a Scene and add the cube node to it */ pfScene *myscene = new pfScene; /* before adding cube create a Dynamic Coordinate System */ pfDCS *dcs = new pfDCS; /* now add cube to the DCS so that it can rotate */ dcs->addChild( modelnode ); /* add the DCS to the scene */ myscene->addChild(dcs); /* light up the scene */ myscene->addChild(new pfLightSource); /* Create a Channel on the pipe and attach the myscene to it */ pfChannel *mychan = new pfChannel(mypipe); mychan->setScene(myscene); /* Set the Camera or Viewpoint x y z h p r and Field Of View */ mychan->setFOV(45.0f, 0.0f); dcs->getBound(&bsphere); mychan->setNearFar(1.0f, bsphere.radius * 10.0f ); view_xyz.set( bsphere.center[0], bsphere.center[1] - (bsphere.radius * 4) , bsphere.center[2] ); view_hpr.set( 0.0, 0.0, 0.0 ); mychan->setView(view_xyz, view_hpr); mychan->setTravFunc( PFTRAV_DRAW, mydraw ); mychan->setViewport( 0.0, 1.0, 0.0, 1.0 ); /* Run the simulation loop */ while(1) { static float angle = 0.0; angle++; pfSync(); /* Add rotation to the dcs which will rotate the cube */ dcs->setRot( angle/4, angle/4, 0.0 ); pfFrame(); } /* since its an infinite loop above */ /* there is no proper exit, please ctrl+c out */ /* in actual case you should check keyboard events */ /* or some thing else to exit gracefully :) */ /* exit(0); */ } /* the draw function */ /* just clear the scene and redraw it */ static void mydraw( pfChannel *chan, void *data ) { chan->clear(); pfDraw(); } static pfNode *load_model( ) { /*const char meshFile[80] = "/usr/share/Performer/data/teapot.dxf";*/ const char meshFile[80] = "teapot.dxf"; pfNode *myObject = pfdLoadFile(meshFile); return myObject; }