Changeset 10489
- Timestamp:
- May 26, 2015, 2:23:26 PM (10 years ago)
- Location:
- code/branches/presentationFS15
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS15/data/gui/scripts/testscript.lua
r10262 r10489 22 22 -- If it worked, call its "movetoposition" function 23 23 if ctrl ~= nil then 24 -- Move to the starting point at (xl+3000,yl,zl) while looking25 -- at xl,yl,zl over the time span of 3 seconds26 ctrl:eventScheduler("mal", xl+3000,yl,zl, xl,yl,zl, 1, 0)27 24 28 -- From there, perform a rotation around the harvester placed there 29 -- in 100 steps 30 dt = math.pi/100 31 for t = 0,math.pi,dt do 32 xt = math.cos(t) 33 yt = math.sin(t) 34 35 ctrl:eventScheduler("mal", xl+3000*xt, yl+3000*yt, zl, xl, yl, zl, dt, t+0.9) 36 end 37 38 39 -- Update absolute time 40 Tabs = math.pi + 0.9 41 42 43 44 -- Move away again, still looking at the station 45 ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3, Tabs+0.4) 46 47 48 49 -- Update absolute time 50 Tabs = Tabs + 0.4 + 3 51 52 53 54 55 56 -- Transition the look from (xl,yl,zl) to (3500,0,0) in 3 seconds 57 ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2, Tabs+0.2) 58 59 Tabs = Tabs + 2 + 0.2 60 61 ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4, Tabs+0) 62 63 Tabs = Tabs + 4 64 65 for t = 0,math.pi,dt do 66 xt = math.cos(t) 67 zt = math.sin(t) 68 69 ctrl:eventScheduler("mal", xr+600*xt, yr, zr+600*zt, xr, yr, zr, dt, Tabs+t) 70 end 71 72 Tabs = Tabs + math.pi 73 74 ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3, Tabs+0.2) 75 76 Tabs = Tabs + 3 + 0.2 77 78 ctrl:eventScheduler("mal", xm,ym,zm, xl,yl,zl, 4, Tabs+2.5) 79 25 ctrl:eventScheduler("mal", xl,yl,zl, xl,yl,zl, 2) 26 ctrl:eventScheduler("idle", 1) 27 ctrl:eventScheduler("ral", xl, yl, zl, 3, 0, 0, math.pi) 28 ctrl:eventScheduler("idle", 1) 29 ctrl:eventScheduler("mal", 0,0,1000, xl,yl,zl, 3) 30 ctrl:eventScheduler("idle", 1) 31 ctrl:eventScheduler("chl", xl, yl, zl, xr, yr, zr, 2) 32 ctrl:eventScheduler("idle", 1) 33 ctrl:eventScheduler("mal", xr + 600,yr,zr, xr,yr,zr, 4) 34 ctrl:eventScheduler("idle", 1) 35 ctrl:eventScheduler("chl", xr, yr, zr, xl, yl, zl, 3) 36 ctrl:eventScheduler("idle", 1) 37 ctrl:eventScheduler("spi", xm,ym,zm, 0,0,0, 4) 38 ctrl:eventScheduler("idle", 1) 80 39 81 40 end 82 83 84 41 85 42 -- Output the newctrlid variable we set from the C++ code … … 89 46 90 47 --orxonox.execute("setPause 1") 91 92 -
code/branches/presentationFS15/data/levels/levelTry.oxw
r10262 r10489 1 1 <!-- First levelFile of mkronig and samuezu. It was copied from dockingToASpaceStation.oxw and modified a little bit --> 2 2 <LevelInfo 3 name = " levelTry"4 description = " Docking into a spacestation."5 tags = " showcase"3 name = "ScriptController" 4 description = "A testlevel for the scriptable controller." 5 tags = "test" 6 6 screenshot = "emptylevel.png" 7 7 /> -
code/branches/presentationFS15/src/orxonox/controllers/ScriptController.cc
r10262 r10489 26 26 * 27 27 */ 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 */ 28 46 29 47 #include "ScriptController.h" … … 32 50 #include "worldentities/ControllableEntity.h" 33 51 #include "core/LuaState.h" 52 #include "core/LuaState.h" 34 53 #include <cmath> 54 35 55 36 56 namespace orxonox … … 66 86 this->eventno = 0; 67 87 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; 68 94 } 69 95 … … 146 172 void ScriptController::tick(float dt) 147 173 { 174 /* hack */ 175 this->deltat = dt; 176 148 177 /* Call the tick function of the classes we derive from */ 149 178 SUPER(ScriptController, tick, dt); … … 178 207 179 208 /* Get a variable that specifies how far along the trajectory 180 * we are 209 * we are currently. 181 210 */ 182 211 float dl = eventTime / currentEvent.duration; 183 212 184 /* Depending */213 /* Depending on command */ 185 214 /* Do some moving */ 186 215 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" ) 189 269 { 190 270 /* Set the position to the correct place in the trajectory */ … … 193 273 /* Look at the specified position */ 194 274 this->entity_->lookAt(this->currentEvent.v2); 195 196 /* Update look at position */197 //this->lookAtPosition = this->currentEvent.v2;198 275 } 199 276 else if( this->currentEvent.fctName == "chl" ) … … 224 301 /* Fill the structure with all the provided information */ 225 302 tmp.fctName = instruction; 303 226 304 //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1; 227 305 //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2; 228 306 tmp.v1 = Vector3(x1,y1,z1); 229 307 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 230 318 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 } 234 330 235 331 /* Add the created event to the event list */ -
code/branches/presentationFS15/src/orxonox/controllers/ScriptController.h
r10262 r10489 45 45 std::string fctName; 46 46 47 /** Final position we want to be at **/ 47 48 Vector3 v1; 49 50 /** Where we are looking **/ 48 51 Vector3 v2; 52 53 /** The parameters are additionally stored as a set of 6 numerical values **/ 54 float a, b, c, d, e, f; 49 55 50 56 /** Time span of the event */ … … 69 75 // LUA interface 70 76 // tolua_begin 71 void eventScheduler(std::string instruction ,72 float x1 , float y1, float z1,73 float x2 , float y2, float z2,74 float duration , float executionTime);77 void eventScheduler(std::string instruction = "", 78 float x1 = 0, float y1 = 0, float z1 = 0, 79 float x2 = 0, float y2 = 0, float z2 = 0, 80 float duration = 0, float executionTime = 0); 75 81 76 82 static ScriptController* getScriptController(); … … 116 122 Vector3 startpos; 117 123 124 /* Time of the previously scheduled event */ 125 float prevEventTime; 126 127 /* Hack: Gain access to delta t */ 128 float deltat; 129 118 130 /* - Position to look at during that transition */ 119 131 //Vector3 lookAtPosition;
Note: See TracChangeset
for help on using the changeset viewer.