Changeset 10177 in orxonox.OLD for branches/ai/src/ai/ai_swarm.cc
- Timestamp:
- Jan 3, 2007, 6:39:09 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ai/src/ai/ai_swarm.cc
r10158 r10177 18 18 #include <stdio.h> 19 19 20 AISwarm::AISwarm() 21 { 22 tickCount=0; 23 randomFreq=100; 24 } 25 26 20 27 void AISwarm::process(float dt) 21 28 { 29 if(tickCount>=randomFreq && movement.len()<60){ 30 tickCount=0; 31 int x = (rand()%141)+10; //10-150 32 int z = (rand()%241)-120; //-120-120 33 randomVector=Vector(x,0,z); 34 35 std::cout << "change to: ||" << randomVector.x << " ==" << randomVector.z << "\n"; 36 } 37 tickCount++; 38 39 22 40 std::set<AIModule*>::iterator it; 23 41 Vector swarmPosition=this->getPosition(); 24 42 //std::cout << swarmPosition.x << " " << swarmPosition.z << "\n"; 25 43 26 44 float aMax=70.0f; 27 45 float vMax=1000.0f; 28 29 Vector correction=(destination -swarmPosition)-movement;46 47 Vector correction=(destination+randomVector-swarmPosition)-movement; 30 48 correction.y=0; 31 49 32 50 float correctionLen=correction.len(); 33 51 if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt; 34 52 35 53 //std::cout << angleRad(correction,movement) << "\n"; 36 54 movement+=correction; 37 55 38 56 float movementLen=movement.len(); 39 57 if(movementLen>vMax)movement=movement/movementLen*vMax; 40 41 58 59 42 60 for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ){ 43 61 (*it)->setDestination(swarmPosition); … … 48 66 } 49 67 68 50 69 void AISwarm::addAI(AIModule* aiModule) 51 70 { 52 71 swarmMembers.insert(aiModule); 53 72 } 73 54 74 55 75 void AISwarm::removeAI(AIModule* aiModule) … … 59 79 delete (*it); 60 80 } 81 61 82 62 83 Vector AISwarm::getPosition()
Note: See TracChangeset
for help on using the changeset viewer.