Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trank: worked on removing alg. from pnode and changed a little on camera for the new tackmanager

File size: 20.8 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            this->localCamera->setRelCoor (cameraOffset);
253            trackManager->condition(1, NEAREST, myPlayer);
254
255            break;
256          }
257        case DEBUG_WORLD_1:
258          {
259            this->nullParent = NullParent::getInstance ();
260            this->nullParent->setName ("NullParent");
261
262            // create a player
263            WorldEntity* myPlayer = new Player();
264            myPlayer->setName ("player");
265            this->spawn(myPlayer);
266            this->localPlayer = myPlayer;           
267           
268            // bind input
269            Orxonox *orx = Orxonox::getInstance();
270            orx->getLocalInput()->bind (myPlayer);
271           
272            // bind camera
273            this->localCamera = new Camera (this);
274            this->localCamera->setName ("camera");
275            this->localCamera->bind (myPlayer); 
276            this->localPlayer->addChild (this->localCamera);
277
278            // Create SkySphere
279            skySphere = new Skysphere("../data/pictures/sky-replace.jpg");
280            this->localPlayer->addChild(this->skySphere);
281
282            break;
283
284
285          }
286        default:
287          printf("World::load() - no world with ID %i found", this->debugWorldNr );
288        }
289    }
290  else if(this->worldName != NULL)
291    {
292
293    }
294
295  // initialize debug coord system
296  objectList = glGenLists(1);
297  glNewList (objectList, GL_COMPILE);
298
299  glColor3f(1.0,0,0);
300
301  int sizeX = 100;
302  int sizeZ = 80;
303  float length = 1000;
304  float width = 200;
305  float widthX = float (length /sizeX);
306  float widthZ = float (width /sizeZ);
307 
308  float height [sizeX][sizeZ];
309  Vector normal_vectors[sizeX][sizeZ];
310 
311 
312  for ( int i = 0; i<sizeX-1; i+=1)
313    for (int j = 0; j<sizeZ-1;j+=1)
314      //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
315#ifdef __WIN32__
316      height[i][j]=(sin((float)j/3)*rand()*i/182400)*.5;
317#else
318      height[i][j]=(sin((float)j/3)*rand()*(long)i/6282450500.0)*.5;
319#endif
320
321  //Die Huegel ein wenig glaetten
322  for (int h=1; h<2;h++)
323    for (int i=1;i<sizeX-2 ;i+=1 )
324      for(int j=1;j<sizeZ-2;j+=1)
325        height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
326 
327  //Berechnung von normalen Vektoren
328  for(int i=1;i<sizeX-2;i+=1)
329    for(int j=1;j<sizeZ-2 ;j+=1)
330      {
331        Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
332        Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
333        Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
334        Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
335        Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
336       
337        Vector c1 = v2 - v1;
338        Vector c2 = v3 - v1;
339        Vector c3=  v4 - v1;
340        Vector c4 = v5 - v1;
341        Vector zero = Vector (0,0,0);
342        normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
343        normal_vectors[i][j].normalize();
344      }
345
346  glBegin(GL_QUADS);
347  int snowheight=3;
348  for ( int i = 0; i<sizeX; i+=1)
349    for (int j = 0; j<sizeZ;j+=1)
350      {   
351        Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
352        Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
353        Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
354        Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
355        float a[3];
356        if(height[i][j]<snowheight){
357          a[0]=0;
358          a[1]=1.0-height[i][j]/10-.3;
359          a[2]=0;
360          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
361        }
362        else{
363            a[0]=1.0;
364            a[1]=1.0;
365            a[2]=1.0;
366            glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
367           
368        }
369        glNormal3f(normal_vectors[i][j].x, normal_vectors[i][j].y, normal_vectors[i][j].z);
370        glVertex3f(v1.x, v1.y, v1.z);
371        if(height[i+1][j]<snowheight){
372          a[0]=0;
373          a[1] =1.0-height[i+1][j]/10-.3;
374          a[2]=0;
375          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
376        }
377        else{
378          a[0]=1.0;
379          a[1]=1.0;
380          a[2]=1.0;
381          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
382         
383        }
384        glNormal3f(normal_vectors[i+1][j].x, normal_vectors[i+1][j].y, normal_vectors[i+1][j].z);
385        glVertex3f(v2.x, v2.y, v2.z);
386        if(height[i+1][j+1]<snowheight){
387          a[0]=0;
388          a[1] =1.0-height[i+1][j+1]/10-.3;
389          a[2]=0;
390          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
391        }
392        else{
393          a[0]=1.0;
394          a[1]=1.0;
395          a[2]=1.0;
396          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
397         
398         
399        }
400        glNormal3f(normal_vectors[i+1][j+1].x, normal_vectors[i+1][j+1].y, normal_vectors[i+1][j+1].z);
401        glVertex3f(v3.x, v3.y, v3.z);
402        if(height[i][j+1]<snowheight){
403          a[0]=0;
404          a[1] =1.0-height[i+1][j+1]/10-.3;
405          a[2]=0;
406          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
407        }
408        else{
409          a[0]=1.0;
410          a[1]=1.0;
411          a[2]=1.0;
412          glMaterialfv(GL_FRONT,GL_DIFFUSE,a);
413        }
414        glNormal3f(normal_vectors[i][j+1].x, normal_vectors[i][j+1].y, normal_vectors[i][j+1].z);
415        glVertex3f(v4.x, v4.y, v4.z);
416       
417      }
418  glEnd();
419
420  trackManager->drawGraph(.01);
421  trackManager->debug(2);
422  glEndList();
423
424
425  // LIGHT initialisation
426  light = Light::getInstance();
427  light->addLight(0);
428  light->setAttenuation(QUADRATIC, 1.0);
429  light->setAttenuation(CONSTANT, 2.0);
430  light->setAttenuation(QUADRATIC, 1.0);
431  light->setPosition(10.0, 10.0, 50.0);
432  light->setDiffuseColor(1,1,1);
433  //  light->addLight(1);
434  //  light->setPosition(20, 10, -20);
435  //  light->setDiffuseColor(0,0,0);
436  light->debug();
437
438
439}
440
441/**
442   \brief initializes a new World
443*/
444ErrorMessage World::init()
445{
446  this->bPause = false;
447  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
448  cn->addToWorld(this);
449  cn->enable(true);
450
451  //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
452  //glEnable (GL_MAP1_VERTEX_3);
453 
454  //theNurb = gluNewNurbsRenderer ();
455  //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR);
456  //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback );
457
458}
459
460
461/**
462   \brief starts the World
463*/
464ErrorMessage World::start()
465{
466  printf("World::start() - starting current World: nr %i\n", this->debugWorldNr);
467  this->bQuitOrxonox = false;
468  this->bQuitCurrentGame = false;
469  this->mainLoop();
470}
471
472/**
473   \brief stops the world.
474
475   This happens, when the player decides to end the Level.
476*/
477ErrorMessage World::stop()
478{
479  printf("World::stop() - got stop signal\n");
480  this->bQuitCurrentGame = true;
481}
482
483/**
484   \brief pauses the Game
485*/
486ErrorMessage World::pause()
487{
488  this->isPaused = true;
489}
490
491/**
492   \brief ends the pause Phase
493*/
494ErrorMessage World::resume()
495{
496  this->isPaused = false;
497}
498
499/**
500   \brief destroys the World
501*/
502ErrorMessage World::destroy()
503{
504  delete trackManager;
505}
506
507/**
508   \brief shows the loading screen
509*/
510void World::displayLoadScreen ()
511{
512  printf ("World::displayLoadScreen - start\n"); 
513 
514  //GLMenuImageScreen*
515  this->glmis = GLMenuImageScreen::getInstance();
516  this->glmis->init();
517  this->glmis->setMaximum(10);
518  this->glmis->draw();
519 
520  printf ("World::displayLoadScreen - end\n"); 
521}
522
523/**
524   \brief removes the loadscreen, and changes over to the game
525
526   \todo take out the delay
527*/
528void World::releaseLoadScreen ()
529{
530  printf ("World::releaseLoadScreen - start\n"); 
531  this->glmis->setValue(this->glmis->getMaximum());
532  SDL_Delay(500);
533  printf ("World::releaseLoadScreen - end\n"); 
534}
535
536
537/**
538    \brief checks for collisions
539   
540    This method runs through all WorldEntities known to the world and checks for collisions
541    between them. In case of collisions the collide() method of the corresponding entities
542    is called.
543*/
544void World::collide ()
545{
546  /*
547  List *a, *b;
548  WorldEntity *aobj, *bobj;
549   
550  a = entities;
551 
552  while( a != NULL)
553    {
554      aobj = a->nextElement();
555      if( aobj->bCollide && aobj->collisioncluster != NULL)
556        {
557          b = a->nextElement();
558          while( b != NULL )
559            {
560              bobj = b->nextElement();
561              if( bobj->bCollide && bobj->collisioncluster != NULL )
562                {
563                  unsigned long ahitflg, bhitflg;
564                  if( check_collision ( &aobj->place, aobj->collisioncluster,
565                                        &ahitflg, &bobj->place, bobj->collisioncluster,
566                                        &bhitflg) );
567                  {
568                    aobj->collide (bobj, ahitflg, bhitflg);
569                    bobj->collide (aobj, bhitflg, ahitflg);
570                  }
571                }
572              b = b->nextElement();
573            }
574        }
575      a = a->enumerate();
576    }
577  */
578}
579
580/**
581    \brief runs through all entities calling their draw() methods
582*/
583void World::draw ()
584{
585  /* draw entities */
586  WorldEntity* entity;
587  glLoadIdentity();
588
589  entity = this->entities->enumerate();
590  while( entity != NULL ) 
591    { 
592      if( entity->bDraw ) entity->draw();
593      entity = this->entities->nextElement();
594    } 
595 
596  glCallList (objectList);
597  //! \todo skysphere is a WorldEntity and should be inside of the world-entity-list.
598  skySphere->draw();
599
600  testFont->printText(0, 0, 1, "orxonox_" PACKAGE_VERSION);
601
602}
603
604
605/**
606   \brief function to put your own debug stuff into it. it can display informations about
607   the current class/procedure
608*/
609void World::debug()
610{
611  printf ("World::debug() - starting debug\n");
612  PNode* p1 = NullParent::getInstance ();
613  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
614  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
615  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
616
617  p1->debug ();
618  p2->debug ();
619  p3->debug ();
620  p4->debug ();
621
622  p1->shiftCoor (new Vector(-1, -1, -1));
623
624  printf("World::debug() - shift\n");
625  p1->debug ();
626  p2->debug ();
627  p3->debug ();
628  p4->debug ();
629 
630  p1->update (1);
631
632  printf ("World::debug() - update\n");
633  p1->debug ();
634  p2->debug ();
635  p3->debug ();
636  p4->debug ();
637
638  p2->shiftCoor (new Vector(-1, -1, -1));
639  p1->update (2);
640
641  p1->debug ();
642  p2->debug ();
643  p3->debug ();
644  p4->debug ();
645
646  p2->setAbsCoor (new Vector(1,2,3));
647
648
649 p1->update (2);
650
651  p1->debug ();
652  p2->debug ();
653  p3->debug ();
654  p4->debug ();
655
656  p1->destroy ();
657 
658 
659  /*
660  WorldEntity* entity;
661  printf("counting all entities\n");
662  printf("World::debug() - enumerate()\n");
663  entity = entities->enumerate(); 
664  while( entity != NULL )
665    {
666      if( entity->bDraw ) printf("got an entity\n");
667      entity = entities->nextElement();
668    }
669  */
670}
671
672
673/**
674  \brief main loop of the world: executing all world relevant function
675
676  in this loop we synchronize (if networked), handle input events, give the heart-beat to
677  all other member-entities of the world (tick to player, enemies etc.), checking for
678  collisions drawing everything to the screen.
679*/
680void World::mainLoop()
681{
682  this->lastFrame = SDL_GetTicks ();
683  printf("World::mainLoop() - Entering main loop\n");
684  while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
685    {
686      // Network
687      this->synchronize ();
688      // Process input
689      this->handleInput ();
690      if( this->bQuitCurrentGame || this->bQuitOrxonox)
691        {
692          printf("World::mainLoop() - leaving loop earlier...\n");
693          break;
694        }
695      // Process time
696      this->timeSlice ();
697      // Process collision
698      this->collide ();
699      // Draw
700      this->display ();
701 
702      for( int i = 0; i < 5000000; i++) {}
703      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
704    }
705  printf("World::mainLoop() - Exiting the main loop\n");
706}
707
708
709/**
710   \brief synchronize local data with remote data
711*/
712void World::synchronize ()
713{
714  // Get remote input
715  // Update synchronizables
716}
717
718
719/**
720   \brief run all input processing
721
722   the command node is the central input event dispatcher. the node uses the even-queue from
723   sdl and has its own event-passing-queue.
724*/
725void World::handleInput ()
726{
727  // localinput
728  CommandNode* cn = Orxonox::getInstance()->getLocalInput();
729  cn->process();
730  // remoteinput
731}
732
733
734/**
735   \brief advance the timeline
736
737   this calculates the time used to process one frame (with all input handling, drawing, etc)
738   the time is mesured in ms and passed to all world-entities and other classes that need
739   a heart-beat.
740*/
741void World::timeSlice ()
742{
743  Uint32 currentFrame = SDL_GetTicks();
744  if(!this->bPause)
745    {
746      Uint32 dt = currentFrame - this->lastFrame;
747     
748      if(dt > 0)
749        {
750          float fps = 1000/dt;
751          printf("fps = %f\n", fps);
752        }
753      else
754        {
755          /* the frame-rate is limited to 100 frames per second, all other things are for
756             nothing.
757          */
758          printf("fps = 1000 - frame rate is adjusted\n");
759          SDL_Delay(10);
760          dt = 10;
761        }
762      //this->timeSlice (dt);
763     
764      /* function to let all entities tick (iterate through list) */
765      WorldEntity* entity;
766      float seconds = dt / 1000.0;     
767      this->nullParent->update (seconds);
768      entity = entities->enumerate(); 
769      while( entity != NULL) 
770        { 
771          entity->tick (seconds);
772          entity = entities->nextElement();
773        }
774      //skySphere->updatePosition(localCamera->absCoordinate);
775     
776      /* update tick the rest */
777      this->localCamera->timeSlice(dt);
778      this->trackManager->tick(dt);
779    }
780  this->lastFrame = currentFrame;
781}
782
783
784/**
785   \brief render the current frame
786   
787   clear all buffers and draw the world
788*/
789void World::display ()
790{
791  // clear buffer
792  glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
793  // set camera
794  this->localCamera->apply ();
795  // draw world
796  this->draw();
797  // draw HUD
798  /* \todo draw HUD */
799  // flip buffers
800  SDL_GL_SwapBuffers();
801  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
802  //SDL_Flip (screen);
803}
804
805
806/**
807   \brief add and spawn a new entity to this world
808   \param entity to be added
809*/
810void World::spawn(WorldEntity* entity)
811{
812  this->nullParent->addChild (entity);
813  this->entities->add (entity);
814  entity->postSpawn ();
815}
816
817
818/**
819   \brief add and spawn a new entity to this world
820   \param entity to be added
821   \param absCoor At what coordinates to add this entity.
822   \param absDir In which direction should it look.
823*/
824void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
825{
826  this->nullParent->addChild (entity);
827  this->entities->add (entity);
828
829  entity->setAbsCoor (absCoor);
830  entity->setAbsDir (absDir);
831
832  entity->postSpawn ();
833}
834
835
836/**
837   \brief add and spawn a new entity to this world
838   \param entity to be added
839   \param entity to be added to (PNode)
840   \param At what relative  coordinates to add this entity.
841   \param In which relative direction should it look.
842*/
843void World::spawn(WorldEntity* entity, PNode* parentNode, 
844                  Vector* relCoor, Quaternion* relDir, 
845                  parentingMode mode)
846{
847
848  if( parentNode != NULL)
849    {
850      parentNode->addChild (entity);
851     
852      entity->setRelCoor (relCoor);
853      entity->setRelDir (relDir);
854     
855      this->entities->add (entity);
856     
857      entity->postSpawn ();
858    }
859}
860
861
862
863/**
864  \brief commands that the world must catch
865  \returns false if not used by the world
866*/
867bool World::command(Command* cmd)
868{
869  return false;
870}
871
Note: See TracBrowser for help on using the repository browser.