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; } } }