Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: new interface to ParticleEmitters

File size: 2.2 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(float emissionRate, float velocity, float angle)
36  : ParticleEmitter( emissionRate, velocity, angle)
37{
38  this->init();
39}
40
41/**
42 *  constructs and loads a DotEmitter from a XML-element
43 * @param root the XML-element to load from
44*/
45DotEmitter::DotEmitter(const TiXmlElement* root)
46  : ParticleEmitter()
47{
48  this->init();
49
50   if (root != NULL)
51     this->loadParams(root);
52}
53
54/**
55 *  standard destructor
56
57   removes the EmitterSystem from the ParticleEngine
58*/
59DotEmitter::~DotEmitter ()
60{
61  this->setSystem(NULL);
62}
63
64/**
65  @brief initializes default values of a ParitcleEmitter
66*/
67void DotEmitter::init()
68{
69  this->setClassID(CL_DOT_EMITTER, "DotEmitter");
70}
71
72void DotEmitter::emitParticles(unsigned int count) const
73{
74  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
75
76  for (unsigned int i = 0; i < count; i++)
77  {
78    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
79    randDir.normalize();
80    randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->getAbsDirX());
81    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
82
83    // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
84    randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
85    randDir.normalize();
86    Quaternion orient = Quaternion(M_PI, randDir);
87    Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
88
89    this->getSystem()->addParticle(this->getAbsCoor(), velocityV, orient, moment);
90
91  }
92}
Note: See TracBrowser for help on using the repository browser.