Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/adm/src/world_entities/particles/dot_emitter.cc @ 10663

Last change on this file since 10663 was 10114, checked in by patrick, 18 years ago

merged network back to trunk

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 "util/loading/load_param.h"
23#include "util/loading/factory.h"
24#include "debug.h"
25
26
27
28
29ObjectListDefinition(DotEmitter);
30CREATE_FACTORY(DotEmitter);
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->registerObject(this, DotEmitter::_objectList);
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() + this->getVelocity()*.1*rand()/RAND_MAX,
90                                   velocityV, orient, moment);
91
92  }
93}
Note: See TracBrowser for help on using the repository browser.