Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2016, 4:38:51 PM (8 years ago)
Author:
fvultier
Message:

merged scriptable controller

Location:
code/branches/presentationFS16
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentationFS16

  • code/branches/presentationFS16/src/orxonox/controllers/ScriptController.cc

    r11083 r11207  
    3434  * Command             | Abbreviation | Parameter 1          | '' 2     | '' 3    | '' 4                 | '' 5     | '' 6     | '' 7
    3535  *
    36   * "Move And Look"     | mal          | GoTo X Coordinate    | '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
    37   * "Rotate And Look"   | ral          | GoTo X Coordinate    | '' Y ''  | '' Z '' | Axis (1=x, 2=z, 3=z) |     -    |     -    | Duration
    38   * "Spiral"            | spi          | GoTo X Coordinate    | '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
    39   * "Transition Look"   | chl          | From X Coordinate    | '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
     36  * "Move And Look"     | mal          | GoTo X Coordinate    |  '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
     37  * "Rotate And Look"   | ral          | GoTo X Coordinate    |  '' Y ''  | '' Z '' | Axis (1=x, 2=y, 3=z) |     -    |     -    | Duration
     38  * "Spiral"            | spi          | GoTo X Coordinate    |  '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
     39  * "Transition Look"   | chl          | From X Coordinate    |  '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
     40  * "rotate round X crd"| rotX         | anchor coordinate    | angle(rad)|    -    |                      |          |          | Duration
    4041  * "Idle (Do nothing)" | idle         | Duration
    4142  */
     
    4647#include "worldentities/ControllableEntity.h"
    4748#include "core/LuaState.h"
    48 #include "core/LuaState.h"
    4949#include "util/Math.h"
    5050
     
    9090        /* Output some debugging information */
    9191        orxout(verbose) << "ScriptController: Taking control" << endl;
    92         orxout(verbose) << "This-pointer: " << this << endl;
     92        orxout(verbose) << "This-pointer: " << this << endl; 
    9393
    9494        /* Set the controller ID (the argument here should be nonzero) */
     
    103103         */
    104104        this->entity_->setDestroyWhenPlayerLeft(false);
    105         this->player_->pauseControl();
     105        this->player_->stopTemporaryControl();
    106106        this->entity_->setController(this);
    107107        this->setControllableEntity(this->entity_);
    108         this->entity_->mouseLook();
    109         this->entity_->setVisible(false);
     108        //this->entity_->mouseLook();
     109        //this->entity_->setVisible(false);
     110       
     111        // TODO take the human Controllers control  dont forget to give it back in the destructor
    110112    }
    111113
     
    201203        {
    202204          // Abbreviation for "spiral" (rotation + translation)
    203           if (this->currentEvent.fctName == "spi") {
    204 
    205             // Need to know a perpendicular basis to the translation vector:
     205          if (this->currentEvent.fctName == "spi")
     206          {
     207              spi(dl); // call the external function
     208          }
     209
     210          // Abbreviation for "rotate and look"
     211          else if (this->currentEvent.fctName == "ral")
     212          {
     213              ral(dl); 
     214          }
     215          else if( this->currentEvent.fctName == "mal" )
     216          {
     217              mal(dl);
     218          }
     219          else if( this->currentEvent.fctName == "chl" )
     220          {
     221              chl(dl);
     222          }
     223
     224
     225          /* Force mouse look */
     226          if( this->entity_->isInMouseLook() == false )
     227            this->entity_->mouseLook();
     228        }
     229    }
     230
     231    void ScriptController::eventScheduler(std::string instruction,
     232      float x1, float y1, float z1,
     233      float x2, float y2, float z2,
     234      float duration, float executionTime)
     235    {
     236      /* put data (from LUA) into time-sorted eventList*/
     237      /* Nimmt den befehl und die argumente aus luascript und ertellt einen
     238       * struct pro event, diese structs werden sortiert nach eventTime
     239       */
     240      struct event tmp;
     241
     242      /* Fill the structure with all the provided information */
     243      tmp.fctName = instruction;
     244
     245      //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
     246      //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
     247      tmp.v1 = Vector3(x1,y1,z1);
     248      tmp.v2 = Vector3(x2,y2,z2);
     249
     250      // the parameters are not required to be vector coordinates!
     251      // for convenience they are however stored twice if they have some kind of different meaning
     252      tmp.a = x1;
     253      tmp.b = y1;
     254      tmp.c = z1;
     255      tmp.d = x2;
     256      tmp.e = y2;
     257      tmp.f = z2;
     258
     259      tmp.duration = duration;
     260
     261      /* This is kind of a hack. If we hit the function idle all we want to do is
     262         advance event execution time, not schedule anything */
     263      if (instruction == "idle") {
     264        tmp.eventTime = this->prevEventTime;
     265        this->prevEventTime += x1;
     266        return;
     267      } else {
     268        tmp.eventTime = this->prevEventTime;
     269        this->prevEventTime += duration;
     270      }
     271
     272      /* Add the created event to the event list */
     273      if(eventList.size()==0)
     274      { /* The list is still empty, just add it */
     275        orxout(verbose) << "eventList empty (01)" << endl;
     276        eventList.insert(eventList.begin(), tmp);
     277        this->eventno += 1;
     278        return; /* Nothing more to do, the event was added */
     279      }
     280
     281      /* Event was not added yet since the list was not empty. Walk through
     282       * the list of events and add it so that the events are correctly in
     283       * order.
     284       */
     285      for (std::vector<event>::iterator it=eventList.begin(); it<eventList.end(); it++)
     286      { if(tmp.eventTime < it->eventTime)
     287        { eventList.insert(it,tmp);
     288          this->eventno += 1;
     289          //orxout()<<"new event added"<<endl;
     290          return;
     291        }
     292      }
     293
     294      /* If the event was still not added here, it belongs in the end of the list */
     295      eventList.insert(eventList.end(), tmp);
     296      this->eventno += 1;
     297
     298    }
     299
     300    // Event Functions
     301
     302    void ScriptController::spi(float dl)
     303    {
     304   
     305                // Need to know a perpendicular basis to the translation vector:
    206306            // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm
    207307            // Currently we set a fix rotational radius of 400
     
    221321            delete ortho1;
    222322            delete ortho2;
    223           }
    224 
    225           // Abbreviation for "rotate and look"
    226           if (this->currentEvent.fctName == "ral")
    227           {
     323
     324    }
     325
     326    void ScriptController::ral(float dl)
     327    {
    228328            // Specify the axis
    229329            Vector3 a;
     
    250350            /* Look at the specified position */
    251351            this->entity_->lookAt(this->currentEvent.v1);
    252           }
    253           else if( this->currentEvent.fctName == "mal" )
    254           {
     352     
     353    }
     354
     355    void ScriptController::mal(float dl)
     356    {
    255357            /* Set the position to the correct place in the trajectory */
    256358            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
     
    258360            /* Look at the specified position */
    259361            this->entity_->lookAt(this->currentEvent.v2);
    260           }
    261           else if( this->currentEvent.fctName == "chl" )
    262           {
     362
     363    }
     364
     365    void ScriptController::chl(float dl)
     366    {
    263367            /* Sweep the look from v1 to v2 */
    264368            this->entity_->lookAt( (1-dl)*this->currentEvent.v1 +
    265369              dl * this->currentEvent.v2 );
    266           }
    267 
    268 
    269           /* Force mouse look */
    270           if( this->entity_->isInMouseLook() == false )
    271             this->entity_->mouseLook();
    272         }
    273     }
    274 
    275     void ScriptController::eventScheduler(std::string instruction,
    276       float x1, float y1, float z1,
    277       float x2, float y2, float z2,
    278       float duration, float executionTime)
    279     {
    280       /* put data (from LUA) into time-sorted eventList*/
    281       /* Nimmt den befehl und die argumente aus luascript und ertellt einen
    282        * struct pro event, diese structs werden sortiert nach eventTime
    283        */
    284       struct event tmp;
    285 
    286       /* Fill the structure with all the provided information */
    287       tmp.fctName = instruction;
    288 
    289       //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
    290       //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
    291       tmp.v1 = Vector3(x1,y1,z1);
    292       tmp.v2 = Vector3(x2,y2,z2);
    293 
    294       // the parameters are not required to be vector coordinates!
    295       // for convenience they are however stored twice if they have some kind of different meaning
    296       tmp.a = x1;
    297       tmp.b = y1;
    298       tmp.c = z1;
    299       tmp.d = x2;
    300       tmp.e = y2;
    301       tmp.f = z2;
    302 
    303       tmp.duration = duration;
    304 
    305       /* This is kind of a hack. If we hit the function idle all we want to do is
    306          advance event execution time, not schedule anything */
    307       if (instruction == "idle") {
    308         tmp.eventTime = this->prevEventTime;
    309         this->prevEventTime += x1;
    310         return;
    311       } else {
    312         tmp.eventTime = this->prevEventTime;
    313         this->prevEventTime += duration;
    314       }
    315 
    316       /* Add the created event to the event list */
    317       if(eventList.size()==0)
    318       { /* The list is still empty, just add it */
    319         orxout(verbose) << "eventList empty (01)" << endl;
    320         eventList.insert(eventList.begin(), tmp);
    321         this->eventno += 1;
    322         return; /* Nothing more to do, the event was added */
    323       }
    324 
    325       /* Event was not added yet since the list was not empty. Walk through
    326        * the list of events and add it so that the events are correctly in
    327        * order.
    328        */
    329       for (std::vector<event>::iterator it=eventList.begin(); it<eventList.end(); it++)
    330       { if(tmp.eventTime < it->eventTime)
    331         { eventList.insert(it,tmp);
    332           this->eventno += 1;
    333           //orxout()<<"new event added"<<endl;
    334           return;
    335         }
    336       }
    337 
    338       /* If the event was still not added here, it belongs in the end of the list */
    339       eventList.insert(eventList.end(), tmp);
    340       this->eventno += 1;
     370
     371    }
     372
     373    void ScriptController::rotX(float dl)
     374    {
     375
    341376
    342377    }
Note: See TracChangeset for help on using the changeset viewer.