Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10800


Ignore:
Timestamp:
Nov 13, 2015, 4:45:44 PM (8 years ago)
Author:
gania
Message:

compilable

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

Legend:

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

    r10799 r10800  
    2626 *
    2727 */
     28//bug or feature? Press 4 control keys from {Q,W,E,A,S,D,C} at the same time or 3 keys from {Q,E,A,D}, spaceship goes in free fly mode
    2829#include "controllers/CommonController.h"
    2930#include "core/XMLPort.h"
     
    4546
    4647    RegisterClass( CommonController );
    47     float SPEED = 0.7f/0.02f;
    48     float ROTATEFACTOR = 0.3f/0.02f;
     48    float SPEED = 0.9f/0.02f;
     49    float ROTATEFACTOR = 0.5f/0.02f;
    4950
    5051    CommonController::CommonController( Context* context ): Controller( context )
     
    132133                ) );*/
    133134            this->setPositionOfTarget( this->target_->getWorldPosition()  );
    134             this->setOrientationOfTarget( this->target_->getControllableEntity() ->getOrientation() );
     135            this->setOrientationOfTarget( this->target_->getOrientation() );
    135136
    136137
     
    160161                if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis )
    161162                {
    162                     //if this can make target overshoot
    163                     if ( diffLength < 200 )
     163                    //no way to dodge
     164                    if ( diffLength < 400 )
    164165                    {
    165166                        Vector3* target = new Vector3 ( 0, -200, -200 );
    166                         moveToPoint(
    167                             *target,
    168                             randomInRange( 45, 180 )
    169                             );
     167                        this->setTargetPosition( this->positionOfTarget_ );
     168
     169
    170170                    }
    171171                    //do scissors
    172172                    else
    173173                    {
    174                         Vector3 target = ( diffUnit )* 150.0f
     174                        Vector3 target = ( diffUnit )* 150.0f;
    175175                        Vector3* randVector = new Vector3(
    176176                            randomInRange( -300, 300 ),
     
    178178                            randomInRange( -300, 300 )
    179179                        );
    180                         Vector3 projection = randVector.dotProduct( diffUnit )* diffUnit;
     180                        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
    181181                        *randVector -= projection;
    182                         target += randVector;
    183                         moveToPoint(
    184                             *target,
    185                             randomInRange( 45, 180 )
    186                             );
     182                        target += *randVector;
     183                        this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target );
     184
    187185                    }
    188186                }
     
    202200                }
    203201            }
     202            else
     203            {
     204                //if diff is insignificant
     205                if ( bThisIsLookingAtTarget && bTargetIsLookingAtThis )
     206                {
     207                    //no way to dodge
     208                    if ( diffLength < 400 )
     209                    {
     210                        Vector3* target = new Vector3 ( 0, -200, -200 );
     211                        this->setTargetPosition( this->positionOfTarget_ );
     212
     213                    }
     214                    //do scissors
     215                    else
     216                    {
     217                        Vector3 target = ( diffUnit )* 150.0f;
     218                        Vector3* randVector = new Vector3(
     219                            randomInRange( -300, 300 ),
     220                            randomInRange( -300, 300 ),
     221                            randomInRange( -300, 300 )
     222                        );
     223                        Vector3 projection = randVector->dotProduct( diffUnit )* diffUnit;
     224                        *randVector -= projection;
     225                        target += *randVector;
     226                        this->setTargetPosition( this->getControllableEntity() ->getWorldPosition() + target );
     227
     228                    }
     229                }
     230                //target has advantage
     231                else
     232                {
     233                    //if too close
     234                    if ( diffLength < 300 )
     235                    {
     236                        this->setTargetPosition( this->getControllableEntity() ->getWorldPosition()  );
     237                    }
     238                    //move closer
     239                    else
     240                    {
     241                        this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector );
     242                    }
     243                }
     244            }
     245            this->bShooting_ = true;
    204246           
    205247        }
     
    730772            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->targetPosition_ ) );
    731773        else
    732             return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->target_->getPosition() ) );
     774            return ( this->getControllableEntity() ->getPosition() .squaredDistance( this->positionOfTarget_ ) );
    733775    }
    734776   
     
    738780            return false;
    739781
    740         return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->targetPosition_ ) < angle );
     782        return ( getAngle( this->getControllableEntity() ->getPosition() , this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT, this->positionOfTarget_ ) < angle );
    741783    }
    742784
     
    744786    {
    745787        float squaredDistance = squaredDistanceToTarget();
     788        this->setPositionOfTarget( this->target_->getPosition() );
     789
    746790        if ( this->bShooting_ && squaredDistance < 9000000 && squaredDistance > 10000 && this->isLookingAtTarget( math::pi /( 0.0002f*squaredDistance )) )
    747791        {
     
    760804        static const float hardcoded_projectile_speed = 750;
    761805
    762         this->targetPosition_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
    763         this->bHasTargetPosition_ = ( this->targetPosition_ != Vector3::ZERO );
     806        this->positionOfTarget_ = getPredictedPosition( this->getControllableEntity() ->getWorldPosition() , hardcoded_projectile_speed, this->target_->getWorldPosition() , this->target_->getVelocity() );
     807        this->bHasPositionOfTarget_ = ( this->positionOfTarget_ != Vector3::ZERO );
    764808
    765809        Pawn* pawn = orxonox_cast<Pawn*>( this->getControllableEntity() );
     
    767811        if ( pawn )
    768812            //pawn->setAimPosition( this->getControllableEntity() ->getWorldPosition()  + 4000*( this->getControllableEntity() ->getOrientation()  * WorldEntity::FRONT ));
    769             pawn->setAimPosition( this->targetPosition_ );
     813            pawn->setAimPosition( this->positionOfTarget_ );
    770814   
    771815        this->getControllableEntity() ->fire( 0 );
  • code/branches/AI_HS15/src/orxonox/controllers/CommonController.h

    r10796 r10800  
    8383        static const float hardcoded_projectile_speed = 750;
    8484
    85             static const float ACTION_INTERVAL = 1.0f;
     85            static const float ACTION_INTERVAL = 2.0f;
    8686
    8787
     
    167167            WeakPtr<ControllableEntity> objectiveTarget_;
    168168
    169 
     169            void maneuver();
    170170            void chooseManeuverType();
    171171            void gunsD();
  • code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc

    r10797 r10800  
    6969        }*/
    7070       
    71        /* if (this->bHasTargetPosition_)
    72         {
    73             this->moveToTargetPosition();
    74         }*/
    75         if (executingMoveToPoint_)
     71        if (this->bHasTargetPosition_)
     72        {
     73            this->moveToTargetPosition(dt);
     74        }
     75       /* if (executingMoveToPoint_)
    7676        {
    7777            executingMoveToPoint_ = !this->moveAndRoll(dt);
     
    8989                Vector3 diffVector = this->positionOfTarget_ - this->getControllableEntity()->getWorldPosition();
    9090                float diffLength = diffVector.length();
    91                /* Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
     91                Quaternion rotationToTarget = (this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).getRotationTo(diffVector);
    9292                Vector3* targetPosition = new Vector3 ( 0, 0, -200 );
    93                 Vector3 target = rotationToTarget * (*targetPosition);*/
     93                Vector3 target = rotationToTarget * (*targetPosition);
    9494                if (diffLength > 200)
    9595                    this->setTargetPosition( this->positionOfTarget_ - 0.6f*diffVector);
     
    106106                this->moveAndRoll(dt);
    107107            }
    108         }
    109         if (this->bShooting_)
     108        }*/
     109        if (this->bShooting_ && this->canFire())
    110110            doFire();
    111111        SUPER(DivisionController, tick, dt);
     
    135135        }*/
    136136        //this->chooseManeuverType();
     137                    this->maneuver();
     138
    137139        switch (this->maneuverType_)
    138140        {
Note: See TracChangeset for help on using the changeset viewer.