Index: code/trunk/src/modules/objects/ForceField.cc
===================================================================
--- code/trunk/src/modules/objects/ForceField.cc	(revision 7652)
+++ code/trunk/src/modules/objects/ForceField.cc	(revision 7673)
@@ -27,4 +27,9 @@
  */
 
+/**
+@file ForceField.cc
+@brief Implementation of the ForceField class.
+*/
+
 #include "ForceField.h"
 
@@ -36,4 +41,7 @@
 {
     CreateFactory(ForceField);
+    
+    /*static*/ const std::string modeStringNormal_s = "tube";
+    /*static*/ const std::string modeStringSphere_s = "sphere";
 
     ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
@@ -43,10 +51,13 @@
         //Standard Values
         this->setDirection(Vector3::ZERO);
-        velocity_ = 100;
-        diameter_ = 500;
-        length_ = 5000;
+        this->velocity_ = 100;
+        this->diameter_ = 500;
+        this->length_ = 5000;
+        this->mode_ = ForceFieldMode::tube;
     }
 
-    ForceField::~ForceField() {}
+    ForceField::~ForceField()
+    {
+    }
 
     void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
@@ -58,24 +69,73 @@
         XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
         XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
+        XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode);
     }
 
     void ForceField::tick(float dt)
     {
+        // Iterate over all objects that could possibly be affected by the ForceField.
         for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
         {
-            //calculate from
-            Vector3 directionVec = this->getOrientation() * WorldEntity::FRONT;
-            directionVec.normalise();
+            if(this->mode_ == ForceFieldMode::tube)
+            {
+                // The direction of the orientation of the force field.
+                Vector3 direction = this->getOrientation() * WorldEntity::FRONT;
+                direction.normalise();
 
-            Vector3 distanceVec = it->getWorldPosition() - (this->getWorldPosition() + (this->length_ / 2 * directionVec));
+                // Vector from the center of the force field to the object its acting on.
+                // TODO: This could probably be simplified.
+                Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction));
+                
+                // The object is outside of the length of the ForceField.
+                if(distanceVector.length() > this->halfLength_)
+                    return;
 
-            //distance from centervector of the field (
-            float distFromCenterVec = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(directionVec)).length();
+                // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector)
+                float distanceFromDirectionVector = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(direction)).length();
+                
+                // If the object in a tube of radius diameter/2 around the direction of orientation.
+                if(distanceFromDirectionVector >= this->radius_)
+                    return;
 
-            if (distanceVec.length() < this->length_ / 2 && distFromCenterVec < diameter_ / 2)
+                // Apply a force to the object in the direction of the orientation.
+                // The force is highest when the object is directly on the direction vector, with a linear decrease, finally reaching zero, when distanceFromDirectionVector = radius.
+                it->applyCentralForce(((this->radius_ - distanceFromDirectionVector)/(this->radius_)) * this->velocity_ * direction);
+            }
+            else if(this->mode_ == ForceFieldMode::sphere)
             {
-                //normalize distance from center
-                it->applyCentralForce(((diameter_ / 2 - distFromCenterVec) / (diameter_ / 2)) * directionVec * velocity_);
+                Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();
+                float distance = distanceVector.length();
+                if (distance < this->radius_)
+                {
+                    distanceVector.normalise();
+                    it->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector);
+                }
             }
+        }
+    }
+    
+    void ForceField::setMode(const std::string& mode)
+    {
+        if(mode == ForceField::modeStringTube_s)
+            this->mode_ = ForceFieldMode::tube;
+        else if(mode == ForceField::modeStringSphere_s)
+            this->mode_ = ForceFieldMode::sphere;
+        else
+        {
+            COUT(2) << "Wrong mode '" << mode << "' in ForceField. Setting to 'tube'." << std::endl;
+            this->mode_ = ForceFieldMode::tube;
+        }
+    }
+    
+    inline const std::string& ForceField::getMode(void)
+    {
+        switch(this->mode_)
+        {
+            case ForceFieldMode::tube:
+                return ForceField::modeStringTube_s;
+            case ForceFieldMode::sphere:
+                return ForceField::modeStringSphere_s;
+            default:
+                return ForceField::modeStringTube_s;
         }
     }
