[4593] | 1 | /* |
---|
[3708] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
[5443] | 13 | co-programmer: Benjamin Grauer |
---|
| 14 | |
---|
[3708] | 15 | */ |
---|
[5357] | 16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON |
---|
[3708] | 17 | |
---|
[5456] | 18 | #include "rocket.h" |
---|
[3708] | 19 | |
---|
[4947] | 20 | #include "fast_factory.h" |
---|
[3708] | 21 | |
---|
[5511] | 22 | #include "model.h" |
---|
[5443] | 23 | #include "state.h" |
---|
| 24 | #include "list.h" |
---|
[5444] | 25 | #include "class_list.h" |
---|
[5054] | 26 | |
---|
[5443] | 27 | #include "particle_engine.h" |
---|
| 28 | #include "particle_emitter.h" |
---|
| 29 | #include "particle_system.h" |
---|
| 30 | |
---|
| 31 | |
---|
[3708] | 32 | using namespace std; |
---|
| 33 | |
---|
[5456] | 34 | CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET); |
---|
[3708] | 35 | |
---|
| 36 | /** |
---|
[4836] | 37 | * standard constructor |
---|
[3708] | 38 | */ |
---|
[5456] | 39 | Rocket::Rocket () : Projectile() |
---|
[3755] | 40 | { |
---|
[5456] | 41 | this->setClassID(CL_TEST_BULLET, "Rocket"); |
---|
[4597] | 42 | |
---|
[4948] | 43 | float modelSize = .3; |
---|
[5499] | 44 | this->loadModel("models/projectiles/orx-rocket.obj", .3); |
---|
[4948] | 45 | |
---|
| 46 | this->energyMin = 1; |
---|
| 47 | this->energyMax = 10; |
---|
[5451] | 48 | this->lifeSpan = 2; |
---|
[5443] | 49 | |
---|
[5447] | 50 | this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5); |
---|
[5443] | 51 | this->emitter->setParent(this); |
---|
[5449] | 52 | this->emitter->setSpread(M_PI, M_PI); |
---|
[3755] | 53 | } |
---|
[3708] | 54 | |
---|
| 55 | |
---|
| 56 | /** |
---|
[4836] | 57 | * standard deconstructor |
---|
[3708] | 58 | */ |
---|
[5456] | 59 | Rocket::~Rocket () |
---|
[3708] | 60 | { |
---|
[5446] | 61 | // delete this->emitter; |
---|
[5444] | 62 | |
---|
[5445] | 63 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[5779] | 64 | if (Rocket::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1) |
---|
[5447] | 65 | { |
---|
[5456] | 66 | if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM)) |
---|
| 67 | delete Rocket::trailParticles; |
---|
| 68 | Rocket::trailParticles = NULL; |
---|
[5447] | 69 | } |
---|
[5779] | 70 | if (Rocket::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1) |
---|
[5444] | 71 | { |
---|
[5456] | 72 | if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 73 | delete Rocket::explosionParticles; |
---|
| 74 | Rocket::explosionParticles = NULL; |
---|
[5444] | 75 | } |
---|
[5445] | 76 | |
---|
[3708] | 77 | } |
---|
| 78 | |
---|
[5456] | 79 | ParticleSystem* Rocket::trailParticles = NULL; |
---|
| 80 | ParticleSystem* Rocket::explosionParticles = NULL; |
---|
[5443] | 81 | |
---|
[5456] | 82 | void Rocket::activate() |
---|
[5443] | 83 | { |
---|
| 84 | State::getWorldEntityList()->add(this); |
---|
[5456] | 85 | if (unlikely(Rocket::trailParticles == NULL)) |
---|
[5447] | 86 | { |
---|
[5471] | 87 | Rocket::trailParticles = new ParticleSystem(2000, PARTICLE_SPRITE); |
---|
[5456] | 88 | Rocket::trailParticles->setName("RocketTrailParticles"); |
---|
[5471] | 89 | Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
| 90 | Rocket::trailParticles->setLifeSpan(1.0, .3); |
---|
[5456] | 91 | Rocket::trailParticles->setRadius(0.0, .5); |
---|
[5472] | 92 | Rocket::trailParticles->setRadius(0.2, 2.0); |
---|
| 93 | Rocket::trailParticles->setRadius(.5, .8); |
---|
[5471] | 94 | Rocket::trailParticles->setRadius(1.0, .8); |
---|
[5456] | 95 | Rocket::trailParticles->setColor(0.0, 1,0,0,.7); |
---|
[5472] | 96 | Rocket::trailParticles->setColor(0.2, .8,.8,0,.5); |
---|
| 97 | Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8); |
---|
[5471] | 98 | Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0); |
---|
[5447] | 99 | } |
---|
[5456] | 100 | if (unlikely(Rocket::explosionParticles == NULL)) |
---|
[5443] | 101 | { |
---|
[5465] | 102 | Rocket::explosionParticles = new ParticleSystem(200, PARTICLE_SPRITE); |
---|
[5456] | 103 | Rocket::explosionParticles->setName("RocketExplosionParticles"); |
---|
[5471] | 104 | Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png"); |
---|
[5693] | 105 | Rocket::explosionParticles->setLifeSpan(.5, .3); |
---|
[5456] | 106 | Rocket::explosionParticles->setRadius(0.0, 10); |
---|
[5693] | 107 | Rocket::explosionParticles->setRadius(.5, 15.0); |
---|
| 108 | Rocket::explosionParticles->setRadius(1.0, 10.0); |
---|
[5465] | 109 | Rocket::explosionParticles->setColor(0.0, 0,1,0,1); |
---|
| 110 | Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8); |
---|
| 111 | Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8); |
---|
[5456] | 112 | Rocket::explosionParticles->setColor(1.0, 1,1,1,.0); |
---|
[5443] | 113 | } |
---|
| 114 | |
---|
[5456] | 115 | ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::trailParticles); |
---|
[5447] | 116 | |
---|
[5769] | 117 | this->updateNode(0); |
---|
[5472] | 118 | this->emitter->setEmissionRate(45.0); |
---|
[5471] | 119 | this->emitter->setEmissionVelocity(0.0); |
---|
[5443] | 120 | } |
---|
| 121 | |
---|
| 122 | |
---|
[5456] | 123 | void Rocket::deactivate() |
---|
[5443] | 124 | { |
---|
[5447] | 125 | ParticleEngine::getInstance()->breakConnections(this->emitter); |
---|
| 126 | this->lifeCycle = 0.0; |
---|
[5443] | 127 | |
---|
[5447] | 128 | // GarbageCollector::getInstance()->collect(this); |
---|
| 129 | State::getWorldEntityList()->remove(this); |
---|
[5456] | 130 | Rocket::fastFactory->kill(this); |
---|
[5443] | 131 | } |
---|
| 132 | |
---|
| 133 | |
---|
[5456] | 134 | void Rocket::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5257] | 135 | { |
---|
[5447] | 136 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
| 137 | this->destroy(); |
---|
| 138 | this->hitEntity = entity; |
---|
[5257] | 139 | } |
---|
[3708] | 140 | |
---|
| 141 | /** |
---|
[4836] | 142 | * signal tick, time dependent things will be handled here |
---|
| 143 | * @param time since last tick |
---|
[3708] | 144 | */ |
---|
[5456] | 145 | void Rocket::tick (float time) |
---|
[3708] | 146 | { |
---|
[4464] | 147 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 148 | Vector v = this->velocity * (time); |
---|
[3708] | 149 | this->shiftCoor(v); |
---|
| 150 | |
---|
[4890] | 151 | this->lifeCycle += time/this->lifeSpan; |
---|
[5447] | 152 | if( this->lifeCycle >= 1.0) |
---|
[3708] | 153 | { |
---|
| 154 | PRINTF(5)("FINALIZE==========================\n"); |
---|
[4890] | 155 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
[3708] | 156 | PRINTF(5)("FINALIZE===========================\n"); |
---|
[5447] | 157 | |
---|
[5443] | 158 | this->deactivate(); |
---|
[3708] | 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | /** |
---|
[4836] | 163 | * the function gets called, when the projectile is destroyed |
---|
[3708] | 164 | */ |
---|
[5456] | 165 | void Rocket::destroy () |
---|
[5257] | 166 | { |
---|
[5456] | 167 | PRINTF(5)("DESTROY Rocket\n"); |
---|
[5448] | 168 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
[5456] | 169 | ParticleEngine::getInstance()->breakConnection(this->emitter, Rocket::trailParticles); |
---|
| 170 | ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::explosionParticles); |
---|
[3708] | 171 | |
---|
[5465] | 172 | this->emitter->setEmissionRate(1000.0); |
---|
[5447] | 173 | this->emitter->setEmissionVelocity(50.0); |
---|
| 174 | // this->deactivate(); |
---|
[3708] | 175 | |
---|
[5257] | 176 | } |
---|
| 177 | |
---|
| 178 | |
---|
[5500] | 179 | void Rocket::draw () const |
---|
[3708] | 180 | { |
---|
| 181 | glMatrixMode(GL_MODELVIEW); |
---|
| 182 | glPushMatrix(); |
---|
| 183 | |
---|
[4593] | 184 | float matrix[4][4]; |
---|
[3708] | 185 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 186 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 187 | glMultMatrixf((float*)matrix); |
---|
[3755] | 188 | glScalef(2.0, 2.0, 2.0); |
---|
[3708] | 189 | this->model->draw(); |
---|
| 190 | |
---|
| 191 | glPopMatrix(); |
---|
| 192 | } |
---|
| 193 | |
---|