Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10881


Ignore:
Timestamp:
Nov 28, 2015, 9:17:24 AM (8 years ago)
Author:
gania
Message:

finished fixing FlyingController: AI is flying as smooth as possible with minimum loss of performance

Location:
code/branches/campaignHS15/src/orxonox/controllers
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc

    r10880 r10881  
    364364            (this->getProtect()->getWorldOrientation()* (targetRelativePosition)));
    365365        this->setTargetPosition(targetAbsolutePosition);
    366         this->setTargetOrientation(this->getProtect()->getWorldOrientation());
     366        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     367        if (this->actionConter_ % 3 == 0)
     368            this->setTargetOrientation(this->getProtect()->getWorldOrientation());
    367369    }
    368370    void ActionpointController::nextActionpoint()
  • code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc

    r10877 r10881  
    3939    {
    4040        RegisterObject(DivisionController);
    41        
     41        this->actionCounter_ = 0;
    4242        this->setFormationMode(FormationMode::DIAMOND);
    4343        this->target_ = 0;
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc

    r10880 r10881  
    3838    {
    3939        this->rotationProgress_ = 0;
    40         this->tickCounter_ = 0;
    4140        this->spread_ = 200;
    4241        this->tolerance_ = 80;
     
    9594    {
    9695        ControllableEntity* entity = this->getControllableEntity();
    97         this->tickCounter_ += this->tickCounter_ < 100000 ? 1 : -this->tickCounter_ ;
    9896
    9997        float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
    10098
    10199
    102         if ( distance > this->tolerance_ )
     100        if ( distance >= this->tolerance_ )
    103101        {
    104102            Vector2 coord = get2DViewCoordinates
     
    115113            if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
    116114                this->getControllableEntity() ->moveFrontBack( SPEED * dt );
    117             if (this->tickCounter_ % 10 == 0 )
    118                 copyTargetOrientation( dt );
    119115        }
    120116        else
    121117        {     
    122118            bHasTargetPosition_ = false;
    123             bHasTargetOrientation_ = false;
    124         }
     119        }
     120        copyTargetOrientation(dt);
    125121    }
    126122   
     
    136132       
    137133        Quaternion myOrient = this->getControllableEntity()->getOrientation();
    138         this->rotationProgress_ += 5*dt;
     134        this->rotationProgress_ += dt;
    139135
    140136        if (this->rotationProgress_ > 1)
    141137        {
    142138            this->rotationProgress_ = 0;
     139            this->bHasTargetOrientation_ = false;
    143140        }
    144141        else
    145142        {
     143
    146144            Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
    147      
     145           
     146            //rotate roll builds a Quaternion in roll method of WorldEntity, then it sets orientation.
     147            //it is faster just to set orientation, plus that way there is no need in calculating the roll angle.
     148            //On the downside, however, ship might also yaw and pitch, but this effect is neglectable, as we only call
     149            //copyOrientation after we move our ship, thus it doesn't affect ships's flying direction too much.
     150            //If you don't like the code style, you are welcomed to uncomment the code below
     151            //and comment out setOrientation part, it will work just fine, but it will also be a tiny bit slower.
     152            //P.S. apperantly it did affect ship's direction and did so way too much.
    148153            Matrix3 orientMatrix, myMatrix;
     154
    149155            delta.ToRotationMatrix(orientMatrix);
    150156            myOrient.ToRotationMatrix (myMatrix);
     
    153159            orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad);
    154160            myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy);
    155             this->getControllableEntity()->rotateRoll (50.0f * dt*(rRad.valueRadians() - rMy.valueRadians()));
    156             //this->getControllableEntity()->setOrientation(delta);
     161
     162            this->getControllableEntity()->rotateRoll ((rRad.valueRadians() - rMy.valueRadians())*ROTATEFACTOR*dt);
     163            // this->getControllableEntity()->setOrientation(delta);
    157164        }
    158165       
  • code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h

    r10880 r10881  
    8383         
    8484            float rotationProgress_;
    85             int tickCounter_;
     85            int actionCounter_;
    8686            bool bHasTargetPosition_;
    8787            Vector3 targetPosition_;
  • code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc

    r10880 r10881  
    9898            LeaderController* newDivisionLeader = findNewDivisionLeader();
    9999            this->myDivisionLeader_ = newDivisionLeader;
     100            //spread copyOrientation called equally among the division
    100101            if (this->myDivisionLeader_)
    101102            {
    102 
     103                this->actionCounter_ = 8;
    103104            }
    104105        }
     
    170171                (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
    171172                 + (orient* (targetRelativePosition)));
    172        
    173             this->setAction (Action::FLY, targetAbsolutePosition, orient);
     173            //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
     174            if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
     175                this->setAction (Action::FLY, targetAbsolutePosition, orient);
     176            else
     177                this->setAction (Action::FLY, targetAbsolutePosition);
     178
    174179            if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
    175180            {
     
    190195            }
    191196        }
    192      
     197        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     198
    193199    }
    194200
  • code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc

    r10880 r10881  
    8787            if (this->myLeader_)
    8888            {
    89 
     89                //spread copyOrientation called equally among the division
     90                if (this->myLeader_->getIdentifier()->getName() == "SectionController")
     91                    this->actionCounter_ = 2;
     92                else
     93                    this->actionCounter_ = 5;
    9094            }
    9195        }
     
    147151                (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
    148152                 + (orient* (targetRelativePosition)));
    149        
    150             this->setAction (Action::FLY, targetAbsolutePosition, orient);
    151 
     153            //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
     154            if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
     155                this->setAction (Action::FLY, targetAbsolutePosition, orient);
     156            else
     157                this->setAction (Action::FLY, targetAbsolutePosition);
    152158            if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
    153159            {
     
    168174            }
    169175        }
    170        
     176        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
    171177    }
    172178     
Note: See TracChangeset for help on using the changeset viewer.