Changeset 2662 for code/trunk/src/orxonox/objects/weaponSystem/projectiles
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.cc
r2099 r2662 30 30 #include "BillboardProjectile.h" 31 31 32 #include <OgreBillboard .h>32 #include <OgreBillboardSet.h> 33 33 34 #include "core/Core.h" 34 35 #include "core/CoreIncludes.h" 36 #include "objects/Scene.h" 35 37 36 38 namespace orxonox … … 38 40 CreateFactory(BillboardProjectile); 39 41 40 BillboardProjectile::BillboardProjectile(BaseObject* creator , Weapon* owner) : Projectile(creator, owner)42 BillboardProjectile::BillboardProjectile(BaseObject* creator) : Projectile(creator) 41 43 { 42 44 RegisterObject(BillboardProjectile); 43 45 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); 47 54 } 48 55 49 56 BillboardProjectile::~BillboardProjectile() 50 57 { 51 if (this->isInitialized() && this->owner_)52 this->detachO bject(this->billboard_.getBillboardSet());58 if (this->isInitialized() && Core::showsGraphics() && this->billboard_.getBillboardSet()) 59 this->detachOgreObject(this->billboard_.getBillboardSet()); 53 60 } 54 61 55 62 void BillboardProjectile::setColour(const ColourValue& colour) 56 63 { 57 this->billboard_. getBillboardSet()->getBillboard(0)->setColour(colour);64 this->billboard_.setColour(colour); 58 65 } 59 66 … … 61 68 { 62 69 SUPER(BillboardProjectile, changedVisibility); 70 63 71 this->billboard_.setVisible(this->isVisible()); 64 72 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/BillboardProjectile.h
r2099 r2662 41 41 { 42 42 public: 43 BillboardProjectile(BaseObject* creator , Weapon* owner = 0);43 BillboardProjectile(BaseObject* creator); 44 44 virtual ~BillboardProjectile(); 45 45 -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.cc
r2099 r2662 30 30 #include "ParticleProjectile.h" 31 31 32 #include "SpaceShip.h" 32 #include <OgreParticleSystem.h> 33 #include <OgreParticleEmitter.h> 34 35 #include "core/Core.h" 33 36 #include "core/CoreIncludes.h" 34 37 #include "core/ConfigValueIncludes.h" 38 #include "objects/Scene.h" 35 39 36 40 namespace orxonox … … 38 42 CreateFactory(ParticleProjectile); 39 43 40 ParticleProjectile::ParticleProjectile(BaseObject* creator , Weapon* owner) : BillboardProjectile(creator, owner)44 ParticleProjectile::ParticleProjectile(BaseObject* creator) : BillboardProjectile(creator) 41 45 { 42 46 RegisterObject(ParticleProjectile); 43 47 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()) 48 49 { 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); 49 55 } 50 // else 51 // { 52 // this->particles_ = 0; 53 // } 54 55 this->setConfigValues(); 56 else 57 this->particles_ = 0; 56 58 } 57 59 … … 59 61 { 60 62 if (this->isInitialized() && this->particles_) 63 { 64 this->detachOgreObject(this->particles_->getParticleSystem()); 61 65 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 } 67 67 } 68 68 … … 70 70 { 71 71 SUPER(ParticleProjectile, changedVisibility); 72 this->particles_->setEnabled(this->isVisible());73 }74 72 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()); 80 75 } 81 76 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/ParticleProjectile.h
r2099 r2662 41 41 { 42 42 public: 43 ParticleProjectile(BaseObject* creator , Weapon* owner = 0);43 ParticleProjectile(BaseObject* creator); 44 44 virtual ~ParticleProjectile(); 45 45 virtual void changedVisibility(); 46 void setConfigValues();47 48 virtual bool create();49 46 50 47 private: -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.cc
r2100 r2662 40 40 #include "objects/worldentities/Model.h" 41 41 #include "objects/worldentities/ParticleSpawner.h" 42 #include "Settings.h" 42 #include "objects/collisionshapes/SphereCollisionShape.h" 43 #include "core/Core.h" 43 44 44 45 namespace orxonox 45 46 { 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) 49 48 { 50 49 RegisterObject(Projectile); 51 50 52 51 this->setConfigValues(); 53 this-> explosionTemplateName_ = "Orxonox/explosion3";54 this-> smokeTemplateName_ = "Orxonox/smoke4";52 this->bDestroy_ = false; 53 this->owner_ = 0; 55 54 56 this->setStatic(false); 57 this->translate(Vector3(55, 0, 0), Ogre::Node::TS_LOCAL); 55 // Get notification about collisions 58 56 59 if ( this->owner_)57 if (Core::isMaster()) 60 58 { 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))); 64 68 } 65 66 if(!orxonox::Settings::isClient()) //only if not on client67 this->destroyTimer_.setTimer(this->lifetime_, false, this, createExecutor(createFunctor(&Projectile::destroyObject)));68 69 } 69 70 … … 76 77 SetConfigValue(damage_, 15.0).description("The damage caused by the projectile"); 77 78 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);79 79 } 80 80 81 void Projectile::speedChanged()82 {83 Projectile::speed_s = this->speed_;84 if (this->owner_)85 this->setVelocity(this->owner_->getInitialDir() * this->speed_);86 }87 81 88 82 void Projectile::tick(float dt) … … 93 87 return; 94 88 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; 117 91 } 118 92 119 93 void Projectile::destroyObject() 120 94 { 121 delete this; 95 if (Core::isMaster()) 96 delete this; 122 97 } 123 98 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; 126 136 } 127 137 } -
code/trunk/src/orxonox/objects/weaponSystem/projectiles/Projectile.h
r2099 r2662 33 33 34 34 #include "objects/worldentities/MovableEntity.h" 35 #include "objects/worldentities/pawns/Pawn.h" 35 36 #include "tools/Timer.h" 36 37 37 38 namespace orxonox 38 39 { 39 class _OrxonoxExport Projectile : public MovableEntity 40 class _OrxonoxExport Projectile : public MovableEntity, public PawnListener 40 41 { 41 42 public: 43 Projectile(BaseObject* creator); 42 44 virtual ~Projectile(); 45 43 46 void setConfigValues(); 44 void speedChanged();45 47 void destroyObject(); 48 46 49 virtual void tick(float dt); 50 virtual bool collidesAgainst(WorldEntity* otherObject, btManifoldPoint& contactPoint); 51 virtual void destroyedPawn(Pawn* pawn); 47 52 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_; } 56 57 57 58 private: 58 std::string explosionTemplateName_; 59 std::string smokeTemplateName_; 60 protected: 61 static float speed_s; 62 float speed_; 63 private: 59 Pawn* owner_; 64 60 float lifetime_; 65 61 float damage_; 62 bool bDestroy_; 66 63 Timer<Projectile> destroyTimer_; 67 64 };
Note: See TracChangeset
for help on using the changeset viewer.