Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10158 in orxonox.OLD for branches/ai/src/ai/ai_swarm.cc


Ignore:
Timestamp:
Jan 2, 2007, 9:47:28 PM (17 years ago)
Author:
tfahrni
Message:

tried some new ideas for swarming and fixed a bug in Vector.h

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/ai/ai_swarm.cc

    r10138 r10158  
    1616#include "ai_swarm.h"
    1717#include "debug.h"
     18#include <stdio.h>
    1819
    1920void AISwarm::process(float dt)
    2021{
    2122        std::set<AIModule*>::iterator it;
    22         it= swarmMembers.begin();
    23         Vector leaderPosition=(*it)->getPosition();
    24         (*it)->setDestination(destination);
    25         (*it)->setEnemyList(enemyList);
    26         (*it)->process(dt);
    27                
    28         for (it++; it!= swarmMembers.end(); it++ ){
    29                 (*it)->setDestination(leaderPosition);
     23        Vector swarmPosition=this->getPosition();
     24        //std::cout << swarmPosition.x << " " << swarmPosition.z << "\n";
     25       
     26        float aMax=70.0f;
     27        float vMax=1000.0f;
     28       
     29        Vector correction=(destination-swarmPosition)-movement;
     30        correction.y=0;
     31       
     32        float correctionLen=correction.len();
     33        if(correctionLen>aMax*dt)correction=correction/correctionLen*aMax*dt;
     34       
     35        //std::cout << angleRad(correction,movement) << "\n";
     36        movement+=correction;
     37       
     38        float movementLen=movement.len();
     39        if(movementLen>vMax)movement=movement/movementLen*vMax;
     40       
     41       
     42        for (it= swarmMembers.begin(); it!= swarmMembers.end(); it++ ){
     43                (*it)->setDestination(swarmPosition);
     44                (*it)->setDestinationMovement(movement);
    3045                (*it)->setEnemyList(enemyList);
    3146                (*it)->process(dt);
Note: See TracChangeset for help on using the changeset viewer.