Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 21, 2015, 2:55:51 PM (9 years ago)
Author:
rgraczyk
Message:

Various changes, see comments in cpp file

File:
1 edited

Legend:

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

    r10262 r10448  
    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#define M_PI 3.14159265358979323846 /* pi */
    2845
    2946#include "ScriptController.h"
     
    3249#include "worldentities/ControllableEntity.h"
    3350#include "core/LuaState.h"
     51#include "core/LuaState.h"
    3452#include <cmath>
     53
    3554
    3655namespace orxonox
     
    6685        this->eventno = 0;
    6786
     87        /* - First "previous event" scheduled at t=0 */
     88        /* - Needed for automatically updating event times */
     89        this->prevEventTime = 0;
     90
     91        /* hack */
     92        this->deltat;
    6893    }
    6994
     
    146171    void ScriptController::tick(float dt)
    147172    {
     173        /* hack */
     174        this->deltat = dt;
     175
    148176        /* Call the tick function of the classes we derive from */
    149177        SUPER(ScriptController, tick, dt);
     
    178206
    179207        /* Get a variable that specifies how far along the trajectory
    180          * we are
     208         * we are currently.
    181209         */
    182210        float dl = eventTime / currentEvent.duration;
    183211
    184         /* Depending */
     212        /* Depending on command */
    185213        /* Do some moving */
    186214        if( this->processing )
    187         {
    188           if( this->currentEvent.fctName == "mal" )
     215        {
     216          // Abbreviation for "spiral" (rotation + translation)
     217          if (this->currentEvent.fctName == "spi") {
     218
     219            // Need to know a perpendicular basis to the translation vector:
     220            // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm
     221            // Currently we set a fix rotational radius of 400
     222            // TODO: Add an option to adjust radius of spiral movement
     223            Vector3 direction = this->currentEvent.v1 - startpos;
     224
     225            Vector3* ortho1 = new Vector3(direction.y, -direction.x, 0);
     226            float absOrtho1 = sqrt(direction.y * direction.y + direction.x * direction.x);
     227            *ortho1 = 400 * cos(2 * M_PI * dl) * (*ortho1)/absOrtho1;
     228
     229            Vector3* ortho2 = new Vector3(0, direction.z, -direction.y);
     230            float absOrtho2 = sqrt(direction.y * direction.y + direction.z * direction.z);
     231            *ortho2 = 400 * sin(2 * M_PI * dl) * (*ortho2)/absOrtho2;
     232
     233            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1 + *ortho1 + *ortho2);
     234
     235            delete ortho1;
     236            delete ortho2;
     237          }
     238
     239          // Abbreviation for "rotate and look"
     240          if (this->currentEvent.fctName == "ral")
     241          {
     242            // Specify the axis
     243            Vector3* a;
     244              switch ((int) currentEvent.d) {
     245                case 3:
     246                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
     247                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
     248                                  this->currentEvent.v1.z);
     249                break;
     250                case 2:
     251                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
     252                                  this->currentEvent.v1.y,
     253                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
     254                break;
     255                case 1:
     256                  a = new Vector3(this->currentEvent.v1.x,
     257                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
     258                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
     259                break;
     260              }
     261
     262            this->entity_->setPosition(*a);
     263
     264            /* Look at the specified position */
     265            this->entity_->lookAt(this->currentEvent.v1);
     266          }
     267          else if( this->currentEvent.fctName == "mal" )
    189268          {
    190269            /* Set the position to the correct place in the trajectory */
     
    193272            /* Look at the specified position */
    194273            this->entity_->lookAt(this->currentEvent.v2);
    195 
    196             /* Update look at position */
    197             //this->lookAtPosition = this->currentEvent.v2;
    198274          }
    199275          else if( this->currentEvent.fctName == "chl" )
     
    224300      /* Fill the structure with all the provided information */
    225301      tmp.fctName = instruction;
     302
    226303      //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
    227304      //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
    228305      tmp.v1 = Vector3(x1,y1,z1);
    229306      tmp.v2 = Vector3(x2,y2,z2);
     307
     308      // the parameters are not required to be vector coordinates!
     309      // for convenience they are however stored twice if they have some kind of different meaning
     310      tmp.a = x1;
     311      tmp.b = y1;
     312      tmp.c = z1;
     313      tmp.d = x2;
     314      tmp.e = y2;
     315      tmp.f = z2;
     316
    230317      tmp.duration = duration;
    231       tmp.eventTime = executionTime;
    232 
    233       orxout(verbose) << tmp.fctName << endl;
     318
     319      /* This is kind of a hack. If we hit the function idle all we want to do is
     320         advance event execution time, not schedule anything */
     321      if (instruction == "idle") {
     322        tmp.eventTime = this->prevEventTime;
     323        this->prevEventTime += x1;
     324        return;
     325      } else {
     326        tmp.eventTime = this->prevEventTime;
     327        this->prevEventTime += duration;
     328      }
    234329
    235330      /* Add the created event to the event list */
Note: See TracChangeset for help on using the changeset viewer.