10 #ifndef hifi_display_plugins_Compositor_h
11 #define hifi_display_plugins_Compositor_h
16 #include <QtCore/QObject>
17 #include <QtCore/QMutex>
18 #include <QtCore/QPropertyAnimation>
19 #include <QtGui/QCursor>
20 #include <QtGui/QMouseEvent>
22 #include <GLMHelpers.h>
23 #include <Transform.h>
24 #include <DependencyManager.h>
26 #include "DisplayPlugin.h"
28 class ReticleInterface;
30 const float HUD_RADIUS = 1.5f;
31 const float DEFAULT_RETICLE_DEPTH = HUD_RADIUS;
33 const float MAGNIFY_WIDTH = 220.0f;
34 const float MAGNIFY_HEIGHT = 100.0f;
35 const float MAGNIFY_MULT = 2.0f;
40 class CompositorHelper :
public QObject,
public Dependency {
43 Q_PROPERTY(
float alpha READ getAlpha WRITE setAlpha NOTIFY alphaChanged)
44 Q_PROPERTY(
bool reticleOverDesktop READ getReticleOverDesktop WRITE setReticleOverDesktop)
46 static const uvec2 VIRTUAL_SCREEN_SIZE;
47 static const QRect VIRTUAL_SCREEN_RECOMMENDED_OVERLAY_RECT;
48 static const float VIRTUAL_UI_ASPECT_RATIO;
49 static const vec2 VIRTUAL_UI_TARGET_FOV;
50 static const vec2 MOUSE_EXTENTS_ANGULAR_SIZE;
51 static const vec2 MOUSE_EXTENTS_PIXELS;
54 void setRenderingWidget(QWidget* widget) { _renderingWidget = widget; }
56 bool calculateRayUICollisionPoint(
const glm::vec3& position,
const glm::vec3& direction, glm::vec3& result)
const;
57 bool calculateParabolaUICollisionPoint(
const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration, glm::vec3& result,
float& parabolicDistance)
const;
60 bool fakeEventActive()
const {
return _fakeMouseEvent; }
66 glm::vec2 sphericalToOverlay(
const glm::vec2 & sphericalPos)
const;
67 glm::vec2 overlayToSpherical(
const glm::vec2 & overlayPos)
const;
68 void computeHmdPickRay(
const glm::vec2& cursorPos, glm::vec3& origin, glm::vec3& direction)
const;
70 glm::vec2 overlayFromSphereSurface(
const glm::vec3& sphereSurfacePoint)
const;
71 glm::vec3 sphereSurfaceFromOverlay(
const glm::vec2& overlay)
const;
73 void setCameraBaseTransform(
const Transform& transform) { _cameraBaseTransform = transform; }
74 const Transform& getCameraBaseTransform()
const {
return _cameraBaseTransform; }
76 void setModelTransform(
const Transform& transform) { _modelTransform = transform; }
77 const Transform& getModelTransform()
const {
return _modelTransform; }
78 glm::mat4 getUiTransform()
const;
80 float getAlpha()
const {
return _alpha; }
81 void setAlpha(
float alpha) {
if (alpha != _alpha) { emit alphaChanged(); _alpha = alpha; } }
83 bool getReticleVisible()
const {
return _reticleVisible; }
84 void setReticleVisible(
bool visible) { _reticleVisible = visible; }
86 float getReticleDepth()
const {
return _reticleDepth; }
87 void setReticleDepth(
float depth) { _reticleDepth = depth; }
88 void resetReticleDepth() { _reticleDepth = DEFAULT_RETICLE_DEPTH; }
90 glm::vec2 getReticlePosition()
const;
91 void setReticlePosition(
const glm::vec2& position,
bool sendFakeEvent =
true);
93 glm::vec2 getReticleMaximumPosition()
const;
95 glm::mat4 getReticleTransform(
const glm::mat4& eyePose = glm::mat4(),
const glm::vec3& headPosition = glm::vec3())
const;
96 glm::mat4 getPoint2DTransform(
const glm::vec2& point,
float sizeX ,
float sizeY)
const;
98 ReticleInterface* getReticleInterface() {
return _reticleInterface; }
101 bool handleRealMouseMoveEvent(
bool sendFakeEvent =
true);
102 void handleLeaveEvent();
103 QPointF getMouseEventPosition(QMouseEvent* event);
105 bool shouldCaptureMouse()
const;
107 bool getAllowMouseCapture()
const {
return _allowMouseCapture; }
108 void setAllowMouseCapture(
bool capture);
111 bool getReticleOverDesktop()
const;
112 void setReticleOverDesktop(
bool value) { _isOverDesktop = value; }
114 void setDisplayPlugin(
const DisplayPluginPointer& displayPlugin) { _currentDisplayPlugin = displayPlugin; }
115 void setFrameInfo(uint32_t frame,
const glm::mat4& camera,
const glm::mat4& sensorToWorldMatrix) {
116 _currentCamera = camera;
117 _sensorToWorldMatrix = sensorToWorldMatrix;
121 void allowMouseCaptureChanged();
125 void sendFakeMouseEvent();
128 void updateTooltips();
130 DisplayPluginPointer _currentDisplayPlugin;
131 glm::mat4 _currentCamera;
132 glm::mat4 _sensorToWorldMatrix;
133 QWidget* _renderingWidget{
nullptr };
143 bool _isOverDesktop {
true };
144 float _textureFov { VIRTUAL_UI_TARGET_FOV.y };
145 float _textureAspectRatio { VIRTUAL_UI_ASPECT_RATIO };
147 float _alpha { 1.0f };
149 int _previousBorderWidth { -1 };
150 int _previousBorderHeight { -1 };
152 Transform _modelTransform;
153 Transform _cameraBaseTransform;
155 std::unique_ptr<QPropertyAnimation> _alphaPropertyAnimation;
157 std::atomic<bool> _reticleVisible {
true };
158 std::atomic<float> _reticleDepth { DEFAULT_RETICLE_DEPTH };
163 glm::vec2 _reticlePositionInHMD { 0.0f, 0.0f };
164 mutable QRecursiveMutex _reticleLock;
166 QPointF _lastKnownRealMouse;
167 bool _ignoreMouseMove {
false };
169 bool _reticleOverQml {
false };
171 std::atomic<bool> _allowMouseCapture {
true };
173 bool _fakeMouseEvent {
false };
175 ReticleInterface* _reticleInterface {
nullptr };
210 class ReticleInterface :
public QObject {
212 Q_PROPERTY(QVariant position READ getPosition WRITE setPosition)
213 Q_PROPERTY(
bool visible READ getVisible WRITE setVisible)
214 Q_PROPERTY(
float depth READ getDepth WRITE setDepth)
215 Q_PROPERTY(
float scale READ getScale WRITE setScale)
216 Q_PROPERTY(glm::vec2 maximumPosition READ getMaximumPosition)
217 Q_PROPERTY(
bool mouseCaptured READ isMouseCaptured)
218 Q_PROPERTY(
bool allowMouseCapture READ getAllowMouseCapture WRITE setAllowMouseCapture)
219 Q_PROPERTY(
bool pointingAtSystemOverlay READ isPointingAtSystemOverlay)
222 ReticleInterface(CompositorHelper* outer) : QObject(outer), _compositor(outer) {}
232 Q_INVOKABLE
bool isMouseCaptured() {
return _compositor->shouldCaptureMouse(); }
241 Q_INVOKABLE
bool getAllowMouseCapture() {
return _compositor->getAllowMouseCapture(); }
250 Q_INVOKABLE
void setAllowMouseCapture(
bool value) {
return _compositor->setAllowMouseCapture(value); }
259 Q_INVOKABLE
bool isPointingAtSystemOverlay() {
return !_compositor->getReticleOverDesktop(); }
268 Q_INVOKABLE
bool getVisible() {
return _compositor->getReticleVisible(); }
277 Q_INVOKABLE
void setVisible(
bool visible) { _compositor->setReticleVisible(visible); }
284 Q_INVOKABLE
float getDepth() {
return _compositor->getReticleDepth(); }
291 Q_INVOKABLE
void setDepth(
float depth) { _compositor->setReticleDepth(depth); }
299 Q_INVOKABLE
float getScale()
const;
307 Q_INVOKABLE
void setScale(
float scale);
316 Q_INVOKABLE QVariant getPosition()
const;
325 Q_INVOKABLE
void setPosition(QVariant position);
333 Q_INVOKABLE glm::vec2 getMaximumPosition() {
return _compositor->getReticleMaximumPosition(); }
336 CompositorHelper* _compositor;