From fbcddf14459ef8c8e49a0fa81fd2bfef39c5c952 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 24 Jul 2018 14:15:49 -0700 Subject: [PATCH] test gradual normal interpolation --- interface/src/raypick/LaserPointer.cpp | 5 +++-- interface/src/raypick/LaserPointer.h | 2 +- interface/src/raypick/ParabolaPointer.cpp | 5 +++-- interface/src/raypick/ParabolaPointer.h | 2 +- interface/src/raypick/PathPointer.cpp | 13 ++++++++++++- interface/src/raypick/PathPointer.h | 4 +++- .../src/raypick/PointerScriptingInterface.cpp | 18 +++++++++++++++--- .../controllers/controllerModules/teleport.js | 4 ++++ 8 files changed, 42 insertions(+), 11 deletions(-) diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 4c47a9f4de..0d724f577b 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -17,8 +17,9 @@ #include "RayPick.h" LaserPointer::LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, - const PointerTriggers& triggers, bool faceAvatar, bool followNormal, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled) : - PathPointer(PickQuery::Ray, rayProps, renderStates, defaultRenderStates, hover, triggers, faceAvatar, followNormal, + const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalTime, bool centerEndY, bool lockEnd, + bool distanceScaleEnd, bool scaleWithAvatar, bool enabled) : + PathPointer(PickQuery::Ray, rayProps, renderStates, defaultRenderStates, hover, triggers, faceAvatar, followNormal, followNormalTime, centerEndY, lockEnd, distanceScaleEnd, scaleWithAvatar, enabled) { } diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index a320e272d1..7ea6a593de 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -40,7 +40,7 @@ public: }; LaserPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, - bool faceAvatar, bool followNormal, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); + bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); static std::shared_ptr buildRenderState(const QVariantMap& propMap); diff --git a/interface/src/raypick/ParabolaPointer.cpp b/interface/src/raypick/ParabolaPointer.cpp index 6ae516bfa4..14a99cdcea 100644 --- a/interface/src/raypick/ParabolaPointer.cpp +++ b/interface/src/raypick/ParabolaPointer.cpp @@ -25,8 +25,9 @@ gpu::PipelinePointer ParabolaPointer::RenderState::ParabolaRenderItem::_parabola gpu::PipelinePointer ParabolaPointer::RenderState::ParabolaRenderItem::_transparentParabolaPipeline { nullptr }; ParabolaPointer::ParabolaPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, - const PointerTriggers& triggers, bool faceAvatar, bool followNormal, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled) : - PathPointer(PickQuery::Parabola, rayProps, renderStates, defaultRenderStates, hover, triggers, faceAvatar, followNormal, + const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, + bool scaleWithAvatar, bool enabled) : + PathPointer(PickQuery::Parabola, rayProps, renderStates, defaultRenderStates, hover, triggers, faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd, scaleWithAvatar, enabled) { } diff --git a/interface/src/raypick/ParabolaPointer.h b/interface/src/raypick/ParabolaPointer.h index 28e34523c2..963aa8dd85 100644 --- a/interface/src/raypick/ParabolaPointer.h +++ b/interface/src/raypick/ParabolaPointer.h @@ -94,7 +94,7 @@ public: }; ParabolaPointer(const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, bool hover, const PointerTriggers& triggers, - bool faceAvatar, bool followNormal, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); + bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); static std::shared_ptr buildRenderState(const QVariantMap& propMap); diff --git a/interface/src/raypick/PathPointer.cpp b/interface/src/raypick/PathPointer.cpp index 13ec063b80..91de839e96 100644 --- a/interface/src/raypick/PathPointer.cpp +++ b/interface/src/raypick/PathPointer.cpp @@ -16,7 +16,7 @@ #include "RayPick.h" PathPointer::PathPointer(PickQuery::PickType type, const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, - bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, bool centerEndY, bool lockEnd, + bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled) : Pointer(DependencyManager::get()->createPick(type, rayProps), enabled, hover), _renderStates(renderStates), @@ -24,6 +24,7 @@ PathPointer::PathPointer(PickQuery::PickType type, const QVariant& rayProps, con _triggers(triggers), _faceAvatar(faceAvatar), _followNormal(followNormal), + _followNormalStrength(followNormalStrength), _centerEndY(centerEndY), _lockEnd(lockEnd), _distanceScaleEnd(distanceScaleEnd), @@ -148,6 +149,16 @@ void PathPointer::updateVisuals(const PickResultPointer& pickResult) { glm::vec3 origin = getPickOrigin(pickResult); glm::vec3 end = getPickEnd(pickResult, _pathLength); glm::vec3 surfaceNormal = getPickedObjectNormal(pickResult); + if (_followNormal && _followNormalStrength > 0.0f && _followNormalStrength < 1.0f) { + if (glm::any(glm::isnan(_avgNormal))) { + _avgNormal = surfaceNormal; + } else { + glm::quat a = Quat().lookAtSimple(glm::vec3(0.0f), _avgNormal); + glm::quat b = Quat().lookAtSimple(glm::vec3(0.0f), surfaceNormal); + surfaceNormal = glm::normalize(glm::slerp(a, b, _followNormalStrength) * Vectors::FRONT); + _avgNormal = surfaceNormal; + } + } _renderStates[_currentRenderState]->update(origin, end, surfaceNormal, _scaleWithAvatar, _distanceScaleEnd, _centerEndY, _faceAvatar, _followNormal, _pathLength, pickResult); if (_defaultRenderStates.find(_currentRenderState) != _defaultRenderStates.end()) { diff --git a/interface/src/raypick/PathPointer.h b/interface/src/raypick/PathPointer.h index a8b3d1bcdb..7df22c80ac 100644 --- a/interface/src/raypick/PathPointer.h +++ b/interface/src/raypick/PathPointer.h @@ -65,7 +65,7 @@ class PathPointer : public Pointer { using Parent = Pointer; public: PathPointer(PickQuery::PickType type, const QVariant& rayProps, const RenderStateMap& renderStates, const DefaultRenderStateMap& defaultRenderStates, - bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, bool centerEndY, bool lockEnd, + bool hover, const PointerTriggers& triggers, bool faceAvatar, bool followNormal, float followNormalStrength, bool centerEndY, bool lockEnd, bool distanceScaleEnd, bool scaleWithAvatar, bool enabled); virtual ~PathPointer(); @@ -86,6 +86,8 @@ protected: float _pathLength { 0.0f }; bool _faceAvatar; bool _followNormal; + float _followNormalStrength; + glm::vec3 _avgNormal { NAN }; bool _centerEndY; bool _lockEnd; bool _distanceScaleEnd; diff --git a/interface/src/raypick/PointerScriptingInterface.cpp b/interface/src/raypick/PointerScriptingInterface.cpp index 486e208647..9f728a2bd8 100644 --- a/interface/src/raypick/PointerScriptingInterface.cpp +++ b/interface/src/raypick/PointerScriptingInterface.cpp @@ -96,6 +96,8 @@ unsigned int PointerScriptingInterface::createStylus(const QVariant& properties) * @property {boolean} [distanceScaleEnd=false] If true, the dimensions of the end of the Pointer will scale linearly with distance. * @property {boolean} [scaleWithAvatar=false] If true, the width of the Pointer's path will scale linearly with your avatar's scale. * @property {boolean} [followNormal=false] If true, the end of the Pointer will rotate to follow the normal of the intersected surface. + * @property {number} [followNormalStrength=0.0] The strength of the interpolation between the real normal and the visual normal if followNormal is true. 0-1. If 0 or 1, + * the normal will follow exactly. * @property {boolean} [enabled=false] * @property {Pointers.RayPointerRenderState[]} [renderStates] A list of different visual states to switch between. * @property {Pointers.DefaultRayPointerRenderState[]} [defaultRenderStates] A list of different visual states to use if there is no intersection. @@ -134,6 +136,10 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope if (propertyMap["followNormal"].isValid()) { followNormal = propertyMap["followNormal"].toBool(); } + float followNormalStrength = 0.0f; + if (propertyMap["followNormalStrength"].isValid()) { + followNormalStrength = propertyMap["followNormalStrength"].toFloat(); + } bool enabled = false; if (propertyMap["enabled"].isValid()) { @@ -193,8 +199,8 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope } return DependencyManager::get()->addPointer(std::make_shared(properties, renderStates, defaultRenderStates, hover, triggers, - faceAvatar, followNormal, centerEndY, lockEnd, distanceScaleEnd, - scaleWithAvatar, enabled)); + faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, + distanceScaleEnd, scaleWithAvatar, enabled)); } /**jsdoc @@ -233,6 +239,8 @@ unsigned int PointerScriptingInterface::createLaserPointer(const QVariant& prope * @property {boolean} [distanceScaleEnd=false] If true, the dimensions of the end of the Pointer will scale linearly with distance. * @property {boolean} [scaleWithAvatar=false] If true, the width of the Pointer's path will scale linearly with your avatar's scale. * @property {boolean} [followNormal=false] If true, the end of the Pointer will rotate to follow the normal of the intersected surface. +* @property {number} [followNormalStrength=0.0] The strength of the interpolation between the real normal and the visual normal if followNormal is true. 0-1. If 0 or 1, +* the normal will follow exactly. * @property {boolean} [enabled=false] * @property {Pointers.ParabolaPointerRenderState[]} [renderStates] A list of different visual states to switch between. * @property {Pointers.DefaultParabolaPointerRenderState[]} [defaultRenderStates] A list of different visual states to use if there is no intersection. @@ -271,6 +279,10 @@ unsigned int PointerScriptingInterface::createParabolaPointer(const QVariant& pr if (propertyMap["followNormal"].isValid()) { followNormal = propertyMap["followNormal"].toBool(); } + float followNormalStrength = 0.0f; + if (propertyMap["followNormalStrength"].isValid()) { + followNormalStrength = propertyMap["followNormalStrength"].toFloat(); + } bool enabled = false; if (propertyMap["enabled"].isValid()) { @@ -330,7 +342,7 @@ unsigned int PointerScriptingInterface::createParabolaPointer(const QVariant& pr } return DependencyManager::get()->addPointer(std::make_shared(properties, renderStates, defaultRenderStates, hover, triggers, - faceAvatar, followNormal, centerEndY, lockEnd, distanceScaleEnd, + faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd, scaleWithAvatar, enabled)); } diff --git a/scripts/system/controllers/controllerModules/teleport.js b/scripts/system/controllers/controllerModules/teleport.js index e926a70bee..d938feb22e 100644 --- a/scripts/system/controllers/controllerModules/teleport.js +++ b/scripts/system/controllers/controllerModules/teleport.js @@ -147,6 +147,7 @@ Script.include("/~/system/libraries/controllers.js"); scaleWithAvatar: true, centerEndY: false, followNormal: true, + followNormalStrength: 0.1, speed: speed, accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, @@ -161,6 +162,7 @@ Script.include("/~/system/libraries/controllers.js"); scaleWithAvatar: true, centerEndY: false, followNormal: true, + followNormalStrength: 0.1, speed: speed, accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, @@ -174,6 +176,7 @@ Script.include("/~/system/libraries/controllers.js"); scaleWithAvatar: true, centerEndY: false, followNormal: true, + followNormalStrength: 0.1, speed: speed, accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true, @@ -188,6 +191,7 @@ Script.include("/~/system/libraries/controllers.js"); scaleWithAvatar: true, centerEndY: false, followNormal: true, + followNormalStrength: 0.1, speed: speed, accelerationAxis: accelerationAxis, rotateAccelerationWithAvatar: true,