Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 20, 2011, 11:27:45 PM (13 years ago)
Author:
dafrick
Message:

Some cleanup…

Location:
code/trunk/src/modules/objects
Files:
2 edited

Legend:

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

    r8706 r8767  
    5858        {
    5959            this->pawnsIn_.clear();
    60        
     60
    6161            for( std::vector<BillboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
    6262            {
     
    6969        }
    7070    }
    71    
     71
    7272    void SpaceBoundaries::checkWhoIsIn()
    7373    {
     
    9494        }
    9595    }
    96    
     96
    9797    void SpaceBoundaries::positionBillboard(const Vector3& position, float alpha)
    9898    {
     
    124124        this->billboards_[current].billy->setCommonUpVector(upVector);
    125125    }
    126    
     126
    127127    void SpaceBoundaries::setBillboardOptions(Billboard *billy)
    128128    {
     
    135135        }
    136136    }
    137    
     137
    138138    void SpaceBoundaries::removeAllBillboards()
    139139    {
     
    144144        }
    145145    }
    146    
     146
    147147    void SpaceBoundaries::setMaxDistance(float r)
    148148    {
     
    153153        return this->maxDistance_;
    154154    }
    155    
     155
    156156    void SpaceBoundaries::setWarnDistance(float r)
    157157    {
     
    162162        return this->warnDistance_;
    163163    }
    164    
     164
    165165    void SpaceBoundaries::setShowDistance(float r)
    166166    {
     
    171171        return this->showDistance_;
    172172    }
    173    
     173
    174174    void SpaceBoundaries::setHealthDecrease(float amount)
    175175    {
     
    180180        return this->healthDecrease_;
    181181    }
    182    
     182
    183183    void SpaceBoundaries::setReaction(int mode)
    184184    {
     
    200200        XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode);
    201201    }
    202    
     202
    203203    void SpaceBoundaries::tick(float dt)
    204204    {
    205205        this->checkWhoIsIn();
    206206        this->removeAllBillboards();
    207        
     207
    208208        float distance;
    209209        bool humanItem;
     
    247247        }
    248248    }
    249    
     249
    250250    float SpaceBoundaries::computeDistance(WorldEntity *item)
    251251    {
     
    258258        }
    259259    }
    260    
     260
    261261    void SpaceBoundaries::displayWarning(const std::string warnText)
    262     {   
     262    {
    263263        // TODO
    264264    }
    265    
     265
    266266    void SpaceBoundaries::displayBoundaries(Pawn *item, float alpha)
    267267    {
    268        
     268
    269269        Vector3 direction = item->getPosition() - this->getPosition();
    270270        direction.normalise();
    271        
     271
    272272        Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
    273        
     273
    274274        this->positionBillboard(boundaryPosition, alpha);
    275275    }
    276    
     276
    277277    void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt)
    278278    {
     
    281281        Vector3 velocity = item->getVelocity();
    282282        float normalSpeed = item->getVelocity().dotProduct(normal);
    283        
     283
    284284        /* Check, whether the Pawn would leave the boundary in the next tick, if so send it back. */
    285285        if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure"
     
    292292        }
    293293    }
    294    
     294
    295295    void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity)
    296296    {
     
    299299        Vector3 acceleration = item->getAcceleration();
    300300        acceleration = acceleration.reflect(*normal);
    301        
     301
    302302        item->lookAt( *velocity + this->getPosition() );
    303        
     303
    304304        item->setAcceleration(acceleration * dampingFactor);
    305305        item->setVelocity(*velocity * dampingFactor);
    306        
     306
    307307        item->setPosition( item->getPosition() - *normal * 10 ); // Set the position of the Pawn to be well inside the boundary.
    308308    }
    309    
     309
    310310    bool SpaceBoundaries::isHumanPlayer(Pawn *item)
    311311    {
     
    319319        return false;
    320320    }
    321    
     321
    322322}
  • code/trunk/src/modules/objects/SpaceBoundaries.h

    r8706 r8767  
    4545{
    4646
    47 /**
    48 @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
     47    /**
     48    @brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
    4949
    50        Some attributes can/should be defined in the XML-File:
    51        - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0)
    52        - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
    53        - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
    54                           inform the player that he'll soon be leaving the allowed area. (not implemented yet!)
    55        - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.
    56        - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
    57                             0: Reflect the space ship (default).
    58                             1: Decrease Health of the space ship after having left the allowed area.
    59                             2: Inverted Version of 0. Prohibit to fly INTO a defined area.
    60        - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
    61                             Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
     50        Some attributes can/should be defined in the XML-File:
     51        - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0)
     52        - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
     53        - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
     54                            inform the player that he'll soon be leaving the allowed area. (not implemented yet!)
     55        - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown.
     56        - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
     57                                0: Reflect the space ship (default).
     58                                1: Decrease Health of the space ship after having left the allowed area.
     59                                2: Inverted Version of 0. Prohibit to fly INTO a defined area.
     60        - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
     61                                Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
    6262
    63 Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information.
     63        Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information.
    6464
    65 Examples:
    66 Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease.
    67 @code
    68 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" />
    69 @endcode
     65        Examples:
     66        Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease.
     67        @code
     68        <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" />
     69        @endcode
    7070
    71 @code
    72 <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" />
    73 @endcode
    74 */
    75 
     71        @code
     72        <SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" />
     73        @endcode
     74    */
    7675    class _ObjectsExport SpaceBoundaries : public StaticEntity, public Tickable
    7776    {
     
    7978            SpaceBoundaries(BaseObject* creator);
    8079            ~SpaceBoundaries();
    81            
     80
    8281            void setMaxDistance(float r);
    8382            float getMaxDistance();
    84            
     83
    8584            void setWarnDistance(float r);
    8685            float getWarnDistance();
    87            
     86
    8887            void setShowDistance(float r);
    8988            float getShowDistance();
    90            
     89
    9190            void setHealthDecrease(float amount);
    9291            float getHealthDecrease();
    93            
     92
    9493            void setReaction(int mode);
    9594            int getReaction();
    9695
    9796            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    98            
     97
    9998            void tick(float dt);
    10099
    101100        private:
    102101            struct BillboardAdministration{ bool usedYet; Billboard* billy; };
    103            
     102
    104103            // Variabeln::
    105104            std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
    106            
     105
    107106            std::vector<BillboardAdministration> billboards_;
    108        
     107
    109108            int reaction_; //!< Values: 0, 1, 2.
    110109                           //!< 0: Reflection on boundary (Standard).
     
    114113            float warnDistance_; //!< Distance in which a warning is displayed.
    115114            float showDistance_; //!< Distance at which the boundaries are displayed.
    116            
     115
    117116            float healthDecrease_; //!< Rate of health loss.
    118            
     117
    119118            //RadarViewable* centerRadar_; //!< Representation of the space boundary in the radar.
    120        
     119
    121120            // Funktionen::
    122121            float computeDistance(WorldEntity *item); //!< Compute distance to center point.
     
    126125            void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
    127126            bool isHumanPlayer(Pawn *item);
    128            
     127
    129128            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
    130            
     129
    131130            void positionBillboard(const Vector3& position, float alpha); //!< Display a Billboard at the position 'position'.
    132131            void setBillboardOptions(Billboard *billy);
    133132            void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
    134            
    135133    };
    136134}
Note: See TracChangeset for help on using the changeset viewer.