From 5e2dcfee53b5e039427ba5a42e4db3c731199a3d Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 24 Jul 2013 16:52:37 -0700 Subject: [PATCH] cleaned up some magic numbers --- interface/src/Application.cpp | 8 ++-- interface/src/ParticleSystem.cpp | 4 +- interface/src/ParticleSystem.h | 20 +++++++-- interface/src/avatar/Hand.cpp | 76 ++++++++++++++++---------------- 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 339bd520e7..b12e452b60 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3650,10 +3650,12 @@ void Application::exportSettings() { } - void Application::updateParticleSystem(float deltaTime) { if (!_particleSystemInitialized) { + + const int LIFESPAN_IN_SECONDS = 100000.0f; + const float EMIT_RATE_IN_SECONDS = 10000.0; // create a stable test emitter and spit out a bunch of particles _coolDemoParticleEmitter = _particleSystem.addEmitter(); @@ -3662,9 +3664,9 @@ void Application::updateParticleSystem(float deltaTime) { glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f); _particleSystem.setEmitterPosition (_coolDemoParticleEmitter, particleEmitterPosition); - _particleSystem.setEmitterParticleLifespan(_coolDemoParticleEmitter, 100000.0f); + _particleSystem.setEmitterParticleLifespan(_coolDemoParticleEmitter, LIFESPAN_IN_SECONDS); _particleSystem.setEmitterThrust (_coolDemoParticleEmitter, 0.0f); - _particleSystem.setEmitterRate (_coolDemoParticleEmitter, 10000.0); // to emit a pile o particles now + _particleSystem.setEmitterRate (_coolDemoParticleEmitter, EMIT_RATE_IN_SECONDS); // to emit a pile o particles now } // signal that the particle system has been initialized diff --git a/interface/src/ParticleSystem.cpp b/interface/src/ParticleSystem.cpp index 1270760459..707fce967a 100644 --- a/interface/src/ParticleSystem.cpp +++ b/interface/src/ParticleSystem.cpp @@ -162,11 +162,11 @@ void ParticleSystem::killParticle(int p) { void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleAttributes attributes) { for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage ++ ) { - setParticleAttributes(emitterIndex, lifeStage, attributes); + setParticleAttributes(emitterIndex, (ParticleLifeStage)lifeStage, attributes); } } -void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, ParticleAttributes attributes) { +void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes) { ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; diff --git a/interface/src/ParticleSystem.h b/interface/src/ParticleSystem.h index 5ecb3510d9..10911a4832 100644 --- a/interface/src/ParticleSystem.h +++ b/interface/src/ParticleSystem.h @@ -10,9 +10,8 @@ #include -const int MAX_PARTICLES = 5000; -const int MAX_EMITTERS = 100; -const int NUM_PARTICLE_LIFE_STAGES = 4; // each equal time-division of the particle's life can have different attributes +const int MAX_PARTICLES = 5000; +const int MAX_EMITTERS = 100; enum ParticleRenderStyle { @@ -22,6 +21,19 @@ enum ParticleRenderStyle NUM_PARTICLE_RENDER_STYLES }; + +enum ParticleLifeStage +{ + PARTICLE_LIFESTAGE_0 = 0, + PARTICLE_LIFESTAGE_1, + PARTICLE_LIFESTAGE_2, + PARTICLE_LIFESTAGE_3, + NUM_PARTICLE_LIFE_STAGES +}; + + + + class ParticleSystem { public: @@ -51,7 +63,7 @@ public: void setUpDirection(glm::vec3 upDirection) {_upDirection = upDirection;} // tell particle system which direction is up void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles - void setParticleAttributes (int emitterIndex, int lifeStage, ParticleAttributes attributes); // set attributes for this life stage of particles + void setParticleAttributes (int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes); // set attributes for this life stage void setEmitterPosition (int emitterIndex, glm::vec3 position ) {_emitter[emitterIndex].position = position; } void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; } void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index ef343e5608..4374e16043 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -304,10 +304,10 @@ void Hand::updateFingerParticles(float deltaTime) { attributes.color = glm::vec4(red, green, blue, 1.0f); attributes.radius = 0.01f + 0.005f * sinf(_testRaveGloveClock * 2.2f); for ( int f = 0; f< NUM_FINGERS; f ++ ) { - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); } } @@ -346,10 +346,10 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 0.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- // trails @@ -373,16 +373,16 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 0.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.radius = 0.002f; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.color = glm::vec4( 1.0f, 0.2f, 0.2f, 0.5f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.color = glm::vec4( 1.0f, 0.2f, 0.2f, 0.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); } //----------------------------------------- @@ -408,22 +408,22 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 1.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.radius = 0.01f; attributes.jitter = 0.0f; attributes.gravity = -0.005f; attributes.color = glm::vec4( 1.0f, 0.2f, 0.0f, 0.4f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.radius = 0.01f; attributes.gravity = 0.0f; attributes.color = glm::vec4( 0.4f, 0.4f, 0.4f, 0.2f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.radius = 0.02f; attributes.color = glm::vec4( 0.4f, 0.6f, 0.9f, 0.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- // water @@ -431,10 +431,10 @@ void Hand::setRaveGloveMode(int mode) { } else if (mode == 3) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); - _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], true ); + _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], true ); _particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 0.6f ); _particleSystem.setEmitterThrust (_fingerParticleEmitter[f], 0.001f ); - _particleSystem.setEmitterRate (_fingerParticleEmitter[f], 100.0 ); + _particleSystem.setEmitterRate (_fingerParticleEmitter[f], 100.0 ); _particleSystem.setEmitterParticleResolution (_fingerParticleEmitter[f], 5 ); attributes.radius = 0.001f; @@ -448,18 +448,18 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 1.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.gravity = 0.01f; attributes.jitter = 0.0f; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.color = glm::vec4( 0.8f, 0.9f, 1.0f, 0.2f); attributes.radius = 0.002f; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.color = glm::vec4( 0.8f, 0.9f, 1.0f, 0.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- // flashy @@ -484,19 +484,19 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 1.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.radius = 0.01f; attributes.color = glm::vec4( 1.0f, 1.0f, 0.0f, 1.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.radius = 0.01f; attributes.color = glm::vec4( 1.0f, 0.0f, 1.0f, 1.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.radius = 0.0f; attributes.color = glm::vec4( 0.0f, 0.0f, 0.0f, 1.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- // Bozo sparkler @@ -521,19 +521,19 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 1.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.radius = 0.01f; attributes.color = glm::vec4( 1.0f, 1.0f, 0.0f, 1.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.radius = 0.01f; attributes.color = glm::vec4( 1.0f, 0.0f, .0f, 1.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.radius = 0.0f; attributes.color = glm::vec4( 0.0f, 0.0f, 1.0f, 0.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- // long sparkler @@ -558,19 +558,19 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 0.0f; attributes.bounce = 1.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.radius = 0.005f; attributes.color = glm::vec4( 0.0f, 0.5f, 0.5f, 0.8f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.radius = 0.007f; attributes.color = glm::vec4( 0.5f, 0.0f, 0.5f, 0.5f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.radius = 0.02f; attributes.color = glm::vec4( 0.0f, 0.0f, 1.0f, 0.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); //----------------------------------------- // bubble snake @@ -595,19 +595,19 @@ void Hand::setRaveGloveMode(int mode) { attributes.neighborRepulsion = 1.1f; attributes.bounce = 0.0f; attributes.usingCollisionSphere = false; - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 0, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_0, attributes); attributes.radius = 0.002f; attributes.color = glm::vec4( 1.0f, 1.0f, 1.0f, 1.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 1, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_1, attributes); attributes.radius = 0.003f; attributes.color = glm::vec4( 0.3f, 0.3f, 0.3f, 0.5f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 2, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_2, attributes); attributes.radius = 0.004f; attributes.color = glm::vec4( 0.3f, 0.3f, 0.3f, 0.0f); - _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], 3, attributes); + _particleSystem.setParticleAttributes(_fingerParticleEmitter[f], PARTICLE_LIFESTAGE_3, attributes); } } }