Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11967 was 11965, checked in by andera, 6 years ago

SpaceRaceController.cc updated

  • Property svn:eol-style set to native
File size: 25.8 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
110    /*
111     * called from 'findStaticCheckpoints'
112     * return how many ways go from the given Checkpoint to the last Checkpoint (of the Game)
113     */
114    int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::map<RaceCheckPoint*, int>& zaehler)
115    {
116
117        if (currentCheckpoint->isLast())
118        {// last point reached
119
120            zaehler[currentCheckpoint] += 1;
121            return 1; // 1 Way form the last point to this one
122        }
123        else
124        {
125            int numberOfWays = 0; // counts number of ways from this Point to the last point
126            for (int checkpointIndex : currentCheckpoint->getNextCheckpoints())
127            {
128                if (findCheckpoint(checkpointIndex) == nullptr){
129                    orxout(internal_warning) << "Problematic Point: " << checkpointIndex << endl;
130                }
131                if (currentCheckpoint == findCheckpoint(checkpointIndex))
132                {
133                    orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
134                    continue;
135                }
136             
137                else
138                    numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(checkpointIndex), zaehler);
139
140            }
141            zaehler[currentCheckpoint] += numberOfWays;
142            return numberOfWays; // returns the number of ways from this point to the last one
143        }
144    }
145
146    //-------------------------------------
147    // functions for dynamic Way-search
148
149    float SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint)
150    {
151        if (this->getControllableEntity() != nullptr)
152        {
153            return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length();
154        }
155        return -1;
156    }
157
158    /*
159     * called by: 'tick' or  'adjustNextPoint'
160     * returns the next Checkpoint which the shortest way contains
161     */
162    RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
163    {
164        float minDistance = 0;
165        RaceCheckPoint* minNextRaceCheckPoint = nullptr;
166
167        // find the next checkpoint with the minimal distance
168        for (int checkpointIndex : raceCheckpoint->getNextCheckpoints())
169        {
170            RaceCheckPoint* nextRaceCheckPoint = findCheckpoint(checkpointIndex);
171            float distance = recCalculateDistance(nextRaceCheckPoint, this->getControllableEntity()->getPosition());
172
173            if (distance < minDistance || minNextRaceCheckPoint == nullptr)
174            {
175                minDistance = distance;
176                minNextRaceCheckPoint = nextRaceCheckPoint;
177
178            }
179
180        }
181        if(minNextRaceCheckPoint == nullptr) orxout()<<"nullptr found @181 SpaceRaceController" << endl;
182        return minNextRaceCheckPoint;
183    }
184
185    /*
186     * called from 'nextPointFind'
187     * returns the distance between "currentPosition" and the next static checkpoint that can be reached from "currentCheckPoint"
188     */
189    float SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, const Vector3& currentPosition)
190    {
191        // find: looks if the currentCheckPoint is a staticCheckPoint (staticCheckPoint is the same as: static Point)
192        if (std::find(staticRacePoints_.begin(), staticRacePoints_.end(), currentCheckPoint) != staticRacePoints_.end())
193        {
194            return (currentCheckPoint->getPosition() - currentPosition).length();
195        }
196        else
197        {
198            float minimum = std::numeric_limits<float>::max();
199            for (int checkpointIndex : currentCheckPoint->getNextCheckpoints())
200            {
201                int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length());
202
203                minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(checkpointIndex), currentCheckPoint->getPosition()));
204                // minimum of distanz from 'currentPosition' to the next static Checkpoint
205            }
206            return minimum;
207        }
208    }
209
210    /*called by 'tick'
211     *adjust chosen way of the Spaceship every "AdjustDistance" because spaceship could be displaced through an other one
212     */
213    RaceCheckPoint* SpaceRaceController::adjustNextPoint()
214    {
215        if (currentRaceCheckpoint_ == nullptr) // no Adjust possible
216
217        {
218            if(nextRaceCheckpoint_ == nullptr) orxout()<<"nullptr found @218 SpaceRaceController" << endl;
219
220            return nextRaceCheckpoint_;
221        }
222        if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible
223
224        {
225            if(nextRaceCheckpoint_ == nullptr) orxout()<<"nullptr found @223 SpaceRaceController" << endl;
226
227            return nextRaceCheckpoint_;
228        }
229
230        //Adjust possible
231
232        return nextPointFind(currentRaceCheckpoint_);
233    }
234
235    RaceCheckPoint* SpaceRaceController::findCheckpoint(int index) const
236    {
237        for (RaceCheckPoint* checkpoint : this->checkpoints_){
238            //conclusion: index=20 is not
239            if (checkpoint->getCheckpointIndex() == index){
240                if(checkpoint == nullptr) orxout()<<"returned nullptr @line 234 SpaceRaceController"<<endl;
241                return checkpoint;
242            }
243        }
244
245        return nullptr;
246    }
247
248    /*RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , const Vector3& virtualCheckPointPosition )
249    {
250        orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl;
251        RaceCheckPoint* newTempRaceCheckPoint;
252        ObjectList<SpaceRaceManager> list;
253        for (ObjectList<SpaceRaceManager>::iterator it = list.begin(); it!= list.end(); ++it)
254        {
255            newTempRaceCheckPoint = new RaceCheckPoint((*it));
256        }
257        newTempRaceCheckPoint->setVisible(false);
258        newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
259        newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
260        newTempRaceCheckPoint->setLast(false);
261        newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
262
263        Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3();
264        //orxout()<<"temp bei 0: ="<< temp.x<< temp.y<< temp.z<<endl;
265        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
266        int positionInNextCheckPoint;
267        for (int i = 0; i <3; i++)
268        {
269            if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint)
270            positionInNextCheckPoint=i;
271        }
272        switch(positionInNextCheckPoint)
273        {
274            case 0: temp.x=virtualCheckPointIndex; break;
275            case 1: temp.y=virtualCheckPointIndex; break;
276            case 2: temp.z=virtualCheckPointIndex; break;
277        }
278        previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint
279        virtualCheckPointIndex--;
280        //orxout()<<"temp bei 1: ="<< temp.x<< temp.y<< temp.z<<endl;
281        //orxout()<<"temp nach ausgabe: "<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().x<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().y<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().z<<endl;
282        //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
283        orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" :       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
284         temp=previousCheckpoint->getNextCheckpointsAsVector3();
285         orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<":       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
286         orxout()<<endl;
287        return newTempRaceCheckPoint;
288    }*/
289
290    SpaceRaceController::~SpaceRaceController()
291    {
292        if (this->isInitialized())
293        {
294            for (int i =-1; i>virtualCheckPointIndex; i--)
295                delete findCheckpoint(i);
296        }
297    }
298
299    void SpaceRaceController::tick(float dt)
300    {
301        if (this->getControllableEntity() == nullptr || this->getControllableEntity()->getPlayer() == nullptr )
302        {
303            //orxout()<< this->getControllableEntity() << " in tick"<<endl;
304            return;
305        }
306        //FOR virtual Checkpoints
307        if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
308        {
309            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200)
310            {
311                currentRaceCheckpoint_=nextRaceCheckpoint_;
312                nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
313                lastPositionSpaceship=this->getControllableEntity()->getPosition();
314                //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
315            }
316        }
317
318        if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
319        {//Checkpoint erreicht
320
321            currentRaceCheckpoint_ = nextRaceCheckpoint_;
322            OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
323            nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
324            lastPositionSpaceship = this->getControllableEntity()->getPosition();
325            //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
326        }
327
328        else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE)
329        {
330            nextRaceCheckpoint_ = adjustNextPoint();
331            if(nextRaceCheckpoint_ == nullptr) orxout()<<"nullptr found @327 SpaceRaceController" << endl;
332
333            lastPositionSpaceship = this->getControllableEntity()->getPosition();
334        }
335
336        // Abmessung fuer MINDISTANCE gut;
337
338        else if((lastPositionSpaceship - this->getControllableEntity()->getPosition()).length()/dt < MINDISTANCE )
339        {
340            this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100));
341            this->spin();
342            //orxout(user_status) << "Mindistance reached" << std::endl;
343            return;
344        }
345        //orxout(user_status) << "dt= " << dt << ";  distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl;
346        /*lastPositionSpaceship = this->getControllableEntity()->getPosition();
347       
348        SpaceRace obj=new SpaceRace();
349        obj.setParentRace(parentRace);
350        this->parentRace=obj.parentRace;*/
351       
352        this->boostControl();
353
354        /*if(nextRaceCheckpoint_ == nullptr){
355            this->parentRace->bLost=true;
356            this->parentRace->end();
357        }*/
358        // if(nextRaceCheckpoint_ == nullptr ){
359        //    // if( nextRaceCheckpoint_->getCheckpointIndex()==19)
360        //     orxout()<<"nullptr @351 Line"<<endl;
361        // }
362
363        this->moveToPosition(nextRaceCheckpoint_->getPosition());
364
365        this->boostControl();
366    }
367
368
369    /*void SpaceRaceController::setParentRace(parentRace){
370        this->parentRace=parentRace;
371    }*/
372    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
373    bool SpaceRaceController::vergleicheQuader(const Vector3& pointToPoint, const Vector3& groesse)
374    {
375        if(std::abs(pointToPoint.x) < groesse.x)
376            return true;
377        if(std::abs(pointToPoint.y) < groesse.y)
378            return true;
379        if(std::abs(pointToPoint.z) < groesse.z)
380            return true;
381        return false;
382
383    }
384
385    bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
386    {
387
388        Vector3 cP1ToCP2 = (racepoint2->getPosition() - racepoint1->getPosition()) / (racepoint2->getPosition() - racepoint1->getPosition()).length(); //unit Vector
389        Vector3 centerCP1 = racepoint1->getPosition();
390        btVector3 positionObject;
391        btScalar radiusObject;
392
393        for (StaticEntity* object : allObjects)
394        {
395            for (int everyShape=0; object->getAttachedCollisionShape(everyShape) != nullptr; everyShape++)
396            {
397                btCollisionShape* currentShape = object->getAttachedCollisionShape(everyShape)->getCollisionShape();
398                if(currentShape == nullptr)
399                continue;
400
401                currentShape->getBoundingSphere(positionObject,radiusObject);
402                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
403                if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0)
404                {
405                    return false;
406                }
407
408            }
409        }
410        return true;
411
412    }
413
414    /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
415    {
416        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
417        Vector3 centerCP1=racepoint1->getPosition();
418        btVector3 positionObject;
419        btScalar radiusObject;
420
421        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
422        {
423            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != nullptr; everyShape++)
424            {
425                btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
426                if(currentShape == nullptr)
427                continue;
428
429                currentShape->getBoundingSphere(positionObject,radiusObject);
430                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
431                Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT);
432
433                if(norm_r_CP.length() == 0){
434                    Vector3 zufall;
435                    do{
436                        zufall=Vector3(rnd(),rnd(),rnd());//random
437                    }while((zufall.crossProduct(cP1ToCP2)).length() == 0);
438                    norm_r_CP=zufall.crossProduct(cP1ToCP2);
439                }
440                Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2);
441                float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
442                float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
443                float distanz = std::max(distanzToCP1,distanzToCP2);
444                //float distanz = 0.0f; //TEMPORARY
445                Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length();
446                Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length();
447                if((newCheckpointPositionPos - centerCP1).length() + (newCheckpointPositionPos - (centerCP1+cP1ToCP2)).length() < (newCheckpointPositionNeg - centerCP1).length() + (newCheckpointPositionNeg - (centerCP1+cP1ToCP2)).length() )
448                {
449                    RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos);
450                }
451                else
452                {
453                    RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg);
454                }
455                return;
456            }
457        }
458
459    }*/
460
461    /*void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2)
462    {
463        Vector3 point1 = racepoint1->getPosition();
464        Vector3 point2 = racepoint2->getPosition();
465        std::vector<StaticEntity*> problematicObjects;
466
467        ObjectList<StaticEntity> list;
468        for (ObjectList<StaticEntity>::iterator it = list.begin(); it!= list.end(); ++it)
469        {
470
471            if (dynamic_cast<RaceCheckPoint*>(*it) != nullptr)
472            {
473                continue;
474            } // does not work jet
475
476            problematicObjects.insert(problematicObjects.end(), *it);
477            //it->getScale3D();// vector fuer halbe wuerfellaenge
478        }
479
480        if(!directLinePossible(racepoint1, racepoint2, problematicObjects))
481        {
482            //orxout()<<"From "<<racepoint1->getCheckpointIndex()<<" to "<<racepoint2->getCheckpointIndex()<<"produces: "<< virtualCheckPointIndex<<endl;
483            computeVirtualCheckpoint(racepoint1, racepoint2, problematicObjects);
484        }
485
486        //
487        //        do{
488        //            zufall=Vector3(rnd(),rnd(),rnd());//random
489        //        }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0);
490        //
491        //        Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition());
492        //        // a'/b'=a/b => a' =b'*a/b
493        //        float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radius*radius)*radius;
494        //        addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec);
495
496        //        Vector3 richtungen [6];
497        //        richtungen[0]= Vector3(1,0,0);
498        //        richtungen[1]= Vector3(-1,0,0);
499        //        richtungen[2]= Vector3(0,1,0);
500        //        richtungen[3]= Vector3(0,-1,0);
501        //        richtungen[4]= Vector3(0,0,1);
502        //        richtungen[5]= Vector3(0,0,-1);
503        //
504        //        for (int i = 0; i< 6; i++)
505        //        {
506        //            const int STEPS=100;
507        //            const float PHI=1.1;
508        //            bool collision=false;
509        //
510        //            for (int j =0; j<STEPS; j++)
511        //            {
512        //                Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*(float)j/STEPS);
513        //                for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
514        //                {
515        //                    btVector3 positionObject;
516        //                    btScalar radiusObject;
517        //                    if((*it)==nullptr)
518        //                    {   orxout()<<"Problempoint 1.1"<<endl; continue;}
519        //                    //TODO: Probably it points on a wrong object
520        //                    for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++)
521        //                    {
522        //                        if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr)
523        //                        {    continue;}
524        //
525        //                        orxout()<<"Problempoint 2.1"<<endl;
526        //                        (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
527        //                        Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
528        //                        if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
529        //                        {
530        //                            collision=true; break;
531        //                        }
532        //                    }
533        //                    if(collision) break;
534        //                }
535        //                if(collision)break;
536        //            }
537        //            if(collision) continue;
538        //            // no collision => possible Way
539        //            for (float j =0; j<STEPS; j++)
540        //            {
541        //                Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
542        //                collision=false;
543        //                for(int ij=0; ij<STEPS; j++)
544        //                {
545        //                    Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*(float)ij/STEPS);
546        //                    for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
547        //                    {
548        //                        btVector3 positionObject;
549        //                        btScalar radiusObject;
550        //                        if((*it)==nullptr)
551        //                        {   orxout()<<"Problempoint 1"<<endl; continue;}
552        //                        for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=nullptr; everyShape++)
553        //                        {
554        //                            if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==nullptr)
555        //                            {   orxout()<<"Problempoint 2.2"<<endl; continue;}
556        //                            (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
557        //                            Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
558        //                            if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
559        //                            {
560        //                                collision=true; break;
561        //                            }
562        //                        }
563        //                        if(collision) break;
564        //                    }
565        //                    if(collision)break;
566        //                    //addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition);
567        //                    return;
568        //                }
569        //
570        //            }
571        //        }
572
573    }*/
574}
Note: See TracBrowser for help on using the repository browser.