Changeset 233 for code/branches
- Timestamp:
- Nov 21, 2007, 3:49:34 PM (17 years ago)
- Location:
- code/branches/AI/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/AI/src/Flocking.h
r212 r233 23 23 24 24 25 void element(Vector3 location_, Vector3 speed_, Vector3 acceleration_) {25 Element(Vector3 location_, Vector3 speed_, Vector3 acceleration_) { 26 26 acceleration = acceleration_; 27 27 speed = speed_; … … 36 36 37 37 //EINF[GEN DES ELEMENTS 38 void update( /*Element übergeben*/) {39 calculateAcceleration( /*Elementübergabe*/); //updates the acceleration38 void update(Element* arrayOfElements) { 39 calculateAcceleration(arrayOfElements); //updates the acceleration 40 40 calculateSpeed(); //updates the speed 41 41 calculateLocation(); //updates the location … … 43 43 44 44 //EINF[GEN DES ELEMENTS 45 void calculateAcceleration( /*Element übergeben*/) {45 void calculateAcceleration(Element* arrayOfElements) { 46 46 //calculates the accelerationvector based on the steeringvectors of 47 47 //separtion, alignment and cohesion. 48 acceleration = acceleration + separation( ) + alignment() + cohesion();48 acceleration = acceleration + separation(arrayOfElements) + 2*alignment(arrayOfElements) + 2*cohesion(arrayOfElements); 49 49 } 50 50 51 51 void calculateSpeed() { 52 52 speed = speed + acceleration; 53 //speed = speed.normalise(); 53 54 } 54 55 … … 58 59 } 59 60 60 Vector3 separation( ) {61 Vector3 separation(Element* arrayOfElements) { 61 62 Vector3 steering; //steeringvector 62 63 int numberOfNeighbour; //number of observed neighbours … … 64 65 for(int i=1; i<3; i++) { //just working with 3 elements at the moment 65 66 Element actual = arrayOfElements[i]; //get the actual element 66 float distance = Element.getDistance(actual); //get distance between this and actual67 float distance = getDistance(actual); //get distance between this and actual 67 68 //DUMMY SEPERATION DETECTION DISTANCE = 25 68 if ((distance > 0) && (distance< 25)) { //do only if actual is inside detectionradius69 if ((distance > 0) && (distance<1)) { //do only if actual is inside detectionradius 69 70 Vector3 inverseDistance = actual.location-location; //calculate the distancevector heading towards this 70 71 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) 72 73 steering = steering + inverseDistance; //add up all significant steeringvectors 73 74 numberOfNeighbour++; //counts the elements inside the detectionradius … … 80 81 } 81 82 82 Vector3 alignment( ) {83 Vector3 alignment(Element* arrayOfElements) { 83 84 Vector3 steering; //steeringvector 84 85 int numberOfNeighbour; //number of observed neighbours … … 86 87 for(int i=1; i<3; i++) { //just working with 3 elements at the moment 87 88 Element actual = arrayOfElements[i]; //get the actual element 88 float distance = Element.getDistance(actual); //get distance between this and actual89 float distance = getDistance(actual); //get distance between this and actual 89 90 //DUMMY ALIGNMENT DETECTION DISTANCE = 50 90 if ((distance > 0) && (distance< 50)) { //check if actual element is inside detectionradius91 if ((distance > 0) && (distance<1000)) { //check if actual element is inside detectionradius 91 92 steering = steering + actual.speed; //add up all speedvectors inside the detectionradius 92 93 numberOfNeighbour++; //counts the elements inside the detectionradius … … 99 100 } 100 101 101 Vector3 cohesion( ) {102 Vector3 cohesion(Element* arrayOfElements) { 102 103 Vector3 steering; //steeringvector 103 104 int numberOfNeighbour; //number of observed neighbours … … 105 106 for(int i=1; i<3; i++) { //just working with 3 elements at the moment 106 107 Element actual = arrayOfElements[i]; //get the actual element 107 float distance = Element.getDistance(actual); //get distance between this and actual108 float distance = getDistance(actual); //get distance between this and actual 108 109 // DUMMY COHESION DETECTION DISTANCE = 50 109 if ((distance > 0) && (distance< 50)) { //check if actual element is inside detectionradius110 if ((distance > 0) && (distance<1000)) { //check if actual element is inside detectionradius 110 111 steering = steering + actual.location; //add up all locations of elements inside the detectionradius 111 112 numberOfNeighbour++; //counts the elements inside the detectionradius -
code/branches/AI/src/orxonox.cc
r212 r233 82 82 Vector3 ElementAccelerationArray[2]; 83 83 84 Element* arrayOfElements[2]; 84 85 85 86 … … 103 104 void moving(const FrameEvent& evt) { 104 105 SceneManager *mgr = root_->getSceneManager("Default SceneManager"); 105 mgr->getSceneNode("HeadNode1")->yaw((Radian)10*evt.timeSinceLastFrame); 106 arrayOfElements[0]->update(*arrayOfElements); 107 mgr->getSceneNode("HeadNode1")->translate(0.000000001*evt.timeSinceLastFrame*arrayOfElements[0]->location); 108 arrayOfElements[1]->update(*arrayOfElements); 109 mgr->getSceneNode("HeadNode2")->translate(0.000000001*evt.timeSinceLastFrame*arrayOfElements[1]->location); 110 arrayOfElements[2]->update(*arrayOfElements); 111 mgr->getSceneNode("HeadNode3")->translate(0.000000001*evt.timeSinceLastFrame*arrayOfElements[2]->location); 112 //mgr->getSceneNode("HeadNode1")->yaw((Radian)10*evt.timeSinceLastFrame); 106 113 } 107 114 … … 216 223 SceneManager *mgr = mRoot->createSceneManager(ST_GENERIC, "Default SceneManager"); 217 224 Camera *cam = mgr->createCamera("Camera"); 218 cam->setPosition(Vector3(0,0, 500));225 cam->setPosition(Vector3(0,0,1000)); 219 226 cam->lookAt(Vector3(0,0,0)); 220 227 Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam); … … 269 276 270 277 //declaration of the 3 Ogreheads 278 //muss leider global sein..... 279 //Element* arrayOfElements[2]; 280 271 281 void example() { 272 282 SceneManager *mgr = mRoot->getSceneManager("Default SceneManager"); … … 275 285 Entity* ent2 = mgr->createEntity("Head2", "ogrehead.mesh"); 276 286 Entity* ent3 = mgr->createEntity("Head3", "ogrehead.mesh"); 277 SceneNode *node1 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode1", Vector3(0, 0,0));287 SceneNode *node1 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode1", Vector3(0,100,0)); 278 288 SceneNode *node2 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode2", Vector3(100,0,0)); 279 289 SceneNode *node3 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode3", Vector3(-100,0,0)); … … 281 291 node2->attachObject(ent2); 282 292 node3->attachObject(ent3); 293 //Camera* cam = mgr->getCamera("Camera"); 294 //node1->attachObject(cam); 283 295 ElementLocationArray[0] = node1->getPosition(); 284 296 ElementLocationArray[1] = node2->getPosition(); … … 290 302 ElementAccelerationArray[1] = (0,0,0); 291 303 ElementAccelerationArray[2] = (0,0,0); 292 for (int i=0; i<3; i++) { 293 Element* arrayOfElements[i] = new element( ElementLocationArray[i], ElementSpeedArray[i], ElementAccelerationArray[i] ); 294 } 304 arrayOfElements[0] = new Element( ElementLocationArray[0], ElementSpeedArray[0], ElementAccelerationArray[0] ); 305 arrayOfElements[1] = new Element( ElementLocationArray[1], ElementSpeedArray[1], ElementAccelerationArray[1] ); 306 arrayOfElements[2] = new Element( ElementLocationArray[2], ElementSpeedArray[2], ElementAccelerationArray[2] ); 307 308 309 310 311 /* for (int i=0; i<3; i++) { 312 Element* arrayOfElements[i] = new Element( ElementLocationArray[i], ElementSpeedArray[i], ElementAccelerationArray[i] ); 313 } */ 314 /* for (int i=0; i<3; i++) { 315 arrayOfElements[i]->update(arrayOfElements); 316 } */ 295 317 } 296 318 };
Note: See TracChangeset
for help on using the changeset viewer.