Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: more cleanup of the WorldEntity (includes rearanged)

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