From 7ab9cc9c14e58d9f70f9c974bf6e17d1afc50680 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 2 Dec 2013 00:17:06 -0800 Subject: [PATCH] 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