Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9507 for code/branches


Ignore:
Timestamp:
Dec 10, 2012, 5:37:23 PM (12 years ago)
Author:
purgham
Message:

Not working together

Location:
code/branches/Racingbot/src/modules/gametypes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc

    r9490 r9507  
    2929 * -staticCheckPoint= static Point (see def over = constructor)
    3030 */
    31 
    3231
    3332/*TODO:
     
    4847
    4948    const int ADJUSTDISTANCE = 500;
    50     const int MINDISTANCE=5;
     49    const int MINDISTANCE = 5;
    5150    /*
    5251     * Idea: Find static Point (checkpoints the spaceship has to reach)
     
    5554        ArtificialController(creator)
    5655    {
    57         RegisterObject(SpaceRaceController);
    58         std::vector<RaceCheckPoint*> checkpoints;
     56        RegisterObject(SpaceRaceController)
     57;        std::vector<RaceCheckPoint*> checkpoints;
    5958        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
    6059        {
     
    6564        OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
    6665        checkpoints_=checkpoints;
    67         for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it){
    68             for (std::set<int>::iterator numb = ((*it)->getNextCheckpoints()).begin(); numb!=((*it)->getNextCheckpoints()).end(); ++numb)
    69                 placeVirtualCheckpoints((*it), findCheckpoint((*numb)));
     66        for( std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it!=checkpoints.end(); ++it)
     67        {
     68            std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints());
     69            if(!nextCheckPoints.empty()) {
     70                orxout() << "yay" << endl;
     71                for (std::set<int>::iterator numb = nextCheckPoints.begin(); numb!=nextCheckPoints.end(); numb++) {
     72                    RaceCheckPoint* point2 = findCheckpoint((*numb));
     73
     74                    if(point2 != NULL)
     75                        placeVirtualCheckpoints((*it), point2);
     76                }
     77            }
    7078        }
    7179        staticRacePoints_ = findStaticCheckpoints(checkpoints);
     
    8189         }*/
    8290
    83         virtualCheckPointIndex=-1;
    84     }
    85 
     91        virtualCheckPointIndex=-2;
     92    }
    8693
    8794    //------------------------------
     
    130137    int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::map<RaceCheckPoint*, int>* zaehler)
    131138    {
     139
    132140        if (currentCheckpoint->isLast())
    133141        {// last point reached
     142            orxout() << "last one" << endl;
    134143            (*zaehler)[currentCheckpoint] += 1;
    135144            return 1; // 1 Way form the last point to this one
     
    140149            for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)
    141150            {
     151                if(currentCheckpoint==findCheckpoint(*it)){
     152                    orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
     153                    continue;
     154                }
     155                for (std::set<int>::iterator a = currentCheckpoint->getNextCheckpoints().begin(); a!= currentCheckpoint->getNextCheckpoints().end(); ++a){
     156                    orxout() << "Nextcheckpoints: "<<(*a) << endl;
     157                }
     158                orxout() << "currentCheck; " << currentCheckpoint->getCheckpointIndex() << "findCheck; " << findCheckpoint(*it)->getCheckpointIndex() << endl;
    142159                numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
    143160            }
     
    146163        }
    147164    }
    148 
    149 
    150165
    151166    //-------------------------------------
     
    167182    RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
    168183    {
    169         int distances[] = {   -1, -1, -1};
     184        int distances[] =
     185        {   -1, -1, -1};
    170186        int temp_i = 0;
    171187        for (std::set<int>::iterator it =raceCheckpoint->getNextCheckpoints().begin(); it!= raceCheckpoint->getNextCheckpoints().end(); ++it)
     
    246262
    247263    RaceCheckPoint* SpaceRaceController::findCheckpoint(int index) const
    248        {
    249            for (size_t i = 0; i < this->checkpoints_.size(); ++i)
    250            if (this->checkpoints_[i]->getCheckpointIndex() == index)
    251            return this->checkpoints_[i];
    252            return NULL;
    253        }
    254 
    255     RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition ){
    256 
    257         RaceCheckPoint* newTempRaceCheckPoint = new RaceCheckPoint(this);
     264    {
     265        for (size_t i = 0; i < this->checkpoints_.size(); ++i)
     266        if (this->checkpoints_[i]->getCheckpointIndex() == index)
     267        return this->checkpoints_[i];
     268        return NULL;
     269    }
     270
     271    RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition )
     272    {
     273        RaceCheckPoint* newTempRaceCheckPoint;
     274        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it){
     275            newTempRaceCheckPoint = new RaceCheckPoint((*it));
     276        }
    258277        newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
    259278        newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
     
    264283        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
    265284        int positionInNextCheckPoint;
    266         for (int i = 0; i <3 ; i++){
     285        for (int i = 0; i <3; i++)
     286        {
    267287            if(previousCheckpoint->getNextCheckpointsAsVector3()[i]==indexFollowingCheckPoint)
    268                 positionInNextCheckPoint=i;
    269         }
    270         switch(positionInNextCheckPoint){
     288            positionInNextCheckPoint=i;
     289        }
     290        switch(positionInNextCheckPoint)
     291        {
    271292            case 0: temp.x=virtualCheckPointIndex; break;
    272293            case 1: temp.y=virtualCheckPointIndex; break;
     
    275296        previousCheckpoint->setNextCheckpointsAsVector3(temp);
    276297        virtualCheckPointIndex--;
     298        OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
    277299        return newTempRaceCheckPoint;
    278300    }
    279301
    280 
    281 
    282302    SpaceRaceController::~SpaceRaceController()
    283303    {
    284         for (int i =-1; i>virtualCheckPointIndex ; i--){
     304        for (int i =-1; i>virtualCheckPointIndex; i--)
     305        {
    285306            delete findCheckpoint(i);
    286307        }
     
    292313        {   orxout()<<this->getControllableEntity()<< " in tick"<<endl; return;}
    293314        //FOR virtual Checkpoints
    294         if(nextRaceCheckpoint_->getCheckpointIndex() < 0){
    295             if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 30){
     315        if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
     316        {
     317            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 30)
     318            {
    296319                currentRaceCheckpoint_=nextRaceCheckpoint_;
    297320                nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
     
    313336        }
    314337        //TODO: korrigieren!
    315         else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE  ){
     338
     339        else if((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt< MINDISTANCE )
     340        {
    316341            this->moveToPosition(Vector3(rnd()*100,rnd()*100,rnd()*100));
    317342            this->spin();
     
    325350
    326351    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
    327     bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse){
     352    bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse)
     353    {
    328354        if(abs(pointToPoint.x)<groesse.x)
    329             return true;
     355        return true;
    330356        if(abs(pointToPoint.y)<groesse.y)
    331                     return true;
     357        return true;
    332358        if(abs(pointToPoint.z)<groesse.z)
    333                     return true;
    334 
    335     }
    336 
    337     void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2){
     359        return true;
     360
     361    }
     362
     363    bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2,std::vector<StaticEntity*> allObjects){
     364
     365        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
     366        Vector3 centerCP1=racepoint1->getPosition();
     367        btVector3 positionObject;
     368        btScalar radiusObject;
     369
     370        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it!=allObjects.end(); ++it){
     371            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){
     372                btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
     373                if(currentShape == NULL)
     374                    continue;
     375
     376                currentShape->getBoundingSphere(positionObject,radiusObject);
     377                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
     378                if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0){
     379                    return false;
     380                }
     381
     382            }
     383        }
     384        return true;
     385
     386    }
     387
     388    void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2,std::vector<StaticEntity*> allObjects){
     389                Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
     390                Vector3 centerCP1=racepoint1->getPosition();
     391                btVector3 positionObject;
     392                btScalar radiusObject;
     393
     394                for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it!=allObjects.end(); ++it){
     395                    for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){
     396                        btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
     397                        if(currentShape == NULL)
     398                            continue;
     399
     400                        currentShape->getBoundingSphere(positionObject,radiusObject);
     401                        Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
     402                        if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0){
     403                            Vector3 zufall;
     404                            Vector3 objectmiddle=positionObjectNonBT;
     405                            do{
     406                                      zufall=Vector3(rnd(),rnd(),rnd());//random
     407                            }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0);
     408
     409
     410                            Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition());
     411                            // a'/b'=a/b => a' =b'*a/b
     412                            float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radiusObject*radiusObject)*radiusObject;
     413                            RaceCheckPoint* newVirtualCheckpoint=addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec);
     414                            //placeVirtualCheckpoints(newVirtualCheckpoint, racepoint2);
     415                            return;
     416                        }
     417
     418                    }
     419                }
     420
     421    }
     422
     423
     424
     425    void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2)
     426    {
    338427        Vector3 point1 = racepoint1->getPosition();
    339428        Vector3 point2 = racepoint2->getPosition();
     
    341430
    342431        for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it)
    343                         {
    344 
    345                             if (dynamic_cast<RaceCheckPoint*>(*it)!=NULL){continue;} // does not work jet
    346 
    347                             problematicObjects.insert(problematicObjects.end(), *it);
    348                             //it->getScale3D();// vector fuer halbe wuerfellaenge
    349                         }
    350         Vector3 richtungen [6];
    351         richtungen[0]= Vector3(1,0,0);
    352         richtungen[1]= Vector3(-1,0,0);
    353         richtungen[2]= Vector3(0,1,0);
    354         richtungen[3]= Vector3(0,-1,0);
    355         richtungen[4]= Vector3(0,0,1);
    356         richtungen[5]= Vector3(0,0,-1);
    357 
    358         for (int i = 0; i< 6; i++){
    359             const int STEPS=100;
    360             const float PHI=1.1;
    361             bool collision=false;
    362 
    363             for (int j =0; j<STEPS; j++){
    364                 Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*(float)j/STEPS);
    365                 for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it){
    366                     btVector3 positionObject;
    367                     btScalar radiusObject;
    368                     //TODO: Probably it points on a wrong object
    369                     for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){
    370                         (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
    371                         Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
    372                         if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))){
    373                             collision=true; break;
    374                         }
    375                     }
    376                     if(collision) break;
    377                 }
    378                 if(collision)break;
    379             }
    380             if(collision) continue;
    381             // no collision => possible Way
    382             for (float j =0; j<STEPS; j++){
    383                 Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
    384                 collision=false;
    385                 for(int ij=0; ij<STEPS; j++){
    386                     Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*(float)ij/STEPS);
    387                             for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it){
    388                                 btVector3 positionObject;
    389                                 btScalar radiusObject;
    390                                 for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){
    391                                     (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
    392                                     Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
    393                                     if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))){
    394                                         collision=true; break;
    395                                     }
    396                                 }
    397                             if(collision) break;
    398                             }
    399                     if(collision)break;
    400                     addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition);
    401                     return;
    402                 }
    403 
    404             }
    405         }
    406 
     432        {
     433
     434            if (dynamic_cast<RaceCheckPoint*>(*it)!=NULL)
     435            {   continue;} // does not work jet
     436
     437            problematicObjects.insert(problematicObjects.end(), *it);
     438            //it->getScale3D();// vector fuer halbe wuerfellaenge
     439        }
     440
     441        if(!directLinePossible(racepoint1, racepoint2, problematicObjects)) {
     442            computeVirtualCheckpoint(racepoint1, racepoint2, problematicObjects);
     443        }
     444
     445
     446//
     447//        do{
     448//            zufall=Vector3(rnd(),rnd(),rnd());//random
     449//        }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0);
     450//
     451//        Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition());
     452//        // a'/b'=a/b => a' =b'*a/b
     453//        float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radius*radius)*radius;
     454//        addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec);
     455
     456//        Vector3 richtungen [6];
     457//        richtungen[0]= Vector3(1,0,0);
     458//        richtungen[1]= Vector3(-1,0,0);
     459//        richtungen[2]= Vector3(0,1,0);
     460//        richtungen[3]= Vector3(0,-1,0);
     461//        richtungen[4]= Vector3(0,0,1);
     462//        richtungen[5]= Vector3(0,0,-1);
     463//
     464//        for (int i = 0; i< 6; i++)
     465//        {
     466//            const int STEPS=100;
     467//            const float PHI=1.1;
     468//            bool collision=false;
     469//
     470//            for (int j =0; j<STEPS; j++)
     471//            {
     472//                Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*(float)j/STEPS);
     473//                for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
     474//                {
     475//                    btVector3 positionObject;
     476//                    btScalar radiusObject;
     477//                    if((*it)==NULL)
     478//                    {   orxout()<<"Problempoint 1.1"<<endl; continue;}
     479//                    //TODO: Probably it points on a wrong object
     480//                    for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++)
     481//                    {
     482//                        if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==NULL)
     483//                        {    continue;}
     484//
     485//                        orxout()<<"Problempoint 2.1"<<endl;
     486//                        (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
     487//                        Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
     488//                        if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
     489//                        {
     490//                            collision=true; break;
     491//                        }
     492//                    }
     493//                    if(collision) break;
     494//                }
     495//                if(collision)break;
     496//            }
     497//            if(collision) continue;
     498//            // no collision => possible Way
     499//            for (float j =0; j<STEPS; j++)
     500//            {
     501//                Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
     502//                collision=false;
     503//                for(int ij=0; ij<STEPS; j++)
     504//                {
     505//                    Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*(float)ij/STEPS);
     506//                    for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
     507//                    {
     508//                        btVector3 positionObject;
     509//                        btScalar radiusObject;
     510//                        if((*it)==NULL)
     511//                        {   orxout()<<"Problempoint 1"<<endl; continue;}
     512//                        for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++)
     513//                        {
     514//                            if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==NULL)
     515//                            {   orxout()<<"Problempoint 2.2"<<endl; continue;}
     516//                            (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
     517//                            Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
     518//                            if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
     519//                            {
     520//                                collision=true; break;
     521//                            }
     522//                        }
     523//                        if(collision) break;
     524//                    }
     525//                    if(collision)break;
     526//                    //addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition);
     527//                    return;
     528//                }
     529//
     530//            }
     531//        }
    407532
    408533    }
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h

    r9487 r9507  
    5050            RaceCheckPoint* nextPointFind(RaceCheckPoint*);
    5151            RaceCheckPoint* adjustNextPoint();
    52             std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<RaceCheckPoint*>);
     52            std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<
     53                    RaceCheckPoint*>);
    5354            std::vector<RaceCheckPoint*> staticCheckpoints();
    54             int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>*);
     55            int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<
     56                    RaceCheckPoint*, int>*);
    5557            // same as SpaceRaceManager, but needed to add virtuell Checkpoints ( Checkpoints which don't exist but needed to avoid collisions with big Objects)
    5658            RaceCheckPoint* findCheckpoint(int index) const;
    57             RaceCheckPoint* addVirtualCheckPoint(RaceCheckPoint*, int , Vector3);
    58             void placeVirtualCheckpoints(RaceCheckPoint*,RaceCheckPoint*);
     59            RaceCheckPoint
     60                    * addVirtualCheckPoint(RaceCheckPoint*, int , Vector3);
     61            void placeVirtualCheckpoints(RaceCheckPoint*, RaceCheckPoint*);
    5962            bool vergleicheQuader(Vector3, Vector3);
     63            bool directLinePossible(RaceCheckPoint*, RaceCheckPoint*, std::vector<StaticEntity*>);
     64            void computeVirtualCheckpoint(RaceCheckPoint*, RaceCheckPoint*, std::vector<StaticEntity*>);
    6065
    6166        public:
Note: See TracChangeset for help on using the changeset viewer.