Changeset 1994 in orxonox.OLD for orxonox/branches/dave/core/orxonox.cc
- Timestamp:
- Jun 21, 2004, 12:39:11 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/dave/core/orxonox.cc
r1883 r1994 26 26 /* class definition header */ 27 27 #include "orxonox.h" 28 #include "environment.h"29 28 30 29 … … 50 49 World* Orxonox::world = 0; 51 50 InputOutput* Orxonox::io = 0; 51 Player* Orxonox::localPlayer = 0; 52 52 bool Orxonox::pause = false; 53 bool Orxonox::inputEnabled = false; 53 54 bool Orxonox::upWeGo = false; 54 55 bool Orxonox::downWeGo = false; 55 56 bool Orxonox::rightWeGo = false; 56 57 bool Orxonox::leftWeGo = false; 58 bool Orxonox::shoot1 = false; 59 int Orxonox::fps = 0; 57 60 int Orxonox::alpha = 0; 58 61 int Orxonox::beta = 0; … … 70 73 int Orxonox::globalInit (int argc, char** argv) 71 74 { 75 glEnable(GL_DEPTH_TEST); 76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 72 77 glutInit(&argc, argv); 73 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 74 glEnable(GL_DEPTH_TEST); 75 glutInitWindowSize(500, 500); 78 glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB | GLUT_DEPTH); 79 glEnable(GL_NORMALIZE); 80 glEnable(GL_COLOR_MATERIAL); 81 /*glEnable(GL_LIGHT0); 82 glEnable(GL_LIGHTING); 83 GLfloat LPosition[4]={1.0,1.0,1.0,0.0}; 84 glLightfv(GL_LIGHT0,GL_POSITION,&LPosition[0]); 85 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); 86 */ 87 88 89 /* muss nicht eingeschaltet werden, da sonst Transparenz aktiviert 90 glEnable(GL_BLEND); 91 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 92 glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE); 93 */ 94 95 96 glutInitWindowSize(1000, 1000); 76 97 //glutFullScreen(); 77 glutInitWindowPosition( 100, 100);98 glutInitWindowPosition(200, 200); 78 99 glutCreateWindow("orxOnox"); 79 glShadeModel(GL_ FLAT);100 glShadeModel(GL_SMOOTH); 80 101 /* window event dispatchers */ 81 102 glutDisplayFunc(display); 82 103 glutReshapeFunc(reshape); 83 104 glutKeyboardFunc(keyboard); 105 glutKeyboardUpFunc(upKeyboard); 106 107 108 glutTimerFunc(1000, timeSlice, 0); 109 cout << "measuring performance..."; 84 110 } 85 111 … … 87 113 int Orxonox::menuInit (void) 88 114 { 89 glClearColor(0.0, 0.0, 0.0, 0.0);115 glClearColor(0.0, 0.0, 0.0,1.0); 90 116 } 91 117 … … 93 119 int Orxonox::gameInit (void) 94 120 { 95 glClearColor(0.0, 0.0, 0.0, 0.0); 121 glClearColor(0.0, 0.0, 0.0,1.0); 122 123 /* world init, shouldnt be done here later */ 96 124 world = new World; 97 125 (*world).initEnvironement(); 98 Player* localPlayer = new Player; 126 localPlayer = new Player; 127 localPlayer->setPosition(0.0, -10.0, 3.0); 128 localPlayer->setCollisionRadius(2.0); 99 129 io = new InputOutput(world, localPlayer); 100 130 (*world).addPlayer(localPlayer); … … 102 132 (*world).addEnv(env); 103 133 134 135 NPC* npc = new NPC; 136 npc->setPosition(3.0, 0.0, 3.0); 137 npc->setCollisionRadius(1.0); 138 world->addNPC(npc); 139 140 NPC* npc2 = new NPC; 141 npc2->setPosition(-2.0, 10.0, 3.0); 142 npc2->setCollisionRadius(1.0); 143 world->addNPC(npc2); 144 145 NPC* npc3 = new NPC; 146 npc3->setPosition(3.0, 30.0, 3.0); 147 npc3->setCollisionRadius(1.0); 148 world->addNPC(npc3); 149 150 NPC* npc4 = new NPC; 151 npc4->setPosition(-2.0, 35.0, 3.0); 152 npc4->setCollisionRadius(1.0); 153 world->addNPC(npc4); 154 155 NPC* npc5 = new NPC; 156 npc5->setPosition(5.0, 45.0, 3.0); 157 npc5->setCollisionRadius(1.0); 158 world->addNPC(npc5); 104 159 105 160 glutSpecialFunc(specFunc); 106 161 glutSpecialUpFunc(releaseKey); 107 162 108 //for testing purps only109 //testTheShit();110 163 glutIdleFunc(continousRedraw); 111 } 164 //cout << "Orxonox::gameInit" << endl; 165 } 166 167 168 /* this is the time triggered function. heart beat*/ 169 170 void Orxonox::timeSlice(int value) 171 { 172 cout << "got " << fps << " fps" << endl; 173 /* this is very very unsafe: io could be uninit */ 174 io->setPlayerStep(19.0/fps); /* set player to propper speed */ 175 localPlayer->shootLaser->setShootStep(20.0/fps); /* set shoot speed */ 176 world->setWorldStep(7.0/fps); /* set the speed of the terrain moving away */ 177 fps = 0; 178 inputEnabled = true; 179 glutTimerFunc(1000, timeSlice, 0); 180 } 181 112 182 113 183 … … 131 201 132 202 /* game controls */ 133 134 203 case 'p': 135 204 if (pause) … … 146 215 } 147 216 break; 217 case 32: 218 shoot1 = true; 219 break; 148 220 case 27: 149 221 case 'q': … … 154 226 155 227 228 void Orxonox::upKeyboard(unsigned char key, int x, int y) 229 { 230 switch(key) { 231 case 32: 232 shoot1 = false; 233 break; 234 } 235 } 236 237 156 238 void Orxonox::quitGame() 157 239 { 158 //glutIgnoreKeyRepeat(0); /* for win32 */ 159 //glutSetKeyRepeat(GLUT_KEY_REPEAT_DEFAULT); /*do not remove or you will have 160 // no repeating keys anymore...*/ 161 cout << "finished garbage colletion, quitting..." << endl; 240 //cout << "finished garbage colletion, quitting..." << endl; 162 241 exit(0); 163 242 } … … 191 270 { 192 271 switch(key) { 193 194 272 /* spacecraft controls */ 195 196 273 case GLUT_KEY_UP: 197 274 upWeGo = true; … … 213 290 { 214 291 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 215 216 glColor3f(0.0, 0.5, 0.6); 292 glColor3f(0.2, 0.0, 0.8); 217 293 glLoadIdentity(); 218 gluLookAt(0.0, -14.0, 15.0, 0.0 + alpha, 0.0 + beta, 0.0, 0.0, 1.0, 0.0);219 (*world).drawWorld();220 294 gluLookAt(0.0, -14.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); 295 // (*world).drawWorld(); diese und die naechste Zeile bedeuten das gleiche!!! 296 world->drawWorld((float)beta,(float)alpha); 221 297 glutSwapBuffers(); 222 298 } … … 225 301 void Orxonox::continousRedraw() 226 302 { 303 /* increment the frames-per-second counter*/ 304 305 fps++; 306 /* check for collisions */ 307 world->detectCollision(); 308 227 309 /* check for input to pass it over */ 228 if ( !pause && (rightWeGo || leftWeGo || upWeGo || downWeGo)) { 229 if (upWeGo) 230 (*io).goUp(); 231 if (downWeGo) 310 if ( !pause && inputEnabled && 311 (rightWeGo || leftWeGo || upWeGo || downWeGo || shoot1)) 312 { 313 if (upWeGo) 314 (*io).goUp(); 315 if (downWeGo) 232 316 (*io).goDown(); 233 if (rightWeGo)234 235 if (leftWeGo)317 if (rightWeGo) 318 (*io).goRight(); 319 if (leftWeGo) 236 320 (*io).goLeft(); 237 } 321 if (shoot1) 322 (*io).shoot(); 323 } 238 324 /* request repaint */ 239 240 //cout << "contiousRedraw" << endl;241 325 glutPostRedisplay(); 326 //cout << "Orxonox::continousRedraw" << endl; 242 327 } 243 328 … … 248 333 glMatrixMode(GL_PROJECTION); 249 334 glLoadIdentity(); 250 //glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); pb: //simple and working251 335 glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 200.0); 252 //glFrustum(-10.0, 10.0, -5.0, 10.0, 0.0, 100.0);253 336 glMatrixMode(GL_MODELVIEW); 254 337 glLoadIdentity(); //pb why a second time?
Note: See TracChangeset
for help on using the changeset viewer.