Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2014, 3:28:28 PM (10 years ago)
Author:
smerkli
Message:

Some cleanups, added a "change look" command

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc

    r10065 r10066  
    4747        this->ctrlid_ = 0;
    4848
    49 
    5049        /* Set default values for all variables */
    5150        /* - pointers to zero */
     
    5554        /* - times */
    5655        this->scTime = 0.0f;
    57         this->timeToTarget = 0.0f;
    5856        this->eventTime = 0.0f;
    5957
    6058        /* - Points in space */
    61         this->target = Vector3(0,0,0);
    6259        this->startpos = Vector3(0,0,0);
    63         this->lookAtPosition = Vector3(0,0,0);
     60        //this->lookAtPosition = Vector3(0,0,0);
    6461
    6562        /* - Processing flag */
     
    9592    }
    9693
    97     /* Yet to be implemented and tested */
    98     //void ScriptController::yieldControl()
    99     //{
    100         //this->player_->startControl(this->entity_);
    101         //this->setActive(false);
    102         //this->controllableEntity_ = NULL;
    103     //}
    104 
    10594    const Vector3& ScriptController::getPosition()
    10695    {
     
    136125    void ScriptController::execute(event ev)
    137126    {
    138         orxout() << "Executing event " << ev.fctName
    139           << " with parameters:\n "
    140           << ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n"
    141           << ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n"
    142           << ev.duration << endl;
    143 
     127        /* Debugging output */
     128        //orxout() << "Executing event " << ev.fctName
     129          //<< " with parameters:\n "
     130          //<< ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n"
     131          //<< ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n"
     132          //<< ev.duration << endl;
     133
     134        /* Event is starting, hence set the time to 0 */
    144135        this->eventTime = 0.0f;
     136        this->processing = true;
     137
     138        /* Copy the event into the currentEvent holder */
     139        this->currentEvent = ev;
     140
     141        /* Store starting position */
    145142        this->startpos = this->entity_->getPosition();
    146         this->processing = true;
    147 
    148         if(ev.fctName == "mal")
    149           moveAndLook(ev.x1, ev.y1, ev.z1, ev.x2, ev.y2, ev.z2, ev.duration);
    150143    }
    151144
     
    157150
    158151        /* If this controller has no entity entry, do nothing */
    159         if( !(this->entity_) )
    160           return;
    161 
    162         //orxout() << "Size 0: " << this->eventList.size() << endl;
     152        if( !(this->entity_) ) return;
    163153
    164154        /* See if time has come for the next event to be run */
    165155        if(this->eventList.size() > 0 && this->eventList[0].eventTime <= scTime)
    166         {
    167           /* Execute the next event on the list */
     156        { /* Execute the next event on the list */
    168157          this->execute(this->eventList[0]);
    169158          this->eventList.erase(this->eventList.begin());
    170159          this->eventno -= 1;
    171           //orxout() << "Size 1: " << this->eventList.size() << endl;
    172           //orxout() << "Eventno is now: " << this->eventno << endl;
    173160        }
    174161
    175162        /* Update the local timers in this object */
    176         scTime += dt;
    177         eventTime += dt;
     163        scTime += dt; eventTime += dt;
    178164
    179165        /* If we've arrived at the target, stop processing */
    180         if( eventTime > timeToTarget && this->processing == true)
     166        if( eventTime > currentEvent.duration && this->processing == true)
    181167        { this->processing = false;
    182168
    183           //orxout() << "Size 4: " << this->eventList.size() << endl;
    184           //orxout() << "Eventno: " << this->eventno << endl;
    185          
     169          /* If we reached the last event, also reenable the normal movement
     170           * and make the model visible again
     171           */
    186172          if( this->eventno == 0 )
    187173          {
     
    194180         * we are
    195181         */
    196         float dl = eventTime / timeToTarget;
    197 
     182        float dl = eventTime / currentEvent.duration;
     183
     184        /* Depending  */
    198185        /* Do some moving */
    199186        if( this->processing )
    200187        {
    201           /* Set the position to the correct place in the trajectory */
    202           this->entity_->setPosition( (1-dl)*startpos + dl * target );
    203 
    204           /* Look at the specified position */
    205           this->entity_->lookAt(lookAtPosition);
     188          if( this->currentEvent.fctName == "mal" )
     189          {
     190            /* Set the position to the correct place in the trajectory */
     191            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
     192
     193            /* Look at the specified position */
     194            this->entity_->lookAt(this->currentEvent.v2);
     195
     196            /* Update look at position */
     197            //this->lookAtPosition = this->currentEvent.v2;
     198          }
     199          else if( this->currentEvent.fctName == "chl" )
     200          {
     201            /* Sweep the look from v1 to v2 */
     202            this->entity_->lookAt( (1-dl)*this->currentEvent.v1 +
     203              dl * this->currentEvent.v2 );
     204          }
     205
    206206
    207207          /* Force mouse look */
     
    209209            this->entity_->mouseLook();
    210210        }
    211     }
    212 
    213     void ScriptController::moveAndLook(
    214       float xm, float ym, float zm,
    215       float xl, float yl, float zl,
    216       float t )
    217     {
    218       orxout()<<"moveAndLook executed"<<endl;
    219 
    220       /* Set the local variables required for this event */
    221       this->target = Vector3(xm,ym,zm);
    222       this->lookAtPosition = Vector3(xl,yl,zl);
    223       this->timeToTarget = t;
    224 
    225 
    226       orxout() << "Moving This-pointer: " << this << endl;
    227 
    228       if(this->entity_ != NULL)
    229         orxout()<<"not-NULL-entity"<<endl;
    230       else
    231         return;
    232 
    233       if(this->player_ != NULL)
    234         orxout()<<"not-NULL-player"<<endl;
    235       else
    236         return;
    237211    }
    238212
     
    250224      /* Fill the structure with all the provided information */
    251225      tmp.fctName = instruction;
    252       tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
    253       tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
     226      //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
     227      //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
     228      tmp.v1 = Vector3(x1,y1,z1);
     229      tmp.v2 = Vector3(x2,y2,z2);
    254230      tmp.duration = duration;
    255231      tmp.eventTime = executionTime;
Note: See TracChangeset for help on using the changeset viewer.