Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 26, 2010, 12:01:53 AM (14 years ago)
Author:
dafrick
Message:

Resolving some stupid bugs and some adding some minor improvements.

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

Legend:

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

    r7673 r7674  
    4242    CreateFactory(ForceField);
    4343   
    44     /*static*/ const std::string modeStringNormal_s = "tube";
    45     /*static*/ const std::string modeStringSphere_s = "sphere";
     44    /*static*/ const std::string ForceField::modeTube_s = "tube";
     45    /*static*/ const std::string ForceField::modeSphere_s = "sphere";
    4646
    4747    ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
     
    5454        this->diameter_ = 500;
    5555        this->length_ = 5000;
    56         this->mode_ = ForceFieldMode::tube;
     56        this->mode_ = forceFieldMode::tube;
    5757    }
    5858
     
    7070        XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
    7171        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;
    7273    }
    7374
    7475    void ForceField::tick(float dt)
    7576    {
    76         // Iterate over all objects that could possibly be affected by the ForceField.
    77         for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
     77        if(this->mode_ == forceFieldMode::tube)
    7878        {
    79             if(this->mode_ == ForceFieldMode::tube)
     79            // Iterate over all objects that could possibly be affected by the ForceField.
     80            for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
    8081            {
    8182                // The direction of the orientation of the force field.
     
    8990                // The object is outside of the length of the ForceField.
    9091                if(distanceVector.length() > this->halfLength_)
    91                     return;
     92                    continue;
    9293
    9394                // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector)
     
    9697                // If the object in a tube of radius diameter/2 around the direction of orientation.
    9798                if(distanceFromDirectionVector >= this->radius_)
    98                     return;
     99                    continue;
    99100
    100101                // Apply a force to the object in the direction of the orientation.
    101102                // The force is highest when the object is directly on the direction vector, with a linear decrease, finally reaching zero, when distanceFromDirectionVector = radius.
    102                 it->applyCentralForce(((this->radius_ - distanceFromDirectionVector)/(this->radius_)) * this->velocity_ * direction);
     103                it->applyCentralForce((this->radius_ - distanceFromDirectionVector)/this->radius_ * this->velocity_ * direction);
    103104            }
    104             else if(this->mode_ == ForceFieldMode::sphere)
     105        }
     106        else if(this->mode_ == forceFieldMode::sphere)
     107        {
     108            // Iterate over all objects that could possibly be affected by the ForceField.
     109            for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
    105110            {
    106111                Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();
     
    117122    void ForceField::setMode(const std::string& mode)
    118123    {
    119         if(mode == ForceField::modeStringTube_s)
    120             this->mode_ = ForceFieldMode::tube;
    121         else if(mode == ForceField::modeStringSphere_s)
    122             this->mode_ = ForceFieldMode::sphere;
     124        if(mode == ForceField::modeTube_s)
     125            this->mode_ = forceFieldMode::tube;
     126        else if(mode == ForceField::modeSphere_s)
     127            this->mode_ = forceFieldMode::sphere;
    123128        else
    124129        {
    125130            COUT(2) << "Wrong mode '" << mode << "' in ForceField. Setting to 'tube'." << std::endl;
    126             this->mode_ = ForceFieldMode::tube;
     131            this->mode_ = forceFieldMode::tube;
    127132        }
    128133    }
     
    132137        switch(this->mode_)
    133138        {
    134             case ForceFieldMode::tube:
    135                 return ForceField::modeStringTube_s;
    136             case ForceFieldMode::sphere:
    137                 return ForceField::modeStringSphere_s;
     139            case forceFieldMode::tube:
     140                return ForceField::modeTube_s;
     141            case forceFieldMode::sphere:
     142                return ForceField::modeSphere_s;
    138143            default:
    139                 return ForceField::modeStringTube_s;
     144                return ForceField::modeTube_s;
    140145        }
    141146    }
  • code/trunk/src/modules/objects/ForceField.h

    r7673 r7674  
    5656    @inGroup Objects
    5757    */
    58     namespace ForceFieldMode
     58    namespace forceFieldMode
    5959    {
    6060        enum Value {
     
    116116
    117117        private:
    118             static const std::string modeStringTube_s;
    119             static const std::string modeStringSphere_s;
     118            static const std::string modeTube_s;
     119            static const std::string modeSphere_s;
    120120       
    121121            float velocity_;
     
    124124            float length_;
    125125            float halfLength_;
    126             ForceFieldMode::Value mode_;
     126            forceFieldMode::Value mode_;
    127127  };
    128128}
Note: See TracChangeset for help on using the changeset viewer.