From 912b417dd4574c65ac142fb3d3540e56b06550ce Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Wed, 19 Jul 2017 13:56:18 -0700 Subject: [PATCH] mouse ray pick --- interface/src/raypick/LaserPointer.cpp | 16 ++++++++++ interface/src/raypick/LaserPointer.h | 2 ++ interface/src/raypick/LaserPointerManager.cpp | 7 ++++ interface/src/raypick/LaserPointerManager.h | 2 ++ .../LaserPointerScriptingInterface.cpp | 24 ++++++++------ interface/src/raypick/MouseRayPick.cpp | 32 +++++++++++++++++++ interface/src/raypick/MouseRayPick.h | 26 +++++++++++++++ 7 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 interface/src/raypick/MouseRayPick.cpp create mode 100644 interface/src/raypick/MouseRayPick.h diff --git a/interface/src/raypick/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp index 930e72a6fe..a4538e4aff 100644 --- a/interface/src/raypick/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -12,6 +12,7 @@ #include "JointRayPick.h" #include "StaticRayPick.h" +#include "MouseRayPick.h" #include "Application.h" #include "avatar/AvatarManager.h" @@ -48,6 +49,21 @@ LaserPointer::LaserPointer(const glm::vec3& position, const glm::vec3& direction } } +LaserPointer::LaserPointer(const uint16_t filter, const float maxDistance, const QHash& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled) : + _renderingEnabled(enabled), + _renderStates(renderStates), + _faceAvatar(faceAvatar), + _centerEndY(centerEndY) +{ + _rayPickUID = DependencyManager::get()->addRayPick(std::make_shared(filter, maxDistance, enabled)); + + for (auto& state : _renderStates.keys()) { + if (!enabled || state != _currentRenderState) { + disableRenderState(state); + } + } +} + LaserPointer::~LaserPointer() { DependencyManager::get()->removeRayPick(_rayPickUID); for (RenderState& renderState : _renderStates) { diff --git a/interface/src/raypick/LaserPointer.h b/interface/src/raypick/LaserPointer.h index ba9a876556..fef7fe62f1 100644 --- a/interface/src/raypick/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -50,6 +50,8 @@ public: const QHash& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled); LaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance, const QHash& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled); + LaserPointer(const uint16_t filter, const float maxDistance, const QHash& renderStates, const bool faceAvatar, + const bool centerEndY, const bool enabled); ~LaserPointer(); unsigned int getUID() { return _rayPickUID; } diff --git a/interface/src/raypick/LaserPointerManager.cpp b/interface/src/raypick/LaserPointerManager.cpp index b8086c2f89..12f0223297 100644 --- a/interface/src/raypick/LaserPointerManager.cpp +++ b/interface/src/raypick/LaserPointerManager.cpp @@ -28,6 +28,13 @@ unsigned int LaserPointerManager::createLaserPointer(const glm::vec3& position, return uid; } +unsigned int LaserPointerManager::createLaserPointer(const uint16_t filter, const float maxDistance, const QHash& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled) { + std::shared_ptr laserPointer = std::make_shared(filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled); + unsigned int uid = laserPointer->getUID(); + _laserPointers[uid] = laserPointer; + return uid; +} + void LaserPointerManager::enableLaserPointer(const unsigned int uid) { if (_laserPointers.contains(uid)) { _laserPointers[uid]->enable(); diff --git a/interface/src/raypick/LaserPointerManager.h b/interface/src/raypick/LaserPointerManager.h index fc043a9685..6eb649efd4 100644 --- a/interface/src/raypick/LaserPointerManager.h +++ b/interface/src/raypick/LaserPointerManager.h @@ -29,6 +29,8 @@ public: const QHash& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled); unsigned int createLaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance, const QHash& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled); + unsigned int createLaserPointer(const uint16_t filter, const float maxDistance, const QHash& renderStates, const bool faceAvatar, + const bool centerEndY, const bool enabled); void removeLaserPointer(const unsigned int uid) { _laserPointers.remove(uid); } void enableLaserPointer(const unsigned int uid); void disableLaserPointer(const unsigned int uid); diff --git a/interface/src/raypick/LaserPointerScriptingInterface.cpp b/interface/src/raypick/LaserPointerScriptingInterface.cpp index a53b3dbf01..3260ffc165 100644 --- a/interface/src/raypick/LaserPointerScriptingInterface.cpp +++ b/interface/src/raypick/LaserPointerScriptingInterface.cpp @@ -88,18 +88,22 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop if (propertyMap["joint"].isValid()) { QString jointName = propertyMap["joint"].toString(); - // x = upward, y = forward, z = lateral - glm::vec3 posOffset = Vectors::ZERO; - if (propertyMap["posOffset"].isValid()) { - posOffset = vec3FromVariant(propertyMap["posOffset"]); - } + if (jointName != "Mouse") { + // x = upward, y = forward, z = lateral + glm::vec3 posOffset = Vectors::ZERO; + if (propertyMap["posOffset"].isValid()) { + posOffset = vec3FromVariant(propertyMap["posOffset"]); + } - glm::vec3 dirOffset = Vectors::UP; - if (propertyMap["dirOffset"].isValid()) { - dirOffset = vec3FromVariant(propertyMap["dirOffset"]); - } + glm::vec3 dirOffset = Vectors::UP; + if (propertyMap["dirOffset"].isValid()) { + dirOffset = vec3FromVariant(propertyMap["dirOffset"]); + } - return DependencyManager::get()->createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled); + return DependencyManager::get()->createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled); + } else { + return DependencyManager::get()->createLaserPointer(filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled); + } } else if (propertyMap["position"].isValid()) { glm::vec3 position = vec3FromVariant(propertyMap["position"]); diff --git a/interface/src/raypick/MouseRayPick.cpp b/interface/src/raypick/MouseRayPick.cpp new file mode 100644 index 0000000000..39dcb74090 --- /dev/null +++ b/interface/src/raypick/MouseRayPick.cpp @@ -0,0 +1,32 @@ +// +// MouseRayPick.cpp +// interface/src/raypick +// +// Created by Sam Gondelman 7/19/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "MouseRayPick.h" + +#include "DependencyManager.h" +#include "Application.h" +#include "display-plugins/CompositorHelper.h" + +MouseRayPick::MouseRayPick(const uint16_t filter, const float maxDistance, const bool enabled) : + RayPick(filter, maxDistance, enabled) +{ +} + +const PickRay MouseRayPick::getPickRay(bool& valid) const { + QVariant position = qApp->getApplicationCompositor().getReticleInterface()->getPosition(); + if (position.isValid()) { + QVariantMap posMap = position.toMap(); + valid = true; + return qApp->getCamera().computePickRay(posMap["x"].toFloat(), posMap["y"].toFloat()); + } + + valid = false; + return PickRay(); +} diff --git a/interface/src/raypick/MouseRayPick.h b/interface/src/raypick/MouseRayPick.h new file mode 100644 index 0000000000..473d1871e8 --- /dev/null +++ b/interface/src/raypick/MouseRayPick.h @@ -0,0 +1,26 @@ +// +// MouseRayPick.h +// interface/src/raypick +// +// Created by Sam Gondelman 7/19/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#ifndef hifi_MouseRayPick_h +#define hifi_MouseRayPick_h + +#include "RayPick.h" + +#include + +class MouseRayPick : public RayPick { + +public: + MouseRayPick(const uint16_t filter, const float maxDistance = 0.0f, const bool enabled = false); + + const PickRay getPickRay(bool& valid) const override; +}; + +#endif // hifi_MouseRayPick_h