Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: Connection-Removing in the Particle-Class

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