Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core6/src/modules/gametypes/SpaceRaceController.cc @ 9629

Last change on this file since 9629 was 9629, checked in by landauf, 11 years ago

BaseObject now requires a Context instead of a creator (BaseObject*) in its constructor.
Namespace, Level, and Scene inherit from Context

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