Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2011, 5:40:16 PM (13 years ago)
Author:
dafrick
Message:

Merging spaceboundaries2 branch into presentation branch.

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc

    r8470 r8614  
    3737#include "interfaces/RadarViewable.h"
    3838#include "graphics/Billboard.h"
     39#include <OgreBillboardSet.h>
     40
    3941
    4042namespace orxonox
     
    4446    SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator)
    4547    {
    46         /* Standardwerte, die zum Tragen kommen,
    47          * falls im XML-File keine Werte spezifiziert wurden. */
     48        RegisterObject(SpaceBoundaries);
     49
    4850        this->setMaxDistance(3000);
    49         this->setWarnDistance(2000);
    50         this->setShowDistance(2500);
    51         this->setHealthDecrease(1);
     51        this->setWarnDistance(this->getMaxDistance());
     52        this->setShowDistance(this->getMaxDistance());
    5253        this->setReaction(0);
    53        
    54         RegisterObject(SpaceBoundaries);
    55        
    56         // Show Boundaries on the radar.
    57         this->centerRadar_ = new RadarViewable(this, this);
    58         this->centerRadar_->setRadarObjectShape(RadarViewable::Dot);
    59         this->centerRadar_->setRadarVisibility(false);
    6054    }
    6155    SpaceBoundaries::~SpaceBoundaries()
     
    6357        if (this->isInitialized())
    6458        {
    65             delete this->centerRadar_;
    66        
    6759            this->pawnsIn_.clear();
    6860       
     
    8476        {
    8577            Pawn* currentPawn = *current;
    86             float distance = this->computeDistance(currentPawn);
    87             if(distance <= this->maxDistance_)
    88             {
     78            if( this->reaction_ == 0 )
     79            {
     80                float distance = this->computeDistance(currentPawn);
     81                if(distance <= this->maxDistance_)
     82                {
     83                    pawnsIn_.push_back(currentPawn);
     84                }
     85            } else if (this->reaction_ == 2) {
     86                float distance = this->computeDistance(currentPawn);
     87                if(distance >= this->maxDistance_)
     88                {
     89                    pawnsIn_.push_back(currentPawn);
     90                }
     91            } else {
    8992                pawnsIn_.push_back(currentPawn);
    9093            }
     
    105108        {
    106109            Billboard *tmp = new Billboard(this);
     110            tmp->setPosition(position);
    107111            this->setBillboardOptions( tmp );
    108             tmp->setPosition(position);
     112            Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
     113            tmp->setCommonDirection ( -1.0 * normalisedVec );
     114            tmp->setCommonUpVector( Vector3::UNIT_Z );
    109115            billboardAdministration tmp2 = { true, tmp };
    110116            this->billboards_.push_back( tmp2 );
    111            
    112117        } else {
    113118            current->billy->setPosition(position);
    114119            current->billy->setVisible(true);
    115120            current->usedYet = true;
     121            Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
     122            current->billy->setCommonDirection ( -1.0 * normalisedVec );
     123            current->billy->setCommonUpVector( Vector3::UNIT_Z );
    116124        }
    117125    }
     
    121129        if(billy != NULL)
    122130        {
    123             billy->setMaterial("Shield");
     131            billy->setMaterial("Grid");
     132            billy->setBillboardType(Ogre::BBT_PERPENDICULAR_COMMON);
     133            billy->setDefaultDimensions(150, 150);
    124134            billy->setVisible(true);
    125135        }
     
    186196        XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
    187197        XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
     198        XMLPortParam(SpaceBoundaries, "showDistance", setShowDistance, getShowDistance, xmlelement, mode);
    188199        XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
    189200        XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode);
     
    194205        this->checkWhoIsIn();
    195206        this->removeAllBillboards();
    196         //COUT(0) << "Groesse der Liste: " << (int) pawnsIn_.size() << std::endl;
    197207       
    198208        float distance;
     
    205215                distance = this->computeDistance(currentPawn);
    206216                humanItem = this->isHumanPlayer(currentPawn);
    207                 //COUT(0) << "Distanz:" << distance << std::endl; // message for debugging
    208                 if(distance > this->warnDistance_ && distance < this->maxDistance_) // Zeige Warnung an!
    209                 {
    210                     //COUT(0) << "You are near by the boundaries!" << std::endl; // message for debugging
     217                COUT(5) << "Distance:" << distance << std::endl; // message for debugging
     218                if(distance > this->warnDistance_ && distance < this->maxDistance_) // Display warning
     219                {
    211220                    if(humanItem)
    212221                    {
    213                         //COUT(0) << "humanItem ist true" << std::endl;
    214                         this->displayWarning("Attention! You are near by the boundaries!");
     222                        this->displayWarning("Attention! You are close to the boundary!");
    215223                    }
    216224                }
    217                 if( (this->maxDistance_ - distance) < this->showDistance_ )
    218                 {
    219                     this->displayBoundaries(currentPawn); // Zeige Grenze an!
     225                if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
     226                {
     227                    this->displayBoundaries(currentPawn); // Show the boundary
    220228                }
    221229                if(distance > this->maxDistance_ && (this->reaction_ == 1) )
     
    223231                    if( humanItem )
    224232                    {
    225                         //COUT(0) << "Health should be decreasing!" << std::endl;
     233                        COUT(5) << "Health should be decreasing!" << std::endl;
    226234                        this->displayWarning("You are out of the area now!");
    227235                    }
    228236                    currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_);
    229237                }
    230                 if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Annahme: Ein Pawn kann von einem Tick bis zum nächsten nicht mehr als 100 Distanzeinheiten zurücklegen.
     238                if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Exception: A Pawn can't move more than 100 units per tick.
     239                {
     240                    this->conditionalBounceBack(currentPawn, distance, dt);
     241                }
     242                if( this->reaction_ == 2 && (distance - 100 < this->maxDistance_) )
    231243                {
    232244                    this->conditionalBounceBack(currentPawn, distance, dt);
     
    249261    void SpaceBoundaries::displayWarning(const std::string warnText)
    250262    {   
    251        
     263        // TODO
    252264    }
    253265   
     
    270282        float normalSpeed = item->getVelocity().dotProduct(normal);
    271283       
    272         /* Checke, ob das Pawn innerhalb des nächsten Ticks, das erlaubte Gebiet verlassen würde.
    273            Falls ja: Spicke es zurück. */
    274         if( currentDistance + normalSpeed * dt > this->maxDistance_ )
    275         {
    276             float dampingFactor = 0.5;
    277             velocity = velocity.reflect(normal);
    278             Vector3 acceleration = item->getAcceleration();
    279             acceleration = acceleration.reflect(normal);
    280            
    281             item->lookAt( velocity + this->getPosition() );
    282            
    283             item->setAcceleration(acceleration * dampingFactor);
    284             item->setVelocity(velocity * dampingFactor);
    285         }
     284        /* Check, whether the Pawn would leave the boundary in the next tick, if so send it back. */
     285        if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure"
     286        {
     287            bounceBack(item, &normal, &velocity);
     288        } else if (this->reaction_ == 2 && currentDistance - normalSpeed * dt < this->maxDistance_ + 10 ) // 10: "security measure"
     289        {
     290            normal = normal * (-1);
     291            bounceBack(item, &normal, &velocity);
     292        }
     293    }
     294   
     295    void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity)
     296    {
     297        float dampingFactor = 0.5;
     298        *velocity = velocity->reflect(*normal);
     299        Vector3 acceleration = item->getAcceleration();
     300        acceleration = acceleration.reflect(*normal);
     301       
     302        item->lookAt( *velocity + this->getPosition() );
     303       
     304        item->setAcceleration(acceleration * dampingFactor);
     305        item->setVelocity(*velocity * dampingFactor);
     306       
     307        item->setPosition( item->getPosition() - *normal * 10 ); // Set the position of the Pawn to be well inside the boundary.
    286308    }
    287309   
Note: See TracChangeset for help on using the changeset viewer.