Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2008, 2:44:48 AM (16 years ago)
Author:
landauf
Message:

added two more graphical classes, ParticleEmitter and ParticleSpawner

Location:
code/branches/objecthierarchy/src/orxonox/objects/worldentities
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Billboard.cc

    r2044 r2065  
    7676                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
    7777                this->getNode()->attachObject(this->billboard_.getBillboardSet());
     78                this->billboard_.setVisible(this->isVisible());
    7879            }
    7980        }
     
    9091                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
    9192                this->getNode()->attachObject(this->billboard_.getBillboardSet());
     93                this->billboard_.setVisible(this->isVisible());
    9294            }
    9395        }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.cc

    r2063 r2065  
    3030#include "BlinkingBillboard.h"
    3131
     32#include "core/Core.h"
    3233#include "core/CoreIncludes.h"
    3334#include "core/XMLPort.h"
     35#include "util/Math.h"
    3436
    3537namespace orxonox
     
    4446        this->frequency_ = 1.0f;
    4547        this->phase_ = 0;
     48        this->bQuadratic_ = false;
    4649        this->time_ = 0;
    4750
     
    6063        XMLPortParam(BlinkingBillboard, "frequency", setFrequency, getFrequency, xmlelement, mode).defaultValues(1.0f);
    6164        XMLPortParam(BlinkingBillboard, "phase",     setPhase,     getPhase,     xmlelement, mode).defaultValues(Degree(0));
     65        XMLPortParam(BlinkingBillboard, "quadratic", setQuadratic, isQuadratic,  xmlelement, mode).defaultValues(false);
    6266    }
    6367
    6468    void BlinkingBillboard::registerVariables()
    6569    {
    66         REGISTERDATA(this->amplitude_, network::direction::toclient);
    67         REGISTERDATA(this->frequency_, network::direction::toclient);
    68         REGISTERDATA(this->phase_,     network::direction::toclient);
     70//        REGISTERDATA(this->amplitude_, network::direction::toclient);
     71//        REGISTERDATA(this->frequency_, network::direction::toclient);
     72//        REGISTERDATA(this->phase_,     network::direction::toclient);
    6973    }
    7074
    7175    void BlinkingBillboard::tick(float dt)
    7276    {
    73         this->time_ += dt;
    74         this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_));
     77        if (Core::isMaster())
     78        {
     79            this->time_ += dt;
     80            if (this->bQuadratic_)
     81                this->setScale(this->amplitude_ * square(sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_)));
     82            else
     83                this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_));
     84        }
    7585    }
    7686}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.h

    r2063 r2065  
    6262                { return this->phase_; }
    6363
     64            inline void setQuadratic(bool bQuadratic)
     65                { this->bQuadratic_ = bQuadratic; }
     66            inline bool isQuadratic() const
     67                { return this->bQuadratic_; }
     68
    6469        private:
    6570            float amplitude_;
    6671            float frequency_;
    6772            Degree phase_;
     73            bool bQuadratic_;
    6874            long double time_;
    6975    };
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2062 r2065  
    9595        XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
    9696
    97         XMLPortObject(ControllableEntity, WorldEntity, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
     97        XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
    9898    }
    9999
     
    239239            else if (this->bControlled_)
    240240            {
    241                 COUT(2) << "setting client position" << endl;
     241//                COUT(2) << "setting client position" << endl;
    242242                this->client_velocity_ = this->velocity_;
    243243                this->client_position_ = this->node_->getPosition();
     
    249249    {
    250250        REGISTERSTRING(this->cameraPositionTemplate_, network::direction::toclient);
    251        
    252        
    253         REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    254         REGISTERDATA(this->server_overwrite_,   network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
    255251
    256252        REGISTERDATA(this->server_position_,    network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     
    258254        REGISTERDATA(this->server_orientation_, network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerOrientation));
    259255
     256        REGISTERDATA(this->server_overwrite_,   network::direction::toclient, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processOverwrite));
     257        REGISTERDATA(this->client_overwrite_,   network::direction::toserver);
    260258
    261259        REGISTERDATA(this->client_position_,    network::direction::toserver, new network::NetworkCallback<ControllableEntity>(this, &ControllableEntity::processClientPosition));
     
    301299        if (this->server_overwrite_ == this->client_overwrite_)
    302300        {
    303             COUT(2) << "callback: setting client position" << endl;
     301//            COUT(2) << "callback: setting client position" << endl;
    304302            this->node_->setPosition(this->client_position_);
    305303            this->server_position_ = this->client_position_;
    306304        }
    307         else
    308           COUT(2) << "callback: not setting client position" << endl;
     305//        else
     306//          COUT(2) << "callback: not setting client position" << endl;
    309307    }
    310308
     
    458456        else if (this->bControlled_)
    459457        {
    460 //             this->node_->lookAt(target, relativeTo, localDirectionVector);
     458            this->node_->lookAt(target, relativeTo, localDirectionVector);
    461459            this->client_orientation_ = this->node_->getOrientation();
    462460        }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Light.cc

    r2044 r2065  
    165165        this->light_->setType(this->type_);
    166166    }
     167
     168    void Light::changedVisibility()
     169    {
     170        SUPER(Light, changedVisibility);
     171
     172        this->light_->setVisible(this->isVisible());
     173    }
    167174}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Light.h

    r2044 r2065  
    4949            void registerVariables();
    5050
     51            virtual void changedVisibility();
     52
    5153            inline Ogre::Light* getLight()
    5254                { return this->light_; }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/Model.cc

    r2040 r2065  
    7676            this->getNode()->attachObject(this->mesh_.getEntity());
    7777            this->mesh_.getEntity()->setCastShadows(this->bCastShadows_);
     78            this->mesh_.setVisible(this->isVisible());
    7879        }
    7980    }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.cc

    r2027 r2065  
    3030#include "ParticleSpawner.h"
    3131
    32 #include <OgreSceneManager.h>
    3332#include "core/CoreIncludes.h"
     33#include "core/EventIncludes.h"
    3434#include "core/Executor.h"
     35#include "core/XMLPort.h"
    3536#include "tools/ParticleInterface.h"
    36 #include "GraphicsEngine.h"
    3737
    3838namespace orxonox
     
    4040    CreateFactory(ParticleSpawner);
    4141
    42     ParticleSpawner::ParticleSpawner()
     42    ParticleSpawner::ParticleSpawner(BaseObject* creator) : ParticleEmitter(creator)
    4343    {
    4444        RegisterObject(ParticleSpawner);
    45         this->particle_ = 0;
    46     }
    4745
    48     ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
    49     {
    50         RegisterObject(ParticleSpawner);
    51         this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction);
    52     }
     46        this->bAutostart_ = true;
     47        this->bSuppressStart_ = false;
     48        this->bAutoDestroy_ = true;
     49        this->bForceDestroy_ = false;
     50        this->bLoop_ = false;
     51        this->startdelay_ = 0;
     52        this->lifetime_ = 0;
     53        this->destroydelay_ = 0;
    5354
    54     void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
    55     {
    56         ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner));
    57         this->destroydelay_ = destroydelay;
    58         executor->setDefaultValues(lifetime);
    59         this->timer_.setTimer(startdelay, false, this, executor);
    60         this->particle_ = new ParticleInterface(templateName, detaillevel);
    61         this->particle_->addToSceneNode(this->getNode());
    62         this->particle_->setEnabled(false);
    63         if (direction != Vector3::ZERO)
    64         {
    65             this->particle_->getAllEmitters()->setDirection(direction);
    66         }
     55        this->startParticleSpawner();
    6756    }
    6857
    6958    ParticleSpawner::~ParticleSpawner()
    7059    {
    71         if (this->isInitialized() && this->particle_)
    72         {
    73             this->particle_->detachFromSceneNode();
    74             delete this->particle_;
    75         }
    76     };
    77 
    78     void ParticleSpawner::destroy()
    79     {
    80         this->setPosition(this->getNode()->getParent()->getPosition());
    81         this->getNode()->getParent()->removeChild(this->getNode());
    82         this->detachFromParent();
    83         if (this->particle_)
    84             this->particle_->setEnabled(false);
    85         if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)
    86             this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
    8760    }
    8861
    89     void ParticleSpawner::createParticleSpawner(float lifetime)
     62    void ParticleSpawner::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    9063    {
    91         this->particle_->setEnabled(true);
    92         if (lifetime != 0)
    93             this->timer_.setTimer(lifetime, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
     64        SUPER(ParticleSpawner, XMLPort, xmlelement, mode);
     65
     66        XMLPortParam(ParticleSpawner, "autostart",    setAutoStart,        getAutoStart,        xmlelement, mode).defaultValues(true);
     67        XMLPortParam(ParticleSpawner, "autodestroy",  setDestroyAfterLife, getDestroyAfterLife, xmlelement, mode).defaultValues(false);
     68        XMLPortParam(ParticleSpawner, "loop",         setLoop,             getLoop,             xmlelement, mode).defaultValues(false);
     69        XMLPortParam(ParticleSpawner, "lifetime",     setLifetime,         getLifetime,         xmlelement, mode).defaultValues(0.0f);
     70        XMLPortParam(ParticleSpawner, "startdelay",   setStartdelay,       getStartdelay,       xmlelement, mode).defaultValues(0.0f);
     71        XMLPortParam(ParticleSpawner, "destroydelay", setDestroydelay,     getDestroydelay,     xmlelement, mode).defaultValues(0.0f);
     72    }
     73
     74    void ParticleSpawner::processEvent(Event& event)
     75    {
     76        SUPER(ParticleSpawner, processEvent, event);
     77
     78        SetEvent(ParticleSpawner, "spawn", spawn, event);
     79    }
     80
     81    void ParticleSpawner::configure(float lifetime, float startdelay, float destroydelay, bool autodestroy)
     82    {
     83        this->bAutoDestroy_ = autodestroy;
     84        this->startdelay_ = startdelay;
     85        this->lifetime_ = lifetime;
     86        this->destroydelay_ = destroydelay;
     87    }
     88
     89    void ParticleSpawner::startParticleSpawner()
     90    {
     91        if (!this->particles_)
     92            return;
     93
     94        this->particles_->setEnabled(false);
     95
     96        if (this->bForceDestroy_ || this->bSuppressStart_)
     97            return;
     98
     99        this->timer_.setTimer(this->startdelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::fireParticleSpawner)));
     100    }
     101
     102    void ParticleSpawner::fireParticleSpawner()
     103    {
     104        this->particles_->setEnabled(true);
     105        if (this->lifetime_ != 0)
     106            this->timer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&ParticleSpawner::stopParticleSpawner)));
     107    }
     108
     109    void ParticleSpawner::stopParticleSpawner()
     110    {
     111        this->particles_->setEnabled(false);
     112
     113        if (this->bAutoDestroy_ || this->bForceDestroy_)
     114        {
     115            this->setPosition(this->getWorldPosition());
     116            this->detachFromParent();
     117
     118            if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)
     119                this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
     120        }
     121        else if (this->bLoop_)
     122        {
     123            this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::startParticleSpawner)));
     124        }
    94125    }
    95126
     
    98129        delete this;
    99130    }
    100 
    101     void ParticleSpawner::setVisible(bool visible)
    102     {
    103         if (this->particle_)
    104             this->particle_->setEnabled(visible);
    105     }
    106131}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/ParticleSpawner.h

    r2044 r2065  
    3232#include "OrxonoxPrereqs.h"
    3333
    34 #include "PositionableEntity.h"
     34#include "ParticleEmitter.h"
    3535#include "tools/Timer.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport ParticleSpawner : public PositionableEntity
     39    class _OrxonoxExport ParticleSpawner : public ParticleEmitter
    4040    {
    4141        public:
    42             ParticleSpawner();
    43             ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO);
     42            ParticleSpawner(BaseObject* creator);
    4443            virtual ~ParticleSpawner();
    45             void destroy();
    4644
    47             void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO);
    48             inline ParticleInterface* getParticleInterface() const
    49                 { return this->particle_; }
     45            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void processEvent(Event& event);
    5047
    51             void setVisible(bool visible);
     48            inline void destroy()
     49                { this->bForceDestroy_ = true; this->stopParticleSpawner(); }
     50            inline void spawn()
     51                { this->bSuppressStart_ = false; this->startParticleSpawner(); }
     52
     53            void configure(float lifetime = 0, float startdelay = 0, float destroydelay = 0, bool autodestroy = true);
     54
     55            inline void setAutoStart(bool autostart)
     56                { this->bAutostart_ = autostart; this->bSuppressStart_ = !autostart; }
     57            inline bool getAutoStart() const
     58                { return this->bAutostart_; }
     59
     60            inline void setDestroyAfterLife(bool destroy)
     61                { this->bAutoDestroy_ = destroy; }
     62            inline bool getDestroyAfterLife() const
     63                { return this->bAutoDestroy_; }
     64
     65            inline void setLoop(bool loop)
     66                { this->bLoop_ = loop; }
     67            inline bool getLoop() const
     68                { return this->bLoop_; }
     69
     70            inline void setLifetime(float lifetime)
     71                { this->lifetime_ = lifetime; this->startParticleSpawner(); }
     72            inline float getLifetime() const
     73                { return this->lifetime_; }
     74
     75            inline void setStartdelay(float startdelay)
     76                { this->startdelay_ = startdelay; this->startParticleSpawner(); }
     77            inline float getStartdelay() const
     78                { return this->startdelay_; }
     79
     80            inline void setDestroydelay(float destroydelay)
     81                { this->destroydelay_ = destroydelay; this->startParticleSpawner(); }
     82            inline float getDestroydelay() const
     83                { return this->destroydelay_; }
    5284
    5385        private:
    54             void createParticleSpawner(float lifetime);
     86            void startParticleSpawner();
     87            void fireParticleSpawner();
     88            void stopParticleSpawner();
    5589            void destroyParticleSpawner();
    5690
    5791            Timer<ParticleSpawner> timer_;
    58             ParticleInterface* particle_;
     92
     93            bool  bSuppressStart_;
     94            bool  bAutostart_;
     95            bool  bForceDestroy_;
     96            bool  bAutoDestroy_;
     97            bool  bLoop_;
     98            float startdelay_;
     99            float lifetime_;
    59100            float destroydelay_;
    60101    };
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/SpawnPoint.cc

    r2040 r2065  
    7878        {
    7979            this->getGametype()->pawnPreSpawn(entity);
     80
    8081            this->spawn(entity);
     82
    8183            if (this->template_)
    8284                entity->addTemplate(this->template_);
     85
    8386            entity->postSpawn();
     87
    8488            this->getGametype()->pawnPostSpawn(entity);
     89
     90            this->fireEvent();
    8591        }
    8692        return entity;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.h

    r2040 r2065  
    134134                { parent->attach(this); }
    135135            inline void detachFromParent()
    136                 { this->parent_->detach(this); }
     136                { if (this->parent_) { this->parent_->detach(this); } }
    137137            inline WorldEntity* getParent() const
    138138                { return this->parent_; }
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc

    r2031 r2065  
    128128      this->bTriggered_ = (newState & 0x1);
    129129      this->bActive_ = newState & 2;
     130      this->fireEvent(this->bActive_);
    130131      this->stateChanges_.pop();
    131132      if (this->stateChanges_.size() != 0)
Note: See TracChangeset for help on using the changeset viewer.