Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10789


Ignore:
Timestamp:
Nov 9, 2015, 4:38:02 PM (9 years ago)
Author:
gania
Message:

did nothing today

Location:
code/branches/AI_HS15
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/data/levels/AITest.oxw

    r10759 r10789  
    8585      </controller>
    8686    </SpaceShip>
    87     <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
     87    <!-- <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">
    8888      <templates>
    8989        <Template link=spaceshipassff />
     
    111111        </SectionController>
    112112      </controller>
    113     </SpaceShip>
     113    </SpaceShip> -->
    114114    <?lua end ?>
    115115   <!--  <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0">
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10782 r10789  
    4545
    4646    RegisterClass(CommonController);
    47     float SPEED = 0.7f;
    48     float ROTATEFACTOR = 0.3f;
     47    float SPEED = 0.7f/0.02f;
     48    float ROTATEFACTOR = 0.3f/0.02f;
    4949
    5050    CommonController::CommonController(Context* context) : Controller(context)
     
    5252        this->bSetupWorked = false;
    5353
    54         this->targetMask_.exclude(ClassByString("BaseObject"));
    55         this->targetMask_.include(ClassByString("WorldEntity"));
    56         this->targetMask_.exclude(ClassByString("Projectile"));
     54        this->executingManeuver_ = false;
     55        this->executingMoveToPoint_ = false;
    5756
    5857        RegisterObject(CommonController);
     
    173172
    174173    //copy the Roll orientation of given Quaternion.
    175     void CommonController::copyOrientation(const Quaternion& orient)
     174    void CommonController::copyOrientation(const Quaternion& orient, float dt)
    176175    {
    177176        //roll angle difference in radian
     
    179178        while(diff>math::twoPi) diff-=math::twoPi;
    180179        while(diff<-math::twoPi) diff+=math::twoPi;
    181         this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR);
    182     }
    183     void CommonController::copyTargetOrientation()
     180        this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR * dt);
     181    }
     182    void CommonController::copyTargetOrientation(float dt)
    184183    {
    185184        if (bHasTargetOrientation_)
    186185        {   
    187             copyOrientation(targetOrientation_);
    188         }
    189     }
    190 
    191 
    192 
    193 
    194     void CommonController::moveToTargetPosition()
    195     {
    196         this->moveToPosition(this->targetPosition_);
    197     }
    198     void CommonController::moveToPosition(const Vector3& target)
     186            copyOrientation(targetOrientation_, dt);
     187        }
     188    }
     189
     190
     191
     192
     193    void CommonController::moveToTargetPosition(float dt)
     194    {
     195        this->moveToPosition(this->targetPosition_, dt);
     196    }
     197    void CommonController::moveToPosition(const Vector3& target, float dt)
    199198    {
    200199        float factor = 1;
     
    227226        {
    228227            //Yaw and Pitch are enough to start facing the target
    229             this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX);
    230             this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY);
     228            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX * dt);
     229            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt);
    231230
    232231            //300 works, maybe less is better
     
    239238                if (bHasTargetOrientation_)
    240239                {
    241                     copyTargetOrientation();
     240                    copyTargetOrientation(dt);
    242241                }
    243242            }
    244243
    245             this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor);
     244            this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor * dt);
    246245        }
    247246        else
     
    253252    //to be called in action
    254253    //PRE: relativeTargetPosition is desired position relative to the spaceship,
    255     //angleRoll is the angle of Roll that should be applied by the end of the movement
    256     //POST: targetPosition_ and angleRoll_ are set, so that it can be used by MoveAndRoll()
    257     void MoveToPoint(const Vector3& relativeTargetPosition, float angleRoll)
     254    //angleRoll is the angle in degrees of Roll that should be applied by the end of the movement
     255    //POST: target orientation and position are set, so that it can be used by MoveAndRoll()
     256    void CommonController::moveToPoint(const Vector3& relativeTargetPosition, float angleRoll)
    258257    {
    259258        ControllableEntity* entity = this->getControllableEntity();
    260259        if (!entity)
    261             return false;
     260            return;
    262261        Quaternion orient = entity->getWorldOrientation();
     262        Quaternion rotation = Quaternion(Degree(angleRoll), Vector3::UNIT_Z);
    263263
    264264        Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
    265265        setTargetPosition(target);
    266         this->angleRoll_ = angleRoll;
    267         this->angleRolled_ = 0;
     266        orient = orient * rotation;
     267        this->setTargetOrientation(orient);
     268       
    268269    }
    269270    //to be called in tick
     
    275276    //if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false,
    276277    //otherwise returns true
    277     bool MoveAndRoll(float dt)
    278     {
     278    //dt is normally around 0.02f, which makes it 1/0.02 = 50 frames/sec
     279    bool CommonController::moveAndRoll(float dt)
     280    {
     281        float factor = 1;
     282        if (!this->getControllableEntity())
     283            return false;
     284        if (this->rank_ == Rank::DIVISIONLEADER)
     285            factor = 0.8;
     286        if (this->rank_ == Rank::SECTIONLEADER)
     287            factor = 0.9;
    279288        int tolerance = 60;
    280         float rollDiff = angleRoll-angleRolled_;
    281         float angleToRoll = 0;
     289       
    282290        ControllableEntity* entity = this->getControllableEntity();
    283291        if (!entity)
    284             return false;
     292            return true;
    285293        Vector2 coord = get2DViewCoordinates
    286294            (entity->getPosition(),
     
    302310            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt);
    303311           
     312            //Roll
     313            if (bHasTargetOrientation_)
     314            {
     315                copyTargetOrientation(dt);
     316            }
     317         
    304318            //Move
    305319            this->getControllableEntity()->moveFrontBack(1.2f * SPEED * factor * dt);
    306            
    307             //Roll
    308             angleToRoll = rollDiff * ROTATEFACTOR * dt;
    309             this->getControllableEntity()->rotateRoll(angleToRoll);
    310             angleRolled_ += angleToRoll;
    311320            //if still moving, return false
    312321            return false;
     
    314323        else
    315324        {     
    316             if (rollDiff > 0)
    317             {
    318                 //Roll
    319                 angleToRoll = rollDiff * ROTATEFACTOR * dt;
    320                 this->getControllableEntity()->rotateRoll(angleToRoll);
    321                 angleRolled_ += angleToRoll;               
    322 
    323                 //Move
    324                 this->getControllableEntity()->moveFrontBack(0.6f * SPEED * factor);
    325                 return false;
    326             }
     325           
    327326            //if finished, return true;
    328             retun true;
    329         }
    330     }
    331 
    332     float squaredDistanceToTarget()
     327            return true;
     328        }
     329    }
     330
     331    float CommonController::squaredDistanceToTarget() const
    333332    {
    334333        if ( !this->getControllableEntity() )
    335334            return 0;
    336335        if ( !this->target_ )
    337             return ( this->getControllableEntity()->
    338                 getPosition().squaredDistance(this->targetPosition_) );
    339         else
    340             return ( this->getControllableEntity()->
    341                 getPosition().squaredDistance(this->target_->getPosition()) );
     336            return ( this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) );
     337        else
     338            return ( this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) );
    342339    }
    343340   
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10782 r10789  
    7676    }
    7777
     78
    7879    class _OrxonoxExport CommonController : public Controller
    7980    {
     
    121122        protected:
    122123
    123             void moveToPosition(const Vector3& target);
    124             void moveToTargetPosition();
     124            void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll);
     125            bool moveAndRoll(float dt);
     126
     127            void moveToPosition(const Vector3& target, float dt);
     128            void moveToTargetPosition(float dt);
    125129            //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes
    126130
    127131            //Mode mode_;
    128             void copyOrientation(const Quaternion& orient);
    129             void copyTargetOrientation();
     132            void copyOrientation(const Quaternion& orient, float dt);
     133            void copyTargetOrientation(float dt);
    130134
    131135            float squaredDistanceToTarget() const;
     
    160164            WeakPtr<ControllableEntity> objectiveTarget_;
    161165
    162             float angleRolled_;
    163             float angleRoll_;
    164166
    165167
     
    169171            Maneuver::Value maneuver_;
    170172
    171             ClassTreeMask               targetMask_;
    172 
     173            bool executingManeuver_;
     174            bool executingMoveToPoint_;
    173175         
    174176        private:
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10780 r10789  
    6363            this->bShooting_ = true;
    6464        }*/
    65      
    66         if (this->bHasTargetPosition_)
     65        
     66       /* if (this->bHasTargetPosition_)
    6767        {
    6868            this->moveToTargetPosition();
     69        }*/
     70        if (executingMoveToPoint_)
     71        {
     72            executingMoveToPoint_ = !this->moveAndRoll(dt);
    6973        }
    7074        if (this->bShooting_)
     
    8185        setTargetPositionOfFollower();
    8286        setTargetPositionOfWingman();
    83 
     87        if (!executingMoveToPoint_)
     88        {
     89            Vector3* targetPosition = new Vector3 (0, 0, -2000);
     90            moveToPoint(*targetPosition, 180);
     91            executingMoveToPoint_ = true;
     92        }
    8493       
    8594        if (this->myFollower_ && this->target_)
  • code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc

    r10763 r10789  
    6969            (*it2)->setTargetPosition(this->getControllableEntity()->getWorldPosition());   
    7070        }*/
    71         for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
     71        /*for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)
    7272        {
    7373            if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() == 0)
     
    7979                break;
    8080            }
    81         }
     81        }*/
    8282
    8383    }
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10780 r10789  
    6161        if (this->bHasTargetPosition_)
    6262        {
    63             this->moveToTargetPosition();
     63            this->moveToTargetPosition(dt);
    6464        }
    6565        if (this->bShooting_)
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10780 r10789  
    125125        if (this->bHasTargetPosition_)
    126126        {
    127             this->moveToTargetPosition();
     127            this->moveToTargetPosition(dt);
    128128        }
    129129       
Note: See TracChangeset for help on using the changeset viewer.