[Orxonox-commit 6224] r10881 - code/branches/campaignHS15/src/orxonox/controllers

gania at orxonox.net gania at orxonox.net
Sat Nov 28 09:17:24 CET 2015


Author: gania
Date: 2015-11-28 09:17:24 +0100 (Sat, 28 Nov 2015)
New Revision: 10881

Modified:
   code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
   code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
   code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
   code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
   code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
Log:
finished fixing FlyingController: AI is flying as smooth as possible with minimum loss of performance

Modified: code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-27 21:37:59 UTC (rev 10880)
+++ code/branches/campaignHS15/src/orxonox/controllers/ActionpointController.cc	2015-11-28 08:17:24 UTC (rev 10881)
@@ -363,7 +363,9 @@
         Vector3 targetAbsolutePosition = ((this->getProtect()->getWorldPosition()) + 
             (this->getProtect()->getWorldOrientation()* (targetRelativePosition)));
         this->setTargetPosition(targetAbsolutePosition);
-        this->setTargetOrientation(this->getProtect()->getWorldOrientation());
+        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
+        if (this->actionConter_ % 3 == 0)
+            this->setTargetOrientation(this->getProtect()->getWorldOrientation());
     }
     void ActionpointController::nextActionpoint()
     {

Modified: code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-27 21:37:59 UTC (rev 10880)
+++ code/branches/campaignHS15/src/orxonox/controllers/DivisionController.cc	2015-11-28 08:17:24 UTC (rev 10881)
@@ -38,7 +38,7 @@
     DivisionController::DivisionController(Context* context) : LeaderController(context)
     {
         RegisterObject(DivisionController);
-        
+        this->actionCounter_ = 0;
         this->setFormationMode(FormationMode::DIAMOND);
         this->target_ = 0;
         this->myFollower_ = 0;

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-11-27 21:37:59 UTC (rev 10880)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.cc	2015-11-28 08:17:24 UTC (rev 10881)
@@ -37,7 +37,6 @@
     FlyingController::FlyingController( Context* context ): CommonController( context )
     {
         this->rotationProgress_ = 0;
-        this->tickCounter_ = 0;
         this->spread_ = 200;
         this->tolerance_ = 80;
         RegisterObject( FlyingController );
@@ -94,12 +93,11 @@
     void FlyingController::moveToPosition( const Vector3& target, float dt )
     {
         ControllableEntity* entity = this->getControllableEntity();
-        this->tickCounter_ += this->tickCounter_ < 100000 ? 1 : -this->tickCounter_ ;
 
         float distance = ( target - this->getControllableEntity() ->getPosition() ).length();
 
 
-        if ( distance > this->tolerance_ )
+        if ( distance >= this->tolerance_ )
         {
             Vector2 coord = get2DViewCoordinates
                 ( entity->getPosition() , 
@@ -114,14 +112,12 @@
           
             if (distance > this->tolerance_*1.5f || (rotateX > -0.01 && rotateX < 0.01 && rotateY > -0.01 && rotateY < 0.01))
                 this->getControllableEntity() ->moveFrontBack( SPEED * dt );
-            if (this->tickCounter_ % 10 == 0 )
-                copyTargetOrientation( dt );
         }
         else
         {      
             bHasTargetPosition_ = false;
-            bHasTargetOrientation_ = false;
         }
+        copyTargetOrientation(dt);
     }
     
     void FlyingController::moveToTargetPosition(float dt)
@@ -135,25 +131,36 @@
         //how can I make my objects rotate smoothly?
        
         Quaternion myOrient = this->getControllableEntity()->getOrientation();
-        this->rotationProgress_ += 5*dt;
+        this->rotationProgress_ += dt;
 
         if (this->rotationProgress_ > 1)
         {
             this->rotationProgress_ = 0;
+            this->bHasTargetOrientation_ = false;
         }
         else
         {
+
             Quaternion delta = Quaternion::Slerp(rotationProgress_, myOrient, orient, true);
-      
+            
+            //rotate roll builds a Quaternion in roll method of WorldEntity, then it sets orientation.
+            //it is faster just to set orientation, plus that way there is no need in calculating the roll angle.
+            //On the downside, however, ship might also yaw and pitch, but this effect is neglectable, as we only call 
+            //copyOrientation after we move our ship, thus it doesn't affect ships's flying direction too much.
+            //If you don't like the code style, you are welcomed to uncomment the code below
+            //and comment out setOrientation part, it will work just fine, but it will also be a tiny bit slower.
+            //P.S. apperantly it did affect ship's direction and did so way too much.
             Matrix3 orientMatrix, myMatrix;
+
             delta.ToRotationMatrix(orientMatrix);
             myOrient.ToRotationMatrix (myMatrix);
 
             Radian yRad, pRad, rRad, yMy, pMy, rMy;
             orientMatrix.ToEulerAnglesYXZ(yRad, pRad, rRad);
             myMatrix.ToEulerAnglesYXZ (yMy, pMy, rMy);
-            this->getControllableEntity()->rotateRoll (50.0f * dt*(rRad.valueRadians() - rMy.valueRadians()));
-            //this->getControllableEntity()->setOrientation(delta);
+
+            this->getControllableEntity()->rotateRoll ((rRad.valueRadians() - rMy.valueRadians())*ROTATEFACTOR*dt);
+            // this->getControllableEntity()->setOrientation(delta);
         }
         
         

Modified: code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-11-27 21:37:59 UTC (rev 10880)
+++ code/branches/campaignHS15/src/orxonox/controllers/FlyingController.h	2015-11-28 08:17:24 UTC (rev 10881)
@@ -82,7 +82,7 @@
             FormationMode::Value formationMode_;
           
             float rotationProgress_;
-            int tickCounter_;
+            int actionCounter_;
             bool bHasTargetPosition_;
             Vector3 targetPosition_;
             bool bHasTargetOrientation_;

Modified: code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-27 21:37:59 UTC (rev 10880)
+++ code/branches/campaignHS15/src/orxonox/controllers/SectionController.cc	2015-11-28 08:17:24 UTC (rev 10881)
@@ -97,9 +97,10 @@
         {
             LeaderController* newDivisionLeader = findNewDivisionLeader();
             this->myDivisionLeader_ = newDivisionLeader;
+            //spread copyOrientation called equally among the division
             if (this->myDivisionLeader_)
             {
-
+                this->actionCounter_ = 8;
             }
         }
         //----If have leader----
@@ -169,8 +170,12 @@
             Vector3 targetAbsolutePosition = 
                 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
                  + (orient* (targetRelativePosition)));
-       
-            this->setAction (Action::FLY, targetAbsolutePosition, orient);
+            //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
+            if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
+                this->setAction (Action::FLY, targetAbsolutePosition, orient);
+            else
+                this->setAction (Action::FLY, targetAbsolutePosition);
+
             if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
             {
                 this->boostControl();
@@ -189,7 +194,8 @@
                 this->bShooting_ = this->canFire();                
             }
         }
-     
+        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
+
     }
 
     

Modified: code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc
===================================================================
--- code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-27 21:37:59 UTC (rev 10880)
+++ code/branches/campaignHS15/src/orxonox/controllers/WingmanController.cc	2015-11-28 08:17:24 UTC (rev 10881)
@@ -86,7 +86,11 @@
             this->myLeader_ = newLeader;
             if (this->myLeader_)
             {
-
+                //spread copyOrientation called equally among the division
+                if (this->myLeader_->getIdentifier()->getName() == "SectionController")
+                    this->actionCounter_ = 2;
+                else
+                    this->actionCounter_ = 5;
             }
         }
         //----If have leader, he will deal with logic----
@@ -146,9 +150,11 @@
             Vector3 targetAbsolutePosition = 
                 (leaderPosition + (orient*WorldEntity::FRONT) * (leaderEntity->getVelocity().length()/5)
                  + (orient* (targetRelativePosition)));
-       
-            this->setAction (Action::FLY, targetAbsolutePosition, orient);
-
+            //let ship finish rotating. also don't call copyOrientation to often as it is a slow function.
+            if (this->actionCounter_ % 9 == 0 && !this->bHasTargetOrientation_)
+                this->setAction (Action::FLY, targetAbsolutePosition, orient);
+            else
+                this->setAction (Action::FLY, targetAbsolutePosition);
             if ((targetAbsolutePosition - myPosition).length() > this->tolerance_ * 1.5f)
             {
                 this->boostControl();
@@ -167,7 +173,7 @@
                 this->bShooting_ = this->canFire();                
             }
         }
-        
+        this->actionCounter_ += this->actionCounter_ < 100000 ? 1 : -this->actionCounter_ ;
     }
      
    




More information about the Orxonox-commit mailing list