Changeset 11834 for code/branches/3DPacman_FS18/src
- Timestamp:
- Mar 29, 2018, 12:15:19 PM (7 years ago)
- Location:
- code/branches/3DPacman_FS18/src/modules/3DPacman
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc
r11832 r11834 50 50 this->localLinearAcceleration_.setValue(0, 0, 0); 51 51 this->localAngularAcceleration_.setValue(0, 0, 0); 52 this->primaryThrust_ = 100;53 this->auxiliaryThrust_ = 100;54 this->rotationThrust_ = 10;55 52 56 53 this->setCollisionType(CollisionType::Dynamic); 54 55 Vector3 resetposition = new Vector3(0,0,0); //Set Default start position 56 57 57 } 58 58 … … 78 78 79 79 XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode); 80 // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort. 81 // Variables can be added by the following command 82 // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode); 83 // Also make sure that you also create the get- and set-functions in AutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there. 80 XMLPortParam(PacmanGhost, "auxilliaryThrust", setAuxillaryThrust, getAuxillaryThrust, xmlelement, mode); 81 XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode); 82 XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode); 84 83 } 85 84 -
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.h
r11832 r11834 55 55 virtual void rotatePitch(const Vector2& value); 56 56 virtual void rotateRoll(const Vector2& value); 57 57 58 virtual void resetGhost(); 58 59 /** 59 60 @brief Moves the Drone in the Front/Back-direction by the specifed amount. … … 100 101 inline void setPrimaryThrust( float thrust ) 101 102 { this->primaryThrust_ = thrust; } 102 //TODO: Place your set-functions here. 103 // Hint: auxiliary thrust, rotation thrust. 104 103 inline void setAuxillaryThrust( float thrust ) 104 { this->auxillaryThrust_ = thrust; } 105 inline void setRotationThrust( float thrust ) 106 { this->rotationThrust_ = thrust; } 107 108 inline void setResetPosition(Vector3 rpos) 109 { this->resetposition = rpos; } 110 105 111 /** 106 112 @brief Gets the primary thrust to the input amount. … … 109 115 inline float getPrimaryThrust() 110 116 { return this->primaryThrust_; } 111 //TODO: Place your get-functions here. 117 inline float getAuxillaryThrust() 118 { return this->auxillaryThrust_; } 119 inline float getRotationThrust() 120 { return this->rotationThrust_; } 121 122 inline Vector3 getResetPosition() 123 { return this->resetposition; } 124 125 112 126 113 127 private: … … 119 133 float auxiliaryThrust_; //!< The amount of auxiliary thrust. Used for all other movements (except for rotations). 120 134 float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.s 135 Vector3 resetposition; //Start position for Ghost 121 136 122 137 }; -
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc
r11832 r11834 43 43 The context of this object. 44 44 */ 45 PacmanGhost Red::PacmanGhostController(Context* context) : Controller(context)45 PacmanGhostController::PacmanGhostController(Context* context) : Controller(context) 46 46 { 47 47 RegisterObject(PacmanGhostController); 48 49 PacmanGhost* myGhost = nullptr; 50 this->actuelposition = myGhost.getPosition(); 51 48 52 bool ismoving = false; 49 float reltarget_x; 50 float reltarget_z; 51 Vector3& actuelposition; 53 this->target_x = actuelposition.x; 54 this->target_z = actuelposition.z; 55 } 56 57 void PacmanGhostController::setGhost(PacmanGhost ghost){ 58 this->myGhost = ghost; 52 59 } 53 60 … … 61 68 } 62 69 70 71 static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)]; 63 72 /** 64 73 @brief … … 77 86 PacmanGhost* myDrone = *it; 78 87 79 if ( myGhost != nullptr)88 if (this->myGhost != nullptr) 80 89 { 81 90 82 actuelposition =myGhost.getPosition();91 this->actuelposition = this->myGhost.getPosition(); 83 92 84 if( actuelposition.x = reltarget_x && actuelposition.z = reltarget_z){85 ismoving = false;93 if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){ 94 this->ismoving = false; 86 95 } 87 96 88 89 90 if(ismoving){ 91 moveRightLeft(); 92 moveFrontBack(); 97 if(this->ismoving){ 98 if(!((this->actuelposition.z-target_z)<0.1)) 99 moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100); 100 if(!((this->actuelposition.x-target_x)<0.1)) 101 moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small 102 } 103 104 else{ //Check on which position ghost is 105 if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){ 106 this->target_x = possibleposition[1].x; 107 this->target_z = possibleposition[1].z; 108 this->ismoving = true; 93 109 } 94 110 else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){ 111 this->target_x = 0 112 this->target_z = 113 this->ismoving = true; 114 } 95 115 else{ 96 97 //hashtable 98 99 int random = rand(); 100 101 switch(actuelposition) { 102 case 1: if(random % 4 == 0){ 103 reltarget_x = 250; 104 reltarget_z = 0; 105 } 106 else if(random % 4 == 1){ 107 reltarget_x = 0; 108 reltarget_z = 250; 109 } 110 else if(random % 4 == 2){ 111 reltarget_x = 0; 112 reltarget_z = -250; 113 } 114 else if(random % 4 == 3){ 115 reltarget_x = -250; 116 reltarget_z = 0; 117 } 118 moving = true; 119 case 2: 120 } 121 } 122 116 } 117 } //End of Position table 123 118 124 119 } 125 120 } 121 126 122 }
Note: See TracChangeset
for help on using the changeset viewer.