Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/projectiles/laser.cc @ 6691

Last change on this file since 6691 was 6691, checked in by snellen, 18 years ago

adjusted some parameters

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