Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/Racingbot/src/modules/gametypes/SpaceRaceController.cc @ 9512

Last change on this file since 9512 was 9512, checked in by purgham, 11 years ago

works but its not properly coded

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