Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10066


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

Some cleanups, added a "change look" command

Location:
code/branches/ScriptableController
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ScriptableController/data/gui/scripts/testscript.lua

    r10065 r10066  
    2020  -- Move to the starting point at (xl+3000,yl,zl) while looking
    2121  -- at xl,yl,zl over the time span of 3 seconds
    22   ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 3, 0)
     22  ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 1, 0)
    2323
    2424  -- From there, perform a rotation around the harvester placed there
     
    2929    yt = math.sin(t)
    3030
    31     ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, 3*dt, 3*t+2.9)
     31    ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, dt, t+0.9)
    3232  end
    3333
    3434  -- Update absolute time
    35   Tabs = 3*math.pi + 2.9
     35  Tabs = math.pi + 0.9
    3636
    3737  -- Move away again, still looking at the station
    3838  ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3, Tabs+0.4)
    3939
     40  -- Update absolute time
     41  Tabs = Tabs + 0.4 + 3
     42
     43  -- Transition the look from (xl,yl,zl) to (3500,0,0) in 3 seconds
     44  ctrl:eventScheduler("chl", xl, yl, zl, 3500, 0, 0, 3, Tabs)
    4045
    4146end
  • 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;
  • code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h

    r10065 r10066  
    3939{  // tolua_export
    4040
     41    /** Structure to describe a single event */
    4142    struct event
    4243    {   
     44        /** Instruction for this event */
    4345        std::string fctName;
    44         float x1;
    45         float y1;
    46         float z1;
    4746
    48         float x2;
    49         float y2;
    50         float z2;
     47        Vector3 v1;
     48        Vector3 v2;
    5149
     50        /** Time span of the event */
    5251        float duration;
    5352
     53        /** Start point in time of the event */
    5454        float eventTime;
    55 
    5655    };
    5756
     
    6160        public:
    6261            ScriptController(Context* context);
    63 
    6462            virtual ~ScriptController() { }
    6563
    66             //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    67            
    6864            void takeControl(int ctrlid);
    6965            void setPlayer(PlayerInfo* player) { this->player_ = player; }
     
    7369            // LUA interface
    7470            // tolua_begin
    75             void moveAndLook(float xm, float ym, float zm,
    76               float xl, float yl, float zl, float t);
    77 
    7871            void eventScheduler(std::string instruction,
    7972              float x1, float y1, float z1,
     
    115108            bool processing;
    116109
    117             /* Data about the point to go to and what to look at */
    118             /* - Target position */
    119             Vector3 target;
    120 
    121             /* - Time it should take to get there */
    122             float timeToTarget;
     110            /* Data about the event currently being processed */
     111            /* - The event itself */
     112            event currentEvent;
    123113
    124114            /* - Time this event has been going on for */
     
    127117
    128118            /* - Position to look at during that transition */
    129             Vector3 lookAtPosition;
     119            //Vector3 lookAtPosition;
    130120
    131121    };// tolua_export
Note: See TracChangeset for help on using the changeset viewer.