Index: code/branches/AI/src/AIClass.h
===================================================================
--- code/branches/AI/src/AIClass.h	(revision 468)
+++ code/branches/AI/src/AIClass.h	(revision 495)
@@ -1,4 +1,4 @@
-#ifndef Flocking_Class
-#define Flocking_Class
+#ifndef AI_Class
+#define AI_Class
 
 #include <Ogre.h>
Index: code/branches/AI/src/Arrival.h
===================================================================
--- code/branches/AI/src/Arrival.h	(revision 468)
+++ code/branches/AI/src/Arrival.h	(revision 495)
@@ -3,6 +3,6 @@
 
 
-#ifndef Flocking_Class
-#define Flocking_Class
+#ifndef Arrival_Class
+#define Arrical_Class
 
 #include <Ogre.h>
@@ -59,4 +59,6 @@
 
   double relativeDirectApproach() {
+    // Maxspeed / accelerationForwards = time needed to break with max acceleration
+    // 2*getDistance()length/(MaxSpeed/accelerationForwards)^2 = required acceleration to arrive at the target with speed = 0
     return (accelerationForwards / (2*getDirection().length / (MaxSpeed/accelerationForwards)^2) );
   }
@@ -65,9 +67,19 @@
     Quaternion rotation = (0,0,0,0);
     if (relativeDirectApproach() > 1) {
-      rotation = speed.getRotationTo(getDirection());
-      // do that turn
-      
+      float length = speed.length();
+      speed = (speed+getDirection());
+      speed.normalise();
+      speed = speed*length; 
+      if (relativeDirectApproach > 4) {
+        //accelerate
+      }
+      else {
+        // speed will stay constant
+      }
+
+
     }
     else {
+
 
     }
Index: code/branches/AI/src/Flocking.h
===================================================================
--- code/branches/AI/src/Flocking.h	(revision 468)
+++ code/branches/AI/src/Flocking.h	(revision 495)
@@ -1,10 +1,4 @@
-//
-//
-//      TODO: testing orxonox -flocking interface
-//            testing algorithm
 
-// ueberpruefen ob vektoren relativ richtig berechnet werden
-//
-//My Flocking Class
+//Headerfile: Flocking.h
 
 #ifndef Flocking_Class
@@ -20,5 +14,4 @@
 #endif
 
-using namespace std;
 using namespace Ogre;
 
@@ -30,6 +23,11 @@
     Vector3 speed;  // speedvector of the element
     Vector3 acceleration;  // accelerationvector of the element
-    bool movable;  // movability of the element
+    bool movable;  // movability of the element, (false) gives the possiblity that an object can`t be moved by flocking but still gets into the calculation
+    static int const SEPERATIONDISTANCE = 300;  //detectionradius of seperation
+    static int const ALIGNMENTDISTANCE = 300;  //detectionradius of alignment
+    static int const COHESIONDISTANCE = 5000;  //detectionradius of cohesion
+    static int const ANZELEMENTS = 9;  //number of elements
 
+  //default constructor
   Element() {
     acceleration = (0,0,0);
@@ -39,4 +37,5 @@
   }
 
+  //constructor
   Element(Vector3 location_, Vector3 speed_, Vector3 acceleration_, bool movable_) {
     acceleration = acceleration_;
@@ -46,4 +45,5 @@
   }
 
