Above
Step: Please look at the note, here slightly.
The implementation code is as follows:
1#include"windows.h"2#include <gl\glut.h>3 4 //size ratio of the three5 #defineSunsize 0.46 #defineEarthsize 0.067 #defineMoonsize 0.0168 9Glfloat Speedmultiplicator =0.01;//Run multipleTen //Time Scale OneGlfloat daysperyear =365.24;//OK, ok ... but it's soo slow with 360! AGlfloat Dayspermoon =27.321;//days of the lunar revolution - //degrees Cumulative Angle -Glfloat Eartharoundsun =0.0; theGlfloat earthitsself =0.0; -Glfloat Moonaroundearth =0.0; -Glfloat moonitsself =0.0; - //radius +Glfloat Earthorbitradius =1.0;//Earth Orbit radius -Glfloat Moonorbitradius =0.15;//Lunar orbit radius + //Angular Velocity AGlfloat Earthitsselfspeed =360.0/1.0* Speedmultiplicator;//take one day as the unit time atGlfloat Moonaroundearthspeed =360.0/Dayspermoon *Speedmultiplicator; -Glfloat moonitsselfspeed = moonaroundearthspeed;//simultaneous rotation of the moon -Glfloat Eartharoundsunspeed =360.0/daysperyear *Speedmultiplicator; - - voidRenderscene (void) - { inGlpushmatrix ();//Press Stack 1 -Glulookat (0.0,3.0,3.0,//position of the eye z-axis +y axis =45% to 0.0,-1.0,-1.0,//position of the eye toward the z axis +y axis =45% + 0.0,1.0,0.0);//the direction of the photo upward (because you can look at the same object with the head tilted) y axis -GLCOLOR3F (1.0,1.0,0.5); theGlutwiresphere (Sunsize, -, -);//Draw the Sun * $Glpushmatrix ();//Press Stack 2Panax NotoginsengGlrotatef (Eartharoundsun,0.0,1.0,0.0);//the orbital angle of the Earth's Revolution y-axis -Gltranslatef (Earthorbitradius,0.0,0.0);//Earth Orbit radius theGlrotatef (-eartharoundsun,0.0,1.0,0.0); + AGlpushmatrix ();//Press Stack 3 theGlrotatef (Earthitsself,0.4348,1.0,0.0);//the orbital angle of the Earth's rotation +GLCOLOR3F (0.0,0.5,0.8); -Glutwiresphere (Earthsize,8,8);//Draw Earth $ //Draw Earth rotation axis Earth Rotation axis $Gllinestipple (0.1,0x0f0f);//Imaginary Line Part 1 -Glenable (gl_line_stipple);//Imaginary Line Part 2 -Glbegin (Gl_lines);//Line theglvertex3f (0.1087,0.25,0.0); -glvertex3f (-0.1087,-0.25,0.0);Wuyi glend (); theGldisable (gl_line_stipple);//Imaginary Line Part 3 - WuGlpopmatrix ();//out of the stack 3 - About //Restore the coordinate system to the Earth's spherical sphere $Glrotatef (Moonaroundearth,0.0,1.0,0.0);//orbit angle of the moon around the earth -Gltranslatef (Moonorbitradius,0.0,0.0);//Lunar orbit radius > earth size radius - //the following 2 lines should be combined, but it's better to understand this -Glrotatef (-moonaroundearth,0.0,1.0,0.0);//The Moon rotates counterclockwise along the y axis AGlrotatef (Moonitsself,0.0,1.0,0.0);//The moon rotates clockwise along the y axis +GLCOLOR3F (0.8,0.8,0.75);//Set Color theGlutwiresphere (Moonsize,8,8);//Draw a Sphere -Glpopmatrix ();//out of the stack 2 $ the //return to the coordinate system of the sun's sphere theGlpopmatrix ();//out of the stack 1 the the } - in voidInit (void) the { theGlclearcolor (0.0,0.0,0.0,0.0);//Clear Color AboutGlcleardepth (10.0);//Clear Depth theGlmatrixmode (Gl_modelview);//Model Matrix theGlloadidentity ();//images captured by the scene are displayed on the screen in special processing the } + - voidDisplay (void) the {Bayi glclear (gl_color_buffer_bit); theRenderscene ();//Rendering the Glflush (); - glutswapbuffers (); - } the the voidReshape (intXinty) the { the if(Y = =0)return; -Glmatrixmode (gl_projection);//projection matrix the glloadidentity (); theGluperspective (30.0, (gldouble) x/(gldouble) y,0.8,10.0);//Setting the projection transformation theGlmatrixmode (Gl_modelview);//Model Matrix94Glviewport (0,0, x, y);//images captured by the scene are displayed on the screen in special processing the Display (); the } the Static Long LongTimes =0;98 voidIdle (void) About { -times++;//Delay101 if(times>50000)102Times =0;103 if(times%50000==0)104 { theEarthitsself + = Earthitsselfspeed;//the speed of the day106Eartharoundsun + = Eartharoundsunspeed;//a year's speed107Moonitsself + = Moonitsselfspeed;//rotation speed of the moon108Moonaroundearth + = Moonaroundearthspeed;//the speed of the moon around the earth109 Display (); the }111 } the 113 the intMainintargcChar*argv[]) the { theGlutinit (&argc, argv);117Glutinitdisplaymode (glut_double |Glut_rgb);118Glutinitwindowsize ( -, -);119Glutcreatewindow (argv[0]); - Init ();121 Glutreshapefunc (reshape);122 Glutdisplayfunc (Display);123 Glutidlefunc (Idle);124 Glutmainloop (); the return 0;126}
OPENGL+VS2010 's routines-Sun Earth Lunar Motion model enhanced (three-dimensional)