Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1994 in orxonox.OLD for orxonox/branches/dave/core/orxonox.cc


Ignore:
Timestamp:
Jun 21, 2004, 12:39:11 AM (20 years ago)
Author:
dave
Message:

orxonox/branches/dave:[test the Shit]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/dave/core/orxonox.cc

    r1883 r1994  
    2626/* class definition header */
    2727#include "orxonox.h"
    28 #include "environment.h"
    2928
    3029
     
    5049World* Orxonox::world = 0;
    5150InputOutput* Orxonox::io = 0;
     51Player* Orxonox::localPlayer = 0;
    5252bool Orxonox::pause = false;
     53bool Orxonox::inputEnabled = false;
    5354bool Orxonox::upWeGo = false;
    5455bool Orxonox::downWeGo = false;
    5556bool Orxonox::rightWeGo = false;
    5657bool Orxonox::leftWeGo = false;
     58bool Orxonox::shoot1 = false;
     59int Orxonox::fps = 0;
    5760int Orxonox::alpha = 0;
    5861int Orxonox::beta = 0;
     
    7073int Orxonox::globalInit (int argc, char** argv)
    7174{
     75  glEnable(GL_DEPTH_TEST);
     76  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    7277  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);
    7697  //glutFullScreen();
    77   glutInitWindowPosition(100, 100);
     98  glutInitWindowPosition(200, 200);
    7899  glutCreateWindow("orxOnox");
    79   glShadeModel(GL_FLAT);
     100  glShadeModel(GL_SMOOTH);
    80101  /* window event dispatchers */
    81102  glutDisplayFunc(display);
    82103  glutReshapeFunc(reshape);
    83104  glutKeyboardFunc(keyboard);
     105  glutKeyboardUpFunc(upKeyboard);
     106 
     107
     108  glutTimerFunc(1000, timeSlice, 0);
     109  cout << "measuring performance...";
    84110}
    85111
     
    87113int Orxonox::menuInit (void)
    88114{
    89   glClearColor(0.0, 0.0, 0.0, 0.0);
     115  glClearColor(0.0, 0.0, 0.0,1.0);
    90116}
    91117
     
    93119int Orxonox::gameInit (void)
    94120{
    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 */
    96124  world = new World;
    97125  (*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);
    99129  io = new InputOutput(world, localPlayer);
    100130  (*world).addPlayer(localPlayer);
     
    102132  (*world).addEnv(env);
    103133 
     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);
    104159
    105160  glutSpecialFunc(specFunc);
    106161  glutSpecialUpFunc(releaseKey);
    107162
    108   //for testing purps only
    109   //testTheShit();
    110163  glutIdleFunc(continousRedraw);
    111 }
     164  //cout << "Orxonox::gameInit" << endl;
     165}
     166
     167
     168/* this is the time triggered function. heart beat*/
     169
     170void 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
    112182
    113183
     
    131201
    132202    /* game controls */
    133 
    134203  case 'p':
    135204    if (pause)
     
    146215      }
    147216    break;
     217  case 32:
     218    shoot1 = true;
     219    break;
    148220  case 27:
    149221  case 'q':
     
    154226
    155227
     228void 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
    156238void Orxonox::quitGame()
    157239{
    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;
    162241  exit(0);
    163242}
     
    191270{
    192271  switch(key) {
    193 
    194272    /* spacecraft controls */
    195    
    196273  case GLUT_KEY_UP:
    197274    upWeGo = true;
     
    213290{
    214291  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);
    217293  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);
    221297  glutSwapBuffers();
    222298}
     
    225301void Orxonox::continousRedraw()
    226302{
     303  /* increment the frames-per-second counter*/
     304 
     305  fps++;
     306  /* check for collisions */
     307  world->detectCollision();
     308
    227309  /* 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)
    232316      (*io).goDown();
    233     if (rightWeGo)
    234       (*io).goRight();
    235     if (leftWeGo)
     317      if (rightWeGo)
     318        (*io).goRight();
     319      if (leftWeGo)
    236320      (*io).goLeft();
    237   }
     321      if (shoot1)
     322        (*io).shoot();
     323    }
    238324  /* request repaint */
    239 
    240   //cout << "contiousRedraw" << endl;
    241325  glutPostRedisplay();
     326  //cout << "Orxonox::continousRedraw" << endl;
    242327}
    243328
     
    248333  glMatrixMode(GL_PROJECTION);
    249334  glLoadIdentity();
    250   //glOrtho(-50.0, 50.0, -50.0, 50.0, -1.0, 1.0); pb: //simple and working
    251335  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);
    253336  glMatrixMode(GL_MODELVIEW);
    254337  glLoadIdentity(); //pb why a second time?
Note: See TracChangeset for help on using the changeset viewer.