[Orxonox-commit 6011] r10670 - in code/branches/AI_HS15: src/libraries/util src/modules/docking src/modules/overlays/hud src/orxonox/controllers test/util
gania at orxonox.net
gania at orxonox.net
Mon Oct 19 16:01:55 CEST 2015
Author: gania
Date: 2015-10-19 16:01:54 +0200 (Mon, 19 Oct 2015)
New Revision: 10670
Modified:
code/branches/AI_HS15/src/libraries/util/Math.cc
code/branches/AI_HS15/src/libraries/util/Math.h
code/branches/AI_HS15/src/modules/docking/DockingController.cc
code/branches/AI_HS15/src/modules/overlays/hud/HUDRadar.cc
code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
code/branches/AI_HS15/src/orxonox/controllers/AIController.h
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
code/branches/AI_HS15/test/util/MathTest.cc
Log:
hold position in formation with waypoints
Modified: code/branches/AI_HS15/src/libraries/util/Math.cc
===================================================================
--- code/branches/AI_HS15/src/libraries/util/Math.cc 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/libraries/util/Math.cc 2015-10-19 14:01:54 UTC (rev 10670)
@@ -160,7 +160,7 @@
- If the other object is only a bit at my right, the function still returns <tt>Vector2(0.01, 0)</tt>.
- If the other object is exactly above me, the function returns <tt>Vector2(0, 0.5)</tt>.
*/
- orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
+ orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)
{
orxonox::Vector3 distance = otherposition - myposition;
Modified: code/branches/AI_HS15/src/libraries/util/Math.h
===================================================================
--- code/branches/AI_HS15/src/libraries/util/Math.h 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/libraries/util/Math.h 2015-10-19 14:01:54 UTC (rev 10670)
@@ -90,7 +90,7 @@
_UtilExport float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition);
_UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
- _UtilExport orxonox::Vector2 get2DViewcoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
+ _UtilExport orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);
_UtilExport orxonox::Vector2 get3DProjection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle, const float detectionlimit);
_UtilExport bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle);
_UtilExport int determineMap3DZOrder(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float detectionlimit);
Modified: code/branches/AI_HS15/src/modules/docking/DockingController.cc
===================================================================
--- code/branches/AI_HS15/src/modules/docking/DockingController.cc 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/modules/docking/DockingController.cc 2015-10-19 14:01:54 UTC (rev 10670)
@@ -60,7 +60,7 @@
return;
float distance = (this->dock_->getWorldPosition() - entity->getPosition()).length();
- Vector2 coord = get2DViewcoordinates( // I don't understand this too
+ Vector2 coord = get2DViewCoordinates( // I don't understand this too
entity->getPosition(),
entity->getOrientation() * WorldEntity::FRONT,
entity->getOrientation() * WorldEntity::UP,
Modified: code/branches/AI_HS15/src/modules/overlays/hud/HUDRadar.cc
===================================================================
--- code/branches/AI_HS15/src/modules/overlays/hud/HUDRadar.cc 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/modules/overlays/hud/HUDRadar.cc 2015-10-19 14:01:54 UTC (rev 10670)
@@ -239,7 +239,7 @@
it->second->_notifyZOrder(this->overlay_->getZOrder() * 100 + 70 + zOrder);
}
else
- coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
+ coord = get2DViewCoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
coord *= math::pi / 3.5f; // small adjustment to make it fit the texture
it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
Modified: code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/AIController.cc 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/orxonox/controllers/AIController.cc 2015-10-19 14:01:54 UTC (rev 10670)
@@ -85,6 +85,7 @@
}
+
if (this->state_ == SLAVE && this->formationMode_ == ATTACK)
{
// search enemy
@@ -107,9 +108,12 @@
//-------------------------------------------------------
//collect data for AI behaviour
- Vector3 meanOfEnemies;
- Vector3 meanOfAllies;
+ Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0);
+ Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0);
+ Vector3 meanOfAllies = *meanOfAlliesPtr;
+ Vector3 meanOfEnemies = *meanOfEnemiesPtr;
+
for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it)
{
@@ -120,31 +124,36 @@
}
if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt))
{
- enemies.push_back(*it);
+ enemies_.push_back(*it);
}
else {
- allies.push_back(*it);
+ allies_.push_back(*it);
}
}
- if (enemies.size() != 0 && allies.size() != 0){
- for (std::vector<AIController*>::iterator it = enemies.begin() ; it != enemies.end(); ++it)
- meanOfEnemies += (*it)->getControllableEntity()->getPosition();
- meanOfEnemies /= enemies.size();
- for (std::vector<AIController*>::iterator it = allies.begin() ; it != allies.end(); ++it)
- meanOfAllies += (*it)->getControllableEntity()->getPosition();
- meanOfAllies /= allies.size();
- //orxout(internal_error) << "There are " << enemiesCounter << " enemies, mean position is " << meanOfEnemies << endl;
- orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
- orxout(internal_error) << "mean of Allies is " << meanOfAllies << ", with a size " << allies.size() << endl;
- orxout(internal_error) << "mean of Enemies is " << meanOfEnemies << ", with a size " << enemies.size() << endl;
+ if (enemies_.size() != 0 && allies_.size() != 0){
+ for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it)
+ meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition();
+
+ meanOfEnemies /= enemies_.size();
+
+ for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it)
+ meanOfAllies += (*it)->getControllableEntity()->getWorldPosition();
+
+ meanOfAllies /= allies_.size();
+
+ //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl;
+ orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl;
+ orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl;
+ orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl;
}
//-------------------------------------------------------
-
+ //Decide which formationMode to choose
this->setFormationMode(ATTACK);
-
- this->commandSlaves();
+ this->setDesiredPositionOfSlaves();
+ //this->commandSlaves();
+
if (this->specificMasterAction_ != NONE)
this->specificMasterActionHold();
@@ -183,8 +192,8 @@
}
}
- allies.clear();
- enemies.clear();
+ allies_.clear();
+ enemies_.clear();
}
void AIController::tick(float dt)
@@ -195,6 +204,15 @@
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
ControllableEntity* controllable = this->getControllableEntity();
+ if (this->state_ == SLAVE)
+ {
+ Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()*desiredRelativePosition_;
+
+ orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext());
+ waypoint->setPosition(desiredAbsolutePosition);
+
+ this->addWaypoint(waypoint);
+ }
//DOES: Either move to the waypoint or search for a Point of interest
if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target
{
Modified: code/branches/AI_HS15/src/orxonox/controllers/AIController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/AIController.h 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/orxonox/controllers/AIController.h 2015-10-19 14:01:54 UTC (rev 10670)
@@ -53,7 +53,9 @@
static const float ACTION_INTERVAL;
Timer actionTimer_; //<! Regularly calls action().
- std::vector<AIController*> enemies, allies;
+ std::vector<WeakPtr<AIController> > enemies_, allies_;
+ Vector3* desiredRelativePosition_;
+ Vector3* currentRelativePosition_;
};
}
Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc 2015-10-19 14:01:54 UTC (rev 10670)
@@ -277,7 +277,7 @@
// return;
}
- Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
float distance = (target - this->getControllableEntity()->getPosition()).length();
float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
@@ -702,7 +702,31 @@
}
}
}
+ /**
+ @brief If master, set the desired relative position of slaves (Vector3) in respect to a master for all the slaves.
+ */
+ void FormationController::setDesiredPositionOfSlaves()
+ {
+ if (this->state_ != MASTER)
+ return;
+ switch (this->formationMode_){
+ case ATTACK:
+ for(std::vector<FormationController*>::iterator it = slaves_.begin(), float i = 0; it != slaves_.end(); it++, ++i)
+ {
+ (*it)->desiredPosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0);
+
+ }
+ break;
+ case NORMAL:
+ break;
+ case DEFEND:
+
+ break;
+ }
+
+ }
+
/**
@brief Used to continue a "specific master action" for a certain time and resuming normal behaviour after.
*/
@@ -1069,7 +1093,7 @@
if (!this->getControllableEntity())
return;
- Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
float distance = (target - this->getControllableEntity()->getPosition()).length();
if (this->target_ || distance > minDistance)
Modified: code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
===================================================================
--- code/branches/AI_HS15/src/orxonox/controllers/FormationController.h 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/src/orxonox/controllers/FormationController.h 2015-10-19 14:01:54 UTC (rev 10670)
@@ -69,7 +69,11 @@
inline int getFormationSize() const
{ return this->maxFormationSize_; }
-
+ /**
+ @brief If master, set the desired position of slaves (Vector2) for all the slaves.
+ */
+ inline void setDesiredPositionOfSlaves();
+
inline void setPassive(bool passive)
{ this->passive_ = passive; }
inline bool getPassive() const
@@ -91,7 +95,7 @@
void setFormationMode(FormationMode val);
inline FormationMode getFormationMode() const
{ return this->formationMode_; }
-
+
virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage);
FormationController* getMaster( void ) { return myMaster_; }
Modified: code/branches/AI_HS15/test/util/MathTest.cc
===================================================================
--- code/branches/AI_HS15/test/util/MathTest.cc 2015-10-19 14:00:00 UTC (rev 10669)
+++ code/branches/AI_HS15/test/util/MathTest.cc 2015-10-19 14:01:54 UTC (rev 10670)
@@ -336,7 +336,7 @@
/*
getAngle
get2DViewdirection
- get2DViewcoordinates
+ get2DViewCoordinates
getPredictedPosition
*/
}
More information about the Orxonox-commit
mailing list