Professional Documents
Culture Documents
CODE
#include <cmath>
#include <cstdlib>
#ifdef _WIN32
#include <Windows.h>
#endif
#include <gl\gl.h>
#include "Gl\glut.h"
#include <GL\glu.h>
#include "tga.h"
#include "solarsystem.h"
#include "camera.h"
#include "globals.h"
// The TGA texture containing the help dialogue and starfield and moon texture
// holds the index of the last planet that was selected with the 1 to 9 number keys
int planetSelected = 1;
SolarSystem solarSystem;
Camera camera;
double time;
double timeSpeed;
// holds the state of the controls for the camera - when true, the key for that control is being
pressed
struct ControlStates
} controls;
void timer(int)
void addMoon()
solarSystem.addMoon(planetSelected,
void init(void)
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
// set up lighting
glEnable(GL_LIGHTING);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glShadeModel (GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDisable(GL_LIGHTING);
// Add all the planets with accurate data. Distance measured in km, time measured in
earth days.
// set up time
time = 2.552f;
timeSpeed = 0.1f;
// reset controls
controls.forward = false;
controls.backward = false;
controls.left = false;
controls.right = false;
controls.rollRight = false;
controls.rollLeft = false;
controls.pitchDown = false;
controls.pitchUp = false;
controls.yawLeft = false;
controls.yawRight = false;
timer(0);
void drawCube(void);
void display(void)
time += timeSpeed;
solarSystem.calculatePositions(time);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
camera.transformOrientation();
glBindTexture(GL_TEXTURE_2D, stars->getTextureHandle());
drawCube();
camera.transformTranslation();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
solarSystem.render();
glDisable(GL_LIGHTING);
if (showOrbits)
solarSystem.renderOrbits();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
if (helpDialogue)
glBindTexture(GL_TEXTURE_2D, help->getTextureHandle());
glBegin(GL_QUADS);
glEnd();
glFlush();
glutSwapBuffers();
float vec[3];
camera.pointAt(vec);
switch (key)
case '-':
break;
case '=':
break;
case 'h':
break;
case '[':
break;
case ']':
break;
case 'o':
break;
case 'm':
break;
case 'r':
planetSizeScale = distanceScale;
break;
case ',':
break;
case '.':
break;
case 'w':
controls.forward = true;
break;
case 's':
controls.backward = true;
break;
case 'a':
controls.left = true;
break;
case 'd':
controls.right = true;
break;
case 'l':
controls.rollRight = true;
break;
case 'j':
controls.rollLeft = true;
break;
case 'i':
controls.pitchDown = true;
break;
case 'k':
controls.pitchUp = true;
break;
case 'q':
controls.yawLeft = true;
break;
case 'e':
controls.yawRight = true;
break;
switch (key)
case 'w':
controls.forward = false;
break;
case 's':
controls.backward = false;
break;
case 'a':
controls.left = false;
break;
case 'd':
controls.right = false;
break;
case 'l':
controls.rollRight = false;
break;
case 'j':
controls.rollLeft = false;
break;
case 'i':
controls.pitchDown = false;
break;
case 'k':
controls.pitchUp = false;
break;
case 'q':
controls.yawLeft = false;
break;
case 'e':
controls.yawRight = false;
break;
screenWidth = w;
screenHeight = h;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutInitWindowSize(1200, 700);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyDown);
glutKeyboardUpFunc(keyUp);
glutMainLoop();
return 0;
void drawCube(void)
glBegin(GL_QUADS);
// new face
// new face
// new face
// new face
// new face
// new face
glEnd();
SNAPSHOTS