Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cd_ancient/src/world_entities/weapons/rocket.cc @ 7434

Last change on this file since 7434 was 5693, checked in by patrick, 19 years ago

orxonox: work flush

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