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