Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: sync

File size: 3.7 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    delete TestBullet::explosionParticles;
72    TestBullet::explosionParticles = NULL;
73  }
74  */
75}
76
77ParticleSystem* TestBullet::explosionParticles = NULL;
78
79
80void TestBullet::activate()
81{
82  State::getWorldEntityList()->add(this);
83  if (unlikely(TestBullet::explosionParticles == NULL))
84  {
85    TestBullet::explosionParticles = new ParticleSystem(10000, PARTICLE_SPRITE);
86    TestBullet::explosionParticles->setLifeSpan(.5);
87    TestBullet::explosionParticles->setRadius(0.0, .5);
88    TestBullet::explosionParticles->setRadius(0.5, 2.0);
89    TestBullet::explosionParticles->setRadius(0.0, 0.0);
90    TestBullet::explosionParticles->setColor(0.0, 1,0,0,.7);
91    TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5);
92    TestBullet::explosionParticles->setColor(1.0, .5,.5,.5,.0);
93  }
94
95  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles);
96}
97
98
99void TestBullet::deactivate()
100{
101  ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::explosionParticles);
102
103  GarbageCollector::getInstance()->collect(this);
104  this->lifeCycle = 0.0;
105}
106
107
108void TestBullet::collidesWith(WorldEntity* entity, const Vector& location)
109{
110
111}
112
113/**
114 *  signal tick, time dependent things will be handled here
115 * @param time since last tick
116*/
117void TestBullet::tick (float time)
118{
119  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
120  Vector v = this->velocity * (time);
121  this->shiftCoor(v);
122
123  this->lifeCycle += time/this->lifeSpan;
124  if( this->lifeCycle >= 1)
125    {
126      PRINTF(5)("FINALIZE==========================\n");
127      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
128      PRINTF(5)("FINALIZE===========================\n");
129//      this->finalize();
130      this->deactivate();
131    }
132}
133
134/**
135 *  the function gets called, when the projectile is destroyed
136*/
137void TestBullet::destroy ()
138{
139  this->deactivate();
140
141
142  GarbageCollector::getInstance()->collect(this);
143
144}
145
146
147void TestBullet::draw ()
148{
149  glMatrixMode(GL_MODELVIEW);
150  glPushMatrix();
151
152  float matrix[4][4];
153  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
154  this->getAbsDir().matrix (matrix);
155  glMultMatrixf((float*)matrix);
156  glScalef(2.0, 2.0, 2.0);
157  this->model->draw();
158
159  glPopMatrix();
160}
161
Note: See TracBrowser for help on using the repository browser.