[Orxonox-commit 2978] r7676 - code/trunk/src/modules/objects

dafrick at orxonox.net dafrick at orxonox.net
Fri Nov 26 08:44:48 CET 2010


Author: dafrick
Date: 2010-11-26 08:44:48 +0100 (Fri, 26 Nov 2010)
New Revision: 7676

Modified:
   code/trunk/src/modules/objects/ForceField.cc
   code/trunk/src/modules/objects/ForceField.h
Log:
Some documentation and simplification


Modified: code/trunk/src/modules/objects/ForceField.cc
===================================================================
--- code/trunk/src/modules/objects/ForceField.cc	2010-11-25 23:06:43 UTC (rev 7675)
+++ code/trunk/src/modules/objects/ForceField.cc	2010-11-26 07:44:48 UTC (rev 7676)
@@ -27,8 +27,8 @@
  */
 
 /**
- at file ForceField.cc
- at brief Implementation of the ForceField class.
+    @file ForceField.cc
+    @brief Implementation of the ForceField class.
 */
 
 #include "ForceField.h"
@@ -40,38 +40,55 @@
 namespace orxonox
 {
     CreateFactory(ForceField);
-    
+
     /*static*/ const std::string ForceField::modeTube_s = "tube";
     /*static*/ const std::string ForceField::modeSphere_s = "sphere";
 
+    /**
+    @brief
+        Constructor. Registers the object and initializes some values.
+    */
     ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
     {
         RegisterObject(ForceField);
 
         //Standard Values
         this->setDirection(Vector3::ZERO);
-        this->velocity_ = 100;
-        this->diameter_ = 500;
-        this->length_ = 5000;
+        this->setVelocity(100);
+        this->setDiameter(500);
+        this->setLength(2000);
         this->mode_ = forceFieldMode::tube;
     }
 
+    /**
+    @brief
+        Destructor.
+    */
     ForceField::~ForceField()
     {
     }
 
+    /**
+    @brief
+        Creates a ForceField object through XML.
+    */
     void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     {
         SUPER(ForceField, XMLPort, xmlelement, mode);
 
-        //For correct xml import use: position, direction, velocity, scale
         XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
         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);
-        COUT(0) << "ForceField created " << this->velocity_ << " " << this->diameter_ << " " << this->radius_ << " " << this->length_ << " " << this->halfLength_ << " " << this->getMode() << std::endl;
     }
 
+    /**
+    @brief
+        A method that is called every tick.
+        Implements the behavior of teh ForceField.
+    @param dt
+        The amount of time that elapsed since the last tick.
+    */
     void ForceField::tick(float dt)
     {
         if(this->mode_ == forceFieldMode::tube)
@@ -86,15 +103,15 @@
                 // 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_)
                     continue;
 
                 // 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 the object in a tube of radius 'radius' around the direction of orientation.
                 if(distanceFromDirectionVector >= this->radius_)
                     continue;
 
@@ -110,15 +127,23 @@
             {
                 Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();
                 float distance = distanceVector.length();
+                // If the object is within 'radius' distance.
                 if (distance < this->radius_)
                 {
                     distanceVector.normalise();
+                    // Apply a force proportional to the velocity, with highest force at the origin of the sphere, linear decreasing until reaching a distance of 'radius' from the origin, where the force reaches zero. 
                     it->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector);
                 }
             }
         }
     }
-    
+
+    /**
+    @brief
+        Set the mode of the ForceField.
+    @param mode
+        The mode as a string.
+    */
     void ForceField::setMode(const std::string& mode)
     {
         if(mode == ForceField::modeTube_s)
@@ -131,8 +156,14 @@
             this->mode_ = forceFieldMode::tube;
         }
     }
-    
-    inline const std::string& ForceField::getMode(void)
+
+    /**
+    @brief
+        Get the mode of the ForceField.
+    @return
+        Returns the mode of the ForceField as a string.
+    */
+    const std::string& ForceField::getMode(void)
     {
         switch(this->mode_)
         {
@@ -144,9 +175,5 @@
                 return ForceField::modeTube_s;
         }
     }
+
 }
-
-
-
-
-

Modified: code/trunk/src/modules/objects/ForceField.h
===================================================================
--- code/trunk/src/modules/objects/ForceField.h	2010-11-25 23:06:43 UTC (rev 7675)
+++ code/trunk/src/modules/objects/ForceField.h	2010-11-26 07:44:48 UTC (rev 7676)
@@ -32,12 +32,6 @@
     @ingroup Objects
 */
 
-/**
- at file ForceField.h
- at brief Definition of the ForceField class.
- at inGroup Objects
-*/
-
 #ifndef _ForceField_H__
 #define _ForceField_H__
 
@@ -52,80 +46,99 @@
     /**
     @brief
         The mode of the ForceField.
-    
-    @inGroup Objects
+
+    @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 velocity The amount of force the ForceField excerts. Default is 100.
+        - @b diameter The diameter of the ForceField. Default is 500.
+        - @b length The length of the ForceField. Default is 2000.
         - @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>.
-        
+            - <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>.
+            Default is <em>tube</em>.
+
     @author
         Aurelian Jaggi
-        
+
     @author
         Damian 'Mozork' Frick
-        
-    @inGroup Objects
+
+    @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);
 
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML.
+            virtual void tick(float dt); //!< A method that is called every tick.
+
+            /**
+            @brief Set the velocity of the ForceField.
+            @param vel The velocity to be set.
+            */
             inline void setVelocity(float vel)
                 { this->velocity_ = vel; }
-
+            /**
+            @brief Get the velocity of the ForceField.
+            @return Returns the velocity of the ForceField.
+            */
             inline float getVelocity()
                 { return this->velocity_; }
 
+            /**
+            @brief Set the diameter of the ForceField.
+            @param diam The diameter to be set.
+            */
             inline void setDiameter(float diam)
-                { this->diameter_ = diam; this->radius_ = diam/2; }
-
+                { this->radius_ = diam/2; }
+            /**
+            @brief Get the diameter of the ForceField.
+            @return Returns the diameter of the ForceField.
+            */
             inline float getDiameter()
-                { return this->diameter_; }
+                { return this->radius_*2; }
 
+            /**
+            @brief Set the length of the ForceField.
+            @param l The length to be set.
+            */
             inline void setLength(float l)
-                { this->length_ = l; this->halfLength_ = l/2; }
-
+                { this->halfLength_ = l/2; }
+            /**
+            @brief Get the length of the ForceField.
+            @return Returns the length of the ForceField.
+            */
             inline float getLength()
-                { return this->length_; }
-                
-            void setMode(const std::string& mode);
-                
-            inline const std::string& getMode(void);
+                { return this->halfLength_*2; }
 
+            void setMode(const std::string& mode); //!< Set the mode of the ForceField.
+            const std::string& getMode(void); //!< Get the mode of the ForceField.
+
         private:
+            //! Strings to represent the modes.
             static const std::string modeTube_s;
             static const std::string modeSphere_s;
-        
-            float velocity_;
-            float diameter_;
-            float radius_;
-            float length_;
-            float halfLength_;
-            forceFieldMode::Value mode_;
+
+            float velocity_; //!< The velocity of the ForceField.
+            float radius_; //!< The radius of the ForceField.
+            float halfLength_; //!< Half of the length of the ForceField.
+            forceFieldMode::Value mode_; //!< The mode of the ForceField.
   };
 }
 
 #endif
-




More information about the Orxonox-commit mailing list