Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6683 was 6628, checked in by bensch, 19 years ago

trunk: segfault-prevention, and minor cleanup

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