From 6998dfae3cd731f0bfa997c4ec08e3341d2e276d Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 23 May 2014 09:57:47 -0700 Subject: [PATCH] add visual indicator of thrust direction --- examples/hydraMove.js | 60 ++++++++++++++++++++++++ interface/src/devices/SixenseManager.cpp | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/examples/hydraMove.js b/examples/hydraMove.js index bd462f5e38..ed6a5a4f44 100644 --- a/examples/hydraMove.js +++ b/examples/hydraMove.js @@ -26,6 +26,7 @@ var THRUST_INCREASE_RATE = 1.05; var MAX_THRUST_MULTIPLIER = 75.0; var thrustMultiplier = INITIAL_THRUST_MULTPLIER; var grabDelta = { x: 0, y: 0, z: 0}; +var grabStartPosition = { x: 0, y: 0, z: 0}; var grabDeltaVelocity = { x: 0, y: 0, z: 0}; var grabStartRotation = { x: 0, y: 0, z: 0, w: 1}; var grabCurrentRotation = { x: 0, y: 0, z: 0, w: 1}; @@ -63,6 +64,63 @@ function printVector(text, v, decimals) { } var debug = false; +var RED_COLOR = { red: 255, green: 0, blue: 0 }; +var GRAY_COLOR = { red: 25, green: 25, blue: 25 }; +var defaultPosition = { x: 0, y: 0, z: 0}; +var RADIUS = 0.05; +var greenSphere = -1; +var redSphere = -1; + +function createDebugOverlay() { + + if (greenSphere == -1) { + greenSphere = Overlays.addOverlay("sphere", { + position: defaultPosition, + size: RADIUS, + color: GRAY_COLOR, + alpha: 1, + visible: true, + solid: true, + anchor: "MyAvatar" + }); + redSphere = Overlays.addOverlay("sphere", { + position: defaultPosition, + size: RADIUS, + color: RED_COLOR, + alpha: 1, + visible: true, + solid: true, + anchor: "MyAvatar" + }); + } +} + +function destroyDebugOverlay() { + if (greenSphere != -1) { + Overlays.deleteOverlay(greenSphere); + Overlays.deleteOverlay(redSphere); + greenSphere = -1; + redSphere = -1; + } +} + +function displayDebug() { + if (!(grabbingWithRightHand || grabbingWithLeftHand)) { + if (greenSphere != -1) { + destroyDebugOverlay(); + } + } else { + // update debug indicator + if (greenSphere == -1) { + createDebugOverlay(); + } + + var displayOffset = { x:0, y:0.5, z:-0.5 }; + + Overlays.editOverlay(greenSphere, { position: Vec3.sum(grabStartPosition, displayOffset) } ); + Overlays.editOverlay(redSphere, { position: Vec3.sum(Vec3.sum(grabStartPosition, grabDelta), displayOffset), size: RADIUS + (0.25 * Vec3.length(grabDelta)) } ); + } +} function getJoystickPosition(palm) { // returns CONTROLLER_ID position in avatar local frame @@ -220,6 +278,8 @@ function flyWithHydra(deltaTime) { MyAvatar.headPitch = newPitch; } handleGrabBehavior(deltaTime); + displayDebug(); + } Script.update.connect(flyWithHydra); diff --git a/interface/src/devices/SixenseManager.cpp b/interface/src/devices/SixenseManager.cpp index d2784961bd..8cd3cc059e 100644 --- a/interface/src/devices/SixenseManager.cpp +++ b/interface/src/devices/SixenseManager.cpp @@ -135,7 +135,7 @@ void SixenseManager::update(float deltaTime) { float velocityFilter = glm::clamp(1.0f - glm::length(rawVelocity), 0.0f, 1.0f); palm->setRawPosition(palm->getRawPosition() * velocityFilter + position * (1.0f - velocityFilter)); palm->setRawRotation(safeMix(palm->getRawRotation(), rotation, 1.0f - velocityFilter)); - + // use the velocity to determine whether there's any movement (if the hand isn't new) const float MOVEMENT_DISTANCE_THRESHOLD = 0.003f; _amountMoved += rawVelocity * deltaTime;