Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3365 in orxonox.OLD for orxonox/trunk/src/world.cc


Ignore:
Timestamp:
Jan 7, 2005, 1:14:33 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: merged branches/parenting back to the.
merged with command:
svn merge branches/parenting trunk -r 3247:HEAD
resolved all conflicts in favor of parenting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/world.cc

    r3233 r3365  
    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  glmis = new GLMenuImageScreen();
     151  glmis->init();
     152  glmis->draw();
     153 
     154  printf ("World::displayLoadScreen - end\n");
     155}
     156
     157
     158void World::releaseLoadScreen ()
     159{
     160  printf ("World::releaseLoadScreen - start\n");
     161
     162  printf ("World::releaseLoadScreen - end\n");
     163}
     164
    110165
    111166void World::load()
    112167{
     168  //  BezierCurve* tmpCurve = new BezierCurve();
    113169  if(this->debugWorldNr != -1)
    114170    {
     171      trackManager = TrackManager::getInstance();
     172      trackManager->addPoint(Vector(0,-5,0));
     173      trackManager->addPoint(Vector(10,0,5));
     174      trackManager->addPoint(Vector(20,0,-5));
     175      trackManager->addPoint(Vector(30,0,5));
     176      trackManager->addPoint(Vector(40,0,5));
     177      trackManager->setDuration(.5);
     178      trackManager->setSavePoint();
     179      trackManager->addPoint(Vector(50,10,10));
     180      trackManager->addPoint(Vector(60,0, 10));
     181      trackManager->addPoint(Vector(70,0, 10));
     182      trackManager->addPoint(Vector(80,0,-10));
     183      trackManager->addPoint(Vector(90,0,-10));
     184      trackManager->setDuration(.5);
     185      trackManager->setSavePoint();
     186      trackManager->addPoint(Vector(110,0,5));
     187      trackManager->addPoint(Vector(120,0, 10));
     188      trackManager->addPoint(Vector(130,0, 10));
     189      trackManager->addPoint(Vector(140,0,-10));
     190      trackManager->addPoint(Vector(150,0,-10));
     191      trackManager->setDuration(.5);
     192      int fork11, fork12, fork13, fork14;
     193      trackManager->fork(4, &fork11, &fork12, &fork13, &fork14);
     194      trackManager->workOn(fork11);
     195      trackManager->addPoint(Vector(170, 0, -15));
     196      trackManager->addPoint(Vector(180, 0, -15));
     197      trackManager->workOn(fork12);
     198      trackManager->addPoint(Vector(170, 0, 10));
     199      trackManager->addPoint(Vector(180, 0, 10));
     200      trackManager->addPoint(Vector(190,2,5));
     201      trackManager->addPoint(Vector(200,2,5));
     202      int fork21, fork22;
     203      trackManager->fork(2, &fork21, &fork22);
     204      trackManager->workOn(fork21);
     205      trackManager->addPoint(Vector(220, 10,-10));
     206      trackManager->addPoint(Vector(230, 0,-10));
     207      trackManager->addPoint(Vector(240, 0, 2));
     208      trackManager->addPoint(Vector(250, 0, 0));
     209      trackManager->addPoint(Vector(260, 0, 5));
     210      trackManager->join(2, fork12, fork11);
     211      trackManager->workOn(fork22);
     212      trackManager->addPoint(Vector(220, -10,10));
     213      trackManager->addPoint(Vector(230, 0, 10));
     214      trackManager->addPoint(Vector(240, 0, 10));
     215      trackManager->addPoint(Vector(250, 0, 5));
     216      trackManager->workOn(fork13);
     217      trackManager->addPoint(Vector(200,-10,5));
     218      trackManager->addPoint(Vector(250,-10,5));
     219      printf("fork14: %d\n", fork14);
     220      trackManager->workOn(fork14);
     221      trackManager->addPoint(Vector(200,15,0));
     222      trackManager->addPoint(Vector(210,0,10));
     223
     224
     225
     226      trackManager->join(4, fork21, fork22, fork13, fork14);
     227
     228      /*
     229      tmpCurve->addNode(Vector(10,0,-10));
     230      //tmpCurve->addNode(Vector(10,2,5));
     231      //tmpCurve->addNode(Vector(10,3,-5));
     232      //      tmpCurve->addNode(Vector(10,1,5));
     233      tmpCurve->addNode(Vector(10,0,5));
     234      */
    115235      switch(this->debugWorldNr)
    116236        {
     
    123243        case DEBUG_WORLD_0:
    124244          {
     245            this->nullParent = NullParent::getInstance ();
     246            this->nullParent->setName ("NullParent");
     247
    125248            // create some path nodes
    126249            this->pathnodes = new Vector[6];
     
    141264            // !\todo old track-system has to be removed
    142265
     266            //create helper for player
     267            HelperParent* hp = new HelperParent ();
     268            /* the player has to be added to this helper */
     269
    143270            // create a player
    144             WorldEntity* myPlayer = new Player();
    145             this->spawn(myPlayer);
     271            WorldEntity* myPlayer = new Player ();
     272            myPlayer->setName ("player");
     273            this->spawn (myPlayer);
    146274            this->localPlayer = myPlayer;           
    147275
    148276            // bind input
    149             Orxonox *orx = Orxonox::getInstance();
     277            Orxonox *orx = Orxonox::getInstance ();
    150278            orx->getLocalInput()->bind (myPlayer);
    151279           
    152280            // bind camera
    153281            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();
     282            this->localCamera->setName ("camera");
     283            this->getCamera()->bind (myPlayer);
     284            this->localPlayer->addChild (this->localCamera);
     285           
     286
     287            Vector* es = new Vector (50, 2, 0);
     288            Quaternion* qs = new Quaternion ();
    159289            WorldEntity* env = new Environment();
    160             this->spawn(env, plc);
     290            env->setName ("env");
     291            this->spawn(env, es, qs);
     292
    161293
    162294            break;
     
    164296        case DEBUG_WORLD_1:
    165297          {
     298            /*
     299            this->testCurve = new UPointCurve();
     300            this->testCurve->addNode(Vector( 0, 0, 0));
     301            this->testCurve->addNode(Vector(10, 0, 5));
     302            this->testCurve->addNode(Vector(20, -5,-5));
     303            this->testCurve->addNode(Vector(30, 5, 10));
     304            this->testCurve->addNode(Vector(40, 0,-10));
     305            this->testCurve->addNode(Vector(50, 0,-10));
     306            */
     307
     308            this->nullParent = NullParent::getInstance ();
     309            this->nullParent->setName ("NullParent");
     310
    166311            // create some path nodes
    167312            this->pathnodes = new Vector[6];
     
    173318            this->pathnodes[5] = Vector(30, 50, 0);
    174319           
     320
     321
     322
    175323            // create the tracks
    176324            this->tracklen = 6;
     
    183331            // create a player
    184332            WorldEntity* myPlayer = new Player();
     333            myPlayer->setName ("player");
    185334            this->spawn(myPlayer);
    186335            this->localPlayer = myPlayer;           
     
    191340           
    192341            // bind camera
    193             this->localCamera = new Camera(this);
     342            this->localCamera = new Camera (this);
     343            this->localCamera->setName ("camera");
    194344            this->getCamera()->bind (myPlayer);
     345            this->localPlayer->addChild (this->localCamera);
    195346            break;
    196347          }
     
    212363
    213364  int sizeX = 100;
    214   int sizeY = 80;
     365  int sizeZ = 80;
    215366  float length = 1000;
    216367  float width = 200;
    217368  float widthX = float (length /sizeX);
    218   float widthY = float (width /sizeY);
    219  
    220   float height [sizeX][sizeY];
    221   Vector normal_vectors[sizeX][sizeY];
     369  float widthZ = float (width /sizeZ);
     370 
     371  float height [sizeX][sizeZ];
     372  Vector normal_vectors[sizeX][sizeZ];
    222373 
    223374 
    224375  for ( int i = 0; i<sizeX-1; i+=1)
    225     for (int j = 0; j<sizeY-1;j+=1)
     376    for (int j = 0; j<sizeZ-1;j+=1)
    226377      //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
    227378#ifdef __WIN32__
     
    231382#endif
    232383
    233   //Die Hügel ein wenig glätten
     384  //Die Huegel ein wenig glaetten
    234385  for (int h=1; h<2;h++)
    235386    for (int i=1;i<sizeX-2 ;i+=1 )
    236       for(int j=1;j<sizeY-2;j+=1)
     387      for(int j=1;j<sizeZ-2;j+=1)
    237388        height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
    238389 
    239390  //Berechnung von normalen Vektoren
    240 
    241391  for(int i=1;i<sizeX-2;i+=1)
    242     for(int j=1;j<sizeY-2 ;j+=1)
     392    for(int j=1;j<sizeZ-2 ;j+=1)
    243393      {
    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]);
     394        Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
     395        Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
     396        Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
     397        Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
     398        Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
    249399       
    250400        Vector c1 = v2 - v1;
     
    253403        Vector c4 = v5 - v1;
    254404        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);
     405        normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
    256406        normal_vectors[i][j].normalize();
    257407      }
     
    259409  int snowheight=3;
    260410  for ( int i = 0; i<sizeX; i+=1)
    261     for (int j = 0; j<sizeY;j+=1)
     411    for (int j = 0; j<sizeZ;j+=1)
    262412      {   
    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);
     413        Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
     414        Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
     415        Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
     416        Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
    267417        float a[3];
    268418        if(height[i][j]<snowheight){
     
    371521  //draw track
    372522  glBegin(GL_LINES);
    373   glColor3f(0,1,1);
     523  glColor3f(0.0, 1.0, 1.0);
    374524  for( int i = 0; i < tracklen; i++)
    375525    {
     
    378528    }
    379529  glEnd();
     530 
     531  /*
     532  glBegin(GL_LINE_STRIP);
     533  glColor3f(1.0, 5.0, 1.0);
     534  for( int i = 0; i <= 30; i++)
     535    {
     536      glEvalCoord1f ((GLfloat) i/30.0);
     537    }
     538  glEnd();
     539  */
     540
     541  trackManager->drawGraph(.01);
     542  trackManager->debug(2);
     543  delete trackManager;
     544 
     545  /*
     546  glBegin(GL_LINES);
     547  float i;
     548  for(i = 0.0; i<1; i+=.01)
     549    {
     550      printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
     551      glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
     552    }
     553  glEnd();
     554  */
    380555  glEndList();
    381556}
     
    430605void World::draw ()
    431606{
    432   // draw geometry
    433  
    434607  // draw entities
    435608  WorldEntity* entity;
    436  
    437609  entity = this->entities->enumerate();
    438610  while( entity != NULL )
     
    440612      if( entity->bDraw ) entity->draw();
    441613      entity = this->entities->nextElement();
    442     }
    443  
    444  
     614    }
     615 
     616  //glmis = new GLMenuImageScreen();
     617  ///glmis->init();
     618
    445619  // draw debug coord system
    446620  glCallList (objectList);
    447 
    448621
    449622}
     
    459632void World::update ()
    460633{
     634  /*
    461635  //List<WorldEntity> *l;
    462636  WorldEntity* entity;
     
    477651          t = loc->part;
    478652         
    479           /* check if entity has still a legal track-id */
    480653          if( t >= tracklen )
    481654            {
     
    500673      else
    501674        {
    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           */
    507675        }
    508676     
    509677      entity = entities->nextElement();
    510678    }
    511  
     679  */ 
    512680}
    513681
     
    522690  float seconds = deltaT / 1000.0;
    523691 
     692  this->nullParent->update (seconds);
     693  //this->nullParent->processTick (seconds);
     694
    524695  entity = entities->enumerate();
    525696  while( entity != NULL)
     
    542713
    543714
    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 
    555715void World::setTrackLen(Uint32 len)
    556716{
     
    571731void World::debug()
    572732{
    573   //List<WorldEntity> *l;
     733  printf ("World::debug() - starting debug\n");
     734  PNode* p1 = NullParent::getInstance ();
     735  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
     736  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
     737  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
     738
     739  p1->debug ();
     740  p2->debug ();
     741  p3->debug ();
     742  p4->debug ();
     743
     744  p1->shiftCoor (new Vector(-1, -1, -1));
     745
     746  printf("World::debug() - shift\n");
     747  p1->debug ();
     748  p2->debug ();
     749  p3->debug ();
     750  p4->debug ();
     751 
     752  p1->update (1);
     753
     754  printf ("World::debug() - update\n");
     755  p1->debug ();
     756  p2->debug ();
     757  p3->debug ();
     758  p4->debug ();
     759
     760  p2->shiftCoor (new Vector(-1, -1, -1));
     761  p1->update (2);
     762
     763  p1->debug ();
     764  p2->debug ();
     765  p3->debug ();
     766  p4->debug ();
     767
     768  p2->setAbsCoor (new Vector(1,2,3));
     769
     770
     771 p1->update (2);
     772
     773  p1->debug ();
     774  p2->debug ();
     775  p3->debug ();
     776  p4->debug ();
     777
     778  p1->destroy ();
     779 
     780 
     781  /*
    574782  WorldEntity* entity;
    575  
    576783  printf("counting all entities\n");
    577784  printf("World::debug() - enumerate()\n");
     
    582789      entity = entities->nextElement();
    583790    }
     791  */
    584792}
    585793
     
    594802void World::mainLoop()
    595803{
    596   this->lastFrame = SDL_GetTicks();
     804  this->lastFrame = SDL_GetTicks ();
    597805  printf("World::mainLoop() - Entering main loop\n");
    598806  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
    599807    {
    600808      // Network
    601       synchronize();
     809      this->synchronize ();
    602810      // Process input
    603       handleInput();
     811      this->handleInput ();
    604812      if( this->bQuitCurrentGame || this->bQuitOrxonox)
    605813        {
     
    608816        }
    609817      // Process time
    610       timeSlice();
     818      this->timeSlice ();
    611819      // Process collision
    612       collision();
     820      this->collision ();
    613821      // Draw
    614       display();
    615  
    616       for(int i = 0; i < 10000000; i++) {}
     822      this->display ();
     823 
     824      for( int i = 0; i < 5000000; i++) {}
     825      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
    617826    }
    618827  printf("World::mainLoop() - Exiting the main loop\n");
     
    701910  this->draw();
    702911  // draw HUD
     912  /* \todo draw HUD */
    703913  // flip buffers
    704914  SDL_GL_SwapBuffers();
     915  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
     916  //SDL_Flip (screen);
    705917}
    706918
     
    723935void World::spawn(WorldEntity* entity)
    724936{
    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     }
     937  if( this->nullParent != NULL && entity->parent == NULL)
     938    this->nullParent->addChild (entity);
     939
     940  this->entities->add (entity);
     941
    740942  entity->postSpawn ();
    741943}
     
    747949   \param location where to add
    748950*/
    749 void World::spawn(WorldEntity* entity, Location* loc)
    750 {
    751   Location zeroLoc;
    752   WorldEntity* owner;
     951void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
     952{
     953  entity->setAbsCoor (absCoor);
     954  entity->setAbsDir (absDir);
     955 
     956  if( this->nullParent != NULL && entity->parent == NULL)
     957    this->nullParent->addChild (entity);
     958
    753959  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     }
     960
    767961  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 }
     962}
     963
    792964
    793965
     
    800972  return false;
    801973}
     974
     975
     976
     977
     978void World::swap (unsigned char &a, unsigned char &b)
     979{
     980  unsigned char temp;
     981  temp = a;
     982  a    = b;
     983  b    = temp;
     984}
Note: See TracChangeset for help on using the changeset viewer.