Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5466 was 5465, checked in by bensch, 19 years ago

orxonox/trunk: vegetation rendering in the terrain (trees are now rendered correctly)

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