Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/weapons/laser.cc @ 6297

Last change on this file since 6297 was 6142, checked in by bensch, 19 years ago

orxonox/trunk: merge the ObjectManager to the trunk
merged with command:
svn merge -r6082:HEAD objectmanager/ ../trunk/

conflicts resolution was easy this time :)
but specially merged the world to network_world

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
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->lifeSpan = 1.0;
48
49  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
50  this->emitter->setParent(this);
51  this->emitter->setSpread(M_PI, M_PI);
52  this->emitter->setEmissionRate(300.0);
53  this->emitter->setEmissionVelocity(50.0);
54}
55
56
57/**
58 *  standard deconstructor
59*/
60Laser::~Laser ()
61{
62  // delete this->emitter;
63
64  /* this is normaly done by World.cc by deleting the ParticleEngine */
65  if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->size() <= 1)
66  {
67    //if (ClassList::exists(Laser::explosionParticles, CL_PARTICLE_SYSTEM))
68    //  delete Laser::explosionParticles;
69    PRINTF(1)("Deleting Laser Particles\n");
70    Laser::explosionParticles = NULL;
71  }
72
73}
74
75ParticleSystem* Laser::explosionParticles = NULL;
76
77void Laser::activate()
78{
79  if (unlikely(Laser::explosionParticles == NULL))
80  {
81    Laser::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
82    Laser::explosionParticles->setName("LaserExplosionParticles");
83    Laser::explosionParticles->setLifeSpan(.5, .3);
84    Laser::explosionParticles->setRadius(0.0, 10.0);
85    Laser::explosionParticles->setRadius(.5, 6.0);
86    Laser::explosionParticles->setRadius(1.0, 3.0);
87    Laser::explosionParticles->setColor(0.0, 1,1,0,.9);
88    Laser::explosionParticles->setColor(0.5, .8,.8,0,.5);
89    Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0);
90  }
91}
92
93
94void Laser::deactivate()
95{
96  ParticleEngine::getInstance()->breakConnections(this->emitter);
97  this->lifeCycle = 0.0;
98
99  this->toList(OM_NULL);
100  this->removeNode();
101  Laser::fastFactory->kill(this);
102}
103
104
105void Laser::collidesWith(WorldEntity* entity, const Vector& location)
106{
107  if (this->hitEntity != entity && entity->isA(CL_NPC))
108    this->destroy();
109  this->hitEntity = entity;
110}
111
112/**
113 *  signal tick, time dependent things will be handled here
114 * @param dt time since last tick
115*/
116void Laser::tick (float dt)
117{
118  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
119  Vector v = this->velocity * dt;
120  this->shiftCoor(v);
121
122  if (this->tickLifeCycle(dt))
123    this->deactivate();
124}
125
126/**
127 *  the function gets called, when the projectile is destroyed
128*/
129void Laser::destroy ()
130{
131  PRINTF(5)("DESTROY Laser\n");
132  this->lifeCycle = .95; //!< @todo calculate this usefully.
133  ParticleEngine::getInstance()->addConnection(this->emitter, Laser::explosionParticles);
134}
135
136
137void Laser::draw () const
138{
139  glMatrixMode(GL_MODELVIEW);
140  glPushMatrix();
141  glPushAttrib(GL_ENABLE_BIT);
142  glDisable(GL_LIGHTING);
143
144  float matrix[4][4];
145  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
146  this->getAbsDir().matrix (matrix);
147  glMultMatrixf((float*)matrix);
148  glScalef(2.0, 2.0, 2.0);
149  this->getModel()->draw();
150  glPopAttrib();
151  glPopMatrix();
152}
153
Note: See TracBrowser for help on using the repository browser.