Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.old/src/world_entities/projectiles/boomerang_projectile.cc @ 10517

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

merged the presentation back

File size: 6.5 KB
Line 
1
2/*
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
13   main-programmer: Silvan Nellen
14   co-programmer:
15
16*/
17#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
18
19#include "boomerang_projectile.h"
20
21#include "state.h"
22#include "class_list.h"
23
24#include "dot_emitter.h"
25#include "sprite_particles.h"
26
27#include "debug.h"
28
29CREATE_FAST_FACTORY_STATIC(BoomerangProjectile, CL_BOOMERANG_PROJECTILE);
30
31/**
32 *  standard constructor
33*/
34BoomerangProjectile::BoomerangProjectile () : Projectile()
35{
36  this->setClassID(CL_BOOMERANG_PROJECTILE, "BoomerangProjectile");
37
38  this->loadModel("models/projectiles/orx-rocket.obj", 2.0);
39  this->loadExplosionSound("sound/explosions/explosion_4.wav");
40
41
42  this->setMinEnergy(1);
43  this->setHealthMax(10);
44  this->lifeSpan = 2.0;
45  this->agility = 3.5;
46  this->maxVelocity = 150;
47
48  this->emitter = new DotEmitter(100, 5, M_2_PI);
49  this->emitter->setParent(this);
50  this->emitter->setSpread(M_PI, M_PI);
51}
52
53
54/**
55 *  standard deconstructor
56*/
57BoomerangProjectile::~BoomerangProjectile ()
58{
59  // delete this->emitter;
60
61  /* this is normaly done by World.cc by deleting the ParticleEngine */
62  if (BoomerangProjectile::trailParticles != NULL && ClassList::getList(CL_BOOMERANG_PROJECTILE)->size() <= 1)
63  {
64    if (ClassList::exists(BoomerangProjectile::trailParticles, CL_PARTICLE_SYSTEM))
65      delete BoomerangProjectile::trailParticles;
66    BoomerangProjectile::trailParticles = NULL;
67  }
68  if (BoomerangProjectile::explosionParticles != NULL && ClassList::getList(CL_BOOMERANG_PROJECTILE)->size() <= 1)
69  {
70    if (ClassList::exists(BoomerangProjectile::explosionParticles, CL_PARTICLE_SYSTEM))
71      delete BoomerangProjectile::explosionParticles;
72    BoomerangProjectile::explosionParticles = NULL;
73  }
74
75}
76
77SpriteParticles* BoomerangProjectile::trailParticles = NULL;
78SpriteParticles* BoomerangProjectile::explosionParticles = NULL;
79
80
81
82void BoomerangProjectile::activate()
83{
84  if (unlikely(BoomerangProjectile::trailParticles == NULL))
85  {
86    BoomerangProjectile::trailParticles = new SpriteParticles(2000);
87    BoomerangProjectile::trailParticles->setName("BoomerangProjectileTrailParticles");
88    BoomerangProjectile::trailParticles->setMaterialTexture("maps/radial-trans-noise.png");
89    BoomerangProjectile::trailParticles->setLifeSpan(1.0, .3);
90    BoomerangProjectile::trailParticles->setRadius(0.0, .5);
91    BoomerangProjectile::trailParticles->setRadius(0.2, 4.0);
92    BoomerangProjectile::trailParticles->setRadius(.5, 1.5);
93    BoomerangProjectile::trailParticles->setRadius(1.0, 1.5);
94    BoomerangProjectile::trailParticles->setColor(0.0, 1,0,0,.7);
95    BoomerangProjectile::trailParticles->setColor(0.2, .8,.8,0,.5);
96    BoomerangProjectile::trailParticles->setColor(0.5, .8,.8,.8,.8);
97    BoomerangProjectile::trailParticles->setColor(1.0, .8,.8,.8,.0);
98  }
99  if (unlikely(BoomerangProjectile::explosionParticles == NULL))
100  {
101    BoomerangProjectile::explosionParticles = new SpriteParticles(200);
102    BoomerangProjectile::explosionParticles->setName("BoomerangProjectileExplosionParticles");
103    BoomerangProjectile::explosionParticles->setMaterialTexture("maps/radial-trans-noise.png");
104    BoomerangProjectile::explosionParticles->setLifeSpan(.5, .3);
105    BoomerangProjectile::explosionParticles->setRadius(0.0, 10);
106    BoomerangProjectile::explosionParticles->setRadius(.5, 15.0);
107    BoomerangProjectile::explosionParticles->setRadius(1.0, 10.0);
108    BoomerangProjectile::explosionParticles->setColor(0.0, 0,1,0,1);
109    BoomerangProjectile::explosionParticles->setColor(0.5, .8,.8,0,.8);
110    BoomerangProjectile::explosionParticles->setColor(0.8, .8,.8,.3,.8);
111    BoomerangProjectile::explosionParticles->setColor(1.0, 1,1,1,.0);
112  }
113
114  this->emitter->setSystem(BoomerangProjectile::trailParticles);
115
116  this->updateNode(0);
117  this->emitter->setEmissionRate(45.0);
118  this->emitter->setEmissionVelocity(0.0);
119
120  this->setHealth(10.0* (float)rand()/(float)RAND_MAX);
121}
122
123
124void BoomerangProjectile::deactivate()
125{
126  this->emitter->setSystem(NULL);
127  this->lifeCycle = 0.0;
128
129  this->toList(OM_DEAD);
130  this->removeNode();
131  BoomerangProjectile::fastFactory->kill(this);
132}
133
134
135void BoomerangProjectile::collidesWith(WorldEntity* entity, const Vector& location)
136{
137  if (this->hitEntity != entity)
138    this->destroy( entity );
139  this->hitEntity = entity;
140}
141
142/**
143 *  signal tick, time dependent things will be handled here
144 * @param time since last tick
145*/
146void BoomerangProjectile::tick (float time)
147{
148
149  Vector targetFarFarAway = this->getAbsCoor() + Vector(100000, 0, 0);
150
151  {
152    speed = velocity.len();
153    diffVector = ((targetFarFarAway - this->getAbsCoor()).getNormalized());
154
155    if(velocity.dot(diffVector) != 0)
156    {
157      correctionVector = (( ( diffVector *  (speed * speed/( velocity.dot(diffVector ) ) )) - velocity).getNormalized()) * agility;
158
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)
162        velocity += correctionVector;
163      else if (velocity.dot(diffVector) < 0)
164        velocity -= correctionVector;
165    }
166    else
167      velocity += diffVector * agility;
168
169    this->setAbsDir(Quaternion(velocity, Vector(0,1,0)) * Quaternion ( -M_PI_2, Vector(0,1,0)));
170  }
171
172  velocity *= maxVelocity/velocity.len();
173  Vector v = this->velocity * (time);
174  this->shiftCoor(v);
175
176  if(this->tickLifeCycle(time))
177    this->deactivate();
178}
179
180/**
181 *  the function gets called, when the projectile is destroyed
182 */
183void BoomerangProjectile::destroy (WorldEntity* killer)
184{
185
186  printf("THIS SHOULD WORLk\n");
187
188  Projectile::destroy( killer );
189  PRINTF(5)("DESTROY BoomerangProjectile\n");
190  this->lifeCycle = .95; //!< @todo calculate this usefully.
191  this->emitter->setSystem(BoomerangProjectile::explosionParticles);
192
193  this->emitter->setEmissionRate(1000.0);
194  this->emitter->setEmissionVelocity(50.0);
195  //  this->deactivate();
196
197}
198
199
200void BoomerangProjectile::draw () const
201{
202  glMatrixMode(GL_MODELVIEW);
203  glPushMatrix();
204
205  float matrix[4][4];
206  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
207  this->getAbsDir().matrix (matrix);
208  glMultMatrixf((float*)matrix);
209  glScalef(2.0, 2.0, 2.0);
210  this->getModel()->draw();
211
212  glPopMatrix();
213
214}
215
Note: See TracBrowser for help on using the repository browser.