Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/spaceshipcontrol/src/world_entities/projectiles/test_bullet.cc @ 6694

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

orxonox/trunk: Material can now be copied
ParticleSprite used for all Projectiles

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