Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.58 KB | None | 0 0
  1. #ifdef WIN32
  2. #include <windows.h>
  3. #endif
  4.  
  5. #include <cassert>
  6.  
  7. #include <GL/glut.h>
  8. #include <GL/glu.h>
  9.  
  10. #include "math.h"
  11. #include "planet.h"
  12. #include "spline.h"
  13.  
  14. const int WINDOW_WIDTH = 640;
  15. const int WINDOW_HEIGHT = 480;
  16.  
  17. __int64 g_Frequency;        // Number of high-performance counter ticks per second
  18. __int64 g_Timer;
  19. int height, width;
  20. CSolarSystem solSys(5);
  21. CPlanet mercury(0.4, 0.383, 88, 1.0, 0.5, 1.0);
  22. CPlanet venus(0.7, 0.949, 225, 0.0, 1.0, 0.0);
  23. CPlanet earth(1.0, 1.0, 365, 0.5, 0.7, 1.0);
  24. CPlanet mars(1.5, 0.533, 687, 1.0, 0.0, 0.0);
  25. CPlanet jupiter(5.2, 11.209, 4331, 1.0, 1.0, 0.9);
  26. CPlanet saturn(9.5, 9.449, 10759, 0.0, 0.5, 0.0);
  27. CPlanet uranus(19.6, 4.007, 30799, 0.0, 0.0, 1.0);
  28. CPlanet neptune(30, 3.883, 60190, 0.0, 1.0, 1.0);
  29.  
  30. CStarCatalog* g_Stars = 0x0;
  31.  
  32. void CheckGLError()
  33. {  
  34.     GLenum error = glGetError();
  35.     if (error != GL_NO_ERROR)
  36.     {
  37.         const GLubyte* str = gluErrorString(error);
  38.         assert(false);  // Use the debugger to look at the contents of str when you end up here
  39.     }
  40. }
  41.  
  42. void display(void)
  43. {
  44.     //Clear the colour and depth buffer before displaying anything
  45.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  46.     glEnable(GL_DEPTH_TEST);
  47.  
  48.     //Designates the modelview as the matrix to perform operations on
  49.     glMatrixMode(GL_MODELVIEW);
  50.     // Replace the current matrix with the identity matrix
  51.     glLoadIdentity();
  52.  
  53.     //Drawing a testcube.
  54.     //TODO: remove later!
  55.     gluLookAt(70.0f, 1.0f, 70.0f,
  56.                 0.0f, 0.0f, 0.0f,
  57.                     0.0f, 1.0f, 0.0f);
  58.  
  59.     /*glColor3f(12,10,1);
  60.     glutWireCube(1.0f);
  61.     glutWireSphere(0.5f, 20, 20);*/
  62.  
  63.     //Call the draw function from planet here
  64.     // Draw the stars and the solar system here!
  65.  
  66.     solSys.Draw();
  67.  
  68.     CheckGLError();
  69.      
  70.     glutSwapBuffers();
  71. }
  72.  
  73. void reshape(int w, int h)
  74. {
  75.     width = w;
  76.     height = h;
  77.     /*Set the size of the view port.
  78.     First two variables designate starting
  79.     coordinates, the second two designate
  80.     width and height respectively*/
  81.     glViewport(0.0f, 0.0f, (GLsizei)w, (GLsizei)h);
  82.  
  83.     glMatrixMode(GL_PROJECTION);
  84.     // Replace the current matrix with the identity matrix
  85.     glLoadIdentity();
  86.    
  87.     // Set an appropriate projection matrix here!
  88.     /*Set a perspective: angle in the y direction, ratio between the angle
  89.     of the x and y direction, distance from the viewer to near plane far
  90.     plane respectively.*/
  91.     GLfloat aspect = (float)w/(float)h;
  92.     gluPerspective(45.0f, aspect, 1.0f, 100.0f);
  93.     glMatrixMode(GL_MODELVIEW);
  94.     // Replace the current matrix with the identity matrix
  95.     glLoadIdentity();
  96.     // Don't forget to set the clip plane distances to appropriate values!
  97. }
  98.  
  99. void idle(void)
  100. {
  101.     __int64 now;
  102.     QueryPerformanceCounter((LARGE_INTEGER *)&now);
  103.  
  104.     float dt = (float)(now - g_Timer) / (float)g_Frequency;     // Seconds
  105.  
  106.     // Update the solar system and camera animation here!
  107.  
  108.     // The variable dt contains the number of seconds
  109.     // since the last frame. So if dt is 0.0166, the time
  110.     // between frames is 16.6 milliseconds. Or, equivalently,
  111.     // (1 / 0.0166) = 60 frames per second.
  112.  
  113.     QueryPerformanceCounter((LARGE_INTEGER *)&g_Timer);
  114.  
  115.     glutPostRedisplay();
  116. }
  117.  
  118. void keyboard(unsigned char key, int x, int y)
  119. {
  120.     switch (key)
  121.     {
  122.     // If the user presses Escape, close the program
  123.     case 27:    // Esc
  124.         // Clean up any memory you allocated on the heap here!
  125.         exit(0);
  126.         break;
  127.     }
  128. }
  129.  
  130. void main(int argc, char **argv)
  131. {
  132.     if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_Frequency))
  133.         assert(false && "High-performance timer needed");
  134.  
  135.     QueryPerformanceCounter((LARGE_INTEGER *)&g_Timer);
  136.  
  137.     glutInit(&argc, argv);
  138.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
  139.     glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
  140.  
  141.     glutCreateWindow("OpenGL Solar System");
  142.  
  143.     CSolarSystem solSys(5);
  144.     CPlanet mercury(0.4, 0.383, 88, 1.0, 0.5, 1.0);
  145.     CPlanet venus(0.7, 0.949, 225, 0.0, 1.0, 0.0);
  146.     CPlanet earth(1.0, 1.0, 365, 0.5, 0.7, 1.0);
  147.     CPlanet mars(1.5, 0.533, 687, 1.0, 0.0, 0.0);
  148.     CPlanet jupiter(5.2, 11.209, 4331, 1.0, 1.0, 0.9);
  149.     CPlanet saturn(9.5, 9.449, 10759, 0.0, 0.5, 0.0);
  150.     CPlanet uranus(19.6, 4.007, 30799, 0.0, 0.0, 1.0);
  151.     CPlanet neptune(30, 3.883, 60190, 0.0, 1.0, 1.0);
  152.  
  153.     solSys.AddPlanet(&mercury);
  154.     solSys.AddPlanet(&venus);
  155.     solSys.AddPlanet(&earth);
  156.     solSys.AddPlanet(&mars);
  157.     solSys.AddPlanet(&jupiter);
  158.     solSys.AddPlanet(&saturn);
  159.     solSys.AddPlanet(&uranus);
  160.     solSys.AddPlanet(&neptune);
  161.  
  162.     glutDisplayFunc(display);
  163.     glutReshapeFunc(reshape);
  164.     glutIdleFunc(idle);
  165.     glutKeyboardFunc(keyboard);
  166.  
  167.     g_Stars = new CStarCatalog(9110);           // The Yale Bright Star Catalog has 9110 entries
  168.     g_Stars->ReadFromFile("star_catalog.txt");
  169.  
  170.     glutMainLoop();
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement