[Orxonox-commit 5829] r10489 - in code/branches/presentationFS15: data/gui/scripts data/levels src/orxonox/controllers

maxima at orxonox.net maxima at orxonox.net
Tue May 26 14:23:27 CEST 2015


Author: maxima
Date: 2015-05-26 14:23:26 +0200 (Tue, 26 May 2015)
New Revision: 10489

Modified:
   code/branches/presentationFS15/data/gui/scripts/testscript.lua
   code/branches/presentationFS15/data/levels/levelTry.oxw
   code/branches/presentationFS15/src/orxonox/controllers/ScriptController.cc
   code/branches/presentationFS15/src/orxonox/controllers/ScriptController.h
Log:
scriptable controller branch merged to presentation.

Modified: code/branches/presentationFS15/data/gui/scripts/testscript.lua
===================================================================
--- code/branches/presentationFS15/data/gui/scripts/testscript.lua	2015-05-26 11:11:30 UTC (rev 10488)
+++ code/branches/presentationFS15/data/gui/scripts/testscript.lua	2015-05-26 12:23:26 UTC (rev 10489)
@@ -21,72 +21,27 @@
 
 -- If it worked, call its "movetoposition" function
 if ctrl ~= nil then
-  -- Move to the starting point at (xl+3000,yl,zl) while looking 
-  -- at xl,yl,zl over the time span of 3 seconds
-  ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 1, 0)
 
-  -- From there, perform a rotation around the harvester placed there
-  -- in 100 steps
-  dt = math.pi/100
-  for t = 0,math.pi,dt do
-    xt = math.cos(t)
-    yt = math.sin(t)
+  ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 2)
+  ctrl:eventScheduler("idle", 1)
+  ctrl:eventScheduler("ral", xl, yl, zl, 3, 0, 0, math.pi)
+  ctrl:eventScheduler("idle", 1)
+  ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3)
+  ctrl:eventScheduler("idle", 1)
+  ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2)
+  ctrl:eventScheduler("idle", 1)
+  ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4)
+  ctrl:eventScheduler("idle", 1)
+  ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3)
+  ctrl:eventScheduler("idle", 1)
+  ctrl:eventScheduler("spi", xm,ym,zm, 0,0,0, 4)
+  ctrl:eventScheduler("idle", 1)
 
-    ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, dt, t+0.9)
-  end
-
-
-  -- Update absolute time
-  Tabs = math.pi + 0.9
-
-  
-
-  -- Move away again, still looking at the station
-  ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3, Tabs+0.4)
-
-
-
-  -- Update absolute time
-  Tabs = Tabs + 0.4 + 3
-
-  
-
-  
-
-  -- Transition the look from (xl,yl,zl) to (3500,0,0) in 3 seconds
-  ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2, Tabs+0.2)
-
-  Tabs = Tabs + 2 + 0.2
-
-   ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4, Tabs+0)
-
-   Tabs = Tabs + 4 
-
-  for t = 0,math.pi,dt do
-    xt = math.cos(t)
-    zt = math.sin(t)
-
-    ctrl:eventScheduler("mal", xr+600*xt, yr, zr+600*zt, xr, yr, zr, dt, Tabs+t)
-  end
-
-  Tabs = Tabs + math.pi
-
-  ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3, Tabs+0.2)
-
-  Tabs = Tabs + 3 + 0.2
-
-  ctrl:eventScheduler("mal", xm,ym,zm, xl,yl,zl, 4, Tabs+2.5)
-
-
 end
 
-
-
 -- Output the newctrlid variable we set from the C++ code
 if newctrlid ~= nil then
   orxonox.execute("orxout message test " .. newctrlid)
 end
 
---orxonox.execute("setPause 1")
-
-
+--orxonox.execute("setPause 1")
\ No newline at end of file

Modified: code/branches/presentationFS15/data/levels/levelTry.oxw
===================================================================
--- code/branches/presentationFS15/data/levels/levelTry.oxw	2015-05-26 11:11:30 UTC (rev 10488)
+++ code/branches/presentationFS15/data/levels/levelTry.oxw	2015-05-26 12:23:26 UTC (rev 10489)
@@ -1,8 +1,8 @@
 <!-- First levelFile of mkronig and samuezu. It was copied from dockingToASpaceStation.oxw and modified a little bit -->
 <LevelInfo
