Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9487 for code


Ignore:
Timestamp:
Dec 3, 2012, 4:46:40 PM (12 years ago)
Author:
purgham
Message:

2.12.2012 - Still some Problems with the additional Checkpoints

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

Legend:

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

    r9470 r9487  
    4040#include "core/XMLPort.h"
    4141#include "gametypes/SpaceRaceManager.h"
     42#include "collisionshapes/CollisionShape.h"
     43#include "BulletCollision/CollisionShapes/btCollisionShape.h"
    4244
    4345namespace orxonox
     
    5355        ArtificialController(creator)
    5456    {
    55         RegisterObject(SpaceRaceController)
    56 ;        std::vector<RaceCheckPoint*> checkpoints;
     57        RegisterObject(SpaceRaceController);
     58        std::vector<RaceCheckPoint*> checkpoints;
    5759        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
    5860        {
     
    6365        OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
    6466        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)));
     70        }
    6571        staticRacePoints_ = findStaticCheckpoints(checkpoints);
    6672        // initialisation of currentRaceCheckpoint_
     
    247253       }
    248254
    249     bool SpaceRaceController::addVirtualCheckPoint(int positionInNextCheckPoint, RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition ){
     255    RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , Vector3 virtualCheckPointPosition ){
    250256
    251257        RaceCheckPoint* newTempRaceCheckPoint = new RaceCheckPoint(this);
     
    257263        Vector3 temp = previousCheckpoint->getNextCheckpointsAsVector3();
    258264        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
     265        int positionInNextCheckPoint;
     266        for (int i = 0; i <3 ; i++){
     267            if(previousCheckpoint->getNextCheckpointsAsVector3()[i]==indexFollowingCheckPoint)
     268                positionInNextCheckPoint=i;
     269        }
    259270        switch(positionInNextCheckPoint){
    260271            case 0: temp.x=virtualCheckPointIndex; break;
     
    262273            case 2: temp.z=virtualCheckPointIndex; break;
    263274        }
     275        previousCheckpoint->setNextCheckpointsAsVector3(temp);
    264276        virtualCheckPointIndex--;
     277        return newTempRaceCheckPoint;
    265278    }
    266279
     
    309322        lastPositionSpaceship=this->getControllableEntity()->getPosition();
    310323        this->moveToPosition(nextRaceCheckpoint_->getPosition());
    311 
    312 
    313         ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin();
    314         /*if ( it->isA(RaceCheckPoint)){
    315             orxout(user_status) << "works" << std::endl;
    316         }
    317         /*
    318             for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it)
    319                 {
    320                     if ((*it).isA(RaceCheckPoint))
    321                     btVector3 temppos;
    322                     it->
    323                     btScalar temppos;
    324                     btCollisionShape* temp= it->getCollisionShape(temppos, temppos);
    325                     it->get
    326 
    327                  }
    328 */
    329     }
    330 
    331     int SpaceRaceController::pointToPointDistance(Vector3 point1, Vector3 point2){
     324    }
     325
     326    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
     327    bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse){
     328        if(abs(pointToPoint.x)<groesse.x)
     329            return true;
     330        if(abs(pointToPoint.y)<groesse.y)
     331                    return true;
     332        if(abs(pointToPoint.z)<groesse.z)
     333                    return true;
     334
     335    }
     336
     337    void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2){
     338        Vector3 point1 = racepoint1->getPosition();
     339        Vector3 point2 = racepoint2->getPosition();
     340        std::vector<StaticEntity*> problematicObjects;
     341
    332342        for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it)
    333343                        {
    334                             if ((*it).isA(RaceCheckPoint)){break;} // does not work jet
    335 
    336                             for (int i=0; it->getAttachedCollisionShape(i)!=0; i++){
    337                                 btVector3 temppos;
    338                                 btScalar tempradius;
    339                                 it->getAttachedCollisionShape(i)->getCollisionShape()->getCollisionShape(temppos,tempradius);
    340                                 //http://bulletphysics.com/Bullet/BulletFull/btCollisionShape_8cpp_source.html#l00032
    341                                 //ueber shape moegliche Hindernisse bestimmen
     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 (float j =0; j<STEPS; j++){
     364                Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
     365                for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it){
     366                    btVector3 positionObject;
     367                    btScalar radiusObject;
     368                    for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){
     369                        (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
     370                        Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
     371                        if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))){
     372                            collision=true; break;
     373                        }
     374                    }
     375                    if(collision) break;
     376                }
     377                if(collision)break;
     378            }
     379            if(collision) continue;
     380            // no collision => possible Way
     381            for (float j =0; j<STEPS; j++){
     382                Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
     383                collision=false;
     384                for(float ij=0; ij<STEPS; j++){
     385                    Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*ij/STEPS);
     386                            for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it){
     387                                btVector3 positionObject;
     388                                btScalar radiusObject;
     389                                for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++){
     390                                    (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
     391                                    Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
     392                                    if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D()))){
     393                                        collision=true; break;
     394                                    }
     395                                }
     396                            if(collision) break;
    342397                            }
    343                             it->getAttachedCollisionShape(i);
    344 
    345 
    346                          }
    347         const int DeltaStrecke = 5;
    348         for( int i=0; i*DeltaStrecke-5 < (point1-point2).length(); i++){
    349             return 0;
    350         }
     398                    if(collision)break;
     399                    addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition);
     400                    return;
     401                }
     402
     403            }
     404        }
     405
     406
    351407    }
    352408}
  • code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.h

    r9470 r9487  
    3333#include "gametypes/RaceCheckPoint.h"
    3434
    35 
    3635namespace orxonox
    3736{
    38     class _GametypesExport SpaceRaceController : public ArtificialController, public Tickable
     37    class _GametypesExport SpaceRaceController: public ArtificialController,
     38            public Tickable
    3939    {
    4040        private:
    4141            std::vector<RaceCheckPoint*> staticRacePoints_;
    42             RaceCheckPoint* nextRaceCheckpoint_;    // checkpoint that should be reached
     42            RaceCheckPoint* nextRaceCheckpoint_; // checkpoint that should be reached
    4343            RaceCheckPoint* currentRaceCheckpoint_; // last checkPoint (already reached)
    4444            std::vector<RaceCheckPoint*> checkpoints_;
     
    5252            std::vector<RaceCheckPoint*> findStaticCheckpoints(std::vector<RaceCheckPoint*>);
    5353            std::vector<RaceCheckPoint*> staticCheckpoints();
    54             int rekSimulationCheckpointsReached(RaceCheckPoint* , std::map< RaceCheckPoint*, int>*);
     54            int rekSimulationCheckpointsReached(RaceCheckPoint*, std::map<RaceCheckPoint*, int>*);
    5555            // same as SpaceRaceManager, but needed to add virtuell Checkpoints ( Checkpoints which don't exist but needed to avoid collisions with big Objects)
    5656            RaceCheckPoint* findCheckpoint(int index) const;
    57             bool addVirtualCheckPoint(int , RaceCheckPoint* , int , Vector3 );
    58             int pointToPointDistance(Vector3, Vector3);
     57            RaceCheckPoint* addVirtualCheckPoint(RaceCheckPoint*, int , Vector3);
     58            void placeVirtualCheckpoints(RaceCheckPoint*,RaceCheckPoint*);
     59            bool vergleicheQuader(Vector3, Vector3);
    5960
    6061        public:
    61           SpaceRaceController(BaseObject* creator);
    62           virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    63           virtual ~SpaceRaceController();
    64           virtual void tick(float dt);
     62            SpaceRaceController(BaseObject* creator);
     63            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     64            virtual ~SpaceRaceController();
     65            virtual void tick(float dt);
    6566    };
    6667
    6768}
    6869
    69 
    7070#endif /* SPACERACECONTROLLER_H_ */
Note: See TracChangeset for help on using the changeset viewer.