- Timestamp:
- Oct 19, 2015, 4:01:54 PM (9 years ago)
- Location:
- code/branches/AI_HS15
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI_HS15/src/libraries/util/Math.cc
r10630 r10670 161 161 - If the other object is exactly above me, the function returns <tt>Vector2(0, 0.5)</tt>. 162 162 */ 163 orxonox::Vector2 get2DView coordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition)163 orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition) 164 164 { 165 165 orxonox::Vector3 distance = otherposition - myposition; -
code/branches/AI_HS15/src/libraries/util/Math.h
r9939 r10670 91 91 _UtilExport float getAngle(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& otherposition); 92 92 _UtilExport orxonox::Vector2 get2DViewdirection(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 93 _UtilExport orxonox::Vector2 get2DView coordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition);93 _UtilExport orxonox::Vector2 get2DViewCoordinates(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition); 94 94 _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); 95 95 _UtilExport bool isObjectHigherThanShipOnMap(const orxonox::Vector3& myposition, const orxonox::Vector3& mydirection, const orxonox::Vector3& myorthonormal, const orxonox::Vector3& otherposition, const float mapangle); -
code/branches/AI_HS15/src/modules/docking/DockingController.cc
r9667 r10670 61 61 62 62 float distance = (this->dock_->getWorldPosition() - entity->getPosition()).length(); 63 Vector2 coord = get2DView coordinates( // I don't understand this too63 Vector2 coord = get2DViewCoordinates( // I don't understand this too 64 64 entity->getPosition(), 65 65 entity->getOrientation() * WorldEntity::FRONT, -
code/branches/AI_HS15/src/modules/overlays/hud/HUDRadar.cc
r9945 r10670 240 240 } 241 241 else 242 coord = get2DView coordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());242 coord = get2DViewCoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition()); 243 243 244 244 coord *= math::pi / 3.5f; // small adjustment to make it fit the texture -
code/branches/AI_HS15/src/orxonox/controllers/AIController.cc
r10654 r10670 86 86 } 87 87 88 88 89 if (this->state_ == SLAVE && this->formationMode_ == ATTACK) 89 90 { … … 108 109 //------------------------------------------------------- 109 110 //collect data for AI behaviour 110 Vector3 meanOfEnemies; 111 Vector3 meanOfAllies; 111 Vector3* meanOfEnemiesPtr = new Vector3(0.0,0.0,0.0); 112 Vector3* meanOfAlliesPtr = new Vector3(0.0,0.0,0.0); 113 Vector3 meanOfAllies = *meanOfAlliesPtr; 114 Vector3 meanOfEnemies = *meanOfEnemiesPtr; 115 112 116 113 117 for (ObjectList<AIController>::iterator it = ObjectList<AIController>::begin(); it; ++it) … … 121 125 if (!FormationController::sameTeam(this->getControllableEntity(), it->getControllableEntity(),gt)) 122 126 { 123 enemies .push_back(*it);127 enemies_.push_back(*it); 124 128 } 125 129 else { 126 allies .push_back(*it);130 allies_.push_back(*it); 127 131 } 128 132 } 129 if (enemies.size() != 0 && allies.size() != 0){ 130 for (std::vector<AIController*>::iterator it = enemies.begin() ; it != enemies.end(); ++it) 131 meanOfEnemies += (*it)->getControllableEntity()->getPosition(); 132 meanOfEnemies /= enemies.size(); 133 for (std::vector<AIController*>::iterator it = allies.begin() ; it != allies.end(); ++it) 134 meanOfAllies += (*it)->getControllableEntity()->getPosition(); 135 meanOfAllies /= allies.size(); 136 //orxout(internal_error) << "There are " << enemiesCounter << " enemies, mean position is " << meanOfEnemies << endl; 137 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 138 orxout(internal_error) << "mean of Allies is " << meanOfAllies << ", with a size " << allies.size() << endl; 139 orxout(internal_error) << "mean of Enemies is " << meanOfEnemies << ", with a size " << enemies.size() << endl; 133 if (enemies_.size() != 0 && allies_.size() != 0){ 134 for (std::vector<WeakPtr<AIController> >::iterator it = enemies_.begin() ; it != enemies_.end(); ++it) 135 meanOfEnemies += (*it)->getControllableEntity()->getWorldPosition(); 136 137 meanOfEnemies /= enemies_.size(); 138 139 for (std::vector<WeakPtr<AIController> >::iterator it = allies_.begin() ; it != allies_.end(); ++it) 140 meanOfAllies += (*it)->getControllableEntity()->getWorldPosition(); 141 142 meanOfAllies /= allies_.size(); 143 144 //orxout(internal_error) << "There are " << enemies_Counter << " enemies_, mean position is " << meanOfEnemies << endl; 145 orxout(internal_error) << "Distance is " << (meanOfEnemies-meanOfAllies).length() << endl; 146 orxout(internal_error) << "mean of allies_ is " << meanOfAllies << ", with a size " << allies_.size() << endl; 147 orxout(internal_error) << "mean of enemies_ is " << meanOfEnemies << ", with a size " << enemies_.size() << endl; 140 148 } 141 149 //------------------------------------------------------- 142 150 143 151 //Decide which formationMode to choose 144 152 this->setFormationMode(ATTACK); 145 146 this->commandSlaves(); 153 this->setDesiredPositionOfSlaves(); 154 155 //this->commandSlaves(); 147 156 148 157 if (this->specificMasterAction_ != NONE) … … 184 193 } 185 194 } 186 allies .clear();187 enemies .clear();195 allies_.clear(); 196 enemies_.clear(); 188 197 } 189 198 … … 196 205 float maxrand = 100.0f / ACTION_INTERVAL; 197 206 ControllableEntity* controllable = this->getControllableEntity(); 207 if (this->state_ == SLAVE) 208 { 209 Vector3 desiredAbsolutePosition = this->myMaster_->getControllableEntity()->getWorldPosition() + this->myMaster_->getControllableEntity()->getWorldOrientation()*desiredRelativePosition_; 210 211 orxonox::WeakPtr<MovableEntity> waypoint = new MovableEntity(this->center_->getContext()); 212 waypoint->setPosition(desiredAbsolutePosition); 213 214 this->addWaypoint(waypoint); 215 } 198 216 //DOES: Either move to the waypoint or search for a Point of interest 199 217 if (controllable && this->mode_ == DEFAULT)// bot is ready to move to a target -
code/branches/AI_HS15/src/orxonox/controllers/AIController.h
r10654 r10670 54 54 55 55 Timer actionTimer_; //<! Regularly calls action(). 56 std::vector<AIController*> enemies, allies; 56 std::vector<WeakPtr<AIController> > enemies_, allies_; 57 Vector3* desiredRelativePosition_; 58 Vector3* currentRelativePosition_; 57 59 }; 58 60 } -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.cc
r10652 r10670 278 278 } 279 279 280 Vector2 coord = get2DView coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);280 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 281 281 float distance = (target - this->getControllableEntity()->getPosition()).length(); 282 282 float rotateX = clamp(coord.x * 10, -1.0f, 1.0f); … … 703 703 } 704 704 } 705 /** 706 @brief If master, set the desired relative position of slaves (Vector3) in respect to a master for all the slaves. 707 */ 708 void FormationController::setDesiredPositionOfSlaves() 709 { 710 if (this->state_ != MASTER) 711 return; 712 switch (this->formationMode_){ 713 case ATTACK: 714 for(std::vector<FormationController*>::iterator it = slaves_.begin(), float i = 0; it != slaves_.end(); it++, ++i) 715 { 716 (*it)->desiredPosition_ = new Vector3 ((i-slaves_.size()/2)*200, 0, 0); 717 718 } 719 break; 720 case NORMAL: 721 722 break; 723 case DEFEND: 724 725 break; 726 } 727 728 } 705 729 706 730 /** … … 1070 1094 return; 1071 1095 1072 Vector2 coord = get2DView coordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);1096 Vector2 coord = get2DViewCoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target); 1073 1097 float distance = (target - this->getControllableEntity()->getPosition()).length(); 1074 1098 -
code/branches/AI_HS15/src/orxonox/controllers/FormationController.h
r10631 r10670 70 70 { return this->maxFormationSize_; } 71 71 72 72 /** 73 @brief If master, set the desired position of slaves (Vector2) for all the slaves. 74 */ 75 inline void setDesiredPositionOfSlaves(); 76 73 77 inline void setPassive(bool passive) 74 78 { this->passive_ = passive; } … … 92 96 inline FormationMode getFormationMode() const 93 97 { return this->formationMode_; } 94 98 95 99 virtual void hit(Pawn* originator, btManifoldPoint& contactpoint, float damage); 96 100 -
code/branches/AI_HS15/test/util/MathTest.cc
r9114 r10670 337 337 getAngle 338 338 get2DViewdirection 339 get2DView coordinates339 get2DViewCoordinates 340 340 getPredictedPosition 341 341 */
Note: See TracChangeset
for help on using the changeset viewer.