Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/cpp11_v2/src/modules/gametypes/SpaceRaceController.cc @ 10821

Last change on this file since 10821 was 10821, checked in by muemart, 8 years ago

Run clang-modernize -loop-convert

  • Again, not all possible loops were converted
  • It can do pretty cool transformations, but I had to fix a few compile errors, so there might be some runtime errors lurking around too
  • Property svn:eol-style set to native
File size: 26.9 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, 2012
23 *      Author: purgham
24 */
25
26/**
27 * Conventions:
28 * -first Checkpoint has index 0
29 * -staticCheckPoint= static Point (see def over = constructor)
30 */
31
32/*TODO:
33 * tICK KORRIGIEREN
34 *
35 *
36 */
37#include <gametypes/SpaceRaceController.h>
38#include "core/CoreIncludes.h"
39#include "core/XMLPort.h"
40#include "gametypes/SpaceRaceManager.h"
41#include "collisionshapes/CollisionShape.h"
42#include "BulletCollision/CollisionShapes/btCollisionShape.h"
43
44
45namespace orxonox
46{
47    RegisterClass(SpaceRaceController);
48
49    const int ADJUSTDISTANCE = 500;
50    const int MINDISTANCE = 5;
51    /*
52     * Idea: Find static Point (checkpoints the spaceship has to reach)
53     */
54    SpaceRaceController::SpaceRaceController(Context* context) :
55        ArtificialController(context)
56    {
57        RegisterObject(SpaceRaceController);
58        std::vector<RaceCheckPoint*> checkpoints;
59
60        virtualCheckPointIndex = -2;
61        if (ObjectList<SpaceRaceManager>::size() != 1)
62            orxout(internal_warning) << "Expected 1 instance of SpaceRaceManager but found " << ObjectList<SpaceRaceManager>::size() << endl;
63        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
64        {
65            checkpoints = it->getAllCheckpoints();
66            nextRaceCheckpoint_ = it->findCheckpoint(0);
67        }
68
69        OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
70        checkpoints_ = checkpoints;
71        /*orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;
72        for(std::vector<RaceCheckPoint*>::iterator it=checkpoints_.begin(); it!=checkpoints_.end(); it++)
73        {
74            orxout()<<"Checkpoint "<<(*it)->getCheckpointIndex()<<"; NExtReal: ";
75            std::set<int> temp =(*it)->getNextCheckpoints();
76            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
77            {
78                orxout()<<(*ii)<<", ";
79            }
80
81            orxout()<<" NextVirtual: ";
82            temp=(*it)->getVirtualNextCheckpoints();
83            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
84            {
85                orxout()<<(*ii)<<", ";
86            }
87            orxout()<<endl<<endl;
88
89        }//ausgabe*/
90        /*
91        for (std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it != checkpoints.end(); ++it)
92        {
93            std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints());
94            if(!nextCheckPoints.empty())
95            {
96                for (std::set<int>::iterator numb = nextCheckPoints.begin(); numb!=nextCheckPoints.end(); numb++)
97                {
98                    RaceCheckPoint* point2 = findCheckpoint((*numb));
99
100                    //if(point2 != nullptr)
101                    //placeVirtualCheckpoints((*it), point2);
102                }
103            }
104        }
105        */
106        /*
107        for(std::vector<RaceCheckPoint*>::iterator it=checkpoints_.begin(); it!=checkpoints_.end(); it++)
108        {
109            orxout()<<"Checkpoint "<<(*it)->getCheckpointIndex()<<"; NExtReal: ";
110            std::set<int> temp =(*it)->getNextCheckpoints();
111            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
112            {
113                orxout()<<(*ii)<<", ";
114            }
115
116            orxout()<<" NextVirtual: ";
117            temp=(*it)->getVirtualNextCheckpoints();
118            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
119            {
120                orxout()<<(*ii)<<", ";
121            }
122            orxout()<<endl;
123
124        }//ausgabe
125        orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;*/
126        staticRacePoints_ = findStaticCheckpoints(nextRaceCheckpoint_, checkpoints);
127        // initialisation of currentRaceCheckpoint_
128        currentRaceCheckpoint_ = nullptr;
129
130        int i;
131        for (i = -2; findCheckpoint(i) != nullptr; i--)
132        {
133            continue;
134        }
135        //orxout()<<"Die ANzahl der virtuellen CP betraegt: "<< (-i)-2<<endl;
136
137    }
138
139    //------------------------------
140    // functions for initialisation
141
142    void SpaceRaceController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
143    {
144        SUPER(SpaceRaceController, XMLPort, xmlelement, mode);
145        XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
146        XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode);
147    }
148
149    /*
150     * called from constructor 'SpaceRaceController'
151     * returns a vector of static Point (checkpoints the spaceship has to reach)
152     */
153    std::vector<RaceCheckPoint*> SpaceRaceController::findStaticCheckpoints(RaceCheckPoint* currentCheckpoint, const std::vector<RaceCheckPoint*>& allCheckpoints)
154    {
155        std::map<RaceCheckPoint*, int> zaehler; // counts how many times the checkpoint was reached (for simulation)
156        for (auto & allCheckpoint : allCheckpoints)
157        {
158            zaehler.insert(std::pair<RaceCheckPoint*, int>(allCheckpoint,0));
159        }
160        int maxWays = rekSimulationCheckpointsReached(currentCheckpoint, zaehler);
161
162        std::vector<RaceCheckPoint*> returnVec;
163        for (auto & elem : zaehler)
164        {
165            if (elem.second == maxWays)
166            {
167                returnVec.push_back(elem.first);
168            }
169        }
170        return returnVec;
171    }
172
173    /*
174     * called from 'findStaticCheckpoints'
175     * return how many ways go from the given Checkpoint to the last Checkpoint (of the Game)
176     */
177    int SpaceRaceController::rekSimulationCheckpointsReached(RaceCheckPoint* currentCheckpoint, std::map<RaceCheckPoint*, int>& zaehler)
178    {
179
180        if (currentCheckpoint->isLast())
181        {// last point reached
182
183            zaehler[currentCheckpoint] += 1;
184            return 1; // 1 Way form the last point to this one
185        }
186        else
187        {
188            int numberOfWays = 0; // counts number of ways from this Point to the last point
189            for (std::set<int>::iterator it = currentCheckpoint->getNextCheckpoints().begin(); it!= currentCheckpoint->getNextCheckpoints().end(); ++it)
190            {
191                if (currentCheckpoint == findCheckpoint(*it))
192                {
193                    //orxout() << currentCheckpoint->getCheckpointIndex()<<endl;
194                    continue;
195                }
196                if (findCheckpoint(*it) == nullptr)
197                    orxout(internal_warning) << "Problematic Point: " << (*it) << endl;
198                else
199                    numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
200            }
201            zaehler[currentCheckpoint] += numberOfWays;
202            return numberOfWays; // returns the number of ways from this point to the last one
203        }
204    }
205
206    //-------------------------------------
207    // functions for dynamic Way-search
208
209    float SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint)
210    {
211        if (this->getControllableEntity() != nullptr)
212        {
213            return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length();
214        }
215        return -1;
216    }
217
218    /*
219     * called by: 'tick' or  'adjustNextPoint'
220     * returns the next Checkpoint which the shortest way contains
221     */
222    RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
223    {
224        float minDistance = 0;
225        RaceCheckPoint* minNextRaceCheckPoint = nullptr;
226
227        // find the next checkpoint with the minimal distance
228        for (auto elem : raceCheckpoint->getNextCheckpoints())
229        {
230            RaceCheckPoint* nextRaceCheckPoint = findCheckpoint(elem);
231            float distance = recCalculateDistance(nextRaceCheckPoint, this->getControllableEntity()->getPosition());
232
233            if (distance < minDistance || minNextRaceCheckPoint == nullptr)
234            {
235                minDistance = distance;
236                minNextRaceCheckPoint = nextRaceCheckPoint;
237            }
238        }
239
240        return minNextRaceCheckPoint;
241    }
242
243    /*
244     * called from 'nextPointFind'
245     * returns the distance between "currentPosition" and the next static checkpoint that can be reached from "currentCheckPoint"
246     */
247    float SpaceRaceController::recCalculateDistance(RaceCheckPoint* currentCheckPoint, const Vector3& currentPosition)
248    {
249        // find: looks if the currentCheckPoint is a staticCheckPoint (staticCheckPoint is the same as: static Point)
250        if (std::find(staticRacePoints_.begin(), staticRacePoints_.end(), currentCheckPoint) != staticRacePoints_.end())
251        {
252            return (currentCheckPoint->getPosition() - currentPosition).length();
253        }
254        else
255        {
256            float minimum = std::numeric_limits<float>::max();
257            for (std::set<int>::iterator it = currentCheckPoint->getNextCheckpoints().begin(); it != currentCheckPoint->getNextCheckpoints().end(); ++it)
258            {
259                int dist_currentCheckPoint_currentPosition = static_cast<int> ((currentPosition- currentCheckPoint->getPosition()).length());
260
261                minimum = std::min(minimum, dist_currentCheckPoint_currentPosition + recCalculateDistance(findCheckpoint(*it), currentCheckPoint->getPosition()));
262                // minimum of distanz from 'currentPosition' to the next static Checkpoint
263            }
264            return minimum;
265        }
266    }
267
268    /*called by 'tick'
269     *adjust chosen way of the Spaceship every "AdjustDistance" because spaceship could be displaced through an other one
270     */
271    RaceCheckPoint* SpaceRaceController::adjustNextPoint()
272    {
273        if (currentRaceCheckpoint_ == nullptr) // no Adjust possible
274
275        {
276            return nextRaceCheckpoint_;
277        }
278        if ((currentRaceCheckpoint_->getNextCheckpoints()).size() == 1) // no Adjust possible
279
280        {
281            return nextRaceCheckpoint_;
282        }
283
284        //Adjust possible
285
286        return nextPointFind(currentRaceCheckpoint_);
287    }
288
289    RaceCheckPoint* SpaceRaceController::findCheckpoint(int index) const
290    {
291        for (auto & elem : this->checkpoints_)
292            if (elem->getCheckpointIndex() == index)
293                return elem;
294        return nullptr;
295    }
296
297    /*RaceCheckPoint* SpaceRaceController::addVirtualCheckPoint( RaceCheckPoint* previousCheckpoint, int indexFollowingCheckPoint , const Vector3& virtualCheckPointPosition )
298    {
299        orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl;
300        RaceCheckPoint* newTempRaceCheckPoint;
301        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
302        {
303            newTempRaceCheckPoint = new RaceCheckPoint((*it));
304        }
305        newTempRaceCheckPoint->setVisible(false);
306        newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
307        newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
308        newTempRaceCheckPoint->setLast(false);
309        newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
310
311        Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3();
312        //orxout()<<"temp bei 0: ="<< temp.x<< temp.y<< temp.z<<endl;
313        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
314        int positionInNextCheckPoint;
315        for (int i = 0; i <3; i++)
316        {
317            if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint)
318            positionInNextCheckPoint=i;
319        }
320        switch(positionInNextCheckPoint)
321        {
322            case 0: temp.x=virtualCheckPointIndex; break;
323            case 1: temp.y=virtualCheckPointIndex; break;
324            case 2: temp.z=virtualCheckPointIndex; break;
325        }
326        previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint
327        virtualCheckPointIndex--;
328        //orxout()<<"temp bei 1: ="<< temp.x<< temp.y<< temp.z<<endl;
329        //orxout()<<"temp nach ausgabe: "<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().x<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().y<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().z<<endl;
330        //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
331        orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" :       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
332         temp=previousCheckpoint->getNextCheckpointsAsVector3();
333         orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<":       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
334         orxout()<<endl;
335        return newTempRaceCheckPoint;
336    }*/
337
338    SpaceRaceController::~SpaceRaceController()
339    {
340        if (this->isInitialized())
341        {
342            for (int i =-1; i>virtualCheckPointIndex; i--)
343                delete findCheckpoint(i);
344        }
345    }
346
347    void SpaceRaceController::tick(float dt)
348    {
349        if (this->getControllableEntity() == nullptr || this->getControllableEntity()->getPlayer() == nullptr )
350        {
351            //orxout()<< this->getControllableEntity() << " in tick"<<endl;
352            return;
353        }
354        //FOR virtual Checkpoints
355        if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
356        {
357            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200)
358            {
359                currentRaceCheckpoint_=nextRaceCheckpoint_;
360                nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
361                lastPositionSpaceship=this->getControllableEntity()->getPosition();
362                //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
363            }
364        }
365
366        if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
367        {//Checkpoint erreicht
368
369            currentRaceCheckpoint_ = nextRaceCheckpoint_;
370            OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
371            nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
372            lastPositionSpaceship = this->getControllableEntity()->getPosition();
373            //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
374        }
375        else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE)
376        {
377            nextRaceCheckpoint_ = adjustNextPoint();
378            lastPositionSpaceship = this->getControllableEntity()->getPosition();
379        }
380
381        // Abmessung fuer MINDISTANCE gut;
382
383        else if((lastPositionSpaceship - this->getControllableEntity()->getPosition()).length()/dt < MINDISTANCE )
384        {
385            this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100));
386            this->spin();
387            //orxout(user_status) << "Mindistance reached" << std::endl;
388            return;
389        }
390        //orxout(user_status) << "dt= " << dt << ";  distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl;
391        lastPositionSpaceship = this->getControllableEntity()->getPosition();
392        this->moveToPosition(nextRaceCheckpoint_->getPosition());
393    }
394
395    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
396    bool SpaceRaceController::vergleicheQuader(const Vector3& pointToPoint, const Vector3& groesse)
397    {
398        if(abs(pointToPoint.x) < groesse.x)
399            return true;
400        if(abs(pointToPoint.y) < groesse.y)
401            return true;
402        if(abs(pointToPoint.z) < groesse.z)
403            return true;
404        return false;
405
406    }
407
408    bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
409    {
410
411        Vector3 cP1ToCP2 = (racepoint2->getPosition() - racepoint1->getPosition()) / (racepoint2->getPosition() - racepoint1->getPosition()).length(); //unit Vector
412        Vector3 centerCP1 = racepoint1->getPosition();
413        btVector3 positionObject;
414        btScalar radiusObject;
415
416        for (const auto & allObject : allObjects)
417        {
418            for (int everyShape=0; (allObject)->getAttachedCollisionShape(everyShape) != nullptr; everyShape++)
419            {
420                btCollisionShape* currentShape = (allObject)->getAttachedCollisionShape(everyShape)->getCollisionShape();
421                if(currentShape == nullptr)
422                continue;
423
424                currentShape->getBoundingSphere(positionObject,radiusObject);
425                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
426                if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0)
427                {
428                    return false;
429                }
430
431            }
432        }
433        return true;
434
435    }
436
437    /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, const std::vector<StaticEntity*>& allObjects)
438    {
439        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
440        Vector3 centerCP1=racepoint1->getPosition();
441        btVector3 positionObject;
442        btScalar radiusObject;
443
444        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
445        {
446            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != nullptr; everyShape++)
447            {
448                btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
449                if(currentShape == nullptr)
450                continue;
451
452                currentShape->getBoundingSphere(positionObject,radiusObject);
453                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
454                Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT);
455
456                if(norm_r_CP.length() == 0){
457                    Vector3 zufall;
458                    do{
459                        zufall=Vector3(rnd(),rnd(),rnd());//random
460                    }while((zufall.crossProduct(cP1ToCP2)).length() == 0);
461                    norm_r_CP=zufall.crossProduct(cP1ToCP2);
462                }
463                Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2);
464                float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
465                float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
466                float distanz = std::max(distanzToCP1,distanzToCP2);
467                //float distanz = 0.0f; //TEMPORARY
468                Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length();
469                Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length();
470                if((newCheckpointPositionPos - centerCP1).length() + (newCheckpointPositionPos - (centerCP1+cP1ToCP2)).length() < (newCheckpointPositionNeg - centerCP1).length() + (newCheckpointPositionNeg - (centerCP1+cP1ToCP2)).length() )
471                {
472                    RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos);
473                }
474                else
475                {
476                    RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg);
477                }
478                return;
479            }
480        }
481
482    }*/
483
484    /*void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2)
485    {
486        Vector3 point1 = racepoint1->getPosition();
487        Vector3 point2 = racepoint2->getPosition();
488        std::vector<StaticEntity*> problematicObjects;
489
490        for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::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.