Index: orxonox/trunk/src/world.cc
===================================================================
--- orxonox/trunk/src/world.cc	(revision 3233)
+++ orxonox/trunk/src/world.cc	(revision 3365)
@@ -18,4 +18,5 @@
 #include "world_entity.h"
 #include "collision.h"
+#include "track_manager.h"
 #include "track.h"
 #include "player.h"
@@ -23,4 +24,8 @@
 #include "camera.h"
 #include "environment.h"
+#include "p_node.h"
+#include "null_parent.h"
+#include "helper_parent.h"
+#include "glmenu_imagescreen.h"
 
 using namespace std;
@@ -34,4 +39,5 @@
 World::World (char* name)
 {
+  this->setClassName ("World");
   this->worldName = name;
   this->debugWorldNr = -1;
@@ -48,4 +54,7 @@
 /** 
     \brief remove the World from memory
+    
+    delete everything explicitly, that isn't contained in the parenting tree!
+    things contained in the tree are deleted automaticaly
 */
 World::~World ()
@@ -57,4 +66,9 @@
   this->localCamera->destroy();
 
+  this->nullParent->destroy ();
+
+  //delete this->trackManager;
+
+  /*
   WorldEntity* entity = entities->enumerate();  
   while( entity != NULL ) 
@@ -64,10 +78,18 @@
     }
   this->entities->destroy();
-
-  delete this->entities;
-  delete this->localCamera;
+  */
+
+  /* FIX the parent list has to be cleared - not possible if we got the old list also*/
+
+
+  //delete this->entities;
+  //delete this->localCamera;
   /* this->localPlayer hasn't to be deleted explicitly, it is 
      contained in entities*/
 }
+
+GLfloat ctrlpoints[4][3] = {
+  {20.0, 10.0, 5.0}, {40.0, -10.0, 0.0},
+  {60.0, -10.0, 5.0}, {80.0, 10.0, 5.0}};
 
 
@@ -78,5 +100,15 @@
   cn->addToWorld(this);
   cn->enable(true);
-}
+
+  //glMap1f (GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
+  //glEnable (GL_MAP1_VERTEX_3);
+  
+  //theNurb = gluNewNurbsRenderer ();
+  //gluNurbsProperty (theNurb, GLU_NURBS_MODE, GLU_NURBS_TESSELLATOR);
+  //gluNurbsProperty (theNurb, GLU_NURBS_VERTEX, vertexCallback );
+
+}
+
+
 
 ErrorMessage World::start()
@@ -99,4 +131,5 @@
 }
 
+
 ErrorMessage World::resume()
 {
@@ -104,13 +137,100 @@
 }
 
