Changeset 10789
- Timestamp:
- Nov 9, 2015, 4:38:02 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/data/levels/AITest.oxw
r10759 r10789 85 85 </controller> 86 86 </SpaceShip> 87 < SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0">87 <!-- <SpaceShip position="<?1000 ?>,<?lua print(1500+i*1000) ?>, -1600 ?>" lookat="0,0,0"> 88 88 <templates> 89 89 <Template link=spaceshipassff /> … … 111 111 </SectionController> 112 112 </controller> 113 </SpaceShip> 113 </SpaceShip> --> 114 114 <?lua end ?> 115 115 <!-- <SpaceShip position="4000, 1500, -1300 ?>" lookat="0,0,0"> -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10782 r10789 45 45 46 46 RegisterClass(CommonController); 47 float SPEED = 0.7f ;48 float ROTATEFACTOR = 0.3f ;47 float SPEED = 0.7f/0.02f; 48 float ROTATEFACTOR = 0.3f/0.02f; 49 49 50 50 CommonController::CommonController(Context* context) : Controller(context) … … 52 52 this->bSetupWorked = false; 53 53 54 this->targetMask_.exclude(ClassByString("BaseObject")); 55 this->targetMask_.include(ClassByString("WorldEntity")); 56 this->targetMask_.exclude(ClassByString("Projectile")); 54 this->executingManeuver_ = false; 55 this->executingMoveToPoint_ = false; 57 56 58 57 RegisterObject(CommonController); … … 173 172 174 173 //copy the Roll orientation of given Quaternion. 175 void CommonController::copyOrientation(const Quaternion& orient )174 void CommonController::copyOrientation(const Quaternion& orient, float dt) 176 175 { 177 176 //roll angle difference in radian … … 179 178 while(diff>math::twoPi) diff-=math::twoPi; 180 179 while(diff<-math::twoPi) diff+=math::twoPi; 181 this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR );182 } 183 void CommonController::copyTargetOrientation( )180 this->getControllableEntity()->rotateRoll(diff*ROTATEFACTOR * dt); 181 } 182 void CommonController::copyTargetOrientation(float dt) 184 183 { 185 184 if (bHasTargetOrientation_) 186 185 { 187 copyOrientation(targetOrientation_ );188 } 189 } 190 191 192 193 194 void CommonController::moveToTargetPosition( )195 { 196 this->moveToPosition(this->targetPosition_ );197 } 198 void CommonController::moveToPosition(const Vector3& target )186 copyOrientation(targetOrientation_, dt); 187 } 188 } 189 190 191 192 193 void CommonController::moveToTargetPosition(float dt) 194 { 195 this->moveToPosition(this->targetPosition_, dt); 196 } 197 void CommonController::moveToPosition(const Vector3& target, float dt) 199 198 { 200 199 float factor = 1; … … 227 226 { 228 227 //Yaw and Pitch are enough to start facing the target 229 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX );230 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY );228 this->getControllableEntity()->rotateYaw(-2.0f * ROTATEFACTOR * rotateX * dt); 229 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt); 231 230 232 231 //300 works, maybe less is better … … 239 238 if (bHasTargetOrientation_) 240 239 { 241 copyTargetOrientation( );240 copyTargetOrientation(dt); 242 241 } 243 242 } 244 243 245 this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor );244 this->getControllableEntity()->moveFrontBack(1.2f*SPEED*factor * dt); 246 245 } 247 246 else … … 253 252 //to be called in action 254 253 //PRE: relativeTargetPosition is desired position relative to the spaceship, 255 //angleRoll is the angle of Roll that should be applied by the end of the movement256 //POST: target Position_ and angleRoll_are set, so that it can be used by MoveAndRoll()257 void MoveToPoint(const Vector3& relativeTargetPosition, float angleRoll)254 //angleRoll is the angle in degrees of Roll that should be applied by the end of the movement 255 //POST: target orientation and position are set, so that it can be used by MoveAndRoll() 256 void CommonController::moveToPoint(const Vector3& relativeTargetPosition, float angleRoll) 258 257 { 259 258 ControllableEntity* entity = this->getControllableEntity(); 260 259 if (!entity) 261 return false;260 return; 262 261 Quaternion orient = entity->getWorldOrientation(); 262 Quaternion rotation = Quaternion(Degree(angleRoll), Vector3::UNIT_Z); 263 263 264 264 Vector3 target = orient * relativeTargetPosition + entity->getWorldPosition(); 265 265 setTargetPosition(target); 266 this->angleRoll_ = angleRoll; 267 this->angleRolled_ = 0; 266 orient = orient * rotation; 267 this->setTargetOrientation(orient); 268 268 269 } 269 270 //to be called in tick … … 275 276 //if position reached with a certain tolerance, and angleRolled_ = angleRoll_, returns false, 276 277 //otherwise returns true 277 bool MoveAndRoll(float dt) 278 { 278 //dt is normally around 0.02f, which makes it 1/0.02 = 50 frames/sec 279 bool CommonController::moveAndRoll(float dt) 280 { 281 float factor = 1; 282 if (!this->getControllableEntity()) 283 return false; 284 if (this->rank_ == Rank::DIVISIONLEADER) 285 factor = 0.8; 286 if (this->rank_ == Rank::SECTIONLEADER) 287 factor = 0.9; 279 288 int tolerance = 60; 280 float rollDiff = angleRoll-angleRolled_; 281 float angleToRoll = 0; 289 282 290 ControllableEntity* entity = this->getControllableEntity(); 283 291 if (!entity) 284 return false;292 return true; 285 293 Vector2 coord = get2DViewCoordinates 286 294 (entity->getPosition(), … … 302 310 this->getControllableEntity()->rotatePitch(2.0f * ROTATEFACTOR * rotateY * dt); 303 311 312 //Roll 313 if (bHasTargetOrientation_) 314 { 315 copyTargetOrientation(dt); 316 } 317 304 318 //Move 305 319 this->getControllableEntity()->moveFrontBack(1.2f * SPEED * factor * dt); 306 307 //Roll308 angleToRoll = rollDiff * ROTATEFACTOR * dt;309 this->getControllableEntity()->rotateRoll(angleToRoll);310 angleRolled_ += angleToRoll;311 320 //if still moving, return false 312 321 return false; … … 314 323 else 315 324 { 316 if (rollDiff > 0) 317 { 318 //Roll 319 angleToRoll = rollDiff * ROTATEFACTOR * dt; 320 this->getControllableEntity()->rotateRoll(angleToRoll); 321 angleRolled_ += angleToRoll; 322 323 //Move 324 this->getControllableEntity()->moveFrontBack(0.6f * SPEED * factor); 325 return false; 326 } 325 327 326 //if finished, return true; 328 retu n true;329 } 330 } 331 332 float squaredDistanceToTarget()327 return true; 328 } 329 } 330 331 float CommonController::squaredDistanceToTarget() const 333 332 { 334 333 if ( !this->getControllableEntity() ) 335 334 return 0; 336 335 if ( !this->target_ ) 337 return ( this->getControllableEntity()-> 338 getPosition().squaredDistance(this->targetPosition_) ); 339 else 340 return ( this->getControllableEntity()-> 341 getPosition().squaredDistance(this->target_->getPosition()) ); 336 return ( this->getControllableEntity()->getPosition().squaredDistance(this->targetPosition_) ); 337 else 338 return ( this->getControllableEntity()->getPosition().squaredDistance(this->target_->getPosition()) ); 342 339 } 343 340 -
code/branches/AI_HS15/src/orxonox/controllers/CommonController.h
r10782 r10789 76 76 } 77 77 78 78 79 class _OrxonoxExport CommonController : public Controller 79 80 { … … 121 122 protected: 122 123 123 void moveToPosition(const Vector3& target); 124 void moveToTargetPosition(); 124 void moveToPoint(const Vector3& relativeTargetPosition, float angleRoll); 125 bool moveAndRoll(float dt); 126 127 void moveToPosition(const Vector3& target, float dt); 128 void moveToTargetPosition(float dt); 125 129 //enum Mode {ROCKET, ATTACK, MOVE, HOLD};//TODO; implement DEFENCE, MOVING modes 126 130 127 131 //Mode mode_; 128 void copyOrientation(const Quaternion& orient );129 void copyTargetOrientation( );132 void copyOrientation(const Quaternion& orient, float dt); 133 void copyTargetOrientation(float dt); 130 134 131 135 float squaredDistanceToTarget() const; … … 160 164 WeakPtr<ControllableEntity> objectiveTarget_; 161 165 162 float angleRolled_;163 float angleRoll_;164 166 165 167 … … 169 171 Maneuver::Value maneuver_; 170 172 171 ClassTreeMask targetMask_;172 173 bool executingManeuver_; 174 bool executingMoveToPoint_; 173 175 174 176 private: -
code/branches/AI_HS15/src/orxonox/controllers/DivisionController.cc
r10780 r10789 63 63 this->bShooting_ = true; 64 64 }*/ 65 66 if (this->bHasTargetPosition_)65 66 /* if (this->bHasTargetPosition_) 67 67 { 68 68 this->moveToTargetPosition(); 69 }*/ 70 if (executingMoveToPoint_) 71 { 72 executingMoveToPoint_ = !this->moveAndRoll(dt); 69 73 } 70 74 if (this->bShooting_) … … 81 85 setTargetPositionOfFollower(); 82 86 setTargetPositionOfWingman(); 83 87 if (!executingMoveToPoint_) 88 { 89 Vector3* targetPosition = new Vector3 (0, 0, -2000); 90 moveToPoint(*targetPosition, 180); 91 executingMoveToPoint_ = true; 92 } 84 93 85 94 if (this->myFollower_ && this->target_) -
code/branches/AI_HS15/src/orxonox/controllers/FleetController.cc
r10763 r10789 69 69 (*it2)->setTargetPosition(this->getControllableEntity()->getWorldPosition()); 70 70 }*/ 71 for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it)71 /*for (ObjectList<Controller>::iterator it = ObjectList<Controller>::begin(); it; ++it) 72 72 { 73 73 if ((this->getControllableEntity()->getTeam() != (it)->getControllableEntity()->getTeam()) && (it)->getControllableEntity()->getTeam() == 0) … … 79 79 break; 80 80 } 81 } 81 }*/ 82 82 83 83 } -
code/branches/AI_HS15/src/orxonox/controllers/SectionController.cc
r10780 r10789 61 61 if (this->bHasTargetPosition_) 62 62 { 63 this->moveToTargetPosition( );63 this->moveToTargetPosition(dt); 64 64 } 65 65 if (this->bShooting_) -
code/branches/AI_HS15/src/orxonox/controllers/WingmanController.cc
r10780 r10789 125 125 if (this->bHasTargetPosition_) 126 126 { 127 this->moveToTargetPosition( );127 this->moveToTargetPosition(dt); 128 128 } 129 129
Note: See TracChangeset
for help on using the changeset viewer.