Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial3/src/modules/gametypes/SpaceRaceController.cc @ 10904

Last change on this file since 10904 was 9526, checked in by jo, 12 years ago

Merging presentationHS12 back to the trunk.

File size: 27.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, 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    CreateFactory(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(BaseObject* creator) :
55        ArtificialController(creator)
56    {
57        RegisterObject(SpaceRaceController)
58;        std::vector<RaceCheckPoint*> checkpoints;
59
60        virtualCheckPointIndex = -2;
61        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it != ObjectList<SpaceRaceManager>::end(); ++it)
62        {
63            checkpoints = it->getAllCheckpoints();
64            nextRaceCheckpoint_ = it->findCheckpoint(0);
65        }
66
67        OrxAssert(!checkpoints.empty(), "No Checkpoints in Level");
68        checkpoints_ = checkpoints;
69        /*orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;
70        for(std::vector<RaceCheckPoint*>::iterator it=checkpoints_.begin(); it!=checkpoints_.end(); it++)
71        {
72            orxout()<<"Checkpoint "<<(*it)->getCheckpointIndex()<<"; NExtReal: ";
73            std::set<int> temp =(*it)->getNextCheckpoints();
74            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
75            {
76                orxout()<<(*ii)<<", ";
77            }
78
79            orxout()<<" NextVirtual: ";
80            temp=(*it)->getVirtualNextCheckpoints();
81            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
82            {
83                orxout()<<(*ii)<<", ";
84            }
85            orxout()<<endl<<endl;
86
87        }//ausgabe*/
88
89        for (std::vector<RaceCheckPoint*>::iterator it = checkpoints.begin(); it != checkpoints.end(); ++it)
90        {
91            std::set<int> nextCheckPoints = ((*it)->getNextCheckpoints());
92            if(!nextCheckPoints.empty())
93            {
94                for (std::set<int>::iterator numb = nextCheckPoints.begin(); numb!=nextCheckPoints.end(); numb++)
95                {
96                    RaceCheckPoint* point2 = findCheckpoint((*numb));
97
98                    //if(point2 != NULL)
99                    //placeVirtualCheckpoints((*it), point2);
100                }
101            }
102        }/*
103        for(std::vector<RaceCheckPoint*>::iterator it=checkpoints_.begin(); it!=checkpoints_.end(); it++)
104        {
105            orxout()<<"Checkpoint "<<(*it)->getCheckpointIndex()<<"; NExtReal: ";
106            std::set<int> temp =(*it)->getNextCheckpoints();
107            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
108            {
109                orxout()<<(*ii)<<", ";
110            }
111
112            orxout()<<" NextVirtual: ";
113            temp=(*it)->getVirtualNextCheckpoints();
114            for (std::set<int>::iterator ii =temp.begin(); ii!=temp.end(); ii++)
115            {
116                orxout()<<(*ii)<<", ";
117            }
118            orxout()<<endl;
119
120        }//ausgabe
121        orxout()<<"es gibt: "<<checkpoints_.size()<<"checkpoints"<<endl;*/
122        staticRacePoints_ = findStaticCheckpoints(checkpoints);
123        // initialisation of currentRaceCheckpoint_
124        currentRaceCheckpoint_ = NULL;
125
126        int i;
127        for (i = -2; findCheckpoint(i) != NULL; i--)
128        {
129            continue;
130        }
131        //orxout()<<"Die ANzahl der virtuellen CP betraegt: "<< (-i)-2<<endl;
132
133    }
134
135    //------------------------------
136    // functions for initialisation
137
138    void SpaceRaceController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
139    {
140        SUPER(SpaceRaceController, XMLPort, xmlelement, mode);
141        XMLPortParam(ArtificialController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
142        XMLPortObject(ArtificialController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode);
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 checkpoint 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)
196                    {orxout()<<"Problematic Point: "<<(*it)<<endl;}
197                numberOfWays += rekSimulationCheckpointsReached(findCheckpoint(*it), zaehler);
198            }
199            (*zaehler)[currentCheckpoint] += numberOfWays;
200            return numberOfWays; // returns the number of ways from this point to the last one
201        }
202    }
203
204    //-------------------------------------
205    // functions for dynamic Way-search
206
207    int SpaceRaceController::distanceSpaceshipToCheckPoint(RaceCheckPoint* CheckPoint)
208    {
209        if (this->getControllableEntity() != NULL)
210        {
211            return (CheckPoint->getPosition()- this->getControllableEntity()->getPosition()).length();
212        }
213        return -1;
214    }
215
216    /*
217     * called by: 'tick' or  'adjustNextPoint'
218     * returns the next Checkpoint which the shortest way contains
219     */
220    RaceCheckPoint* SpaceRaceController::nextPointFind(RaceCheckPoint* raceCheckpoint)
221    {
222        int distances[] = {-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        orxout()<<"add VCP at"<<virtualCheckPointPosition.x<<", "<<virtualCheckPointPosition.y<<", "<<virtualCheckPointPosition.z<<endl;
311        RaceCheckPoint* newTempRaceCheckPoint;
312        for (ObjectList<SpaceRaceManager>::iterator it = ObjectList<SpaceRaceManager>::begin(); it!= ObjectList<SpaceRaceManager>::end(); ++it)
313        {
314            newTempRaceCheckPoint = new RaceCheckPoint((*it));
315        }
316        newTempRaceCheckPoint->setVisible(false);
317        newTempRaceCheckPoint->setPosition(virtualCheckPointPosition);
318        newTempRaceCheckPoint->setCheckpointIndex(virtualCheckPointIndex);
319        newTempRaceCheckPoint->setLast(false);
320        newTempRaceCheckPoint->setNextVirtualCheckpointsAsVector3(Vector3(indexFollowingCheckPoint,-1,-1));
321
322        Vector3 temp = previousCheckpoint->getVirtualNextCheckpointsAsVector3();
323        //orxout()<<"temp bei 0: ="<< temp.x<< temp.y<< temp.z<<endl;
324        checkpoints_.insert(checkpoints_.end(), newTempRaceCheckPoint);
325        int positionInNextCheckPoint;
326        for (int i = 0; i <3; i++)
327        {
328            if(previousCheckpoint->getVirtualNextCheckpointsAsVector3()[i] == indexFollowingCheckPoint)
329            positionInNextCheckPoint=i;
330        }
331        switch(positionInNextCheckPoint)
332        {
333            case 0: temp.x=virtualCheckPointIndex; break;
334            case 1: temp.y=virtualCheckPointIndex; break;
335            case 2: temp.z=virtualCheckPointIndex; break;
336        }
337        previousCheckpoint->setNextVirtualCheckpointsAsVector3(temp); //Existiert internes Problem bei negativen index fueer next Checkpoint
338        virtualCheckPointIndex--;
339        //orxout()<<"temp bei 1: ="<< temp.x<< temp.y<< temp.z<<endl;
340        //orxout()<<"temp nach ausgabe: "<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().x<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().y<<previousCheckpoint->getVirtualNextCheckpointsAsVector3().z<<endl;
341        //OrxAssert(virtualCheckPointIndex < -1, "TO much virtual cp");
342        /*orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<", following:"<<indexFollowingCheckPoint<<" :       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
343         temp=previousCheckpoint->getNextCheckpointsAsVector3();
344         orxout()<<"id: "<< previousCheckpoint->getCheckpointIndex() <<":       "<<temp.x<<", "<<temp.y<<", "<<temp.z<<";       ";
345         orxout()<<endl;*//*
346        return newTempRaceCheckPoint;
347    }*/
348
349    SpaceRaceController::~SpaceRaceController()
350    {
351        for (int i =-1; i>virtualCheckPointIndex; i--)
352        {
353            delete findCheckpoint(i);
354        }
355    }
356
357    void SpaceRaceController::tick(float dt)
358    {
359        if (this->getControllableEntity() == NULL || this->getControllableEntity()->getPlayer() == NULL )
360        {
361            //orxout()<< this->getControllableEntity() << " in tick"<<endl;
362            return;
363        }
364        //FOR virtual Checkpoints
365        if(nextRaceCheckpoint_->getCheckpointIndex() < 0)
366        {
367            if( distanceSpaceshipToCheckPoint(nextRaceCheckpoint_) < 200)
368            {
369                currentRaceCheckpoint_=nextRaceCheckpoint_;
370                nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
371                lastPositionSpaceship=this->getControllableEntity()->getPosition();
372                //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
373            }
374        }
375
376        if (nextRaceCheckpoint_->playerWasHere(this->getControllableEntity()->getPlayer()))
377        {//Checkpoint erreicht
378
379            currentRaceCheckpoint_ = nextRaceCheckpoint_;
380            OrxAssert(nextRaceCheckpoint_, "next race checkpoint undefined");
381            nextRaceCheckpoint_ = nextPointFind(nextRaceCheckpoint_);
382            lastPositionSpaceship = this->getControllableEntity()->getPosition();
383            //orxout()<< "CP "<< currentRaceCheckpoint_->getCheckpointIndex()<<" chanched to: "<< nextRaceCheckpoint_->getCheckpointIndex()<<endl;
384        }
385        else if ((lastPositionSpaceship-this->getControllableEntity()->getPosition()).length()/dt > ADJUSTDISTANCE)
386        {
387            nextRaceCheckpoint_ = adjustNextPoint();
388            lastPositionSpaceship = this->getControllableEntity()->getPosition();
389        }
390
391        // Abmessung fuer MINDISTANCE gut;
392
393        else if((lastPositionSpaceship - this->getControllableEntity()->getPosition()).length()/dt < MINDISTANCE )
394        {
395            this->moveToPosition(Vector3(rnd()*100, rnd()*100, rnd()*100));
396            this->spin();
397            //orxout(user_status) << "Mindistance reached" << std::endl;
398            return;
399        }
400        //orxout(user_status) << "dt= " << dt << ";  distance= " << (lastPositionSpaceship-this->getControllableEntity()->getPosition()).length() <<std::endl;
401        lastPositionSpaceship = this->getControllableEntity()->getPosition();
402        this->moveToPosition(nextRaceCheckpoint_->getPosition());
403    }
404
405    // True if a coordinate of 'pointToPoint' is smaller then the corresponding coordinate of 'groesse'
406    bool SpaceRaceController::vergleicheQuader(Vector3 pointToPoint, Vector3 groesse)
407    {
408        if(abs(pointToPoint.x) < groesse.x)
409            return true;
410        if(abs(pointToPoint.y) < groesse.y)
411            return true;
412        if(abs(pointToPoint.z) < groesse.z)
413            return true;
414        return false;
415
416    }
417
418    bool SpaceRaceController::directLinePossible(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2,std::vector<StaticEntity*> allObjects)
419    {
420
421        Vector3 cP1ToCP2 = (racepoint2->getPosition() - racepoint1->getPosition()) / (racepoint2->getPosition() - racepoint1->getPosition()).length(); //unit Vector
422        Vector3 centerCP1 = racepoint1->getPosition();
423        btVector3 positionObject;
424        btScalar radiusObject;
425
426        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
427        {
428            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)
429            {
430                btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
431                if(currentShape == NULL)
432                continue;
433
434                currentShape->getBoundingSphere(positionObject,radiusObject);
435                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
436                if((powf((cP1ToCP2.dotProduct(centerCP1-positionObjectNonBT)),2)-(centerCP1-positionObjectNonBT).dotProduct(centerCP1-positionObjectNonBT)+powf(radiusObject, 2))>0)
437                {
438                    return false;
439                }
440
441            }
442        }
443        return true;
444
445    }
446
447    /*void SpaceRaceController::computeVirtualCheckpoint(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2, std::vector<StaticEntity*> allObjects)
448    {
449        Vector3 cP1ToCP2=(racepoint2->getPosition()-racepoint1->getPosition()) / (racepoint2->getPosition()-racepoint1->getPosition()).length(); //unit Vector
450        Vector3 centerCP1=racepoint1->getPosition();
451        btVector3 positionObject;
452        btScalar radiusObject;
453
454        for (std::vector<StaticEntity*>::iterator it = allObjects.begin(); it != allObjects.end(); ++it)
455        {
456            for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape) != 0; everyShape++)
457            {
458                btCollisionShape* currentShape = (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape();
459                if(currentShape == NULL)
460                continue;
461
462                currentShape->getBoundingSphere(positionObject,radiusObject);
463                Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
464                                Vector3 norm_r_CP = cP1ToCP2.crossProduct(centerCP1-positionObjectNonBT);
465
466                                if(norm_r_CP.length() == 0){
467                                        Vector3 zufall;
468                    do{
469                        zufall=Vector3(rnd(),rnd(),rnd());//random
470                    }while((zufall.crossProduct(cP1ToCP2)).length() == 0);
471                                        norm_r_CP=zufall.crossProduct(cP1ToCP2);
472                                }
473                                Vector3 VecToVCP = norm_r_CP.crossProduct(cP1ToCP2);
474                                float distanzToCP1 = sqrt(powf(radiusObject,4)/(powf((centerCP1-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
475                                float distanzToCP2 = sqrt(powf(radiusObject,4)/(powf((racepoint2->getPosition()-positionObjectNonBT).length(), 2)-powf(radiusObject,2))+powf(radiusObject,2));
476                float distanz = std::max(distanzToCP1,distanzToCP2);
477                                //float distanz = 0.0f; //TEMPORARY
478                                Vector3 newCheckpointPositionPos = positionObjectNonBT+(distanz*VecToVCP)/VecToVCP.length();
479                                Vector3 newCheckpointPositionNeg = positionObjectNonBT-(distanz*VecToVCP)/VecToVCP.length();
480                                if((newCheckpointPositionPos - centerCP1).length() + (newCheckpointPositionPos - (centerCP1+cP1ToCP2)).length() < (newCheckpointPositionNeg - centerCP1).length() + (newCheckpointPositionNeg - (centerCP1+cP1ToCP2)).length() )
481                                {
482                                        RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionPos);
483                                }
484                                else
485                                {
486                                        RaceCheckPoint* newVirtualCheckpoint = addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), newCheckpointPositionNeg);
487                                }
488                                return;
489            }
490        }
491
492    }*/
493
494    /*void SpaceRaceController::placeVirtualCheckpoints(RaceCheckPoint* racepoint1, RaceCheckPoint* racepoint2)
495    {
496        Vector3 point1 = racepoint1->getPosition();
497        Vector3 point2 = racepoint2->getPosition();
498        std::vector<StaticEntity*> problematicObjects;
499
500        for (ObjectList<StaticEntity>::iterator it = ObjectList<StaticEntity>::begin(); it!= ObjectList<StaticEntity>::end(); ++it)
501        {
502
503            if (dynamic_cast<RaceCheckPoint*>(*it) != NULL)
504            {
505                continue;
506            } // does not work jet
507
508            problematicObjects.insert(problematicObjects.end(), *it);
509            //it->getScale3D();// vector fuer halbe wuerfellaenge
510        }
511
512        if(!directLinePossible(racepoint1, racepoint2, problematicObjects))
513        {
514            //orxout()<<"From "<<racepoint1->getCheckpointIndex()<<" to "<<racepoint2->getCheckpointIndex()<<"produces: "<< virtualCheckPointIndex<<endl;
515            computeVirtualCheckpoint(racepoint1, racepoint2, problematicObjects);
516        }
517
518        //
519        //        do{
520        //            zufall=Vector3(rnd(),rnd(),rnd());//random
521        //        }while((zufall.crossProduct(objectmiddle-racepoint1->getPosition())).length()==0);
522        //
523        //        Vector3 normalvec=zufall.crossProduct(objectmiddle-racepoint1->getPosition());
524        //        // a'/b'=a/b => a' =b'*a/b
525        //        float laengeNormalvec=(objectmiddle-racepoint1->getPosition()).length()/sqrt((objectmiddle-racepoint1->getPosition()).squaredLength()-radius*radius)*radius;
526        //        addVirtualCheckPoint(racepoint1,racepoint2->getCheckpointIndex(), objectmiddle+normalvec/normalvec.length()*laengeNormalvec);
527
528        //        Vector3 richtungen [6];
529        //        richtungen[0]= Vector3(1,0,0);
530        //        richtungen[1]= Vector3(-1,0,0);
531        //        richtungen[2]= Vector3(0,1,0);
532        //        richtungen[3]= Vector3(0,-1,0);
533        //        richtungen[4]= Vector3(0,0,1);
534        //        richtungen[5]= Vector3(0,0,-1);
535        //
536        //        for (int i = 0; i< 6; i++)
537        //        {
538        //            const int STEPS=100;
539        //            const float PHI=1.1;
540        //            bool collision=false;
541        //
542        //            for (int j =0; j<STEPS; j++)
543        //            {
544        //                Vector3 tempPosition=(point1 - (point2-point1+richtungen[i]*PHI)*(float)j/STEPS);
545        //                for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
546        //                {
547        //                    btVector3 positionObject;
548        //                    btScalar radiusObject;
549        //                    if((*it)==NULL)
550        //                    {   orxout()<<"Problempoint 1.1"<<endl; continue;}
551        //                    //TODO: Probably it points on a wrong object
552        //                    for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++)
553        //                    {
554        //                        if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==NULL)
555        //                        {    continue;}
556        //
557        //                        orxout()<<"Problempoint 2.1"<<endl;
558        //                        (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
559        //                        Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
560        //                        if (((tempPosition - positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
561        //                        {
562        //                            collision=true; break;
563        //                        }
564        //                    }
565        //                    if(collision) break;
566        //                }
567        //                if(collision)break;
568        //            }
569        //            if(collision) continue;
570        //            // no collision => possible Way
571        //            for (float j =0; j<STEPS; j++)
572        //            {
573        //                Vector3 possiblePosition=(point1 - (point2-point1+richtungen[i]*PHI)*j/STEPS);
574        //                collision=false;
575        //                for(int ij=0; ij<STEPS; j++)
576        //                {
577        //                    Vector3 tempPosition=(possiblePosition - (point2-possiblePosition)*(float)ij/STEPS);
578        //                    for (std::vector<StaticEntity*>::iterator it = problematicObjects.begin(); it!=problematicObjects.end(); ++it)
579        //                    {
580        //                        btVector3 positionObject;
581        //                        btScalar radiusObject;
582        //                        if((*it)==NULL)
583        //                        {   orxout()<<"Problempoint 1"<<endl; continue;}
584        //                        for (int everyShape=0; (*it)->getAttachedCollisionShape(everyShape)!=0; everyShape++)
585        //                        {
586        //                            if((*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()==NULL)
587        //                            {   orxout()<<"Problempoint 2.2"<<endl; continue;}
588        //                            (*it)->getAttachedCollisionShape(everyShape)->getCollisionShape()->getBoundingSphere(positionObject,radiusObject);
589        //                            Vector3 positionObjectNonBT(positionObject.x(), positionObject.y(), positionObject.z());
590        //                            if (((tempPosition-positionObjectNonBT).length()<radiusObject) && (vergleicheQuader((tempPosition-positionObjectNonBT),(*it)->getScale3D())))
591        //                            {
592        //                                collision=true; break;
593        //                            }
594        //                        }
595        //                        if(collision) break;
596        //                    }
597        //                    if(collision)break;
598        //                    //addVirtualCheckPoint(racepoint1, racepoint2->getCheckpointIndex(), possiblePosition);
599        //                    return;
600        //                }
601        //
602        //            }
603        //        }
604
605    }*/
606}
Note: See TracBrowser for help on using the repository browser.