Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10158 in orxonox.OLD for branches


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

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

Location:
branches/ai/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/ai/src/ai/ai_module.h

    r10138 r10158  
    1414        inline void setEnemyList(std::vector<WorldEntity*>* enemyList){this->enemyList=enemyList;}
    1515        inline Vector getPosition(){return myWorldEntity->getAbsCoor();}
     16        inline Vector getMovement(){return this->movement;}
    1617        inline void setDestination(Vector destination){this->destination=destination;}
     18        inline void setDestinationMovement(Vector destinationMovement){this->destinationMovement=destinationMovement;}
    1719       
    1820 protected:
     
    2123        std::vector<WorldEntity*>* enemyList;
    2224        Vector destination;
     25        Vector destinationMovement;
     26        Vector movement;
    2327};
    2428
  • 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);
  • branches/ai/src/ai/ai_swarm.h

    r10138 r10158  
    1919        private:
    2020                Vector destination;
     21                Vector movement;
    2122                std::vector<WorldEntity*>* enemyList;
    2223                std::set<AIModule*> swarmMembers;
  • branches/ai/src/ai/ai_team.cc

    r10138 r10158  
    1919void AITeam::process(float dt)
    2020{
     21        //int x;
     22        //int z;
     23        //Vector random;
     24       
    2125        std::map<int,AISwarm*>::iterator it;
    2226        for (it= swarms.begin(); it!= swarms.end(); it++ ){
     27       
     28                //x = 20*(rand()%10 + 1)-100;
     29                //z = 20*(rand()%10 + 1)-100;
     30                //random=Vector(x,0,z);
     31               
    2332                it->second->setEnemyList(enemyList);
    2433                if(enemyList->size()>0)
  • branches/ai/src/ai/movement_module.cc

    r10138 r10158  
    202202        Vector vectorToDestination=destination-myPosition;
    203203
    204         Vector correction=playerCollision*50+npcCollision*50+vectorToDestination+Vector(0,0,0)-myMovement;
     204        Vector correction=              playerCollision*50*3
     205                                                                +       npcCollision*50*3
     206                                                                +       Vector(0,0,0)
     207                                                                +       destinationMovement*2//-myMovement
     208                                                                +       (vectorToDestination-myMovement)*3;
    205209
    206210        correction.y=0;
     
    225229        //myNPC->setAbsDir( Quaternion( view, Vector(0,1,0)));
    226230        myNPC->setAbsDirSoft( Quaternion( view, Vector(0,1,0)),3);
     231        movement=myMovement;
    227232}
    228233
  • branches/ai/src/lib/math/vector.h

    r9110 r10158  
    114114 * @return the angle between the vectors in radians
    115115*/
    116 inline float angleDeg (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())); };
     116inline float angleRad (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())); };
    117117/**
    118118 *  calculate the angle between two vectors in degrees
     
    121121 * @return the angle between the vectors in degrees
    122122*/
    123 inline float angleRad (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())) * 180/M_PI; };
     123inline float angleDeg (const Vector& v1, const Vector& v2) { return acos( v1 * v2 / (v1.len() * v2.len())) * 180/M_PI; };
    124124
    125125/** an easy way to create a Random Vector @param sideLength the length of the Vector (x not sqrt(x^2...)) */
Note: See TracChangeset for help on using the changeset viewer.