Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6176 was 6142, checked in by bensch, 19 years ago

orxonox/trunk: merge the ObjectManager to the trunk
merged with command:
svn merge -r6082:HEAD objectmanager/ ../trunk/

conflicts resolution was easy this time :)
but specially merged the world to network_world

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