[Orxonox-commit 6106] r10764 - code/branches/AI_HS15/src/orxonox/controllers
gania at orxonox.net
gania at orxonox.net
Wed Nov 4 16:07:46 CET 2015
Author: gania
Date: 2015-11-04 16:07:46 +0100 (Wed, 04 Nov 2015)
New Revision: 10764
Modified:
code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
Log:
fixed canFire() function
Modified: code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-03 16:06:05 UTC (rev 10763)
+++ code/branches/AI_HS15/src/orxonox/controllers/CommonController.cc 2015-11-04 15:07:46 UTC (rev 10764)
@@ -258,24 +258,35 @@
bool CommonController::canFire()
{
+
+ float tolerance = 50.0f;
+
//check pointers
- if (!this->getControllableEntity() || !this->target_)
+ if (!this->getControllableEntity() || !this->target_ || !this->target_->getControllableEntity())
return false;
-
+
//check if this points in the direction of target_
Vector3 myPosition = this->getControllableEntity()->getWorldPosition();
- Vector3 targetPosition = this->target_->getWorldPosition();
+ Vector3 targetPosition = this->target_->getControllableEntity()->getWorldPosition();
+
Vector3 differenceVector = targetPosition - myPosition;
- float scalarProduct = differenceVector.dotProduct(WorldEntity::FRONT);
- Vector3 projection = scalarProduct * WorldEntity::FRONT;
- if ((differenceVector - projection).length() > 50)
+ float differenceLength = differenceVector.length();
+
+ Vector3 myDirection = this->getControllableEntity()->getOrientation() * WorldEntity::FRONT;
+
+ float angle = getAngle (myPosition, myDirection, targetPosition);
+ float heightLength = sin(angle) * differenceLength;
+
+ if (heightLength > tolerance)
return false;
+
//check if there are allies on the way
- Vector3 allyPosition, allyDifference, allyProjection;
- float allyScalarProduct;
+ Vector3 allyPosition, allyDifference;
+ float allyDifferenceLength, allyAngle, allyHeightLength;
+
for (ObjectList<CommonController>::iterator it = ObjectList<CommonController>::begin(); it; ++it)
{
if (!it->getControllableEntity())
@@ -283,12 +294,17 @@
if ((this->getControllableEntity()->getTeam() == (it)->getControllableEntity()->getTeam()))
{
allyPosition = it->getControllableEntity()->getWorldPosition();
+
allyDifference = allyPosition - myPosition;
- allyScalarProduct = allyDifference.dotProduct(WorldEntity::FRONT);
- allyProjection = allyScalarProduct * WorldEntity::FRONT;
- if (allyScalarProduct < 0 || allyScalarProduct > scalarProduct)
+ allyDifferenceLength = allyDifference.length();
+
+ allyAngle = getAngle (myPosition, myDirection, allyPosition);
+
+ allyHeightLength = sin(allyAngle) * allyDifferenceLength;
+
+ if (allyAngle > math::pi /2)
continue;
- if ((allyDifference - allyProjection).length() < 50)
+ if (allyHeightLength <= tolerance)
return false;
}
}
More information about the Orxonox-commit
mailing list