Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the christmas branche to the trunk
merged with command:
svn merge -r6165:HEAD christmas_branche/ ../trunk/
no conflicts

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