opengl+vs2010 routines-Rotating cubes (three-dimensional)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.