[360] | 1 | #include "ParticleInterface.h" |
---|
| 2 | #include <Ogre.h> |
---|
| 3 | #include <OIS/OIS.h> |
---|
| 4 | #include <CEGUI/CEGUI.h> |
---|
| 5 | #include <CEGUIRenderer.h> |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | using namespace Ogre; |
---|
| 9 | |
---|
| 10 | namespace particle { |
---|
| 11 | |
---|
| 12 | ParticleInterface::~ParticleInterface(void) |
---|
| 13 | { |
---|
| 14 | sceneManager_->destroyParticleSystem(particleSystem_); |
---|
| 15 | |
---|
| 16 | delete sceneNode_; |
---|
| 17 | delete particleSystem_; |
---|
| 18 | delete sceneManager_; |
---|
| 19 | } |
---|
| 20 | |
---|
| 21 | ParticleInterface::ParticleInterface( SceneManager *sceneManager, String name, String templateName ) |
---|
| 22 | { |
---|
| 23 | sceneManager_ = sceneManager; |
---|
| 24 | particleSystem_ = sceneManager->createParticleSystem(name, templateName); |
---|
| 25 | |
---|
| 26 | //Variabeln einlesen, Emitter1_ ist Referenz-Emitter |
---|
| 27 | velocity_ = particleSystem_->getSpeedFactor(); |
---|
| 28 | colour_ = particleSystem_->getEmitter(0)->getColour(); |
---|
| 29 | rate_ = particleSystem_->getEmitter(0)->getEmissionRate(); |
---|
| 30 | distance_ = particleSystem_->getEmitter(0)->getTimeToLive(); |
---|
| 31 | |
---|
| 32 | //Anzahl der Emitter |
---|
| 33 | numberOfEmitters_ = particleSystem_->getNumEmitters(); |
---|
| 34 | standardizeEmitters(); |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | void ParticleInterface::standardizeEmitters(void) |
---|
| 38 | { |
---|
| 39 | //Abgleichen der anderen Emitter an die Variabeln |
---|
| 40 | for (int i=1; i<numberOfEmitters_; i++) { |
---|
| 41 | particleSystem_->getEmitter(i)->setColour( colour_ ); |
---|
| 42 | particleSystem_->getEmitter(i)->setTimeToLive( distance_ ); |
---|
| 43 | particleSystem_->getEmitter(i)->setEmissionRate( rate_ ); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | void ParticleInterface::addToSceneNode( SceneNode* sceneNode ) |
---|
| 49 | { |
---|
| 50 | sceneNode_ = sceneNode; |
---|
| 51 | sceneNode_->attachObject(particleSystem_); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void ParticleInterface::dettachFromSceneNode ( void ) |
---|
| 55 | { |
---|
| 56 | sceneNode_->detachObject(particleSystem_); |
---|
| 57 | sceneNode_ = NULL; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | Real ParticleInterface::getVelocity() |
---|
| 61 | { |
---|
| 62 | return velocity_; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | void ParticleInterface::setVelocity(Real v) |
---|
| 66 | { |
---|
| 67 | velocity_ = v; |
---|
| 68 | //partikel anpassen |
---|
| 69 | particleSystem_->setSpeedFactor(v); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | int ParticleInterface::getRate() |
---|
| 73 | { |
---|
| 74 | return rate_; |
---|
| 75 | } |
---|
| 76 | void ParticleInterface::setRate(int r) |
---|
| 77 | { |
---|
| 78 | rate_ = r; |
---|
| 79 | //partikel anpassen |
---|
| 80 | for (int i=0; i<numberOfEmitters_; i++) { |
---|
| 81 | particleSystem_->getEmitter(i)->setEmissionRate(rate_); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | Real ParticleInterface::getDistance() |
---|
| 86 | { |
---|
| 87 | return distance_; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | void ParticleInterface::setDistance(Real d) |
---|
| 91 | { |
---|
| 92 | distance_ = d; |
---|
| 93 | //partikel anpassen |
---|
| 94 | for (int i=0; i<numberOfEmitters_; i++) { |
---|
| 95 | particleSystem_->getEmitter(i)->setTimeToLive(distance_); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | ColourValue ParticleInterface::getColour() |
---|
| 99 | { |
---|
| 100 | return colour_; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | void ParticleInterface::setColour(ColourValue colour) |
---|
| 104 | { |
---|
| 105 | colour_ = colour; |
---|
| 106 | //partikel anpassen |
---|
| 107 | for (int i=0; i<numberOfEmitters_; i++) { |
---|
| 108 | particleSystem_->getEmitter(i)->setColour(colour_); |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | ParticleEmitter* ParticleInterface::getEmitter( int emitterNr ) |
---|
| 113 | { |
---|
| 114 | if (!(emitterNr<numberOfEmitters_)) return NULL; |
---|
| 115 | return particleSystem_->getEmitter(emitterNr); |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | void ParticleInterface::newEmitter ( void ) |
---|
| 119 | { |
---|
| 120 | particleSystem_->addEmitter(particleSystem_->getEmitter(0)->getType()); |
---|
| 121 | numberOfEmitters_=numberOfEmitters_+1; |
---|
| 122 | particleSystem_->getEmitter(0)->copyParametersTo( particleSystem_->getEmitter(numberOfEmitters_-1) ); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | void ParticleInterface::setPositionOfEmitter ( int emitterNr, Vector3 position ) |
---|
| 126 | { |
---|
| 127 | particleSystem_->getEmitter(emitterNr)->setPosition(position); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | Vector3 ParticleInterface::getPositionOfEmitter ( int emitterNr ) |
---|
| 131 | { |
---|
| 132 | return particleSystem_->getEmitter(0)->getPosition(); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | void ParticleInterface::setDirection ( Vector3 direction ) |
---|
| 136 | { |
---|
| 137 | for(int i=0; i<numberOfEmitters_; i++) { |
---|
| 138 | particleSystem_->getEmitter(i)->setDirection(direction); |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | Vector3 ParticleInterface::getDirection ( void ) |
---|
| 144 | { |
---|
| 145 | return particleSystem_->getEmitter(0)->getDirection(); |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | void ParticleInterface::switchEnable(){ |
---|
| 149 | bool enable=(!(particleSystem_->getEmitter(0)->getEnabled())); |
---|
| 150 | for(int i=0; i<numberOfEmitters_; i++) { |
---|
| 151 | particleSystem_->getEmitter(i)->setEnabled(enable); |
---|
| 152 | } |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | } |
---|