Above
Step: Slightly
The implementation code is as follows:
1#include"windows.h"2#include <gl\glut.h>3 4 #defineSunsize 0.45 #defineEarthsize 0.066 #defineMoonsize 0.0167 8Glfloat Speedmultiplicator =1.0;9Glfloat daysperyear =50.0;//OK, ok ... but it's soo slow with 360!TenGlfloat year =0.0;//degrees OneGlfloat Day =0.0; AGlfloat Moonaroundearth =0.0; -Glfloat moonitsself =0.0; -Glfloat Earthorbitradius =1.0; theGlfloat Moonorbitradius =0.1; -Glfloat Dayspeed =5.0*Speedmultiplicator; -Glfloat yearspeed = daysperyear/360.0* Dayspeed *Speedmultiplicator; -Glfloat Moonaroundearthspeed =Ten*Speedmultiplicator; +Glfloat Moonitsselfspeed =5*Speedmultiplicator; - voidRenderscene (void) + { A Glpushmatrix (); atGlulookat (0.0,0.0,-4.0, - 0.0,0.0,1.0, - 0.0,-3.0,0.0); -GLCOLOR3F (1.0,1.0,0.6); -Glutwiresphere (Sunsize, -, -); - Glpushmatrix (); inGlrotatef (Year,0.0,1.0,0.0); -Gltranslatef (Earthorbitradius,0.0,0.0); toGlrotatef (-year,0.0,1.0,0.0); + Glpushmatrix (); -Glrotatef (Day,0.25,1.0,0.0); theGLCOLOR3F (0.0,0.5,0.8); *Glutwiresphere (Earthsize,Ten,Ten);//Draw Earth $ //Draw Earth Rotation axisPanax Notoginseng Glbegin (gl_lines); -glvertex3f (-0.0625,-0.25,0.0); theglvertex3f (0.0625,0.25,0.0); + glend (); A Glpopmatrix (); theGlrotatef (Moonaroundearth,0.0,1.0,0.0); +Gltranslatef (Moonorbitradius,0.0,0.0); - //the following 2 lines should be combined, but it's better to understand this $Glrotatef (-moonaroundearth,0.0,1.0,0.0); $Glrotatef (Moonitsself,0.0,1.0,0.0); -GLCOLOR3F (0.8,0.8,0.75); -Glutwiresphere (Moonsize,8,8); the Glpopmatrix (); - Wuyi Glpopmatrix (); the } - Wu voidInit (void) - { AboutGlclearcolor (0.0,0.0,0.0,0.0); $Glcleardepth (10.0); - Glmatrixmode (gl_modelview); - glloadidentity (); - } A + voidDisplay (void) the { - glclear (gl_color_buffer_bit); $ Renderscene (); the Glflush (); the glutswapbuffers (); the } the - voidReshape (intXinty) in { the if(Y = =0)return; the Glmatrixmode (gl_projection); About glloadidentity (); theGluperspective (40.0, (gldouble) x/(gldouble) y,0.5,20.0); the Glmatrixmode (gl_modelview); theGlviewport (0,0, x, y); + Display (); - } the Static Long LongTimes =0;Bayi voidIdle (void) the { thetimes++; - if(times>1000000) -Times =0; the if(times%1000000==0) the { theDay + =Dayspeed; theYear + =Yearspeed; -Moonitsself + =Moonitsselfspeed; theMoonaroundearth + =Moonaroundearthspeed; the Display (); the }94 } the the the intMainintargcChar*argv[])98 { AboutGlutinit (&argc, argv); -Glutinitdisplaymode (glut_double |Glut_rgb);101Glutinitwindowsize ( -, -);102Glutcreatewindow (argv[0]);103 Init ();104 Glutreshapefunc (reshape); the Glutdisplayfunc (Display);106 Glutidlefunc (Idle);107 Glutmainloop ();108 return 0;109}
OPENGL+VS2010 's routine--the sun-earth Lunar motion model (three-dimensional)