#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include const int NUM_LIGHTS = 4; static pfLight *ls[NUM_LIGHTS]; static void OpenPipeWin(pfPipeWindow *pw); static void DrawChannel(pfChannel *channel, void *data); main() // // Calculate and render pairs of object orientations that are examples of // all different kinds of object/view/rotation axis directions // { pfInit(); pfuInit(); pfMultiprocess( PFMP_DEFAULT ); pfdInitConverter("dummy.iv"); pfConfig(); pfScene *scene = new pfScene; pfDCS *dcs = new pfDCS; pfNode *node = pfdLoadFile( "cube.iv" ); if( dcs && node ) { dcs->addChild( node ); scene->addChild( dcs ); } pfPipe *pipe = pfGetPipe(0); pfPipeWindow *pw = new pfPipeWindow(pipe); pw->setName(""); int display_x = 500, display_y = 350; pw->setOriginSize( 0, 0, display_x, display_y ); pw->setMode( PFWIN_NOBORDER, PFIS_TRUE ); pw->setConfigFunc(OpenPipeWin); pw->config(); float near = 0.1, far = 10000.0, h_fov = 45.0, v_fov = 0.0; pfChannel *chan = new pfChannel( pipe ); chan->setNearFar( near, far ); chan->setFOV( h_fov, v_fov ); chan->setScene( scene ); chan->setTravFunc( PFTRAV_DRAW, DrawChannel ); pfVec3 xyz( 0.0, 0.0, 0.0), hpr( 0.0, 0.0, 0.0 ); xyz[1] = -5.0; chan->setView( xyz, hpr ); // // User input // pfuInitInput( pipe->getPWin( 0 ), PFUINPUT_X ); pfuMouse mouse; int mouse_button_press[3] = {0, 0, 0}; // Left, middle and right float finc = 2.0; int cnt = 0; while ( cnt < 250 ) { cnt++; pfSync(); pfuGetMouse( &mouse ); if( mouse.click || mouse.release ) { cout << pfGetTime() << '\t' << mouse.click << '\t' << mouse.release << endl; } if( mouse.click & PFUDEV_MOUSE_LEFT_DOWN ) { mouse_button_press[0] = 1; } if( mouse.release & PFUDEV_MOUSE_LEFT_DOWN ) { mouse_button_press[0] = 0; } if( mouse.click & PFUDEV_MOUSE_MIDDLE_DOWN ) { mouse_button_press[1] = 1; } if( mouse.release & PFUDEV_MOUSE_MIDDLE_DOWN ) { mouse_button_press[1] = 0; } if( mouse.click & PFUDEV_MOUSE_RIGHT_DOWN ) { mouse_button_press[2] = 1; } if( mouse.release & PFUDEV_MOUSE_RIGHT_DOWN ) { mouse_button_press[2] = 0; } if( mouse_button_press[0] ) { hpr[0] += finc; } if( mouse_button_press[1] ) { hpr[1] += finc; } if( mouse_button_press[2] ) { hpr[2] += finc; } dcs->setRot( hpr[0], hpr[1], hpr[2] ); if( mouse_button_press[0] || mouse_button_press[1] || mouse_button_press[2] ) { cout << pfGetTime() << " mouse: " << mouse_button_press[0] << mouse_button_press[1] << mouse_button_press[2] << endl; } pfFrame(); } pfuExitInput(); pfuExitUtil(); pfExit(); } void OpenPipeWin(pfPipeWindow *pw_local) { int l1; pw_local->open(); 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( 0.0f, 0.0f, -1.0f, 0.0f ); l1++; 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( -2.0f, -1.0f, 0.1f, 0.0f ); l1++; 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( 1.0f, 1.5f, 0.1f, 0.0f ); l1++; 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 ); //cull_back_face ? PFCF_BACK : PFCF_OFF ); } static void DrawChannel (pfChannel *channel, void *data) { int l1; for( l1=0; l1on(); } channel->clear(); pfDraw(); }