Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8301


Ignore:
Timestamp:
Apr 22, 2011, 6:42:42 PM (13 years ago)
Author:
kmaurus
Message:

several billboards that represent the boundary can be displayed now

Location:
code/branches/spaceboundaries/src/orxonox/worldentities
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc

    r8281 r8301  
    3838#include "graphics/Billboard.h"
    3939
    40 
    41 //#include <OgreTextAreaOverlayElement.h>
    42 #include <OgreOverlayManager.h>
    43 //#include <overlays/OverlayText.h>
    44 
    4540namespace orxonox
    4641{
     
    6257        this->centerRadar_->setRadarObjectShape(RadarViewable::Dot);
    6358        this->centerRadar_->setRadarVisibility(false);
    64        
    65 //         m_pColoredTextAreaOverlayElementFactory = new ColoredTextAreaOverlayElementFactory();
    6659    }
    6760    SpaceBoundaries::~SpaceBoundaries()
     
    7669        this->pawnsIn_.clear();
    7770       
    78 //        delete pColoredTextAreaOverlayElementFactory;
     71        for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
     72        {
     73            if( current->billy != NULL)
     74            {
     75                delete current->billy;
     76            }
     77        }
     78        this->billboards_.clear();
    7979    }
    8080   
     
    9393    }
    9494   
     95    void SpaceBoundaries::positionBillboard(const Vector3 position)
     96    {
     97        std::vector<billboardAdministration>::iterator current;
     98        for( current = this->billboards_.begin(); current != this->billboards_.end(); current++)
     99        {
     100            if(!current->usedYet)
     101            {
     102                break;
     103            }
     104        }
     105        if( current == this->billboards_.end() )
     106        {
     107            Billboard *tmp = new Billboard(this);
     108            setBillboardOptions( tmp );
     109            tmp->setPosition(position);
     110            billboardAdministration tmp2 = { true, tmp };
     111            this->billboards_.push_back( tmp2 );
     112           
     113        } else {
     114            current->billy->setPosition(position);
     115            current->billy->setVisible(true);
     116            current->usedYet = true;
     117        }
     118    }
     119   
     120    void SpaceBoundaries::setBillboardOptions(Billboard *billy)
     121    {
     122        if(billy != NULL)
     123        {
     124            billy->setMaterial("Shield");
     125            billy->setVisible(true);
     126        }
     127    }
     128   
     129    void SpaceBoundaries::removeAllBillboards()
     130    {
     131        for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
     132        {
     133            current->usedYet = false;
     134            current->billy->setVisible(false);
     135        }
     136    }
     137   
    95138    void SpaceBoundaries::setMaxDistance(float r)
    96139    {
     
    140183    void SpaceBoundaries::tick(float dt)
    141184    {
    142        
     185        this->removeAllBillboards();
    143186        COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
    144187       
    145         //for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
     188        float distance;
     189        bool humanItem;
    146190        for( std::list<Pawn*>::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
    147191        {
    148192            Pawn* currentPawn = *current;
    149             float distance = this->computeDistance(currentPawn);
    150             bool humanItem = this->isHumanPlayer(currentPawn);
    151             COUT(0) << "Distanz:" << distance << std::endl; //!< message for debugging
     193            distance = this->computeDistance(currentPawn);
     194            humanItem = this->isHumanPlayer(currentPawn);
     195            COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
    152196            if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
    153197            {
    154                 COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
     198                COUT(0) << "You are leaving the area" << std::endl; // message for debugging
    155199                if(humanItem)
    156200                {
     
    185229    float SpaceBoundaries::computeDistance(WorldEntity *item)
    186230    {
    187         Vector3 itemPosition = item->getPosition();
    188         return (itemPosition.distance(this->getPosition()));
     231        if(item != NULL)
     232        {
     233            Vector3 itemPosition = item->getPosition();
     234            return (itemPosition.distance(this->getPosition()));
     235        } else {
     236            return -1;
     237        }
    189238    }
    190239   
    191240    void SpaceBoundaries::displayWarning(const std::string warnText)
    192     {   /*
    193         Ogre::TextAreaOverlayElement *pTextArea;
    194         Ogre::OverlayManager manager = Ogre::OverlayManager();
    195         Ogre::OverlayElement temp = manager.createOverlayElement("TextArea", "MyTextArea");
    196         //pTextArea = (Ogre::TextAreaOverlayElement *)
    197        // pTextArea->setCaption("Some plain text");
    198    
    199         Ogre::TextAreaOverlayElement warning(warnText);
    200         warning.initialise();
    201         //warning.setPosition(0.2, 0.2);
    202        
    203 
    204         COUT(0) << "Breite des Warntextes: " << warning.getWidth() << std::endl;
    205         COUT(0) << "Hoehe des Warntextes: " << warning.getHeight() << std::endl;
    206        
    207         warning.show();*/
    208         // Register the overlay element
    209 /*         OverlayManager::getSingleton().addOverlayElementFactory(pColoredTextAreaOverlayElementFactory);
    210          
    211         Ogre::TextAreaOverlayElement *pTextArea =
    212                 (Ogre::TextAreaOverlayElement*)Ogre::OverlayManager.createOverlayElement("TextArea", "MyTextArea");
    213         pTextArea->setCaption("Some plain text");
    214 */
     241    {   
    215242       
    216243    }
     
    224251        Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
    225252       
    226         if(this->boundary_ == NULL)
    227         {
    228             this->boundary_ = new Billboard(this);
    229             this->boundary_->setMaterial("Examples/Flare");
    230             this->boundary_->setVisible(true);
    231         }
    232        
    233         this->boundary_->setPosition(boundaryPosition);
     253        this->positionBillboard(boundaryPosition);
    234254    }
    235255   
     
    237257    {
    238258        Vector3 normal = item->getPosition() - this->getPosition();
    239         if( item->getVelocity().dotProduct(normal) > 0 ) // greife nur ein, falls
     259        if( item->getVelocity().dotProduct(normal) > 0 ) // Greife nur ein, falls sich das Pawn nach Aussen bewegt.
    240260        {
    241261            float dampingFactor = 0.5;
     
    246266            Vector3 acceleration = item->getAcceleration();
    247267            acceleration = acceleration.reflect(normal);
    248             /*
    249             Vector3 rotationAxis = velocity.crossProduct(normal);
    250             Ogre::Radian angle = 2 * velocity.angleBetween(normal);
    251             item->setOrientation(Ogre::Quaternion::Quaternion(angle, rotationAxis));
    252             */
    253             /*
    254             Ogre::Quaternion orientation = item->getOrientation();
    255             orientation = -1.0 * orientation;
    256             item->setOrientation(orientation);
    257             */
    258             //item->setOrientation(item->getOrientation().UnitInverse() );
    259268           
    260269            item->lookAt( velocity + this->getPosition() );
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h

    r8281 r8301  
    2727 */
    2828 
    29  /* TODO:   - Mehrere SpaceBoundaries-Instanzen pro Level ermoeglichen
    30             - Pro Pawn ein Billboard verwenden
     29 /* TODO:   - Sobald Bots im Spiel sind, stürzt das Programm relativ bald ab!!!
    3130 */
    3231 
     
    5251#include "worldentities/WorldEntity.h"
    5352
    54 //#include <ColoredTextAreaOverlayElementFactory.h>
    55 
    5653#include <string>
    5754#include <list>
     55#include <map>
     56#include <vector>
    5857
    5958/**
     
    7877            ~SpaceBoundaries();
    7978           
    80             void checkWhoIsIn();
     79            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
     80           
     81            void positionBillboard(const Vector3 position);
     82            void setBillboardOptions(Billboard *billy);
     83            void removeAllBillboards();
    8184           
    8285            void setMaxDistance(float r);
     
    97100
    98101        private:
    99             std::list<Pawn*> pawnsIn_;
     102            struct billboardAdministration{ bool usedYet; Billboard* billy; };
     103           
     104            std::list<Pawn*> pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
     105           
     106            std::vector<billboardAdministration> billboards_;
    100107       
    101108            float maxDistance_; //!< maximal zulaessige Entfernung von 'this->getPosition()'.
     
    116123            bool isHumanPlayer(Pawn *item);
    117124           
    118  //           ColoredTextAreaOverlayElementFactory* pColoredTextAreaOverlayElementFactory;
    119125    };
    120126}
Note: See TracChangeset for help on using the changeset viewer.