Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/spike_ball.cc @ 10252

Last change on this file since 10252 was 10252, checked in by nicolasc, 17 years ago

bump

File size: 7.8 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004-2006 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: Nicolas Schlumberger, Marc Schaerrer
13   co-programmer: Benjamin Grauer
14
15*/
16
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "spike_ball.h"
21
22#include "state.h"
23#include "model.h"
24
25#include "particles/dot_emitter.h"
26#include "particles/sprite_particles.h"
27
28#include <cassert>
29#include "debug.h"
30
31#include "space_ships/space_ship.h"
32
33
34#include "class_id_DEPRECATED.h"
35ObjectListDefinition(SpikeBall);
36CREATE_FAST_FACTORY_STATIC(SpikeBall);
37
38/**
39 *  standard constructor
40*/
41SpikeBall::SpikeBall () : ProjectileWeapon()
42{
43  this->registerObject(this, SpikeBall::_objectList);
44
45  this->loadModel("models/projectiles/spike_ball.obj", .25);
46
47  this->setMinEnergy(1);
48  this->setHealthMax(1);
49  this->lifeSpan = 1.0;
50
51  this->emitter = new DotEmitter(100, 5, M_2_PI);
52  this->emitter->setParent(this);
53  this->emitter->setSpread(M_PI, M_PI);
54  this->emitter->setEmissionRate(300.0);
55  this->emitter->setEmissionVelocity(50.0);
56
57  this->speed = 150;
58
59  this->angle = 0;
60  this->rotationSpeed = 130;
61
62  this->halo = new Billboard();
63  this->halo->setSize(2, 2);
64  this->halo->setTexture("hbolt_halo.png");
65
66  this->setFragments(26);
67
68  this->size = 4;
69//   this->fastFactory = tFastFactory<Spike>::getFastFactory(CL_SPIKE, "Spike");
70
71/*
72  this->weaponMan = new WeaponManager(dynamic_cast<WorldEntity*>(this));
73  this->weaponMan->setParentEntity(this);
74  this->weaponMan->setSlotCount(1);
75  this->weaponMan->setSlotPosition(0, Vector(0, 0, 0));
76  this->weaponMan->setSlotCapability(0, WTYPE_ALLDIRS | WTYPE_DIRECTIONAL);
77
78  Weapon* cannon = new SpikeLauncher();
79  cannon->setName( "SpikeLauncher");
80  this->weaponMan->addWeapon(cannon, 0, 0);
81  this->weaponMan->changeWeaponConfig(0);
82
83  this->weaponMan->getWeapon(0)->increaseEnergy(50);*/
84}
85
86
87/**
88 *  standard deconstructor
89*/
90SpikeBall::~SpikeBall ()
91{
92  // delete this->emitter;
93
94  /* this is normaly done by World.cc by deleting the ParticleEngine */
95  if (SpikeBall::explosionParticles != NULL && SpikeBall::objectList().size() <= 1)
96  {
97    //if (ClassList::exists(SpikeBall::explosionParticles, CL_PARTICLE_SYSTEM))
98    //  delete SpikeBall::explosionParticles;
99    PRINTF(1)("Deleting SpikeBall Particles\n");
100    SpikeBall::explosionParticles = NULL;
101  }
102
103}
104
105SpriteParticles* SpikeBall::explosionParticles = NULL;
106
107void SpikeBall::activate()
108{
109  if (unlikely(SpikeBall::explosionParticles == NULL))
110  {
111    SpikeBall::explosionParticles = new SpriteParticles(1000);
112    SpikeBall::explosionParticles->setName("BoltExplosionParticles");
113    SpikeBall::explosionParticles->setLifeSpan(.5, .3);
114    SpikeBall::explosionParticles->setRadius(0.0, 10.0);
115    SpikeBall::explosionParticles->setRadius(.5, 6.0);
116    SpikeBall::explosionParticles->setRadius(1.0, 3.0);
117    SpikeBall::explosionParticles->setColor(0.0, 1,1,0,.9);
118    SpikeBall::explosionParticles->setColor(0.5, .8,.8,0,.5);
119    SpikeBall::explosionParticles->setColor(1.0, .8,.8,.7,.0);
120  }
121
122  this->setDamage(5);
123  this->setHealth(0);
124  this->setRotationAxis(VECTOR_RAND(1));
125  this->setAngle();
126
127  this->launcher[0] = Vector(1.0, 0.0, 0.0);
128  this->launcher[1] = Vector(0.0, 1.0, 0.0);
129  this->launcher[2] = Vector(0.0, 0.0, 1.0);
130
131  this->launcher[3] = Vector(1.0, 1.0, 0.0);
132  this->launcher[4] = Vector(0.0, 1.0, 1.0);
133  this->launcher[5] = Vector(1.0, 0.0, 1.0);
134  this->launcher[6] = Vector(1.0, -1.0, 0.0);
135  this->launcher[7] = Vector(0.0, 1.0, -1.0);
136  this->launcher[8] = Vector(-1.0, 0.0, 1.0);
137
138  this->launcher[9] = Vector(-1.0, 1.0, 1.0);
139  this->launcher[10] = Vector(1.0, 1.0, 1.0);
140  this->launcher[11] = Vector(1.0, -1.0, 1.0);
141  this->launcher[12] = Vector(-1.0, -1.0, 1.0);
142
143  int tmp = this->getFragments() / 2;
144  for (int i = 0; i < tmp; i++)
145  {
146    this->launcher[i].normalize();
147    this->launcher[tmp + i] =  this->launcher[i] * (-1);
148  }
149}
150
151
152void SpikeBall::deactivate()
153{
154  assert (SpikeBall::explosionParticles != NULL);
155  SpikeBall::explosionParticles->removeEmitter(this->emitter);
156  this->lifeCycle = 0.0;
157
158  this->toList(OM_NULL);
159  this->removeNode();
160  SpikeBall::fastFactory->kill(this);
161}
162
163
164void SpikeBall::collidesWith(WorldEntity* entity, const Vector& location)
165{
166  PRINTF(0)("Collision with SpikeBall\n");
167  if (this->hitEntity != entity && entity->isA(CL_NPC))
168    this->destroy( entity );
169  this->hitEntity = entity;
170  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
171//   this->deactivate();
172}
173
174
175void SpikeBall::blow()
176{
177  Spike* pj = NULL;
178
179  for ( int i = 0; i < this->getFragments(); i++)
180  {
181    pj  = new Spike();
182    if (pj == NULL)
183      return;
184
185    pj->setParent(PNode::getNullParent());
186
187    pj->setVelocity(this->launcher[i].getNormalized() * 250.0);
188
189    pj->setParent(PNode::getNullParent());
190    pj->setAbsCoor(this->getAbsCoor() + this->launcher[i] * this->size);
191    Quaternion q;
192    pj->setAbsDir(q.lookAt(Vector(), this->launcher[i], VECTOR_RAND(1)));
193/*
194    pj->setAbsCoor(this->getAbsCoor() + VECTOR_RAND(3));
195    pj->setAbsDir(this->getAbsDir());*/
196    pj->activate();
197  }
198}
199
200
201void SpikeBall::updateFireDir(){
202
203  float** m = new float* [3];
204  for( int i = 0; i < 3 ; i++)
205    m[i] = new float;
206
207  float nx, ny, nz, ca, sa;
208
209  nx = this->getRotationAxis().x;
210  ny = this->getRotationAxis().y;
211  nz = this->getRotationAxis().z;
212
213  ca = cos (this->getAngle());
214  sa = sin (this->getAngle());
215// final version below... easier to to cheat with the one above.
216
217  m[0][0] = nx * nx * (1 - ca) + ca;
218  m[0][1] = nx * ny * (1 - ca) + nz * sa;
219  m[0][2] = nx * nz * (1 - ca) - ny * sa;
220  m[1][0] = nx * nz * (1 - ca) - nz * sa;
221  m[1][1] = ny * ny * (1 - ca) + ca;
222  m[1][2] = ny * nz * (1 - ca) + nx * sa;
223  m[2][0] = nx * nz * (1 - ca) + ny * sa;
224  m[2][1] = ny * nz * (1 - ca) - nx * sa;
225  m[2][2] = nz * nz * (1 - ca) + ca;
226
227  float x, y, z;
228  for (int i = 0; i < this->getFragments(); i++){
229//     printf("%i ", i);
230    x = m[0][0] * this->launcher[i].x + m[0][1] * this->launcher[i].y + m[0][2] * this->launcher[i].z;
231    y = m[1][0] * this->launcher[i].x + m[1][1] * this->launcher[i].y + m[1][2] * this->launcher[i].z;
232    z = m[2][0] * this->launcher[i].x + m[2][1] * this->launcher[i].y + m[2][2] * this->launcher[i].z;
233
234    this->launcher[i] = Vector (x, y, z);
235  }
236//   printf("\n");
237
238  for( int i = 0; i < 3 ; i++)
239    delete m[i];
240  delete m;
241}
242
243
244/**
245 *  signal tick, time dependent things will be handled here
246 * @param dt time since last tick
247*/
248void SpikeBall::tick (float dt)
249{
250  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
251  Vector v = this->velocity * dt;
252  this->shiftCoor(v);
253
254  if(this->lifeCycle > .9){
255//     printf("called by spikeball  ");
256//     this->weaponMan->fire();
257//     this->blow();
258  }
259
260  if (this->tickLifeCycle(dt))
261      this->deactivate();
262
263  this->updateAngle( dt );
264//   angle += rotationSpeed * dt;
265}
266
267/**
268 *  the function gets called, when the projectile is destroyed
269*/
270void SpikeBall::destroy (WorldEntity* killer)
271{
272  ProjectileWeapon::destroy( killer );
273  PRINTF(5)("DESTROY SpikeBall\n");
274  this->lifeCycle = .95; //!< @todo calculate this usefully.
275
276  this->emitter->setSystem(SpikeBall::explosionParticles);
277}
278
279
280void SpikeBall::draw () const
281{
282  glPushAttrib(GL_ENABLE_BIT);
283  //glDisable(GL_LIGHTING);
284
285  glMatrixMode(GL_MODELVIEW);
286  glPushMatrix();
287
288  float matrix[4][4];
289  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
290
291  glRotatef(angle, this->rotationVector.x, this->rotationVector.y, this->rotationVector.z);
292  this->getAbsDir().matrix (matrix);
293  glMultMatrixf((float*)matrix);
294  this->getModel()->draw();
295
296  this->halo->draw();
297
298  glPopMatrix();
299
300  glPopAttrib();
301}
302
Note: See TracBrowser for help on using the repository browser.