Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef WIN32
- #include <windows.h>
- #endif
- #include <cassert>
- #include <GL/glut.h>
- #include <GL/glu.h>
- #include "math.h"
- #include "planet.h"
- #include "spline.h"
- const int WINDOW_WIDTH = 640;
- const int WINDOW_HEIGHT = 480;
- __int64 g_Frequency; // Number of high-performance counter ticks per second
- __int64 g_Timer;
- int height, width;
- CSolarSystem solSys(5);
- CPlanet mercury(0.4, 0.383, 88, 1.0, 0.5, 1.0);
- CPlanet venus(0.7, 0.949, 225, 0.0, 1.0, 0.0);
- CPlanet earth(1.0, 1.0, 365, 0.5, 0.7, 1.0);
- CPlanet mars(1.5, 0.533, 687, 1.0, 0.0, 0.0);
- CPlanet jupiter(5.2, 11.209, 4331, 1.0, 1.0, 0.9);
- CPlanet saturn(9.5, 9.449, 10759, 0.0, 0.5, 0.0);
- CPlanet uranus(19.6, 4.007, 30799, 0.0, 0.0, 1.0);
- CPlanet neptune(30, 3.883, 60190, 0.0, 1.0, 1.0);
- CStarCatalog* g_Stars = 0x0;
- void CheckGLError()
- {
- GLenum error = glGetError();
- if (error != GL_NO_ERROR)
- {
- const GLubyte* str = gluErrorString(error);
- assert(false); // Use the debugger to look at the contents of str when you end up here
- }
- }
- void display(void)
- {
- //Clear the colour and depth buffer before displaying anything
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glEnable(GL_DEPTH_TEST);
- //Designates the modelview as the matrix to perform operations on
- glMatrixMode(GL_MODELVIEW);
- // Replace the current matrix with the identity matrix
- glLoadIdentity();
- //Drawing a testcube.
- //TODO: remove later!
- gluLookAt(70.0f, 1.0f, 70.0f,
- 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f);
- /*glColor3f(12,10,1);
- glutWireCube(1.0f);
- glutWireSphere(0.5f, 20, 20);*/
- //Call the draw function from planet here
- // Draw the stars and the solar system here!
- solSys.Draw();
- CheckGLError();
- glutSwapBuffers();
- }
- void reshape(int w, int h)
- {
- width = w;
- height = h;
- /*Set the size of the view port.
- First two variables designate starting
- coordinates, the second two designate
- width and height respectively*/
- glViewport(0.0f, 0.0f, (GLsizei)w, (GLsizei)h);
- glMatrixMode(GL_PROJECTION);
- // Replace the current matrix with the identity matrix
- glLoadIdentity();
- // Set an appropriate projection matrix here!
- /*Set a perspective: angle in the y direction, ratio between the angle
- of the x and y direction, distance from the viewer to near plane far
- plane respectively.*/
- GLfloat aspect = (float)w/(float)h;
- gluPerspective(45.0f, aspect, 1.0f, 100.0f);
- glMatrixMode(GL_MODELVIEW);
- // Replace the current matrix with the identity matrix
- glLoadIdentity();
- // Don't forget to set the clip plane distances to appropriate values!
- }
- void idle(void)
- {
- __int64 now;
- QueryPerformanceCounter((LARGE_INTEGER *)&now);
- float dt = (float)(now - g_Timer) / (float)g_Frequency; // Seconds
- // Update the solar system and camera animation here!
- // The variable dt contains the number of seconds
- // since the last frame. So if dt is 0.0166, the time
- // between frames is 16.6 milliseconds. Or, equivalently,
- // (1 / 0.0166) = 60 frames per second.
- QueryPerformanceCounter((LARGE_INTEGER *)&g_Timer);
- glutPostRedisplay();
- }
- void keyboard(unsigned char key, int x, int y)
- {
- switch (key)
- {
- // If the user presses Escape, close the program
- case 27: // Esc
- // Clean up any memory you allocated on the heap here!
- exit(0);
- break;
- }
- }
- void main(int argc, char **argv)
- {
- if (!QueryPerformanceFrequency((LARGE_INTEGER *)&g_Frequency))
- assert(false && "High-performance timer needed");
- QueryPerformanceCounter((LARGE_INTEGER *)&g_Timer);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT);
- glutCreateWindow("OpenGL Solar System");
- CSolarSystem solSys(5);
- CPlanet mercury(0.4, 0.383, 88, 1.0, 0.5, 1.0);
- CPlanet venus(0.7, 0.949, 225, 0.0, 1.0, 0.0);
- CPlanet earth(1.0, 1.0, 365, 0.5, 0.7, 1.0);
- CPlanet mars(1.5, 0.533, 687, 1.0, 0.0, 0.0);
- CPlanet jupiter(5.2, 11.209, 4331, 1.0, 1.0, 0.9);
- CPlanet saturn(9.5, 9.449, 10759, 0.0, 0.5, 0.0);
- CPlanet uranus(19.6, 4.007, 30799, 0.0, 0.0, 1.0);
- CPlanet neptune(30, 3.883, 60190, 0.0, 1.0, 1.0);
- solSys.AddPlanet(&mercury);
- solSys.AddPlanet(&venus);
- solSys.AddPlanet(&earth);
- solSys.AddPlanet(&mars);
- solSys.AddPlanet(&jupiter);
- solSys.AddPlanet(&saturn);
- solSys.AddPlanet(&uranus);
- solSys.AddPlanet(&neptune);
- glutDisplayFunc(display);
- glutReshapeFunc(reshape);
- glutIdleFunc(idle);
- glutKeyboardFunc(keyboard);
- g_Stars = new CStarCatalog(9110); // The Yale Bright Star Catalog has 9110 entries
- g_Stars->ReadFromFile("star_catalog.txt");
- glutMainLoop();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement