Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8110


Ignore:
Timestamp:
Mar 24, 2011, 4:16:54 PM (13 years ago)
Author:
kmaurus
Message:

Iteratorschleife aller MobileEntities sowie Funktion zum Berechnen des Abstandes einer MobileEntity vom Zentrun erstellt

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

Legend:

Unmodified
Added
Removed
  • code/branches/spaceboundaries/src/orxonox/worldentities/CMakeLists.txt

    r7163 r8110  
    1212  SpawnPoint.cc
    1313  TeamSpawnPoint.cc
     14  SpaceBoundaries.cc
    1415)
    1516
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.cc

    r8087 r8110  
    3030
    3131/* Folgender Block ist Copy-Paste und somit teilweise wohl unnoetig */
    32 #include "core/CoreIncludes.h"
    3332#include "core/Template.h"
    3433#include "core/XMLPort.h"
     
    3736
    3837/* Eigene, spezifische include-Statements*/
     38#include "worldentities/MobileEntity.h"
     39#include "core/ObjectListIterator.h"
    3940
    4041namespace orxonox
     
    4546    {
    4647        RegisterObject(SpaceBoundaries);
     48       
     49        // Show Boundaries on the radar.
    4750    }
    48    
    4951    SpaceBoundaries::~SpaceBoundaries()
    5052    {
    5153   
    5254    }
     55   
     56    void SpaceBoundaries::setCenter(Vector3 r)
     57    {
     58        this->center = r;
     59    }
     60    Vector3 SpaceBoundaries::getCenter()
     61    {
     62        return this->center;
     63    }
     64   
     65    void SpaceBoundaries::setMaxDistance(float r)
     66    {
     67        this->maxDistance = r;
     68    }
     69    float SpaceBoundaries::getMaxDistance()
     70    {
     71        return this->maxDistance;
     72    }
     73   
     74    void SpaceBoundaries::setWarnDistance(float r)
     75    {
     76        this->warnDistance = r;
     77    }
     78    float SpaceBoundaries::getWarnDistance()
     79    {
     80        return this->warnDistance;
     81    }
    5382
    5483    void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    5584    {
    56     //    SUPER(SpaceBoundaries, XMLPort, xmlelement, mode);
     85        SUPER(SpaceBoundaries, XMLPort, xmlelement, mode);
    5786
    58     //    XMLPortParam(SpaceBoundaries, "spawnclass", setSpawnClassName, getSpawnClassName, xmlelement, mode);
    59     //    XMLPortParam(SpaceBoundaries, "pawndesign", setTemplateName, getTemplateName, xmlelement, mode);
     87        XMLPortParam(SpaceBoundaries, "center", setCenter, getCenter, xmlelement, mode);
     88        XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
     89        XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
    6090    }
     91   
     92    void SpaceBoundaries::tick(float dt)
     93    {
     94        for(ObjectListIterator<MobileEntity> item = ObjectList<MobileEntity>::begin(); item != ObjectList<MobileEntity>::end(); ++item)
     95        {
     96            float distance = computeDistance((WorldEntity *)&item); // fuer casts gibt's scheinbar andere, neuere Variante --> vgl. Coding-Guide und andere Files
     97            if(distance > this->warnDistance && distance < this->maxDistance)
     98            {
     99                COUT(0) << "You are leaving the area" << std::endl; //!< message for debugging
     100                // Display Warning on Screen if the humanPlayer (infos/PlayerInfo.h) is leaving the area
     101            } else if(distance > maxDistance)
     102            {
     103                // Decrease Health
     104            }
     105        }
     106    }
     107   
     108    float SpaceBoundaries::computeDistance(WorldEntity *item)
     109    {
     110        Vector3 itemPosition = item->getPosition();
     111        return (itemPosition.distance(center));
     112    }
     113   
     114   
     115   
     116   
     117   
     118   
     119   
     120   
     121   
     122   
     123   
     124   
     125   
     126   
     127   
     128   
     129   
     130   
     131   
     132   
     133   
     134   
     135   
     136   
     137   
    61138}
  • code/branches/spaceboundaries/src/orxonox/worldentities/SpaceBoundaries.h

    r8087 r8110  
    3434#include <string>
    3535#include "core/SubclassIdentifier.h"
    36 #include "worldentities/StaticEntity.h"
    3736
    3837/* Einige, spezifische include-Statements */
    39 
     38#include "core/CoreIncludes.h"
     39#include "tools/interfaces/Tickable.h"
     40#include "worldentities/StaticEntity.h"
     41#include "worldentities/WorldEntity.h"
    4042
    4143
     
    4648        public:
    4749            SpaceBoundaries(BaseObject* creator);
    48             virtual ~SpaceBoundaries() {}
     50            ~SpaceBoundaries();
     51           
     52            void setCenter(Vector3 r);
     53            Vector3 getCenter();
     54           
     55            void setMaxDistance(float r);
     56            float getMaxDistance();
     57           
     58            void setWarnDistance(float r);
     59            float getWarnDistance();
    4960
    50             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     61            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     62           
     63            void tick(float dt);
    5164
    5265        private:
     66            Vector3 center;
     67            float maxDistance;
     68            float warnDistance;
    5369       
     70            float computeDistance(WorldEntity *item); //!< Auf den Mittelpunkt 'center' bezogen.
    5471    };
    5572}
Note: See TracChangeset for help on using the changeset viewer.