/* Rotates3D points. Changes points each time mouse is clicked (courtesy of Brooks van Horn) */ #ifdef _WIN32 #include #endif #include #include void mouse( int, int, int, int ); void display( void ); void reshape( int, int ); void keyboard( unsigned char, int, int ); void Idle( void ); void InitializeVariables( void ); /// forwarding functions int xdim, ydim; /// screen dimensions struct vPoint { inline float &operator[] ( int index ) { return element[index]; } float element[3]; }; // const float X_STEP = 0.005; const float Y_STEP = 0.020; const float Z_STEP = 0.025; // bool flag; /// flag to tell us if there is anything to draw yet/ vPoint rotation; // current rotation const int MAX_DOTS = 10; /// # of dots to generate and render/ vPoint dots[ MAX_DOTS ]; /// the set of points to render/ int main( int argc, char *argv[] ) { InitializeVariables(); /// nothing to do with OpenGL. My function that zeroes variables and such stuff./ xdim = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 500; ydim = ( argc > 2 ) ? atoi( argv[ 2 ] ) : 500; glutInit( &argc, argv ); //* Initialization function *// glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); /// Set double buffer and GRB modes/ glutInitWindowSize( xdim, ydim ); /// Set the screen size/ glutCreateWindow( "This is the title of the window."); glClearColor( 0.0, 0.0, 0.0, 0.0 ); /// clear color and alpha at each pixel/ glShadeModel( GL_FLAT ); /// set shading mode to flat (constant color for each polygon)/ glutDisplayFunc( display ); /// tells OpenGL what function to call when it needs to redraw/ glutReshapeFunc( reshape ); /// tells OpenGL what function to call when window is reshaped/ glutMouseFunc( mouse ); /// tells OpenGL what function to call when a mouse button is pressed/ glutKeyboardFunc( keyboard ); /// tells OpenGL to call the keyboard function with current parameters/ glutIdleFunc( Idle ); glutMainLoop(); /// important call to include after the above 3/ return EXIT_SUCCESS; } void InitializeVariables( void ) {rotation[ 0 ] = rotation[ 1 ] = rotation[ 2 ] = 0.0; flag = true; } void mouse( int button, int state, int x, int y ) /* button: GLUT_LEFT_BUTTON or GLUT_MIDDLE_BUTTON or GLUT_RIGHT_BUTTON, state : state of the button: pressed (GLUT_DOWN) or not pressed (GLUT_UP), x, y : position of mouse */ { if ( state == GLUT_UP ) return ; /// we don't care when the mouse button is released/ for (int i = 0; i