Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9105


Ignore:
Timestamp:
Apr 20, 2012, 4:31:00 PM (12 years ago)
Author:
scmoritz
Message:

Movement to Waypoint fixed. Speed still has to get adjusted

File:
1 edited

Legend:

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

    r9093 r9105  
    276276                if(coord.x < 0.0001 && coord.y < 0.0001)
    277277                {
    278                         // I AM HERE
    279                         Vector3 v_temp = this->getControllableEntity()->getOrientation();
    280                         Quaternion quat = v_temp.getRotationTo(target) * v_temp;
     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);
    281281                        this->getControllableEntity()->rotate(quat);
    282                        
    283                         //this->getControllableEntity()->setOrientation(this->getControllableEntity()->getPosition().getRotationTo(target) * this->getControllableEntity()->getOrientation());
    284282                }
    285283
     
    318316
    319317        if(this->state_ == SLAVE)
    320         {
    321 
    322            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR_MASTER * coord.x * 2);
    323            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR_MASTER * coord.y * 2);
    324 
    325             if (distance < 300)
    326             {
    327                  if (bHasTargetOrientation_)
    328                     {
    329                         copyTargetOrientation();
    330                     }
    331                 if (distance < 100)
    332                 {  //linear speed reduction
    333                     this->getControllableEntity()->moveFrontBack(distance/100.0f*0.4f*SPEED_MASTER);
    334                    
    335                 } else this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER);
    336 
    337             } else {
    338                 this->getControllableEntity()->moveFrontBack(1.2f*SPEED_MASTER + distance/300.0f);
    339             }
    340         }
     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                }
    341339
    342340        if (distance < 10)
     
    391389    void FormationController::searchNewMaster()
    392390    {
    393         if (this->state_==SLAVE) 
     391        if (this->state_==SLAVE)
    394392           return;
    395393        if (!this->getControllableEntity())
     
    402400        for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
    403401        {
    404            
     402
    405403            //same team?
    406404            Gametype* gt=this->getGametype();
     
    487485                 bool left=true;
    488486            int i = 1;
    489            
     487
    490488            for(std::vector<FormationController*>::iterator it = slaves_.begin(); it != slaves_.end(); it++)
    491489            {
     
    498496                    i++;
    499497                    dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
    500                 }               
     498                }
    501499                (*it)->setTargetOrientation(orient);
    502500                (*it)->setTargetPosition(pos);
     
    607605
    608606        if (this->state_==SLAVE)  //become master of this formation
    609         {   
     607        {
    610608            this->slaves_=this->myMaster_->slaves_;
    611609            this->myMaster_->slaves_.clear();
    612610            this->myMaster_->state_=SLAVE;
    613611            this->myMaster_->myMaster_=this;
    614            
     612
    615613            //delete myself in slavelist
    616614            std::vector<FormationController*>::iterator it2 = std::find(this->slaves_.begin(), this->slaves_.end(), this);
     
    655653           if (i>=slaves_.size()/2) break; //half the formation should attack.
    656654       }
    657     }     
     655    }
    658656
    659657
     
    868866    void FormationController::setTargetOrientation(const Quaternion& orient)
    869867    {
    870         this->targetOrientation_=orient;       
     868        this->targetOrientation_=orient;
    871869        this->bHasTargetOrientation_=true;
    872870    }
Note: See TracChangeset for help on using the changeset viewer.