From 9890cf72ce71e2caf367fe23531fb7c35ab6a592 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Fri, 26 Jul 2013 12:37:37 -0700 Subject: [PATCH] added keyboard mode switching for rave glove effects --- interface/src/Application.cpp | 42 +++++++++++++++++++---- interface/src/ParticleSystem.cpp | 35 +++++++++---------- interface/src/avatar/Avatar.cpp | 2 +- interface/src/avatar/Hand.cpp | 54 ++++++++++++++++-------------- interface/src/avatar/Hand.h | 24 ++++++++++++- libraries/avatars/src/AvatarData.h | 12 +++++++ 6 files changed, 118 insertions(+), 51 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index b12e452b60..eb3c72786e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -551,6 +551,7 @@ void Application::sendVoxelServerAddScene() { } void Application::keyPressEvent(QKeyEvent* event) { + if (activeWindow() == _window) { if (_chatEntryOn) { if (_chatEntry.keyPressEvent(event)) { @@ -566,6 +567,11 @@ void Application::keyPressEvent(QKeyEvent* event) { } return; } + + //this is for switching between modes for the leap rave glove test + if (_simulateLeapHand->isChecked() || _testRaveGlove->isChecked()) { + _myAvatar.getHand().setRaveGloveEffectsMode((QKeyEvent*)event); + } bool shifted = event->modifiers().testFlag(Qt::ShiftModifier); switch (event->key()) { @@ -765,7 +771,7 @@ void Application::keyPressEvent(QKeyEvent* event) { case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: - _swatch.handleEvent(event->key(), _eyedropperMode->isChecked()); + _swatch.handleEvent(event->key(), _eyedropperMode->isChecked()); break; default: event->ignore(); @@ -776,6 +782,7 @@ void Application::keyPressEvent(QKeyEvent* event) { void Application::keyReleaseEvent(QKeyEvent* event) { if (activeWindow() == _window) { + if (_chatEntryOn) { _myAvatar.setKeyState(NO_KEY_DOWN); return; @@ -2652,9 +2659,17 @@ void Application::displaySide(Camera& whichCamera) { float sphereRadius = 0.25f; glColor3f(1,0,0); glPushMatrix(); - glutSolidSphere(sphereRadius, 15, 15); + glutSolidSphere(sphereRadius, 15, 15); glPopMatrix(); +/* +glPushMatrix(); +glColor3f(1, 0, 1); +glTranslatef(0.0f, 0.0f, 5.0f); +_particleSystem.render(); +glPopMatrix(); +*/ + //draw a grid ground plane.... if (_renderGroundPlaneOn->isChecked()) { renderGroundPlaneGrid(EDGE_SIZE_GROUND_PLANE, _audio.getCollisionSoundMagnitude()); @@ -2715,13 +2730,25 @@ void Application::displaySide(Camera& whichCamera) { renderLookatIndicator(_lookatOtherPosition, whichCamera); } } - + if (TESTING_PARTICLE_SYSTEM) { if (_particleSystemInitialized) { - _particleSystem.render(); + + + +/* +glPushMatrix(); +glColor3f(1, 0, 1); +glTranslatef(0.0f, 0.0f, 5.0f); +_particleSystem.render(); +glPopMatrix(); +*/ + +_particleSystem.render(); } } - + + // Render the world box if (!_lookingInMirror->isChecked() && _renderStatsOn->isChecked()) { render_world_box(); } @@ -3658,8 +3685,9 @@ void Application::updateParticleSystem(float deltaTime) { const float EMIT_RATE_IN_SECONDS = 10000.0; // create a stable test emitter and spit out a bunch of particles _coolDemoParticleEmitter = _particleSystem.addEmitter(); - + if (_coolDemoParticleEmitter != -1) { + _particleSystem.setShowingEmitter(_coolDemoParticleEmitter, true); glm::vec3 particleEmitterPosition = glm::vec3(5.0f, 1.0f, 5.0f); @@ -3673,7 +3701,7 @@ void Application::updateParticleSystem(float deltaTime) { _particleSystemInitialized = true; } else { // update the particle system - + static bool emitting = true; static float t = 0.0f; t += deltaTime; diff --git a/interface/src/ParticleSystem.cpp b/interface/src/ParticleSystem.cpp index 350f2a6b65..286d7786a4 100644 --- a/interface/src/ParticleSystem.cpp +++ b/interface/src/ParticleSystem.cpp @@ -25,19 +25,19 @@ ParticleSystem::ParticleSystem() { for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) { - Emitter e = _emitter[emitterIndex]; + Emitter * e = &_emitter[emitterIndex]; - e.position = glm::vec3(0.0f, 0.0f, 0.0f); - e.direction = glm::vec3(0.0f, 1.0f, 0.0f); - e.visible = false; - e.particleResolution = DEFAULT_PARTICLE_SPHERE_RESOLUTION; - e.particleLifespan = DEFAULT_PARTICLE_LIFESPAN; - e.showingBaseParticle = false; - e.emitReserve = 0.0; - e.thrust = 0.0f; - e.rate = 0.0f; - e.currentParticle = 0; - e.particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; + e->position = glm::vec3(0.0f, 0.0f, 0.0f); + e->direction = glm::vec3(0.0f, 1.0f, 0.0f); + e->visible = false; + e->particleResolution = DEFAULT_PARTICLE_SPHERE_RESOLUTION; + e->particleLifespan = DEFAULT_PARTICLE_LIFESPAN; + e->showingBaseParticle = false; + e->emitReserve = 0.0; + e->thrust = 0.0f; + e->rate = 0.0f; + e->currentParticle = 0; + e->particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; for (int lifeStage = 0; lifeStage _emitter[_particle[p].emitterIndex].particleLifespan) { killParticle(p); } else { @@ -319,12 +320,12 @@ void ParticleSystem::render() { } }; - // render the particles + // render the particles for (unsigned int p = 0; p < _numParticles; p++) { if (_particle[p].alive) { if (_emitter[_particle[p].emitterIndex].particleLifespan > 0.0) { renderParticle(p); - } + } } } } @@ -363,8 +364,8 @@ void ParticleSystem::renderParticle(int p) { } else if (_emitter[_particle[p].emitterIndex].particleRenderStyle == PARTICLE_RENDER_STYLE_SPHERE) { glPushMatrix(); - glTranslatef(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z); - glutSolidSphere(_particle[p].radius, _emitter[_particle[p].emitterIndex].particleResolution, _emitter[_particle[p].emitterIndex].particleResolution); + glTranslatef(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z); + glutSolidSphere(_particle[p].radius, _emitter[_particle[p].emitterIndex].particleResolution, _emitter[_particle[p].emitterIndex].particleResolution); glPopMatrix(); } else if (_emitter[_particle[p].emitterIndex].particleRenderStyle == PARTICLE_RENDER_STYLE_RIBBON) { diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index c2a2d5aadd..8406db78b7 100755 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -447,7 +447,7 @@ void Avatar::updateThrust(float deltaTime, Transmitter * transmitter) { } void Avatar::simulate(float deltaTime, Transmitter* transmitter) { - + glm::quat orientation = getOrientation(); glm::vec3 front = orientation * IDENTITY_FRONT; glm::vec3 right = orientation * IDENTITY_RIGHT; diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 4374e16043..d5a5cc4fbf 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -14,9 +14,7 @@ #include "Util.h" #include "renderer/ProgramObject.h" -const bool SHOW_LEAP_HAND = false; -const int NUM_TEST_RAVE_GLOVE_MODES = 8; -const float TEST_RAVE_GLOVE_MODE_DURATION = 7.0f; +const bool SHOW_LEAP_HAND = false; using namespace std; @@ -52,6 +50,7 @@ void Hand::init() { void Hand::reset() { } + void Hand::simulate(float deltaTime, bool isMine) { if (_isRaveGloveActive) { updateFingerParticles(deltaTime); @@ -86,6 +85,20 @@ void Hand::calculateGeometry() { } } +void Hand::setRaveGloveEffectsMode(QKeyEvent* event) { + switch (event->key()) { + case Qt::Key_0: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_0); break; + case Qt::Key_1: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_1); break; + case Qt::Key_2: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_2); break; + case Qt::Key_3: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_3); break; + case Qt::Key_4: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_4); break; + case Qt::Key_5: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_5); break; + case Qt::Key_6: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_6); break; + case Qt::Key_7: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_7); break; + case Qt::Key_8: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_8); break; + case Qt::Key_9: setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_9); break; + }; +} void Hand::render(bool lookingInMirror) { @@ -277,25 +290,14 @@ void Hand::updateFingerParticles(float deltaTime) { assert( _fingerParticleEmitter[f] != -1 ); } - setRaveGloveMode(_testRaveGloveMode); + setRaveGloveMode(RAVE_GLOVE_EFFECTS_MODE_2); _particleSystem.setUpDirection(glm::vec3(0.0f, 1.0f, 0.0f)); _particleSystemInitialized = true; } else { + _testRaveGloveClock += deltaTime; - // cycle through the rave glove test modes... - if (_testRaveGloveClock > TEST_RAVE_GLOVE_MODE_DURATION) { - _testRaveGloveClock = 0.0f; - _testRaveGloveMode ++; - - if (_testRaveGloveMode > NUM_TEST_RAVE_GLOVE_MODES) { - _testRaveGloveMode = 0; - } - - setRaveGloveMode(_testRaveGloveMode); - } - - if (_testRaveGloveMode == 0) { + if (_testRaveGloveMode == RAVE_GLOVE_EFFECTS_MODE_0) { ParticleSystem::ParticleAttributes attributes; float red = 0.5f + 0.5f * sinf(_testRaveGloveClock * 1.4f); float green = 0.5f + 0.5f * cosf(_testRaveGloveClock * 1.7f); @@ -317,6 +319,8 @@ void Hand::updateFingerParticles(float deltaTime) { void Hand::setRaveGloveMode(int mode) { + _testRaveGloveMode = mode; + _particleSystem.killAllParticles(); for ( int f = 0; f< NUM_FINGERS; f ++ ) { @@ -326,7 +330,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // throbbing color cycle //----------------------------------------- - if (mode == 0) { + if (mode == RAVE_GLOVE_EFFECTS_MODE_0) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], true ); _particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 0.0f ); @@ -354,7 +358,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // trails //----------------------------------------- - } else if (mode == 1) { + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_1) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_RIBBON ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], false ); _particleSystem.setEmitterParticleLifespan (_fingerParticleEmitter[f], 1.0f ); @@ -388,7 +392,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // Fire! //----------------------------------------- - if (mode == 2) { + if (mode == RAVE_GLOVE_EFFECTS_MODE_2) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], false ); @@ -428,7 +432,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // water //----------------------------------------- - } else if (mode == 3) { + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_3) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], true ); @@ -464,7 +468,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // flashy //----------------------------------------- - } else if (mode == 4) { + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_4) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], true ); @@ -501,7 +505,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // Bozo sparkler //----------------------------------------- - } else if (mode == 5) { + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_5) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_RIBBON ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], false ); @@ -538,7 +542,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // long sparkler //----------------------------------------- - } else if (mode == 6) { + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_6) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_RIBBON ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], false ); @@ -575,7 +579,7 @@ void Hand::setRaveGloveMode(int mode) { //----------------------------------------- // bubble snake //----------------------------------------- - } else if (mode == 7) { + } else if (mode == RAVE_GLOVE_EFFECTS_MODE_7) { _particleSystem.setParticleRenderStyle (_fingerParticleEmitter[f], PARTICLE_RENDER_STYLE_SPHERE ); _particleSystem.setShowingEmitterBaseParticle(_fingerParticleEmitter[f], true ); diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 8152a4b271..de3e4f420d 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -8,6 +8,12 @@ #ifndef hifi_Hand_h #define hifi_Hand_h +#include +#include +#include +#include +#include + #include #include #include @@ -22,6 +28,22 @@ class Avatar; class ProgramObject; +enum RaveGloveEffectsMode +{ + RAVE_GLOVE_EFFECTS_MODE_NULL = -1, + RAVE_GLOVE_EFFECTS_MODE_0, + RAVE_GLOVE_EFFECTS_MODE_1, + RAVE_GLOVE_EFFECTS_MODE_2, + RAVE_GLOVE_EFFECTS_MODE_3, + RAVE_GLOVE_EFFECTS_MODE_4, + RAVE_GLOVE_EFFECTS_MODE_5, + RAVE_GLOVE_EFFECTS_MODE_6, + RAVE_GLOVE_EFFECTS_MODE_7, + RAVE_GLOVE_EFFECTS_MODE_8, + RAVE_GLOVE_EFFECTS_MODE_9, + NUM_RAVE_GLOVE_EFFECTS_MODES +}; + class Hand : public HandData { public: Hand(Avatar* owningAvatar); @@ -45,7 +67,7 @@ public: void updateFingerParticles(float deltaTime); void updateFingerParticleEmitters(); void setRaveGloveActive(bool active) { _isRaveGloveActive = active; } - + void setRaveGloveEffectsMode(QKeyEvent* event); // getters const glm::vec3& getLeapBallPosition (int ball) const { return _leapBalls[ball].position;} diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 209d822426..368cf7733a 100755 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -32,6 +32,18 @@ const float MAX_AUDIO_LOUDNESS = 1000.0; // close enough for mouth animation enum KeyState { NO_KEY_DOWN = 0, + /* + ONE_KEY_DOWN, + TOW_KEY_DOWN, + THREE_KEY_DOWN, + FOUR_KEY_DOWN, + FIVE_KEY_DOWN, + SIX_KEY_DOWN, + SEVEN_KEY_DOWN, + EIGHT_KEY_DOWN, + NINE_KEY_DOWN, + ZERO_KEY_DOWN, + */ INSERT_KEY_DOWN, DELETE_KEY_DOWN };