Index: /orxonox/trunk/src/lib/coord/p_node.cc
===================================================================
--- /orxonox/trunk/src/lib/coord/p_node.cc	(revision 4992)
+++ /orxonox/trunk/src/lib/coord/p_node.cc	(revision 4993)
@@ -1,4 +1,2 @@
-
-
 /*
    orxonox - the future of 3D-vertical-scrollers
@@ -60,5 +58,4 @@
 }
 
-
 /**
  *  constructor with coodinates
@@ -66,15 +63,12 @@
  * @param parent The parent-node of this node.
 */
-PNode::PNode (const Vector& absCoordinate, PNode* parent )
+PNode::PNode (const Vector& absCoor, PNode* parent )
 {
   this->init(parent);
 
-  this->absCoordinate = absCoordinate;
-
   if (likely(parent != NULL))
-  {
-    this->relCoordinate = this->absCoordinate - parent->getAbsCoor();
     parent->addChild (this);
-  }
+
+  this->setAbsCoor(absCoor);
 }
 
@@ -107,10 +101,9 @@
   this->children = new tList<PNode>();
   this->bRelCoorChanged = true;
-  this->bAbsCoorChanged = false;
   this->bRelDirChanged = true;
-  this->bAbsDirChanged = false;
   this->parent = parent;
 
-  this->toPosition = NULL;
+  // iterators
+  this->toCoordinate = NULL;
   this->toDirection = NULL;
   this->bias = 1.0;
@@ -167,6 +160,6 @@
 void PNode::setRelCoor (const Vector& relCoord)
 {
+  this->relCoordinate = relCoord;
   this->bRelCoorChanged = true;
-  this->relCoordinate = relCoord;
 }
 
@@ -176,5 +169,5 @@
  * @param y y-relative coordinates to its parent
  * @param z z-relative coordinates to its parent
-   \see  void PNode::setRelCoor (const Vector& relCoord)
+ * @see  void PNode::setRelCoor (const Vector& relCoord)
 */
 void PNode::setRelCoor (float x, float y, float z)
@@ -190,8 +183,8 @@
 void PNode::setRelCoorSoft(const Vector& relCoordSoft, float bias)
 {
-  if (likely(this->toPosition == NULL))
-    this->toPosition = new Vector();
-
-  *this->toPosition = relCoordSoft;
+  if (likely(this->toCoordinate == NULL))
+    this->toCoordinate = new Vector();
+
+  *this->toCoordinate = relCoordSoft;
   this->bias = bias;
 }
@@ -203,5 +196,5 @@
  * @param y y-relative coordinates to its parent
  * @param z z-relative coordinates to its parent
-   \see  void PNode::setRelCoorSoft (const Vector&, float)
+ * @see  void PNode::setRelCoorSoft (const Vector&, float)
  */
 void PNode::setRelCoorSoft (float x, float y, float z, float bias)
@@ -219,6 +212,22 @@
 void PNode::setAbsCoor (const Vector& absCoord)
 {
-  this->bAbsCoorChanged = true;
-  this->absCoordinate = absCoord;
+  if( likely(this->parentMode & PNODE_MOVEMENT))
+  {
+      /* if you have set the absolute coordinates this overrides all other changes */
+    if (likely(this->parent != NULL))
+      this->relCoordinate = absCoord - parent->getAbsCoor ();
+    else
+      this->relCoordinate = absCoord;
+  }
+  if( this->parentMode & PNODE_ROTATE_MOVEMENT)
+  {
+    if (likely(this->parent != NULL))
+      this->relCoordinate = absCoord - parent->getAbsCoor ();
+    else
+      this->relCoordinate = absCoord;
+  }
+
+  this->bRelCoorChanged = true;
+//  this->absCoordinate = absCoord;
 }
 
@@ -259,14 +268,6 @@
 void PNode::shiftCoor (const Vector& shift)
 {
-
-  if( unlikely(this->bAbsCoorChanged))
-    {
-      this->absCoordinate += shift;
-    }
-  else
-    {
-      this->relCoordinate += shift;
-      this->bRelCoorChanged = true;
-    }
+  this->relCoordinate += shift;
+  this->bRelCoorChanged = true;
 }
 
@@ -281,6 +282,6 @@
 void PNode::setRelDir (const Quaternion& relDir)
 {
+  this->relDirection = relDir;
   this->bRelCoorChanged = true;
-  this->relDirection = relDir;
 }
 
