Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1552 for code


Ignore:
Timestamp:
Jun 6, 2008, 5:31:58 PM (16 years ago)
Author:
landauf
Message:

several improvements:

  • AI works properly now - add enemies with 'createEnemy x' where x is the number of enemies to add, default is 1. You can remove AI ships with 'killEnemies'.
  • Added new explosion (with smoke)
  • Added new projectile (with trail)
  • Added new thruster emitter
  • AI ships are destroyable - they start with 100 hp, each hit makes 15 hp damage, this value is configurable in the config-file: [Projectile] damage_
  • Added AI ship spawn and explosion effects
Location:
code/trunk/src
Files:
6 added
2 deleted
17 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/asylum/orxonox/objects/Fighter.cc

    r1505 r1552  
    132132#if 0
    133133        w = new particle::ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"schuss" + this->getName(),"Orxonox/schuss");
    134         w->getParticleSystem()->setParameter("local_space","true");
    135134        w->newEmitter();
    136135/*
     
    151150
    152151        tt = new ParticleInterface(GraphicsEngine::getSingleton().getSceneManager(),"twinthruster" + this->getName(),"Orxonox/engineglow");
    153         tt->getParticleSystem()->setParameter("local_space","true");
    154152        tt->newEmitter();
    155153/*
  • code/trunk/src/orxonox/CMakeLists.txt

    r1535 r1552  
    2222  objects/Camera.cc
    2323  objects/CameraHandler.cc
    24   objects/Explosion.cc
    2524  objects/Model.cc
    2625  objects/NPC.cc
    27   objects/Projectile.cc
    28   objects/RotatingProjectile.cc
     26  objects/ParticleSpawner.cc
    2927  objects/Skybox.cc
    3028  objects/SpaceShip.cc
     
    3230  objects/Tickable.cc
    3331  objects/WorldEntity.cc
     32
     33  objects/Projectile.cc
     34  objects/BillboardProjectile.cc
     35  objects/RotatingProjectile.cc
     36  objects/ParticleProjectile.cc
    3437
    3538#  objects/weapon/AmmunitionDump.cc
  • code/trunk/src/orxonox/OrxonoxPrereqs.h

    r1505 r1552  
    6767  class Ambient;
    6868  class Camera;
    69   class Explosion;
    7069  class Fighter;
    7170  class Model;
    7271  class NPC;
    73   class Projectile;
     72  class ParticleSpawner;
    7473  class Skybox;
    7574  class SpaceShip;
    7675  class SpaceShipAI;
    7776  class WorldEntity;
     77
     78  class Projectile;
     79  class BillboardProjectile;
     80  class RotatingProjectile;
     81  class ParticleProjectile;
    7882
    7983  class AmmunitionDump;
  • code/trunk/src/orxonox/objects/Model.cc

    r1511 r1552  
    4545    CreateFactory(Model);
    4646
    47     Model::Model()
     47    Model::Model() : meshSrc_("")
    4848    {
    4949        RegisterObject(Model);
     
    5353    Model::~Model()
    5454    {
     55        if ((this->meshSrc_ != "") && (this->meshSrc_.size() > 0))
     56            this->detachObject(this->mesh_.getEntity());
    5557    }
    5658
  • code/trunk/src/orxonox/objects/Projectile.cc

    r1505 r1552  
    3535#include "core/Executor.h"
    3636#include "core/ConfigValueIncludes.h"
     37#include "particle/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_ = 2000;
    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/explosion1";
     53        this->smokeTemplateName_ = "Orxonox/smoke3";
    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");
     73        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
     74        SetConfigValue(lifetime_, 5.0).description("The time in seconds a projectile stays alive");
    7975        SetConfigValue(speed_, 2000.0).description("The speed of a projectile in units per second");
    8076
    81         this->setVelocity(Vector3(1, 0, 0) * this->speed_);
     77        this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    8278    }
    8379
     
    9591                if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    9692                {
    97                     Explosion *exp = new Explosion(this);
    98                     exp->create();
     93                    // hit
     94                    if (it->isA(Class(SpaceShipAI)))
     95                        ((SpaceShipAI*)(*it))->damage(this->damage_);
     96                    ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, 2.0);
     97                    explosion->setPosition(this->getPosition());
     98                    explosion->create();
     99                    ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, 6.0, 0.0);
     100                    smoke->setPosition(this->getPosition());
     101                    smoke->getParticleInterface()->setSpeedFactor(3.0);
     102                    smoke->create();
    99103                    delete this;
    100104                    return;
     
    108112        delete this;
    109113    }
    110 
    111     void Projectile::setColour(const ColourValue& colour)
    112     {
    113         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
    114     }
    115114}
  • code/trunk/src/orxonox/objects/Projectile.h

    r1505 r1552  
    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/trunk/src/orxonox/objects/RotatingProjectile.cc

    r1505 r1552  
    3737    CreateFactory(RotatingProjectile);
    3838
    39     RotatingProjectile::RotatingProjectile(SpaceShip* owner) : Projectile(owner)
     39    RotatingProjectile::RotatingProjectile(SpaceShip* owner) : BillboardProjectile(owner)
    4040    {
    4141        RegisterObject(RotatingProjectile);
  • code/trunk/src/orxonox/objects/RotatingProjectile.h

    r1505 r1552  
    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();}
    1817
    1918        private:
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1535 r1552  
    4444#include "core/input/InputManager.h"
    4545#include "particle/ParticleInterface.h"
    46 #include "Projectile.h"
    4746#include "RotatingProjectile.h"
     47#include "ParticleProjectile.h"
    4848#include "core/XMLPort.h"
    4949#include "core/ConsoleCommand.h"
     
    6969    SpaceShip* SpaceShip::instance_s;
    7070
    71    
     71
    7272    SpaceShip *SpaceShip::getLocalShip(){
    7373      Iterator<SpaceShip> it;
     
    8888      cam_(0),
    8989      camName_("CamNode"),
    90       tt_(0),
     90      tt1_(0),
     91      tt2_(0),
    9192      redNode_(0),
    9293      greenNode_(0),
     
    111112      mouseX_(0.0f),
    112113      mouseY_(0.0f),
    113       emitterRate_(0.0f),
    114114      myShip_(false),
    115115      teamNr_(0),
     
    138138    SpaceShip::~SpaceShip()
    139139    {
    140         if (this->tt_)
    141             delete this->tt_;
     140        if (this->tt1_)
     141            delete this->tt1_;
     142        if (this->tt2_)
     143            delete this->tt2_;
    142144        if(setMouseEventCallback_)
    143145          InputManager::removeMouseHandler("SpaceShip");
     
    180182    {
    181183        // 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);
     184        this->tt1_ = new ParticleInterface("Orxonox/thruster1");
     185        this->tt1_->createNewEmitter();
     186        this->tt1_->getAllEmitters()->setDirection(-this->getInitialDir());
     187        this->tt1_->getEmitter(0)->setPosition(Vector3(-15, 20, -1));
     188        this->tt1_->getEmitter(1)->setPosition(Vector3(-15, -20, -1));
     189        this->tt1_->setSpeedFactor(3.0);
     190
     191        Ogre::SceneNode* node2a = this->getNode()->createChildSceneNode(this->getName() + "particle2a");
     192        node2a->setInheritScale(false);
     193        node2a->setScale(1, 1, 1);
     194        tt1_->addToSceneNode(node2a);
     195
     196        this->tt2_ = new ParticleInterface("Orxonox/thruster2");
     197        this->tt2_->createNewEmitter();
     198        this->tt2_->getAllEmitters()->setDirection(Vector3(-1, 0, 0));
     199        this->tt2_->getEmitter(0)->setPosition(Vector3(-30, 40, -2));
     200        this->tt2_->getEmitter(1)->setPosition(Vector3(-30, -40, -2));
     201
     202        Ogre::SceneNode* node2b = this->getNode()->createChildSceneNode(this->getName() + "particle2b");
     203        node2b->setInheritScale(false);
     204        node2b->setScale(0.5, 0.5, 0.5);
     205        tt2_->addToSceneNode(node2b);
    200206        // END CREATING THRUSTER
    201207
     
    266272      this->camNode_ = this->getNode()->createChildSceneNode(camName_);
    267273      COUT(4) << "position: (this)" << this->getNode()->getPosition() << std::endl;
    268       this->camNode_->setPosition(Vector3(-50,0,10));
     274      this->camNode_->setPosition(Vector3(-25,0,5));
    269275//      Quaternion q1 = Quaternion(Radian(Degree(90)),Vector3(0,-1,0));
    270276//      Quaternion q2 = Quaternion(Radian(Degree(90)),Vector3(0,0,-1));
     
    339345    }
    340346
    341     Vector3 SpaceShip::getDir() {
    342         return currentDir_;
    343     }
    344 
    345     Vector3 SpaceShip::getOrth(){
    346         return currentOrth_;
    347     }
    348 
    349     float SpaceShip::getMaxSpeed() { return maxSpeed_; }
    350 
    351347    void SpaceShip::tick(float dt)
    352348    {
     
    374370        {
    375371
    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)
     372            BillboardProjectile* projectile = new ParticleProjectile(this);
     373            projectile->setColour(this->getProjectileColour());
     374            projectile->create();
     375            if (projectile->classID == 0)
     376            {
    384377              COUT(3) << "generated projectile with classid 0" <<  std::endl; // TODO: remove this output
    385 
    386             p->setBacksync(true);
     378            }
     379
     380            projectile->setBacksync(true);
    387381            this->timeToReload_ = this->reloadTime_;
    388382        }
     
    464458
    465459        if (this->acceleration_.x > 0)
    466             this->tt_->setRate(emitterRate_);
     460        {
     461            this->tt1_->setEnabled(true);
     462            this->tt2_->setEnabled(true);
     463        }
    467464        else
    468             this->tt_->setRate(0);
     465        {
     466            this->tt1_->setEnabled(false);
     467            this->tt2_->setEnabled(false);
     468        }
    469469
    470470        if( myShip_ )
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1535 r1552  
    4343    {
    4444        public:
    45          
    46 
    4745            static SpaceShip *getLocalShip();
    4846
     
    6664            void getFocus();
    6765
     66            inline float getMaxSpeed() const
     67                { return this->maxSpeed_; }
     68            inline float getMaxSideAndBackSpeed() const
     69                { return this->maxSideAndBackSpeed_; }
     70            inline float getMaxRotation() const
     71                { return this->maxRotation_; }
     72            inline float getTransAcc() const
     73                { return this->translationAcceleration_; }
     74            inline float getRotAcc() const
     75                { return this->rotationAcceleration_; }
     76            inline float getTransDamp() const
     77                { return this->translationDamping_; }
     78            inline float getRotDamp() const
     79                { return this->rotationDamping_; }
     80
    6881            static std::string whereAmI();
    6982            static void setMaxSpeedTest(float value)
     
    8396            void doFire();
    8497
    85             float getMaxSpeed();
    86             Vector3 getDir();
    87             Vector3 getOrth();
     98            inline const Vector3& getDir() const
     99                { return this->currentDir_; }
     100            inline const Vector3& getInitialDir() const
     101                { return this->initialDir_; }
     102            inline const Vector3& getOrth() const
     103                { return this->currentOrth_; }
     104            inline const Vector3& getInitialOrth() const
     105                { return this->initialOrth_; }
     106
    88107            Camera* getCamera();
    89108
    90109            int getTeamNr() const
    91110                { return this->teamNr_; }
    92             int getHealth() const
     111            float getHealth() const
    93112                { return this->health_; }
    94113
     
    118137            std::string camName_;
    119138
    120 
    121             ParticleInterface* tt_;
     139            ParticleInterface* tt1_;
     140            ParticleInterface* tt2_;
    122141
    123142            BillboardSet redBillboard_;
     
    153172            float mouseY_;
    154173
    155             float emitterRate_;
    156 
    157174        protected:
    158175            bool myShip_;
    159176
    160177            int teamNr_;
    161             int health_;
     178            float health_;
    162179
    163180            static SpaceShip* instance_s;
  • code/trunk/src/orxonox/objects/SpaceShipAI.cc

    r1505 r1552  
    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 "particle/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;
    76 
     81
     82        this->myShip_=true;
    7783        this->actionTimer_.setTimer(ACTION_INTERVAL, true, this, createExecutor(createFunctor(&SpaceShipAI::action)));
    7884    }
     
    8591            newenemy->setMesh("assff.mesh");
    8692//            newenemy->setPosition(0, 0, 0);
     93            newenemy->setPosition(Vector3(rnd(-3000, 3000), rnd(-3000, 3000), rnd(-3000, 3000)));
    8794            newenemy->setScale(10);
    8895            newenemy->setMaxSpeed(500);
     
    95102            Element xmlelement;
    96103            newenemy->XMLPort(xmlelement, XMLPort::LoadObject);
     104
     105            ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", 2.0, 0.0, newenemy->getOrth());
     106            spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50);
     107            spawneffect->create();
    97108        }
    98109    }
     
    103114        for (Iterator<SpaceShipAI> it = ObjectList<SpaceShipAI>::begin(); it; )
    104115        {
    105             delete *(it++);
    106             ++i;
     116            (it++)->kill();
    107117            if (num && i >= num)
    108118                break;
     
    122132        // search enemy
    123133        random = rnd(maxrand);
    124 //std::cout << "search enemy: " << random << std::endl;
    125134        if (random < 20 && (!this->target_))
    126         {
    127135            this->searchNewTarget();
    128         }
    129136
    130137        // forget enemy
    131138        random = rnd(maxrand);
    132 //std::cout << "forget enemy: " << random << std::endl;
    133139        if (random < 5 && (this->target_))
    134         {
    135140            this->forgetTarget();
    136         }
    137141
    138142        // next enemy
    139143        random = rnd(maxrand);
    140 //std::cout << "next enemy: " << random << std::endl;
    141144        if (random < 10 && (this->target_))
    142         {
    143145            this->searchNewTarget();
    144         }
    145146
    146147        // fly somewhere
    147148        random = rnd(maxrand);
    148 //std::cout << "fly somewhere: " << random << std::endl;
    149149        if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))
    150         {
    151150            this->searchNewTargetPosition();
    152         }
    153151
    154152        // stop flying
    155153        random = rnd(maxrand);
    156 //std::cout << "stop flying: " << random << std::endl;
    157154        if (random < 10 && (this->bHasTargetPosition_ && !this->target_))
    158         {
    159155            this->bHasTargetPosition_ = false;
    160         }
    161156
    162157        // fly somewhere else
    163158        random = rnd(maxrand);
    164 //std::cout << "fly somewhere else: " << random << std::endl;
    165159        if (random < 30 && (this->bHasTargetPosition_ && !this->target_))
    166         {
    167160            this->searchNewTargetPosition();
    168         }
    169161
    170162        // shoot
    171163        random = rnd(maxrand);
    172 //std::cout << "shoot: " << random << std::endl;
    173164        if (random < 75 && (this->target_ && !this->bShooting_))
    174         {
    175165            this->bShooting_ = true;
    176         }
    177166
    178167        // stop shooting
    179168        random = rnd(maxrand);
    180 //std::cout << "stop shooting: " << random << std::endl;
    181169        if (random < 25 && (this->bShooting_))
    182         {
    183170            this->bShooting_ = false;
    184         }
     171    }
     172
     173    void SpaceShipAI::damage(float damage)
     174    {
     175        this->health_ -= damage;
     176        if (this->health_ <= 0)
     177        {
     178            this->kill();
     179            SpaceShipAI::createEnemy(1);
     180        }
     181    }
     182
     183    void SpaceShipAI::kill()
     184    {
     185        ParticleSpawner* explosion = new ParticleSpawner("Orxonox/BigExplosion1part1", 3.0);
     186        explosion->setPosition(this->getPosition());
     187        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     188        explosion->setScale(4);
     189        explosion->create();
     190
     191        explosion = new ParticleSpawner("Orxonox/BigExplosion1part2", 3.0);
     192        explosion->setPosition(this->getPosition());
     193        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     194        explosion->setScale(4);
     195        explosion->create();
     196
     197        Vector3 ringdirection = Vector3(rnd(), rnd(), rnd());
     198        ringdirection.normalise();
     199        explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", 3.0, 0.5, ringdirection);
     200        explosion->setPosition(this->getPosition());
     201        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     202        explosion->setScale(4);
     203        explosion->create();
     204
     205        delete this;
    185206    }
    186207
     
    193214            this->moveToTargetPosition(dt);
    194215
    195         if (this->bShooting_ && this->isCloseAtTarget(2000) && this->isLookingAtTarget(Ogre::Math::PI / 10.0f))
     216        if (this->bShooting_ && this->isCloseAtTarget(2500) && this->isLookingAtTarget(Ogre::Math::PI / 10))
    196217            this->doFire();
    197218
     
    201222    void SpaceShipAI::moveToTargetPosition(float dt)
    202223    {
    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         {
     224        Vector3 proj = Ogre::Plane(this->getDir(), this->getPosition()).projectVector(this->targetPosition_ - this->getPosition());
     225        float angle = acos((this->getOrth().dotProduct(proj)) / (this->getOrth().length()*proj.length()));
     226
     227        if ((this->getDir().crossProduct(this->getOrth())).dotProduct(this->targetPosition_ - this->getPosition()) > 0)
     228            this->setMoveYaw(sgn(sin(angle)));
     229        else
     230            this->setMoveYaw(-sgn(sin(angle)));
     231        this->setMovePitch(sgn(cos(angle)));
     232
     233        if ((this->targetPosition_ - this->getPosition()).length() > 300)
    219234            this->setMoveLongitudinal(1);
    220         }
    221 
     235
     236        if (this->isCloseAtTarget(300) && this->target_)
     237        {
     238            if (this->getVelocity().length() > this->target_->getVelocity().length())
     239                this->setMoveLongitudinal(-1);
     240        }
    222241    }
    223242
     
    241260                Vector3 distanceNew = it->getPosition() - this->getPosition();
    242261                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)))
     262                        < 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))
    244263                {
    245264                    this->target_ = (*it);
     
    248267            }
    249268        }
    250    }
     269    }
    251270
    252271    void SpaceShipAI::forgetTarget()
     
    260279        if (!this->target_)
    261280            return;
    262 /*
     281
    263282        Vector3 enemymovement = this->target_->getVelocity();
    264283        Vector3 distance_normalised = this->target_->getPosition() - this->getPosition();
     
    267286        float scalarprod = enemymovement.dotProduct(distance_normalised);
    268287        float aimoffset = scalarprod*scalarprod + Projectile::getSpeed() * Projectile::getSpeed() - this->target_->getVelocity().squaredLength();
     288
    269289        if (aimoffset < 0)
    270290        {
     
    273293        }
    274294        aimoffset = -scalarprod + sqrt(aimoffset);
    275         this->targetPosition_ = enemymovement + distance_normalised * aimoffset;
     295        this->targetPosition_ = this->getPosition() + enemymovement + distance_normalised * aimoffset;
    276296        this->bHasTargetPosition_ = true;
    277 
    278         std::cout << "targetpos: " << this->targetPosition_ << std::endl;
    279 */
    280         this->targetPosition_ = this->target_->getPosition();
    281         this->bHasTargetPosition_ = true;
    282297    }
    283298
    284299    bool SpaceShipAI::isCloseAtTarget(float distance)
    285300    {
    286         return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     301        if (!this->target_)
     302            return (this->getPosition().squaredDistance(this->targetPosition_) < distance*distance);
     303        else
     304            return (this->getPosition().squaredDistance(this->target_->getPosition()) < distance*distance);
    287305    }
    288306
    289307    bool SpaceShipAI::isLookingAtTarget(float angle)
    290308    {
    291         return (this->getOrientation() * Ogre::Vector3::UNIT_X).directionEquals(this->targetPosition_ - this->getPosition(), Radian(angle));
     309        Vector3 dist = this->targetPosition_ - this->getPosition();
     310        return (acos((this->getDir().dotProduct(dist)) / (dist.length() * this->getDir().length())) < angle);
     311    }
     312
     313    void SpaceShipAI::shipDied(SpaceShipAI* ship)
     314    {
     315        this->forgetTarget();
     316        this->searchNewTargetPosition();
    292317    }
    293318}
  • code/trunk/src/orxonox/objects/SpaceShipAI.h

    r1505 r1552  
    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/trunk/src/orxonox/objects/WorldEntity.cc

    r1505 r1552  
    6666        }
    6767    }
    68    
     68
    6969
    7070    WorldEntity::~WorldEntity()
    7171    {
    72       // just to make sure we clean out all scene nodes
    73       if(this->getNode())
    74         this->getNode()->removeAndDestroyAllChildren();
     72        // just to make sure we clean out all scene nodes
     73        if(this->getNode())
     74        {
     75            this->getNode()->removeAndDestroyAllChildren();
     76            GraphicsEngine::getSingleton().getSceneManager()->destroySceneNode(this->getName());
     77        }
    7578    }
    7679
     
    9598        create();
    9699    }
    97    
     100
    98101
    99102    void WorldEntity::setYawPitchRoll(const Degree& yaw, const Degree& pitch, const Degree& roll)
     
    122125
    123126        XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, mode, false, true);
    124        
     127
    125128        WorldEntity::create();
    126129    }
  • code/trunk/src/orxonox/particle/ParticleInterface.cc

    r1505 r1552  
    3434#include "ParticleInterface.h"
    3535
    36 // #include <OgreParticleSystem.h>
    37 // #include <Ogre.h>
    38 // #include <OIS/OIS.h>
    39 // #include <CEGUI/CEGUI.h>
    40 // #include <CEGUIRenderer.h>
     36#include <OgreParticleSystem.h>
     37#include <OgreParticleEmitter.h>
     38#include <OgreSceneManager.h>
    4139
     40#include "GraphicsEngine.h"
     41#include "util/Convert.h"
    4242
     43namespace orxonox
     44{
     45  unsigned int ParticleInterface::counter_s = 0;
     46  ParticleInterface* ParticleInterface::currentParticleInterface_s = 0;
    4347
    44 namespace orxonox {
    45   using namespace Ogre;
    46 
    47   ParticleInterface::ParticleInterface( SceneManager *sceneManager, std::string name, std::string templateName )
     48  ParticleInterface::ParticleInterface(const std::string& templateName)
    4849  {
    49     sceneManager_ = sceneManager;
    50     particleSystem_ = sceneManager->createParticleSystem(name, templateName);
    51 
    52     //Variabeln einlesen, Emitter1_ ist Referenz-Emitter
    53     velocity_ = particleSystem_->getSpeedFactor();
    54     colour_ = particleSystem_->getEmitter(0)->getColour();
    55     rate_ = particleSystem_->getEmitter(0)->getEmissionRate();
    56     distance_ = particleSystem_->getEmitter(0)->getTimeToLive();
    57 
    58     //Anzahl der Emitter
    59     numberOfEmitters_ = particleSystem_->getNumEmitters();
    60     standardizeEmitters();
     50    this->sceneNode_ = 0;
     51    this->particleSystem_ = GraphicsEngine::getSingleton().getSceneManager()->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName);
    6152  }
    6253
    63   ParticleInterface::~ParticleInterface(void)
     54  ParticleInterface::~ParticleInterface()
    6455  {
    65     while(particleSystem_->getNumEmitters()>0)
    66       particleSystem_->removeEmitter(particleSystem_->getNumEmitters()-1);
    67     sceneManager_->destroyParticleSystem(particleSystem_);
     56    this->particleSystem_->removeAllEmitters();
     57    GraphicsEngine::getSingleton().getSceneManager()->destroyParticleSystem(particleSystem_);
    6858  }
    6959
    70   void ParticleInterface::standardizeEmitters(void)
     60  void ParticleInterface::addToSceneNode(Ogre::SceneNode* sceneNode)
    7161  {
    72     //Abgleichen der anderen Emitter an die Variabeln
    73     for (int i=0; i < numberOfEmitters_; i++) {
    74       particleSystem_->getEmitter(i)->setColour( colour_ );
    75       particleSystem_->getEmitter(i)->setTimeToLive( distance_ );
    76       particleSystem_->getEmitter(i)->setEmissionRate( rate_ );
    77     }
    78 
     62    this->sceneNode_ = sceneNode;
     63    this->sceneNode_->attachObject(this->particleSystem_);
    7964  }
    8065
    81   void ParticleInterface::setVelocity(Real v)
     66  void ParticleInterface::detachFromSceneNode()
    8267  {
    83     velocity_ = v;
    84     //partikel anpassen
    85     particleSystem_->setSpeedFactor(v);
    86   }
    87 
    88   void ParticleInterface::setRate(float r)
    89   {
    90     rate_ = r;
    91     //partikel anpassen
    92     for (int i=0; i<numberOfEmitters_; i++) {
    93       particleSystem_->getEmitter(i)->setEmissionRate(rate_);
     68    if (this->sceneNode_)
     69    {
     70      this->sceneNode_->detachObject(this->particleSystem_);
     71      this->sceneNode_ = 0;
    9472    }
    9573  }
    9674
    97   void ParticleInterface::setDistance(Real d)
     75  Ogre::ParticleEmitter* ParticleInterface::createNewEmitter()
    9876  {
    99     distance_ = d;
    100     //partikel anpassen
    101     for (int i=0; i < numberOfEmitters_; i++) {
    102       particleSystem_->getEmitter(i)->setTimeToLive(distance_);
     77    if (this->particleSystem_->getNumEmitters() > 0)
     78    {
     79      Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType());
     80      this->particleSystem_->getEmitter(0)->copyParametersTo(newemitter);
     81      return newemitter;
    10382    }
     83    else
     84      return 0;
     85  }
     86  Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const
     87  {
     88    if (emitterNr < this->particleSystem_->getNumEmitters())
     89      return this->particleSystem_->getEmitter(emitterNr);
     90    else
     91      return 0;
     92  }
     93  void ParticleInterface::removeEmitter(unsigned int emitterNr)
     94  {
     95    if (emitterNr < this->particleSystem_->getNumEmitters())
     96      this->particleSystem_->removeEmitter(emitterNr);
     97  }
     98  void ParticleInterface::removeAllEmitters()
     99  {
     100    this->particleSystem_->removeAllEmitters();
     101  }
     102  unsigned int ParticleInterface::getNumEmitters() const
     103  {
     104    return this->particleSystem_->getNumEmitters();
    104105  }
    105106
    106   void ParticleInterface::setColour(ColourValue colour)
     107  Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name)
    107108  {
    108     colour_ = colour;
    109     //partikel anpassen
    110     for (int i=0; i < numberOfEmitters_; i++) {
    111       particleSystem_->getEmitter(i)->setColour(colour_);
    112     }
     109    return this->particleSystem_->addAffector(name);
     110  }
     111  Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const
     112  {
     113    if (affectorNr < this->particleSystem_->getNumAffectors())
     114      return this->particleSystem_->getAffector(affectorNr);
     115    else
     116      return 0;
     117  }
     118  void ParticleInterface::removeAffector(unsigned int affectorNr)
     119  {
     120    if (affectorNr < this->particleSystem_->getNumAffectors())
     121      this->particleSystem_->removeAffector(affectorNr);
     122  }
     123  void ParticleInterface::removeAllAffectors()
     124  {
     125    this->particleSystem_->removeAllAffectors();
     126  }
     127  unsigned int ParticleInterface::getNumAffectors() const
     128  {
     129    return this->particleSystem_->getNumAffectors();
    113130  }
    114131
    115   ParticleEmitter* ParticleInterface::getEmitter( int emitterNr )
     132  void ParticleInterface::setEnabled(bool enable)
    116133  {
    117     if ( (emitterNr >= numberOfEmitters_) || (emitterNr < 0) ) return NULL;
    118     return particleSystem_->getEmitter(emitterNr);
     134    for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++)
     135      this->particleSystem_->getEmitter(i)->setEnabled(enable);
    119136  }
    120137
    121   void ParticleInterface::newEmitter ()
     138  void ParticleInterface::setSpeedFactor(float factor)
    122139  {
    123     particleSystem_->addEmitter(particleSystem_->getEmitter(0)->getType());
    124     particleSystem_->getEmitter(0)->copyParametersTo( particleSystem_->getEmitter(numberOfEmitters_) );
    125     numberOfEmitters_++;
     140    this->particleSystem_->setSpeedFactor(factor);
     141  }
     142  float ParticleInterface::getSpeedFactor() const
     143  {
     144    return this->particleSystem_->getSpeedFactor();
    126145  }
    127146
    128   // TODO check if this really works
    129   Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr )
     147  bool ParticleInterface::getKeepParticlesInLocalSpace() const
    130148  {
    131     return particleSystem_->getEmitter(emitterNr)->getPosition();
     149    return this->particleSystem_->getKeepParticlesInLocalSpace();
    132150  }
    133 
    134   void ParticleInterface::setDirection ( Vector3 direction )
     151  void ParticleInterface::setKeepParticlesInLocalSpace(bool keep)
    135152  {
    136     for(int i=0; i < numberOfEmitters_; i++) {
    137       particleSystem_->getEmitter(i)->setDirection(direction);
    138     }
     153    this->particleSystem_->setKeepParticlesInLocalSpace(keep);
    139154  }
    140 
    141   void ParticleInterface::switchEnable(){
    142     bool enable=(!(particleSystem_->getEmitter(0)->getEnabled()));
    143     for(int i=0; i < numberOfEmitters_; i++) {
    144       particleSystem_->getEmitter(i)->setEnabled(enable);
    145     }
    146   }
    147 
    148155}
  • code/trunk/src/orxonox/particle/ParticleInterface.h

    r1505 r1552  
    2121 *
    2222 *   Author:
    23  *      Fabian 'x3n' Landau
     23 *      ...
    2424 *   Co-authors:
    2525 *      ...
     
    3333
    3434#include <string>
    35 
    36 // #include "ParticleInterface.h"
    37 // #include <Ogre.h>
    38 // #include <OIS/OIS.h>
    39 // #include <CEGUI/CEGUI.h>
    40 // #include <CEGUIRenderer.h>
    41 #include <OgreParticleSystem.h>
    4235#include <OgreParticleEmitter.h>
    43 #include <OgreSceneManager.h>
    4436
    4537#include "util/Math.h"
    4638
     39#define getAllEmitters() \
     40  storeThisAsCurrentParticleInterface(); \
     41  for (unsigned int i = 0; i < ParticleInterface::getCurrentParticleInterface()->getNumEmitters(); ++i) \
     42    ParticleInterface::getCurrentParticleInterface()->getEmitter(i)
    4743
    4844namespace orxonox
    4945{
    50 
    5146  class _OrxonoxExport ParticleInterface
    5247  {
    53   public:
     48    public:
     49      ParticleInterface(const std::string& templateName);
     50      ~ParticleInterface();
    5451
    55     ParticleInterface( Ogre::SceneManager *sceneManager, std::string name, std::string templateName );
    56     ~ParticleInterface( void );
     52      inline Ogre::ParticleSystem* getParticleSystem() const
     53        { return this->particleSystem_; }
    5754
    58     inline void addToSceneNode( Ogre::SceneNode* sceneNode )
    59         { sceneNode_ = sceneNode; sceneNode_->attachObject(particleSystem_);};
    60     inline void detachFromSceneNode( void )
    61         { sceneNode_->detachObject(particleSystem_); sceneNode_ = NULL;};
     55      void addToSceneNode(Ogre::SceneNode* sceneNode);
     56      void detachFromSceneNode();
    6257
    63     Ogre::ParticleEmitter* getEmitter ( int emitterNr );
    64     void newEmitter ( void );
     58      Ogre::ParticleEmitter* createNewEmitter();
     59      Ogre::ParticleEmitter* getEmitter(unsigned int emitterNr) const;
     60      void removeEmitter(unsigned int emitterNr);
     61      void removeAllEmitters();
     62      unsigned int getNumEmitters() const;
    6563
    66     Vector3 getPositionOfEmitter ( int emitterNr );
    67     inline void setPositionOfEmitter ( int emitterNr, Vector3 position )
    68         { particleSystem_->getEmitter(emitterNr)->setPosition(position); };
     64      Ogre::ParticleAffector* addAffector(const std::string& name);
     65      Ogre::ParticleAffector* getAffector(unsigned int affectorNr) const;
     66      void removeAffector(unsigned int affectorNr);
     67      void removeAllAffectors();
     68      unsigned int getNumAffectors() const;
    6969
    70     inline Vector3 getDirection ( void )
    71         { return particleSystem_->getEmitter(0)->getDirection(); };
    72     void setDirection ( Vector3 direction );
     70      float getSpeedFactor() const;
     71      void setSpeedFactor(float factor);
     72      bool getKeepParticlesInLocalSpace() const;
     73      void setKeepParticlesInLocalSpace(bool keep);
    7374
    74     inline Real getVelocity()
    75         {return velocity_; };
    76     void setVelocity( Real v );
     75      void setEnabled(bool enable);
    7776
    78     inline float getRate()
    79       { return rate_; };
    80     void setRate( float r );
     77      inline void storeThisAsCurrentParticleInterface()
     78        { ParticleInterface::currentParticleInterface_s = this; }
     79      inline static ParticleInterface* getCurrentParticleInterface()
     80        { return ParticleInterface::currentParticleInterface_s; }
    8181
    82     inline Real getDistance()
    83         { return distance_; };
    84     void setDistance( Real d );
    85 
    86     inline ColourValue getColour( void )
    87         {return colour_;};
    88     void setColour( ColourValue colour );
    89 
    90     void switchEnable();
    91 
    92     inline Ogre::ParticleSystem* getParticleSystem()
    93         { return this->particleSystem_; };
    94 
    95   private:
    96     Ogre::SceneNode *sceneNode_;
    97     Ogre::SceneManager *sceneManager_;
    98     Ogre::ParticleSystem *particleSystem_;
    99     Real distance_;
    100     Real velocity_;
    101     float rate_;
    102     ColourValue colour_;
    103     int numberOfEmitters_;
    104 
    105     void standardizeEmitters();
     82    private:
     83      static ParticleInterface* currentParticleInterface_s;
     84      static unsigned int counter_s;
     85      Ogre::SceneNode* sceneNode_;
     86      Ogre::ParticleSystem* particleSystem_;
    10687  };
    107 
    10888}
    10989
  • code/trunk/src/orxonox/tools/Timer.cc

    r1505 r1552  
    102102    TimerBase::~TimerBase()
    103103    {
    104       if (this->executor_)
    105           delete this->executor_;
     104        this->deleteExecutor();
    106105    }
    107106
     
    112111    {
    113112        (*this->executor_)();
     113    }
     114
     115    /**
     116        @brief Deletes the executor.
     117    */
     118    void TimerBase::deleteExecutor()
     119    {
     120      if (this->executor_)
     121          delete this->executor_;
    114122    }
    115123
  • code/trunk/src/orxonox/tools/Timer.h

    r1535 r1552  
    7878
    7979            void run() const;
     80            void deleteExecutor();
    8081
    8182            /** @brief Starts the Timer: Function-call after 'interval' seconds. */
     
    149150            void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor)
    150151            {
     152                this->deleteExecutor();
     153
    151154                this->interval_ = interval;
    152155                this->bLoop_ = bLoop;
     
    185188            void setTimer(float interval, bool bLoop, ExecutorStatic* executor)
    186189            {
     190                this->deleteExecutor();
     191
    187192                this->interval_ = interval;
    188193                this->bLoop_ = bLoop;
Note: See TracChangeset for help on using the changeset viewer.