Changeset 10066 for code/branches/ScriptableController/src
- Timestamp:
- May 21, 2014, 3:28:28 PM (11 years ago)
- Location:
- code/branches/ScriptableController/src/orxonox/controllers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
r10065 r10066 47 47 this->ctrlid_ = 0; 48 48 49 50 49 /* Set default values for all variables */ 51 50 /* - pointers to zero */ … … 55 54 /* - times */ 56 55 this->scTime = 0.0f; 57 this->timeToTarget = 0.0f;58 56 this->eventTime = 0.0f; 59 57 60 58 /* - Points in space */ 61 this->target = Vector3(0,0,0);62 59 this->startpos = Vector3(0,0,0); 63 this->lookAtPosition = Vector3(0,0,0);60 //this->lookAtPosition = Vector3(0,0,0); 64 61 65 62 /* - Processing flag */ … … 95 92 } 96 93 97 /* Yet to be implemented and tested */98 //void ScriptController::yieldControl()99 //{100 //this->player_->startControl(this->entity_);101 //this->setActive(false);102 //this->controllableEntity_ = NULL;103 //}104 105 94 const Vector3& ScriptController::getPosition() 106 95 { … … 136 125 void ScriptController::execute(event ev) 137 126 { 138 orxout() << "Executing event " << ev.fctName 139 << " with parameters:\n " 140 << ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n" 141 << ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n" 142 << ev.duration << endl; 143 127 /* Debugging output */ 128 //orxout() << "Executing event " << ev.fctName 129 //<< " with parameters:\n " 130 //<< ev.x1 << " " << ev.y1 << " " << ev.z1 << "\n" 131 //<< ev.x2 << " " << ev.y2 << " " << ev.z2 << "\n" 132 //<< ev.duration << endl; 133 134 /* Event is starting, hence set the time to 0 */ 144 135 this->eventTime = 0.0f; 136 this->processing = true; 137 138 /* Copy the event into the currentEvent holder */ 139 this->currentEvent = ev; 140 141 /* Store starting position */ 145 142 this->startpos = this->entity_->getPosition(); 146 this->processing = true;147 148 if(ev.fctName == "mal")149 moveAndLook(ev.x1, ev.y1, ev.z1, ev.x2, ev.y2, ev.z2, ev.duration);150 143 } 151 144 … … 157 150 158 151 /* If this controller has no entity entry, do nothing */ 159 if( !(this->entity_) ) 160 return; 161 162 //orxout() << "Size 0: " << this->eventList.size() << endl; 152 if( !(this->entity_) ) return; 163 153 164 154 /* See if time has come for the next event to be run */ 165 155 if(this->eventList.size() > 0 && this->eventList[0].eventTime <= scTime) 166 { 167 /* Execute the next event on the list */ 156 { /* Execute the next event on the list */ 168 157 this->execute(this->eventList[0]); 169 158 this->eventList.erase(this->eventList.begin()); 170 159 this->eventno -= 1; 171 //orxout() << "Size 1: " << this->eventList.size() << endl;172 //orxout() << "Eventno is now: " << this->eventno << endl;173 160 } 174 161 175 162 /* Update the local timers in this object */ 176 scTime += dt; 177 eventTime += dt; 163 scTime += dt; eventTime += dt; 178 164 179 165 /* If we've arrived at the target, stop processing */ 180 if( eventTime > timeToTarget&& this->processing == true)166 if( eventTime > currentEvent.duration && this->processing == true) 181 167 { this->processing = false; 182 168 183 / /orxout() << "Size 4: " << this->eventList.size() << endl;184 //orxout() << "Eventno: " << this->eventno << endl;185 169 /* If we reached the last event, also reenable the normal movement 170 * and make the model visible again 171 */ 186 172 if( this->eventno == 0 ) 187 173 { … … 194 180 * we are 195 181 */ 196 float dl = eventTime / timeToTarget; 197 182 float dl = eventTime / currentEvent.duration; 183 184 /* Depending */ 198 185 /* Do some moving */ 199 186 if( this->processing ) 200 187 { 201 /* Set the position to the correct place in the trajectory */ 202 this->entity_->setPosition( (1-dl)*startpos + dl * target ); 203 204 /* Look at the specified position */ 205 this->entity_->lookAt(lookAtPosition); 188 if( this->currentEvent.fctName == "mal" ) 189 { 190 /* Set the position to the correct place in the trajectory */ 191 this->entity_->setPosition( (1-dl)*startpos + dl * this->currentEvent.v1); 192 193 /* Look at the specified position */ 194 this->entity_->lookAt(this->currentEvent.v2); 195 196 /* Update look at position */ 197 //this->lookAtPosition = this->currentEvent.v2; 198 } 199 else if( this->currentEvent.fctName == "chl" ) 200 { 201 /* Sweep the look from v1 to v2 */ 202 this->entity_->lookAt( (1-dl)*this->currentEvent.v1 + 203 dl * this->currentEvent.v2 ); 204 } 205 206 206 207 207 /* Force mouse look */ … … 209 209 this->entity_->mouseLook(); 210 210 } 211 }212 213 void ScriptController::moveAndLook(214 float xm, float ym, float zm,215 float xl, float yl, float zl,216 float t )217 {218 orxout()<<"moveAndLook executed"<<endl;219 220 /* Set the local variables required for this event */221 this->target = Vector3(xm,ym,zm);222 this->lookAtPosition = Vector3(xl,yl,zl);223 this->timeToTarget = t;224 225 226 orxout() << "Moving This-pointer: " << this << endl;227 228 if(this->entity_ != NULL)229 orxout()<<"not-NULL-entity"<<endl;230 else231 return;232 233 if(this->player_ != NULL)234 orxout()<<"not-NULL-player"<<endl;235 else236 return;237 211 } 238 212 … … 250 224 /* Fill the structure with all the provided information */ 251 225 tmp.fctName = instruction; 252 tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1; 253 tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2; 226 //tmp.x1 = x1; tmp.y1 = y1; tmp.z1 = z1; 227 //tmp.x2 = x2; tmp.y2 = y2; tmp.z2 = z2; 228 tmp.v1 = Vector3(x1,y1,z1); 229 tmp.v2 = Vector3(x2,y2,z2); 254 230 tmp.duration = duration; 255 231 tmp.eventTime = executionTime; -
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.h
r10065 r10066 39 39 { // tolua_export 40 40 41 /** Structure to describe a single event */ 41 42 struct event 42 43 { 44 /** Instruction for this event */ 43 45 std::string fctName; 44 float x1;45 float y1;46 float z1;47 46 48 float x2; 49 float y2; 50 float z2; 47 Vector3 v1; 48 Vector3 v2; 51 49 50 /** Time span of the event */ 52 51 float duration; 53 52 53 /** Start point in time of the event */ 54 54 float eventTime; 55 56 55 }; 57 56 … … 61 60 public: 62 61 ScriptController(Context* context); 63 64 62 virtual ~ScriptController() { } 65 63 66 //virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);67 68 64 void takeControl(int ctrlid); 69 65 void setPlayer(PlayerInfo* player) { this->player_ = player; } … … 73 69 // LUA interface 74 70 // tolua_begin 75 void moveAndLook(float xm, float ym, float zm,76 float xl, float yl, float zl, float t);77 78 71 void eventScheduler(std::string instruction, 79 72 float x1, float y1, float z1, … … 115 108 bool processing; 116 109 117 /* Data about the point to go to and what to look at */ 118 /* - Target position */ 119 Vector3 target; 120 121 /* - Time it should take to get there */ 122 float timeToTarget; 110 /* Data about the event currently being processed */ 111 /* - The event itself */ 112 event currentEvent; 123 113 124 114 /* - Time this event has been going on for */ … … 127 117 128 118 /* - Position to look at during that transition */ 129 Vector3 lookAtPosition;119 //Vector3 lookAtPosition; 130 120 131 121 };// tolua_export
Note: See TracChangeset
for help on using the changeset viewer.