@@ -334,9 +335,17 @@
    absDirection. If you don't use this, the PNode won't recognize, that something
    has changed and won't update the children Nodes.
+ *
+ * FIXME ERROR HERE THIS IS IMPLEMENTED FALSELY
+ * @todo FIXME
 */
 void PNode::setAbsDir (const Quaternion& absDir)
 {
-  this->bAbsDirChanged = true;
-  this->absDirection = absDir;
+//  if (this->parent)
+    this->relDirection = absDir;// - parent->getAbsDir();
+//  else
+//    this->relDirection = absDir;
+
+  this->bRelDirChanged = true;
+//  this->absDirection = absDir;
 }
 
@@ -357,26 +366,10 @@
  *  shift coordinate (abs and rel)
  * @param shift vector
-
-   this function shifts the current coordinates about the vector shift. this is
-   usefull because from some place else you can:
-   PNode* someNode = ...;
-   Quaternion objectMovement = calculateShift();
-   someNode->shiftCoor(objectMovement);
-
-   elsewhere you would have to:
-   PNode* someNode = ...;
-   Quaternion objectMovement = calculateShift();
-   Quaternion currentCoor = someNode->getRelCoor();
-   Quaternion newCoor = currentCoor + objectMovement;
-   someNode->setRelCoor(newCoor);
-
-   yea right... shorter...
-
-   @todo implement this
+ * @todo implement this
 */
 void PNode::shiftDir (const Quaternion& shift)
 {
+  this->relDirection = this->relDirection * shift;
   this->bRelDirChanged = true;
-  this->relDirection = this->relDirection * shift;
 }
 
@@ -385,17 +378,18 @@
  * @param pNode child reference
  * @param parentMode on which changes the child should also change ist state
-
-   use this to add a child to this node.
-*/
-void PNode::addChild (PNode* pNode, int parentMode)
-{
-  if( likely(pNode->parent != NULL))
+ *
+ * use this to add a child to this node.
+*/
+void PNode::addChild (PNode* child, int parentMode)
+{
+  if( likely(child->parent != NULL))
     {
       PRINTF(4)("PNode::addChild() - reparenting node: removing it and adding it again\n");
-      pNode->parent->children->remove(pNode);
+      child->parent->children->remove(child);
     }
-  pNode->parentMode = parentMode;
-  pNode->parent = this;
-  this->children->add(pNode);
+  child->parentMode = parentMode;
+  child->parent = this;
+  this->children->add(child);
+  child->parentCoorChanged();
 }
 
@@ -411,18 +405,16 @@
 }
 
-
 /**
  *  removes a child from the node
  * @param pNode the child to remove from this pNode.
-
-   Children from pNode will not be lost, they are referenced to NullPointer
-*/
-void PNode::removeChild (PNode* pNode)
-{
-  pNode->remove();
-  this->children->remove (pNode);
-  pNode->parent = NULL;
-}
-
+ *
+ * Children from pNode will not be lost, they are referenced to NullPointer
+*/
+void PNode::removeChild (PNode* child)
+{
+  child->remove();
+  this->children->remove(child);
+  child->parent = NULL;
+}
 
 /**
@@ -447,7 +439,6 @@
 }
 
-
-/**
- *  sets the parent of this PNode
+/**
+ * sets the parent of this PNode
  * @param parent the Parent to set
 */
@@ -471,4 +462,5 @@
  * does the reparenting in a very smooth way
  * @param parentNode the new Node to connect this node to.
+ * @param bias the speed to iterate to this new Positions
  */
 void PNode::softReparent(PNode* parentNode, float bias)
@@ -477,9 +469,8 @@
     return;
 
-  //this->setRelCoorSoft(this->getRelCoor());
-  if (likely(this->toPosition == NULL))
+  if (likely(this->toCoordinate == NULL))
   {
-    this->toPosition = new Vector();
-    *this->toPosition = this->getRelCoor();
+    this->toCoordinate = new Vector();
+    *this->toCoordinate = this->getRelCoor();
   }
   if (likely(this->toDirection == NULL))
@@ -504,4 +495,9 @@
 }
 
+/**
+ * does the reparenting in a very smooth way
+ * @param parentName the name of the Parent to reconnect to
+ * @param bias the speed to iterate to this new Positions
+ */
 void PNode::softReparent(const char* parentName, float bias)
 {
@@ -511,14 +507,4 @@
 }
 