- name = "levelTry"
- description = "Docking into a spacestation."
- tags = "showcase"
+ name = "ScriptController"
+ description = "A testlevel for the scriptable controller."
+ tags = "test"
  screenshot = "emptylevel.png"
 />
 

Modified: code/branches/presentationFS15/src/orxonox/controllers/ScriptController.cc
===================================================================
--- code/branches/presentationFS15/src/orxonox/controllers/ScriptController.cc	2015-05-26 11:11:30 UTC (rev 10488)
+++ code/branches/presentationFS15/src/orxonox/controllers/ScriptController.cc	2015-05-26 12:23:26 UTC (rev 10489)
@@ -26,13 +26,33 @@
  *
  */
 
+ /*
+  * Currently available lua commands:
+  *
+  * IMPORTANT: ALL COMMANDS DO REQUIRE 7 PARAMETERS TO BE PROVIDED. FILL UP WITH ZEROES IN UNIMPORTANT PLACES.
+  *
+  * Command             | Abbreviation | Parameter 1          | '' 2     | '' 3    | '' 4                 | '' 5     | '' 6     | '' 7
+  *
+  * "Move And Look"     | mal          | GoTo X Coordinate    | '' Y ''  | '' Z '' | LookAt X Coordinate  |  '' Y '' |  '' Y '' | Duration
+  * "Rotate And Look"   | ral          | GoTo X Coordinate    | '' Y ''  | '' Z '' | Axis (1=x, 2=z, 3=z) |     -    |     -    | Duration
+  * "Spiral"            | spi          | GoTo X Coordinate    | '' Y ''  | '' Z '' |          -           |     -    |     -    | Duration
+  * "Transition Look"   | chl          | From X Coordinate    | '' Y ''  | '' Z '' | To X Coordinate      |  '' Y '' |  '' Y '' | Duration
+  * "Idle (Do nothing)" | idle         | Duration
+  */
+
+// TODO: Which library can this be found in?
+
+#define M_PI 3.14159265358979323846 /* pi */
+
 #include "ScriptController.h"
 #include "infos/PlayerInfo.h"
 #include "core/CoreIncludes.h"
 #include "worldentities/ControllableEntity.h"
 #include "core/LuaState.h"
+#include "core/LuaState.h"
 #include <cmath>
 
+
 namespace orxonox
 {
     RegisterClass(ScriptController);
@@ -65,6 +85,12 @@
         /* - Counters */
         this->eventno = 0;
 
+        /* - First "previous event" scheduled at t=0 */
+        /* - Needed for automatically updating event times */
+        this->prevEventTime = 0;
+
+        /* hack */
+        this->deltat = 0;
     }
 
     void ScriptController::takeControl(int ctrlid)
@@ -145,6 +171,9 @@
 
     void ScriptController::tick(float dt)
     {
+        /* hack */
+        this->deltat = dt;
+
         /* Call the tick function of the classes we derive from */
         SUPER(ScriptController, tick, dt);
 
@@ -177,24 +206,72 @@
         }
 
         /* Get a variable that specifies how far along the trajectory
-         * we are 
+         * we are currently.
          */
         float dl = eventTime / currentEvent.duration; 
 
-        /* Depending  */
+        /* Depending on command */
         /* Do some moving */
         if( this->processing )