+
 void World::destroy()
 {
-
-}
+}
+
+
+void World::displayLoadScreen ()
+{
+  printf ("World::displayLoadScreen - start\n"); 
+  
+  //GLMenuImageScreen* 
+  glmis = new GLMenuImageScreen();
+  glmis->init();
+  glmis->draw();
+ 
+  printf ("World::displayLoadScreen - end\n"); 
+}
+
+
+void World::releaseLoadScreen ()
+{
+  printf ("World::releaseLoadScreen - start\n"); 
+
+  printf ("World::releaseLoadScreen - end\n"); 
+}
+
 
 void World::load()
 {
+  //  BezierCurve* tmpCurve = new BezierCurve();
   if(this->debugWorldNr != -1)
     {
+      trackManager = TrackManager::getInstance();
+      trackManager->addPoint(Vector(0,-5,0));
+      trackManager->addPoint(Vector(10,0,5));
+      trackManager->addPoint(Vector(20,0,-5));
+      trackManager->addPoint(Vector(30,0,5));
+      trackManager->addPoint(Vector(40,0,5));
+      trackManager->setDuration(.5);
+      trackManager->setSavePoint();
+      trackManager->addPoint(Vector(50,10,10));
+      trackManager->addPoint(Vector(60,0, 10));
+      trackManager->addPoint(Vector(70,0, 10));
+      trackManager->addPoint(Vector(80,0,-10));
+      trackManager->addPoint(Vector(90,0,-10));
+      trackManager->setDuration(.5);
+      trackManager->setSavePoint();
+      trackManager->addPoint(Vector(110,0,5));
+      trackManager->addPoint(Vector(120,0, 10));
+      trackManager->addPoint(Vector(130,0, 10));
+      trackManager->addPoint(Vector(140,0,-10));
+      trackManager->addPoint(Vector(150,0,-10));
+      trackManager->setDuration(.5);
+      int fork11, fork12, fork13, fork14;
+      trackManager->fork(4, &fork11, &fork12, &fork13, &fork14);
+      trackManager->workOn(fork11);
+      trackManager->addPoint(Vector(170, 0, -15));
+      trackManager->addPoint(Vector(180, 0, -15));
+      trackManager->workOn(fork12);
+      trackManager->addPoint(Vector(170, 0, 10));
+      trackManager->addPoint(Vector(180, 0, 10));
+      trackManager->addPoint(Vector(190,2,5));
+      trackManager->addPoint(Vector(200,2,5));
+      int fork21, fork22;
+      trackManager->fork(2, &fork21, &fork22);
+      trackManager->workOn(fork21);
+      trackManager->addPoint(Vector(220, 10,-10));
+      trackManager->addPoint(Vector(230, 0,-10));
+      trackManager->addPoint(Vector(240, 0, 2));
+      trackManager->addPoint(Vector(250, 0, 0));
+      trackManager->addPoint(Vector(260, 0, 5));
+      trackManager->join(2, fork12, fork11);
+      trackManager->workOn(fork22);
+      trackManager->addPoint(Vector(220, -10,10));
+      trackManager->addPoint(Vector(230, 0, 10));
+      trackManager->addPoint(Vector(240, 0, 10));
+      trackManager->addPoint(Vector(250, 0, 5));
+      trackManager->workOn(fork13);
+      trackManager->addPoint(Vector(200,-10,5));
+      trackManager->addPoint(Vector(250,-10,5));
+      printf("fork14: %d\n", fork14);
+      trackManager->workOn(fork14);
+      trackManager->addPoint(Vector(200,15,0));
+      trackManager->addPoint(Vector(210,0,10));
+
+
+
+      trackManager->join(4, fork21, fork22, fork13, fork14);
+
+      /*
+      tmpCurve->addNode(Vector(10,0,-10));
+      //tmpCurve->addNode(Vector(10,2,5));
+      //tmpCurve->addNode(Vector(10,3,-5));
+      //      tmpCurve->addNode(Vector(10,1,5));
+      tmpCurve->addNode(Vector(10,0,5));
+      */
       switch(this->debugWorldNr)
 	{
@@ -123,4 +243,7 @@
 	case DEBUG_WORLD_0:
 	  {
+	    this->nullParent = NullParent::getInstance ();
+	    this->nullParent->setName ("NullParent");
+
 	    // create some path nodes
 	    this->pathnodes = new Vector[6];
@@ -141,22 +264,31 @@
 	    // !\todo old track-system has to be removed
 
+	    //create helper for player
+	    HelperParent* hp = new HelperParent ();
+	    /* the player has to be added to this helper */
+
 	    // create a player
-	    WorldEntity* myPlayer = new Player();
-	    this->spawn(myPlayer);
+	    WorldEntity* myPlayer = new Player ();
+	    myPlayer->setName ("player");
+	    this->spawn (myPlayer);
 	    this->localPlayer = myPlayer;	    
 
 	    // bind input
-	    Orxonox *orx = Orxonox::getInstance();
+	    Orxonox *orx = Orxonox::getInstance ();
 	    orx->getLocalInput()->bind (myPlayer);
 	    
 	    // bind camera
 	    this->localCamera = new Camera(this);
-	    this->getCamera()->bind (myPlayer);	
-
-	    Placement* plc = new Placement;
-	    plc->r = Vector(100, 10, 10);
-	    plc->w = Quaternion();
+	    this->localCamera->setName ("camera");
+	    this->getCamera()->bind (myPlayer);
+	    this->localPlayer->addChild (this->localCamera);
+	    
+
+	    Vector* es = new Vector (50, 2, 0);
+	    Quaternion* qs = new Quaternion ();
 	    WorldEntity* env = new Environment();
-	    this->spawn(env, plc);
+	    env->setName ("env");
+	    this->spawn(env, es, qs);
+
 
 	    break;
@@ -164,4 +296,17 @@
 	case DEBUG_WORLD_1:
 	  {
+	    /*
+	    this->testCurve = new UPointCurve();
+	    this->testCurve->addNode(Vector( 0, 0, 0));
+	    this->testCurve->addNode(Vector(10, 0, 5));
+	    this->testCurve->addNode(Vector(20, -5,-5));
+	    this->testCurve->addNode(Vector(30, 5, 10));
+	    this->testCurve->addNode(Vector(40, 0,-10));
+	    this->testCurve->addNode(Vector(50, 0,-10));
+	    */
+
+	    this->nullParent = NullParent::getInstance ();
+	    this->nullParent->setName ("NullParent");
+
 	    // create some path nodes
 	    this->pathnodes = new Vector[6];
@@ -173,4 +318,7 @@
 	    this->pathnodes[5] = Vector(30, 50, 0);
 	    
+
+
+
 	    // create the tracks
 	    this->tracklen = 6;
@@ -183,4 +331,5 @@
 	    // create a player
 	    WorldEntity* myPlayer = new Player();
+	    myPlayer->setName ("player");
 	    this->spawn(myPlayer);
 	    this->localPlayer = myPlayer;	    
@@ -191,6 +340,8 @@
 	    
 	    // bind camera
-	    this->localCamera = new Camera(this);
+	    this->localCamera = new Camera (this);
+	    this->localCamera->setName ("camera");
 	    this->getCamera()->bind (myPlayer);	
+	    this->localPlayer->addChild (this->localCamera);
 	    break;
 	  }
@@ -212,16 +363,16 @@
 
   int sizeX = 100;
-  int sizeY = 80;
+  int sizeZ = 80;
   float length = 1000;
   float width = 200;
   float widthX = float (length /sizeX);
-  float widthY = float (width /sizeY);
-  
-  float height [sizeX][sizeY];
-  Vector normal_vectors[sizeX][sizeY];
+  float widthZ = float (width /sizeZ);
+  
+  float height [sizeX][sizeZ];
+  Vector normal_vectors[sizeX][sizeZ];
   
   
   for ( int i = 0; i<sizeX-1; i+=1)
-    for (int j = 0; j<sizeY-1;j+=1)
+    for (int j = 0; j<sizeZ-1;j+=1)
       //height[i][j] = rand()/20046 + (j-25)*(j-25)/30;
 #ifdef __WIN32__
@@ -231,20 +382,19 @@
 #endif
 
-  //Die Hügel ein wenig glätten
+  //Die Huegel ein wenig glaetten
   for (int h=1; h<2;h++)
     for (int i=1;i<sizeX-2 ;i+=1 )
-      for(int j=1;j<sizeY-2;j+=1)
+      for(int j=1;j<sizeZ-2;j+=1)
 	height[i][j]=(height[i+1][j]+height[i][j+1]+height[i-1][j]+height[i][j-1])/4;
   
   //Berechnung von normalen Vektoren
-
   for(int i=1;i<sizeX-2;i+=1)
-    for(int j=1;j<sizeY-2 ;j+=1)
+    for(int j=1;j<sizeZ-2 ;j+=1)
       {
-	Vector v1 = Vector (widthX*(1),      widthY*(j)  ,      height[i][j]);
-	Vector v2 = Vector (widthX*(i-1),    widthY*(j)  ,      height[i-1][j]);
-	Vector v3 = Vector (widthX*(i),      widthY*(j+1),      height[i][j+1]);
-	Vector v4 = Vector (widthX*(i+1),    widthY*(j),        height[i+1][j]);
-	Vector v5 = Vector (widthX*(i),      widthY*(j-1),      height[i][j-1]);
+	Vector v1 = Vector (widthX*(1),      height[i][j],      widthZ*(j) );
+	Vector v2 = Vector (widthX*(i-1),    height[i-1][j],    widthZ*(j));
+	Vector v3 = Vector (widthX*(i),      height[i][j+1],    widthZ*(j+1));
+	Vector v4 = Vector (widthX*(i+1),    height[i+1][j],    widthZ*(j));
+	Vector v5 = Vector (widthX*(i),      height[i][j-1],    widthZ*(j-1));
 	
 	Vector c1 = v2 - v1;
@@ -253,5 +403,5 @@
 	Vector c4 = v5 - v1;
 	Vector zero = Vector (0,0,0);
-	normal_vectors[i][j]=c1.cross(v4-v2)+c2.cross(v1-v3)+c3.cross(v2-v4)+c4.cross(v3-v1);
+	normal_vectors[i][j]=c1.cross(v3-v5)+c2.cross(v4-v2)+c3.cross(v5-v3)+c4.cross(v2-v4);
 	normal_vectors[i][j].normalize();
       }
@@ -259,10 +409,10 @@
   int snowheight=3;
   for ( int i = 0; i<sizeX; i+=1)
-    for (int j = 0; j<sizeY;j+=1)
+    for (int j = 0; j<sizeZ;j+=1)
       {	  
-	Vector v1 = Vector (widthX*(i),      widthY*(j)  -width/2,      height[i][j]-20 );
-	Vector v2 = Vector (widthX*(i+1),    widthY*(j)  -width/2,      height[i+1][j]-20);
-	Vector v3 = Vector (widthX*(i+1),    widthY*(j+1)-width/2,    height[i+1][j+1]-20);
-	Vector v4 = Vector (widthX*(i),      widthY*(j+1)-width/2,    height[i][j+1]-20);
+	Vector v1 = Vector (widthX*(i),      height[i][j]-20,       widthZ*(j)  -width/2);
+	Vector v2 = Vector (widthX*(i+1),    height[i+1][j]-20,     widthZ*(j)  -width/2);
+	Vector v3 = Vector (widthX*(i+1),    height[i+1][j+1]-20,   widthZ*(j+1)-width/2);
+	Vector v4 = Vector (widthX*(i),      height[i][j+1]-20,     widthZ*(j+1)-width/2);
 	float a[3];
 	if(height[i][j]<snowheight){
@@ -371,5 +521,5 @@
   //draw track
   glBegin(GL_LINES);
-  glColor3f(0,1,1);
+  glColor3f(0.0, 1.0, 1.0);
   for( int i = 0; i < tracklen; i++)
     {
@@ -378,4 +528,29 @@
     }
   glEnd();
+  
+  /*
+  glBegin(GL_LINE_STRIP);
+  glColor3f(1.0, 5.0, 1.0);
+  for( int i = 0; i <= 30; i++)
+    {
+      glEvalCoord1f ((GLfloat) i/30.0);
+    }
+  glEnd();
+  */
+
+  trackManager->drawGraph(.01);
+  trackManager->debug(2);
+  delete trackManager;
+  
+  /*
+  glBegin(GL_LINES);
+  float i;
+  for(i = 0.0; i<1; i+=.01)
+    {
+      printf("%f, %f, %f\n",tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
+      glVertex3f(tmpCurve->calcPos(i).x, tmpCurve->calcPos(i).y, tmpCurve->calcPos(i).z);
+    }
+  glEnd();
+  */
   glEndList();
 }
@@ -430,9 +605,6 @@
 void World::draw ()
 {
-  // draw geometry
-  
   // draw entities
   WorldEntity* entity;
-  
   entity = this->entities->enumerate();
   while( entity != NULL ) 
@@ -440,10 +612,11 @@
       if( entity->bDraw ) entity->draw();
       entity = this->entities->nextElement();
-    }
-  
-  
+    } 
+  
+  //glmis = new GLMenuImageScreen();
+  ///glmis->init();
+
   // draw debug coord system
   glCallList (objectList);
-
 
 }
@@ -459,4 +632,5 @@
 void World::update ()
 {
+  /*
   //List<WorldEntity> *l;
   WorldEntity* entity;
@@ -477,5 +651,4 @@
 	  t = loc->part;
 	  
-	  /* check if entity has still a legal track-id */
 	  if( t >= tracklen )
 	    {
@@ -500,14 +673,9 @@
       else
 	{
-	  /* \todo: implement check whether this particular free entity 
-	     is out of the game area
-	     \todo: call function to notify the entity that it left 
-	     the game area
-	  */
 	}
       
       entity = entities->nextElement();
     }
-  
+  */  
 }
 
@@ -522,4 +690,7 @@
   float seconds = deltaT / 1000.0;
   
+  this->nullParent->update (seconds);
+  //this->nullParent->processTick (seconds);
+
   entity = entities->enumerate(); 
   while( entity != NULL) 
@@ -542,15 +713,4 @@
 
 
-
-/**
-   \brief calls the correct mapping function to convert a given "look at"-Location to a 
-   Camera Placement
-*/
-void World::calcCameraPos (Location* loc, Placement* plc)
-{
-  track[loc->part].mapCamera (loc, plc);
-}
-
-
 void World::setTrackLen(Uint32 len)
 {
@@ -571,7 +731,54 @@
 void World::debug()
 {
-  //List<WorldEntity> *l;
+  printf ("World::debug() - starting debug\n");
+  PNode* p1 = NullParent::getInstance ();
+  PNode* p2 = new PNode (new Vector(2, 2, 2), p1);
+  PNode* p3 = new PNode (new Vector(4, 4, 4), p1);
+  PNode* p4 = new PNode (new Vector(6, 6, 6), p2);
+
+  p1->debug ();
+  p2->debug ();
+  p3->debug ();
+  p4->debug ();
+
+  p1->shiftCoor (new Vector(-1, -1, -1));
+
+  printf("World::debug() - shift\n");
+  p1->debug ();
+  p2->debug ();
+  p3->debug ();
+  p4->debug ();
+  
+  p1->update (1);
+
+  printf ("World::debug() - update\n");
+  p1->debug ();
+  p2->debug ();
+  p3->debug ();
+  p4->debug ();
+
+  p2->shiftCoor (new Vector(-1, -1, -1));
+  p1->update (2);
+
+  p1->debug ();
+  p2->debug ();
+  p3->debug ();
+  p4->debug ();
+
+  p2->setAbsCoor (new Vector(1,2,3));
+
+
+ p1->update (2);
+
+  p1->debug ();
+  p2->debug ();
+  p3->debug ();
+  p4->debug ();
+
+  p1->destroy ();
+  
+  
+  /*
   WorldEntity* entity;
-  
   printf("counting all entities\n");
   printf("World::debug() - enumerate()\n");
@@ -582,4 +789,5 @@
       entity = entities->nextElement();
     }
+  */
 }
 
@@ -594,12 +802,12 @@
 void World::mainLoop()
 {
-  this->lastFrame = SDL_GetTicks();
+  this->lastFrame = SDL_GetTicks ();
   printf("World::mainLoop() - Entering main loop\n");
   while( !this->bQuitOrxonox && !this->bQuitCurrentGame) /* \todo implement pause */
     {
       // Network
-      synchronize();
+      this->synchronize ();
       // Process input
-      handleInput();
+      this->handleInput ();
       if( this->bQuitCurrentGame || this->bQuitOrxonox)
 	{
@@ -608,11 +816,12 @@
 	}
       // Process time
-      timeSlice();
+      this->timeSlice ();
       // Process collision
-      collision();
+      this->collision ();
       // Draw
-      display();
-  
-      for(int i = 0; i < 10000000; i++) {}
+      this->display ();
+  
+      for( int i = 0; i < 5000000; i++) {}
+      /* \todo this is to slow down the program for openGl Software emulator computers, reimplement*/
     }
   printf("World::mainLoop() - Exiting the main loop\n");
@@ -701,6 +910,9 @@
   this->draw();
   // draw HUD
+  /* \todo draw HUD */
   // flip buffers
   SDL_GL_SwapBuffers();
+  //SDL_Surface* screen = Orxonox::getInstance()->getScreen ();
+  //SDL_Flip (screen);
 }
 
@@ -723,19 +935,9 @@
 void World::spawn(WorldEntity* entity)
 {
-  Location zeroloc;
-  Location* loc = NULL;
-  WorldEntity* owner;
-
-  entities->add (entity);
-  zeroloc.dist = 0;
-  zeroloc.part = 0;
-  zeroloc.pos = Vector();
-  zeroloc.rot = Quaternion();
-  loc = &zeroloc;
-  entity->init (loc, owner);
-  if (entity->bFree)
-    {
-      this->track[loc->part].mapCoords( loc, entity->getPlacement());
-    }
+  if( this->nullParent != NULL && entity->parent == NULL)
+    this->nullParent->addChild (entity);
+
+  this->entities->add (entity);
+
   entity->postSpawn ();
 }
@@ -747,47 +949,17 @@
    \param location where to add
 */
-void World::spawn(WorldEntity* entity, Location* loc)
-{
-  Location zeroLoc;
-  WorldEntity* owner;
+void World::spawn(WorldEntity* entity, Vector* absCoor, Quaternion* absDir)
+{
+  entity->setAbsCoor (absCoor);
+  entity->setAbsDir (absDir);
+  
+  if( this->nullParent != NULL && entity->parent == NULL)
+    this->nullParent->addChild (entity);
+
   this->entities->add (entity);
-  if( loc == NULL)
-    {
-      zeroLoc.dist = 0;
-      zeroLoc.part = 0;
-      zeroLoc.pos = Vector();
-      zeroLoc.rot = Quaternion();
-      loc = &zeroLoc;
-    }
-  entity->init (loc, owner);
-  if (entity->bFree)
-    {
-      this->track[loc->part].mapCoords( loc, entity->getPlacement());
-    }
+
   entity->postSpawn ();
-  //return entity;
-}
-
-
-/**
-   \brief add and spawn a new entity to this world
-   \param entity to be added
-   \param place where to be added
-*/
-void World::spawn(WorldEntity* entity, Placement* plc)
-{
-  Placement zeroPlc;
-  WorldEntity* owner;
-  if( plc == NULL)
-    {
-      zeroPlc.r = Vector();
-      zeroPlc.w = Quaternion();
-      plc = &zeroPlc;
-    }
-  this->entities->add (entity);
-  entity->init (plc, owner);
-  entity->postSpawn ();
-  //return entity;
-}
+}
+
 
 
@@ -800,2 +972,13 @@
   return false;
 }
+
+
+
+
+void World::swap (unsigned char &a, unsigned char &b)
+{
+  unsigned char temp;
+  temp = a;
+  a    = b;
+  b    = temp;
+}
