Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

oroxnox/branches/parenting: turned coordinate system, now using the normal opengl orientation: x: forth, y: up, z: right. tried to turn the landscape, but didnt work. will be remade later

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