Changeset 7047 in orxonox.OLD for trunk/src/world_entities/effects
- Timestamp:
- Feb 6, 2006, 1:29:09 PM (19 years ago)
- Location:
- trunk/src/world_entities/effects
- Files:
-
- 1 added
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/world_entities/effects/explosion.cc
r7046 r7047 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON 17 17 18 #include " rocket.h"18 #include "explosion.h" 19 19 20 20 #include "fast_factory.h" … … 29 29 using namespace std; 30 30 31 CREATE_FAST_FACTORY_STATIC( Rocket, CL_ROCKET);31 CREATE_FAST_FACTORY_STATIC(Explosion, CL_EXPLOSION); 32 32 33 33 /** 34 34 * standard constructor 35 35 */ 36 Rocket::Rocket () : Projectile()36 Explosion::Explosion () 37 37 { 38 this->setClassID(CL_ROCKET, "Rocket"); 39 40 float modelSize = .3; 41 this->loadModel("models/projectiles/orx-rocket.obj", .3); 42 43 this->setMinEnergy(1); 44 this->setHealthMax(10); 45 this->lifeSpan = 5; 38 this->setClassID(CL_EXPLOSION, "Explosion"); 46 39 47 40 this->emitter = new DotEmitter(100, 5, M_2_PI); 41 this->emitter->addNodeFlags(PNODE_PROHIBIT_DELETE_WITH_PARENT); 48 42 this->emitter->setParent(this); 49 43 this->emitter->setSpread(M_PI, M_PI); 44 45 this->lifeCycle = 0.0f; 46 this->lifeTime = 4.0f; 47 50 48 } 51 49 … … 54 52 * standard deconstructor 55 53 */ 56 Rocket::~Rocket()54 Explosion::~Explosion () 57 55 { 58 //delete this->emitter;56 delete this->emitter; 59 57 60 58 /* this is normaly done by World.cc by deleting the ParticleEngine */ 61 if (Rocket::trailParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) 59 if (Explosion::explosionParticles != NULL && ClassList::getList(CL_EXPLOSION)->size() <= 1) 60 Explosion::explosionParticles = NULL; 61 } 62 63 SpriteParticles* Explosion::explosionParticles = NULL; 64 65 void Explosion::activate() 66 { 67 if (unlikely(Explosion::explosionParticles == NULL)) 62 68 { 63 /* if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM)) 64 delete Rocket::trailParticles;*/ 65 Rocket::trailParticles = NULL; 66 } 67 if (Rocket::explosionParticles != NULL && ClassList::getList(CL_ROCKET)->size() <= 1) 68 { 69 /* if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM)) 70 delete Rocket::explosionParticles;*/ 71 Rocket::explosionParticles = NULL; 69 Explosion::explosionParticles = new SpriteParticles(200); 70 Explosion::explosionParticles->setName("ExplosionExplosionParticles"); 71 Explosion::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); 72 Explosion::explosionParticles->setLifeSpan(.5, .3); 73 Explosion::explosionParticles->setRadius(0.0, 10); 74 Explosion::explosionParticles->setRadius(.5, 15.0); 75 Explosion::explosionParticles->setRadius(1.0, 10.0); 76 Explosion::explosionParticles->setColor(0.0, 0,1,0,1); 77 Explosion::explosionParticles->setColor(0.5, .8,.8,0,.8); 78 Explosion::explosionParticles->setColor(0.8, .8,.8,.3,.8); 79 Explosion::explosionParticles->setColor(1.0, 1,1,1,.0); 72 80 } 73 81 74 } 75 76 SpriteParticles* Rocket::trailParticles = NULL; 77 SpriteParticles* Rocket::explosionParticles = NULL; 78 79 void Rocket::activate() 80 { 81 if (unlikely(Rocket::trailParticles == NULL)) 82 { 83 Rocket::trailParticles = new SpriteParticles(2000); 84 Rocket::trailParticles->setName("RocketTrailParticles"); 85 Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png"); 86 Rocket::trailParticles->setLifeSpan(1.0, .3); 87 Rocket::trailParticles->setRadius(0.0, .5); 88 Rocket::trailParticles->setRadius(0.2, 2.0); 89 Rocket::trailParticles->setRadius(.5, .8); 90 Rocket::trailParticles->setRadius(1.0, .8); 91 Rocket::trailParticles->setColor(0.0, 1,0,0,.7); 92 Rocket::trailParticles->setColor(0.2, .8,.8,0,.5); 93 Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8); 94 Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0); 95 } 96 if (unlikely(Rocket::explosionParticles == NULL)) 97 { 98 Rocket::explosionParticles = new SpriteParticles(200); 99 Rocket::explosionParticles->setName("RocketExplosionParticles"); 100 Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); 101 Rocket::explosionParticles->setLifeSpan(.5, .3); 102 Rocket::explosionParticles->setRadius(0.0, 10); 103 Rocket::explosionParticles->setRadius(.5, 15.0); 104 Rocket::explosionParticles->setRadius(1.0, 10.0); 105 Rocket::explosionParticles->setColor(0.0, 0,1,0,1); 106 Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8); 107 Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8); 108 Rocket::explosionParticles->setColor(1.0, 1,1,1,.0); 109 } 110 111 this->emitter->setSystem(Rocket::trailParticles); 82 this->emitter->setSystem(Explosion::explosionParticles); 112 83 113 84 this->updateNode(0); 114 85 this->emitter->setEmissionRate(45.0); 115 86 this->emitter->setEmissionVelocity(0.0); 87 this->toList(OM_DEAD_TICK); 116 88 } 117 89 118 90 119 void Rocket::deactivate()91 void Explosion::deactivate() 120 92 { 121 93 this->emitter->setSystem(NULL); 122 94 this->lifeCycle = 0.0; 123 this->toList(OM_ NULL);95 this->toList(OM_DEAD); 124 96 125 // GarbageCollector::getInstance()->collect(this); 126 this->toList(OM_DEAD); 127 Rocket::fastFactory->kill(this); 97 Explosion::fastFactory->kill(this); 128 98 } 129 99 130 131 void Rocket::collidesWith(WorldEntity* entity, const Vector& location)132 {133 if (this->hitEntity != entity)134 this->destroy();135 this->hitEntity = entity;136 }137 100 138 101 /** … … 140 103 * @param time since last tick 141 104 */ 142 void Rocket::tick (float dt)105 void Explosion::tick (float dt) 143 106 { 144 //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); 145 Vector v = this->velocity * (dt); 146 this->shiftCoor(v); 147 148 if(this->tickLifeCycle(dt)) 107 this->lifeCycle += dt; 108 if(this->lifeTime < this->lifeCycle) 149 109 this->deactivate(); 150 110 } 151 152 /**153 * the function gets called, when the projectile is destroyed154 */155 void Rocket::destroy ()156 {157 PRINTF(5)("DESTROY Rocket\n");158 this->lifeCycle = .95; //!< @todo calculate this usefully.159 this->emitter->setSystem(Rocket::explosionParticles);160 161 this->emitter->setEmissionRate(1000.0);162 this->emitter->setEmissionVelocity(50.0);163 // this->deactivate();164 165 }166 167 168 void Rocket::draw () const169 {170 glMatrixMode(GL_MODELVIEW);171 glPushMatrix();172 173 float matrix[4][4];174 glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);175 this->getAbsDir().matrix (matrix);176 glMultMatrixf((float*)matrix);177 glScalef(2.0, 2.0, 2.0);178 this->getModel()->draw();179 180 glPopMatrix();181 }182 -
trunk/src/world_entities/effects/explosion.h
r7046 r7047 1 1 /*! 2 * @file rocket.h3 * @brief a RocketProjectile2 * @file explosion.h 3 * @brief a Explosion Projectile 4 4 */ 5 5 6 #ifndef _ ROCKET_H7 #define _ ROCKET_H6 #ifndef _EXPLOSION_H 7 #define _EXPLOSION_H 8 8 9 #include " projectile.h"9 #include "world_entity.h" 10 10 11 class Vector;12 class Weapon;13 11 class SpriteParticles; 14 12 class ParticleEmitter; 15 13 class FastFactory; 16 14 17 class Rocket : public Projectile15 class Explosion : public WorldEntity 18 16 { 19 17 public: 20 Rocket (); 21 virtual ~Rocket (); 22 18 Explosion (); 19 virtual ~Explosion (); 23 20 24 21 virtual void activate(); 25 22 virtual void deactivate(); 26 23 27 virtual void collidesWith(WorldEntity* entity, const Vector& location);28 29 virtual void destroy ();30 31 24 virtual void tick (float time); 32 virtual void draw () const;33 34 25 35 26 private: 36 static FastFactory* fastFactory; 37 static SpriteParticles* trailParticles; 27 static FastFactory* fastFactory; 28 29 float lifeTime; 30 float lifeCycle; 31 38 32 static SpriteParticles* explosionParticles; 39 40 ParticleEmitter* emitter; 41 42 43 WorldEntity* hitEntity; // FIXME TEMPORARY 44 33 ParticleEmitter* emitter; 45 34 }; 46 35 47 #endif /* _ ROCKET_H */36 #endif /* _EXPLOSION_H */
Note: See TracChangeset
for help on using the changeset viewer.