Index: /code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc
===================================================================
--- /code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc	(revision 9516)
+++ /code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc	(revision 9517)
@@ -42,4 +42,5 @@
 #include "BulletCollision/CollisionShapes/btCollisionShape.h"
 
+
 namespace orxonox
 {
@@ -57,13 +58,13 @@
 ;        std::vector<RaceCheckPoint*> checkpoints;
 
-        virtualCheckPointIndex=-2;
-        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
+        virtualCheckPointIndex = -2;
+        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
         {
             checkpoints = it->getAllCheckpoints();
-            nextRaceCheckpoint_=it->findCheckpoint(0);
+            nextRaceCheckpoint_ = it->findCheckpoint(0);
         }
 
         OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
-        checkpoints_=checkpoints;
+        checkpoints_ = checkpoints;
         /*orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;
         for(std::vector<RaceCheckPoint*>::iterator it=checkpoints_.begin(); it!=checkpoints_.end(); it++)
@@ -86,5 +87,5 @@
         }//ausgabe*/
 
-        for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it)
+        for (std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it != checkpoints.end(); ++it)
         {
             std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints());
@@ -124,5 +125,5 @@
 
         int i;
-        for (i=-2; findCheckpoint(i)!= NULL; i--)
+        for (i = -2; findCheckpoint(i) != NULL; i--)
         {
             continue;
@@ -140,5 +141,4 @@
         XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
         XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode);
-
     }
 
@@ -149,5 +149,5 @@
     std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(std::vector<RaceCheckPoint*> allCheckpoints)
     {
-        std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoit was reached (for simulation)
+        std::map<RaceCheckPoint*, int> * zaehler = new std::map<RaceCheckPoint*, int>(); // counts how many times the checkpoint was reached (for simulation)
         for (unsigned int i = 0; i < allCheckpoints.size(); i++)
         {
@@ -158,5 +158,5 @@
         std::vector<RaceCheckPoint*> returnVec;
         returnVec.clear();
-        for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler->begin(); iter!= zaehler->end(); iter++)
+        for (std::map<RaceCheckPoint*, int>::iterator iter = zaehler->begin(); iter != zaehler->end(); iter++)
         {
             if (iter->second == maxWays)
@@ -188,10 +188,11 @@
             for (std::set<int>::iterator it = currentCheckpoint->getVirtualNextCheckpoints().begin(); it!= currentCheckpoint->getVirtualNextCheckpoints().end(); ++it)
             {
-                if(currentCheckpoint==findCheckpoint(*it))
+                if(currentCheckpoint == findCheckpoint(*it))
                 {
                     //orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
                     continue;
                 }
-                if(findCheckpoint(*it)==NULL){orxout()<<"Problematic Point: "<<(*it)<<endl;}
+                if(findCheckpoint(*it) == NULL)
+                    {orxout()<<"Problematic Point: "<<(*it)<<endl;}
                 numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
             }
@@ -219,6 +220,5 @@
     RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
     {
-        int distances[] =
-        {   -1, -1, -1};
+        int distances[] = {-1, -1, -1};
         int temp_i = 0;
         for (std::set<int>::iterator it =raceCheckpoint->getVirtualNextCheckpoints().begin(); it!= raceCheckpoint->getVirtualNextCheckpoints().end(); ++it)
@@ -266,9 +266,9 @@
         {
             int minimum = std::numeric_limits<int>::max();
-            for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it!= currentCheckPoint->getVirtualNextCheckpoints().end(); ++it)
+            for (std::set<int>::iterator it = currentCheckPoint->getVirtualNextCheckpoints().begin(); it != currentCheckPoint->getVirtualNextCheckpoints().end(); ++it)
             {
                 int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length());
 
-                minimum= std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(*it), currentCheckPoint->getPosition()));
+                minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(*it), currentCheckPoint->getPosition()));
                 // minimum of distanz from 'currentPosition' to the next static Checkpoint
             }
@@ -374,8 +374,8 @@
         {//Checkpoint erreicht
 
-            currentRaceCheckpoint_=nextRaceCheckpoint_;
+            currentRaceCheckpoint_ = nextRaceCheckpoint_;
             OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
             nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
-            lastPositionSpaceship=this->getControllableEntity()->getPosition();
+            lastPositionSpaceship = this->getControllableEntity()->getPosition();
             //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
         }
@@ -383,12 +383,12 @@
         {
             nextRaceCheckpoint_ = adjustNextPoint();
-            lastPositionSpaceship=this->getControllableEntity()->getPosition();
+            lastPositionSpaceship = this->getControllableEntity()->getPosition();
         }
 
         // Abmessung fuer MINDISTANCE gut;
 
