Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/story_entities/world.cc @ 3548

Last change on this file since 3548 was 3548, checked in by bensch, 19 years ago

orxonox/trunk: debug information in importer set like they should be

File size: 21.0 KB
Line 
1
2/*
3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   ### File Specific:
13   main-programmer: Patrick Boenzli
14   co-programmer: Christian Meyer
15*/
16
17#include "world.h"
18#include "world_entity.h"
19#include "track_manager.h"
20#include "player.h"
21#include "command_node.h"
22#include "camera.h"
23#include "environment.h"
24#include "primitive.h"
25#include "p_node.h"
26#include "null_parent.h"
27#include "helper_parent.h"
28#include "glmenu_imagescreen.h"
29#include "skysphere.h"
30#include "light.h"
31#include "fontset.h"
32#include "track_node.h"
33
34using namespace std;
35
36
37/**
38    \brief create a new World
39   
40    This creates a new empty world!
41*/
42World::World (char* name)
43{
44  this->init(name, -1);
45  NullParent* np = NullParent::getInstance();
46}
47
48/**
49   \brief creates a new World...
50   \param worldID with this ID
51*/
52World::World (int worldID)
53{
54  this->init(NULL, worldID);
55}
56
57/**
58    \brief remove the World from memory
59   
60    delete everything explicitly, that isn't contained in the parenting tree!
61    things contained in the tree are deleted automaticaly
62*/
63World::~World ()
64{
65  PRINTF(3)("World::~World() - deleting current world\n");
66  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
67  cn->unbind(this->localPlayer);
68  cn->reset();
69
70  delete this->localCamera;
71  delete this->nullParent;
72  //delete this->skySphere;
73
74  //delete this->trackManager;
75
76  /*
77  WorldEntity* entity = entities->enumerate(); 
78  while( entity != NULL )
79    {
80      entity->destroy();
81      entity = entities->nextElement();
82    }
83  this->entities->destroy();
84  */
85
86  /* FIX the parent list has to be cleared - not possible if we got the old list also*/
87
88
89  //delete this->entities;
90  //delete this->localCamera;
91  /* this->localPlayer hasn't to be deleted explicitly, it is
92     contained in entities*/
93}
94
95/**
96   \brief initializes a new World
97*/
98void World::init(char* name, int worldID)
99{
100  this->setClassName ("World");
101
102  this->worldName = name;
103  this->debugWorldNr = worldID;
104  this->entities = new tList<WorldEntity>();
105
106  // Enable default GL stuff
107  glEnable(GL_DEPTH_TEST);
108
109}
110
111
112/**
113   \brief loads the World by initializing all resources, and set their default values.
114*/
115ErrorMessage World::load()
116{
117  //  BezierCurve* tmpCurve = new BezierCurve();
118  if(this->debugWorldNr != -1)
119    {
120      // initializing Font
121      testFont = new FontSet();
122      testFont->buildFont("../data/pictures/font.tga");
123
124      // initializing the TrackManager
125      trackManager = TrackManager::getInstance();
126      trackManager->addPoint(Vector(0,-5,0));
127      trackManager->addPoint(Vector(10,0,5));
128      trackManager->addPoint(Vector(20,0,-5));
129      trackManager->addPoint(Vector(30,0,5));
130      trackManager->addPoint(Vector(40,0,5));
131      trackManager->setDuration(4);
132      int fork11, fork12, fork13;
133      trackManager->fork(3, &fork11, &fork12, &fork13);
134      trackManager->workOn(fork11);
135      trackManager->addPoint(Vector(70, 0, -10));
136      trackManager->addPoint(Vector(100, 0, -15));
137      trackManager->addPoint(Vector(300, 0, -15));
138      trackManager->setDuration(10);
139      trackManager->workOn(fork12);
140      trackManager->addPoint(Vector(70,  0, 0));
141      trackManager->addPoint(Vector(100, 0, 0));
142      trackManager->addPoint(Vector(120,10, 0));
143      trackManager->addPoint(Vector(150,10, 0));
144      trackManager->addPoint(Vector(180,15, 0));
145      trackManager->addPoint(Vector(200,10, 0));
146      trackManager->setDuration(7);
147      trackManager->workOn(fork13);
148      trackManager->addPoint(Vector(70,  0, 10));
149      trackManager->addPoint(Vector(100, 0, 30));
150      trackManager->addPoint(Vector(120,-10, 30));
151      trackManager->addPoint(Vector(150,-10, 30));
152      trackManager->setDuration(10);
153      trackManager->join(2, fork12, fork13);
154
155      trackManager->workOn(5);
156      trackManager->addPoint(Vector(250, 20, 10));
157      trackManager->addPoint(Vector(290, 20, 10));
158      trackManager->setDuration(5);
159      trackManager->setSavePoint();
160      trackManager->addPoint(Vector(350, 20, 10));
161      trackManager->addPoint(Vector(360, 20, 10));
162      trackManager->addPoint(Vector(370, 20, 10));
163      trackManager->setDuration(5);
164
165      trackManager->join(2, 6, fork11);
166
167      trackManager->finalize();
168
169     
170      /*monitor progress*/
171      this->glmis->step();
172
173      /*
174        tmpCurve->addNode(Vector(10,  -1,  -1));
175        tmpCurve->addNode(Vector(10,  -2,   2));
176        tmpCurve->addNode(Vector(10,   3,   3));
177        tmpCurve->addNode(Vector(10,   4,  -4), 0);
178        tmpCurve->addNode(Vector(10,  -1,  -1));
179        tmpCurve->addNode(Vector(10,  -2,   2));
180        tmpCurve->addNode(Vector(10,   3,   3));
181        tmpCurve->addNode(Vector(10,   4,  -4), 0);
182        tmpCurve->debug();
183      */
184      switch(this->debugWorldNr)
185        {
186          /*
187            this loads the hard-coded debug world. this only for simplicity and will be
188            removed by a reald world-loader, which interprets a world-file.
189            if you want to add an own debug world, just add a case DEBUG_WORLD_[nr] and
190            make whatever you want...
191           */
192        case DEBUG_WORLD_0:
193          {
194            this->nullParent = NullParent::getInstance ();
195            this->nullParent->setName ("NullParent");
196
197            // !\todo old track-system has to be removed
198
199            //create helper for player
200            HelperParent* hp = new HelperParent ();
201            /* the player has to be added to this helper */
202
203            // create a player
204            WorldEntity* myPlayer = new Player ();
205            myPlayer->setName ("player");
206            this->spawn (myPlayer);
207            this->localPlayer = myPlayer;
208            /*monitor progress*/
209            this->glmis->step();           
210
211            // bind input
212            Orxonox *orx = Orxonox::getInstance ();
213            orx->getLocalInput()->bind (myPlayer);
214           
215            // bind camera
216            this->localCamera = new Camera(this);
217            this->localCamera->setName ("camera");
218            this->localCamera->bind (myPlayer);
219            /*monitor progress*/
220            this->glmis->step();           
221
222            // Create SkySphere
223            this->skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
224            this->skySphere->setName("SkySphere");
225            this->localCamera->addChild(this->skySphere);
226            this->skySphere->setMode(MOVEMENT);
227
228            /*monitor progress*/
229            this->glmis->step();
230
231           
232            WorldEntity* env = new Environment();
233            env->setName ("env");
234            this->spawn(env);
235
236            /*
237            Vector* es = new Vector (50, 2, 0);
238            Quaternion* qs = new Quaternion ();
239            WorldEntity* pr = new Primitive(PSPHERE);
240            pr->setName("primitive");
241            this->spawn(pr, this->localPlayer, es, qs, ROTATION);
242            */
243
244
245            /*monitor progress*/
246            this->glmis->step();
247
248            //      trackManager->setBindSlave(env);
249            TrackNode* tn = TrackNode::getInstance();
250            tn->addChild(myPlayer);
251
252            //localCamera->setParent(TrackNode::getInstance());
253            TrackNode::getInstance()->addChild (this->localCamera);
254            //Vector* cameraOffset = new Vector (0, 5, -10);
255            Vector* cameraOffset = new Vector (-10, 5, 0);
256            this->localCamera->setRelCoor (cameraOffset);
257            trackManager->condition(1, NEAREST, myPlayer);
258
259            break;
260          }
261        case DEBUG_WORLD_1:
262          {
263            this->nullParent = NullParent::getInstance ();
264            this->nullParent->setName ("NullParent");
265
266            // create a player
267            WorldEntity* myPlayer = new Player();
268            myPlayer->setName ("player");
269            this->spawn(myPlayer);
270            this->localPlayer = myPlayer;           
271           
272            // bind input
273            Orxonox *orx = Orxonox::getInstance();
274            orx->getLocalInput()->bind (myPlayer);
275           
276            // bind camera
277            this->localCamera = new Camera (this);
278            this->localCamera->setName ("camera");
279            this->localCamera->bind (myPlayer); 
280            this->localPlayer->addChild (this->localCamera);
281
282            // Create SkySphere
283            skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
284            this->localPlayer->addChild(this->skySphere);
285
286            break;
287
288
289          }
290        default:
291          printf("World::load() - no world with ID %i found", this->debugWorldNr );
292        }
293    }
294  else if(this->worldName != NULL)
295    {
296
297    }
298
299  // initialize debug coord system
300  objectList = glGenLists(1);
301  glNewList (objectList, GL_COMPILE);
302
303  glColor3f(1.0,0,0);
304
305  int sizeX = 100;
306  int sizeZ = 80;
307  float length = 1000;
308  float width = 200;
309  float widthX = float (length /sizeX);
310  float widthZ = float (width /sizeZ);
311 
312  float height [sizeX][sizeZ];
313  Vector normal_vectors[sizeX][sizeZ];
314 
315 
316  for ( int i = 0; i<sizeX-1; i+=1)
317    for (int j = 0; j<sizeZ-1;j+=1)
318      //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
319#ifdef __WIN32__
320      height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
321#else
322      height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
323#endif
324
325  //Die Huegel ein wenig glaetten
326  for (int h=1; h<2;h++)
327    for (int i=1;i<sizeX-2 ;i+=1 )
328      for(int j=1;j<sizeZ-2;j+=1)
329        height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
330 
331  //Berechnung von normalen Vektoren
332  for(int i=1;i<sizeX-2;i+=1)
333    for(int j=1;j<sizeZ-2 ;j+=1)
334      {
335        Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
336        Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
337        Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
338        Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
339        Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
340       
341        Vector c1 = v2 - v1;
342        Vector c2 = v3 - v1;
343        Vector c3=  v4 - v1;
344        Vector c4 = v5 - v1;
345        Vector zero = Vector (0,0,0);
346        normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
347        normal_vectors[i][j].normalize();
348      }
349
350  glBegin(GL_QUADS);
351  int snowheight=3;
352  for ( int i = 0; i<sizeX; i+=1)
353    for (int j = 0; j<sizeZ;j+=1)
354      {   
355        Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
356        Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
357        Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
358        Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
359        float a[3];
360        if(height[i][j]<snowheight){
361          a[0]=0;
362          a[1]=1.0-height[i][j]/10-.3;
363          a[2]=0;
364          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
365        }
366        else{
367            a[0]=1.0;
368            a[1]=1.0;
369            a[2]=1.0;
370            glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
371           
372        }
373        glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
374        glVertex3f(v1.x, v1.y, v1.z);
375        if(height[i+1][j]<snowheight){
376          a[0]=0;
377          a[1] =1.0-height[i+1][j]/10-.3;
378          a[2]=0;
379          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
380        }
381        else{
382          a[0]=1.0;
383          a[1]=1.0;
384          a[2]=1.0;
385          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
386         
387        }
388        glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
389        glVertex3f(v2.x, v2.y, v2.z);
390        if(height[i+1][j+1]<snowheight){
391          a[0]=0;
392          a[1] =1.0-height[i+1][j+1]/10-.3;
393          a[2]=0;
394          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
395        }
396        else{
397          a[0]=1.0;
398          a[1]=1.0;
399          a[2]=1.0;
400          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
401         
402         
403        }
404        glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
405        glVertex3f(v3.x, v3.y, v3.z);
406        if(height[i][j+1]<snowheight){
407          a[0]=0;
408          a[1] =1.0-height[i+1][j+1]/10-.3;
409          a[2]=0;
410          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
411        }
412        else{
413          a[0]=1.0;
414          a[1]=1.0;
415          a[2]=1.0;
416          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
417        }
418        glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
419        glVertex3f(v4.x, v4.y, v4.z);
420       
421      }
422  glEnd();
423
424  trackManager->drawGraph(.01);
425  trackManager->debug(2);
426  glEndList();
427
428
429  // LIGHT initialisation
430  light = Light::getInstance();
431  light->addLight(0);
432  light->setAttenuation(QUADRATIC, 1.0);
433  light->setAttenuation(CONSTANT, 2.0);
434  light->setAttenuation(QUADRATIC, 1.0);
435  light->setPosition(10.0, 10.0, 50.0);
436  light->setDiffuseColor(1,1,1);
437  //  light->addLight(1);
438  //  light->setPosition(20, 10, -20);
439  //  light->setDiffuseColor(0,0,0);
440  light->debug();
441
442
443}
444
445/**
446   \brief initializes a new World
447*/
448ErrorMessage World::init()
449{
450  this->bPause = false;
451  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
452  cn->addToWorld(this);
453  cn->enable(true);
454
455  //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
456  //glEnable (GL_MAP1_VERTEX_3);
457 
458  //theNurb = gluNewNurbsRenderer ();
459  //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR);
460  //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback );
461
462}
463
464
465/**
466   \brief starts the World
467*/
468ErrorMessage World::start()
469{
470  PRINTF(3)("World::start() - starting current World: nr %i\n", this->debugWorldNr);
471  this->bQuitOrxonox = false;
472  this->bQuitCurrentGame = false;
473  this->mainLoop();
474}
475
476/**
477   \brief stops the world.
478
479   This happens, when the player decides to end the Level.
480*/
481ErrorMessage World::stop()
482{
483  PRINTF(3)("World::stop() - got stop signal\n");
484  this->bQuitCurrentGame = true;
485}
486
487/**
488   \brief pauses the Game
489*/
490ErrorMessage World::pause()
491{
492  this->isPaused = true;
493}
494
495/**
496   \brief ends the pause Phase
497*/
498ErrorMessage World::resume()
499{
500  this->isPaused = false;
501}
502
503/**
504   \brief destroys the World
505*/
506ErrorMessage World::destroy()
507{
508  delete trackManager;
509}
510
511/**
512   \brief shows the loading screen
513*/
514void World::displayLoadScreen ()
515{
516  PRINTF(3)("World::displayLoadScreen - start\n"); 
517 
518  //GLMenuImageScreen*
519  this->glmis = GLMenuImageScreen::getInstance();
520  this->glmis->init();
521  this->glmis->setMaximum(10);
522  this->glmis->draw();
523 
524  PRINTF(3)("World::displayLoadScreen - end\n"); 
525}
526
527/**
528   \brief removes the loadscreen, and changes over to the game
529
530   \todo take out the delay
531*/
532void World::releaseLoadScreen ()
533{
534  PRINTF(3)("World::releaseLoadScreen - start\n"); 
535  this->glmis->setValue(this->glmis->getMaximum());
536  SDL_Delay(500);
537  PRINTF(3)("World::releaseLoadScreen - end\n"); 
538}
539
540
541/**
542    \brief checks for collisions
543   
544    This method runs through all WorldEntities known to the world and checks for collisions
545    between them. In case of collisions the collide() method of the corresponding entities
546    is called.
547*/
548void World::collide ()
549{
550  /*
551  List *a, *b;
552  WorldEntity *aobj, *bobj;
553   
554  a = entities;
555 
556  while( a != NULL)
557    {
558      aobj = a->nextElement();
559      if( aobj->bCollide && aobj->collisioncluster != NULL)
560        {
561          b = a->nextElement();
562          while( b != NULL )
563            {
564              bobj = b->nextElement();
565              if( bobj->bCollide && bobj->collisioncluster != NULL )
566                {
567                  unsigned long ahitflg, bhitflg;
568                  if( check_collision ( &aobj->place, aobj->collisioncluster,
569                                        &ahitflg, &bobj->place, bobj->collisioncluster,
570                                        &bhitflg) );
571                  {
572                    aobj->collide (bobj, ahitflg, bhitflg);
573                    bobj->collide (aobj, bhitflg, ahitflg);
574                  }
575                }
576              b = b->nextElement();
577            }
578        }
579      a = a->enumerate();
580    }
581  */
582}
583
584/**
585    \brief runs through all entities calling their draw() methods
586*/
587void World::draw ()
588{
589  /* draw entities */
590  WorldEntity* entity;
591  glLoadIdentity();
592
593  entity = this->entities->enumerate();
594  while( entity != NULL ) 
595    { 
596      if( entity->bDraw ) entity->draw();
597      entity = this->entities->nextElement();
598    } 
599 
600  glCallList (objectList);
601  //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list.
602  skySphere->draw();
603
604  testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION);
605
606}
607
608
609/**
610   \brief function to put your own debug stuff into it. it can display informations about
611   the current class/procedure
612*/
613void World::debug()
614{
615  PRINTF(2)("debug() - starting debug\n");
616  PNode* p1 = NullParent::getInstance ();
617  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
618  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
619  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
620
621  p1->debug ();
622  p2->debug ();
623  p3->debug ();
624  p4->debug ();
625
626  p1->shiftCoor (new Vector(-1, -1, -1));
627
628  printf("World::debug() - shift\n");
629  p1->debug ();
630  p2->debug ();
631  p3->debug ();
632  p4->debug ();
633 
634  p1->update (1);
635
636  printf ("World::debug() - update\n");
637  p1->debug ();
638  p2->debug ();
639  p3->debug ();
640  p4->debug ();
641
642  p2->shiftCoor (new Vector(-1, -1, -1));
643  p1->update (2);
644
645  p1->debug ();
646  p2->debug ();
647  p3->debug ();
648  p4->debug ();
649
650  p2->setAbsCoor (new Vector(1,2,3));
651
652
653 p1->update (2);
654
655  p1->debug ();
656  p2->debug ();
657  p3->debug ();
658  p4->debug ();
659
660  delete p1;
661 
662 
663  /*
664  WorldEntity* entity;
665  printf("counting all entities\n");
666  printf("World::debug() - enumerate()\n");
667  entity = entities->enumerate(); 
668  while( entity != NULL )
669    {
670      if( entity->bDraw ) printf("got an entity\n");
671      entity = entities->nextElement();
672    }
673  */
674}
675
676
677/**
678  \brief main loop of the world: executing all world relevant function
679
680  in this loop we synchronize (if networked), handle input events, give the heart-beat to
681  all other member-entities of the world (tick to player, enemies etc.), checking for
682  collisions drawing everything to the screen.
683*/
684void World::mainLoop()
685{
686  this->lastFrame = SDL_GetTicks ();
687  PRINTF(3)("World::mainLoop() - Entering main loop\n");
688  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
689    {
690      PRINTF(3)("World::mainloop() - number of entities: %i\n", this->entities->getSize());
691      // Network
692      this->synchronize ();
693      // Process input
694      this->handleInput ();
695      if( this->bQuitCurrentGame || this->bQuitOrxonox)
696          break;
697      // Process time
698      this->timeSlice ();
699      // Process collision
700      this->collide ();
701      // Draw
702      this->display ();
703
704      (TrackNode::getInstance()->getAbsCoor() - localPlayer->getAbsCoor()).debug();
705 
706      for( int i = 0; i < 5000000; i++) {}
707      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
708    }
709  PRINTF(3)("World::mainLoop() - Exiting the main loop\n");
710}
711
712
713/**
714   \brief synchronize local data with remote data
715*/
716void World::synchronize ()
717{
718  // Get remote input
719  // Update synchronizables
720}
721
722
723/**
724   \brief run all input processing
725
726   the command node is the central input event dispatcher. the node uses the even-queue from
727   sdl and has its own event-passing-queue.
728*/
729void World::handleInput ()
730{
731  // localinput
732  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
733  cn->process();
734  // remoteinput
735}
736
737
738/**
739   \brief advance the timeline
740
741   this calculates the time used to process one frame (with all input handling, drawing, etc)
742   the time is mesured in ms and passed to all world-entities and other classes that need
743   a heart-beat.
744*/
745void World::timeSlice ()
746{
747  Uint32 currentFrame = SDL_GetTicks();
748  if(!this->bPause)
749    {
750      Uint32 dt = currentFrame - this->lastFrame;
751     
752      if(dt > 0)
753        {
754          float fps = 1000/dt;
755          PRINTF(3)("fps = %f\n", fps);
756        }
757      else
758        {
759          /* the frame-rate is limited to 100 frames per second, all other things are for
760             nothing.
761          */
762          PRINTF(2)("fps = 1000 - frame rate is adjusted\n");
763          SDL_Delay(10);
764          dt = 10;
765        }
766      //this->timeSlice (dt);
767     
768      /* function to let all entities tick (iterate through list) */
769      WorldEntity* entity;
770      float seconds = dt / 1000.0;     
771      entity = entities->enumerate(); 
772      while( entity != NULL) 
773        { 
774          entity->tick (seconds);
775          entity = entities->nextElement();
776        }
777      //skySphere->updatePosition(localCamera->absCoordinate);
778     
779      /* update tick the rest */
780      this->localCamera->timeSlice(dt);
781      this->trackManager->tick(dt);
782      this->nullParent->update (seconds);
783    }
784  this->lastFrame = currentFrame;
785}
786
787
788/**
789   \brief render the current frame
790   
791   clear all buffers and draw the world
792*/
793void World::display ()
794{
795  // clear buffer
796  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
797  // set camera
798  this->localCamera->apply ();
799  // draw world
800  this->draw();
801  // draw HUD
802  /* \todo draw HUD */
803  // flip buffers
804  SDL_GL_SwapBuffers();
805  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
806  //SDL_Flip (screen);
807}
808
809
810/**
811   \brief add and spawn a new entity to this world
812   \param entity to be added
813*/
814void World::spawn(WorldEntity* entity)
815{
816  this->nullParent->addChild (entity);
817  this->entities->add (entity);
818  entity->postSpawn ();
819}
820
821
822/**
823   \brief add and spawn a new entity to this world
824   \param entity to be added
825   \param absCoor At what coordinates to add this entity.
826   \param absDir In which direction should it look.
827*/
828void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
829{
830  this->nullParent->addChild (entity);
831  this->entities->add (entity);
832
833  entity->setAbsCoor (absCoor);
834  entity->setAbsDir (absDir);
835
836  entity->postSpawn ();
837}
838
839
840/**
841   \brief add and spawn a new entity to this world
842   \param entity to be added
843   \param entity to be added to (PNode)
844   \param At what relative  coordinates to add this entity.
845   \param In which relative direction should it look.
846*/
847void World::spawn(WorldEntity* entity, PNode* parentNode, 
848                  Vector* relCoor, Quaternion* relDir, 
849                  parentingMode mode)
850{
851
852  if( parentNode != NULL)
853    {
854      parentNode->addChild (entity);
855     
856      entity->setRelCoor (relCoor);
857      entity->setRelDir (relDir);
858     
859      this->entities->add (entity);
860     
861      entity->postSpawn ();
862    }
863}
864
865
866
867/**
868  \brief commands that the world must catch
869  \returns false if not used by the world
870*/
871bool World::command(Command* cmd)
872{
873  return false;
874}
875
Note: See TracBrowser for help on using the repository browser.