Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain.old/src/lib/particles/box_emitter.cc @ 10642

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

orxonox/trunk: merged the proxy back

merged with commandsvn merge -r9346:HEAD https://svn.orxonox.net/orxonox/branches/proxy .

no conflicts

File size: 2.9 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 "util/loading/load_param.h"
23#include "util/loading/factory.h"
24#include "debug.h"
25#include "stdlibincl.h"
26
27
28
29
30CREATE_FACTORY(BoxEmitter, CL_BOX_EMITTER);
31
32/**
33 *  standard constructor
34*/
35BoxEmitter::BoxEmitter(const Vector& size, float emissionRate, float velocity, float angle)
36    :  ParticleEmitter(emissionRate, velocity, angle)
37{
38  this->init();
39  this->setSize(size);
40}
41
42/**
43 *  constructs and loads a BoxEmitter from a XML-element
44 * @param root the XML-element to load from
45*/
46BoxEmitter::BoxEmitter(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*/
60BoxEmitter::~BoxEmitter ()
61{
62  this->setSystem(NULL);
63}
64
65/**
66  @brief initializes default values of a ParitcleEmitter
67*/
68void BoxEmitter::init()
69{
70  this->setClassID(CL_BOX_EMITTER, "BoxEmitter");
71  this->setSize(1.0f,1.0f,1.0f);
72}
73
74void BoxEmitter::loadParams(const TiXmlElement* root)
75{
76  ParticleEmitter::loadParams(root);
77
78  LoadParam(root, "size", this, BoxEmitter, setSize)
79  .describe("The Size of the BoxEmitter: x, y, z")
80  .defaultValues(1.0f,1.0f,1.0f);
81}
82
83void BoxEmitter::setSize(float x, float y, float z)
84{
85  this->size = Vector (x,y,z);
86}
87
88
89void BoxEmitter::emitParticles(unsigned int count) const
90{
91  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
92
93  Vector xDir = this->getAbsDirX() * this->size.x;
94  Vector yDir = this->getAbsDirY() * this->size.y;
95  Vector zDir = this->getAbsDirZ() * this->size.z;
96
97  for (unsigned int i = 0; i < count; i++)
98  {
99    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
100    randDir.normalize();
101    randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->getAbsDirX());
102    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
103
104    Vector box = this->getAbsCoor() +
105        xDir * ((float)rand()/RAND_MAX -.5) +
106        yDir * ((float)rand()/RAND_MAX -.5) +
107        zDir * ((float)rand()/RAND_MAX -.5);
108
109    // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
110    randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
111    randDir.normalize();
112    Quaternion orient = Quaternion(M_PI, randDir);
113    Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
114
115    this->getSystem()->addParticle(box, velocityV, orient, moment);
116
117  }
118}
Note: See TracBrowser for help on using the repository browser.