Changeset 4597 in orxonox.OLD for orxonox/trunk/src/lib/particles
- Timestamp:
- Jun 11, 2005, 12:55:48 AM (20 years ago)
- Location:
- orxonox/trunk/src/lib/particles
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/lib/particles/particle_emitter.cc
r4496 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 31 31 \brief standard constructor 32 32 */ 33 ParticleEmitter::ParticleEmitter(const Vector& direction, float angle, float emissionRate, 34 float velocity) 35 { 33 ParticleEmitter::ParticleEmitter(const Vector& direction, float angle, float emissionRate, 34 float velocity) 35 { 36 this->setClassID(CL_PARTICLE_EMITTER, "ParticleEmitter"); 36 37 this->type = EMITTER_DOT; 37 38 this->emitterSize = 1.0; … … 64 65 removes the EmitterSystem from the ParticleEngine 65 66 */ 66 ParticleEmitter::~ParticleEmitter () 67 ParticleEmitter::~ParticleEmitter () 67 68 { 68 69 ParticleEngine::getInstance()->removeEmitter(this); … … 91 92 LoadParam<ParticleEmitter>(root, "emission-velocity", this, &ParticleEmitter::setEmissionVelocity) 92 93 .describe("How fast the particles are emittet (their initial speed)"); 93 94 94 95 LoadParam<ParticleEmitter>(root, "spread", this, &ParticleEmitter::setSpread) 95 96 .describe("The angle the particles are emitted from (angle, deviation)"); … … 224 225 float count = (dt+this->saveTime) * this->emissionRate; 225 226 this->saveTime = modff(count, &count) / this->emissionRate; 226 PRINTF(5)("emitting %f particles, saving %f seconds for the next round\n", count, this->saveTime); 227 227 PRINTF(5)("emitting %f particles, saving %f seconds for the next round\n", count, this->saveTime); 228 228 229 if (likely(count > 0)) 229 230 { 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 231 Vector inheritVelocity = this->getVelocity() * this->inheritSpeed; 232 for (int i = 0; i < count; i++) 233 // emmits from EMITTER_DOT, 234 { 235 Vector randDir = Vector(rand()-RAND_MAX/2, rand()-RAND_MAX/2, rand()-RAND_MAX/2); 236 randDir.normalize(); 237 randDir = (this->getAbsDir()*Quaternion(angle + randomAngle *((float)rand()/RAND_MAX -.5), randDir)).apply(this->direction); 238 Vector velocityV = randDir.getNormalized()*this->velocity + inheritVelocity; 239 240 // this should spread the Particles evenly. if the Emitter is moved around quickly 241 Vector equalSpread = this->getVelocity() * rand()/RAND_MAX * dt; 242 Vector extension; // the Vector for different fields. 243 244 if (this->type & 2) 245 { 246 extension = Vector(this->emitterSize * ((float)rand()/RAND_MAX -.5), 0, this->emitterSize * ((float)rand()/RAND_MAX - .5)); 247 extension = this->getAbsDir().apply(extension); 248 } 249 else if (this->type & 8) 250 { 251 extension = Vector((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * this->emitterSize; 252 } 253 254 system->addParticle(this->getAbsCoor() + extension - equalSpread, velocityV); 255 256 } 256 257 } 257 258 } -
orxonox/trunk/src/lib/particles/particle_emitter.h
r4493 r4597 1 /*! 1 /*! 2 2 \file particle_emitter.h 3 3 \brief Definition of a ParticleEmitter … … 9 9 #include "p_node.h" 10 10 11 // FORWARD DEFINITION 11 // FORWARD DEFINITION 12 12 class ParticleSystem; 13 13 class TiXmlElement; 14 14 15 15 //! The form of the Emitter to emit from 16 typedef enum EMITTER_TYPE { EMITTER_DOT = 1, 17 EMITTER_PLANE = 2, 18 EMITTER_SPHERE= 4, 19 EMITTER_CUBE = 8 }; 16 typedef enum EMITTER_TYPE 17 { 18 EMITTER_DOT = 1, 19 EMITTER_PLANE = 2, 20 EMITTER_SPHERE = 4, 21 EMITTER_CUBE = 8 22 }; 20 23 21 24 //! A class to handle an Emitter. … … 24 27 public: 25 28 ParticleEmitter(const Vector& direction, float angle = .5, 26 29 float emissionRate = 1.0, float velocity = 1.0); 27 30 ParticleEmitter(const TiXmlElement* root); 28 31 virtual ~ParticleEmitter(void); 29 32 30 33 void loadParams(const TiXmlElement* root); 31 34 -
orxonox/trunk/src/lib/particles/particle_engine.cc
r4519 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 30 30 \brief standard constructor 31 31 */ 32 ParticleEngine::ParticleEngine () 32 ParticleEngine::ParticleEngine () 33 33 { 34 34 this->setClassID(CL_PARTICLE_ENGINE, "ParticleEngine"); 35 this->setName("ParticleEngine"); 35 36 36 37 this->systemList = new tList<ParticleSystem>; … … 47 48 \brief deletes all the system, emitters, connections and Lists 48 49 */ 49 ParticleEngine::~ParticleEngine () 50 ParticleEngine::~ParticleEngine () 50 51 { 51 52 // delete all remaining systems … … 113 114 { 114 115 if (tmpConnection->emitter == emitter && tmpConnection->system == system) 115 116 117 118 119 120 116 { 117 PRINTF(2)("Connection between Emitter and System already added\n"); 118 delete tmpConIt; 119 return; 120 } 121 121 122 tmpConnection = tmpConIt->nextElement(); 122 123 } 123 124 delete tmpConIt; 124 125 125 126 126 127 … … 144 145 { 145 146 if (tmpConnection->system == system) 146 147 this->breakConnection(tmpConnection); 147 148 tmpConnection = tmpConIt->nextElement(); 148 149 } … … 165 166 { 166 167 if (tmpConnection->emitter == emitter) 167 168 this->breakConnection(tmpConnection); 168 169 tmpConnection = tmpConIt->nextElement(); 169 170 } … … 191 192 if (tmpConnection->emitter == emitter && tmpConnection->system == system) 192 193 { 193 194 195 194 this->breakConnection(tmpConnection); 195 delete tmpConIt; 196 return true; 196 197 } 197 198 tmpConnection = tmpConIt->nextElement(); … … 268 269 { 269 270 if (!strcmp(systemName, tmpSys->getName())) 270 271 272 273 271 { 272 delete tmpIt; 273 return tmpSys; 274 } 274 275 tmpSys = tmpIt->nextElement(); 275 276 } … … 291 292 count++; 292 293 if ( count == number) 293 294 295 296 294 { 295 delete tmpIt; 296 return tmpSys; 297 } 297 298 tmpSys = tmpIt->nextElement(); 298 299 } … … 312 313 { 313 314 if (!strcmp(emitterName, tmpEmit->getName())) 314 315 316 317 315 { 316 delete tmpIt; 317 return tmpEmit; 318 } 318 319 tmpEmit = tmpIt->nextElement(); 319 320 } … … 336 337 count++; 337 338 if ( count == number) 338 339 340 341 339 { 340 delete tmpIt; 341 return tmpEmit; 342 } 342 343 tmpEmit = tmpIt->nextElement(); 343 344 } … … 356 357 PRINT(0)(" Reference: %p\n", ParticleEngine::singletonRef); 357 358 PRINT(0)(" Count: Emitters: %d; Systems: %d, Connections: %d\n", 358 359 this->emitterList->getSize(), this->systemList->getSize(), this->connectionList->getSize()); 359 360 if (this->connectionList->getSize() > 0) 360 361 { … … 365 366 ParticleConnection* tmpConnection = tmpConIt->nextElement(); 366 367 while(tmpConnection) 367 368 369 370 368 { 369 PRINT(0)(" Emitter '%s' emitts into System '%s'\n", tmpConnection->emitter->getName(), tmpConnection->system->getName()); 370 tmpConnection = tmpConIt->nextElement(); 371 } 371 372 delete tmpConIt; 372 373 } … … 376 377 ParticleSystem* tmpSys = tmpIt->nextElement(); 377 378 while(tmpSys) 378 379 380 381 379 { 380 tmpSys->debug(); 381 tmpSys = tmpIt->nextElement(); 382 } 382 383 delete tmpIt; 383 384 } -
orxonox/trunk/src/lib/particles/particle_system.cc
r4515 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 41 41 { 42 42 this->setClassID(CL_PARTICLE_SYSTEM, "ParticleSystem"); 43 43 44 this->material = NULL; 44 45 this->maxCount = maxCount; … … 125 126 /** 126 127 \brief Sets the lifespan of newly created particles 127 */ 128 */ 128 129 void ParticleSystem::setLifeSpan(float lifeSpan, float randomLifeSpan) 129 130 { … … 197 198 { 198 199 Particle* tickPart = particles; // the particle to Tick 199 Particle* prevPart = NULL; // 200 Particle* prevPart = NULL; // 200 201 while (likely(tickPart != NULL)) 201 202 { 202 203 // applying force to the System. 203 204 if (likely (tickPart->mass > 0.0)) 204 205 tickPart->velocity += tickPart->extForce / tickPart->mass * dt; 205 206 206 207 // rendering new position. 207 208 tickPart->position = tickPart->position + tickPart->velocity * dt; 208 209 tickPart->radius = radiusAnim.getValue(tickPart->lifeCycle) 209 210 + randRadiusAnim.getValue(tickPart->lifeCycle) * tickPart->radiusRand; 210 211 211 212 tickPart->mass = massAnim.getValue(tickPart->lifeCycle) 212 213 213 + randMassAnim.getValue(tickPart->lifeCycle) * tickPart->massRand; 214 214 215 tickPart->extForce = Vector(0,0,0); 215 216 … … 223 224 224 225 if (this->conserve < 1.0) 225 226 tickPart->velocity = tickPart->velocity * this->conserve; 226 227 // find out if we have to delete tickPart 227 228 if (unlikely((tickPart->lifeCycle += dt/tickPart->lifeTime) >= 1.0)) 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 229 { 230 // remove the particle from the list 231 if (likely(prevPart != NULL)) 232 { 233 prevPart->next = tickPart->next; 234 tickPart->next = this->deadList; 235 this->deadList = tickPart; 236 tickPart = prevPart->next; 237 } 238 else 239 { 240 prevPart = NULL; 241 this->particles = tickPart->next; 242 tickPart->next = this->deadList; 243 this->deadList = tickPart; 244 tickPart = this->particles; 245 } 246 --this->count; 247 } 247 248 else 248 { 249 250 251 252 } 253 } 254 255 /** 249 { 250 prevPart = tickPart; 251 tickPart = tickPart->next; 252 } 253 } 254 } 255 256 /** 256 257 \brief applies some force to a Particle. 257 258 \param field the Field to apply. … … 281 282 282 283 Particle* drawPart = particles; 283 284 284 285 switch (this->particleType) 285 286 { … … 289 290 glDepthMask(GL_FALSE); 290 291 291 material->select(); 292 material->select(); 292 293 //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE); 293 294 294 295 295 296 while (likely(drawPart != NULL)) 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 297 { 298 glColor4fv(drawPart->color); 299 //! \todo implement a faster code for the look-at Camera algorithm. 300 301 const PNode* camera = State::getInstance()->getCamera(); //!< \todo MUST be different 302 Vector cameraPos = camera->getAbsCoor(); 303 Vector cameraTargetPos = State::getInstance()->getCameraTarget()->getAbsCoor(); 304 Vector view = cameraTargetPos - cameraPos; 305 Vector up = Vector(0, 1, 0); 306 up = camera->getAbsDir().apply(up); 307 Vector h = up.cross(view); 308 Vector v = h.cross(view); 309 h.normalize(); 310 v.normalize(); 311 v *= .5 * drawPart->radius; 312 h *= .5 * drawPart->radius; 313 314 glBegin(GL_TRIANGLE_STRIP); 315 glTexCoord2i(1, 1); 316 glVertex3f(drawPart->position.x - h.x - v.x, 317 drawPart->position.y - h.y - v.y, 318 drawPart->position.z - h.z - v.z); 319 glTexCoord2i(0, 1); 320 glVertex3f(drawPart->position.x - h.x + v.x, 321 drawPart->position.y - h.y + v.y, 322 drawPart->position.z - h.z + v.z); 323 glTexCoord2i(1, 0); 324 glVertex3f(drawPart->position.x + h.x - v.x, 325 drawPart->position.y + h.y - v.y, 326 drawPart->position.z + h.z - v.z); 327 glTexCoord2i(0, 0); 328 glVertex3f(drawPart->position.x + h.x + v.x, 329 drawPart->position.y + h.y + v.y, 330 drawPart->position.z + h.z + v.z); 331 332 glEnd(); 333 334 drawPart = drawPart->next; 335 } 335 336 glDepthMask(GL_TRUE); 336 337 break; … … 340 341 glBegin(GL_LINES); 341 342 while (likely(drawPart != NULL)) 342 343 344 345 346 347 348 349 343 { 344 glColor4fv(drawPart->color); 345 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 346 glVertex3f(drawPart->position.x - drawPart->velocity.x, 347 drawPart->position.y - drawPart->velocity.y, 348 drawPart->position.z - drawPart->velocity.z); 349 drawPart = drawPart->next; 350 } 350 351 glEnd(); 351 352 break; 352 353 353 354 case PARTICLE_DOT: 354 355 glBegin(GL_POINTS); 355 356 while (likely(drawPart != NULL)) 356 357 358 359 360 361 362 363 357 { 358 glColor4fv(drawPart->color); 359 360 glLineWidth(drawPart->radius); 361 362 glVertex3f(drawPart->position.x, drawPart->position.y, drawPart->position.z); 363 drawPart = drawPart->next; 364 } 364 365 glEnd(); 365 366 break; … … 380 381 // if it is the first Particle 381 382 if (unlikely(particles == NULL)) 382 383 384 385 386 387 388 389 390 391 392 393 394 383 { 384 if (likely(deadList != NULL)) 385 { 386 this->particles = this->deadList; 387 deadList = deadList->next; 388 } 389 else 390 { 391 PRINTF(5)("Generating new Particle\n"); 392 this->particles = new Particle; 393 } 394 this->particles->next = NULL; 395 } 395 396 // filling the List from the beginning 396 397 else 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 398 { 399 Particle* tmpPart; 400 if (likely(deadList != NULL)) 401 { 402 tmpPart = this->deadList; 403 deadList = deadList->next; 404 } 405 else 406 { 407 PRINTF(5)("Generating new Particle\n"); 408 tmpPart = new Particle; 409 } 410 tmpPart->next = this->particles; 411 this->particles = tmpPart; 412 } 413 413 414 particles->lifeTime = this->lifeSpan + (float)(rand()/RAND_MAX)* this->randomLifeSpan; 414 415 particles->lifeCycle = 0.0; -
orxonox/trunk/src/lib/particles/particle_system.h
r4493 r4597 1 /*! 1 /*! 2 2 \file particle_system.h 3 3 … … 23 23 24 24 //! An enumerator for the different types of particles. 25 typedef enum PARTICLE_TYPE { PARTICLE_DOT = PARTICLE_DOT_MASK, 26 PARTICLE_SPARK = PARTICLE_SPARK_MASK, 27 PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, 28 PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, 29 PARTICLE_MODEL = PARTICLE_MODEL_MASK, 30 PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK }; 25 typedef enum PARTICLE_TYPE 26 { 27 PARTICLE_DOT = PARTICLE_DOT_MASK, 28 PARTICLE_SPARK = PARTICLE_SPARK_MASK, 29 PARTICLE_SPRITE = PARTICLE_SPRITE_MASK, 30 PARTICLE_MULTI_SPRITE = PARTICLE_SPRITE_MASK | PARTICLE_MULTI_MASK, 31 PARTICLE_MODEL = PARTICLE_MODEL_MASK, 32 PARTICLE_MULTI_MODE = PARTICLE_MODEL_MASK | PARTICLE_MULTI_MASK 33 }; 31 34 32 35 #define PARTICLE_DEFAULT_MAX_COUNT 200 //!< A default count of particles in the system. … … 59 62 //! A class to handle ParticleSystems 60 63 class ParticleSystem : public WorldEntity, public PhysicsInterface { 61 64 62 65 public: 63 66 ParticleSystem(unsigned int maxCount = PARTICLE_DEFAULT_MAX_COUNT, 64 67 PARTICLE_TYPE type = PARTICLE_DEFAULT_TYPE); 65 68 virtual ~ParticleSystem(); 66 69 … … 116 119 117 120 GLuint* glID; //!< A List of different gl-List-ID's 118 GLuint dialectCount; //!< How many different types of particles are there in the Particle System 121 GLuint dialectCount; //!< How many different types of particles are there in the Particle System 119 122 120 123 // per particle attributes -
orxonox/trunk/src/lib/particles/quick_animation.cc
r4479 r4597 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 27 27 using namespace std; 28 28 29 30 29 /** 31 30 \brief standard constructor … … 33 32 QuickAnimation::QuickAnimation (void) 34 33 { 35 this->setClass Name("QuickAnimation");34 this->setClassID(CL_QUICK_ANIMATION, "QuickAnimation"); 36 35 37 36 this->first = this->current = NULL; … … 47 46 this->current = this->first; 48 47 QuickKeyFrame delKF; 49 48 50 49 while (this->current != NULL) 51 50 { … … 54 53 this->current = this->first; 55 54 } 56 57 55 } 58 56 … … 70 68 // if it is between some keyframes 71 69 if ((!this->current->next && this->current->position < position) 72 73 70 || (this->current->position < position && this->current->next->position > position)) 71 break; 74 72 // if it is the same as an already existing keyframe 75 73 else if (this->current->position == position) 76 74 return false; 77 75 this->current = this->current->next; 78 76 } … … 92 90 newKey->value = value; 93 91 newKey->position = position; 94 92 95 93 this->current = this->first; 96 94 … … 110 108 { 111 109 if (this->current->position < position+region && this->current->position > position-region) 112 113 114 115 116 this->current = this->current->next; 110 { 111 this->current->value = value; 112 return true; 113 } 114 this->current = this->current->next; 117 115 } 118 116 this->current = this->first; … … 122 120 /* 123 121 \param position The position where to find the Node to kill 124 122 125 123 bool QuickAnimation::removeEntry(float position) 126 124 { 127 125 this->current = this->first; 128 QuickKeyFrame* last = 129 126 QuickKeyFrame* last = 127 130 128 while (this->current) 131 129 { 132 130 if (this->current->position == position) 133 131 { 134 135 132 133 136 134 } 137 this->current = this->current->next; 135 this->current = this->current->next; 138 136 } 139 137 this->current = this->first; … … 145 143 \param position the position to get the value from :) 146 144 */ 147 float QuickAnimation::getValue(float position) 145 float QuickAnimation::getValue(float position) 148 146 { 149 147 if (unlikely(this->first == NULL)) … … 154 152 { 155 153 if (unlikely(position < this->current->position)) 156 157 158 159 160 154 { 155 if (position <= this->first->position) 156 return this->first->value; 157 this->current = this->first; 158 } 161 159 while (likely(this->current->next != NULL && position > this->current->next->position)) 162 160 this->current = this->current->next; 163 161 if (this->current->next == NULL) 164 165 162 return this->current->value; 163 166 164 return this->current->value + (this->current->next->value - this->current->value) 167 165 * ((position-this->current->position) / (this->current->next->position -this->current->position)); 168 166 } 169 167 } -
orxonox/trunk/src/lib/particles/quick_animation.h
r4479 r4597 1 /*! 1 /*! 2 2 \file quick_animation.h 3 3 \brief Definition of the QuickAnimation-class … … 21 21 this class is optimized for a raising value. eg. 100 particles sorted 22 22 by age. 23 \todo speedUP this stuff (especially getValue) 23 24 */ 24 25 class QuickAnimation : public BaseObject {
Note: See TracChangeset
for help on using the changeset viewer.