Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 31, 2015, 4:07:29 PM (9 years ago)
Author:
gania
Message:

added a little bit of firing functionality

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc

    r10729 r10731  
    3535    static const float ROTATEFACTOR = 0.2f;
    3636
    37     /*static const float SPEED_FREE = 0.8f;
    38     static const float ROTATEFACTOR_FREE = 0.8f;*/
    39    
     37    CommonController::CommonController(Context* context) : Controller(context)
     38    {
     39
     40        RegisterObject(CommonController);
     41    }
     42
     43
     44    CommonController::~CommonController()
     45    {
     46    }
     47
     48
     49
     50
    4051    bool CommonController::setWingman (CommonController* wingman)
    4152    {
    4253        return false;
    4354    }
    44     bool CommonController::isLeader ()
    45     {
    46         return false;
    47     }
     55   
    4856    bool CommonController::hasWingman()
    4957    {
     
    5159    }
    5260
    53     CommonController::CommonController(Context* context) : Controller(context)
    54     {
    55 
    56         RegisterObject(CommonController);
    57     }
    58 
    59 
    60     CommonController::~CommonController()
    61     {
    62     }
     61
     62
     63
     64    void CommonController::setTargetPosition(const Vector3& target)
     65    {
     66        this->targetPosition_ = target;
     67        this->bHasTargetPosition_ = true;
     68    }
     69
     70    void CommonController::setTargetOrientation(const Quaternion& orient)
     71    {
     72        this->targetOrientation_=orient;
     73        this->bHasTargetOrientation_=true;
     74    }
     75
     76    void CommonController::setTargetOrientation(ControllableEntity* target)
     77    {
     78        if (target)
     79            setTargetOrientation(target->getOrientation());
     80    }
     81
     82    /*void CommonController::spin()
     83    {
     84        this->moveToTargetPosition();
     85        this->getControllableEntity()->rotateRoll(8.0f);
     86    }
     87    void CommonController::turn180()
     88    {
     89        Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
     90
     91        this->getControllableEntity()->rotateYaw(-2.0f * sgn(coord.x) * coord.x*coord.x);
     92        this->getControllableEntity()->rotatePitch(2.0f * sgn(coord.y) * coord.y*coord.y);
     93
     94        this->getControllableEntity()->moveFrontBack(SPEED);
     95    }*/
     96
     97
     98
    6399    //copy the Roll orientation of given Quaternion.
    64100    void CommonController::copyOrientation(const Quaternion& orient)
     
    69105        while(diff<-math::twoPi) diff+=math::twoPi;
    70106        this->getControllableEntity()->rotateRoll(-diff);
    71 
    72 
    73 
    74     }
    75     void CommonController::setTargetPosition(const Vector3& target)
    76     {
    77         this->targetPosition_ = target;
    78         this->bHasTargetPosition_ = true;
    79     }
    80 
     107    }
    81108    void CommonController::copyTargetOrientation()
    82109    {
     
    86113        }
    87114    }
    88     void CommonController::setTargetOrientation(const Quaternion& orient)
    89     {
    90         this->targetOrientation_=orient;
    91         this->bHasTargetOrientation_=true;
    92     }
    93     void CommonController::setTargetOrientation(ControllableEntity* target)
    94     {
    95         if (target)
    96             setTargetOrientation(target->getOrientation());
    97     }
    98 
    99 
     115
     116
     117
     118
     119    void CommonController::moveToTargetPosition()
     120    {
     121        this->moveToPosition(this->targetPosition_);
     122    }
    100123    void CommonController::moveToPosition(const Vector3& target)
    101124    {
     
    146169            bHasTargetOrientation_ = false;
    147170        }
    148 
    149      
    150     }
    151     void CommonController::moveToTargetPosition()
    152     {
    153         this->moveToPosition(this->targetPosition_);
    154     }
     171    }
     172    void CommonController::doFire()
     173    {
     174         if (this->isLookingAtTarget(math::pi / 20.0f))
     175            this->getControllableEntity()->fire(0); //ai uses lens flare if they're close enough to the target
     176    }
     177    bool CommonController::isLookingAtTarget(float angle) const
     178    {
     179        if (!this->getControllableEntity())
     180            return false;
     181
     182        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
     183    }
     184
     185    void CommonController::aimAtTarget()
     186    {
     187        if (!this->target_ || !this->getControllableEntity())
     188            return;
     189
     190        static const float hardcoded_projectile_speed = 750;
     191
     192        Vector3 aimPosition = getPredictedPosition(this->getControllableEntity()->getWorldPosition(),
     193            hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
     194
     195        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
     196        if (pawn)
     197            pawn->setAimPosition(aimPosition);
     198    }
     199   
    155200 
    156201
Note: See TracChangeset for help on using the changeset viewer.