mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 10:43:21 +02:00
Fix ray picks against HUD sphere at different sensor scale factors
This commit is contained in:
parent
26e9e6e580
commit
f0912987a3
4 changed files with 23 additions and 12 deletions
|
@ -2551,7 +2551,7 @@ void Application::paintGL() {
|
||||||
|
|
||||||
{
|
{
|
||||||
PROFILE_RANGE(render, "/updateCompositor");
|
PROFILE_RANGE(render, "/updateCompositor");
|
||||||
getApplicationCompositor().setFrameInfo(_frameCount, _myCamera.getTransform());
|
getApplicationCompositor().setFrameInfo(_frameCount, _myCamera.getTransform(), getMyAvatar()->getSensorToWorldMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
gpu::FramebufferPointer finalFramebuffer;
|
gpu::FramebufferPointer finalFramebuffer;
|
||||||
|
|
|
@ -108,4 +108,4 @@ void RayPickScriptingInterface::setIgnoreAvatars(QUuid uid, const QScriptValue&
|
||||||
|
|
||||||
void RayPickScriptingInterface::setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) {
|
void RayPickScriptingInterface::setIncludeAvatars(QUuid uid, const QScriptValue& includeAvatars) {
|
||||||
qApp->getRayPickManager().setIncludeAvatars(uid, includeAvatars);
|
qApp->getRayPickManager().setIncludeAvatars(uid, includeAvatars);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <QtGui/QWindow>
|
#include <QtGui/QWindow>
|
||||||
#include <QQuickWindow>
|
#include <QQuickWindow>
|
||||||
|
|
||||||
|
#include <DebugDraw.h>
|
||||||
#include <shared/QtHelpers.h>
|
#include <shared/QtHelpers.h>
|
||||||
#include <ui/Menu.h>
|
#include <ui/Menu.h>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
|
@ -339,23 +340,29 @@ void CompositorHelper::computeHmdPickRay(const glm::vec2& cursorPos, glm::vec3&
|
||||||
glm::mat4 CompositorHelper::getUiTransform() const {
|
glm::mat4 CompositorHelper::getUiTransform() const {
|
||||||
glm::mat4 modelMat;
|
glm::mat4 modelMat;
|
||||||
_modelTransform.getMatrix(modelMat);
|
_modelTransform.getMatrix(modelMat);
|
||||||
return _currentCamera * glm::inverse(_currentDisplayPlugin->getHeadPose()) * modelMat;
|
return _sensorToWorldMatrix * modelMat;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Finds the collision point of a world space ray
|
//Finds the collision point of a world space ray
|
||||||
bool CompositorHelper::calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const {
|
bool CompositorHelper::calculateRayUICollisionPoint(const glm::vec3& position, const glm::vec3& direction, glm::vec3& result) const {
|
||||||
auto UITransform = getUiTransform();
|
glm::mat4 uiToWorld = getUiTransform();
|
||||||
auto relativePosition4 = glm::inverse(UITransform) * vec4(position, 1);
|
glm::mat4 worldToUi = glm::inverse(uiToWorld);
|
||||||
auto relativePosition = vec3(relativePosition4) / relativePosition4.w;
|
glm::vec3 localPosition = transformPoint(worldToUi, position);
|
||||||
auto relativeDirection = glm::inverse(glm::quat_cast(UITransform)) * direction;
|
glm::vec3 localDirection = glm::normalize(transformVectorFast(worldToUi, direction));
|
||||||
|
|
||||||
const float UI_RADIUS = 1.0f; // * myAvatar->getUniformScale(); // FIXME - how do we want to handle avatar scale
|
const float UI_RADIUS = 1.0f;
|
||||||
float instersectionDistance;
|
float instersectionDistance;
|
||||||
if (raySphereIntersect(relativeDirection, relativePosition, UI_RADIUS, &instersectionDistance)){
|
if (raySphereIntersect(localDirection, localPosition, UI_RADIUS, &instersectionDistance)) {
|
||||||
result = position + glm::normalize(direction) * instersectionDistance;
|
result = transformPoint(uiToWorld, localPosition + localDirection * instersectionDistance);
|
||||||
|
#ifdef WANT_DEBUG
|
||||||
|
DebugDraw::getInstance().drawRay(position, result, glm::vec4(0.0f, 1.0f, 0.0f, 1.0f));
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
#ifdef WANT_DEBUG
|
||||||
|
DebugDraw::getInstance().drawRay(position, position + (direction * 1000.0f), glm::vec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,10 @@ public:
|
||||||
void setReticleOverDesktop(bool value) { _isOverDesktop = value; }
|
void setReticleOverDesktop(bool value) { _isOverDesktop = value; }
|
||||||
|
|
||||||
void setDisplayPlugin(const DisplayPluginPointer& displayPlugin) { _currentDisplayPlugin = displayPlugin; }
|
void setDisplayPlugin(const DisplayPluginPointer& displayPlugin) { _currentDisplayPlugin = displayPlugin; }
|
||||||
void setFrameInfo(uint32_t frame, const glm::mat4& camera) { _currentCamera = camera; }
|
void setFrameInfo(uint32_t frame, const glm::mat4& camera, const glm::mat4& sensorToWorldMatrix) {
|
||||||
|
_currentCamera = camera;
|
||||||
|
_sensorToWorldMatrix = sensorToWorldMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void allowMouseCaptureChanged();
|
void allowMouseCaptureChanged();
|
||||||
|
@ -124,6 +127,7 @@ private:
|
||||||
|
|
||||||
DisplayPluginPointer _currentDisplayPlugin;
|
DisplayPluginPointer _currentDisplayPlugin;
|
||||||
glm::mat4 _currentCamera;
|
glm::mat4 _currentCamera;
|
||||||
|
glm::mat4 _sensorToWorldMatrix;
|
||||||
QWidget* _renderingWidget{ nullptr };
|
QWidget* _renderingWidget{ nullptr };
|
||||||
|
|
||||||
//// Support for hovering and tooltips
|
//// Support for hovering and tooltips
|
||||||
|
|
Loading…
Reference in a new issue