Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2018, 4:12:25 PM (6 years ago)
Author:
dreherm
Message:

Moving ghosts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhost.cc

    r11849 r11859  
    4646        RegisterObject(PacmanGhost);
    4747
    48         this->localLinearAcceleration_.setValue(1, 1, 1);
    49         this->localAngularAcceleration_.setValue(1, 1, 1);
    50 
    5148        this->velocity = Vector3(0, 0, 0);
    5249
     
    7976        SUPER(PacmanGhost, XMLPort, xmlelement, mode);
    8077
    81         XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
    82         XMLPortParam(PacmanGhost, "auxiliaryThrust", setAuxiliaryThrust, getAuxiliaryThrust, xmlelement, mode);
    83         XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
    8478        XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode);
    8579    }
     
    8781
    8882   
    89     Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,0,240)};
     83    Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,10,245),Vector3(215,10,220)};
    9084
    9185    /**
     
    9993        SUPER(PacmanGhost, tick, dt);
    10094
    101         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_);
    102         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_);
    103         if (this->localLinearAcceleration_.z() > 0)
    104             this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_);
    105         else
    106             this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    107         this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    108         this->localLinearAcceleration_.setValue(0, 0, 0);
    109 
    110         this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    111         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    112         this->localAngularAcceleration_.setValue(0, 0, 0);
    113 
     95        //setorientation
    11496
    11597        this->actuelposition = this->getPosition();
    11698       
    11799        //Stop, if target arrived
    118         if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){
     100        if((abs(this->actuelposition.x - this->target_x)<0.1) && (abs(this->actuelposition.z - this->target_z)<0.1)){
    119101                 this->ismoving = false;
    120102        }
     
    122104        //Move, if ghost hasn't arrived yet
    123105        if(this->ismoving){
    124             if(!((this->actuelposition.z-target_z)<0.1)) {
    125                 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),-sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));
     106            if(!(abs(this->actuelposition.z-target_z)<0.1)) {
     107                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));
    126108                move(dt, actuelposition, velocity);
    127109            }   
    128             if(!((this->actuelposition.x-target_x)<0.1)){
    129                 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),-sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));
     110            if(!(abs(this->actuelposition.x-target_x)<0.1)){
     111                velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z));
    130112                move(dt, actuelposition, velocity);
    131113            }
     
    134116        //Check on which position ghost has arrived and set new target
    135117         else{
    136             if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[0].z)<0.1)){
    137                 this->target_x = possibleposition[1].x;
    138                 this->target_z = possibleposition[1].z;
    139                 this->ismoving = true;
     118            if((abs(this->actuelposition.x - possibleposition[0].x)<0.1) && (abs(this->actuelposition.z - possibleposition[0].z)<0.1)){
     119                decision = rand()%1;
     120            switch(decision){
     121                case 0:
     122                    this->target_x = possibleposition[1].x;
     123                    this->target_z = possibleposition[1].z;
     124                    this->ismoving = true;
    140125            }
    141             else if(((actuelposition.x - possibleposition[1].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){
    142                 this->target_x = possibleposition[0].x;
    143                 this->target_z = possibleposition[0].z;
    144                 this->ismoving = true;
     126           
    145127            }
     128            else if((abs(actuelposition.x - possibleposition[1].x)<0.1) && (abs(actuelposition.z - possibleposition[1].z)<0.1)){
     129                decision = rand()%2;
     130            switch(decision){
     131                case 0:
     132                    this->target_x = possibleposition[0].x;
     133                    this->target_z = possibleposition[0].z;
     134                    this->ismoving = true;
     135                    break;
     136                case 1:
     137                    this->target_x = possibleposition[2].x;
     138                    this->target_z = possibleposition[2].z;
     139                    this->ismoving = true;   
     140            }
     141
     142            }
     143            if((abs(this->actuelposition.x - possibleposition[2].x)<0.1) && (abs(this->actuelposition.z - possibleposition[2].z)<0.1)){
     144                decision = rand()%1;
     145            switch(decision){
     146                case 0:
     147                    this->target_x = possibleposition[1].x;
     148                    this->target_z = possibleposition[1].z;
     149                    this->ismoving = true;
     150            }
     151           
     152            }
     153
    146154            else{
    147155            } //End of Position table
     
    151159
    152160
    153 
    154161    void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){
    155 
    156         this->setPosition(Vector3(actuelposition.x+velocity.x*dt,actuelposition.y+velocity.y*dt ,actuelposition.z+velocity.z*dt));
     162        this->setPosition(Vector3(actuelposition.x+20*velocity.x*dt,10,actuelposition.z+20*velocity.z*dt));
    157163    }
    158164
    159 
    160     /**
    161     @brief
    162         Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector.
    163     @param value
    164         The vector determining the amount of the movement.
    165     */
    166     void PacmanGhost::moveFrontBack(const Vector2& value)
    167     {
    168         //this->setPosition(dt*(actuelposition + velocity_));
     165    void PacmanGhost::resetGhost(){
     166        this->setPosition(resetposition);
    169167    }
    170 
    171     /**
    172     @brief
    173         Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.
    174     @param value
    175         The vector determining the amount of the movement.
    176     */
    177     void PacmanGhost::moveRightLeft(const Vector2& value)
    178     {
    179         this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
    180     }
    181 
    182     /**
    183     @brief
    184         Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.
    185     @param value
    186         The vector determining the amount of the movement.
    187     */
    188     void PacmanGhost::moveUpDown(const Vector2& value)
    189     {
    190         this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
    191     }
    192 
    193     /**
    194     @brief
    195         Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.
    196     @param value
    197         The vector determining the amount of the angular movement.
    198     */
    199     void PacmanGhost::rotateYaw(const Vector2& value)
    200     {
    201         this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);
    202     }
    203 
    204     /**
    205     @brief
    206         Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.
    207     @param value
    208         The vector determining the amount of the angular movement.
    209     */
    210     void PacmanGhost::rotatePitch(const Vector2& value)
    211     {
    212         this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
    213     }
    214 
    215     /**
    216     @brief
    217         Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.
    218     @param value
    219         The vector determining the amount of the angular movement.
    220     */
    221     void PacmanGhost::rotateRoll(const Vector2& value)
    222     {
    223         this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
    224     }
    225 
    226168}
Note: See TracChangeset for help on using the changeset viewer.