Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/guided_missile.cc @ 6619

Last change on this file since 6619 was 6619, checked in by bensch, 18 years ago

orxonox/trunk: rendering without the ParticleEngine, so now we are FAST :)

File size: 6.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
[5759]12   main-programmer: Silvan Nellen
13   co-programmer:
[5443]14
[3708]15*/
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3708]17
[5759]18#include "guided_missile.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"
26#include "particle_system.h"
27
[3708]28using namespace std;
29
[5759]30CREATE_FAST_FACTORY_STATIC(GuidedMissile, CL_GUIDED_MISSILE);
[3708]31
32/**
[4836]33 *  standard constructor
[3708]34*/
[5759]35GuidedMissile::GuidedMissile () : Projectile()
[3755]36{
[5759]37  this->setClassID(CL_GUIDED_MISSILE, "GuidedMissile");
[4597]38
[4948]39  float modelSize = .3;
[5764]40  this->loadModel("models/projectiles/orx-rocket.obj", .3);
[4948]41
[6431]42  this->setMinEnergy(1);
43  this->setMaxEnergy(10);
[6162]44  this->lifeSpan = 10.0;
[6426]45  this->agility = 500;
[6162]46  this->maxVelocity = 75;
[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*/
[5759]57GuidedMissile::~GuidedMissile ()
[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 (GuidedMissile::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
[5447]63  {
[5759]64    if (ClassList::exists(GuidedMissile::trailParticles, CL_PARTICLE_SYSTEM))
65      delete GuidedMissile::trailParticles;
66    GuidedMissile::trailParticles = NULL;
[5447]67  }
[5779]68  if (GuidedMissile::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
[5444]69  {
[5759]70    if (ClassList::exists(GuidedMissile::explosionParticles, CL_PARTICLE_SYSTEM))
71      delete GuidedMissile::explosionParticles;
72    GuidedMissile::explosionParticles = NULL;
[5444]73  }
[5445]74
[3708]75}
76
[5759]77ParticleSystem* GuidedMissile::trailParticles = NULL;
78ParticleSystem* GuidedMissile::explosionParticles = NULL;
[5443]79
[5760]80
81
[5759]82void GuidedMissile::activate()
[5443]83{
[5759]84  if (unlikely(GuidedMissile::trailParticles == NULL))
[5447]85  {
[5759]86    GuidedMissile::trailParticles = new ParticleSystem(2000, PARTICLE_SPRITE);
87    GuidedMissile::trailParticles->setName("GuidedMissileTrailParticles");
88    GuidedMissile::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
89    GuidedMissile::trailParticles->setLifeSpan(1.0, .3);
90    GuidedMissile::trailParticles->setRadius(0.0, .5);
91    GuidedMissile::trailParticles->setRadius(0.2, 2.0);
92    GuidedMissile::trailParticles->setRadius(.5, .8);
93    GuidedMissile::trailParticles->setRadius(1.0, .8);
94    GuidedMissile::trailParticles->setColor(0.0, 1,0,0,.7);
95    GuidedMissile::trailParticles->setColor(0.2, .8,.8,0,.5);
96    GuidedMissile::trailParticles->setColor(0.5, .8,.8,.8,.8);
97    GuidedMissile::trailParticles->setColor(1.0, .8,.8,.8,.0);
[5447]98  }
[5759]99  if (unlikely(GuidedMissile::explosionParticles == NULL))
[5443]100  {
[5759]101    GuidedMissile::explosionParticles = new ParticleSystem(200, PARTICLE_SPRITE);
102    GuidedMissile::explosionParticles->setName("GuidedMissileExplosionParticles");
103    GuidedMissile::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
104    GuidedMissile::explosionParticles->setLifeSpan(.5, .3);
105    GuidedMissile::explosionParticles->setRadius(0.0, 10);
106    GuidedMissile::explosionParticles->setRadius(.5, 15.0);
107    GuidedMissile::explosionParticles->setRadius(1.0, 10.0);
108    GuidedMissile::explosionParticles->setColor(0.0, 0,1,0,1);
109    GuidedMissile::explosionParticles->setColor(0.5, .8,.8,0,.8);
110    GuidedMissile::explosionParticles->setColor(0.8, .8,.8,.3,.8);
111    GuidedMissile::explosionParticles->setColor(1.0, 1,1,1,.0);
[5443]112  }
113
[6619]114  this->emitter->setSystem(GuidedMissile::trailParticles);
[5447]115
[5772]116  this->updateNode(0);
[5472]117  this->emitter->setEmissionRate(45.0);
[5471]118  this->emitter->setEmissionVelocity(0.0);
[5443]119}
120
121
[5759]122void GuidedMissile::deactivate()
[5443]123{
[6619]124  this->emitter->setSystem(NULL);
[5447]125  this->lifeCycle = 0.0;
[5443]126
[6142]127  this->toList(OM_DEAD);
[6056]128  this->removeNode();
[5759]129  GuidedMissile::fastFactory->kill(this);
[5443]130}
131
132
[5759]133void GuidedMissile::collidesWith(WorldEntity* entity, const Vector& location)
[5257]134{
[6433]135  if (this->hitEntity != entity)
[5447]136    this->destroy();
137  this->hitEntity = entity;
[5257]138}
[3708]139
140/**
[4836]141 *  signal tick, time dependent things will be handled here
142 * @param time since last tick
[3708]143*/
[5759]144void GuidedMissile::tick (float time)
[3708]145{
[6162]146
[6431]147
[6241]148if (this->target != NULL && this->target->getParent() != PNode::getNullParent())
[5764]149   {
[6162]150    speed = velocity.len();
151    diffVector = ((target->getAbsCoor() - this->getAbsCoor()).getNormalized());
[5765]152
[6162]153    if(velocity.dot(diffVector) != 0)
[6241]154     {
[6162]155     correctionVector = (( ( diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )) - velocity).getNormalized()) * agility;
156
[6426]157      if( (diffVector *  (speed * speed/( velocity.dot(diffVector ) ) ) -velocity).len() < agility )
158       velocity = ((diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )).getNormalized())*agility;
159      else if(velocity.dot(diffVector) > 0)
[6162]160        velocity += correctionVector;
161      else if (velocity.dot(diffVector) < 0)
162        velocity -= correctionVector;
[6241]163     }
[6162]164    else
165      velocity += diffVector * agility;
166
[5765]167     this->setAbsDir(Quaternion(velocity, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)));
[5764]168   }
[6162]169
170  velocity *= maxVelocity/velocity.len();
[4464]171  Vector v = this->velocity * (time);
[3708]172  this->shiftCoor(v);
173
[6056]174  if(this->tickLifeCycle(time))
175    this->deactivate();
[3708]176}
177
178/**
[4836]179 *  the function gets called, when the projectile is destroyed
[5765]180 */
[5759]181void GuidedMissile::destroy ()
[5257]182{
[5759]183  PRINTF(5)("DESTROY GuidedMissile\n");
[5448]184  this->lifeCycle = .95; //!< @todo calculate this usefully.
[6619]185  this->emitter->setSystem(GuidedMissile::explosionParticles);
[3708]186
[5465]187  this->emitter->setEmissionRate(1000.0);
[5447]188  this->emitter->setEmissionVelocity(50.0);
189//  this->deactivate();
[3708]190
[5257]191}
192
193
[5759]194void GuidedMissile::draw () const
[3708]195{
196  glMatrixMode(GL_MODELVIEW);
197  glPushMatrix();
198
[4593]199  float matrix[4][4];
[3708]200  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
201  this->getAbsDir().matrix (matrix);
[4593]202  glMultMatrixf((float*)matrix);
[3755]203  glScalef(2.0, 2.0, 2.0);
[5994]204  this->getModel()->draw();
[3708]205
206  glPopMatrix();
[5765]207
[3708]208}
209
Note: See TracBrowser for help on using the repository browser.