Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10230 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

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