Changeset 6623 in orxonox.OLD for trunk/src/lib/particles
- Timestamp:
- Jan 20, 2006, 12:54:20 AM (19 years ago)
- Location:
- trunk/src/lib/particles
- Files:
-
- 6 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/particles/Makefile.am
r6621 r6623 9 9 particle_system.cc \ 10 10 sprite_particles.cc \ 11 spark_particles.cc \ 12 \ 11 13 quick_animation.cc 12 14 … … 17 19 particle_system.h \ 18 20 sprite_particles.h \ 21 spark_particles.h \ 22 \ 19 23 quick_animation.h -
trunk/src/lib/particles/particle_emitter.cc
r6620 r6623 64 64 ParticleEmitter::~ParticleEmitter () 65 65 { 66 } 67 68 /** 69 \brief initializes default values of a ParitcleEmitter 66 this->setSystem(NULL); 67 } 68 69 /** 70 @brief initializes default values of a ParitcleEmitter 70 71 */ 71 72 void ParticleEmitter::init() -
trunk/src/lib/particles/particle_system.cc
r6621 r6623 44 44 45 45 this->setMaxCount(maxCount); 46 }47 48 /**49 * @brief creates a Particle System out of a XML-element50 * @param root: the XML-element to load from51 */52 ParticleSystem::ParticleSystem(const TiXmlElement* root)53 {54 this->init();55 56 this->loadParams(root);57 46 } 58 47 … … 78 67 } 79 68 80 if (this->material) 81 delete this->material; 69 while(!this->emitters.empty()) 70 { 71 this->removeEmitter(this->emitters.front()); 72 } 73 82 74 } 83 75 … … 89 81 this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem"); 90 82 91 this->material = NULL;92 83 this->setMaxCount(PARTICLE_DEFAULT_MAX_COUNT); 93 84 this->count = 0; … … 96 87 this->setConserve(1); 97 88 this->setLifeSpan(1); 98 this->glID = NULL;99 89 100 90 this->toList(OM_ENVIRON); … … 120 110 .describe("sets the Conserve factor of the Particles (1.0: they keep all their energy, 0.0:they keep no energy)"); 121 111 122 LoadParam(root, "texture", this, ParticleSystem, setMaterialTexture); 123 LoadParamXML(root, "emitter", this, ParticleSystem, addEmitterXML); 112 LoadParamXML(root, "emitters", this, ParticleSystem, loadEmitters); 124 113 125 114 LOAD_PARAM_START_CYCLE(root, element); … … 140 129 141 130 /** 131 * @brief loads the Emitters from An XML-Root 132 * @param root the XML-Element to load all emitters from 133 */ 134 void ParticleSystem::loadEmitters(const TiXmlElement* root) 135 { 136 LOAD_PARAM_START_CYCLE(root, element); 137 { 138 BaseObject* emitter = Factory::fabricate(element); 139 if (emitter->isA(CL_PARTICLE_EMITTER)) 140 this->addEmitter(dynamic_cast<ParticleEmitter*>(emitter)); 141 else 142 { 143 PRINTF(2)("Tried to load an Element of type '%s' that should be a ParticleEmitter onto '%s::%s'.\n", 144 emitter->getClassName(), this->getClassName(), this->getName()); 145 delete emitter; 146 } 147 } 148 LOAD_PARAM_END_CYCLE(element); 149 } 150 151 /** 142 152 * @param maxCount the maximum count of particles that can be emitted 143 153 */ … … 148 158 149 159 // setting properties 150 /**151 * sets the material to an external material152 * @param material: the material to set this material to.153 154 !! important if the extern material gets deleted it MUST be unregistered here or segfault !!155 */156 void ParticleSystem::setMaterial(Material* material)157 {158 this->material = material;159 }160 161 void ParticleSystem::setMaterialTexture(const char* textureFile)162 {163 if (this->material != NULL)164 this->material->setDiffuseMap(textureFile);165 }166 167 160 /** 168 161 * Sets the lifespan of newly created particles … … 237 230 emitter->getSystem()->removeEmitter(emitter); 238 231 this->emitters.push_back(emitter); 239 }240 241 void ParticleSystem::addEmitterXML(const TiXmlElement* emitterRoot)242 {243 ParticleEmitter* emitter = new ParticleEmitter(emitterRoot);244 this->addEmitter(emitter);245 232 } 246 233 -
trunk/src/lib/particles/particle_system.h
r6621 r6623 58 58 public: 59 59 ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT); 60 ParticleSystem(const TiXmlElement* root);61 60 virtual ~ParticleSystem(); 62 61 63 62 void init(); 64 63 virtual void loadParams(const TiXmlElement* root); 64 void loadEmitters(const TiXmlElement* root); 65 65 66 void setMaterial(Material* material);67 void setMaterialTexture(const char* textureFile);68 void setModel(const char* modelName = NULL);69 66 void setLifeSpan(float lifeSpan, float randomLifeSpan = 0.0); 70 67 void setConserve(float conserve); … … 76 73 void setColor(float lifeCycleTime, float red, float green, float blue, float alpha); 77 74 78 /** @returns the Material that lies on this particles */79 inline const Material* getMaterial() const { return this->material; };80 75 /** @returns the lifespan of the particles */ 81 76 inline float getLifeSpan() const { return this->lifeSpan; }; … … 92 87 93 88 void addEmitter(ParticleEmitter* emitter); 94 void addEmitterXML(const TiXmlElement* emitterRoot);95 89 void removeEmitter(ParticleEmitter* emitter); 96 90 … … 115 109 int maxCount; //!< The maximum count of Particles. 116 110 int count; //!< The current count of Particles. 117 Material* material; //!< A Material for all the Particles.118 111 Particle* particles; //!< A list of particles of this System. 119 112 Particle* deadList; //!< A list of dead Particles in the System. 120 121 GLuint* glID; //!< A List of different gl-List-ID's122 GLuint dialectCount; //!< How many different types of particles are there in the Particle System123 113 124 114 std::list<ParticleEmitter*> emitters; //!< The Emitters that do emit into this System. -
trunk/src/lib/particles/spark_particles.cc
r6622 r6623 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS 17 17 18 #include "sp rite_particles.h"18 #include "spark_particles.h" 19 19 20 20 #include "load_param.h" … … 28 28 29 29 30 CREATE_FACTORY(SpriteParticles, CL_SPRITE_PARTICLES); 31 32 SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture) 33 ->defaultValues(1, "maps/evil-flower.png"); 30 CREATE_FACTORY(SparkParticles, CL_SPARK_PARTICLES); 34 31 35 32 using namespace std; … … 38 35 * standard constructor 39 36 * @param maxCount the Count of particles in the System 40 * @param type The Type of the Sp riteParticles37 * @param type The Type of the SparkParticles 41 38 */ 42 Sp riteParticles::SpriteParticles (unsigned int maxCount)43 : ParticleSystem(maxCount)39 SparkParticles::SparkParticles (unsigned int maxCount) 40 : ParticleSystem(maxCount) 44 41 { 45 42 this->init(); … … 50 47 * @param root: the XML-element to load from 51 48 */ 52 Sp riteParticles::SpriteParticles(const TiXmlElement* root)49 SparkParticles::SparkParticles(const TiXmlElement* root) 53 50 { 54 51 this->init(); 55 52 56 this->loadParams(root); 53 if (root != NULL) 54 this->loadParams(root); 57 55 } 58 56 … … 60 58 * standard deconstructor 61 59 */ 62 Sp riteParticles::~SpriteParticles()60 SparkParticles::~SparkParticles() 63 61 { 64 62 // deleting all the living Particles … … 80 78 81 79 /** 82 * @brief initializes the Sp riteParticles with default values80 * @brief initializes the SparkParticles with default values 83 81 */ 84 void Sp riteParticles::init()82 void SparkParticles::init() 85 83 { 86 this->setClassID(CL_SP RITE_PARTICLES, "SpriteParticles");84 this->setClassID(CL_SPARK_PARTICLES, "SparkParticles"); 87 85 88 86 this->material = NULL; … … 94 92 * @param root the XML-element to load from. 95 93 */ 96 void Sp riteParticles::loadParams(const TiXmlElement* root)94 void SparkParticles::loadParams(const TiXmlElement* root) 97 95 { 98 SpriteParticles::loadParams(root); 99 100 LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture); 101 } 102 103 // setting properties 104 /** 105 * @brief sets the material to an external material 106 * @param material: the material to set this material to. 107 * 108 * !! important if the extern material gets deleted it MUST be unregistered here or segfault !! 109 */ 110 void SpriteParticles::setMaterial(Material* material) 111 { 112 this->material = *material; 113 } 114 115 void SpriteParticles::setMaterialTexture(const char* textureFile) 116 { 117 this->material.setDiffuseMap(textureFile); 96 ParticleSystem::loadParams(root); 118 97 } 119 98 … … 125 104 * This is just the fastest Way to do this, but will most likely be changed in the future. 126 105 */ 127 void Sp riteParticles::draw() const106 void SparkParticles::draw() const 128 107 { 129 108 glPushAttrib(GL_ENABLE_BIT); … … 131 110 Particle* drawPart = particles; 132 111 133 glDisable(GL_LIGHTING);134 glMatrixMode(GL_MODELVIEW);135 112 glDepthMask(GL_FALSE); 136 113 137 material.select(); 138 glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 114 glDisable(GL_LIGHTING); 115 glEnable(GL_LINE_SMOOTH); 116 glEnable(GL_BLEND); 139 117 140 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 141 142 118 glBegin(GL_LINES); 143 119 while (likely(drawPart != NULL)) 144 120 { 145 121 glColor4fv(drawPart->color); 146 //! @todo implement a faster code for the look-at Camera algorithm. 147 148 const PNode* camera = State::getCamera(); //!< @todo MUST be different 149 Vector cameraPos = camera->getAbsCoor(); 150 Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor(); 151 Vector view = cameraTargetPos - cameraPos; 152 Vector up = Vector(0, 1, 0); 153 up = camera->getAbsDir().apply(up); 154 Vector h = up.cross(view); 155 Vector v = h.cross(view); 156 h.normalize(); 157 v.normalize(); 158 v *= .5 * drawPart->radius; 159 h *= .5 * drawPart->radius; 160 161 glBegin(GL_TRIANGLE_STRIP); 162 glTexCoord2i(1, 1); 163 glVertex3f(drawPart->position.x - h.x - v.x, 164 drawPart->position.y - h.y - v.y, 165 drawPart->position.z - h.z - v.z); 166 glTexCoord2i(0, 1); 167 glVertex3f(drawPart->position.x - h.x + v.x, 168 drawPart->position.y - h.y + v.y, 169 drawPart->position.z - h.z + v.z); 170 glTexCoord2i(1, 0); 171 glVertex3f(drawPart->position.x + h.x - v.x, 172 drawPart->position.y + h.y - v.y, 173 drawPart->position.z + h.z - v.z); 174 glTexCoord2i(0, 0); 175 glVertex3f(drawPart->position.x + h.x + v.x, 176 drawPart->position.y + h.y + v.y, 177 drawPart->position.z + h.z + v.z); 178 179 glEnd(); 180 122 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 123 glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius, 124 drawPart->position.y - drawPart->velocity.y * drawPart->radius, 125 drawPart->position.z - drawPart->velocity.z * drawPart->radius); 181 126 drawPart = drawPart->next; 182 127 } 128 glEnd(); 129 183 130 glDepthMask(GL_TRUE); 184 131 glPopAttrib(); -
trunk/src/lib/particles/spark_particles.h
r6622 r6623 1 1 /*! 2 * @file particle_system.h2 * @file spark_particles.h 3 3 4 4 */ 5 5 6 #ifndef _SP RITE_PARTICLE_SYSTEM_H7 #define _SP RITE_PARTICLE_SYSTEM_H6 #ifndef _SPARK_PARTICLE_SYSTEM_H 7 #define _SPARK_PARTICLE_SYSTEM_H 8 8 9 9 #include "particle_system.h" … … 11 11 12 12 //! A class to handle ParticleSystems 13 class Sp riteParticles : public ParticleSystem13 class SparkParticles : public ParticleSystem 14 14 { 15 15 16 16 public: 17 Sp riteParticles(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT);18 Sp riteParticles(const TiXmlElement* root);19 virtual ~Sp riteParticles();17 SparkParticles(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT); 18 SparkParticles(const TiXmlElement* root); 19 virtual ~SparkParticles(); 20 20 21 21 virtual void loadParams(const TiXmlElement* root); 22 22 23 void setMaterial(Material* material);24 void setMaterialTexture(const char* textureFile);25 26 /** @returns the Material that lies on this particles */27 inline const Material* getMaterial() const { return &this->material; };28 29 23 virtual void draw() const; 30 31 void debug() const;32 24 33 25 private: … … 38 30 }; 39 31 40 #endif /* _SP RITE_PARTICLE_SYSTEM_H */32 #endif /* _SPARK_PARTICLE_SYSTEM_H */ -
trunk/src/lib/particles/sprite_particles.cc
r6621 r6623 53 53 { 54 54 this->init(); 55 56 this->loadParams(root);55 if (root != NULL) 56 this->loadParams(root); 57 57 } 58 58 … … 96 96 void SpriteParticles::loadParams(const TiXmlElement* root) 97 97 { 98 SpriteParticles::loadParams(root);98 ParticleSystem::loadParams(root); 99 99 100 100 LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture); -
trunk/src/lib/particles/sprite_particles.h
r6621 r6623 1 1 /*! 2 * @file particle_system.h2 * @file sprite_particles.h 3 3 4 4 */ … … 29 29 virtual void draw() const; 30 30 31 void debug() const;32 33 31 private: 34 32 void init();
Note: See TracChangeset
for help on using the changeset viewer.