Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 31, 2010, 4:44:02 PM (14 years ago)
Author:
gasserlu
Message:

drone shootingRange implemented

Location:
code/branches/presentation3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/data/levels/templates/pickup_representation_templates.oxt

    r7038 r7060  
    429429
    430430<Template name=droneTemplate>
    431     <Drone name="meineDrohne"  mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=50 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>
     431    <Drone name="meineDrohne"  mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=75 maxShootingRange_=1000 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>
    432432        <attached>
    433433            <Model scale="1" mesh="drone.mesh"/>
  • code/branches/presentation3/src/orxonox/controllers/DroneController.cc

    r7038 r7060  
    7575        float random;
    7676        float maxrand = 100.0f / ACTION_INTERVAL;
     77        float distanceToTargetSquared;
    7778
    78         // const Vector3& ownerPosition = getOwner()->getWorldPosition();
    79         // const Vector3& dronePosition = getDrone()->getWorldPosition();
    80 
    81         // const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(ownerPosition-dronePosition); //Vector from Drone To Owner out of drones local coordinate system
    82 
     79        if (target_) {
     80        const Vector3& locTargetDir = getDrone()->getOrientation().UnitInverse()*((getDrone()->getWorldPosition())-(target_->getWorldPosition())); //Vector from Drone To target out of drones local coordinate system
     81            distanceToTargetSquared = locTargetDir.squaredLength();
     82        }
     83         
    8384        random = rnd(maxrand);
    84         if ( random < 30 && (!this->target_))
     85        if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
    8586            this->searchNewTarget();
    8687
    87         if (random < 50 && this->target_)
     88        if (random < 50 && this->target_ && distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
    8889        {
    8990            this->isShooting_ = true;
     
    105106    void DroneController::tick(float dt)
    106107    {
    107         // Drone *myDrone = static_cast<Drone*>(this->getControllableEntity());
    108108        float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
    109109        float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
    110110        if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength()  > maxDistanceSquared) {
    111             this->moveToPosition(this->getOwner()->getWorldPosition());
     111            this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
    112112        }
    113113        else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
    114             this->moveToPosition(-this->getOwner()->getWorldPosition());
     114            this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
    115115        }
    116116        else if(!isShooting_) {
     
    131131    void DroneController::ownerDied()
    132132    {
     133//         if (this->target_) {            //Drone has some kind of Stockholm-Syndrom --> gets attached to Owners Killer
     134//             this->setOwner(target_);
     135//             this->searchNewTarget();
     136//         }
    133137        if (this->drone_)
    134138            this->drone_->destroy();
  • code/branches/presentation3/src/orxonox/worldentities/Drone.cc

    r7039 r7060  
    7979        XMLPortParam(Drone, "maxDistanceToOwner_", setMaxDistanceToOwner, getMaxDistanceToOwner, xmlelement, mode);
    8080        XMLPortParam(Drone, "minDistanceToOwner_", setMinDistanceToOwner, getMinDistanceToOwner, xmlelement, mode);
     81        XMLPortParam(Drone, "maxShootingRange_", setMaxShootingRange, getMaxShootingRange, xmlelement, mode);
    8182    }
    8283
  • code/branches/presentation3/src/orxonox/worldentities/Drone.h

    r7039 r7060  
    114114            inline void setMinDistanceToOwner( float distance)
    115115                { this->minDistanceToOwner_=distance; }
     116            inline void setMaxShootingRange( float distance)
     117                { this->maxShootingRange_=distance; }
    116118
    117119           
     
    130132            inline float getMinDistanceToOwner()
    131133                { return this->minDistanceToOwner_; }
     134            inline float getMaxShootingRange()
     135                { return this->maxShootingRange_; }
    132136           
    133137        private:
     
    141145            float maxDistanceToOwner_; //Maximum Distance to owner
    142146            float minDistanceToOwner_; //Minimum Distance to owner
     147            float maxShootingRange_;
    143148    };
    144149
Note: See TracChangeset for help on using the changeset viewer.