Changeset 10764 for code/branches/AI_HS15/src/orxonox/controllers
- Timestamp:
- Nov 4, 2015, 4:07:46 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
r10763 r10764 259 259 bool CommonController::canFire() 260 260 { 261 262 float tolerance = 50.0f; 263 261 264 //check pointers 262 if (!this->getControllableEntity() || !this->target_ )265 if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity()) 263 266 return false; 264 267 265 268 //check if this points in the direction of target_ 266 269 267 270 Vector3 myPosition = this->getControllableEntity()->getWorldPosition(); 268 Vector3 targetPosition = this->target_->getWorldPosition(); 271 Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition(); 272 269 273 Vector3 differenceVector = targetPosition - myPosition; 270 float scalarProduct = differenceVector.dotProduct(WorldEntity::FRONT); 271 Vector3 projection = scalarProduct * WorldEntity::FRONT; 272 if ((differenceVector - projection).length() > 50) 274 float differenceLength = differenceVector.length(); 275 276 Vector3 myDirection = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT; 277 278 float angle = getAngle (myPosition, myDirection, targetPosition); 279 float heightLength = sin(angle) * differenceLength; 280 281 if (heightLength > tolerance) 273 282 return false; 274 283 275 284 285 276 286 //check if there are allies on the way 277 Vector3 allyPosition, allyDifference, allyProjection; 278 float allyScalarProduct; 287 Vector3 allyPosition, allyDifference; 288 float allyDifferenceLength, allyAngle, allyHeightLength; 289 279 290 for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it) 280 291 { … … 284 295 { 285 296 allyPosition = it->getControllableEntity()->getWorldPosition(); 297 286 298 allyDifference = allyPosition - myPosition; 287 allyScalarProduct = allyDifference.dotProduct(WorldEntity::FRONT); 288 allyProjection = allyScalarProduct * WorldEntity::FRONT; 289 if (allyScalarProduct < 0 || allyScalarProduct > scalarProduct) 299 allyDifferenceLength = allyDifference.length(); 300 301 allyAngle = getAngle (myPosition, myDirection, allyPosition); 302 303 allyHeightLength = sin(allyAngle) * allyDifferenceLength; 304 305 if (allyAngle > math::pi /2) 290 306 continue; 291 if ( (allyDifference - allyProjection).length() < 50)307 if (allyHeightLength <= tolerance) 292 308 return false; 293 309 }
Note: See TracChangeset
for help on using the changeset viewer.