Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/particles/dot_emitter.cc @ 6822

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

trunk: ParticleEmitters now splitted into SubClasses.
Also fixed a little Boeg in the ClassID

File size: 2.3 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: Benjamin Grauer
13   co-programmer: Patrick Boenzli
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
17
18#include "dot_emitter.h"
19
20#include "particle_system.h"
21
22#include "load_param.h"
23#include "factory.h"
24#include "debug.h"
25#include "stdlibincl.h"
26
27using namespace std;
28
29
30CREATE_FACTORY(DotEmitter, CL_DOT_EMITTER);
31
32/**
33 *  standard constructor
34*/
35DotEmitter::DotEmitter(const Vector& direction, float angle, float emissionRate,
36                       float velocity)
37  : ParticleEmitter(direction, angle, emissionRate, velocity)
38{
39  this->init();
40}
41
42/**
43 *  constructs and loads a DotEmitter from a XML-element
44 * @param root the XML-element to load from
45*/
46DotEmitter::DotEmitter(const TiXmlElement* root)
47  : ParticleEmitter()
48{
49  this->init();
50
51   if (root != NULL)
52     this->loadParams(root);
53}
54
55/**
56 *  standard destructor
57
58   removes the EmitterSystem from the ParticleEngine
59*/
60DotEmitter::~DotEmitter ()
61{
62  this->setSystem(NULL);
63}
64
65/**
66  @brief initializes default values of a ParitcleEmitter
67*/
68void DotEmitter::init()
69{
70  this->setClassID(CL_DOT_EMITTER, "DotEmitter");
71}
72
73void DotEmitter::emitParticles(unsigned int count) const
74{
75  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
76
77  for (unsigned int i = 0; i < count; i++)
78  {
79    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
80    randDir.normalize();
81    randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction);
82    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
83
84    // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
85    randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
86    randDir.normalize();
87    Quaternion orient = Quaternion(M_PI, randDir);
88    Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
89
90    this->getSystem()->addParticle(this->getAbsCoor(), velocityV, orient, moment);
91
92  }
93}
Note: See TracBrowser for help on using the repository browser.