Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8967


Ignore:
Timestamp:
Dec 8, 2011, 5:01:18 PM (12 years ago)
Author:
willis
Message:

added DEFEND behaviour, fixed some orientation issue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/formation/src/orxonox/controllers/Masterable.cc

    r8965 r8967  
    344344    }
    345345
    346     void Masterable::copyOrientation(const Quaternion& orient)
    347     {
    348         //roll angle in radian, difference between master and slave
    349         float diff=orient.getRoll().valueRadians()-(this->getControllableEntity()->getOrientation().getRoll().valueRadians());
    350         if ((diff<math::twoPi && diff>math::pi) || diff>(math::pi)*3)
    351         {
    352                 diff=diff-math::twoPi;
    353         }
    354         this->getControllableEntity()->rotateRoll(1.0f*ROTATEFACTOR_MASTER*diff);
     346  //copy the Roll orientation of given Quaternion.
     347  void Masterable::copyOrientation(const Quaternion& orient)
     348    {
     349        //roll angle difference in radian
     350        float diff=orient.getRoll(false).valueRadians()-(this->getControllableEntity()->getOrientation().getRoll(false).valueRadians());
     351        while(diff>math::twoPi) diff-=math::twoPi;
     352        while(diff<-math::twoPi) diff+=math::twoPi;
     353        this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR_MASTER);
    355354    }
    356355
    357356    void Masterable::copyTargetOrientation()
    358357    {
    359         if (bHasTargetOrientation_)
    360         {
    361                 copyOrientation(targetOrientation_);
    362         }
     358        if (bHasTargetOrientation_)
     359        {
     360            copyOrientation(targetOrientation_);
     361        }
    363362    }
    364363
     
    475474            dest += 1.0f*orient*WorldEntity::BACK;
    476475            Vector3 pos = Vector3::ZERO;
    477             bool left=true;
     476                 bool left=true;
    478477            int i = 1;
    479478           
     
    481480            {
    482481                pos = Vector3::ZERO;
    483                 if (left)
    484                 {
     482                if (left)
     483                {
    485484                    pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::LEFT);
    486                 } else
    487                 {
    488                     pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
    489                     i++;
    490                     dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
    491                 }               
    492                 (*it)->setTargetOrientation(orient);
     485                } else{
     486                    pos+=dest+i*FORMATION_WIDTH*(orient*WorldEntity::RIGHT);
     487                    i++;
     488                    dest+=FORMATION_LENGTH*(orient*WorldEntity::BACK);
     489                }               
     490                (*it)->setTargetOrientation(orient);
    493491                (*it)->setTargetPosition(pos);
    494                 left=!left;
     492                left=!left;
    495493            }
    496494        }
     
    633631    {
    634632       orxout(debug_output)<<"slaves, attack!"<<endl;
     633       unsigned int i=0;
     634       for(std::vector<Masterable*>::reverse_iterator it = slaves_.rbegin(); it != slaves_.rend(); it++)
     635       {
     636           if ((*it)->state_!=FREE)
     637           {
     638               (*it)->state_=FREE;
     639               (*it)->forceFreedom();
     640               (*it)->target_=originator;
     641           }
     642           i++;
     643           if (i==slaves_.size()/2) break; //half the formation should attack.
     644       }
    635645    }     
    636646
     
    846856    void Masterable::setTargetOrientation(const Quaternion& orient)
    847857    {
    848         this->targetOrientation_=orient;       
    849         this->bHasTargetOrientation_=true;
     858        this->targetOrientation_=orient;       
     859        this->bHasTargetOrientation_=true;
    850860    }
    851861
    852862    void Masterable::setTargetOrientation(Pawn* target)
    853863    {
    854         if (target)
    855             setTargetOrientation(target->getOrientation());
     864        if (target)
     865            setTargetOrientation(target->getOrientation());
    856866    }
    857867
Note: See TracChangeset for help on using the changeset viewer.