/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. ### File Specific main-programmer: Patrick Boenzli co-programmer: Benjamin Grauer */ #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON #include "test_bullet.h" #include "model.h" #include "vector.h" #include "garbage_collector.h" #include "fast_factory.h" #include "state.h" #include "list.h" #include "class_list.h" #include "particle_engine.h" #include "particle_emitter.h" #include "particle_system.h" using namespace std; CREATE_FAST_FACTORY(TestBullet, CL_TEST_BULLET); /** * standard constructor */ TestBullet::TestBullet () : Projectile() { this->setClassID(CL_TEST_BULLET, "TestBullet"); float modelSize = .3; this->loadModelWithScale("models/projectiles/orx-rocket.obj", .3); this->energyMin = 1; this->energyMax = 10; this->remove(); this->lifeSpan = 5; this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 0.01); this->emitter->setParent(this); this->emitter->setEmissionRate(20); this->emitter->setSpread(M_2_PI); } /** * standard deconstructor */ TestBullet::~TestBullet () { delete this->emitter; /* this is normaly done by World.cc by deleting the ParticleEngine if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() == 1) { delete TestBullet::explosionParticles; TestBullet::explosionParticles = NULL; } */ } ParticleSystem* TestBullet::explosionParticles = NULL; void TestBullet::activate() { State::getWorldEntityList()->add(this); if (unlikely(TestBullet::explosionParticles == NULL)) { TestBullet::explosionParticles = new ParticleSystem(10000, PARTICLE_SPRITE); TestBullet::explosionParticles->setLifeSpan(.5); TestBullet::explosionParticles->setRadius(0.0, .5); TestBullet::explosionParticles->setRadius(0.5, 2.0); TestBullet::explosionParticles->setRadius(0.0, 0.0); TestBullet::explosionParticles->setColor(0.0, 1,0,0,.7); TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5); TestBullet::explosionParticles->setColor(1.0, .5,.5,.5,.0); } ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles); } void TestBullet::deactivate() { ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::explosionParticles); GarbageCollector::getInstance()->collect(this); this->lifeCycle = 0.0; } void TestBullet::collidesWith(WorldEntity* entity, const Vector& location) { } /** * signal tick, time dependent things will be handled here * @param time since last tick */ void TestBullet::tick (float time) { //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1); Vector v = this->velocity * (time); this->shiftCoor(v); this->lifeCycle += time/this->lifeSpan; if( this->lifeCycle >= 1) { PRINTF(5)("FINALIZE==========================\n"); PRINTF(5)("current life cycle is: %f\n", this->lifeCycle); PRINTF(5)("FINALIZE===========================\n"); // this->finalize(); this->deactivate(); } } /** * the function gets called, when the projectile is destroyed */ void TestBullet::destroy () { this->deactivate(); GarbageCollector::getInstance()->collect(this); } void TestBullet::draw () { glMatrixMode(GL_MODELVIEW); glPushMatrix(); float matrix[4][4]; glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z); this->getAbsDir().matrix (matrix); glMultMatrixf((float*)matrix); glScalef(2.0, 2.0, 2.0); this->model->draw(); glPopMatrix(); }