#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static void OpenPipeWin(pfPipeWindow *pw); static void DrawChannel(pfChannel *channel, void *data); static pfPipeWindow *pw; const int NUM_LIGHTS = 4; static pfLight *ls[NUM_LIGHTS]; #define PI (3.1415926535897) #define DEG_TO_RAD( d ) ( (d) * PI / 180.0 ) int main( int argc, char *argv[] ) { int l1; // // Initialise and configure Performer // pfInit(); pfuInit(); pfMultiprocess( PFMP_DEFAULT ); pfdInitConverter("dummy.iv"); pfConfig(); // // Configure and open pipe and pipewindow(s) // pfPipe *pipe = pfGetPipe(0); int pw_origin[2] = {0, 0}, pw_size[2] = {1280, 1024}; pw = new pfPipeWindow(pipe); pw->setOriginSize( pw_origin[0], pw_origin[1], pw_size[0], pw_size[1] ); pw->setMode( PFWIN_NOBORDER, PFIS_TRUE ); pw->setConfigFunc(OpenPipeWin); pw->config(); pfScene *scene = new pfScene; pfChannel *chan = new pfChannel( pipe ); chan->setNearFar( 0.01, 1000.0 ); chan->setFOV( 48.0, 0.0 ); chan->setScene( scene ); chan->setTravFunc( PFTRAV_DRAW, DrawChannel ); pfNode *node = pfdLoadFile( "cyl.iv" ); // // Input // pfuInitInput( pw, PFUINPUT_X ); if( node ) { scene->addChild( node ); } float heading, pitch, xx = 0.0, yy = 0.0, zz = 1.65; pfVec3 xyz( xx, yy, zz ), hpr; pfuMouse mouse; int exit_flag = 0; double t1, t2 = pfGetTime(); l1 = 0; do { pfSync(); t1 = t2; pfuGetMouse( &mouse ); heading = float(mouse.xpos - 640) / 640.0 * 180.0; pitch = float(mouse.ypos - 512) / 512.0 * 90.0; hpr.set( heading, pitch, 0.0 ); chan->setView( xyz, hpr ); t2 = pfGetTime(); xx += 0.5 * (t2 - t1) * cos( DEG_TO_RAD( 90.0 + heading ) ); yy += 0.5 * (t2 - t1) * sin( DEG_TO_RAD( 90.0 + heading ) ); xyz.set( xx, yy, zz ); chan->setView( xyz, hpr ); pfFrame(); } while( !exit_flag ); pfuExitUtil(); pfExit(); return 0; } void OpenPipeWin(pfPipeWindow *pw_local) { int l1; pw_local->open(); l1 = 0; pfLightModel *light_model = new pfLightModel; float col = 0.3; light_model->setAmbient( col, col, col ); light_model->apply(); col = 1.0f; l1 = 0; ls[l1] = new pfLight; ls[l1]->setColor( PFLT_DIFFUSE, col, col, col ); ls[l1]->setPos( 1.0f, 0.0f, 0.0f, 0.0f ); l1++; ls[l1] = new pfLight; col = 0.7f; ls[l1]->setColor( PFLT_DIFFUSE, col, col, col ); ls[l1]->setPos( 0.0f, 1.0f, 0.0f, 0.0f ); l1++; ls[l1] = new pfLight; col = 0.4f; ls[l1]->setColor( PFLT_DIFFUSE, col, col, col ); ls[l1]->setPos( 0.0f, 0.0f, 1.0f, 0.0f ); l1++; ls[l1] = new pfLight; col = 0.2f; ls[l1]->setColor( PFLT_DIFFUSE, col, col, col ); ls[l1]->setPos( 0.0f, -1.0f, 0.0f, 0.0f ); l1++; pfEnable(PFEN_LIGHTING); //pfOverride(PFSTATE_FRONTMTL, PF_ON); pfOverride(PFSTATE_LIGHTMODEL, PF_ON); pfAntialias( PFAA_OFF ); pfCullFace( PFCF_BACK ); } static void DrawChannel (pfChannel *channel, void *data) { int l1; for( l1=0; l1on(); } channel->clear(); pfDraw(); }