Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2860 in orxonox.OLD for orxonox/branches/dave/src/world.cc


Ignore:
Timestamp:
Nov 15, 2004, 11:13:21 PM (21 years ago)
Author:
dave
Message:

orxonox/branches/dave: das level hat jetzt form angenommen, stand:nach der Convention vom Samstag….

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/dave/src/world.cc

    r2731 r2860  
    2222#include "command_node.h"
    2323#include "camera.h"
     24#include "environment.h"
    2425
    2526using namespace std;
     
    3536  this->worldName = name;
    3637  this->debugWorldNr = -1;
    37   this->entities = new List<WorldEntity>();
     38  this->entities = new tList<WorldEntity>();
    3839}
    3940
     
    4243  this->debugWorldNr = worldID;
    4344  this->worldName = NULL;
    44   this->entities = new List<WorldEntity>();
     45  this->entities = new tList<WorldEntity>();
    4546}
    4647
     
    7475  this->bQuitCurrentGame = true;
    7576  this->localCamera->setWorld(NULL);
     77  this->entities->clear();
     78  Orxonox::getInstance()->get_localinput()->reset();
    7679  this->~World();
    7780}
     
    98101            this->pathnodes = new Vector[6];
    99102            this->pathnodes[0] = Vector(0, 0, 0);
    100             this->pathnodes[1] = Vector(-100, 40, 0);
    101             this->pathnodes[2] = Vector(-100, 140, 0);
    102             this->pathnodes[3] = Vector(0, 180, 0);
    103             this->pathnodes[4] = Vector(100, 140, 0);
    104             this->pathnodes[5] = Vector(100, 40, 0);
     103            this->pathnodes[1] = Vector(1000, 0, 0);
     104            //      this->pathnodes[2] = Vector(-100, 140, 0);
     105            //      this->pathnodes[3] = Vector(0, 180, 0);
     106            //      this->pathnodes[4] = Vector(100, 140, 0);
     107            //      this->pathnodes[5] = Vector(100, 40, 0);
    105108           
    106109            // create the tracks
    107             this->tracklen = 6;
    108             this->track = new Track[6];
     110            this->tracklen = 2;
     111            this->track = new Track[2];
    109112            for( int i = 0; i < this->tracklen; i++)
    110113              {
     
    113116           
    114117            // create a player
    115             //WorldEntity* myPlayer = (WorldEntity*) this->spawn<Player>();
    116118            WorldEntity* myPlayer = new Player();
    117119            this->spawn(myPlayer);
     
    125127            this->localCamera = new Camera(this);
    126128            this->getCamera()->bind (myPlayer);
     129
     130            Placement* plc = new Placement;
     131            plc->r = Vector(100, 10, 10);
     132            plc->w = Quaternion();
     133            WorldEntity* env = new Environment();
     134            this->spawn(env, plc);
     135
    127136            break;
    128137          }
     
    174183  glNewList (objectList, GL_COMPILE);
    175184  glLoadIdentity();
     185  glColor3f(1.0,0,0);
     186  glBegin(GL_QUADS);
     187  float height [500][50];
     188  Vector normal_vectors[500][50];
     189  float size = 2;
     190    for(int i=0;i<400;i+=1){
     191                for(int j=0;j<50;j+=1){
     192        normal_vectors[i][j].x=0;
     193    normal_vectors[i][j].y=1;
     194        normal_vectors[i][j].z=0;
     195       
     196       
     197       
     198        }
     199        }
     200       
     201       
     202        for ( int i = 0; i<400; i+=1)
     203      {
     204        for (int j = 0; j<50;j+=1)
     205          {
     206            //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
     207            height[i][j]=(sin((float)j/3)*rand()*i/182400)*.2;
     208          }
     209      }
     210         for(int a=0;a<2;a+=1){
     211         for (int i=1;i<399 ;i+=1 ){
     212                 for(int j=1;j<49;j+=1){
     213                         height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
     214
     215                 }
     216         }
     217         }
     218    //Berechnung von normalen Vektoren
     219
     220        for(int i=1;i<399;i+=1){
     221    for(int j=1;j<49 ;j+=1)
     222
     223    {
     224                Vector* v1 = new Vector (size*i,        size*(j-25),      height[i][j]-20 );
     225            Vector* v2 = new Vector (size*(i+1),    size*(j-25),      height[i+1][j]-20);
     226            Vector* v3 = new Vector (size*(i),    size*(j-24),  height[i][j+1]-20);
     227            Vector* v4 = new Vector (size*(i-1),        size*(j-25),  height[i-1][j]-20);
     228                Vector* v5 = new Vector (size*(i), size*(j-26), height[i][j-1]-20);
     229               
     230                Vector c1 = *v1 - *v2;
     231            Vector c2 = *v1 - *v3;
     232            Vector c3= *v1 - *v4;
     233            Vector c4 = *v1 - *v5;
     234            normal_vectors[i][j]=c1.cross(*v1-*v3)+c2.cross(*v1-*v4)+c3.cross(*v1-*v5)+c4.cross(*v1-*v2);
     235                normal_vectors[i][j].normalize();
     236           
     237   
     238       
     239       
     240        }
     241        }
     242        int snowheight=3;
     243        for ( int i = 0; i<400; i+=1)
     244      {
     245        for (int j = 0; j<50;j+=1)
     246          {       
     247            Vector* v1 = new Vector (size*i,        size*(j-25),      height[i][j]-20 );
     248            Vector* v2 = new Vector (size*(i+1),    size*(j-25),      height[i+1][j]-20);
     249            Vector* v3 = new Vector (size*(i+1),    size*(j-24),  height[i+1][j+1]-20);
     250            Vector* v4 = new Vector (size*(i),        size*(j-24),  height[i][j+1]-20);
     251            float a[3];
     252                if(height[i][j]<snowheight){
     253                a[0]=0;
     254                a[1]=1.0-height[i][j]/10-.3;
     255                a[2]=0;
     256                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     257                }
     258                else{
     259                a[0]=1.0;
     260                a[1]=1.0;
     261                a[2]=1.0;
     262                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     263
     264                }
     265                glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
     266            glVertex3f(v1->x, v1->y, v1->z);
     267                if(height[i+1][j]<snowheight){
     268                a[0]=0;
     269                a[1] =1.0-height[i+1][j]/10-.3;
     270                a[2]=0;
     271                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     272            }
     273                else{
     274                a[0]=1.0;
     275                a[1]=1.0;
     276                a[2]=1.0;
     277                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     278               
     279                }
     280                glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
     281            glVertex3f(v2->x, v2->y, v2->z);
     282                if(height[i+1][j+1]<snowheight){
     283                a[0]=0;
     284                a[1] =1.0-height[i+1][j+1]/10-.3;
     285                a[2]=0;
     286                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     287            }
     288                else{
     289                a[0]=1.0;
     290                a[1]=1.0;
     291                a[2]=1.0;
     292                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     293               
     294               
     295                }
     296                glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
     297            glVertex3f(v3->x, v3->y, v3->z);
     298                if(height[i][j+1]<snowheight){
     299                a[0]=0;
     300                a[1] =1.0-height[i+1][j+1]/10-.3;
     301                a[2]=0;
     302                glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     303            }
     304                else{
     305                        a[0]=1.0;
     306                a[1]=1.0;
     307                a[2]=1.0;
     308                        glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
     309                }
     310                glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
     311            glVertex3f(v4->x, v4->y, v4->z);
     312
     313          }
     314      }
     315glEnd();
     316/* 
    176317  glBegin(GL_LINES);
    177  
    178318  for( float x = -128.0; x < 128.0; x += 25.0)
    179319    {
     
    213353     
    214354    }
    215  
     355  */ 
    216356  //draw track
     357  glBegin(GL_LINES);
    217358  glColor3f(0,1,1);
    218359  for( int i = 0; i < tracklen; i++)
     
    235376void World::collide ()
    236377{
    237   List<WorldEntity> *a, *b;
     378  /*
     379  List *a, *b;
    238380  WorldEntity *aobj, *bobj;
    239  
    240   a = entities->get_next();
     381   
     382  a = entities;
    241383 
    242384  while( a != NULL)
    243385    {
    244       aobj = a->get_object();
     386      aobj = a->nextElement();
    245387      if( aobj->bCollide && aobj->collisioncluster != NULL)
    246388        {
    247           b = a->get_next();
     389          b = a->nextElement();
    248390          while( b != NULL )
    249391            {
    250               bobj = b->get_object();
     392              bobj = b->nextElement();
    251393              if( bobj->bCollide && bobj->collisioncluster != NULL )
    252394                {
     
    260402                  }
    261403                }
    262               b = b->get_next();
     404              b = b->nextElement();
    263405            }
    264406        }
    265       a = a->get_next();
    266     }
     407      a = a->enumerate();
     408    }
     409  */
    267410}
    268411
     
    275418 
    276419  // draw entities
    277   List<WorldEntity> *l;
    278420  WorldEntity* entity;
    279421 
    280   l = entities->get_next(); 
    281   while( l != NULL )
     422  entity = this->entities->enumerate();
     423  while( entity != NULL )
    282424    {
    283       entity = l->get_object();
    284425      if( entity->bDraw ) entity->draw();
    285       l = l->get_next();
     426      entity = this->entities->nextElement();
    286427    }
    287428 
     
    303444void World::update ()
    304445{
    305   List<WorldEntity> *l;
     446  //List<WorldEntity> *l;
    306447  WorldEntity* entity;
    307448  Location* loc;
     
    309450  Uint32 t;
    310451 
    311   l = entities->get_next(); 
    312   while( l != NULL )
     452  //  l = entities->enumerate();
     453  entity = this->entities->enumerate();
     454  while( entity != NULL )
    313455    {
    314       entity = l->get_object();
     456
    315457     
    316458      if( !entity->isFree() )
     
    350492        }
    351493     
    352       l = l->get_next();
     494      entity = entities->nextElement();
    353495    }
    354496 
     
    361503void World::time_slice (Uint32 deltaT)
    362504{
    363   List<WorldEntity> *l;
     505  //List<WorldEntity> *l;
    364506  WorldEntity* entity;
    365507  float seconds = deltaT;
     
    367509  seconds /= 1000;
    368510 
    369   l = entities->get_next();
    370   while( l != NULL)
     511  entity = entities->enumerate();
     512  while( entity != NULL)
    371513    {
    372       entity = l->get_object();
    373514      entity->tick (seconds);
    374       l = l->get_next();
    375     }
    376  
     515      entity = entities->nextElement();
     516    }
     517
    377518  for( int i = 0; i < tracklen; i++) track[i].tick (seconds);
    378519}
     
    411552void World::debug()
    412553{
    413   List<WorldEntity> *l;
     554  //List<WorldEntity> *l;
    414555  WorldEntity* entity;
    415556 
    416557  printf("counting all entities\n");
    417   l = entities->get_next(); 
    418   while( l != NULL )
     558  printf("World::debug() - enumerate()\n");
     559  entity = entities->enumerate(); 
     560  while( entity != NULL )
    419561    {
    420       entity = l->get_object();
    421562      if( entity->bDraw ) printf("got an entity\n");
    422       l = l->get_next();
     563      entity = entities->nextElement();
    423564    }
    424565}
     
    445586      // Draw
    446587      display();
     588 
     589      //for(int i = 0; i < 1000000; i++){}
     590
    447591    }
    448592  printf("World|Exiting the main loop\n");
     
    477621    {
    478622      Uint32 dt = currentFrame - this->lastFrame;
    479       /*
     623     
    480624      if(dt > 0)
    481625        {
     
    485629      else
    486630        {
    487           printf("fps = 1000\n");
    488         }
    489       */
     631          printf("fps = 1000 but 0ms!\n");
     632        }
     633     
    490634      this->time_slice (dt);
    491635      this->update ();
     
    545689  Location* loc = NULL;
    546690  WorldEntity* owner;
    547   //T* entity = new T();
    548   entities->add (entity, LIST_ADD_NEXT);
    549   //if( loc == NULL)
    550   //{
    551       zeroloc.dist = 0;
    552       zeroloc.part = 0;
    553       zeroloc.pos = Vector();
    554       zeroloc.rot = Quaternion();
    555       loc = &zeroloc;
    556       //}
     691
     692  entities->add (entity);
     693  zeroloc.dist = 0;
     694  zeroloc.part = 0;
     695  zeroloc.pos = Vector();
     696  zeroloc.rot = Quaternion();
     697  loc = &zeroloc;
    557698  entity->init (loc, owner);
    558699  if (entity->bFree)
     
    561702    }
    562703  entity->post_spawn ();
     704}
     705
     706
     707void World::spawn(WorldEntity* entity, Location* loc)
     708{
     709  Location zeroLoc;
     710  WorldEntity* owner;
     711  this->entities->add (entity);
     712  if( loc == NULL)
     713    {
     714      zeroLoc.dist = 0;
     715      zeroLoc.part = 0;
     716      zeroLoc.pos = Vector();
     717      zeroLoc.rot = Quaternion();
     718      loc = &zeroLoc;
     719    }
     720  entity->init (loc, owner);
     721  if (entity->bFree)
     722    {
     723      this->track[loc->part].map_coords( loc, entity->get_placement());
     724    }
     725  entity->post_spawn ();
    563726  //return entity;
    564727}
     728
     729
     730void World::spawn(WorldEntity* entity, Placement* plc)
     731{
     732  Placement zeroPlc;
     733  WorldEntity* owner;
     734  if( plc == NULL)
     735    {
     736      zeroPlc.r = Vector();
     737      zeroPlc.w = Quaternion();
     738      plc = &zeroPlc;
     739    }
     740  this->entities->add (entity);
     741  entity->init (plc, owner);
     742  entity->post_spawn ();
     743  //return entity;
     744}
Note: See TracChangeset for help on using the changeset viewer.