Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    {
Note: See TracChangeset for help on using the changeset viewer.