Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10782


Ignore:
Timestamp:
Nov 9, 2015, 11:19:51 AM (8 years ago)
Author:
gania
Message:

not compilable change to move behaviour

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

Legend:

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

    r10780 r10782  
    251251        }
    252252    }
    253 
    254     bool CommonController::isCloseAtTarget(float distance) const
     253    //to be called in action
     254    //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)
     258    {
     259        ControllableEntity* entity = this->getControllableEntity();
     260        if (!entity)
     261            return false;
     262        Quaternion orient = entity->getWorldOrientation();
     263
     264        Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition();
     265        setTargetPosition(target);
     266        this->angleRoll_ = angleRoll;
     267        this->angleRolled_ = 0;
     268    }
     269    //to be called in tick
     270    //PRE: MoveToPoint was called
     271    //POST: spaceship changes its yaw and pitch to point towards targetPosition_,
     272    //moves towards targetPosition_ by amount depending on dt and its speed,
     273    //rolls by amount depending on the difference between angleRoll_ and angleRolled_, dt, and
     274    //angular speed
     275    //if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false,
     276    //otherwise returns true
     277    bool MoveAndRoll(float dt)
     278    {
     279        int tolerance = 60;
     280        float rollDiff = angleRoll-angleRolled_;
     281        float angleToRoll = 0;
     282        ControllableEntity* entity = this->getControllableEntity();
     283        if (!entity)
     284            return false;
     285        Vector2 coord = get2DViewCoordinates
     286            (entity->getPosition(),
     287            entity->getOrientation() * WorldEntity::FRONT,
     288            entity->getOrientation() * WorldEntity::UP,
     289            targetPosition_);
     290
     291        float distance = (targetPosition_ - this->getControllableEntity()->getPosition()).length();
     292
     293        //rotates should be in range [-1,+1], clamp cuts off all that is not
     294        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
     295        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
     296
     297       
     298        if (distance > tolerance)
     299        {
     300            //Yaw and Pitch are enough to start facing the target
     301            this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX * dt);
     302            this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt);
     303           
     304            //Move
     305            this->getControllableEntity()->moveFrontBack(1.2f * SPEED * factor * dt);
     306           
     307            //Roll
     308            angleToRoll = rollDiff * ROTATEFACTOR * dt;
     309            this->getControllableEntity()->rotateRoll(angleToRoll);
     310            angleRolled_ += angleToRoll;
     311            //if still moving, return false
     312            return false;
     313        }
     314        else
     315        {     
     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            }
     327            //if finished, return true;
     328            retun true;
     329        }
     330    }
     331
     332    float squaredDistanceToTarget()
     333    {
     334        if ( !this->getControllableEntity() )
     335            return 0;
     336        if ( !this->target_ )
     337            return ( this->getControllableEntity()->
     338                getPosition().squaredDistance(this->targetPosition_) );
     339        else
     340            return ( this->getControllableEntity()->
     341                getPosition().squaredDistance(this->target_->getPosition()) );
     342    }
     343   
     344    bool CommonController::isLookingAtTarget(float angle) const
    255345    {
    256346        if (!this->getControllableEntity())
    257347            return false;
    258348
    259         if (!this->target_)
    260             return (this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
    261         else
    262             return (this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
    263     }
    264     bool CommonController::isLookingAtTarget(float angle) const
    265     {
    266         if (!this->getControllableEntity())
    267             return false;
    268 
    269349        return (getAngle(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->targetPosition_) < angle);
    270350    }
     
    272352    bool CommonController::canFire()
    273353    {
    274         if ( this->bShooting_ && this->isCloseAtTarget(3000) && this->isLookingAtTarget(math::pi / 20.0f) )
     354        float squaredDistance = squaredDistanceToTarget();
     355        if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget(math::pi /(0.0002f*squaredDistance)) )
    275356        {
    276357            return true;
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10780 r10782  
    129129            void copyTargetOrientation();
    130130
    131             bool isCloseAtTarget(float distance) const;
     131            float squaredDistanceToTarget() const;
    132132            void doFire();
    133133            void aimAtTarget();
     
    150150
    151151
    152             bool bHasObjectivePosition_;
    153             Vector3 objectivePosition_;
    154             bool bHasObjectiveOrientation_;
    155             Quaternion objectiveOrientation_;
     152            bool bHasPositionOfTarget_;
     153            Vector3 positionOfTarget_;
     154            bool bHasOrientationOfTarget_;
     155            Quaternion orientationOfTarget_;
     156
    156157
    157158            WeakPtr<ControllableEntity> target_;
     
    159160            WeakPtr<ControllableEntity> objectiveTarget_;
    160161
     162            float angleRolled_;
     163            float angleRoll_;
    161164
    162165
Note: See TracChangeset for help on using the changeset viewer.