Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/spike_ball.cc @ 10772

Last change on this file since 10772 was 10698, checked in by snellen, 17 years ago

merged adm, hud, vs-enhancements : beni's responsible for this commit. blame him!

File size: 7.1 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
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->setRotationSpeed(130);
58
59  this->halo = new Billboard();
60  this->halo->setSize(2, 2);
61  this->halo->setTexture("hbolt_halo.png");
62  this->halo->setVisibility(false);
63
64  this->setFragments(26);
65
66  this->size = 4;
67
68
69  this->launcher = new Vector [this->getFragments()];
70}
71
72
73/**
74 *  standard deconstructor
75*/
76SpikeBall::~SpikeBall ()
77{
78  // delete this->emitter;
79
80  /* this is normaly done by World.cc by deleting the ParticleEngine */
81  if (SpikeBall::explosionParticles != NULL && SpikeBall::objectList().size() <= 1)
82  {
83    //if (ClassList::exists(SpikeBall::explosionParticles, CL_PARTICLE_SYSTEM))
84    //  delete SpikeBall::explosionParticles;
85    PRINTF(1)("Deleting SpikeBall Particles\n");
86//    if (SpikeBall::objectList().exists(SpikeBall::explosionParticles))
87//      delete SpikeBall::explosionParticles;
88    SpikeBall::explosionParticles = NULL;
89  }
90
91}
92
93SpriteParticles* SpikeBall::explosionParticles = NULL;
94
95void SpikeBall::activate()
96{
97  this->halo->setVisibility(true);
98  if (unlikely(SpikeBall::explosionParticles == NULL))
99  {
100    SpikeBall::explosionParticles = new SpriteParticles(1000);
101    SpikeBall::explosionParticles->setName("SpikeBallExplosionParticles");
102    SpikeBall::explosionParticles->setLifeSpan(.5, .3);
103    SpikeBall::explosionParticles->setRadius(0.0, 10.0);
104    SpikeBall::explosionParticles->setRadius(.5, 6.0);
105    SpikeBall::explosionParticles->setRadius(1.0, 3.0);
106    SpikeBall::explosionParticles->setColor(0.0, 1,1,0,.9);
107    SpikeBall::explosionParticles->setColor(0.5, .8,.8,0,.5);
108    SpikeBall::explosionParticles->setColor(1.0, .8,.8,.7,.0);
109  }
110  this->setDamage(5);
111  this->setHealth(10);
112  this->setRotationAxis(VECTOR_RAND(1));
113  this->setAngle();
114
115  this->launcher[0] = Vector(1.0, 0.0, 0.0);
116  this->launcher[1] = Vector(0.0, 1.0, 0.0);
117  this->launcher[2] = Vector(0.0, 0.0, 1.0);
118
119  this->launcher[3] = Vector(1.0, 1.0, 0.0);
120  this->launcher[4] = Vector(0.0, 1.0, 1.0);
121  this->launcher[5] = Vector(1.0, 0.0, 1.0);
122  this->launcher[6] = Vector(1.0, -1.0, 0.0);
123  this->launcher[7] = Vector(0.0, 1.0, -1.0);
124  this->launcher[8] = Vector(-1.0, 0.0, 1.0);
125
126  this->launcher[9] = Vector(-1.0, 1.0, 1.0);
127  this->launcher[10] = Vector(1.0, 1.0, 1.0);
128  this->launcher[11] = Vector(1.0, -1.0, 1.0);
129  this->launcher[12] = Vector(-1.0, -1.0, 1.0);
130
131  int tmp = this->getFragments() / 2;
132  for (int i = 0; i < tmp; i++)
133  {
134    this->launcher[i].normalize();
135    this->launcher[tmp + i] =  this->launcher[i] * (-1);
136  }
137
138  this->freeMode = false;
139}
140
141
142void SpikeBall::deactivate()
143{
144  this->halo->setVisibility(false);
145  assert (SpikeBall::explosionParticles != NULL);
146  //SpikeBall::explosionParticles->removeEmitter(this->emitter);
147  this->emitter->setSystem(NULL);
148  this->lifeCycle = 0.0;
149
150  this->toList(OM_NULL);
151//   this->removeNode();
152  SpikeBall::fastFactory->kill(this);
153}
154
155/*
156void SpikeBall::collidesWith(WorldEntity* entity, const Vector& location)
157{
158  PRINTF(0)("Collision with SpikeBall\n");
159  if (this->hitEntity != entity && entity->isA(CL_NPC))
160    this->destroy( entity );
161  this->hitEntity = entity;
162  dynamic_cast<SpaceShip*>(entity)->damage(this->getDamage(),0);
163}*/
164
165
166void SpikeBall::blow()
167{
168  if ( this->freeMode )
169    updateFireDir();
170
171  Spike* pj = NULL;
172  for ( int i = 0; i < this->getFragments(); i++)
173  {
174    pj  = new Spike();
175    assert( pj );
176    pj->setParent(PNode::getNullParent());
177
178    pj->setVelocity(this->launcher[i].getNormalized() * 250.0);
179
180    pj->setParent(PNode::getNullParent());
181    pj->setAbsCoor(this->getAbsCoor() + this->launcher[i] * this->size);
182//     Quaternion q;
183    pj->setAbsDir(Quaternion(this->launcher[i], 0));
184
185    pj->toList(this->getOMListNumber());
186
187    pj->activate();
188  }
189}
190
191
192void SpikeBall::updateFireDir(){
193
194  float** m = new float* [3];
195  for( int i = 0; i < 3 ; i++)
196    m[i] = new float;
197
198  float nx, ny, nz, ca, sa;
199
200  nx = this->getRotationAxis().x;
201  ny = this->getRotationAxis().y;
202  nz = this->getRotationAxis().z;
203
204  ca = cos (this->getAngle());
205  sa = sin (this->getAngle());
206
207  m[0][0] = nx * nx * (1 - ca) + ca;
208  m[0][1] = nx * ny * (1 - ca) + nz * sa;
209  m[0][2] = nx * nz * (1 - ca) - ny * sa;
210  m[1][0] = nx * nz * (1 - ca) - nz * sa;
211  m[1][1] = ny * ny * (1 - ca) + ca;
212  m[1][2] = ny * nz * (1 - ca) + nx * sa;
213  m[2][0] = nx * nz * (1 - ca) + ny * sa;
214  m[2][1] = ny * nz * (1 - ca) - nx * sa;
215  m[2][2] = nz * nz * (1 - ca) + ca;
216
217  float x, y, z;
218  for (int i = 0; i < this->getFragments(); i++){
219    x = m[0][0] * this->launcher[i].x + m[0][1] * this->launcher[i].y + m[0][2] * this->launcher[i].z;
220    y = m[1][0] * this->launcher[i].x + m[1][1] * this->launcher[i].y + m[1][2] * this->launcher[i].z;
221    z = m[2][0] * this->launcher[i].x + m[2][1] * this->launcher[i].y + m[2][2] * this->launcher[i].z;
222
223    this->launcher[i] = Vector (x, y, z);
224  }
225
226  for( int i = 0; i < 3 ; i++)
227    delete m[i];
228  delete m;
229}
230
231
232/**
233 *  signal tick, time dependent things will be handled here
234 * @param dt time since last tick
235*/
236void SpikeBall::tick (float dt)
237{
238  Vector v = this->velocity * dt;
239  this->shiftCoor(v);
240
241  if (this->tickLifeCycle(dt)){
242    this->blow();
243    this->deactivate();
244  }
245
246  this->updateAngle( dt );
247}
248
249/**
250 *  the function gets called, when the projectile is destroyed
251*/
252void SpikeBall::destroy (WorldEntity* killer)
253{
254  ProjectileWeapon::destroy( killer );
255  PRINTF(5)("DESTROY SpikeBall\n");
256  this->lifeCycle = .95; //!< @todo calculate this usefully.
257
258  this->emitter->setSystem(SpikeBall::explosionParticles);
259}
260
261
262void SpikeBall::draw () const
263{
264  glPushAttrib(GL_ENABLE_BIT);
265  glMatrixMode(GL_MODELVIEW);
266  glPushMatrix();
267
268  float matrix[4][4];
269  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
270  this->halo->draw();
271
272  glRotatef(angle, this->getRotationAxis().x, this->getRotationAxis().y, this->getRotationAxis().z);
273  this->getAbsDir().matrix (matrix);
274  glMultMatrixf((float*)matrix);
275  this->getModel()->draw();
276
277
278  glPopMatrix();
279  glPopAttrib();
280}
281
Note: See TracBrowser for help on using the repository browser.