Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/RacingBots_FS18/src/modules/gametypes/SpaceRaceController.cc @ 11977

Last change on this file since 11977 was 11977, checked in by arismu, 6 years ago

updated endthe
Game

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