- Timestamp:
- May 8, 2014, 10:16:23 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ScriptableController/src/orxonox/controllers/ScriptController.cc
r10046 r10047 28 28 29 29 #include "ScriptController.h" 30 #include "infos/PlayerInfo.h" 30 31 #include "core/CoreIncludes.h" 31 32 #include "worldentities/ControllableEntity.h" … … 42 43 RegisterObject(ScriptController); 43 44 //set_controlled(CE); 45 this->ctrlid_ = 0; 44 46 } 45 47 46 void ScriptController:: set_luasrc(std::string lsrc)48 void ScriptController::takeControl(int ctrlid) 47 49 { 48 this->luasrc=lsrc; 50 orxout() << "ScriptController: Taking control" << endl; 51 orxout() << "This-pointer: " << this << endl; 52 this->ctrlid_ = ctrlid; 53 this->entity_ = this->player_->getControllableEntity(); 54 assert(this->entity_); 55 56 this->entity_->setDestroyWhenPlayerLeft(false); 57 this->player_->pauseControl(); 58 this->entity_->setController(this); 59 this->setControllableEntity(this->entity_); 49 60 } 50 61 51 void ScriptController::set_controlled(ControllableEntity* toControl) 52 { 53 this->controlled=toControl; 54 } 55 62 /* Yet to be implemented and tested */ 63 //void ScriptController::yieldControl() 64 //{ 65 //this->player_->startControl(this->entity_); 66 //this->setActive(false); 67 //this->controllableEntity_ = NULL; 68 //} 69 56 70 void ScriptController::XMLPort(Element& xmlelement, XMLPort::Mode mode) 57 71 { … … 62 76 const Vector3& ScriptController::getPosition() 63 77 { 64 return this-> controlled->getPosition();78 return this->entity_->getPosition(); 65 79 } 66 80 … … 70 84 orxout() << "Great success!" << std::endl; 71 85 72 /* Loop over all the scriptcontrollers currently present in the game */ 86 /* Debugging: print all the scriptcontroller object pointers */ 87 for(ObjectList<ScriptController>::iterator it = 88 ObjectList<ScriptController>::begin(); 89 it != ObjectList<ScriptController>::end(); ++it) 90 { orxout() << "Have object in list: " << *it << endl; } 91 92 /* Find the first one with a nonzero ID */ 73 93 for(ObjectList<ScriptController>::iterator it = 74 94 ObjectList<ScriptController>::begin(); … … 76 96 { 77 97 // TODO: do some selection here. Currently just returns the first one 78 return *it; 98 if( (*it)->getID() > 0 ) 99 return *it; 79 100 80 101 } … … 82 103 } 83 104 105 void ScriptController::tick(float dt) 106 { 107 /* If this controller has no entity entry, do nothing */ 108 if( !(this->entity_) ) 109 return; 110 111 //orxout() << "Rotating!" << endl; 112 113 //this->entity_->rotateYaw(-1.0f * 100.0f * dt); 114 //this->entity_->rotatePitch(0.8f * 100.0f); 115 116 SUPER(ScriptController, tick, dt); 117 } 84 118 85 119 86 120 void ScriptController::moveToPosition_beta(float x, float y, float z ) 87 121 { 88 / * The section commented out here below throws segfaults */89 //const Vector3 local=getPosition();90 // const Vector3 target=Vector3(x,y,z);91 //Vector3 way=target-local;122 //const Vector3 local = this->getPosition(); 123 const Vector3 target = Vector3(100*x,100*y,100*z); 124 //Vector3 way = target-local; 125 orxout() << "Moving This-pointer: " << this << endl; 92 126 93 127 94 //this->controlled->lookAt(target);95 //this->controlled->moveFrontBack(way.length());128 this->entity_->lookAt(target); 129 this->entity_->moveFrontBack(-1000*target.length()); 96 130 97 131 … … 99 133 orxout()<<x<<" "<<y<<" "<<z<<endl; 100 134 } 135 101 136 102 137 /* TODO: hilfs(zwischen)funktionen um lua eingabe zu ermoeglichen: zb moveToPosition(float...) weil in LUA wohl
Note: See TracChangeset
for help on using the changeset viewer.