Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/playability/src/world_entities/projectiles/hbolt.cc @ 10063

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

halo effects

File size: 5.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 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: Patrick Boenzli
13   co-programmer: Benjamin Grauer
14
15*/
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
17
18#include "hbolt.h"
19
20#include "state.h"
21#include "model.h"
22
23#include "particles/dot_emitter.h"
24#include "particles/sprite_particles.h"
25
26#include <cassert>
27#include "debug.h"
28
29#include "static_model.h"
30#include "effects/billboard.h"
31
32
33#include "class_id_DEPRECATED.h"
34ObjectListDefinition(HBolt);
35CREATE_FAST_FACTORY_STATIC(HBolt);
36
37/**
38 *  standard constructor
39*/
40HBolt::HBolt () : Projectile()
41{
42  this->registerObject(this, HBolt::_objectList);
43
44  this->loadModel("models/projectiles/hbolt.obj",1.3);
45
46  this->setMinEnergy(10);
47  this->setHealthMax(0);
48  this->lifeSpan = 7.0;
49
50  this->angle = 0;
51  this->rotationSpeed = 600;
52
53  this->emitter = new DotEmitter(100, 5, M_2_PI);
54  this->emitter->setParent(this);
55  this->emitter->setSpread(M_PI, M_PI);
56  this->emitter->setEmissionRate(300.0);
57  this->emitter->setEmissionVelocity(50.0);
58
59  this->mat = new Material("hBolt_halo");
60  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
61  //this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
62  this->mat->setDiffuse(1,1,1);
63  this->mat->setAmbient(1,1,1);
64  this->mat->setIllum(3);
65  this->mat->setDiffuseMap("hbolt_halo.png");
66//   this->mat->setDiffuseMap("hbolt_halo.png",1);
67//   this->mat->setDiffuseMap("hbolt_halo.png",2);
68//   dynamic_cast<StaticModel*>(this->getModel())->addMaterial(this->mat);
69//   dynamic_cast<StaticModel*>(this->getModel())->finalize();
70
71  this->halo = new Billboard();
72  this->halo->setSize(.65, .65);
73  this->halo->setTexture("hbolt_halo2.png");
74
75}
76
77
78/**
79 *  standard deconstructor
80*/
81HBolt::~HBolt ()
82{
83  // delete this->emitter;
84
85  /* this is normaly done by World.cc by deleting the ParticleEngine */
86  if (HBolt::explosionParticles != NULL && HBolt::objectList().size() <= 1)
87  {
88    //if (ClassList::exists(HBolt::explosionParticles, CL_PARTICLE_SYSTEM))
89    //  delete HBolt::explosionParticles;
90    PRINTF(1)("Deleting HBolt Particles\n");
91    HBolt::explosionParticles = NULL;
92  }
93
94}
95
96SpriteParticles* HBolt::explosionParticles = NULL;
97
98void HBolt::activate()
99{
100  if (unlikely(HBolt::explosionParticles == NULL))
101  {
102    HBolt::explosionParticles = new SpriteParticles(1000);
103    HBolt::explosionParticles->setName("HBoltExplosionParticles");
104    HBolt::explosionParticles->setLifeSpan(.5, .3);
105    HBolt::explosionParticles->setRadius(0.0, 10.0);
106    HBolt::explosionParticles->setRadius(.5, 6.0);
107    HBolt::explosionParticles->setRadius(1.0, 3.0);
108    HBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
109    HBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
110    HBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
111  }
112
113  this->setDamage(100);
114  this->setHealth(0);
115}
116
117
118void HBolt::deactivate()
119{
120  assert (HBolt::explosionParticles != NULL);
121  HBolt::explosionParticles->removeEmitter(this->emitter);
122  this->lifeCycle = 0.0;
123
124  this->toList(OM_NULL);
125  this->removeNode();
126  HBolt::fastFactory->kill(this);
127}
128
129
130void HBolt::collidesWith(WorldEntity* entity, const Vector& location)
131{
132  if (this->hitEntity != entity && entity->isA(CL_NPC))
133    this->destroy( entity );
134  this->hitEntity = entity;
135}
136
137
138void HBolt::updateAngle (float time)
139{
140  this->angle += this->rotationSpeed * time;
141}
142
143
144/**
145 *  signal tick, time dependent things will be handled here
146 * @param dt time since last tick
147*/
148void HBolt::tick (float dt)
149{
150  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
151  Vector v = this->velocity * dt;
152  this->shiftCoor(v);
153
154  if (this->tickLifeCycle(dt))
155    this->deactivate();
156
157  //float w = this->rotationSpeed * M_PI;
158  //Quaternion rotation(this->rotationSpeed * dt, this->axis);
159  //Quaternion u = this->getRelDir();
160  //this->setRelDir(u * rotation);
161
162  this->updateAngle(dt);
163
164}
165
166/**
167 *  the function gets called, when the projectile is destroyed
168*/
169void HBolt::destroy (WorldEntity* killer)
170{
171  Projectile::destroy( killer );
172  PRINTF(5)("DESTROY HBolt\n");
173  this->lifeCycle = .95; //!< @todo calculate this usefully.
174
175  this->emitter->setSystem(HBolt::explosionParticles);
176}
177
178
179void HBolt::draw () const
180{
181
182  glMatrixMode(GL_MODELVIEW);
183  glPushMatrix();
184
185
186  glTranslatef (this->getAbsCoor ().x,
187                  this->getAbsCoor ().y,
188                  this->getAbsCoor ().z);
189
190//   glPushMatrix();
191//     glEnable(GL_BLEND);
192//     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
193//     glShadeModel(GL_FLAT);
194//     glClearColor(0.0, 0.0, 0.0, 0.0);
195//
196//     glEnable(GL_TEXTURE_2D);
197//     this->mat->select();
198//
199// //     Vector camera = State::getCamera()->getViewVector();
200//
201//     glBegin(GL_QUADS); // +X
202//       glTexCoord2f (0.0, 0.0);
203//       glVertex3f( 0.0f, -.7f, -.7f);
204//
205//       glTexCoord2f (0.0, 1.0);
206//       glVertex3f( 0.0f, -.7f , .7f);
207//
208//       glTexCoord2f (1.0, 1.0);
209//       glVertex3f( 0.0, .7f , .7f );
210//
211//       glTexCoord2f (1.0, 0.0);
212//       glVertex3f( 0.0, .7f, -.7f );
213//     glEnd();
214//   glPopMatrix();
215
216//   this->billboard->toggleBillboard();
217
218  this->halo->draw();
219
220  Vector tmpRot = this->getAbsDir().getSpacialAxis();
221  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
222  glRotatef(this->angle, 0.0, 0.0, 1.0);
223
224//   this->getModel()->draw();
225
226//   this->mat->select();
227   dynamic_cast<StaticModel*>(this->getModel())->draw();
228//   this->mat->select();
229//   dynamic_cast<StaticModel*>(this->getModel())->draw();
230//   this->mat->unselect();
231
232
233  glPopMatrix();
234}
Note: See TracBrowser for help on using the repository browser.