Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 27, 2008, 8:07:29 AM (17 years ago)
Author:
rgrieder
Message:

updated input branch

Location:
code/branches/input/src/orxonox/objects
Files:
3 deleted
18 edited
8 copied

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/orxonox/objects/Ambient.cc

    r1505 r1629  
    7373     
    7474    }
    75    
    76     void Ambient::loadParams(TiXmlElement* xmlElem)
     75
     76    void Ambient::setAmbientLight(const ColourValue& colour)
    7777    {
    78         if (xmlElem->Attribute("colourvalue"))
    79         {
    80         SubString colourvalues(xmlElem->Attribute("colourvalue"), ',');
    81 
    82                 float r, g, b;
    83         convertValue<std::string, float>(&r, colourvalues[0]);
    84         convertValue<std::string, float>(&g, colourvalues[1]);
    85         convertValue<std::string, float>(&b, colourvalues[2]);
    86 
    87                 this->setAmbientLight(ColourValue(r, g, b));
    88 
    89                 COUT(4) << "Loader: Set ambient light: "<<r<<" " << g << " " << b  << std::endl << std::endl;
    90         }
    91    }
    92 
    93    void Ambient::setAmbientLight(const ColourValue& colour)
    94    {
    95         GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour);
     78            GraphicsEngine::getSingleton().getSceneManager()->setAmbientLight(colour);
    9679      ambientLight_=colour;     
    97    }
     80    }
    9881
    9982    /**
  • code/branches/input/src/orxonox/objects/Ambient.h

    r1505 r1629  
    4444            virtual ~Ambient();
    4545
    46             void loadParams(TiXmlElement* xmlElem);
    4746            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4847            void setAmbientLight(const ColourValue& colour);
  • code/branches/input/src/orxonox/objects/Model.cc

    r1511 r1629  
    5353    Model::~Model()
    5454    {
     55        if (this->isInitialized() && (this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
     56            this->detachObject(this->mesh_.getEntity());
    5557    }
    5658
    5759    /**
    5860        @brief XML loading and saving.
    59     @p
    60     aram xmlelement The XML-element
     61        @param xmlelement The XML-element
    6162        @param loading Loading (true) or saving (false)
    6263        @return The XML-element
     
    9495      registerVar(&meshSrc_, meshSrc_.length() + 1, network::STRING);
    9596    }
     97
     98    void Model::changedVisibility()
     99    {
     100        WorldEntity::changedVisibility();
     101        if (this->isInitialized())
     102            this->mesh_.setVisible(this->isVisible());
     103    }
    96104}
  • code/branches/input/src/orxonox/objects/Model.h

    r1505 r1629  
    4444            virtual ~Model();
    4545            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void changedVisibility();
    4647            void setMesh(const std::string& meshname);
    4748            virtual bool create();
  • code/branches/input/src/orxonox/objects/NPC.cc

    r1505 r1629  
    4545  NPC::~NPC()
    4646  {
    47   }
    48 
    49   void NPC::loadParams(TiXmlElement* xmlElem)
    50   {
    51     Model::loadParams(xmlElem);
    5247  }
    5348
  • code/branches/input/src/orxonox/objects/NPC.h

    r1505 r1629  
    4848      NPC();
    4949      virtual ~NPC();
    50       virtual void loadParams(TiXmlElement* xmlElem);
    5150      void tick(float dt);
    5251      void update();
  • code/branches/input/src/orxonox/objects/Projectile.cc

    r1505 r1629  
    3535#include "core/Executor.h"
    3636#include "core/ConfigValueIncludes.h"
     37#include "tools/ParticleInterface.h"
    3738
    38 #include "SpaceShip.h"
    39 #include "Explosion.h"
     39#include "SpaceShipAI.h"
     40#include "ParticleSpawner.h"
    4041#include "Model.h"
    4142
    4243namespace orxonox
    4344{
    44     CreateFactory(Projectile);
     45    float Projectile::speed_ = 5000;
    4546
    46     float Projectile::speed_ = 0;
    47 
    48     Projectile::Projectile(SpaceShip* owner) :
    49       owner_(owner)
     47    Projectile::Projectile(SpaceShip* owner) : owner_(owner)
    5048    {
    5149        RegisterObject(Projectile);
    5250
    5351        this->setConfigValues();
    54 
    55         this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
    56         this->attachObject(this->billboard_.getBillboardSet());
    57         this->scale(0.5);
     52        this->explosionTemplateName_ = "Orxonox/explosion3";
     53        this->smokeTemplateName_ = "Orxonox/smoke4";
    5854
    5955        if (this->owner_)
     
    6359            this->setPosition(this->owner_->getPosition());
    6460            this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
    65             this->setVelocity(Vector3(1, 0, 0) * this->speed_);
     61            this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    6662        }
    6763
    6864        this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    69 //        COUT(3) << this->classID << std::endl;
    7065    }
    7166
     
    7671    void Projectile::setConfigValues()
    7772    {
    78         SetConfigValue(lifetime_, 10.0).description("The time in seconds a projectile stays alive");
    79         SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second");
     73        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
     74        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
     75        SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second");
    8076
    81         this->setVelocity(Vector3(1, 0, 0) * this->speed_);
     77        if(this->owner_)
     78          this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    8279    }
    8380
     
    8582    {
    8683        WorldEntity::tick(dt);
     84
     85        if (!this->isActive())
     86            return;
    8787
    8888        float radius;
     
    9595                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9696                {
    97                     Explosion *exp = new Explosion(this);
    98                     exp->create();
     97                    // hit
     98                    if (it->isA(Class(SpaceShipAI)))
     99                        ((SpaceShipAI*)(*it))->damage(this->damage_);
     100                    ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0);
     101                    explosion->setPosition(this->getPosition());
     102                    explosion->create();
     103                    ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0);
     104                    smoke->setPosition(this->getPosition());
     105//                    smoke->getParticleInterface()->setSpeedFactor(3.0);
     106                    smoke->create();
    99107                    delete this;
    100108                    return;
     
    108116        delete this;
    109117    }
    110 
    111     void Projectile::setColour(const ColourValue& colour)
    112     {
    113         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    114     }
    115118}
  • code/branches/input/src/orxonox/objects/Projectile.h

    r1505 r1629  
    3333
    3434#include "WorldEntity.h"
    35 #include "../tools/BillboardSet.h"
    36 #include "../tools/Timer.h"
    37 #include "util/Math.h"
     35#include "tools/Timer.h"
    3836
    3937namespace orxonox
     
    4240    {
    4341        public:
    44             Projectile(SpaceShip* owner = 0);
    4542            virtual ~Projectile();
    4643            void setConfigValues();
    4744            void destroyObject();
    4845            virtual void tick(float dt);
    49             virtual bool create(){return WorldEntity::create();}
    50             void setColour(const ColourValue& colour);
    5146
    5247            static float getSpeed()
     
    5449
    5550        protected:
     51            Projectile(SpaceShip* owner = 0);
    5652            SpaceShip* owner_;
    5753
    5854        private:
    59             BillboardSet billboard_;
     55            std::string explosionTemplateName_;
     56            std::string smokeTemplateName_;
    6057            static float speed_;
    6158            float lifetime_;
     59            float damage_;
    6260            Timer<Projectile> destroyTimer_;
    6361    };
  • code/branches/input/src/orxonox/objects/RotatingProjectile.cc

    r1505 r1629  
    3737    CreateFactory(RotatingProjectile);
    3838
    39     RotatingProjectile::RotatingProjectile(SpaceShip* owner) : Projectile(owner)
     39    RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner)
    4040    {
    4141        RegisterObject(RotatingProjectile);
     
    7373    void RotatingProjectile::tick(float dt)
    7474    {
    75         this->time_ += dt;
     75        if (this->isActive())
     76        {
     77            this->time_ += dt;
    7678
    77         this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20));
    78         this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20));
     79            this->rotatingNode1_->setPosition(0, 50 * sin(this->time_ * 20), 50 * cos(this->time_ * 20));
     80            this->rotatingNode2_->setPosition(0, -50 * sin(this->time_ * 20), -50 * cos(this->time_ * 20));
     81        }
    7982
    8083        Projectile::tick(dt);
    8184    }
     85
     86    void RotatingProjectile::changedVisibility()
     87    {
     88        BillboardProjectile::changedVisibility();
     89        this->rotatingBillboard1_.setVisible(this->isVisible());
     90        this->rotatingBillboard2_.setVisible(this->isVisible());
     91    }
    8292}
  • code/branches/input/src/orxonox/objects/RotatingProjectile.h

    r1505 r1629  
    22#define _RotatingProjectile_H__
    33
    4 #include "../OrxonoxPrereqs.h"
     4#include "OrxonoxPrereqs.h"
    55#include "util/Math.h"
    6 #include "Projectile.h"
     6#include "BillboardProjectile.h"
    77
    88namespace orxonox
    99{
    10     class _OrxonoxExport RotatingProjectile : public Projectile/*, public network::Synchronisable*/
     10    class _OrxonoxExport RotatingProjectile : public BillboardProjectile
    1111    {
    1212        public:
     
    1515            void setConfigValues();
    1616            virtual void tick(float dt);
    17             virtual bool create(){return Projectile::create();}
     17            virtual void changedVisibility();
    1818
    1919        private:
  • code/branches/input/src/orxonox/objects/Skybox.cc

    r1505 r1629  
    5454    }
    5555
    56     void Skybox::loadParams(TiXmlElement* xmlElem)
     56    void Skybox::setSkybox(const std::string& skyboxname)
    5757    {
    58         if (xmlElem->Attribute("src"))
    59         {
    60                 skyboxSrc_ = xmlElem->Attribute("src");
    61         this->create();
     58        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);
     59    }
    6260
    63                 COUT(4) << "Loader: Set skybox: "<< skyboxSrc_ << std::endl << std::endl;
    64         }
    65    }
     61    void Skybox::setSkyboxSrc(const std::string& src)
     62    {
     63        this->skyboxSrc_ = src;
     64    }
    6665
    67    void Skybox::setSkybox(const std::string& skyboxname)
    68    {
    69         GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(true, skyboxname);
    70    }
    71 
    72    void Skybox::setSkyboxSrc(const std::string& src){
    73      skyboxSrc_ = src;
    74    }
    75    
    7666    /**
    7767        @brief XML loading and saving.
     
    8777        create();
    8878    }
    89    
    90     bool Skybox::create(){
    91       this->setSkybox(skyboxSrc_);
    92       return Synchronisable::create();
     79
     80    bool Skybox::create()
     81    {
     82        this->setSkybox(this->skyboxSrc_);
     83        return Synchronisable::create();
    9384    }
    94    
    95     void Skybox::registerAllVariables(){
    96       registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
     85
     86    void Skybox::registerAllVariables()
     87    {
     88        registerVar(&skyboxSrc_, skyboxSrc_.length()+1 ,network::STRING);
    9789    }
    98    
     90
     91    void Skybox::changedVisibility()
     92    {
     93        BaseObject::changedVisibility();
     94        GraphicsEngine::getSingleton().getSceneManager()->setSkyBox(this->isVisible(), this->skyboxSrc_);
     95    }
    9996}
  • code/branches/input/src/orxonox/objects/Skybox.h

    r1505 r1629  
    4343            virtual ~Skybox();
    4444
    45             void loadParams(TiXmlElement* xmlElem);
    4645            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46            virtual void changedVisibility();
    4747            void setSkybox(const std::string& skyboxname);
    48            
     48
    4949            virtual bool create();
    5050            void registerAllVariables();
  • code/branches/input/src/orxonox/objects/SpaceShip.cc

    r1535 r1629  
    3535#include <OgreSceneNode.h>
    3636
    37 #include "CameraHandler.h"
    3837#include "util/Convert.h"
    3938#include "util/Math.h"
     39
    4040#include "core/CoreIncludes.h"
    4141#include "core/ConfigValueIncludes.h"
    4242#include "core/Debug.h"
    43 #include "GraphicsEngine.h"
    44 #include "core/input/InputManager.h"
    45 #include "particle/ParticleInterface.h"
    46 #include "Projectile.h"
    47 #include "RotatingProjectile.h"
    4843#include "core/XMLPort.h"
    4944#include "core/ConsoleCommand.h"
     45
    5046#include "network/Client.h"
    51 #include "hud/HUD.h"
     47
     48#include "tools/ParticleInterface.h"
     49
     50#include "GraphicsEngine.h"
     51#include "RotatingProjectile.h"
     52#include "ParticleProjectile.h"
     53#include "ParticleSpawner.h"
     54#include "Backlight.h"
     55#include "CameraHandler.h"
    5256
    5357namespace orxonox
     
    6973    SpaceShip* SpaceShip::instance_s;
    7074
    71    
     75
    7276    SpaceShip *SpaceShip::getLocalShip(){
    7377      Iterator<SpaceShip> it;
     
    7983    }
    8084
    81     SpaceShip::SpaceShip() :
    82       //testvector_(0,0,0),
    83       //bInvertYAxis_(false),
    84       setMouseEventCallback_(false),
    85       bLMousePressed_(false),
    86       bRMousePressed_(false),
    87       camNode_(0),
    88       cam_(0),
    89       camName_("CamNode"),
    90       tt_(0),
    91       redNode_(0),
    92       greenNode_(0),
    93       blinkTime_(0.0f),
    94       chNearNode_(0),
    95       chFarNode_(0),
    96       timeToReload_(0.0f),
    97       //reloadTime_(0.0f),
    98       maxSideAndBackSpeed_(0.0f),
    99       maxSpeed_(0.0f),
    100       maxRotation_(0.0f),
    101       translationAcceleration_(0.0f),
    102       rotationAcceleration_(0.0f),
    103       translationDamping_(0.0f),
    104       rotationDamping_(0.0f),
    105       maxRotationRadian_(0),
    106       rotationAccelerationRadian_(0),
    107       rotationDampingRadian_(0),
    108       zeroRadian_(0),
    109       mouseXRotation_(0),
    110       mouseYRotation_(0),
    111       mouseX_(0.0f),
    112       mouseY_(0.0f),
    113       emitterRate_(0.0f),
    114       myShip_(false),
    115       teamNr_(0),
    116       health_(100)
     85    SpaceShip::SpaceShip()
    11786    {
    11887        RegisterObject(SpaceShip);
    119         this->registerAllVariables();
    120 
    121         SpaceShip::instance_s = this;
    122 
    123         this->setConfigValues();
    124 
    125         initialDir_ = Vector3(1.0, 0.0, 0.0);
    126         currentDir_ = initialDir_;
    127         initialOrth_ = Vector3(0.0, 0.0, 1.0);
    128         currentOrth_ = initialOrth_;
    129 
    130         this->camName_ = this->getName() + "CamNode";
    13188
    13289        this->setRotationAxis(1, 0, 0);
    13390        this->setStatic(false);
    13491
    135         COUT(3) << "Info: SpaceShip was loaded" << std::endl;
     92        this->zeroRadian_ = 0;
     93        this->maxSideAndBackSpeed_ = 0;
     94        this->maxSpeed_ = 0;
     95        this->maxRotation_ = 0;
     96        this->translationAcceleration_ = 0;
     97        this->rotationAcceleration_ = 0;
     98        this->translationDamping_ = 0;
     99        this->rotationDamping_ = 0;
     100        this->maxRotationRadian_ = 0;
     101        this->rotationAccelerationRadian_ = 0;
     102        this->rotationDampingRadian_ = 0;
     103
     104        this->cam_ = 0;
     105        this->tt1_ = 0;
     106        this->tt2_ = 0;
     107        this->smoke_ = 0;
     108        this->fire_ = 0;
     109
     110        this->backlight_ = 0;
     111
     112        this->redNode_ = 0;
     113        this->greenNode_ = 0;
     114        this->blinkTime_ = 0;
     115
     116        this->timeToReload_ = 0;
     117
     118        this->bLMousePressed_ = false;
     119        this->bRMousePressed_ = false;
     120        this->mouseXRotation_ = 0;
     121        this->mouseYRotation_ = 0;
     122        this->myShip_ = false;
     123
     124        this->registerAllVariables();
     125
     126        SpaceShip::instance_s = this;
     127
     128        this->setConfigValues();
     129
     130        this->initialDir_ = Vector3(1.0, 0.0, 0.0);
     131        this->currentDir_ = initialDir_;
     132        this->initialOrth_ = Vector3(0.0, 0.0, 1.0);
     133        this->currentOrth_ = initialOrth_;
     134
     135        this->camName_ = this->getName() + "CamNode";
     136
     137        this->teamNr_ = 0;
     138        this->health_ = 100;
     139
     140        this->radarObject_ = static_cast<WorldEntity*>(this);
    136141    }
    137142
    138143    SpaceShip::~SpaceShip()
    139144    {
    140         if (this->tt_)
    141             delete this->tt_;
    142         if(setMouseEventCallback_)
    143           InputManager::removeMouseHandler("SpaceShip");
    144         if (this->cam_)
    145           delete this->cam_;
    146         if (!Identifier::isCreatingHierarchy() && !myShip_ && &HUD::getSingleton()!=NULL)
    147           //remove the radar object
    148           HUD::getSingleton().removeRadarObject(this->getNode());
     145        if (this->isInitialized())
     146        {
     147            if (this->tt1_)
     148                delete this->tt1_;
     149            if (this->tt2_)
     150                delete this->tt2_;
     151
     152            if (this->smoke_)
     153                this->smoke_->destroy();
     154            if (this->fire_)
     155                this->fire_->destroy();
     156
     157            if (this->backlight_)
     158                delete this->backlight_;
     159
     160            if (this->cam_)
     161                delete this->cam_;
     162        }
    149163    }
    150164
     
    154168          myShip_=true;
    155169        else
    156           HUD::getSingleton().addRadarObject(this->getNode(), 3);
     170          this->setRadarObjectColour(this->getProjectileColour());
    157171      }
    158172      if(Model::create())
     
    179193    void SpaceShip::init()
    180194    {
    181         // START CREATING THRUSTER
    182         this->tt_ = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
    183         this->tt_->getParticleSystem()->setParameter("local_space","true");
    184         this->tt_->newEmitter();
    185 /*
    186         this->tt_->setDirection(Vector3(0,0,1));
    187         this->tt_->setPositionOfEmitter(0, Vector3(20,-1,-15));
    188         this->tt_->setPositionOfEmitter(1, Vector3(-20,-1,-15));
    189 */
    190         this->tt_->setDirection(Vector3(-1,0,0));
    191         this->tt_->setPositionOfEmitter(0, Vector3(-15,20,-1));
    192         this->tt_->setPositionOfEmitter(1, Vector3(-15,-20,-1));
    193         this->tt_->setVelocity(50);
    194 
    195         emitterRate_ = tt_->getRate();
    196 
    197         Ogre::SceneNode* node2 = this->getNode()->createChildSceneNode(this->getName() + "particle2");
    198         node2->setInheritScale(false);
    199         tt_->addToSceneNode(node2);
    200         // END CREATING THRUSTER
     195        // START CREATING THRUSTERS
     196        this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low);
     197        this->tt1_->createNewEmitter();
     198        this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir());
     199        this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1));
     200        this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1));
     201        this->tt1_->setSpeedFactor(3.0);
     202
     203        Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a");
     204        node2a->setInheritScale(false);
     205        node2a->setScale(1, 1, 1);
     206        tt1_->addToSceneNode(node2a);
     207
     208        this->tt2_ = new ParticleInterface("Orxonox/thruster2", LODParticle::normal);
     209        this->tt2_->createNewEmitter();
     210        this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0));
     211        this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2));
     212        this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2));
     213
     214        Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b");
     215        node2b->setInheritScale(false);
     216        node2b->setScale(0.5, 0.5, 0.5);
     217        tt2_->addToSceneNode(node2b);
     218
     219        this->leftThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, -10, -0.5));
     220        this->rightThrusterFlare_.setBillboardSet("Flares/ThrusterFlare1", Vector3(-7.5, 10, -0.5));
     221
     222        Ogre::SceneNode* node2c = this->getNode()->createChildSceneNode(this->getName() + "particle2c");
     223        node2c->setInheritScale(false);
     224        node2c->setScale(2, 2, 2);
     225        node2c->attachObject(this->leftThrusterFlare_.getBillboardSet());
     226        node2c->attachObject(this->rightThrusterFlare_.getBillboardSet());
     227        // END CREATING THRUSTERS
    201228
    202229        // START CREATING BLINKING LIGHTS
     
    216243        // END CREATING BLINKING LIGHTS
    217244
     245        // START CREATING ADDITIONAL EFFECTS
     246        this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
     247        this->attachObject(this->backlight_);
     248        this->backlight_->setPosition(-2.35, 0, 0.2);
     249        this->backlight_->setColour(this->getProjectileColour());
     250
     251        this->smoke_ = new ParticleSpawner();
     252        this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
     253        this->attachObject(this->smoke_);
     254
     255        this->fire_ = new ParticleSpawner();
     256        this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
     257        this->attachObject(this->fire_);
     258        // END CREATING ADDITIONAL EFFECTS
     259
    218260        if (this->isExactlyA(Class(SpaceShip)))
    219261        {
     
    232274            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    233275            this->chFarNode_->setScale(0.4, 0.4, 0.4);
     276            // END of testing crosshair
    234277        }
    235278
    236279        createCamera();
    237         // END of testing crosshair
    238280    }
    239281
     
    245287    }
    246288
     289    void SpaceShip::changedVisibility()
     290    {
     291        Model::changedVisibility();
     292
     293        this->tt1_->setEnabled(this->isVisible());
     294        this->tt2_->setEnabled(this->isVisible());
     295        this->redBillboard_.setVisible(this->isVisible());
     296        this->greenBillboard_.setVisible(this->isVisible());
     297        this->crosshairNear_.setVisible(this->isVisible());
     298        this->crosshairFar_.setVisible(this->isVisible());
     299        this->rightThrusterFlare_.setVisible(this->isVisible());
     300        this->leftThrusterFlare_.setVisible(this->isVisible());
     301        this->smoke_->setVisible(this->isVisible());
     302        this->fire_->setVisible(this->isVisible());
     303        this->backlight_->setVisible(this->isVisible());
     304    }
     305
     306    void SpaceShip::changedActivity()
     307    {
     308        Model::changedActivity();
     309
     310        this->tt1_->setEnabled(this->isVisible());
     311        this->tt2_->setEnabled(this->isVisible());
     312        this->redBillboard_.setVisible(this->isVisible());
     313        this->greenBillboard_.setVisible(this->isVisible());
     314        this->crosshairNear_.setVisible(this->isVisible());
     315        this->crosshairFar_.setVisible(this->isVisible());
     316        this->rightThrusterFlare_.setVisible(this->isVisible());
     317        this->leftThrusterFlare_.setVisible(this->isVisible());
     318    }
     319
    247320    void SpaceShip::setCamera(const std::string& camera)
    248321    {
     322      myShip_=true; // TODO: this is only a hack
    249323      camName_=camera;
    250324      // change camera attributes here, if you want to ;)
     
    266340      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    267341      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
    268       this->camNode_->setPosition(Vector3(-50,0,10));
     342      this->camNode_->setPosition(Vector3(-25,0,5));
    269343//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    270344//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     
    277351      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    278352      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(1,0,0));
    279       camNode_->setOrientation(q2*q1);
     353      this->camNode_->setOrientation(q2*q1);
    280354      if(network::Client::getSingleton()!=0 && network::Client::getSingleton()->getShipID()==objectID){
    281355        this->setBacksync(true);
    282356        CameraHandler::getInstance()->requestFocus(cam_);
    283357      }
    284 
    285358    }
    286359
     
    318391        XMLPortParamLoadOnly(SpaceShip, "transDamp", setTransDamp, xmlelement, mode);
    319392        XMLPortParamLoadOnly(SpaceShip, "rotDamp", setRotDamp, xmlelement, mode);
    320         myShip_=true; // TODO: this is only a hack
    321393
    322394        SpaceShip::create();
     
    325397    }
    326398
    327     int sgn(float x)
    328     {
    329         if (x >= 0)
    330             return 1;
    331         else
    332             return -1;
    333     }
    334 
    335399    std::string SpaceShip::whereAmI() {
    336         return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
    337         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
    338         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
    339     }
    340 
    341     Vector3 SpaceShip::getDir() {
    342         return currentDir_;
    343     }
    344 
    345     Vector3 SpaceShip::getOrth(){
    346         return currentOrth_;
    347     }
    348 
    349     float SpaceShip::getMaxSpeed() { return maxSpeed_; }
     400        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
     401        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
     402        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
     403    }
    350404
    351405    void SpaceShip::tick(float dt)
    352406    {
     407        if (!this->isActive())
     408            return;
     409
    353410        currentDir_ = getOrientation()*initialDir_;
    354                 currentOrth_ = getOrientation()*initialOrth_;
     411        currentOrth_ = getOrientation()*initialOrth_;
    355412
    356413        if (this->cam_)
    357414            this->cam_->tick(dt);
     415
     416        if (this->smoke_)
     417            this->smoke_->setVisible(this->isVisible() && this->health_ < 40);
     418        if (this->fire_)
     419            this->fire_->setVisible(this->isVisible() && this->health_ < 20);
     420
     421        if (this->backlight_)
     422        {   // (there's already fire ||                 we're to slow                 ||                  we're moving backwards                  )
     423            if (this->health_ < 20   || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0)
     424                this->backlight_->setActive(false);
     425            else
     426                this->backlight_->setActive(true);
     427        }
    358428
    359429        if (this->redNode_ && this->greenNode_)
     
    374444        {
    375445
    376             Projectile *p;
    377             if (this->isExactlyA(Class(SpaceShip)))
    378                 p = new RotatingProjectile(this);
    379             else
    380                 p = new Projectile(this);
    381             p->setColour(this->getProjectileColour());
    382             p->create();
    383             if(p->classID==0)
     446            BillboardProjectile* projectile = new ParticleProjectile(this);
     447            projectile->setColour(this->getProjectileColour());
     448            projectile->create();
     449            if (projectile->classID == 0)
     450            {
    384451              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
    385 
    386             p->setBacksync(true);
     452            }
     453
     454            projectile->setBacksync(true);
    387455            this->timeToReload_ = this->reloadTime_;
    388456        }
     
    464532
    465533        if (this->acceleration_.x > 0)
    466             this->tt_->setRate(emitterRate_);
     534        {
     535            this->tt1_->setEnabled(true);
     536            this->tt2_->setEnabled(true);
     537        }
    467538        else
    468             this->tt_->setRate(0);
    469 
    470         if( myShip_ )
    471         {
    472           COUT(5) << "steering our ship: " << objectID << std::endl;
    473           this->acceleration_.x = 0;
    474           this->acceleration_.y = 0;
    475           this->momentum_ = 0;
    476           this->mouseXRotation_ = Radian(0);
    477           this->mouseYRotation_ = Radian(0);
    478           this->bLMousePressed_ = false;
    479         }/*else
    480           COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
     539        {
     540            this->tt1_->setEnabled(false);
     541            this->tt2_->setEnabled(false);
     542        }
     543
     544        COUT(5) << "steering our ship: " << objectID << std::endl;
     545        this->acceleration_.x = 0;
     546        this->acceleration_.y = 0;
     547        this->momentum_ = 0;
     548        this->mouseXRotation_ = Radian(0);
     549        this->mouseYRotation_ = Radian(0);
     550        this->bLMousePressed_ = false;
    481551    }
    482552
  • code/branches/input/src/orxonox/objects/SpaceShip.h

    r1535 r1629  
    3636#include "Camera.h"
    3737#include "Model.h"
     38#include "RadarViewable.h"
    3839#include "tools/BillboardSet.h"
    3940
    4041namespace orxonox
    4142{
    42     class _OrxonoxExport SpaceShip : public Model
     43    class _OrxonoxExport SpaceShip : public Model, public RadarViewable
    4344    {
    4445        public:
    45          
    46 
    4746            static SpaceShip *getLocalShip();
    4847
     
    5554            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5655            virtual void tick(float dt);
     56            virtual void changedVisibility();
     57            virtual void changedActivity();
    5758
    5859            void setCamera(const std::string& camera = "");
     
    6566            void setRotDamp(float value);
    6667            void getFocus();
     68
     69            inline float getMaxSpeed() const
     70                { return this->maxSpeed_; }
     71            inline float getMaxSideAndBackSpeed() const
     72                { return this->maxSideAndBackSpeed_; }
     73            inline float getMaxRotation() const
     74                { return this->maxRotation_; }
     75            inline float getTransAcc() const
     76                { return this->translationAcceleration_; }
     77            inline float getRotAcc() const
     78                { return this->rotationAcceleration_; }
     79            inline float getTransDamp() const
     80                { return this->translationDamping_; }
     81            inline float getRotDamp() const
     82                { return this->rotationDamping_; }
    6783
    6884            static std::string whereAmI();
     
    8399            void doFire();
    84100
    85             float getMaxSpeed();
    86             Vector3 getDir();
    87             Vector3 getOrth();
     101            inline const Vector3& getDir() const
     102                { return this->currentDir_; }
     103            inline const Vector3& getInitialDir() const
     104                { return this->initialDir_; }
     105            inline const Vector3& getOrth() const
     106                { return this->currentOrth_; }
     107            inline const Vector3& getInitialOrth() const
     108                { return this->initialOrth_; }
     109
    88110            Camera* getCamera();
    89111
    90112            int getTeamNr() const
    91113                { return this->teamNr_; }
    92             int getHealth() const
     114            float getHealth() const
    93115                { return this->health_; }
    94116
     
    110132            Vector3 currentOrth_;
    111133            bool bInvertYAxis_;
    112             bool setMouseEventCallback_;
    113134            bool bLMousePressed_;
    114135            bool bRMousePressed_;
     
    118139            std::string camName_;
    119140
     141            ParticleInterface* tt1_;
     142            ParticleInterface* tt2_;
     143            BillboardSet leftThrusterFlare_;
     144            BillboardSet rightThrusterFlare_;
    120145
    121             ParticleInterface* tt_;
     146            Backlight* backlight_;
    122147
    123148            BillboardSet redBillboard_;
     
    126151            Ogre::SceneNode* greenNode_;
    127152            float blinkTime_;
     153
     154            ParticleSpawner* smoke_;
     155            ParticleSpawner* fire_;
    128156
    129157            BillboardSet crosshairNear_;
     
    153181            float mouseY_;
    154182
    155             float emitterRate_;
    156 
    157183        protected:
    158184            bool myShip_;
    159185
    160186            int teamNr_;
    161             int health_;
     187            float health_;
    162188
    163189            static SpaceShip* instance_s;
  • code/branches/input/src/orxonox/objects/SpaceShipAI.cc

    r1505 r1629  
    3232#include <OgreMath.h>
    3333#include "Projectile.h"
     34#include "ParticleSpawner.h"
    3435#include "core/CoreIncludes.h"
    3536#include "core/Iterator.h"
     
    3738#include "core/ConsoleCommand.h"
    3839#include "core/XMLPort.h"
     40#include "tools/ParticleInterface.h"
    3941
    4042#define ACTION_INTERVAL 1.0f
     
    5153        RegisterObject(SpaceShipAI);
    5254
    53         this->alive_ = true;
    54         this->setPosition(Vector3(rnd(-1000, 1000), rnd(-1000, 1000), rnd(-1000, 0000)));
    5555        this->target_ = 0;
    5656        this->bShooting_ = 0;
     
    7070    }
    7171
     72    SpaceShipAI::~SpaceShipAI()
     73    {
     74        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; ++it)
     75            it->shipDied(this);
     76    }
     77
    7278    void SpaceShipAI::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    7379    {
    7480        SpaceShip::XMLPort(xmlelement, mode);
    75         myShip_=true;
    7681
    7782        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));
     
    8590            newenemy->setMesh("assff.mesh");
    8691//            newenemy->setPosition(0, 0, 0);
     92            newenemy->setPosition(Vector3(rnd(-3000, 3000), rnd(-3000, 3000), rnd(-3000, 3000)));
    8793            newenemy->setScale(10);
    8894            newenemy->setMaxSpeed(500);
     
    95101            Element xmlelement;
    96102            newenemy->XMLPort(xmlelement, XMLPort::LoadObject);
     103
     104            ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", LODParticle::normal, 2.0, 0, 0, newenemy->getOrth());
     105            spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50);
     106            spawneffect->create();
    97107        }
    98108    }
     
    103113        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; )
    104114        {
    105             delete *(it++);
    106             ++i;
     115            (it++)->kill();
    107116            if (num && i >= num)
    108117                break;
     
    122131        // search enemy
    123132        random = rnd(maxrand);
    124 //std::cout << "search enemy: " << random << std::endl;
    125         if (random < 20 && (!this->target_))
    126         {
     133        if (random < 15 && (!this->target_))
    127134            this->searchNewTarget();
    128         }
    129135
    130136        // forget enemy
    131137        random = rnd(maxrand);
    132 //std::cout << "forget enemy: " << random << std::endl;
    133138        if (random < 5 && (this->target_))
    134         {
    135139            this->forgetTarget();
    136         }
    137140
    138141        // next enemy
    139142        random = rnd(maxrand);
    140 //std::cout << "next enemy: " << random << std::endl;
    141143        if (random < 10 && (this->target_))
    142         {
    143144            this->searchNewTarget();
    144         }
    145145
    146146        // fly somewhere
    147147        random = rnd(maxrand);
    148 //std::cout << "fly somewhere: " << random << std::endl;
    149         if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))
    150         {
     148        if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    151149            this->searchNewTargetPosition();
    152         }
    153150
    154151        // stop flying
    155152        random = rnd(maxrand);
    156 //std::cout << "stop flying: " << random << std::endl;
    157153        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    158         {
    159154            this->bHasTargetPosition_ = false;
    160         }
    161155
    162156        // fly somewhere else
    163157        random = rnd(maxrand);
    164 //std::cout << "fly somewhere else: " << random << std::endl;
    165158        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    166         {
    167159            this->searchNewTargetPosition();
    168         }
    169160
    170161        // shoot
    171162        random = rnd(maxrand);
    172 //std::cout << "shoot: " << random << std::endl;
    173163        if (random < 75 && (this->target_ && !this->bShooting_))
    174         {
    175164            this->bShooting_ = true;
    176         }
    177165
    178166        // stop shooting
    179167        random = rnd(maxrand);
    180 //std::cout << "stop shooting: " << random << std::endl;
    181168        if (random < 25 && (this->bShooting_))
    182         {
    183169            this->bShooting_ = false;
    184         }
     170    }
     171
     172    void SpaceShipAI::damage(float damage)
     173    {
     174        this->health_ -= damage;
     175        if (this->health_ <= 0)
     176        {
     177            this->kill();
     178            SpaceShipAI::createEnemy(1);
     179        }
     180    }
     181
     182    void SpaceShipAI::kill()
     183    {
     184        ParticleSpawner* explosion = new ParticleSpawner("Orxonox/BigExplosion1part1", LODParticle::low, 3.0);
     185        explosion->setPosition(this->getPosition());
     186        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     187        explosion->setScale(4);
     188        explosion->create();
     189
     190        explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", LODParticle::normal, 3.0);
     191        explosion->setPosition(this->getPosition());
     192        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     193        explosion->setScale(4);
     194        explosion->create();
     195        explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", LODParticle::high, 3.0);
     196        explosion->setPosition(this->getPosition());
     197        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     198        explosion->setScale(4);
     199        explosion->create();
     200
     201        Vector3 ringdirection = Vector3(rnd(), rnd(), rnd());
     202        ringdirection.normalise();
     203        explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::normal, 3.0, 0.5, 0, ringdirection);
     204        explosion->setPosition(this->getPosition());
     205        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     206        explosion->setScale(4);
     207        explosion->create();
     208        explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::high, 3.0, 0.5, 0, ringdirection);
     209        explosion->setPosition(this->getPosition());
     210        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     211        explosion->setScale(4);
     212        explosion->create();
     213
     214        delete this;
    185215    }
    186216
    187217    void SpaceShipAI::tick(float dt)
    188218    {
     219        if (!this->isActive())
     220            return;
     221
    189222        if (this->target_)
    190223            this->aimAtTarget();
     
    193226            this->moveToTargetPosition(dt);
    194227
    195         if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))
     228        if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
    196229            this->doFire();
    197230
     
    201234    void SpaceShipAI::moveToTargetPosition(float dt)
    202235    {
    203         static Radian RadianZERO(0);
    204 
    205 //        float dotprod = (this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(this->targetPosition_ - this->getPosition());
    206         Quaternion rotation = (this->getOrientation() * Ogre::Vector3::UNIT_X).getRotationTo(this->targetPosition_ - this->getPosition());
    207 /*
    208 std::cout << "scalprod: " << dotprod << std::endl;
    209 std::cout << "dist: " << this->targetPosition_ - this->getPosition() << std::endl;
    210 std::cout << "yaw: " << rotation.getYaw().valueRadians() << std::endl;
    211 std::cout << "pitch: " << rotation.getPitch().valueRadians() << std::endl;
    212 std::cout << "roll: " << rotation.getRoll().valueRadians() << std::endl;
    213 */
    214         this->setMoveYaw(-rotation.getRoll().valueRadians());
    215         this->setMovePitch(rotation.getYaw().valueRadians());
    216 
    217         if ((this->targetPosition_ - this->getPosition()).length() > 100)
    218         {
    219             this->setMoveLongitudinal(1);
    220         }
    221 
     236        Vector2 coord = get2DViewdirection(this->getPosition(), this->getDir(), this->getOrth(), this->targetPosition_);
     237
     238        float distance = (this->targetPosition_ - this->getPosition()).length();
     239        if (this->target_ || distance > 50)
     240        {
     241            // Multiply with 0.8 to make them a bit slower
     242            this->setMoveYaw(0.8 * sgn(coord.x) * coord.x*coord.x);
     243            this->setMovePitch(0.8 * sgn(coord.y) * coord.y*coord.y);
     244        }
     245
     246        if (this->target_ && distance < 1000 && this->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     247            this->setMoveLongitudinal(-0.5); // They don't brake with full power to give the player a chance
     248        else if (!this->target_ && distance <= this->getVelocity().length() / (2 * this->getTransAcc()))
     249            this->setMoveLongitudinal(-1.0);
     250        else
     251            this->setMoveLongitudinal(0.8);
    222252    }
    223253
     
    241271                Vector3 distanceNew = it->getPosition() - this->getPosition();
    242272                if (!this->target_ || it->getPosition().squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI))
    243                         < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)))
     273                        < this->targetPosition_.squaredDistance(this->getPosition()) * (1.5f + acos((this->getOrientation() * Ogre::Vector3::UNIT_X).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) + rnd(-250, 250))
    244274                {
    245275                    this->target_ = (*it);
     
    248278            }
    249279        }
    250    }
     280    }
    251281
    252282    void SpaceShipAI::forgetTarget()
     
    260290        if (!this->target_)
    261291            return;
    262 /*
    263         Vector3 enemymovement = this->target_->getVelocity();
    264         Vector3 distance_normalised = this->target_->getPosition() - this->getPosition();
    265         distance_normalised.normalise();
    266 
    267         float scalarprod = enemymovement.dotProduct(distance_normalised);
    268         float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength();
    269         if (aimoffset < 0)
    270         {
    271             this->bHasTargetPosition_ = false;
    272             return;
    273         }
    274         aimoffset = -scalarprod + sqrt(aimoffset);
    275         this->targetPosition_ = enemymovement + distance_normalised * aimoffset;
    276         this->bHasTargetPosition_ = true;
    277 
    278         std::cout << "targetpos: " << this->targetPosition_ << std::endl;
    279 */
    280         this->targetPosition_ = this->target_->getPosition();
    281         this->bHasTargetPosition_ = true;
     292
     293        this->targetPosition_ = getPredictedPosition(this->getPosition(), Projectile::getSpeed(), this->target_->getPosition(), this->target_->getOrientation() * this->target_->getVelocity());
     294        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    282295    }
    283296
    284297    bool SpaceShipAI::isCloseAtTarget(float distance)
    285298    {
    286         return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     299        if (!this->target_)
     300            return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     301        else
     302            return (this->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
    287303    }
    288304
    289305    bool SpaceShipAI::isLookingAtTarget(float angle)
    290306    {
    291         return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle));
     307        return (getAngle(this->getPosition(), this->getDir(), this->targetPosition_) < angle);
     308    }
     309
     310    void SpaceShipAI::shipDied(SpaceShipAI* ship)
     311    {
     312        if (ship == this->target_)
     313        {
     314            this->forgetTarget();
     315            this->searchNewTargetPosition();
     316        }
    292317    }
    293318}
  • code/branches/input/src/orxonox/objects/SpaceShipAI.h

    r1505 r1629  
    4444        public:
    4545            SpaceShipAI();
     46            virtual ~SpaceShipAI();
     47
    4648            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    4749            static void createEnemy(int num);
    4850            static void killEnemies(int num);
     51            void shipDied(SpaceShipAI* ship);
     52            void damage(float damage);
     53            void kill();
    4954
    5055        private:
     
    6469            Timer<SpaceShipAI> actionTimer_;
    6570
    66             bool alive_;
    6771            bool bHasTargetPosition_;
    6872            Vector3 targetPosition_;
  • code/branches/input/src/orxonox/objects/WorldEntity.cc

    r1505 r1629  
    4545    unsigned int WorldEntity::worldEntityCounter_s = 0;
    4646
    47     WorldEntity::WorldEntity() :
    48       velocity_    (0, 0, 0),
    49       acceleration_(0, 0, 0),
    50       rotationAxis_(0, 1, 0),
    51       rotationRate_(0),
    52       momentum_    (0),
    53       node_        (0),
    54       bStatic_     (true)
     47    WorldEntity::WorldEntity()
    5548    {
    5649        RegisterObject(WorldEntity);
     
    5851        if (GraphicsEngine::getSingleton().getSceneManager())
    5952        {
    60           std::ostringstream name;
    61           name << (WorldEntity::worldEntityCounter_s++);
    62           this->setName("WorldEntity" + name.str());
    63           this->node_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
     53            std::ostringstream name;
     54            name << (WorldEntity::worldEntityCounter_s++);
     55            this->setName("WorldEntity" + name.str());
     56            this->node_ = GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->createChildSceneNode(this->getName());
    6457
    65           registerAllVariables();
     58            registerAllVariables();
    6659        }
     60        else
     61        {
     62            this->node_ = 0;
     63        }
     64
     65        this->bStatic_ = true;
     66        this->velocity_ = Vector3(0, 0, 0);
     67        this->acceleration_ = Vector3(0, 0, 0);
     68        this->rotationAxis_ = Vector3(0, 1, 0);
     69        this->rotationRate_ = 0;
     70        this->momentum_ = 0;
    6771    }
    68    
     72
    6973
    7074    WorldEntity::~WorldEntity()
    7175    {
    72       // just to make sure we clean out all scene nodes
    73       if(this->getNode())
    74         this->getNode()->removeAndDestroyAllChildren();
     76        if (this->isInitialized())
     77        {
     78            this->getNode()->removeAndDestroyAllChildren();
     79            GraphicsEngine::getSingleton().getSceneManager()->destroySceneNode(this->getName());
     80        }
    7581    }
    7682
    7783    void WorldEntity::tick(float dt)
    7884    {
    79         if (!this->bStatic_)
     85        if (!this->bStatic_ && this->isActive())
    8086        {
    8187//             COUT(4) << "acceleration: " << this->acceleration_ << " velocity: " << this->velocity_ << std::endl;
     
    8995    }
    9096
    91     void WorldEntity::loadParams(TiXmlElement* xmlElem)
    92     {
    93 
    94         BaseObject::loadParams(xmlElem);
    95         create();
    96     }
    97    
    9897
    9998    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
     
    122121
    123122        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
    124        
     123
    125124        WorldEntity::create();
    126125    }
     
    129128    void WorldEntity::registerAllVariables()
    130129    {
     130      // register inheritec variables from BaseObject
     131      registerVar( (void*) &(this->bActive_), sizeof(this->bActive_), network::DATA, 0x3);
     132      registerVar( (void*) &(this->bVisible_), sizeof(this->bVisible_), network::DATA, 0x3);
    131133      // register coordinates
    132134      registerVar( (void*) &(this->getPosition().x), sizeof(this->getPosition().x), network::DATA, 0x3);
     
    163165    {
    164166        this->attachedWorldEntities_.push_back(entity);
     167        this->attachObject(entity);
    165168    }
    166169
     
    172175            return 0;
    173176    }
     177
     178    void WorldEntity::attachObject(const WorldEntity& obj) const
     179    {
     180        GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeChild(obj.getNode());
     181        this->getNode()->addChild(obj.getNode());
     182    }
     183
     184    void WorldEntity::attachObject(WorldEntity* obj) const
     185    {
     186        GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->removeChild(obj->getNode());
     187        this->getNode()->addChild(obj->getNode());
     188    }
    174189}
  • code/branches/input/src/orxonox/objects/WorldEntity.h

    r1535 r1629  
    5151
    5252            virtual void tick(float dt);
    53             virtual void loadParams(TiXmlElement* xmlElem);
    5453            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5554            virtual inline bool create(){ return Synchronisable::create(); }
     
    5857            const WorldEntity* getAttachedWorldEntity(unsigned int index) const;
    5958
    60             inline Ogre::SceneNode* getNode()
     59            inline Ogre::SceneNode* getNode() const
    6160                { return this->node_; }
    6261
     
    7473            inline const Vector3& getPosition() const
    7574                { return this->node_->getPosition(); }
    76 
    77             inline void translate(const Vector3 &d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     75            inline const Vector3& getWorldPosition() const
     76                { return this->node_->getWorldPosition(); }
     77
     78            inline void translate(const Vector3& d, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    7879                { this->node_->translate(d, relativeTo); }
    7980            inline void translate(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    8081                { this->node_->translate(x, y, z, relativeTo); }
    81             inline void translate(const Matrix3 &axes, const Vector3 &move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     82            inline void translate(const Matrix3& axes, const Vector3& move, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    8283                { this->node_->translate(axes, move, relativeTo); }
    83             inline void translate(const Matrix3 &axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
     84            inline void translate(const Matrix3& axes, Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_PARENT)
    8485                { this->node_->translate(axes, x, y, z, relativeTo); }
    8586
    86             inline void yaw(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     87            inline void yaw(const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    8788                { this->node_->yaw(angle, relativeTo); }
    88             inline void pitch(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     89            inline void pitch(const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    8990                { this->node_->pitch(angle, relativeTo); }
    90             inline void roll(const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     91            inline void roll(const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    9192                { this->node_->roll(angle, relativeTo); }
    9293            void setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll);
    9394
    94             inline void setYaw(const Degree &angle)
     95            inline void setYaw(const Degree& angle)
    9596                { this->node_->yaw(angle, Ogre::Node::TS_LOCAL); }
    96             inline void setPitch(const Degree &angle)
     97            inline void setPitch(const Degree& angle)
    9798                { this->node_->pitch(angle, Ogre::Node::TS_LOCAL); }
    98             inline void setRoll(const Degree &angle)
     99            inline void setRoll(const Degree& angle)
    99100                { this->node_->roll(angle, Ogre::Node::TS_LOCAL); }
    100101
    101102            inline const Ogre::Quaternion& getOrientation()
    102103              { return this->node_->getOrientation(); }
     104            inline const Ogre::Quaternion& getWorldOrientation()
     105              { return this->node_->getWorldOrientation(); }
    103106            inline void setOrientation(const Ogre::Quaternion& quat)
    104107              { this->node_->setOrientation(quat); }
    105             inline void rotate(const Vector3 &axis, const Radian &angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
     108            inline void rotate(const Vector3& axis, const Radian& angle, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL)
    106109              { this->node_->rotate(axis, angle, relativeTo); }
    107110            inline void setDirectionLoader(Real x, Real y, Real z)
    108111              { this->setDirection(x, y, z); }
    109             inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
     112            inline void setDirection(Real x, Real y, Real z, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
    110113              { this->node_->setDirection(x, y, z, relativeTo, localDirectionVector); }
    111             inline void setDirection(const Vector3 &vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
     114            inline void setDirection(const Vector3& vec, Ogre::Node::TransformSpace relativeTo=Ogre::Node::TS_LOCAL, const Vector3& localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
    112115              { this->node_->setDirection(vec, relativeTo, localDirectionVector); }
    113             inline void lookAt(const Vector3 &targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3 &localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
     116            inline void lookAt(const Vector3& targetPoint, Ogre::Node::TransformSpace relativeTo, const Vector3& localDirectionVector=Vector3::NEGATIVE_UNIT_Z)
    114117              { this->node_->lookAt(targetPoint, relativeTo, localDirectionVector); }
    115118
    116             inline void setScale(const Vector3 &scale)
     119            inline void setScale(const Vector3& scale)
    117120              { this->node_->setScale(scale); }
    118121            inline void setScale(Real x, Real y, Real z)
     
    124127            inline const Vector3& getScale(void) const
    125128              { return this->node_->getScale(); }
    126             inline void scale(const Vector3 &scale)
     129            inline void scale(const Vector3& scale)
    127130              { this->node_->scale(scale); }
    128131            inline void scale(Real x, Real y, Real z)
     
    131134              { this->node_->scale(scale, scale, scale); }
    132135
    133             inline void attachObject(Ogre::MovableObject *obj)
     136            void attachObject(const WorldEntity& obj) const;
     137            void attachObject(WorldEntity* obj) const;
     138            inline void attachObject(Ogre::MovableObject* obj) const
    134139              { this->node_->attachObject(obj); }
    135             inline void attachObject(Mesh &mesh)
     140            inline void attachObject(Mesh& mesh) const
    136141              { this->node_->attachObject(mesh.getEntity()); }
    137             inline void detachObject(Ogre::MovableObject *obj)
     142            inline void detachObject(Ogre::MovableObject* obj) const
    138143              { this->node_->detachObject(obj); }
    139             inline void detachAllObjects()
     144            inline void detachAllObjects() const
    140145              { this->node_->detachAllObjects(); }
    141146
     
    179184            inline void setStatic(bool bStatic)
    180185                { this->bStatic_ = bStatic; }
    181             inline bool isStatic()
     186            inline bool isStatic() const
    182187                { return this->bStatic_; }
    183188
Note: See TracChangeset for help on using the changeset viewer.