Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/presentation/src/world_entities/projectiles/mbolt.cc

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

moved loadShield (XML), some minor cleanup

File size: 5.1 KB
RevLine 
[9999]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
[10104]4   Copyright (C) 2004-2006 orx
[9999]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
[10104]12   main-programmer: Marc Schaerrer
[9999]13   co-programmer: Benjamin Grauer
14
15*/
16
17
18#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WEAPON
19
20#include "mbolt.h"
21
22#include "state.h"
23#include "model.h"
24
[10545]25#include "world_entities/npcs/npc.h"
26
[9999]27#include "particles/dot_emitter.h"
28#include "particles/sprite_particles.h"
29
[10064]30#include "space_ships/space_ship.h"
31
[9999]32#include <cassert>
33#include "debug.h"
34
[10042]35#include "static_model.h"
[9999]36
[10081]37#include "effects/trail.h"
[10042]38
[10740]39#include "obb_tree.h"
[10081]40
[10366]41
[10740]42
[10064]43ObjectListDefinition(MBolt);
[9999]44CREATE_FAST_FACTORY_STATIC(MBolt);
45
46/**
47 *  standard constructor
48*/
49MBolt::MBolt () : Projectile()
50{
[10064]51  this->registerObject(this, MBolt::_objectList);
[10113]52  this->loadModel("models/projectiles/mbolt.obj",4);
[10081]53
[10036]54  this->setMinEnergy(4);
[9999]55  this->setHealthMax(0);
[10274]56  this->lifeSpan = 1.5;
[10042]57  this->angle     = 0;
[9999]58
[10113]59  this->emitter = new DotEmitter(50, 0, 0);
[9999]60  this->emitter->setParent(this);
[10064]61  this->emitter->setSpread(M_PI,M_PI);
62  this->emitter->setInheritSpeed(this->velocity.len());
63  this->emitter->setEmissionRate(500.0);
64  this->emitter->setEmissionVelocity(this->velocity.len());
[10042]65
66  this->mat = new Material("mBolt");
67  this->mat->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
68  this->mat->setDiffuse(1,1,1);
[10064]69  this->mat->setDiffuseMap("laser_add.png");
[10042]70  this->mat->setDiffuseMap("laser.png",1);
[10064]71
[10366]72  dynamic_cast<StaticModel*>(this->getModel())->addMaterial(*this->mat);
[10042]73  dynamic_cast<StaticModel*>(this->getModel())->finalize();
[10081]74
[10113]75  dynamic_cast<StaticModel*>(this->getModel())->rebuild();
[10261]76  //this->buildObbTree(4);
[10366]77
[10132]78  this->trail = new Trail(6, 4, .1, this);
[10420]79  this->trail->setTexture( "textures/laser.png");
[10618]80  this->trail->setAbsCoor(this->getAbsCoor() - this->getVelocity().getNormalized() * .7);
[10763]81
[10740]82  this->obbTree = new OBBTree();
83  this->obbTree->createBox(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 1.0f, 1.0f));
84  this->setOBBTree(this->obbTree);
[10345]85
[9999]86}
87
88
89/**
90 *  standard deconstructor
[10078]91 *
92 */
[9999]93MBolt::~MBolt ()
94{
95
96  if (MBolt::explosionParticles != NULL && MBolt::objectList().size() <= 1)
97  {
[10042]98    if (ParticleSystem::objectList().exists(MBolt::explosionParticles))
99      delete MBolt::explosionParticles;
[9999]100    MBolt::explosionParticles = NULL;
[10081]101    PRINTF(1)("Deleting MBolt Explosion Particles\n");
[9999]102  }
[10168]103
104  delete this->emitter;
105  delete this->trail;
[9999]106}
107
108SpriteParticles* MBolt::explosionParticles = NULL;
109
110void MBolt::activate()
111{
112  if (unlikely(MBolt::explosionParticles == NULL))
113  {
114    MBolt::explosionParticles = new SpriteParticles(1000);
115    MBolt::explosionParticles->setName("MBoltExplosionParticles");
[10113]116    MBolt::explosionParticles->setLifeSpan(.2, .1);
[9999]117    MBolt::explosionParticles->setRadius(0.0, 10.0);
118    MBolt::explosionParticles->setRadius(.5, 6.0);
119    MBolt::explosionParticles->setRadius(1.0, 3.0);
120    MBolt::explosionParticles->setColor(0.0, 1,1,0,.9);
121    MBolt::explosionParticles->setColor(0.5, .8,.8,0,.5);
122    MBolt::explosionParticles->setColor(1.0, .8,.8,.7,.0);
123  }
124
[10081]125  this->setPhysDamage(10);
126  this->setElecDamage(0);
[9999]127  this->setHealth(0);
[10042]128
[10064]129  this->emitter->setSpread(0);
[10078]130  this->emitter->setEmissionRate(10.0);
[10113]131  this->emitter->setEmissionVelocity(50);
[9999]132}
133
134
135void MBolt::deactivate()
136{
137  assert (MBolt::explosionParticles != NULL);
138  MBolt::explosionParticles->removeEmitter(this->emitter);
139  this->lifeCycle = 0.0;
140
[10345]141  this->lifeCycle = 0.0;
142  this->toList(OM_NULL);
143  //this->toList(OM_DEAD);
[10698]144//   this->removeNode();
[9999]145  MBolt::fastFactory->kill(this);
146}
[10763]147  // HACK direction AbsDir calulation
[9999]148
[10274]149void MBolt::hit (float damage, WorldEntity* entity )
[9999]150{
[10113]151
[10117]152  if (this->hitEntity != entity)
153    this->destroy( entity );
154  this->hitEntity = entity;
[10763]155
[10132]156  this->deactivate();
[10366]157
[10117]158  return;
159
[10261]160}
[9999]161
162/**
163 *  signal tick, time dependent things will be handled here
164 * @param dt time since last tick
165*/
166void MBolt::tick (float dt)
167{
168  Vector v = this->velocity * dt;
169  this->shiftCoor(v);
170
171  if (this->tickLifeCycle(dt))
172    this->deactivate();
[10042]173
174  this->angle += MBolt::rotationSpeed * dt;
[10081]175  this->trail->tick(dt);
[9999]176}
177
178/**
179 *  the function gets called, when the projectile is destroyed
180*/
181void MBolt::destroy (WorldEntity* killer)
182{
183  Projectile::destroy( killer );
184  PRINTF(5)("DESTROY MBolt\n");
185  this->lifeCycle = .95; //!< @todo calculate this usefully.
186
187  this->emitter->setSystem(MBolt::explosionParticles);
188}
189
190
191void MBolt::draw () const
192{
193  glPushAttrib(GL_ENABLE_BIT);
194  glDisable(GL_LIGHTING);
195
[10042]196  glPushMatrix();
197  float matrix[4][4];
198  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
[10698]199//   glRotatef(this->angle, 1.0f, 0.0f, 0.0f); //spinning missile
200  glRotatef(this->angle, this->flightDirection.x, this->flightDirection.y, this->flightDirection.z);
[10042]201  this->getAbsDir().matrix (matrix);
202  glMultMatrixf((float*)matrix);
203
[10113]204  glScalef(0.75/4, 0.7/16, 0.7/16);  // no double rescale
[10042]205
206  this->mat->select();
207  dynamic_cast<StaticModel*>(this->getModel())->draw();
208  this->mat->unselect();
[10113]209  glScalef(4/.75,16/.7,16/.7);
210  glTranslatef(-3,0,0);
[10081]211  this->trail->draw();
[10042]212  glPopMatrix();
[9999]213  glPopAttrib();
[10042]214
[10140]215}
Note: See TracBrowser for help on using the repository browser.