Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/mbolt.cc @ 10761

Last change on this file since 10761 was 10747, checked in by nicolasc, 18 years ago

cleaned out origList

File size: 5.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004-2006 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: Marc Schaerrer
13   co-programmer: Benjamin Grauer
14
15*/
16
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "mbolt.h"
21
22#include "state.h"
23#include "model.h"
24
25#include "world_entities/npcs/npc.h"
26
27#include "particles/dot_emitter.h"
28#include "particles/sprite_particles.h"
29
30#include "space_ships/space_ship.h"
31
32#include <cassert>
33#include "debug.h"
34
35#include "static_model.h"
36
37#include "effects/trail.h"
38
39#include "obb_tree.h"
40
41
42
43ObjectListDefinition(MBolt);
44CREATE_FAST_FACTORY_STATIC(MBolt);
45
46/**
47 *  standard constructor
48*/
49MBolt::MBolt () : Projectile()
50{
51  this->registerObject(this, MBolt::_objectList);
52  this->loadModel("models/projectiles/mbolt.obj",4);
53
54
55  //this->loadModel("models/projectiles/laser.obj");
56
57  this->setMinEnergy(4);
58  this->setHealthMax(0);
59  this->lifeSpan = 1.5;
60  this->angle     = 0;
61
62  //this->emitter = new DotEmitter(1000, 0, 0);
63  this->emitter = new DotEmitter(50, 0, 0);
64  this->emitter->setParent(this);
65  this->emitter->setSpread(M_PI,M_PI);
66  this->emitter->setInheritSpeed(this->velocity.len());
67  this->emitter->setEmissionRate(500.0);
68  this->emitter->setEmissionVelocity(this->velocity.len());
69
70  this->mat = new Material("mBolt");
71  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
72  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
73  this->mat->setDiffuse(1,1,1);
74  this->mat->setDiffuseMap("laser_add.png");
75  this->mat->setDiffuseMap("laser.png",1);
76
77  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(*this->mat);
78  dynamic_cast<StaticModel*>(this->getModel())->finalize();
79
80  dynamic_cast<StaticModel*>(this->getModel())->rebuild();
81  //this->buildObbTree(4);
82
83  this->trail = new Trail(6, 4, .1, this);
84  //this->trail->setParent( this);
85  this->trail->setTexture( "textures/laser.png");
86//   this->trail->setAbsCoor(this->getAbsCoor() - Vector(.7,0,0));
87  this->trail->setAbsCoor(this->getAbsCoor() - this->getVelocity().getNormalized() * .7);
88 
89  this->obbTree = new OBBTree();
90  this->obbTree->createBox(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 1.0f, 1.0f));
91  this->setOBBTree(this->obbTree);
92
93}
94
95
96/**
97 *  standard deconstructor
98 *
99 */
100MBolt::~MBolt ()
101{
102
103  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
104  {
105    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
106      delete MBolt::explosionParticles;
107    MBolt::explosionParticles = NULL;
108    PRINTF(1)("Deleting MBolt Explosion Particles\n");
109  }
110
111  delete this->emitter;
112  delete this->trail;
113}
114
115SpriteParticles* MBolt::explosionParticles = NULL;
116
117void MBolt::activate()
118{
119//   this->origList = this->getOMListNumber();
120//   this->toList(OM_ENVIRON);
121  if (unlikely(MBolt::explosionParticles == NULL))
122  {
123    MBolt::explosionParticles = new SpriteParticles(1000);
124    MBolt::explosionParticles->setName("MBoltExplosionParticles");
125    MBolt::explosionParticles->setLifeSpan(.2, .1);
126    MBolt::explosionParticles->setRadius(0.0, 10.0);
127    MBolt::explosionParticles->setRadius(.5, 6.0);
128    MBolt::explosionParticles->setRadius(1.0, 3.0);
129    MBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
130    MBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
131    MBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
132  }
133
134  this->setPhysDamage(10);
135  this->setElecDamage(0);
136  this->setHealth(0);
137
138  this->emitter->setSpread(0);
139  this->emitter->setEmissionRate(10.0);
140  this->emitter->setEmissionVelocity(50);
141}
142
143
144void MBolt::deactivate()
145{
146  assert (MBolt::explosionParticles != NULL);
147  MBolt::explosionParticles->removeEmitter(this->emitter);
148  this->lifeCycle = 0.0;
149
150  this->lifeCycle = 0.0;
151  this->toList(OM_NULL);
152  //this->toList(OM_DEAD);
153//   this->removeNode();
154  MBolt::fastFactory->kill(this);
155}
156
157void MBolt::hit (float damage, WorldEntity* entity )
158{
159
160  if (this->hitEntity != entity)
161    this->destroy( entity );
162  this->hitEntity = entity;
163 // dynamic_cast<SpaceShip*>(entity)->damage(this->getPhysDamage(),this->getElecDamage());
164  //this->destroy(this);
165  this->deactivate();
166
167  return;
168
169}
170
171/**
172 *  signal tick, time dependent things will be handled here
173 * @param dt time since last tick
174*/
175void MBolt::tick (float dt)
176{
177  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
178  Vector v = this->velocity * dt;
179  this->shiftCoor(v);
180
181  if (this->tickLifeCycle(dt))
182    this->deactivate();
183
184  this->angle += MBolt::rotationSpeed * dt;
185  this->trail->tick(dt);
186}
187
188/**
189 *  the function gets called, when the projectile is destroyed
190*/
191void MBolt::destroy (WorldEntity* killer)
192{
193  //this->deactivate();
194  Projectile::destroy( killer );
195  PRINTF(5)("DESTROY MBolt\n");
196  this->lifeCycle = .95; //!< @todo calculate this usefully.
197
198  this->emitter->setSystem(MBolt::explosionParticles);
199}
200
201
202void MBolt::draw () const
203{
204  glPushAttrib(GL_ENABLE_BIT);
205  glDisable(GL_LIGHTING);
206
207  glPushMatrix();
208  float matrix[4][4];
209  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
210//   glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile
211  glRotatef(this->angle, this->flightDirection.x, this->flightDirection.y, this->flightDirection.z);
212  this->getAbsDir().matrix (matrix);
213  glMultMatrixf((float*)matrix);
214
215  glScalef(0.75/4, 0.7/16, 0.7/16);  // no double rescale
216
217  this->mat->select();
218  dynamic_cast<StaticModel*>(this->getModel())->draw();
219  this->mat->unselect();
220  glScalef(4/.75,16/.7,16/.7);
221  glTranslatef(-3,0,0);
222  this->trail->draw();
223  glPopMatrix();
224  glPopAttrib();
225
226}
Note: See TracBrowser for help on using the repository browser.