Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/laser.cc @ 6958

Last change on this file since 6958 was 6825, checked in by bensch, 19 years ago

trunk: new interface to ParticleEmitters

File size: 3.6 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 "laser.h"
19#include <assert.h>
20
21
22#include "fast_factory.h"
23
24#include "state.h"
25#include "class_list.h"
26#include "model.h"
27
28#include "dot_emitter.h"
29#include "sprite_particles.h"
30
31#include <cassert>
32
33using namespace std;
34
35CREATE_FAST_FACTORY_STATIC(Laser, CL_LASER);
36
37/**
38 *  standard constructor
39*/
40Laser::Laser () : Projectile()
41{
42  this->setClassID(CL_LASER, "Laser");
43
44  this->loadModel("models/projectiles/laser.obj");
45
46  this->setMinEnergy(1);
47  this->setHealthMax(10);
48  this->lifeSpan = 5.0;
49
50  this->emitter = new DotEmitter(100, 5, M_2_PI);
51  this->emitter->setParent(this);
52  this->emitter->setSpread(M_PI, M_PI);
53  this->emitter->setEmissionRate(300.0);
54  this->emitter->setEmissionVelocity(50.0);
55}
56
57
58/**
59 *  standard deconstructor
60*/
61Laser::~Laser ()
62{
63  // delete this->emitter;
64
65  /* this is normaly done by World.cc by deleting the ParticleEngine */
66  if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->size() <= 1)
67  {
68    //if (ClassList::exists(Laser::explosionParticles, CL_PARTICLE_SYSTEM))
69    //  delete Laser::explosionParticles;
70    PRINTF(1)("Deleting Laser Particles\n");
71    Laser::explosionParticles = NULL;
72  }
73
74}
75
76SpriteParticles* Laser::explosionParticles = NULL;
77
78void Laser::activate()
79{
80  if (unlikely(Laser::explosionParticles == NULL))
81  {
82    Laser::explosionParticles = new SpriteParticles(1000);
83    Laser::explosionParticles->setName("LaserExplosionParticles");
84    Laser::explosionParticles->setLifeSpan(.5, .3);
85    Laser::explosionParticles->setRadius(0.0, 10.0);
86    Laser::explosionParticles->setRadius(.5, 6.0);
87    Laser::explosionParticles->setRadius(1.0, 3.0);
88    Laser::explosionParticles->setColor(0.0, 1,1,0,.9);
89    Laser::explosionParticles->setColor(0.5, .8,.8,0,.5);
90    Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0);
91  }
92}
93
94
95void Laser::deactivate()
96{
97  assert (Laser::explosionParticles != NULL);
98  Laser::explosionParticles->removeEmitter(this->emitter);
99  this->lifeCycle = 0.0;
100
101  this->toList(OM_NULL);
102  this->removeNode();
103  Laser::fastFactory->kill(this);
104}
105
106
107void Laser::collidesWith(WorldEntity* entity, const Vector& location)
108{
109  if (this->hitEntity != entity && entity->isA(CL_NPC))
110    this->destroy();
111  this->hitEntity = entity;
112}
113
114/**
115 *  signal tick, time dependent things will be handled here
116 * @param dt time since last tick
117*/
118void Laser::tick (float dt)
119{
120  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
121  Vector v = this->velocity * dt;
122  this->shiftCoor(v);
123
124  if (this->tickLifeCycle(dt))
125    this->deactivate();
126}
127
128/**
129 *  the function gets called, when the projectile is destroyed
130*/
131void Laser::destroy ()
132{
133  PRINTF(5)("DESTROY Laser\n");
134  this->lifeCycle = .95; //!< @todo calculate this usefully.
135
136  this->emitter->setSystem(Laser::explosionParticles);
137}
138
139
140void Laser::draw () const
141{
142  glMatrixMode(GL_MODELVIEW);
143  glPushMatrix();
144  glPushAttrib(GL_ENABLE_BIT);
145  glDisable(GL_LIGHTING);
146
147  float matrix[4][4];
148  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
149  this->getAbsDir().matrix (matrix);
150  glMultMatrixf((float*)matrix);
151  glScalef(2.0, 2.0, 2.0);
152  this->getModel()->draw();
153  glPopAttrib();
154  glPopMatrix();
155}
156
Note: See TracBrowser for help on using the repository browser.