Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/parenting/src/world.cc @ 3320

Last change on this file since 3320 was 3319, checked in by bensch, 21 years ago

orxonox/branches/parenting: added a testCurve to world.cc, and removed curve from the vector-class.

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