Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2012, 11:08:17 PM (12 years ago)
Author:
landauf
Message:

merged branch presentation2012merge back to trunk

Location:
code/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/controllers/FormationController.cc

    • Property svn:eol-style set to native
    r9265 r9348  
    5050{
    5151
    52   SetConsoleCommand("FormationController", "formationflight",  &FormationController::formationflight);
    53   SetConsoleCommand("FormationController", "masteraction",     &FormationController::masteraction);
    54   SetConsoleCommand("FormationController", "followme",         &FormationController::followme);
    55   SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
    56   SetConsoleCommand("FormationController", "formationsize",    &FormationController::formationsize);
    57 
    58 
    59 
    60 
    61   static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
    62   static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
    63   static const float FORMATION_LENGTH =  110;
    64   static const float FORMATION_WIDTH =  110;
    65   static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
    66   static const float SPEED_MASTER = 0.6f;
    67   static const float ROTATEFACTOR_MASTER = 0.2f;
    68   static const float SPEED_FREE = 0.8f;
    69   static const float ROTATEFACTOR_FREE = 0.8f;
    70 
    71   FormationController::FormationController(BaseObject* creator) : Controller(creator)
    72   {
     52    SetConsoleCommand("FormationController", "formationflight",  &FormationController::formationflight);
     53    SetConsoleCommand("FormationController", "masteraction",     &FormationController::masteraction);
     54    SetConsoleCommand("FormationController", "followme",         &FormationController::followme);
     55    SetConsoleCommand("FormationController", "passivebehaviour", &FormationController::passivebehaviour);
     56    SetConsoleCommand("FormationController", "formationsize",    &FormationController::formationsize);
     57
     58
     59
     60
     61    static const unsigned int STANDARD_MAX_FORMATION_SIZE = 9;
     62    static const int RADIUS_TO_SEARCH_FOR_MASTERS = 5000;
     63    static const float FORMATION_LENGTH =  110;
     64    static const float FORMATION_WIDTH =  110;
     65    static const int FREEDOM_COUNT = 4; //seconds the slaves in a formation will be set free when master attacks an enemy
     66    static const float SPEED_MASTER = 0.6f;
     67    static const float ROTATEFACTOR_MASTER = 0.2f;
     68    static const float SPEED_FREE = 0.8f;
     69    static const float ROTATEFACTOR_FREE = 0.8f;
     70
     71    FormationController::FormationController(BaseObject* creator) : Controller(creator)
     72    {
    7373        RegisterObject(FormationController);
    7474
     
    9191        this->team_=-1;
    9292        this->target_.setCallback(createFunctor(&FormationController::targetDied, this));
    93   }
    94 
    95   FormationController::~FormationController()
    96   {
    97     if (this->isInitialized())
     93    }
     94
     95    FormationController::~FormationController()
     96    {
     97        if (this->isInitialized())
    9898        {
    9999            this->removeFromFormation();
     
    123123            }
    124124        }
    125   }
    126 
    127   void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     125    }
     126
     127    void FormationController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    128128    {
    129129        SUPER(FormationController, XMLPort, xmlelement, mode);
     
    137137
    138138
    139   /**
     139    /**
    140140        @brief Activates / deactivates formationflight behaviour
    141141        @param form activate formflight if form is true
    142142    */
    143   void FormationController::formationflight(const bool form)
     143    void FormationController::formationflight(const bool form)
    144144    {
    145145        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
     
    168168    }
    169169
    170   /**
     170    /**
    171171        @brief Get all masters to do a "specific master action"
    172172        @param action which action to perform (integer, so it can be called with a console command (tmp solution))
     
    198198    }
    199199
    200   /**
     200    /**
    201201        @brief Sets shooting behaviour of pawns.
    202202        @param passive if true, bots won't shoot.
     
    225225    }
    226226
    227   /**
     227    /**
    228228        @brief Sets maximal formation size
    229229        @param size maximal formation size.
     
    280280        }
    281281
    282         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     282        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    283283        float distance = (target - this->getControllableEntity()->getPosition()).length();
    284 
     284        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     285        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
    285286
    286287        if(this->state_ == FREE)
     
    289290            {
    290291                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    291                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    292                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
    293             }
    294 
    295             if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     292                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * rotateX);
     293                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * rotateY);
     294            }
     295
     296            if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    296297            {
    297298              this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     
    305306            if (this->target_ || distance > 10)
    306307            {
    307                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    308                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     308                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * rotateX);
     309                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * rotateY);
    309310            }
    310311
     
    320321        {
    321322
    322            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    323            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     323            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * rotateX);
     324            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * rotateY);
    324325
    325326            if (distance < 300)
    326327            {
    327                 if (bHasTargetOrientation_)
    328                     {
    329                         copyTargetOrientation();
    330                     }
     328                if (bHasTargetOrientation_)
     329                {
     330                    copyTargetOrientation();
     331                }
    331332                if (distance < 100)
    332                 {   //linear speed reduction
     333                { //linear speed reduction
    333334                    this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
    334 
    335                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
    336 
    337             } else {
     335                }
     336                else
     337                    this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
     338            }
     339            else
    338340                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
    339             }
    340341        }
    341342
     
    343344        {
    344345            this->positionReached();
    345             bHasTargetOrientation_=false;
    346         }
    347     }
    348 
    349 
    350 
    351   void FormationController::moveToTargetPosition()
     346            bHasTargetOrientation_=false;
     347        }
     348    }
     349
     350
     351
     352    void FormationController::moveToTargetPosition()
    352353    {
    353354        this->moveToPosition(this->targetPosition_);
    354355    }
    355356
    356   //copy the Roll orientation of given Quaternion.
    357   void FormationController::copyOrientation(const Quaternion& orient)
     357    //copy the Roll orientation of given Quaternion.
     358    void FormationController::copyOrientation(const Quaternion& orient)
    358359    {
    359360        //roll angle difference in radian
     
    373374
    374375
    375    /**
     376    /**
    376377        @brief Unregisters a slave from its master. Initiated by a slave.
    377378    */
     
    463464        }
    464465    }
    465  /**
     466
     467    /**
    466468        @brief Commands the slaves of a master into a formation. Sufficiently fast not to be called within tick. Initiated by a master.
    467469    */
    468 
    469 void FormationController::commandSlaves()
     470    void FormationController::commandSlaves()
    470471    {
    471472        if(this->state_ != MASTER) return;
     
    481482        }
    482483        else
    483         // formation:
     484        // formation:
    484485        {
    485486            dest += 1.0f*orient*WorldEntity::BACK;
    486487            Vector3 pos = Vector3::ZERO;
    487                  bool left=true;
     488            bool left=true;
    488489            int i = 1;
    489490
     
    683684
    684685        if (specificMasterActionHoldCount_ == 0)
    685          {
     686        {
    686687            this->specificMasterAction_ = NONE;
    687688            this->searchNewTarget();
    688          }
    689         else specificMasterActionHoldCount_--;
     689        }
     690        else
     691            specificMasterActionHoldCount_--;
    690692    }
    691693
     
    711713    void FormationController::turn180()
    712714    {
    713             Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
    714 
    715             this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
    716             this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
    717 
    718             this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
     715        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     716
     717        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     718        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     719
     720        this->getControllableEntity()->moveFrontBack(SPEED_MASTER);
    719721    }
    720722
     
    734736    void FormationController::spin()
    735737    {
    736             this->moveToTargetPosition();
    737             this->getControllableEntity()->rotateRoll(0.8f);
     738        this->moveToTargetPosition();
     739        this->getControllableEntity()->rotateRoll(0.8f);
    738740    }
    739741
     
    773775        if((humanPawn != NULL) && (allMasters.size() != 0))
    774776        {
    775                 float posHuman = humanPawn->getPosition().length();
    776                 float distance = 0.0f;
    777                 float minDistance = FLT_MAX;
    778                 int index = 0;
    779                 int i = 0;
    780 
    781                 for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
    782                     {
    783                         if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
    784                         distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
    785                         if(distance < minDistance) index = i;
    786                     }
    787                 allMasters[index]->followInit(humanPawn);
    788             }
    789 
    790     }
    791 
    792 
    793 
    794 
     777            float posHuman = humanPawn->getPosition().length();
     778            float distance = 0.0f;
     779            float minDistance = FLT_MAX;
     780            int index = 0;
     781            int i = 0;
     782
     783            for(std::vector<FormationController*>::iterator it = allMasters.begin(); it != allMasters.end(); it++, i++)
     784            {
     785                if (!FormationController::sameTeam((*it)->getControllableEntity(), humanPawn, (*it)->getGametype())) continue;
     786                distance = posHuman - (*it)->getControllableEntity()->getPosition().length();
     787                if(distance < minDistance) index = i;
     788            }
     789            allMasters[index]->followInit(humanPawn);
     790        }
     791    }
    795792
    796793    /**
     
    814811    }
    815812
    816    /**
     813    /**
    817814        @brief Master begins to follow a randomly chosen human player of the same team. Is a "specific master action".
    818815    */
     
    842839
    843840
    844   /**
     841    /**
    845842        @brief Master follows target with adjusted speed. Called within tick.
    846843    */
     
    854851
    855852
    856   void FormationController::setTargetPosition(const Vector3& target)
     853    void FormationController::setTargetPosition(const Vector3& target)
    857854    {
    858855        this->targetPosition_ = target;
     
    918915    }
    919916
    920   void FormationController::forgetTarget()
     917    void FormationController::forgetTarget()
    921918    {
    922919        this->target_ = 0;
     
    924921    }
    925922
    926    void FormationController::targetDied()
     923    void FormationController::targetDied()
    927924    {
    928925        this->forgetTarget();
     
    930927    }
    931928
    932   bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
     929    bool FormationController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
    933930    {
    934931        if (entity1 == entity2)
     
    10541051            return;
    10551052
    1056         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     1053        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    10571054        float distance = (target - this->getControllableEntity()->getPosition()).length();
    10581055
     
    10601057            {
    10611058                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    1062                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    1063                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
     1059                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * clamp(coord.x * 10, -1.0f, 1.0f));
     1060                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * clamp(coord.y * 10, -1.0f, 1.0f));
    10641061                this->getControllableEntity()->moveFrontBack(SPEED_FREE);
    10651062            }
  • code/trunk/src/orxonox/controllers/FormationController.h

    • Property svn:eol-style set to native
  • code/trunk/src/orxonox/controllers/NewHumanController.cc

    r9016 r9348  
    298298        //Used in HumanController for formationFlight
    299299        HumanController::hit(originator,contactpoint,damage);
    300        
     300
    301301        if (this->showDamageOverlay_ && !this->controlPaused_ && this->controllableEntity_ && !this->controllableEntity_->isInMouseLook())
    302302        {
     
    397397                try
    398398                {
    399                     wePtr = dynamic_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
     399                    wePtr = orxonox_cast<WorldEntity*>(Ogre::any_cast<OrxonoxClass*>(itr->movable->getUserAny()));
    400400                }
    401401                catch (...)
Note: See TracChangeset for help on using the changeset viewer.