Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/particles/box_emitter.cc @ 9693

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

new_class_id: many more classes done

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