Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 29, 2011, 4:02:07 PM (13 years ago)
Author:
landauf
Message:

added fade in/out effect for space boundaries (alpha value, based on distance)

Location:
code/branches/presentation/src/modules/objects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/modules/objects/SpaceBoundaries.cc

    r8657 r8660  
    5959            this->pawnsIn_.clear();
    6060       
    61             for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
     61            for( std::vector<BillboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
    6262            {
    6363                if( current->billy != NULL)
     
    9595    }
    9696   
    97     void SpaceBoundaries::positionBillboard(const Vector3 position)
    98     {
    99         std::vector<billboardAdministration>::iterator current;
    100         for( current = this->billboards_.begin(); current != this->billboards_.end(); current++)
    101         {
    102             if(!current->usedYet)
    103             {
     97    void SpaceBoundaries::positionBillboard(const Vector3& position, float alpha)
     98    {
     99        size_t current;
     100        for (current = 0; current < this->billboards_.size(); ++current)
     101            if (!this->billboards_[current].usedYet)
    104102                break;
    105             }
    106         }
    107         if( current == this->billboards_.end() )
    108         {
    109             Billboard *tmp = new Billboard(this);
    110             tmp->setPosition(position);
    111             this->setBillboardOptions( tmp );
    112             Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
    113             tmp->setCommonDirection ( -1.0 * normalisedVec );
    114             Vector3 upVector = Vector3(normalisedVec.z, normalisedVec.z, -(normalisedVec.x+normalisedVec.y));
    115             upVector.normalise();
    116             tmp->setCommonUpVector( upVector );
    117             billboardAdministration tmp2 = { true, tmp };
    118             this->billboards_.push_back( tmp2 );
    119         } else {
    120             current->billy->setPosition(position);
    121             current->billy->setVisible(true);
    122             current->usedYet = true;
    123             Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
    124             current->billy->setCommonDirection ( -1.0 * normalisedVec );
    125             Vector3 upVector = Vector3(normalisedVec.z, normalisedVec.z, -(normalisedVec.x+normalisedVec.y));
    126             upVector.normalise();
    127             current->billy->setCommonUpVector( upVector );
    128         }
     103
     104        if (current == this->billboards_.size())
     105        {
     106            Billboard* billboard = new Billboard(this);
     107            billboard->setPosition(position);
     108            this->setBillboardOptions(billboard);
     109            BillboardAdministration ba = {true, billboard};
     110            this->billboards_.push_back(ba);
     111        }
     112
     113        this->billboards_[current].billy->setPosition(position);
     114        this->billboards_[current].billy->setVisible(true);
     115        this->billboards_[current].billy->setColour(ColourValue(1, 1, 1, alpha));
     116        this->billboards_[current].usedYet = true;
     117
     118        Vector3 directionVector = (this->getPosition() - position).normalisedCopy(); // vector from the position of the billboard to the center of the sphere
     119        this->billboards_[current].billy->setCommonDirection(directionVector);
     120
     121        Vector3 upVector = Vector3(directionVector.z, directionVector.z, -(directionVector.x + directionVector.y)); // vector perpendicular to the direction vector
     122        upVector.normalise();
     123        this->billboards_[current].billy->setCommonUpVector(upVector);
    129124    }
    130125   
     
    142137    void SpaceBoundaries::removeAllBillboards()
    143138    {
    144         for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
     139        for( std::vector<BillboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
    145140        {
    146141            current->usedYet = false;
     
    229224                if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
    230225                {
    231                     this->displayBoundaries(currentPawn); // Show the boundary
     226                    this->displayBoundaries(currentPawn, 1.0f - fabs(this->maxDistance_ - distance) / this->showDistance_); // Show the boundary
    232227                }
    233228                if(distance > this->maxDistance_ && (this->reaction_ == 1) )
     
    268263    }
    269264   
    270     void SpaceBoundaries::displayBoundaries(Pawn *item)
     265    void SpaceBoundaries::displayBoundaries(Pawn *item, float alpha)
    271266    {
    272267       
     
    276271        Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
    277272       
    278         this->positionBillboard(boundaryPosition);
     273        this->positionBillboard(boundaryPosition, alpha);
    279274    }
    280275   
  • code/branches/presentation/src/modules/objects/SpaceBoundaries.h

    r8645 r8660  
    100100
    101101        private:
    102             struct billboardAdministration{ bool usedYet; Billboard* billy; };
     102            struct BillboardAdministration{ bool usedYet; Billboard* billy; };
    103103           
    104104            // Variabeln::
    105105            std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
    106106           
    107             std::vector<billboardAdministration> billboards_;
     107            std::vector<BillboardAdministration> billboards_;
    108108       
    109109            int reaction_; //!< Values: 0, 1, 2.
     
    122122            float computeDistance(WorldEntity *item); //!< Compute distance to center point.
    123123            void displayWarning(const std::string warnText); //!< TODO: Implement.
    124             void displayBoundaries(Pawn *item);
     124            void displayBoundaries(Pawn *item, float alpha);
    125125            void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
    126126            void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
     
    129129            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
    130130           
    131             void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
     131            void positionBillboard(const Vector3& position, float alpha); //!< Display a Billboard at the position 'position'.
    132132            void setBillboardOptions(Billboard *billy);
    133133            void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
Note: See TracChangeset for help on using the changeset viewer.