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