Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3399 in orxonox.OLD for orxonox/branches/nico/src/world.cc


Ignore:
Timestamp:
Feb 6, 2005, 11:27:25 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/nico: merged trunk into branches/nico
merged with command:
svn merge ../trunk/ nico/ -r 3238:HEAD
resolved conflict in favor of branches/nico.

Location:
orxonox/branches/nico
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/nico

    • Property svn:externals set to
  • orxonox/branches/nico/src/world.cc

    r3238 r3399  
    1818#include "world_entity.h"
    1919#include "collision.h"
     20#include "track_manager.h"
    2021#include "track.h"
    2122#include "player.h"
     
    2324#include "camera.h"
    2425#include "environment.h"
     26#include "p_node.h"
     27#include "null_parent.h"
     28#include "helper_parent.h"
     29#include "glmenu_imagescreen.h"
    2530
    2631using namespace std;
     
    3439World::World (char* name)
    3540{
     41  this->setClassName ("World");
    3642  this->worldName = name;
    3743  this->debugWorldNr = -1;
     
    4854/**
    4955    \brief remove the World from memory
     56   
     57    delete everything explicitly, that isn't contained in the parenting tree!
     58    things contained in the tree are deleted automaticaly
    5059*/
    5160World::~World ()
     
    5766  this->localCamera->destroy();
    5867
     68  this->nullParent->destroy ();
     69
     70  //delete this->trackManager;
     71
     72  /*
    5973  WorldEntity* entity = entities->enumerate(); 
    6074  while( entity != NULL )
     
    6478    }
    6579  this->entities->destroy();
    66 
    67   delete this->entities;
    68   delete this->localCamera;
     80  */
     81
     82  /* FIX the parent list has to be cleared - not possible if we got the old list also*/
     83
     84
     85  //delete this->entities;
     86  //delete this->localCamera;
    6987  /* this->localPlayer hasn't to be deleted explicitly, it is
    7088     contained in entities*/
    7189}
     90
     91GLfloat ctrlpoints[4][3] = {
     92  {20.0, 10.0, 5.0}, {40.0, -10.0, 0.0},
     93  {60.0, -10.0, 5.0}, {80.0, 10.0, 5.0}};
    7294
    7395
     
    78100  cn->addToWorld(this);
    79101  cn->enable(true);
    80 }
     102
     103  //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
     104  //glEnable (GL_MAP1_VERTEX_3);
     105 
     106  //theNurb = gluNewNurbsRenderer ();
     107  //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR);
     108  //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback );
     109
     110}
     111
     112
    81113
    82114ErrorMessage World::start()
     
    99131}
    100132
     133
    101134ErrorMessage World::resume()
    102135{
     
    104137}
    105138
     139
    106140void World::destroy()
    107141{
    108 
    109 }
     142}
     143
     144
     145void World::displayLoadScreen ()
     146{
     147  printf ("World::displayLoadScreen - start\n");
     148 
     149  //GLMenuImageScreen*
     150  this->glmis = new GLMenuImageScreen();
     151  this->glmis->init();
     152  this->glmis->setMaximum(10);
     153  this->glmis->draw();
     154 
     155  printf ("World::displayLoadScreen - end\n");
     156}
     157
     158
     159void World::releaseLoadScreen ()
     160{
     161  printf ("World::releaseLoadScreen - start\n");
     162  this->glmis->setValue(this->glmis->getMaximum());
     163  SDL_Delay(500);
     164  printf ("World::releaseLoadScreen - end\n");
     165}
     166
    110167
    111168void World::load()
    112169{
     170  //  BezierCurve* tmpCurve = new BezierCurve();
    113171  if(this->debugWorldNr != -1)
    114172    {
     173      trackManager = TrackManager::getInstance();
     174      trackManager->addPoint(Vector(0,-5,0));
     175      trackManager->addPoint(Vector(10,0,5));
     176      trackManager->addPoint(Vector(20,0,-5));
     177      trackManager->addPoint(Vector(30,0,5));
     178      trackManager->addPoint(Vector(40,0,5));
     179      trackManager->setDuration(.5);
     180      trackManager->setSavePoint();
     181      trackManager->addPoint(Vector(50,10,10));
     182      trackManager->addPoint(Vector(60,0, 10));
     183      trackManager->addPoint(Vector(70,0, 10));
     184      trackManager->addPoint(Vector(80,0,-10));
     185      trackManager->addPoint(Vector(90,0,-10));
     186      trackManager->setDuration(.5);
     187      trackManager->setSavePoint();
     188      trackManager->addPoint(Vector(110,0,5));
     189      trackManager->addPoint(Vector(120,0, 10));
     190      trackManager->addPoint(Vector(130,0, 10));
     191      trackManager->addPoint(Vector(140,0,-10));
     192      trackManager->addPoint(Vector(150,0,-10));
     193      trackManager->setDuration(.5);
     194      int fork11, fork12, fork13, fork14;
     195      trackManager->fork(4, &fork11, &fork12, &fork13, &fork14);
     196      trackManager->workOn(fork11);
     197      trackManager->addPoint(Vector(170, 0, -15));
     198      trackManager->addPoint(Vector(180, 0, -15));
     199      trackManager->workOn(fork12);
     200      trackManager->addPoint(Vector(170, 0, 10));
     201      trackManager->addPoint(Vector(180, 0, 10));
     202      trackManager->addPoint(Vector(190,2,5));
     203      trackManager->addPoint(Vector(200,2,5));
     204      int fork21, fork22;
     205      trackManager->fork(2, &fork21, &fork22);
     206      trackManager->workOn(fork21);
     207      trackManager->addPoint(Vector(220, 10,-10));
     208      trackManager->addPoint(Vector(230, 0,-10));
     209      trackManager->addPoint(Vector(240, 0, 2));
     210      trackManager->addPoint(Vector(250, 0, 0));
     211      trackManager->addPoint(Vector(260, 0, 5));
     212      trackManager->join(2, fork12, fork11);
     213      trackManager->workOn(fork22);
     214      trackManager->addPoint(Vector(220, -10,10));
     215      trackManager->addPoint(Vector(230, 0, 10));
     216      trackManager->addPoint(Vector(240, 0, 10));
     217      trackManager->addPoint(Vector(250, 0, 5));
     218      trackManager->workOn(fork13);
     219      trackManager->addPoint(Vector(200,-10,5));
     220      trackManager->addPoint(Vector(250,-10,5));
     221      printf("fork14: %d\n", fork14);
     222      trackManager->workOn(fork14);
     223      trackManager->addPoint(Vector(200,15,0));
     224      trackManager->addPoint(Vector(210,0,10));
     225
     226
     227
     228      trackManager->join(4, fork21, fork22, fork13, fork14);
     229
     230      /*monitor progress*/
     231      this->glmis->step();
     232
     233      /*
     234      tmpCurve->addNode(Vector(10,0,-10));
     235      //tmpCurve->addNode(Vector(10,2,5));
     236      //tmpCurve->addNode(Vector(10,3,-5));
     237      //      tmpCurve->addNode(Vector(10,1,5));
     238      tmpCurve->addNode(Vector(10,0,5));
     239      */
    115240      switch(this->debugWorldNr)
    116241        {
     
    123248        case DEBUG_WORLD_0:
    124249          {
     250            this->nullParent = NullParent::getInstance ();
     251            this->nullParent->setName ("NullParent");
     252
    125253            // create some path nodes
    126254            this->pathnodes = new Vector[6];
     
    141269            // !\todo old track-system has to be removed
    142270
     271            //create helper for player
     272            HelperParent* hp = new HelperParent ();
     273            /* the player has to be added to this helper */
     274
    143275            // create a player
    144             WorldEntity* myPlayer = new Player();
    145             this->spawn(myPlayer);
    146             this->localPlayer = myPlayer;           
     276            WorldEntity* myPlayer = new Player ();
     277            myPlayer->setName ("player");
     278            this->spawn (myPlayer);
     279            this->localPlayer = myPlayer;
     280
     281            /*monitor progress*/
     282            this->glmis->step();           
    147283
    148284            // bind input
    149             Orxonox *orx = Orxonox::getInstance();
     285            Orxonox *orx = Orxonox::getInstance ();
    150286            orx->getLocalInput()->bind (myPlayer);
    151287           
    152288            // bind camera
    153289            this->localCamera = new Camera(this);
    154             this->getCamera()->bind (myPlayer);
    155 
    156             Placement* plc = new Placement;
    157             plc->r = Vector(100, 10, 10);
    158             plc->w = Quaternion();
     290            this->localCamera->setName ("camera");
     291            this->getCamera()->bind (myPlayer);
     292            this->localPlayer->addChild (this->localCamera);
     293
     294            /*monitor progress*/
     295            this->glmis->step();
     296
     297            Vector* es = new Vector (50, 2, 0);
     298            Quaternion* qs = new Quaternion ();
    159299            WorldEntity* env = new Environment();
    160             this->spawn(env, plc);
     300            env->setName ("env");
     301            this->spawn(env, es, qs);
     302           
     303            /*monitor progress*/
     304            this->glmis->step();
    161305
    162306            break;
     
    164308        case DEBUG_WORLD_1:
    165309          {
     310            /*
     311            this->testCurve = new UPointCurve();
     312            this->testCurve->addNode(Vector( 0, 0, 0));
     313            this->testCurve->addNode(Vector(10, 0, 5));
     314            this->testCurve->addNode(Vector(20, -5,-5));
     315            this->testCurve->addNode(Vector(30, 5, 10));
     316            this->testCurve->addNode(Vector(40, 0,-10));
     317            this->testCurve->addNode(Vector(50, 0,-10));
     318            */
     319
     320            this->nullParent = NullParent::getInstance ();
     321            this->nullParent->setName ("NullParent");
     322
    166323            // create some path nodes
    167324            this->pathnodes = new Vector[6];
     
    173330            this->pathnodes[5] = Vector(30, 50, 0);
    174331           
     332
     333
     334
    175335            // create the tracks
    176336            this->tracklen = 6;
     
    183343            // create a player
    184344            WorldEntity* myPlayer = new Player();
     345            myPlayer->setName ("player");
    185346            this->spawn(myPlayer);
    186347            this->localPlayer = myPlayer;           
     
    191352           
    192353            // bind camera
    193             this->localCamera = new Camera(this);
     354            this->localCamera = new Camera (this);
     355            this->localCamera->setName ("camera");
    194356            this->getCamera()->bind (myPlayer);
     357            this->localPlayer->addChild (this->localCamera);
    195358            break;
    196359          }
     
    212375
    213376  int sizeX = 100;
    214   int sizeY = 80;
     377  int sizeZ = 80;
    215378  float length = 1000;
    216379  float width = 200;
    217380  float widthX = float (length /sizeX);
    218   float widthY = float (width /sizeY);
    219  
    220   float height [sizeX][sizeY];
    221   Vector normal_vectors[sizeX][sizeY];
     381  float widthZ = float (width /sizeZ);
     382 
     383  float height [sizeX][sizeZ];
     384  Vector normal_vectors[sizeX][sizeZ];
    222385 
    223386 
    224387  for ( int i = 0; i<sizeX-1; i+=1)
    225     for (int j = 0; j<sizeY-1;j+=1)
     388    for (int j = 0; j<sizeZ-1;j+=1)
    226389      //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    227390#ifdef __WIN32__
     
    231394#endif
    232395
    233   //Die Hügel ein wenig glätten
     396  //Die Huegel ein wenig glaetten
    234397  for (int h=1; h<2;h++)
    235398    for (int i=1;i<sizeX-2 ;i+=1 )
    236       for(int j=1;j<sizeY-2;j+=1)
     399      for(int j=1;j<sizeZ-2;j+=1)
    237400        height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
    238401 
    239402  //Berechnung von normalen Vektoren
    240 
    241403  for(int i=1;i<sizeX-2;i+=1)
    242     for(int j=1;j<sizeY-2 ;j+=1)
     404    for(int j=1;j<sizeZ-2 ;j+=1)
    243405      {
    244         Vector v1 = Vector (widthX*(1),      widthY*(j)  ,      height[i][j]);
    245         Vector v2 = Vector (widthX*(i-1),    widthY*(j)  ,      height[i-1][j]);
    246         Vector v3 = Vector (widthX*(i),      widthY*(j+1),      height[i][j+1]);
    247         Vector v4 = Vector (widthX*(i+1),    widthY*(j),        height[i+1][j]);
    248         Vector v5 = Vector (widthX*(i),      widthY*(j-1),      height[i][j-1]);
     406        Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
     407        Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
     408        Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
     409        Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
     410        Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
    249411       
    250412        Vector c1 = v2 - v1;
     
    253415        Vector c4 = v5 - v1;
    254416        Vector zero = Vector (0,0,0);
    255         normal_vectors[i][j]=c1.cross(v4-v2)+c2.cross(v1-v3)+c3.cross(v2-v4)+c4.cross(v3-v1);
     417        normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
    256418        normal_vectors[i][j].normalize();
    257419      }
     
    259421  int snowheight=3;
    260422  for ( int i = 0; i<sizeX; i+=1)
    261     for (int j = 0; j<sizeY;j+=1)
     423    for (int j = 0; j<sizeZ;j+=1)
    262424      {   
    263         Vector v1 = Vector (widthX*(i),      widthY*(j)  -width/2,      height[i][j]-20 );
    264         Vector v2 = Vector (widthX*(i+1),    widthY*(j)  -width/2,      height[i+1][j]-20);
    265         Vector v3 = Vector (widthX*(i+1),    widthY*(j+1)-width/2,    height[i+1][j+1]-20);
    266         Vector v4 = Vector (widthX*(i),      widthY*(j+1)-width/2,    height[i][j+1]-20);
     425        Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
     426        Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
     427        Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
     428        Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
    267429        float a[3];
    268430        if(height[i][j]<snowheight){
     
    371533  //draw track
    372534  glBegin(GL_LINES);
    373   glColor3f(0,1,1);
     535  glColor3f(0.0, 1.0, 1.0);
    374536  for( int i = 0; i < tracklen; i++)
    375537    {
     
    378540    }
    379541  glEnd();
     542 
     543  /*
     544  glBegin(GL_LINE_STRIP);
     545  glColor3f(1.0, 5.0, 1.0);
     546  for( int i = 0; i <= 30; i++)
     547    {
     548      glEvalCoord1f ((GLfloat) i/30.0);
     549    }
     550  glEnd();
     551  */
     552
     553  trackManager->drawGraph(.01);
     554  trackManager->debug(2);
     555  delete trackManager;
     556 
     557  /*
     558  glBegin(GL_LINES);
     559  float i;
     560  for(i = 0.0; i<1; i+=.01)
     561    {
     562      printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
     563      glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
     564    }
     565  glEnd();
     566  */
    380567  glEndList();
    381568}
     
    430617void World::draw ()
    431618{
    432   // draw geometry
    433  
    434619  // draw entities
    435620  WorldEntity* entity;
    436  
    437621  entity = this->entities->enumerate();
    438622  while( entity != NULL )
     
    440624      if( entity->bDraw ) entity->draw();
    441625      entity = this->entities->nextElement();
    442     }
    443  
    444  
     626    }
     627 
     628  //glmis = new GLMenuImageScreen();
     629  ///glmis->init();
     630
    445631  // draw debug coord system
    446632  glCallList (objectList);
    447 
    448633
    449634}
     
    459644void World::update ()
    460645{
     646  /*
    461647  //List<WorldEntity> *l;
    462648  WorldEntity* entity;
     
    477663          t = loc->part;
    478664         
    479           /* check if entity has still a legal track-id */
    480665          if( t >= tracklen )
    481666            {
     
    500685      else
    501686        {
    502           /* \todo: implement check whether this particular free entity
    503              is out of the game area
    504              \todo: call function to notify the entity that it left
    505              the game area
    506           */
    507687        }
    508688     
    509689      entity = entities->nextElement();
    510690    }
    511  
     691  */ 
    512692}
    513693
     
    522702  float seconds = deltaT / 1000.0;
    523703 
     704  this->nullParent->update (seconds);
     705  //this->nullParent->processTick (seconds);
     706
    524707  entity = entities->enumerate();
    525708  while( entity != NULL)
     
    542725
    543726
    544 
    545 /**
    546    \brief calls the correct mapping function to convert a given "look at"-Location to a
    547    Camera Placement
    548 */
    549 void World::calcCameraPos (Location* loc, Placement* plc)
    550 {
    551   track[loc->part].mapCamera (loc, plc);
    552 }
    553 
    554 
    555727void World::setTrackLen(Uint32 len)
    556728{
     
    571743void World::debug()
    572744{
    573   //List<WorldEntity> *l;
     745  printf ("World::debug() - starting debug\n");
     746  PNode* p1 = NullParent::getInstance ();
     747  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
     748  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
     749  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
     750
     751  p1->debug ();
     752  p2->debug ();
     753  p3->debug ();
     754  p4->debug ();
     755
     756  p1->shiftCoor (new Vector(-1, -1, -1));
     757
     758  printf("World::debug() - shift\n");
     759  p1->debug ();
     760  p2->debug ();
     761  p3->debug ();
     762  p4->debug ();
     763 
     764  p1->update (1);
     765
     766  printf ("World::debug() - update\n");
     767  p1->debug ();
     768  p2->debug ();
     769  p3->debug ();
     770  p4->debug ();
     771
     772  p2->shiftCoor (new Vector(-1, -1, -1));
     773  p1->update (2);
     774
     775  p1->debug ();
     776  p2->debug ();
     777  p3->debug ();
     778  p4->debug ();
     779
     780  p2->setAbsCoor (new Vector(1,2,3));
     781
     782
     783 p1->update (2);
     784
     785  p1->debug ();
     786  p2->debug ();
     787  p3->debug ();
     788  p4->debug ();
     789
     790  p1->destroy ();
     791 
     792 
     793  /*
    574794  WorldEntity* entity;
    575  
    576795  printf("counting all entities\n");
    577796  printf("World::debug() - enumerate()\n");
     
    582801      entity = entities->nextElement();
    583802    }
     803  */
    584804}
    585805
     
    594814void World::mainLoop()
    595815{
    596   this->lastFrame = SDL_GetTicks();
     816  this->lastFrame = SDL_GetTicks ();
    597817  printf("World::mainLoop() - Entering main loop\n");
    598818  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
    599819    {
    600820      // Network
    601       synchronize();
     821      this->synchronize ();
    602822      // Process input
    603       handleInput();
     823      this->handleInput ();
    604824      if( this->bQuitCurrentGame || this->bQuitOrxonox)
    605825        {
     
    608828        }
    609829      // Process time
    610       timeSlice();
     830      this->timeSlice ();
    611831      // Process collision
    612       collision();
     832      this->collision ();
    613833      // Draw
    614       display();
    615  
    616       for(int i = 0; i < 10000000; i++) {}
     834      this->display ();
     835 
     836      for( int i = 0; i < 5000000; i++) {}
     837      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
    617838    }
    618839  printf("World::mainLoop() - Exiting the main loop\n");
     
    701922  this->draw();
    702923  // draw HUD
     924  /* \todo draw HUD */
    703925  // flip buffers
    704926  SDL_GL_SwapBuffers();
     927  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
     928  //SDL_Flip (screen);
    705929}
    706930
     
    723947void World::spawn(WorldEntity* entity)
    724948{
    725   Location zeroloc;
    726   Location* loc = NULL;
    727   WorldEntity* owner;
    728 
    729   entities->add (entity);
    730   zeroloc.dist = 0;
    731   zeroloc.part = 0;
    732   zeroloc.pos = Vector();
    733   zeroloc.rot = Quaternion();
    734   loc = &zeroloc;
    735   entity->init (loc, owner);
    736   if (entity->bFree)
    737     {
    738       this->track[loc->part].mapCoords( loc, entity->getPlacement());
    739     }
     949  if( this->nullParent != NULL && entity->parent == NULL)
     950    this->nullParent->addChild (entity);
     951
     952  this->entities->add (entity);
     953
    740954  entity->postSpawn ();
    741955}
     
    747961   \param location where to add
    748962*/
    749 void World::spawn(WorldEntity* entity, Location* loc)
    750 {
    751   Location zeroLoc;
    752   WorldEntity* owner;
     963void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
     964{
     965  entity->setAbsCoor (absCoor);
     966  entity->setAbsDir (absDir);
     967 
     968  if( this->nullParent != NULL && entity->parent == NULL)
     969    this->nullParent->addChild (entity);
     970
    753971  this->entities->add (entity);
    754   if( loc == NULL)
    755     {
    756       zeroLoc.dist = 0;
    757       zeroLoc.part = 0;
    758       zeroLoc.pos = Vector();
    759       zeroLoc.rot = Quaternion();
    760       loc = &zeroLoc;
    761     }
    762   entity->init (loc, owner);
    763   if (entity->bFree)
    764     {
    765       this->track[loc->part].mapCoords( loc, entity->getPlacement());
    766     }
     972
    767973  entity->postSpawn ();
    768   //return entity;
    769 }
    770 
    771 
    772 /**
    773    \brief add and spawn a new entity to this world
    774    \param entity to be added
    775    \param place where to be added
    776 */
    777 void World::spawn(WorldEntity* entity, Placement* plc)
    778 {
    779   Placement zeroPlc;
    780   WorldEntity* owner;
    781   if( plc == NULL)
    782     {
    783       zeroPlc.r = Vector();
    784       zeroPlc.w = Quaternion();
    785       plc = &zeroPlc;
    786     }
    787   this->entities->add (entity);
    788   entity->init (plc, owner);
    789   entity->postSpawn ();
    790   //return entity;
    791 }
     974}
     975
    792976
    793977
     
    800984  return false;
    801985}
     986
     987
     988
     989
     990void World::swap (unsigned char &a, unsigned char &b)
     991{
     992  unsigned char temp;
     993  temp = a;
     994  a    = b;
     995  b    = temp;
     996}
Note: See TracChangeset for help on using the changeset viewer.