[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 "laser.h" |
---|
[3708] | 19 | |
---|
[4947] | 20 | #include "fast_factory.h" |
---|
[3708] | 21 | |
---|
[5443] | 22 | #include "state.h" |
---|
| 23 | #include "list.h" |
---|
[5444] | 24 | #include "class_list.h" |
---|
[5511] | 25 | #include "model.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(Laser, CL_LASER); |
---|
[3708] | 35 | |
---|
| 36 | /** |
---|
[4836] | 37 | * standard constructor |
---|
[3708] | 38 | */ |
---|
[5456] | 39 | Laser::Laser () : Projectile() |
---|
[3755] | 40 | { |
---|
[5512] | 41 | this->setClassID(CL_LASER, "Laser"); |
---|
[4597] | 42 | |
---|
[5687] | 43 | this->loadModel("models/projectiles/laser.obj"); |
---|
[4948] | 44 | |
---|
| 45 | this->energyMin = 1; |
---|
| 46 | this->energyMax = 10; |
---|
[5458] | 47 | this->lifeSpan = 1.0; |
---|
[5443] | 48 | |
---|
[5447] | 49 | this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5); |
---|
[5443] | 50 | this->emitter->setParent(this); |
---|
[5449] | 51 | this->emitter->setSpread(M_PI, M_PI); |
---|
[5465] | 52 | this->emitter->setEmissionRate(300.0); |
---|
[5456] | 53 | this->emitter->setEmissionVelocity(50.0); |
---|
[3755] | 54 | } |
---|
[3708] | 55 | |
---|
| 56 | |
---|
| 57 | /** |
---|
[4836] | 58 | * standard deconstructor |
---|
[3708] | 59 | */ |
---|
[5456] | 60 | Laser::~Laser () |
---|
[3708] | 61 | { |
---|
[5446] | 62 | // delete this->emitter; |
---|
[5444] | 63 | |
---|
[5445] | 64 | /* this is normaly done by World.cc by deleting the ParticleEngine */ |
---|
[5779] | 65 | if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->size() <= 1) |
---|
[5447] | 66 | { |
---|
[5512] | 67 | //if (ClassList::exists(Laser::explosionParticles, CL_PARTICLE_SYSTEM)) |
---|
| 68 | // delete Laser::explosionParticles; |
---|
| 69 | PRINTF(1)("Deleting Laser Particles\n"); |
---|
[5456] | 70 | Laser::explosionParticles = NULL; |
---|
[5447] | 71 | } |
---|
[5445] | 72 | |
---|
[3708] | 73 | } |
---|
| 74 | |
---|
[5456] | 75 | ParticleSystem* Laser::explosionParticles = NULL; |
---|
[5443] | 76 | |
---|
[5456] | 77 | void Laser::activate() |
---|
[5443] | 78 | { |
---|
| 79 | State::getWorldEntityList()->add(this); |
---|
[5456] | 80 | if (unlikely(Laser::explosionParticles == NULL)) |
---|
[5447] | 81 | { |
---|
[5456] | 82 | Laser::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE); |
---|
| 83 | Laser::explosionParticles->setName("LaserExplosionParticles"); |
---|
| 84 | Laser::explosionParticles->setLifeSpan(.5, .3); |
---|
[5750] | 85 | Laser::explosionParticles->setRadius(0.0, 10.0); |
---|
[5465] | 86 | Laser::explosionParticles->setRadius(.5, 6.0); |
---|
[5456] | 87 | Laser::explosionParticles->setRadius(1.0, 3.0); |
---|
[5457] | 88 | Laser::explosionParticles->setColor(0.0, 1,1,0,.9); |
---|
[5456] | 89 | Laser::explosionParticles->setColor(0.5, .8,.8,0,.5); |
---|
[5457] | 90 | Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0); |
---|
[5447] | 91 | } |
---|
[5443] | 92 | } |
---|
| 93 | |
---|
| 94 | |
---|
[5456] | 95 | void Laser::deactivate() |
---|
[5443] | 96 | { |
---|
[5447] | 97 | ParticleEngine::getInstance()->breakConnections(this->emitter); |
---|
| 98 | this->lifeCycle = 0.0; |
---|
[5443] | 99 | |
---|
[5447] | 100 | // GarbageCollector::getInstance()->collect(this); |
---|
| 101 | State::getWorldEntityList()->remove(this); |
---|
[5456] | 102 | Laser::fastFactory->kill(this); |
---|
[5443] | 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
[5456] | 106 | void Laser::collidesWith(WorldEntity* entity, const Vector& location) |
---|
[5257] | 107 | { |
---|
[5447] | 108 | if (this->hitEntity != entity && entity->isA(CL_NPC)) |
---|
| 109 | this->destroy(); |
---|
| 110 | this->hitEntity = entity; |
---|
[5257] | 111 | } |
---|
[3708] | 112 | |
---|
| 113 | /** |
---|
[4836] | 114 | * signal tick, time dependent things will be handled here |
---|
| 115 | * @param time since last tick |
---|
[3708] | 116 | */ |
---|
[5456] | 117 | void Laser::tick (float time) |
---|
[3708] | 118 | { |
---|
[4464] | 119 | //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); |
---|
| 120 | Vector v = this->velocity * (time); |
---|
[3708] | 121 | this->shiftCoor(v); |
---|
| 122 | |
---|
[4890] | 123 | this->lifeCycle += time/this->lifeSpan; |
---|
[5447] | 124 | if( this->lifeCycle >= 1.0) |
---|
[3708] | 125 | { |
---|
| 126 | PRINTF(5)("FINALIZE==========================\n"); |
---|
[4890] | 127 | PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); |
---|
[3708] | 128 | PRINTF(5)("FINALIZE===========================\n"); |
---|
[5447] | 129 | |
---|
[5443] | 130 | this->deactivate(); |
---|
[3708] | 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | /** |
---|
[4836] | 135 | * the function gets called, when the projectile is destroyed |
---|
[3708] | 136 | */ |
---|
[5456] | 137 | void Laser::destroy () |
---|
[5257] | 138 | { |
---|
[5456] | 139 | PRINTF(5)("DESTROY Laser\n"); |
---|
[5448] | 140 | this->lifeCycle = .95; //!< @todo calculate this usefully. |
---|
[5456] | 141 | ParticleEngine::getInstance()->addConnection(this->emitter, Laser::explosionParticles); |
---|
[3708] | 142 | |
---|
[5257] | 143 | } |
---|
| 144 | |
---|
| 145 | |
---|
[5500] | 146 | void Laser::draw () const |
---|
[3708] | 147 | { |
---|
| 148 | glMatrixMode(GL_MODELVIEW); |
---|
| 149 | glPushMatrix(); |
---|
[5457] | 150 | glPushAttrib(GL_ENABLE_BIT); |
---|
| 151 | glDisable(GL_LIGHTING); |
---|
[3708] | 152 | |
---|
[4593] | 153 | float matrix[4][4]; |
---|
[3708] | 154 | glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); |
---|
| 155 | this->getAbsDir().matrix (matrix); |
---|
[4593] | 156 | glMultMatrixf((float*)matrix); |
---|
[3755] | 157 | glScalef(2.0, 2.0, 2.0); |
---|
[3708] | 158 | this->model->draw(); |
---|
[5457] | 159 | glPopAttrib(); |
---|
[3708] | 160 | glPopMatrix(); |
---|
| 161 | } |
---|
| 162 | |
---|