// 3次元空間の広さ const double L = 32.0; //---- Graphics settings. // properties about the window size. const int WIN_WID = 256; const int WIN_HEI = 256; const GLfloat WIN_COL[] = { 0.0, 0.0, 0.0, 1.0 }; // properties about the scope. const GLdouble EYE_POS[] = { 0.0, 2*L, L/2 }; const GLdouble GAZE_POS[] = { 0.0, 0.0, 0.0 }; const GLdouble UP_DIR[] = { 0.0, -L, L*4 }; const GLdouble SCOPE_ANG = 32.0; const GLdouble SCOPE_NEAR = L/2; const GLdouble SCOPE_FAR = 8*L; // properties about the light. GLfloat LIGHT_POS[] = { L, L, 3*L }; const GLfloat LIGHT_DIF[] = { 1.0, 1.0, 1.0, 1.0 }; const GLfloat LIGHT_SPE[] = { 1.0, 1.0, 1.0, 1.0 }; const GLfloat LIGHT_AMB[] = { 0.5, 0.5, 0.5, 1.0 }; /*********** Definition of OpenGL callback functions **********************/ double dthe = 0.0, dphi = 0.0; //---- Callback function which is called to draw. void myDisplay(void) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glPushMatrix();{ glCallList(1); }glPopMatrix(); glFlush(); glutSwapBuffers(); } //---- Mouseの callback void myMouse( int button, int state, int x, int y ) { static int xs=0, ys=0, xe, ye; if( button == GLUT_LEFT_BUTTON ){ if( state == GLUT_DOWN ){ xs = x, ys = y; }else if( state == GLUT_UP ){ xe = x, ye = y; dthe = double((ye-ys)/16); dphi = double((xe-xs)/16); xs = xe, ys = ye; if( dthe == 0.0 && dphi == 0.0 ){ glutIdleFunc( NULL ); }else{ glutIdleFunc( myIdle ); } } } } //---- Callback function which is called by the keyboard actions. void myNormalKey( int k, int x, int y ) { switch( k ){ case 's' : { char fname[64]; fprintf( stdout, "Input file name:"); fflush( stdout ); fscanf( stdin, "%s", fname ); fflush( stdin ); glutSaveWindow(fname); break; } } glutPostRedisplay(); } void mySpecialKey( int k, int x, int y ) { switch( k ){ case GLUT_KEY_ESC : exit(0); } glutPostRedisplay(); } //---- idle時に計算を行うcallback void myIdle( void ) { glRotateL(dthe, 1.0, 0.0, 0.0 ); glRotateL(dphi, 0.0, 1.0, 0.0 ); glutPostRedisplay(); } //---- セットアップを行う関数 void stdSetup( int& argc, char** argv ) { glutOpenWindow( argc, argv, WIN_WID, WIN_HEI, WIN_COL ); glutSetEye( SCOPE_ANG, SCOPE_NEAR, SCOPE_FAR, EYE_POS, GAZE_POS, UP_DIR ); glutSetLight( LIGHT_POS, LIGHT_AMB, LIGHT_DIF, LIGHT_SPE ); glutIdleFunc( NULL ); }