Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2015, 2:23:26 PM (9 years ago)
Author:
maxima
Message:

scriptable controller branch merged to presentation.

File:
1 edited

Legend:

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

    r10262 r10489  
    2626 *
    2727 */
     28
     29 /*
     30  * Currently available lua commands:
     31  *
     32  * IMPORTANT: ALL COMMANDS DO REQUIRE 7 PARAMETERS TO BE PROVIDED. FILL UP WITH ZEROES IN UNIMPORTANT PLACES.
     33  *
     34  * Command             | Abbreviation | Parameter 1          | '' 2     | '' 3    | '' 4                 | '' 5     | '' 6     | '' 7
     35  *
     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
     40  * "Idle (Do nothing)" | idle         | Duration
     41  */
     42
     43// TODO: Which library can this be found in?
     44
     45#define M_PI 3.14159265358979323846 /* pi */
    2846
    2947#include "ScriptController.h"
     
    3250#include "worldentities/ControllableEntity.h"
    3351#include "core/LuaState.h"
     52#include "core/LuaState.h"
    3453#include <cmath>
     54
    3555
    3656namespace orxonox
     
    6686        this->eventno = 0;
    6787
     88        /* - First "previous event" scheduled at t=0 */
     89        /* - Needed for automatically updating event times */
     90        this->prevEventTime = 0;
     91
     92        /* hack */
     93        this->deltat = 0;
    6894    }
    6995
     
    146172    void ScriptController::tick(float dt)
    147173    {
     174        /* hack */
     175        this->deltat = dt;
     176
    148177        /* Call the tick function of the classes we derive from */
    149178        SUPER(ScriptController, tick, dt);
     
    178207
    179208        /* Get a variable that specifies how far along the trajectory
    180          * we are
     209         * we are currently.
    181210         */
    182211        float dl = eventTime / currentEvent.duration;
    183212
    184         /* Depending */
     213        /* Depending on command */
    185214        /* Do some moving */
    186215        if( this->processing )
    187         {
    188           if( this->currentEvent.fctName == "mal" )
     216        {
     217          // Abbreviation for "spiral" (rotation + translation)
     218          if (this->currentEvent.fctName == "spi") {
     219
     220            // Need to know a perpendicular basis to the translation vector:
     221            // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm
     222            // Currently we set a fix rotational radius of 400
     223            // TODO: Add an option to adjust radius of spiral movement
     224            Vector3 direction = this->currentEvent.v1 - startpos;
     225
     226            Vector3* ortho1 = new Vector3(direction.y, -direction.x, 0);
     227            float absOrtho1 = sqrt(direction.y * direction.y + direction.x * direction.x);
     228            *ortho1 = 400 * cos(2 * M_PI * dl) * (*ortho1)/absOrtho1;
     229
     230            Vector3* ortho2 = new Vector3(0, direction.z, -direction.y);
     231            float absOrtho2 = sqrt(direction.y * direction.y + direction.z * direction.z);
     232            *ortho2 = 400 * sin(2 * M_PI * dl) * (*ortho2)/absOrtho2;
     233
     234            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1 + *ortho1 + *ortho2);
     235
     236            delete ortho1;
     237            delete ortho2;
     238          }
     239
     240          // Abbreviation for "rotate and look"
     241          if (this->currentEvent.fctName == "ral")
     242          {
     243            // Specify the axis
     244            Vector3* a;
     245              switch ((int) currentEvent.d) {
     246                case 3:
     247                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
     248                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
     249                                  this->currentEvent.v1.z);
     250                break;
     251                case 2:
     252                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
     253                                  this->currentEvent.v1.y,
     254                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
     255                break;
     256                case 1:
     257                  a = new Vector3(this->currentEvent.v1.x,
     258                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
     259                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
     260                break;
     261              }
     262
     263            this->entity_->setPosition(*a);
     264
     265            /* Look at the specified position */
     266            this->entity_->lookAt(this->currentEvent.v1);
     267          }
     268          else if( this->currentEvent.fctName == "mal" )
    189269          {
    190270            /* Set the position to the correct place in the trajectory */
     
    193273            /* Look at the specified position */
    194274            this->entity_->lookAt(this->currentEvent.v2);
    195 
    196             /* Update look at position */
    197             //this->lookAtPosition = this->currentEvent.v2;
    198275          }
    199276          else if( this->currentEvent.fctName == "chl" )
     
    224301      /* Fill the structure with all the provided information */
    225302      tmp.fctName = instruction;
     303
    226304      //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
    227305      //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
    228306      tmp.v1 = Vector3(x1,y1,z1);
    229307      tmp.v2 = Vector3(x2,y2,z2);
     308
     309      // the parameters are not required to be vector coordinates!
     310      // for convenience they are however stored twice if they have some kind of different meaning
     311      tmp.a = x1;
     312      tmp.b = y1;
     313      tmp.c = z1;
     314      tmp.d = x2;
     315      tmp.e = y2;
     316      tmp.f = z2;
     317
    230318      tmp.duration = duration;
    231       tmp.eventTime = executionTime;
    232 
    233       orxout(verbose) << tmp.fctName << endl;
     319
     320      /* This is kind of a hack. If we hit the function idle all we want to do is
     321         advance event execution time, not schedule anything */
     322      if (instruction == "idle") {
     323        tmp.eventTime = this->prevEventTime;
     324        this->prevEventTime += x1;
     325        return;
     326      } else {
     327        tmp.eventTime = this->prevEventTime;
     328        this->prevEventTime += duration;
     329      }
    234330
    235331      /* Add the created event to the event list */
Note: See TracChangeset for help on using the changeset viewer.