From 96809415002ca76ae54cd539db389751bdb560e3 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 29 Nov 2013 14:50:18 -0800 Subject: [PATCH 1/7] Add palm velocity --- interface/src/Application.cpp | 6 +++--- interface/src/Application.h | 2 +- interface/src/devices/SixenseManager.cpp | 5 ++++- interface/src/devices/SixenseManager.h | 2 +- libraries/avatars/src/HandData.h | 3 +++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 43a5e784ed..a06024132e 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2221,11 +2221,11 @@ void Application::updateLeap(float deltaTime) { LeapManager::nextFrame(); } -void Application::updateSixense() { +void Application::updateSixense(float deltaTime) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateSixense()"); - _sixenseManager.update(); + _sixenseManager.update(deltaTime); } void Application::updateSerialDevices(float deltaTime) { @@ -2435,7 +2435,7 @@ void Application::update(float deltaTime) { updateMouseVoxels(deltaTime, mouseRayOrigin, mouseRayDirection, distance, face); // UI/UX related to voxels updateHandAndTouch(deltaTime); // Update state for touch sensors updateLeap(deltaTime); // Leap finger-sensing device - updateSixense(); // Razer Hydra controllers + updateSixense(deltaTime); // Razer Hydra controllers updateSerialDevices(deltaTime); // Read serial port interface devices updateAvatar(deltaTime); // Sample hardware, update view frustum if needed, and send avatar data to mixer/nodes updateThreads(deltaTime); // If running non-threaded, then give the threads some time to process... diff --git a/interface/src/Application.h b/interface/src/Application.h index e2d0820ab9..a81c10041b 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -247,7 +247,7 @@ private: glm::vec3& eyePosition); void updateHandAndTouch(float deltaTime); void updateLeap(float deltaTime); - void updateSixense(); + void updateSixense(float deltaTime); void updateSerialDevices(float deltaTime); void updateThreads(float deltaTime); void updateMyAvatarSimulation(float deltaTime); diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index dfeab1f309..8322c589c9 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -25,7 +25,7 @@ SixenseManager::~SixenseManager() { #endif } -void SixenseManager::update() { +void SixenseManager::update(float deltaTime) { #ifdef HAVE_SIXENSE if (sixenseGetNumActiveControllers() == 0) { return; @@ -63,6 +63,9 @@ void SixenseManager::update() { palm.setActive(true); glm::vec3 position(data.pos[0], data.pos[1], data.pos[2]); + // Compute current velocity from position change + palm.setVelocity((position - palm.getPosition()) / deltaTime); + // Adjust for distance between acquisition 'orb' and the user's torso // (distance to the right of body center, distance below torso, distance behind torso) const glm::vec3 SPHERE_TO_TORSO(-250.f, -300.f, -300.f); diff --git a/interface/src/devices/SixenseManager.h b/interface/src/devices/SixenseManager.h index 90b8cf988f..43e11b682f 100644 --- a/interface/src/devices/SixenseManager.h +++ b/interface/src/devices/SixenseManager.h @@ -16,7 +16,7 @@ public: SixenseManager(); ~SixenseManager(); - void update(); + void update(float deltaTime); }; #endif /* defined(__interface__SixenseManager__) */ diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index c871c568bb..ad32d068bc 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -144,6 +144,8 @@ public: void setLeapID(int id) { _leapID = id; } void setRawPosition(const glm::vec3& pos) { _rawPosition = pos; } void setRawNormal(const glm::vec3& normal) { _rawNormal = normal; } + void setVelocity(const glm::vec3& velocity) { _velocity = velocity; } + const glm::vec3& getVelocity() const { return _velocity; } void incrementFramesWithoutData() { _numFramesWithoutData++; } void resetFramesWithoutData() { _numFramesWithoutData = 0; } @@ -153,6 +155,7 @@ private: std::vector _fingers; glm::vec3 _rawPosition; glm::vec3 _rawNormal; + glm::vec3 _velocity; bool _isActive; // This has current valid data int _leapID; // the Leap's serial id for this tracked object int _numFramesWithoutData; // after too many frames without data, this tracked object assumed lost. From abca79ea3e7208afdd2080c852b17e04c1e2547c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 29 Nov 2013 16:20:43 -0800 Subject: [PATCH 2/7] Add button detection for hydra controller to palmData --- interface/src/avatar/Hand.cpp | 9 +++++++++ interface/src/avatar/Hand.h | 7 +++++-- interface/src/devices/SixenseManager.cpp | 3 +++ libraries/avatars/src/HandData.cpp | 2 ++ libraries/avatars/src/HandData.h | 12 ++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 43fc8cc0de..61aa30af21 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -157,6 +157,15 @@ void Hand::render() { } } + // If hand controller buttons pressed, render stuff + if (getPalms().size() > 0) { + for (size_t i = 0; i < getPalms().size(); ++i) { + PalmData& palm = getPalms()[i]; + //printf("buttons = %i\n", palm.getControllerButtons()); + } + } + + glEnable(GL_DEPTH_TEST); glEnable(GL_RESCALE_NORMAL); diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 36573cfc86..336cb30350 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -30,6 +30,7 @@ enum RaveLightsSetting { RAVE_LIGHTS_PARTICLES }; + class Avatar; class ProgramObject; @@ -46,7 +47,7 @@ public: bool isCollidable; // whether or not the ball responds to collisions float touchForce; // a scalar determining the amount that the cursor (or hand) is penetrating the ball }; - + void init(); void reset(); void simulate(float deltaTime, bool isMine); @@ -62,7 +63,7 @@ public: // getters const glm::vec3& getLeapFingerTipBallPosition (int ball) const { return _leapFingerTipBalls [ball].position;} const glm::vec3& getLeapFingerRootBallPosition(int ball) const { return _leapFingerRootBalls[ball].position;} - + private: // disallow copies of the Hand, copy of owning Avatar is disallowed too Hand(const Hand&); @@ -72,6 +73,8 @@ private: float _raveGloveClock; bool _raveGloveInitialized; int _raveGloveEmitter[NUM_FINGERS]; + + int _controllerButtons; /// Button states read from hand-held controllers Avatar* _owningAvatar; float _renderAlpha; diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 8322c589c9..361f756206 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -66,6 +66,9 @@ void SixenseManager::update(float deltaTime) { // Compute current velocity from position change palm.setVelocity((position - palm.getPosition()) / deltaTime); + // Read controller buttons into the hand + palm.setControllerButtons(data.buttons); + // Adjust for distance between acquisition 'orb' and the user's torso // (distance to the right of body center, distance below torso, distance behind torso) const glm::vec3 SPHERE_TO_TORSO(-250.f, -300.f, -300.f); diff --git a/libraries/avatars/src/HandData.cpp b/libraries/avatars/src/HandData.cpp index f00dbff327..cfa43725b8 100644 --- a/libraries/avatars/src/HandData.cpp +++ b/libraries/avatars/src/HandData.cpp @@ -37,6 +37,8 @@ PalmData& HandData::addNewPalm() { PalmData::PalmData(HandData* owningHandData) : _rawPosition(0, 0, 0), _rawNormal(0, 1, 0), +_velocity(0, 0, 0), +_controllerButtons(0), _isActive(false), _leapID(LEAPID_INVALID), _numFramesWithoutData(0), diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index ad32d068bc..ca8f97d40a 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -41,6 +41,12 @@ enum RaveGloveEffectsMode NUM_RAVE_GLOVE_EFFECTS_MODES }; +const int BUTTON_1 = 32; +const int BUTTON_2 = 64; +const int BUTTON_3 = 8; +const int BUTTON_4 = 16; +const int BUTTON_FWD = 128; + class HandData { public: HandData(AvatarData* owningAvatar); @@ -150,12 +156,18 @@ public: void incrementFramesWithoutData() { _numFramesWithoutData++; } void resetFramesWithoutData() { _numFramesWithoutData = 0; } int getFramesWithoutData() const { return _numFramesWithoutData; } + + // Controller buttons + void setControllerButtons(int controllerButtons) { _controllerButtons = controllerButtons; } + int getControllerButtons() { return _controllerButtons; } private: std::vector _fingers; glm::vec3 _rawPosition; glm::vec3 _rawNormal; glm::vec3 _velocity; + int _controllerButtons; + bool _isActive; // This has current valid data int _leapID; // the Leap's serial id for this tracked object int _numFramesWithoutData; // after too many frames without data, this tracked object assumed lost. From 65ec91ec139c7f1ac577ce6462f6ac1daaa4a75b Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 29 Nov 2013 17:49:35 -0800 Subject: [PATCH 3/7] Add hand thrusters --- interface/src/avatar/Hand.cpp | 20 +++++++++++++++++++- interface/src/avatar/MyAvatar.cpp | 15 +++++++++++++++ libraries/avatars/src/HandData.h | 4 ++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 61aa30af21..d241b6a2fc 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -161,7 +161,25 @@ void Hand::render() { if (getPalms().size() > 0) { for (size_t i = 0; i < getPalms().size(); ++i) { PalmData& palm = getPalms()[i]; - //printf("buttons = %i\n", palm.getControllerButtons()); + // If FWD button(s) are pressed, render laser beam forward + const float POINTER_BEAM_LENGTH = 10.f; + if (palm.getControllerButtons() & BUTTON_FWD) { + FingerData& finger = palm.getFingers()[0]; + if (finger.isActive()) { + glm::vec3 palmPosition = palm.getPosition(); + glm::vec3 pointerPosition = palmPosition + glm::normalize(finger.getTipPosition() - palmPosition) * POINTER_BEAM_LENGTH; + glColor4f(1, 0, 0, 0.5); + glPushMatrix(); + glTranslatef(pointerPosition.x, pointerPosition.y, pointerPosition.z); + glutSolidSphere(0.05, 10, 10); + glPopMatrix(); + glLineWidth(2.0); + glBegin(GL_LINES); + glVertex3f(palmPosition.x, palmPosition.y, palmPosition.z); + glVertex3f(pointerPosition.x, pointerPosition.y, pointerPosition.z); + glEnd(); + } + } } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index baedb1bc6b..2836fab951 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -848,6 +848,21 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { up; } } + // Add thrust from hand controllers + const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD * 10.f; + for (size_t i = 0; i < getHand().getPalms().size(); ++i) { + PalmData& palm = getHand().getPalms()[i]; + if (palm.isActive()) { + if (palm.getControllerButtons() & BUTTON_FWD) { + FingerData& finger = palm.getFingers()[0]; + if (finger.isActive()) { + } + glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition()); + _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * _thrustMultiplier * deltaTime; + } + } + } + // Update speed brake status const float MIN_SPEED_BRAKE_VELOCITY = _scale * 0.4f; diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index ca8f97d40a..5dc42b4675 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -168,8 +168,8 @@ private: glm::vec3 _velocity; int _controllerButtons; - bool _isActive; // This has current valid data - int _leapID; // the Leap's serial id for this tracked object + bool _isActive; // This has current valid data + int _leapID; // the Leap's serial id for this tracked object int _numFramesWithoutData; // after too many frames without data, this tracked object assumed lost. HandData* _owningHandData; }; From a9139b05e87b2633ad961a7df3b7950341d8e7c8 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 29 Nov 2013 20:46:16 -0800 Subject: [PATCH 4/7] Drive with trigger pointing --- interface/src/avatar/Hand.cpp | 15 +++++++++------ interface/src/avatar/MyAvatar.cpp | 7 +++---- interface/src/devices/SixenseManager.cpp | 17 +---------------- libraries/avatars/src/HandData.h | 4 ++++ 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index d241b6a2fc..c8e0d4feb6 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -157,17 +157,20 @@ void Hand::render() { } } - // If hand controller buttons pressed, render stuff + // If hand controller buttons pressed, render stuff as needed if (getPalms().size() > 0) { for (size_t i = 0; i < getPalms().size(); ++i) { PalmData& palm = getPalms()[i]; - // If FWD button(s) are pressed, render laser beam forward - const float POINTER_BEAM_LENGTH = 10.f; - if (palm.getControllerButtons() & BUTTON_FWD) { + // If trigger pulled, thrust in that direction and draw beam + const float MAX_THRUSTER_BEAM_LENGTH = 5.f; + if (palm.getTrigger() > 0.f) { FingerData& finger = palm.getFingers()[0]; - if (finger.isActive()) { + if (finger.isActive() && (palm.getTrigger() > 0.f)) { + printf("trigger = %.2f\n", palm.getTrigger()); glm::vec3 palmPosition = palm.getPosition(); - glm::vec3 pointerPosition = palmPosition + glm::normalize(finger.getTipPosition() - palmPosition) * POINTER_BEAM_LENGTH; + glm::vec3 pointerPosition = palmPosition + + glm::normalize(finger.getTipPosition() - palmPosition) * + (0.01f + palm.getTrigger()) * MAX_THRUSTER_BEAM_LENGTH; glColor4f(1, 0, 0, 0.5); glPushMatrix(); glTranslatef(pointerPosition.x, pointerPosition.y, pointerPosition.z); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 2836fab951..b314145326 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -849,21 +849,20 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { } } // Add thrust from hand controllers - const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD * 10.f; + const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD * 100.f; for (size_t i = 0; i < getHand().getPalms().size(); ++i) { PalmData& palm = getHand().getPalms()[i]; if (palm.isActive()) { - if (palm.getControllerButtons() & BUTTON_FWD) { + if (palm.getTrigger() > 0.f) { FingerData& finger = palm.getFingers()[0]; if (finger.isActive()) { } glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition()); - _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * _thrustMultiplier * deltaTime; + _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * palm.getTrigger() * _thrustMultiplier * deltaTime; } } } - // Update speed brake status const float MIN_SPEED_BRAKE_VELOCITY = _scale * 0.4f; if ((glm::length(_thrust) == 0.0f) && _isThrustOn && (glm::length(_velocity) > MIN_SPEED_BRAKE_VELOCITY)) { diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 361f756206..79c4eadfcc 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -42,22 +42,6 @@ void SixenseManager::update(float deltaTime) { sixenseControllerData data; sixenseGetNewestData(i, &data); - // drive avatar with joystick and triggers - if (data.controller_index) { - avatar->setDriveKeys(ROT_LEFT, qMax(0.0f, -data.joystick_x)); - avatar->setDriveKeys(ROT_RIGHT, qMax(0.0f, data.joystick_x)); - avatar->setDriveKeys(ROT_UP, qMax(0.0f, data.joystick_y)); - avatar->setDriveKeys(ROT_DOWN, qMax(0.0f, -data.joystick_y)); - avatar->setDriveKeys(UP, data.trigger); - - } else { - avatar->setDriveKeys(FWD, qMax(0.0f, data.joystick_y)); - avatar->setDriveKeys(BACK, qMax(0.0f, -data.joystick_y)); - avatar->setDriveKeys(LEFT, qMax(0.0f, -data.joystick_x)); - avatar->setDriveKeys(RIGHT, qMax(0.0f, data.joystick_x)); - avatar->setDriveKeys(DOWN, data.trigger); - } - // Set palm position and normal based on Hydra position/orientation PalmData palm(&hand); palm.setActive(true); @@ -68,6 +52,7 @@ void SixenseManager::update(float deltaTime) { // Read controller buttons into the hand palm.setControllerButtons(data.buttons); + palm.setTrigger(data.trigger); // Adjust for distance between acquisition 'orb' and the user's torso // (distance to the right of body center, distance below torso, distance behind torso) diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index 5dc42b4675..786fc4fdcd 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -161,12 +161,16 @@ public: void setControllerButtons(int controllerButtons) { _controllerButtons = controllerButtons; } int getControllerButtons() { return _controllerButtons; } + void setTrigger(float trigger) { _trigger = trigger; } + float getTrigger() { return _trigger; } + private: std::vector _fingers; glm::vec3 _rawPosition; glm::vec3 _rawNormal; glm::vec3 _velocity; int _controllerButtons; + float _trigger; bool _isActive; // This has current valid data int _leapID; // the Leap's serial id for this tracked object From ea850368ded95568e9f66d5aab0daa986eae5e1d Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Sun, 1 Dec 2013 20:16:14 -0800 Subject: [PATCH 5/7] First working voxel insertion at fingertip --- interface/src/Application.cpp | 40 +++++++++++++++++++++++++++++++ interface/src/Application.h | 1 + interface/src/avatar/Hand.cpp | 21 ++++++++++++++-- interface/src/avatar/Hand.h | 2 ++ interface/src/avatar/MyAvatar.cpp | 4 ++-- 5 files changed, 64 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a06024132e..5885603314 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1487,6 +1487,44 @@ void Application::doKillLocalVoxels() { _wantToKillLocalVoxels = true; } +void Application::createVoxel(glm::vec3 position, + float scale, + glm::vec3 color, + bool isDestructive) { + VoxelDetail voxel; + voxel.x = position.x / TREE_SCALE; + voxel.y = position.y / TREE_SCALE; + voxel.z = position.z / TREE_SCALE; + voxel.s = scale / TREE_SCALE; + voxel.red = color.x; + voxel.green = color.y; + voxel.blue = color.z; + PACKET_TYPE message = isDestructive ? PACKET_TYPE_SET_VOXEL_DESTRUCTIVE : PACKET_TYPE_SET_VOXEL; + _voxelEditSender.sendVoxelEditMessage(message, voxel); + + // create the voxel locally so it appears immediately + + _voxels.createVoxel(voxel.x, voxel.y, voxel.z, voxel.s, + voxel.red, voxel.green, voxel.blue, + isDestructive); + + // Implement voxel fade effect + VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f); + const float VOXEL_BOUNDS_ADJUST = 0.01f; + float slightlyBigger = voxel.s * VOXEL_BOUNDS_ADJUST; + fade.voxelDetails.x = voxel.x - slightlyBigger; + fade.voxelDetails.y = voxel.y - slightlyBigger; + fade.voxelDetails.z = voxel.z - slightlyBigger; + fade.voxelDetails.s = voxel.s + slightlyBigger + slightlyBigger; + _voxelFades.push_back(fade); + + // inject a sound effect + injectVoxelAddedSoundEffect(); + + // remember the position for drag detection + _justEditedVoxel = true; +} + const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) { return glm::vec3((_mouseVoxel.x + _mouseVoxel.s / 2.f) * TREE_SCALE, (_mouseVoxel.y + _mouseVoxel.s / 2.f) * TREE_SCALE, @@ -4097,6 +4135,8 @@ bool Application::maybeEditVoxelUnderCursor() { _voxelEditSender.sendVoxelEditMessage(message, _mouseVoxel); // create the voxel locally so it appears immediately + printf("create voxel from mouse %.4f, %.4f, %.4f, scale %.6f \n", _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); + _voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s, _mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, Menu::getInstance()->isOptionChecked(MenuOption::DestructiveAddVoxel)); diff --git a/interface/src/Application.h b/interface/src/Application.h index a81c10041b..09ee24ba2a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -117,6 +117,7 @@ public: void wheelEvent(QWheelEvent* event); + void createVoxel(glm::vec3 position, float scale, glm::vec3 color, bool isDestructive); const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel); QGLWidget* getGLWidget() { return _glWidget; } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index c8e0d4feb6..0d51768247 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -61,6 +61,24 @@ void Hand::simulate(float deltaTime, bool isMine) { updateRaveGloveParticles(deltaTime); } + + // Create a voxel at fingertip if controller button is pressed + const float FINGERTIP_VOXEL_SIZE = 0.0125; + for (size_t i = 0; i < getNumPalms(); ++i) { + PalmData& palm = getPalms()[i]; + if (palm.isActive()) { + if (palm.getControllerButtons() & BUTTON_1) { + FingerData& finger = palm.getFingers()[0]; + glm::vec3 newVoxelPosition = finger.getTipPosition(); + if (glm::length(newVoxelPosition - _lastFingerVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { + QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value(); + glm::vec3 newVoxelColor(paintColor.red(), paintColor.green(), paintColor.blue()); + Application::getInstance()->createVoxel(newVoxelPosition, FINGERTIP_VOXEL_SIZE, newVoxelColor, true); + _lastFingerVoxel = newVoxelPosition; + } + } + } + } } void Hand::calculateGeometry() { @@ -166,7 +184,6 @@ void Hand::render() { if (palm.getTrigger() > 0.f) { FingerData& finger = palm.getFingers()[0]; if (finger.isActive() && (palm.getTrigger() > 0.f)) { - printf("trigger = %.2f\n", palm.getTrigger()); glm::vec3 palmPosition = palm.getPosition(); glm::vec3 pointerPosition = palmPosition + glm::normalize(finger.getTipPosition() - palmPosition) * @@ -257,7 +274,7 @@ void Hand::renderLeapHands() { //const glm::vec3 handColor = _ballColor; const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color - glDisable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); glPushMatrix(); // Draw the leap balls diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 336cb30350..9e15033ba0 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -82,6 +82,8 @@ private: std::vector _leapFingerTipBalls; std::vector _leapFingerRootBalls; + glm::vec3 _lastFingerVoxel; + // private methods void setLeapHands(const std::vector& handPositions, const std::vector& handNormals); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index b314145326..0934bec41b 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -849,7 +849,7 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { } } // Add thrust from hand controllers - const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD * 100.f; + const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD / 5.f; for (size_t i = 0; i < getHand().getPalms().size(); ++i) { PalmData& palm = getHand().getPalms()[i]; if (palm.isActive()) { @@ -858,7 +858,7 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { if (finger.isActive()) { } glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition()); - _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * palm.getTrigger() * _thrustMultiplier * deltaTime; + _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * powf(palm.getTrigger() * 10.f, 2.f) * _thrustMultiplier * deltaTime; } } } From 2456c26207b24b825a8181db224706d57d98ad07 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Sun, 1 Dec 2013 20:46:42 -0800 Subject: [PATCH 6/7] changed function name so less confusing --- interface/src/Application.cpp | 54 ++++++++++++----------------------- interface/src/Application.h | 7 ++++- interface/src/avatar/Hand.cpp | 8 ++++-- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5885603314..dbef4f050d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1487,18 +1487,20 @@ void Application::doKillLocalVoxels() { _wantToKillLocalVoxels = true; } -void Application::createVoxel(glm::vec3 position, - float scale, - glm::vec3 color, - bool isDestructive) { +void Application::makeVoxel(glm::vec3 position, + float scale, + unsigned char red, + unsigned char green, + unsigned char blue, + bool isDestructive) { VoxelDetail voxel; voxel.x = position.x / TREE_SCALE; voxel.y = position.y / TREE_SCALE; voxel.z = position.z / TREE_SCALE; voxel.s = scale / TREE_SCALE; - voxel.red = color.x; - voxel.green = color.y; - voxel.blue = color.z; + voxel.red = red; + voxel.green = green; + voxel.blue = blue; PACKET_TYPE message = isDestructive ? PACKET_TYPE_SET_VOXEL_DESTRUCTIVE : PACKET_TYPE_SET_VOXEL; _voxelEditSender.sendVoxelEditMessage(message, voxel); @@ -1518,11 +1520,6 @@ void Application::createVoxel(glm::vec3 position, fade.voxelDetails.s = voxel.s + slightlyBigger + slightlyBigger; _voxelFades.push_back(fade); - // inject a sound effect - injectVoxelAddedSoundEffect(); - - // remember the position for drag detection - _justEditedVoxel = true; } const glm::vec3 Application::getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel) { @@ -4129,31 +4126,18 @@ bool Application::maybeEditVoxelUnderCursor() { if (Menu::getInstance()->isOptionChecked(MenuOption::VoxelAddMode) || Menu::getInstance()->isOptionChecked(MenuOption::VoxelColorMode)) { if (_mouseVoxel.s != 0) { - PACKET_TYPE message = Menu::getInstance()->isOptionChecked(MenuOption::DestructiveAddVoxel) - ? PACKET_TYPE_SET_VOXEL_DESTRUCTIVE - : PACKET_TYPE_SET_VOXEL; - _voxelEditSender.sendVoxelEditMessage(message, _mouseVoxel); - - // create the voxel locally so it appears immediately - printf("create voxel from mouse %.4f, %.4f, %.4f, scale %.6f \n", _mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s); - - _voxels.createVoxel(_mouseVoxel.x, _mouseVoxel.y, _mouseVoxel.z, _mouseVoxel.s, - _mouseVoxel.red, _mouseVoxel.green, _mouseVoxel.blue, - Menu::getInstance()->isOptionChecked(MenuOption::DestructiveAddVoxel)); - - // Implement voxel fade effect - VoxelFade fade(VoxelFade::FADE_OUT, 1.0f, 1.0f, 1.0f); - const float VOXEL_BOUNDS_ADJUST = 0.01f; - float slightlyBigger = _mouseVoxel.s * VOXEL_BOUNDS_ADJUST; - fade.voxelDetails.x = _mouseVoxel.x - slightlyBigger; - fade.voxelDetails.y = _mouseVoxel.y - slightlyBigger; - fade.voxelDetails.z = _mouseVoxel.z - slightlyBigger; - fade.voxelDetails.s = _mouseVoxel.s + slightlyBigger + slightlyBigger; - _voxelFades.push_back(fade); - + makeVoxel(glm::vec3(_mouseVoxel.x * TREE_SCALE, + _mouseVoxel.y * TREE_SCALE, + _mouseVoxel.z * TREE_SCALE), + _mouseVoxel.s * TREE_SCALE, + _mouseVoxel.red, + _mouseVoxel.green, + _mouseVoxel.blue, + Menu::getInstance()->isOptionChecked(MenuOption::DestructiveAddVoxel)); + // inject a sound effect injectVoxelAddedSoundEffect(); - + // remember the position for drag detection _justEditedVoxel = true; diff --git a/interface/src/Application.h b/interface/src/Application.h index 09ee24ba2a..cfef871e3c 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -117,7 +117,12 @@ public: void wheelEvent(QWheelEvent* event); - void createVoxel(glm::vec3 position, float scale, glm::vec3 color, bool isDestructive); + void makeVoxel(glm::vec3 position, + float scale, + unsigned char red, + unsigned char green, + unsigned char blue, + bool isDestructive); const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel); QGLWidget* getGLWidget() { return _glWidget; } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 0d51768247..2c9262fd04 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -72,8 +72,12 @@ void Hand::simulate(float deltaTime, bool isMine) { glm::vec3 newVoxelPosition = finger.getTipPosition(); if (glm::length(newVoxelPosition - _lastFingerVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value(); - glm::vec3 newVoxelColor(paintColor.red(), paintColor.green(), paintColor.blue()); - Application::getInstance()->createVoxel(newVoxelPosition, FINGERTIP_VOXEL_SIZE, newVoxelColor, true); + Application::getInstance()->makeVoxel(newVoxelPosition, + FINGERTIP_VOXEL_SIZE, + paintColor.red(), + paintColor.green(), + paintColor.blue(), + true); _lastFingerVoxel = newVoxelPosition; } } From 7ab9cc9c14e58d9f70f9c974bf6e17d1afc50680 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 2 Dec 2013 00:17:06 -0800 Subject: [PATCH 7/7] Voxel editing with hands, flying and rotation with hands --- interface/src/Application.cpp | 13 +++++++++ interface/src/Application.h | 3 ++ interface/src/avatar/Hand.cpp | 37 +++++++++++++++++------- interface/src/avatar/Hand.h | 2 +- interface/src/avatar/MyAvatar.cpp | 12 +++++--- interface/src/devices/SixenseManager.cpp | 3 +- libraries/avatars/src/HandData.h | 6 +++- 7 files changed, 58 insertions(+), 18 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index dbef4f050d..a858aa3867 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1487,6 +1487,19 @@ void Application::doKillLocalVoxels() { _wantToKillLocalVoxels = true; } +void Application::removeVoxel(glm::vec3 position, + float scale) { + VoxelDetail voxel; + voxel.x = position.x / TREE_SCALE; + voxel.y = position.y / TREE_SCALE; + voxel.z = position.z / TREE_SCALE; + voxel.s = scale / TREE_SCALE; + _voxelEditSender.sendVoxelEditMessage(PACKET_TYPE_ERASE_VOXEL, voxel); + + // delete it locally to see the effect immediately (and in case no voxel server is present) + _voxels.deleteVoxelAt(voxel.x, voxel.y, voxel.z, voxel.s); +} + void Application::makeVoxel(glm::vec3 position, float scale, unsigned char red, diff --git a/interface/src/Application.h b/interface/src/Application.h index cfef871e3c..6e584102a3 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -123,6 +123,9 @@ public: unsigned char green, unsigned char blue, bool isDestructive); + + void removeVoxel(glm::vec3 position, float scale); + const glm::vec3 getMouseVoxelWorldCoordinates(const VoxelDetail _mouseVoxel); QGLWidget* getGLWidget() { return _glWidget; } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 2c9262fd04..f733a40c9f 100755 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -67,10 +67,10 @@ void Hand::simulate(float deltaTime, bool isMine) { for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& palm = getPalms()[i]; if (palm.isActive()) { + FingerData& finger = palm.getFingers()[0]; + glm::vec3 newVoxelPosition = finger.getTipPosition(); if (palm.getControllerButtons() & BUTTON_1) { - FingerData& finger = palm.getFingers()[0]; - glm::vec3 newVoxelPosition = finger.getTipPosition(); - if (glm::length(newVoxelPosition - _lastFingerVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { + if (glm::length(newVoxelPosition - _lastFingerAddVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { QColor paintColor = Menu::getInstance()->getActionForOption(MenuOption::VoxelPaintColor)->data().value(); Application::getInstance()->makeVoxel(newVoxelPosition, FINGERTIP_VOXEL_SIZE, @@ -78,7 +78,12 @@ void Hand::simulate(float deltaTime, bool isMine) { paintColor.green(), paintColor.blue(), true); - _lastFingerVoxel = newVoxelPosition; + _lastFingerAddVoxel = newVoxelPosition; + } + } else if (palm.getControllerButtons() & BUTTON_2) { + if (glm::length(newVoxelPosition - _lastFingerDeleteVoxel) > (FINGERTIP_VOXEL_SIZE / 2.f)) { + Application::getInstance()->removeVoxel(newVoxelPosition, FINGERTIP_VOXEL_SIZE); + _lastFingerDeleteVoxel = newVoxelPosition; } } } @@ -185,17 +190,27 @@ void Hand::render() { PalmData& palm = getPalms()[i]; // If trigger pulled, thrust in that direction and draw beam const float MAX_THRUSTER_BEAM_LENGTH = 5.f; - if (palm.getTrigger() > 0.f) { + const float THRUSTER_MARKER_SIZE = 0.0125f; + if (palm.getJoystickY() != 0.f) { FingerData& finger = palm.getFingers()[0]; - if (finger.isActive() && (palm.getTrigger() > 0.f)) { + if (finger.isActive()) { + if (palm.getJoystickY() > 0.f) { + glColor3f(0, 1, 0); + } else { + glColor3f(1, 0, 0); + } glm::vec3 palmPosition = palm.getPosition(); glm::vec3 pointerPosition = palmPosition + glm::normalize(finger.getTipPosition() - palmPosition) * - (0.01f + palm.getTrigger()) * MAX_THRUSTER_BEAM_LENGTH; - glColor4f(1, 0, 0, 0.5); + MAX_THRUSTER_BEAM_LENGTH; glPushMatrix(); - glTranslatef(pointerPosition.x, pointerPosition.y, pointerPosition.z); - glutSolidSphere(0.05, 10, 10); + glm::vec3 markerPosition = palmPosition + + glm::normalize(finger.getTipPosition() - palmPosition) * + MAX_THRUSTER_BEAM_LENGTH * + (0.5f + palm.getJoystickY() / 2.f); + + glTranslatef(markerPosition.x, markerPosition.y, markerPosition.z); + glutSolidSphere(THRUSTER_MARKER_SIZE, 10, 10); glPopMatrix(); glLineWidth(2.0); glBegin(GL_LINES); @@ -279,7 +294,7 @@ void Hand::renderLeapHands() { const glm::vec3 handColor(1.0, 0.84, 0.66); // use the skin color glEnable(GL_DEPTH_TEST); - glDepthMask(GL_FALSE); + glDepthMask(GL_TRUE); glPushMatrix(); // Draw the leap balls for (size_t i = 0; i < _leapFingerTipBalls.size(); i++) { diff --git a/interface/src/avatar/Hand.h b/interface/src/avatar/Hand.h index 9e15033ba0..aea03f4cc1 100755 --- a/interface/src/avatar/Hand.h +++ b/interface/src/avatar/Hand.h @@ -82,7 +82,7 @@ private: std::vector _leapFingerTipBalls; std::vector _leapFingerRootBalls; - glm::vec3 _lastFingerVoxel; + glm::vec3 _lastFingerAddVoxel, _lastFingerDeleteVoxel; // private methods void setLeapHands(const std::vector& handPositions, diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 0934bec41b..1b1caac90f 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -848,17 +848,21 @@ void MyAvatar::updateThrust(float deltaTime, Transmitter * transmitter) { up; } } - // Add thrust from hand controllers - const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD / 5.f; + // Add thrust and rotation from hand controllers + const float THRUST_MAG_HAND_JETS = THRUST_MAG_FWD; + const float JOYSTICK_YAW_MAG = YAW_MAG; for (size_t i = 0; i < getHand().getPalms().size(); ++i) { PalmData& palm = getHand().getPalms()[i]; if (palm.isActive()) { - if (palm.getTrigger() > 0.f) { + if (palm.getJoystickY() != 0.f) { FingerData& finger = palm.getFingers()[0]; if (finger.isActive()) { } glm::vec3 thrustDirection = glm::normalize(finger.getTipPosition() - palm.getPosition()); - _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * powf(palm.getTrigger() * 10.f, 2.f) * _thrustMultiplier * deltaTime; + _thrust += thrustDirection * _scale * THRUST_MAG_HAND_JETS * palm.getJoystickY() * _thrustMultiplier * deltaTime; + } + if (palm.getJoystickX() != 0.f) { + _bodyYawDelta -= palm.getJoystickX() * JOYSTICK_YAW_MAG * deltaTime; } } } diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index 79c4eadfcc..8055e8112d 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -50,9 +50,10 @@ void SixenseManager::update(float deltaTime) { // Compute current velocity from position change palm.setVelocity((position - palm.getPosition()) / deltaTime); - // Read controller buttons into the hand + // Read controller buttons and joystick into the hand palm.setControllerButtons(data.buttons); palm.setTrigger(data.trigger); + palm.setJoystick(data.joystick_x, data.joystick_y); // Adjust for distance between acquisition 'orb' and the user's torso // (distance to the right of body center, distance below torso, distance behind torso) diff --git a/libraries/avatars/src/HandData.h b/libraries/avatars/src/HandData.h index 786fc4fdcd..b8a06d53ad 100755 --- a/libraries/avatars/src/HandData.h +++ b/libraries/avatars/src/HandData.h @@ -163,6 +163,9 @@ public: void setTrigger(float trigger) { _trigger = trigger; } float getTrigger() { return _trigger; } + void setJoystick(float joystickX, float joystickY) { _joystickX = joystickX; _joystickY = joystickY; } + float getJoystickX() { return _joystickX; } + float getJoystickY() { return _joystickY; } private: std::vector _fingers; @@ -170,7 +173,8 @@ private: glm::vec3 _rawNormal; glm::vec3 _velocity; int _controllerButtons; - float _trigger; + float _trigger; + float _joystickX, _joystickY; bool _isActive; // This has current valid data int _leapID; // the Leap's serial id for this tracked object