Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/gametypes/SpaceRaceController.cc @ 11358

Last change on this file since 11358 was 11358, checked in by patricwi, 7 years ago

space race merged

  • Property svn:eol-style set to native
File size: 24.5 KB
RevLine 
[9399]1/*
[9412]2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
[9399]4 *
[9412]5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
[11358]18 *   You should have     a copy of the GNU General Public License
[9412]19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
[9399]22 *  Created on: Oct 8, 2012
23 *      Author: purgham
24 */
[9459]25
[9399]26#include <gametypes/SpaceRaceController.h>
27#include "core/CoreIncludes.h"
28#include "core/XMLPort.h"
[9412]29#include "gametypes/SpaceRaceManager.h"
[9487]30#include "collisionshapes/CollisionShape.h"
31#include "BulletCollision/CollisionShapes/btCollisionShape.h"
[9399]32
[9523]33
[9399]34namespace orxonox
35{
[9667]36    RegisterClass(SpaceRaceController);
[9399]37
[9470]38    const int ADJUSTDISTANCE = 500;
[9507]39    const int MINDISTANCE = 5;
[9412]40    /*
41     * Idea: Find static Point (checkpoints the spaceship has to reach)
42     */
[9667]43    SpaceRaceController::SpaceRaceController(Context* context) :
44        ArtificialController(context)
[9432]45    {
[9973]46        RegisterObject(SpaceRaceController);
47        std::vector<RaceCheckPoint*> checkpoints;
[9508]48
[9523]49        virtualCheckPointIndex = -2;
[11071]50        if (ObjectList<SpaceRaceManager>().size() != 1)
51            orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>().size() << endl;
52        for (SpaceRaceManager* manager : ObjectList<SpaceRaceManager>())
[9432]53        {
[11071]54            checkpoints = manager->getAllCheckpoints();
55            nextRaceCheckpoint_ = manager->findCheckpoint(0);
[9432]56        }
[9399]57
[9432]58        OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
[9523]59        checkpoints_ = checkpoints;
[9973]60        staticRacePoints_ = findStaticCheckpoints(nextRaceCheckpoint_, checkpoints);
[9451]61        // initialisation of currentRaceCheckpoint_
[11071]62        currentRaceCheckpoint_ = nullptr;
[9459]63
[9508]64        int i;
[11071]65        for (i = -2; findCheckpoint(i) != nullptr; i--)
[9512]66        {
[9508]67            continue;
68        }
69
[9459]70    }
71
72    //------------------------------
73    // functions for initialisation
74
75    void SpaceRaceController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
76    {
77        SUPER(SpaceRaceController, XMLPort, xmlelement, mode);
78        XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
79        XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode);
80    }
81
82    /*
83     * called from constructor 'SpaceRaceController'
84     * returns a vector of static Point (checkpoints the spaceship has to reach)
85     */
[9973]86    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(RaceCheckPoint* currentCheckpoint, const std::vector<RaceCheckPoint*>& allCheckpoints)
[9459]87    {
[9967]88        std::map<RaceCheckPoint*, int> zaehler; // counts how many times the checkpoint was reached (for simulation)
[11071]89        for (RaceCheckPoint* checkpoint : allCheckpoints)
[9459]90        {
[11071]91            zaehler.insert(std::pair<RaceCheckPoint*, int>(checkpoint,0));
[9459]92        }
[9973]93        int maxWays = rekSimulationCheckpointsReached(currentCheckpoint, zaehler);
[9459]94
95        std::vector<RaceCheckPoint*> returnVec;
[11071]96        for (const auto& mapEntry : zaehler)
[9459]97        {
[11071]98            if (mapEntry.second == maxWays)
[9459]99            {
[11071]100                returnVec.push_back(mapEntry.first);
[9441]101            }
102        }
[9459]103        return returnVec;
104    }
[9399]105
[9459]106    /*
107     * called from 'findStaticCheckpoints'
108     * return how many ways go from the given Checkpoint to the last Checkpoint (of the Game)
109     */
[9967]110    int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::map<RaceCheckPoint*, int>& zaehler)
[9459]111    {
[9507]112
[9459]113        if (currentCheckpoint->isLast())
114        {// last point reached
[9508]115
[9967]116            zaehler[currentCheckpoint] += 1;
[9459]117            return 1; // 1 Way form the last point to this one
118        }
119        else
120        {
121            int numberOfWays = 0; // counts number of ways from this Point to the last point
[11071]122            for (int checkpointIndex : currentCheckpoint->getNextCheckpoints())
[9459]123            {
[11071]124                if (currentCheckpoint == findCheckpoint(checkpointIndex))
[9512]125                {
[9513]126                    //orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
[9507]127                    continue;
128                }
[11071]129                if (findCheckpoint(checkpointIndex) == nullptr)
130                    orxout(internal_warning) << "Problematic Point: " << checkpointIndex << endl;
[9973]131                else
[11071]132                    numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(checkpointIndex), zaehler);
[9459]133            }
[9967]134            zaehler[currentCheckpoint] += numberOfWays;
[9459]135            return numberOfWays; // returns the number of ways from this point to the last one
136        }
[9432]137    }
[9399]138
[9459]139    //-------------------------------------
140    // functions for dynamic Way-search
141
[9962]142    float SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint)
[9432]143    {
[11071]144        if (this->getControllableEntity() != nullptr)
[9432]145        {
146            return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length();
147        }
148        return -1;
[9412]149    }
150
[9459]151    /*
152     * called by: 'tick' or  'adjustNextPoint'
153     * returns the next Checkpoint which the shortest way contains
154     */
[9432]155    RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
156    {
[9965]157        float minDistance = 0;
[11071]158        RaceCheckPoint* minNextRaceCheckPoint = nullptr;
[9965]159
160        // find the next checkpoint with the minimal distance
[11071]161        for (int checkpointIndex : raceCheckpoint->getNextCheckpoints())
[9432]162        {
[11071]163            RaceCheckPoint* nextRaceCheckPoint = findCheckpoint(checkpointIndex);
[9965]164            float distance = recCalculateDistance(nextRaceCheckPoint, this->getControllableEntity()->getPosition());
165
[11071]166            if (distance < minDistance || minNextRaceCheckPoint == nullptr)
[9432]167            {
[9965]168                minDistance = distance;
169                minNextRaceCheckPoint = nextRaceCheckPoint;
[9432]170            }
[11358]171
[9432]172        }
[9965]173
174        return minNextRaceCheckPoint;
[9432]175    }
[9412]176
[9459]177    /*
178     * called from 'nextPointFind'
179     * returns the distance between "currentPosition" and the next static checkpoint that can be reached from "currentCheckPoint"
180     */
[9967]181    float SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, const Vector3& currentPosition)
[9432]182    {
[9459]183        // find: looks if the currentCheckPoint is a staticCheckPoint (staticCheckPoint is the same as: static Point)
184        if (std::find(staticRacePoints_.begin(), staticRacePoints_.end(), currentCheckPoint) != staticRacePoints_.end())
[9432]185        {
186            return (currentCheckPoint->getPosition() - currentPosition).length();
187        }
188        else
189        {
[9962]190            float minimum = std::numeric_limits<float>::max();
[11071]191            for (int checkpointIndex : currentCheckPoint->getNextCheckpoints())
[9459]192            {
193                int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length());
[9441]194
[11071]195                minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(checkpointIndex), currentCheckPoint->getPosition()));
[9441]196                // minimum of distanz from 'currentPosition' to the next static Checkpoint
[9459]197            }
[9432]198            return minimum;
199        }
200    }
[9412]201
[9459]202    /*called by 'tick'
203     *adjust chosen way of the Spaceship every "AdjustDistance" because spaceship could be displaced through an other one
[9432]204     */
[9459]205    RaceCheckPoint* SpaceRaceController::adjustNextPoint()
[9432]206    {
[11071]207        if (currentRaceCheckpoint_ == nullptr) // no Adjust possible
[9459]208
[9432]209        {
[9459]210            return nextRaceCheckpoint_;
[9432]211        }
[9964]212        if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible
[9399]213
[9432]214        {
[9459]215            return nextRaceCheckpoint_;
[9432]216        }
[9459]217
218        //Adjust possible
219
220        return nextPointFind(currentRaceCheckpoint_);
[9432]221    }
[9399]222
[9459]223    RaceCheckPoint* SpaceRaceController::findCheckpoint(int index) const
[9507]224    {
[11071]225        for (RaceCheckPoint* checkpoint : this->checkpoints_)
226            if (checkpoint->getCheckpointIndex() == index)
227                return checkpoint;
228        return nullptr;
[9507]229    }
[9459]230
[9967]231    /*RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , const Vector3& virtualCheckPointPosition )
[9507]232    {
[9513]233        orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl;
[9507]234        RaceCheckPoint* newTempRaceCheckPoint;
[11071]235        ObjectList<SpaceRaceManager> list;
236        for (ObjectList<SpaceRaceManager>::iterator it = list.begin(); it!= list.end(); ++it)
[9512]237        {
[9507]238            newTempRaceCheckPoint = new RaceCheckPoint((*it));
239        }
[9508]240        newTempRaceCheckPoint->setVisible(false);
[9459]241        newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
242        newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
243        newTempRaceCheckPoint->setLast(false);
[9508]244        newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
[9459]245
[9508]246        Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3();
[9513]247        //orxout()<<"temp bei 0: ="<< temp.x<< temp.y<< temp.z<<endl;
[9459]248        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
[9487]249        int positionInNextCheckPoint;
[9507]250        for (int i = 0; i <3; i++)
251        {
[9508]252            if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint)
[9512]253            positionInNextCheckPoint=i;
[9487]254        }
[9507]255        switch(positionInNextCheckPoint)
256        {
[9459]257            case 0: temp.x=virtualCheckPointIndex; break;
258            case 1: temp.y=virtualCheckPointIndex; break;
259            case 2: temp.z=virtualCheckPointIndex; break;
[9432]260        }
[9508]261        previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint
[9459]262        virtualCheckPointIndex--;
[9513]263        //orxout()<<"temp bei 1: ="<< temp.x<< temp.y<< temp.z<<endl;
264        //orxout()<<"temp nach ausgabe: "<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().x<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().y<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().z<<endl;
[9508]265        //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
[9667]266        orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" :       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
[9512]267         temp=previousCheckpoint->getNextCheckpointsAsVector3();
268         orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<":       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
[9667]269         orxout()<<endl;
[9487]270        return newTempRaceCheckPoint;
[9523]271    }*/
[9399]272
[9432]273    SpaceRaceController::~SpaceRaceController()
274    {
[10318]275        if (this->isInitialized())
[9507]276        {
[10318]277            for (int i =-1; i>virtualCheckPointIndex; i--)
278                delete findCheckpoint(i);
[9459]279        }
[9432]280    }
[9399]281
[9459]282    void SpaceRaceController::tick(float dt)
[9432]283    {
[11071]284        if (this->getControllableEntity() == nullptr || this->getControllableEntity()->getPlayer() == nullptr )
[9523]285        {
286            //orxout()<< this->getControllableEntity() << " in tick"<<endl;
287            return;
288        }
[9459]289        //FOR virtual Checkpoints
[9507]290        if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
291        {
[9508]292            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200)
[9507]293            {
[9459]294                currentRaceCheckpoint_=nextRaceCheckpoint_;
295                nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
296                lastPositionSpaceship=this->getControllableEntity()->getPosition();
[9513]297                //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
[9459]298            }
299        }
[9399]300
[9432]301        if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
302        {//Checkpoint erreicht
[9508]303
[9523]304            currentRaceCheckpoint_ = nextRaceCheckpoint_;
[9432]305            OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
306            nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
[9523]307            lastPositionSpaceship = this->getControllableEntity()->getPosition();
[9513]308            //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
[9432]309        }
[11358]310
[9470]311        else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE)
[9432]312        {
313            nextRaceCheckpoint_ = adjustNextPoint();
[9523]314            lastPositionSpaceship = this->getControllableEntity()->getPosition();
[9432]315        }
[9507]316
[9508]317        // Abmessung fuer MINDISTANCE gut;
[9512]318
[9523]319        else if((lastPositionSpaceship - this->getControllableEntity()->getPosition()).length()/dt < MINDISTANCE )
[9507]320        {
[9523]321            this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100));
[9459]322            this->spin();
[9470]323            //orxout(user_status) << "Mindistance reached" << std::endl;
324            return;
[9459]325        }
[9470]326        //orxout(user_status) << "dt= " << dt << ";  distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl;
[9523]327        lastPositionSpaceship = this->getControllableEntity()->getPosition();
[11358]328       
329this->boostControl();
[9432]330        this->moveToPosition(nextRaceCheckpoint_->getPosition());
[11358]331        this->boostControl();
[9487]332    }
[9459]333
[9487]334    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
[9967]335    bool SpaceRaceController::vergleicheQuader(const Vector3& pointToPoint, const Vector3& groesse)
[9507]336    {
[11083]337        if(std::abs(pointToPoint.x) < groesse.x)
[9523]338            return true;
[11083]339        if(std::abs(pointToPoint.y) < groesse.y)
[9523]340            return true;
[11083]341        if(std::abs(pointToPoint.z) < groesse.z)
[9523]342            return true;
343        return false;
[9459]344
[9432]345    }
[9399]346
[9967]347    bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
[9512]348    {
[9487]349
[9523]350        Vector3 cP1ToCP2 = (racepoint2->getPosition() - racepoint1->getPosition()) / (racepoint2->getPosition() - racepoint1->getPosition()).length(); //unit Vector
351        Vector3 centerCP1 = racepoint1->getPosition();
[9507]352        btVector3 positionObject;
353        btScalar radiusObject;
[9470]354
[11071]355        for (StaticEntity* object : allObjects)
[9512]356        {
[11071]357            for (int everyShape=0; object->getAttachedCollisionShape(everyShape) != nullptr; everyShape++)
[9512]358            {
[11071]359                btCollisionShape* currentShape = object->getAttachedCollisionShape(everyShape)->getCollisionShape();
360                if(currentShape == nullptr)
[9512]361                continue;
[9487]362
[9507]363                currentShape->getBoundingSphere(positionObject,radiusObject);
364                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
[9512]365                if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0)
366                {
[9507]367                    return false;
368                }
[9487]369
[9507]370            }
371        }
372        return true;
[9487]373
[9507]374    }
375
[9967]376    /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
[9512]377    {
378        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
379        Vector3 centerCP1=racepoint1->getPosition();
380        btVector3 positionObject;
381        btScalar radiusObject;
[9507]382
[9523]383        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
[9512]384        {
[11071]385            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != nullptr; everyShape++)
[9512]386            {
387                btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
[11071]388                if(currentShape == nullptr)
[9512]389                continue;
[9507]390
[9512]391                currentShape->getBoundingSphere(positionObject,radiusObject);
392                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
[9945]393                Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT);
[9523]394
[9945]395                if(norm_r_CP.length() == 0){
396                    Vector3 zufall;
[9523]397                    do{
[9512]398                        zufall=Vector3(rnd(),rnd(),rnd());//random
[9523]399                    }while((zufall.crossProduct(cP1ToCP2)).length() == 0);
[9945]400                    norm_r_CP=zufall.crossProduct(cP1ToCP2);
401                }
402                Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2);
403                float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
404                float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
[9523]405                float distanz = std::max(distanzToCP1,distanzToCP2);
[9945]406                //float distanz = 0.0f; //TEMPORARY
407                Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length();
408                Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length();
409                if((newCheckpointPositionPos - centerCP1).length() + (newCheckpointPositionPos - (centerCP1+cP1ToCP2)).length() < (newCheckpointPositionNeg - centerCP1).length() + (newCheckpointPositionNeg - (centerCP1+cP1ToCP2)).length() )
410                {
411                    RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos);
412                }
413                else
414                {
415                    RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg);
416                }
417                return;
[9512]418            }
419        }
[9507]420
[9523]421    }*/
[9507]422
[9523]423    /*void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2)
[9507]424    {
425        Vector3 point1 = racepoint1->getPosition();
426        Vector3 point2 = racepoint2->getPosition();
427        std::vector<StaticEntity*> problematicObjects;
428
[11071]429        ObjectList<StaticEntity> list;
430        for (ObjectList<StaticEntity>::iterator it = list.begin(); it!= list.end(); ++it)
[9507]431        {
432
[11071]433            if (dynamic_cast<RaceCheckPoint*>(*it) != nullptr)
[9523]434            {
435                continue;
436            } // does not work jet
[9507]437
438            problematicObjects.insert(problematicObjects.end(), *it);
439            //it->getScale3D();// vector fuer halbe wuerfellaenge
[9487]440        }
[9470]441
[9512]442        if(!directLinePossible(racepoint1, racepoint2, problematicObjects))
443        {
[9513]444            //orxout()<<"From "<<racepoint1->getCheckpointIndex()<<" to "<<racepoint2->getCheckpointIndex()<<"produces: "<< virtualCheckPointIndex<<endl;
[9507]445            computeVirtualCheckpoint(racepoint1, racepoint2, problematicObjects);
446        }
[9487]447
[9512]448        //
449        //        do{
450        //            zufall=Vector3(rnd(),rnd(),rnd());//random
451        //        }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0);
452        //
453        //        Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition());
454        //        // a'/b'=a/b => a' =b'*a/b
455        //        float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radius*radius)*radius;
456        //        addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec);
[9507]457
[9512]458        //        Vector3 richtungen [6];
459        //        richtungen[0]= Vector3(1,0,0);
460        //        richtungen[1]= Vector3(-1,0,0);
461        //        richtungen[2]= Vector3(0,1,0);
462        //        richtungen[3]= Vector3(0,-1,0);
463        //        richtungen[4]= Vector3(0,0,1);
464        //        richtungen[5]= Vector3(0,0,-1);
465        //
466        //        for (int i = 0; i< 6; i++)
467        //        {
468        //            const int STEPS=100;
469        //            const float PHI=1.1;
470        //            bool collision=false;
471        //
472        //            for (int j =0; j<STEPS; j++)
473        //            {
474        //                Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*(float)j/STEPS);
475        //                for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
476        //                {
477        //                    btVector3 positionObject;
478        //                    btScalar radiusObject;
[11071]479        //                    if((*it)==nullptr)
[9512]480        //                    {   orxout()<<"Problempoint 1.1"<<endl; continue;}
481        //                    //TODO: Probably it points on a wrong object
[11071]482        //                    for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++)
[9512]483        //                    {
[11071]484        //                        if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr)
[9512]485        //                        {    continue;}
486        //
487        //                        orxout()<<"Problempoint 2.1"<<endl;
488        //                        (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
489        //                        Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
490        //                        if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
491        //                        {
492        //                            collision=true; break;
493        //                        }
494        //                    }
495        //                    if(collision) break;
496        //                }
497        //                if(collision)break;
498        //            }
499        //            if(collision) continue;
500        //            // no collision => possible Way
501        //            for (float j =0; j<STEPS; j++)
502        //            {
503        //                Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
504        //                collision=false;
505        //                for(int ij=0; ij<STEPS; j++)
506        //                {
507        //                    Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*(float)ij/STEPS);
508        //                    for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
509        //                    {
510        //                        btVector3 positionObject;
511        //                        btScalar radiusObject;
[11071]512        //                        if((*it)==nullptr)
[9512]513        //                        {   orxout()<<"Problempoint 1"<<endl; continue;}
[11071]514        //                        for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++)
[9512]515        //                        {
[11071]516        //                            if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr)
[9512]517        //                            {   orxout()<<"Problempoint 2.2"<<endl; continue;}
518        //                            (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
519        //                            Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
520        //                            if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
521        //                            {
522        //                                collision=true; break;
523        //                            }
524        //                        }
525        //                        if(collision) break;
526        //                    }
527        //                    if(collision)break;
528        //                    //addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition);
529        //                    return;
530        //                }
531        //
532        //            }
533        //        }
[9507]534
[9523]535    }*/
[9399]536}
Note: See TracBrowser for help on using the repository browser.