Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (16 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc

    r2099 r2662  
    3030#include "BillboardProjectile.h"
    3131
    32 #include <OgreBillboard.h>
     32#include <OgreBillboardSet.h>
    3333
     34#include "core/Core.h"
    3435#include "core/CoreIncludes.h"
     36#include "objects/Scene.h"
    3537
    3638namespace orxonox
     
    3840    CreateFactory(BillboardProjectile);
    3941
    40     BillboardProjectile::BillboardProjectile(BaseObject* creator, Weapon* owner) : Projectile(creator, owner)
     42    BillboardProjectile::BillboardProjectile(BaseObject* creator) : Projectile(creator)
    4143    {
    4244        RegisterObject(BillboardProjectile);
    4345
    44         this->billboard_.setBillboardSet("Examples/Flare", ColourValue(1.0, 1.0, 0.5), 1);
    45         this->attachObject(this->billboard_.getBillboardSet());
    46         this->scale(0.5);
     46        if (Core::showsGraphics())
     47        {
     48            assert(this->getScene()->getSceneManager()); // getScene() was already checked by WorldEntity
     49            this->billboard_.setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(0.5, 0.5, 0.7, 0.8), 1);
     50            this->attachOgreObject(this->billboard_.getBillboardSet());
     51        }
     52
     53        this->setScale(0.2);
    4754    }
    4855
    4956    BillboardProjectile::~BillboardProjectile()
    5057    {
    51         if (this->isInitialized() && this->owner_)
    52             this->detachObject(this->billboard_.getBillboardSet());
     58        if (this->isInitialized() && Core::showsGraphics() && this->billboard_.getBillboardSet())
     59            this->detachOgreObject(this->billboard_.getBillboardSet());
    5360    }
    5461
    5562    void BillboardProjectile::setColour(const ColourValue& colour)
    5663    {
    57         this->billboard_.getBillboardSet()->getBillboard(0)->setColour(colour);
     64        this->billboard_.setColour(colour);
    5865    }
    5966
     
    6168    {
    6269        SUPER(BillboardProjectile, changedVisibility);
     70
    6371        this->billboard_.setVisible(this->isVisible());
    6472    }
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h

    r2099 r2662  
    4141    {
    4242        public:
    43             BillboardProjectile(BaseObject* creator, Weapon* owner = 0);
     43            BillboardProjectile(BaseObject* creator);
    4444            virtual ~BillboardProjectile();
    4545
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc

    r2099 r2662  
    3030#include "ParticleProjectile.h"
    3131
    32 #include "SpaceShip.h"
     32#include <OgreParticleSystem.h>
     33#include <OgreParticleEmitter.h>
     34
     35#include "core/Core.h"
    3336#include "core/CoreIncludes.h"
    3437#include "core/ConfigValueIncludes.h"
     38#include "objects/Scene.h"
    3539
    3640namespace orxonox
     
    3842    CreateFactory(ParticleProjectile);
    3943
    40     ParticleProjectile::ParticleProjectile(BaseObject* creator, Weapon* owner) : BillboardProjectile(creator, owner)
     44    ParticleProjectile::ParticleProjectile(BaseObject* creator) : BillboardProjectile(creator)
    4145    {
    4246        RegisterObject(ParticleProjectile);
    4347
    44         this->particles_ = new ParticleInterface("Orxonox/shot2", LODParticle::normal);
    45         this->particles_->addToSceneNode(this->getNode());
    46         this->particles_->setKeepParticlesInLocalSpace(true);
    47         if (this->owner_)
     48        if (Core::showsGraphics())
    4849        {
     50            this->particles_ = new ParticleInterface(this->getScene()->getSceneManager(), "Orxonox/shot3_small", LODParticle::normal);
     51            this->attachOgreObject(this->particles_->getParticleSystem());
     52            this->particles_->setKeepParticlesInLocalSpace(0);
     53
     54            this->particles_->getAllEmitters()->setDirection(-WorldEntity::FRONT);
    4955        }
    50 //        else
    51 //        {
    52 //            this->particles_ = 0;
    53 //        }
    54 
    55         this->setConfigValues();
     56        else
     57            this->particles_ = 0;
    5658    }
    5759
     
    5961    {
    6062        if (this->isInitialized() && this->particles_)
     63        {
     64            this->detachOgreObject(this->particles_->getParticleSystem());
    6165            delete this->particles_;
    62     }
    63 
    64     void ParticleProjectile::setConfigValues()
    65     {
    66         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback((Projectile*)this, &ParticleProjectile::speedChanged);
     66        }
    6767    }
    6868
     
    7070    {
    7171        SUPER(ParticleProjectile, changedVisibility);
    72         this->particles_->setEnabled(this->isVisible());
    73     }
    7472
    75     bool ParticleProjectile::create(){
    76       if(!Projectile::create())
    77         return false;
    78       this->particles_->getAllEmitters()->setDirection(-this->getOrientation()*Vector3(1,0,0));
    79       return true;
     73        if (this->particles_)
     74            this->particles_->setEnabled(this->isVisible());
    8075    }
    8176}
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h

    r2099 r2662  
    4141    {
    4242        public:
    43             ParticleProjectile(BaseObject* creator, Weapon* owner = 0);
     43            ParticleProjectile(BaseObject* creator);
    4444            virtual ~ParticleProjectile();
    4545            virtual void changedVisibility();
    46             void setConfigValues();
    47 
    48             virtual bool create();
    4946
    5047        private:
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc

    r2100 r2662  
    4040#include "objects/worldentities/Model.h"
    4141#include "objects/worldentities/ParticleSpawner.h"
    42 #include "Settings.h"
     42#include "objects/collisionshapes/SphereCollisionShape.h"
     43#include "core/Core.h"
    4344
    4445namespace orxonox
    4546{
    46     float Projectile::speed_s = 5000;
    47 
    48     Projectile::Projectile(BaseObject* creator, Weapon* owner) : MovableEntity(creator), owner_(owner)
     47    Projectile::Projectile(BaseObject* creator) : MovableEntity(creator)
    4948    {
    5049        RegisterObject(Projectile);
    5150
    5251        this->setConfigValues();
    53         this->explosionTemplateName_ = "Orxonox/explosion3";
    54         this->smokeTemplateName_ = "Orxonox/smoke4";
     52        this->bDestroy_ = false;
     53        this->owner_ = 0;
    5554
    56         this->setStatic(false);
    57         this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL);
     55        // Get notification about collisions
    5856
    59         if (this->owner_)
     57        if (Core::isMaster())
    6058        {
    61             this->setOrientation(this->owner_->getOrientation());
    62             this->setPosition(this->owner_->getPosition());
    63             this->setVelocity(this->owner_->getInitialDir() * this->speed_);
     59            this->enableCollisionCallback();
     60
     61            this->setCollisionType(Kinematic);
     62
     63            SphereCollisionShape* shape = new SphereCollisionShape(this);
     64            shape->setRadius(10);
     65            this->attachCollisionShape(shape);
     66
     67            this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    6468        }
    65 
    66         if(!orxonox::Settings::isClient()) //only if not on client
    67           this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));
    6869    }
    6970
     
    7677        SetConfigValue(damage_, 15.0).description("The damage caused by the projectile");
    7778        SetConfigValue(lifetime_, 4.0).description("The time in seconds a projectile stays alive");
    78         SetConfigValue(speed_, 5000.0).description("The speed of a projectile in units per second").callback(this, &Projectile::speedChanged);
    7979    }
    8080
    81     void Projectile::speedChanged()
    82     {
    83         Projectile::speed_s = this->speed_;
    84         if (this->owner_)
    85             this->setVelocity(this->owner_->getInitialDir() * this->speed_);
    86     }
    8781
    8882    void Projectile::tick(float dt)
     
    9387            return;
    9488
    95         float radius;
    96         for (ObjectList<Model>::iterator it = ObjectList<Model>::begin(); it; ++it)
    97         {
    98 //            if ((*it) != this->owner_)
    99             {
    100                 radius = it->getScale3D().x * 3.0;
    101 
    102                 if (this->getPosition().squaredDistance(it->getPosition()) <= (radius*radius))
    103                 {
    104                     // hit
    105                     ParticleSpawner* explosion = new ParticleSpawner(this->explosionTemplateName_, LODParticle::low, 2.0);
    106                     explosion->setPosition(this->getPosition());
    107                     explosion->create();
    108                     ParticleSpawner* smoke = new ParticleSpawner(this->smokeTemplateName_, LODParticle::normal, 2.0, 0.0);
    109                     smoke->setPosition(this->getPosition());
    110 //                    smoke->getParticleInterface()->setSpeedFactor(3.0);
    111                     smoke->create();
    112                     delete this;
    113                     return;
    114                 }
    115             }
    116         }
     89        if (this->bDestroy_)
     90            delete this;
    11791    }
    11892
    11993    void Projectile::destroyObject()
    12094    {
    121         delete this;
     95        if (Core::isMaster())
     96            delete this;
    12297    }
    12398
    124     bool Projectile::create(){
    125       return WorldEntity::create();
     99    bool Projectile::collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint)
     100    {
     101        if (!this->bDestroy_ && Core::isMaster())
     102        {
     103            this->bDestroy_ = true;
     104
     105            if (this->owner_)
     106            {
     107                {
     108                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
     109                    effect->setPosition(this->getPosition());
     110                    effect->setOrientation(this->getOrientation());
     111                    effect->setDestroyAfterLife(true);
     112                    effect->setSource("Orxonox/explosion3");
     113                    effect->setLifetime(2.0f);
     114                }
     115                {
     116                    ParticleSpawner* effect = new ParticleSpawner(this->owner_->getCreator());
     117                    effect->setPosition(this->getPosition());
     118                    effect->setOrientation(this->getOrientation());
     119                    effect->setDestroyAfterLife(true);
     120                    effect->setSource("Orxonox/smoke4");
     121                    effect->setLifetime(3.0f);
     122                }
     123            }
     124
     125            Pawn* victim = dynamic_cast<Pawn*>(otherObject);
     126            if (victim)
     127                victim->damage(this->damage_, this->owner_);
     128        }
     129        return false;
     130    }
     131
     132    void Projectile::destroyedPawn(Pawn* pawn)
     133    {
     134        if (this->owner_ == pawn)
     135            this->owner_ = 0;
    126136    }
    127137}
  • code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.h

    r2099 r2662  
    3333
    3434#include "objects/worldentities/MovableEntity.h"
     35#include "objects/worldentities/pawns/Pawn.h"
    3536#include "tools/Timer.h"
    3637
    3738namespace orxonox
    3839{
    39     class _OrxonoxExport Projectile : public MovableEntity
     40    class _OrxonoxExport Projectile : public MovableEntity, public PawnListener
    4041    {
    4142        public:
     43            Projectile(BaseObject* creator);
    4244            virtual ~Projectile();
     45
    4346            void setConfigValues();
    44             void speedChanged();
    4547            void destroyObject();
     48
    4649            virtual void tick(float dt);
     50            virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint);
     51            virtual void destroyedPawn(Pawn* pawn);
    4752
    48             virtual bool create();
    49 
    50             static float getSpeed()
    51                 { return Projectile::speed_s; }
    52 
    53         protected:
    54             Projectile(BaseObject* creator, Weapon* owner = 0);
    55             SpaceShip* owner_;
     53            inline void setOwner(Pawn* owner)
     54                { this->owner_ = owner; }
     55            inline Pawn* getOwner() const
     56                { return this->owner_; }
    5657
    5758        private:
    58             std::string explosionTemplateName_;
    59             std::string smokeTemplateName_;
    60         protected:
    61             static float speed_s;
    62             float speed_;
    63         private:
     59            Pawn* owner_;
    6460            float lifetime_;
    6561            float damage_;
     62            bool bDestroy_;
    6663            Timer<Projectile> destroyTimer_;
    6764    };
Note: See TracChangeset for help on using the changeset viewer.