-
-/**
- *  set the mode of this parent manualy
- * @param parentMode the mode of the bind-type.
-*/
-void PNode::setParentMode (PARENT_MODE parentMode)
-{
-  this->parentMode = parentMode;
-}
-
 /**
  *  sets the mode of this parent manually
@@ -527,29 +513,6 @@
 void PNode::setParentMode (const char* parentingMode)
 {
-  if (!strcmp(parentingMode, "local-rotate"))
-    this->setParentMode(PNODE_LOCAL_ROTATE);
-  else  if (!strcmp(parentingMode, "rotate-movement"))
-    this->setParentMode(PNODE_ROTATE_MOVEMENT);
-  else  if (!strcmp(parentingMode, "movement"))
-    this->setParentMode(PNODE_MOVEMENT);
-  else  if (!strcmp(parentingMode, "all"))
-    this->setParentMode(PNODE_ALL);
-  else  if (!strcmp(parentingMode, "rotate-and-move"))
-    this->setParentMode(PNODE_ROTATE_AND_MOVE);
-}
-
-
-/**
- *  has to be called, if the parent coordinate has changed
-
-   normaly this will be done by the parent itself automaticaly. If you call this, you
-   will force an update of the coordinated of the node.
-*/
-/*
-void PNode::parentCoorChanged ()
-{
-  this->bRelCoorChanged = true;
-}
-*/
+  this->setParentMode(PNode::charToParentingMode(parentingMode));
+}
 
 /**
@@ -566,7 +529,7 @@
     {
       // movement for nodes with smoothMove enabled
-      if (unlikely(this->toPosition != NULL))
+      if (unlikely(this->toCoordinate != NULL))
       {
-        Vector moveVect = (*this->toPosition - this->getRelCoor()) *dt*bias;
+        Vector moveVect = (*this->toCoordinate - this->getRelCoor()) *dt*bias;
 
         if (likely(moveVect.len() >= .001))
@@ -576,6 +539,6 @@
         else
         {
-          delete this->toPosition;
-          this->toPosition = NULL;
+          delete this->toCoordinate;
+          this->toCoordinate = NULL;
           PRINTF(5)("SmoothMove of %s finished\n", this->getName());
         }
@@ -591,105 +554,64 @@
 /*        else
         {
-          delete this->toPosition;
-          this->toPosition = NULL;
+          delete this->toCoordinate;
+          this->toCoordinate = NULL;
           PRINTF(5)("SmoothMove of %s finished\n", this->getName());
         }*/
       }
 
