Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file was 10415, checked in by patrick, 18 years ago

changed the path names to reflect the new data repos

File size: 6.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
[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
[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"
[3708]26
[10114]27
28ObjectListDefinition(GuidedMissile);
[9869]29CREATE_FAST_FACTORY_STATIC(GuidedMissile);
[3708]30
31/**
[4836]32 *  standard constructor
[3708]33*/
[5759]34GuidedMissile::GuidedMissile () : Projectile()
[3755]35{
[9869]36  this->registerObject(this, GuidedMissile::_objectList);
[4597]37
[9235]38  this->loadModel("models/projectiles/orx-rocket.obj", 2.0);
[10415]39  this->loadExplosionSound("sounds/explosions/explosion_4.wav");
[4948]40
[7086]41
[6431]42  this->setMinEnergy(1);
[6700]43  this->setHealthMax(10);
[7081]44  this->lifeSpan = 4.0;
[7102]45  this->agility = 3.5;
[9298]46  this->maxVelocity = 100;
[5443]47
[6825]48  this->emitter = new DotEmitter(100, 5, M_2_PI);
[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 */
[9869]62  if (GuidedMissile::trailParticles != NULL && GuidedMissile::objectList().size() <= 1)
[5447]63  {
[9869]64    if (ParticleSystem::objectList().exists(GuidedMissile::trailParticles))
[5759]65      delete GuidedMissile::trailParticles;
66    GuidedMissile::trailParticles = NULL;
[5447]67  }
[9869]68  if (GuidedMissile::explosionParticles != NULL && GuidedMissile::objectList().size() <= 1)
[5444]69  {
[9869]70    if (ParticleSystem::objectList().exists(GuidedMissile::explosionParticles))
[5759]71      delete GuidedMissile::explosionParticles;
72    GuidedMissile::explosionParticles = NULL;
[5444]73  }
[5445]74
[3708]75}
76
[6622]77SpriteParticles* GuidedMissile::trailParticles = NULL;
78SpriteParticles* GuidedMissile::explosionParticles = NULL;
[5443]79
[5760]80
81
[5759]82void GuidedMissile::activate()
[5443]83{
[5759]84  if (unlikely(GuidedMissile::trailParticles == NULL))
[5447]85  {
[6621]86    GuidedMissile::trailParticles = new SpriteParticles(2000);
[5759]87    GuidedMissile::trailParticles->setName("GuidedMissileTrailParticles");
[10317]88    GuidedMissile::trailParticles->setMaterialTexture("textures/radial-trans-noise.png");
[5759]89    GuidedMissile::trailParticles->setLifeSpan(1.0, .3);
90    GuidedMissile::trailParticles->setRadius(0.0, .5);
[9235]91    GuidedMissile::trailParticles->setRadius(0.2, 4.0);
92    GuidedMissile::trailParticles->setRadius(.5, 1.5);
93    GuidedMissile::trailParticles->setRadius(1.0, 1.5);
[5759]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  {
[6621]101    GuidedMissile::explosionParticles = new SpriteParticles(200);
[5759]102    GuidedMissile::explosionParticles->setName("GuidedMissileExplosionParticles");
[10317]103    GuidedMissile::explosionParticles->setMaterialTexture("textures/radial-trans-noise.png");
[5759]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);
[7072]119
120  this->setHealth(10.0* (float)rand()/(float)RAND_MAX);
[5443]121}
122
123
[5759]124void GuidedMissile::deactivate()
[5443]125{
[6619]126  this->emitter->setSystem(NULL);
[5447]127  this->lifeCycle = 0.0;
[5443]128
[6142]129  this->toList(OM_DEAD);
[6056]130  this->removeNode();
[5759]131  GuidedMissile::fastFactory->kill(this);
[5443]132}
133
134
[5759]135void GuidedMissile::collidesWith(WorldEntity* entity, const Vector& location)
[5257]136{
[6433]137  if (this->hitEntity != entity)
[9235]138    this->destroy( entity );
[5447]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*/
[5759]146void GuidedMissile::tick (float time)
[3708]147{
[6162]148
[6431]149
[6241]150if (this->target != NULL && this->target->getParent() != PNode::getNullParent())
[5764]151   {
[6162]152    speed = velocity.len();
153    diffVector = ((target->getAbsCoor() - this->getAbsCoor()).getNormalized());
[5765]154
[6162]155    if(velocity.dot(diffVector) != 0)
[6241]156     {
[6162]157     correctionVector = (( ( diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )) - velocity).getNormalized()) * agility;
158
[6426]159      if( (diffVector *  (speed * speed/( velocity.dot(diffVector ) ) ) -velocity).len() < agility )
160       velocity = ((diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )).getNormalized())*agility;
161      else if(velocity.dot(diffVector) > 0)
[6162]162        velocity += correctionVector;
163      else if (velocity.dot(diffVector) < 0)
164        velocity -= correctionVector;
[6241]165     }
[6162]166    else
167      velocity += diffVector * agility;
168
[5765]169     this->setAbsDir(Quaternion(velocity, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)));
[5764]170   }
[6162]171
172  velocity *= maxVelocity/velocity.len();
[4464]173  Vector v = this->velocity * (time);
[3708]174  this->shiftCoor(v);
175
[6056]176  if(this->tickLifeCycle(time))
177    this->deactivate();
[3708]178}
179
180/**
[4836]181 *  the function gets called, when the projectile is destroyed
[5765]182 */
[9235]183void GuidedMissile::destroy (WorldEntity* killer)
[5257]184{
[9235]185
186  printf("THIS SHOULD WORLk\n");
187
188  Projectile::destroy( killer );
[5759]189  PRINTF(5)("DESTROY GuidedMissile\n");
[5448]190  this->lifeCycle = .95; //!< @todo calculate this usefully.
[6619]191  this->emitter->setSystem(GuidedMissile::explosionParticles);
[3708]192
[5465]193  this->emitter->setEmissionRate(1000.0);
[5447]194  this->emitter->setEmissionVelocity(50.0);
195//  this->deactivate();
[3708]196
[5257]197}
198
199
[5759]200void GuidedMissile::draw () const
[3708]201{
202  glMatrixMode(GL_MODELVIEW);
203  glPushMatrix();
204
[4593]205  float matrix[4][4];
[3708]206  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
207  this->getAbsDir().matrix (matrix);
[4593]208  glMultMatrixf((float*)matrix);
[3755]209  glScalef(2.0, 2.0, 2.0);
[5994]210  this->getModel()->draw();
[3708]211
212  glPopMatrix();
[5765]213
[3708]214}
215
Note: See TracBrowser for help on using the repository browser.