Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 8, 2015, 6:19:12 PM (9 years ago)
Author:
gania
Message:

fixed firing direction

Location:
code/branches/AI_HS15/src/orxonox/controllers
Files:
5 edited

Legend:

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

    r10764 r10780  
    3636#include "worldentities/pawns/SpaceShip.h"
    3737
    38 
     38#include "Scene.h"
     39#include <OgreRay.h>
     40#include <OgreSceneQuery.h>
     41#include <OgreCamera.h>
     42#include <OgreSceneManager.h>
    3943namespace orxonox
    4044{
     
    4751    {
    4852        this->bSetupWorked = false;
     53
     54        this->targetMask_.exclude(ClassByString("BaseObject"));
     55        this->targetMask_.include(ClassByString("WorldEntity"));
     56        this->targetMask_.exclude(ClassByString("Projectile"));
    4957
    5058        RegisterObject(CommonController);
     
    234242                }
    235243            }
    236                     orxout (internal_error) << "MOVING" <<endl ;
    237244
    238245            this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor);
     
    255262            return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
    256263    }
    257    
     264    bool CommonController::isLookingAtTarget(float angle) const
     265    {
     266        if (!this->getControllableEntity())
     267            return false;
     268
     269        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
     270    }
    258271
    259272    bool CommonController::canFire()
    260273    {
    261        
    262         float tolerance = 50.0f;
    263        
    264         //check pointers
    265         if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity())
     274        if ( this->bShooting_ && this->isCloseAtTarget(3000) && this->isLookingAtTarget(math::pi / 20.0f) )
     275        {
     276            return true;
     277        }
     278        else
     279        {
    266280            return false;
    267        
    268         //check if this points in the direction of target_
    269 
    270         Vector3 myPosition = this->getControllableEntity()->getWorldPosition();
    271         Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition();
    272        
    273         Vector3 differenceVector = targetPosition - myPosition;
    274         float differenceLength = differenceVector.length();
    275        
    276         Vector3 myDirection = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
    277        
    278         float angle = getAngle (myPosition, myDirection, targetPosition);
    279         float heightLength = sin(angle) * differenceLength;
    280 
    281         if (heightLength > tolerance)
    282             return false;
    283        
    284 
    285 
    286         //check if there are allies on the way
    287         Vector3 allyPosition, allyDifference;
    288         float allyDifferenceLength, allyAngle, allyHeightLength;
    289 
    290         for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
    291         {
    292             if (!it->getControllableEntity())
    293                 continue;
    294             if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
    295             {
    296                 allyPosition = it->getControllableEntity()->getWorldPosition();
    297 
    298                 allyDifference = allyPosition - myPosition;
    299                 allyDifferenceLength = allyDifference.length();
    300 
    301                 allyAngle = getAngle (myPosition, myDirection, allyPosition);
    302 
    303                 allyHeightLength = sin(allyAngle) * allyDifferenceLength;
    304 
    305                 if (allyAngle > math::pi /2)
    306                     continue;
    307                 if (allyHeightLength <= tolerance)
    308                     return false;
    309             }
    310         }
     281        }
     282
     283    }
     284    void CommonController::doFire()
     285    {
     286        if (!this->target_ || !this->getControllableEntity())
     287            return;
     288        static const float hardcoded_projectile_speed = 750;
     289
     290        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
     291        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    311292
    312293        Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
    313294        if (pawn)
    314             pawn->setAimPosition(WorldEntity::FRONT);
     295            pawn->setAimPosition(this->getControllableEntity()->getWorldPosition() + 4000*(this->getControllableEntity()->getOrientation() * WorldEntity::FRONT));
    315296   
    316         return true;
    317 
    318     }
    319     void CommonController::doFire()
    320     {
    321297        this->getControllableEntity()->fire(0);
    322298    }
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10763 r10780  
    3434#include "worldentities/ControllableEntity.h"
    3535#include "worldentities/pawns/Pawn.h"
     36#include "core/ClassTreeMask.h"
    3637
    3738
     
    164165            ManeuverType::Value maneuverType_;
    165166            Maneuver::Value maneuver_;
     167
     168            ClassTreeMask               targetMask_;
     169
    166170         
    167171        private:
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10763 r10780  
    6868            this->moveToTargetPosition();
    6969        }
    70 
     70        if (this->bShooting_)
     71            doFire();
    7172        SUPER(DivisionController, tick, dt);
    7273
     
    9798        }
    9899           */
    99        
    100100        if (canFire())
    101             doFire();
    102      
     101           this->bShooting_ = true;
     102        else
     103            this->bShooting_ = false;
    103104    }
    104105
  • code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc

    r10762 r10780  
    6363            this->moveToTargetPosition();
    6464        }
    65 
     65        if (this->bShooting_)
     66            doFire();
    6667       
    6768        SUPER(SectionController, tick, dt);
     
    8687        if (this->target_ && this->myWingman_)
    8788            this->myWingman_->setTarget(this->target_);
    88 
    8989        if (canFire())
    90             doFire();
     90           this->bShooting_ = true;
     91        else
     92            this->bShooting_ = false;
    9193               
    9294
  • code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc

    r10762 r10780  
    128128        }
    129129       
    130        
     130        if (this->bShooting_)
     131            doFire();
    131132       
    132133        SUPER(WingmanController, tick, dt);
     
    152153
    153154        }
    154 
    155155        if (canFire())
    156             doFire();
     156           this->bShooting_ = true;
     157        else
     158            this->bShooting_ = false;
     159         
    157160    }
    158161     
Note: See TracChangeset for help on using the changeset viewer.