+      // MAIN UPDATE /////////////////////////////////////
       this->lastAbsCoordinate = this->absCoordinate;
 
       PRINTF(5)("PNode::update - %s - (%f, %f, %f)\n", this->getName(), this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
 
-      if( likely(this->parentMode & PNODE_MOVEMENT))
-        {
-          if( unlikely(this->bAbsCoorChanged))
-            {
-              /* if you have set the absolute coordinates this overrides all other changes */
-              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
-            }
-          if( likely(this->bRelCoorChanged))
-            {
-              /* update the current absCoordinate */
-              this->absCoordinate = parent->getAbsCoor() + this->relCoordinate;
-            }
-        }
-
-      if( this->parentMode & PNODE_LOCAL_ROTATE)
-        {
-          if( unlikely(this->bAbsDirChanged))
-            {
-              /* if you have set the absolute coordinates this overrides all other changes */
-              this->relDirection = this->absDirection - parent->getAbsDir();
-            }
-          else if( likely(this->bRelDirChanged))
-            {
-              /* update the current absDirection - remember * means rotation around sth.*/
-              this->absDirection = parent->getAbsDir() * this->relDirection;
-            }
-        }
+      if(likely(this->parentMode & PNODE_MOVEMENT))
+      {
+        /* update the current absCoordinate */
+        this->absCoordinate = this->parent->getAbsCoor() + this->relCoordinate;
+      }
+
+      if( this->parentMode & PNODE_LOCAL_ROTATE && this->bRelDirChanged)
+      {
+        /* update the current absDirection - remember * means rotation around sth.*/
+        this->absDirection = parent->getAbsDir() * this->relDirection;
+      }
 
       if( this->parentMode & PNODE_ROTATE_MOVEMENT)
-        {
-          if( unlikely(this->bAbsCoorChanged))
-            {
-              /* if you have set the absolute coordinates this overrides all other changes */
-              this->relCoordinate = this->absCoordinate - parent->getAbsCoor ();
-            }
-          else if( likely(this->bRelCoorChanged))
-            {
-              /* update the current absCoordinate */
-              this->absCoordinate = parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
-            }
-        }
-
-
-      tIterator<PNode>* iterator = this->children->getIterator();
-      PNode* pn = iterator->nextElement();
-      while( pn != NULL)
-        {
-          /* if this node has changed, make sure, that all children are updated also */
-          if( likely(this->bRelCoorChanged || this->bAbsCoorChanged))
-            pn->parentCoorChanged ();
-          if( likely(this->bRelDirChanged || this->bAbsDirChanged))
-            pn->parentDirChanged ();
-
-          pn->update(dt);
-          //pn = this->children->nextElement();
-          pn = iterator->nextElement();
-        }
-      delete iterator;
-
-      this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
-      this->bRelCoorChanged = false;
-      this->bAbsCoorChanged = false;
-      this->bRelDirChanged = false;
-      this->bAbsDirChanged = false;
-    }
+      {
+        /* update the current absCoordinate */
+        this->absCoordinate = this->parent->getAbsCoor() + parent->getAbsDir().apply(this->relCoordinate);
+      }
+      /////////////////////////////////////////////////
+   }
   else
     {
       PRINTF(4)("NullParent::update - (%f, %f, %f)\n", this->absCoordinate.x, this->absCoordinate.y, this->absCoordinate.z);
-      this->absCoordinate = this->relCoordinate;
-      this->absDirection = this->getAbsDir () * this->relDirection;
-
+      if (this->bRelCoorChanged)
+        this->absCoordinate = this->relCoordinate;
+      if (this->bRelDirChanged)
+        this->absDirection = this->getAbsDir () * this->relDirection;
+    }
+
+    if(this->children->getSize() > 0)
+    {
       tIterator<PNode>* iterator = this->children->getIterator();
-      //PNode* pn = this->children->enumerate ();
       PNode* pn = iterator->nextElement();
       while( pn != NULL)
       {
         /* if this node has changed, make sure, that all children are updated also */
-          if( this->bRelCoorChanged || this->bAbsCoorChanged)
-            pn->parentCoorChanged ();
-          if( this->bRelDirChanged || this->bAbsDirChanged)
-            pn->parentDirChanged ();
-          pn->update (dt);
-          //pn = this->children->nextElement ();
-          pn = iterator->nextElement();
-        }
+        if( likely(this->bRelCoorChanged))
+          pn->parentCoorChanged ();
+        if( likely(this->bRelDirChanged))
+          pn->parentDirChanged ();
+
+        pn->update(dt);
+          //pn = this->children->nextElement();
+        pn = iterator->nextElement();
+      }
       delete iterator;
-      this->bRelCoorChanged = false;
-      this->bAbsCoorChanged = false;
-      this->bRelDirChanged = false;
-      this->bAbsDirChanged = false;
     }
+    this->velocity = (this->absCoordinate - this->lastAbsCoordinate) / dt;
+    this->bRelCoorChanged = false;
+    this->bRelDirChanged = false;
 }
 
@@ -708,5 +630,5 @@
   else
     PRINT(0)(" -");
-  PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f)\n",
+  PRINT(0)("PNode(%s::%s) - absCoord: (%0.2f, %0.2f, %0.2f), relCoord(%0.2f, %0.2f, %0.2f) - %s\n",
            this->getClassName(),
            this->getName(),
@@ -716,5 +638,6 @@
            this->relCoordinate.x,
            this->relCoordinate.y,
-           this->relCoordinate.z );
+           this->relCoordinate.z,
+           this->parentingModeToChar(parentMode));
   if (depth >= 2 || depth == 0)
   {
@@ -777,2 +700,46 @@
   glPopMatrix();
 }