+  //function to chance values of an element
   void setValues(Vector3 location_, Vector3 speed_, Vector3 acceleration_, bool movable_) {
     acceleration = acceleration_;
@@ -55,108 +55,80 @@
   //calculates the distance between the element and an other point given by temp
   float getDistance(Element temp) {
-    Vector3 distance = temp.location-location;  //this doesn't work
+    Vector3 distance = temp.location-location;
     return distance.length();
   }
 
-//EINFÜGEN DES ELEMENTS
-  void update(Element arrayOfElements[], const FrameEvent& time) {
-      if (this->movable == true) {calculateAcceleration(arrayOfElements);}
-
- /*   if (this->movable ==  true) {
-      calculateAcceleration(arrayOfElements);  //updates the acceleration
-      calculateSpeed(time);  //updates the speed
-      calculateLocation(time);  //updates the location
-    }   */
+  //updates the data of an element
+  void update(Element arrayOfElements[]) {
+    if (this->movable == true) {calculateAcceleration(arrayOfElements);} //if element is movable, calculate acceleration
   }
 
-//EINFÜGEN DES ELEMENTS
+  //calculates the new acceleration of an element
   void calculateAcceleration(Element arrayOfElements[]) {
-  //calculates the accelerationvector based on the steeringvectors of
-  //separtion, alignment and cohesion.
-  acceleration = separation(arrayOfElements) + alignment(arrayOfElements) + cohesion(arrayOfElements);
+    acceleration = separation(arrayOfElements) + alignment(arrayOfElements) + cohesion(arrayOfElements);  //acceleration consisting of flocking-functions
   }
 
-  void calculateSpeed(const FrameEvent& time) {
-    speed = speed + acceleration*time.timeSinceLastFrame;
+  //separation-function (keep elements separated, avoid crashs)
+  Vector3 separation(Element arrayOfElements[]) {
+    Vector3 steering = Vector3(0,0,0); //steeringvector
+    Vector3 inverseDistance = Vector3(0,0,0);  //vector pointing away from possible collisions
+    int numberOfNeighbour = 0;  //number of observed neighbours
+    float distance = 0;  // distance to the actual element
+    for(int i=0; i<ANZELEMENTS; i++) {  //go through all elements
+      Element actual = arrayOfElements[i];  //get the actual element
+      distance = getDistance(actual);  //get distance between this and actual
+      if ((distance > 0) && (distance < SEPERATIONDISTANCE)) {  //do only if actual is inside detectionradius
+        inverseDistance = (0,0,0);
+        inverseDistance = location-actual.location;  //calculate the distancevector heading towards this
+        //adaptation of the inverseDistance to the distance
+        if ((distance < 200) && (distance >= 120)) {inverseDistance = 2*inverseDistance;}
+        if ((distance < 120) && (distance >= 80)) {inverseDistance = 5*inverseDistance;}
+        if ((distance < 80) && (distance >= 40)) {inverseDistance = 10*inverseDistance;}
+        if ((distance < 40) && (distance > 0)) {inverseDistance = 10*inverseDistance;}
+        steering = steering + inverseDistance;  //add up all significant steeringvectors
+        numberOfNeighbour++;  //counts the elements inside the detectionradius
+      }
+    }
+    if(numberOfNeighbour > 0) { steering = steering / (float)numberOfNeighbour; }  //devide the sum of steeringvectors by the number of elements -> separation steeringvector
+    return steering;
   }
 
-  void calculateLocation(const FrameEvent& time) {
-    location = location + speed*time.timeSinceLastFrame;
-  }
-
-
-  Vector3 separation(Element arrayOfElements[]) {
-    Vector3* steering = new Vector3(0,0,0); //steeringvector
-    Vector3* inverseDistance = new Vector3(0,0,0);
+  //alignment-function (lead elements to the same heading)
+  Vector3 alignment(Element arrayOfElements[]) {
+    Vector3 steering = Vector3(0,0,0); //steeringvector
     int numberOfNeighbour = 0;  //number of observed neighbours
     float distance = 0;
     //go through all elements
-    for(int i=0; i<9; i++) {  //just working with 3 elements at the moment
+    for(int i=0; i<ANZELEMENTS; i++) {  //just working with 3 elements at the moment
       Element actual = arrayOfElements[i];  //get the actual element
-      distance = getDistance(actual);  //get distance between this and actual
-//DUMMY SEPERATION DETECTION DISTANCE =100
-      if ((distance > 0) && (distance < 200)) {  //do only if actual is inside detectionradius
-        *inverseDistance = (0,0,0);
-        *inverseDistance = location-actual.location;  //calculate the distancevector heading towards this
-        //*inverseDistance = inverseDistance->normalise(); //does this work correctly?  //normalise the distancevector
-        if ((distance < 100) && (distance >= 80)) {*inverseDistance = *inverseDistance*2;}
-        if ((distance < 80) && (distance >= 60)) {*inverseDistance = *inverseDistance*5;}
-        if ((distance < 60) && (distance >= 40)) {*inverseDistance = *inverseDistance*10;}
-        if ((distance < 40) && (distance > 0)) {*inverseDistance = *inverseDistance*20;}
-      //  *inverseDistance = *inverseDistance/distance;  //devide distancevector by distance (the closer the bigger gets the distancevector -> steeringvector)
-        *steering = *steering + *inverseDistance;  //add up all significant steeringvectors
+      float distance = getDistance(actual);  //get distance between this and actual
+      if ((distance > 0) && (distance < ALIGNMENTDISTANCE)) {  //check if actual element is inside detectionradius
+        steering = steering + actual.speed;  //add up all speedvectors inside the detectionradius
+        numberOfNeighbour++;  //counts the elements inside the detectionradius
+      }
+    }
+    if(numberOfNeighbour > 0) { steering = steering / (float)numberOfNeighbour; }  //devide the sum of steeringvectors by the number of elements -> alignment steeringvector
+    return steering;
+  }
+
+  //cohseion-function (keep elements close to each other)
+  Vector3 cohesion(Element arrayOfElements[]) {
+    Vector3 steering = Vector3(0,0,0); //steeringvector
+    int numberOfNeighbour = 0;  //number of observed neighbours
+    float distance = 0;
+    //go through all elements
+    for(int i=0; i<ANZELEMENTS; i++) {  //just working with 3 elements at the moment
+      Element actual = arrayOfElements[i];  //get the actual element
+      float distance = getDistance(actual);  //get distance between this and actual
+      if ((distance > 0) && (distance < COHESIONDISTANCE)) {  //check if actual element is inside detectionradius
+        steering = steering + actual.location;  //add up all locations of elements inside the detectionradius
         numberOfNeighbour++;  //counts the elements inside the detectionradius
       }
     }
     if(numberOfNeighbour > 0) {
-    *steering = *steering / (float)numberOfNeighbour;  //devide the sum of steeringvectors by the number of elements -> separation steeringvector
+      steering = steering  / (float)numberOfNeighbour;  //devide the sum steeringvector by the number of elements -> cohesion steeringvector
+      steering = steering - this->location;  //transform the vector for the ship
     }
-    cout<<*steering<<endl;
-    return *steering;
+    return steering;
   }
-
-  Vector3 alignment(Element arrayOfElements[]) {
-    Vector3* steering = new Vector3(0,0,0); //steeringvector
-    int numberOfNeighbour = 0;  //number of observed neighbours
-    float distance = 0;
-    //go through all elements
-    for(int i=0; i<9; i++) {  //just working with 3 elements at the moment
-      Element actual = arrayOfElements[i];  //get the actual element
-      float distance = getDistance(actual);  //get distance between this and actual
-//DUMMY ALIGNMENT DETECTION DISTANCE = 1000
-      if ((distance > 0) && (distance < 300)) {  //check if actual element is inside detectionradius
-        *steering = *steering + actual.speed;  //add up all speedvectors inside the detectionradius
-        numberOfNeighbour++;  //counts the elements inside the detectionradius
-      }
-    }
-    if(numberOfNeighbour > 0) {
-    *steering = *steering / (float)numberOfNeighbour;  //devide the sum of steeringvectors by the number of elements -> alignment steeringvector
-    }
-    return *steering;
-  }
-
-  Vector3 cohesion(Element arrayOfElements[]) {
-    Vector3* steering = new Vector3(0,0,0); //steeringvector
-    int numberOfNeighbour = 0;  //number of observed neighbours
-    float distance = 0;
-    //go through all elements
-    for(int i=0; i<9; i++) {  //just working with 3 elements at the moment
-      Element actual = arrayOfElements[i];  //get the actual element
-      float distance = getDistance(actual);  //get distance between this and actual
-// DUMMY COHESION DETECTION DISTANCE = 1000
-      if ((distance > 0) && (distance < 5000)) {  //check if actual element is inside detectionradius
-        *steering = *steering + actual.location;  //add up all locations of elements inside the detectionradius
-        numberOfNeighbour++;  //counts the elements inside the detectionradius
-      }
-     }
-    if(numberOfNeighbour > 0) {
-    *steering = *steering  / (float)numberOfNeighbour;  //devide the sum steeringvector by the number of elements -> cohesion steeringvector
-    *steering = *steering - this->location;  // (?) Koordinatensystem?
-    }
-    return *steering;
-  }
-};
-
-
-
-//End of My Flocking Class
+};     //End of class Element
Index: code/branches/AI/src/orxonox.cc
===================================================================
--- code/branches/AI/src/orxonox.cc	(revision 468)
+++ code/branches/AI/src/orxonox.cc	(revision 495)
@@ -44,5 +44,5 @@
 #include "loader/LevelLoader.h"
 #include "Flocking.h"
-#include "AIClass.h"
+#include "Wander.h"
 
 // some tests to see if enet works without includsion
@@ -86,6 +86,8 @@
 
 Element arrayOfElements[9];
-
- // float time = 0;
+Wander walker;
+int counter = 0;
+int times = 0;
+
 
 
@@ -110,28 +112,35 @@
       SceneManager *mgr = root_->getSceneManager("Default SceneManager");
 
-      arrayOfElements[0].update(arrayOfElements, evt);
-      arrayOfElements[1].update(arrayOfElements, evt);
-      arrayOfElements[2].update(arrayOfElements, evt);
-      arrayOfElements[3].update(arrayOfElements, evt);
-      arrayOfElements[4].update(arrayOfElements, evt);
-      arrayOfElements[5].update(arrayOfElements, evt);
-      arrayOfElements[6].update(arrayOfElements, evt);
-      arrayOfElements[7].update(arrayOfElements, evt);
-      arrayOfElements[8].update(arrayOfElements, evt);
-
- /*   arrayOfElements[0].update(arrayOfElements, evt);
-      arrayOfElements[1].update(arrayOfElements, evt);
-      arrayOfElements[2].update(arrayOfElements, evt);
-      arrayOfElements[3].update(arrayOfElements, evt);
-      arrayOfElements[4].update(arrayOfElements, evt);   */
-
+/*    // RUN WANDER
+
+      walker.update();
+      walker.speed = walker.speed + 10*walker.acceleration*evt.timeSinceLastFrame;
+      walker.location = walker.location + 10*walker.speed*evt.timeSinceLastFrame;
+      walker.acceleration  = (0,0,0);
+      mgr->getSceneNode("HeadNode10")->setPosition(walker.location);
+
+*/   // END RUN WANDER
+
+
+
+
+     //  RUN FLOCKING
+
+      arrayOfElements[8].location = 100*Vector3(Math::Cos(Math::DegreesToRadians(counter)/10),Math::Sin(Math::DegreesToRadians(counter)/10),Math::Cos(Math::DegreesToRadians(counter+(counter-180)/2)/10));
+
+      arrayOfElements[0].update(arrayOfElements);
+      arrayOfElements[1].update(arrayOfElements);
+      arrayOfElements[2].update(arrayOfElements);
+      arrayOfElements[3].update(arrayOfElements);
+      arrayOfElements[4].update(arrayOfElements);
+      arrayOfElements[5].update(arrayOfElements);
+      arrayOfElements[6].update(arrayOfElements);
+      arrayOfElements[7].update(arrayOfElements);
+      arrayOfElements[8].update(arrayOfElements);
 
       for(int i=0; i<9; i++) {
-
-         arrayOfElements[i].speed = 0.995*arrayOfElements[i].speed + arrayOfElements[i].acceleration*evt.timeSinceLastFrame;
-
-         arrayOfElements[i].location = arrayOfElements[i].location + arrayOfElements[i].speed*evt.timeSinceLastFrame;
-
-         arrayOfElements[i].acceleration  = (0,0,0);
+        arrayOfElements[i].speed = 0.995*arrayOfElements[i].speed + arrayOfElements[i].acceleration*evt.timeSinceLastFrame;
+        arrayOfElements[i].location = arrayOfElements[i].location + arrayOfElements[i].speed*evt.timeSinceLastFrame;
+        arrayOfElements[i].acceleration  = (0,0,0);
       }
 
@@ -146,15 +155,9 @@
       mgr->getSceneNode("HeadNode9")->setPosition(arrayOfElements[8].location);
 
-
-      /*
-
-      mgr->getSceneNode("HeadNode9")->setPosition(Vector3(200*cos(10*time),0,0));
-      time = time + evt.timeSinceLastFrame;
-
-     */
-
-
-
-    //  mgr->getSceneNode("HeadNode1")->yaw((Radian)10*evt.timeSinceLastFrame);
+      counter = counter + 1;
+      counter = counter%7200;
+
+      // END RUN FLOCKING 
+
     }
 
@@ -272,5 +275,7 @@
       cam->lookAt(Vector3(0,0,0));
       Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
-      example();  //my stuff
+
+      //Invoke example to test AI
+      example();
     }
 
@@ -321,11 +326,21 @@
     }
 
-    //declaration of the 3 Ogreheads
-   //muss leider global sein.....
-    //Element* arrayOfElements[2];
-
     void example() {
     SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
     mgr->setAmbientLight(ColourValue(1.0,1.0,1.0));
+
+/*  //TEST DATA WANDER
+
+    Entity* ent10 = mgr->createEntity("Head10", "ogrehead.mesh");
+    SceneNode *node10 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode10", Vector3(0,0,0));
+    node10->attachObject(ent10);
+    Vector3 temp;
+    temp = (0,0,0);
+    walker.setValues(node10->getPosition(),temp,temp,true);
+
+*/  //END TEST DATA WANDER
+
+
+//   TEST DATA FLOCKING
 
     Entity* ent1 = mgr->createEntity("Head1", "ogrehead.mesh");
@@ -347,13 +362,5 @@
     SceneNode *node7 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode7", Vector3(-150,-150,0));
     SceneNode *node8 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode8", Vector3(-150,150,0));
-    SceneNode *node9 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode9", Vector3(0,0,0));  
-
-// follwing camera
-
- //  Camera *cam = mgr->getCamera("Camera");
- //  node1->attachObject(cam);
-
-
-
+    SceneNode *node9 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode9", Vector3(0,0,0));
 
     node1->attachObject(ent1);
@@ -376,7 +383,5 @@
     ElementLocationArray[7] = node8->getPosition();
     ElementLocationArray[8] = node9->getPosition();
-/*
-ElementLocationArray[5] = node6->getPosition();
-ElementLocationArray[6] = node7->getPosition();*/
+
     ElementSpeedArray[0] = (0,0,0);
     ElementSpeedArray[1] = (0,0,0);
@@ -388,7 +393,5 @@
     ElementSpeedArray[7] = (0,0,0);
     ElementSpeedArray[8] = (0,0,0);
-/*
-ElementSpeedArray[5] = (0,0,0);
-ElementSpeedArray[6] = (0,0,0); */
+
     ElementAccelerationArray[0] = (0,0,0);
     ElementAccelerationArray[1] = (0,0,0);
@@ -400,7 +403,5 @@
     ElementAccelerationArray[7] = (0,0,0);
     ElementAccelerationArray[8] = (0,0,0);
-/*
-ElementAccelerationArray[5] = (0,0,0);
-ElementAccelerationArray[6] = (0,0,0); */
+
     arrayOfElements[0].setValues( ElementLocationArray[0], ElementSpeedArray[0], ElementAccelerationArray[0], true);
     arrayOfElements[1].setValues( ElementLocationArray[1], ElementSpeedArray[1], ElementAccelerationArray[1], true);
@@ -412,21 +413,6 @@
     arrayOfElements[7].setValues( ElementLocationArray[7], ElementSpeedArray[7], ElementAccelerationArray[7], true);
     arrayOfElements[8].setValues( ElementLocationArray[8], ElementSpeedArray[8], ElementAccelerationArray[8], false);
-/*
-arrayOfElements[5].setValues( ElementLocationArray[5], ElementSpeedArray[5], ElementAccelerationArray[5], false);
-arrayOfElements[6].setValues( ElementLocationArray[6], ElementSpeedArray[6], ElementAccelerationArray[6], false);*/
-
-
-
-
-   /* for (int i=0; i<3; i++) {
-      Element* arrayOfElements[i] = new Element( ElementLocationArray[i], ElementSpeedArray[i], ElementAccelerationArray[i] );
-    } */
-   /* for (int i=0; i<3; i++) {
-    arrayOfElements[i]->update(arrayOfElements);
-    }  */
-
-//testing AIPilot -> function steer
-  //  AIPilot temp;
-  //  Vector3 foo = temp.steer(Vector3(0,0,1));
+
+   // END TEST DATA FLOCKING
 
 
