Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/particles/plane_emitter.cc @ 9968

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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 "plane_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_DEPRECATED.h"
27
28ObjectListDefinitionID(PlaneEmitter, CL_PLANE_EMITTER);
29CREATE_FACTORY(PlaneEmitter);
30
31/**
32 *  standard constructor
33*/
34PlaneEmitter::PlaneEmitter(const Vector2D& size, float emissionRate, float velocity, float angle)
35    :  ParticleEmitter(emissionRate, velocity, angle)
36{
37  this->init();
38  this->setSize(size);
39}
40
41/**
42 *  constructs and loads a PlaneEmitter from a XML-element
43 * @param root the XML-element to load from
44*/
45PlaneEmitter::PlaneEmitter(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*/
59PlaneEmitter::~PlaneEmitter ()
60{
61  this->setSystem(NULL);
62}
63
64/**
65  @brief initializes default values of a ParitcleEmitter
66*/
67void PlaneEmitter::init()
68{
69  this->registerObject(this, PlaneEmitter::_objectList);
70  this->setSize(1.0f, 1.0f);
71}
72
73void PlaneEmitter::loadParams(const TiXmlElement* root)
74{
75  ParticleEmitter::loadParams(root);
76
77  LoadParam(root, "size", this, PlaneEmitter, setSize)
78  .describe("The Size of the PlaneEmitter: x, y")
79  .defaultValues(1.0f,1.0f);
80}
81
82void PlaneEmitter::setSize(float x, float y)
83{
84  this->size = Vector2D(x, y);
85}
86
87
88void PlaneEmitter::emitParticles(unsigned int count) const
89{
90  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
91
92  Vector xDir = this->getAbsDirX() * this->size.x;
93  Vector yDir = this->getAbsDirZ() * this->size.y;
94  Vector zDir = this->getAbsDirY();
95
96  for (unsigned int i = 0; i < count; i++)
97  {
98    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
99    randDir.normalize();
100    randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(zDir);
101    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
102
103    Vector plane = this->getAbsCoor() +
104        xDir * ((float)rand()/RAND_MAX -.5) +
105        yDir * ((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(plane, velocityV, orient, moment);
114
115  }
116}
Note: See TracBrowser for help on using the repository browser.