test gradual normal interpolation

This commit is contained in:
SamGondelman 2018-07-24 14:15:49 -07:00
parent 645f905239
commit fbcddf1445
8 changed files with 42 additions and 11 deletions

View file

@ -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)
{
}

View file

@ -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<StartEndRenderState> buildRenderState(const QVariantMap& propMap);

View file

@ -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)
{
}

View file

@ -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<StartEndRenderState> buildRenderState(const QVariantMap& propMap);

View file

@ -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<PickScriptingInterface>()->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()) {

View file

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

View file

@ -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. <code>0-1</code>. 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<PointerManager>()->addPointer(std::make_shared<LaserPointer>(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. <code>0-1</code>. 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<PointerManager>()->addPointer(std::make_shared<ParabolaPointer>(properties, renderStates, defaultRenderStates, hover, triggers,
faceAvatar, followNormal, centerEndY, lockEnd, distanceScaleEnd,
faceAvatar, followNormal, followNormalStrength, centerEndY, lockEnd, distanceScaleEnd,
scaleWithAvatar, enabled));
}

View file

@ -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,