Index: code/trunk/src/modules/objects/ForceField.h
===================================================================
--- code/trunk/src/modules/objects/ForceField.h	(revision 7652)
+++ code/trunk/src/modules/objects/ForceField.h	(revision 7673)
@@ -23,5 +23,5 @@
  *      Aurelian Jaggi
  *   Co-authors:
- *      ...
+ *      Damian 'Mozork' Frick
  *
  */
@@ -31,4 +31,10 @@
     @brief Definition of the ForceField class.
     @ingroup Objects
+*/
+
+/**
+@file ForceField.h
+@brief Definition of the ForceField class.
+@inGroup Objects
 */
 
@@ -43,34 +49,80 @@
 namespace orxonox
 {
+
+    /**
+    @brief
+        The mode of the ForceField.
+    
+    @inGroup Objects
+    */
+    namespace ForceFieldMode
+    {
+        enum Value {
+            tube, //!< The ForceField has a tube shape.
+            sphere //!< The ForceField has a spherical shape.
+            
+        };
+    }
+
+    /**
+    @brief
+        Implements a force field, that applies a force to any @ref orxonox::MoblieEnity "MobileEntity" that enters its range.
+        
+        The following parameters can be set to specify the behavior of the ForceField.
+        - @b velocity The amount of force the ForceField excerts.
+        - @b diameter The diameter of the ForceField.
+        - @b length The length of the ForceField.
+        - @b mode The mode the ForceField is in. For mode:
+        -- <em>tube</em> A ForceField which exerts force only in the direction it is oriented. The force is only exerted on objects that are in a tube of length <em>length</em> and diameter <em>diameter</em>. The magintude of the force is proportional to the <em><velocity/em>, being highest when an object is in the middle of the tube (radius-wise), linearly decreasing with greater radii and finally reaching zero, when the object is <code>diameter/2</code> away from the orientation vector.
+        -- <em>sphere</em> A Force Field which exerts force radially away from itself, with the greatest magnitude (proportional to <em>velocity</em>) being in the origin of the ForceField, linearly decreasing with respect to the distance to the origin and finally reaching zero at distance <code>diameter/2</code>.
+        
+    @author
+        Aurelian Jaggi
+        
+    @author
+        Damian 'Mozork' Frick
+        
+    @inGroup Objects
+    */
     class _ObjectsExport ForceField : public StaticEntity, public Tickable
     {
-    public:
-        ForceField(BaseObject* creator);
-        virtual ~ForceField();
-        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-        virtual void tick(float dt);
+        public:
+            ForceField(BaseObject* creator);
+            virtual ~ForceField();
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            virtual void tick(float dt);
 
-        inline void setVelocity(float vel)
-            { this->velocity_ = vel; }
+            inline void setVelocity(float vel)
+                { this->velocity_ = vel; }
 
-        inline float getVelocity()
-            { return velocity_; }
+            inline float getVelocity()
+                { return this->velocity_; }
 
-        inline void setDiameter(float diam)
-            { this->diameter_ = diam; }
+            inline void setDiameter(float diam)
+                { this->diameter_ = diam; this->radius_ = diam/2; }
 
-        inline float getDiameter()
-            { return diameter_; }
+            inline float getDiameter()
+                { return this->diameter_; }
 
-        inline void setLength(float l)
-            { this->length_ = l; }
+            inline void setLength(float l)
+                { this->length_ = l; this->halfLength_ = l/2; }
 
-        inline float getLength()
-            { return length_; }
+            inline float getLength()
+                { return this->length_; }
+                
+            void setMode(const std::string& mode);
+                
+            inline const std::string& getMode(void);
 
-    private:
-        float velocity_;
-        float diameter_;
-        float length_;
+        private:
+            static const std::string modeStringTube_s;
+            static const std::string modeStringSphere_s;
+        
+            float velocity_;
+            float diameter_;
+            float radius_;
+            float length_;
+            float halfLength_;
+            ForceFieldMode::Value mode_;
   };
 }
