#include <particle.h>
Inheritance diagram for Spark:
Public Methods | |
Spark () | |
~Spark () | |
void | Update () |
void | Render (int nodeid) |
void | SetShape (PARTICLE *Particle) |
void | SetDefaults (PARTICLE *Particle) |
|
Definition at line 114 of file particle.h.
00114 {}; |
|
Definition at line 115 of file particle.h.
00115 {}; |
|
Reimplemented from ParticleSystem. Definition at line 303 of file particle.cpp. References ParticleInfo::Alive, ParticleInfo::Color, MATRIX::Element, LinkedList< PARTICLE >::Get(), ParticleInfo::Leaf, VECTOR::Normalize(), SystemInfo::numParticles, ParticleSystem::ParticleList, PARTICLE::PartInfo, ParticleInfo::Pos, ParticleInfo::SizeX, ParticleInfo::SizeY, ParticleSystem::SysInfo, SystemInfo::TexID, VECTOR::x, VECTOR::y, and VECTOR::z.
00304 { 00305 MATRIX mat; 00306 VECTOR up; 00307 VECTOR right; 00308 PARTICLE* tempParticle; 00309 // Get the current modelview matrix 00310 glGetFloatv(GL_MODELVIEW_MATRIX, mat.Element); 00311 // Set texture states 00312 glEnable(GL_BLEND); 00313 glDepthMask(0); 00314 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 00315 glDisable(GL_LIGHTING); 00316 glBindTexture(GL_TEXTURE_2D, SysInfo.TexID); 00317 // Loop through all the particles in this system 00318 for (int loop = 1; loop <= SysInfo.numParticles; loop++) 00319 { 00320 // Get the particle from the list 00321 tempParticle = ParticleList.Get(loop); 00322 // If the particle is in the current bsp node 00323 if (tempParticle->PartInfo.Leaf == nodeid) 00324 { 00325 // If the particle is still alive 00326 if (tempParticle->PartInfo.Alive) 00327 { 00328 // Set the shape, should really be performed in Spark::SetShape() 00329 right.x = mat.Element[0]; 00330 right.y = mat.Element[4]; 00331 right.z = mat.Element[8]; 00332 right.Normalize(); 00333 right.x *= tempParticle->PartInfo.SizeX / 2; 00334 right.y *= tempParticle->PartInfo.SizeX / 2; 00335 right.z *= tempParticle->PartInfo.SizeX / 2; 00336 00337 up.x = mat.Element[1]; 00338 up.y = mat.Element[5]; 00339 up.z = mat.Element[9]; 00340 up.Normalize(); 00341 up.x *= tempParticle->PartInfo.SizeY / 2; 00342 up.y *= tempParticle->PartInfo.SizeY / 2; 00343 up.z *= tempParticle->PartInfo.SizeY / 2; 00344 // Set the color to the default values 00345 glColor4f(tempParticle->PartInfo.Color[0], 00346 tempParticle->PartInfo.Color[1], 00347 tempParticle->PartInfo.Color[2], 00348 tempParticle->PartInfo.Color[3]); 00349 // Render the billboarded particle 00350 glBegin(GL_QUADS); 00351 glTexCoord2f(0.0f, 0.0f); 00352 glVertex3f(tempParticle->PartInfo.Pos.x + (-right.x - up.x), 00353 tempParticle->PartInfo.Pos.y + (-right.y - up.y), 00354 tempParticle->PartInfo.Pos.z + (-right.z - up.z)); 00355 glTexCoord2f(1.0f, 0.0f); 00356 glVertex3f(tempParticle->PartInfo.Pos.x + (right.x - up.x), 00357 tempParticle->PartInfo.Pos.y + (right.y - up.y), 00358 tempParticle->PartInfo.Pos.z + (right.z - up.z)); 00359 glTexCoord2f(1.0f, 1.0f); 00360 glVertex3f(tempParticle->PartInfo.Pos.x + (right.x + up.x), 00361 tempParticle->PartInfo.Pos.y + (right.y + up.y), 00362 tempParticle->PartInfo.Pos.z + (right.z + up.z)); 00363 glTexCoord2f(0.0f, 1.0f); 00364 glVertex3f(tempParticle->PartInfo.Pos.x + (up.x - right.x), 00365 tempParticle->PartInfo.Pos.y + (up.y - right.y), 00366 tempParticle->PartInfo.Pos.z + (up.z - right.z)); 00367 glEnd(); 00368 } 00369 } 00370 } 00371 // Reset texture states 00372 glEnable(GL_LIGHTING); 00373 glDepthMask(1); 00374 glDisable(GL_BLEND); 00375 } |
|
Reimplemented from ParticleSystem. Definition at line 377 of file particle.cpp. References ParticleInfo::Alive, ParticleInfo::Color, VECTOR::dot(), ParticleInfo::Energy, SystemInfo::InitialVelocity, SystemInfo::Normal, VECTOR::normalize(), ParticleInfo::OldPos, ParticleInfo::OrigPos, PARTICLE::PartInfo, SystemInfo::Pos, ParticleInfo::Pos, ParticleInfo::SizeX, ParticleInfo::SizeY, ParticleSystem::SysInfo, ParticleInfo::Velocity, VECTOR::x, VECTOR::y, and VECTOR::z.
00378 { 00379 // Set this particle systems properties 00380 Particle->PartInfo.Alive = true; 00381 Particle->PartInfo.Pos = SysInfo.Pos; 00382 Particle->PartInfo.OldPos = SysInfo.Pos; 00383 Particle->PartInfo.OrigPos = SysInfo.Pos; 00384 // Reflect the initial velocity 00385 VECTOR Velocity = SysInfo.InitialVelocity; 00386 VECTOR vectn = SysInfo.Normal * (SysInfo.Normal.dot(Velocity)); 00387 VECTOR vectt = Velocity - vectn; 00388 VECTOR vel = (vectt - vectn); 00389 Velocity.normalize(); 00390 // Create a random spread for each particle 00391 float x; 00392 x = (float)rand()/(float)RAND_MAX; 00393 Particle->PartInfo.Velocity.x = Velocity.x + (x - 0.5); 00394 Particle->PartInfo.Velocity.x /= 2.0; 00395 x = (float)rand()/(float)RAND_MAX; 00396 Particle->PartInfo.Velocity.y = Velocity.y + (x - 0.5); 00397 Particle->PartInfo.Velocity.y /= 2.0; 00398 x = (float)rand()/(float)RAND_MAX; 00399 Particle->PartInfo.Velocity.z = Velocity.z + (x - 0.5); 00400 Particle->PartInfo.Velocity.z /= 2.0; 00401 // Set the color 00402 Particle->PartInfo.Color[0] = 1.0; 00403 Particle->PartInfo.Color[1] = 1.0; 00404 Particle->PartInfo.Color[2] = 1.0; 00405 Particle->PartInfo.Color[3] = 1.0; 00406 // Create a random energy value between 0.5 and 1.0 00407 x = (float)rand()/(float)RAND_MAX; 00408 Particle->PartInfo.Energy = x + 0.5; 00409 if (Particle->PartInfo.Energy > 1.0) 00410 Particle->PartInfo.Energy = 1.0; 00411 // Set the size of the particle 00412 Particle->PartInfo.SizeX = 0.8; 00413 Particle->PartInfo.SizeY = 0.8; 00414 } |
|
Reimplemented from ParticleSystem. Definition at line 416 of file particle.cpp.
00417 { 00418 // Unused for now 00419 } |
|
Reimplemented from ParticleSystem. Definition at line 244 of file particle.cpp. References ParticleInfo::Alive, CheckForParticleCollision(), ParticleInfo::Color, VECTOR::dot(), ParticleInfo::Energy, LinkedList< PARTICLE >::Get(), SystemInfo::numParticles, ParticleInfo::OldPos, ParticleSystem::ParticleList, PARTICLE::PartInfo, ParticleInfo::Pos, ParticleSystem::SysInfo, ParticleInfo::Velocity, VECTOR::x, VECTOR::y, and VECTOR::z.
00245 { 00246 bool CollisionFlag; 00247 VECTOR VelocityVector, normal, pos, oldpos, temppos; 00248 PARTICLE* tempParticle; 00249 // Loop through all the particles of this system 00250 for (int loop = 1; loop <= SysInfo.numParticles; loop++) 00251 { 00252 // Get the particle from the list 00253 tempParticle = ParticleList.Get(loop); 00254 // Set the old position 00255 tempParticle->PartInfo.OldPos = tempParticle->PartInfo.Pos; 00256 // Apply gravity 00257 tempParticle->PartInfo.Velocity.x += 0.0; 00258 tempParticle->PartInfo.Velocity.y += -0.002; 00259 tempParticle->PartInfo.Velocity.z += 0.0; 00260 00261 if (tempParticle->PartInfo.Energy > 0.0) 00262 { 00263 // Set the alpha channel to the energy value 00264 tempParticle->PartInfo.Color[3] = tempParticle->PartInfo.Energy; 00265 // Decrease the energy 00266 tempParticle->PartInfo.Energy -= 0.002; 00267 // Update the position 00268 oldpos = tempParticle->PartInfo.Pos; 00269 pos = tempParticle->PartInfo.Pos + tempParticle->PartInfo.Velocity; 00270 temppos = pos; 00271 // Check for a collision and get the normal of the collision polygon 00272 CollisionFlag = CheckForParticleCollision(tempParticle, oldpos, &temppos, &normal); 00273 // If there was a collision then reflect the velocity vector 00274 if (CollisionFlag) 00275 { 00276 VECTOR vectn = normal * (normal.dot(tempParticle->PartInfo.Velocity)); 00277 VECTOR vectt = tempParticle->PartInfo.Velocity - vectn; 00278 VECTOR vel = (vectt - vectn); 00279 tempParticle->PartInfo.Pos.x += vel.x; 00280 tempParticle->PartInfo.Pos.y += vel.y; 00281 tempParticle->PartInfo.Pos.z += vel.z; 00282 // Decrease the velocity 00283 tempParticle->PartInfo.Velocity.x = vel.x / 3.0; 00284 tempParticle->PartInfo.Velocity.y = vel.y / 3.0; 00285 tempParticle->PartInfo.Velocity.z = vel.z / 3.0; 00286 // Reduce the particles energy due to the collision 00287 tempParticle->PartInfo.Energy -= 0.2; 00288 } 00289 else // Update the position as normal 00290 { 00291 tempParticle->PartInfo.Pos.x += tempParticle->PartInfo.Velocity.x; 00292 tempParticle->PartInfo.Pos.y += tempParticle->PartInfo.Velocity.y; 00293 tempParticle->PartInfo.Pos.z += tempParticle->PartInfo.Velocity.z; 00294 } 00295 } 00296 else // The particles energy has reduced to zero 00297 { 00298 tempParticle->PartInfo.Alive = false; 00299 } 00300 } 00301 } |