Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: removed stupid included in base_object.h
this should lead to faster compile-times

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