Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5994 was 5994, checked in by bensch, 18 years ago

orxonox/trunk: much cleaner Model Loading unloading, model is now private to WorldEntity (not protected)

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;
[5451]48  this->lifeSpan = 2;
[5443]49
[5447]50  this->emitter = new ParticleEmitter(Vector(0,1,0), M_2_PI, 100, 5);
[5443]51  this->emitter->setParent(this);
[5449]52  this->emitter->setSpread(M_PI, M_PI);
[3755]53}
[3708]54
55
56/**
[4836]57 *  standard deconstructor
[3708]58*/
[4593]59TestBullet::~TestBullet ()
[3708]60{
[5446]61  // delete this->emitter;
[5444]62
[5445]63  /* this is normaly done by World.cc by deleting the ParticleEngine */
[5779]64  if (TestBullet::trailParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
[5447]65  {
66    if (ClassList::exists(TestBullet::trailParticles, CL_PARTICLE_SYSTEM))
67      delete TestBullet::trailParticles;
68    TestBullet::trailParticles = NULL;
69  }
[5779]70  if (TestBullet::explosionParticles != NULL && ClassList::getList(CL_TEST_BULLET)->size() <= 1)
[5444]71  {
[5445]72    if (ClassList::exists(TestBullet::explosionParticles, CL_PARTICLE_SYSTEM))
73      delete TestBullet::explosionParticles;
[5444]74    TestBullet::explosionParticles = NULL;
75  }
[5445]76
[3708]77}
78
[5447]79ParticleSystem* TestBullet::trailParticles = NULL;
[5443]80ParticleSystem* TestBullet::explosionParticles = NULL;
81
82void TestBullet::activate()
83{
84  State::getWorldEntityList()->add(this);
[5447]85  if (unlikely(TestBullet::trailParticles == NULL))
86  {
87    TestBullet::trailParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
88    TestBullet::trailParticles->setName("TestBulletTrailParticles");
89    TestBullet::trailParticles->setLifeSpan(.5, .3);
90    TestBullet::trailParticles->setRadius(0.0, .5);
91    TestBullet::trailParticles->setRadius(0.5, 2.0);
92    TestBullet::trailParticles->setRadius(1.0, 5.0);
93    TestBullet::trailParticles->setColor(0.0, 1,0,0,.7);
94    TestBullet::trailParticles->setColor(0.5, .8,.8,0,.5);
95    TestBullet::trailParticles->setColor(1.0, .7,.7,.7,.0);
96  }
[5443]97  if (unlikely(TestBullet::explosionParticles == NULL))
98  {
[5446]99    TestBullet::explosionParticles = new ParticleSystem(1000, PARTICLE_SPRITE);
[5447]100    TestBullet::explosionParticles->setName("TestBulletExplosionParticles");
[5446]101    TestBullet::explosionParticles->setLifeSpan(.5, .3);
[5447]102    TestBullet::explosionParticles->setRadius(0.0, 10);
103    TestBullet::explosionParticles->setRadius(.5, 20.0);
104    TestBullet::explosionParticles->setRadius(1.0, 3.0);
[5448]105    TestBullet::explosionParticles->setColor(0.0, 0,1,0,.9);
[5443]106    TestBullet::explosionParticles->setColor(0.5, .8,.8,0,.5);
[5447]107    TestBullet::explosionParticles->setColor(1.0, 1,1,1,.0);
[5443]108  }
109
[5447]110  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::trailParticles);
111
112  this->emitter->setEmissionRate(20.0);
[5448]113  this->emitter->setEmissionVelocity(3.0);
[5443]114}
115
116
117void TestBullet::deactivate()
118{
[5447]119  ParticleEngine::getInstance()->breakConnections(this->emitter);
120  this->lifeCycle = 0.0;
[5443]121
[5447]122//  GarbageCollector::getInstance()->collect(this);
123  State::getWorldEntityList()->remove(this);
124  TestBullet::fastFactory->kill(this);
[5443]125}
126
127
[5257]128void TestBullet::collidesWith(WorldEntity* entity, const Vector& location)
129{
[5447]130  if (this->hitEntity != entity && entity->isA(CL_NPC))
131    this->destroy();
132  this->hitEntity = entity;
[5257]133}
[3708]134
135/**
[4836]136 *  signal tick, time dependent things will be handled here
137 * @param time since last tick
[3708]138*/
[4593]139void TestBullet::tick (float time)
[3708]140{
[4464]141  //Vector v = *this->flightDirection * ( this->speed * time * 1000 + 0.1);
142  Vector v = this->velocity * (time);
[3708]143  this->shiftCoor(v);
144
[4890]145  this->lifeCycle += time/this->lifeSpan;
[5447]146  if( this->lifeCycle >= 1.0)
[3708]147    {
148      PRINTF(5)("FINALIZE==========================\n");
[4890]149      PRINTF(5)("current life cycle is: %f\n", this->lifeCycle);
[3708]150      PRINTF(5)("FINALIZE===========================\n");
[5447]151
[5443]152      this->deactivate();
[3708]153    }
154}
155
156/**
[4836]157 *  the function gets called, when the projectile is destroyed
[3708]158*/
[4593]159void TestBullet::destroy ()
[5257]160{
[5448]161  PRINTF(5)("DESTROY TestBullet\n");
162  this->lifeCycle = .95; //!< @todo calculate this usefully.
[5447]163  ParticleEngine::getInstance()->breakConnection(this->emitter, TestBullet::trailParticles);
164  ParticleEngine::getInstance()->addConnection(this->emitter, TestBullet::explosionParticles);
[3708]165
[5448]166  this->emitter->setEmissionRate(30.0);
[5447]167  this->emitter->setEmissionVelocity(50.0);
168//  this->deactivate();
[3708]169
[5257]170}
171
172
[5500]173void TestBullet::draw () const
[3708]174{
175  glMatrixMode(GL_MODELVIEW);
176  glPushMatrix();
177
[4593]178  float matrix[4][4];
[3708]179  glTranslatef (this->getAbsCoor ().x, this->getAbsCoor ().y, this->getAbsCoor ().z);
180  this->getAbsDir().matrix (matrix);
[4593]181  glMultMatrixf((float*)matrix);
[3755]182  glScalef(2.0, 2.0, 2.0);
[5994]183  this->getModel()->draw();
[3708]184
185  glPopMatrix();
186}
187
Note: See TracBrowser for help on using the repository browser.