Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Some documentation and simplification

File:
1 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 
Note: See TracChangeset for help on using the changeset viewer.