mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 00:13:10 +02:00
added emitter active bool for switching emitters on/off when Leap loses fingers
This commit is contained in:
parent
5c040ad84d
commit
5b2693f99c
3 changed files with 77 additions and 45 deletions
|
@ -27,6 +27,7 @@ ParticleSystem::ParticleSystem() {
|
|||
for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) {
|
||||
|
||||
Emitter * e = &_emitter[emitterIndex];
|
||||
e->active = false;
|
||||
e->position = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
e->previousPosition = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
e->direction = glm::vec3(0.0f, 1.0f, 0.0f);
|
||||
|
@ -72,25 +73,16 @@ void ParticleSystem::simulate(float deltaTime) {
|
|||
|
||||
_timer += deltaTime;
|
||||
|
||||
// emit particles
|
||||
for (int e = 0; e < _numEmitters; e++) {
|
||||
// update emitters
|
||||
for (int emitterIndex = 0; emitterIndex < _numEmitters; emitterIndex++) {
|
||||
assert(emitterIndex <= MAX_EMITTERS);
|
||||
|
||||
assert(e >= 0);
|
||||
assert(e <= MAX_EMITTERS);
|
||||
assert(_emitter[e].rate >= 0);
|
||||
|
||||
_emitter[e].emitReserve += _emitter[e].rate * deltaTime;
|
||||
_emitter[e].numParticlesEmittedThisTime = (int)_emitter[e].emitReserve;
|
||||
_emitter[e].emitReserve -= _emitter[e].numParticlesEmittedThisTime;
|
||||
|
||||
for (int p = 0; p < _emitter[e].numParticlesEmittedThisTime; p++) {
|
||||
float timeFraction = (float)p / (float)_emitter[e].numParticlesEmittedThisTime;
|
||||
createParticle(e, timeFraction);
|
||||
if (_emitter[emitterIndex].active) {
|
||||
updateEmitter(emitterIndex, deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
// update particles
|
||||
|
||||
// update particles
|
||||
for (int p = 0; p < MAX_PARTICLES; p++) {
|
||||
if (_particle[p].alive) {
|
||||
if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) {
|
||||
|
@ -102,6 +94,20 @@ void ParticleSystem::simulate(float deltaTime) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ParticleSystem::updateEmitter(int emitterIndex, float deltaTime) {
|
||||
|
||||
_emitter[emitterIndex].emitReserve += _emitter[emitterIndex].rate * deltaTime;
|
||||
_emitter[emitterIndex].numParticlesEmittedThisTime = (int)_emitter[emitterIndex].emitReserve;
|
||||
_emitter[emitterIndex].emitReserve -= _emitter[emitterIndex].numParticlesEmittedThisTime;
|
||||
|
||||
for (int p = 0; p < _emitter[emitterIndex].numParticlesEmittedThisTime; p++) {
|
||||
float timeFraction = (float)p / (float)_emitter[emitterIndex].numParticlesEmittedThisTime;
|
||||
createParticle(emitterIndex, timeFraction);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ParticleSystem::createParticle(int e, float timeFraction) {
|
||||
|
||||
for (unsigned int p = 0; p < MAX_PARTICLES; p++) {
|
||||
|
@ -212,7 +218,6 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage l
|
|||
}
|
||||
|
||||
|
||||
|
||||
void ParticleSystem::updateParticle(int p, float deltaTime) {
|
||||
|
||||
Emitter myEmitter = _emitter[_particle[p].emitterIndex];
|
||||
|
@ -363,14 +368,16 @@ void ParticleSystem::killAllParticles() {
|
|||
void ParticleSystem::render() {
|
||||
|
||||
// render the emitters
|
||||
for (int e = 0; e < _numEmitters; e++) {
|
||||
for (int e = 0; e < MAX_EMITTERS; e++) {
|
||||
|
||||
if (_emitter[e].showingBaseParticle) {
|
||||
glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a);
|
||||
glPushMatrix();
|
||||
glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z);
|
||||
glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution);
|
||||
glPopMatrix();
|
||||
if (_emitter[e].active) {
|
||||
if (_emitter[e].showingBaseParticle) {
|
||||
glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a);
|
||||
glPushMatrix();
|
||||
glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z);
|
||||
glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
if (_emitter[e].visible) {
|
||||
|
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
const int MAX_PARTICLES = 5000;
|
||||
const int NULL_EMITTER = -1;
|
||||
const int NULL_PARTICLE = -1;
|
||||
const int MAX_EMITTERS = 100;
|
||||
const int MAX_PARTICLES = 5000;
|
||||
|
||||
enum ParticleRenderStyle
|
||||
{
|
||||
|
@ -78,6 +78,7 @@ public:
|
|||
void setParticleAttributes (int emitterIndex, ParticleAttributes attributes); // set attributes for whole life of particles
|
||||
void setParticleAttributes (int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes); // set attributes for this life stage
|
||||
void setEmitterPosition (int emitterIndex, glm::vec3 position );
|
||||
void setEmitterActive (int emitterIndex, bool active ) {_emitter[emitterIndex].active = active; }
|
||||
void setEmitterParticleResolution (int emitterIndex, int resolution ) {_emitter[emitterIndex].particleResolution = resolution; }
|
||||
void setEmitterDirection (int emitterIndex, glm::vec3 direction ) {_emitter[emitterIndex].direction = direction; }
|
||||
void setShowingEmitter (int emitterIndex, bool showing ) {_emitter[emitterIndex].visible = showing; }
|
||||
|
@ -101,6 +102,7 @@ private:
|
|||
};
|
||||
|
||||
struct Emitter {
|
||||
bool active; // if false, the emitter is disabled - allows for easy switching on and off
|
||||
glm::vec3 position; // the position of the emitter in world coordinates
|
||||
glm::vec3 previousPosition; // the position of the emitter in the previous time step
|
||||
glm::vec3 direction; // a normalized vector used as an axis for particle emission and other effects
|
||||
|
@ -124,6 +126,7 @@ private:
|
|||
float _timer;
|
||||
|
||||
// private methods
|
||||
void updateEmitter(int emitterIndex, float deltaTime);
|
||||
void updateParticle(int index, float deltaTime);
|
||||
void createParticle(int e, float timeFraction);
|
||||
void killParticle(int p);
|
||||
|
|
|
@ -244,6 +244,7 @@ void Hand::setLeapHands(const std::vector<glm::vec3>& handPositions,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// call this right after the geometry of the leap hands are set
|
||||
void Hand::updateRaveGloveEmitters() {
|
||||
|
||||
|
@ -253,7 +254,7 @@ void Hand::updateRaveGloveEmitters() {
|
|||
|
||||
if(debug) printf( "\n" );
|
||||
if(debug) printf( "------------------------------------\n" );
|
||||
if(debug) printf( "updating rave glove emitters:\n" );
|
||||
if(debug) printf( "updating rave glove emitters: \n" );
|
||||
if(debug) printf( "------------------------------------\n" );
|
||||
|
||||
int emitterIndex = 0;
|
||||
|
@ -271,16 +272,16 @@ void Hand::updateRaveGloveEmitters() {
|
|||
for (size_t f = 0; f < palm.getNumFingers(); ++f) {
|
||||
FingerData& finger = palm.getFingers()[f];
|
||||
|
||||
if(debug) printf( "emitterIndex %d: ", emitterIndex );
|
||||
if(debug) printf( "emitterIndex %d: ", emitterIndex );
|
||||
|
||||
if (finger.isActive()) {
|
||||
|
||||
if ((emitterIndex >=0)
|
||||
&& (emitterIndex < NUM_FINGERS)) {
|
||||
|
||||
assert(emitterIndex >=0 );
|
||||
assert(emitterIndex < NUM_FINGERS );
|
||||
if ((emitterIndex >=0)
|
||||
&& (emitterIndex < NUM_FINGERS)) {
|
||||
|
||||
_raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[emitterIndex], false); // set to false by default...
|
||||
|
||||
if (finger.isActive()) {
|
||||
_raveGloveParticleSystem.setEmitterActive(_raveGloveEmitter[emitterIndex], true);
|
||||
|
||||
if(debug) printf( "_raveGloveEmitter[%d] = %d\n", emitterIndex, _raveGloveEmitter[emitterIndex] );
|
||||
|
||||
glm::vec3 fingerDirection = finger.getTipPosition() - finger.getRootPosition();
|
||||
|
@ -317,16 +318,11 @@ void Hand::updateRaveGloveParticles(float deltaTime) {
|
|||
|
||||
if (!_raveGloveInitialized) {
|
||||
|
||||
//printf( "Initializing rave glove emitters:\n" );
|
||||
//printf( "The indices of the emitters are:\n" );
|
||||
|
||||
// start up the rave glove finger particles...
|
||||
for ( int f = 0; f< NUM_FINGERS; f ++ ) {
|
||||
_raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter();
|
||||
_raveGloveEmitter[f] = _raveGloveParticleSystem.addEmitter();
|
||||
assert( _raveGloveEmitter[f] >= 0 );
|
||||
assert( _raveGloveEmitter[f] != NULL_EMITTER );
|
||||
|
||||
//printf( "%d\n", _raveGloveEmitter[f] );
|
||||
}
|
||||
|
||||
setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_FIRE);
|
||||
|
@ -339,13 +335,13 @@ void Hand::updateRaveGloveParticles(float deltaTime) {
|
|||
// this rave glove effect oscillates though various colors and radii that are meant to show off some effects
|
||||
if (_raveGloveMode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) {
|
||||
ParticleSystem::ParticleAttributes attributes;
|
||||
float red = 0.5f + 0.5f * sinf(_raveGloveClock * 1.4f);
|
||||
float green = 0.5f + 0.5f * cosf(_raveGloveClock * 1.7f);
|
||||
float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 2.0f);
|
||||
float red = 0.5f + 0.5f * sinf(_raveGloveClock * 2.4f);
|
||||
float green = 0.5f + 0.5f * cosf(_raveGloveClock * 2.7f);
|
||||
float blue = 0.5f + 0.5f * sinf(_raveGloveClock * 3.0f);
|
||||
float alpha = 1.0f;
|
||||
|
||||
attributes.color = glm::vec4(red, green, blue, alpha);
|
||||
attributes.radius = 0.01f + 0.005f * sinf(_raveGloveClock * 2.2f);
|
||||
attributes.radius = 0.01f + 0.003f * sinf(_raveGloveClock * 50.0f);
|
||||
attributes.modulationAmplitude = 0.0f;
|
||||
|
||||
for ( int f = 0; f< NUM_FINGERS; f ++ ) {
|
||||
|
@ -360,6 +356,8 @@ void Hand::updateRaveGloveParticles(float deltaTime) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Hand::setRaveGloveMode(int mode) {
|
||||
|
||||
_raveGloveMode = mode;
|
||||
|
@ -376,7 +374,7 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
if (mode == RAVE_GLOVE_EFFECTS_MODE_THROBBING_COLOR) {
|
||||
_raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE );
|
||||
_raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true );
|
||||
_raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.0f );
|
||||
_raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03f );
|
||||
_raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f );
|
||||
_raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0f );
|
||||
_raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 );
|
||||
|
@ -650,7 +648,7 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes);
|
||||
|
||||
//-----------------------------------------
|
||||
// throb
|
||||
// long sparkler
|
||||
//-----------------------------------------
|
||||
} else if (mode == RAVE_GLOVE_EFFECTS_MODE_LONG_SPARKLER) {
|
||||
|
||||
|
@ -672,6 +670,30 @@ void Hand::setRaveGloveMode(int mode) {
|
|||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes);
|
||||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes);
|
||||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes);
|
||||
|
||||
//-----------------------------------------
|
||||
// throb
|
||||
//-----------------------------------------
|
||||
} else if (mode == RAVE_GLOVE_EFFECTS_MODE_THROB) {
|
||||
|
||||
_raveGloveParticleSystem.setParticleRenderStyle (_raveGloveEmitter[f], PARTICLE_RENDER_STYLE_SPHERE );
|
||||
_raveGloveParticleSystem.setShowingEmitterBaseParticle(_raveGloveEmitter[f], true );
|
||||
_raveGloveParticleSystem.setEmitterParticleLifespan (_raveGloveEmitter[f], 0.03 );
|
||||
_raveGloveParticleSystem.setEmitterThrust (_raveGloveEmitter[f], 0.0f );
|
||||
_raveGloveParticleSystem.setEmitterRate (_raveGloveEmitter[f], 30.0 );
|
||||
_raveGloveParticleSystem.setEmitterParticleResolution (_raveGloveEmitter[f], 20 );
|
||||
|
||||
_raveGloveParticleSystem.setParticleAttributesToDefault(&attributes);
|
||||
|
||||
attributes.radius = 0.01f;
|
||||
attributes.color = glm::vec4( 0.1f, 0.2f, 0.4f, 0.5f);
|
||||
attributes.modulationAmplitude = 0.5;
|
||||
attributes.modulationRate = 3.0;
|
||||
attributes.modulationStyle = COLOR_MODULATION_STYLE_LIGHTNESS_WAVE;
|
||||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_0, attributes);
|
||||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_1, attributes);
|
||||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_2, attributes);
|
||||
_raveGloveParticleSystem.setParticleAttributes(_raveGloveEmitter[f], PARTICLE_LIFESTAGE_3, attributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue