Above
Step: First, set the model perspective back, then rotate the view, then draw with the default drawing cube function, and finally, use idle to make the model angle fine-tuning.
The implementation code is as follows:
1#include <GL\glut.h>2 3 glfloat xrotated, yrotated, zrotated;4 5 voidDisplay (void)6 {7 glclear (gl_color_buffer_bit);8 glloadidentity ();9Gltranslatef (0.0,0.0,-4.0);TenGlrotatef (xrotated,1.0,0.0,0.0); OneGlrotatef (yrotated,0.0,1.0,0.0); AGlrotatef (zrotated,0.0,0.0,1.0); - //Glscalef (2.0,1.0,1.0); -Glutwirecube (1.5); theGlflush ();//Finish Rendering - glutswapbuffers (); - } - + voidReshape (intXinty) - { + if(Y = =0|| x = =0)return;//Nothing was visible then and so return A //Set a new projection matrix at Glmatrixmode (gl_projection); - glloadidentity (); - //Angle of view:40 degrees - //Near clipping plane distance:0.5 - //Far clipping plane distance:20.0 -Gluperspective (40.0, (gldouble) x/(gldouble) y,0.5,20.0); in Glmatrixmode (gl_modelview); -Glviewport (0,0, x, y);//Use the whole window for rendering to } + Static intTimes =0; - voidIdle (void) the { *times++; $ if(Times >30000)Panax NotoginsengTimes =0; - the if(Times%30000==0) + { Axrotated + =0.3; theyrotated + =0.1; +zrotated + =-0.4; - Display (); $ } $ } - - the intMain (intargcChar**argv) - {Wuyi //Initialize GLUT theGlutinit (&argc, argv); -Glutinitdisplaymode (glut_double | GLUT_RGB);//For animations your should use double buffering WuGlutinitwindowsize ( -, -); - //Create A window with rendering context and everything else we need AboutGlutcreatewindow ("Cube Example"); $ Glpolygonmode (gl_front_and_back,gl_line); -xrotated = yrotated = zrotated =0.0; -Glclearcolor (0.0,0.0,0.0,0.0); - //Assign The Used msg-routines A Glutdisplayfunc (Display); + Glutreshapefunc (reshape); the Glutidlefunc (Idle); - //Let GLUT get the msgs $ Glutmainloop (); the return 0; the}
opengl+vs2010 routines-Rotating cubes (three-dimensional)