Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/new_class_id/src/lib/particles/plane_emitter.cc @ 9716

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

more renamings

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
[9716]26#include "class_id_DEPRECATED.h"
[3926]27
[9715]28ObjectListDefinitionID(PlaneEmitter, CL_PLANE_EMITTER);
[9709]29CREATE_FACTORY(PlaneEmitter);
[4725]30
[3926]31/**
[4836]32 *  standard constructor
[3926]33*/
[6873]34PlaneEmitter::PlaneEmitter(const Vector2D& size, float emissionRate, float velocity, float angle)
[6825]35    :  ParticleEmitter(emissionRate, velocity, angle)
[3926]36{
[4726]37  this->init();
[6823]38  this->setSize(size);
[4437]39}
40
[4478]41/**
[6873]42 *  constructs and loads a PlaneEmitter from a XML-element
[4836]43 * @param root the XML-element to load from
[4478]44*/
[6873]45PlaneEmitter::PlaneEmitter(const TiXmlElement* root)
[6823]46    : ParticleEmitter()
[4437]47{
[4726]48  this->init();
[4338]49
[6823]50  if (root != NULL)
51    this->loadParams(root);
[3926]52}
53
54/**
[4836]55 *  standard destructor
[3926]56
[4496]57   removes the EmitterSystem from the ParticleEngine
[3926]58*/
[6873]59PlaneEmitter::~PlaneEmitter ()
[3935]60{
[6623]61  this->setSystem(NULL);
[3935]62}
[3929]63
[4478]64/**
[6623]65  @brief initializes default values of a ParitcleEmitter
[4726]66*/
[6873]67void PlaneEmitter::init()
[4726]68{
[9686]69  this->registerObject(this, PlaneEmitter::_objectList);
[6873]70  this->setSize(1.0f, 1.0f);
[4726]71}
72
[6873]73void PlaneEmitter::loadParams(const TiXmlElement* root)
[4437]74{
[6823]75  ParticleEmitter::loadParams(root);
76
[6873]77  LoadParam(root, "size", this, PlaneEmitter, setSize)
78  .describe("The Size of the PlaneEmitter: x, y")
[7198]79  .defaultValues(1.0f,1.0f);
[6823]80}
81
[6873]82void PlaneEmitter::setSize(float x, float y)
[6826]83{
[6873]84  this->size = Vector2D(x, y);
[6826]85}
86
87
[6873]88void PlaneEmitter::emitParticles(unsigned int count) const
[6823]89{
[6822]90  Vector inheritVelocity = this->getVelocity() * this->inheritSpeed;
[3929]91
[6826]92  Vector xDir = this->getAbsDirX() * this->size.x;
[6873]93  Vector yDir = this->getAbsDirZ() * this->size.y;
94  Vector zDir = this->getAbsDirY();
[6826]95
[6822]96  for (unsigned int i = 0; i < count; i++)
[3950]97  {
[6822]98    Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2);
99    randDir.normalize();
[6873]100    randDir = (Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(zDir);
[6822]101    Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity;
[4597]102
[6873]103    Vector plane = this->getAbsCoor() +
[6826]104        xDir * ((float)rand()/RAND_MAX -.5) +
[6873]105        yDir * ((float)rand()/RAND_MAX -.5);
[6823]106
[6822]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);
[4176]112
[6873]113    this->getSystem()->addParticle(plane, velocityV, orient, moment);
[4176]114
[3950]115  }
[3932]116}
Note: See TracBrowser for help on using the repository browser.