Main Page | Namespace List | Class Hierarchy | Data Structures | File List | Data Fields | Globals

D:/Archiv/Projekte/OpenGL/quaxbomber03/main.cpp

Go to the documentation of this file.
00001 
00008 #include "Quaxbomber.h"
00009 #include "GameArea.h"
00010 #include "GameTile.h"
00011 #include "CoveredGameTileModel.h"
00012 #include "UncoveredGameTileModel.h"
00013 
00014 #include <gl/gl.h>
00015 #include <gl/glu.h>
00016 #include <gl/glut.h>
00017 
00018 
00019 #include <iostream>
00020 #include <math.h>
00021 #include <time.h>
00022 
00023 using namespace std;
00024 
00025 // function declarations. see comments above the functions for details
00026 void display(void);
00027 void initGL(void);
00028 void setViewpoint(GLfloat radius, GLfloat rotX, GLfloat rotY);
00029 
00030 
00031 // angle around the x-axis
00032 GLint angleX =  STARTANGLE;
00033 // angle around the y axis
00034 GLfloat angleY = STARTANGLE;
00035 //
00036 GameArea *gA;
00037 
00046 void setViewpoint(GLfloat radius, GLfloat rotX, GLfloat rotY) {
00047   // move along the positive z-axis
00048   glTranslated(0.0, 0.0, -radius);
00049   // rotation around the x-axis
00050   glRotatef(-rotX, 1.0, 0.0, 0.0);
00051   // rotation around the y-axis
00052   glRotatef(rotY, 0.0, 1.0, 0.0);
00053 }
00054 
00055 
00059 void display(void) {
00060   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00061   glLoadIdentity();
00062   // calculate the eyepoint coordinates  
00063   setViewpoint(CAMRADIUS, angleX, angleY);
00064   glTranslatef((GLfloat)-TILESOFFSET, 0.0f, (GLfloat)-TILESOFFSET);
00065   gA->renderGameArea();
00066   glutSwapBuffers();
00067 }
00068 
00069 
00070 
00071 void reshape (int w, int h) {
00072   // VIEWPORT TRANSFORMATION
00073   // define the region of the output image
00074   glViewport (0, 0, (GLsizei) w, (GLsizei) h);
00075   // PROJECTION TRANSFORMATION
00076   // choose projection matrix stack
00077   glMatrixMode (GL_PROJECTION);
00078   glLoadIdentity ();
00079   gluPerspective(60, (GLdouble)w/h, 1.5, 30.0);
00080   // choose model matrix stack.
00081   glMatrixMode (GL_MODELVIEW);
00082   glLoadIdentity();
00083 }
00084 
00088 void initGL (void) {
00089   glClearColor (0.0, 0.0, 0.0, 0.0);
00090   glEnableClientState(GL_VERTEX_ARRAY);
00091   glEnableClientState(GL_COLOR_ARRAY);
00092     
00093   glShadeModel(GL_SMOOTH);
00094   glEnable(GL_DEPTH_TEST);      
00095 }
00096 
00097 
00101 void keyEvent(unsigned char key, int x, int y) {
00102   long s;
00103   srand(time(&s));
00104   int a = (rand()) % (gA->dim);
00105   int b = (rand()) % (gA->dim);
00106 
00107   switch(key) {
00108     case 'b':      
00109       gA->uncoverTile(a, b);
00110       cout << "x, y: " << a << ", " << b << endl;
00111       break;        
00112     case 27: 
00113       exit(0); 
00114       break;
00115     default: 
00116       break;
00117   }   
00118 }
00119 
00120 
00121 
00125 int main(int argc, char** argv) {
00126   gA = new GameArea(GameArea::EASY);
00127   gA -> debugArrays(true, true, true);
00128   glutInit(&argc, argv);
00129   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA);
00130   glutInitWindowSize (800, 600);
00131   glutInitWindowPosition (100, 100);
00132   glutCreateWindow ("Quaxbomber 0.1");
00133   initGL();
00134   glutDisplayFunc(display);
00135   glutReshapeFunc(reshape);
00136   glutKeyboardFunc(keyEvent);
00137   glutMainLoop();
00138   return 0;
00139 }

Generated on Fri Apr 8 00:11:47 2005 for Quaxbomber by  doxygen 1.4.1