Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 12, 2007, 10:37:06 PM (17 years ago)
Author:
motth
Message:

fixed a memory leak, added documentation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/AI/src/orxonox.cc

    r468 r495  
    4444#include "loader/LevelLoader.h"
    4545#include "Flocking.h"
    46 #include "AIClass.h"
     46#include "Wander.h"
    4747
    4848// some tests to see if enet works without includsion
     
    8686
    8787Element arrayOfElements[9];
    88 
    89  // float time = 0;
     88Wander walker;
     89int counter = 0;
     90int times = 0;
     91
    9092
    9193
     
    110112      SceneManager *mgr = root_->getSceneManager("Default SceneManager");
    111113
    112       arrayOfElements[0].update(arrayOfElements, evt);
    113       arrayOfElements[1].update(arrayOfElements, evt);
    114       arrayOfElements[2].update(arrayOfElements, evt);
    115       arrayOfElements[3].update(arrayOfElements, evt);
    116       arrayOfElements[4].update(arrayOfElements, evt);
    117       arrayOfElements[5].update(arrayOfElements, evt);
    118       arrayOfElements[6].update(arrayOfElements, evt);
    119       arrayOfElements[7].update(arrayOfElements, evt);
    120       arrayOfElements[8].update(arrayOfElements, evt);
    121 
    122  /*   arrayOfElements[0].update(arrayOfElements, evt);
    123       arrayOfElements[1].update(arrayOfElements, evt);
    124       arrayOfElements[2].update(arrayOfElements, evt);
    125       arrayOfElements[3].update(arrayOfElements, evt);
    126       arrayOfElements[4].update(arrayOfElements, evt);   */
    127 
     114/*    // RUN WANDER
     115
     116      walker.update();
     117      walker.speed = walker.speed + 10*walker.acceleration*evt.timeSinceLastFrame;
     118      walker.location = walker.location + 10*walker.speed*evt.timeSinceLastFrame;
     119      walker.acceleration  = (0,0,0);
     120      mgr->getSceneNode("HeadNode10")->setPosition(walker.location);
     121
     122*/   // END RUN WANDER
     123
     124
     125
     126
     127     //  RUN FLOCKING
     128
     129      arrayOfElements[8].location = 100*Vector3(Math::Cos(Math::DegreesToRadians(counter)/10),Math::Sin(Math::DegreesToRadians(counter)/10),Math::Cos(Math::DegreesToRadians(counter+(counter-180)/2)/10));
     130
     131      arrayOfElements[0].update(arrayOfElements);
     132      arrayOfElements[1].update(arrayOfElements);
     133      arrayOfElements[2].update(arrayOfElements);
     134      arrayOfElements[3].update(arrayOfElements);
     135      arrayOfElements[4].update(arrayOfElements);
     136      arrayOfElements[5].update(arrayOfElements);
     137      arrayOfElements[6].update(arrayOfElements);
     138      arrayOfElements[7].update(arrayOfElements);
     139      arrayOfElements[8].update(arrayOfElements);
    128140
    129141      for(int i=0; i<9; i++) {
    130 
    131          arrayOfElements[i].speed = 0.995*arrayOfElements[i].speed + arrayOfElements[i].acceleration*evt.timeSinceLastFrame;
    132 
    133          arrayOfElements[i].location = arrayOfElements[i].location + arrayOfElements[i].speed*evt.timeSinceLastFrame;
    134 
    135          arrayOfElements[i].acceleration  = (0,0,0);
     142        arrayOfElements[i].speed = 0.995*arrayOfElements[i].speed + arrayOfElements[i].acceleration*evt.timeSinceLastFrame;
     143        arrayOfElements[i].location = arrayOfElements[i].location + arrayOfElements[i].speed*evt.timeSinceLastFrame;
     144        arrayOfElements[i].acceleration  = (0,0,0);
    136145      }
    137146
     
    146155      mgr->getSceneNode("HeadNode9")->setPosition(arrayOfElements[8].location);
    147156
    148 
    149       /*
    150 
    151       mgr->getSceneNode("HeadNode9")->setPosition(Vector3(200*cos(10*time),0,0));
    152       time = time + evt.timeSinceLastFrame;
    153 
    154      */
    155 
    156 
    157 
    158     //  mgr->getSceneNode("HeadNode1")->yaw((Radian)10*evt.timeSinceLastFrame);
     157      counter = counter + 1;
     158      counter = counter%7200;
     159
     160      // END RUN FLOCKING
     161
    159162    }
    160163
     
    272275      cam->lookAt(Vector3(0,0,0));
    273276      Viewport *vp = mRoot->getAutoCreatedWindow()->addViewport(cam);
    274       example();  //my stuff
     277
     278      //Invoke example to test AI
     279      example();
    275280    }
    276281
     
    321326    }
    322327
    323     //declaration of the 3 Ogreheads
    324    //muss leider global sein.....
    325     //Element* arrayOfElements[2];
    326 
    327328    void example() {
    328329    SceneManager *mgr = mRoot->getSceneManager("Default SceneManager");
    329330    mgr->setAmbientLight(ColourValue(1.0,1.0,1.0));
     331
     332/*  //TEST DATA WANDER
     333
     334    Entity* ent10 = mgr->createEntity("Head10", "ogrehead.mesh");
     335    SceneNode *node10 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode10", Vector3(0,0,0));
     336    node10->attachObject(ent10);
     337    Vector3 temp;
     338    temp = (0,0,0);
     339    walker.setValues(node10->getPosition(),temp,temp,true);
     340
     341*/  //END TEST DATA WANDER
     342
     343
     344//   TEST DATA FLOCKING
    330345
    331346    Entity* ent1 = mgr->createEntity("Head1", "ogrehead.mesh");
     
    347362    SceneNode *node7 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode7", Vector3(-150,-150,0));
    348363    SceneNode *node8 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode8", Vector3(-150,150,0));
    349     SceneNode *node9 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode9", Vector3(0,0,0)); 
    350 
    351 // follwing camera
    352 
    353  //  Camera *cam = mgr->getCamera("Camera");
    354  //  node1->attachObject(cam);
    355 
    356 
    357 
     364    SceneNode *node9 = mgr->getRootSceneNode()->createChildSceneNode("HeadNode9", Vector3(0,0,0));
    358365
    359366    node1->attachObject(ent1);
     
    376383    ElementLocationArray[7] = node8->getPosition();
    377384    ElementLocationArray[8] = node9->getPosition();
    378 /*
    379 ElementLocationArray[5] = node6->getPosition();
    380 ElementLocationArray[6] = node7->getPosition();*/
     385
    381386    ElementSpeedArray[0] = (0,0,0);
    382387    ElementSpeedArray[1] = (0,0,0);
     
    388393    ElementSpeedArray[7] = (0,0,0);
    389394    ElementSpeedArray[8] = (0,0,0);
    390 /*
    391 ElementSpeedArray[5] = (0,0,0);
    392 ElementSpeedArray[6] = (0,0,0); */
     395
    393396    ElementAccelerationArray[0] = (0,0,0);
    394397    ElementAccelerationArray[1] = (0,0,0);
     
    400403    ElementAccelerationArray[7] = (0,0,0);
    401404    ElementAccelerationArray[8] = (0,0,0);
    402 /*
    403 ElementAccelerationArray[5] = (0,0,0);
    404 ElementAccelerationArray[6] = (0,0,0); */
     405
    405406    arrayOfElements[0].setValues( ElementLocationArray[0], ElementSpeedArray[0], ElementAccelerationArray[0], true);
    406407    arrayOfElements[1].setValues( ElementLocationArray[1], ElementSpeedArray[1], ElementAccelerationArray[1], true);
     
    412413    arrayOfElements[7].setValues( ElementLocationArray[7], ElementSpeedArray[7], ElementAccelerationArray[7], true);
    413414    arrayOfElements[8].setValues( ElementLocationArray[8], ElementSpeedArray[8], ElementAccelerationArray[8], false);
    414 /*
    415 arrayOfElements[5].setValues( ElementLocationArray[5], ElementSpeedArray[5], ElementAccelerationArray[5], false);
    416 arrayOfElements[6].setValues( ElementLocationArray[6], ElementSpeedArray[6], ElementAccelerationArray[6], false);*/
    417 
    418 
    419 
    420 
    421    /* for (int i=0; i<3; i++) {
    422       Element* arrayOfElements[i] = new Element( ElementLocationArray[i], ElementSpeedArray[i], ElementAccelerationArray[i] );
    423     } */
    424    /* for (int i=0; i<3; i++) {
    425     arrayOfElements[i]->update(arrayOfElements);
    426     }  */
    427 
    428 //testing AIPilot -> function steer
    429   //  AIPilot temp;
    430   //  Vector3 foo = temp.steer(Vector3(0,0,1));
     415
     416   // END TEST DATA FLOCKING
    431417
    432418
Note: See TracChangeset for help on using the changeset viewer.