Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/projectiles/boomerang_projectile.cc @ 9869

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 6.5 KB
RevLine 
[9217]1
[4593]2/*
[3708]3   orxonox - the future of 3D-vertical-scrollers
4
5   Copyright (C) 2004 orx
6
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2, or (at your option)
10   any later version.
11
12   ### File Specific
[5759]13   main-programmer: Silvan Nellen
14   co-programmer:
[5443]15
[3708]16*/
[5357]17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
[3708]18
[9217]19#include "boomerang_projectile.h"
[3708]20
[5443]21#include "state.h"
[5054]22
[9869]23#include "particles/dot_emitter.h"
24#include "particles/sprite_particles.h"
[5443]25
[8362]26#include "debug.h"
[3708]27
[9869]28#include "class_id_DEPRECATED.h"
29ObjectListDefinitionID(BoomerangProjectile, CL_BOOMERANG_PROJECTILE);
30CREATE_FAST_FACTORY_STATIC(BoomerangProjectile);
[3708]31
32/**
[4836]33 *  standard constructor
[3708]34*/
[9217]35BoomerangProjectile::BoomerangProjectile () : Projectile()
[3755]36{
[9869]37  this->registerObject(this, BoomerangProjectile::_objectList);
[4597]38
[9181]39  this->loadModel("models/projectiles/orx-rocket.obj", 2.0);
[7086]40  this->loadExplosionSound("sound/explosions/explosion_4.wav");
[4948]41
[7086]42
[6431]43  this->setMinEnergy(1);
[6700]44  this->setHealthMax(10);
[9223]45  this->lifeSpan = 2.0;
[7102]46  this->agility = 3.5;
[9223]47  this->maxVelocity = 150;
[5443]48
[6825]49  this->emitter = new DotEmitter(100, 5, M_2_PI);
[5443]50  this->emitter->setParent(this);
[5449]51  this->emitter->setSpread(M_PI, M_PI);
[3755]52}
[3708]53
54
55/**
[4836]56 *  standard deconstructor
[3708]57*/
[9217]58BoomerangProjectile::~BoomerangProjectile ()
[3708]59{
[5446]60  // delete this->emitter;
[5444]61
[5445]62  /* this is normaly done by World.cc by deleting the ParticleEngine */
[9869]63  if (BoomerangProjectile::trailParticles != NULL && BoomerangProjectile::objectList().size() <= 1)
[5447]64  {
[9869]65    if (ParticleSystem::objectList().exists(BoomerangProjectile::trailParticles))
[9217]66      delete BoomerangProjectile::trailParticles;
67    BoomerangProjectile::trailParticles = NULL;
[5447]68  }
[9869]69  if (BoomerangProjectile::explosionParticles != NULL && BoomerangProjectile::objectList().size() <= 1)
[5444]70  {
[9869]71    if (ParticleSystem::objectList().exists(BoomerangProjectile::explosionParticles))
[9217]72      delete BoomerangProjectile::explosionParticles;
73    BoomerangProjectile::explosionParticles = NULL;
[5444]74  }
[5445]75
[3708]76}
77
[9217]78SpriteParticles* BoomerangProjectile::trailParticles = NULL;
79SpriteParticles* BoomerangProjectile::explosionParticles = NULL;
[5443]80
[5760]81
82
[9217]83void BoomerangProjectile::activate()
[5443]84{
[9217]85  if (unlikely(BoomerangProjectile::trailParticles == NULL))
[5447]86  {
[9217]87    BoomerangProjectile::trailParticles = new SpriteParticles(2000);
88    BoomerangProjectile::trailParticles->setName("BoomerangProjectileTrailParticles");
89    BoomerangProjectile::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
90    BoomerangProjectile::trailParticles->setLifeSpan(1.0, .3);
91    BoomerangProjectile::trailParticles->setRadius(0.0, .5);
92    BoomerangProjectile::trailParticles->setRadius(0.2, 4.0);
93    BoomerangProjectile::trailParticles->setRadius(.5, 1.5);
94    BoomerangProjectile::trailParticles->setRadius(1.0, 1.5);
95    BoomerangProjectile::trailParticles->setColor(0.0, 1,0,0,.7);
96    BoomerangProjectile::trailParticles->setColor(0.2, .8,.8,0,.5);
97    BoomerangProjectile::trailParticles->setColor(0.5, .8,.8,.8,.8);
98    BoomerangProjectile::trailParticles->setColor(1.0, .8,.8,.8,.0);
[5447]99  }
[9217]100  if (unlikely(BoomerangProjectile::explosionParticles == NULL))
[5443]101  {
[9217]102    BoomerangProjectile::explosionParticles = new SpriteParticles(200);
103    BoomerangProjectile::explosionParticles->setName("BoomerangProjectileExplosionParticles");
104    BoomerangProjectile::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
105    BoomerangProjectile::explosionParticles->setLifeSpan(.5, .3);
106    BoomerangProjectile::explosionParticles->setRadius(0.0, 10);
107    BoomerangProjectile::explosionParticles->setRadius(.5, 15.0);
108    BoomerangProjectile::explosionParticles->setRadius(1.0, 10.0);
109    BoomerangProjectile::explosionParticles->setColor(0.0, 0,1,0,1);
110    BoomerangProjectile::explosionParticles->setColor(0.5, .8,.8,0,.8);
111    BoomerangProjectile::explosionParticles->setColor(0.8, .8,.8,.3,.8);
112    BoomerangProjectile::explosionParticles->setColor(1.0, 1,1,1,.0);
[5443]113  }
114
[9217]115  this->emitter->setSystem(BoomerangProjectile::trailParticles);
[5447]116
[5772]117  this->updateNode(0);
[5472]118  this->emitter->setEmissionRate(45.0);
[5471]119  this->emitter->setEmissionVelocity(0.0);
[7072]120
121  this->setHealth(10.0* (float)rand()/(float)RAND_MAX);
[5443]122}
123
124
[9217]125void BoomerangProjectile::deactivate()
[5443]126{
[6619]127  this->emitter->setSystem(NULL);
[5447]128  this->lifeCycle = 0.0;
[5443]129
[6142]130  this->toList(OM_DEAD);
[6056]131  this->removeNode();
[9217]132  BoomerangProjectile::fastFactory->kill(this);
[5443]133}
134
135
[9217]136void BoomerangProjectile::collidesWith(WorldEntity* entity, const Vector& location)
[5257]137{
[6433]138  if (this->hitEntity != entity)
[9162]139    this->destroy( entity );
[5447]140  this->hitEntity = entity;
[5257]141}
[3708]142
143/**
[4836]144 *  signal tick, time dependent things will be handled here
145 * @param time since last tick
[3708]146*/
[9217]147void BoomerangProjectile::tick (float time)
[3708]148{
[6162]149
[9217]150  Vector targetFarFarAway = this->getAbsCoor() + Vector(100000, 0, 0);
[6431]151
[9217]152  {
[6162]153    speed = velocity.len();
[9217]154    diffVector = ((targetFarFarAway - this->getAbsCoor()).getNormalized());
[5765]155
[6162]156    if(velocity.dot(diffVector) != 0)
[9217]157    {
158      correctionVector = (( ( diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )) - velocity).getNormalized()) * agility;
[6162]159
[6426]160      if( (diffVector *  (speed * speed/( velocity.dot(diffVector ) ) ) -velocity).len() < agility )
[9217]161        velocity = ((diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )).getNormalized())*agility;
[6426]162      else if(velocity.dot(diffVector) > 0)
[6162]163        velocity += correctionVector;
164      else if (velocity.dot(diffVector) < 0)
165        velocity -= correctionVector;
[9217]166    }
[6162]167    else
168      velocity += diffVector * agility;
169
[9217]170    this->setAbsDir(Quaternion(velocity, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)));
171  }
[6162]172
173  velocity *= maxVelocity/velocity.len();
[4464]174  Vector v = this->velocity * (time);
[3708]175  this->shiftCoor(v);
176
[6056]177  if(this->tickLifeCycle(time))
178    this->deactivate();
[3708]179}
180
181/**
[4836]182 *  the function gets called, when the projectile is destroyed
[5765]183 */
[9217]184void BoomerangProjectile::destroy (WorldEntity* killer)
[5257]185{
[9206]186
187  printf("THIS SHOULD WORLk\n");
188
[9162]189  Projectile::destroy( killer );
[9217]190  PRINTF(5)("DESTROY BoomerangProjectile\n");
[5448]191  this->lifeCycle = .95; //!< @todo calculate this usefully.
[9217]192  this->emitter->setSystem(BoomerangProjectile::explosionParticles);
[3708]193
[5465]194  this->emitter->setEmissionRate(1000.0);
[5447]195  this->emitter->setEmissionVelocity(50.0);
[9217]196  //  this->deactivate();
[3708]197
[5257]198}
199
200
[9217]201void BoomerangProjectile::draw () const
[3708]202{
203  glMatrixMode(GL_MODELVIEW);
204  glPushMatrix();
205
[4593]206  float matrix[4][4];
[3708]207  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
208  this->getAbsDir().matrix (matrix);
[4593]209  glMultMatrixf((float*)matrix);
[3755]210  glScalef(2.0, 2.0, 2.0);
[5994]211  this->getModel()->draw();
[3708]212
213  glPopMatrix();
[5765]214
[3708]215}
216
Note: See TracBrowser for help on using the repository browser.