Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/rocket.cc @ 5472

Last change on this file since 5472 was 5472, checked in by bensch, 18 years ago

orxonox/trunk: even cooler rocket trails

File size: 5.3 KB
Line 
1/*
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
13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "rocket.h"
19
20#include "fast_factory.h"
21
22#include "state.h"
23#include "list.h"
24#include "class_list.h"
25
26#include "particle_engine.h"
27#include "particle_emitter.h"
28#include "particle_system.h"
29
30
31using namespace std;
32
33CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET);
34
35/**
36 *  standard constructor
37*/
38Rocket::Rocket () : Projectile()
39{
40  this->setClassID(CL_TEST_BULLET, "Rocket");
41
42  float modelSize = .3;
43  this->loadModelWithScale("models/projectiles/orx-rocket.obj", .3);
44
45  this->energyMin = 1;
46  this->energyMax = 10;
47  this->remove();
48  this->lifeSpan = 2;
49
50  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
51  this->emitter->setParent(this);
52  this->emitter->setSpread(M_PI, M_PI);
53}
54
55
56/**
57 *  standard deconstructor
58*/
59Rocket::~Rocket ()
60{
61  // delete this->emitter;
62
63  /* this is normaly done by World.cc by deleting the ParticleEngine */
64  if (Rocket::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
65  {
66    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM))
67      delete Rocket::trailParticles;
68    Rocket::trailParticles = NULL;
69  }
70  if (Rocket::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->getSize() <= 1)
71  {
72    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM))
73      delete Rocket::explosionParticles;
74    Rocket::explosionParticles = NULL;
75  }
76
77}
78
79ParticleSystem* Rocket::trailParticles = NULL;
80ParticleSystem* Rocket::explosionParticles = NULL;
81
82void Rocket::activate()
83{
84  State::getWorldEntityList()->add(this);
85  if (unlikely(Rocket::trailParticles == NULL))
86  {
87    Rocket::trailParticles = new ParticleSystem(2000, PARTICLE_SPRITE);
88    Rocket::trailParticles->setName("RocketTrailParticles");
89    Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
90    Rocket::trailParticles->setLifeSpan(1.0, .3);
91    Rocket::trailParticles->setRadius(0.0, .5);
92    Rocket::trailParticles->setRadius(0.2, 2.0);
93    Rocket::trailParticles->setRadius(.5, .8);
94    Rocket::trailParticles->setRadius(1.0, .8);
95    Rocket::trailParticles->setColor(0.0, 1,0,0,.7);
96    Rocket::trailParticles->setColor(0.2, .8,.8,0,.5);
97    Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8);
98    Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0);
99  }
100  if (unlikely(Rocket::explosionParticles == NULL))
101  {
102    Rocket::explosionParticles = new ParticleSystem(200, PARTICLE_SPRITE);
103    Rocket::explosionParticles->setName("RocketExplosionParticles");
104    Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
105    Rocket::explosionParticles->setLifeSpan(.6, .3);
106    Rocket::explosionParticles->setRadius(0.0, 10);
107    Rocket::explosionParticles->setRadius(.5, 20.0);
108    Rocket::explosionParticles->setRadius(1.0, 20.0);
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);
112    Rocket::explosionParticles->setColor(1.0, 1,1,1,.0);
113  }
114
115  ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::trailParticles);
116
117  this->emitter->setEmissionRate(45.0);
118  this->emitter->setEmissionVelocity(0.0);
119}
120
121
122void Rocket::deactivate()
123{
124  ParticleEngine::getInstance()->breakConnections(this->emitter);
125  this->lifeCycle = 0.0;
126
127//  GarbageCollector::getInstance()->collect(this);
128  State::getWorldEntityList()->remove(this);
129  Rocket::fastFactory->kill(this);
130}
131
132
133void Rocket::collidesWith(WorldEntity* entity, const Vector& location)
134{
135  if (this->hitEntity != entity && entity->isA(CL_NPC))
136    this->destroy();
137  this->hitEntity = entity;
138}
139
140/**
141 *  signal tick, time dependent things will be handled here
142 * @param time since last tick
143*/
144void Rocket::tick (float time)
145{
146  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
147  Vector v = this->velocity * (time);
148  this->shiftCoor(v);
149
150  this->lifeCycle += time/this->lifeSpan;
151  if( this->lifeCycle >= 1.0)
152    {
153      PRINTF(5)("FINALIZE==========================\n");
154      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
155      PRINTF(5)("FINALIZE===========================\n");
156
157      this->deactivate();
158    }
159}
160
161/**
162 *  the function gets called, when the projectile is destroyed
163*/
164void Rocket::destroy ()
165{
166  PRINTF(5)("DESTROY Rocket\n");
167  this->lifeCycle = .95; //!< @todo calculate this usefully.
168  ParticleEngine::getInstance()->breakConnection(this->emitter, Rocket::trailParticles);
169  ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::explosionParticles);
170
171  this->emitter->setEmissionRate(1000.0);
172  this->emitter->setEmissionVelocity(50.0);
173//  this->deactivate();
174
175}
176
177
178void Rocket::draw ()
179{
180  glMatrixMode(GL_MODELVIEW);
181  glPushMatrix();
182
183  float matrix[4][4];
184  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
185  this->getAbsDir().matrix (matrix);
186  glMultMatrixf((float*)matrix);
187  glScalef(2.0, 2.0, 2.0);
188  this->model->draw();
189
190  glPopMatrix();
191}
192
Note: See TracBrowser for help on using the repository browser.