Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "windows.h"
- #include <gl\glut.h>
- #define sunRaduis 0.4
- #define earthRaduis 0.06
- #define moonRaduis 0.016
- GLfloat rotationSpeed = 0.1;
- GLfloat daysInYear = 365;
- GLfloat year = 0.0; //degrees
- GLfloat day = 0.0;
- GLfloat moonAroundEarth = 0.0;
- GLfloat moonItsSelf = 0.0;
- GLfloat earthOrbitRadius = 1.0;
- GLfloat moonOrbitRadius = 0.1;
- GLfloat moonAroundEarthRate = 2 * rotationSpeed;
- GLfloat moonRotationItselfRate = 5.0 * rotationSpeed;
- GLfloat dayRate = 5.0 * rotationSpeed;
- GLfloat yearRate = daysInYear / 360.0 * dayRate * rotationSpeed;
- void drawSolarSystem(void);
- void Initialization(void);
- void displayFunc(void);
- void reshapeFunc(int x, int y);
- void idleFunc(void);
- int main(int argc, char* argv[])
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowSize(700,700);
- glutCreateWindow("Sonyachna systema");
- Initialization();
- glutReshapeFunc(reshapeFunc);
- glutDisplayFunc(displayFunc);
- glutIdleFunc(idleFunc);
- glutMainLoop();
- return 0;
- }
- void drawSolarSystem(void)
- {
- glPushMatrix();
- gluLookAt( 0.0,0.0,-4.0,
- 0.0,0.0,1.0,
- 0.0,-3.0,0.0);
- glColor3f(1.0,0.8,0.3);
- glutSolidSphere(sunRaduis,50,50);
- glPushMatrix();
- glRotatef(year,0.0,1.0,0.0);
- glTranslatef(earthOrbitRadius,0.0,0.0);
- glRotatef(-year,0.0,1.0,0.0);
- glPushMatrix();
- glRotatef(day,0.25,1.0,0.0);
- glColor3f(0.4,0.6,0.3);
- glutSolidSphere(earthRaduis,10,10);
- glPopMatrix();
- glRotatef(moonAroundEarth,0.0,1.0,0.0);
- glTranslatef(moonOrbitRadius,0.0,0.0);
- glRotatef(-moonAroundEarth,0.0,1.0,0.0);
- glRotatef(moonItsSelf,0.0,1.0,0.0);
- glColor3f(0.3,0.3,0.5);
- glutSolidSphere(moonRaduis,8,8);
- glPopMatrix();
- glPopMatrix();
- }
- void Initialization(void)
- {
- glClearColor(0.0,0.0,0.0,0.0);
- glClearDepth(10.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- void displayFunc(void)
- {
- glClear(GL_COLOR_BUFFER_BIT);
- drawSolarSystem();
- glFlush();
- glutSwapBuffers();
- }
- void reshapeFunc(int x, int y)
- {
- if (y == 0 || x==0) return;
- glLoadIdentity();
- gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
- glMatrixMode(GL_MODELVIEW);
- glViewport(0,0,x,y);
- displayFunc();
- }
- void idleFunc(void)
- {
- day += dayRate;
- year += yearRate;
- moonItsSelf += moonRotationItselfRate;
- moonAroundEarth += moonAroundEarthRate;
- displayFunc();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement