Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 21, 2007, 3:49:34 PM (16 years ago)
Author:
motth
Message:

added Flocking

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI/src/Flocking.h

    r212 r233  
    2323
    2424
    25   void element(Vector3 location_, Vector3 speed_, Vector3 acceleration_) {
     25  Element(Vector3 location_, Vector3 speed_, Vector3 acceleration_) {
    2626    acceleration = acceleration_;
    2727    speed = speed_;
     
    3636
    3737//EINF[GEN DES ELEMENTS
    38   void update(/*Element übergeben*/) {
    39     calculateAcceleration(/*Elementübergabe*/);  //updates the acceleration
     38  void update(Element* arrayOfElements) {
     39    calculateAcceleration(arrayOfElements);  //updates the acceleration
    4040    calculateSpeed();  //updates the speed
    4141    calculateLocation();  //updates the location
     
    4343
    4444//EINF[GEN DES ELEMENTS
    45   void calculateAcceleration(/*Element übergeben*/) {
     45  void calculateAcceleration(Element* arrayOfElements) {
    4646  //calculates the accelerationvector based on the steeringvectors of
    4747  //separtion, alignment and cohesion.
    48   acceleration = acceleration + separation() + alignment() + cohesion();
     48  acceleration = acceleration + separation(arrayOfElements) + 2*alignment(arrayOfElements) + 2*cohesion(arrayOfElements);
    4949  }
    5050
    5151  void calculateSpeed() {
    5252  speed = speed + acceleration;
     53  //speed = speed.normalise();
    5354  }
    5455
     
    5859  }
    5960
    60   Vector3 separation() {
     61  Vector3 separation(Element* arrayOfElements) {
    6162    Vector3 steering; //steeringvector
    6263    int numberOfNeighbour;  //number of observed neighbours
     
    6465    for(int i=1; i<3; i++) {  //just working with 3 elements at the moment
    6566      Element actual = arrayOfElements[i];  //get the actual element
    66       float distance = Element.getDistance(actual);  //get distance between this and actual
     67      float distance = getDistance(actual);  //get distance between this and actual
    6768//DUMMY SEPERATION DETECTION DISTANCE = 25
    68       if ((distance > 0) && (distance<25)) {  //do only if actual is inside detectionradius
     69      if ((distance > 0) && (distance<1)) {  //do only if actual is inside detectionradius
    6970        Vector3 inverseDistance = actual.location-location;  //calculate the distancevector heading towards this
    7071        inverseDistance = inverseDistance.normalise(); //does this work correctly?  //normalise the distancevector
    71         inverseDistance = inverseDistance/distance;  //devide distancevector by distance (the closer the bigger gets the distancevector -> steeringvector)
     72        inverseDistance = inverseDistance/*/distance;*/ ;  //devide distancevector by distance (the closer the bigger gets the distancevector -> steeringvector)
    7273        steering = steering + inverseDistance;  //add up all significant steeringvectors
    7374        numberOfNeighbour++;  //counts the elements inside the detectionradius
     
    8081  }
    8182
    82   Vector3 alignment() {
     83  Vector3 alignment(Element* arrayOfElements) {
    8384    Vector3 steering; //steeringvector
    8485    int numberOfNeighbour;  //number of observed neighbours
     
    8687    for(int i=1; i<3; i++) {  //just working with 3 elements at the moment
    8788      Element actual = arrayOfElements[i];  //get the actual element
    88       float distance = Element.getDistance(actual);  //get distance between this and actual
     89      float distance = getDistance(actual);  //get distance between this and actual
    8990//DUMMY ALIGNMENT DETECTION DISTANCE = 50
    90       if ((distance > 0) && (distance<50)) {  //check if actual element is inside detectionradius
     91      if ((distance > 0) && (distance<1000)) {  //check if actual element is inside detectionradius
    9192        steering = steering + actual.speed;  //add up all speedvectors inside the detectionradius
    9293        numberOfNeighbour++;  //counts the elements inside the detectionradius
     
    99100  }
    100101
    101   Vector3 cohesion() {
     102  Vector3 cohesion(Element* arrayOfElements) {
    102103    Vector3 steering; //steeringvector
    103104    int numberOfNeighbour;  //number of observed neighbours
     
    105106    for(int i=1; i<3; i++) {  //just working with 3 elements at the moment
    106107      Element actual = arrayOfElements[i];  //get the actual element
    107       float distance = Element.getDistance(actual);  //get distance between this and actual
     108      float distance = getDistance(actual);  //get distance between this and actual
    108109// DUMMY COHESION DETECTION DISTANCE = 50
    109       if ((distance > 0) && (distance<50)) {  //check if actual element is inside detectionradius
     110      if ((distance > 0) && (distance<1000)) {  //check if actual element is inside detectionradius
    110111        steering = steering + actual.location;  //add up all locations of elements inside the detectionradius
    111112        numberOfNeighbour++;  //counts the elements inside the detectionradius
Note: See TracChangeset for help on using the changeset viewer.