Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 25, 2009, 5:54:42 PM (15 years ago)
Author:
Aurelian
Message:

Final commit of gametype asteroids for presentation. everything working. New gadget: Radar displays the next checkpoint to reach!

File:
1 edited

Legend:

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

    r3033 r3064  
    3535namespace orxonox
    3636{
    37   CreateFactory(ForceField);
     37    CreateFactory(ForceField);
    3838
    3939    ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
    4040    {
    41       RegisterObject(ForceField);
     41        RegisterObject(ForceField);
    4242
    43       //Standard Values
    44       this->setDirection(Vector3::ZERO);
    45       velocity_ = 100;
    46       diameter_ = 500;
    47       length_ = 2000;
     43        //Standard Values
     44        this->setDirection(Vector3::ZERO);
     45        velocity_ = 100;
     46        diameter_ = 500;
     47        length_ = 5000;
    4848    }
    4949
     
    5252    void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5353    {
    54       SUPER(ForceField, XMLPort, xmlelement, mode);
    55 
    56       //For correct xml import use: position, direction, velocity, scale
    57 
    58       XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
    59       XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
    60       XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
     54        SUPER(ForceField, XMLPort, xmlelement, mode);
     55 
     56        //For correct xml import use: position, direction, velocity, scale
     57        XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
     58        XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
     59        XMLPortParam(ForceField, "length"  , setLength  , getLength  , xmlelement, mode).defaultValues(2000);
    6160    }
    6261
    6362    void ForceField::tick(float dt)
    6463    {
     64        for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
     65        {
     66            //calculate from
     67            Vector3 directionVec = this->getOrientation() * WorldEntity::FRONT;
     68            directionVec.normalise();
    6569
    66       for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
    67       {
     70            Vector3 distanceVec = it->getWorldPosition() - (this->getWorldPosition() + (this->length_ / 2 * directionVec));
    6871
    69         //calculate from
    70         Vector3 directionVec = this->getOrientation() * WorldEntity::FRONT;
    71         directionVec.normalise();
     72            //distance from centervector of the field (
     73            float distFromCenterVec = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(directionVec)).length();
    7274
    73         Vector3 distanceVec = it->getWorldPosition() - (this->getWorldPosition() + (this->length_ / 2 * directionVec));
    74 
    75         //distance from centervector of the field (
    76         float distFromCenterVec = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(directionVec)).length();
    77 
    78         if (distanceVec.length() < this->length_ / 2 && distFromCenterVec < diameter_ / 2)
    79         {
    80           //normalize distance from center
    81           it->applyCentralForce(((diameter_ / 2 - distFromCenterVec) / (diameter_ / 2)) * directionVec * velocity_);
     75            if (distanceVec.length() < this->length_ / 2 && distFromCenterVec < diameter_ / 2)
     76            {
     77                //normalize distance from center
     78                it->applyCentralForce(((diameter_ / 2 - distFromCenterVec) / (diameter_ / 2)) * directionVec * velocity_);
     79            }
    8280        }
    83 
    84       }
    85   }
     81    }
    8682}
    8783
Note: See TracChangeset for help on using the changeset viewer.