+
+
+
+/////////////////////
+// HELPER_FUCTIONS //
+/////////////////////
+
+/**
+ * converts a parentingMode into a string that is the name of it
+ * @param parentingMode the ParentingMode to convert
+ * @return the converted string
+ */
+const char* PNode::parentingModeToChar(int parentingMode)
+{
+  if (parentingMode == PNODE_LOCAL_ROTATE)
+    return "local-rotate";
+  else if (parentingMode == PNODE_ROTATE_MOVEMENT)
+    return "rotate-movement";
+  else if (parentingMode == PNODE_MOVEMENT)
+    return "movement";
+  else if (parentingMode == PNODE_ALL)
+    return "all";
+  else if (parentingMode == PNODE_ROTATE_AND_MOVE)
+    return "rotate-and-move";
+}
+
+/**
+ * converts a parenting-mode-string into a int
+ * @param parentingMode the string naming the parentingMode
+ * @return the int corresponding to the named parentingMode
+ */
+PARENT_MODE PNode::charToParentingMode(const char* parentingMode)
+{
+  if (!strcmp(parentingMode, "local-rotate"))
+    return (PNODE_LOCAL_ROTATE);
+  else  if (!strcmp(parentingMode, "rotate-movement"))
+    return (PNODE_ROTATE_MOVEMENT);
+  else  if (!strcmp(parentingMode, "movement"))
+    return (PNODE_MOVEMENT);
+  else  if (!strcmp(parentingMode, "all"))
+    return (PNODE_ALL);
+  else  if (!strcmp(parentingMode, "rotate-and-move"))
+    return (PNODE_ROTATE_AND_MOVE);
+}
Index: /orxonox/trunk/src/lib/coord/p_node.h
===================================================================
--- /orxonox/trunk/src/lib/coord/p_node.h	(revision 4992)
+++ /orxonox/trunk/src/lib/coord/p_node.h	(revision 4993)
@@ -1,4 +1,4 @@
 /*!
-    \file p_node.h
+    @file p_node.h
   *  Definition of a parenting node
 
@@ -55,5 +55,5 @@
   PNode ();
   PNode(const TiXmlElement* root);
-  PNode (const Vector& absCoordinate, PNode* pNode);
+  PNode (const Vector& absCoor, PNode* pNode);
   virtual ~PNode ();
 
@@ -89,12 +89,12 @@
 
   /** @returns the Speed of the Node */
-  inline float getSpeed() const {return this->velocity.len();}
+  inline float getSpeed() const { return this->velocity.len(); };
   /** @returns the Velocity of the Node */
-  inline const Vector& getVelocity() const {return this->velocity;}
+  inline const Vector& getVelocity() const { return this->velocity; };
 
 
-  void addChild (PNode* pNode, int parentingMode = DEFAULT_MODE);
+  void addChild (PNode* child, int parentingMode = DEFAULT_MODE);
   void addChild (const char* childName);
-  void removeChild (PNode* pNode);
+  void removeChild (PNode* child);
   void remove();
 
@@ -107,5 +107,6 @@
   void softReparent(const char* parentName, float bias = 1.0);
 
-  void setParentMode (PARENT_MODE parentMode);
+  /** @param parentMode sets the parentingMode of this Node */
+  void setParentMode (PARENT_MODE parentMode) { this->parentMode = parentMode; };
   void setParentMode (const char* parentingMode);
   /** @returns the Parenting mode of this node */
@@ -117,4 +118,8 @@
   void debugDraw(float size = 1.0) const;
 
+
+  // helper functions //
+  static const char* parentingModeToChar(int parentingMode);
+  static PARENT_MODE charToParentingMode(const char* parentingMode);
  private:
   void init(PNode* parent);
@@ -124,11 +129,9 @@
   inline void parentDirChanged () { this->bRelDirChanged = true; }
   /** @returns the last calculated coordinate */
-  inline Vector getLastAbsCoor() {return this->lastAbsCoordinate;}
+  inline Vector getLastAbsCoor() { return this->lastAbsCoordinate; }
 
 
  private:
-  bool            bAbsCoorChanged;    //!< If Absolute Coordinate has changed since last time we checked
   bool            bRelCoorChanged;    //!< If Relative Coordinate has changed since last time we checked
-  bool            bAbsDirChanged;     //!< If Absolute Direction has changed since last time we checked
   bool            bRelDirChanged;     //!< If Relative Direction has changed since last time we checked
 
@@ -142,5 +145,5 @@
 
 
-  Vector*         toPosition;         //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
+  Vector*         toCoordinate;       //!< a position to which to iterate. (This is used in conjunction with softReparent.and set*CoorSoft)
   Quaternion*     toDirection;        //!< a direction to which to iterate. (This is used in conjunction with softReparent and set*DirSoft)
   float           bias;               //!< how fast to iterate to the given position (default is 1)
