- Timestamp:
- Oct 4, 2015, 12:16:42 PM (10 years ago)
- Location:
- code/branches/presentationFS15merge
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentationFS15merge
- Property svn:mergeinfo changed
/code/branches/SciptableControllerFS15 (added) merged: 10308,10315,10448,10600,10605,10609 /code/branches/presentationFS15 (added) merged: 10499
- Property svn:mergeinfo changed
-
code/branches/presentationFS15merge/src/orxonox/controllers/ScriptController.cc
r10262 r10614 21 21 * 22 22 * Author: 23 * Fabian 'x3n' Landau23 * ... 24 24 * Co-authors: 25 25 * ... 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 */ 28 42 29 43 #include "ScriptController.h" … … 32 46 #include "worldentities/ControllableEntity.h" 33 47 #include "core/LuaState.h" 48 #include "core/LuaState.h" 34 49 #include <cmath> 50 35 51 36 52 namespace orxonox … … 66 82 this->eventno = 0; 67 83 84 /* - First "previous event" scheduled at t=0 */ 85 /* - Needed for automatically updating event times */ 86 this->prevEventTime = 0; 68 87 } 69 88 … … 178 197 179 198 /* Get a variable that specifies how far along the trajectory 180 * we are 199 * we are currently. 181 200 */ 182 201 float dl = eventTime / currentEvent.duration; 183 202 184 /* Depending */203 /* Depending on command */ 185 204 /* Do some moving */ 186 205 if( this->processing ) 187 { 188 if( this->currentEvent.fctName == "mal" ) 206 { 207 // Abbreviation for "spiral" (rotation + translation) 208 if (this->currentEvent.fctName == "spi") { 209 210 // Need to know a perpendicular basis to the translation vector: 211 // Given (a, b, c) we chose (b, -a, 0)norm and (0, c, -b)norm 212 // Currently we set a fix rotational radius of 400 213 // TODO: Add an option to adjust radius of spiral movement 214 Vector3 direction = this->currentEvent.v1 - startpos; 215 216 Vector3* ortho1 = new Vector3(direction.y, -direction.x, 0); 217 float absOrtho1 = sqrt(direction.y * direction.y + direction.x * direction.x); 218 *ortho1 = 400 * cos(2 * M_PI * dl) * (*ortho1)/absOrtho1; 219 220 Vector3* ortho2 = new Vector3(0, direction.z, -direction.y); 221 float absOrtho2 = sqrt(direction.y * direction.y + direction.z * direction.z); 222 *ortho2 = 400 * sin(2 * M_PI * dl) * (*ortho2)/absOrtho2; 223 224 this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1 + *ortho1 + *ortho2); 225 226 delete ortho1; 227 delete ortho2; 228 } 229 230 // Abbreviation for "rotate and look" 231 if (this->currentEvent.fctName == "ral") 232 { 233 // Specify the axis 234 Vector3* a; 235 switch ((int) currentEvent.d) { 236 case 3: 237 a = new Vector3(this->currentEvent.v1.x + this->currentEvent.e*cos(2*M_PI*dl), 238 this->currentEvent.v1.y + this->currentEvent.e*sin(2*M_PI*dl), 239 this->currentEvent.v1.z); 240 break; 241 case 2: 242 a = new Vector3(this->currentEvent.v1.x + this->currentEvent.e*sin(2*M_PI*dl), 243 this->currentEvent.v1.y, 244 this->currentEvent.v1.z + this->currentEvent.e*cos(2*M_PI*dl)); 245 break; 246 case 1: 247 a = new Vector3(this->currentEvent.v1.x, 248 this->currentEvent.v1.y + this->currentEvent.e*sin(2*M_PI*dl), 249 this->currentEvent.v1.z + this->currentEvent.e*cos(2*M_PI*dl)); 250 break; 251 } 252 253 this->entity_->setPosition(*a); 254 255 /* Look at the specified position */ 256 this->entity_->lookAt(this->currentEvent.v1); 257 } 258 else if( this->currentEvent.fctName == "mal" ) 189 259 { 190 260 /* Set the position to the correct place in the trajectory */ … … 193 263 /* Look at the specified position */ 194 264 this->entity_->lookAt(this->currentEvent.v2); 195 196 /* Update look at position */197 //this->lookAtPosition = this->currentEvent.v2;198 265 } 199 266 else if( this->currentEvent.fctName == "chl" ) … … 224 291 /* Fill the structure with all the provided information */ 225 292 tmp.fctName = instruction; 293 226 294 //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1; 227 295 //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2; 228 296 tmp.v1 = Vector3(x1,y1,z1); 229 297 tmp.v2 = Vector3(x2,y2,z2); 298 299 // the parameters are not required to be vector coordinates! 300 // for convenience they are however stored twice if they have some kind of different meaning 301 tmp.a = x1; 302 tmp.b = y1; 303 tmp.c = z1; 304 tmp.d = x2; 305 tmp.e = y2; 306 tmp.f = z2; 307 230 308 tmp.duration = duration; 231 tmp.eventTime = executionTime; 232 233 orxout(verbose) << tmp.fctName << endl; 309 310 /* This is kind of a hack. If we hit the function idle all we want to do is 311 advance event execution time, not schedule anything */ 312 if (instruction == "idle") { 313 tmp.eventTime = this->prevEventTime; 314 this->prevEventTime += x1; 315 return; 316 } else { 317 tmp.eventTime = this->prevEventTime; 318 this->prevEventTime += duration; 319 } 234 320 235 321 /* Add the created event to the event list */
Note: See TracChangeset
for help on using the changeset viewer.