Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3538 was 3538, checked in by patrick, 19 years ago

orxonox/trunk: turned the camera again to the right (though seems wrong) position

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