- Timestamp:
- Nov 9, 2008, 4:28:42 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/orxonox/tools/ParticleInterface.cc
r2114 r2161 41 41 42 42 #include "GraphicsEngine.h" 43 #include "core/Core.h" 43 44 #include "core/CoreIncludes.h" 44 45 #include "util/Convert.h" … … 57 58 this->scenemanager_ = scenemanager; 58 59 this->sceneNode_ = 0; 60 this->particleSystem_ = 0; 59 61 60 62 this->bEnabled_ = true; … … 62 64 this->bAllowedByLOD_ = true; 63 65 64 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 65 this->particleSystem_->setSpeedFactor(1.0f); 66 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 66 if (Core::showsGraphics()) 67 { 68 try 69 { 70 this->particleSystem_ = this->scenemanager_->createParticleSystem("particles" + getConvertedValue<unsigned int, std::string>(ParticleInterface::counter_s++), templateName); 71 this->particleSystem_->setSpeedFactor(1.0f); 72 // this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor()); 73 } 74 catch (...) 75 { 76 COUT(1) << "Error: Couln't load particle system \"" << templateName << "\"" << std::endl; 77 this->particleSystem_ = 0; 78 } 79 } 67 80 68 81 this->setDetailLevel((unsigned int)detaillevel); … … 71 84 ParticleInterface::~ParticleInterface() 72 85 { 73 this->particleSystem_->removeAllEmitters(); 74 this->detachFromSceneNode(); 75 this->scenemanager_->destroyParticleSystem(particleSystem_); 86 if (this->particleSystem_) 87 { 88 this->particleSystem_->removeAllEmitters(); 89 this->detachFromSceneNode(); 90 this->scenemanager_->destroyParticleSystem(this->particleSystem_); 91 } 76 92 } 77 93 … … 81 97 this->detachFromSceneNode(); 82 98 83 this->sceneNode_ = sceneNode; 84 this->sceneNode_->attachObject(this->particleSystem_); 99 if (this->particleSystem_) 100 { 101 this->sceneNode_ = sceneNode; 102 this->sceneNode_->attachObject(this->particleSystem_); 103 } 85 104 } 86 105 … … 89 108 if (this->sceneNode_) 90 109 { 91 this->sceneNode_->detachObject(this->particleSystem_); 110 if (this->particleSystem_) 111 this->sceneNode_->detachObject(this->particleSystem_); 92 112 this->sceneNode_ = 0; 93 113 } … … 96 116 Ogre::ParticleEmitter* ParticleInterface::createNewEmitter() 97 117 { 98 if (this->particleSystem_ ->getNumEmitters() > 0)118 if (this->particleSystem_ && this->particleSystem_->getNumEmitters() > 0) 99 119 { 100 120 Ogre::ParticleEmitter* newemitter = this->particleSystem_->addEmitter(this->particleSystem_->getEmitter(0)->getType()); … … 107 127 Ogre::ParticleEmitter* ParticleInterface::getEmitter(unsigned int emitterNr) const 108 128 { 109 if ( emitterNr < this->particleSystem_->getNumEmitters())129 if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) 110 130 return this->particleSystem_->getEmitter(emitterNr); 111 131 else … … 114 134 void ParticleInterface::removeEmitter(unsigned int emitterNr) 115 135 { 116 if ( emitterNr < this->particleSystem_->getNumEmitters())136 if (this->particleSystem_ && (emitterNr < this->particleSystem_->getNumEmitters())) 117 137 this->particleSystem_->removeEmitter(emitterNr); 118 138 } 119 139 void ParticleInterface::removeAllEmitters() 120 140 { 121 this->particleSystem_->removeAllEmitters(); 141 if (this->particleSystem_) 142 this->particleSystem_->removeAllEmitters(); 122 143 } 123 144 unsigned int ParticleInterface::getNumEmitters() const 124 145 { 125 return this->particleSystem_->getNumEmitters(); 146 if (this->particleSystem_) 147 return this->particleSystem_->getNumEmitters(); 148 else 149 return 0; 126 150 } 127 151 128 152 Ogre::ParticleAffector* ParticleInterface::addAffector(const std::string& name) 129 153 { 130 return this->particleSystem_->addAffector(name); 154 if (this->particleSystem_) 155 return this->particleSystem_->addAffector(name); 156 else 157 return 0; 131 158 } 132 159 Ogre::ParticleAffector* ParticleInterface::getAffector(unsigned int affectorNr) const 133 160 { 134 if ( affectorNr < this->particleSystem_->getNumAffectors())161 if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) 135 162 return this->particleSystem_->getAffector(affectorNr); 136 163 else … … 139 166 void ParticleInterface::removeAffector(unsigned int affectorNr) 140 167 { 141 if ( affectorNr < this->particleSystem_->getNumAffectors())168 if (this->particleSystem_ && (affectorNr < this->particleSystem_->getNumAffectors())) 142 169 this->particleSystem_->removeAffector(affectorNr); 143 170 } 144 171 void ParticleInterface::removeAllAffectors() 145 172 { 146 this->particleSystem_->removeAllAffectors(); 173 if (this->particleSystem_) 174 this->particleSystem_->removeAllAffectors(); 147 175 } 148 176 unsigned int ParticleInterface::getNumAffectors() const 149 177 { 150 return this->particleSystem_->getNumAffectors(); 178 if (this->particleSystem_) 179 return this->particleSystem_->getNumAffectors(); 180 else 181 return 0; 151 182 } 152 183 … … 155 186 this->bEnabled_ = enable; 156 187 157 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 158 this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); 188 if (this->particleSystem_) 189 for (unsigned int i = 0; i < this->particleSystem_->getNumEmitters(); i++) 190 this->particleSystem_->getEmitter(i)->setEnabled(this->bEnabled_ && this->bAllowedByLOD_); 159 191 } 160 192 … … 163 195 this->bVisible_ = visible; 164 196 165 this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); 197 if (this->particleSystem_) 198 this->particleSystem_->setVisible(this->bVisible_ && this->bAllowedByLOD_); 166 199 } 167 200 … … 169 202 { 170 203 this->detaillevel_ = level; 171 this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); 204 if (GraphicsEngine::getInstancePtr()) 205 this->detailLevelChanged(GraphicsEngine::getInstance().getDetailLevelParticle()); 172 206 } 173 207 … … 190 224 void ParticleInterface::setSpeedFactor(float factor) 191 225 { 192 //this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 193 this->particleSystem_->setSpeedFactor(1.0f * factor); 226 if (this->particleSystem_) 227 { 228 // this->particleSystem_->setSpeedFactor(Orxonox::getInstance().getTimeFactor() * factor); 229 this->particleSystem_->setSpeedFactor(1.0f * factor); 230 } 194 231 } 195 232 float ParticleInterface::getSpeedFactor() const 196 233 { 197 //return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 198 return (this->particleSystem_->getSpeedFactor() / 1.0f); 234 if (this->particleSystem_) 235 { 236 // return (this->particleSystem_->getSpeedFactor() / Orxonox::getInstance().getTimeFactor()); 237 return (this->particleSystem_->getSpeedFactor() / 1.0f); 238 } 239 else 240 return 1.0f; 199 241 } 200 242 201 243 bool ParticleInterface::getKeepParticlesInLocalSpace() const 202 244 { 203 return this->particleSystem_->getKeepParticlesInLocalSpace(); 245 if (this->particleSystem_) 246 return this->particleSystem_->getKeepParticlesInLocalSpace(); 247 else 248 return false; 204 249 } 205 250 void ParticleInterface::setKeepParticlesInLocalSpace(bool keep) 206 251 { 207 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 252 if (this->particleSystem_) 253 this->particleSystem_->setKeepParticlesInLocalSpace(keep); 208 254 } 209 255 }
Note: See TracChangeset
for help on using the changeset viewer.