Advertisement
Guest User

Untitled

a guest
Dec 18th, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. #include "windows.h"
  2. #include <gl\glut.h>
  3.  
  4. #define sunRaduis 0.4
  5. #define earthRaduis 0.06
  6. #define moonRaduis 0.016
  7.  
  8. GLfloat rotationSpeed = 0.1;
  9. GLfloat daysInYear = 365;  
  10. GLfloat year = 0.0; //degrees
  11. GLfloat day = 0.0;
  12. GLfloat moonAroundEarth = 0.0;
  13. GLfloat moonItsSelf = 0.0;
  14. GLfloat earthOrbitRadius = 1.0;
  15. GLfloat moonOrbitRadius = 0.1;
  16. GLfloat moonAroundEarthRate = 2 * rotationSpeed;
  17. GLfloat moonRotationItselfRate = 5.0 * rotationSpeed;
  18. GLfloat dayRate = 5.0 * rotationSpeed;
  19. GLfloat yearRate = daysInYear / 360.0 * dayRate * rotationSpeed;
  20. void drawSolarSystem(void);
  21. void Initialization(void);
  22. void displayFunc(void);
  23. void reshapeFunc(int x, int y);
  24. void idleFunc(void);
  25. int main(int argc, char* argv[])
  26. {
  27.  
  28.     glutInit(&argc, argv);
  29.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  30.     glutInitWindowSize(700,700);
  31.     glutCreateWindow("Sonyachna systema");
  32.     Initialization();
  33.     glutReshapeFunc(reshapeFunc);
  34.     glutDisplayFunc(displayFunc);
  35.     glutIdleFunc(idleFunc);
  36.     glutMainLoop();
  37.     return 0;
  38. }
  39. void drawSolarSystem(void)
  40. {
  41.  
  42.     glPushMatrix();    
  43.  
  44.         gluLookAt(    0.0,0.0,-4.0,
  45.                     0.0,0.0,1.0,
  46.                     0.0,-3.0,0.0);
  47.         glColor3f(1.0,0.8,0.3);
  48.         glutSolidSphere(sunRaduis,50,50);
  49.         glPushMatrix();
  50.  
  51.             glRotatef(year,0.0,1.0,0.0);
  52.             glTranslatef(earthOrbitRadius,0.0,0.0);
  53.             glRotatef(-year,0.0,1.0,0.0);
  54.             glPushMatrix();
  55.                 glRotatef(day,0.25,1.0,0.0);
  56.                 glColor3f(0.4,0.6,0.3);
  57.                 glutSolidSphere(earthRaduis,10,10);  
  58.  
  59.             glPopMatrix();
  60.             glRotatef(moonAroundEarth,0.0,1.0,0.0);
  61.             glTranslatef(moonOrbitRadius,0.0,0.0);
  62.  
  63.             glRotatef(-moonAroundEarth,0.0,1.0,0.0);
  64.             glRotatef(moonItsSelf,0.0,1.0,0.0);
  65.  
  66.             glColor3f(0.3,0.3,0.5);
  67.             glutSolidSphere(moonRaduis,8,8);
  68.         glPopMatrix();
  69.  
  70.     glPopMatrix();
  71. }
  72.  
  73. void Initialization(void)
  74. {
  75.     glClearColor(0.0,0.0,0.0,0.0);
  76.     glClearDepth(10.0);
  77.  
  78.  
  79.  
  80.     glMatrixMode(GL_MODELVIEW);
  81.     glLoadIdentity();
  82. }
  83.  
  84. void displayFunc(void)
  85. {
  86.     glClear(GL_COLOR_BUFFER_BIT);
  87.     drawSolarSystem();
  88.     glFlush();
  89.     glutSwapBuffers();
  90. }
  91.  
  92. void reshapeFunc(int x, int y)
  93. {
  94.     if (y == 0 || x==0) return;
  95.  
  96.     glLoadIdentity();
  97.     gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
  98.     glMatrixMode(GL_MODELVIEW);
  99.     glViewport(0,0,x,y);
  100.     displayFunc();
  101. }
  102.  
  103. void idleFunc(void)
  104. {
  105.     day += dayRate;
  106.     year += yearRate;
  107.     moonItsSelf += moonRotationItselfRate;
  108.     moonAroundEarth += moonAroundEarthRate;
  109.     displayFunc();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement