Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/collision_detection/src/world_entities/weapons/laser.cc @ 5813

Last change on this file since 5813 was 5687, checked in by bensch, 19 years ago

orxonox/trunk: subproject collision_detection works again, and again, and again

File size: 4.0 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
20#include "fast_factory.h"
21
22#include "state.h"
23#include "list.h"
24#include "class_list.h"
25#include "model.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(Laser, CL_LASER);
35
36/**
37 *  standard constructor
38*/
39Laser::Laser () : Projectile()
40{
41  this->setClassID(CL_LASER, "Laser");
42
43  this->loadModel("models/projectiles/laser.obj");
44
45  this->energyMin = 1;
46  this->energyMax = 10;
47  this->remove();
48  this->lifeSpan = 1.0;
49
50  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
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)->getSize() <= 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
76ParticleSystem* Laser::explosionParticles = NULL;
77
78void Laser::activate()
79{
80  State::getWorldEntityList()->add(this);
81  if (unlikely(Laser::explosionParticles == NULL))
82  {
83    Laser::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
84    Laser::explosionParticles->setName("LaserExplosionParticles");
85    Laser::explosionParticles->setLifeSpan(.5, .3);
86    Laser::explosionParticles->setRadius(0.0, 3.0);
87    Laser::explosionParticles->setRadius(.5, 6.0);
88    Laser::explosionParticles->setRadius(1.0, 3.0);
89    Laser::explosionParticles->setColor(0.0, 1,1,0,.9);
90    Laser::explosionParticles->setColor(0.5, .8,.8,0,.5);
91    Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0);
92  }
93}
94
95
96void Laser::deactivate()
97{
98  ParticleEngine::getInstance()->breakConnections(this->emitter);
99  this->lifeCycle = 0.0;
100
101//  GarbageCollector::getInstance()->collect(this);
102  State::getWorldEntityList()->remove(this);
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 time since last tick
117*/
118void Laser::tick (float time)
119{
120  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
121  Vector v = this->velocity * (time);
122  this->shiftCoor(v);
123
124  this->lifeCycle += time/this->lifeSpan;
125  if( this->lifeCycle >= 1.0)
126    {
127      PRINTF(5)("FINALIZE==========================\n");
128      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
129      PRINTF(5)("FINALIZE===========================\n");
130
131      this->deactivate();
132    }
133}
134
135/**
136 *  the function gets called, when the projectile is destroyed
137*/
138void Laser::destroy ()
139{
140  PRINTF(5)("DESTROY Laser\n");
141  this->lifeCycle = .95; //!< @todo calculate this usefully.
142  ParticleEngine::getInstance()->addConnection(this->emitter, Laser::explosionParticles);
143
144}
145
146
147void Laser::draw () const
148{
149  glMatrixMode(GL_MODELVIEW);
150  glPushMatrix();
151  glPushAttrib(GL_ENABLE_BIT);
152  glDisable(GL_LIGHTING);
153
154  float matrix[4][4];
155  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
156  this->getAbsDir().matrix (matrix);
157  glMultMatrixf((float*)matrix);
158  glScalef(2.0, 2.0, 2.0);
159  this->model->draw();
160  glPopAttrib();
161  glPopMatrix();
162}
163
Note: See TracBrowser for help on using the repository browser.