Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 26, 2010, 8:44:48 AM (14 years ago)
Author:
dafrick
Message:

Some documentation and simplification

Location:
code/trunk/src/modules/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/objects/ForceField.cc

    r7674 r7676  
    2828
    2929/**
    30 @file ForceField.cc
    31 @brief Implementation of the ForceField class.
     30    @file ForceField.cc
     31    @brief Implementation of the ForceField class.
    3232*/
    3333
     
    4141{
    4242    CreateFactory(ForceField);
    43    
     43
    4444    /*static*/ const std::string ForceField::modeTube_s = "tube";
    4545    /*static*/ const std::string ForceField::modeSphere_s = "sphere";
    4646
     47    /**
     48    @brief
     49        Constructor. Registers the object and initializes some values.
     50    */
    4751    ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
    4852    {
     
    5155        //Standard Values
    5256        this->setDirection(Vector3::ZERO);
    53         this->velocity_ = 100;
    54         this->diameter_ = 500;
    55         this->length_ = 5000;
     57        this->setVelocity(100);
     58        this->setDiameter(500);
     59        this->setLength(2000);
    5660        this->mode_ = forceFieldMode::tube;
    5761    }
    5862
     63    /**
     64    @brief
     65        Destructor.
     66    */
    5967    ForceField::~ForceField()
    6068    {
    6169    }
    6270
     71    /**
     72    @brief
     73        Creates a ForceField object through XML.
     74    */
    6375    void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    6476    {
    6577        SUPER(ForceField, XMLPort, xmlelement, mode);
    6678
    67         //For correct xml import use: position, direction, velocity, scale
    6879        XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
    6980        XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
    7081        XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
    7182        XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode);
    72         COUT(0) << "ForceField created " << this->velocity_ << " " << this->diameter_ << " " << this->radius_ << " " << this->length_ << " " << this->halfLength_ << " " << this->getMode() << std::endl;
    7383    }
    7484
     85    /**
     86    @brief
     87        A method that is called every tick.
     88        Implements the behavior of teh ForceField.
     89    @param dt
     90        The amount of time that elapsed since the last tick.
     91    */
    7592    void ForceField::tick(float dt)
    7693    {
     
    87104                // TODO: This could probably be simplified.
    88105                Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction));
    89                
     106
    90107                // The object is outside of the length of the ForceField.
    91108                if(distanceVector.length() > this->halfLength_)
     
    94111                // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector)
    95112                float distanceFromDirectionVector = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(direction)).length();
    96                
    97                 // If the object in a tube of radius diameter/2 around the direction of orientation.
     113
     114                // If the object in a tube of radius 'radius' around the direction of orientation.
    98115                if(distanceFromDirectionVector >= this->radius_)
    99116                    continue;
     
    111128                Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();
    112129                float distance = distanceVector.length();
     130                // If the object is within 'radius' distance.
    113131                if (distance < this->radius_)
    114132                {
    115133                    distanceVector.normalise();
     134                    // 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.
    116135                    it->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector);
    117136                }
     
    119138        }
    120139    }
    121    
     140
     141    /**
     142    @brief
     143        Set the mode of the ForceField.
     144    @param mode
     145        The mode as a string.
     146    */
    122147    void ForceField::setMode(const std::string& mode)
    123148    {
     
    132157        }
    133158    }
    134    
    135     inline const std::string& ForceField::getMode(void)
     159
     160    /**
     161    @brief
     162        Get the mode of the ForceField.
     163    @return
     164        Returns the mode of the ForceField as a string.
     165    */
     166    const std::string& ForceField::getMode(void)
    136167    {
    137168        switch(this->mode_)
     
    145176        }
    146177    }
     178
    147179}
    148 
    149 
    150 
    151 
    152 
  • code/trunk/src/modules/objects/ForceField.h

    r7674 r7676  
    3333*/
    3434
    35 /**
    36 @file ForceField.h
    37 @brief Definition of the ForceField class.
    38 @inGroup Objects
    39 */
    40 
    4135#ifndef _ForceField_H__
    4236#define _ForceField_H__
     
    5347    @brief
    5448        The mode of the ForceField.
    55    
    56     @inGroup Objects
     49
     50    @ingroup Objects
    5751    */
    5852    namespace forceFieldMode
     
    6155            tube, //!< The ForceField has a tube shape.
    6256            sphere //!< The ForceField has a spherical shape.
    63            
    6457        };
    6558    }
     
    6861    @brief
    6962        Implements a force field, that applies a force to any @ref orxonox::MoblieEnity "MobileEntity" that enters its range.
    70        
     63
    7164        The following parameters can be set to specify the behavior of the ForceField.
    72         - @b velocity The amount of force the ForceField excerts.
    73         - @b diameter The diameter of the ForceField.
    74         - @b length The length of the ForceField.
     65        - @b velocity The amount of force the ForceField excerts. Default is 100.
     66        - @b diameter The diameter of the ForceField. Default is 500.
     67        - @b length The length of the ForceField. Default is 2000.
    7568        - @b mode The mode the ForceField is in. For mode:
    76         -- <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.
    77         -- <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>.
    78        
     69            - <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.
     70            - <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>.
     71            Default is <em>tube</em>.
     72
    7973    @author
    8074        Aurelian Jaggi
    81        
     75
    8276    @author
    8377        Damian 'Mozork' Frick
    84        
    85     @inGroup Objects
     78
     79    @ingroup Objects
    8680    */
    8781    class _ObjectsExport ForceField : public StaticEntity, public Tickable
     
    9084            ForceField(BaseObject* creator);
    9185            virtual ~ForceField();
    92             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    93             virtual void tick(float dt);
    9486
     87            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a ForceField object through XML.
     88            virtual void tick(float dt); //!< A method that is called every tick.
     89
     90            /**
     91            @brief Set the velocity of the ForceField.
     92            @param vel The velocity to be set.
     93            */
    9594            inline void setVelocity(float vel)
    9695                { this->velocity_ = vel; }
    97 
     96            /**
     97            @brief Get the velocity of the ForceField.
     98            @return Returns the velocity of the ForceField.
     99            */
    98100            inline float getVelocity()
    99101                { return this->velocity_; }
    100102
     103            /**
     104            @brief Set the diameter of the ForceField.
     105            @param diam The diameter to be set.
     106            */
    101107            inline void setDiameter(float diam)
    102                 { this->diameter_ = diam; this->radius_ = diam/2; }
     108                { this->radius_ = diam/2; }
     109            /**
     110            @brief Get the diameter of the ForceField.
     111            @return Returns the diameter of the ForceField.
     112            */
     113            inline float getDiameter()
     114                { return this->radius_*2; }
    103115
    104             inline float getDiameter()
    105                 { return this->diameter_; }
     116            /**
     117            @brief Set the length of the ForceField.
     118            @param l The length to be set.
     119            */
     120            inline void setLength(float l)
     121                { this->halfLength_ = l/2; }
     122            /**
     123            @brief Get the length of the ForceField.
     124            @return Returns the length of the ForceField.
     125            */
     126            inline float getLength()
     127                { return this->halfLength_*2; }
    106128
    107             inline void setLength(float l)
    108                 { this->length_ = l; this->halfLength_ = l/2; }
    109 
    110             inline float getLength()
    111                 { return this->length_; }
    112                
    113             void setMode(const std::string& mode);
    114                
    115             inline const std::string& getMode(void);
     129            void setMode(const std::string& mode); //!< Set the mode of the ForceField.
     130            const std::string& getMode(void); //!< Get the mode of the ForceField.
    116131
    117132        private:
     133            //! Strings to represent the modes.
    118134            static const std::string modeTube_s;
    119135            static const std::string modeSphere_s;
    120        
    121             float velocity_;
    122             float diameter_;
    123             float radius_;
    124             float length_;
    125             float halfLength_;
    126             forceFieldMode::Value mode_;
     136
     137            float velocity_; //!< The velocity of the ForceField.
     138            float radius_; //!< The radius of the ForceField.
     139            float halfLength_; //!< Half of the length of the ForceField.
     140            forceFieldMode::Value mode_; //!< The mode of the ForceField.
    127141  };
    128142}
    129143
    130144#endif
    131 
Note: See TracChangeset for help on using the changeset viewer.