Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10670 for code


Ignore:
Timestamp:
Oct 19, 2015, 4:01:54 PM (9 years ago)
Author:
gania
Message:

hold position in formation with waypoints

Location:
code/branches/AI_HS15
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/libraries/util/Math.cc

    r10630 r10670  
    161161         - If the other object is exactly above me, the function returns <tt>Vector2(0, 0.5)</tt>.
    162162    */
    163     orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
     163    orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
    164164    {
    165165        orxonox::Vector3 distance = otherposition - myposition;
  • code/branches/AI_HS15/src/libraries/util/Math.h

    r9939 r10670  
    9191    _UtilExport float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition);
    9292    _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    93     _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
     93    _UtilExport orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
    9494    _UtilExport orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit);
    9595    _UtilExport bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle);
  • code/branches/AI_HS15/src/modules/docking/DockingController.cc

    r9667 r10670  
    6161
    6262        float distance = (this->dock_->getWorldPosition() - entity->getPosition()).length();
    63         Vector2 coord = get2DViewcoordinates(     // I don't understand this too
     63        Vector2 coord = get2DViewCoordinates(     // I don't understand this too
    6464            entity->getPosition(),
    6565            entity->getOrientation() * WorldEntity::FRONT,
  • code/branches/AI_HS15/src/modules/overlays/hud/HUDRadar.cc

    r9945 r10670  
    240240            }
    241241            else
    242                 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
     242                coord = get2DViewCoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
    243243
    244244            coord *= math::pi / 3.5f; // small adjustment to make it fit the texture
  • code/branches/AI_HS15/src/orxonox/controllers/AIController.cc

    r10654 r10670  
    8686        }
    8787
     88
    8889        if (this->state_ == SLAVE && this->formationMode_ == ATTACK)
    8990        {
     
    108109            //-------------------------------------------------------
    109110            //collect data for AI behaviour
    110             Vector3 meanOfEnemies;
    111             Vector3 meanOfAllies;
     111            Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
     112            Vector3* meanOfAlliesPtr  = new Vector3(0.0,0.0,0.0);
     113            Vector3 meanOfAllies = *meanOfAlliesPtr;
     114            Vector3 meanOfEnemies = *meanOfEnemiesPtr;
     115
    112116
    113117            for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)
     
    121125                if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))
    122126                {
    123                     enemies.push_back(*it);
     127                    enemies_.push_back(*it);
    124128                }
    125129                else {
    126                     allies.push_back(*it);
     130                    allies_.push_back(*it);
    127131                }
    128132            }
    129             if (enemies.size() != 0 && allies.size() != 0){
    130             for (std::vector<AIController*>::iterator it = enemies.begin() ; it != enemies.end(); ++it)
    131                 meanOfEnemies += (*it)->getControllableEntity()->getPosition();
    132             meanOfEnemies /= enemies.size();
    133             for (std::vector<AIController*>::iterator it = allies.begin() ; it != allies.end(); ++it)
    134                 meanOfAllies += (*it)->getControllableEntity()->getPosition();
    135             meanOfAllies /= allies.size();
    136             //orxout(internal_error) << "There are " << enemiesCounter << " enemies, mean position is " << meanOfEnemies << endl;
    137             orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
    138             orxout(internal_error) << "mean of Allies is " << meanOfAllies << ", with a size " << allies.size() << endl;
    139             orxout(internal_error) << "mean of Enemies is " << meanOfEnemies << ", with a size " << enemies.size() << endl;
     133            if (enemies_.size() != 0 && allies_.size() != 0){
     134                for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it)
     135                    meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition();
     136
     137                meanOfEnemies /= enemies_.size();
     138
     139                for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it)
     140                    meanOfAllies += (*it)->getControllableEntity()->getWorldPosition();
     141
     142                meanOfAllies /= allies_.size();
     143
     144                //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl;
     145                orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
     146                orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl;
     147                orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
    140148            }
    141149            //-------------------------------------------------------
    142150           
    143 
     151            //Decide which formationMode to choose
    144152            this->setFormationMode(ATTACK);
    145            
    146             this->commandSlaves();
     153            this->setDesiredPositionOfSlaves();
     154
     155            //this->commandSlaves();
    147156
    148157            if  (this->specificMasterAction_ != NONE)
     
    184193            }
    185194        }
    186         allies.clear();
    187         enemies.clear();
     195        allies_.clear();
     196        enemies_.clear();
    188197    }
    189198
     
    196205        float maxrand = 100.0f / ACTION_INTERVAL;
    197206        ControllableEntity* controllable = this->getControllableEntity();
     207        if (this->state_ == SLAVE)
     208        {
     209            Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()*desiredRelativePosition_;
     210           
     211            orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext());
     212            waypoint->setPosition(desiredAbsolutePosition);
     213           
     214            this->addWaypoint(waypoint);
     215        }
    198216        //DOES: Either move to the waypoint or search for a Point of interest
    199217        if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
  • code/branches/AI_HS15/src/orxonox/controllers/AIController.h

    r10654 r10670  
    5454
    5555            Timer actionTimer_; //<! Regularly calls action().
    56             std::vector<AIController*> enemies, allies;
     56            std::vector<WeakPtr<AIController> > enemies_, allies_;
     57            Vector3* desiredRelativePosition_;
     58            Vector3* currentRelativePosition_;
    5759    };
    5860}
  • code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc

    r10652 r10670  
    278278        }
    279279
    280         Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     280        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    281281        float distance = (target - this->getControllableEntity()->getPosition()).length();
    282282        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     
    703703        }
    704704    }
     705     /**
     706      @brief If master, set the desired relative position of slaves (Vector3) in respect to a master for all the slaves.
     707    */
     708    void FormationController::setDesiredPositionOfSlaves()
     709    {
     710        if (this->state_ != MASTER)
     711            return;
     712        switch (this->formationMode_){
     713            case ATTACK:
     714            for(std::vector<FormationController*>::iterator it = slaves_.begin(), float i = 0; it != slaves_.end(); it++, ++i)
     715            {
     716                (*it)->desiredPosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);
     717               
     718            }
     719            break;
     720            case NORMAL:
     721
     722            break;
     723            case DEFEND:
     724
     725            break;
     726        }
     727       
     728    }
    705729
    706730    /**
     
    10701094            return;
    10711095
    1072         Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     1096        Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    10731097        float distance = (target - this->getControllableEntity()->getPosition()).length();
    10741098
  • code/branches/AI_HS15/src/orxonox/controllers/FormationController.h

    r10631 r10670  
    7070           { return this->maxFormationSize_; }
    7171
    72 
     72      /**
     73      @brief If master, set the desired position of slaves (Vector2) for all the slaves.
     74      */
     75      inline void setDesiredPositionOfSlaves();
     76     
    7377      inline void setPassive(bool passive)
    7478           { this->passive_ = passive; }
     
    9296      inline FormationMode getFormationMode() const
    9397           { return this->formationMode_; }
    94 
     98     
    9599      virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
    96100
  • code/branches/AI_HS15/test/util/MathTest.cc

    r9114 r10670  
    337337    getAngle
    338338    get2DViewdirection
    339     get2DViewcoordinates
     339    get2DViewCoordinates
    340340    getPredictedPosition
    341341*/
Note: See TracChangeset for help on using the changeset viewer.