Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/world_entities/projectiles/rocket.cc @ 7539

Last change on this file since 7539 was 7193, checked in by bensch, 19 years ago

orxonox/trunk: new style for resources (prework/movement)

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