Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: zero-loop problem in pnode, dynamic pnode realocation. unstable, segfault when changing level.

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