-        { 
-          if( this->currentEvent.fctName == "mal" )
+        {
+          // Abbreviation for "spiral" (rotation + translation)
+          if (this->currentEvent.fctName == "spi") {
+
+            // Need to know a perpendicular basis to the translation vector:
+            // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm
+            // Currently we set a fix rotational radius of 400
+            // TODO: Add an option to adjust radius of spiral movement
+            Vector3 direction = this->currentEvent.v1 - startpos;
+
+            Vector3* ortho1 = new Vector3(direction.y, -direction.x, 0);
+            float absOrtho1 = sqrt(direction.y * direction.y + direction.x * direction.x);
+            *ortho1 = 400 * cos(2 * M_PI * dl) * (*ortho1)/absOrtho1;
+
+            Vector3* ortho2 = new Vector3(0, direction.z, -direction.y);
+            float absOrtho2 = sqrt(direction.y * direction.y + direction.z * direction.z);
+            *ortho2 = 400 * sin(2 * M_PI * dl) * (*ortho2)/absOrtho2;
+
+            this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1 + *ortho1 + *ortho2);
+
+            delete ortho1;
+            delete ortho2;
+          }
+
+          // Abbreviation for "rotate and look"
+          if (this->currentEvent.fctName == "ral")
+          { 
+            // Specify the axis
+            Vector3* a;
+              switch ((int) currentEvent.d) {
+                case 3:
+                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
+                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
+                                  this->currentEvent.v1.z);
+                break;
+                case 2:
+                  a = new Vector3(this->currentEvent.v1.x + 3000*cos(2*M_PI*dl),
+                                  this->currentEvent.v1.y,
+                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
+                break;
+                case 1:
+                  a = new Vector3(this->currentEvent.v1.x,
+                                  this->currentEvent.v1.y + 3000*sin(2*M_PI*dl),
+                                  this->currentEvent.v1.z + 3000*cos(2*M_PI*dl));
+                break;
+              }
+
+            this->entity_->setPosition(*a);
+
+            /* Look at the specified position */
+            this->entity_->lookAt(this->currentEvent.v1);
+          }
+          else if( this->currentEvent.fctName == "mal" )
           {
             /* Set the position to the correct place in the trajectory */
             this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1);
 
             /* Look at the specified position */
             this->entity_->lookAt(this->currentEvent.v2);
-
-            /* Update look at position */
-            //this->lookAtPosition = this->currentEvent.v2;
           }
           else if( this->currentEvent.fctName == "chl" )
           {
@@ -223,14 +300,33 @@
 
       /* Fill the structure with all the provided information */
       tmp.fctName = instruction;
+
       //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1;
       //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2;
       tmp.v1 = Vector3(x1,y1,z1);
       tmp.v2 = Vector3(x2,y2,z2);
+
+      // the parameters are not required to be vector coordinates!
+      // for convenience they are however stored twice if they have some kind of different meaning
+      tmp.a = x1;
+      tmp.b = y1;
+      tmp.c = z1;
+      tmp.d = x2;
+      tmp.e = y2;
+      tmp.f = z2;
+
       tmp.duration = duration;
-      tmp.eventTime = executionTime;
 
-      orxout(verbose) << tmp.fctName << endl;
+      /* This is kind of a hack. If we hit the function idle all we want to do is
+         advance event execution time, not schedule anything */
+      if (instruction == "idle") {
+        tmp.eventTime = this->prevEventTime;
+        this->prevEventTime += x1;
+        return;
+      } else {
+        tmp.eventTime = this->prevEventTime;
+        this->prevEventTime += duration;
+      }
 
       /* Add the created event to the event list */
       if(eventList.size()==0)

Modified: code/branches/presentationFS15/src/orxonox/controllers/ScriptController.h
===================================================================
--- code/branches/presentationFS15/src/orxonox/controllers/ScriptController.h	2015-05-26 11:11:30 UTC (rev 10488)
+++ code/branches/presentationFS15/src/orxonox/controllers/ScriptController.h	2015-05-26 12:23:26 UTC (rev 10489)
@@ -44,9 +44,15 @@
         /** Instruction for this event */
         std::string fctName;
 
+        /** Final position we want to be at **/
         Vector3 v1;
+
+        /** Where we are looking **/
         Vector3 v2;
 
+        /** The parameters are additionally stored as a set of 6 numerical values **/
+        float a, b, c, d, e, f;
+
         /** Time span of the event */
         float duration;
 
@@ -68,10 +74,10 @@
 
             // LUA interface
             // tolua_begin 
-            void eventScheduler(std::string instruction, 
-              float x1, float y1, float z1, 
-              float x2, float y2, float z2, 
-              float duration, float executionTime);
+            void eventScheduler(std::string instruction = "", 
+              float x1 = 0, float y1 = 0, float z1 = 0, 
+              float x2 = 0, float y2 = 0, float z2 = 0, 
+              float duration = 0, float executionTime = 0);
 
             static ScriptController* getScriptController();
 
@@ -115,6 +121,12 @@
             float eventTime;
             Vector3 startpos;
 
+            /* Time of the previously scheduled event */
+            float prevEventTime;
+
+            /* Hack: Gain access to delta t */
+            float deltat;
+
             /* - Position to look at during that transition */
             //Vector3 lookAtPosition;
 




More information about the Orxonox-commit mailing list