Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8244


Ignore:
Timestamp:
Apr 14, 2011, 4:53:27 PM (14 years ago)
Author:
kmaurus
Message:

Pawns that want to leave the area are reflected, one billboard is added that represents the boundary

Location:
code/branches/spaceboundaries
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceboundaries/data/levels/myTestLevel.oxw

    r8201 r8244  
    3030
    3131    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
    32     <SpawnPoint team=0 position="0,0,0" lookat="200,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
     32    <SpawnPoint team=0 position="0,0,0" lookat="2,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
    3333   
    34     <SpaceBoundaries warnDistance="-1" maxDistance="200" healthDecrease="0.1" position="200,0,0"/>
     34    <SpaceBoundaries warnDistance="1" maxDistance="200" showDistance="100" healthDecrease="0.1" position="0,0,0"/>
    3535   
    3636  </Scene>
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc

    r8201 r8244  
    3636#include "infos/PlayerInfo.h"
    3737#include "interfaces/RadarViewable.h"
     38#include "graphics/Billboard.h"
    3839
    3940
     
    5253        this->setMaxDistance(3000);
    5354        this->setWarnDistance(2000);
     55        this->setShowDistance(2500);
    5456        this->setHealthDecrease(1);
    5557       
     
    6668    {
    6769        delete this->centerRadar_;
     70       
     71        if(this->boundary_ != NULL)
     72        {
     73            delete this->boundary_;
     74        }
     75       
    6876//        delete pColoredTextAreaOverlayElementFactory;
    6977    }
     
    8593    {
    8694        return this->warnDistance_;
     95    }
     96   
     97    void SpaceBoundaries::setShowDistance(float r)
     98    {
     99        this->showDistance_ = r;
     100    }
     101    float SpaceBoundaries::getShowDistance()
     102    {
     103        return this->showDistance_;
    87104    }
    88105   
     
    110127        {
    111128            MobileEntity* myMobileEntity = *item;
    112             Pawn* myItem = dynamic_cast<Pawn*>(myMobileEntity);
    113             if(myItem != NULL)
     129            Pawn* currentPawn = dynamic_cast<Pawn*>(myMobileEntity);
     130            if(currentPawn != NULL)
    114131            {
    115                 float distance = computeDistance((WorldEntity*) myItem);
    116                 bool humanItem = this->isHumanPlayer(myItem);
     132                float distance = this->computeDistance(currentPawn);
     133                bool humanItem = this->isHumanPlayer(currentPawn);
    117134                COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
    118                 if(distance > this->warnDistance_ && distance < this->maxDistance_)
     135                if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
    119136                {
    120137                    COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
     
    127144                    }
    128145                }
    129                 if(distance > maxDistance_)
     146                if( (this->maxDistance_ - distance) < this->showDistance_)
     147                {
     148                    // Zeige Grenze an!
     149                    this->displayBoundaries(currentPawn);
     150                }
     151                if(distance > this->maxDistance_)
    130152                {
    131153                    if(humanItem)
     
    133155                        COUT(0) << "Health should be decreasing!" << std::endl;
    134156                        this->displayWarning("You are out of the area now!");
    135                         myItem->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
     157                        currentPawn->removeHealth( (distance - maxDistance_) * this->healthDecrease_);
    136158                    } else {
    137159                       
    138160                    }
     161                   
     162                    this->bounceBack(currentPawn);
    139163                }
    140164            }
     
    175199    }
    176200   
     201    void SpaceBoundaries::displayBoundaries(Pawn *item)
     202    {
     203       
     204        Vector3 direction = item->getPosition() - this->getPosition();
     205        direction.normalise();
     206       
     207        Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
     208       
     209        if(this->boundary_ == NULL)
     210        {
     211            this->boundary_ = new Billboard(this);
     212            this->boundary_->setMaterial("Examples/Flare");
     213            this->boundary_->setVisible(true);
     214        }
     215       
     216        this->boundary_->setPosition(boundaryPosition);
     217    }
     218   
     219    void SpaceBoundaries::bounceBack(Pawn *item)
     220    {
     221        Vector3 normal = item->getPosition() - this->getPosition();
     222        if( item->getVelocity().dotProduct(normal) > 0 ) // greife nur ein, falls
     223        {
     224            normal.normalise();
     225            Vector3 velocity = item->getVelocity();
     226            velocity = velocity.reflect(normal);
     227            Vector3 acceleration = item->getAcceleration();
     228            acceleration = acceleration.reflect(normal);
     229            /*
     230            Vector3 rotationAxis = velocity.crossProduct(normal);
     231            Ogre::Radian angle = velocity.angleBetween(normal);
     232            item->setOrientation(Ogre::Quaternion::Quaternion(angle, rotationAxis));
     233            */
     234            item->setAcceleration(acceleration);
     235            item->setVelocity(velocity);
     236        }
     237    }
     238   
    177239    bool SpaceBoundaries::isHumanPlayer(Pawn *item)
    178240    {
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h

    r8237 r8244  
    2727 */
    2828 
    29  /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
    30           - Kugel-Model mal hinzufuegen, das nur sichtbar ist, wenn man genuegend nah an maxDistance dran ist
    31           - Reflexion an obiger Kugel beim Versuch durchzudringen
     29 /* TODO: - Markiere SpaceBoundaries-Position mit einem schoenen Objekt
     30          - Reflexion an Grenze mit Quaternionen machen (--> vgl. Funktion bounceBack() )
    3231 */
    3332
     
    4948@brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area.
    5049
    51        Four attributes can/should be defined in the XML-File:
    52        - 'position' : absolute position of the SpaceBoundaries class. '*Distance' refers to this 'position'.
     50       Five attributes can/should be defined in the XML-File:
     51       - 'position' : absolute position of the SpaceBoundaries class. 'warnDistance' and 'maxDistance' refer to this 'position'.
    5352       - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
    5453                          inform the player that he'll soon be leaving the allowed area.
    5554       - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
     55       - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.
    5656       - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area.
    5757                            Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
     
    6666            ~SpaceBoundaries();
    6767           
    68             void se     tMaxDistance(float r);
     68            void setMaxDistance(float r);
    6969            float getMaxDistance();
    7070           
    7171            void setWarnDistance(float r);
    7272            float getWarnDistance();
     73           
     74            void setShowDistance(float r);
     75            float getShowDistance();
    7376           
    7477            void setHealthDecrease(float amount);
     
    8285            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
    8386            float warnDistance_; //!< Entfernung von 'this->getPosition()', ab der eine Warnung angezeigt wird, dass man bald das zulaessige Areal verlaesst.
     87            float showDistance_; //!< Definiert, wann die Grenzen visualisiert werden sollen.
    8488           
    8589            float healthDecrease_; //!< Mass fuer die Anzahl Health-Points, die nach ueberschreiten der Entfernung 'maxDistance_' von 'this->getPosition()' abgezogen werden.
    8690                                   //!< Empfohlene Werte: 0.1 (langsame Health-Verminderung) bis 5 (sehr schnelle Health-Verminderung)
     91           
     92            Billboard *boundary_;
    8793           
    8894            RadarViewable* centerRadar_; //!< Repraesentation von SpaceBoundaries auf dem Radar.
     
    9096            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'this->getPosition()' bezogen.
    9197            void displayWarning(const std::string warnText);
     98            void displayBoundaries(Pawn *item);
     99            void bounceBack(Pawn *item);
    92100            bool isHumanPlayer(Pawn *item);
    93101           
Note: See TracChangeset for help on using the changeset viewer.