Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/particles/plane_emitter.cc @ 7266

Last change on this file since 7266 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: 2.9 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
[6873]18#include "plane_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
[6873]30CREATE_FACTORY(PlaneEmitter, CL_PLANE_EMITTER);
[4725]31
[3926]32/**
[4836]33 *  standard constructor
[3926]34*/
[6873]35PlaneEmitter::PlaneEmitter(const Vector2D& size, float emissionRate, float velocity, float angle)
[6825]36    :  ParticleEmitter(emissionRate, velocity, angle)
[3926]37{
[4726]38  this->init();
[6823]39  this->setSize(size);
[4437]40}
41
[4478]42/**
[6873]43 *  constructs and loads a PlaneEmitter from a XML-element
[4836]44 * @param root the XML-element to load from
[4478]45*/
[6873]46PlaneEmitter::PlaneEmitter(const TiXmlElement* root)
[6823]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*/
[6873]60PlaneEmitter::~PlaneEmitter ()
[3935]61{
[6623]62  this->setSystem(NULL);
[3935]63}
[3929]64
[4478]65/**
[6623]66  @brief initializes default values of a ParitcleEmitter
[4726]67*/
[6873]68void PlaneEmitter::init()
[4726]69{
[6873]70  this->setClassID(CL_PLANE_EMITTER, "PlaneEmitter");
71  this->setSize(1.0f, 1.0f);
[4726]72}
73
[6873]74void PlaneEmitter::loadParams(const TiXmlElement* root)
[4437]75{
[6823]76  ParticleEmitter::loadParams(root);
77
[6873]78  LoadParam(root, "size", this, PlaneEmitter, setSize)
79  .describe("The Size of the PlaneEmitter: x, y")
[7198]80  .defaultValues(1.0f,1.0f);
[6823]81}
82
[6873]83void PlaneEmitter::setSize(float x, float y)
[6826]84{
[6873]85  this->size = Vector2D(x, y);
[6826]86}
87
88
[6873]89void PlaneEmitter::emitParticles(unsigned int count) const
[6823]90{
[6822]91  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
[3929]92
[6826]93  Vector xDir = this->getAbsDirX() * this->size.x;
[6873]94  Vector yDir = this->getAbsDirZ() * this->size.y;
95  Vector zDir = this->getAbsDirY();
[6826]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();
[6873]101    randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(zDir);
[6822]102    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
[4597]103
[6873]104    Vector plane = this->getAbsCoor() +
[6826]105        xDir * ((float)rand()/RAND_MAX -.5) +
[6873]106        yDir * ((float)rand()/RAND_MAX -.5);
[6823]107
[6822]108    // ROTATIONAL CALCULATION (this must not be done for all types of particles.)
109    randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
110    randDir.normalize();
111    Quaternion orient = Quaternion(M_PI, randDir);
112    Quaternion moment = Quaternion(this->momentum + this->momentumRandom, randDir);
[4176]113
[6873]114    this->getSystem()->addParticle(plane, velocityV, orient, moment);
[4176]115
[3950]116  }
[3932]117}
Note: See TracBrowser for help on using the repository browser.