Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/particles/box_emitter.cc @ 6823

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

orxonox/trunk: BoxEmitter

File size: 2.7 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 "box_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(BoxEmitter, CL_BOX_EMITTER);
31
32/**
33 *  standard constructor
34*/
35BoxEmitter::BoxEmitter(const Vector& size)
36{
37  this->init();
38  this->setSize(size);
39}
40
41/**
42 *  constructs and loads a BoxEmitter from a XML-element
43 * @param root the XML-element to load from
44*/
45BoxEmitter::BoxEmitter(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*/
59BoxEmitter::~BoxEmitter ()
60{
61  this->setSystem(NULL);
62}
63
64/**
65  @brief initializes default values of a ParitcleEmitter
66*/
67void BoxEmitter::init()
68{
69  this->setClassID(CL_BOX_EMITTER, "BoxEmitter");
70  this->setSize(1.0f,1.0f,1.0f);
71}
72
73void BoxEmitter::loadParams(const TiXmlElement* root)
74{
75  ParticleEmitter::loadParams(root);
76
77  LoadParam(root, "size", this, BoxEmitter, setSize)
78  .describe("The Size of the BoxEmitter: x, y, z")
79  .defaultValues(3, 1.0f,1.0f,1.0f);
80}
81
82void BoxEmitter::emitParticles(unsigned int count) const
83{
84  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
85
86  for (unsigned int i = 0; i < count; i++)
87  {
88    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
89    randDir.normalize();
90    randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction);
91    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
92
93    Vector extension = Vector(((float)rand()/RAND_MAX -.5)*this->size.x,
94                              ((float)rand()/RAND_MAX -.5) *this->size.y,
95                              ((float)rand()/RAND_MAX -.5) * this->size.z);
96
97
98    // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
99    randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
100    randDir.normalize();
101    Quaternion orient = Quaternion(M_PI, randDir);
102    Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
103
104    this->getSystem()->addParticle(this->getAbsCoor() + extension, velocityV, orient, moment);
105
106  }
107}
Note: See TracBrowser for help on using the repository browser.