Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/rocket.cc @ 5554

Last change on this file since 5554 was 5511, checked in by bensch, 19 years ago

orxonox/trunk: more cleanup of the WorldEntity (includes rearanged)

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