Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/rocket.cc @ 6602

Last change on this file since 6602 was 6434, checked in by bensch, 19 years ago

orxonox/trunk: moved the projectiles to Projectiles

File size: 5.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 "rocket.h"
[3708]19
[4947]20#include "fast_factory.h"
[3708]21
[5443]22#include "state.h"
[5444]23#include "class_list.h"
[5054]24
[5443]25#include "particle_engine.h"
26#include "particle_emitter.h"
27#include "particle_system.h"
28
29
[3708]30using namespace std;
31
[5456]32CREATE_FAST_FACTORY_STATIC(Rocket, CL_ROCKET);
[3708]33
34/**
[4836]35 *  standard constructor
[3708]36*/
[5456]37Rocket::Rocket () : Projectile()
[3755]38{
[5456]39  this->setClassID(CL_TEST_BULLET, "Rocket");
[4597]40
[4948]41  float modelSize = .3;
[5499]42  this->loadModel("models/projectiles/orx-rocket.obj", .3);
[4948]43
[6431]44  this->setMinEnergy(1);
45  this->setMaxEnergy(10);
[5819]46  this->lifeSpan = 5;
[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);
[3755]51}
[3708]52
53
54/**
[4836]55 *  standard deconstructor
[3708]56*/
[5456]57Rocket::~Rocket ()
[3708]58{
[5446]59  // delete this->emitter;
[5444]60
[5445]61  /* this is normaly done by World.cc by deleting the ParticleEngine */
[5779]62  if (Rocket::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
[5447]63  {
[5456]64    if (ClassList::exists(Rocket::trailParticles, CL_PARTICLE_SYSTEM))
65      delete Rocket::trailParticles;
66    Rocket::trailParticles = NULL;
[5447]67  }
[5779]68  if (Rocket::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
[5444]69  {
[5456]70    if (ClassList::exists(Rocket::explosionParticles, CL_PARTICLE_SYSTEM))
71      delete Rocket::explosionParticles;
72    Rocket::explosionParticles = NULL;
[5444]73  }
[5445]74
[3708]75}
76
[5456]77ParticleSystem* Rocket::trailParticles = NULL;
78ParticleSystem* Rocket::explosionParticles = NULL;
[5443]79
[5456]80void Rocket::activate()
[5443]81{
[5456]82  if (unlikely(Rocket::trailParticles == NULL))
[5447]83  {
[5471]84    Rocket::trailParticles = new ParticleSystem(2000, PARTICLE_SPRITE);
[5456]85    Rocket::trailParticles->setName("RocketTrailParticles");
[5471]86    Rocket::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
87    Rocket::trailParticles->setLifeSpan(1.0, .3);
[5456]88    Rocket::trailParticles->setRadius(0.0, .5);
[5472]89    Rocket::trailParticles->setRadius(0.2, 2.0);
90    Rocket::trailParticles->setRadius(.5, .8);
[5471]91    Rocket::trailParticles->setRadius(1.0, .8);
[5456]92    Rocket::trailParticles->setColor(0.0, 1,0,0,.7);
[5472]93    Rocket::trailParticles->setColor(0.2, .8,.8,0,.5);
94    Rocket::trailParticles->setColor(0.5, .8,.8,.8,.8);
[5471]95    Rocket::trailParticles->setColor(1.0, .8,.8,.8,.0);
[5447]96  }
[5456]97  if (unlikely(Rocket::explosionParticles == NULL))
[5443]98  {
[5465]99    Rocket::explosionParticles = new ParticleSystem(200, PARTICLE_SPRITE);
[5456]100    Rocket::explosionParticles->setName("RocketExplosionParticles");
[5471]101    Rocket::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
[5693]102    Rocket::explosionParticles->setLifeSpan(.5, .3);
[5456]103    Rocket::explosionParticles->setRadius(0.0, 10);
[5693]104    Rocket::explosionParticles->setRadius(.5, 15.0);
105    Rocket::explosionParticles->setRadius(1.0, 10.0);
[5465]106    Rocket::explosionParticles->setColor(0.0, 0,1,0,1);
107    Rocket::explosionParticles->setColor(0.5, .8,.8,0,.8);
108    Rocket::explosionParticles->setColor(0.8, .8,.8,.3,.8);
[5456]109    Rocket::explosionParticles->setColor(1.0, 1,1,1,.0);
[5443]110  }
111
[5456]112  ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::trailParticles);
[5447]113
[5769]114  this->updateNode(0);
[5472]115  this->emitter->setEmissionRate(45.0);
[5471]116  this->emitter->setEmissionVelocity(0.0);
[5443]117}
118
119
[5456]120void Rocket::deactivate()
[5443]121{
[5447]122  ParticleEngine::getInstance()->breakConnections(this->emitter);
123  this->lifeCycle = 0.0;
[6142]124  this->toList(OM_NULL);
[5443]125
[5447]126//  GarbageCollector::getInstance()->collect(this);
[6142]127  this->toList(OM_DEAD);
[5456]128  Rocket::fastFactory->kill(this);
[5443]129}
130
131
[5456]132void Rocket::collidesWith(WorldEntity* entity, const Vector& location)
[5257]133{
[6433]134  if (this->hitEntity != entity)
[5447]135    this->destroy();
136  this->hitEntity = entity;
[5257]137}
[3708]138
139/**
[4836]140 *  signal tick, time dependent things will be handled here
141 * @param time since last tick
[3708]142*/
[6056]143void Rocket::tick (float dt)
[3708]144{
[4464]145  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
[6056]146  Vector v = this->velocity * (dt);
[3708]147  this->shiftCoor(v);
148
[6056]149  if(this->tickLifeCycle(dt))
150    this->deactivate();
[3708]151}
152
153/**
[4836]154 *  the function gets called, when the projectile is destroyed
[3708]155*/
[5456]156void Rocket::destroy ()
[5257]157{
[5456]158  PRINTF(5)("DESTROY Rocket\n");
[5448]159  this->lifeCycle = .95; //!< @todo calculate this usefully.
[5456]160  ParticleEngine::getInstance()->breakConnection(this->emitter, Rocket::trailParticles);
161  ParticleEngine::getInstance()->addConnection(this->emitter, Rocket::explosionParticles);
[3708]162
[5465]163  this->emitter->setEmissionRate(1000.0);
[5447]164  this->emitter->setEmissionVelocity(50.0);
165//  this->deactivate();
[3708]166
[5257]167}
168
169
[5500]170void Rocket::draw () const
[3708]171{
172  glMatrixMode(GL_MODELVIEW);
173  glPushMatrix();
174
[4593]175  float matrix[4][4];
[3708]176  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
177  this->getAbsDir().matrix (matrix);
[4593]178  glMultMatrixf((float*)matrix);
[3755]179  glScalef(2.0, 2.0, 2.0);
[5994]180  this->getModel()->draw();
[3708]181
182  glPopMatrix();
183}
184
Note: See TracBrowser for help on using the repository browser.