Changeset 10448 for code/branches/SciptableControllerFS15/src/orxonox
- Timestamp:
- May 21, 2015, 2:55:51 PM (10 years ago)
- Location:
- code/branches/SciptableControllerFS15/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/SciptableControllerFS15/src/orxonox/controllers/ScriptController.cc
r10262 r10448 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 #define M_PI 3.14159265358979323846 /* pi */ 28 45 29 46 #include "ScriptController.h" … … 32 49 #include "worldentities/ControllableEntity.h" 33 50 #include "core/LuaState.h" 51 #include "core/LuaState.h" 34 52 #include <cmath> 53 35 54 36 55 namespace orxonox … … 66 85 this->eventno = 0; 67 86 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; 68 93 } 69 94 … … 146 171 void ScriptController::tick(float dt) 147 172 { 173 /* hack */ 174 this->deltat = dt; 175 148 176 /* Call the tick function of the classes we derive from */ 149 177 SUPER(ScriptController, tick, dt); … … 178 206 179 207 /* Get a variable that specifies how far along the trajectory 180 * we are 208 * we are currently. 181 209 */ 182 210 float dl = eventTime / currentEvent.duration; 183 211 184 /* Depending */212 /* Depending on command */ 185 213 /* Do some moving */ 186 214 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" ) 189 268 { 190 269 /* Set the position to the correct place in the trajectory */ … … 193 272 /* Look at the specified position */ 194 273 this->entity_->lookAt(this->currentEvent.v2); 195 196 /* Update look at position */197 //this->lookAtPosition = this->currentEvent.v2;198 274 } 199 275 else if( this->currentEvent.fctName == "chl" ) … … 224 300 /* Fill the structure with all the provided information */ 225 301 tmp.fctName = instruction; 302 226 303 //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1; 227 304 //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2; 228 305 tmp.v1 = Vector3(x1,y1,z1); 229 306 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 230 317 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 } 234 329 235 330 /* Add the created event to the event list */ -
code/branches/SciptableControllerFS15/src/orxonox/controllers/ScriptController.h
r10315 r10448 51 51 Vector3 v2; 52 52 53 /** The parameters are additionally stored as a set of 6 numerical values **/ 54 float a, b, c, d, e, f; 55 53 56 /** Time span of the event */ 54 57 float duration; … … 72 75 // LUA interface 73 76 // tolua_begin 74 void eventScheduler(std::string instruction ,75 float x1 , float y1, float z1,76 float x2 , float y2, float z2,77 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); 78 81 79 82 static ScriptController* getScriptController(); … … 119 122 Vector3 startpos; 120 123 124 /* Time of the previously scheduled event */ 125 float prevEventTime; 126 127 /* Hack: Gain access to delta t */ 128 float deltat; 129 121 130 /* - Position to look at during that transition */ 122 131 //Vector3 lookAtPosition;
Note: See TracChangeset
for help on using the changeset viewer.