Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/rocket.cc @ 6455

Last change on this file since 6455 was 6434, checked in by bensch, 19 years ago

orxonox/trunk: moved the projectiles to Projectiles

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