mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 19:29:47 +02:00
initial code review
This commit is contained in:
parent
298faa9f0f
commit
55a025b827
10 changed files with 55 additions and 63 deletions
|
@ -591,6 +591,10 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) {
|
||||||
DependencyManager::set<CloseEventSender>();
|
DependencyManager::set<CloseEventSender>();
|
||||||
DependencyManager::set<ResourceManager>();
|
DependencyManager::set<ResourceManager>();
|
||||||
|
|
||||||
|
DependencyManager::set<LaserPointerScriptingInterface>();
|
||||||
|
DependencyManager::set<LaserPointerManager>();
|
||||||
|
DependencyManager::set<RayPickManager>();
|
||||||
|
|
||||||
return previousSessionCrashed;
|
return previousSessionCrashed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4922,12 +4926,12 @@ void Application::update(float deltaTime) {
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(app, "RayPick");
|
PROFILE_RANGE(app, "RayPick");
|
||||||
RayPickManager::getInstance().update();
|
DependencyManager::get<RayPickManager>()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(app, "LaserPointerManager");
|
PROFILE_RANGE(app, "LaserPointerManager");
|
||||||
LaserPointerManager::getInstance().update();
|
DependencyManager::get<LaserPointerManager>()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update _viewFrustum with latest camera and view frustum data...
|
// Update _viewFrustum with latest camera and view frustum data...
|
||||||
|
@ -5775,7 +5779,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get<AudioScope>().data());
|
scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get<AudioScope>().data());
|
||||||
scriptEngine->registerGlobalObject("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
|
scriptEngine->registerGlobalObject("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().data());
|
||||||
scriptEngine->registerGlobalObject("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data());
|
scriptEngine->registerGlobalObject("LocationBookmarks", DependencyManager::get<LocationBookmarks>().data());
|
||||||
scriptEngine->registerGlobalObject("LaserPointers", LaserPointerScriptingInterface::getInstance());
|
scriptEngine->registerGlobalObject("LaserPointers", DependencyManager::get<LaserPointerScriptingInterface>().data());
|
||||||
|
|
||||||
// Caches
|
// Caches
|
||||||
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
scriptEngine->registerGlobalObject("AnimationCache", DependencyManager::get<AnimationCache>().data());
|
||||||
|
@ -5828,7 +5832,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data());
|
scriptEngine->registerGlobalObject("EntityScriptServerLog", entityScriptServerLog.data());
|
||||||
scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance());
|
scriptEngine->registerGlobalObject("AvatarInputs", AvatarInputs::getInstance());
|
||||||
|
|
||||||
scriptEngine->registerGlobalObject("RayPick", &RayPickManager::getInstance());
|
scriptEngine->registerGlobalObject("RayPick", DependencyManager::get<RayPickManager>().data());
|
||||||
|
|
||||||
qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);
|
qScriptRegisterMetaType(scriptEngine, OverlayIDtoScriptValue, OverlayIDfromScriptValue);
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,8 @@ JointRayPick::JointRayPick(const QString& jointName, const glm::vec3& posOffset,
|
||||||
const PickRay JointRayPick::getPickRay(bool& valid) const {
|
const PickRay JointRayPick::getPickRay(bool& valid) const {
|
||||||
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
auto myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
|
||||||
int jointIndex = myAvatar->getJointIndex(_jointName);
|
int jointIndex = myAvatar->getJointIndex(_jointName);
|
||||||
if (jointIndex != -1) {
|
const int INVALID_JOINT = -1;
|
||||||
|
if (jointIndex != INVALID_JOINT) {
|
||||||
glm::vec3 jointPos = myAvatar->getAbsoluteJointTranslationInObjectFrame(jointIndex);
|
glm::vec3 jointPos = myAvatar->getAbsoluteJointTranslationInObjectFrame(jointIndex);
|
||||||
glm::quat jointRot = myAvatar->getAbsoluteJointRotationInObjectFrame(jointIndex);
|
glm::quat jointRot = myAvatar->getAbsoluteJointRotationInObjectFrame(jointIndex);
|
||||||
glm::vec3 avatarPos = myAvatar->getPosition();
|
glm::vec3 avatarPos = myAvatar->getPosition();
|
||||||
|
|
|
@ -23,7 +23,7 @@ LaserPointer::LaserPointer(const QString& jointName, const glm::vec3& posOffset,
|
||||||
_faceAvatar(faceAvatar),
|
_faceAvatar(faceAvatar),
|
||||||
_centerEndY(centerEndY)
|
_centerEndY(centerEndY)
|
||||||
{
|
{
|
||||||
_rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
|
_rayPickUID = DependencyManager::get<RayPickManager>()->addRayPick(std::make_shared<JointRayPick>(jointName, posOffset, dirOffset, filter, maxDistance, enabled));
|
||||||
|
|
||||||
for (auto& state : _renderStates.keys()) {
|
for (auto& state : _renderStates.keys()) {
|
||||||
if (!enabled || state != _currentRenderState) {
|
if (!enabled || state != _currentRenderState) {
|
||||||
|
@ -39,7 +39,7 @@ LaserPointer::LaserPointer(const glm::vec3& position, const glm::vec3& direction
|
||||||
_faceAvatar(faceAvatar),
|
_faceAvatar(faceAvatar),
|
||||||
_centerEndY(centerEndY)
|
_centerEndY(centerEndY)
|
||||||
{
|
{
|
||||||
_rayPickUID = RayPickManager::getInstance().addRayPick(std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled));
|
_rayPickUID = DependencyManager::get<RayPickManager>()->addRayPick(std::make_shared<StaticRayPick>(position, direction, filter, maxDistance, enabled));
|
||||||
|
|
||||||
for (auto& state : _renderStates.keys()) {
|
for (auto& state : _renderStates.keys()) {
|
||||||
if (!enabled || state != _currentRenderState) {
|
if (!enabled || state != _currentRenderState) {
|
||||||
|
@ -49,7 +49,7 @@ LaserPointer::LaserPointer(const glm::vec3& position, const glm::vec3& direction
|
||||||
}
|
}
|
||||||
|
|
||||||
LaserPointer::~LaserPointer() {
|
LaserPointer::~LaserPointer() {
|
||||||
RayPickManager::getInstance().removeRayPick(_rayPickUID);
|
DependencyManager::get<RayPickManager>()->removeRayPick(_rayPickUID);
|
||||||
for (RenderState& renderState : _renderStates) {
|
for (RenderState& renderState : _renderStates) {
|
||||||
if (!renderState.getStartID().isNull()) {
|
if (!renderState.getStartID().isNull()) {
|
||||||
qApp->getOverlays().deleteOverlay(renderState.getStartID());
|
qApp->getOverlays().deleteOverlay(renderState.getStartID());
|
||||||
|
@ -64,12 +64,12 @@ LaserPointer::~LaserPointer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointer::enable() {
|
void LaserPointer::enable() {
|
||||||
RayPickManager::getInstance().enableRayPick(_rayPickUID);
|
DependencyManager::get<RayPickManager>()->enableRayPick(_rayPickUID);
|
||||||
_renderingEnabled = true;
|
_renderingEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointer::disable() {
|
void LaserPointer::disable() {
|
||||||
RayPickManager::getInstance().disableRayPick(_rayPickUID);
|
DependencyManager::get<RayPickManager>()->disableRayPick(_rayPickUID);
|
||||||
_renderingEnabled = false;
|
_renderingEnabled = false;
|
||||||
if (!_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) {
|
if (!_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState)) {
|
||||||
disableRenderState(_currentRenderState);
|
disableRenderState(_currentRenderState);
|
||||||
|
@ -105,9 +105,9 @@ void LaserPointer::disableRenderState(const QString& renderState) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void LaserPointer::update() {
|
void LaserPointer::update() {
|
||||||
RayPickResult prevRayPickResult = RayPickManager::getInstance().getPrevRayPickResult(_rayPickUID);
|
RayPickResult prevRayPickResult = DependencyManager::get<RayPickManager>()->getPrevRayPickResult(_rayPickUID);
|
||||||
if (_renderingEnabled && !_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState) && prevRayPickResult.type != IntersectionType::NONE) {
|
if (_renderingEnabled && !_currentRenderState.isEmpty() && _renderStates.contains(_currentRenderState) && prevRayPickResult.type != IntersectionType::NONE) {
|
||||||
PickRay pickRay = RayPickManager::getInstance().getPickRay(_rayPickUID);
|
PickRay pickRay = DependencyManager::get<RayPickManager>()->getPickRay(_rayPickUID);
|
||||||
if (!_renderStates[_currentRenderState].getStartID().isNull()) {
|
if (!_renderStates[_currentRenderState].getStartID().isNull()) {
|
||||||
QVariantMap startProps;
|
QVariantMap startProps;
|
||||||
startProps.insert("position", vec3toVariant(pickRay.origin));
|
startProps.insert("position", vec3toVariant(pickRay.origin));
|
||||||
|
|
|
@ -14,6 +14,8 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
#include "ui/overlays/Overlay.h"
|
#include "ui/overlays/Overlay.h"
|
||||||
|
|
||||||
|
#include <DependencyManager.h>
|
||||||
#include "RayPickManager.h"
|
#include "RayPickManager.h"
|
||||||
|
|
||||||
class RayPickResult;
|
class RayPickResult;
|
||||||
|
@ -53,7 +55,7 @@ public:
|
||||||
unsigned int getUID() { return _rayPickUID; }
|
unsigned int getUID() { return _rayPickUID; }
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
const RayPickResult getPrevRayPickResult() { return RayPickManager::getInstance().getPrevRayPickResult(_rayPickUID); }
|
const RayPickResult getPrevRayPickResult() { return DependencyManager::get<RayPickManager>()->getPrevRayPickResult(_rayPickUID); }
|
||||||
|
|
||||||
void setRenderState(const QString& state);
|
void setRenderState(const QString& state);
|
||||||
void disableRenderState(const QString& renderState);
|
void disableRenderState(const QString& renderState);
|
||||||
|
|
|
@ -12,11 +12,6 @@
|
||||||
#include "LaserPointer.h"
|
#include "LaserPointer.h"
|
||||||
#include "RayPick.h"
|
#include "RayPick.h"
|
||||||
|
|
||||||
LaserPointerManager& LaserPointerManager::getInstance() {
|
|
||||||
static LaserPointerManager instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
unsigned int LaserPointerManager::createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled) {
|
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled) {
|
||||||
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
std::shared_ptr<LaserPointer> laserPointer = std::make_shared<LaserPointer>(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||||
|
|
|
@ -17,14 +17,14 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "LaserPointer.h"
|
#include "LaserPointer.h"
|
||||||
|
#include "DependencyManager.h"
|
||||||
|
|
||||||
class RayPickResult;
|
class RayPickResult;
|
||||||
|
|
||||||
class LaserPointerManager {
|
class LaserPointerManager : public Dependency {
|
||||||
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static LaserPointerManager& getInstance();
|
|
||||||
|
|
||||||
unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
unsigned int createLaserPointer(const QString& jointName, const glm::vec3& posOffset, const glm::vec3& dirOffset, const uint16_t filter, const float maxDistance,
|
||||||
const QHash<QString, RenderState>& renderStates, const bool faceAvatar, const bool centerEndY, const bool enabled);
|
const QHash<QString, RenderState>& 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,
|
unsigned int createLaserPointer(const glm::vec3& position, const glm::vec3& direction, const uint16_t filter, const float maxDistance,
|
||||||
|
|
|
@ -17,11 +17,6 @@
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
LaserPointerScriptingInterface* LaserPointerScriptingInterface::getInstance() {
|
|
||||||
static LaserPointerScriptingInterface instance;
|
|
||||||
return &instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
|
uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& properties) {
|
||||||
QVariantMap propertyMap = properties.toMap();
|
QVariantMap propertyMap = properties.toMap();
|
||||||
|
|
||||||
|
@ -104,7 +99,7 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
|
||||||
dirOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
dirOffset = vec3FromVariant(propertyMap["dirOffset"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LaserPointerManager::getInstance().createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(jointName, posOffset, dirOffset, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||||
} else if (propertyMap["position"].isValid()) {
|
} else if (propertyMap["position"].isValid()) {
|
||||||
glm::vec3 position = vec3FromVariant(propertyMap["position"]);
|
glm::vec3 position = vec3FromVariant(propertyMap["position"]);
|
||||||
|
|
||||||
|
@ -113,7 +108,7 @@ uint32_t LaserPointerScriptingInterface::createLaserPointer(const QVariant& prop
|
||||||
direction = vec3FromVariant(propertyMap["direction"]);
|
direction = vec3FromVariant(propertyMap["direction"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return LaserPointerManager::getInstance().createLaserPointer(position, direction, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
return DependencyManager::get<LaserPointerManager>()->createLaserPointer(position, direction, filter, maxDistance, renderStates, faceAvatar, centerEndY, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -15,20 +15,19 @@
|
||||||
|
|
||||||
#include "LaserPointerManager.h"
|
#include "LaserPointerManager.h"
|
||||||
#include "RegisteredMetaTypes.h"
|
#include "RegisteredMetaTypes.h"
|
||||||
|
#include "DependencyManager.h"
|
||||||
|
|
||||||
class LaserPointerScriptingInterface : public QObject {
|
class LaserPointerScriptingInterface : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
SINGLETON_DEPENDENCY
|
||||||
public:
|
|
||||||
static LaserPointerScriptingInterface* getInstance();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
Q_INVOKABLE unsigned int createLaserPointer(const QVariant& properties);
|
Q_INVOKABLE unsigned int createLaserPointer(const QVariant& properties);
|
||||||
Q_INVOKABLE void enableLaserPointer(unsigned int uid) { LaserPointerManager::getInstance().enableLaserPointer(uid); }
|
Q_INVOKABLE void enableLaserPointer(unsigned int uid) { DependencyManager::get<LaserPointerManager>()->enableLaserPointer(uid); }
|
||||||
Q_INVOKABLE void disableLaserPointer(unsigned int uid) { LaserPointerManager::getInstance().disableLaserPointer(uid); }
|
Q_INVOKABLE void disableLaserPointer(unsigned int uid) { DependencyManager::get<LaserPointerManager>()->disableLaserPointer(uid); }
|
||||||
Q_INVOKABLE void removeLaserPointer(unsigned int uid) { LaserPointerManager::getInstance().removeLaserPointer(uid); }
|
Q_INVOKABLE void removeLaserPointer(unsigned int uid) { DependencyManager::get<LaserPointerManager>()->removeLaserPointer(uid); }
|
||||||
Q_INVOKABLE void setRenderState(unsigned int uid, const QString& renderState) { LaserPointerManager::getInstance().setRenderState(uid, renderState); }
|
Q_INVOKABLE void setRenderState(unsigned int uid, const QString& renderState) { DependencyManager::get<LaserPointerManager>()->setRenderState(uid, renderState); }
|
||||||
Q_INVOKABLE RayPickResult getPrevRayPickResult(unsigned int uid) { return LaserPointerManager::getInstance().getPrevRayPickResult(uid); }
|
Q_INVOKABLE RayPickResult getPrevRayPickResult(unsigned int uid) { return DependencyManager::get<LaserPointerManager>()->getPrevRayPickResult(uid); }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,7 @@
|
||||||
#include "scripting/HMDScriptingInterface.h"
|
#include "scripting/HMDScriptingInterface.h"
|
||||||
#include "DependencyManager.h"
|
#include "DependencyManager.h"
|
||||||
|
|
||||||
RayPickManager& RayPickManager::getInstance() {
|
bool RayPickManager::checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache, RayPickResult& res, unsigned int mask) {
|
||||||
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(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.contains(ray) && cache[ray].contains(mask)) {
|
||||||
if (cache[ray][mask].distance < res.distance) {
|
if (cache[ray][mask].distance < res.distance) {
|
||||||
res = cache[ray][mask];
|
res = cache[ray][mask];
|
||||||
|
@ -35,8 +29,7 @@ bool RayPickManager::checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& r
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayPickManager::cacheResult(const bool intersects, const RayPickResult& resTemp, unsigned int mask, RayPickResult& res,
|
void RayPickManager::cacheResult(const bool intersects, const RayPickResult& resTemp, unsigned int mask, RayPickResult& res, QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache) {
|
||||||
QPair<glm::vec3, glm::vec3>& ray, QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>>& cache) {
|
|
||||||
if (intersects) {
|
if (intersects) {
|
||||||
cache[ray][mask] = resTemp;
|
cache[ray][mask] = resTemp;
|
||||||
if (resTemp.distance < res.distance) {
|
if (resTemp.distance < res.distance) {
|
||||||
|
@ -48,7 +41,7 @@ void RayPickManager::cacheResult(const bool intersects, const RayPickResult& res
|
||||||
}
|
}
|
||||||
|
|
||||||
void RayPickManager::update() {
|
void RayPickManager::update() {
|
||||||
QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>> results;
|
RayPickCache results;
|
||||||
for (auto& uid : _rayPicks.keys()) {
|
for (auto& uid : _rayPicks.keys()) {
|
||||||
std::shared_ptr<RayPick> rayPick = _rayPicks[uid];
|
std::shared_ptr<RayPick> rayPick = _rayPicks[uid];
|
||||||
if (!rayPick->isEnabled() || rayPick->getFilter() == RayPickMask::PICK_NOTHING || rayPick->getMaxDistance() < 0.0f) {
|
if (!rayPick->isEnabled() || rayPick->getFilter() == RayPickMask::PICK_NOTHING || rayPick->getMaxDistance() < 0.0f) {
|
||||||
|
|
|
@ -11,33 +11,34 @@
|
||||||
#ifndef hifi_RayPickManager_h
|
#ifndef hifi_RayPickManager_h
|
||||||
#define hifi_RayPickManager_h
|
#define hifi_RayPickManager_h
|
||||||
|
|
||||||
#include "RegisteredMetaTypes.h"
|
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QQueue>
|
#include <QQueue>
|
||||||
#include <QReadWriteLock>
|
#include <QReadWriteLock>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
|
|
||||||
|
#include "RegisteredMetaTypes.h"
|
||||||
|
#include "DependencyManager.h"
|
||||||
|
|
||||||
class RayPick;
|
class RayPick;
|
||||||
class RayPickResult;
|
class RayPickResult;
|
||||||
|
|
||||||
enum RayPickMask {
|
enum RayPickMask {
|
||||||
PICK_NOTHING = 0,
|
PICK_NOTHING = 0,
|
||||||
PICK_ENTITIES = 1,
|
PICK_ENTITIES = 1 << 0,
|
||||||
PICK_OVERLAYS = 2,
|
PICK_OVERLAYS = 1 << 1,
|
||||||
PICK_AVATARS = 4,
|
PICK_AVATARS = 1 << 2,
|
||||||
PICK_HUD = 8,
|
PICK_HUD = 1 << 3,
|
||||||
|
|
||||||
PICK_BOUNDING_BOX = 16, // if not set, picks again physics mesh (can't pick against graphics mesh, yet)
|
PICK_BOUNDING_BOX = 1 << 4, // 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_INVISIBLE = 1 << 5, // 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_INCLUDE_NONCOLLIDABLE = 1 << 6, // 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
|
PICK_ALL_INTERSECTIONS = 1 << 7 // if not set, returns closest intersection, otherwise, returns list of all intersections
|
||||||
};
|
};
|
||||||
|
|
||||||
class RayPickManager : public QObject {
|
class RayPickManager : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(unsigned int PICK_NOTHING READ PICK_NOTHING CONSTANT)
|
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_ENTITIES READ PICK_ENTITIES CONSTANT)
|
||||||
|
@ -53,14 +54,10 @@ class RayPickManager : public QObject {
|
||||||
Q_PROPERTY(unsigned int INTERSECTED_OVERLAY READ INTERSECTED_OVERLAY CONSTANT)
|
Q_PROPERTY(unsigned int INTERSECTED_OVERLAY READ INTERSECTED_OVERLAY CONSTANT)
|
||||||
Q_PROPERTY(unsigned int INTERSECTED_AVATAR READ INTERSECTED_AVATAR CONSTANT)
|
Q_PROPERTY(unsigned int INTERSECTED_AVATAR READ INTERSECTED_AVATAR CONSTANT)
|
||||||
Q_PROPERTY(unsigned int INTERSECTED_HUD READ INTERSECTED_HUD CONSTANT)
|
Q_PROPERTY(unsigned int INTERSECTED_HUD READ INTERSECTED_HUD CONSTANT)
|
||||||
|
SINGLETON_DEPENDENCY
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static RayPickManager& getInstance();
|
|
||||||
|
|
||||||
void update();
|
void update();
|
||||||
bool checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>>& cache, RayPickResult& res, unsigned int mask);
|
|
||||||
void cacheResult(const bool intersects, const RayPickResult& resTemp, unsigned int mask, RayPickResult& res,
|
|
||||||
QPair<glm::vec3, glm::vec3>& ray, QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>>& cache);
|
|
||||||
unsigned int addRayPick(std::shared_ptr<RayPick> rayPick);
|
unsigned int addRayPick(std::shared_ptr<RayPick> rayPick);
|
||||||
void removeRayPick(const unsigned int uid);
|
void removeRayPick(const unsigned int uid);
|
||||||
void enableRayPick(const unsigned int uid);
|
void enableRayPick(const unsigned int uid);
|
||||||
|
@ -78,6 +75,12 @@ private:
|
||||||
QQueue<unsigned int> _rayPicksToRemove;
|
QQueue<unsigned int> _rayPicksToRemove;
|
||||||
QReadWriteLock _containsLock;
|
QReadWriteLock _containsLock;
|
||||||
|
|
||||||
|
typedef QHash<QPair<glm::vec3, glm::vec3>, QHash<unsigned int, RayPickResult>> RayPickCache;
|
||||||
|
|
||||||
|
// Returns true if this ray exists in the cache, and if it does, update res if the cached result is closer
|
||||||
|
bool checkAndCompareCachedResults(QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache, RayPickResult& res, unsigned int mask);
|
||||||
|
void cacheResult(const bool intersects, const RayPickResult& resTemp, unsigned int mask, RayPickResult& res, QPair<glm::vec3, glm::vec3>& ray, RayPickCache& cache);
|
||||||
|
|
||||||
unsigned int PICK_NOTHING() { return RayPickMask::PICK_NOTHING; }
|
unsigned int PICK_NOTHING() { return RayPickMask::PICK_NOTHING; }
|
||||||
unsigned int PICK_ENTITIES() { return RayPickMask::PICK_ENTITIES; }
|
unsigned int PICK_ENTITIES() { return RayPickMask::PICK_ENTITIES; }
|
||||||
unsigned int PICK_OVERLAYS() { return RayPickMask::PICK_OVERLAYS; }
|
unsigned int PICK_OVERLAYS() { return RayPickMask::PICK_OVERLAYS; }
|
||||||
|
|
Loading…
Reference in a new issue