Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/gametypes/SpaceRaceController.cc @ 9967

Last change on this file since 9967 was 9967, checked in by landauf, 10 years ago

call by reference instead of value

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