Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 16, 2008, 6:01:13 PM (15 years ago)
Author:
landauf
Message:

Merged objecthierarchy2 into presentation branch

Couln't merge 2 lines in Gamestate.cc and a whole block of code in GSDedicated.cc (it seems like oli implemented in both branches something like a network-tick-limiter but with different approaches)

Not yet tested in network mode and with bots
The SpaceShips movement is also not yet fully adopted to the new physics (see Engine class)

Location:
code/branches/presentation
Files:
35 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/worldentities/Backlight.cc

    r2459 r2485  
    3030#include "Backlight.h"
    3131
    32 #include <OgreBillboard.h>
    3332#include <OgreRibbonTrail.h>
    3433#include <OgreSceneManager.h>
    3534
     35#include "core/Core.h"
    3636#include "core/CoreIncludes.h"
    37 #include "core/ConfigValueIncludes.h"
    3837#include "core/Executor.h"
    39 #include "util/Math.h"
    40 #include "GraphicsEngine.h"
     38#include "core/XMLPort.h"
     39#include "objects/Scene.h"
     40#include "util/Exception.h"
    4141
    4242namespace orxonox
     
    4444    CreateFactory(Backlight);
    4545
    46     float Backlight::timeFactor_s = 1.0;
    47 
    48     Backlight::Backlight(float maxspeed, float brakingtime, float scale)
     46    Backlight::Backlight(BaseObject* creator) : FadingBillboard(creator)
    4947    {
    5048        RegisterObject(Backlight);
    5149
    52         this->setConfigValues();
    53         this->traillength_ = 1;
    54 
    55         this->configure(maxspeed, brakingtime, scale);
    56     }
    57    
    58     bool Backlight::create(){
    59       if(!WorldEntity::create())
    60         return false;
    61      
    62       this->getNode()->setInheritScale(false);
    63 
    64       this->billboard_.setBillboardSet("Flares/backlightflare");
    65       this->attachObject(this->billboard_.getBillboardSet());
    66 
    67       this->ribbonTrail_ = GraphicsEngine::getInstance().getLevelSceneManager()->createRibbonTrail(this->getName() + "RibbonTrail");
    68       this->ribbonTrailNode_ = GraphicsEngine::getInstance().getLevelSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName() + "RibbonTrailNode");
    69       this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
    70       this->ribbonTrail_->addNode(this->getNode());
    71 
    72 
    73       this->ribbonTrail_->setTrailLength(this->maxTraillength_);
    74       this->ribbonTrail_->setMaterialName("Trail/backlighttrail");
    75 
    76         //this->setTimeFactor(Orxonox::getInstance().getTimeFactor());
    77       this->setTimeFactor(1.0f);
    78      
    79       this->ribbonTrail_->setMaxChainElements(this->maxTrailsegments_);
    80       this->ribbonTrail_->setTrailLength(this->traillength_ = 2 * this->maxTrailsegments_);
    81       this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getScale());
    82       this->ribbonTrail_->setWidthChange(0, this->width_ * this->getScale() / this->maxLifeTime_ * Backlight::timeFactor_s);
    83       return true;
     50        this->ribbonTrail_ = 0;
     51        this->ribbonTrailNode_ = 0;
     52
     53        this->width_ = 0;
     54        this->length_ = 1.0f;
     55        this->lifetime_ = 0.001f;
     56        this->maxelements_ = 1;
     57
     58        this->tickcount_ = 0;
     59
     60        if (Core::showsGraphics())
     61        {
     62            if (!this->getScene())
     63                ThrowException(AbortLoading, "Can't create Backlight, no scene given.");
     64            if (!this->getScene()->getSceneManager())
     65                ThrowException(AbortLoading, "Can't create Backlight, no scene manager given.");
     66            if (!this->getScene()->getRootSceneNode())
     67                ThrowException(AbortLoading, "Can't create Backlight, no root scene node given.");
     68
     69            this->ribbonTrail_ = this->getScene()->getSceneManager()->createRibbonTrail(this->getNode()->getName());
     70
     71            this->ribbonTrailNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
     72            this->ribbonTrailNode_->attachObject(this->ribbonTrail_);
     73
     74            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
     75            this->ribbonTrail_->setTrailLength(this->length_);
     76            this->ribbonTrail_->setInitialWidth(0, 0);
     77        }
     78
     79        this->registerVariables();
    8480    }
    8581
     
    8884        if (this->isInitialized())
    8985        {
    90             this->detachObject(this->billboard_.getBillboardSet());
    91             GraphicsEngine::getInstance().getLevelSceneManager()->destroySceneNode(this->getName() + "RibbonTrailNode");
    92             GraphicsEngine::getInstance().getLevelSceneManager()->destroyRibbonTrail(this->ribbonTrail_);
    93         }
    94     }
    95 
    96     void Backlight::setConfigValues()
    97     {
    98         SetConfigValue(maxLifeTime_, 4.0).description("The maximal amount of seconds the trail behind a SpaceShip stays visible");
    99         SetConfigValue(trailSegmentLength_, 50).description("The length of one segment of the trail behind a SpaceShip (lower values make it more smooth)");
    100         SetConfigValue(width_, 7.0).description("The width of the trail");
    101     }
    102 
    103     void Backlight::setTimeFactor(float factor)
    104     {
    105         Backlight::timeFactor_s = factor;
    106         float change = Backlight::timeFactor_s / this->maxLifeTime_;
    107         this->ribbonTrail_->setWidthChange(0, this->width_ * change);
    108         this->updateColourChange();
    109     }
    110 
    111     void Backlight::updateColourChange()
    112     {
    113         this->ribbonTrail_->setColourChange(0, ColourValue(0, 0, 0, this->maxTraillength_ / this->traillength_ / this->maxLifeTime_ * Backlight::timeFactor_s));
    114     }
    115    
    116    
    117     void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode){
    118       SUPER(Backlight, XMLPort, xmlelement, mode);
    119      
    120       Backlight::create();
     86            if (this->ribbonTrail_)
     87            {
     88                if (this->ribbonTrailNode_)
     89                {
     90                    this->ribbonTrailNode_->detachObject(this->ribbonTrail_);
     91                    this->getScene()->getSceneManager()->destroySceneNode(this->ribbonTrailNode_->getName());
     92                }
     93                this->getScene()->getSceneManager()->destroyRibbonTrail(this->ribbonTrail_);
     94            }
     95        }
     96    }
     97
     98    void Backlight::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     99    {
     100        SUPER(Backlight, XMLPort, xmlelement, mode);
     101
     102        XMLPortParam(Backlight, "length",        setLength,        getLength,        xmlelement, mode).defaultValues(100.0f);
     103        XMLPortParam(Backlight, "width",         setWidth,         getWidth,         xmlelement, mode).defaultValues(1.0f);
     104        XMLPortParam(Backlight, "elements",      setMaxElements,   getMaxElements,   xmlelement, mode).defaultValues(10);
     105        XMLPortParam(Backlight, "lifetime",      setLifetime,      getLifetime,      xmlelement, mode).defaultValues(1.0f);
     106        XMLPortParam(Backlight, "trailmaterial", setTrailMaterial, getTrailMaterial, xmlelement, mode);
     107    }
     108
     109    void Backlight::registerVariables()
     110    {
     111        registerVariable(this->width_,         variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_width));
     112        registerVariable(this->lifetime_,      variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_lifetime));
     113        registerVariable(this->length_,        variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_length));
     114        registerVariable(this->maxelements_,   variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_maxelements));
     115        registerVariable(this->trailmaterial_, variableDirection::toclient, new NetworkCallback<Backlight>(this, &Backlight::update_trailmaterial));
     116    }
     117
     118    void Backlight::changedColour()
     119    {
     120        FadingBillboard::changedColour();
     121
     122        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     123            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
     124    }
     125
     126    void Backlight::update_width()
     127    {
     128        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     129            this->ribbonTrail_->setInitialWidth(0, this->width_ * this->getWorldScale());
     130        this->update_lifetime();
     131    }
     132
     133    void Backlight::update_lifetime()
     134    {
     135        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     136        {
     137            this->ribbonTrail_->setWidthChange(0, this->width_ * this->getWorldScale() / this->lifetime_ * this->getTimeFactor());
     138            this->ribbonTrail_->setColourChange(0, 0, 0, 0, 1.0f / this->lifetime_ * this->getTimeFactor());
     139        }
     140    }
     141
     142    void Backlight::update_length()
     143    {
     144        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     145            this->ribbonTrail_->setTrailLength(this->length_ * this->getWorldScale());
     146    }
     147
     148    void Backlight::update_maxelements()
     149    {
     150        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     151            this->ribbonTrail_->setMaxChainElements(this->maxelements_);
     152    }
     153
     154    void Backlight::update_trailmaterial()
     155    {
     156        if (this->ribbonTrail_ && this->tickcount_ >= 2)
     157            this->ribbonTrail_->setMaterialName(this->trailmaterial_);
     158    }
     159
     160    void Backlight::changedVisibility()
     161    {
     162        SUPER(Backlight, changedVisibility);
     163
     164        if (this->ribbonTrail_)
     165            this->ribbonTrail_->setVisible(this->isVisible());
     166    }
     167
     168    void Backlight::startturnonoff()
     169    {
     170        FadingBillboard::startturnonoff();
     171
     172        if (this->ribbonTrail_ && this->isActive() && this->isVisible())
     173            this->ribbonTrail_->setVisible(true);
     174    }
     175
     176    void Backlight::stopturnonoff()
     177    {
     178        this->postprocessingtime_ = max(0.0f, this->lifetime_ - this->turnofftime_);
     179
     180        FadingBillboard::stopturnonoff();
     181
     182        if (this->ribbonTrail_)
     183            this->ribbonTrail_->setInitialColour(0, this->getFadedColour());
     184    }
     185
     186    void Backlight::poststopturnonoff()
     187    {
     188        FadingBillboard::poststopturnonoff();
     189
     190        if (this->ribbonTrail_)
     191            this->ribbonTrail_->setVisible(false);
     192    }
     193
     194    void Backlight::changedScale()
     195    {
     196        SUPER(Backlight, changedScale);
     197
     198        this->update_width();
     199        this->update_length();
    121200    }
    122201
    123202    void Backlight::tick(float dt)
    124203    {
     204        if (this->tickcount_ < 2)
     205        {
     206            ++this->tickcount_;
     207            if (this->tickcount_ == 2)
     208            {
     209                this->changedColour();
     210                this->update_width();
     211                this->update_lifetime();
     212                this->update_length();
     213                this->update_maxelements();
     214                this->update_trailmaterial();
     215                if (this->ribbonTrail_)
     216                    this->ribbonTrail_->addNode(const_cast<Ogre::SceneNode*>(this->getNode()));
     217            }
     218        }
     219
    125220        SUPER(Backlight, tick, dt);
    126221
    127         if (this->isActive())
    128         {
    129             if (this->traillength_ < this->maxTraillength_)
    130             {
    131                 this->traillength_ = min<float>(this->maxTraillength_, this->traillength_ + dt * this->maxTraillength_ / this->maxLifeTime_);
    132                 this->updateColourChange();
    133             }
    134         }
    135         else
    136         {
    137             if (this->traillength_ > 1)
    138             {
    139                 this->traillength_ = max<float>(1, this->traillength_ - this->brakefactor_ * dt * this->maxTraillength_ / this->maxLifeTime_);
    140                 this->updateColourChange();
    141             }
    142         }
    143 
    144         this->ribbonTrail_->setTrailLength(this->traillength_);
    145     }
    146 
    147     void Backlight::setColour(const ColourValue& colour)
    148     {
    149         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    150         this->ribbonTrail_->setInitialColour(0, ColourValue(colour.r / 4 + 0.75, colour.g / 4 + 0.75, colour.b / 4 + 0.75));
    151     }
    152 
    153     void Backlight::configure(float maxspeed, float brakingtime, float scale)
    154     {
    155         this->maxTraillength_ = this->maxLifeTime_ * maxspeed;
    156         this->maxTrailsegments_ = (size_t)(this->maxTraillength_ / this->trailSegmentLength_);
    157 
    158         this->brakefactor_ = this->maxLifeTime_ / brakingtime;
    159 
    160         this->scale(scale);
    161     }
    162 
    163     void Backlight::changedVisibility()
    164     {
    165         SUPER(Backlight, changedVisibility);
    166 
    167         this->billboard_.setVisible(this->isVisible());
    168         this->ribbonTrail_->setVisible(this->isVisible());
     222        if (this->ribbonTrail_ && this->changedirection_ != 0)
     223        {
     224            // we use alpha_blend, only adjust alpha
     225            const ColourValue& colour = this->getColour();
     226            this->ribbonTrail_->setInitialColour(0, colour.r, colour.g, colour.b, this->getFadedColour().a);
     227        }
     228    }
     229
     230    void Backlight::changedTimeFactor(float factor_new, float factor_old)
     231    {
     232        this->update_lifetime();
    169233    }
    170234}
  • code/branches/presentation/src/orxonox/objects/worldentities/Backlight.h

    r2459 r2485  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 
    34 #include "StaticEntity.h"
    35 #include "tools/BillboardSet.h"
     33#include "FadingBillboard.h"
     34#include "gamestates/GSRoot.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport Backlight : public StaticEntity
     38    class _OrxonoxExport Backlight : public FadingBillboard, public TimeFactorListener
    4039    {
    4140        public:
    42             Backlight(float maxspeed = 1.0, float brakingtime = 1.0, float scale = 1.0);
     41            Backlight(BaseObject* creator);
    4342            virtual ~Backlight();
    4443
    45             void setConfigValues();
    4644            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     45            void registerVariables();
     46
    4747            virtual void tick(float dt);
    4848            virtual void changedVisibility();
    49             virtual bool create();
    5049
    51             void setColour(const ColourValue& colour);
    52             void setTimeFactor(float factor);
     50            inline void setWidth(float width)
     51                { this->width_ = width; this->update_width(); }
     52            inline float getWidth() const
     53                { return this->width_; }
     54
     55            inline void setLifetime(float lifetime)
     56                { this->lifetime_ = lifetime; this->update_lifetime(); }
     57            inline float getLifetime() const
     58                { return this->lifetime_; }
     59
     60            inline void setLength(float length)
     61                { this->length_ = length; this->update_length(); }
     62            inline float getLength() const
     63                { return this->length_; }
     64
     65            inline void setMaxElements(size_t maxelements)
     66                { this->maxelements_ = maxelements; this->update_maxelements(); }
     67            inline size_t getMaxElements() const
     68                { return this->maxelements_; }
     69
     70            inline void setTrailMaterial(const std::string& material)
     71                { this->trailmaterial_ = material; this->update_trailmaterial(); }
     72            inline const std::string& getTrailMaterial() const
     73                { return this->trailmaterial_; }
     74
     75            virtual void changedScale();
     76
     77        protected:
     78            virtual void changedTimeFactor(float factor_new, float factor_old);
    5379
    5480        private:
    55             void configure(float maxspeed, float brakingtime, float scale = 1);
    56             void updateColourChange();
     81            virtual void startturnonoff();
     82            virtual void stopturnonoff();
     83            virtual void poststopturnonoff();
     84            virtual void changedColour();
     85            void update_width();
     86            void update_lifetime();
     87            void update_length();
     88            void update_maxelements();
     89            void update_trailmaterial();
    5790
    58             static float timeFactor_s;
    59             BillboardSet billboard_;
     91            Ogre::RibbonTrail* ribbonTrail_;
    6092            Ogre::SceneNode* ribbonTrailNode_;
    61             Ogre::RibbonTrail* ribbonTrail_;
    62 
    63             float maxLifeTime_;
    64             float trailSegmentLength_;
    6593            float width_;
    66 
    67             float brakefactor_;
    68 
    69             float maxTraillength_;
    70             float traillength_;
    71 
    72             size_t maxTrailsegments_;
     94            float length_;
     95            float lifetime_;
     96            size_t maxelements_;
     97            std::string trailmaterial_;
     98            char tickcount_;
    7399    };
    74100}
  • code/branches/presentation/src/orxonox/objects/worldentities/Billboard.cc

    r2459 r2485  
    4444        RegisterObject(Billboard);
    4545
     46        this->material_ = "";
     47        this->colour_ = ColourValue::White;
     48
    4649        this->registerVariables();
    4750    }
     
    5255        {
    5356            if (this->isInitialized() && this->billboard_.getBillboardSet())
    54                 this->detachOgreObject(this->billboard_.getName());
     57                this->detachOgreObject(this->billboard_.getBillboardSet());
    5558        }
    5659    }
     
    7275    void Billboard::changedMaterial()
    7376    {
     77        if (this->material_ == "")
     78            return;
     79
    7480        if (!this->billboard_.getBillboardSet())
    7581        {
     
    9096        if (!this->billboard_.getBillboardSet())
    9197        {
    92             if (this->getScene() && this->getScene()->getSceneManager())
     98/*
     99            if (this->getScene() && this->getScene()->getSceneManager() && (this->material_ != ""))
    93100            {
    94101                this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), this->material_, this->colour_, 1);
     
    97104                this->billboard_.setVisible(this->isVisible());
    98105            }
     106*/
    99107        }
    100108        else
  • code/branches/presentation/src/orxonox/objects/worldentities/Billboard.h

    r2459 r2485  
    6161                { return this->colour_; }
    6262
     63        protected:
     64            inline BillboardSet& getBillboardSet()
     65                { return this->billboard_; }
     66
     67            virtual void changedColour();
     68
    6369        private:
    6470            void changedMaterial();
    65             void changedColour();
    6671
    6772            BillboardSet billboard_;
  • code/branches/presentation/src/orxonox/objects/worldentities/BlinkingBillboard.cc

    r2171 r2485  
    6868    void BlinkingBillboard::registerVariables()
    6969    {
    70 //        REGISTERDATA(this->amplitude_, direction::toclient);
    71 //        REGISTERDATA(this->frequency_, direction::toclient);
    72 //        REGISTERDATA(this->phase_,     direction::toclient);
     70//        registerVariable(this->amplitude_, variableDirection::toclient);
     71//        registerVariable(this->frequency_, variableDirection::toclient);
     72//        registerVariable(this->phase_,     variableDirection::toclient);
    7373    }
    7474
    7575    void BlinkingBillboard::tick(float dt)
    7676    {
     77        SUPER(BlinkingBillboard, tick, dt);
     78
    7779        if (Core::isMaster() && this->isActive())
    7880        {
  • code/branches/presentation/src/orxonox/objects/worldentities/CMakeLists.txt

    r2459 r2485  
    55  MobileEntity.cc
    66  ControllableEntity.cc
    7   Model.cc
     7
     8  Backlight.cc
    89  Billboard.cc
    910  BlinkingBillboard.cc
     11  ExplosionChunk.cc
     12  FadingBillboard.cc
    1013  Light.cc
    1114  Camera.cc
    1215  CameraPosition.cc
    13   SpawnPoint.cc
     16  Model.cc
    1417  ParticleEmitter.cc
    1518  ParticleSpawner.cc
    1619  Planet.cc
    17 #  Backlight.cc
     20  SpawnPoint.cc
    1821)
    1922
  • code/branches/presentation/src/orxonox/objects/worldentities/Camera.cc

    r2459 r2485  
    3636#include <OgreSceneManager.h>
    3737#include <OgreSceneNode.h>
    38 #include <OgreViewport.h>
    3938
    4039#include "util/Exception.h"
     
    5251        RegisterObject(Camera);
    5352
    54         if (!this->getScene() || !this->getScene()->getSceneManager())
    55             ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given.");
     53        if (!this->getScene())
     54            ThrowException(AbortLoading, "Can't create Camera, no scene.");
     55        if (!this->getScene()->getSceneManager())
     56            ThrowException(AbortLoading, "Can't create Camera, no scene-manager given.");
     57        if (!this->getScene()->getRootSceneNode())
     58            ThrowException(AbortLoading, "Can't create Camera, no root-scene-node given.");
    5659
    5760        this->camera_ = this->getScene()->getSceneManager()->createCamera(getUniqueNumberString());
    58         this->attachOgreObject(this->camera_);
     61        this->cameraNode_ = this->getScene()->getRootSceneNode()->createChildSceneNode();
     62        this->attachNode(this->cameraNode_);
     63        this->cameraNode_->attachObject(this->camera_);
    5964
    6065        this->bHasFocus_ = false;
     
    6671        this->setConfigValues();
    6772        this->configvaluecallback_changedNearClipDistance();
    68 
    69         this->requestFocus(); // ! HACK ! REMOVE THIS !
    7073    }
    7174
     
    7578        {
    7679            this->releaseFocus();
     80
     81            this->cameraNode_->detachAllObjects();
     82            this->getScene()->getSceneManager()->destroyCamera(this->camera_);
     83
     84            if (this->bDrag_)
     85                this->detachNode(this->cameraNode_);
     86
     87            if (this->getScene()->getSceneManager())
     88                this->getScene()->getSceneManager()->destroySceneNode(this->cameraNode_->getName());
    7789        }
    7890    }
     
    90102    void Camera::tick(float dt)
    91103    {
    92 /*
    93         // this stuff here may need some adjustments
    94         float coeff = (this->bDrag_) ? min(1.0f, 15.0f * dt) : (1.0f);
     104        SUPER(Camera, tick, dt);
    95105
    96         Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition();
    97         this->cameraNode_->translate(coeff * offset);
     106        if (this->bDrag_)
     107        {
     108            // this stuff here may need some adjustments
     109            float coeff = min(1.0f, 15.0f * dt);
    98110
    99         this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false));
    100 */
     111            Vector3 offset = this->getNode()->getWorldPosition() - this->cameraNode_->getWorldPosition();
     112            this->cameraNode_->translate(coeff * offset);
     113
     114            this->cameraNode_->setOrientation(Quaternion::Slerp(coeff, this->cameraNode_->getWorldOrientation(), this->getWorldOrientation(), false));
     115            //this->cameraNode_->setOrientation(this->getWorldOrientation());
     116        }
    101117    }
    102118
     
    120136    }
    121137
    122     void Camera::setFocus(Ogre::Viewport* viewport)
     138    void Camera::setFocus()
    123139    {
    124140        this->bHasFocus_ = true;
    125         viewport->setCamera(this->camera_);
     141        CameraManager::getInstance().useCamera(this->camera_);
     142    }
     143
     144    void Camera::setDrag(bool bDrag)
     145    {
     146        if (bDrag != this->bDrag_)
     147        {
     148            this->bDrag_ = bDrag;
     149
     150            if (!bDrag)
     151            {
     152                this->attachNode(this->cameraNode_);
     153                this->cameraNode_->setPosition(Vector3::ZERO);
     154                this->cameraNode_->setOrientation(Quaternion::IDENTITY);
     155            }
     156            else
     157            {
     158                this->detachNode(this->cameraNode_);
     159                this->cameraNode_->setPosition(this->getWorldPosition());
     160                this->cameraNode_->setOrientation(this->getWorldOrientation());
     161            }
     162        }
    126163    }
    127164}
  • code/branches/presentation/src/orxonox/objects/worldentities/Camera.h

    r2459 r2485  
    5555                { return this->bHasFocus_; }
    5656
    57             inline void setDrag(bool bDrag)
    58                 { this->bDrag_ = bDrag; }
     57            void setDrag(bool bDrag);
    5958            inline bool getDrag() const
    6059                { return this->bDrag_; }
     
    6261        private:
    6362            void removeFocus();
    64             void setFocus(Ogre::Viewport* viewport);
     63            void setFocus();
    6564            void configvaluecallback_changedNearClipDistance();
    6665
    67             Ogre::Camera*   camera_;
    68             float           nearClipDistance_;
    69             bool            bHasFocus_;
    70             bool            bDrag_;
     66            Ogre::Camera*    camera_;
     67            Ogre::SceneNode* cameraNode_;
     68            float            nearClipDistance_;
     69            bool             bHasFocus_;
     70            bool             bDrag_;
    7171    };
    7272}
  • code/branches/presentation/src/orxonox/objects/worldentities/CameraPosition.cc

    r2459 r2485  
    4343
    4444        this->bDrag_ = false;
     45        this->bAllowMouseLook_ = false;
    4546
    4647        this->setObjectMode(0x0);
     
    5657
    5758        XMLPortParam(CameraPosition, "drag", setDrag, getDrag, xmlelement, mode).defaultValues(false);
     59        XMLPortParam(CameraPosition, "mouselook", setAllowMouseLook, getAllowMouseLook, xmlelement, mode).defaultValues(false);
    5860    }
    5961
    6062    void CameraPosition::attachCamera(Camera* camera)
    6163    {
    62         camera->setDrag(this->bDrag_);
     64        if (!this->bDrag_)
     65            camera->setDrag(false);
     66
    6367        this->attach(camera);
     68
     69        if (this->bDrag_)
     70            camera->setDrag(true);
    6471    }
    6572}
  • code/branches/presentation/src/orxonox/objects/worldentities/CameraPosition.h

    r2459 r2485  
    4949                { return this->bDrag_; }
    5050
     51            inline void setAllowMouseLook(bool bAllow)
     52                { this->bAllowMouseLook_ = bAllow; }
     53            inline bool getAllowMouseLook() const
     54                { return this->bAllowMouseLook_; }
     55
    5156            void attachCamera(Camera* camera);
    5257
    5358        private:
    5459            bool bDrag_;
     60            bool bAllowMouseLook_;
    5561    };
    5662}
  • code/branches/presentation/src/orxonox/objects/worldentities/ControllableEntity.cc

    r2474 r2485  
    3030#include "ControllableEntity.h"
    3131
     32#include <OgreSceneManager.h>
     33
    3234#include "core/CoreIncludes.h"
     35#include "core/ConfigValueIncludes.h"
    3336#include "core/Core.h"
    3437#include "core/XMLPort.h"
    3538#include "core/Template.h"
    3639
     40#include "objects/Scene.h"
    3741#include "objects/infos/PlayerInfo.h"
    3842#include "objects/worldentities/Camera.h"
    3943#include "objects/worldentities/CameraPosition.h"
     44#include "objects/gametypes/Gametype.h"
    4045#include "overlays/OverlayGroup.h"
    4146
     
    4853        RegisterObject(ControllableEntity);
    4954
    50         this->bControlled_ = false;
     55        this->bHasLocalController_ = false;
     56        this->bHasHumanController_ = false;
     57
    5158        this->server_overwrite_ = 0;
    5259        this->client_overwrite_ = 0;
     
    5663        this->camera_ = 0;
    5764        this->bDestroyWhenPlayerLeft_ = false;
     65        this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
     66        this->bMouseLook_ = false;
     67        this->mouseLookSpeed_ = 200;
     68
     69        this->gtinfo_ = 0;
     70        this->gtinfoID_ = OBJECTID_UNKNOWN;
     71        this->changedGametype();
    5872
    5973        this->server_position_         = Vector3::ZERO;
     
    6781
    6882
     83        this->setConfigValues();
    6984        this->setPriority( priority::very_high );
    7085        this->registerVariables();
     
    7590        if (this->isInitialized())
    7691        {
    77             if (this->bControlled_)
    78                 this->stopLocalControl();
     92            this->bDestroyWhenPlayerLeft_ = false;
     93
     94            if (this->bHasLocalController_ && this->bHasHumanController_)
     95                this->stopLocalHumanControl();
     96
     97            if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
     98                this->getPlayer()->stopControl(this, false);
    7999
    80100            if (this->hud_)
     
    84104                delete this->camera_;
    85105
    86             if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
    87                 this->getPlayer()->stopControl(this, false);
     106            for (std::list<CameraPosition*>::const_iterator it = this->cameraPositions_.begin(); it != this->cameraPositions_.end(); ++it)
     107                delete (*it);
     108
     109            if (this->getScene()->getSceneManager())
     110                this->getScene()->getSceneManager()->destroySceneNode(this->cameraPositionRootNode_->getName());
    88111        }
    89112    }
     
    99122    }
    100123
     124    void ControllableEntity::setConfigValues()
     125    {
     126        SetConfigValue(mouseLookSpeed_, 3.0f);
     127    }
     128
     129    void ControllableEntity::changedGametype()
     130    {
     131        //SUPER(ControllableEntity, changedGametype);
     132        WorldEntity::changedGametype();
     133
     134        this->gtinfo_ = 0;
     135        this->gtinfoID_ = OBJECTID_UNKNOWN;
     136
     137        if (this->getGametype() && this->getGametype()->getGametypeInfo())
     138        {
     139            this->gtinfo_ = this->getGametype()->getGametypeInfo();
     140            this->gtinfoID_ = this->gtinfo_->getObjectID();
     141        }
     142    }
     143
    101144    void ControllableEntity::addCameraPosition(CameraPosition* position)
    102145    {
    103         this->attach(position);
     146        if (position->getAllowMouseLook())
     147            position->attachToNode(this->cameraPositionRootNode_);
     148        else
     149            this->attach(position);
    104150        this->cameraPositions_.push_back(position);
    105151    }
     
    142188            else
    143189            {
    144                 this->attach(this->camera_);
     190                this->camera_->attachToNode(this->cameraPositionRootNode_);
    145191            }
    146192        }
     193    }
     194
     195    void ControllableEntity::mouseLook()
     196    {
     197        this->bMouseLook_ = !this->bMouseLook_;
     198
     199        if (!this->bMouseLook_)
     200            this->cameraPositionRootNode_->setOrientation(Quaternion::IDENTITY);
     201    }
     202
     203    void ControllableEntity::rotateYaw(const Vector2& value)
     204    {
     205        if (this->bMouseLook_)
     206            this->cameraPositionRootNode_->yaw(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
     207    }
     208
     209    void ControllableEntity::rotatePitch(const Vector2& value)
     210    {
     211        if (this->bMouseLook_)
     212            this->cameraPositionRootNode_->pitch(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
     213    }
     214
     215    void ControllableEntity::rotateRoll(const Vector2& value)
     216    {
     217        if (this->bMouseLook_)
     218            this->cameraPositionRootNode_->roll(Radian(value.y * this->mouseLookSpeed_), Ogre::Node::TS_LOCAL);
    147219    }
    148220
     
    157229        this->player_ = player;
    158230        this->playerID_ = player->getObjectID();
    159         this->bControlled_ = (player->isLocalPlayer() && player->isHumanPlayer());
    160         if (this->bControlled_)
    161         {
    162             this->startLocalControl();
     231        this->bHasLocalController_ = player->isLocalPlayer();
     232        this->bHasHumanController_ = player->isHumanPlayer();
     233
     234        if (this->bHasLocalController_ && this->bHasHumanController_)
     235        {
     236            this->startLocalHumanControl();
    163237
    164238            if (!Core::isMaster())
    165239            {
    166240                this->client_overwrite_ = this->server_overwrite_;
    167 COUT(0) << "CE: bidirectional synchronization" << std::endl;
    168241                this->setObjectMode(objectDirection::bidirectional);
    169242            }
     
    173246    void ControllableEntity::removePlayer()
    174247    {
    175         if (this->bControlled_)
    176             this->stopLocalControl();
     248        if (this->bHasLocalController_ && this->bHasHumanController_)
     249            this->stopLocalHumanControl();
    177250
    178251        this->player_ = 0;
    179252        this->playerID_ = OBJECTID_UNKNOWN;
    180         this->bControlled_ = false;
     253        this->bHasLocalController_ = false;
     254        this->bHasHumanController_ = false;
    181255        this->setObjectMode(objectDirection::toclient);
    182256
     
    196270    }
    197271
    198     void ControllableEntity::startLocalControl()
    199     {
    200 //        std::cout << this->getObjectID() << " ###### start local control" << std::endl;
    201         this->camera_ = new Camera(this);
    202         this->camera_->requestFocus();
    203         if (this->cameraPositionTemplate_ != "")
    204             this->addTemplate(this->cameraPositionTemplate_);
    205         if (this->cameraPositions_.size() > 0)
    206             this->cameraPositions_.front()->attachCamera(this->camera_);
    207         else
    208             this->attach(this->camera_);
    209 
    210         if (this->hudtemplate_ != "")
    211         {
    212             this->hud_ = new OverlayGroup(this);
    213             this->hud_->addTemplate(this->hudtemplate_);
    214         }
    215     }
    216 
    217     void ControllableEntity::stopLocalControl()
    218     {
    219 //        std::cout << "###### stop local control" << std::endl;
    220         this->camera_->detachFromParent();
    221         delete this->camera_;
    222         this->camera_ = 0;
    223 
    224         delete this->hud_;
    225         this->hud_ = 0;
     272    void ControllableEntity::networkcallback_changedgtinfoID()
     273    {
     274        if (this->gtinfoID_ != OBJECTID_UNKNOWN)
     275        {
     276            this->gtinfo_ = dynamic_cast<GametypeInfo*>(Synchronisable::getSynchronisable(this->gtinfoID_));
     277
     278            if (!this->gtinfo_)
     279                this->gtinfoID_ = OBJECTID_UNKNOWN;
     280        }
     281    }
     282
     283    void ControllableEntity::startLocalHumanControl()
     284    {
     285        if (!this->camera_)
     286        {
     287            this->camera_ = new Camera(this);
     288            this->camera_->requestFocus();
     289            if (this->cameraPositionTemplate_ != "")
     290                this->addTemplate(this->cameraPositionTemplate_);
     291            if (this->cameraPositions_.size() > 0)
     292                this->cameraPositions_.front()->attachCamera(this->camera_);
     293            else
     294                this->camera_->attachToNode(this->cameraPositionRootNode_);
     295        }
     296
     297        if (!this->hud_)
     298        {
     299            if (this->hudtemplate_ != "")
     300            {
     301                this->hud_ = new OverlayGroup(this);
     302                this->hud_->addTemplate(this->hudtemplate_);
     303                this->hud_->setOwner(this);
     304            }
     305        }
     306    }
     307
     308    void ControllableEntity::stopLocalHumanControl()
     309    {
     310        if (this->camera_)
     311        {
     312            this->camera_->detachFromParent();
     313            delete this->camera_;
     314            this->camera_ = 0;
     315        }
     316
     317        if (this->hud_)
     318        {
     319            delete this->hud_;
     320            this->hud_ = 0;
     321        }
    226322    }
    227323
     
    242338                    this->server_angular_velocity_ = this->getAngularVelocity();
    243339                }
    244                 else if (this->bControlled_)
     340                else if (this->bHasLocalController_)
    245341                {
    246342                    this->client_position_ = this->getPosition();
     
    255351    void ControllableEntity::registerVariables()
    256352    {
    257         registerVariable(this->cameraPositionTemplate_, variableDirection::toclient);
     353        registerVariable(this->cameraPositionTemplate_,  variableDirection::toclient);
     354        registerVariable(this->hudtemplate_,             variableDirection::toclient);
    258355
    259356        registerVariable(this->server_position_,         variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::processServerPosition));
     
    271368
    272369        registerVariable(this->playerID_,                variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedplayerID));
     370        registerVariable(this->gtinfoID_,                variableDirection::toclient, new NetworkCallback<ControllableEntity>(this, &ControllableEntity::networkcallback_changedgtinfoID));
    273371    }
    274372
    275373    void ControllableEntity::processServerPosition()
    276374    {
    277         if (!this->bControlled_)
     375        if (!this->bHasLocalController_)
    278376            MobileEntity::setPosition(this->server_position_);
    279377    }
     
    281379    void ControllableEntity::processServerLinearVelocity()
    282380    {
    283         if (!this->bControlled_)
     381        if (!this->bHasLocalController_)
    284382            MobileEntity::setVelocity(this->server_linear_velocity_);
    285383    }
     
    287385    void ControllableEntity::processServerOrientation()
    288386    {
    289         if (!this->bControlled_)
     387        if (!this->bHasLocalController_)
    290388            MobileEntity::setOrientation(this->server_orientation_);
    291389    }
     
    293391    void ControllableEntity::processServerAngularVelocity()
    294392    {
    295         if (!this->bControlled_)
     393        if (!this->bHasLocalController_)
    296394            MobileEntity::setAngularVelocity(this->server_angular_velocity_);
    297395    }
     
    299397    void ControllableEntity::processOverwrite()
    300398    {
    301         if (this->bControlled_)
     399        if (this->bHasLocalController_)
    302400        {
    303401            this->setPosition(this->server_position_);
     
    354452            ++this->server_overwrite_;
    355453        }
    356         else if (this->bControlled_)
     454        else if (this->bHasLocalController_)
    357455        {
    358456            MobileEntity::setPosition(position);
     
    369467            ++this->server_overwrite_;
    370468        }
    371         else if (this->bControlled_)
     469        else if (this->bHasLocalController_)
    372470        {
    373471            MobileEntity::setOrientation(orientation);
     
    384482            ++this->server_overwrite_;
    385483        }
    386         else if (this->bControlled_)
     484        else if (this->bHasLocalController_)
    387485        {
    388486            MobileEntity::setVelocity(velocity);
     
    399497            ++this->server_overwrite_;
    400498        }
    401         else if (this->bControlled_)
     499        else if (this->bHasLocalController_)
    402500        {
    403501            MobileEntity::setAngularVelocity(velocity);
     
    416514            this->server_angular_velocity_ = this->getAngularVelocity();
    417515        }
    418         else if (this->bControlled_)
     516        else if (this->bHasLocalController_)
    419517        {
    420518            this->client_position_ = this->getPosition();
  • code/branches/presentation/src/orxonox/objects/worldentities/ControllableEntity.h

    r2459 r2485  
    4545            virtual void tick(float dt);
    4646            void registerVariables();
     47            void setConfigValues();
     48
     49            virtual void changedGametype();
    4750
    4851            virtual void setPlayer(PlayerInfo* player);
     
    6063            virtual void moveUpDown(const Vector2& value) {}
    6164
    62             virtual void rotateYaw(const Vector2& value) {}
    63             virtual void rotatePitch(const Vector2& value) {}
    64             virtual void rotateRoll(const Vector2& value) {}
     65            virtual void rotateYaw(const Vector2& value);
     66            virtual void rotatePitch(const Vector2& value);
     67            virtual void rotateRoll(const Vector2& value);
     68
     69            inline void moveFrontBack(float value)
     70                { this->moveFrontBack(Vector2(value, 0)); }
     71            inline void moveRightLeft(float value)
     72                { this->moveRightLeft(Vector2(value, 0)); }
     73            inline void moveUpDown(float value)
     74                { this->moveUpDown(Vector2(value, 0)); }
     75
     76            inline void rotateYaw(float value)
     77                { this->rotateYaw(Vector2(value, 0)); }
     78            inline void rotatePitch(float value)
     79                { this->rotatePitch(Vector2(value, 0)); }
     80            inline void rotateRoll(float value)
     81                { this->rotateRoll(Vector2(value, 0)); }
    6582
    6683            virtual void fire() {}
    6784            virtual void altFire() {}
    6885
     86            virtual void boost() {}
    6987            virtual void greet() {}
    7088            virtual void use() {}
    7189            virtual void switchCamera();
     90            virtual void mouseLook();
    7291
    7392            inline const std::string& getHudTemplate() const
     
    99118            void setAngularVelocity(const Vector3& velocity);
    100119
     120            inline bool hasLocalController() const
     121                { return this->bHasLocalController_; }
     122            inline bool hasHumanController() const
     123                { return this->bHasHumanController_; }
     124
     125            inline const GametypeInfo* getGametypeInfo() const
     126                { return this->gtinfo_; }
     127
     128            inline bool isInMouseLook() const
     129                { return this->bMouseLook_; }
     130            inline float getMouseLookSpeed() const
     131                { return this->mouseLookSpeed_; }
     132
    101133        protected:
    102             virtual void startLocalControl();
    103             virtual void stopLocalControl();
     134            virtual void startLocalHumanControl();
     135            virtual void stopLocalHumanControl();
    104136
    105137            inline void setHudTemplate(const std::string& name)
    106138                { this->hudtemplate_ = name; }
    107 
    108             inline bool isLocallyControlled() const
    109                 { return this->bControlled_; }
    110139
    111140        private:
     
    124153
    125154            void networkcallback_changedplayerID();
     155            void networkcallback_changedgtinfoID();
    126156
    127157            // Bullet btMotionState related
     
    131161            unsigned int client_overwrite_;
    132162
    133             bool bControlled_;
     163            bool bHasLocalController_;
     164            bool bHasHumanController_;
     165            bool bDestroyWhenPlayerLeft_;
     166
    134167            Vector3 server_position_;
    135168            Vector3 client_position_;
     
    143176            PlayerInfo* player_;
    144177            unsigned int playerID_;
     178
    145179            std::string hudtemplate_;
    146180            OverlayGroup* hud_;
     181
    147182            Camera* camera_;
    148             bool bDestroyWhenPlayerLeft_;
    149 
     183            bool bMouseLook_;
     184            float mouseLookSpeed_;
     185            Ogre::SceneNode* cameraPositionRootNode_;
    150186            std::list<CameraPosition*> cameraPositions_;
    151187            std::string cameraPositionTemplate_;
     188
     189            const GametypeInfo* gtinfo_;
     190            unsigned int gtinfoID_;
    152191    };
    153192}
  • code/branches/presentation/src/orxonox/objects/worldentities/ExplosionChunk.cc

    r2480 r2485  
    3030#include "ExplosionChunk.h"
    3131
     32#include <OgreParticleSystem.h>
     33
    3234#include "core/Core.h"
    3335#include "core/CoreIncludes.h"
     
    5456        {
    5557            this->fire_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/fire4", this->LOD_);
    56             this->fire_->addToSceneNode(this->getNode());
     58            this->attachOgreObject(this->fire_->getParticleSystem());
    5759            this->smoke_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/smoke7", this->LOD_);
    58             this->smoke_->addToSceneNode(this->getNode());
     60            this->attachOgreObject(this->smoke_->getParticleSystem());
    5961        }
    6062        catch (...)
     
    8385        {
    8486            if (this->fire_)
     87            {
     88                this->detachOgreObject(this->fire_->getParticleSystem());
    8589                delete this->fire_;
     90            }
    8691            if (this->smoke_)
     92            {
     93                this->detachOgreObject(this->smoke_->getParticleSystem());
    8794                delete this->smoke_;
     95            }
    8896        }
    8997    }
     
    9199    void ExplosionChunk::registerVariables()
    92100    {
    93         REGISTERDATA(this->LOD_,   direction::toclient, new NetworkCallback<ExplosionChunk>(this, &ExplosionChunk::LODchanged));
    94         REGISTERDATA(this->bStop_, direction::toclient, new NetworkCallback<ExplosionChunk>(this, &ExplosionChunk::checkStop));
     101        registerVariable((int&)(this->LOD_), variableDirection::toclient, new NetworkCallback<ExplosionChunk>(this, &ExplosionChunk::LODchanged));
     102        registerVariable(this->bStop_,       variableDirection::toclient, new NetworkCallback<ExplosionChunk>(this, &ExplosionChunk::checkStop));
    95103    }
    96104
  • code/branches/presentation/src/orxonox/objects/worldentities/FadingBillboard.cc

    r2480 r2485  
    6666    void FadingBillboard::registerVariables()
    6767    {
    68         REGISTERDATA(this->turnontime_,         direction::toclient);
    69         REGISTERDATA(this->turnofftime_,        direction::toclient);
     68        registerVariable(this->turnontime_,  variableDirection::toclient);
     69        registerVariable(this->turnofftime_, variableDirection::toclient);
    7070    }
    7171
  • code/branches/presentation/src/orxonox/objects/worldentities/Light.cc

    r2459 r2485  
    3636
    3737#include "util/String.h"
    38 #include "util/Convert.h"
     38#include "util/Exception.h"
     39#include "core/Core.h"
    3940#include "core/CoreIncludes.h"
    4041#include "core/XMLPort.h"
     
    4344namespace orxonox
    4445{
    45     unsigned int Light::lightCounter_s = 0;
    46 
    4746    CreateFactory(Light);
    4847
     
    5150        RegisterObject(Light);
    5251
    53         if (this->getScene() && this->getScene()->getSceneManager())
    54         this->light_ = this->getScene()->getSceneManager()->createLight("Light" + convertToString(Light::lightCounter_s++));
    55         this->attachOgreObject(this->light_);
     52        this->light_ = 0;
     53        this->diffuse_ = ColourValue::White;
     54        this->specular_ = ColourValue::White;
     55        this->type_ = Ogre::Light::LT_POINT;
     56        this->attenuation_ = Vector4(100000, 1, 0, 0);
     57        this->spotlightRange_ = Vector3(40.0f, 30.0f, 1.0f);
     58
     59        if (Core::showsGraphics())
     60        {
     61            if (!this->getScene())
     62                ThrowException(AbortLoading, "Can't create Light, no scene given.");
     63            if (!this->getScene()->getSceneManager())
     64                ThrowException(AbortLoading, "Can't create Light, no scene manager given.");
     65
     66            if (this->getScene() && this->getScene()->getSceneManager())
     67            {
     68                this->light_ = this->getScene()->getSceneManager()->createLight("Light" + getUniqueNumberString());
     69                this->light_->setDirection(WorldEntity::FRONT);
     70                this->attachOgreObject(this->light_);
     71
     72                this->updateType();
     73                this->updateDiffuseColour();
     74                this->updateSpecularColour();
     75                this->updateAttenuation();
     76                this->updateSpotlightRange();
     77            }
     78        }
    5679
    5780        this->registerVariables();
     
    7194        SUPER(Light, XMLPort, xmlelement, mode);
    7295
    73         XMLPortParam(Light, "type", setTypeString, getTypeString, xmlelement, mode).defaultValues("point");
    74         XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "diffuse",   setDiffuseColour,  getDiffuseColour,  xmlelement, mode, const ColourValue&);
    75         XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "specular",  setSpecularColour, getSpecularColour, xmlelement, mode, const ColourValue&);
    76         XMLPortParamExternTemplate(Light, Ogre::Light, this->light_, "direction", setDirection,      getDirection,      xmlelement, mode, const Vector3&);
     96        XMLPortParam(Light, "type",           setTypeString,     getTypeString,     xmlelement, mode).defaultValues("point");
     97        XMLPortParam(Light, "diffuse",        setDiffuseColour,  getDiffuseColour,  xmlelement, mode).defaultValues(ColourValue::White);
     98        XMLPortParam(Light, "specular",       setSpecularColour, getSpecularColour, xmlelement, mode).defaultValues(ColourValue::White);
     99        XMLPortParam(Light, "attenuation",    setAttenuation,    getAttenuation,    xmlelement, mode).defaultValues(Vector4(100000, 1, 0, 0));
     100        XMLPortParam(Light, "spotlightrange", setSpotlightRange, getSpotlightRange, xmlelement, mode).defaultValues(Vector3(40.0f, 30.0f, 1.0f));
    77101    }
    78102
    79103    void Light::registerVariables()
    80104    {
    81         registerVariable((int &)this->type_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::changedType));
    82         registerVariable(this->light_->getDiffuseColour(), variableDirection::toclient);
    83         registerVariable(this->light_->getSpecularColour(), variableDirection::toclient);
    84         registerVariable(this->light_->getDirection(), variableDirection::toclient);
     105        registerVariable((int&)this->type_,     variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateType));
     106        registerVariable(this->diffuse_,        variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateDiffuseColour));
     107        registerVariable(this->specular_,       variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateSpecularColour));
     108        registerVariable(this->attenuation_,    variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateAttenuation));
     109        registerVariable(this->spotlightRange_, variableDirection::toclient, new NetworkCallback<Light>(this, &Light::updateSpotlightRange));
    85110    }
    86111
    87     const std::string& Light::getName() const
     112    void Light::updateDiffuseColour()
    88113    {
    89114        if (this->light_)
    90             return this->light_->getName();
    91         else
    92             return BLANKSTRING;
     115            this->light_->setDiffuseColour(this->diffuse_);
    93116    }
    94117
    95     void Light::setDiffuseColour(const ColourValue& colour)
     118    void Light::updateSpecularColour()
    96119    {
    97120        if (this->light_)
    98             this->light_->setDiffuseColour(colour);
     121            this->light_->setSpecularColour(this->specular_);
    99122    }
    100123
    101     const ColourValue& Light::getDiffuseColour() const
     124    void Light::updateAttenuation()
    102125    {
    103         if (this->light_)
    104             return this->light_->getDiffuseColour();
    105         else
    106             return ColourValue::White;
     126        if (this->light_ && this->type_ != Ogre::Light::LT_DIRECTIONAL)
     127            this->light_->setAttenuation(this->attenuation_.x, this->attenuation_.y, this->attenuation_.z, this->attenuation_.w);
    107128    }
    108129
    109     void Light::setSpecularColour(const ColourValue& colour)
     130    void Light::updateSpotlightRange()
    110131    {
    111         if (this->light_)
    112             this->light_->setSpecularColour(colour);
    113     }
    114 
    115     const ColourValue& Light::getSpecularColour() const
    116     {
    117         if (this->light_)
    118             return this->light_->getSpecularColour();
    119         else
    120             return ColourValue::White;
    121     }
    122 
    123     void Light::setDirection(const Vector3& direction)
    124     {
    125         if (this->light_)
    126             this->light_->setDirection(direction);
    127     }
    128 
    129     const Vector3& Light::getDirection() const
    130     {
    131         if (this->light_)
    132             return this->light_->getDirection();
    133         else
    134             return Vector3::ZERO;
     132        if (this->light_ && this->type_ == Ogre::Light::LT_SPOTLIGHT)
     133            this->light_->setSpotlightRange(Degree(this->spotlightRange_.x), Degree(this->spotlightRange_.y), this->spotlightRange_.z);
    135134    }
    136135
     
    157156            case Ogre::Light::LT_POINT:
    158157            default:
    159                 return "poinT";
     158                return "point";
    160159        }
    161160    }
    162161
    163     void Light::changedType()
     162    void Light::updateType()
    164163    {
    165         this->light_->setType(this->type_);
     164        if (this->light_)
     165        {
     166            this->light_->setType(this->type_);
     167
     168            if (this->type_ != Ogre::Light::LT_DIRECTIONAL)
     169                this->updateAttenuation();
     170            if (this->type_ == Ogre::Light::LT_SPOTLIGHT)
     171                this->updateSpotlightRange();
     172        }
    166173    }
    167174
     
    170177        SUPER(Light, changedVisibility);
    171178
    172         this->light_->setVisible(this->isVisible());
     179        if (this->light_)
     180            this->light_->setVisible(this->isVisible());
    173181    }
    174182}
  • code/branches/presentation/src/orxonox/objects/worldentities/Light.h

    r2459 r2485  
    5454                { return this->light_; }
    5555
    56             const std::string& getName() const;
    57 
    5856            inline void setType(Ogre::Light::LightTypes type)
    59                 { this->type_ = type; this->changedType(); }
    60             Ogre::Light::LightTypes getType() const
     57                { this->type_ = type; this->updateType(); }
     58            inline Ogre::Light::LightTypes getType() const
    6159                { return this->type_; }
    6260
    63             void setDiffuseColour(const ColourValue& colour);
    64             const ColourValue& getDiffuseColour() const;
     61            inline void setDiffuseColour(const ColourValue& colour)
     62                { this->diffuse_ = colour; this->updateDiffuseColour(); }
     63            inline const ColourValue& getDiffuseColour() const
     64                { return this->diffuse_; }
    6565
    66             void setSpecularColour(const ColourValue& colour);
    67             const ColourValue& getSpecularColour() const;
     66            inline void setSpecularColour(const ColourValue& colour)
     67                { this->specular_ = colour; this->updateSpecularColour(); }
     68            inline const ColourValue& getSpecularColour() const
     69                { return this->specular_; }
    6870
    69             void setDirection(const Vector3& direction);
    70             const Vector3& getDirection() const;
     71            /**
     72                @brief Sets the attenuation parameters of the light source i.e. how it diminishes with distance.
     73
     74                @param attenuation.x range (The absolute upper range of the light in world units)
     75                @param attenuation.y constant (The constant factor in the attenuation formula: 1.0 means never attenuate, 0.0 is complete attenuation)
     76                @param attenuation.z linear (The linear factor in the attenuation formula: 1 means attenuate evenly over the distance)
     77                @param attenuation.w quadratic (The quadratic factor in the attenuation formula: adds a curvature to the attenuation formula)
     78
     79                Quote from the Ogre API:
     80                Lights normally get fainter the further they are away. Also, each light is given a maximum range beyond which it cannot affect any objects.
     81                Light attenuation is not applicable to directional lights since they have an infinite range and constant intensity.
     82                This follows a standard attenuation approach - see any good 3D text for the details of what they mean since i don't have room here!
     83
     84                Quote from the Ogre wiki:
     85                "Using these numbers, the light has 100% intensity at 0 distance, and
     86                trails off to near black at a distance equal to the Range. Keep in mind
     87                that most of the light falls in the first 20% of the range."
     88
     89                Range   Constant   Linear     Quadratic
     90                3250,     1.0,     0.0014,    0.000007
     91                600,      1.0,     0.007,     0.0002
     92                325,      1.0,     0.014,     0.0007
     93                200,      1.0,     0.022,     0.0019
     94                160,      1.0,     0.027,     0.0028
     95                100,      1.0,     0.045,     0.0075
     96                65,       1.0,     0.07,      0.017
     97                50,       1.0,     0.09,      0.032
     98                32,       1.0,     0.14,      0.07
     99                20,       1.0,     0.22,      0.20
     100                13,       1.0,     0.35,      0.44
     101                7,        1.0,     0.7,       1.8
     102            */
     103            inline void setAttenuation(const Vector4& attenuation)
     104                { this->attenuation_ = attenuation; this->updateAttenuation(); }
     105            inline const Vector4& getAttenuation() const
     106                { return this->attenuation_; }
     107
     108            /**
     109                @brief Sets the range of a spotlight, i.e. the angle of the inner and outer cones and the rate of falloff between them.
     110
     111                @param spotlightRange.x innerAngle (The angle covered by the bright inner cone)
     112                @param spotlightRange.x outerAngle (The angle covered by the outer cone)
     113                @param spotlightRange.x falloff (The rate of falloff between the inner and outer cones. 1.0 means a linear falloff, less means slower falloff, higher means faster falloff.)
     114            */
     115            inline void setSpotlightRange(const Vector3& spotlightRange)
     116                { this->spotlightRange_ = spotlightRange; this->updateSpotlightRange(); }
     117            inline const Vector3& getSpotlightRange() const
     118                { return this->spotlightRange_; }
    71119
    72120        private:
     
    74122            std::string getTypeString() const;
    75123
    76             void changedType();
     124            void updateType();
     125            void updateDiffuseColour();
     126            void updateSpecularColour();
     127            void updateAttenuation();
     128            void updateSpotlightRange();
    77129
    78             static unsigned int lightCounter_s;
    79130            Ogre::Light* light_;
    80131            Ogre::Light::LightTypes type_;
    81 
     132            ColourValue diffuse_;
     133            ColourValue specular_;
     134            Vector4 attenuation_;
     135            Vector3 spotlightRange_;
    82136    };
    83137}
  • code/branches/presentation/src/orxonox/objects/worldentities/MobileEntity.cc

  • code/branches/presentation/src/orxonox/objects/worldentities/MobileEntity.h

  • code/branches/presentation/src/orxonox/objects/worldentities/Model.cc

    r2468 r2485  
    4242    {
    4343        RegisterObject(Model);
     44
     45        this->bCastShadows_ = true;
    4446
    4547        this->registerVariables();
  • code/branches/presentation/src/orxonox/objects/worldentities/MovableEntity.cc

    r2470 r2485  
    3535#include "core/Executor.h"
    3636#include "core/Core.h"
    37 #include "tools/Timer.h"
    3837
    3938namespace orxonox
     
    8180    void MovableEntity::clientConnected(unsigned int clientID)
    8281    {
    83         new Timer<MovableEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), true);
     82        this->resynchronizeTimer_.setTimer(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&MovableEntity::resynchronize)));
    8483    }
    8584
  • code/branches/presentation/src/orxonox/objects/worldentities/MovableEntity.h

    r2459 r2485  
    3535#include "MobileEntity.h"
    3636#include "network/ClientConnectionListener.h"
     37#include "tools/Timer.h"
    3738
    3839namespace orxonox
     
    7273            Vector3    overwrite_position_;
    7374            Quaternion overwrite_orientation_;
     75
     76            Timer<MovableEntity> resynchronizeTimer_;
    7477            Timer<MovableEntity>* continuousResynchroTimer_;
    7578    };
  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleEmitter.cc

    r2468 r2485  
    5252
    5353        if (Core::showsGraphics() && (!this->getScene() || !this->getScene()->getSceneManager()))
    54             ThrowException(AbortLoading, "Can't create Camera, no scene or no scene manager given.");
     54            ThrowException(AbortLoading, "Can't create ParticleEmitter, no scene or no scene manager given.");
    5555
    5656        this->particles_ = 0;
     
    109109            {
    110110                this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), this->source_, this->LOD_);
    111                 this->attachOgreObject(particles_->getParticleSystem());
     111                this->attachOgreObject(this->particles_->getParticleSystem());
    112112                this->particles_->setVisible(this->isVisible());
    113113                this->particles_->setEnabled(this->isActive());
  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleSpawner.cc

  • code/branches/presentation/src/orxonox/objects/worldentities/ParticleSpawner.h

  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.cc

    r2481 r2485  
    9595        {
    9696            this->node_->detachAllObjects();
     97
     98            for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); )
     99                delete (*(it++));
     100
     101            if (this->parent_)
     102                this->detachFromParent();
     103
     104            this->node_->removeAllChildren();
     105
    97106            if (this->getScene()->getSceneManager())
    98107                this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName());
     
    140149    void WorldEntity::registerVariables()
    141150    {
     151        registerVariable(this->mainStateName_,  variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState));
     152
    142153        registerVariable(this->bActive_,        variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
    143154        registerVariable(this->bVisible_,       variableDirection::toclient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
     
    212223    }
    213224
     225    void WorldEntity::attachNode(Ogre::SceneNode* node)
     226    {
     227        Ogre::Node* parent = node->getParent();
     228        if (parent)
     229            parent->removeChild(node);
     230        this->node_->addChild(node);
     231    }
     232
     233    void WorldEntity::detachNode(Ogre::SceneNode* node)
     234    {
     235        this->node_->removeChild(node);
     236//        this->getScene()->getRootSceneNode()->addChild(node);
     237    }
     238
     239    void WorldEntity::attachToNode(Ogre::SceneNode* node)
     240    {
     241        Ogre::Node* parent = this->node_->getParent();
     242        if (parent)
     243            parent->removeChild(this->node_);
     244        node->addChild(this->node_);
     245    }
     246
     247    void WorldEntity::detachFromNode(Ogre::SceneNode* node)
     248    {
     249        node->removeChild(this->node_);
     250//        this->getScene()->getRootSceneNode()->addChild(this->node_);
     251    }
     252
    214253    void WorldEntity::attach(WorldEntity* object)
    215254    {
     
    243282        }
    244283
     284        if (object == this)
     285        {
     286            COUT(2) << "Warning: Can't attach a WorldEntity to itself." << std::endl;
     287            return;
     288        }
     289
    245290        if (object->getParent())
    246291            object->detachFromParent();
    247         else
    248         {
    249             Ogre::Node* parent = object->node_->getParent();
    250             if (parent)
    251                 parent->removeChild(object->node_);
    252         }
    253 
    254         this->node_->addChild(object->node_);
     292
     293        this->attachNode(object->node_);
     294
    255295        this->children_.insert(object);
    256296        object->parent_ = this;
     
    275315        }
    276316
    277         this->node_->removeChild(object->node_);
     317        this->detachNode(object->node_);
    278318        this->children_.erase(object);
    279319        object->parent_ = 0;
    280320        object->parentID_ = OBJECTID_UNKNOWN;
    281 //        this->getScene()->getRootSceneNode()->addChild(object->node_);
    282321
    283322        // Note: It is possible that the object has physics but was disabled when attaching
     
    466505
    467506        this->node_->setScale(scale);
     507
     508        this->changedScale();
     509    }
     510
     511    const Vector3& WorldEntity::getWorldScale3D() const
     512    {
     513        return this->node_->_getDerivedScale();
     514    }
     515
     516    float WorldEntity::getWorldScale() const
     517    {
     518        Vector3 scale = this->getWorldScale3D();
     519        return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1;
    468520    }
    469521
  • code/branches/presentation/src/orxonox/objects/worldentities/WorldEntity.h

    r2466 r2485  
    7474            inline void translate(float x, float y, float z, TransformSpace::Space relativeTo = TransformSpace::Parent)
    7575                { this->translate(Vector3(x, y, z), relativeTo); }
     76
     77            virtual inline const Vector3& getVelocity() const
     78                { return Vector3::ZERO; }
    7679
    7780            virtual void setOrientation(const Quaternion& orientation) = 0;
     
    105108                { this->setScale3D(Vector3(x, y, z)); }
    106109            const Vector3& getScale3D(void) const;
    107 
    108             void setScale(float scale)
     110            const Vector3& getWorldScale3D() const;
     111
     112            inline void setScale(float scale)
    109113                { this->setScale3D(scale, scale, scale); }
    110114            inline float getScale() const
    111115                { Vector3 scale = this->getScale3D(); return (scale.x == scale.y && scale.x == scale.z) ? scale.x : 1; }
     116            float getWorldScale() const;
    112117
    113118            inline void scale3D(const Vector3& scale)
     
    118123                { this->scale3D(scale, scale, scale); }
    119124
     125            virtual void changedScale() {}
     126
    120127            void attach(WorldEntity* object);
    121128            void detach(WorldEntity* object);
     
    134141            inline WorldEntity* getParent() const
    135142                { return this->parent_; }
     143
     144            void attachNode(Ogre::SceneNode* node);
     145            void detachNode(Ogre::SceneNode* node);
     146            void attachToNode(Ogre::SceneNode* node);
     147            void detachFromNode(Ogre::SceneNode* node);
    136148
    137149            void notifyChildPropsChanged();
     
    302314        { return this->node_->getScale(); }
    303315#endif
     316
     317    SUPER_FUNCTION(5, WorldEntity, changedScale, false);
    304318}
    305319
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.cc

    r2371 r2485  
    3030#include "Pawn.h"
    3131
     32#include "core/Core.h"
    3233#include "core/CoreIncludes.h"
    3334#include "core/XMLPort.h"
    3435#include "util/Math.h"
     36#include "PawnManager.h"
    3537#include "objects/infos/PlayerInfo.h"
    3638#include "objects/gametypes/Gametype.h"
    3739#include "objects/weaponSystem/WeaponSystem.h"
     40#include "objects/worldentities/ParticleSpawner.h"
     41#include "objects/worldentities/ExplosionChunk.h"
    3842
    3943namespace orxonox
     
    4549        RegisterObject(Pawn);
    4650
    47         this->bAlive_ = false;
     51        PawnManager::touch();
     52
     53        this->bAlive_ = true;
    4854
    4955        this->health_ = 0;
     
    5359        this->lastHitOriginator_ = 0;
    5460        this->weaponSystem_ = 0;
     61
     62        this->spawnparticleduration_ = 3.0f;
    5563
    5664        /*
     
    6270        */
    6371
     72        this->setRadarObjectColour(ColourValue::Red);
     73        this->setRadarObjectShape(RadarViewable::Dot);
     74
    6475        this->registerVariables();
    6576    }
     
    6778    Pawn::~Pawn()
    6879    {
     80        if (this->isInitialized())
     81        {
     82            for (ObjectList<PawnListener>::iterator it = ObjectList<PawnListener>::begin(); it != ObjectList<PawnListener>::end(); ++it)
     83                it->destroyedPawn(this);
     84        }
    6985    }
    7086
     
    7389        SUPER(Pawn, XMLPort, xmlelement, mode);
    7490
    75         XMLPortParam(Pawn, "health", setHealth, getHealht, xmlelement, mode).defaultValues(100);
     91        XMLPortParam(Pawn, "health", setHealth, getHealth, xmlelement, mode).defaultValues(100);
    7692        XMLPortParam(Pawn, "maxhealth", setMaxHealth, getMaxHealth, xmlelement, mode).defaultValues(200);
    7793        XMLPortParam(Pawn, "initialhealth", setInitialHealth, getInitialHealth, xmlelement, mode).defaultValues(100);
     94        XMLPortParam(Pawn, "spawnparticlesource", setSpawnParticleSource, getSpawnParticleSource, xmlelement, mode);
     95        XMLPortParam(Pawn, "spawnparticleduration", setSpawnParticleDuration, getSpawnParticleDuration, xmlelement, mode).defaultValues(3.0f);
     96        XMLPortParam(Pawn, "explosionchunks", setExplosionChunks, getExplosionChunks, xmlelement, mode).defaultValues(7);
    7897    }
    7998
    8099    void Pawn::registerVariables()
    81100    {
    82         registerVariable(this->bAlive_, variableDirection::toclient);
    83         registerVariable(this->health_, variableDirection::toclient);
     101        registerVariable(this->bAlive_,        variableDirection::toclient);
     102        registerVariable(this->health_,        variableDirection::toclient);
     103        registerVariable(this->initialHealth_, variableDirection::toclient);
    84104    }
    85105
     
    119139    }
    120140
    121     void Pawn::spawn()
     141    void Pawn::spawneffect()
    122142    {
    123143        // play spawn effect
     144        if (this->spawnparticlesource_ != "")
     145        {
     146            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     147            effect->setPosition(this->getPosition());
     148            effect->setOrientation(this->getOrientation());
     149            effect->setDestroyAfterLife(true);
     150            effect->setSource(this->spawnparticlesource_);
     151            effect->setLifetime(this->spawnparticleduration_);
     152        }
    124153    }
    125154
    126155    void Pawn::death()
    127156    {
     157        // Set bAlive_ to false and wait for PawnManager to do the destruction
    128158        this->bAlive_ = false;
     159
     160        this->setDestroyWhenPlayerLeft(false);
     161
    129162        if (this->getGametype())
    130163            this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
     164
    131165        if (this->getPlayer())
    132166            this->getPlayer()->stopControl(this);
    133167
    134         delete this;
    135 
     168        if (Core::isMaster())
     169            this->deatheffect();
     170    }
     171
     172    void Pawn::deatheffect()
     173    {
    136174        // play death effect
     175        {
     176            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     177            effect->setPosition(this->getPosition());
     178            effect->setOrientation(this->getOrientation());
     179            effect->setDestroyAfterLife(true);
     180            effect->setSource("Orxonox/explosion2b");
     181            effect->setLifetime(4.0f);
     182        }
     183        {
     184            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     185            effect->setPosition(this->getPosition());
     186            effect->setOrientation(this->getOrientation());
     187            effect->setDestroyAfterLife(true);
     188            effect->setSource("Orxonox/smoke6");
     189            effect->setLifetime(4.0f);
     190        }
     191        {
     192            ParticleSpawner* effect = new ParticleSpawner(this->getCreator());
     193            effect->setPosition(this->getPosition());
     194            effect->setOrientation(this->getOrientation());
     195            effect->setDestroyAfterLife(true);
     196            effect->setSource("Orxonox/sparks");
     197            effect->setLifetime(4.0f);
     198        }
     199        for (unsigned int i = 0; i < this->numexplosionchunks_; ++i)
     200        {
     201            ExplosionChunk* chunk = new ExplosionChunk(this->getCreator());
     202            chunk->setPosition(this->getPosition());
     203
     204        }
    137205    }
    138206
     
    146214    {
    147215        this->setHealth(this->initialHealth_);
    148         this->spawn();
     216        if (Core::isMaster())
     217            this->spawneffect();
     218    }
     219
     220    ///////////////////
     221    // Pawn Listener //
     222    ///////////////////
     223    PawnListener::PawnListener()
     224    {
     225        RegisterRootObject(PawnListener);
    149226    }
    150227}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Pawn.h

    r2098 r2485  
    3333
    3434#include "objects/worldentities/ControllableEntity.h"
     35#include "objects/RadarViewable.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport Pawn : public ControllableEntity
     39    class _OrxonoxExport Pawn : public ControllableEntity, public RadarViewable
    3940    {
    4041        public:
     
    5455            inline void removeHealth(float health)
    5556                { this->setHealth(this->health_ - health); }
    56             inline float getHealht() const
     57            inline float getHealth() const
    5758                { return this->health_; }
    5859
     
    7879            virtual void postSpawn();
    7980
     81            inline const WorldEntity* getWorldEntity() const
     82                { return (WorldEntity*)this; }
     83
     84            inline void setSpawnParticleSource(const std::string& source)
     85                { this->spawnparticlesource_ = source; }
     86            inline const std::string& getSpawnParticleSource() const
     87                { return this->spawnparticlesource_; }
     88
     89            inline void setSpawnParticleDuration(float duration)
     90                { this->spawnparticleduration_ = duration; }
     91            inline float getSpawnParticleDuration() const
     92                { return this->spawnparticleduration_; }
     93
     94            inline void setExplosionChunks(unsigned int chunks)
     95                { this->numexplosionchunks_ = chunks; }
     96            inline unsigned int getExplosionChunks() const
     97                { return this->numexplosionchunks_; }
     98
    8099        protected:
    81             virtual void spawn();
    82100            virtual void death();
     101            virtual void deatheffect();
     102            virtual void spawneffect();
    83103
    84104            bool bAlive_;
     
    91111
    92112            WeaponSystem* weaponSystem_;
     113
     114            std::string spawnparticlesource_;
     115            float spawnparticleduration_;
     116            unsigned int numexplosionchunks_;
     117    };
     118
     119    class _OrxonoxExport PawnListener : public OrxonoxClass
     120    {
     121        friend class Pawn;
     122
     123        public:
     124            PawnListener();
     125            virtual ~PawnListener() {}
     126
     127        protected:
     128            virtual void destroyedPawn(Pawn* pawn) = 0;
    93129    };
    94130}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2475 r2485  
    3636#include "core/CoreIncludes.h"
    3737#include "core/ConfigValueIncludes.h"
     38#include "core/Template.h"
    3839#include "core/XMLPort.h"
     40#include "objects/items/Engine.h"
    3941
    4042namespace orxonox
     
    5355        this->localLinearAcceleration_.setValue(0, 0, 0);
    5456        this->localAngularAcceleration_.setValue(0, 0, 0);
     57        this->bBoost_ = false;
     58        this->steering_ = Vector3::ZERO;
     59        this->engine_ = 0;
     60
    5561
    5662        this->bInvertYAxis_ = false;
     
    7076    SpaceShip::~SpaceShip()
    7177    {
     78        if (this->isInitialized() && this->engine_)
     79            delete this->engine_;
    7280    }
    7381
     
    7684        SUPER(SpaceShip, XMLPort, xmlelement, mode);
    7785
     86        XMLPortParam(SpaceShip, "engine",            setEngineTemplate,    getEngineTemplate,    xmlelement, mode);
    7887        XMLPortParamVariable(SpaceShip, "primaryThrust",  primaryThrust_,  xmlelement, mode);
    7988        XMLPortParamVariable(SpaceShip, "auxilaryThrust", auxilaryThrust_, xmlelement, mode);
     
    109118        SUPER(SpaceShip, tick, dt);
    110119
    111         if (this->isLocallyControlled())
     120        if (this->hasLocalController())
    112121        {
    113             this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
    114             this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
    115             if (this->localLinearAcceleration_.z() > 0)
    116                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
    117             else
    118                 this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
    119             this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
    120             this->localLinearAcceleration_.setValue(0, 0, 0);
     122            if (!this->isInMouseLook())
     123            {
     124                this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() * getMass() * this->auxilaryThrust_);
     125                this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() * getMass() * this->auxilaryThrust_);
     126                if (this->localLinearAcceleration_.z() > 0)
     127                    this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->auxilaryThrust_);
     128                else
     129                    this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() * getMass() * this->primaryThrust_);
     130                this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * this->localLinearAcceleration_);
     131                this->localLinearAcceleration_.setValue(0, 0, 0);
     132            }
    121133
    122134            this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     
    129141    {
    130142        this->localLinearAcceleration_.setZ(this->localLinearAcceleration_.z() - value.x);
     143        this->steering_.z = -value.x;
    131144    }
    132145
     
    134147    {
    135148        this->localLinearAcceleration_.setX(this->localLinearAcceleration_.x() + value.x);
     149        this->steering_.x = value.x;
    136150    }
    137151
     
    139153    {
    140154        this->localLinearAcceleration_.setY(this->localLinearAcceleration_.y() + value.x);
     155        this->steering_.y = value.x;
    141156    }
    142157
     
    144159    {
    145160        this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x);
     161
     162        Pawn::rotateYaw(value);
    146163    }
    147164
     
    149166    {
    150167        this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x);
     168
     169        Pawn::rotatePitch(value);
    151170    }
    152171
     
    154173    {
    155174        this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x);
     175
     176        Pawn::rotateRoll(value);
    156177    }
    157178
     
    159180    {
    160181    }
     182
     183    void SpaceShip::boost()
     184    {
     185        this->bBoost_ = true;
     186    }
     187
     188    void SpaceShip::loadEngineTemplate()
     189    {
     190        if (this->enginetemplate_ != "")
     191        {
     192            Template* temp = Template::getTemplate(this->enginetemplate_);
     193
     194            if (temp)
     195            {
     196                Identifier* identifier = temp->getBaseclassIdentifier();
     197
     198                if (identifier)
     199                {
     200                    BaseObject* object = identifier->fabricate(this);
     201                    this->engine_ = dynamic_cast<Engine*>(object);
     202
     203                    if (this->engine_)
     204                    {
     205                        this->engine_->addTemplate(temp);
     206                        this->engine_->addToSpaceShip(this);
     207                    }
     208                    else
     209                    {
     210                        delete object;
     211                    }
     212                }
     213            }
     214        }
     215    }
     216
     217    void SpaceShip::setEngine(Engine* engine)
     218    {
     219        this->engine_ = engine;
     220        if (engine && engine->getShip() != this)
     221            engine->addToSpaceShip(this);
     222    }
    161223}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/SpaceShip.h

    r2459 r2485  
    5858
    5959            virtual void fire();
     60            virtual void boost();
     61
     62            void setEngine(Engine* engine);
     63            inline Engine* getEngine() const
     64                { return this->engine_; }
     65
     66            inline void setSteeringDirection(const Vector3& direction)
     67                { this->steering_ = direction; }
     68            inline const Vector3& getSteeringDirection() const
     69                { return this->steering_; }
     70
     71            inline void setBoost(bool bBoost)
     72                { this->bBoost_ = bBoost; }
     73            inline bool getBoost() const
     74                { return this->bBoost_; }
     75
     76            inline void setEngineTemplate(const std::string& temp)
     77                { this->enginetemplate_ = temp; this->loadEngineTemplate(); }
     78            inline const std::string& getEngineTemplate() const
     79                { return this->enginetemplate_; }
    6080
    6181        protected:
    6282            bool bInvertYAxis_;
    6383
     84            bool bBoost_;
     85            Vector3 steering_;
    6486            float primaryThrust_;
    6587            float auxilaryThrust_;
     
    7193        private:
    7294            virtual bool isCollisionTypeLegal(WorldEntity::CollisionType type) const;
     95
     96        private:
     97            void loadEngineTemplate();
     98
     99            std::string enginetemplate_;
     100            Engine* engine_;
    73101    };
    74102}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2480 r2485  
    3333
    3434#include "core/CoreIncludes.h"
     35#include "core/ConfigValueIncludes.h"
    3536#include "core/Core.h"
    3637#include "objects/worldentities/Model.h"
     
    5152        RegisterObject(Spectator);
    5253
    53         this->speed_ = 100;
    54         this->rotationGain_ = 3;
     54        this->speed_ = 200;
    5555
    5656        this->yaw_ = 0;
     
    5959        this->localVelocity_ = Vector3::ZERO;
    6060        this->setHudTemplate("spectatorhud");
    61         this->hudmode_ = 0;
     61        this->greetingFlare_ = 0;
    6262
    6363        this->setDestroyWhenPlayerLeft(true);
    6464
    65         if ( Core::showsGraphics() )
    66         {
     65        if (Core::showsGraphics())
     66        {
    6767            this->greetingFlare_ = new BillboardSet();
    6868            this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
     
    7171            this->greetingFlare_->setVisible(false);
    7272        }
    73         else
    74             this->greetingFlare_ = 0;
     73
    7574        this->bGreetingFlareVisible_ = false;
    7675        this->bGreeting_ = false;
    7776
     77        this->setConfigValues();
    7878        this->registerVariables();
    7979    }
     
    8787                if (this->greetingFlare_->getBillboardSet())
    8888                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
     89
    8990                delete this->greetingFlare_;
    9091            }
     
    9293    }
    9394
     95    void Spectator::setConfigValues()
     96    {
     97        SetConfigValue(speed_, 200.0f);
     98    }
     99
    94100    void Spectator::registerVariables()
    95101    {
    96102        registerVariable(this->bGreetingFlareVisible_, variableDirection::toclient, new NetworkCallback<Spectator>(this, &Spectator::changedFlareVisibility));
    97103        registerVariable(this->bGreeting_,             variableDirection::toserver, new NetworkCallback<Spectator>(this, &Spectator::changedGreeting));
    98         registerVariable(this->hudmode_,               variableDirection::toclient);
    99104    }
    100105
     
    107112    void Spectator::changedFlareVisibility()
    108113    {
    109         if ( this->greetingFlare_ )             
     114        if ( this->greetingFlare_ )
    110115            this->greetingFlare_->setVisible(this->bGreetingFlareVisible_);
    111116    }
     
    113118    void Spectator::tick(float dt)
    114119    {
    115         this->updateHUD();
    116 
    117         if (this->isLocallyControlled())
     120        if (this->hasLocalController())
    118121        {
    119122            float localSpeedSquared = this->localVelocity_.squaredLength();
     
    132135            this->localVelocity_.z = 0;
    133136
    134             this->yaw  (Radian(this->yaw_   * this->rotationGain_));
    135             this->pitch(Radian(this->pitch_ * this->rotationGain_));
    136             this->roll (Radian(this->roll_  * this->rotationGain_));
     137            if (!this->isInMouseLook())
     138            {
     139                this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()));
     140                this->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
     141                this->roll(Radian(this->roll_ * this->getMouseLookSpeed()));
     142            }
    137143
    138144            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    146152        ControllableEntity::setPlayer(player);
    147153
    148 //        this->setObjectMode(direction::toclient);
    149     }
    150 
    151     void Spectator::startLocalControl()
    152     {
    153         ControllableEntity::startLocalControl();
    154 //        if (this->isLocallyControlled())
    155 //            this->testmesh_->setVisible(false);
     154//        this->setObjectMode(objectDirection::toclient);
     155    }
     156
     157    void Spectator::startLocalHumanControl()
     158    {
     159        ControllableEntity::startLocalHumanControl();
    156160    }
    157161
     
    174178    {
    175179        this->yaw_ += value.y;
     180
     181        ControllableEntity::rotateYaw(value);
    176182    }
    177183
     
    179185    {
    180186        this->pitch_ += value.y;
     187
     188        ControllableEntity::rotatePitch(value);
    181189    }
    182190
     
    184192    {
    185193        this->roll_ += value.y;
     194
     195        ControllableEntity::rotateRoll(value);
    186196    }
    187197
     
    202212        }
    203213    }
    204 
    205     void Spectator::updateHUD()
    206     {
    207         // <hack>
    208         if (Core::isMaster())
    209         {
    210             if (this->getPlayer() && this->getGametype())
    211             {
    212                 if (!this->getGametype()->hasStarted() && !this->getGametype()->isStartCountdownRunning())
    213                 {
    214                     if (!this->getPlayer()->isReadyToSpawn())
    215                         this->hudmode_ = 0;
    216                     else
    217                         this->hudmode_ = 1;
    218                 }
    219                 else if (!this->getGametype()->hasEnded())
    220                 {
    221                     if (this->getGametype()->isStartCountdownRunning())
    222                         this->hudmode_ = 2 + 10*(int)ceil(this->getGametype()->getStartCountdown());
    223                     else
    224                         this->hudmode_ = 3;
    225                 }
    226                 else
    227                     this->hudmode_ = 4;
    228             }
    229             else
    230                 return;
    231         }
    232 
    233         if (this->getHUD())
    234         {
    235             std::string text;
    236             int hudmode = this->hudmode_ % 10;
    237 
    238             switch (hudmode)
    239             {
    240                 case 0:
    241                     text = "Press [Fire] to start the match";
    242                     break;
    243                 case 1:
    244                     text = "Waiting for other players";
    245                     break;
    246                 case 2:
    247                     text = convertToString((this->hudmode_ - 2) / 10);
    248                     break;
    249                 case 3:
    250                     text = "Press [Fire] to respawn";
    251                     break;
    252                 case 4:
    253                     text = "Game has ended";
    254                     break;
    255                 default:;
    256             }
    257 
    258             std::map<std::string, OrxonoxOverlay*>::const_iterator it = this->getHUD()->getOverlays().begin();
    259             for (; it != this->getHUD()->getOverlays().end(); ++it)
    260             {
    261                 if (it->second->isA(Class(OverlayText)) && it->second->getName() == "state")
    262                 {
    263                     OverlayText* overlay = dynamic_cast<OverlayText*>(it->second);
    264                     if (overlay)
    265                         overlay->setCaption(text);
    266                     break;
    267                 }
    268             }
    269         }
    270         // </hack>
    271     }
    272214}
  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.h

    r2459 r2485  
    4242            virtual ~Spectator();
    4343
     44            void setConfigValues();
    4445            void registerVariables();
    4546            virtual void tick(float dt);
    4647
    4748            virtual void setPlayer(PlayerInfo* player);
    48             virtual void startLocalControl();
     49            virtual void startLocalHumanControl();
    4950
    5051            virtual void moveFrontBack(const Vector2& value);
     
    6263            void changedGreeting();
    6364            void changedFlareVisibility();
    64             void updateHUD();
    6565
    6666            BillboardSet* greetingFlare_;
     
    6969
    7070            float speed_;
    71             float rotationGain_;
    7271
    7372            float yaw_;
     
    7675
    7776            Vector3 localVelocity_;
    78 
    79             int hudmode_;
    8077    };
    8178}
  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc

  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/DistanceTrigger.h

  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/Trigger.cc

    r2459 r2485  
    107107    if (!this->BaseObject::isActive())
    108108        return;
     109
     110    SUPER(Trigger, tick, dt);
    109111
    110112    bool newTriggered = this->isTriggered() ^ this->bInvertMode_;
  • code/branches/presentation/src/orxonox/objects/worldentities/triggers/Trigger.h

Note: See TracChangeset for help on using the changeset viewer.