Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/laser.cc @ 5532

Last change on this file since 5532 was 5512, checked in by bensch, 19 years ago

orxonox/trunk: removed a segfault, that came through the call to BaseObject::exists(); in Laser.h

File size: 4.0 KB
RevLine 
[4593]1/*
[3708]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
[5443]13   co-programmer: Benjamin Grauer
14
[3708]15*/
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3708]17
[5456]18#include "laser.h"
[3708]19
[4947]20#include "fast_factory.h"
[3708]21
[5443]22#include "state.h"
23#include "list.h"
[5444]24#include "class_list.h"
[5511]25#include "model.h"
[5054]26
[5443]27#include "particle_engine.h"
28#include "particle_emitter.h"
29#include "particle_system.h"
30
31
[3708]32using namespace std;
33
[5456]34CREATE_FAST_FACTORY_STATIC(Laser, CL_LASER);
[3708]35
36/**
[4836]37 *  standard constructor
[3708]38*/
[5456]39Laser::Laser () : Projectile()
[3755]40{
[5512]41  this->setClassID(CL_LASER, "Laser");
[4597]42
[4948]43  float modelSize = .3;
[5457]44  this->loadModel("models/projectiles/laser.obj");
[4948]45
46  this->energyMin = 1;
47  this->energyMax = 10;
[4969]48  this->remove();
[5458]49  this->lifeSpan = 1.0;
[5443]50
[5447]51  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
[5443]52  this->emitter->setParent(this);
[5449]53  this->emitter->setSpread(M_PI, M_PI);
[5465]54  this->emitter->setEmissionRate(300.0);
[5456]55  this->emitter->setEmissionVelocity(50.0);
[3755]56}
[3708]57
58
59/**
[4836]60 *  standard deconstructor
[3708]61*/
[5456]62Laser::~Laser ()
[3708]63{
[5446]64  // delete this->emitter;
[5444]65
[5445]66  /* this is normaly done by World.cc by deleting the ParticleEngine */
[5512]67  if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->getSize() <= 1)
[5447]68  {
[5512]69    //if (ClassList::exists(Laser::explosionParticles, CL_PARTICLE_SYSTEM))
70    //  delete Laser::explosionParticles;
71    PRINTF(1)("Deleting Laser Particles\n");
[5456]72    Laser::explosionParticles = NULL;
[5447]73  }
[5445]74
[3708]75}
76
[5456]77ParticleSystem* Laser::explosionParticles = NULL;
[5443]78
[5456]79void Laser::activate()
[5443]80{
81  State::getWorldEntityList()->add(this);
[5456]82  if (unlikely(Laser::explosionParticles == NULL))
[5447]83  {
[5456]84    Laser::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
85    Laser::explosionParticles->setName("LaserExplosionParticles");
86    Laser::explosionParticles->setLifeSpan(.5, .3);
[5465]87    Laser::explosionParticles->setRadius(0.0, 3.0);
88    Laser::explosionParticles->setRadius(.5, 6.0);
[5456]89    Laser::explosionParticles->setRadius(1.0, 3.0);
[5457]90    Laser::explosionParticles->setColor(0.0, 1,1,0,.9);
[5456]91    Laser::explosionParticles->setColor(0.5, .8,.8,0,.5);
[5457]92    Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0);
[5447]93  }
[5443]94}
95
96
[5456]97void Laser::deactivate()
[5443]98{
[5447]99  ParticleEngine::getInstance()->breakConnections(this->emitter);
100  this->lifeCycle = 0.0;
[5443]101
[5447]102//  GarbageCollector::getInstance()->collect(this);
103  State::getWorldEntityList()->remove(this);
[5456]104  Laser::fastFactory->kill(this);
[5443]105}
106
107
[5456]108void Laser::collidesWith(WorldEntity* entity, const Vector& location)
[5257]109{
[5447]110  if (this->hitEntity != entity && entity->isA(CL_NPC))
111    this->destroy();
112  this->hitEntity = entity;
[5257]113}
[3708]114
115/**
[4836]116 *  signal tick, time dependent things will be handled here
117 * @param time since last tick
[3708]118*/
[5456]119void Laser::tick (float time)
[3708]120{
[4464]121  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
122  Vector v = this->velocity * (time);
[3708]123  this->shiftCoor(v);
124
[4890]125  this->lifeCycle += time/this->lifeSpan;
[5447]126  if( this->lifeCycle >= 1.0)
[3708]127    {
128      PRINTF(5)("FINALIZE==========================\n");
[4890]129      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
[3708]130      PRINTF(5)("FINALIZE===========================\n");
[5447]131
[5443]132      this->deactivate();
[3708]133    }
134}
135
136/**
[4836]137 *  the function gets called, when the projectile is destroyed
[3708]138*/
[5456]139void Laser::destroy ()
[5257]140{
[5456]141  PRINTF(5)("DESTROY Laser\n");
[5448]142  this->lifeCycle = .95; //!< @todo calculate this usefully.
[5456]143  ParticleEngine::getInstance()->addConnection(this->emitter, Laser::explosionParticles);
[3708]144
[5257]145}
146
147
[5500]148void Laser::draw () const
[3708]149{
150  glMatrixMode(GL_MODELVIEW);
151  glPushMatrix();
[5457]152  glPushAttrib(GL_ENABLE_BIT);
153  glDisable(GL_LIGHTING);
[3708]154
[4593]155  float matrix[4][4];
[3708]156  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
157  this->getAbsDir().matrix (matrix);
[4593]158  glMultMatrixf((float*)matrix);
[3755]159  glScalef(2.0, 2.0, 2.0);
[3708]160  this->model->draw();
[5457]161  glPopAttrib();
[3708]162  glPopMatrix();
163}
164
Note: See TracBrowser for help on using the repository browser.