Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9188


Ignore:
Timestamp:
May 18, 2012, 1:54:37 PM (12 years ago)
Author:
mentzerf
Message:
  • Now using new waypoints
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/newlevel2012/src/orxonox/controllers/FormationController.cc

    r9016 r9188  
    272272        }
    273273
    274         Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     274        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    275275        float distance = (target - this->getControllableEntity()->getPosition()).length();
    276 
     276                if(coord.x < 0.0001 && coord.y < 0.0001)
     277                {
     278                        // if the ship reaches a direction very close to the direct one, set it to the direct one
     279                        Vector3 v_temp = this->getControllableEntity()->getPosition();
     280                        Quaternion quat = v_temp.getRotationTo(target);
     281                        this->getControllableEntity()->rotate(quat);
     282                }
    277283
    278284        if(this->state_ == FREE)
     
    281287            {
    282288                // Multiply with ROTATEFACTOR_FREE to make them a bit slower
    283                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * sgn(coord.x) * coord.x*coord.x);
    284                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * sgn(coord.y) * coord.y*coord.y);
    285             }
    286 
    287             if (this->target_ && distance < 200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     289                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_FREE * coord.x * 2);
     290                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_FREE * coord.y * 2);
     291            }
     292
     293            if (this->target_ && distance <  200 && this->getControllableEntity()->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
    288294            {
    289295              this->getControllableEntity()->moveFrontBack(-0.05f); // They don't brake with full power to give the player a chance
     
    297303            if (this->target_ || distance > 10)
    298304            {
    299                 this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    300                 this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
     305                this->getControllableEntity()->rotateYaw(-1.0f * ROTATEFACTOR_MASTER * coord.x * 2);
     306                this->getControllableEntity()->rotatePitch(ROTATEFACTOR_MASTER * coord.y * 2);
    301307            }
    302308
     
    310316
    311317        if(this->state_ == SLAVE)
    312         {
    313 
    314            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * sgn(coord.x) * coord.x*coord.x);
    315            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * sgn(coord.y) * coord.y*coord.y);
    316 
    317             if (distance < 300)
    318             {
    319                  if (bHasTargetOrientation_)
    320                     {
    321                         copyTargetOrientation();
    322                     }
    323                 if (distance < 100)
    324                 {  //linear speed reduction
    325                     this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
    326                    
    327                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
    328 
    329             } else {
    330                 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
    331             }
    332         }
     318                {
     319
     320                        this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * coord.x * 2);
     321                        this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * coord.y * 2);
     322
     323                        if (distance < 300)
     324                        {
     325                                if (bHasTargetOrientation_)
     326                                {
     327                                        copyTargetOrientation();
     328                                }
     329                                if (distance < 100)
     330                                { //linear speed reduction
     331                                        this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
     332
     333                                } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
     334
     335                        } else {
     336                                this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
     337                        }
     338                }
    333339
    334340        if (distance < 10)
     
    383389    void FormationController::searchNewMaster()
    384390    {
    385         if (this->state_==SLAVE) 
     391        if (this->state_==SLAVE)
    386392           return;
    387393        if (!this->getControllableEntity())
     
    394400        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    395401        {
    396            
     402
    397403            //same team?
    398404            Gametype* gt=this->getGametype();
     
    479485                 bool left=true;
    480486            int i = 1;
    481            
     487
    482488            for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    483489            {
     
    490496                    i++;
    491497                    dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
    492                 }               
     498                }
    493499                (*it)->setTargetOrientation(orient);
    494500                (*it)->setTargetPosition(pos);
     
    599605
    600606        if (this->state_==SLAVE)  //become master of this formation
    601         {   
     607        {
    602608            this->slaves_=this->myMaster_->slaves_;
    603609            this->myMaster_->slaves_.clear();
    604610            this->myMaster_->state_=SLAVE;
    605611            this->myMaster_->myMaster_=this;
    606            
     612
    607613            //delete myself in slavelist
    608614            std::vector<FormationController*>::iterator it2 = std::find(this->slaves_.begin(), this->slaves_.end(), this);
     
    647653           if (i>=slaves_.size()/2) break; //half the formation should attack.
    648654       }
    649     }     
     655    }
    650656
    651657
     
    860866    void FormationController::setTargetOrientation(const Quaternion& orient)
    861867    {
    862         this->targetOrientation_=orient;       
     868        this->targetOrientation_=orient;
    863869        this->bHasTargetOrientation_=true;
    864870    }
Note: See TracChangeset for help on using the changeset viewer.