Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <glut.h>
- float angle = 0.0f;
- float red = 1.0f, blue = 1.0f, green = 1.0f;
- float zoom_in_out = 45.0f;
- float change_angle_up = 0.0;
- void renderScene(void);
- void changeSize(int width, int height);
- void processSpecialKeys(int key, int x, int y);
- int main(int argc, char **argv)
- {
- // initialize glut and create window
- glutInit(&argc,argv);
- glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(320, 320);
- glutCreateWindow("Solar System");
- // register callback functions
- glutDisplayFunc(renderScene);
- glutReshapeFunc(changeSize);
- glutIdleFunc(renderScene);
- // register keyboard entry
- glutSpecialFunc(processSpecialKeys);
- // enter glut event processing loop
- glutMainLoop();
- return 1;
- }
- void renderScene(void)
- {
- // clear color and depth buffers
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- // reset transformations
- glLoadIdentity();
- // set camera
- gluLookAt(50.0f, 50.0f, zoom_in_out,
- 0.0f, 0.0f, 0.0f,
- 0.5f, 0.5f, 0.5f);
- // draw earth
- glPushMatrix();
- glColor3f(0.5, 1, 0.5);
- glRotatef(angle, 0.0f, 1.0f, 0.0f);
- glTranslatef(0.0f, 0.0f, 50.0f);
- glPushMatrix();
- glColor3f(1, 1,1);
- glRotatef(angle, 0.0f, 0.0f, 1.0f);
- glTranslatef(0.1f,0.1f,0.0f);
- glutSolidSphere(5, 50, 50);
- glPopMatrix();
- glutSolidSphere(5, 50, 50);
- glPopMatrix();
- // draw sun
- glPushMatrix();
- glColor3f(1.0f, 1.0f, 0.0f);
- glTranslatef(0.0f, 0.0f, 0.0f);
- glutSolidSphere(10, 50, 50);
- glPopMatrix();
- //rotate
- angle += 0.1f;
- glutSwapBuffers();
- }
- void changeSize(int width, int height)
- {
- // prevent division by zero when window is too short
- if (height == 0) height = 1;
- float ratio = 1.0* width / height;
- // use the projection matrix
- glMatrixMode(GL_PROJECTION);
- // reset matrix
- glLoadIdentity();
- // set the viewport to be the entire window
- glViewport(0, 0, width, height);
- // set the correct perspective
- gluPerspective(45, ratio, 1, 1000);
- // Get Back to the Modelview
- glMatrixMode(GL_MODELVIEW);
- }
- void processSpecialKeys(int key, int x, int y)
- {
- switch (key)
- {
- case GLUT_KEY_LEFT:
- break;
- case GLUT_KEY_RIGHT:
- break;
- case GLUT_KEY_UP:
- //if(zoom_in_out != 30.0f)
- zoom_in_out -= 3.0f;
- break;
- case GLUT_KEY_DOWN:
- //if (zoom_in_out != 60.0f)
- zoom_in_out += 3.0f;
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement