Changeset 426 for code/branches/AI/src/Flocking.h
- Timestamp:
- Dec 5, 2007, 10:08:12 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI/src/Flocking.h
r326 r426 13 13 #include <Ogre.h> 14 14 #include <OgreVector3.h> 15 15 16 16 17 #include <iostream> … … 29 30 Vector3 speed; // speedvector of the element 30 31 Vector3 acceleration; // accelerationvector of the element 32 bool movable; // movability of the element 31 33 32 34 Element() { … … 34 36 speed = (0,0,0); 35 37 location = (0,0,0); 38 movable = true; 36 39 } 37 40 38 Element(Vector3 location_, Vector3 speed_, Vector3 acceleration_ ) {41 Element(Vector3 location_, Vector3 speed_, Vector3 acceleration_, bool movable_) { 39 42 acceleration = acceleration_; 40 43 speed = speed_; 41 44 location = location_; 45 movable = movable_; 42 46 } 43 47 44 void setValues(Vector3 location_, Vector3 speed_, Vector3 acceleration_ ) {48 void setValues(Vector3 location_, Vector3 speed_, Vector3 acceleration_, bool movable_) { 45 49 acceleration = acceleration_; 46 50 speed = speed_; 47 51 location = location_; 52 movable = movable_; 48 53 } 49 54 … … 54 59 } 55 60 56 //EINF [GEN DES ELEMENTS61 //EINFÜGEN DES ELEMENTS 57 62 void update(Element arrayOfElements[], const FrameEvent& time) { 58 calculateAcceleration(arrayOfElements); //updates the acceleration 59 calculateSpeed(time); //updates the speed 60 calculateLocation(time); //updates the location 63 if (this->movable == true) {calculateAcceleration(arrayOfElements);} 64 65 /* if (this->movable == true) { 66 calculateAcceleration(arrayOfElements); //updates the acceleration 67 calculateSpeed(time); //updates the speed 68 calculateLocation(time); //updates the location 69 } */ 61 70 } 62 71 63 //EINF [GEN DES ELEMENTS72 //EINFÜGEN DES ELEMENTS 64 73 void calculateAcceleration(Element arrayOfElements[]) { 65 74 //calculates the accelerationvector based on the steeringvectors of … … 79 88 Vector3 separation(Element arrayOfElements[]) { 80 89 Vector3* steering = new Vector3(0,0,0); //steeringvector 90 Vector3* inverseDistance = new Vector3(0,0,0); 81 91 int numberOfNeighbour = 0; //number of observed neighbours 92 float distance = 0; 82 93 //go through all elements 83 for(int i=0; i< 3; i++) { //just working with 3 elements at the moment94 for(int i=0; i<9; i++) { //just working with 3 elements at the moment 84 95 Element actual = arrayOfElements[i]; //get the actual element 85 floatdistance = getDistance(actual); //get distance between this and actual96 distance = getDistance(actual); //get distance between this and actual 86 97 //DUMMY SEPERATION DETECTION DISTANCE =100 87 if ((distance > 0) && (distance<100)) { //do only if actual is inside detectionradius 88 Vector3 inverseDistance = actual.location-location; //calculate the distancevector heading towards this 89 inverseDistance = inverseDistance.normalise(); //does this work correctly? //normalise the distancevector 90 inverseDistance = inverseDistance/*/distance*/; //devide distancevector by distance (the closer the bigger gets the distancevector -> steeringvector) 91 *steering = *steering + inverseDistance; //add up all significant steeringvectors 98 if ((distance > 0) && (distance < 200)) { //do only if actual is inside detectionradius 99 *inverseDistance = (0,0,0); 100 *inverseDistance = location-actual.location; //calculate the distancevector heading towards this 101 //*inverseDistance = inverseDistance->normalise(); //does this work correctly? //normalise the distancevector 102 if ((distance < 100) && (distance >= 80)) {*inverseDistance = *inverseDistance*2;} 103 if ((distance < 80) && (distance >= 60)) {*inverseDistance = *inverseDistance*5;} 104 if ((distance < 60) && (distance >= 40)) {*inverseDistance = *inverseDistance*10;} 105 if ((distance < 40) && (distance > 0)) {*inverseDistance = *inverseDistance*20;} 106 // *inverseDistance = *inverseDistance/distance; //devide distancevector by distance (the closer the bigger gets the distancevector -> steeringvector) 107 *steering = *steering + *inverseDistance; //add up all significant steeringvectors 92 108 numberOfNeighbour++; //counts the elements inside the detectionradius 93 109 } … … 96 112 *steering = *steering / (float)numberOfNeighbour; //devide the sum of steeringvectors by the number of elements -> separation steeringvector 97 113 } 114 cout<<*steering<<endl; 98 115 return *steering; 99 116 } … … 102 119 Vector3* steering = new Vector3(0,0,0); //steeringvector 103 120 int numberOfNeighbour = 0; //number of observed neighbours 121 float distance = 0; 104 122 //go through all elements 105 for(int i=0; i< 3; i++) { //just working with 3 elements at the moment123 for(int i=0; i<9; i++) { //just working with 3 elements at the moment 106 124 Element actual = arrayOfElements[i]; //get the actual element 107 125 float distance = getDistance(actual); //get distance between this and actual 108 126 //DUMMY ALIGNMENT DETECTION DISTANCE = 1000 109 if ((distance > 0) && (distance <1000)) { //check if actual element is inside detectionradius127 if ((distance > 0) && (distance < 300)) { //check if actual element is inside detectionradius 110 128 *steering = *steering + actual.speed; //add up all speedvectors inside the detectionradius 111 129 numberOfNeighbour++; //counts the elements inside the detectionradius … … 121 139 Vector3* steering = new Vector3(0,0,0); //steeringvector 122 140 int numberOfNeighbour = 0; //number of observed neighbours 141 float distance = 0; 123 142 //go through all elements 124 for(int i=0; i< 3; i++) { //just working with 3 elements at the moment143 for(int i=0; i<9; i++) { //just working with 3 elements at the moment 125 144 Element actual = arrayOfElements[i]; //get the actual element 126 145 float distance = getDistance(actual); //get distance between this and actual 127 146 // DUMMY COHESION DETECTION DISTANCE = 1000 128 if ((distance > 0) && (distance <1000)) { //check if actual element is inside detectionradius147 if ((distance > 0) && (distance < 5000)) { //check if actual element is inside detectionradius 129 148 *steering = *steering + actual.location; //add up all locations of elements inside the detectionradius 130 149 numberOfNeighbour++; //counts the elements inside the detectionradius … … 133 152 if(numberOfNeighbour > 0) { 134 153 *steering = *steering / (float)numberOfNeighbour; //devide the sum steeringvector by the number of elements -> cohesion steeringvector 154 *steering = *steering - this->location; // (?) Koordinatensystem? 135 155 } 136 156 return *steering; 137 157 } 138 139 158 }; 140 159
Note: See TracChangeset
for help on using the changeset viewer.