Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/lbolt.cc @ 10758

Last change on this file since 10758 was 10747, checked in by nicolasc, 18 years ago

cleaned out origList

File size: 4.7 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 "lbolt.h"
21
22#include "state.h"
23#include "model.h"
24
25#include "world_entities/npcs/npc.h"
26
27#include "particles/dot_emitter.h"
28#include "particles/sprite_particles.h"
29#include "npcs/npc.h"
30
31#include <cassert>
32#include "debug.h"
33
34#include "obb_tree.h"
35
36#include "space_ships/space_ship.h"
37
38
39
40ObjectListDefinition(LBolt);
41CREATE_FAST_FACTORY_STATIC(LBolt);
42
43/**
44 *  standard constructor
45*/
46LBolt::LBolt () : Projectile()
47{
48  this->registerObject(this, LBolt::_objectList);
49
50  this->loadModel("models/projectiles/lbolt.obj");
51
52  this->setMinEnergy(1);
53  this->setHealthMax(0);
54  this->lifeSpan = 1.0;
55
56  this->emitter = new DotEmitter(100, 5, M_2_PI);
57  this->emitter->setParent(this);
58  this->emitter->setSpread(M_PI, M_PI);
59  this->emitter->setEmissionRate(300.0);
60  this->emitter->setEmissionVelocity(50.0);
61
62  this->angle = 0;
63
64  this->halo = new Billboard();
65  this->halo->setSize(.35, .35);
66  this->halo->setTexture("hbolt_halo.jpg");
67  this->halo->setVisibility(false);
68
69  this->halo->setPulse();
70
71   
72  this->obbTree = new OBBTree();
73  this->obbTree->createBox(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 1.0f, 1.0f));
74  this->setOBBTree(this->obbTree);
75}
76
77
78/**
79 *  standard deconstructor
80*/
81LBolt::~LBolt ()
82{
83  // delete this->emitter;
84
85  /* this is normaly done by World.cc by deleting the ParticleEngine */
86  if (LBolt::explosionParticles != NULL && LBolt::objectList().size() <= 1)
87  {
88    //if (ClassList::exists(LBolt::explosionParticles, CL_PARTICLE_SYSTEM))
89    //  delete LBolt::explosionParticles;
90    PRINTF(1)("Deleting LBolt Particles\n");
91    LBolt::explosionParticles = NULL;
92  }
93
94}
95
96SpriteParticles* LBolt::explosionParticles = NULL;
97
98void LBolt::activate()
99{
100  this->halo->setVisibility(true);
101//   this->origList = this->getOMListNumber();
102//   this->toList(OM_ENVIRON);
103  if (unlikely(LBolt::explosionParticles == NULL))
104  {
105    LBolt::explosionParticles = new SpriteParticles(1000);
106    LBolt::explosionParticles->setName("BoltExplosionParticles");
107    LBolt::explosionParticles->setLifeSpan(.5, .3);
108    LBolt::explosionParticles->setRadius(0.0, 10.0);
109    LBolt::explosionParticles->setRadius(.5, 6.0);
110    LBolt::explosionParticles->setRadius(1.0, 3.0);
111    LBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
112    LBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
113    LBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
114  }
115
116  this->setDamage(5);
117  this->setHealth(0);
118}
119
120
121void LBolt::deactivate()
122{
123  assert (LBolt::explosionParticles != NULL);
124  LBolt::explosionParticles->removeEmitter(this->emitter);
125  this->halo->setVisibility(false);
126  this->lifeCycle = 0.0;
127
128  this->toList(OM_DEAD);
129//   this->removeNode();
130  LBolt::fastFactory->kill(this);
131}
132
133
134void LBolt::hit (float damage, WorldEntity* entity )
135{
136  PRINTF(0)("Collision with LBolt\n");
137  if (this->hitEntity != entity && entity->isA(NPC::staticClassID()))
138    this->destroy( entity );
139  this->hitEntity = entity;
140  this->deactivate();
141}
142
143/**
144 *  signal tick, time dependent things will be handled here
145 * @param dt time since last tick
146*/
147void LBolt::tick (float dt)
148{
149  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
150  Vector v = this->velocity * dt;
151  this->shiftCoor(v);
152
153  if (this->tickLifeCycle(dt))
154    this->deactivate();
155
156  angle += LBolt::rotationSpeed * dt;
157  if(angle > 360)
158    angle -= 360;
159}
160
161/**
162 *  the function gets called, when the projectile is destroyed
163*/
164void LBolt::destroy (WorldEntity* killer)
165{
166  Projectile::destroy( killer );
167  PRINTF(5)("DESTROY LBolt\n");
168  this->lifeCycle = .95; //!< @todo calculate this usefully.
169
170  this->emitter->setSystem(LBolt::explosionParticles);
171}
172
173
174void LBolt::draw () const
175{
176  glPushAttrib(GL_ENABLE_BIT);
177  //glDisable(GL_LIGHTING);
178
179  glMatrixMode(GL_MODELVIEW);
180  glPushMatrix();
181
182    float matrix[4][4];
183    glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
184    this->halo->draw();
185
186    Vector tmpRot;
187    tmpRot = this->flightDirection.getNormalized();
188    glRotatef(this->angle, tmpRot.x, tmpRot.y, tmpRot.z);
189    tmpRot = this->getAbsDir().getSpacialAxis();
190    glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
191
192    this->getAbsDir().matrix (matrix);
193    glMultMatrixf((float*)matrix);
194    this->getModel()->draw();
195
196  glPopMatrix();
197  glPopAttrib();
198}
199
Note: See TracBrowser for help on using the repository browser.