-        else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE )
-        {
-            this->moveToPosition(Vector3(rnd()*100,rnd()*100,rnd()*100));
+        else if((lastPositionSpaceship - this->getControllableEntity()->getPosition()).length()/dt < MINDISTANCE )
+        {
+            this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100));
             this->spin();
             //orxout(user_status) << "Mindistance reached" << std::endl;
@@ -396,5 +396,5 @@
         }
         //orxout(user_status) << "dt= " << dt << ";  distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl;
-        lastPositionSpaceship=this->getControllableEntity()->getPosition();
+        lastPositionSpaceship = this->getControllableEntity()->getPosition();
         this->moveToPosition(nextRaceCheckpoint_->getPosition());
     }
@@ -403,10 +403,10 @@
     bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse)
     {
-        if(abs(pointToPoint.x)<groesse.x)
-        return true;
-        if(abs(pointToPoint.y)<groesse.y)
-        return true;
-        if(abs(pointToPoint.z)<groesse.z)
-        return true;
+        if(abs(pointToPoint.x) < groesse.x)
+            return true;
+        if(abs(pointToPoint.y) < groesse.y)
+            return true;
+        if(abs(pointToPoint.z) < groesse.z)
+            return true;
 
     }
@@ -415,12 +415,12 @@
     {
 
-        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
-        Vector3 centerCP1=racepoint1->getPosition();
+        Vector3 cP1ToCP2 = (racepoint2->getPosition() - racepoint1->getPosition()) / (racepoint2->getPosition() - racepoint1->getPosition()).length(); //unit Vector
+        Vector3 centerCP1 = racepoint1->getPosition();
         btVector3 positionObject;
         btScalar radiusObject;
 
-        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it!=allObjects.end(); ++it)
-        {
-            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++)
+        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
+        {
+            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)
             {
                 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
@@ -441,5 +441,5 @@
     }
 
-    void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2,std::vector<StaticEntity*> allObjects)
+    void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, std::vector<StaticEntity*> allObjects)
     {
         Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
@@ -448,7 +448,7 @@
         btScalar radiusObject;
 
-        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it!=allObjects.end(); ++it)
-        {
-            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++)
+        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
+        {
+            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)
             {
                 btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
@@ -458,21 +458,26 @@
                 currentShape->getBoundingSphere(positionObject,radiusObject);
                 Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
-                if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0)
-                {
-                    Vector3 zufall;
-                    Vector3 objectmiddle=positionObjectNonBT;
-                    do
-                    {
+				Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT);
+
+				if(norm_r_CP.length == 0){
+					Vector3 zufall;
+                    do{
                         zufall=Vector3(rnd(),rnd(),rnd());//random
-                    }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0);
-
-                    Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition());
-                    // a'/b'=a/b => a' =b'*a/b
-                    float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radiusObject*radiusObject)*radiusObject;
-                    RaceCheckPoint* newVirtualCheckpoint=addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec);
-                    //placeVirtualCheckpoints(newVirtualCheckpoint, racepoint2);
-                    return;
-                }
-
+                    }while((zufall.crossProduct(cP1ToCP2)).length() == 0);
+					norm_r_CP=zufall.crossProduct(cP1ToCP2);
+				}
+				Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2);
+				float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
+				float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
+				//TODO float distanz=max(distanzToCP1,distanzToCP2);
+				float distanz = 0.0f; //TEMPORARY
+				Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length();
+				Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length();
+				if((newCheckpointPositionPos-centerCP1).length+(newCheckpointPositionPos-(centerCP1+cP1ToCP2)).length < (newCheckpointPositionNeg-centerCP1).length+(newCheckpointPositionNeg-(centerCP1+cP1ToCP2)).length){
+					RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos);
+				}else{
+					RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg);
+				}
+				return;
             }
         }
@@ -489,5 +494,5 @@
         {
 
-            if (dynamic_cast<RaceCheckPoint*>(*it)!=NULL)
+            if (dynamic_cast<RaceCheckPoint*>(*it) != NULL)
             {   continue;} // does not work jet
 
Index: /code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h
===================================================================
--- /code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h	(revision 9516)
+++ /code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h	(revision 9517)
@@ -32,4 +32,5 @@
 #include "gametypes/Gametype.h"
 #include "gametypes/RaceCheckPoint.h"
+#include "util/Math.h"
 
 namespace orxonox
