diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 16e322a142..6fad34b6f1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -190,8 +190,8 @@ #include #include #include -#include "LaserPointerScriptingInterface.h" -#include +#include +#include // On Windows PC, NVidia Optimus laptop, we want to enable NVIDIA GPU // FIXME seems to be broken. @@ -5821,6 +5821,8 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data()); scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance()); + scriptEngine->registerGlobalObject("RayPick", &RayPickManager::getInstance()); + qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue); // connect this script engines printedMessage signal to the global ScriptEngines these various messages diff --git a/libraries/shared/src/JointRayPick.cpp b/interface/src/raypick/JointRayPick.cpp similarity index 64% rename from libraries/shared/src/JointRayPick.cpp rename to interface/src/raypick/JointRayPick.cpp index 4a645fa3fd..8ea48f842f 100644 --- a/libraries/shared/src/JointRayPick.cpp +++ b/interface/src/raypick/JointRayPick.cpp @@ -1,6 +1,6 @@ // // JointRayPick.cpp -// libraries/shared/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -10,17 +10,18 @@ // #include "JointRayPick.h" -JointRayPick::JointRayPick(const QString& jointName, const Transform& offsetTransform, const uint16_t filter, const float maxDistance, const bool enabled) : +JointRayPick::JointRayPick(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, const bool enabled) : RayPick(filter, maxDistance, enabled), _jointName(jointName), - _offsetTransform(offsetTransform) + _posOffset(posOffset), + _dirOffset(dirOffset) { } const PickRay JointRayPick::getPickRay() { // TODO: // get pose for _jointName - // apply _offsetTransform + // apply offset // create and return PickRay return PickRay(); } diff --git a/libraries/shared/src/JointRayPick.h b/interface/src/raypick/JointRayPick.h similarity index 65% rename from libraries/shared/src/JointRayPick.h rename to interface/src/raypick/JointRayPick.h index cd5de79c69..4b2f7d1071 100644 --- a/libraries/shared/src/JointRayPick.h +++ b/interface/src/raypick/JointRayPick.h @@ -1,6 +1,6 @@ // // JointRayPick.h -// libraries/shared/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -14,18 +14,18 @@ #include "RayPick.h" #include -#include "Transform.h" class JointRayPick : public RayPick { public: - JointRayPick(const QString& jointName, const Transform& offsetTransform, const uint16_t filter, const float maxDistance = 0.0f, const bool enabled = false); + JointRayPick(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance = 0.0f, const bool enabled = false); const PickRay getPickRay() override; private: QString _jointName; - Transform _offsetTransform; + glm::vec3 _posOffset; + glm::vec3 _dirOffset; }; diff --git a/libraries/controllers/src/controllers/LaserPointer.cpp b/interface/src/raypick/LaserPointer.cpp similarity index 72% rename from libraries/controllers/src/controllers/LaserPointer.cpp rename to interface/src/raypick/LaserPointer.cpp index 4f3adce875..898df04345 100644 --- a/libraries/controllers/src/controllers/LaserPointer.cpp +++ b/interface/src/raypick/LaserPointer.cpp @@ -1,6 +1,6 @@ // // LaserPointer.cpp -// libraries/controllers/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -13,9 +13,9 @@ #include "RayPickManager.h" #include "JointRayPick.h" -LaserPointer::LaserPointer(const QString& jointName, const Transform& offsetTransform, const uint16_t filter, const float maxDistance, const bool enabled) +LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, const bool enabled) { - _rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared(jointName, offsetTransform, filter, maxDistance, enabled)); + _rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled)); } LaserPointer::~LaserPointer() { diff --git a/libraries/controllers/src/controllers/LaserPointer.h b/interface/src/raypick/LaserPointer.h similarity index 76% rename from libraries/controllers/src/controllers/LaserPointer.h rename to interface/src/raypick/LaserPointer.h index d09defe7b2..93dd33f305 100644 --- a/libraries/controllers/src/controllers/LaserPointer.h +++ b/interface/src/raypick/LaserPointer.h @@ -1,6 +1,6 @@ // // LaserPointer.h -// libraries/controllers/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -12,12 +12,12 @@ #define hifi_LaserPointer_h #include -#include "Transform.h" +#include "glm/glm.hpp" class LaserPointer { public: - LaserPointer(const QString& jointName, const Transform& offsetTransform, const uint16_t filter, const float maxDistance, bool enabled); + LaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled); ~LaserPointer(); unsigned int getUID() { return _rayPickUID; } diff --git a/libraries/controllers/src/controllers/LaserPointerManager.cpp b/interface/src/raypick/LaserPointerManager.cpp similarity index 80% rename from libraries/controllers/src/controllers/LaserPointerManager.cpp rename to interface/src/raypick/LaserPointerManager.cpp index adea77f530..1be2087ffb 100644 --- a/libraries/controllers/src/controllers/LaserPointerManager.cpp +++ b/interface/src/raypick/LaserPointerManager.cpp @@ -1,6 +1,6 @@ // // LaserPointerManager.cpp -// libraries/controllers/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -16,8 +16,8 @@ LaserPointerManager& LaserPointerManager::getInstance() { return instance; } -unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const Transform& offsetTransform, const uint16_t filter, const float maxDistance, bool enabled) { - std::shared_ptr laserPointer = std::make_shared(jointName, offsetTransform, filter, maxDistance, enabled); +unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, bool enabled) { + std::shared_ptr laserPointer = std::make_shared(jointName, posOffset, dirOffset, filter, maxDistance, enabled); unsigned int uid = laserPointer->getUID(); _laserPointers[uid] = laserPointer; return uid; diff --git a/libraries/controllers/src/controllers/LaserPointerManager.h b/interface/src/raypick/LaserPointerManager.h similarity index 83% rename from libraries/controllers/src/controllers/LaserPointerManager.h rename to interface/src/raypick/LaserPointerManager.h index 28d354cf98..503db5e459 100644 --- a/libraries/controllers/src/controllers/LaserPointerManager.h +++ b/interface/src/raypick/LaserPointerManager.h @@ -1,6 +1,6 @@ // // LaserPointerManager.h -// libraries/controllers/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -14,7 +14,7 @@ #include #include #include -#include "Transform.h" +#include class LaserPointer; @@ -23,7 +23,7 @@ class LaserPointerManager { public: static LaserPointerManager& getInstance(); - unsigned int createLaserPointer(const QString& jointName, const Transform& offsetTransform, const uint16_t filter, const float maxDistance, bool enabled); + unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance, 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/LaserPointerScriptingInterface.cpp b/interface/src/raypick/LaserPointerScriptingInterface.cpp similarity index 73% rename from interface/src/LaserPointerScriptingInterface.cpp rename to interface/src/raypick/LaserPointerScriptingInterface.cpp index a5770a9252..f8bba2bf04 100644 --- a/interface/src/LaserPointerScriptingInterface.cpp +++ b/interface/src/raypick/LaserPointerScriptingInterface.cpp @@ -1,6 +1,6 @@ // // LaserPointerScriptingInterface.cpp -// interface/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -12,7 +12,8 @@ #include "LaserPointerScriptingInterface.h" #include -#include "Transform.h" +#include "RegisteredMetaTypes.h" +#include "GLMHelpers.h" LaserPointerScriptingInterface* LaserPointerScriptingInterface::getInstance() { static LaserPointerScriptingInterface instance; @@ -25,10 +26,14 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop if (propertyMap["joint"].isValid()) { QString jointName = propertyMap["joint"].toString(); - Transform offsetTransform; - if (propertyMap["offsetTransform"].isValid()) { - // TODO: - // convert transform + glm::vec3 posOffset = Vectors::ZERO; + if (propertyMap["posOffset"].isValid()) { + posOffset = vec3FromVariant(propertyMap["posOffset"]); + } + + glm::vec3 dirOffset = Vectors::FRONT; + if (propertyMap["dirOffset"].isValid()) { + posOffset = vec3FromVariant(propertyMap["dirOffset"]); } uint16_t filter = 0; @@ -49,7 +54,7 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop // TODO: // handle render state properties - return LaserPointerManager::getInstance().createLaserPointer(jointName, offsetTransform, filter, maxDistance, enabled); + return LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, enabled); } else { return 0; } diff --git a/interface/src/LaserPointerScriptingInterface.h b/interface/src/raypick/LaserPointerScriptingInterface.h similarity index 95% rename from interface/src/LaserPointerScriptingInterface.h rename to interface/src/raypick/LaserPointerScriptingInterface.h index c455843d03..428d722bbb 100644 --- a/interface/src/LaserPointerScriptingInterface.h +++ b/interface/src/raypick/LaserPointerScriptingInterface.h @@ -1,6 +1,6 @@ // // LaserPointerScriptingInterface.h -// interface/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. @@ -13,7 +13,7 @@ #include -#include "controllers\LaserPointerManager.h" +#include "LaserPointerManager.h" class LaserPointerScriptingInterface : public QObject { Q_OBJECT diff --git a/libraries/shared/src/RayPick.cpp b/interface/src/raypick/RayPick.cpp similarity index 94% rename from libraries/shared/src/RayPick.cpp rename to interface/src/raypick/RayPick.cpp index 674913e2e0..e807ef23ff 100644 --- a/libraries/shared/src/RayPick.cpp +++ b/interface/src/raypick/RayPick.cpp @@ -1,6 +1,6 @@ // // RayPick.cpp -// libraries/shared/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/shared/src/RayPick.h b/interface/src/raypick/RayPick.h similarity index 97% rename from libraries/shared/src/RayPick.h rename to interface/src/raypick/RayPick.h index 8a292bf5f7..7ad2d9f83f 100644 --- a/libraries/shared/src/RayPick.h +++ b/interface/src/raypick/RayPick.h @@ -1,6 +1,6 @@ // // RayPick.h -// libraries/shared/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. diff --git a/interface/src/raypick/RayPickManager.cpp b/interface/src/raypick/RayPickManager.cpp new file mode 100644 index 0000000000..bb25c8f168 --- /dev/null +++ b/interface/src/raypick/RayPickManager.cpp @@ -0,0 +1,145 @@ +// +// RayPickManager.cpp +// interface/src/raypick +// +// Created by Sam Gondelman 7/11/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 "RayPickManager.h" +#include "RayPick.h" + +#include "Application.h" +#include "EntityScriptingInterface.h" +#include "ui/overlays/Overlays.h" +#include "avatar/AvatarManager.h" +#include "DependencyManager.h" + +RayPickManager& RayPickManager::getInstance() { + static RayPickManager instance; + return instance; +} + +// Returns true if this ray exists in the cache, and if it does, update res if the cached result is closer +bool RayPickManager::checkAndCompareCachedResults(std::shared_ptr rayPick, QPair& ray, QHash, QHash> cache, RayPickResult& res, unsigned int mask) { + if (cache.contains(ray) && cache[ray].contains(mask)) { + if (cache[ray][mask].getDistance() < res.getDistance() && cache[ray][mask].getDistance() < rayPick->getMaxDistance()) { + res = cache[ray][mask]; + } + return true; + } + return false; +} + +void RayPickManager::update() { + QHash, QHash> results; + for (auto &rayPick : _rayPicks) { + if (!rayPick->isEnabled() || rayPick->getFilter() == RayPickMask::PICK_NOTHING || rayPick->getMaxDistance() < 0.0f) { + continue; + } + + PickRay ray = rayPick->getPickRay(); + // TODO: + // get rid of this and make PickRay hashable + QPair rayKey = QPair(ray.origin, ray.direction); + RayPickResult res; // start with FLT_MAX distance + + if (rayPick->getFilter() & RayPickMask::PICK_ENTITIES) { + RayToEntityIntersectionResult entityRes; + if (rayPick->getFilter() & RayPickMask::PICK_INCLUDE_INVISIBLE && rayPick->getFilter() & RayPickMask::PICK_INCLUDE_NONCOLLIDABLE) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_ENTITIES | RayPickMask::PICK_INCLUDE_INVISIBLE | RayPickMask::PICK_INCLUDE_NONCOLLIDABLE)) { + entityRes = DependencyManager::get()->findRayIntersection(ray, true, QScriptValue(), QScriptValue(), false, false); + } + } + else if (rayPick->getFilter() & RayPickMask::PICK_INCLUDE_INVISIBLE) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_ENTITIES | RayPickMask::PICK_INCLUDE_INVISIBLE)) { + entityRes = DependencyManager::get()->findRayIntersection(ray, true, QScriptValue(), QScriptValue(), false, true); + } + } + else if (rayPick->getFilter() & RayPickMask::PICK_INCLUDE_NONCOLLIDABLE) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_ENTITIES | RayPickMask::PICK_INCLUDE_NONCOLLIDABLE)) { + entityRes = DependencyManager::get()->findRayIntersection(ray, true, QScriptValue(), QScriptValue(), true, false); + } + } + else { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_ENTITIES)) { + entityRes = DependencyManager::get()->findRayIntersection(ray, true, QScriptValue(), QScriptValue(), true, true); + } + } + if (entityRes.intersects) { + res = RayPickResult(entityRes.entityID, entityRes.distance, entityRes.intersection, entityRes.surfaceNormal); + // add to cache + } + } + + if (rayPick->getFilter() & RayPickMask::PICK_OVERLAYS) { + RayToOverlayIntersectionResult overlayRes; + if (rayPick->getFilter() & RayPickMask::PICK_INCLUDE_INVISIBLE && rayPick->getFilter() & RayPickMask::PICK_INCLUDE_NONCOLLIDABLE) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_OVERLAYS | RayPickMask::PICK_INCLUDE_INVISIBLE | RayPickMask::PICK_INCLUDE_NONCOLLIDABLE)) { + overlayRes = qApp->getOverlays().findRayIntersection(ray, true, QScriptValue(), QScriptValue(), false, false); + } + } + else if (rayPick->getFilter() & RayPickMask::PICK_INCLUDE_INVISIBLE) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_OVERLAYS | RayPickMask::PICK_INCLUDE_INVISIBLE)) { + overlayRes = qApp->getOverlays().findRayIntersection(ray, true, QScriptValue(), QScriptValue(), false, true); + } + } + else if (rayPick->getFilter() & RayPickMask::PICK_INCLUDE_NONCOLLIDABLE) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_OVERLAYS | RayPickMask::PICK_INCLUDE_NONCOLLIDABLE)) { + overlayRes = qApp->getOverlays().findRayIntersection(ray, true, QScriptValue(), QScriptValue(), true, false); + } + } + else { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_OVERLAYS)) { + overlayRes = qApp->getOverlays().findRayIntersection(ray, true, QScriptValue(), QScriptValue(), true, true); + } + } + if (overlayRes.intersects) { + res = RayPickResult(overlayRes.overlayID, overlayRes.distance, overlayRes.intersection, overlayRes.surfaceNormal); + // add to cache + } + } + + if (rayPick->getFilter() & RayPickMask::PICK_AVATARS) { + if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_AVATARS)) { + RayToAvatarIntersectionResult avatarRes = DependencyManager::get()->findRayIntersection(ray, QScriptValue(), QScriptValue()); + if (avatarRes.intersects) { + res = RayPickResult(avatarRes.avatarID, avatarRes.distance, avatarRes.intersection); + // add to cache + } + } + } + + } +} + +unsigned int RayPickManager::addRayPick(std::shared_ptr rayPick) { + // TODO: + // use lock and defer adding to prevent issues + _rayPicks[_nextUID] = rayPick; + return _nextUID++; +} + +void RayPickManager::removeRayPick(const unsigned int uid) { + // TODO: + // use lock and defer removing to prevent issues + _rayPicks.remove(uid); +} + +void RayPickManager::enableRayPick(const unsigned int uid) { + // TODO: + // use lock and defer enabling to prevent issues + if (_rayPicks.contains(uid)) { + _rayPicks[uid]->enable(); + } +} + +void RayPickManager::disableRayPick(const unsigned int uid) { + // TODO: + // use lock and defer disabling to prevent issues + if (_rayPicks.contains(uid)) { + _rayPicks[uid]->disable(); + } +} diff --git a/interface/src/raypick/RayPickManager.h b/interface/src/raypick/RayPickManager.h new file mode 100644 index 0000000000..ac700118f6 --- /dev/null +++ b/interface/src/raypick/RayPickManager.h @@ -0,0 +1,97 @@ +// +// RayPickManager.h +// interface/src/raypick +// +// Created by Sam Gondelman 7/11/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_RayPickManager_h +#define hifi_RayPickManager_h + +#include "RegisteredMetaTypes.h" + +#include +#include +#include + +class RayPick; + +enum RayPickMask { + PICK_NOTHING = 0, + PICK_ENTITIES = 1, + PICK_OVERLAYS = 2, + PICK_AVATARS = 4, + PICK_HUD = 8, + + PICK_BOUNDING_BOX = 16, // if not set, picks again physics mesh (can't pick against graphics mesh, yet) + + PICK_INCLUDE_INVISIBLE = 32, // if not set, will not intersect invisible elements, otherwise, intersects both visible and invisible elements + PICK_INCLUDE_NONCOLLIDABLE = 64, // if not set, will not intersect noncollidable elements, otherwise, intersects both collidable and noncollidable elements + + PICK_ALL_INTERSECTIONS = 128 // if not set, returns closest intersection, otherwise, returns list of all intersections +}; + +// TODO: +// move/improve this and register it as a meta type +class RayPickResult { + +public: + RayPickResult() {} + RayPickResult(const QUuid& objectID, const float distance, const glm::vec3& intersection, const glm::vec3& surfaceNormal = glm::vec3(NAN)) : + _objectID(objectID), _distance(distance), _intersection(intersection), _surfaceNormal(surfaceNormal) {} + + const QUuid& getUID() { return _objectID; } + const float getDistance() { return _distance; } + const glm::vec3& getIntersection() { return _intersection; } + const glm::vec3& getSurfaceNormal() { return _surfaceNormal; } + +private: + //Type type; + QUuid _objectID { 0 }; + float _distance { FLT_MAX }; + glm::vec3 _intersection { NAN }; + glm::vec3 _surfaceNormal { NAN }; +}; + +class RayPickManager : public QObject { + Q_OBJECT + Q_PROPERTY(unsigned int PICK_NOTHING READ PICK_NOTHING CONSTANT) + Q_PROPERTY(unsigned int PICK_ENTITIES READ PICK_ENTITIES CONSTANT) + Q_PROPERTY(unsigned int PICK_OVERLAYS READ PICK_OVERLAYS CONSTANT) + Q_PROPERTY(unsigned int PICK_AVATARS READ PICK_AVATARS CONSTANT) + Q_PROPERTY(unsigned int PICK_HUD READ PICK_HUD CONSTANT) + Q_PROPERTY(unsigned int PICK_BOUNDING_BOX READ PICK_BOUNDING_BOX CONSTANT) + Q_PROPERTY(unsigned int PICK_INCLUDE_INVISIBLE READ PICK_INCLUDE_INVISIBLE CONSTANT) + Q_PROPERTY(unsigned int PICK_INCLUDE_NONCOLLIDABLE READ PICK_INCLUDE_NONCOLLIDABLE CONSTANT) + Q_PROPERTY(unsigned int PICK_ALL_INTERSECTIONS READ PICK_ALL_INTERSECTIONS CONSTANT) + +public: + static RayPickManager& getInstance(); + + void update(); + bool RayPickManager::checkAndCompareCachedResults(std::shared_ptr rayPick, QPair& ray, QHash, QHash> cache, RayPickResult& res, unsigned int mask); + unsigned int addRayPick(std::shared_ptr rayPick); + void removeRayPick(const unsigned int uid); + void enableRayPick(const unsigned int uid); + void disableRayPick(const unsigned int uid); + +private: + QHash> _rayPicks; + unsigned int _nextUID { 1 }; // 0 is invalid + + const unsigned int PICK_NOTHING() { return RayPickMask::PICK_NOTHING; } + const unsigned int PICK_ENTITIES() { return RayPickMask::PICK_ENTITIES; } + const unsigned int PICK_OVERLAYS() { return RayPickMask::PICK_OVERLAYS; } + const unsigned int PICK_AVATARS() { return RayPickMask::PICK_AVATARS; } + const unsigned int PICK_HUD() { return RayPickMask::PICK_HUD; } + const unsigned int PICK_BOUNDING_BOX() { return RayPickMask::PICK_BOUNDING_BOX; } + const unsigned int PICK_INCLUDE_INVISIBLE() { return RayPickMask::PICK_INCLUDE_INVISIBLE; } + const unsigned int PICK_INCLUDE_NONCOLLIDABLE() { return RayPickMask::PICK_INCLUDE_NONCOLLIDABLE; } + const unsigned int PICK_ALL_INTERSECTIONS() { return RayPickMask::PICK_ALL_INTERSECTIONS; } + +}; + +#endif hifi_RayPickManager_h \ No newline at end of file diff --git a/libraries/shared/src/StaticRayPick.cpp b/interface/src/raypick/StaticRayPick.cpp similarity index 95% rename from libraries/shared/src/StaticRayPick.cpp rename to interface/src/raypick/StaticRayPick.cpp index 2ebe431b00..b3bce16b58 100644 --- a/libraries/shared/src/StaticRayPick.cpp +++ b/interface/src/raypick/StaticRayPick.cpp @@ -1,6 +1,6 @@ // // StaticRayPick.cpp -// libraries/shared/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/shared/src/StaticRayPick.h b/interface/src/raypick/StaticRayPick.h similarity index 96% rename from libraries/shared/src/StaticRayPick.h rename to interface/src/raypick/StaticRayPick.h index 6424b731c7..6d3df21859 100644 --- a/libraries/shared/src/StaticRayPick.h +++ b/interface/src/raypick/StaticRayPick.h @@ -1,6 +1,6 @@ // // StaticRayPick.h -// libraries/shared/src +// interface/src/raypick // // Created by Sam Gondelman 7/11/2017 // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/shared/src/RayPickManager.cpp b/libraries/shared/src/RayPickManager.cpp deleted file mode 100644 index 5c5ebd8c10..0000000000 --- a/libraries/shared/src/RayPickManager.cpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// RayPickManager.cpp -// libraries/shared/src -// -// Created by Sam Gondelman 7/11/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 "RayPickManager.h" -#include "RayPick.h" - -RayPickManager& RayPickManager::getInstance() { - static RayPickManager instance; - return instance; -} - -void RayPickManager::update() { - /*** - - somehow calculate minimum number of intersection tests, update raypicks accordingly - -one option : - loop over all raypicks{ loop over all necessary intersection tests and take min distance less than rayPick->maxDistance, but keep cache of this frame's previous tests to prevent duplicate intersection tests } - ***/ -} - -unsigned int RayPickManager::addRayPick(std::shared_ptr rayPick) { - // TODO: - // use lock and defer adding to prevent issues - _rayPicks[_nextUID] = rayPick; - return _nextUID++; -} - -void RayPickManager::removeRayPick(const unsigned int uid) { - // TODO: - // use lock and defer removing to prevent issues - _rayPicks.remove(uid); -} - -void RayPickManager::enableRayPick(const unsigned int uid) { - // TODO: - // use lock and defer enabling to prevent issues - if (_rayPicks.contains(uid)) { - _rayPicks[uid]->enable(); - } -} - -void RayPickManager::disableRayPick(const unsigned int uid) { - // TODO: - // use lock and defer disabling to prevent issues - if (_rayPicks.contains(uid)) { - _rayPicks[uid]->disable(); - } -} diff --git a/libraries/shared/src/RayPickManager.h b/libraries/shared/src/RayPickManager.h deleted file mode 100644 index c296c14af7..0000000000 --- a/libraries/shared/src/RayPickManager.h +++ /dev/null @@ -1,50 +0,0 @@ -// -// RayPickManager.h -// libraries/shared/src -// -// Created by Sam Gondelman 7/11/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_RayPickManager_h -#define hifi_RayPickManager_h - -#include -#include - -class RayPick; - -enum RayPickMask { - PICK_NOTHING = 0, - PICK_ENTITIES = 1, - PICK_AVATARS = 2, - PICK_OVERLAYS = 4, - PICK_HUD = 8, - - PICK_BOUNDING_BOX = 16, // if not set, picks again physics mesh (can't pick against graphics mesh, yet) - - PICK_INCLUDE_INVISIBLE = 32, // if not set, will not intersect invisible elements, otherwise, intersects both visible and invisible elements - - PICK_ALL_INTERSECTIONS = 64 // if not set, returns closest intersection, otherwise, returns list of all intersections -}; - -class RayPickManager { - -public: - static RayPickManager& getInstance(); - - void update(); - unsigned int addRayPick(std::shared_ptr rayPick); - void removeRayPick(const unsigned int uid); - void enableRayPick(const unsigned int uid); - void disableRayPick(const unsigned int uid); - -private: - QHash> _rayPicks; - unsigned int _nextUID { 1 }; // 0 is invalid - -}; - -#endif hifi_RayPickManager_h \ No newline at end of file