Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6693 was 6692, checked in by patrick, 19 years ago

emerged spaceshipcontrol back to trunk via command >svn merge branches/spaceshipcontrol/ trunk/ -r 6639:HEAD

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
[5443]28#include "particle_emitter.h"
[6621]29#include "sprite_particles.h"
[6692]30#include <cassert>
[5443]31
32
[6655]33
[3708]34using namespace std;
35
[5456]36CREATE_FAST_FACTORY_STATIC(Laser, CL_LASER);
[3708]37
38/**
[4836]39 *  standard constructor
[3708]40*/
[5456]41Laser::Laser () : Projectile()
[3755]42{
[5512]43  this->setClassID(CL_LASER, "Laser");
[4597]44
[5687]45  this->loadModel("models/projectiles/laser.obj");
[4948]46
[6431]47  this->setMinEnergy(1);
48  this->setMaxEnergy(10);
[6162]49  this->lifeSpan = 5.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 */
[5779]67  if (Laser::explosionParticles != NULL && ClassList::getList(CL_LASER)->size() <= 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
[6622]77SpriteParticles* Laser::explosionParticles = NULL;
[5443]78
[5456]79void Laser::activate()
[5443]80{
[5456]81  if (unlikely(Laser::explosionParticles == NULL))
[5447]82  {
[6621]83    Laser::explosionParticles = new SpriteParticles(1000);
[5456]84    Laser::explosionParticles->setName("LaserExplosionParticles");
85    Laser::explosionParticles->setLifeSpan(.5, .3);
[5750]86    Laser::explosionParticles->setRadius(0.0, 10.0);
[5465]87    Laser::explosionParticles->setRadius(.5, 6.0);
[5456]88    Laser::explosionParticles->setRadius(1.0, 3.0);
[5457]89    Laser::explosionParticles->setColor(0.0, 1,1,0,.9);
[5456]90    Laser::explosionParticles->setColor(0.5, .8,.8,0,.5);
[5457]91    Laser::explosionParticles->setColor(1.0, .8,.8,.7,.0);
[5447]92  }
[5443]93}
94
95
[5456]96void Laser::deactivate()
[5443]97{
[6619]98  assert (Laser::explosionParticles != NULL);
99  Laser::explosionParticles->removeEmitter(this->emitter);
[5447]100  this->lifeCycle = 0.0;
[5443]101
[6142]102  this->toList(OM_NULL);
[6056]103  this->removeNode();
[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
[6056]117 * @param dt time since last tick
[3708]118*/
[6056]119void Laser::tick (float dt)
[3708]120{
[4464]121  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
[6056]122  Vector v = this->velocity * dt;
[3708]123  this->shiftCoor(v);
124
[6056]125  if (this->tickLifeCycle(dt))
126    this->deactivate();
[3708]127}
128
129/**
[4836]130 *  the function gets called, when the projectile is destroyed
[3708]131*/
[5456]132void Laser::destroy ()
[5257]133{
[5456]134  PRINTF(5)("DESTROY Laser\n");
[5448]135  this->lifeCycle = .95; //!< @todo calculate this usefully.
[6619]136
137  this->emitter->setSystem(Laser::explosionParticles);
[5257]138}
139
140
[5500]141void Laser::draw () const
[3708]142{
143  glMatrixMode(GL_MODELVIEW);
144  glPushMatrix();
[5457]145  glPushAttrib(GL_ENABLE_BIT);
146  glDisable(GL_LIGHTING);
[3708]147
[4593]148  float matrix[4][4];
[3708]149  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
150  this->getAbsDir().matrix (matrix);
[4593]151  glMultMatrixf((float*)matrix);
[3755]152  glScalef(2.0, 2.0, 2.0);
[5994]153  this->getModel()->draw();
[5457]154  glPopAttrib();
[3708]155  glPopMatrix();
156}
157
Note: See TracBrowser for help on using the repository browser.