Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: new interface to ParticleEmitters

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