Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/parenting: derivation-curve implemented.

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