- Timestamp:
- Apr 12, 2018, 4:12:25 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/3DPacman_FS18/src/modules/Pacman/PacmanGhost.cc
r11849 r11859 46 46 RegisterObject(PacmanGhost); 47 47 48 this->localLinearAcceleration_.setValue(1, 1, 1);49 this->localAngularAcceleration_.setValue(1, 1, 1);50 51 48 this->velocity = Vector3(0, 0, 0); 52 49 … … 79 76 SUPER(PacmanGhost, XMLPort, xmlelement, mode); 80 77 81 XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);82 XMLPortParam(PacmanGhost, "auxiliaryThrust", setAuxiliaryThrust, getAuxiliaryThrust, xmlelement, mode);83 XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);84 78 XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode); 85 79 } … … 87 81 88 82 89 Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215, 0,240)};83 Vector3 possibleposition[] = {Vector3(0,10,245),Vector3(215,10,245),Vector3(215,10,220)}; 90 84 91 85 /** … … 99 93 SUPER(PacmanGhost, tick, dt); 100 94 101 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxiliaryThrust_); 102 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxiliaryThrust_); 103 if (this->localLinearAcceleration_.z() > 0) 104 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxiliaryThrust_); 105 else 106 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_); 107 this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_); 108 this->localLinearAcceleration_.setValue(0, 0, 0); 109 110 this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_; 111 this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_); 112 this->localAngularAcceleration_.setValue(0, 0, 0); 113 95 //setorientation 114 96 115 97 this->actuelposition = this->getPosition(); 116 98 117 99 //Stop, if target arrived 118 if(( (this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){100 if((abs(this->actuelposition.x - this->target_x)<0.1) && (abs(this->actuelposition.z - this->target_z)<0.1)){ 119 101 this->ismoving = false; 120 102 } … … 122 104 //Move, if ghost hasn't arrived yet 123 105 if(this->ismoving){ 124 if(!( (this->actuelposition.z-target_z)<0.1)) {125 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x), -sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));106 if(!(abs(this->actuelposition.z-target_z)<0.1)) { 107 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z)); 126 108 move(dt, actuelposition, velocity); 127 109 } 128 if(!( (this->actuelposition.x-target_x)<0.1)){129 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x), -sgn(this->actuelposition.y),-sgn(this->actuelposition.z-this->target_z));110 if(!(abs(this->actuelposition.x-target_x)<0.1)){ 111 velocity = Vector3(-sgn(this->actuelposition.x-this->target_x),0,-sgn(this->actuelposition.z-this->target_z)); 130 112 move(dt, actuelposition, velocity); 131 113 } … … 134 116 //Check on which position ghost has arrived and set new target 135 117 else{ 136 if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[0].z)<0.1)){ 137 this->target_x = possibleposition[1].x; 138 this->target_z = possibleposition[1].z; 139 this->ismoving = true; 118 if((abs(this->actuelposition.x - possibleposition[0].x)<0.1) && (abs(this->actuelposition.z - possibleposition[0].z)<0.1)){ 119 decision = rand()%1; 120 switch(decision){ 121 case 0: 122 this->target_x = possibleposition[1].x; 123 this->target_z = possibleposition[1].z; 124 this->ismoving = true; 140 125 } 141 else if(((actuelposition.x - possibleposition[1].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){ 142 this->target_x = possibleposition[0].x; 143 this->target_z = possibleposition[0].z; 144 this->ismoving = true; 126 145 127 } 128 else if((abs(actuelposition.x - possibleposition[1].x)<0.1) && (abs(actuelposition.z - possibleposition[1].z)<0.1)){ 129 decision = rand()%2; 130 switch(decision){ 131 case 0: 132 this->target_x = possibleposition[0].x; 133 this->target_z = possibleposition[0].z; 134 this->ismoving = true; 135 break; 136 case 1: 137 this->target_x = possibleposition[2].x; 138 this->target_z = possibleposition[2].z; 139 this->ismoving = true; 140 } 141 142 } 143 if((abs(this->actuelposition.x - possibleposition[2].x)<0.1) && (abs(this->actuelposition.z - possibleposition[2].z)<0.1)){ 144 decision = rand()%1; 145 switch(decision){ 146 case 0: 147 this->target_x = possibleposition[1].x; 148 this->target_z = possibleposition[1].z; 149 this->ismoving = true; 150 } 151 152 } 153 146 154 else{ 147 155 } //End of Position table … … 151 159 152 160 153 154 161 void PacmanGhost::move(float dt, Vector3 actuelposition, Vector3 velocity){ 155 156 this->setPosition(Vector3(actuelposition.x+velocity.x*dt,actuelposition.y+velocity.y*dt ,actuelposition.z+velocity.z*dt)); 162 this->setPosition(Vector3(actuelposition.x+20*velocity.x*dt,10,actuelposition.z+20*velocity.z*dt)); 157 163 } 158 164 159 160 /** 161 @brief 162 Moves the AutonomousDrone in the negative z-direction (Front/Back) by an amount specified by the first component of the input 2-dim vector. 163 @param value 164 The vector determining the amount of the movement. 165 */ 166 void PacmanGhost::moveFrontBack(const Vector2& value) 167 { 168 //this->setPosition(dt*(actuelposition + velocity_)); 165 void PacmanGhost::resetGhost(){ 166 this->setPosition(resetposition); 169 167 } 170 171 /**172 @brief173 Moves the AutonomousDrone in the x-direction (Right/Left) by an amount specified by the first component of the input 2-dim vector.174 @param value175 The vector determining the amount of the movement.176 */177 void PacmanGhost::moveRightLeft(const Vector2& value)178 {179 this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);180 }181 182 /**183 @brief184 Moves the AutonomousDrone in the y-direction (Up/Down) by an amount specified by the first component of the input 2-dim vector.185 @param value186 The vector determining the amount of the movement.187 */188 void PacmanGhost::moveUpDown(const Vector2& value)189 {190 this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);191 }192 193 /**194 @brief195 Rotates the AutonomousDrone around the y-axis by the amount specified by the first component of the input 2-dim vector.196 @param value197 The vector determining the amount of the angular movement.198 */199 void PacmanGhost::rotateYaw(const Vector2& value)200 {201 this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() - value.x);202 }203 204 /**205 @brief206 Rotates the AutonomousDrone around the x-axis by the amount specified by the first component of the input 2-dim vector.207 @param value208 The vector determining the amount of the angular movement.209 */210 void PacmanGhost::rotatePitch(const Vector2& value)211 {212 this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);213 }214 215 /**216 @brief217 Rotates the AutonomousDrone around the z-axis by the amount specified by the first component of the input 2-dim vector.218 @param value219 The vector determining the amount of the angular movement.220 */221 void PacmanGhost::rotateRoll(const Vector2& value)222 {223 this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);224 }225 226 168 }
Note: See TracChangeset
for help on using the changeset viewer.