Changeset 6629 in orxonox.OLD for trunk/src/lib/particles
- Timestamp:
- Jan 20, 2006, 8:11:04 PM (19 years ago)
- Location:
- trunk/src/lib/particles
- Files:
-
- 4 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/particles/Makefile.am
r6623 r6629 10 10 sprite_particles.cc \ 11 11 spark_particles.cc \ 12 model_particles.cc \ 12 13 \ 13 14 quick_animation.cc … … 20 21 sprite_particles.h \ 21 22 spark_particles.h \ 23 model_particles.h \ 22 24 \ 23 25 quick_animation.h -
trunk/src/lib/particles/model_particles.cc
r6628 r6629 16 16 #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS 17 17 18 #include " sprite_particles.h"18 #include "model_particles.h" 19 19 20 20 #include "load_param.h" … … 28 28 29 29 30 CREATE_FACTORY( SpriteParticles, CL_SPRITE_PARTICLES);30 CREATE_FACTORY(ModelParticles, CL_MODEL_PARTICLES); 31 31 32 SHELL_COMMAND(texture, SpriteParticles, setMaterialTexture)33 32 SHELL_COMMAND(texture, ModelParticles, setMaterialTexture) 33 ->defaultValues(1, "maps/evil-flower.png"); 34 34 35 35 using namespace std; … … 38 38 * standard constructor 39 39 * @param maxCount the Count of particles in the System 40 * @param type The Type of the SpriteParticles40 * @param type The Type of the ModelParticles 41 41 */ 42 SpriteParticles::SpriteParticles (unsigned int maxCount)43 : ParticleSystem(maxCount)42 ModelParticles::ModelParticles (unsigned int maxCount) 43 : ParticleSystem(maxCount) 44 44 { 45 45 this->init(); … … 50 50 * @param root: the XML-element to load from 51 51 */ 52 SpriteParticles::SpriteParticles(const TiXmlElement* root)52 ModelParticles::ModelParticles(const TiXmlElement* root) 53 53 { 54 54 this->init(); … … 60 60 * standard deconstructor 61 61 */ 62 SpriteParticles::~SpriteParticles()62 ModelParticles::~ModelParticles() 63 63 { 64 64 // deleting all the living Particles … … 80 80 81 81 /** 82 * @brief initializes the SpriteParticles with default values82 * @brief initializes the ModelParticles with default values 83 83 */ 84 void SpriteParticles::init()84 void ModelParticles::init() 85 85 { 86 this->setClassID(CL_ SPRITE_PARTICLES, "SpriteParticles");86 this->setClassID(CL_MODEL_PARTICLES, "ModelParticles"); 87 87 88 88 this->material.setDiffuseMap("maps/radial-trans-noise.png"); … … 94 94 * @param root the XML-element to load from. 95 95 */ 96 void SpriteParticles::loadParams(const TiXmlElement* root)96 void ModelParticles::loadParams(const TiXmlElement* root) 97 97 { 98 98 ParticleSystem::loadParams(root); 99 99 100 LoadParam(root, "texture", this, SpriteParticles, setMaterialTexture);100 LoadParam(root, "texture", this, ModelParticles, setMaterialTexture); 101 101 } 102 102 103 103 /** 104 104 * @brief sets the Texutre that is placed onto the particles 105 * @param textureFile the Texture to load onto these SpriteParticles105 * @param textureFile the Texture to load onto these ModelParticles 106 106 */ 107 void SpriteParticles::setMaterialTexture(const char* textureFile)107 void ModelParticles::setMaterialTexture(const char* textureFile) 108 108 { 109 109 this->material.setDiffuseMap(textureFile); … … 117 117 * This is just the fastest Way to do this, but will most likely be changed in the future. 118 118 */ 119 void SpriteParticles::draw() const119 void ModelParticles::draw() const 120 120 { 121 121 glPushAttrib(GL_ENABLE_BIT); 122 123 122 Particle* drawPart = particles; 124 123 … … 128 127 glDisable(GL_LIGHTING); 129 128 glMatrixMode(GL_MODELVIEW); 130 glDepthMask(GL_FALSE);131 129 132 material.select();130 this->material.select(); 133 131 glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA); 134 132 135 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);133 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 136 134 135 if (likely(this->getModel() != NULL)) 136 while (likely(drawPart != NULL)) 137 { 138 glPushMatrix(); 139 glMatrixMode(GL_MODELVIEW); 140 /* move */ 141 glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z); 142 /* scale */ 143 glScalef(drawPart->radius, drawPart->radius, drawPart->radius); 144 /* rotate */ 145 Vector tmpRot = drawPart->orientation.getSpacialAxis(); 146 glRotatef (drawPart->orientation.getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); 137 147 138 while (likely(drawPart != NULL)) 139 { 140 glColor4fv(drawPart->color); 141 //! @todo implement a faster code for the look-at Camera algorithm. 148 this->getModel()->draw(); 142 149 143 const PNode* camera = State::getCamera(); //!< @todo MUST be different 144 Vector cameraPos = camera->getAbsCoor(); 145 Vector cameraTargetPos = State::getCameraTarget()->getAbsCoor(); 146 Vector view = cameraTargetPos - cameraPos; 147 Vector up = Vector(0, 1, 0); 148 up = camera->getAbsDir().apply(up); 149 Vector h = up.cross(view); 150 Vector v = h.cross(view); 151 h.normalize(); 152 v.normalize(); 153 v *= .5 * drawPart->radius; 154 h *= .5 * drawPart->radius; 155 156 glBegin(GL_TRIANGLE_STRIP); 157 glTexCoord2i(1, 1); 158 glVertex3f(drawPart->position.x - h.x - v.x, 159 drawPart->position.y - h.y - v.y, 160 drawPart->position.z - h.z - v.z); 161 glTexCoord2i(0, 1); 162 glVertex3f(drawPart->position.x - h.x + v.x, 163 drawPart->position.y - h.y + v.y, 164 drawPart->position.z - h.z + v.z); 165 glTexCoord2i(1, 0); 166 glVertex3f(drawPart->position.x + h.x - v.x, 167 drawPart->position.y + h.y - v.y, 168 drawPart->position.z + h.z - v.z); 169 glTexCoord2i(0, 0); 170 glVertex3f(drawPart->position.x + h.x + v.x, 171 drawPart->position.y + h.y + v.y, 172 drawPart->position.z + h.z + v.z); 173 174 glEnd(); 175 176 drawPart = drawPart->next; 177 } 178 glDepthMask(GL_TRUE); 150 glPopMatrix(); 151 drawPart = drawPart->next; 152 } 153 else 154 PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getName()); 179 155 glPopAttrib(); 180 156 } -
trunk/src/lib/particles/model_particles.h
r6628 r6629 1 1 /*! 2 * @file sprite_particles.h2 * @file model_particles.h 3 3 4 4 */ 5 5 6 #ifndef _ SPRITE_PARTICLE_SYSTEM_H7 #define _ SPRITE_PARTICLE_SYSTEM_H6 #ifndef _MODEL_PARTICLE_SYSTEM_H 7 #define _MODEL_PARTICLE_SYSTEM_H 8 8 9 9 #include "particle_system.h" … … 11 11 12 12 //! A class to handle ParticleSystems 13 class SpriteParticles : public ParticleSystem13 class ModelParticles : public ParticleSystem 14 14 { 15 16 15 public: 17 SpriteParticles(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT);18 SpriteParticles(const TiXmlElement* root);19 virtual ~ SpriteParticles();16 ModelParticles(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT); 17 ModelParticles(const TiXmlElement* root); 18 virtual ~ModelParticles(); 20 19 21 20 virtual void loadParams(const TiXmlElement* root); … … 35 34 }; 36 35 37 #endif /* _ SPRITE_PARTICLE_SYSTEM_H */36 #endif /* _MODEL_PARTICLE_SYSTEM_H */ -
trunk/src/lib/particles/particle_system.cc
r6626 r6629 74 74 75 75 /** 76 \brief initializes the ParticleSystem with default values77 */76 * @brief initializes the ParticleSystem with default values 77 */ 78 78 void ParticleSystem::init() 79 79 { … … 125 125 } 126 126 LOAD_PARAM_END_CYCLE(element); 127 128 LoadParam(root, "precache", this, ParticleSystem, precache) 129 .describe("Precaches the ParticleSystem for %1 seconds, %2 times per Second") 130 .defaultValues(2, 1, 25); 127 131 } 128 132 … … 222 226 } 223 227 224 228 /** 229 * @brief adds an Emitter to this System. 230 * @param emitter the Emitter to add. 231 */ 225 232 void ParticleSystem::addEmitter(ParticleEmitter* emitter) 226 233 { … … 232 239 } 233 240 234 241 /** 242 * @brief removes a ParticleEmitter from this System 243 * @param emitter the Emitter to remove 244 */ 235 245 void ParticleSystem::removeEmitter(ParticleEmitter* emitter) 236 246 { … … 244 254 245 255 /** 256 * @brief does a Precaching, meaning, that the ParticleSystem(and its emitters) will be ticked force 257 * @param seconds: seconds 258 * @param ticksPerSeconds times per Second. 259 */ 260 void ParticleSystem::precache(unsigned int seconds, unsigned int ticksPerSecond) 261 { 262 PRINTF(4)("Precaching %s::%s %d seconds %d timesPerSecond\n", this->getClassName(), this->getName(), seconds, ticksPerSecond); 263 this->debug(); 264 for (unsigned int i = 0; i < seconds*ticksPerSecond; i++) 265 this->tick(1.0/(float)ticksPerSecond); 266 } 267 268 269 /** 246 270 * ticks the system. 247 271 * @param dt the time to tick all the Particles of the System … … 355 379 // switch (this->particleType) 356 380 // { 357 // case PARTICLE_SPARK:358 // glDisable(GL_LIGHTING);359 // glDepthMask(GL_FALSE);360 // //glEnable(GL_LINE_SMOOTH);361 // glEnable(GL_BLEND);362 //363 // glBegin(GL_LINES);364 // while (likely(drawPart != NULL))365 // {366 // glColor4fv(drawPart->color);367 // glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z);368 // glVertex3f(drawPart->position.x - drawPart->velocity.x * drawPart->radius,369 // drawPart->position.y - drawPart->velocity.y * drawPart->radius,370 // drawPart->position.z - drawPart->velocity.z * drawPart->radius);371 // drawPart = drawPart->next;372 // }373 // glEnd();374 // break;375 381 // 376 382 // case PARTICLE_MODEL: 377 383 // { 378 // GLfloat matrix[4][4];379 //380 // if (likely(this->getModel() != NULL))381 // while (likely(drawPart != NULL))382 // {383 // glPushMatrix();384 // glMatrixMode(GL_MODELVIEW);385 // /* move */386 // glTranslatef(drawPart->position.x, drawPart->position.y, drawPart->position.z);387 // /* scale */388 // glScalef(drawPart->radius, drawPart->radius, drawPart->radius);389 // /* rotate */390 // drawPart->orientation.matrix (matrix);391 // glMultMatrixf((float*)matrix);392 //393 // this->getModel()->draw();394 //395 // glPopMatrix();396 // drawPart = drawPart->next;397 // }398 // else399 // PRINTF(2)("no model loaded onto ParticleSystem-%s\n", this->getName());400 384 // } 401 385 // break; … … 488 472 void ParticleSystem::debug() const 489 473 { 490 PRINT(0)(" ParticleCount: %d , maximumCount: %d :: filled %d%%\n", this->count, this->maxCount, 100*this->count/this->maxCount);474 PRINT(0)(" ParticleCount: %d emitters: %d, maximumCount: %d :: filled %d%%\n", this->count, this->emitters.size(), this->maxCount, 100*this->count/this->maxCount); 491 475 if (deadList) 492 476 { -
trunk/src/lib/particles/particle_system.h
r6623 r6629 95 95 void addParticle(const Vector& position, const Vector& velocity, const Quaternion& orientation, const Quaternion& momentum, unsigned int data = 0); 96 96 97 void precache(unsigned int seconds, unsigned int ticksPerSecond = 25); 98 97 99 virtual void tick(float dt); 98 100 virtual void draw() const = 0; -
trunk/src/lib/particles/spark_particles.cc
r6626 r6629 107 107 void SparkParticles::draw() const 108 108 { 109 exit(-1);110 109 glPushAttrib(GL_ENABLE_BIT); 111 110
Note: See TracChangeset
for help on using the changeset viewer.