mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
expose RayPickMask to JS, move everything to interface/src/raypick to prevent dependency issues, start working on RayPickManager::update (needs testing)
This commit is contained in:
parent
3ac369d782
commit
ea65a04f28
17 changed files with 285 additions and 139 deletions
|
@ -190,8 +190,8 @@
|
|||
#include <src/scripting/LimitlessVoiceRecognitionScriptingInterface.h>
|
||||
#include <EntityScriptClient.h>
|
||||
#include <ModelScriptingInterface.h>
|
||||
#include "LaserPointerScriptingInterface.h"
|
||||
#include <RayPickManager.h>
|
||||
#include <raypick/LaserPointerScriptingInterface.h>
|
||||
#include <raypick/RayPickManager.h>
|
||||
|
||||
// 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
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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 <QString>
|
||||
#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;
|
||||
|
||||
};
|
||||
|
|
@ -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<JointRayPick>(jointName, offsetTransform, filter, maxDistance, enabled));
|
||||
_rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
|
||||
}
|
||||
|
||||
LaserPointer::~LaserPointer() {
|
|
@ -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 <QString>
|
||||
#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; }
|
|
@ -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> laserPointer = std::make_shared<LaserPointer>(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> laserPointer = std::make_shared<LaserPointer>(jointName, posOffset, dirOffset, filter, maxDistance, enabled);
|
||||
unsigned int uid = laserPointer->getUID();
|
||||
_laserPointers[uid] = laserPointer;
|
||||
return uid;
|
|
@ -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 <QHash>
|
||||
#include <QString>
|
||||
#include <memory>
|
||||
#include "Transform.h"
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
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);
|
|
@ -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 <QVariant>
|
||||
#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;
|
||||
}
|
|
@ -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 <QtCore/QObject>
|
||||
|
||||
#include "controllers\LaserPointerManager.h"
|
||||
#include "LaserPointerManager.h"
|
||||
|
||||
class LaserPointerScriptingInterface : public QObject {
|
||||
Q_OBJECT
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// RayPick.cpp
|
||||
// libraries/shared/src
|
||||
// interface/src/raypick
|
||||
//
|
||||
// Created by Sam Gondelman 7/11/2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// RayPick.h
|
||||
// libraries/shared/src
|
||||
// interface/src/raypick
|
||||
//
|
||||
// Created by Sam Gondelman 7/11/2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
145
interface/src/raypick/RayPickManager.cpp
Normal file
145
interface/src/raypick/RayPickManager.cpp
Normal file
|
@ -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> rayPick, QPair<glm::vec3, glm::vec3>& ray, QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>> 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<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>> 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<glm::vec3, glm::vec3> rayKey = QPair<glm::vec3, glm::vec3>(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<EntityScriptingInterface>()->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<EntityScriptingInterface>()->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<EntityScriptingInterface>()->findRayIntersection(ray, true, QScriptValue(), QScriptValue(), true, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!checkAndCompareCachedResults(rayPick, rayKey, results, res, RayPickMask::PICK_ENTITIES)) {
|
||||
entityRes = DependencyManager::get<EntityScriptingInterface>()->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<AvatarManager>()->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> 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();
|
||||
}
|
||||
}
|
97
interface/src/raypick/RayPickManager.h
Normal file
97
interface/src/raypick/RayPickManager.h
Normal file
|
@ -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 <QHash>
|
||||
#include <memory>
|
||||
#include <QtCore/QObject>
|
||||
|
||||
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> rayPick, QPair<glm::vec3, glm::vec3>& ray, QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>> cache, RayPickResult& res, unsigned int mask);
|
||||
unsigned int addRayPick(std::shared_ptr<RayPick> rayPick);
|
||||
void removeRayPick(const unsigned int uid);
|
||||
void enableRayPick(const unsigned int uid);
|
||||
void disableRayPick(const unsigned int uid);
|
||||
|
||||
private:
|
||||
QHash<unsigned int, std::shared_ptr<RayPick>> _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
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// StaticRayPick.cpp
|
||||
// libraries/shared/src
|
||||
// interface/src/raypick
|
||||
//
|
||||
// Created by Sam Gondelman 7/11/2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
|
@ -1,6 +1,6 @@
|
|||
//
|
||||
// StaticRayPick.h
|
||||
// libraries/shared/src
|
||||
// interface/src/raypick
|
||||
//
|
||||
// Created by Sam Gondelman 7/11/2017
|
||||
// Copyright 2017 High Fidelity, Inc.
|
|
@ -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> 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();
|
||||
}
|
||||
}
|
|
@ -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 <QHash>
|
||||
#include <memory>
|
||||
|
||||
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> rayPick);
|
||||
void removeRayPick(const unsigned int uid);
|
||||
void enableRayPick(const unsigned int uid);
|
||||
void disableRayPick(const unsigned int uid);
|
||||
|
||||
private:
|
||||
QHash<unsigned int, std::shared_ptr<RayPick>> _rayPicks;
|
||||
unsigned int _nextUID { 1 }; // 0 is invalid
|
||||
|
||||
};
|
||||
|
||||
#endif hifi_RayPickManager_h
|
Loading…
Reference in a new issue