Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/weapons/test_bullet.cc @ 6260

Last change on this file since 6260 was 6222, checked in by bensch, 19 years ago

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

File size: 5.1 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 "test_bullet.h"
19
20#include "fast_factory.h"
21
22#include "state.h"
23#include "class_list.h"
24
25#include "particle_engine.h"
26#include "particle_emitter.h"
27#include "particle_system.h"
28
29
30using namespace std;
31
32CREATE_FAST_FACTORY_STATIC(TestBullet, CL_TEST_BULLET);
33
34/**
35 *  standard constructor
36*/
37TestBullet::TestBullet () : Projectile()
38{
39  this->setClassID(CL_TEST_BULLET, "TestBullet");
40
41  float modelSize = .3;
42  this->loadModel("models/projectiles/orx-rocket.obj", .3);
43
44  this->energyMin = 1;
45  this->energyMax = 10;
46  this->lifeSpan = 2;
47
48  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
49  this->emitter->setParent(this);
50  this->emitter->setSpread(M_PI, M_PI);
51}
52
53
54/**
55 *  standard deconstructor
56*/
57TestBullet::~TestBullet ()
58{
59  // delete this->emitter;
60
61  /* this is normaly done by World.cc by deleting the ParticleEngine */
62  if (TestBullet::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
63  {
64    if (ClassList::exists(TestBullet::trailParticles, CL_PARTICLE_SYSTEM))
65      delete TestBullet::trailParticles;
66    TestBullet::trailParticles = NULL;
67  }
68  if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
69  {
70    if (ClassList::exists(TestBullet::explosionParticles, CL_PARTICLE_SYSTEM))
71      delete TestBullet::explosionParticles;
72    TestBullet::explosionParticles = NULL;
73  }
74
75}
76
77ParticleSystem* TestBullet::trailParticles = NULL;
78ParticleSystem* TestBullet::explosionParticles = NULL;
79
80void TestBullet::activate()
81{
82  if (unlikely(TestBullet::trailParticles == NULL))
83  {
84    TestBullet::trailParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
85    TestBullet::trailParticles->setName("TestBulletTrailParticles");
86    TestBullet::trailParticles->setLifeSpan(.5, .3);
87    TestBullet::trailParticles->setRadius(0.0, .5);
88    TestBullet::trailParticles->setRadius(0.5, 2.0);
89    TestBullet::trailParticles->setRadius(1.0, 5.0);
90    TestBullet::trailParticles->setColor(0.0, 1,0,0,.7);
91    TestBullet::trailParticles->setColor(0.5, .8,.8,0,.5);
92    TestBullet::trailParticles->setColor(1.0, .7,.7,.7,.0);
93  }
94  if (unlikely(TestBullet::explosionParticles == NULL))
95  {
96    TestBullet::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
97    TestBullet::explosionParticles->setName("TestBulletExplosionParticles");
98    TestBullet::explosionParticles->setLifeSpan(.5, .3);
99    TestBullet::explosionParticles->setRadius(0.0, 10);
100    TestBullet::explosionParticles->setRadius(.5, 20.0);
101    TestBullet::explosionParticles->setRadius(1.0, 3.0);
102    TestBullet::explosionParticles->setColor(0.0, 0,1,0,.9);
103    TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5);
104    TestBullet::explosionParticles->setColor(1.0, 1,1,1,.0);
105  }
106
107  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::trailParticles);
108
109  this->emitter->setEmissionRate(20.0);
110  this->emitter->setEmissionVelocity(3.0);
111}
112
113
114void TestBullet::deactivate()
115{
116  ParticleEngine::getInstance()->breakConnections(this->emitter);
117  this->lifeCycle = 0.0;
118  this->toList(OM_NULL);
119
120  TestBullet::fastFactory->kill(this);
121}
122
123
124void TestBullet::collidesWith(WorldEntity* entity, const Vector& location)
125{
126  if (this->hitEntity != entity && entity->isA(CL_NPC))
127    this->destroy();
128  this->hitEntity = entity;
129}
130
131/**
132 *  signal tick, time dependent things will be handled here
133 * @param time since last tick
134*/
135void TestBullet::tick (float time)
136{
137  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
138  Vector v = this->velocity * (time);
139  this->shiftCoor(v);
140
141  this->lifeCycle += time/this->lifeSpan;
142  if( this->lifeCycle >= 1.0)
143    {
144      PRINTF(5)("FINALIZE==========================\n");
145      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
146      PRINTF(5)("FINALIZE===========================\n");
147
148      this->deactivate();
149    }
150}
151
152/**
153 *  the function gets called, when the projectile is destroyed
154*/
155void TestBullet::destroy ()
156{
157  PRINTF(5)("DESTROY TestBullet\n");
158  this->lifeCycle = .95; //!< @todo calculate this usefully.
159  ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::trailParticles);
160  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles);
161
162  this->emitter->setEmissionRate(30.0);
163  this->emitter->setEmissionVelocity(50.0);
164//  this->deactivate();
165
166}
167
168
169void TestBullet::draw () const
170{
171  glMatrixMode(GL_MODELVIEW);
172  glPushMatrix();
173
174  float matrix[4][4];
175  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
176  this->getAbsDir().matrix (matrix);
177  glMultMatrixf((float*)matrix);
178  glScalef(2.0, 2.0, 2.0);
179  this->getModel()->draw();
180
181  glPopMatrix();
182}
183
Note: See TracBrowser for help on using the repository browser.