Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7627 was 7198, checked in by bensch, 19 years ago

orxonox/trunk: new Default Values… they now too are in MultiType instead of (count, …) or (count, va_arg) style

File size: 3.0 KB
RevLine 
[4597]1/*
[3926]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:
[3938]12   main-programmer: Benjamin Grauer
[3926]13   co-programmer: Patrick Boenzli
14*/
15
[5357]16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
[3926]17
[6823]18#include "box_emitter.h"
[3926]19
[3932]20#include "particle_system.h"
21
[7193]22#include "util/loading/load_param.h"
23#include "util/loading/factory.h"
[4381]24#include "debug.h"
25#include "stdlibincl.h"
26
[3926]27using namespace std;
28
29
[6823]30CREATE_FACTORY(BoxEmitter, CL_BOX_EMITTER);
[4725]31
[3926]32/**
[4836]33 *  standard constructor
[3926]34*/
[6825]35BoxEmitter::BoxEmitter(const Vector& size, float emissionRate, float velocity, float angle)
36    :  ParticleEmitter(emissionRate, velocity, angle)
[3926]37{
[4726]38  this->init();
[6823]39  this->setSize(size);
[4437]40}
41
[4478]42/**
[6823]43 *  constructs and loads a BoxEmitter from a XML-element
[4836]44 * @param root the XML-element to load from
[4478]45*/
[6823]46BoxEmitter::BoxEmitter(const TiXmlElement* root)
47    : ParticleEmitter()
[4437]48{
[4726]49  this->init();
[4338]50
[6823]51  if (root != NULL)
52    this->loadParams(root);
[3926]53}
54
55/**
[4836]56 *  standard destructor
[3926]57
[4496]58   removes the EmitterSystem from the ParticleEngine
[3926]59*/
[6823]60BoxEmitter::~BoxEmitter ()
[3935]61{
[6623]62  this->setSystem(NULL);
[3935]63}
[3929]64
[4478]65/**
[6623]66  @brief initializes default values of a ParitcleEmitter
[4726]67*/
[6823]68void BoxEmitter::init()
[4726]69{
[6823]70  this->setClassID(CL_BOX_EMITTER, "BoxEmitter");
71  this->setSize(1.0f,1.0f,1.0f);
[4726]72}
73
[6823]74void BoxEmitter::loadParams(const TiXmlElement* root)
[4437]75{
[6823]76  ParticleEmitter::loadParams(root);
77
78  LoadParam(root, "size", this, BoxEmitter, setSize)
79  .describe("The Size of the BoxEmitter: x, y, z")
[7198]80  .defaultValues(1.0f,1.0f,1.0f);
[6823]81}
82
[6826]83void BoxEmitter::setSize(float x, float y, float z)
84{
85  this->size = Vector (x,y,z);
86}
87
88
[6823]89void BoxEmitter::emitParticles(unsigned int count) const
90{
[6822]91  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
[3929]92
[6826]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
[6822]97  for (unsigned int i = 0; i < count; i++)
[3950]98  {
[6822]99    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
100    randDir.normalize();
[6825]101    randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->getAbsDirX());
[6822]102    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
[4597]103
[6826]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);
[6823]108
[6822]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);
[4176]114
[6826]115    this->getSystem()->addParticle(box, velocityV, orient, moment);
[4176]116
[3950]117  }
[3932]118}
Note: See TracBrowser for help on using the repository browser.